import{r as i,c as t,h as s,g as o}from"./p-b891c2f1.js";import{_ as e}from"./p-684c85b4.js";import"./p-aafd8ea4.js";import{U as r}from"./p-aad60fb9.js";import{g as n}from"./p-60f049de.js";import"./p-112455b1.js";const h=class{constructor(s){i(this,s),this.scOrderUpdated=t(this,"scOrderUpdated",7),this.scOrderFinalized=t(this,"scOrderFinalized",7),this.scOrderError=t(this,"scOrderError",7),this.prices=[],this.mode="live",this.currencyCode="usd",this.persistSession=!0,this.successUrl="",this.editLineItems=!0,this.removeLineItems=!0,this.stripePaymentElement=!1,this.pricesEntities={},this.productsEntities={},this.checkoutState="idle",this.processor="stripe",this.paymentIntents={}}handleSetPaymentIntent(i){var t,s;const o=null===(t=i.detail)||void 0===t?void 0:t.payment_intent,e=null===(s=i.detail)||void 0===s?void 0:s.processor;this.paymentIntents[e]=o}handleProcessorChange(i){this.processor=i.detail}handleAddEntities(i){const{products:t,prices:s}=i.detail;Object.keys((null==t?void 0:t.length)||{})&&(this.productsEntities={...this.productsEntities,...t}),Object.keys((null==s?void 0:s.length)||{})&&(this.pricesEntities={...this.pricesEntities,...s})}async submit({skip_validation:i}={skip_validation:!1}){return i||await this.validate(),await this.sessionProvider.finalize()}async validate(){const i=this.el.querySelector("sc-form");return await i.validate()}componentWillLoad(){r.create(this,this.state()),this.isDuplicate=document.querySelector("sc-checkout")!==this.el}order(){return n(null==this?void 0:this.formId,this.mode)}state(){var i,t,s,o,e,r,n,h,d,c,a,l,u,p;return{processor:this.processor,processors:this.processors,processor_data:null===(i=this.order())||void 0===i?void 0:i.processor_data,state:this.checkoutState,paymentIntents:this.paymentIntents,successUrl:this.successUrl,order:this.order(),shippingEnabled:null===(t=this.order())||void 0===t?void 0:t.shipping_enabled,lineItems:(null===(o=null===(s=this.order())||void 0===s?void 0:s.line_items)||void 0===o?void 0:o.data)||[],editLineItems:this.editLineItems,removeLineItems:this.removeLineItems,loading:"loading"===this.checkoutState,busy:["updating","finalizing","paid","confirmed"].includes(this.checkoutState),paying:["finalizing","paid","confirmed"].includes(this.checkoutState),empty:!["loading","updating"].includes(this.checkoutState)&&!(null===(n=null===(r=null===(e=this.order())||void 0===e?void 0:e.line_items)||void 0===r?void 0:r.pagination)||void 0===n?void 0:n.count),stripePaymentElement:this.stripePaymentElement,error:this.error,customer:this.customer,tax_status:null===(h=this.order())||void 0===h?void 0:h.tax_status,customerShippingAddress:"string"!=typeof(null===(d=this.order())||void 0===d?void 0:d.customer)?null===(a=null===(c=this.order())||void 0===c?void 0:c.customer)||void 0===a?void 0:a.shipping_address:{},shippingAddress:null===(l=this.order())||void 0===l?void 0:l.shipping_address,taxStatus:null===(u=this.order())||void 0===u?void 0:u.tax_status,taxIdentifier:null===(p=this.order())||void 0===p?void 0:p.tax_identifier,taxProtocol:this.taxProtocol,lockedChoices:this.prices,products:this.productsEntities,prices:this.pricesEntities,country:"US",loggedIn:this.loggedIn,formId:this.formId,mode:this.mode,currencyCode:this.currencyCode}}render(){return this.isDuplicate?s("sc-alert",{open:!0},e("Due to processor restrictions, only one checkout form is allowed on the page.","surecart")):s("div",{class:{"sc-checkout-container":!0,"sc-align-center":"center"===this.alignment,"sc-align-wide":"wide"===this.alignment,"sc-align-full":"full"===this.alignment}},s(r.Provider,{state:this.state()},s("sc-form-state-provider",{onScSetCheckoutFormState:i=>this.checkoutState=i.detail},s("sc-form-error-provider",{order:this.order(),onScUpdateError:i=>this.error=i.detail},s("sc-form-components-validator",{order:this.order(),disabled:this.disableComponentsValidation,taxProtocol:this.taxProtocol},s("sc-order-confirm-provider",{order:this.order(),"success-url":this.successUrl,"form-id":this.formId,mode:this.mode},s("sc-session-provider",{ref:i=>this.sessionProvider=i,prices:this.prices,stripePaymentElement:this.stripePaymentElement,paymentIntents:this.paymentIntents,persist:this.persistSession,modified:this.modified,mode:this.mode,"form-id":this.formId,"group-id":this.el.id,processor:this.processor,"currency-code":this.currencyCode,onScError:i=>this.error=i.detail},s("slot",null)))))),this.state().busy&&s("sc-block-ui",{"z-index":9})))}get el(){return o(this)}};h.style="sc-checkout{display:block;font-family:var(--sc-font-sans);font-size:var(--sc-checkout-font-size, 16px);position:relative}sc-checkout h3{font-size:var(--sc-input-label-font-size-medium)}sc-alert{margin-bottom:var(--sc-form-row-spacing)}.sc-checkout-container.sc-align-center{max-width:500px;margin-left:auto;margin-right:auto}.sc-checkout-container.sc-align-wide{max-width:800px;margin-left:auto;margin-right:auto}::slotted(*){font-family:var(--sc-font-sans)}";export{h as sc_checkout}