define(['ko','uiElement','jquery','mage/translate','mage/mage','Magento_Catalog/js/price-utils','catalogAddToCart','domReady!'],function(ko,Element,$,$t,mage,priceUtils,catalogAddToCart){return Element.extend({defaults:{template:'Magento_Catalog/input-counter',submitForm:$('#product_addtocart_form'),productId:'',cartButton:'',priceText:''},initObservable:function(){this._super().observe('qty');this.productId=this.submitForm.find('input[name="product"]').val() this.cartButton=this.submitForm.find('#product-addtocart-button');this.priceText=$('.product-info-price #product-price-'+this.productId);var element=this;setTimeout(function(){element.updateButtonText(element.qty());element.virtualProduct();},1000);return this;},getDataValidator:function(){return JSON.stringify(this.dataValidate);},decreaseQty:function(){var qty;if(this.qty()>1){qty=this.qty()-1;}else{qty=1;} this.qty(qty);this.updateButtonText(qty);},increaseQty:function(){var qty=this.qty()+1;this.qty(qty);this.updateButtonText(qty);},updateButtonText:function(qty){var title='Add to Cart';var price=this.priceText.data('price-amount');var finalPrice=qty*price;var finalPriceFormat=this.getFormattedPrice(finalPrice);var finalPriceText=finalPriceFormat+' | '+$t(title);this.cartButton.find('span').text(finalPriceText);this.cartButton.attr('title',finalPriceText);this.submitForm.catalogAddToCart({bindSubmit:false,addToCartButtonTextWhileAdding:finalPriceFormat+' | '+$t('adding..'),addToCartButtonTextDefault:finalPriceFormat+' | '+$t(title),addToCartButtonTextAdded:finalPriceFormat+' | '+$t('added'),});},virtualProduct:function(){var element=this;$('.amcard-label-block').on('click',function(){var price=$(this).find('input').val();element.priceText.data('price-amount',price);element.updateButtonText(element.qty());});},getFormattedPrice:function(price){var priceFormat={decimalSymbol:'.',groupLength:3,groupSymbol:",",integerRequired:false,pattern:this.currencyFormat,precision:2,requiredPrecision:2};return priceUtils.formatPrice(price,priceFormat);}});});