<?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:47:17
 */

$helper = $block->getAjaxHelper();
$addUrl = $block->getUrl('ajaxcart');
$quickview = 'false';
$isProductView = 'false';

if ($block->getRequest()->getModuleName() == 'ajaxcart') {
    $quickview = 'true';
    $isProductView = 'true';
}

if ($block->getRequest()->getFullActionName() == 'catalog_product_view') {
    $isProductView = 'true';
}

$isEnable = $helper->isEnabled();

if ($isProductView == 'true' && !$helper->isEnabledProductView()) {
    $isEnable = false;
}

if ($block->getRequest()->getFullActionName() == 'checkout_cart_index'
    || $block->getRequest()->getFullActionName() == 'wishlist_index_index'
    || $block->getRequest()->getFullActionName() == 'customer_account_index'
    || $block->getRequest()->getFullActionName() == 'catalog_product_compare_index'
    || $block->getRequest()->getFullActionName() == 'checkout_cart_configure') {
    $isEnable = false;
}

if (!$isEnable) return;

$btnTextColor = $helper->getBtnTextColor();

$btnContinueBackground = $helper->getBtnContinueBackground();

$btnContinueHover = $helper->getBtnContinueHover();
$btnViewcartBackground = $helper->getBtnViewcartBackground();
$btnViewcartHover = $helper->getBtnViewcartHover();
$countDown = ($helper->getCountDownTime() > 0 && $helper->getCountDownActive()) ? $helper->getCountDownTime() : 0;
$quickViewUrl = $helper->isModuleEnabled('Magiccart_Alothemes') ? $block->getUrl('alothemes/product/view/') : $block->getUrl('ajaxcart/index/view/');
$showLoader = $helper->getConfigModule('general/showLoader');
?>

<div id="magepow_ajaxcart_popup"></div>
<style type="text/css">
    .ajaxcart-wrapper-main .btn-continue .continue {
        background: <?php echo $block->escapeHtml($btnContinueBackground); ?>;
        color: <?php echo $block->escapeHtml($btnTextColor); ?>;
    }

    .ajaxcart-wrapper-main .btn-continue .continue:hover {
        background: <?php echo $block->escapeHtml($btnContinueHover); ?>;
    }

    .ajaxcart-wrapper-main .btn-viewcart .viewcart {
        background: <?php echo $block->escapeHtml($btnViewcartBackground); ?>;
        color: <?php echo $block->escapeHtml($btnTextColor); ?>;
    }

    .ajaxcart-wrapper-main .btn-viewcart .viewcart:hover {
        background: <?php echo $block->escapeHtml($btnViewcartHover); ?>;
    }
</style>

<script type="text/x-magento-init">
    {
        "body": {
            "magepowAjaxcart": {
                "countDown": "<?php echo $countDown; ?>",
                "showLoader": "<?php echo (bool) $showLoader; ?>",
                "addUrl": "<?php echo $block->escapeUrl($addUrl); ?>",
                "quickview": <?php echo $block->escapeJsQuote($quickview); ?>,
                "quickViewUrl": "<?php echo $block->escapeUrl($quickViewUrl); ?>",
                "isProductView": <?php echo $block->escapeJsQuote($isProductView); ?>,
                "addToCartSelector": "<?php echo $block->escapeJsQuote($helper->getAddToCartSelector()); ?>"
            }
        }
    }
</script>