<?php
/**
 * Copyright © 2017 Codazon, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>

<?php
$orderBy = $block->getData('order_by');
$orderWay = $block->getData('order_way');
$onlyFeaturedBrands = ($block->getData('collection') == 'featured_brands');
$limit = $block->getData('limit');
$brands = $block->getBrandObject($orderBy, $orderWay, $onlyFeaturedBrands, false, $limit);
$itemPerCol = $block->getData('items_per_column');
$itemCount = count($brands);
$width = $block->getData('thumb_width');
$height = $block->getData('thumb_height');
$paddingBottom = 100*$height/$width;
$widget = ['themewidgets' => [
    'codazon.slider' => ['sliderConfig' => $block->getSliderData(), 'noLoadedClass' => 'no-loaded']
]];
?>

<?php if ($itemCount > 0): ?>
<?php $i = 0; ?>
<div class="brand-slider-wrapper no-loaded" data-role="slider-wrapper">
    <div class="brand-loader double-bounce-spinner" data-role="slider-loader">
        <div class="double-bounce1"></div>
        <div class="double-bounce2"></div>
    </div>
    <div class="shop-by-brand-slider style-default owl-carousel<?= $block->getData('slider_dots')?' has-dots':'' ?>" data-mage-init='<?= json_encode($widget) ?>'>
        <?php foreach ($brands as $brand) : ?>
        <?php if ($i%$itemPerCol == 0) : ?>
        <div class="item-group">
        <?php endif ?>
        <div class="brand-item">
            <a class="brand-link abs-img" style="padding-bottom: <?= $paddingBottom ?>%" href="<?= $brand->getUrl() ?>" title="<?= $brand->getBrandLabel(); ?>">
                <img class="brand-img owl-lazy zoom-eff" alt="<?= strip_tags($brand->getBrandLabel()) ?>" data-src="<?= $block->getThumbnailImage($brand, ['width' => $width, 'height' => $height]) ?>" />
            </a>
        </div>
        <?php if (($i%$itemPerCol == ($itemPerCol - 1)) || ($i == $itemCount - 1)) : ?>
        </div>
        <?php endif ?>
        <?php $i++; endforeach ?>
    </div>
</div>
<?php else : ?>
<div class="message info empty"><div><?= __('We can\'t find brands matching the selection.') ?></div></div>
<?php endif ?>