{"version":3,"sources":["components/product/detail/actions/@common/product-detail-actions.js"],"names":["ProductDetailActionsBase","Component","constructor","el","variantInput","$find","buttonBuy","buttonInquiry","buttonCannotBuy","amountInput","form","cartUrl","$el","dataset","urlCart","inquiryUrl","urlInquiry","addEventListeners","setVariant","variant","value","id","resetButtons","classList","add","updateForm","salable","remove","setAttribute","EventBus","getInstance","dispatchEvent","button","inquirable","onVariantChange","addToCart","formData","FormData","append","fetch","getAttribute","method","body","then","response","json","data","error","alert","onCartAdded","catch","console","finally","remarketingCodes","Util","appendToBody","showInquiry","url","URLSearchParams","toString","onFormSubmit","e","preventDefault","doTheAction","action","addEventListener","detail"],"mappings":"aAAA,KAAMA,CAAAA,wBAAN,QAAuCC,CAAAA,SAAU,CAChDC,WAAW,CAACC,EAAD,CAAK,CACf,MAAMA,EAAN,EACA,KAAKC,YAAL,CAAoB,KAAKC,KAAL,CAAW,sBAAX,CAApB,CACA,KAAKC,SAAL,CAAiB,KAAKD,KAAL,CAAW,mBAAX,CAAjB,CACA,KAAKE,aAAL,CAAqB,KAAKF,KAAL,CAAW,uBAAX,CAArB,CACA,KAAKG,eAAL,CAAuB,KAAKH,KAAL,CAAW,0BAAX,CAAvB,CACA,KAAKI,WAAL,CAAmB,KAAKJ,KAAL,CAAW,2BAAX,CAAnB,CACA,KAAKK,IAAL,CAAY,KAAKL,KAAL,CAAW,MAAX,CAAZ,CAEA,KAAKM,OAAL,CAAe,KAAKC,GAAL,CAASC,OAAT,CAAiBC,OAAhC,CACA,KAAKC,UAAL,CAAkB,KAAKH,GAAL,CAASC,OAAT,CAAiBG,UAAnC,CAEA,KAAKC,iBAAL,EACA,CAEDC,UAAU,CAACC,OAAD,CAAU,CACnB,KAAKf,YAAL,CAAkBgB,KAAlB,CAA0BD,OAAO,CAACE,EAClC,CAEDC,YAAY,EAAG,CACd,KAAKhB,SAAL,CAAeiB,SAAf,CAAyBC,GAAzB,CAA6B,UAA7B,EACA,KAAKjB,aAAL,CAAmBgB,SAAnB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AvB,CAAqC,aAArC,CAAoD,CACnD0B,GAAG,CAAE,KAAK1C,UAAL,CAAkB,GAAlB,CAAwB,GAAI2C,CAAAA,eAAJ,CAAoB,GAAIrB,CAAAA,QAAJ,CAAa,KAAK3B,IAAlB,CAApB,EAA6CiD,QAA7C,EAAxB,CAAkF,SADpC,CAApD,CAGA,CAEDC,YAAY,CAACC,CAAD,CAAI,CACfA,CAAC,CAACC,cAAF,GACA,KAAKC,WAAL,EACA,CAKDA,WAAW,EAAG,CACb,KAAMC,CAAAA,MAAM,CAAG,KAAKtD,IAAL,CAAU8B,YAAV,CAAuB,QAAvB,CAAf,CAEAX,QAAQ,CAACC,WAAT,GAAuBC,aAAvB,CAAqC,mBAArC,EAEA,GAAGiC,MAAM,GAAK,KAAKrD,OAAnB,CAA4B,CAC3B,KAAKwB,SAAL,EACA,CAFD,IAEO,IAAI6B,MAAM,GAAK,KAAKjD,UAApB,CAAgC,CACtC,KAAKyC,WAAL,EACA,CACD,CAEDvC,iBAAiB,EAAG,CACnBY,QAAQ,CAACC,WAAT,GAAuBmC,gBAAvB,CAAwC,uBAAxC,CAAiEJ,CAAC,EAAI,KAAK3B,eAAL,CAAqB2B,CAAC,CAACK,MAAvB,CAAtE,EACA,KAAKxD,IAAL,CAAUuD,gBAAV,CAA2B,QAA3B,CAAqCJ,CAAC,EAAI,KAAKD,YAAL,CAAkBC,CAAlB,CAA1C,EACAhC,QAAQ,CAACC,WAAT,GAAuBmC,gBAAvB,CAAwC,2BAAxC,CAAqEJ,CAAC,EAAI,KAAKE,WAAL,EAA1E,CACA,CAnH+C","sourcesContent":["class ProductDetailActionsBase extends Component {\r\n\tconstructor(el) {\r\n\t\tsuper(el);\r\n\t\tthis.variantInput = this.$find('[data-variant-input]');\r\n\t\tthis.buttonBuy = this.$find('[data-button-buy]');\r\n\t\tthis.buttonInquiry = this.$find('[data-button-inquiry]');\r\n\t\tthis.buttonCannotBuy = this.$find('[data-button-cannot-buy]');\r\n\t\tthis.amountInput = this.$find('[data-input-up-down-base]');\r\n\t\tthis.form = this.$find('form');\r\n\r\n\t\tthis.cartUrl = this.$el.dataset.urlCart;\r\n\t\tthis.inquiryUrl = this.$el.dataset.urlInquiry;\r\n\r\n\t\tthis.addEventListeners();\r\n\t}\r\n\r\n\tsetVariant(variant) {\r\n\t\tthis.variantInput.value = variant.id;\r\n\t}\r\n\r\n\tresetButtons() {\r\n\t\tthis.buttonBuy.classList.add('u-hidden');\r\n\t\tthis.buttonInquiry.classList.add('u-hidden');\r\n\t\tthis.buttonCannotBuy.classList.add('u-hidden');\r\n\t\tthis.amountInput && this.amountInput.classList.add('u-hidden');\r\n\t}\r\n\r\n\tupdateForm(variant) {\r\n\t\tthis.resetButtons();\r\n\r\n\t\tif (variant.salable) {\r\n\t\t\tthis.buttonBuy.classList.remove('u-hidden');\r\n\t\t\tthis.amountInput && this.amountInput.classList.remove('u-hidden');\r\n\t\t\tthis.form.setAttribute('action', this.cartUrl);\r\n\t\t\tthis.form.setAttribute('method', 'get');\r\n\t\t\tEventBus.getInstance().dispatchEvent('productDetailActionButtonChanged', {button:this.buttonBuy});\r\n\t\t} else if (variant.inquirable) {\r\n\t\t\tthis.buttonInquiry.classList.remove('u-hidden');\r\n\t\t\tthis.form.setAttribute('action', this.inquiryUrl);\r\n\t\t\tthis.form.setAttribute('method', 'post');\r\n\t\t\tEventBus.getInstance().dispatchEvent('productDetailActionButtonChanged', {button:this.buttonInquiry});\r\n\t\t} else {\r\n\t\t\tthis.buttonCannotBuy.classList.remove('u-hidden');\r\n\t\t\tthis.form.setAttribute('action', '');\r\n\t\t\tthis.form.setAttribute('method', '');\r\n\t\t\tEventBus.getInstance().dispatchEvent('productDetailActionButtonChanged', {button:this.buttonCannotBuy});\r\n\t\t}\r\n\t}\r\n\r\n\tonVariantChange(variant) {\r\n\t\tthis.setVariant(variant);\r\n\t\tthis.updateForm(variant);\r\n\t}\r\n\r\n\taddToCart() {\r\n\t\tconst formData = new FormData(this.form);\r\n\t\tformData.append('ajax', '1');\r\n\r\n\t\tfetch(this.form.getAttribute('action'), {\r\n\t\t\tmethod: 'POST',\r\n\t\t\tbody: formData,\r\n\t\t})\r\n\t\t\t.then(response => response.json())\r\n\t\t\t.then(data => {\r\n\t\t\t\tif ('error' in data && data.error) {\r\n\t\t\t\t\talert(data.error);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis.onCartAdded(data)\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t\t.catch((error) => {\r\n\t\t\t\tconsole.error('Error:', error);\r\n\t\t\t})\r\n\t\t\t.finally(() => {\r\n\t\t\t\tEventBus.getInstance().dispatchEvent('hideGlobalSpinner');\r\n\t\t\t});\r\n\t}\r\n\r\n\tonCartAdded(data) {\r\n\t\tEventBus.getInstance().dispatchEvent('cartUpdated', data);\r\n\t\tif (data.remarketingCodes) {\r\n\t\t\tUtil.appendToBody(data.remarketingCodes);\r\n\t\t}\r\n\t}\r\n\r\n\tshowInquiry() {\r\n\t\tEventBus.getInstance().dispatchEvent('showInquiry', {\r\n\t\t\turl: this.inquiryUrl + '?' + new URLSearchParams(new FormData(this.form)).toString() + '&ajax=1'\r\n\t\t});\r\n\t}\r\n\r\n\tonFormSubmit(e) {\r\n\t\te.preventDefault();\r\n\t\tthis.doTheAction();\r\n\t}\r\n\r\n\t/**\r\n\t * Provede akci, ktera je aktualne dostupna na zvolene variante (koupit, poptat, ...)\r\n\t */\r\n\tdoTheAction() {\r\n\t\tconst action = this.form.getAttribute('action');\r\n\r\n\t\tEventBus.getInstance().dispatchEvent('showGlobalSpinner');\r\n\r\n\t\tif(action === this.cartUrl) {\r\n\t\t\tthis.addToCart();\r\n\t\t} else if (action === this.inquiryUrl) {\r\n\t\t\tthis.showInquiry();\r\n\t\t}\r\n\t}\r\n\r\n\taddEventListeners() {\r\n\t\tEventBus.getInstance().addEventListener('productVariantChanged', e => this.onVariantChange(e.detail));\r\n\t\tthis.form.addEventListener('submit', e => this.onFormSubmit(e));\r\n\t\tEventBus.getInstance().addEventListener('productDetailActionSubmit', e => this.doTheAction());\r\n\t}\r\n}\r\n"],"file":"product-detail-actions.min.js"}