<?php
$_brandCollection          = $block->getBrandCollection();
$_helper                   = $this->helper('Rokanthemes\Brand\Helper\Data');
$title                     = $this->getConfig('brand_block/title');
$show_brand_name           = $this->getConfig('brand_block/show_brand_name');

$blockId                   = rand() . time() . uniqid();
$number_item_per_column    = (int)$this->getConfig('brand_block/number_item_per_column');
if($number_item_per_column == '' || $number_item_per_column == 0)
$number_item_per_column = 1;

$default_items             = $this->getConfig('brand_block/default_items');
$addition_class            = $this->getConfig('brand_block/addition_class');
$mobile_items              = (int)$this->getConfig('brand_block/mobile_items',1);
$tablet_small_items        = (int)$this->getConfig('brand_block/tablet_small_items',2);
$tablet_items              = (int)$this->getConfig('brand_block/tablet_items',3);
$portrait_items            = (int)$this->getConfig('brand_block/portrait_items',4);
$large_items               = (int)$this->getConfig('brand_block/large_items',5);
$dots                      = $this->getConfig('brand_block/dots');
$nav                       = $this->getConfig('brand_block/nav');
$nav_prev                  = $this->getConfig('brand_block/nav_prev');
$nav_next                  = $this->getConfig('brand_block/nav_next');
$loop                      = $this->getConfig('brand_block/loop');
$autoplay                  = $this->getConfig('brand_block/autoplay');
$autoplay_timeout          = (int)$this->getConfig('brand_block/autoplay_timeout',3000);
$autoplay_pauseonhover     = (int)$this->getConfig('brand_block/autoplay_pauseonhover');
$auto_play                 = $this->getConfig('brand_block/auto_play');
$rtl                       = $this->getConfig('brand_block/rtl');
$pretext                   = $_helper->filter($this->getConfig('brand_block/pretext'));
?>
<?php if ( $_brandCollection->count() ){ ?>
<?php
$_collection = [];
$i = $x = 0;
$total  = $_brandCollection->count();
$column = 8;
if($total%$number_item_per_column == 0){
	$column = $total/$number_item_per_column;
}else{
	$column = floor($total/$number_item_per_column)+1;
}
if($column<$default_items) $column = $default_items;
$i = $x = 0;
foreach ($_brandCollection as $_brand) {
	if($i<$column){
		$i++;
	}else{
		$i = 1;
		$x++;
	}
	$_collection[$i][$x] = $_brand;
} 
?>
<div class="block widget rokanthemes-widget brand-widget <?php echo $addition_class?$addition_class:'' ?>">
	<?php if($title){ ?>
	<div class="block-title"><strong><?php echo $title ?></strong></div>
	<?php } ?>
	<?php if($pretext!=''){ ?>
	<div class="pretext-html"><?php echo $pretext ?></div>
	<?php } ?>
	<div class="block-content brandowl-play">
		<ul id="<?php echo $blockId ?>" class="owl-carousel" data-rtl="<?php echo $rtl?"true":"false" ?>" data-loop="<?php echo $loop?"true":"false" ?>" data-nav="false" data-dot="<?php echo $dots?"true":"false" ?>" data-autoplay="<?php echo $autoplay?"true":"false" ?>" data-autoplay-timeout="<?php echo $autoplay_timeout ?>" data-pauonhover="<?php echo $autoplay_pauseonhover?"true":"false" ?>" data-mobile-items="<?php echo (int)$mobile_items ?>" data-tablet-small-items="<?php echo (int)$tablet_small_items ?>" data-tablet-items="<?php echo (int)$tablet_items ?>" data-portrait-items="<?php echo (int)$portrait_items ?>" data-large-items="<?php echo (int)$default_items ?>" data-large-max-items="<?php echo (int)$large_items ?>" >
			<?php foreach ($_collection as $_brandCollection) { ?> 
			<li class="item-load item"> 
				<?php foreach ($_brandCollection as $_brand) { ?>
				<div class="brand-item">
					<div class="brand-image"><a href="<?php echo $_brand->getUrl(); ?>" title="<?php echo $_brand->getName(); ?>"><img src="<?php echo $_brand->getThumbnailUrl(); ?>" alt="<?php echo $_brand->getName(); ?>"/></a></div>
					<?php if($show_brand_name){ ?>
					<div class="brand-name"><a href="<?php echo $_brand->getUrl(); ?>" title="<?php echo $_brand->getName(); ?>"><?php echo $_brand->getName() ?></a></div>
					<?php } ?>
				</div>
				<?php } ?>
			</li>
			<?php } ?>
		</ul>
		<?php if($nav){ ?>
		<a href="#" class="owl-left"><?php echo $nav_prev?$nav_prev:'Prev'; ?></a>
		<a href="#" class="owl-right"><?php echo $nav_next?$nav_next:'Next'; ?></a>
		<?php } ?>
	</div>
</div>
<?php } ?>
<script type="text/javascript">
	require(['jquery',
		<?php if($this->helper("Rokanthemes\All\Helper\Data")->getConfig("enable_owlcarousel")): ?>
		"Rokanthemes_All/lib/owl.carousel/owl.carousel.min",
		<?php endif; ?>
		'Rokanthemes_Brand/js/brand'], function () {});
</script>