<?php
/**
 * Copyright © 2018 Codazon, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php
$helper = $this->helper('Codazon\ThemeLayoutPro\Helper\Data');
$json = $helper->getConfig('mobile/general/bottom_toolbar_json');
?>
<?php if ((bool)$helper->getConfig('mobile/general/display_bottom_toolbar') && $json) : ?>
<?php
$displayLabel = $helper->getConfig('mobile/general/display_button_label');
$minicartStyle = $helper->getMiniCartStyle();
$toolbarItems = [];
$items = json_decode($json, true);
foreach ($items as $i => $item) {
    switch ($item['type']) {
        case 'cart':
            $item['class'] = $item['class'] . ' js-footer-cart';
            if ($minicartStyle == 'dropdown') {
                $item['data_action'] = '{"display": {"element": "#mobi_cart-wrapper .block-minicart"}}';
            } else {
                $item['data_action'] = '{"trigger": {"event":"click", "target": "#mobi_cart-wrapper a.cdz-top-link"}}';
            }
            $item['custom_html'] = '<span class="info-wrap" data-bind="scope: \'minicart_content\'" data-block="minicart"><span class="counter-number"><!-- ko text: getCartParam(\'summary_count\') --><!-- /ko --></span></span>';
            break;
        case 'search':
            $item['data_action'] = '{"trigger": {"event":"click", "target": ".full-box-trigger:first"}}';
            break;
        case 'menu':
            $item['data_action'] = '{"trigger": {"event":"click", "target": ".page-header .nav-toggle[data-action=toggle-nav]"}}';
            break;
        default:
    }
    $toolbarItems[] = $item;
}
$count = count($toolbarItems);
ob_start();
?>
<?php if ($count) : ?>
<div class="mb-bottom-toolbar visible-xs" id="mb-bottom-toolbar">
    <div class="mb-toolbar-backface" data-role="close-content"></div>
    <div class="mb-toolbar-content">
        <div class="mb-toolbar-content-inner cdz-dd-content cdz-dropdown" data-role="mb-toolbar-content"></div>
    </div>
    <div class="mb-toolbar-inner row">
        <div class="btn-groups <?= ($count > 4) ? 'col-xs-18' : 'col-xs-24' ?>">
            <div class="owl-carousel" id="btn-group-slider" data-role="group-slider">
                <div class="btn-group" id="tool-btn-group-1" data-role="group-item">
                    <ul class="menu-items items row">
                        <?php for($i = 0; $i < 4; $i++) : ?>
                        <?php if (!empty($toolbarItems[$i])) : ?>
                        <li class="item col-xs-6<?= empty($toolbarItems[$i]['class']) ? '' : ' '.$toolbarItems[$i]['class']; ?>">
                            <a class="action"
                                href="<?= empty($toolbarItems[$i]['url']) ? '' : $toolbarItems[$i]['url']; ?>" <?= $toolbarItems[$i]['attributes'] ?>
                                <?= empty($toolbarItems[$i]['data_action']) ? '' : "data-action='{$toolbarItems[$i]['data_action']}'" ?>
                                >
                                <i class="<?= empty($toolbarItems[$i]['icon']) ? 'fa fa-user-o' : $toolbarItems[$i]['icon']; ?>"></i>
                                <?= empty($toolbarItems[$i]['custom_html']) ? '' : $toolbarItems[$i]['custom_html']; ?>
                            </a>
                            <?php if ($displayLabel) : ?><span class="ilabel"><?= $toolbarItems[$i]['label'] ?></span><?php endif ?>
                        </li>
                        <?php endif ?>
                        <?php endfor ?>
                    </ul>
                </div>
                <?php if ($count > 4) : ?>
                <div class="btn-group" id="tool-btn-group-2" data-role="group-item">
                    <ul class="menu-items items row">
                        <?php for($i = 4; $i < 8; $i++) : ?>
                        <?php if (!empty($toolbarItems[$i])) : ?>
                        <li class="item col-xs-6<?= empty($toolbarItems[$i]['class']) ? '' : ' '.$toolbarItems[$i]['class']; ?>">
                            <a class="action" href="<?= empty($toolbarItems[$i]['url']) ? '' : $toolbarItems[$i]['url']; ?>" <?= $toolbarItems[$i]['attributes'] ?>
                                <?= empty($toolbarItems[$i]['data_action']) ? '' : "data-action='{$toolbarItems[$i]['data_action']}'" ?>
                                >
                                <i class="<?= empty($toolbarItems[$i]['icon']) ? 'fa fa-user-o' : $toolbarItems[$i]['icon']; ?>"></i>
                                <?= empty($toolbarItems[$i]['custom_html']) ? '' : $toolbarItems[$i]['custom_html']; ?>
                            </a>
                            <?php if ($displayLabel) : ?><span class="ilabel"><?= $toolbarItems[$i]['label'] ?></span><?php endif ?>
                        </li>
                        <?php endif ?>
                        <?php endfor ?>
                    </ul>
                </div>
                <?php endif ?>
            </div>
        </div>
        <?php if ($count > 4) : ?>
        <div class="col-xs-6 group-switch">
            <button data-role="switch-group" class="switcher" href="javascript:void(0);">
                <span class="fa fa-circle-o dot"></span>
                <span class="fa fa-circle-o dot"></span>
                <span class="fa fa-circle-o dot"></span>
                <span class="times"></span>
            </button>
            <?php if ($displayLabel) : ?><span class="ilabel"><?= __('More') ?></span><?php endif ?>
        </div>
        <?php endif ?>
    </div>
</div>
<?php $html = ob_get_contents();
ob_end_clean();
echo $helper->htmlFilter($html); ?>
<?php endif ?>
<?php endif ?>