!function(){"use strict";const t=(()=>{try{const t="kaching_local_storage_test";return localStorage.setItem(t,t),localStorage.removeItem(t),!0}catch(t){return!1}})()?window.localStorage:window.sessionStorage,e=()=>new URLSearchParams(window.location.search).get("kaching");let n;let i;const r=()=>(void 0===i&&(i="debug"===e()),i);let o;const a=async(e,n,i,r,o)=>{try{const a="kaching_visited_deal_blocks",s=t.getItem(a),c=s?JSON.parse(s):[];if(c.includes(n))return;c.push(n),t.setItem(a,JSON.stringify(c));const u=`${"https://bundles-stats.kachingappz.app"}/impressions`;await fetch(u,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({shopDomain:e,dealBlockId:n,productId:i,abTestVariantId:r,sessionId:o})})}catch(a){console.error(a)}},s=async(t,e={},n=1)=>{if(Math.random()>n)return;l("sendStorefrontEvent",{name:t,data:e});const i=window.location.href;return await fetch("https://storefront-events.kachingappz.app/bundles/events",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:{name:t,data:e,url:i,shop:window.Shopify.shop}})})},c=async(t,e,n,i=.1)=>{if(Math.random()>i)return;if("Failed to fetch"===e)return;if(e&&(e.includes("Cannot define multiple custom elements with the same tag name")||e.includes("Failed to execute 'define' on 'CustomElementRegistry'")||e.includes("CustomElementRegistry.define")))return;const r=window.location.href,o=window.Shopify.shop;return await fetch("https://storefront-events.kachingappz.app/bundles/errors",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({error:{filename:t,message:e,stack:n,url:r,shop:o}})})},u=()=>{const t=["kaching-bundles.js","kaching-bundles-block.js"];window.addEventListener("error",(async function(e){try{await(async e=>{const{filename:n,message:i,error:o}=e;for(const a of t)if(n.includes(a)){if(r()||I())return void l("Error",e);await c(n,i,o.stack)}})(e)}catch(n){console.error(n)}})),window.addEventListener("unhandledrejection",(async function(e){try{await(async e=>{if("object"!=typeof e.reason)return;const{message:n,stack:i}=e.reason;if(i)for(const o of t)if(i.includes(o)){if(r()||I())return void l("Unhandled rejection",e);await c(o,n,i)}})(e)}catch(n){console.error(n)}}))};function l(t,n=null){(r()||(void 0===o&&(o="dev"===e()),o))&&console.debug("[Kaching Bundles]",t,n)}const d=()=>{const t=t=>{window.dispatchEvent(new Event(t))},e=history.pushState;history.pushState=function(...n){const i=e.apply(this,n);return t("pushstate"),t("locationchange"),i};const n=history.replaceState;history.replaceState=function(...e){const i=n.apply(this,e);return t("replacestate"),t("locationchange"),i},m(window,"popstate",(()=>{t("locationchange")}))},p=(t,e,n,i=0)=>{const r=Object.getPrototypeOf(t);if(r.hasOwnProperty(e)){const o=Object.getOwnPropertyDescriptor(r,e);if(!o.configurable)return;Object.defineProperty(t,e,{configurable:!0,get:function(...t){return o.get.apply(this,t)},set:function(...t){const r=this[e];o.set.apply(this,t);const a=this[e];return"function"==typeof n&&setTimeout(n.bind(this,r,a),i),a}})}},h=(t,e=document.body)=>{try{return e.querySelector(t)}catch(n){return null}},f=(t,e=document.body)=>{try{return[...e.querySelectorAll(t)]}catch(n){return[]}},m=(t,e,n)=>t.addEventListener(e,n),w=t=>document.createElement(t),_=(t,e,n)=>t.setAttribute(e,n),g=t=>t.dataset,y=t=>{const e=h(t);if(!e)return;const n=JSON.parse(e.textContent);return l("jsonFromElement",n),n},b=(t,e)=>{let n=0,i=t;for(;i!==e&&i!==document.body;)n++,i=i.parentNode;if(i!==e)throw new Error("The specified child node is not a descendant of the parent node.");return n},v=(t,e)=>{const n=new Range;return n.setStart(t,0),n.setEnd(e,0),n.collapsed&&(n.setStart(e,0),n.setEnd(t,0)),n.commonAncestorContainer},k=(t,e,n=1/0)=>{let i=null,r=1/0;for(const o of e){const e=v(t,o),a=b(t,e);a>n||a{const t=document.currentScript;if(!t)return!1;return t.src.includes("kaching-bundles-dev")},P=(t,e={})=>{const n=window.Shopify.routes,i=(n&&n.root||"/")+t,r=new URLSearchParams;for(const[a,s]of Object.entries(e))r.append(a,s);const o=r.toString();return o?`${i}?${o}`:i},S=(t,e)=>{new MutationObserver(((n,i)=>{for(const r of n)"childList"===r.type&&r.removedNodes.forEach((n=>{n.contains(t)&&(i.disconnect(),e())}))})).observe(document.body,{childList:!0,subtree:!0})},C=[['[data-icon="gpicon-product-cartbutton"]','[data-icon="gpicon-product-quantity"]'],["gp-product-button","gp-product-quantity"],["product-form",".product-form__quantity"],['[data-pf-type="ProductATC"]','[data-pf-type="ProductQuantity"]'],[".product-form__item--submit",'label[for="Quantity-product-template"]'],[".product-single__add-to-cart",".product-single__quantity"],[".product-info__buy-buttons",".product-info__quantity-selector"],[".ProductForm__BuyButtons, .ProductForm__AddToCart",".ProductForm__QuantitySelector"],['[data-block-type="buy-buttons"]','[data-block-type="quantity-selector"]'],[".product-page--submit-action",".quantity-controls__outer"],[".product-form__payment-container",".product-form__info-item--quantity"],["[data-product-submit]",".product-quantity-input"],[".product-form--atc",".product-form--atc-qty"],[".purchase-details",".purchase-details__quantity"],[".product-single__form .payment-buttons",".product__quantity"],[".product-form--wide",".product-single__quantity"],[".product-single__add-to-cart",".product-single__quantity"],[".product-form--button-container",null],[".product-form__item--submit",".product-form__item--quantity"],[".product-detail__form__action",null],[".product__submit__buttons",null],[".buy-buttons-row",".quantity-wrapper"],[".t4s-product-form__buttons","[data-quantity-wrapper]"],[".qty-wrapper--with-payment-button",".product-qty"],[".shopify-product-form",".product-quantity-block"],[".shopify-product-form",".product-block-quantity-selector"],[".type_buy_buttons",".type_quantity_selector"],[".product-single__form .add-to-cart",".product__quantity"],[".purchase-section",".quantity.form"],[".product-form__buttons",".quantity_selector"],[".product__atc",".quantity--input"],[".product-form__payment-container",".quantity-selector"],[".ecom-product-single__add-to-cart",".ecom-product-single__quantity"],[".product-form__submit",".product__quantity"],[".product-info__add-to-cart","quantity-input"],[".yv-checkout-btn",".yv-product-quantity"],[".product-add-to-cart-container","quantity-selector"],[".product__block__buttons",".product__block__quantity"],["x-buy-button","x-quantity-input"],['[data-instant-action-type="redirect-to-cart"]','[data-instant-type="container"]:has(> .instant-quantity-input)']];class N extends Error{constructor(t){super(t),this.name="CartFetchError"}}const q="kaching_session_id",$=()=>{const e=new URL(window.location.href),n=new URLSearchParams(e.search),i=n.get("preview_kaching_session_id");i&&(t.setItem(q,i),n.delete("preview_kaching_session_id"),e.search=n.toString(),window.history.replaceState({},"",e.toString()))},T=()=>t.getItem(q)||x(),x=()=>{const e=V();return t.setItem(q,e),e},V=()=>"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():F(),F=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(t=>(+t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+t/4).toString(16))),A=async()=>{const t=await fetch(P("cart.js"));if(!t.ok)throw new N("Failed to fetch cart");return(await t.json()).attributes._kaching_session_id},D=async t=>{const e=new FormData;e.append("attributes[_kaching_session_id]",t);const n=await fetch(P("cart/update.js"),{method:"POST",body:e});return await n.json()},O=(t,e)=>{const n=t.slice(-1);return parseInt(n,16)%e+1};class B{constructor(t,e,n,i,r){if(l("AddToCartForm",[t]),this.t=t,this.i=e,this.o=n,this.u=i,r){this.l("properties[__kaching_session_id]").value=T()}}update(t){l("AddToCartForm#update",[this.t,t]),this.p(t.id),this.h(t.quantity),this.m(t.properties),this._(t.selling_plan)}currentVariantId(){const t=this.v("id");if(t)return Number(t.value)}p(t){const e=this.l("id");e.disabled=!1,e.value=String(t)}h(t){l("AddToCartForm#_updateQuantityInput",t);let e=null;e=this.o?this.l("quantity"):this.v("quantity"),e&&(e.disabled=!1,e.value=String(t))}m(t){var e,n;if(t.__kaching_bundles){const i=this.l("properties[__kaching_bundles]");let r=t.__kaching_bundles;const o=null==(n=null==(e=window.Shopify.theme)?void 0:e.schema_name)?void 0:n.toLowerCase();(null==o?void 0:o.startsWith("shrine pro"))&&(r=btoa(r)),i.value=r}else{const t=this.v("properties[__kaching_bundles]");null==t||t.remove()}}_(t){if(this.u)if(t){this.l("selling_plan").value=String(t)}else{const t=this.v("selling_plan");null==t||t.remove()}}l(t){return this.v(t)||this.k(t)}v(t){return h(`[name="${t}"]`,this.t)}k(t){const e=w("input");return e.type="hidden",e.name=t,this.t.prepend(e),e}}class j{constructor(t){this.storefrontApiVersion="2025-04",this.storefrontAccessToken=t}async query(t,{variables:e}={variables:{}}){var n;let i=`https://${window.Shopify.shop}/api/${this.storefrontApiVersion}/graphql.json`;const r=null==(n=t.match(/query\s+(\w+)/))?void 0:n[1];r&&(i+=`?operation_name=${r}`);const o=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:t,variables:e})});let a=null;try{if(a=await o.text(),!a)throw new Error("Empty graphql response");return JSON.parse(a).data}catch(c){throw s("storefront_graphql_error",{status:o.status,body:a}),c}}}const G="$app:kaching_bundles",E="\n id\n availableForSale\n price {\n amount\n }\n compareAtPrice {\n amount\n }\n selectedOptions {\n name\n value\n }\n image {\n id\n url(transform: { maxWidth: 200, maxHeight: 200 })\n }\n unitPriceMeasurement {\n quantityUnit\n quantityValue\n referenceUnit\n referenceValue\n }\n sellingPlanAllocations(first: 100) @include(if: $includeSellingPlans) {\n nodes {\n sellingPlan {\n id\n }\n priceAdjustments {\n price {\n amount\n }\n }\n }\n }\n",M=async(t,{country:e,language:n,productIds:i,removeUnavailableVariants:r,includeSellingPlans:o})=>{const a=i.map((t=>`gid://shopify/Product/${t}`));let s=(await t.query(`\n query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!) @inContext(country: ${e}, language: ${n}) {\n nodes(ids: $productGIDs) {\n ... on Product {\n id\n handle\n onlineStoreUrl\n availableForSale\n title\n featuredImage {\n url\n }\n options {\n name\n optionValues {\n id\n name\n swatch {\n color\n image {\n previewImage {\n url(transform: { maxWidth: 200, maxHeight: 200 })\n }\n }\n }\n }\n }\n variants(first: 250) {\n nodes {\n ${E}\n }\n }\n collections(first: 50) {\n nodes {\n id\n }\n }\n metafield: metafield(namespace: "${G}", key: "text") {\n value\n }\n metafield2: metafield(namespace: "${G}", key: "text2") {\n value\n }\n metafield3: metafield(namespace: "${G}", key: "text3") {\n value\n }\n metafield4: metafield(namespace: "${G}", key: "text4") {\n value\n }\n legacy_metafield_text: metafield(namespace: "kaching_bundles", key: "text") {\n value\n }\n legacy_metafield_text2: metafield(namespace: "kaching_bundles", key: "text2") {\n value\n }\n requiresSellingPlan\n sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {\n nodes {\n sellingPlans(first: 100) {\n nodes {\n id\n name\n priceAdjustments {\n adjustmentValue {\n __typename\n ... on SellingPlanPercentagePriceAdjustment {\n adjustmentPercentage\n }\n ... on SellingPlanFixedAmountPriceAdjustment {\n adjustmentAmount {\n amount\n }\n }\n ... on SellingPlanFixedPriceAdjustment {\n price {\n amount\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n `,{variables:{productGIDs:a,includeSellingPlans:o}})).nodes.filter((t=>null!=t));return s=await Promise.all(s.map((e=>U(t,e)))),s.map((t=>R(t,r)))},U=async(t,e)=>{if(e.variants.nodes.length<250)return e;const n=new Set,i=[],r=[],o=async o=>{let a=!0,s=null;for(;a;){const c=await t.query(`\n query($productGID: ID!, $cursor: String, $reverse: Boolean) {\n product(id: $productGID) {\n variants(first: 250, after: $cursor, reverse: $reverse) {\n nodes {\n ${E}\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n }\n }\n `,{variables:{productGID:e.id,cursor:s,reverse:o}}),{nodes:u,pageInfo:l}=c.product.variants;for(const t of u){if(n.has(t.id)){a=!1;break}n.add(t.id),o?r.push(t):i.push(t)}l.hasNextPage||(a=!1),s=l.endCursor}};return await Promise.all([o(!1),o(!0)]),e.variants.nodes=[...i,...r.reverse()],l("fetchAllVariantsForProduct",{productId:e.id,variants:e.variants.nodes.length}),s("2048_variants",{variants:e.variants.nodes.length}),e},R=(t,e)=>{var n,i,r,o,a,s,c,u;let l=t.variants.nodes.map((({unitPriceMeasurement:t,...e})=>{var n,i,r,o;return{id:Number(e.id.split("/").pop()),availableForSale:e.availableForSale,price:Math.round(100*Number(e.price.amount)),compareAtPrice:e.compareAtPrice?Math.round(100*Number(e.compareAtPrice.amount)):null,options:e.selectedOptions.map((t=>t.value)),imageId:e.image?Number(e.image.id.split("/").pop()):null,image:(null==(n=e.image)?void 0:n.url)||null,unitPriceQuantityValue:(null==t?void 0:t.quantityValue)||null,unitPriceQuantityUnit:(null==(i=null==t?void 0:t.quantityUnit)?void 0:i.toLowerCase())||null,unitPriceReferenceValue:(null==t?void 0:t.referenceValue)||null,unitPriceReferenceUnit:(null==(r=null==t?void 0:t.referenceUnit)?void 0:r.toLowerCase())||null,sellingPlans:(null==(o=e.sellingPlanAllocations)?void 0:o.nodes.map((t=>({id:Number(t.sellingPlan.id.split("/").pop()),price:t.priceAdjustments.length>0?Math.round(100*Number(t.priceAdjustments[0].price.amount)):Math.round(100*Number(e.price.amount))}))))||[]}}));if(e){const t=l.filter((t=>t.availableForSale));t.length>0&&(l=t)}const d=t.options.map(((t,e)=>{const n=t.optionValues.map((t=>{var e,n,i,r;return{id:Number(t.id.split("/").pop()),defaultName:t.name,name:t.name,swatch:{color:(null==(e=t.swatch)?void 0:e.color)||null,image:(null==(r=null==(i=null==(n=t.swatch)?void 0:n.image)?void 0:i.previewImage)?void 0:r.url)||null}}}));return{defaultName:t.name,name:t.name,position:e+1,optionValues:J(n,e,l)}})),p=t=>{const e=t.priceAdjustments[0];if(!e)return null;const n=e.adjustmentValue;switch(n.__typename){case"SellingPlanPercentagePriceAdjustment":return{type:"percentage",value:n.adjustmentPercentage};case"SellingPlanFixedAmountPriceAdjustment":return{type:"fixed_amount",value:100*Number(n.adjustmentAmount.amount)};case"SellingPlanFixedPriceAdjustment":return{type:"price",value:100*Number(n.price.amount)};default:throw new Error(`Unknown price adjustment type: ${n.__typename}`)}},h=(null==(n=t.sellingPlanGroups)?void 0:n.nodes.flatMap((t=>t.sellingPlans.nodes.map((t=>({id:Number(t.id.split("/").pop()),name:t.name,priceAdjustment:p(t)}))))))||[];return{id:Number(t.id.split("/").pop()),url:t.onlineStoreUrl,availableForSale:t.availableForSale,title:t.title,image:(null==(i=t.featuredImage)?void 0:i.url)||null,collectionIds:t.collections.nodes.map((t=>Number(t.id.split("/").pop()))),options:d,selectedVariantId:Number(t.variants.nodes[0].id.split("/").pop()),variants:l,requiresSellingPlan:t.requiresSellingPlan,sellingPlans:h,metafields:{text:(null==(r=t.metafield)?void 0:r.value)||null,text2:(null==(o=t.metafield2)?void 0:o.value)||null,text3:(null==(a=t.metafield3)?void 0:a.value)||null,text4:(null==(s=t.metafield4)?void 0:s.value)||null},legacyMetafields:{kaching_bundles:{text:(null==(c=t.legacy_metafield_text)?void 0:c.value)||null,text2:(null==(u=t.legacy_metafield_text2)?void 0:u.value)||null}}}},J=(t,e,n)=>t.filter((t=>n.filter((n=>n.options[e]===t.name)).length>0)),Q=t=>{const e=t.options.map(((t,e)=>({defaultName:t.name,position:e+1,optionValues:t.optionValues.map((t=>({id:Number(t.id.split("/").pop()),defaultName:t.name})))})));return{id:Number(t.id.split("/").pop()),options:e}},z=async(t,e,n=200)=>(await t.query("\n query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {\n nodes(ids: $mediaImageIds) {\n ... on MediaImage {\n id\n image {\n url(transform: { maxWidth: $size, maxHeight: $size })\n }\n }\n }\n }\n ",{variables:{mediaImageIds:e,size:n}})).nodes.filter(Boolean).map((t=>({gid:t.id,url:t.image.url}))),L=async t=>{var e;const n=null==(e=(await t.query(`\n query FetchDealBlocks {\n shop {\n metafield(namespace: "${G}", key: "deal_blocks") {\n value\n }\n }\n }\n `)).shop.metafield)?void 0:e.value;return n?JSON.parse(n):[]},K=async(t,e)=>{const n=e.dealBars.map((t=>t.mediaImageGID)).filter((t=>null!=t)).filter((t=>!t.includes("placeholder")));if(!n.length)return[];let i=300;"d1b96b-5.myshopify.com"===window.Shopify.shop&&(i=1200);return await z(t,n,i)},H=async(t,e)=>{const n=e.dealBars.map((({freeGifts:t})=>(t||[]).map((t=>t.mediaImageGID)))).reduce(((t,e)=>t.concat(e)),[]).filter((t=>null!=t)).filter((t=>!t.includes("placeholder")));if(!n.length)return[];return await z(t,n,300)},W=async(t,e)=>{const n=e.dealBars.map((({upsells:t})=>(t||[]).map((t=>t.mediaImageGID)))).reduce(((t,e)=>t.concat(e)),[]).filter((t=>null!=t));if(!n.length)return[];return await z(t,n,300)},X=async(t,e)=>{if(!e.swatchOptions)return[];const n=e.swatchOptions.reduce(((t,e)=>[...t,...e.images.map((t=>t.mediaImageGID)).filter((t=>null!=t))]),[]);if(!n.length)return[];return await z(t,n,300)},Y=async(t,e)=>{if(!e.collectionBreaksEnabled||!e.collectionBreaks)return[];const n=e.collectionBreaks.mediaImageGID;if(!n)return[];return await z(t,[n],300)},Z=async(t,e,n)=>{var i;if(!t)return;if(0===e.length)return;const r=tt(n);if(0===r.length)return;const o=e.map((t=>t.id)),a=null==(i=r.find((t=>t.localization)))?void 0:i.localization,s=new j(t);try{const t=await(async(t,e,n)=>{const i=e.map((t=>`gid://shopify/Product/${t}`));let r="";return n&&(r=`@inContext(country: ${n.country}, language: ${n.language})`),(await t.query(`\n query FetchProductsInDefaultLanguage($productGIDs: [ID!]!) ${r} {\n nodes(ids: $productGIDs) {\n ... on Product {\n id\n options {\n name\n optionValues {\n id\n name\n }\n }\n }\n }\n localization {\n country {\n isoCode\n }\n language {\n isoCode\n }\n }\n }\n `,{variables:{productGIDs:i}})).nodes.filter((t=>null!=t)).map(Q)})(s,o,a);for(const n of e){const e=t.find((t=>t.id===n.id));e&&et(n,e)}}catch(c){console.error("[Kaching Bundles] Failed to fetch swatches",c),setTimeout((()=>{throw c}),0)}},tt=t=>t.map((t=>t.swatchOptions||[])).reduce(((t,e)=>t.concat(e)),[]).filter((t=>null!=t)).filter((t=>"default"!==t.swatchType)),et=(t,e)=>{for(const n of e.options){const e=t.options.find((t=>t.position===n.position));if(e){e.defaultName=n.defaultName;for(const t of n.optionValues){const n=e.optionValues.find((e=>e.id===t.id));n&&(n.defaultName=t.defaultName)}}}},nt=(t,e)=>{if(l("_updateNativePrice",{discountedPrice:t,fullPrice:e}),e.amount>0){const n=f("[data-kaching-price-compare]");if(n.length>0)for(const i of n)e.amount>t.amount?(i.innerHTML=e.formatted,i.style.display=""):i.style.display="none";else{const t=[".price--large .price__sale .price-item--regular",".price--medium .price__sale .price-item--regular",".lumin-price .price__sale .price-item--regular",".product-page-price .price__sale .price-item--regular",".f-price--large .f-price__sale .f-price-item--regular",'gp-product-price div[type="compare"]',"product-price .compare-at-price",".pp-product-price .pp-price-item--sale",".product__price-and-badge .product__price--compare",".product-block--price span[data-compare-price]",".main-product__block-price .m-price__sale .m-price-item--regular",".product-info__price compare-at-price",'.product-info__block-item[data-block-type="price"] compare-at-price',".product-form__info-item .price--compare",'[data-product-type="compare_at_price"]'].flatMap((t=>f(t)));for(const n of t)n.innerHTML=e.formatted}}if(t.amount>0){const e=f("[data-kaching-price]");if(e.length>0)for(const n of e)n.innerHTML=t.formatted;else{const e=[".price--large .price__regular .price-item--regular",".price--large .price__sale .price-item--sale",".price--medium .price__regular .price-item--regular",".price--medium .price__sale .price-item--sale",".lumin-price .price__regular .price-item--regular",".lumin-price .price__sale .price-item--sale",".product-page-price .price__regular .price-item--regular",".product-page-price .price__sale .price-item--sale",".f-price--large .f-price__regular .f-price-item--regular",".f-price--large .f-price__sale .f-price-item--sale",'gp-product-price div[type="regular"]',"product-price .price",".pp-product-price .pp-price-item--regular",".product__price-and-badge .product__price--regular",".product-block--price span[data-product-price]",".main-product__block-price .m-price__sale .m-price-item--sale",".product-info__price sale-price",'.product-info__block-item[data-block-type="price"] sale-price',".product-form__info-item .price:not(.price--compare)",'[data-product-type="price"]'].flatMap((t=>f(t)));for(const n of e)n.innerHTML=t.formatted}}if(t.amount>0&&e.amount>0){const n=Math.round((e.amount-t.amount)/e.amount*100),i=f("[data-kaching-price-badge]");if(i.length>0)for(const t of i)n>0?(t.innerHTML=t.innerHTML.replace(/\d+%/,`${n}%`),t.style.display=""):t.style.display="none";else{const t=[".price--large .price__badge-sale",".lumin-price .price__badge-sale",".product-page-price .price__badge-sale","gp-product-tag div[data-gp-text]",".product__price-and-badge span[data-price-off-amount]",".product-block--price span[data-save-price]",".product-info__price on-sale-badge"].flatMap((t=>f(t)));for(const e of t)!/\d/.test(e.innerHTML)||e.innerHTML.includes("%")?e.innerHTML=e.innerHTML.replace(/\d+%/,`${n}%`):e.style.display="none"}}},it=window;class rt{constructor(t,e,n,i,r,o,a,s,c){var u;if(this.I=[],this.P=!1,l("DealBlock",{dealBlockElement:t,cartForm:e,addToCartButton:n,quantityInput:i,variantPicker:r,globalConfig:o,translations:a,dealBlockSettings:s,product:c}),this.S=t,this.t=e,this.C=n,this.N=i,this.q=r,this.$=o,this.T=a,this.V=s,this.i=c,this.F=window.Shopify.country,this.A=window.Shopify.locale.split("-")[0].toUpperCase(),this.$.featureFlags.initialize_with_form_variant){let t=this.i.selectedVariantId||this.i.variants[0].id;const e=null==(u=this.t)?void 0:u.querySelector('input[name="id"]');if(e){const n=Number(e.value);n&&(t=n)}this.D=t}else this.D=this.i.selectedVariantId||this.i.variants[0].id;this.O=e&&new B(e,c,!i,!!s.subscriptionsEnabled||s.dealBars.some((t=>"subscription"===t.dealBarType)),!!s.abTestVariantNumber),this.B()}replaceVariantPicker(t){this.q=t}replaceAddToCartButton(t){this.C=t,this.j()}replaceQuantityInput(t){this.N=t,this.G()}B(){_(this.S,"config",JSON.stringify(this.$)),_(this.S,"translations",JSON.stringify(this.T)),_(this.S,"deal-block",JSON.stringify(this.V)),_(this.S,"product",JSON.stringify(this.i)),_(this.S,"current-variant-id",String(this.D)),this.M(),this.U(),this.R(),this.J(),this.t&&this.L()}async M(){if(!this.$.storefrontAccessToken)return;const t=new j(this.$.storefrontAccessToken),e=await(async(t,e)=>{const[n,i,r,o,a]=await Promise.all([K(t,e),H(t,e),W(t,e),X(t,e),Y(t,e)]);return[...n,...i,...r,...o,...a]})(t,this.V);_(this.S,"media-images",JSON.stringify(e))}async U(){if(!this.$.storefrontAccessToken)return;const t=this.V.dealBars.flatMap((({freeGifts:t})=>t?t.map((t=>t.productGID)):[])).filter((t=>null!=t)),e=this.V.dealBars.flatMap((({upsells:t})=>t?t.map((t=>t.productGID)):[])).filter((t=>null!=t)),n=this.V.dealBars.flatMap((({bundleProducts:t})=>t?t.map((t=>t.productGID)):[])).filter((t=>null!=t)).filter((t=>"default"!==t)),i=Array.from(new Set([...t,...e,...n]));if(!i.length)return;const r=new j(this.$.storefrontAccessToken),o=await M(r,{country:this.F,language:this.A,productIds:i.map((t=>Number(t.split("/").pop()))),removeUnavailableVariants:!0,includeSellingPlans:this.$.accessScopes.includes("unauthenticated_read_selling_plans")});await Z(this.$.storefrontAccessToken,o,[this.V]),_(this.S,"other-products",JSON.stringify(o))}async R(){if(!this.$.storefrontAccessToken)return;const{collectionBreaksEnabled:t,collectionBreaks:e}=this.V;if(!t||!e)return;const n=(e.excludedProducts||[]).map((({id:t})=>t)),i=(e.selectedProducts||[]).map((({id:t})=>t)),r=(e.selectedCollections||[]).map((({id:t})=>t)),o=new j(this.$.storefrontAccessToken);let a=await(async(t,{country:e,language:n,blockVisibility:i,excludedProductGIDs:r,selectedProductGIDs:o,selectedCollectionGIDs:a})=>{const s=250;switch(i){case"selected-products":return o.slice(0,s);case"all-products":case"excluded-products":{let o=(await t.query(`\n query FetchProductGIDs($limit: Int!) @inContext(country: ${e}, language: ${n}) {\n products(first: $limit) {\n nodes {\n id\n }\n }\n }\n `,{variables:{limit:s}})).products.nodes.map((t=>t.id));return"excluded-products"===i&&(o=o.filter((t=>!r.includes(t)))),o}case"selected-collections":return(await t.query("\n query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) {\n nodes(ids: $collectionGIDs) {\n ... on Collection {\n products(first: $limit) {\n nodes {\n id\n }\n }\n }\n }\n }\n ",{variables:{collectionGIDs:a,limit:s}})).nodes.flatMap((t=>t.products.nodes.map((t=>t.id)))).splice(0,s)}})(o,{country:this.F,language:this.A,blockVisibility:e.visibility,excludedProductGIDs:n,selectedProductGIDs:i,selectedCollectionGIDs:r});a=a.slice(0,250);const s=(c=50,a.reduce(((t,e,n)=>{const i=Math.floor(n/c);return t[i]||(t[i]=[]),t[i].push(e),t}),[]));var c;let u=(await Promise.all(s.map((t=>M(o,{country:this.F,language:this.A,productIds:t.map((t=>Number(t.split("/").pop()))),removeUnavailableVariants:!1,includeSellingPlans:this.$.accessScopes.includes("unauthenticated_read_selling_plans")}))))).flat();u=u.filter((t=>t.availableForSale)),u.sort(((t,e)=>t.id===this.i.id?-1:e.id===this.i.id?1:0)),await Z(this.$.storefrontAccessToken,u,[this.V]),_(this.S,"collection-breaks-products",JSON.stringify(u)),setTimeout((()=>{this.K(u)}),1e3)}async J(){if(!this.V.dealBars.some((t=>{var e;return null==(e=t.upsells)?void 0:e.some((t=>"complementary"===t.productSource))})))return;if(!this.$.storefrontAccessToken)return;const t=new j(this.$.storefrontAccessToken),e=await(async(t,{productId:e,country:n,language:i})=>{var r;return(null==(r=(await t.query(`\n query FetchComplementaryProductGIDs($productGID: ID!) @inContext(country: ${n}, language: ${i}) {\n productRecommendations(productId: $productGID, intent: COMPLEMENTARY) {\n id\n }\n }\n `,{variables:{productGID:`gid://shopify/Product/${e}`}})).productRecommendations)?void 0:r.map((t=>t.id)))||[]})(t,{country:this.F,language:this.A,productId:this.i.id});if(!e.length)return;let n=await M(t,{country:this.F,language:this.A,productIds:e.map((t=>Number(t.split("/").pop()))),removeUnavailableVariants:!0,includeSellingPlans:this.$.accessScopes.includes("unauthenticated_read_selling_plans")});n=n.filter((t=>t.availableForSale)),await Z(this.$.storefrontAccessToken,n,[this.V]),_(this.S,"complementary-products",JSON.stringify(n))}K(t){for(const e of t){const t=e.variants[0].image||e.image;if(t){(new Image).src=t}}}L(){if(this.H(),this.W(),this.X(),this.G(),this.Y(),this.Z(),!window.kachingBundlesDisableAddToCartHandling){this.j();try{this.tt()}catch(t){console.error(t)}}}tt(){m(document.body,"kaching-unavailable-option-value-selected",(t=>{const{swatch:e}=t.detail;s("unavailable-option-value-selected-3",{swatch:e})}))}H(){d(),m(it,"locationchange",(()=>{const t=new URLSearchParams(it.location.search).get("variant");t&&this.et(Number(t))}))}W(){const t=h('input[name="id"]',this.t);t&&p(t,"value",((t,e)=>{l("_listenForVariantIdInputChange",[t,e]),t!==e&&e&&this.et(Number(e))}))}X(){const t=h('select[name="id"]',this.t);if(!t)return;let e;window.setInterval((()=>{const n=t.value;e!==n&&n&&(l("_listenForVariantIdSelectChange",[e,n]),e=n,this.et(Number(n)))}),100)}et(t){if(l("handleNativeVariantChange",{variantId:t,currentVariantId:this.D}),t!=this.D&&this.i.variants.find((e=>e.id==t))){if(this.$.featureFlags.remove_variant_change_delay&&window.kachingBundlesCurrentVariantChangeInProgress||(this.D=t),this.$.featureFlags.remove_variant_change_delay){if(window.kachingBundlesCurrentVariantChangeInProgress)return void l("handleNativeVariantChange","skipping")}else if(this.S.dataset.nativeVariantChangeInProgress||window.kachingBundlesCurrentVariantChangeInProgress)return void l("handleNativeVariantChange","skipping");this.S.dataset.nativeVariantChangeInProgress="true",setTimeout((()=>{delete this.S.dataset.nativeVariantChangeInProgress}),this.$.featureFlags.remove_variant_change_delay?1e3:500),_(this.S,"current-variant-id",String(t))}}G(){this.N&&(m(this.N,"change",(()=>{const t=Number(this.N.value);l("_listenForQuantityInputChange change",t),this.nt(t)})),p(this.N,"value",((t,e)=>{t!==e&&(l("_listenForQuantityInputChange observe",[t,e]),this.nt(Number(e)))})))}nt(t){window.kachingBundlesQuantityChangeInProgress||(!this.$.keepQuantityInput||window.kachingBundlesCurrentVariantChangeInProgress||this.S.dataset.nativeVariantChangeInProgress?this.it():this.$.keepQuantityInput&&_(this.S,"quantity",String(t)))}it(){if(!this.N||0===this.I.length)return;if(window.kachingBundlesDisableAddToCartHandling&&!this.$.keepQuantityInput)return;window.kachingBundlesQuantityChangeInProgress=!0;const t=this.I.filter((t=>this.rt(t))),e=(t.find((({id:t})=>t==this.D))||t[0]).quantity;l("_updateQuantityInput",e),this.N.value=String(e),"119a01-bf.myshopify.com"===window.Shopify.shop&&this.N.dispatchEvent(new Event("input",{bubbles:!0})),this.N.dispatchEvent(new Event("change",{bubbles:!0})),setTimeout((()=>{delete window.kachingBundlesQuantityChangeInProgress}),100)}Y(){this.q&&m(this.S,"variant-selected",(t=>{const{variantId:e}=t.detail;l("listenForBlockVariantSelect",e),this.ot(e)}))}Z(){m(this.S,"variants-changed",(t=>{var e;clearTimeout(this.st);const{pricing:n,preselected:i}=t.detail;this.I=this.S.items(),l("listenForBlockVariantsChange",{items:this.I,pricing:n,preselected:i});const r=this.I.filter((t=>this.rt(t))),o=r.find((t=>t.id==this.D))||r[0];if(this.ot(o.id),this.O.update(o),this.it(),null==(e=this.C)||e.updatePrice(n.discountedPrice),i&&setTimeout((()=>{var t;return null==(t=this.C)?void 0:t.updatePrice(n.discountedPrice)}),300),this.ct(),i&&(this.st=setTimeout((()=>{this.it(),delete this.st}),1e3)),this.V.updateNativePrice){clearTimeout(this.ut);const t="item"===this.V.updateNativePriceType?n.discountedPricePerItem:n.discountedPrice,e="item"===this.V.updateNativePriceType?n.fullPricePerItem:n.fullPrice;nt(t,e),this.ut=setTimeout((()=>{nt(t,e)}),1e3)}this.lt()}))}lt(){var t,e,n,i;l("reconvertPrices");try{(null==(t=window.bucksCC)?void 0:t.reConvert)&&window.bucksCC.reConvert(),(null==(e=window.baCurr)?void 0:e.refreshConversion)&&window.baCurr.refreshConversion(),(null==(n=window.DoublyGlobalCurrency)?void 0:n.convertAll)&&window.DoublyGlobalCurrency.convertAll(),(null==(i=window.conversionBearAutoCurrencyConverter)?void 0:i.convertPricesOnPage)&&window.conversionBearAutoCurrencyConverter.convertPricesOnPage(),window.mlvedaload&&window.mlvedaload()}catch(r){console.error(r)}}ot(t){const e=this.i.variants.find((e=>e.id==t));if(l("_changeCurrentVariant",{variantId:t,currentVariantId:this.D}),this.D==t)return;if(this.D=t,!this.q)return;(!this.$.featureFlags.remove_variant_change_delay||!this.S.dataset.nativeVariantChangeInProgress)&&(clearTimeout(window.kachingBundlesCurrentVariantChangeInProgress),window.kachingBundlesCurrentVariantChangeInProgress=setTimeout((()=>{delete window.kachingBundlesCurrentVariantChangeInProgress}),1e3));for(const[n,i]of e.options.entries()){const t=this.i.options[n],r=t.name,o=t.optionValues.find((t=>t.name===i)).id;this.q.select(n+1,o,r,i,this.i.id,e.id)}}j(){if(!this.C)return;this.C.onClickIfConditionMet((()=>!window.kachingBundlesDisableAddToCartHandling&&(!!this.V.skipCart||(!!this.dt()||(!!this.ht()||this.I.length>1)))),(async()=>{if(this.V.skipCart)return await this.ft(),window.kachingCartApi&&(l("Kaching Cart update tiered promotions bar"),await window.kachingCartApi.updateTieredPromotionsBar()),void(window.location.href=P("checkout"));if(this.dt()){try{window.upcartOpenCart&&window.upcartOpenCart()}catch(t){console.error("upcartOpenCart error",t)}return await this.ft(),void(window.upcartRefreshCart&&window.upcartRefreshCart())}if(this.ht()){try{window.opusOpen&&window.opusOpen()}catch(t){console.error("opusOpen error",t)}return await this.ft(),void(window.opusRefreshCart&&window.opusRefreshCart())}return this.wt()}),(()=>this.V.skipCart||this.dt()||this.ht())),this._t(),this.gt()}_t(){window.upcartShouldSkipAddToCartInterceptor=!0;const t=window.upcartShouldSkipAddToCart;window.upcartShouldSkipAddToCart=e=>{if("function"==typeof t){if(!0===t(e))return!0}return e.includes("kaching_bundles=true")}}gt(){["the-gloria-skincare.myshopify.com","xzxihx-8t.myshopify.com","e76602-61.myshopify.com"].includes(window.Shopify.shop)&&(window.OpusNoATC=!0)}dt(){return!!h("#UpcartPopup")||!!window.upcartDocumentOrShadowRoot}ht(){return["the-gloria-skincare.myshopify.com","xzxihx-8t.myshopify.com","e76602-61.myshopify.com"].includes(window.Shopify.shop)&&window.opusActive||!1}async wt(){l("addItemsExceptCurrentToCart",this.I);const t=this.O.currentVariantId();setTimeout((()=>{t!=this.D&&s("different_current_variant_v3",{form:t,object:this.D})}));const e=this.I.findIndex((e=>this.rt(e)&&e.id==t)),n=this.I.filter(((t,n)=>n!==e));await this.yt({items:n,partial:!0})}async ft(){l("addAllItemsToCart",this.I);let t=this.I;0===t.length&&(t=[{id:this.O.currentVariantId(),quantity:1,properties:{}}]),await this.yt({items:t})}bt(){const t=f('[name^="properties"]').map((t=>[t.name.match(/properties\[(.*)\]/)[1],t.value])).filter((([t])=>"__kaching_bundles"!==t));return Object.fromEntries(t)}rt(t){const e=this.vt(t);return!e||(e.main||!1)}vt(t){if(!t.properties.__kaching_bundles)return null;return JSON.parse(t.properties.__kaching_bundles)}async yt({items:t,partial:e=!1}){const n=this.bt(),i=t.map((t=>{var e;return this.rt(t)||(null==(e=this.vt(t))?void 0:e.collectionBreaksProduct)?{...t,properties:{...n,...t.properties}}:t}));setTimeout((()=>this.kt(n)));const r={kaching_bundles:"true"};e&&(r.partial="true");const o={"Content-Type":"application/json"};e||(o["X-Kaching-Cart-Ignore"]="1"),await fetch(P("cart/add.js",r),{method:"POST",body:JSON.stringify({items:i}),headers:o})}kt(t){if(!this.V.collectionBreaksEnabled)return;const e=Object.fromEntries(Object.entries(t).filter((([t])=>!t.startsWith("__kaching_"))));0!==Object.keys(e).length&&s("collection_break_properties",{properties:e})}ct(){const t="kaching-bundles-form--different-variants-selected";this.I.length>1?this.t.classList.add(t):this.t.classList.remove(t)}}class ot{static find(t,e){let n=t.parentElement;for(;n;){if(e){const t=f(e,n);if(t.length>0)return new ot(t)}const t=h(["variant-selects","variant-radios","variant-picker","product-variants","gp-product-variants",".gf_variants-wrapper",'[data-pf-type="ProductVariantSwatches"]',".product-selectors",".product-block-variant-picker","dm-variant-selects"].join(", "),n);if(t)return new ot([t]);let i=f([".selector-wrapper",".radio-wrapper",".variant-wrapper","div[data-product-option]",".pp-variant-picker"].join(", "),n);if(["28212b.myshopify.com","9bd9ad.myshopify.com"].includes(window.Shopify.shop)&&(i=f(".selector-wrapper, .radio-wrapper, .variant-wrapper, .select-wrapper, div[data-product-option]",n)),i.length>0){const t=i.filter((t=>!i.some((e=>e!==t&&e.contains(t)))));return new ot(t)}n=n.parentElement}return null}constructor(t){this.It=t}elements(){return this.It}hide(){for(const t of this.It)t.style.display="none",t.parentElement.classList.add("kaching-bundles--variant-selects-hidden")}select(t,e,n,i,r,o){l("VariantPicker#select",[t,e,n,i]),this.Pt(t,e,n,i,r)||this.St(t,n,i)||this.Ct(o)}Pt(t,e,n,i,r){const o=this.It.map((t=>[...t.querySelectorAll("input")])).flat();let a=o.filter((e=>[n,`${n}-${t}`,`options[${n}]`,`option${t}`,`option-${r}-${t-1}`].includes(e.name.trim())));a.length||(a=o.filter((e=>!!e.dataset.optionPosition&&Number(e.dataset.optionPosition)===t))),a.length||(a=o.filter((t=>"radio"===t.type)));const s=a.find((t=>t.value==i||t.value===String(e)));return!!s&&(l("VariantPicker#_clickRadioInput",s),s.click(),!0)}St(t,e,n){const i=this.It.map((t=>[...t.querySelectorAll("select")])).flat().find((n=>!![`options[${e}]`,`option${t}`].includes(n.name)||(n.dataset.index===`option${t}`||(n.dataset.optionName===e||(n.id==="SingleOptionSelector-product-"+(t-1)||n.id===`p-variant-dropdown-${t}`)))));if(!i)return!1;return!![...i.options].find((t=>t.value==n))&&(i.value===n?(l("VariantPicker#_setSelectValue - already set",{variantSelect:i,optionValue:n}),!0):(l("VariantPicker#_setSelectValue",{variantSelect:i,optionValue:n}),i.value=n,i.dispatchEvent(new Event("change",{bubbles:!0})),!0))}Ct(t){const e=this.It.map((t=>[...t.querySelectorAll("select")])).flat().find((e=>[...e.options].find((e=>Number(e.value)===t))));return!!e&&(e.value===String(t)?(l("VariantPicker#_setSelectVariantId - already set",{variantSelect:e,variantId:t}),!0):(l("VariantPicker#_setSelectVariantId",{variantSelect:e,variantId:t}),e.value=String(t),e.dispatchEvent(new Event("change",{bubbles:!0})),!0))}}class at{constructor(t){this.Nt=!1,this.qt=!1,this.element=t}onClickIfConditionMet(t,e,n){this.element.addEventListener("click",(async i=>{const r=t(),o=n();l("AddToCartButton#interceptClick",{conditionMet:r,preventDefault:o,submitInProgress:this.Nt,ignoreClick:this.qt}),r&&(this.Nt?this.Nt=!1:this.qt||(this.Nt=!0,this.qt=!0,this.element.disabled=!0,setTimeout((()=>{this.qt=!1}),1e3),i.preventDefault(),i.stopPropagation(),i.stopImmediatePropagation(),await e(),this.element.disabled=!1,o?this.Nt=!1:(await new Promise((t=>setTimeout(t,200))),this.element.click())))}),!0)}updatePrice(t){const e=this.$t(this.element);e&&(e.innerHTML=t.amount>0?t.formatted:"")}$t(t){if(!t.childNodes.length)return null;const e=t.childNodes[0].nodeValue;if(e&&e.match(/\d/)&&!e.match(/[a-zA-Z]{4}/)&&!e.includes("%"))return t;for(const n of t.childNodes){const t=this.$t(n);if(t)return t}return null}}let st,ct,ut=null,lt=[];const dt=async()=>{if(ut)return ut;ut=(async()=>{if(!st.storefrontAccessToken)return;const t=new j(st.storefrontAccessToken);ct=await L(t)})();try{await ut}catch(t){throw ut=null,t}},pt=async()=>{var t;await dt();const e=ct.filter((t=>{if(!t.abTestVariantId)return!0;const e=T(),n=O(e,t.abTestVariantsCount);return t.abTestVariantNumber===n})),n=null==(t=lt.find((t=>t.locale===st.locale)))?void 0:t.translations;return e.map((t=>{const e=(null==n?void 0:n.dealBlocks[t.id])||{};return ht(t,e)}))},ht=(t,e)=>{var n;const i=t=>({id:t.id,title:e[t.title]||t.title,mediaImageGID:t.mediaImageGID,freeGifts:s(t.freeGifts),upsells:c(t.upsells),dealBarType:"quantity-break",quantity:Number(t.quantity),discount:ft(t.discountType,t.discountValue)}),r=t=>({id:t.id,title:e[t.title]||t.title,mediaImageGID:t.mediaImageGID,freeGifts:s(t.freeGifts),upsells:c(t.upsells),dealBarType:"bxgy",buyQuantity:Number(t.buyQuantity),getQuantity:Number(t.getQuantity)}),o=t=>({id:t.id,title:e[t.title]||t.title,mediaImageGID:t.mediaImageGID,freeGifts:s(t.freeGifts),upsells:c(t.upsells),dealBarType:"bundle",bundleProducts:a(t.bundleProducts)}),a=t=>t.map((t=>({id:t.id,productId:"default"===t.productGID?"default":mt(t.productGID),variantId:t.variantGID?mt(t.variantGID):null,quantity:Number(t.quantity),discount:ft(t.discountType,t.discountValue)}))),s=t=>{if(!t)return[];return t.filter((t=>t.productGID)).map((t=>({id:t.id,productId:mt(t.productGID),variantId:t.variantGID?mt(t.variantGID):null,quantity:Number(t.quantity)})))},c=t=>t?t.map((t=>({id:t.id,productId:t.productGID?mt(t.productGID):null,variantId:t.variantGID?mt(t.variantGID):null,quantity:Number(t.quantity),discount:ft(t.discountType,t.discountValue)}))):[];return{id:t.id,nanoId:t.nanoId,collectionBreaksEnabled:null!=(n=t.collectionBreaksEnabled)&&n,differentVariantsEnabled:t.differentVariantsEnabled,dealBars:t.dealBars.map((t=>{switch(t.dealBarType){case void 0:case"quantity-break":return i(t);case"bxgy":return r(t);case"bundle":return o(t);default:return null}})).filter((t=>null!==t))}},ft=(t,e)=>t&&"default"!==t?{type:t,value:Number(e)}:null,mt=t=>Number(t.split("/").pop()),wt=['[data-pf-type^="ProductATC"]',"button.gp-button-atc","gp-product-button button","x-buy-button",'button[type="submit"]','input[type="submit"]'],_t=['form[action*="/cart/add"]',"form[data-instant-form-product-url]"],gt=()=>{"visualPreviewInitialLoad"!==new URLSearchParams(window.location.search).get("source")&&console.log('%c❗ [Kaching Bundles] Please add "Add to cart" button to the page template',"color: white; font-weight: bold; background: linear-gradient(90deg, #8181d7, #93e9e5); padding: 5px 8px; border-radius: 3px;")};class yt{constructor(t,e,n,i,r){this.N=null,this.q=null,this.C=null;const o={...e};o.moneyFormat=this.Tt(e.moneyFormat,i.showPricesWithoutDecimals),o.currencyRate=this.xt(e.currencyRate,i.currency),this.$=o,this.T=n,this.V=i,t.innerHTML='',g(t).initialized="true",this.S=h("kaching-bundles-block",t),this.t=this.Vt(),this.Ft(),this.At(),this.Dt(),this.Ot(),this.Bt(),this.jt(),this.Gt(),this.Et=new rt(this.S,this.t,this.C,this.N,this.q,this.$,n,i,r)}Tt(t,e){return e?t.includes("amount_no_decimals")?t:t.replace(/\{\{.+\}\}/g,"{{ amount_no_decimals }}"):t}xt(t,e){return e?window.Shopify.currency.active===e.currencyCode?1:1/e.currencyRate*t:t}Dt(){const t=this.Mt();t||gt();const e=t&&new at(t);this.C=e}Mt(){if(!this.t)return null;if(this.$.customSelectors.addToCartButton){const t=h(this.$.customSelectors.addToCartButton,this.t);if(t)return t}const t=[];for(const n of wt){const e=f(n,this.t);t.push(...e)}const e=k(this.S,t);return e||this.t.querySelector("button")}Ot(){this.C&&S(this.C.element,(()=>{var t;this.Dt(),l("observeAddToCartButtonRemoval found new add to cart button",this.C),s("add_to_cart_button_removed",{recreated:!!this.C,theme:null==(t=window.Shopify.theme)?void 0:t.schema_name},.01),this.Et.replaceAddToCartButton(this.C),this.Ot()}))}Bt(){const t=ot.find(this.S,this.$.customSelectors.variantPicker);t&&(this.V.hideVariantPicker&&t.hide(),this.q=t)}jt(){this.q&&S(this.q.elements()[0],(()=>{var t;this.Bt(),l("observeVariantPickerRemoval found new variant picker",this.q),s("variant_picker_removed",{recreated:!!this.q,theme:null==(t=window.Shopify.theme)?void 0:t.schema_name},.01),this.Et.replaceVariantPicker(this.q),this.jt()}))}Vt(){let t=this.S.parentElement;for(;t;){for(const e of _t)for(const n of[this.$.customSelectors.addToCartButton,...wt,"button"]){if(!n)continue;const i=h(`${e} ${n}`,t);if(i)return i.closest(e)}t=t.parentElement}return null}Ft(){const t=this.Ut(),e=k(this.S,t,6);if(!e)return;this.$.keepQuantityInput||(e.style.display="none");const n=e.matches("input")?e:e.querySelector("input");this.N=n}At(){this.N&&S(this.N,(()=>{var t;this.Ft(),l("observeQuantityInputRemoval found new quantity input",this.N),s("quantity_input_removed",{recreated:!!this.N,theme:null==(t=window.Shopify.theme)?void 0:t.schema_name},.01),this.Et.replaceQuantityInput(this.N),this.At()}))}Ut(){const t=this.$.customSelectors.quantity;if(t){const e=f(t);if(e.length)return e}for(const[e,n]of C){if(!n)continue;const t=f(n);if(t.length)return t}return f(".product-form__quantity")}Gt(){const t=setInterval((()=>{(void 0!==window.FastClick||void 0!==window.T4SThemeSP&&void 0!==window.T4SThemeSP.FastClick||void 0!==window.BEEThemeSP&&void 0!==window.BEEThemeSP.FastClick)&&(clearInterval(t),f("*",this.S).forEach((t=>{return n="needsclick",(e=t)&&e.classList.add(n);var e,n})))}),500)}}class bt{constructor(t){this.$=t,setTimeout((()=>{const t=document.querySelector('link[href*="kaching-bundles-block.css"]');t&&S(t,(()=>{var t;s("css_removed",{theme:null==(t=window.Shopify.theme)?void 0:t.schema_name},.01)}))}),100)}init(){this.Rt();const t=f("kaching-bundle, kaching-bundle-deals");this.Jt(t),0===t.length&&this.Qt(),this.zt(),this.$.abTestsRunning&&(async()=>{try{$();const t=T();await A()!==t&&await D(t)}catch(t){if(!(t instanceof N))throw t;console.error(t)}})()}Rt(){const t=y("script#kaching-bundles-translations")||[],e=t.find((t=>t.locale===this.$.locale));this.T=null==e?void 0:e.translations,(async t=>{lt=t})(t)}Jt(t){const e=y("script.kaching-bundles-product");if(e)for(const n of t)n.getAttribute("product-id")||n.setAttribute("product-id",e.id)}Qt(){if(!h("script.kaching-bundles-deal-block-settings"))return;const t=this.Lt();if(!t.length)return void gt();const e=y("script.kaching-bundles-product"),n=e&&e.id||this.$.productId;for(const i of t){const t=w("kaching-bundle");t.setAttribute("product-id",n),i.parentElement.insertBefore(t,i)}}async zt(){var t,e;const n=[...f("kaching-bundle, kaching-bundle-deals")].filter((t=>t.getAttribute("product-id")));l("_initializePlaceholders",n);if(0===n.filter((t=>!g(t).initialized)).length)return;const i=await this.Kt(n);l("placeholdersData",i);const r=Array.from(i.values()).map((({dealBlock:t})=>t)).filter((t=>null!=t)),o=Array.from(i.values()).map((({product:t})=>t)).filter((t=>null!=t));await Z(this.$.storefrontAccessToken,o,r);const s=T();for(const c of n){const n=Number(c.getAttribute("product-id")),{product:r,dealBlock:o}=i.get(n);if(!r||!o)continue;this.$.webPixel?(l("Tracking view with web pixel",window.Shopify.analytics),setTimeout((()=>{var t;null==(t=window.Shopify.analytics)||t.publish("kaching_bundle_viewed",{product_id:n,deal_block_id:o.id,ab_test_variant_id:o.abTestVariantId,session_id:s})}))):(l("Tracking view without web pixel (legacy)"),setTimeout((()=>{a(this.$.shopifyDomain,o.id,n,o.abTestVariantId,s)}),2e3));const u={...{...this.$.defaultTranslations,...null==(t=this.T)?void 0:t.system},...null==(e=this.T)?void 0:e.dealBlocks[o.id]};new yt(c,this.$,u,o,r)}}async Kt(t){var e;const n=t.map((t=>Number(t.getAttribute("product-id")))),i=this.$.locale===this.$.liquidLocale?[...f("script.kaching-bundles-product")]:[],r=new Map(i.map((t=>{const e=Number(g(t).productId),n=JSON.parse(t.textContent);return 250===n.variants.length?null:[e,n]})).filter((t=>null!==t))),o=n.filter((t=>!r.has(t))),a=[...f("script.kaching-bundles-deal-block-settings")],s=new Map;for(const l of n){const t=a.filter((t=>Number(g(t).productId)===l));t.length&&s.set(l,t.map((t=>t.textContent?JSON.parse(t.textContent):null)))}const c=n.filter((t=>!s.has(t))),u=this.$.storefrontAccessToken?new j(this.$.storefrontAccessToken):null,d=o.length>0&&u?M(u,{country:window.Shopify.country,language:window.Shopify.locale.split("-")[0].toUpperCase(),productIds:o,removeUnavailableVariants:!1,includeSellingPlans:this.$.accessScopes.includes("unauthenticated_read_selling_plans")}):[],p=c.length>0&&u?L(u):[],[h,m]=await Promise.all([d,p]),w=new Map(o.map((t=>[t,h.find((e=>e.id==t))]))),_=new Map([...r,...w]),y=T(),b=new Map;for(const f of n){const t=_.get(f);if(!t)continue;const n=(null==(e=s.get(f))?void 0:e.filter((t=>t)))||m;n.sort(((t,e)=>{const n=!!t.marketId;return n===!!e.marketId?0:n?-1:1}));let i=this.Ht(n,t);l("applicableDealBlocks",i),i=i.filter((t=>!t.marketId||t.marketId===this.$.marketId)),i=i.filter((t=>{if(!t.abTestVariantId)return!0;const e=O(y,t.abTestVariantsCount);return t.abTestVariantNumber===e})),this.$.b2bCustomer&&(i=i.filter((t=>!t.excludeB2bCustomers))),i.length?b.set(f,{product:t,dealBlock:i[0]}):b.set(f,{product:t,dealBlock:null})}return b}Ht(t,e){const n=[],i=t.filter((t=>"selected-products"===t.blockVisibility));for(const s of i)s.selectedProductIds.map(Number).includes(e.id)&&n.push(s);const r=t.filter((t=>"selected-collections"===t.blockVisibility));for(const s of r)e.collectionIds.some((t=>s.selectedCollectionIds.map(Number).includes(t)))&&n.push(s);const o=t.filter((t=>"excluded-products"===t.blockVisibility));for(const s of o)s.excludedProductIds.map(Number).includes(e.id)||(s.excludedCollectionIds||[]).some((t=>e.collectionIds.includes(t)))||n.push(s);const a=t.filter((t=>"all-products"===t.blockVisibility));for(const s of a)n.push(s);return n}Lt(){const t=this.Wt();if(t)return[t];const e=this.Xt();if(e)return[e];const n=this.Yt();return n?[n]:[]}Wt(){const t=f("gp-product-button");for(const e of t)if(!e.closest("gp-sticky"))return e;return null}Xt(){for(const t of C){const e=h(t[0]);if(e){if(e.closest(".dbtfy-sticky-addtocart, .cart-drawer, cart-drawer"))continue;return setTimeout((()=>{var n;const i=e.closest('[class*="cart"], [class*="Cart"]');i&&"body"!==i.tagName.toLowerCase()&&(i.classList.toString().includes("add-to-cart")||i.classList.toString().includes("AddToCart")||i.classList.toString().includes("icartShopifyCartContent")||s("theme_position_in_cart_drawer_v8",{selector:t[0],classes:i.classList.toString(),theme:null==(n=window.Shopify.theme)?void 0:n.schema_name},.01))})),e}}return null}Yt(){for(const t of _t)for(const e of[this.$.customSelectors.addToCartButton,...wt,"button"]){if(!e)continue;const n=h(`${t} ${e}`);if(n)return n.parentElement}return null}}const vt=t=>{var e;801===(null==(e=window.Shopify.theme)?void 0:e.theme_store_id)?setTimeout((()=>new bt(t).init()),100):new bt(t).init()},kt=()=>{if(void 0===n&&(n="off"===e()),n){const t=f("style#kaching-bundles-custom-css");for(const e of t)e.remove();return}r()&&(l("App version",(()=>{const t=document.currentScript;if(!t)return null;const e=t.src.match(/\/([^/]+)\/assets\//);return e&&e[1]?e[1]:null})()),l("Shopify domain",window.Shopify.shop));const t=y("script#kaching-bundles-config");if(!t)return;u();const i=window.Shopify.currency;t.currencyRate=i?Number(i.rate):1,t.locale=window.Shopify.locale||t.liquidLocale,window.kachingBundlesKeepQuantityInput&&(t.keepQuantityInput=!0),vt(t),window.Shopify.designMode&&m(window,"shopify:section:load",(()=>{vt(t)})),(()=>{const t=/\b__kaching_/,e=["script","style"],n=n=>{const i=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode:t=>{const n=t.parentElement;return!n||e.includes(n.tagName.toLowerCase())?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}});let r;for(;r=i.nextNode();){const e=r.textContent||"";if(t.test(e)){const t=r.parentElement;if(t.classList.contains("properties-key-value-key"))continue;if("dt"===t.tagName.toLowerCase()){const e=t.nextElementSibling;"dd"===(null==e?void 0:e.tagName.toLowerCase())&&(e.style.display="none")}t.style.display="none",s("kaching_property_hidden",{text:e,element:t.tagName},.01)}}};new MutationObserver((t=>{for(const e of t)for(const t of e.addedNodes)t.nodeType===Node.ELEMENT_NODE&&n(t)})).observe(document.body,{childList:!0,subtree:!0}),n(document.body)})(),(()=>{const t=document.querySelector('link[href*="kaching-bundles-block.css"]');if(!t)return;const e=t.closest('div[data-block-type="liquid"]');e&&(e.dataset.blockType="liquid-kaching-fix")})(),window.kachingBundlesApi=(st=t,{fetchDeals:pt}),setTimeout((()=>{dt()}),1e3)};window.kachingBundlesDisableAutoInitialize||kt(),window.kachingBundlesInitialize=kt}();