<?php
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Advanced Search Base for Magento 2
 */ if ($block->isTabsEnabled()): ?>
    <?php
        /** @var \Amasty\Xsearch\Block\Search\Tab $block */ $collection = $block->getTabs();
        /** @var \Magento\Framework\Escaper $escaper */
    ?>
    <?php if ($collection): ?>
        <?php $searchResultHtml = $block->getChildHtml('search.result'); ?>
        <div class="amsearch-result-tabs product data items"
             data-mage-init='{"tabs":{"openedState":"active"}}'>
            <div class="data item title"
                 data-role="collapsible">
                <a class="data switch"
                   tabindex="-1"
                   data-toggle="switch"
                   href="#tabs-amasty_search_products_tab"
                   title="<?= /* @noEscape */ __('Products'); ?>">
                    <?= /* @noEscape */ __('Products'); ?>
                    <span class="amsearch-results-count">(<?= /* @noEscape */ $block->getProductCount()?>)</span>
                </a>
            </div>
            <?php $itemsCount = count($collection); ?>
            <?php foreach ($collection as $key => $item): ?>
                <div class="data item title <?php if ($key == $itemsCount - 1): ?>last<?php endif;?>"
                     data-role="collapsible">
                    <a class="data switch"
                       tabindex="-1"
                       data-toggle="switch"
                       href="#tabs-<?= /* @noEscape */ $item['block_name'];?>"
                       title="<?= /* @noEscape */ $item['name'] ?>">
                        <?= /* @noEscape */ $item['name']; ?>
                        <span class="amsearch-results-count">(<?= /* @noEscape */ $item['items_count']?>)</span>
                    </a>
                </div>
            <?php endforeach; ?>

            <div class="amsearch-products-tab data item content"
                 id="tabs-amasty_search_products_tab"
                 aria-label="<?= $escaper->escapeHtmlAttr(__('Search Tab')) ?>"
                 data-role="content">
                <?= /* @noEscape */ $searchResultHtml ?>
            </div>
            <?php foreach ($collection as $item): ?>
                <div class="data item content <?= /* @noEscape */ $item['block_name'];?>"
                     id="tabs-<?= /* @noEscape */ $item['block_name'];?>"
                     data-role="content">
                    <?= /* @noEscape */ $item['html'];?>
                </div>
            <?php endforeach; ?>
        </div>
    <?php else: ?>
        <?= $block->getChildHtml('search.result'); ?>
    <?php endif; ?>
<?php else: ?>
    <?= $block->getChildHtml('search.result'); ?>
<?php endif; ?>
