import{r as i,h as s}from"./p-dfbe004d.js";import{_ as n}from"./p-8415f806.js";import"./p-fd56940f.js";import{a as e}from"./p-7393a06c.js";import{a as t}from"./p-1c2e2695.js";import"./p-9a7a47e8.js";const l=class{constructor(s){i(this,s)}async handleSubmit(i){var s;this.loading=!0;try{const{email:n,first_name:l,last_name:a,phone:o,billing_matches_shipping:r,shipping_name:c,shipping_city:d,"tax_identifier.number_type":p,"tax_identifier.number":u,shipping_country:_,shipping_line_1:h,shipping_postal_code:m,shipping_state:g,billing_name:v,billing_city:b,billing_country:y,billing_line_1:f,billing_postal_code:w,billing_state:x}=await i.target.getFormJson();await e({path:t(`surecart/v1/customers/${null===(s=this.customer)||void 0===s?void 0:s.id}`,{expand:["tax_identifier"]}),method:"PATCH",data:{email:n,first_name:l,last_name:a,phone:o,billing_matches_shipping:"on"===r,shipping_address:{name:c,city:d,country:_,line_1:h,postal_code:m,state:g},billing_address:{name:v,city:b,country:y,line_1:f,postal_code:w,state:x},...u&&p?{tax_identifier:{number:u,number_type:p}}:{}}}),this.successUrl?window.location.assign(this.successUrl):this.loading=!1}catch(i){this.error=(null==i?void 0:i.message)||n("Something went wrong","surecart"),this.loading=!1}}render(){var i,e,t,l,a,o,r,c,d,p,u,_;return s("sc-dashboard-module",{class:"customer-edit",error:this.error},s("span",{slot:"heading"},this.heading||n("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"},n("Test","surecart"))),s("sc-card",null,s("sc-form",{onScFormSubmit:i=>this.handleSubmit(i)},s("sc-columns",{style:{"--sc-column-spacing":"var(--sc-spacing-medium)"}},s("sc-column",null,s("sc-input",{label:n("First Name","surecart"),name:"first_name",value:null===(e=this.customer)||void 0===e?void 0:e.first_name})),s("sc-column",null,s("sc-input",{label:n("Last Name","surecart"),name:"last_name",value:null===(t=this.customer)||void 0===t?void 0:t.last_name}))),s("sc-column",null,s("sc-phone-input",{label:n("Phone","surecart"),name:"phone",value:null===(l=this.customer)||void 0===l?void 0:l.phone})),s("div",null,s("sc-address",{label:n("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"},n("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:n("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===(_=null===(u=this.customer)||void 0===u?void 0:u.tax_identifier)||void 0===_?void 0:_.number_type}),s("div",null,s("sc-button",{type:"primary",full:!0,submit:!0},n("Save","surecart"))))),this.loading&&s("sc-block-ui",{spinner:!0}))}};l.style=":host{display:block;position:relative}.customer-edit{display:grid;gap:0.75em}";export{l as sc_customer_edit}