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

// Boostrap Carousel
$itemsperpage = (int)$this->getConfig('brand_block/item_per_page',6);
$lg_column_item = (int)$this->getConfig('brand_block/lg_column_item',6);
$md_column_item = (int)$this->getConfig('brand_block/md_column_item',6);
$sm_column_item = (int)$this->getConfig('brand_block/sm_column_item',6);
$xs_column_item = (int)$this->getConfig('brand_block/xs_column_item',6);

$lg_column = 12/$lg_column_item;
$md_column = 12/$md_column_item;
$sm_column = 12/$sm_column_item;
$xs_column = 12/$xs_column_item;

$show_brand_name = $this->getConfig('brand_block/show_brand_name');
$addition_class = $this->getConfig('brand_block/addition_class');
$interval = $this->getConfig('brand_block/interval',1000);
$auto_play = $this->getConfig('brand_block/auto_play');
$speed = $this->getConfig('brand_block/speed');
$dots = $this->getConfig('brand_block/dots',true);
$nav = $this->getConfig('brand_block/nav',true);
$nav_prev = $this->getConfig('brand_block/nav_prev');
$nav_next = $this->getConfig('brand_block/nav_next');

?>
<?php if ( $_brandCollection->count() ){ ?>
<?php
$total = $_brandCollection->getSize();
$totalPage = '';
if($total%$itemsperpage == 0){
	$totalPage = $total/$itemsperpage;
}else{
	$totalPage = floor($total/$itemsperpage)+1;
}
$pretext                = $_helper->filter($this->getConfig('brand_block/pretext'));
?>
<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 id="productcarousel-<?php echo $blockId ?>" class="block-content carousel slide" data-ride="carousel" data-interval="<?php echo $interval?$interval:"false"; ?>">
		<!-- Indicators -->
		<?php if($dots && $totalPage>0){ ?>
		<ol class="carousel-indicators">
			<?php for ($i=0; $i < $totalPage ; $i++) { ?>
			<li data-target="#productcarousel-<?php echo $blockId ?>" data-slide-to="<?php echo $i ?>"></li>
			<?php } ?>
		</ol>
		<?php } ?>
		<!-- Wrapper for slides -->
		<div class="carousel-inner" role="listbox">
			<?php
			$i = 1;
			$x = 0;
			?>
			<?php foreach ($_brandCollection as $_brand) { ?>
			<?php if( $itemsperpage == 1 || $i % $itemsperpage == 1){ ?>
			<div class="item <?php if($i==1){ ?>active<?php } ?>">
				<?php } ?>
				<?php if( $lg_column_item == 1 || $x%$lg_column_item == 0 || $x%$itemsperpage == 0){ ?>
				<div class="row">
					<?php } ?>
					<div class="col-lg-<?php echo $lg_column ?> col-md-<?php echo $md_column ?> col-sm-<?php echo $sm_column ?> col-xs-<?php echo $xs_column ?>">
						<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>
					</div>
					<?php if( $lg_column_item == 1 || ($x+1)%$lg_column_item == 0 || $i == $total || ($x>0 && ($x+1)%$itemsperpage == 0) ) {  ?>
				</div>
				<?php } ?>
				<?php if( $itemsperpage == 1 || ($i+1)%$itemsperpage == 1 || $i == $total ) { $x = -1; ?>
			</div>
			<?php } ?>
			<?php $i++; $x++; ?>
			<?php } ?>
		</div>
		<?php if($nav && $total>$xs_column_item){ ?>
		<div class="carousel-controls">
			<a class="left carousel-control" href="#productcarousel-<?php echo $blockId ?>" role="button" data-slide="prev"><?php echo $nav_prev?$nav_prev:'Previous'); ?></a>
			<a class="right carousel-control" href="#productcarousel-<?php echo $blockId ?>" role="button" data-slide="next"><?php echo $nav_next?$nav_next:'Next'; ?></a>
		</div>
		<?php } ?>
	</div>
</div>
<?php } ?>
<script type="text/javascript">
	require([<?php if($this->helper("Rokanthemes\All\Helper\Data")->getConfig("enable_bootstrap_js")): ?>
		"Rokanthemes_All/lib/bootstrap/js/bootstrap.min",
	<?php endif; ?>
		], function () {});
</script>