1import{a as O,B as f}from"./chunk-BaseElement-COVKFV2h.js";import{W as v}from"./chunk-WithShopifyCart-BWb_K9t8.js";import{x as m,T as _}from"./chunk-lit-element-CULRVKo8.js";import{t as u}from"./chunk-custom-element-BhZVzxrc.js";import{n as c}from"./chunk-property-BXqvfTtY.js";import{r as C}from"./chunk-state-BP5Nb0So.js";import{e as b,n as w}from"./chunk-ref-CqgMGa9s.js";import"./chunk-quantity-input-DGlSggB4.js";import{H as S}from"./chunk-HTMLUpdateUtility-BS1fn5Vz.js";import"./chunk-WithApiClient-CVkX1jbr.js";import"./chunk-index-CKJCYK2x.js";import"./chunk-cart-sections-DQ33OuN-.js";import"./chunk-create-context-89xeped_.js";import"./chunk-consume-BsoYqMTv.js";import"./chunk-context-request-event-CEfviNJd.js";import"./chunk-directive-helpers-R4cBqjor.js";import"./chunk-directive-CF8sV3Lr.js";import"./chunk-FormElement-B78wXcbw.js";import"./chunk-debounce-D6ZMjh7U.js";import"./chunk-LiveRegionUtility-tvV1eypT.js";import"./chunk-aria-live-region-context-DAmBJh4s.js";import"./chunk-firstFocusableElement-BqnhZP5g.js";var y=Object.defineProperty,U=Object.getOwnPropertyDescriptor,d=(e,t,r,o)=>{for(var i=o>1?void 0:o?U(t,r):t,n=e.length-1,a;n>=0;n--)(a=e[n])&&(i=(o?a(t,r,i):a(i))||i);return o&&i&&y(t,r,i),i};let l=class extends v(O){constructor(){super(...arguments),this.selectedOptions={},this.error=null,this.$errorMessage=b(),this._handleOptionChanged=e=>{const t=e.detail;this.selectedOptions={...this.selectedOptions,[t.optionSet]:t.optionLabel}}}connectedCallback(){super.connectedCallback(),this._setDefaultOptions(),window.addEventListener("customizer:optionChanged",this._handleOptionChanged)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("customizer:optionChanged",this._handleOptionChanged)}_setDefaultOptions(){const e=document.querySelector(`script.product-form-${this.productId}`);if(!e)return;let t=[];try{t=JSON.parse((e==null?void 0:e.textContent)||"[]")}catch(o){console.error("Error parsing product options",o)}if(!t.length)return;const r={};for(const o of t){const i=o.option_groups[0].options[0].option_label;r[o.option_set_name]=i}this.selectedOptions={...r}}_cleanOptionSetName(e){return e.replaceAll("_"," ").replace(/option(s)?$/,"").replace(/(^\w{1})|(\s+\w{1})/g,t=>t.toUpperCase())}async _handleFormSubmit(e){var t;try{this.error=null,e.preventDefault();const r=e.target,o=new FormData(r);if(Object.keys(this.selectedOptions).length)for(const[i,n]of Object.entries(this.selectedOptions))o.set(`properties[${this._cleanOptionSetName(i)}]`,n);r&&await this.addItemToWithForm(o),this.openCartDrawer()}catch(r){this.error=r.errrors||r.message||"An error occurred",await this.updateComplete,(t=this.$errorMessage.value)==null||t.scrollIntoView({behavior:"smooth",block:"center"})}}get errorHTML(){return this.error?m`<p 2 class="body mt-sm p-2xs text-u-error ring-1 ring-u-error" 3 ${w(this.$errorMessage)} 4 > 5 ${this.error} 6 </p>`:_}render(){return m` 7 <slot @submit=${this._handleFormSubmit}></slot> 8 ${this.errorHTML} 9 `}};d([c({type:String,attribute:"product-id"})],l.prototype,"productId",2);d([C()],l.prototype,"selectedOptions",2);d([C()],l.prototype,"error",2);l=d([u("product-form")],l);var P=Object.defineProperty,$=Object.getOwnPropertyDescriptor,E=(e,t,r,o)=>{for(var i=o>1?void 0:o?$(t,r):t,n=e.length-1,a;n>=0;n--)(a=e[n])&&(i=(o?a(t,r,i):a(i))||i);return o&&i&&P(t,r,i),i};const h="variant-picker:change";let g=class extends f{connectedCallback(){super.connectedCallback(),this._handleOptionChange=this._handleOptionChange.bind(this),this.addEventListener("change",this._handleOptionChange)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("change",this._handleOptionChange)}getValueFromTarget(e){var t;switch(e.tagName){case"SELECT":return e.selectedOptions[0];case"CUSTOM-SELECT":return(t=e.getSelectedOptionByValue(e.value))==null?void 0:t.el;default:return e}}getVariantIdFromCustomSelect(e){const t=e.getSelectedOptionByValue(e.value);if(t)return t.el.dataset.variantId}getProductUrlFromCustomSelect(e){const t=e.getSelectedOptionByValue(e.value);if(t)return t.el.dataset.productUrl}_handleOptionChange(e){e.stopPropagation();const t=e.target,r=this.getValueFromTarget(t)||t,o=t.tagName==="CUSTOM-SELECT"?this.getVariantIdFromCustomSelect(t):r.dataset.variantId,i=t.tagName==="CUSTOM-SELECT"?this.getProductUrlFromCustomSelect(t):r.dataset.productUrl;t&&this.$emit(h,{event:e,target:r,variantId:o,productUrl:i,selectedOptionValues:this.selectedOptionValues})}get selectedOptionValues(){return Array.from(this.querySelectorAll("select, fieldset input:checked")).map(({dataset:e})=>
9e.optionValueId).filter(Boolean)}};g=E([u("variant-picker")],g);var V=Object.defineProperty,L=Object.getOwnPropertyDescriptor,p=(e,t,r,o)=>{for(var i=o>1?void 0:o?L(t,r):t,n=e.length-1,a;n>=0;n--)(a=e[n])&&(i=(o?a(t,r,i):a(i))||i);return o&&i&&V(t,r,i),i};let s=class extends f{constructor(){super(...arguments),this.$htmlUpdateUtility=new S(this)}connectedCallback(){super.connectedCallback(),this.handleVariantPickerChange=this.handleVariantPickerChange.bind(this),this.addEventListener(h,this.handleVariantPickerChange),this.$htmlUpdateUtility.addPostProcessCallback(()=>{var e,t;(t=(e=window==null?void 0:window.Shopify)==null?void 0:e.PaymentButton)==null||t.init()})}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(h,this.handleVariantPickerChange)}updateURL(e,t,r){if(!this.shouldUpdateUrl)return;const o=new URLSearchParams(window.location.search);o.set("variant",t),r&&r!==""&&o.set("selling_plan",r),window.history.replaceState({},"",`${e}${t?`?${o.toString()}`:""}`)}handleVariantPickerChange(e){const t=e.detail.productUrl,r=e.detail.variantId,o=e.detail.sellingPlan;!r||r.trim()===""||(this.updateURL(t??"",r,o),t&&t!==""&&t!==this.productUrl&&(this.productUrl=t),this.$htmlUpdateUtility.fetchAndReplaceSectionId({renderRoot:this,sectionId:this.sectionId,baseUrl:t||this.productUrl,params:{variant:r,...o&&o!==""?{selling_plan:o}:{},...this.view?{view:this.view}:{}},withCache:!0}).catch(i=>{if(i instanceof Error)throw i;console.warn(i)}))}};p([c({type:String,attribute:"section-id"})],s.prototype,"sectionId",2);p([c({type:String,attribute:"product-url"})],s.prototype,"productUrl",2);p([c({type:String,attribute:"view"})],s.prototype,"view",2);p([c({type:String,attribute:"update-url",converter:e=>e==="true"})],s.prototype,"shouldUpdateUrl",2);s=p([u("main-product")],s);
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.