import{r as i,h as s}from"./p-b891c2f1.js";import{_ as e}from"./p-684c85b4.js";import"./p-aafd8ea4.js";import{a as n}from"./p-6fd3642a.js";import{a as l}from"./p-1c2e2695.js";import"./p-112455b1.js";const t=class{constructor(s){i(this,s)}async handleSubmit(i){var s;this.loading=!0;try{const{email:e,name:t,phone:a,billing_matches_shipping:o,shipping_name:r,shipping_city:c,"tax_identifier.number_type":d,"tax_identifier.number":p,shipping_country:u,shipping_line_1:h,shipping_postal_code:m,shipping_state:_,billing_name:g,billing_city:v,billing_country:b,billing_line_1:y,billing_postal_code:f,billing_state:w}=await i.target.getFormJson();await n({path:l(`surecart/v1/customers/${null===(s=this.customer)||void 0===s?void 0:s.id}`,{expand:["tax_identifier"]}),method:"PATCH",data:{email:e,name:t,phone:a,billing_matches_shipping:"on"===o,shipping_address:{name:r,city:c,country:u,line_1:h,postal_code:m,state:_},billing_address:{name:g,city:v,country:b,line_1:y,postal_code:f,state:w},...p&&d?{tax_identifier:{number:p,number_type:d}}:{}}}),this.successUrl?window.location.assign(this.successUrl):this.loading=!1}catch(i){this.error=(null==i?void 0:i.message)||e("Something went wrong","surecart"),this.loading=!1}}render(){var i,n,l,t,a,o,r,c,d,p,u,h;return s("sc-dashboard-module",{class:"customer-edit",error:this.error},s("span",{slot:"heading"},this.heading||e("Update Billing Details","surecart")," ",!(null===(i=null==this?void 0:this.customer)||void 0===i?void 0:i.live_mode)&&s("sc-tag",{type:"warning",size:"small"},e("Test","surecart"))),s("sc-card",null,s("sc-form",{onScFormSubmit:i=>this.handleSubmit(i)},s("sc-input",{label:e("Billing Email","surecart"),name:"email",value:null===(n=this.customer)||void 0===n?void 0:n.email,required:!0}),s("sc-columns",{style:{"--sc-column-spacing":"var(--sc-spacing-medium)"}},s("sc-column",null,s("sc-input",{label:e("Name","surecart"),name:"name",value:null===(l=this.customer)||void 0===l?void 0:l.name})),s("sc-column",null,s("sc-input",{label:e("Phone","surecart"),name:"phone",value:null===(t=this.customer)||void 0===t?void 0:t.phone}))),s("div",null,s("sc-address",{label:e("Shipping Address","surecart"),showName:!0,address:{...null===(a=this.customer)||void 0===a?void 0:a.shipping_address},required:!1,names:{name:"shipping_name",country:"shipping_country",line_1:"shipping_line_1",line_2:"shipping_line_2",city:"shipping_city",postal_code:"shipping_postal_code",state:"shipping_state"}})),s("div",null,s("sc-switch",{name:"billing_matches_shipping",checked:null===(o=this.customer)||void 0===o?void 0:o.billing_matches_shipping,onScChange:i=>{this.customer={...this.customer,billing_matches_shipping:i.target.checked}},value:"on"},e("Billing address same as shipping","surecart"))),s("div",{style:{display:(null===(r=this.customer)||void 0===r?void 0:r.billing_matches_shipping)?"none":"block"}},s("sc-address",{label:e("Billing Address","surecart"),showName:!0,address:{...null===(c=this.customer)||void 0===c?void 0:c.billing_address},names:{name:"billing_name",country:"billing_country",line_1:"billing_line_1",line_2:"billing_line_2",city:"billing_city",postal_code:"billing_postal_code",state:"billing_state"},required:!1})),s("sc-tax-id-input",{show:!0,number:null===(p=null===(d=this.customer)||void 0===d?void 0:d.tax_identifier)||void 0===p?void 0:p.number,type:null===(h=null===(u=this.customer)||void 0===u?void 0:u.tax_identifier)||void 0===h?void 0:h.number_type}),s("div",null,s("sc-button",{type:"primary",full:!0,submit:!0},e("Save","surecart"))))),this.loading&&s("sc-block-ui",{spinner:!0}))}};t.style=":host{display:block;position:relative}.customer-edit{display:grid;gap:0.75em}";export{t as sc_customer_edit}