if(!customElements.get("variant-picker")){class VariantPicker extends HTMLElement{constructor(){super(),this.section=this.closest(".js-product"),this.productForm=this.section.querySelector(".js-product-form-main"),this.optionSelectors=this.querySelectorAll(".option-selector"),this.data=this.getProductData(),this.variant=this.getSelectedVariant(),this.updateAvailability(),this.updateAddToCartButton(),this.addEventListener("change",this.handleVariantChange.bind(this))}handleVariantChange(evt){this.variant=null,this.variant=this.getSelectedVariant(),this.variant&&(this.updateMedia(),this.updateUrl(evt),this.updateVariantInput()),this.updateAddToCartButton(),this.updateAvailability(),this.updatePrice(),this.updateWeight(),this.updateBarcode(),this.updateBackorderText(),this.updatePickupAvailability(),this.updateSku(),VariantPicker.updateLabelText(evt),this.dispatchEvent(new CustomEvent("on:variant:change",{bubbles:!0,detail:{form:this.productForm,variant:this.variant,product:this.data.product}}))}updateAddToCartButton(){if(this.productForm=this.section.querySelector(".js-product-form-main"),!this.productForm)return;this.addBtn=this.addBtn||this.productForm.querySelector('[name="add"]');const variantAvailable=this.variant&&this.variant.available,unavailableStr=this.variant?theme.strings.noStock:theme.strings.noVariant;this.addBtn.disabled=!variantAvailable,this.addBtn.textContent=variantAvailable?this.addBtn.dataset.addToCartText:unavailableStr}static updateOptionAvailability(optionEl,exists,available){const el=optionEl,unavailableText=exists?theme.strings.noStock:theme.strings.noVariant;if(el.classList.toggle("is-unavailable",!available),el.classList.toggle("is-nonexistent",!exists),optionEl.classList.contains("custom-select__option")){const em=el.querySelector("em");em&&(em.hidden=available),available||(em?em.textContent=unavailableText:el.innerHTML=`${el.innerHTML} ${unavailableText}`)}else available?el.nextElementSibling.removeAttribute("title"):el.nextElementSibling.title=unavailableText}updateAvailability(){if(this.dataset.showAvailability==="false")return;const{availabilityMethod}=this.dataset;let currVariant=this.variant;const selectedOptions=this.getSelectedOptions();this.variant||(currVariant={options:selectedOptions}),availabilityMethod==="selection"?(this.querySelectorAll(".js-option").forEach(optionEl=>{VariantPicker.updateOptionAvailability(optionEl,!1,!1)}),this.optionSelectors.forEach((selector,selectorIndex)=>{this.data.product.variants.forEach(variant=>{let matchCount=0;if(variant.options.forEach((option,optionIndex)=>{option===currVariant.options[optionIndex]&&optionIndex!==selectorIndex&&(matchCount+=1)}),matchCount===currVariant.options.length-1){const options=selector.querySelectorAll(".js-option"),optionEl=Array.from(options).find(opt=>selector.dataset.selectorType==="dropdown"?opt.dataset.value===variant.options[selectorIndex]:opt.value===variant.options[selectorIndex]);optionEl&&VariantPicker.updateOptionAvailability(optionEl,!0,variant.available)}})})):this.optionSelectors.forEach((selector,selectorIndex)=>{selector.querySelectorAll('.js-option:not([data-value=""])').forEach(option=>{const optionValue=selector.dataset.selectorType==="dropdown"?option.dataset.value:option.value;let variantsExist=!1,variantsAvailable=!1;this.data.product.variants.forEach(v=>{let matches=0;for(let i=0;i .price"),!!this.price){if(this.variant){const priceCurrentEl=this.price.querySelector(".price__current"),priceWasEl=this.price.querySelector(".price__was"),unitPriceEl=this.price.querySelector(".unit-price");if(priceCurrentEl.innerHTML=this.data.formatted[this.variant.id].price,priceWasEl&&(priceWasEl.innerHTML=this.data.formatted[this.variant.id].compareAtPrice||""),this.variant.unit_price_measurement){const valueEl=this.price.querySelector(".unit-price__price"),unitEl=this.price.querySelector(".unit-price__unit"),value=this.variant.unit_price_measurement.reference_value,unit=this.variant.unit_price_measurement.reference_unit;valueEl.innerHTML=this.data.formatted[this.variant.id].unitPrice,unitEl.textContent=value===1?unit:`${value} ${unit}`}unitPriceEl.hidden=!this.variant.unit_price_measurement,this.price.classList.toggle("price--on-sale",this.variant.compare_at_price>this.variant.price),this.price.classList.toggle("price--sold-out",!this.variant.available)}this.price.querySelector(".price__default").hidden=!this.variant,this.price.querySelector(".price__no-variant").hidden=this.variant}}updateWeight(){if(this.weights=this.weights||this.section.querySelectorAll(".product-info__weight"),this.weights.length===0)return;const weightAvailable=this.variant&&this.variant.weight>0;this.weights.forEach(weight=>{weight.textContent=weightAvailable?this.data.formatted[this.variant.id].weight:"",weight.hidden=!weightAvailable})}updateBarcode(){if(this.barcodes=this.barcodes||this.section.querySelectorAll(".product-info__barcode-value"),this.barcodes.length===0)return;const barcodeAvailable=this.variant&&this.variant.barcode;this.barcodes.forEach(barcode=>{barcode.textContent=barcodeAvailable?this.variant.barcode:"",barcode.parentNode.hidden=!barcodeAvailable})}updateSku(){if(this.sku=this.sku||this.section.querySelector(".product-sku__value"),!this.sku)return;const skuAvailable=this.variant&&this.variant.sku;this.sku.textContent=skuAvailable?this.variant.sku:"",this.sku.parentNode.hidden=!skuAvailable}updateUrl(evt){!evt||evt.type!=="change"||this.dataset.updateUrl==="false"||window.history.replaceState({},"",`${this.dataset.url}?variant=${this.variant.id}`)}updateVariantInput(){this.forms=this.forms||this.section.querySelectorAll(".js-product-form-main, .js-instalments-form"),this.forms.forEach(form=>{const input=form.querySelector('input[name="id"]');input.value=this.variant.id,input.dispatchEvent(new Event("change",{bubbles:!0}))})}getSelectedOptions(){const selectedOptions=[];return this.optionSelectors.forEach(selector=>{selector.dataset.selectorType==="dropdown"?selectedOptions.push(selector.querySelector(".custom-select__btn").textContent.trim()):selectedOptions.push(selector.querySelector("input:checked").value)}),selectedOptions}getProductData(){const dataEl=this.querySelector('[type="application/json"]');return JSON.parse(dataEl.textContent)}getSelectedVariant(){const selectedOptions=this.getSelectedOptions();return this.data.product.variants.find(v=>v.options.every((val,index)=>val===selectedOptions[index]))}}customElements.define("variant-picker",VariantPicker)} //# sourceMappingURL=/cdn/shop/t/10/assets/variant-picker.js.map?v=65958280291136870461716915740