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

// @codingStandardsIgnoreFile

/** @var $block \Magento\Catalog\Block\Product\View */
?>
<?php $_product = $block->getProduct(); ?>
<?php 
$block_popup=$block->getLayout()->createBlock('\Magebees\Ajaxaddtocart\Block\Popup');
$dialog_config=$block_popup->getDialogConfig();
if(isset($dialog_config['livetime'])){
	$livetime=$dialog_config['livetime'];
} else {
	$livetime= 4;
}
?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php if ($_product->isSaleable()): ?>
<div class="box-tocart">
    <div class="fieldset">
<?php //MNM ?>    
        <?php //if ($block->shouldRenderQuantity()): ?>
<?php //MNM ?>        
        <div class="field qty">
            <label class="label" for="qty"><span><?php /* @escapeNotVerified */ echo __('Qty') ?></span></label>
            <input type="number" name="qty" id="qty" maxlength="12" value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>"
                       title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty" data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>" />
        </div>
<?php //MNM ?>        
        <?php //endif; ?>
<?php //MNM ?>        
        <div class="actions">
            <button type="submit"
                    title="<?php /* @escapeNotVerified */ echo $buttonTitle ?>"
                    class="action primary ajaxproduct"
                    id="product-addtocart-button">
                <span><?php /* @escapeNotVerified */ echo $buttonTitle ?></span>
            </button>
            <?php echo $block->getChildHtml('', true) ?>
        </div>
    </div>
</div>
<?php endif; ?>
<?php if ($block->isRedirectToCartEnabled()) : ?>
<script type="text/x-magento-init">
    {
        ".product_addtocart_forms": {
            "Magento_Catalog/product/view/validation": {
                "radioCheckboxClosest": ".nested"
            }
        }
    }
</script>
<?php else : ?>
<script>
    require([
        'jquery',
        'mage/mage',
        'Magebees_Ajaxaddtocart/product/view/validation',
        'Magebees_Ajaxaddtocart/js/ajax-to-cart'
    ], function ($) {
        'use strict';

		var livetime=<?php echo $livetime ;?>;
        $('.product_addtocart_forms').mage('validation', {
			
            radioCheckboxClosest: '.nested',
            submitHandler: function (form) {
                var widget = $(form).ajaxToCart({
                    bindSubmit: false
                });
				document.getElementById('loadingImage').style['display']='block';
                widget.ajaxToCart('ajaxSubmitForm', $(form),livetime);

                return false;
            }
        });
		$('body').on('click','#shopcontinue',function(){
					var widget = $(this).ajaxToCart({});					 
					widget.ajaxToCart('shopContinue');
					});
    });
</script>
<?php endif; ?>
