<?php
/*
 * @category: Magepow
 * @copyright: Copyright (c) 2014 Magepow (http://www.magepow.com/)
 * @licence: http://www.magepow.com/license-agreement
 * @author: MichaelHa
 * @create date: 2019-06-14 17:19:50
 * @LastEditors: MichaelHa
 * @LastEditTime: 2019-06-29 12:48:03
 */
?>
<?php
$freeShipping_status = $block->getFreeShippingStatus();
$currencySymbols = $block->getStoreCurrency();
$currencyCode = $block->getCurrentCurrencyCode();
$freeShipping = $block->getFreeShippingValue();
$helper = $block->getAjaxHelper();
$imageHelper = $block->getImageHelper();
$resultItem = $block->getItem();
$product = $resultItem->getProduct();
$resultPrice = $helper->getProductTaxDisplayType() == \Magento\Tax\Model\Config::DISPLAY_TYPE_EXCLUDING_TAX ?
$resultItem->getPrice() : $resultItem->getPriceInclTax();
$cart = $block->getCartHelper()->getCart();
$showContinue = $helper->isShowContinueBtn();
$showCartInfo = $helper->isShowCartInfo();
$showCheckoutLink = $helper->isShowCheckoutLink();
$freeShipping_message = $helper->getFreeShippingMessageText();
$congratulation_message = $helper->getCongratulationMessageText();
$countDown = ($helper->getCountDownTime() > 0) ? $helper->getCountDownTime() : 0;
?>
<div class="popup">
    <div class="block">
        <div class="header">
            <strong><?php echo $block->escapeHtml(__('Shopping Cart')); ?></strong>
        </div>
        <p class="message">
            <?php echo $block->escapeHtml(__('You added ')); ?>
            <a href="<?php echo $block->escapeUrl($product->getProductUrl()); ?>"
                title="<?php echo $block->escapeHtml($resultItem->getName()); ?>">
                <?php echo $block->escapeHtml($resultItem->getName());?>
            </a>
            <?php echo $block->getRelatedAdded() ? $block->escapeHtml(__(' and related products')) : ''; ?>
            <?php echo $block->escapeHtml(__(' to your shopping cart.')); ?>
        </p>

        <?php if ($helper->isShowProductImage()) :?>
            <div class="product-image">
                <img src="<?php echo $block->escapeUrl(
                $imageHelper->init(
                $product,
                'category_page_list',
                ['height' => $helper->getImageSize() , 'width'=> $helper->getImageSize()]
                )->getUrl()
                ); ?>">
                <?php if ($helper->isShowProductPrice() && $product->getTypeId() != \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE) :?>
                <div>
                    <span>
                        <?php
                        echo $block->escapeHtml(
                            $block->getPricingHelper()->currency(
                                $resultPrice,
                                true,
                                false
                            )
                        );
                        ?>
                    </span>
                </div>
            <?php endif; ?>
        </div>
    <?php endif; ?>

    <?php if ($showCartInfo || $showCheckoutLink) :?>
        <div class="cart-info">
            <?php if ($showCartInfo) : ?>
                <div class="items-count">
                    <span>
                        <?php
                        if ($cart->getItemsQty() > 1) {
                            echo $block->escapeHtml(__('There are '));
                        } else {
                            echo $block->escapeHtml(__('There is '));
                        }
                        ?>
                        <a href="<?php echo $block->escapeUrl($block->getUrl('checkout/cart')); ?>">
                            <?php
                            echo $block->escapeHtml($cart->getItemsQty());
                            if ($cart->getItemsQty() > 1) {
                                echo $block->escapeHtml(__(' items'));
                            } else {
                                echo $block->escapeHtml(__(' item'));
                            }
                            ?>
                        </a>
                        <?php echo $block->escapeHtml(__(' in your cart.')); ?>
                    </span>
                </div>
                <div class="subtotal">
                    <span>
                        <?php
                        $quote = $block->getCartHelper()->getQuote();
                        echo $block->escapeHtml(__('Cart Subtotal: '));
                        if(isset($currencySymbols))
                        {
                            echo $block->escapeHtml(__($currencySymbols));
                        }else{
                            echo $block->escapeHtml(__($currencyCode));
                        }
                        echo $block->escapeHtml(__($quote->getSubtotal()));
                        ?>
                    </span>
                </div>
            <?php endif; ?>
            <?php
            if($freeShipping_status == 1)
            {
                $quote = $block->getCartHelper()->getQuote();
                $total = $quote->getSubtotal();
                $freeShipping = $block->getPricingHelper()->currency(
                    $freeShipping,
                    false,
                    false
                );
                $needMore = $freeShipping - $total;
                if($total < $freeShipping) {
                    ?>
                    <div class="freeShipping_message">
                        <?php
                        ?>
                        <div class="needMore">
                            <?php
                            if(isset($currencySymbols))
                            {
                                echo $block->escapeHtml(__('Spend '.$currencySymbols));
                            }else{
                                echo $block->escapeHtml(__('Spend '.$currencyCode));
                            }
                            echo $block->escapeHtml(__($needMore.' more to get free shipping!'));
                            echo '<br>';
                            ?>
                        </div>
                        <?php
                        echo $block->escapeHtml(__($freeShipping_message));
                        ?>
                    </div>
                    <?php
                }else{
                    ?>
                    <div class="congratulation">
                        <?php
                        echo $block->escapeHtml(__($congratulation_message));
                        ?>
                    </div>
                    <?php
                }
            }
            ?>
            <?php if ($showCheckoutLink) : ?>
                <div class="checkout-link">
                    <a href="<?php echo $block->escapeUrl($block->getUrl('checkout')); ?>">
                        <span><?php echo $block->escapeHtml(__('Go to checkout')); ?></span>
                    </a>
                </div>
            <?php endif; ?>
        </div>
    <?php endif; ?>
</div>

<?php echo $block->getChildHtml('ajaxcart.popup.suggest'); ?>

<div class="action clearfix">
    <div class="btn-viewcart <?php echo (!$showContinue) ? 'full-width' : ''; ?>">
        <a
        href="<?php echo $block->escapeUrl($block->getUrl('checkout/cart')); ?>"
        title="<?php echo $block->escapeHtml(__($helper->getBtnViewcartText())); ?>"
        class="view-cart"
        >
        <button class="viewcart"
        type="button"
        title="<?php echo $block->escapeHtml(__($helper->getBtnViewcartText())); ?>">
        <span><?php echo $block->escapeHtml(__($helper->getBtnViewcartText())); ?></span>
        <?php if ($helper->getCountDownActive() == \Magepow\Ajaxcart\Model\Config\Source\Countdown::POPUP_COUNTDOWN_VIEW_CART_BTN
        && $helper->getCountDownTime() > 0) :?>
        <span class="<?php echo ($helper->getCountDownActive() == \Magepow\Ajaxcart\Model\Config\Source\Countdown::POPUP_COUNTDOWN_VIEW_CART_BTN) ? 'countdown' : ''; ?>">
            (<?php echo $block->escapeHtml($helper->getCountDownTime()); ?>)
        </span>
    <?php endif; ?>
</button>
</a>
</div>

<?php if ($showContinue) : ?>
    <div class="btn-continue">
        <button
        class="continue"
        type="button"
        title="<?php echo $block->escapeHtml(__($helper->getBtnContinueText())); ?>"
        >
        <span><?php echo $block->escapeHtml(__($helper->getBtnContinueText())); ?></span>
        <?php if ($helper->getCountDownActive() == \Magepow\Ajaxcart\Model\Config\Source\Countdown::POPUP_COUNTDOWN_CONTINUE_BTN
        && $helper->getCountDownTime() > 0) :?>
        <span class="<?php echo ($helper->getCountDownActive() == \Magepow\Ajaxcart\Model\Config\Source\Countdown::POPUP_COUNTDOWN_CONTINUE_BTN) ? 'countdown' : ''; ?>">
            (<?php echo $block->escapeHtml($helper->getCountDownTime()); ?>)
        </span>
    <?php endif; ?>
</button>
</div>
<?php endif; ?>
</div>
</div>

<script type="text/x-magento-init">
    {
        "#magepow_ajaxcart_popup": {
        "magepowPopup": {
        "countDown": <?php echo $block->escapeJsQuote($countDown); ?>
    }
}
}
</script>
