import{r as t,h as i,F as s}from"./p-dfbe004d.js";import{a as o}from"./p-7393a06c.js";import{U as r}from"./p-c7dd942d.js";import{b as e}from"./p-85821e4e.js";import{g as a,s as d}from"./p-10aa7556.js";import{u as n}from"./p-57d82274.js";import{a as c}from"./p-1c2e2695.js";import"./p-fd56940f.js";import"./p-699b9e85.js";import"./p-ea78c070.js";import"./p-35c4916d.js";import"./p-a41f5fb3.js";import"./p-6c2a2148.js";import"./p-4d73f82a.js";const l=class{constructor(i){t(this,i),this.open=null,this.mode="live",this.uiState="idle"}handleOpenChange(){n.set("cart",{...n.state.cart,open:this.open}),!0===this.open&&this.fetchOrder()}order(){return a(this.formId,this.mode)}setOrder(t){d(t,this.formId)}pageHasForm(){return!!document.querySelector("sc-checkout")}getItemsCount(){var t,i;const s=null===(i=null===(t=this.order())||void 0===t?void 0:t.line_items)||void 0===i?void 0:i.data;let o=0;return(s||[]).forEach((t=>{o+=null==t?void 0:t.quantity})),o}handleSetState(t){this.uiState=t.detail}handleErrorEvent(t){this.error=t.detail,this.uiState="idle"}handleCloseCart(){this.open=!1}async fetchOrder(){var t;try{this.uiState="loading";const i=await o({method:"GET",path:c(`${e}${null===(t=this.order())||void 0===t?void 0:t.id}`,{expand:["line_items","line_item.price","price.product","customer","customer.shipping_address","payment_intent","discount","discount.promotion","discount.coupon","recommended_bumps","bump.price","shipping_address","tax_identifier"]})});this.setOrder(i)}catch(t){throw console.error(t),t}finally{this.uiState="idle"}}componentWillLoad(){r.create(this,this.state()),this.open=!!n.state.cart.open,n.onChange("cart",(t=>{this.open=t.open}))}state(){var t,i,s,o,r,e,a,d,n,c,l,h;return{processor_data:null===(t=this.order())||void 0===t?void 0:t.processor_data,uiState:this.uiState,checkoutLink:this.checkoutLink,loading:"loading"===this.uiState,busy:"busy"===this.uiState,navigating:"navigating"===this.uiState,empty:!(null===(o=null===(s=null===(i=this.order())||void 0===i?void 0:i.line_items)||void 0===s?void 0:s.pagination)||void 0===o?void 0:o.count),error:this.error,order:this.order(),lineItems:(null===(e=null===(r=this.order())||void 0===r?void 0:r.line_items)||void 0===e?void 0:e.data)||[],tax_status:null===(a=this.order())||void 0===a?void 0:a.tax_status,customerShippingAddress:"string"!=typeof(null===(d=this.order())||void 0===d?void 0:d.customer)?null===(c=null===(n=this.order())||void 0===n?void 0:n.customer)||void 0===c?void 0:c.shipping_address:{},shippingAddress:null===(l=this.order())||void 0===l?void 0:l.shipping_address,taxStatus:null===(h=this.order())||void 0===h?void 0:h.tax_status,formId:this.formId}}render(){return i(s,null,this.order()&&i(r.Provider,{state:this.state()},i("sc-cart-session-provider",{order:this.order(),"form-id":this.formId,"group-id":this.formId,onScUpdateOrderState:t=>this.setOrder(t.detail),onScError:t=>this.error=t.detail},i("sc-cart-icon",{count:this.getItemsCount(),onClick:()=>this.open=!this.open}),i("sc-drawer",{open:this.open,onScAfterHide:()=>this.open=!1,onScAfterShow:()=>this.open=!0},!0===this.open&&i(s,null,i("div",{class:"cart__header-suffix",slot:"header"},i("slot",{name:"cart-header"}),i("sc-error",{style:{"--sc-alert-border-radius":"0"},slot:"header",error:this.error,onScUpdateError:t=>this.error=t.detail})),i("slot",null)),"busy"===this.uiState&&i("sc-block-ui",{"z-index":9})))))}static get watchers(){return{open:["handleOpenChange"]}}};l.style=":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}";export{l as sc_cart}