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

/** @var $block \Magento\Checkout\Block\Cart\Sidebar */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>

<div data-block="minicart" class="minicart-wrapper">
    <a class="action showcart" href="<?= $block->escapeUrl($block->getShoppingCartUrl()) ?>"
       data-bind="scope: 'minicart_content'">
        <span class="text"><?= $block->escapeHtml(__('My Cart')) ?></span>
        <span class="counter qty empty"
              data-bind="css: { empty: !!getCartParam('summary_count') == false && !isLoading() },
               blockLoader: isLoading">
            <!-- ko if: getCartParam('summary_count') -->
                <span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
            <!-- /ko -->
            <!-- ko ifnot: getCartParam('summary_count') -->
                <span class="counter-number">0</span>
            <!-- /ko -->
            <span class="counter-label">
            <!-- ko if: getCartParam('summary_count') -->
                <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
                <!-- ko i18n: 'items' --><!-- /ko -->
            <!-- /ko -->
            </span>
        </span>
    </a>
    <?php if ($block->getIsNeedToDisplaySideBar()):?>
        <div class="block block-minicart"
             data-role="dropdownDialog"
             data-mage-init='{"dropdownDialog":{
                "appendTo":"[data-block=minicart]",
                "triggerTarget":".showcart",
                "timeout": "2000",
                "closeOnMouseLeave": false,
                "closeOnEscape": true,
                "triggerClass":"active",
                "parentClass":"active",
                "buttons":[]}}'>
            <div id="minicart-content-wrapper" data-bind="scope: 'minicart_content'">
                <h3 class="close-minicart">
                    <?php echo __('Mini Cart'); ?>
                    <button id="close-minicart"><i class="close-cart pe-7s-close pa"></i></button>
                </h3>
                <!-- ko template: getTemplate() --><!-- /ko -->
            </div>
            <?= $block->getChildHtml('minicart.addons') ?>
        </div>
    <?php else: ?>
        <?php $scriptString = <<<script
            require(['jquery'], function ($) {
                $('a.action.showcart').on('click', function() {
                    $(document.body).trigger('processStart');
                });
            });
        script;
        ?>
        <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false); ?>
    <?php endif ?>
    <?= /* @noEscape */ $secureRenderer->renderTag('script', [], 'window.checkout = ' .
     /* @noEscape */ $block->getSerializedConfig(), false); ?>
    <script type="text/x-magento-init">
    {
        "[data-block='minicart']": {
            "Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
        },
        "*": {
            "Magento_Ui/js/block-loader": "<?= $block->escapeJs(
                $block->escapeUrl($block->getViewFileUrl('images/loader-1.gif'))
            ) ?>"
        }
    }
    </script>
</div>
