{"version":3,"file":"product.js","sources":["../../../../../Flow.Showcase.Static.Bundler/Pharmacy/entrypoints/product.ts"],"sourcesContent":["import {\n getQuantityAttributes,\n stopCartRequests,\n resetCartRequests,\n} from \"@root/modules/cart.module\";\nimport eventBus from \"@root/modules/event-bus.module\";\n\ntry {\n const actionsBlocks = document.querySelectorAll(\"[data-product-actions]\")\n\n actionsBlocks.forEach(actionsBlock => {\n const btnBuyNow = actionsBlock.querySelector(\"[data-buy-now-btn]\");\n const quantityInput = actionsBlock.querySelector(\"[data-quantity-input]\");\n\n // Если в корзине нет данного товара, то добавить 1\n // Перейти на страницу корзины\n btnBuyNow?.addEventListener(\"click\", async () => {\n btnBuyNow.disabled = true;\n await stopCartRequests();\n const quantity = parseInt(quantityInput?.dataset.quantity ?? \"\") || 0;\n if (quantity === 0) {\n await resetCartRequests();\n const { setQuantity } = getQuantityAttributes(btnBuyNow);\n setQuantity(1);\n await stopCartRequests();\n }\n location.href = \"/cart\";\n });\n })\n\n // @ts-ignore\n eventBus.subscribe('cart-changed', ({ variantId, quantity }) => {\n actionsBlocks.forEach((actionBlock) => {\n const addToCartButton = actionBlock.querySelector(`[data-add-to-cart-btn][data-variant-id=\"${variantId}\"]`);\n const buyNowButton = actionBlock.querySelector(`[data-buy-now-btn][data-variant-id=\"${variantId}\"]`);\n const goToCartButton = actionBlock.querySelector(`[data-go-to-cart][data-variant-id=\"${variantId}\"]`);\n const counter = actionBlock.querySelector(`[data-counter][data-variant-id=\"${variantId}\"]`);\n\n if (quantity > 0) {\n addToCartButton?.classList.add('display-none');\n buyNowButton?.classList.add('display-none');\n counter?.classList.remove('display-none');\n goToCartButton?.classList.remove('display-none');\n } else {\n addToCartButton?.classList.remove('display-none');\n buyNowButton?.classList.remove('display-none');\n counter?.classList.add('display-none');\n goToCartButton?.classList.add('display-none');\n }\n })\n})\n} catch (error) {\n console.error(error);\n}\n\n"],"names":["actionsBlocks","actionsBlock","btnBuyNow","quantityInput","stopCartRequests","resetCartRequests","setQuantity","getQuantityAttributes","eventBus","variantId","quantity","actionBlock","addToCartButton","buyNowButton","goToCartButton","counter","error"],"mappings":"iLAOA,GAAI,CACM,MAAAA,EAAgB,SAAS,iBAAiB,wBAAwB,EAExEA,EAAc,QAAwBC,GAAA,CAC5B,MAAAC,EAAsCD,EAAa,cAAc,oBAAoB,EACrFE,EAAyCF,EAAa,cAAc,uBAAuB,EAItFC,GAAA,MAAAA,EAAA,iBAAiB,QAAS,SAAY,CAI7C,GAHAA,EAAU,SAAW,GACrB,MAAME,EAAiB,GACN,UAASD,GAAA,YAAAA,EAAe,QAAQ,WAAY,EAAE,GAAK,KACnD,EAAG,CAChB,MAAME,EAAkB,EACxB,KAAM,CAAE,YAAAC,CAAA,EAAgBC,EAAsBL,CAAS,EACvDI,EAAY,CAAC,EACb,MAAMF,EAAiB,CAAA,CAE3B,SAAS,KAAO,OAAA,EACnB,CACJ,EAGDI,EAAS,UAAU,eAAgB,CAAC,CAAE,UAAAC,EAAW,SAAAC,KAAe,CAC9CV,EAAA,QAASW,GAAgB,CACnC,MAAMC,EAAkBD,EAAY,cAAc,2CAA2CF,CAAS,IAAI,EACpGI,EAAeF,EAAY,cAAc,uCAAuCF,CAAS,IAAI,EAC7FK,EAAiBH,EAAY,cAAc,sCAAsCF,CAAS,IAAI,EAC9FM,EAAUJ,EAAY,cAAc,mCAAmCF,CAAS,IAAI,EAEtFC,EAAW,GACME,GAAA,MAAAA,EAAA,UAAU,IAAI,gBACjBC,GAAA,MAAAA,EAAA,UAAU,IAAI,gBACnBE,GAAA,MAAAA,EAAA,UAAU,OAAO,gBACVD,GAAA,MAAAA,EAAA,UAAU,OAAO,kBAEhBF,GAAA,MAAAA,EAAA,UAAU,OAAO,gBACpBC,GAAA,MAAAA,EAAA,UAAU,OAAO,gBACtBE,GAAA,MAAAA,EAAA,UAAU,IAAI,gBACPD,GAAA,MAAAA,EAAA,UAAU,IAAI,gBAClC,CACH,CAAA,CACR,CACD,OAASE,EAAO,CACZ,QAAQ,MAAMA,CAAK,CACvB"}