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

// @codingStandardsIgnoreFile

/**
 * Product view template
 *
 * @var $block \Magento\Catalog\Block\Product\View
 */
?>
<?php $_helper = $this->helper('Magento\Catalog\Helper\Output'); ?>
<?php $_product = $block->getProduct(); ?>

<form action="<?php /* @escapeNotVerified */ echo $block->getSubmitUrl($_product) ?>" method="post"
	  id="product_addtocart_form"<?php if ($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>  class="product_addtocart_forms">
	<input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $_product->getId() ?>" />
	<input type="hidden" name="selected_configurable_option" value="" />
	<input type="hidden" name="related_product" id="related-products-field" value="" />
	<?php echo $block->getBlockHtml('formkey')?>
	<div class="product-add-form">
		
		<?php echo $block->getChildHtml('form_top'); ?>
		<?php if (!$block->hasOptions()):?>
			<?php echo $block->getChildHtml('product_info_form_content'); ?>
		<?php else:?>
			<?php if ($_product->isSaleable() && $block->getOptionsContainer() == 'container1'):?>
				<?php echo $block->getChildChildHtml('options_container') ?>
				<?php echo $block->getChildChildHtml('block_products') ?>
			<?php endif;?>
		<?php endif; ?>

		<?php if ($_product->isSaleable() && $block->hasOptions() && $block->getOptionsContainer() == 'container2'):?>
			<?php echo $block->getChildChildHtml('options_container') ?>
		<?php endif;?>
		<?php echo $block->getChildHtml('form_bottom'); ?>
	</div>		
	
	<?php echo $block->getChildChildHtml('block_products') ?>		
	
</form>

<script>
    require([
        'jquery',
        'ajaxPriceBox'
    ], function($){
		
		       // var priceBoxes = $('[data-role=priceBox]');
		$('#popup_content').trigger('contentUpdated');		
		var priceBoxes =$("#popup_content div[data-product-id=<?php echo $_product->getId() ?>]");		
        priceBoxes = priceBoxes.filter(function(index, elem){
            return !$(elem).find('.price-from').length;
        });
        priceBoxes.ajaxPriceBox({'priceConfig': <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>});
<?php //MNM ?>
        $('.table-wrapper.grouped #super-product-table').each(function() {
            $formQtyInput = $(this).closest('form').find('input[name="qty"]');
            $products = $(this).find('.item');

            $products.eq(0).addClass('selected');

            $products.each(function() {
    			var $el = $(this);

    		    $el.mouseenter(function() {$el.addClass('highlight')});
    			$el.mouseleave(function() {$el.removeClass('highlight')});
    
				$el.click(function() {
					$products.removeClass('selected').find('input').val(0);

					$el.addClass('selected').find('input').val( $formQtyInput.val());
				});
            });

            $products.eq(0).click();
            $formQtyInput.change(function() {
            	$products.filter('.selected').find('input').val($(this).val());
            });
        });		  
<?php //MNM ?>	
    });
</script>
