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

/** @var $block \Magento\Catalog\Block\Product\View */
$qty = 1;
?>
<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Update Cart'); ?>
<?php if ($_product->isSaleable()) :?>
    <div class="box-tocart update">
        <fieldset class="fieldset">
            <?php if ($block->shouldRenderQuantity()) :?>
            <div class="field qty up-down flex-layout no-wrap">
				<div class="control">
					<input type="number"
						   name="qty"
						   id="qty"
						   maxlength="12"
						   value="<?php /* @escapeNotVerified */ echo $qty * 1 ?>"
						   title="<?php /* @escapeNotVerified */ echo __('Quantity') ?>" class="input-text qty"
						   data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
						   />
				</div>
				<div class="click-up-down flex-layout no-wrap column">
					<a class="qty-up-fixed-onclick qty-up" href="#"><span class="icon-chevron-up"></span></a> 
					<a class="qty-down-fixed-onclick qty-down" href="#"><span class="icon-chevron-down"></span></a> 
				</div>
			</div>
            <?php endif; ?>
            <div class="actions">
                <button type="submit"
                        title="<?= $block->escapeHtmlAttr($buttonTitle) ?>"
                        class="action primary tocart"
                        id="product-updatecart-button">
                    <span><?= $block->escapeHtml($buttonTitle) ?></span>
                </button>
                <?= $block->getChildHtml('', true) ?>
            </div>
        </fieldset>
    </div>
    <script type="text/x-magento-init">
        {
            "#product_addtocart_form": {
                "validation": {},
                "addToCart": {
                    "cartButtonId": "#product-updatecart-button",
                    "cartForm": "#product_addtocart_form"
                }
            }
        }
    </script>
<?php endif; ?>
<script>
	require([
		'jquery'
	], function ($) {
		'use strict';
		var number_click = <?php echo $qty;?>;
		$(".qty-down-fixed-onclick").click(function() {
			var val_input = $(this).closest('div.field').find('#qty').val();
			val_input = parseInt(val_input);
			if(val_input <= number_click){
				val_input = number_click;
			}
			else{
				val_input = val_input - number_click;
			}
			$('div.field div.control #qty').val(val_input);
			return false;
		});
		$(".qty-up-fixed-onclick").click(function() {
			var val_input = $(this).closest('div.field').find('#qty').val();
			val_input = parseInt(val_input);
			val_input = val_input + number_click;
			$('div.field div.control #qty').val(val_input);
			return false;
		});
	});
</script>