D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
diafdxji
/
shihty.com
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
surecart
/
Filename :
p-b80843e4.entry.js
back
Copy
import{r as i,c as e,h as t,H as s,a as o}from"./p-e97fde0a.js";import{s as n,o as d,u as r}from"./p-53e7f7d7.js";import{d as a,e as c,f as l,g as u,h,c as v}from"./p-be3a018c.js";import{c as f}from"./p-ff10bfbf.js";import"./p-273a6ac5.js";import{s as p}from"./p-566c9487.js";import{s as m}from"./p-fab02ef6.js";import{c as g}from"./p-d7c7b076.js";import{s as b,f as y}from"./p-97355490.js";import{v as w,c as _,s as k}from"./p-95325ec5.js";import{a as x}from"./p-dd3464cd.js";import{s as E}from"./p-830ab1a3.js";import{c as S,r as C,a as I}from"./p-1f60f497.js";import{a as T,g as j}from"./p-401e165e.js";import{p as L}from"./p-8b323bfb.js";import{r as R,g as P}from"./p-d3366af3.js";import"./p-03631502.js";import"./p-9dbc54d6.js";import"./p-ec182234.js";import"./p-3f6362a4.js";import"./p-4df6e0c5.js";import"./p-93127aa7.js";import"./p-e3f4d732.js";const A=":host{display:block}sc-table{height:auto}h4{display:block;margin:0;font-weight:var(--sc-font-weight-bold);font-size:var(--sc-font-size-medium)}.stock-alert{--body-spacing:var(--sc-spacing-x-large);--width:500px}.stock-alert__image{width:50px;height:50px;object-fit:cover;margin-right:10px;display:block}.stock-alert__product-info{display:flex;flex-direction:column;gap:var(--sc-spacing-xx-small)}.stock-alert__variant{color:var(--sc-color-gray-500);font-size:var(--sc-font-size-small)}.stock-alert__quantity{color:var(--sc-color-gray-500);font-weight:var(--sc-font-weight-bold);display:flex;align-items:center;justify-content:flex-end;gap:var(--sc-spacing-xx-small)}";const O=A;const q=class{constructor(t){i(this,t);this.scUpdateLineItem=e(this,"scUpdateLineItem",7);this.stockErrors=[];this.busy=undefined;this.error=undefined}getOutOfStockLineItems(){var i,e;return(((e=(i=n.checkout)===null||i===void 0?void 0:i.line_items)===null||e===void 0?void 0:e.data)||[]).filter((i=>{var e,t,s;const o=(e=i.price)===null||e===void 0?void 0:e.product;if((i===null||i===void 0?void 0:i.purchasable_status)!=="out_of_stock")return false;if((t=i===null||i===void 0?void 0:i.variant)===null||t===void 0?void 0:t.id){return((s=i===null||i===void 0?void 0:i.variant)===null||s===void 0?void 0:s.available_stock)<i.quantity}return(o===null||o===void 0?void 0:o.available_stock)<i.quantity}))}getStockAdjustedLineItems(){var i,e;const t=new Map;this.getOutOfStockLineItems().forEach((i=>{var e,s,o;const n=(e=i.price)===null||e===void 0?void 0:e.product;const d=((s=i===null||i===void 0?void 0:i.variant)===null||s===void 0?void 0:s.id)?Math.max(((o=i===null||i===void 0?void 0:i.variant)===null||o===void 0?void 0:o.available_stock)||0,0):Math.max((n===null||n===void 0?void 0:n.available_stock)||0,0);t.set(i.id,d)}));return(((e=(i=n.checkout)===null||i===void 0?void 0:i.line_items)===null||e===void 0?void 0:e.data)||[]).map((i=>{var e,s;const o=t.get(i.id);return{id:i.id,price_id:(e=i.price)===null||e===void 0?void 0:e.id,quantity:o!==undefined?o:i.quantity,...((s=i===null||i===void 0?void 0:i.variant)===null||s===void 0?void 0:s.id)?{variant:i.variant.id}:{}}}))}async onSubmit(){try{this.busy=true;n.checkout=await a({id:n.checkout.id,data:{line_items:this.getStockAdjustedLineItems().filter((i=>!!i.quantity))}})}catch(i){const e=((i===null||i===void 0?void 0:i.additional_errors)||[]).map((i=>i===null||i===void 0?void 0:i.message)).filter((i=>i));this.error=`${(i===null||i===void 0?void 0:i.message)||wp.i18n.__("Something went wrong.","surecart")} ${(e===null||e===void 0?void 0:e.length)&&` ${e.join(". ")}`}`}finally{this.busy=false}}render(){const i=(this.getOutOfStockLineItems()||[]).map((i=>{var e,t,s;const o=(e=i.price)===null||e===void 0?void 0:e.product;const n=((t=i===null||i===void 0?void 0:i.variant)===null||t===void 0?void 0:t.id)?(s=i===null||i===void 0?void 0:i.variant)===null||s===void 0?void 0:s.available_stock:o===null||o===void 0?void 0:o.available_stock;return{name:o===null||o===void 0?void 0:o.name,variant:i===null||i===void 0?void 0:i.variant_display_options,image:i===null||i===void 0?void 0:i.image,quantity:i.quantity,available_stock:n}}));const e=i===null||i===void 0?void 0:i.some((i=>(i===null||i===void 0?void 0:i.available_stock)<1));return t(s,null,t("sc-dialog",{open:!!i.length&&f()==="draft",noHeader:true,onScRequestClose:i=>i.preventDefault(),class:"stock-alert"},t("sc-dashboard-module",{class:"subscription-cancel",error:this.error,style:{"--sc-dashboard-module-spacing":"1em"}},t("sc-flex",{slot:"heading","align-items":"center","justify-content":"flex-start"},t("sc-icon",{name:"alert-circle",style:{color:"var(--sc-color-primary-500"}}),e?wp.i18n.__("Out of Stock","surecart"):wp.i18n.__("Quantity Update","surecart")),t("span",{slot:"description"},e?wp.i18n.__("Some items are no longer available. Your cart will be updated.","surecart"):wp.i18n.__("Available quantities for these items have changed. Your cart will be updated.","surecart")),t("sc-card",{"no-padding":true},t("sc-table",null,t("sc-table-cell",{slot:"head"},wp.i18n.__("Description","surecart")),t("sc-table-cell",{slot:"head",style:{width:"100px",textAlign:"right"}},wp.i18n.__("Quantity","surecart")),i.map(((e,s)=>{const o=s===i.length-1;return t("sc-table-row",{style:{"--columns":"2",...o?{border:"none"}:{}}},t("sc-table-cell",null,t("sc-flex",{justifyContent:"flex-start",alignItems:"center"},(e===null||e===void 0?void 0:e.image)&&t("img",{...e.image,class:"stock-alert__image"}),t("div",{class:"stock-alert__product-info"},t("h4",null,e.name),(e===null||e===void 0?void 0:e.variant)&&t("span",{class:"stock-alert__variant"},e.variant)))),t("sc-table-cell",{style:{width:"100px",textAlign:"right"}},t("span",{class:"stock-alert__quantity"},t("span",null,e===null||e===void 0?void 0:e.quantity)," ",t("sc-icon",{name:"arrow-right"})," ",t("span",null,Math.max(e===null||e===void 0?void 0:e.available_stock,0)))))}))))),t("sc-button",{slot:"footer",type:"primary",loading:this.busy,onClick:()=>this.onSubmit()},wp.i18n.__("Continue","surecart"),t("sc-icon",{name:"arrow-right",slot:"suffix"})),this.busy&&t("sc-block-ui",{spinner:true})))}};q.style=O;const D=".confirm__icon{margin-bottom:var(--sc-spacing-medium);display:flex;justify-content:center}.confirm__icon-container{background:var(--sc-color-primary-500);width:55px;height:55px;border-radius:999999px;display:flex;align-items:center;justify-content:center;font-size:26px;line-height:1;color:white}sc-dialog::part(overlay){backdrop-filter:blur(4px)}";const H=D;const F=class{constructor(t){i(this,t);this.scOrderPaid=e(this,"scOrderPaid",7);this.scSetState=e(this,"scSetState",7);this.showSuccessModal=false;this.manualPaymentMethod=undefined;this.checkoutStatus=undefined;this.successUrl=undefined}handleConfirmOrderEvent(){if(this.checkoutStatus==="test_mode_restricted"){this.confirmOrder()}}async confirmOrder(){var i;this.manualPaymentMethod=(i=p.manualPaymentMethods||[])===null||i===void 0?void 0:i.find((i=>i.id===m.id));this.showSuccessModal=true;g()}handleSuccessModal(){if(this.showSuccessModal){setTimeout((()=>{var i;(i=this.continueButton)===null||i===void 0?void 0:i.focus()}),50)}}render(){var i,e,o,n,d;return t(s,{key:"3c0c52fb69aacbf3bf4fb797586c7a2432c1f790"},t("slot",{key:"d63060fd4eb7e78e7a658bbd8d17c0cf8707e473"}),t("sc-dialog",{key:"01e59224ca7271e9bd5c7457e374f097e4276a73",open:!!this.showSuccessModal,style:{"--body-spacing":"var(--sc-spacing-xxx-large)","--width":"400px"},noHeader:true,onScRequestClose:i=>i.preventDefault()},t("div",{key:"039b32ae7d4c69f45ee0269422cac7154e333ec3",class:"confirm__icon"},t("div",{key:"1a9da9a6d06ab049b13e26dfc59a89e79de54a87",class:"confirm__icon-container"},t("sc-icon",{key:"3e4b7bd0355bd487dfb6c8064353adb79f348b14",name:"check"}))),t("sc-dashboard-module",{key:"3be338aee9787680a67a7dc62fb1f7c835702f98",heading:wp.i18n.__("Test checkout successful!","surecart"),style:{"--sc-dashboard-module-spacing":"var(--sc-spacing-x-large)",textAlign:"center"}},t("span",{key:"b0ae504ecc5c5ba5bc9f2bd7808cfa3b1ec7b088",slot:"description"},wp.i18n.__("This is a simulated test checkout, and no orders were processed. To perform a test order, please contact your store administrator. ","surecart")),!!((i=this.manualPaymentMethod)===null||i===void 0?void 0:i.name)&&!!((e=this.manualPaymentMethod)===null||e===void 0?void 0:e.instructions)&&t("sc-alert",{key:"a3781ca62e40a451874384561f69d4443efec91e",type:"info",open:true,style:{"text-align":"left"}},t("span",{key:"ead7333597d5ba39dafc5ec79713a3311ac8f316",slot:"title"},(o=this.manualPaymentMethod)===null||o===void 0?void 0:o.name),t("div",{key:"98fd27422acf9b9f822a96735828b99660e02ebe",innerHTML:(n=this.manualPaymentMethod)===null||n===void 0?void 0:n.instructions})),t("sc-button",{key:"fae99645209c19f410aea3814cb15da84e2f714f",href:(d=window===null||window===void 0?void 0:window.scData)===null||d===void 0?void 0:d.home_url,size:"large",type:"primary",ref:i=>this.continueButton=i},wp.i18n.__("Go to Homepage","surecart"),t("sc-icon",{key:"11c366e99b08f2197a044734c748d98d6a29aa35",name:"arrow-right",slot:"suffix"})))))}get el(){return o(this)}static get watchers(){return{checkoutStatus:["handleConfirmOrderEvent"],showSuccessModal:["handleSuccessModal"]}}};F.style=H;const M=class{constructor(e){i(this,e);this.state=undefined}componentDidLoad(){window.addEventListener("beforeunload",(i=>this.warnIfUnsavedChanges(i)),{capture:true})}warnIfUnsavedChanges(i){if(["updating","finalizing","confirming"].includes(this.state)){console.log({e:i});i.preventDefault();i.returnValue=wp.i18n.__("Your payment is processing. Exiting this page could cause an error in your order. Please do not navigate away from this page.","surecart");return i.returnValue}}};const z=class{constructor(e){i(this,e);this.disabled=undefined;this.taxProtocol=undefined;this.hasAddress=undefined;this.hasTaxIDField=undefined;this.hasBumpsField=undefined;this.hasTaxLine=undefined;this.hasBumpLine=undefined;this.hasShippingChoices=undefined;this.hasShippingAmount=undefined;this.hasInvoiceDetails=undefined;this.hasInvoiceMemo=undefined;this.hasTrialLineItem=undefined}handleOrderChange(){var i,e,t,s,o,d,r,a,c;if(this.disabled)return;if(b()){this.addAddressField()}if((t=(e=(i=n.checkout)===null||i===void 0?void 0:i.recommended_bumps)===null||e===void 0?void 0:e.data)===null||t===void 0?void 0:t.length){this.addBumps()}if(!!((s=n.checkout)===null||s===void 0?void 0:s.tax_amount)){this.addTaxLine()}if(((o=n.checkout)===null||o===void 0?void 0:o.shipping_enabled)&&((d=n.checkout)===null||d===void 0?void 0:d.selected_shipping_choice_required)){this.addShippingChoices()}if(!!((r=n.checkout)===null||r===void 0?void 0:r.shipping_amount)){this.addShippingAmount()}if(!!((a=n.checkout)===null||a===void 0?void 0:a.invoice)){this.addInvoiceDetails();this.addInvoiceMemo()}if(!!((c=n.checkout)===null||c===void 0?void 0:c.trial_amount)){this.addTrialLineItem()}}handleHasAddressChange(){if(!this.hasAddress)return;this.handleShippingAddressRequired()}componentWillLoad(){var i,e;this.hasAddress=!!this.el.querySelector("sc-order-shipping-address");this.hasTaxIDField=!!this.el.querySelector("sc-order-tax-id-input");this.hasBumpsField=!!this.el.querySelector("sc-order-bumps");this.hasTaxLine=!!this.el.querySelector("sc-line-item-tax");this.hasShippingChoices=!!this.el.querySelector("sc-shipping-choices");this.hasShippingAmount=!!this.el.querySelector("sc-line-item-shipping");this.hasInvoiceDetails=!!this.el.querySelector("sc-invoice-details");this.hasInvoiceMemo=!!this.el.querySelector("sc-invoice-memo");this.hasTrialLineItem=!!this.el.querySelector("sc-line-item-trial");if(((i=this.taxProtocol)===null||i===void 0?void 0:i.tax_enabled)&&((e=this.taxProtocol)===null||e===void 0?void 0:e.eu_vat_required)){this.addTaxIDField()}this.handleOrderChange();this.removeCheckoutListener=d("checkout",(()=>this.handleOrderChange()));this.removePaymentRequiresShippingListener=d("paymentMethodRequiresShipping",(()=>this.handleOrderChange()))}disconnectedCallback(){this.removeCheckoutListener();this.removePaymentRequiresShippingListener()}handleShippingAddressRequired(){var i;if(!((i=n.checkout)===null||i===void 0?void 0:i.shipping_address_required))return;const e=this.el.querySelector("sc-order-shipping-address");if(!e)return;e.required=true;const t=this.el.querySelector("sc-customer-name");if(!!t){t.required=true;return}const s=this.el.querySelector("sc-customer-firstname");const o=this.el.querySelector("sc-customer-lastname");if(!!s){s.required=true;if(!!o){o.required=true}return}e.requireName=true;e.showName=true}addAddressField(){if(this.hasAddress){return}const i=this.el.querySelector("sc-payment");const e=document.createElement("sc-order-shipping-address");i.parentNode.insertBefore(e,i);if(y()){const e=document.createElement("sc-order-billing-address");e.label=wp.i18n.__("Billing Address","surecart");i.parentNode.insertBefore(e,i)}else{e.label=wp.i18n.__("Address","surecart")}this.hasAddress=true}addTaxIDField(){if(this.hasTaxIDField)return;const i=this.el.querySelector("sc-payment");const e=document.createElement("sc-order-tax-id-input");i.parentNode.insertBefore(e,i);this.hasTaxIDField=true}addBumps(){if(this.hasBumpsField)return;const i=this.el.querySelector("sc-order-billing-address")||this.el.querySelector("sc-payment");const e=document.createElement("sc-order-bumps");i===null||i===void 0?void 0:i.parentNode.insertBefore(e,i.nextSibling);this.hasBumpsField=true}addTaxLine(){var i;if(this.hasTaxLine)return;const e=this.el.querySelector("sc-line-item-total[total=total]");const t=document.createElement("sc-line-item-tax");if(!e)return;if(((i=e===null||e===void 0?void 0:e.previousElementSibling)===null||i===void 0?void 0:i.tagName)==="SC-DIVIDER"){e.parentNode.insertBefore(t,e.previousElementSibling)}else{e.parentNode.insertBefore(t,e)}this.hasTaxLine=true}addShippingChoices(){if(this.hasShippingChoices)return;const i=this.el.querySelector("sc-payment");const e=document.createElement("sc-shipping-choices");i.parentNode.insertBefore(e,i);this.hasShippingChoices=true}addShippingAmount(){var i;if(this.hasShippingAmount)return;let e=this.el.querySelector("sc-line-item-tax");const t=this.el.querySelector("sc-line-item-total[total=total]");if(!t)return;if(!e){e=((i=t===null||t===void 0?void 0:t.previousElementSibling)===null||i===void 0?void 0:i.tagName)==="SC-DIVIDER"?t.previousElementSibling:t}const s=document.createElement("sc-line-item-shipping");e.parentNode.insertBefore(s,e);this.hasShippingAmount=true}addInvoiceDetails(){if(this.hasInvoiceDetails)return;let i=this.el.querySelector("sc-line-items");const e=document.createElement("sc-invoice-details");i.parentNode.insertBefore(e,i);const t=document.createElement("sc-line-item-invoice-number");e.appendChild(t);const s=document.createElement("sc-line-item-invoice-due-date");e.appendChild(s);const o=document.createElement("sc-line-item-invoice-receipt-download");e.appendChild(o);const n=document.createElement("sc-divider");e.appendChild(n);this.hasInvoiceDetails=true}addInvoiceMemo(){if(this.hasInvoiceMemo)return;const i=this.el.querySelector("sc-order-summary");const e=document.createElement("sc-invoice-details");i.parentNode.insertBefore(e,i.nextSibling);const t=document.createElement("sc-invoice-memo");e.appendChild(t);this.hasInvoiceMemo=true}addTrialLineItem(){if(this.hasTrialLineItem)return;const i=this.el.querySelector("sc-line-item-total[total=subtotal]");const e=document.createElement("sc-line-item-trial");if(!i)return;i.parentNode.insertBefore(e,i.nextSibling);this.hasTrialLineItem=true}render(){return t("slot",{key:"1aeeef762063b3744670ce62d3028a82c6dafc3c"})}get el(){return o(this)}static get watchers(){return{hasAddress:["handleHasAddressChange"]}}};const U=class{constructor(e){i(this,e)}componentWillLoad(){this.maybeAddErrorsComponent()}maybeAddErrorsComponent(){var i,e;if(!!this.el.querySelector("sc-checkout-form-errors"))return;const t=document.createElement("sc-checkout-form-errors");(e=(i=this.el.querySelector("sc-form"))===null||i===void 0?void 0:i.prepend)===null||e===void 0?void 0:e.call(i,t)}render(){return t("slot",{key:"34c29b55dc72b6c4d524eab8b4cd15bc85799f9e"})}get el(){return o(this)}};const J=class{constructor(t){i(this,t);this.scSetCheckoutFormState=e(this,"scSetCheckoutFormState",7);this._stateService=w(_);this.checkoutState=_.initialState}setState(i){const{send:e}=this._stateService;r(i);return e(i)}handleCheckoutStateChange(i){this.scSetCheckoutFormState.emit(i.value)}componentWillLoad(){this._stateService.subscribe((i=>this.checkoutState=i));this._stateService.start()}disconnectedCallback(){this._stateService.stop()}handleSetStateEvent(i){this.setState(i.detail)}async handlePaid(){this.setState("PAID")}render(){if(this.checkoutState.value==="expired"){return t("sc-block-ui",null,t("div",null,wp.i18n.__("Please refresh the page.","surecart")))}return t("slot",null)}static get watchers(){return{checkoutState:["handleCheckoutStateChange"]}}};const N=":host{display:block}";const V=N;const Y=class{constructor(t){i(this,t);this.scSetLoggedIn=e(this,"scSetLoggedIn",7);this.scSetCustomer=e(this,"scSetCustomer",7);this.loggedIn=undefined;this.order=undefined;this.notice=undefined;this.open=undefined;this.loading=undefined;this.error=undefined}handleLoginPrompt(){this.open=true}handleLoginDialogChange(i){if(i){setTimeout((()=>{this.loginForm.querySelector("sc-input").triggerFocus()}),100)}}handleLoggedInChange(i,e){if(e===false&&i){this.notice=true}}handleOrderChange(i,e){if((i===null||i===void 0?void 0:i.updated_at)!==(e===null||e===void 0?void 0:e.updated_at)){this.notice=false}}async handleFormSubmit(i){i.preventDefault();i.stopImmediatePropagation();this.error=null;const{login:e,password:t}=await i.target.getFormJson();try{this.loading=true;const{name:i,email:s}=await x({method:"POST",path:"surecart/v1/login",data:{login:e,password:t}});this.scSetLoggedIn.emit(true);this.scSetCustomer.emit({name:i,email:s});this.open=false}catch(i){console.error(i);this.error=(i===null||i===void 0?void 0:i.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=false}}render(){return t(s,{key:"4c5e121736909c4e3462f3a518103730c078d55d"},!!this.notice&&t("sc-alert",{key:"c0ca8a0477fc6c21452b25d321ff5a1c5cf24ad4",type:"success",open:true,style:{marginBottom:"var(--sc-form-row-spacing)"},closable:true},t("span",{key:"71983897ddbb14fe8371077bef734f677b25ed72",slot:"title"},wp.i18n.__("Welcome back!","surecart")),wp.i18n.__("You have logged in successfully.","surecart")),t("slot",{key:"5181b5b557e88ea9c73dfdc366440120285f7f69"}),!this.loggedIn&&t("sc-dialog",{key:"9e680f662c0be234101926960a75858cbbc9f3d3",label:wp.i18n.__("Login to your account","surecart"),open:this.open,onScRequestClose:()=>this.open=false},t("sc-form",{key:"46b1dae6809de40d830278ee6c8fe69fef3a4d3c",ref:i=>this.loginForm=i,onScFormSubmit:i=>{i.preventDefault();i.stopImmediatePropagation()},onScSubmit:i=>this.handleFormSubmit(i)},!!this.error&&t("sc-alert",{key:"64d295f44f8b6236a80d6344ceb899a6a4e475ee",type:"danger",open:!!this.error},this.error),t("sc-input",{key:"8a50f469d7f606debd6b29bf95344e4f1ba85d0b",label:wp.i18n.__("Email or Username","surecart"),type:"text",name:"login",required:true,autofocus:this.open}),t("sc-input",{key:"2ebc186a50e92e48f355aa651db98a9ee838d0d5",label:wp.i18n.__("Password","surecart"),type:"password",name:"password",required:true}),t("sc-button",{key:"6dc1d2df070be463e5b90fc007dfc0ce68e48820",type:"primary",full:true,loading:this.loading,submit:true},wp.i18n.__("Login","surecart")))))}static get watchers(){return{open:["handleLoginDialogChange"],loggedIn:["handleLoggedInChange"],order:["handleOrderChange"]}}};Y.style=V;const G=".confirm__icon{margin-bottom:var(--sc-spacing-medium);display:flex;justify-content:center}.confirm__icon-container{background:var(--sc-color-primary-500);width:55px;height:55px;border-radius:999999px;display:flex;align-items:center;justify-content:center;font-size:26px;line-height:1;color:white}sc-dialog::part(overlay){backdrop-filter:blur(4px)}";const W=G;const Z=class{constructor(t){i(this,t);this.scOrderPaid=e(this,"scOrderPaid",7);this.scSetState=e(this,"scSetState",7);this.showSuccessModal=false;this.manualPaymentMethod=undefined;this.checkoutStatus=undefined;this.successUrl=undefined}handleConfirmOrderEvent(){if(this.checkoutStatus==="confirming"){this.confirmOrder()}else if(this.checkoutStatus==="confirmed"){E(wp.i18n.__("Order has been confirmed. Please select continue to go to the next step.","surecart"))}}async confirmOrder(){var i,e,t,s;try{n.checkout=await x({method:"PATCH",path:T(`surecart/v1/checkouts/${(i=n===null||n===void 0?void 0:n.checkout)===null||i===void 0?void 0:i.id}/confirm`,{expand:c})});this.scSetState.emit("CONFIRMED")}catch(i){console.error(i);S(i)}finally{this.manualPaymentMethod=((e=n.checkout)===null||e===void 0?void 0:e.manual_payment_method)||null;const i=n.checkout;const o=n.formId;if(!!((t=i===null||i===void 0?void 0:i.current_upsell)===null||t===void 0?void 0:t.permalink)){setTimeout((()=>{var e;return window.location.assign(T((e=i===null||i===void 0?void 0:i.current_upsell)===null||e===void 0?void 0:e.permalink,{sc_checkout_id:i===null||i===void 0?void 0:i.id,sc_form_id:o}))}),50);g();return}const d=((s=i===null||i===void 0?void 0:i.metadata)===null||s===void 0?void 0:s.success_url)||this.successUrl;if(d){this.scSetState.emit("REDIRECT");const e=T(d,{sc_order:i===null||i===void 0?void 0:i.id});setTimeout((()=>window.location.assign(e)),50)}else{this.showSuccessModal=true}g()}}getSuccessUrl(){var i,e,t,s,o;const d=((e=(i=n.checkout)===null||i===void 0?void 0:i.metadata)===null||e===void 0?void 0:e.success_url)||this.successUrl;return d?T(d,{sc_order:(t=n.checkout)===null||t===void 0?void 0:t.id}):(o=(s=window===null||window===void 0?void 0:window.scData)===null||s===void 0?void 0:s.pages)===null||o===void 0?void 0:o.dashboard}handleSuccessModal(){if(this.showSuccessModal){setTimeout((()=>{var i;(i=this.continueButton)===null||i===void 0?void 0:i.focus()}),50)}}render(){var i,e,o,n,d,r,a,c,l,u;return t(s,{key:"4384f70d5b8f8e0a41af91ecf23bb78b7c553ff3"},t("slot",{key:"8ef9ef6e4bc086364989d78290a17ae0c46cb779"}),t("sc-dialog",{key:"7e40ebffe1522f2c68c01db6d15bcb2e11b78765",open:!!this.showSuccessModal,style:{"--body-spacing":"var(--sc-spacing-xxx-large)","--width":"400px"},noHeader:true,onScRequestClose:i=>i.preventDefault()},t("div",{key:"cd7e49ee98c6ced9ea55bb6276d56a8a2f91f882",class:"confirm__icon"},t("div",{key:"220e52f385ba3e8f1993b6b8a18cdda812d4e113",class:"confirm__icon-container"},t("sc-icon",{key:"0c7a00f086fa9a82670b0450090ec6c5618309b0",name:"check"}))),t("sc-dashboard-module",{key:"2a599f9af9af533ae97b8e164e9e777a92146456",heading:((e=(i=k===null||k===void 0?void 0:k.text)===null||i===void 0?void 0:i.success)===null||e===void 0?void 0:e.title)||wp.i18n.__("Thanks for your order!","surecart"),style:{"--sc-dashboard-module-spacing":"var(--sc-spacing-x-large)",textAlign:"center"}},t("span",{key:"8d099f11e11fe65861ead8c9b21bc258f5b67da9",slot:"description"},((n=(o=k===null||k===void 0?void 0:k.text)===null||o===void 0?void 0:o.success)===null||n===void 0?void 0:n.description)||wp.i18n.__("Your payment was successful. A receipt is on its way to your inbox.","surecart")),!!((d=this.manualPaymentMethod)===null||d===void 0?void 0:d.name)&&!!((r=this.manualPaymentMethod)===null||r===void 0?void 0:r.instructions)&&t("sc-alert",{key:"78f370b58a2cbf0c5196e13f62a5708b15c6748f",type:"info",open:true,style:{"text-align":"left"}},t("span",{key:"dcefbd797b46f79465723fb7209da8583c43a6f7",slot:"title"},(a=this.manualPaymentMethod)===null||a===void 0?void 0:a.name),t("div",{key:"49c00b04bcef2cae521b673c45bacacb3d040f08",innerHTML:(c=this.manualPaymentMethod)===null||c===void 0?void 0:c.instructions})),t("sc-button",{key:"68997dd337047d7afe499ac89efcc33ade19121c",href:this.getSuccessUrl(),size:"large",type:"primary",ref:i=>this.continueButton=i},((u=(l=k===null||k===void 0?void 0:k.text)===null||l===void 0?void 0:l.success)===null||u===void 0?void 0:u.button)||wp.i18n.__("Continue","surecart"),t("sc-icon",{key:"e4b6a695b971816e2bb00559cf3c8601997da1f1",name:"arrow-right",slot:"suffix"})))))}get el(){return o(this)}static get watchers(){return{checkoutStatus:["handleConfirmOrderEvent"],showSuccessModal:["handleSuccessModal"]}}};Z.style=W;const $=class{constructor(t){i(this,t);this.scUpdateOrderState=e(this,"scUpdateOrderState",7);this.scUpdateDraftState=e(this,"scUpdateDraftState",7);this.scPaid=e(this,"scPaid",7);this.scSetState=e(this,"scSetState",7);this.prices=[];this.persist=true}handlePricesChange(){let i=this.addInitialPrices()||[];if(!(i===null||i===void 0?void 0:i.length)){return}return this.loadUpdate({line_items:i})}async finalize(){return await this.handleFormSubmit()}async getFormData(){let i={};const e=this.el.querySelector("sc-form");if(e){const t=await e.getFormJson();i=L(t)}return i}async handleFormSubmit(){var i,e,t,s,o,d,a,c,u,h,v,f;C();r("FINALIZE");if(((i=n===null||n===void 0?void 0:n.checkout)===null||i===void 0?void 0:i.payment_method_required)&&(m===null||m===void 0?void 0:m.id)==="stripe"&&p.config.stripe.paymentElement){if(!((e=p===null||p===void 0?void 0:p.instances)===null||e===void 0?void 0:e.stripeElements)){r("REJECT");this.handleErrorResponse({message:"Stripe Elements not found.",code:"stripe_elements_not_found"});return new Error("Stripe Elements not found.")}const{error:i}=await((t=p===null||p===void 0?void 0:p.instances)===null||t===void 0?void 0:t.stripeElements.submit());if(i){console.error({error:i});r("REJECT");S(i);return}}let g=await this.getFormData();if(((s=window===null||window===void 0?void 0:window.scData)===null||s===void 0?void 0:s.recaptcha_site_key)&&(window===null||window===void 0?void 0:window.grecaptcha)){try{g["grecaptcha"]=await window.grecaptcha.execute(window.scData.recaptcha_site_key,{action:"surecart_checkout_submit"})}catch(i){console.error(i);r("REJECT");this.handleErrorResponse(i);return new Error(i===null||i===void 0?void 0:i.message)}}try{await this.update(g)}catch(i){console.error(i);r("REJECT");this.handleErrorResponse(i)}try{n.checkout=await l({id:(o=n===null||n===void 0?void 0:n.checkout)===null||o===void 0?void 0:o.id,query:{...(m===null||m===void 0?void 0:m.method)?{payment_method_type:m===null||m===void 0?void 0:m.method}:{},return_url:T(window.location.href,{...((d=n===null||n===void 0?void 0:n.checkout)===null||d===void 0?void 0:d.id)?{checkout_id:(a=n===null||n===void 0?void 0:n.checkout)===null||a===void 0?void 0:a.id}:{},is_surecart_payment_redirect:true})},data:g,processor:{id:m.id,manual:m.manual}});if((v=(h=(u=(c=n.checkout)===null||c===void 0?void 0:c.payment_intent)===null||u===void 0?void 0:u.processor_data)===null||h===void 0?void 0:h.mollie)===null||v===void 0?void 0:v.checkout_url){r("PAYING");return setTimeout((()=>{var i,e,t,s;return window.location.assign((s=(t=(e=(i=n.checkout)===null||i===void 0?void 0:i.payment_intent)===null||e===void 0?void 0:e.processor_data)===null||t===void 0?void 0:t.mollie)===null||s===void 0?void 0:s.checkout_url)}),50)}if(["paid","processing"].includes((f=n.checkout)===null||f===void 0?void 0:f.status)){this.scPaid.emit()}setTimeout((()=>{r("PAYING")}),50);return n.checkout}catch(i){console.error(i);this.handleErrorResponse(i);return new Error(i===null||i===void 0?void 0:i.message)}}async handlePaid(){r("PAID")}async handleAbandonedCartUpdate(i){const e=i.detail;this.loadUpdate({abandoned_checkout_enabled:e})}componentDidLoad(){this.findOrCreateOrder()}async findOrCreateOrder(){var i;const{redirect_status:e,checkout_id:t,line_items:s,coupon:o,is_surecart_payment_redirect:d}=j(window.location.href);window.history.replaceState({},document.title,R(window.location.href,"redirect_status","coupon","line_items","confirm_checkout_id","checkout_id","no_cart","is_surecart_payment_redirect"));if(!!d&&!!t){r("FINALIZE");r("PAYING");return this.handleCheckoutIdFromUrl(t,o,{refresh_status:true})}if(!!e){return this.handleRedirectStatus(e,t)}if(!!t){return this.handleCheckoutIdFromUrl(t,o)}if(!!s){return this.handleInitialLineItems(s,o)}const a=(i=n===null||n===void 0?void 0:n.checkout)===null||i===void 0?void 0:i.id;if(a&&this.persist){return this.handleExistingCheckout(a,o)}return this.handleNewCheckout(o)}async handleRedirectStatus(i,e){var t,s;console.info("Handling payment redirect.");if(i==="failed"){S(wp.i18n.__("Payment unsuccessful. Please try again.","surecart"));return}if(!e){S(wp.i18n.__("Could not find checkout. Please contact us before attempting to purchase again.","surecart"));return}try{r("FINALIZE");n.checkout=await u({id:e,query:{refresh_status:true}});if(((t=n.checkout)===null||t===void 0?void 0:t.status)&&["paid","processing"].includes((s=n.checkout)===null||s===void 0?void 0:s.status)){setTimeout((()=>{r("PAID");this.scPaid.emit()}),100)}}catch(i){this.handleErrorResponse(i)}}async handleCheckoutIdFromUrl(i,e="",t={}){var s;console.info("Handling existing checkout from url.",e,i);if(e){return this.loadUpdate({id:i,discount:{promotion_code:e},refresh_line_items:true,...t})}try{r("FETCH");n.checkout=await u({id:i,query:{refresh_line_items:true,...t}});r("RESOLVE")}catch(i){this.handleErrorResponse(i)}switch((s=n.checkout)===null||s===void 0?void 0:s.status){case"paid":case"processing":return setTimeout((()=>{r("FINALIZE");r("PAID");this.scPaid.emit()}),100);case"payment_failed":S({message:wp.i18n.__("Payment unsuccessful.","surecart")});r("REJECT");return;case"payment_intent_canceled":r("REJECT");return;case"canceled":g();S({message:wp.i18n.__("Payment canceled. Please try again.","surecart")});r("REJECT");return}}async handleInitialLineItems(i,e){console.info("Handling initial line items.");const t=this.el.querySelector("sc-order-shipping-address");return this.loadUpdate({line_items:i,refresh_line_items:true,...e?{discount:{promotion_code:e}}:{},...(t===null||t===void 0?void 0:t.defaultCountry)?{shipping_address:{country:t===null||t===void 0?void 0:t.defaultCountry}}:{}})}async handleNewCheckout(i){var e,t,s;const o=this.getFormData();let d=n.initialLineItems||[];const a=this.el.querySelector("sc-order-shipping-address");try{r("FETCH");n.checkout=await h({data:{...o,...i?{discount:{promotion_code:i}}:{},...(a===null||a===void 0?void 0:a.defaultCountry)?{shipping_address:{country:a===null||a===void 0?void 0:a.defaultCountry}}:{},line_items:d,...((e=n.taxProtocol)===null||e===void 0?void 0:e.eu_vat_required)?{tax_identifier:{number_type:"eu_vat"}}:{}}});r("RESOLVE")}catch(i){console.error(i);this.handleErrorResponse(i);if(((s=(t=i===null||i===void 0?void 0:i.additional_errors)===null||t===void 0?void 0:t[0])===null||s===void 0?void 0:s.code)==="checkout.discount.coupon.blank"){await this.handleNewCheckout(false);S(i)}}}async handleExistingCheckout(i,e){var t,s,o;if(!i)return this.handleNewCheckout(e);console.info("Handling existing checkout.");try{r("FETCH");n.checkout=await v({id:i,data:{...e?{discount:{promotion_code:e}}:{},...((t=n.taxProtocol)===null||t===void 0?void 0:t.eu_vat_required)?{tax_identifier:{number_type:"eu_vat"}}:{},refresh_line_items:true}});r("RESOLVE")}catch(e){console.error(e);this.handleErrorResponse(e);if(((o=(s=e===null||e===void 0?void 0:e.additional_errors)===null||s===void 0?void 0:s[0])===null||o===void 0?void 0:o.code)==="checkout.discount.coupon.blank"){await this.handleExistingCheckout(i,false);S(e)}}}async handleErrorResponse(i){var e,t,s,o,d,a;if(["checkout.not_found"].includes(i===null||i===void 0?void 0:i.code)){g();return this.handleNewCheckout(false)}if(["test_mode_restricted"].includes(i===null||i===void 0?void 0:i.code)){r("TEST_MODE_RESTRICTED");return}const c=((i===null||i===void 0?void 0:i.additional_errors)||[]).some((i=>{var e,t;const s=((t=(e=i===null||i===void 0?void 0:i.data)===null||e===void 0?void 0:e.options)===null||t===void 0?void 0:t.purchasable_statuses)||[];return["price_old_version","variant_old_version"].some((i=>s.includes(i)))}));if(c){await this.loadUpdate({id:(e=n===null||n===void 0?void 0:n.checkout)===null||e===void 0?void 0:e.id,refresh_line_items:true,status:"draft"});I(((s=(t=i===null||i===void 0?void 0:i.additional_errors)===null||t===void 0?void 0:t[0])===null||s===void 0?void 0:s.message)||wp.i18n.__("Some products in your order were outdated and have been updated. Please review your order summary before proceeding to payment.","surecart"));r("REJECT");return}if(((d=(o=i===null||i===void 0?void 0:i.additional_errors)===null||o===void 0?void 0:o[0])===null||d===void 0?void 0:d.code)==="checkout.product.out_of_stock"){this.fetch();r("REJECT");return}if(["order.invalid_status_transition"].includes(i===null||i===void 0?void 0:i.code)){await this.loadUpdate({id:(a=n===null||n===void 0?void 0:n.checkout)===null||a===void 0?void 0:a.id,status:"draft"});this.handleFormSubmit();return}if((i===null||i===void 0?void 0:i.code)==="rest_cookie_invalid_nonce"){r("EXPIRE");return}if((i===null||i===void 0?void 0:i.code)==="readonly"){g();window.location.assign(R(window.location.href,"order"));return}S(i);r("REJECT")}async initialize(i={}){let e=n.initialLineItems||[];return this.loadUpdate({...(e===null||e===void 0?void 0:e.length)?{line_items:e}:{},...i})}addInitialPrices(){var i;if(!((i=this===null||this===void 0?void 0:this.prices)===null||i===void 0?void 0:i.length))return[];if(this.prices.some((i=>!(i===null||i===void 0?void 0:i.id)))){return}return this.prices.map((i=>({price_id:i.id,quantity:i.quantity,variant:i.variant})))}getSessionId(){var i,e;const t=P(window.location.href,"checkout_id");if(!!t){return t}if((i=n===null||n===void 0?void 0:n.checkout)===null||i===void 0?void 0:i.id){return(e=n===null||n===void 0?void 0:n.checkout)===null||e===void 0?void 0:e.id}return null}async fetchCheckout(i,{query:e={},data:t={}}={}){try{r("FETCH");const s=await v({id:i,query:e,data:t});r("RESOLVE");return s}catch(i){this.handleErrorResponse(i)}}async fetch(i={}){try{r("FETCH");n.checkout=await u({id:this.getSessionId(),query:i});r("RESOLVE")}catch(i){this.handleErrorResponse(i)}}async update(i={},e={}){try{n.checkout=await v({id:(i===null||i===void 0?void 0:i.id)?i.id:this.getSessionId(),data:i,query:e})}catch(i){if(["checkout.not_found"].includes(i===null||i===void 0?void 0:i.code)){g();return this.initialize()}console.error(i);throw i}}async loadUpdate(i={}){try{r("FETCH");await this.update(i);r("RESOLVE")}catch(i){this.handleErrorResponse(i)}}render(){return t("sc-line-items-provider",{key:"4a3533ae8d7a28a6c3fd06085e6495c49830764e",order:n===null||n===void 0?void 0:n.checkout,onScUpdateLineItems:i=>this.loadUpdate({line_items:i.detail})},t("slot",{key:"a5d1623d04bc771f017020180b99114ef3751350"}))}get el(){return o(this)}static get watchers(){return{prices:["handlePricesChange"]}}};export{q as sc_checkout_stock_alert,F as sc_checkout_test_complete,M as sc_checkout_unsaved_changes_warning,z as sc_form_components_validator,U as sc_form_error_provider,J as sc_form_state_provider,Y as sc_login_provider,Z as sc_order_confirm_provider,$ as sc_session_provider}; //# sourceMappingURL=p-b80843e4.entry.js.map