import apiFetch from"../../../../functions/fetch";import{h}from"@stencil/core";import{__}from"@wordpress/i18n";import{addQueryArgs,getQueryArg}from"@wordpress/url";import{Universe}from"stencil-wormhole";export class ScOrderConfirmation{constructor(){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:["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})})}catch(e){(null==e?void 0:e.message)?this.error=e.message:this.error=__("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},__("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:"b659e8338c0273dd7ef253ed4f32464e2146a48b",state:this.state()},h("div",{key:"5d84c1bd84442419ddcb1a982650206689f2058d",class:{"order-confirmation":!0}},h("div",{key:"42624f443d33444d29ec135987f7c849a80ae0b5",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:"641a174a2bd69de8cb9fa8b5075b29f2f4c7e06b",checkout:this.order},h("slot",{key:"8cf3285abdcb9a3ffd37df7af8e974d2f433d8a5"}))),!(null===(t=this.order)||void 0===t?void 0:t.id)&&!this.loading&&h("sc-heading",{key:"315539c145ce66fbff3765f63d39738d1ed969da"},__("Order not found.","surecart"),h("span",{key:"3981783f698410bdecccc2429bc5a37faef496ef",slot:"description"},__("This order could not be found. Please try again.","surecart")))))}static get is(){return"sc-order-confirmation"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-order-confirmation.css"]}}static get styleUrls(){return{$:["sc-order-confirmation.css"]}}static get properties(){return{order:{type:"unknown",mutable:!0,complexType:{original:"Checkout",resolved:"Checkout",references:{Checkout:{location:"import",path:"../../../../types",id:"src/types.ts::Checkout"}}},required:!1,optional:!1,docs:{tags:[],text:""}}}}static get states(){return{loading:{},error:{}}}}