import{proxyCustomElement,HTMLElement}from"@stencil/core/internal/client";import{s as se}from"./inline.js";import{s as state$1}from"./mutations2.js";import{s as state}from"./watchers5.js";import{o as onChange}from"./store3.js";import{c as currentFormState}from"./getters3.js";import{u as updateFormState}from"./mutations5.js";import{c as createErrorNotice}from"./mutations3.js";const ScCheckoutPaystackPaymentProvider=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow()}componentWillLoad(){this.unlistenToFormState=onChange("formState",(()=>{"paying"===currentFormState()&&this.confirm()}))}disconnectedCallback(){this.unlistenToFormState()}async confirm(){var t,e,o,s;if("paystack"===(null==state?void 0:state.id)&&(null===(e=null===(t=null==state$1?void 0:state$1.checkout)||void 0===t?void 0:t.payment_intent)||void 0===e?void 0:e.processor_data.paystack)&&"paid"!==(null===(o=null==state$1?void 0:state$1.checkout)||void 0===o?void 0:o.status))try{const{public_key:t,access_code:e}=null===(s=null==state$1?void 0:state$1.checkout)||void 0===s?void 0:s.payment_intent.processor_data.paystack;if(!t||!e)return void createErrorNotice({message:wp.i18n.sprintf(wp.i18n.__("Payment gateway configuration incomplete. Please ensure Paystack is properly configured for transactions.","surecart"))});const o=new se;await o.newTransaction({key:t,accessCode:e,onSuccess:async t=>{if("success"!==(null==t?void 0:t.status))throw{message:wp.i18n.sprintf(wp.i18n.__("Paystack transaction could not be finished. Status: %s","surecart"),null==t?void 0:t.status)};return updateFormState("PAID")},onClose:()=>updateFormState("REJECT")})}catch(t){createErrorNotice(t),console.error(t),updateFormState("REJECT")}}},[1,"sc-checkout-paystack-payment-provider"]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-checkout-paystack-payment-provider"].forEach((t=>{"sc-checkout-paystack-payment-provider"===t&&(customElements.get(t)||customElements.define(t,ScCheckoutPaystackPaymentProvider))}))}export{ScCheckoutPaystackPaymentProvider as S,defineCustomElement as d};