<?php
/**
 * Maho
 *
 * @category    design
 * @package     rwd_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2022 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Shoping cart sidebar
 *
 * @var Mage_Checkout_Block_Cart_Minicart $this
 */
?>

<?php
$_cartQty = $this->getSummaryCount();
if(empty($_cartQty)) {
    $_cartQty = 0;
}
?>
<div id="minicart-error-message" class="minicart-message"></div>
<div id="minicart-success-message" class="minicart-message"></div>

<div class="minicart-wrapper">

    <p class="block-subtitle">
        <?= $this->__('Recently added item(s)') ?>
        <a class="close skip-link-close" href="#" title="<?= $this->quoteEscape($this->__('Close')) ?>">&times;</a>
    </p>

    <?php $_items = $this->getRecentItems() ?>
    <?php $countItems = count($_items); ?>
    <?php if($countItems): ?>
        <div>
            <ul id="cart-sidebar" class="mini-products-list">
                <?php foreach($_items as $_item): ?>
                    <?= $this->getItemHtml($_item) ?>
                <?php endforeach ?>
            </ul>
        </div>
        <script type="text/javascript">
            truncateOptions();
            document.addEventListener('DOMContentLoaded', function() {
                var Mini = new Minicart({
                    formKey: "<?= $this->getFormKey() ?>"
                });
                Mini.init();
            });
        </script>

        <div id="minicart-widgets">
            <?= $this->getChildHtml('cart_promotion') ?>
        </div>
        <div class="block-content">
            <p class="subtotal">
                <?php if ($this->canApplyMsrp()): ?>
                    <span class="map-cart-sidebar-total"><?= $this->__('ORDER TOTAL WILL BE DISPLAYED BEFORE YOU SUBMIT THE ORDER') ?></span>
                <?php else: ?>
                    <span class="label"><?= $this->__('Cart Subtotal:') ?></span> <?= Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?>
                    <?php if ($_subtotalInclTax = $this->getSubtotalInclTax()): ?>
                        <br />(<?= Mage::helper('checkout')->formatPrice($_subtotalInclTax) ?> <?= Mage::helper('tax')->getIncExcText(true) ?>)
                    <?php endif ?>
                <?php endif ?>
            </p>
        </div>


        <div class="minicart-actions">
            <?php if($_cartQty && $this->isPossibleOnepageCheckout()): ?>
                <ul class="checkout-types minicart">
                    <?= $this->getChildHtml('extra_actions') ?>
                    <li>
                        <a title="<?= $this->quoteEscape($this->__('Checkout')) ?>" class="button checkout-button" href="<?= $this->getCheckoutUrl() ?>">
                            <?= $this->__('Checkout') ?>
                        </a>
                    </li>
                </ul>
            <?php endif ?>
            <a class="cart-link" href="<?= $this->getUrl('checkout/cart') ?>">
                <?= $this->__('View Shopping Cart') ?>
            </a>
        </div>

    <?php else: ?>
        <p class="empty"><?= $this->__('You have no items in your shopping cart.') ?></p>
    <?php endif ?>
</div>
