<?php
/**
 * Olegnax BrandSlider
 * 
 * This file is part of Olegnax/Core.
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Olegnax.com license that is
 * available through the world-wide-web at this URL:
 * https://www.olegnax.com/license
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Olegnax
 * @package     Olegnax_BrandSlider
 * @copyright   Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
 * @license     https://www.olegnax.com/license
 */
$slider_id			 = $block->getSliderId();
$brands				 = $block->getItems();
$athleteImgHelper	 = $this->helper( 'Olegnax\BrandSlider\Helper\Image' );
$customArrows		 = true;
$showNav = ($block->getNav() == 'hide') ? false : true;
$classes = [];
$classes [] = $block->getColumnsMobile() ? ('columns-s-' . $block->getColumnsMobile()) : '';
$classes[] = 'hover-'. ($block->getImageHover() ?: 'default');
$width = $block->getWidth();
$height = $block->getHeight();
$paddingBottom = ($height / $width) * 100 . '%';
if($block->getBordered()){
	$classes[] = 'ox-brand--bordered';
}
if ( 0 < count( $brands ) ) :
	?>
	<div id="<?php echo $slider_id ?>" class="block widget ox-brand-slider__container <?php echo $escaper->escapeHtmlAttr(implode(' ', $classes )); ?>">
		<?php if ( $customArrows && $showNav ) { ?>
			<div class="ox-nav-sideline">
				<div id="<?php echo $escaper->escapeHtmlAttr($slider_id) ?>_list_nav" class="owl-nav ox-owl-nav">				
					<button class="owl-prev ox-owl-prev" role="presentation"><span aria-label="Previous">></span></button>
					<button class="owl-next ox-owl-next" role="presentation"><span aria-label="Next"><</span></button>
				</div>
			</div>
		<?php } ?>
		<div id="<?php echo $escaper->escapeHtmlAttr($slider_id) ?>_list" class="ox-carousel__brands owl-carousel" data-mage-init='{"OXBrandsSlider":<?php echo
		json_encode( [
			'autoScroll'	 => $escaper->escapeHtmlAttr($block->getAutoScroll()),
			'slideBy'		 => $escaper->escapeHtmlAttr($block->getScrollItems()),
			'rewind'		 => (bool) $block->getRewind(),
			'responsive'	 => $block->getResponsive( false ),
			'slideWidth'	 => $escaper->escapeHtmlAttr($width),
			'slideHeight'	 => $escaper->escapeHtmlAttr($height),
		] );
		?>}' style="height: <?php echo $height ?>px">
				<?php foreach ( $brands as $brand ) : ?>
					<?php
					$size	 = [ $block->getWidth(), $block->getHeight() ];
					$url	 = $athleteImgHelper->adaptiveResize( $brand->getImageName(), $size )->getUrl();
					if($athleteImgHelper->_imageExist){ 
					?>
						<div class="ox-brand__slide slide<?php echo $escaper->escapeHtmlAttr($brand->getValue()); ?>">
							<?php 
								$link = '';
								if(!$brand->getNoLink()) {
									$link = $block->getBrandUrl( $brand );
								}	
							?>
							<a href="<?php echo $escaper->escapeUrl($link) ?>" class="ox-brand__link" style="padding-bottom: <?php echo $escaper->escapeHtmlAttr($paddingBottom) ?>"><span></span><img src="<?php echo $escaper->escapeUrl($url); ?>" alt="<?php echo $escaper->escapeHtmlAttr($brand->getLabel()); ?>" width="<?php echo $escaper->escapeHtmlAttr($width); ?>" height="<?php echo $escaper->escapeHtmlAttr($height); ?>" class="ox-brand-slider__image" /></a>
						</div>
					<?php } ?>
			<?php endforeach; ?>
		</div>
	</div>
<?php endif; ?>
