import{r as e,h as t,F as i,a as o}from"./p-9add63ef.js";import"./p-445fd8b4.js";import{e as s,b as a}from"./p-c1ecac8a.js";import{a as d,g as r,b as n,s as c,u as l,c as p}from"./p-1282ed4a.js";import{c as u}from"./p-78468e45.js";import{f as h}from"./p-b51de06c.js";import{a as v}from"./p-401e165e.js";import{a as f}from"./p-259c3935.js";import"./p-d3366af3.js";import"./p-2b28ea49.js";import"./p-dd24e53c.js";import"./p-830ab1a3.js";import"./p-ec182234.js";import"./p-3f6362a4.js";import"./p-31faf2b8.js";import"./p-610295e2.js";const m=":host{--sc-drawer-header-spacing:var(--sc-spacing-large);--sc-drawer-body-spacing:var(--sc-spacing-large);--sc-drawer-footer-spacing:var(--sc-spacing-large)}.cart{font-size:16px}.cart__header{display:flex;align-items:center;justify-content:space-between;width:100%;font-size:1em}.cart__close{opacity:0.75;transition:opacity 0.25s ease;cursor:pointer}.cart__close:hover{opacity:1}::slotted(*){padding:var(--sc-drawer-header-spacing);background:var(--sc-panel-background-color);position:relative}::slotted(sc-line-items){flex:1 1 auto;overflow:auto;-webkit-overflow-scrolling:touch;min-height:200px}::slotted(:last-child){border-bottom:0 !important}sc-drawer::part(body){display:flex;flex-direction:column;box-sizing:border-box;padding:0;overflow:hidden}";const b=m;const g=class{constructor(t){e(this,t);this.open=null;this.formId=undefined;this.header=undefined;this.checkoutLink=undefined;this.cartTemplate=undefined;this.mode="live";this.checkoutUrl=undefined;this.alwaysShow=undefined;this.floatingIconEnabled=true;this.uiState="idle"}handleOpenChange(){var e,t,i;d.set("cart",{...d.state.cart,...{open:this.open}});if(this.open===true){this.fetchOrder()}else{(i=(t=(e=document===null||document===void 0?void 0:document.querySelector("sc-cart-icon"))===null||e===void 0?void 0:e.shadowRoot)===null||t===void 0?void 0:t.querySelector(".cart"))===null||i===void 0?void 0:i.focus()}}order(){return r(this.formId,this.mode)}setCheckout(e){n(e,this.formId)}pageHasForm(){return!!document.querySelector("sc-checkout")}getItemsCount(){var e,t;const i=(t=(e=c.checkout)===null||e===void 0?void 0:e.line_items)===null||t===void 0?void 0:t.data;let o=0;(i||[]).forEach((e=>{o=o+(e===null||e===void 0?void 0:e.quantity)}));return o}handleSetState(e){this.uiState=e.detail}handleCloseCart(){this.open=false}async fetchOrder(){var e,t;if(!((e=c.checkout)===null||e===void 0?void 0:e.id)){return}try{l("FETCH");c.checkout=await f({method:"GET",path:v(`${a}${(t=c.checkout)===null||t===void 0?void 0:t.id}`,{expand:s})});l("RESOLVE")}catch(e){console.error(e);l("REJECT");u(e);if((e===null||e===void 0?void 0:e.code)==="checkout.not_found"){p(this.formId,this.mode)}}}componentWillLoad(){this.open=!!d.state.cart.open;d.onChange("cart",(e=>{this.open=e.open}))}state(){var e,t,i,o,s,a,d,r,n,l,p;return{uiState:this.uiState,checkoutLink:this.checkoutLink,loading:this.uiState==="loading",busy:this.uiState==="busy",navigating:this.uiState==="navigating",empty:!((i=(t=(e=c.checkout)===null||e===void 0?void 0:e.line_items)===null||t===void 0?void 0:t.pagination)===null||i===void 0?void 0:i.count),order:c.checkout,lineItems:((s=(o=c.checkout)===null||o===void 0?void 0:o.line_items)===null||s===void 0?void 0:s.data)||[],tax_status:(a=c.checkout)===null||a===void 0?void 0:a.tax_status,customerShippingAddress:typeof((d=c.checkout)===null||d===void 0?void 0:d.customer)!=="string"?(n=(r=c.checkout)===null||r===void 0?void 0:r.customer)===null||n===void 0?void 0:n.shipping_address:{},shippingAddress:(l=c.checkout)===null||l===void 0?void 0:l.shipping_address,taxStatus:(p=c.checkout)===null||p===void 0?void 0:p.tax_status,formId:this.formId}}render(){return t("sc-cart-session-provider",{key:"560c163d6734b8e3523aa3ef694402087bb8d925"},t("sc-drawer",{key:"afef03ec7696549111ea08d98f082b16a12bd089",open:this.open,onScAfterShow:()=>this.open=true,onScAfterHide:()=>{this.open=false}},this.open===true&&t(i,{key:"587340601c82b370c27c1eb24ee656a376703e27"},t("div",{key:"c97b85fc5346f04a8c6c1f9620ed5fb5da93ad52",class:"cart__header-suffix",slot:"header"},t("slot",{key:"90c42dc0deca0417a7c2c0e34dcb98ea61bf9b09",name:"cart-header"}),t("sc-error",{key:"2dfa19f7e78f4203b0e0bd84c33dc23406e5f052",style:{"--sc-alert-border-radius":"0"},slot:"header"})),t("slot",{key:"7eeb0334a95f5d87bba56813e38cb76017ea09c1"})),h()&&t("sc-block-ui",{key:"006485d36e0db4fe8d635b56250df23aae6a9056","z-index":9})))}get el(){return o(this)}static get watchers(){return{open:["handleOpenChange"]}}};g.style=b;export{g as sc_cart};
//# sourceMappingURL=p-2821c6fe.entry.js.map