{"version":3,"sources":["webpack:///./cartridges/app_harmony/cartridge/client/default/js/widgets/cart/HarmonyMiniCartDialog.js"],"names":["MinicartDialog","HarmonyMiniCartDialog","init","eventBus","on","hiddenRefreshMinicart","getJSONByUrl","prefs","actionUrl","then","response","render","undefined","ref","refDialog","minicartHtml","catch","emit","errorCode","closeMinicart","autoCloseTimeout","window","setTimeout","closeModal","bind","cancel","clearTimeout","confirmedRemoveProduct","button","movedToWishlist","removeProductLink","uuid","data","pid","promise","submitFormJson","needUpdate","basket","accessibilityAlert","accessibilityAlerts","movedtowishlist","productremoved","numItems","showMinicart","updateQty","inputSelect","toggleSpinner","quantity","getValue","displayItemLevelErrorMessage","message","hasError","quantitychanged","updateContent","finally","$","removeClass","redirectUrl","handleRedirectUrl","location","assign","showModal","attributes","addClass","classesActivated","addFocusTraps","close","moveProductToWishlist","link","productID","productName","actionMovetowishlist","openShipTo","shipToTarget","document","querySelector","dispatchEvent","Event"],"mappings":";;;;;;;;;;;;;;;AAAA;AAGA;;;;AAIA;;;;;;AAKe,yEAAUA,cAAV,EAA0B;AACrC,SAAO,MAAMC,qBAAN,SAAoCD,cAApC,CAAmD;AACtDE,QAAI,GAAG;AACH,YAAMA,IAAN;AACA,WAAKC,QAAL,GAAgBC,EAAhB,CAAmB,qBAAnB,EAA0C,eAA1C;AACA,WAAKD,QAAL,GAAgBC,EAAhB,CAAmB,oBAAnB,EAAyC,uBAAzC;AACH;AAED;;;;;;AAIAC,yBAAqB,GAAG;AACpBC,+EAAY,CAAC,KAAKC,KAAL,GAAaC,SAAd,CAAZ,CACKC,IADL,CACWC,QAAD,IAAc;AAChB,YAAI,CAACA,QAAL,EAAe;AACX;AACH;;AACD,aAAKC,MAAL,CACIC,SADJ,EAEI,EAFJ,EAGI,KAAKC,GAAL,CAAS,KAAKN,KAAL,GAAaO,SAAtB,CAHJ,EAIIJ,QAAQ,CAACK,YAJb;AAMH,OAXL,EAYKC,KAZL,CAYW,MAAM;AACT,aAAKb,QAAL,GAA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J;;AArOqD,GAA1D;AAuOH,C","file":"harmony.minicart.bundle.js","sourcesContent":["import { getJSONByUrl, submitFormJson } from 'widgets/toolbox/ajax';\n\n\n/**\n * @typedef {typeof import('widgets/cart/MinicartDialog').default} MinicartDialog\n */\n\n/**\n * @description Base HarmonyMiniCartDialog implementation\n * @param {ReturnType} MinicartDialog Base widget for extending\n * @returns {typeof HarmonyMiniCartDialog} HarmonyMiniCartDialog class\n */\nexport default function (MinicartDialog) {\n return class HarmonyMiniCartDialog extends MinicartDialog {\n init() {\n super.init();\n this.eventBus().on('auto.close.minicart', 'closeMinicart');\n this.eventBus().on('cart.items.refresh', 'hiddenRefreshMinicart');\n }\n\n /**\n * @description Hidden refresh the minicart page\n * @returns {void}\n */\n hiddenRefreshMinicart() {\n getJSONByUrl(this.prefs().actionUrl)\n .then((response) => {\n if (!response) {\n return;\n }\n this.render(\n undefined,\n {},\n this.ref(this.prefs().refDialog),\n response.minicartHtml\n );\n })\n .catch(() => {\n this.eventBus().emit('alert.show', { errorCode: 500 });\n });\n }\n\n closeMinicart(autoCloseTimeout) {\n this.autoCloseTimeout = window.setTimeout(\n this.closeModal.bind(this),\n autoCloseTimeout\n );\n }\n\n cancel() {\n window.clearTimeout(this.autoCloseTimeout);\n super.cancel();\n }\n\n confirmedRemoveProduct(button, movedToWishlist = false) {\n if (this.removeProductLink) {\n this.eventBus().emit('minicart.remove.product', this);\n\n const uuid = this.removeProductLink.data('uuid');\n const pid = this.removeProductLink.data('pid');\n const promise = submitFormJson(\n this.removeProductLink.data('removeAction') || this.removeProductLink.data('action'),\n {\n pid: pid,\n uuid: uuid\n },\n 'POST'\n ).then((response) => {\n if (!response) {\n return;\n }\n\n this.needUpdate = true;\n this.eventBus().emit('minicart.updated', response.basket);\n this.eventBus().emit('minicart.removed.product', pid);\n this.accessibilityAlert(\n movedToWishlist\n ? this.prefs().accessibilityAlerts.movedtowishlist\n : this.prefs().accessibilityAlerts.productremoved\n );\n if (response.basket.numItems) {\n // this function renders updated minicart,\n // for example when we change product quantity.\n // But when we don't have products in minicart, this function renders modal window with text: 'Empty shopping cart',\n // but accordint to FSD we don't need this window, we need just close mini cart, when last product was deleted\n this.showMinicart();\n } else {\n this.cancel();\n }\n });\n\n this.eventBus().emit('loader.start', promise);\n\n this.removeProductLink = null;\n }\n }\n\n /**\n * @description Updates quantity for concrete product in minicart widget\n * @param {inputSelect} inputSelect - Target select input in minicart widget, which triggers quantity update\n * @emits \"minicart.updated\"\n * @returns {void}\n */\n updateQty(inputSelect) {\n this.toggleSpinner(true);\n\n const uuid = inputSelect.data('uuid');\n const promise = submitFormJson(inputSelect.data('action'), {\n pid: inputSelect.data('pid'),\n uuid: uuid,\n quantity: inputSelect.getValue()\n }, 'GET')\n .catch(response => {\n this.displayItemLevelErrorMessage(uuid, (response && response.message));\n })\n .then((response) => {\n if (!response) {\n return;\n }\n\n this.needUpdate = true;\n /**\n * @description Event to notify concerned widgets, that Minicart was updated\n * @event \"minicart.updated\"\n */\n this.eventBus().emit('minicart.updated', response);\n\n if (!inputSelect.hasError) {\n this.accessibilityAlert(`${this.prefs().accessibilityAlerts.quantitychanged} ${inputSelect.getValue()}`);\n }\n\n this.updateContent();\n })\n .finally(() => {\n this.toggleSpinner(false);\n });\n\n this.eventBus().emit('loader.start', promise);\n }\n\n /**\n * @description Update minicart panel content\n * Fetch actual content in case when it needed. Use flag `needUpdate` for this\n * @returns {void}\n */\n updateContent() {\n if (!this.needUpdate) {\n return;\n }\n\n $('.b-loader').removeClass('h-hidden');\n\n getJSONByUrl(this.prefs().actionUrl)\n .then((response) => {\n if (response\n && response.redirectUrl\n && this.handleRedirectUrl\n ) {\n window.location.assign(response.redirectUrl);\n return;\n }\n\n this.handleRedirectUrl = false;\n this.needUpdate = false;\n\n this.render(\n undefined,\n {},\n this.ref(this.prefs().refDialog),\n response.minicartHtml\n ).then(() => {\n // Open modal after new template rendering\n this.showModal({\n attributes: {\n 'data-tau-unique': 'minicart_dialog'\n }\n });\n this.ref(this.prefs().refDialog).addClass(this.prefs().classesActivated);\n $('.b-loader').addClass('h-hidden');\n this.addFocusTraps(); // enclose new content with focus trap\n });\n })\n .catch(() => {\n this.eventBus().emit('alert.show', { errorCode: 500 });\n $('.b-loader').addClass('h-hidden');\n this.close();\n });\n }\n\n /**\n * @description A method, called when event `click` happens on minicart icon\n * - Check cart total if empty redirect to cart page\n * - Shows minicart panel\n * - Update content of the panel\n * @returns {void}\n */\n showMinicart() {\n // If we make a request to update cart, then we need to open modal after receiving information\n if (this.needUpdate) {\n // We have to check response for the presence of redirectUrl,\n // to catch expired basket and redirect user to the empty cart page\n this.handleRedirectUrl = true;\n this.updateContent();\n\n return;\n }\n\n // Otherwise we open modal with the template we rendered earlier\n this.showModal({\n attributes: {\n 'data-tau-unique': 'minicart_dialog'\n }\n });\n this.ref(this.prefs().refDialog).addClass(this.prefs().classesActivated);\n }\n\n /**\n * @description Move product from minicart to wishlist.\n * In fact this functionality implemented in 2 steps:\n * 1. Add product to wishlist\n * 2. Remove product from minicart\n * This is done due to possible backend code duplication in one universal endpoint\n * @returns {void}\n */\n moveProductToWishlist() {\n if (this.removeProductLink) {\n const link = this.removeProductLink;\n const productID = link?.data('master-pid') || link?.data('pid');\n const productName = link?.data('name');\n submitFormJson(this.prefs().actionMovetowishlist, {\n pid: productID\n }).then(() => {\n this.confirmedRemoveProduct(null, true);\n this.eventBus().emit('product.added.to.wishlist', productName);\n });\n }\n }\n openShipTo() {\n const shipToTarget = document.querySelector('.b-ship_to');\n if (shipToTarget) {\n shipToTarget.dispatchEvent(new Event('click'));\n }\n }\n };\n}\n"],"sourceRoot":""}