import{r as e,c as t,h as i,g as s}from"./p-b891c2f1.js";import{p as l}from"./p-f0bb2283.js";import"./p-112455b1.js";const r=class{constructor(i){e(this,i),this.scPaid=t(this,"scPaid",7),this.scPayError=t(this,"scPayError",7),this.loaded=!1,this.confirming=!1}async componentDidLoad(){this.publishableKey&&this.accountId&&(this.stripe=await l.loadStripe(this.publishableKey,{stripeAccount:this.accountId}),this.loadElement())}handleClientSecretChange(e,t){e!==t&&(this.loaded=!1,this.loadElement())}async maybeConfirmOrder(e){var t,i,s,l,r,o,n;if("finalized"===(null==e?void 0:e.status)&&"stripe"===(null===(t=null==e?void 0:e.payment_intent)||void 0===t?void 0:t.processor_type)&&(null===(l=null===(s=null===(i=null==e?void 0:e.payment_intent)||void 0===i?void 0:i.processor_data)||void 0===s?void 0:s.stripe)||void 0===l?void 0:l.type))return await this.confirm(null===(n=null===(o=null===(r=null==e?void 0:e.payment_intent)||void 0===r?void 0:r.processor_data)||void 0===o?void 0:o.stripe)||void 0===n?void 0:n.type)}async confirm(e,t={}){const i={elements:this.elements,confirmParams:{return_url:this.successUrl},redirect:"if_required",...t};if(!this.confirming)try{const t="setup"===e?await this.stripe.confirmSetup(i):await this.stripe.confirmPayment(i);if(null==t?void 0:t.error)throw this.error=t.error.message,t.error;this.scPaid.emit()}catch(e){console.error(e),this.scPayError.emit(e),e.message&&(this.error=e.message)}finally{this.confirming=!1}}loadElement(){if(!this.stripe||!this.clientSecret||!this.container)return;const e=getComputedStyle(document.body);this.elements=this.stripe.elements({clientSecret:this.clientSecret,appearance:{variables:{colorPrimary:e.getPropertyValue("--sc-color-primary-500"),colorText:e.getPropertyValue("--sc-input-label-color"),borderRadius:e.getPropertyValue("--sc-input-border-radius-medium"),colorBackground:e.getPropertyValue("--sc-input-background-color"),fontSizeBase:e.getPropertyValue("--sc-input-font-size-medium")},rules:{".Input":{border:e.getPropertyValue("--sc-input-border")},".Input::placeholder":{color:e.getPropertyValue("--sc-input-placeholder-color")}}}}),this.elements.create("payment",{wallets:{applePay:"never",googlePay:"never"}}).mount(".sc-payment-element-container"),this.element=this.elements.getElement("payment"),this.element.on("ready",(()=>this.loaded=!0))}render(){return i("div",{class:"sc-stripe-payment-element","data-testid":"stripe-payment-element"},!!this.error&&i("sc-text",{style:{color:"var(--sc-color-danger-500)","--font-size":"var(--sc-font-size-small)",marginBottom:"0.5em"}},this.error),i("div",{class:"loader",hidden:this.loaded},i("div",{class:"loader__row"},i("div",{style:{width:"50%"}},i("sc-skeleton",{style:{width:"50%",marginBottom:"0.5em"}}),i("sc-skeleton",null)),i("div",{style:{flex:"1"}},i("sc-skeleton",{style:{width:"50%",marginBottom:"0.5em"}}),i("sc-skeleton",null)),i("div",{style:{flex:"1"}},i("sc-skeleton",{style:{width:"50%",marginBottom:"0.5em"}}),i("sc-skeleton",null))),i("div",{class:"loader__details"},i("sc-skeleton",{style:{height:"1rem"}}),i("sc-skeleton",{style:{height:"1rem",width:"30%"}}))),i("div",{hidden:!this.loaded,class:"sc-payment-element-container",ref:e=>this.container=e}))}get el(){return s(this)}static get watchers(){return{clientSecret:["handleClientSecretChange"],order:["maybeConfirmOrder"]}}};r.style="sc-stripe-payment-element{display:block}.loader{display:grid;height:128px;gap:2em}.loader__row{display:flex;align-items:flex-start;justify-content:space-between;gap:1em}.loader__details{display:grid;gap:0.5em}";export{r as sc_stripe_payment_element}