import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import"./fetch.js";import{U as Universe}from"./universe.js";import{d as defineCustomElement$6}from"./sc-alert2.js";import{d as defineCustomElement$5}from"./sc-heading2.js";import{d as defineCustomElement$4}from"./sc-icon2.js";import{d as defineCustomElement$3}from"./sc-order-confirm-components-validator2.js";import{d as defineCustomElement$2}from"./sc-order-manual-instructions2.js";import{g as getQueryArg}from"./remove-query-args.js";import{a as addQueryArgs}from"./add-query-args.js";import{a as apiFetch}from"./index4.js";const scOrderConfirmationCss=":host{display:block;max-width:800px;margin:auto}::slotted(*:not(:last-child)),sc-form form>*:not(:last-child){margin-bottom:var(--sc-form-row-spacing-large)}.order-confirmation__content{color:var(--sc-order-confirmation-color, var(--sc-color-gray-500))}.order-confirmation__content.hidden{display:none}::part(line-items){display:grid;gap:0.5em}",ScOrderConfirmationStyle0=scOrderConfirmationCss,ScOrderConfirmation$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.order=void 0,this.loading=!1,this.error=void 0}componentWillLoad(){Universe.create(this,this.state()),this.getSession()}getSessionId(){var e;return(null===(e=this.order)||void 0===e?void 0:e.id)?this.order.id:getQueryArg(window.location.href,"sc_order")}async getSession(){var e;if(this.getSessionId()&&!(null===(e=this.order)||void 0===e?void 0:e.id))try{this.loading=!0,this.order=await await apiFetch({path:addQueryArgs(`surecart/v1/checkouts/${this.getSessionId()}`,{expand:["checkout_fees","shipping_fees","line_items","line_item.price","line_item.fees","price.product","customer","customer.shipping_address","payment_intent","discount","manual_payment_method","discount.promotion","billing_address","shipping_address"],refresh_status:!0,currency_conversion:!1})})}catch(e){(null==e?void 0:e.message)?this.error=e.message:this.error=wp.i18n.__("Something went wrong","surecart")}finally{this.loading=!1}}state(){var e,t;const r=null===(e=this.order)||void 0===e?void 0:e.manual_payment_method;return{processor:"stripe",loading:this.loading,orderId:this.getSessionId(),order:this.order,customer:null===(t=this.order)||void 0===t?void 0:t.customer,manualPaymentTitle:null==r?void 0:r.name,manualPaymentInstructions:null==r?void 0:r.instructions}}renderOnHold(){var e,t,r;return"processing"!==(null===(e=this.order)||void 0===e?void 0:e.status)?null:"paypal"===(null===(r=null===(t=null==this?void 0:this.order)||void 0===t?void 0:t.payment_intent)||void 0===r?void 0:r.processor_type)?h("sc-alert",{type:"warning",open:!0},wp.i18n.__("Paypal is taking a closer look at this payment. It’s required for some payments and normally takes up to 3 business days.","surecart")):void 0}renderManualInstructions(){var e;const t=null===(e=this.order)||void 0===e?void 0:e.manual_payment_method;if(null==t?void 0:t.instructions)return h("sc-alert",{type:"info",open:!0},h("span",{slot:"title"},null==t?void 0:t.name),h("div",{innerHTML:null==t?void 0:t.instructions}))}render(){var e,t;return h(Universe.Provider,{key:"21e583d8b2407ebce3a355b5d303475433373148",state:this.state()},h("div",{key:"0814352b24e81fad53da042bbba33ea97025ad66",class:{"order-confirmation":!0}},h("div",{key:"ca6c449acae714b486e6144753c67b3d554fc40d",class:{"order-confirmation__content":!0,hidden:!(null===(e=this.order)||void 0===e?void 0:e.id)&&!this.loading}},h("sc-order-confirm-components-validator",{key:"0b02ab7520b6dc6ee6abe2deef6ae9611f025383",checkout:this.order},h("slot",{key:"4a5fc2e13dccb99863415f68ea74d626972b04d4"}))),!(null===(t=this.order)||void 0===t?void 0:t.id)&&!this.loading&&h("sc-heading",{key:"baead488ab30c8c5ebfb8bc67929a627cf61f624"},wp.i18n.__("Order not found.","surecart"),h("span",{key:"04e9c0c2d341cbcc00a5b2d66d9b8620ddedf076",slot:"description"},wp.i18n.__("This order could not be found. Please try again.","surecart")))))}static get style(){return ScOrderConfirmationStyle0}},[1,"sc-order-confirmation",{order:[1040],loading:[32],error:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-order-confirmation","sc-alert","sc-heading","sc-icon","sc-order-confirm-components-validator","sc-order-manual-instructions"].forEach((e=>{switch(e){case"sc-order-confirmation":customElements.get(e)||customElements.define(e,ScOrderConfirmation$1);break;case"sc-alert":customElements.get(e)||defineCustomElement$6();break;case"sc-heading":customElements.get(e)||defineCustomElement$5();break;case"sc-icon":customElements.get(e)||defineCustomElement$4();break;case"sc-order-confirm-components-validator":customElements.get(e)||defineCustomElement$3();break;case"sc-order-manual-instructions":customElements.get(e)||defineCustomElement$2()}}))}const ScOrderConfirmation=ScOrderConfirmation$1,defineCustomElement=defineCustomElement$1;export{ScOrderConfirmation,defineCustomElement};