1import{t as e}from"./classPrivateMethodInitSpec-BPYNANpg.js";import{n as t,t as n}from"./classPrivateFieldGet2-CFIOuXdl.js";import{t as r}from"./assertClassBrand-Dh7UAh7K.js";import{t as i}from"./classPrivateFieldSet2-DNfdh3So.js";import{t as a}from"./defineProperty-CDrfZGhu.js";import{Component as o}from"@theme/component";import{fetchConfig as s}from"@theme/utilities";import{DiscountUpdateEvent as c}from"@theme/events";import{morphSection as l}from"@theme/section-renderer";import{cartPerformance as u}from"@theme/performance";var d=new WeakMap,f=new WeakSet,p=class extends o{constructor(...n){super(...n),e(this,f),a(this,`requiredRefs`,[`cartDiscountError`,`cartDiscountErrorDiscountCode`,`cartDiscountErrorShipping`]),t(this,d,null),a(this,`applyDiscount`,async e=>{let{cartDiscountError:t,cartDiscountErrorDiscountCode:n,cartDiscountErrorShipping:a}=this.refs;e.preventDefault(),e.stopPropagation();let o=e.target;if(!(o instanceof HTMLFormElement))return;let p=o.querySelector(`input[name="discount"]`);if(!(p instanceof HTMLInputElement)||typeof this.dataset.sectionId!=`string`)return;let _=p.value,v=r(f,this,m).call(this);try{let e=r(f,this,g).call(this);if(e.includes(_))return;t.classList.add(`hidden`),n.classList.add(`hidden`),a.classList.add(`hidden`);let i=s(`json`,{body:JSON.stringify({discount:[...e,_].join(`,`),sections:[this.dataset.sectionId]})}),o=await(await fetch(Theme.routes.cart_update_url,{...i,signal:v.signal})).json();if(o.discount_codes.find(e=>e.code===_&&e.applicable===!1)){p.value=``,r(f,this,h).call(this,`discount_code`);return}let u=o.sections[this.dataset.sectionId],d=new DOMParser().parseFromString(u,`text/html`).getElementById(`shopify-section-${this.dataset.sectionId}`),m=(d==null?void 0:d.querySelectorAll(`.cart-discount__pill`))||[];if(d){let t=Array.from(m).map(e=>e instanceof HTMLLIElement?e.dataset.discountCode:null).filter(Boolean);if(t.length===e.length&&t.every(t=>e.includes(t))&&o.discount_codes.find(e=>e.code===_&&e.applicable===!0)){r(f,this,h).call(this,`shipping`),p.value=``;return}}document.dispatchEvent(new c(o,this.id)),l(this.dataset.sectionId,u)}catch{}finally{i(d,this,null),u.measureFromEvent(`discount-update:user-action`,e)}}),a(this,`removeDiscount`,async e=>{if(e.preventDefault(),e.stopPropagation(),e instanceof KeyboardEvent&&e.key!==`Enter`||!(e instanceof MouseEvent)||!(e.target instanceof HTMLElement)||typeof this.dataset.sectionId!=`string`)return;let t=e.target.closest(`.cart-discount__pill`);if(!(t instanceof HTMLLIElement))return;let n=t.dataset.discountCode;if(!n)return;let a=r(f,this,g).call(this),o=a.indexOf(n);if(o===-1)return;a.splice(o,1);let u=r(f,this,m).call(this);try{let e=s(`json`,{body:JSON.stringify({discount:a.join(`,`),sections:[this.dataset.sectionId]})}),t=await(await fetch(Theme.routes.cart_update_url,{...e,signal:u.signal})).json();document.dispatchEvent(new c(t,this.id)),l(this.dataset.sectionId,t.sections[this.dataset.sectionId])}catch{}finally{i(d,this,null)}})}};function m(){n(d,this)&&n(d,this).abort();let e=new AbortController;return i(d,this,e),e}function h(e){let{cartDiscountError:t,cartDiscountErrorDiscountCode:n,cartDiscountErrorShipping:r}=this.refs,i=e===`discount_code`?n:r;t.classList.remove(`hidden`),i.classList.remove(`hidden`)}function g(){let e=[],t=this.querySelectorAll(`.cart-discount__pill`);for(let n of t)n instanceof HTMLLIElement&&typeof n.dataset.discountCode==`string`&&e.push(n.dataset.discountCode);return e}customElements.get(`cart-discount-component`)||customElements.define(`cart-discount-component`,p); 2//# sourceMappingURL=cart-discount.js.map
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.