1(()=>{const WIDGET_SELECTOR="[data-custom-skio-widget]",normalizeString=(value="")=>value.toLowerCase().replace(/\s+/g," ").trim(),extractNumericTokens=(value="")=>value.match(/\d+/g)||[],CADENCE_TO_DAYS={day:1,days:1,week:7,weeks:7,month:30,months:30},toInteger=(value,fallback=0)=>{const parsed=Number.parseInt(value,10);return Number.isFinite(parsed)?parsed:fallback},parseCents=value=>{if(value==null||value==="")return null;const parsed=Number(value);return Number.isFinite(parsed)?parsed:null},extractQuantity=(value="")=>{const normalizedValue=String(value||"").trim(),quantityMatch=normalizedValue.match(/(\d+)\s*(bag|bags|box|boxes)\b/i);if(quantityMatch)return toInteger(quantityMatch[1],null);const numericOnlyMatch=normalizedValue.match(/^(\d+)$/);return numericOnlyMatch?toInteger(numericOnlyMatch[1],null):null},isQuantityLabel=(value="")=>extractQuantity(value)!==null,splitLines=(value="")=>value.split("||").map(line=>line.trim()).filter(Boolean),HTML_ESCAPES={"&":"&","<":"<",">":">",'"':""","'":"'"},escapeHtml=(value="")=>String(value).replace(/[&<>"']/g,character=>HTML_ESCAPES[character]),formatMoney=cents=>{if(!Number.isFinite(cents))return"";try{return new Intl.NumberFormat(navigator.language||"en-US",{style:"currency",currency:window.Shopify&&window.Shopify.currency&&window.Shopify.currency.active||"USD"}).format(cents/100)}catch{return`$${(cents/100).toFixed(2)}`}},namesMatch=(requestedName="",candidateName="")=>{const normalizedRequested=normalizeString(requestedName),normalizedCandidate=normalizeString(candidateName);if(!normalizedRequested||!normalizedCandidate)return!1;if(normalizedRequested===normalizedCandidate||normalizedCandidate.includes(normalizedRequested)||normalizedRequested.includes(normalizedCandidate))return!0;const requestedNumericTokens=extractNumericTokens(normalizedRequested);return requestedNumericTokens.length>0&&requestedNumericTokens.every(token=>normalizedCandidate.includes(token))},getCadenceDays=(value="")=>{const cadenceMatch=normalizeString(value).match(/(\d+)\s*(day|days|week|weeks|month|months)/);if(!cadenceMatch)return null;const cadenceCount=toInteger(cadenceMatch[1],0),cadenceUnit=CADENCE_TO_DAYS[cadenceMatch[2]];return!cadenceCount||!cadenceUnit?null:cadenceCount*cadenceUnit},findCadenceMatch=(requestedName="",candidates=[])=>{const requestedDays=getCadenceDays(requestedName);if(!requestedDays)return null;const nearestMatch=candidates.map(candidate=>({...candidate,cadenceDays:getCadenceDays(candidate.name)})).filter(candidate=>candidate.cadenceDays!==null).sort((left,right)=>Math.abs(left.cadenceDays-requestedDays)-Math.abs(right.cadenceDays-requestedDays))[0];return!nearestMatch||Math.abs(nearestMatch.cadenceDays-requestedDays)>7?null:nearestMatch};class CustomSkioWidget{constructor(root){this.root=root,this.root.dataset.customSkioWidgetInitialized="true",this.formId=this.root.dataset.formId,this.hasSellingPlans=this.root.dataset.hasSellingPlans==="true",this.defaultOptionKey=this.root.dataset.defaultOption,this.oneTimeOptionKey=this.root.dataset.oneTimeOption||this.defaultOptionKey,this.form=document.getElementById(this.formId),this.section=this.root.closest("product-info")||this.root.closest(".product__info-container")||document,this.optionButtons=[...this.root.querySelectorAll("[data-custom-skio-option]")],this.modeButtons=[...this.root.querySelectorAll("[data-custom-skio-mode]")],this.mixFlavorsLink=this.root.querySelector("[data-custom-skio-mix-flavors]"),this.quantityInput=this.root.querySelector("[data-custom-skio-quantity-input]")||this.form?.querySelector('input[name="quantity"]'),this.nativeFieldset=null,this.nativeBlock=null,this.nativeSubscriptionRadio=null,this.nativeOneTimeRadio=null,this.nativeSelect=null,this.sellingPlanInput=null,this.productJsonNode=null,this.productData=null,this.currentOption=null,this.currentMode=this.hasSellingPlans?"subscription":"one-time",this.lastSubscriptionOption=null,this.hasModeInteraction=!1,this.cart=document.querySelector("cart-drawer")||document.querySelector("cart-notification"),this.freeGiftsByOption=this.parseFreeGiftsJson(),this.handleOptionClick=this.handleOptionClick.bind(this),this.handleModeClick=this.handleModeClick.bind(this),this.handleSectionChange=this.handleSectionChange.bind(this),this.handleFormSubmit=this.handleFormSubmit.bind(this),this.handleCartUpdate=this.handleCartUpdate.bind(this),this.optionButtons.forEach(button=>button.addEventListener("click",this.handleOptionClick)),this.modeButtons.forEach(button=>button.addEventListener("click",this.handleModeClick)),this.section.addEventListener("change",this.handleSectionChange),this.form?.addEventListener("submit",this.handleFormSubmit,!0),subscribe(PUB_SUB_EVENTS.cartUpdate,this.handleCartUpdate),this.refresh({syncModeFromNative:!0}),this.hideNativeWidgetIfNeeded()}parseProductData(){if(!this.productJsonNode)return null;try{return JSON.parse(this.productJsonNode.textContent)}catch{return null}}parseFreeGiftsJson(){const node=this.root.querySelector("script[data-custom-skio-free-gifts-json]");if(!node)return{};try{return JSON.parse(node.textContent)||{}}catch{return{}}}getFreeGifts(optionButton){const key=optionButton?.dataset.optionKey;return key&&this.freeGiftsByOption[key]||[]}ensureSellingPlanInput(){if(!this.form)return null;let input=this.form.querySelector('input[name="selling_plan"]');return input||(input=document.createElement("input"),input.type="hidden",input.name="selling_plan",input.dataset.customSkioManaged="true",this.form.appendChild(input),input)}refreshNativeReferences(){const managedSellingPlanInput=this.form?.querySelector('input[name="selling_plan"][data-custom-skio-managed]');this.nativeFieldset=this.section.querySelector("fieldset[skio-plan-picker]"),this.nativeBlock=this.nativeFieldset?this.nativeFieldset.closest(".shopify-app-block"):null,this.nativeSubscriptionRadio=this.nativeFieldset?this.nativeFieldset.querySelector("input[skio-selling-plan-group]"):null,this.nativeOneTimeRadio=this.nativeFieldset?this.nativeFieldset.querySelector("input[skio-one-time]"):null,this.nativeSelect=this.nativeFieldset?this.nativeFieldset.querySelector("select[skio-selling-plans]"):null;const nativeSellingPlanInput=this.nativeFieldset&&this.nativeFieldset.querySelector(`input[name="selling_plan"][form="${this.formId}"]`)||document.querySelector(`input[name="selling_plan"][form="${this.formId}"]`);nativeSellingPlanInput&&managedSellingPlanInput&&nativeSellingPlanInput!==managedSellingPlanInput&&managedSellingPlanInput.remove(),this.sellingPlanInput=this.form?.querySelector('input[name="selling_plan"]')||nativeSellingPlanInput||(this.hasSellingPlans?this.ensureSellingPlanInput():null),this.productJsonNode=this.root.querySelector("script[data-custom-skio-product-json]")||this.nativeFieldset&&this.nativeFieldset.querySelector("script[skio-product-json]"),this.productData=this.parseProductData()}resolveInitialMode(){return!this.hasSellingPlans||this.nativeOneTimeRadio?.checked?"one-time":this.sellingPlanInput?.value||this.nativeSubscriptionRadio?.checked||this.modeButtons.find(button=>button.dataset.customSkioMode==="subscription")?"subscription":"one-time"}getCurrentVariant(){if(!this.productData||!this.productData.variants||
1!this.productData.variants.length)return null;const variantId=this.form?this.form.querySelector('[name="id"]')?.value:null;return this.productData.variants.find(variant=>String(variant.id)===String(variantId))||this.productData.variants[0]}getVariantQuantity(variant){return variant?extractQuantity(variant.option2)||extractQuantity(variant.option1)||extractQuantity(variant.option3)||extractQuantity(variant.title):null}getVariantFlavorKey(variant){return variant&&[variant.option1,variant.option2,variant.option3].find(value=>value&&!isQuantityLabel(value))||null}getPricingVariant(optionButton){if(!this.productData?.variants?.length)return null;const requestedQuantity=Math.max(toInteger(optionButton.dataset.quantity,1),1),currentVariant=this.getCurrentVariant(),currentFlavor=this.getVariantFlavorKey(currentVariant),variants=this.productData.variants,flavorMatches=currentFlavor?variants.filter(variant=>this.getVariantFlavorKey(variant)===currentFlavor):variants;return(flavorMatches.length?flavorMatches:variants).find(variant=>this.getVariantQuantity(variant)===requestedQuantity)||variants.find(variant=>this.getVariantQuantity(variant)===requestedQuantity)||currentVariant||variants[0]}getSellingPlans(){return!this.productData||!this.productData.selling_plan_groups?[]:this.productData.selling_plan_groups.flatMap(group=>(group.selling_plans||[]).map(plan=>({id:String(plan.id),name:plan.name})))}getSelectOptions(){return this.nativeSelect?[...this.nativeSelect.options].filter(option=>option.value).map(option=>({id:String(option.value),name:option.textContent.trim()})):[]}getPlanMatch(optionButton){if(!this.hasSellingPlans)return null;if(this.root.dataset.varietyPack==="true"){const variant=this.getPricingVariant(optionButton),quantity=Math.max(toInteger(optionButton.dataset.quantity,1),1),discountPercent={1:15,2:20,3:25}[quantity],basePrice=parseCents(variant?.price);if(!discountPercent||!basePrice)return null;const expectedUnitCents=basePrice*(1-discountPercent/100),plan=this.getSellingPlans().find(candidate=>{const allocation=this.getPlanAllocation(variant,candidate.id),price=parseCents(allocation?.price);return getCadenceDays(candidate.name)===28&&price!==null&&Math.abs(price-expectedUnitCents)<=1});return plan?{...plan,matchType:"name"}:null}const requestedName=normalizeString(optionButton.dataset.planName),requestedPosition=toInteger(optionButton.dataset.planPosition,1)-1,sellingPlans=this.getSellingPlans(),selectOptions=this.getSelectOptions();if(requestedName){const planMatch=sellingPlans.find(plan=>namesMatch(requestedName,plan.name));if(planMatch)return{...planMatch,matchType:"name"};const cadencePlanMatch=findCadenceMatch(requestedName,sellingPlans);if(cadencePlanMatch)return{...cadencePlanMatch,matchType:"cadence"};const selectMatch=selectOptions.find(option=>namesMatch(requestedName,option.name));if(selectMatch)return{...selectMatch,matchType:"name"};const cadenceSelectMatch=findCadenceMatch(requestedName,selectOptions);if(cadenceSelectMatch)return{...cadenceSelectMatch,matchType:"cadence"}}return!requestedName&&sellingPlans[requestedPosition]?{...sellingPlans[requestedPosition],matchType:"position"}:!requestedName&&selectOptions[requestedPosition]?{...selectOptions[requestedPosition],matchType:"position"}:sellingPlans[0]?{...sellingPlans[0],matchType:"default"}:selectOptions[0]?{...selectOptions[0],matchType:"default"}:null}getPlanAllocation(variant,planId){return!variant||!variant.selling_plan_allocations||!variant.selling_plan_allocations.length?null:variant.selling_plan_allocations.find(allocation=>String(allocation.selling_plan_id)===String(planId))||null}getOptionState(optionButton){const variant=this.getPricingVariant(optionButton),planMatch=this.getPlanMatch(optionButton),quantity=Math.max(toInteger(optionButton.dataset.quantity,1),1),canUseLivePlanPricing=planMatch&&(planMatch.matchType==="name"||planMatch.matchType==="position"),allocation=canUseLivePlanPricing?this.getPlanAllocation(variant,planMatch&&planMatch.id):null,basePriceCents=parseCents(variant?.price)??parseCents(this.productData?.price),allocationPriceCents=parseCents(allocation?.price),subscriptionCents=allocationPriceCents!==null?allocationPriceCents*quantity:null,comparePriceCents=basePriceCents!==null?basePriceCents*quantity:null,hasPlanPricing=this.hasSellingPlans&&!!(planMatch||this.get
1SellingPlans().length),summaryOverride=optionButton.dataset.summary?.trim(),subscriptionPriceOverride=optionButton.dataset.subscriptionPriceOverride?.trim(),subscriptionCompareOverride=optionButton.dataset.subscriptionComparePriceOverride?.trim(),oneTimePriceOverride=optionButton.dataset.oneTimePriceOverride?.trim(),captionOverride=optionButton.dataset.cardCaption?.trim(),detailLines=hasPlanPricing?splitLines(optionButton.dataset.detailLines||""):[],title=optionButton.querySelector(".custom-skio-widget__option-title")?.textContent.trim()||optionButton.dataset.optionKey,hasLiveComparePrice=comparePriceCents!==null,hasLiveSubscriptionPrice=canUseLivePlanPricing&&subscriptionCents!==null,liveSummaryText=hasLiveComparePrice&&hasLiveSubscriptionPrice&&comparePriceCents>subscriptionCents?`Save ${formatMoney(comparePriceCents-subscriptionCents)}`:"",isVarietyPack=this.root.dataset.varietyPack==="true",subscriptionPriceText=hasPlanPricing?hasLiveSubscriptionPrice?formatMoney(subscriptionCents):subscriptionPriceOverride||(hasLiveComparePrice?formatMoney(comparePriceCents):""):hasLiveComparePrice?formatMoney(comparePriceCents):oneTimePriceOverride||"",subscriptionCompareText=hasPlanPricing?hasLiveComparePrice?formatMoney(comparePriceCents):subscriptionCompareOverride||"":"",oneTimePriceText=hasLiveComparePrice?formatMoney(comparePriceCents):oneTimePriceOverride||"",summaryText=hasPlanPricing&&(isVarietyPack?summaryOverride||liveSummaryText:liveSummaryText||summaryOverride)||"",captionText=isVarietyPack&&hasLiveSubscriptionPrice?`${formatMoney(subscriptionCents/(quantity*10))}/serving`:captionOverride||(canUseLivePlanPricing&&planMatch?planMatch.name:""),freeGifts=this.getFreeGifts(optionButton);return{quantity,planId:planMatch?String(planMatch.id):"",planName:planMatch?planMatch.name:"",title,captionText,summaryText,subscriptionPriceText,subscriptionCompareText,oneTimePriceText,detailLines,freeGifts}}refreshOptionCards(){this.optionButtons.forEach(button=>{const state=this.getOptionState(button),priceNode=button.querySelector('[data-custom-skio-render="card-price"]'),compareNode=button.querySelector('[data-custom-skio-render="card-compare-price"]'),captionNode=button.querySelector('[data-custom-skio-render="card-caption"]'),overridePrice=button.dataset.subscriptionPriceOverride?.trim(),overrideCompare=button.dataset.subscriptionComparePriceOverride?.trim(),cardPriceText=state.subscriptionPriceText||overridePrice,cardCompareText=state.subscriptionCompareText||overrideCompare;if(priceNode&&(priceNode.textContent=cardPriceText),compareNode){const compareVisible=cardCompareText&&cardCompareText!==cardPriceText;compareNode.textContent=compareVisible?cardCompareText:"",compareNode.classList.toggle("is-hidden",!compareVisible)}captionNode&&(captionNode.textContent=state.captionText,captionNode.classList.toggle("is-hidden",!state.captionText))})}getInitialOption(){return this.getOptionByKey(this.defaultOptionKey)||this.optionButtons[0]||null}getOptionByKey(key){return this.optionButtons.find(button=>button.dataset.optionKey===key)||null}getOneTimeOption(){const configuredOption=this.getOptionByKey(this.oneTimeOptionKey);return configuredOption&&toInteger(configuredOption.dataset.quantity,0)===1?configuredOption:this.optionButtons.find(button=>toInteger(button.dataset.quantity,0)===1)||configuredOption||this.optionButtons[this.optionButtons.length-1]||null}getOneTimeModeButton(){return this.modeButtons.find(button=>button.dataset.customSkioMode==="one-time")||null}isOneTimeAvailable(optionButton=this.currentOption){if(!this.hasSellingPlans)return!0;const oneTimeOption=this.getOneTimeOption();return!!(optionButton&&oneTimeOption&&optionButton.dataset.optionKey===oneTimeOption.dataset.optionKey&&toInteger(optionButton.dataset.quantity,0)===1)}renderOneTimeAvailability(optionButton=this.currentOption){const oneTimeButton=this.getOneTimeModeButton();if(!oneTimeButton)return;const isAvailable=this.isOneTimeAvailable(optionButton);oneTimeButton.hidden=!isAvailable,oneTimeButton.classList.toggle("is-hidden",!isAvailable)}refresh({syncModeFromNative=!1}={}){this.refreshNativeReferences(),this.optionButtons.length&&(syncModeFromNative&&(this.currentMode=this.resolveInitialMode()),this.hasSellingPlans||(this.currentMode="one-time"),this.refreshOptionCards(),this.currentOption=this.currentOption||this.getInitialOption(),this.currentOption&&(this.currentMode==="one-time"&&!this.isOneTimeAvailable(this.currentOption)&&(this.currentMode="subscription"),this.setSelectedOption(this.currentOption,{syncNative:!1}),this.modeButtons.find(button=>button.dataset.customSkioMode===this.currentMode)||(this.currentMode="subscription"),this.setMode(this.currentMode,{syncNative:!1}),this.syncNativeState()))}setSelectedOption(optionButton,{syncNative=!0,rememberSubscriptionSelection=this.currentMode==="subscription"}={}){this.currentOption=optionButton;const optionState=this.getOptionState(optionButton);rememberSubscriptionSelection&&(this.lastSubscriptionOption=optionButton),this.optionButtons.forEach(button=>{const isSelected=button===optionButton;button.classList.toggle("is-selected",isSelected),button.setAttribute("aria-checked",String(isSelected))}),this.quantityInput&&(this.quantityInput.value=String(optionState.quantity)),this.renderDeliveryState(optionState),this.renderMixFlavorsState(optionState),this.renderOneTimeAvailability(optionButton),syncNative&&this.syncNativeState()}setMode(mode,{syncNative=!0}={}){if(this.hasSellingPlans||(mode="one-time"),mode==="one-time"){if(this.currentMode!=="one-time"&&this.currentOption&&(this.lastSubscriptionOption=this.currentOption),this.hasSellingPlans){const oneTimeOption=this.getOneTimeOption();oneTimeOption&&this.currentOption!==oneTimeOption&&this.setSelectedOption(oneTimeOption,{syncNative:!1,rememberSubscriptionSelection:!1})}}else{const subscriptionOption=this.lastSubscriptionOption||this.getInitialOption();subscriptionOption&&this.currentOption!==subscriptionOption&&this.setSelectedOption(subscriptionOption,{syncNative:!1,rememberSubscriptionSelection:!0}
1)}this.currentMode=mode,this.modeButtons.forEach(button=>{const isSelected=button.dataset.customSkioMode===mode;button.classList.toggle("is-selected",isSelected),button.setAttribute("aria-checked",String(isSelected))}),this.currentOption&&(this.renderMixFlavorsState(this.getOptionState(this.currentOption)),this.renderOneTimeAvailability(this.currentOption)),syncNative&&this.syncNativeState()}renderDeliveryState(optionState){const summaryNode=this.root.querySelector('[data-custom-skio-render="summary"]'),subscriptionPriceNode=this.root.querySelector('[data-custom-skio-render="subscription-price"]'),subscriptionCompareNode=this.root.querySelector('[data-custom-skio-render="subscription-compare-price"]'),detailsNode=this.root.querySelector('[data-custom-skio-render="details"]'),oneTimePriceNode=this.root.querySelector('[data-custom-skio-render="one-time-price"]'),oneTimeMetaNode=this.root.querySelector('[data-custom-skio-render="one-time-meta"]');if(summaryNode&&(summaryNode.textContent=optionState.summaryText,summaryNode.classList.toggle("is-hidden",!optionState.summaryText)),subscriptionPriceNode&&(subscriptionPriceNode.textContent=optionState.subscriptionPriceText),subscriptionCompareNode){const compareVisible=optionState.subscriptionCompareText&&optionState.subscriptionCompareText!==optionState.subscriptionPriceText;subscriptionCompareNode.textContent=compareVisible?optionState.subscriptionCompareText:"",subscriptionCompareNode.classList.toggle("is-hidden",!compareVisible)}detailsNode&&(detailsNode.innerHTML=optionState.detailLines.map(line=>`<li>${line}</li>`).join(""),detailsNode.classList.toggle("is-hidden",optionState.detailLines.length===0)),this.renderFreeGifts(optionState),oneTimePriceNode&&(oneTimePriceNode.textContent=optionState.oneTimePriceText),oneTimeMetaNode&&(oneTimeMetaNode.textContent=optionState.title,oneTimeMetaNode.classList.toggle("is-hidden",!optionState.title))}renderMixFlavorsState(optionState){if(!this.mixFlavorsLink)return;const shouldShow=this.currentMode==="subscription"&&optionState.quantity>1;this.mixFlavorsLink.classList.toggle("is-hidden",!shouldShow)}renderFreeGifts(optionState){const container=this.root.querySelector('[data-custom-skio-render="free-gifts"]'),listNode=this.root.querySelector('[data-custom-skio-render="free-gifts-list"]');if(!container||!listNode)return;const gifts=optionState.freeGifts||[];listNode.innerHTML=gifts.map(gift=>`<li>${gift.image?`<img class="custom-skio-widget__free-gifts-thumb" src="${escapeHtml(gift.image)}" width="40" height="40" loading="lazy" alt="">`:""}<span>${escapeHtml(gift.title)}</span></li>`).join(""),container.classList.toggle("is-hidden",gifts.length===0)}syncNativeState(){if(this.refreshNativeReferences(),!this.currentOption)return;const optionState=this.getOptionState(this.currentOption);this.currentMode==="one-time"?(this.nativeOneTimeRadio&&(this.nativeOneTimeRadio.checked=!0,this.dispatchValueEvents(this.nativeOneTimeRadio)),this.sellingPlanInput&&(this.sellingPlanInput.value="",this.dispatchValueEvents(this.sellingPlanInput))):(this.nativeSubscriptionRadio&&(this.nativeSubscriptionRadio.checked=!0,this.dispatchValueEvents(this.nativeSubscriptionRadio)),this.nativeSelect&&optionState.planId&&(this.nativeSelect.value=optionState.planId,this.dispatchValueEvents(this.nativeSelect)),this.sellingPlanInput&&(this.sellingPlanInput.value=optionState.planId||(this.nativeSelect?this.nativeSelect.value:""),this.dispatchValueEvents(this.sellingPlanInput))),this.updateNativeClasses()}updateNativeClasses(){if(!this.nativeFieldset)return;const subscriptionContainer=this.nativeSubscriptionRadio?this.nativeSubscriptionRadio.closest("[skio-group-container]"):null,oneTimeContainer=this.nativeOneTimeRadio?this.nativeOneTimeRadio.closest("[skio-group-container]"):null,subscriptionSelected=this.currentMode==="subscription";subscriptionContainer?.classList.toggle("skio-group-container--selected",subscriptionSelected),oneTimeContainer?.classList.toggle("skio-group-container--selected",!subscriptionSelected)}hideNativeWidgetIfNeeded(){this.root.dataset.hideNative!=="true"||!this.nativeBlock||this.nativeBlock.classList.add("custom-skio-widget__native-hidden")}
1dispatchValueEvents(element){element&&(element.dispatchEvent(new Event("input",{bubbles:!0})),element.dispatchEvent(new Event("change",{bubbles:!0})))}handleOptionClick(event){event.preventDefault();const optionButton=event.currentTarget;if(this.hasSellingPlans&&this.currentMode==="one-time"&&optionButton.dataset.optionKey!==this.oneTimeOptionKey){this.setSelectedOption(optionButton,{syncNative:!1,rememberSubscriptionSelection:!0}),this.setMode("subscription");return}this.setSelectedOption(optionButton)}handleModeClick(event){event.preventDefault(),this.hasModeInteraction=!0,this.setMode(event.currentTarget.dataset.customSkioMode)}handleSectionChange(event){const target=event.target;target&&(target.name==="id"||target.matches("variant-selects select, variant-radios input")||target.closest("variant-selects, variant-radios"))&&window.requestAnimationFrame(()=>{if(this.refreshNativeReferences(),this.refreshOptionCards(),this.currentOption){const optionState=this.getOptionState(this.currentOption);this.renderDeliveryState(optionState),this.renderMixFlavorsState(optionState)}})}handleFormSubmit(event){if(this.root.dataset.varietyPack==="true"&&this.currentMode==="subscription"&&!this.getOptionState(this.currentOption).planId){event.preventDefault(),event.stopImmediatePropagation(),this.form?.closest("product-form")?.handleErrorMessage("This subscription option is temporarily unavailable. Please try another option.");return}this.syncNativeState(),this.pendingGiftSubmission={variantId:this.form?.querySelector('[name="id"]')?.value,planId:this.sellingPlanInput?.value,giftVariantIds:this.currentMode==="subscription"?this.getFreeGiftVariantIds(this.currentOption):[]}}getFreeGiftVariantIds(optionButton){return this.getFreeGifts(optionButton).map(gift=>gift.variantId).filter(Boolean)}handleCartUpdate(payload){if(!payload||payload.source!=="product-form"||payload.formId!==this.formId)return;const submission=this.pendingGiftSubmission;if(this.pendingGiftSubmission=null,!(!submission?.planId||!submission.giftVariantIds.length||!(payload.cartData?.items||[payload.cartData]).some(item=>String(item?.variant_id||item?.id)===String(submission.variantId)&&String(item?.selling_plan_allocation?.selling_plan?.id)===String(submission.planId))))return this.addFreeGifts(submission.giftVariantIds,submission.variantId).catch(error=>console.error("[custom-skio-widget] Failed to verify free gifts",error))}async addFreeGifts(giftVariantIds,parentVariantId){const cartResponse=await fetch(window.Shopify.routes.root+"cart.js");if(!cartResponse.ok)throw new Error("Unable to verify gift eligibility");const cart=await cartResponse.json();if(!cart.items.some(item=>String(item.variant_id)===String(parentVariantId)&&item.selling_plan_allocation)||(giftVariantIds=[...new Set(giftVariantIds)].filter(id=>!cart.items.some(item=>String(item.variant_id)===String(id))),!giftVariantIds.length))return;const config=fetchConfig("json");return config.body=JSON.stringify({items:giftVariantIds.map(variantId=>({id:Number(variantId),quantity:1,properties:{_subscription_gift_parent:String(parentVariantId)}})),sections:this.cart?this.cart.getSectionsToRender().map(section=>section.id):[],sections_url:window.location.pathname}),fetch(routes.cart_add_url,config).then(response=>response.json()).then(response=>{if(response.status){console.error("[custom-skio-widget] Failed to add free gifts",response.errors||response.description);return}this.cart&&this.cart.renderContents(response)}).catch(error=>console.error("[custom-skio-widget] Failed to add free gifts",error))}}const initWidgets=(scope=document)=>{(scope.matches?.(WIDGET_SELECTOR)?[scope]:[...scope.querySelectorAll?.(WIDGET_SELECTOR)||[]]).forEach(widget=>{widget.dataset.customSkioWidgetInitialized!=="true"&&(widget.__customSkioWidget=new CustomSkioWidget(widget))})};document.addEventListener("DOMContentLoaded",()=>{initWidgets(),new MutationObserver(mutations=>{mutations.forEach(mutation=>{mutation.addedNodes.forEach(node=>{node.nodeType===Node.ELEMENT_NODE&&initWidgets(node)})})}).observe(document.body,{childList:!0,subtree:!0})}),document.addEventListener("shopify:section:load",event=>initWidgets(event.target)),document.addEventListener("skio:widget-loaded",()=>{initWidgets(),document.querySelectorAll(WIDGET_SELECTOR).forEac
1h(widget=>{const customSkioWidget=widget.__customSkioWidget;customSkioWidget&&(customSkioWidget.refresh({syncModeFromNative:!customSkioWidget.hasModeInteraction}),customSkioWidget.hideNativeWidgetIfNeeded())})})})(); 2//# sourceMappingURL=/cdn/shop/t/54/assets/custom-skio-widget.js.map?v=79195081721176767211789233532
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.