JezK
Edit File: sc-customer-edit.js
import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import"./fetch.js";import{d as defineCustomElement$q}from"./sc-address2.js";import{d as defineCustomElement$p}from"./sc-address-suggestions2.js";import{d as defineCustomElement$o}from"./sc-alert2.js";import{d as defineCustomElement$n}from"./sc-block-ui2.js";import{d as defineCustomElement$m}from"./sc-button2.js";import{d as defineCustomElement$l}from"./sc-card2.js";import{d as defineCustomElement$k}from"./sc-checkbox2.js";import{d as defineCustomElement$j}from"./sc-column2.js";import{d as defineCustomElement$i}from"./sc-columns2.js";import{d as defineCustomElement$h}from"./sc-dashboard-module2.js";import{d as defineCustomElement$g}from"./dropdown.js";import{d as defineCustomElement$f}from"./sc-flex2.js";import{d as defineCustomElement$e}from"./sc-form2.js";import{d as defineCustomElement$d}from"./sc-form-control2.js";import{d as defineCustomElement$c}from"./sc-icon2.js";import{d as defineCustomElement$b}from"./sc-input2.js";import{d as defineCustomElement$a}from"./sc-menu2.js";import{d as defineCustomElement$9}from"./sc-menu-item2.js";import{d as defineCustomElement$8}from"./sc-menu-label2.js";import{d as defineCustomElement$7}from"./sc-phone-input2.js";import{d as defineCustomElement$6}from"./sc-select2.js";import{d as defineCustomElement$5}from"./sc-spinner2.js";import{d as defineCustomElement$4}from"./sc-tag2.js";import{d as defineCustomElement$3}from"./sc-tax-id-input2.js";import{d as defineCustomElement$2}from"./sc-visually-hidden2.js";import{a as addQueryArgs}from"./add-query-args.js";import{a as apiFetch}from"./index4.js";const scCustomerEditCss=":host{display:block;position:relative}.customer-edit{display:grid;gap:0.75em}",ScCustomerEditStyle0=scCustomerEditCss,ScCustomerEdit$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.heading=void 0,this.customer=void 0,this.successUrl=void 0,this.loading=void 0,this.error=void 0}async handleSubmit(e){var s,t;this.loading=!0;try{const{email:t,first_name:i,last_name:n,phone:c,billing_matches_shipping:o,shipping_name:m,shipping_city:a,"tax_identifier.number_type":d,"tax_identifier.number":l,shipping_country:r,shipping_line_1:u,shipping_line_2:f,shipping_postal_code:p,shipping_state:b,billing_name:h,billing_city:g,billing_country:_,billing_line_1:E,billing_line_2:C,billing_postal_code:y,billing_state:k}=await e.target.getFormJson();this.customer.billing_address={name:h,city:g,country:_,line_1:E,line_2:C,postal_code:y,state:k},this.customer.shipping_address={name:m,city:a,country:r,line_1:u,line_2:f,postal_code:p,state:b},await apiFetch({path:addQueryArgs(`surecart/v1/customers/${null===(s=this.customer)||void 0===s?void 0:s.id}`,{expand:["tax_identifier"]}),method:"PATCH",data:{email:t,first_name:i,last_name:n,phone:c,billing_matches_shipping:!0===o||"on"===o,shipping_address:this.customer.shipping_address,billing_address:this.customer.billing_address,...l&&d?{tax_identifier:{number:l,number_type:d}}:{}}}),this.successUrl?window.location.assign(this.successUrl):this.loading=!1}catch(e){this.error=(null===(t=null==e?void 0:e.additional_errors)||void 0===t?void 0:t.length)?e.additional_errors.map((e=>e.message)).join(", "):(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart"),this.loading=!1}}render(){var e,s,t,i,n,c,o,m,a,d,l,r;return h("sc-dashboard-module",{key:"b0868e6cc2d8789718662e8584c6eb79652e4b48",class:"customer-edit",error:this.error},h("span",{key:"60f3719bd34ec30b09abdb5d879329135736cefc",slot:"heading"},this.heading||wp.i18n.__("Update Billing Details","surecart")," ",!(null===(e=null==this?void 0:this.customer)||void 0===e?void 0:e.live_mode)&&h("sc-tag",{key:"8b943872648c8a9562ce000e9d183f4cfeada128",type:"warning",size:"small"},wp.i18n.__("Test","surecart"))),h("sc-card",{key:"23a3cad6c0e61c5812ac39f105c6ab639fbe5350"},h("sc-form",{key:"8adfa8259521ae911fd6ce44c944bb5bb8e4b4dc",onScFormSubmit:e=>this.handleSubmit(e)},h("sc-columns",{key:"fcc7c56a09ca25e4cc16bf57c5b102cb3a32fdfa",style:{"--sc-column-spacing":"var(--sc-spacing-medium)"}},h("sc-column",{key:"7a244a14f9c7aea993b7a65f1fa1bb8fea9c1012"},h("sc-input",{key:"5a53ad092fc6ceeff375d240e47f0c116a20eb96",label:wp.i18n.__("First Name","surecart"),name:"first_name",value:null===(s=this.customer)||void 0===s?void 0:s.first_name})),h("sc-column",{key:"f665e83ec6d8311daf55ae82964da70500a4228a"},h("sc-input",{key:"19f629227cf366327e4643c61baa7b8639eac6b1",label:wp.i18n.__("Last Name","surecart"),name:"last_name",value:null===(t=this.customer)||void 0===t?void 0:t.last_name}))),h("sc-column",{key:"87edeffc8a0f27b7bec289861ea4705da6724a3c"},h("sc-phone-input",{key:"18e631f763688ed4adf9b482f9b66fd50046be51",label:wp.i18n.__("Phone","surecart"),name:"phone",value:null===(i=this.customer)||void 0===i?void 0:i.phone})),h("sc-flex",{key:"bcaf7e6992abec31db6292361994f1ab1c4ff838",style:{"--sc-flex-column-gap":"var(--sc-spacing-medium)"},flexDirection:"column"},h("div",{key:"3c2502e2d21d58ec0652e01c70a34d3577f726ca"},h("sc-address",{key:"10b303c243f112a53f88d6a6a7185785341322db",label:wp.i18n.__("Shipping Address","surecart"),showName:!0,address:{...null===(n=this.customer)||void 0===n?void 0:n.shipping_address},showLine2:!0,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"}})),h("div",{key:"1dfb9374290bc21b563fbd6e64c693bf98ca1330"},h("sc-checkbox",{key:"828e70ca7edd0b161d759dbb270f3dbe7a62bbc0",name:"billing_matches_shipping",checked:null===(c=this.customer)||void 0===c?void 0:c.billing_matches_shipping,onScChange:e=>{this.customer={...this.customer,billing_matches_shipping:e.target.checked}},value:"on"},wp.i18n.__("Billing address is same as shipping","surecart"))),h("div",{key:"93ce6721cde0603365d6a19b5e0c145f5416a965",style:{display:(null===(o=this.customer)||void 0===o?void 0:o.billing_matches_shipping)?"none":"block"}},h("sc-address",{key:"5ff07ff28093a253328ef5bacf3cc89468cf25ec",label:wp.i18n.__("Billing Address","surecart"),showName:!0,address:{...null===(m=this.customer)||void 0===m?void 0:m.billing_address},showLine2:!0,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:!0})),h("sc-tax-id-input",{key:"5a87ac8d4b4e00c680e2409929ebe8ac8895c972",show:!0,number:null===(d=null===(a=this.customer)||void 0===a?void 0:a.tax_identifier)||void 0===d?void 0:d.number,type:null===(r=null===(l=this.customer)||void 0===l?void 0:l.tax_identifier)||void 0===r?void 0:r.number_type})),h("div",{key:"b26f474e86f33940ebea025ad3aa81676bc34bcd"},h("sc-button",{key:"43e8b4a4d92d48094faa1dbd7e8f5c5bc9245abb",type:"primary",full:!0,submit:!0},wp.i18n.__("Save","surecart"))))),this.loading&&h("sc-block-ui",{key:"c672b8e94fe3dcd205f0ab1065d5effba7717ac1",spinner:!0}))}static get style(){return ScCustomerEditStyle0}},[1,"sc-customer-edit",{heading:[1],customer:[1040],successUrl:[1,"success-url"],loading:[32],error:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-customer-edit","sc-address","sc-address-suggestions","sc-alert","sc-block-ui","sc-button","sc-card","sc-checkbox","sc-column","sc-columns","sc-dashboard-module","sc-dropdown","sc-flex","sc-form","sc-form-control","sc-icon","sc-input","sc-menu","sc-menu-item","sc-menu-label","sc-phone-input","sc-select","sc-spinner","sc-tag","sc-tax-id-input","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-customer-edit":customElements.get(e)||customElements.define(e,ScCustomerEdit$1);break;case"sc-address":customElements.get(e)||defineCustomElement$q();break;case"sc-address-suggestions":customElements.get(e)||defineCustomElement$p();break;case"sc-alert":customElements.get(e)||defineCustomElement$o();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$n();break;case"sc-button":customElements.get(e)||defineCustomElement$m();break;case"sc-card":customElements.get(e)||defineCustomElement$l();break;case"sc-checkbox":customElements.get(e)||defineCustomElement$k();break;case"sc-column":customElements.get(e)||defineCustomElement$j();break;case"sc-columns":customElements.get(e)||defineCustomElement$i();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$h();break;case"sc-dropdown":customElements.get(e)||defineCustomElement$g();break;case"sc-flex":customElements.get(e)||defineCustomElement$f();break;case"sc-form":customElements.get(e)||defineCustomElement$e();break;case"sc-form-control":customElements.get(e)||defineCustomElement$d();break;case"sc-icon":customElements.get(e)||defineCustomElement$c();break;case"sc-input":customElements.get(e)||defineCustomElement$b();break;case"sc-menu":customElements.get(e)||defineCustomElement$a();break;case"sc-menu-item":customElements.get(e)||defineCustomElement$9();break;case"sc-menu-label":customElements.get(e)||defineCustomElement$8();break;case"sc-phone-input":customElements.get(e)||defineCustomElement$7();break;case"sc-select":customElements.get(e)||defineCustomElement$6();break;case"sc-spinner":customElements.get(e)||defineCustomElement$5();break;case"sc-tag":customElements.get(e)||defineCustomElement$4();break;case"sc-tax-id-input":customElements.get(e)||defineCustomElement$3();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$2()}}))}const ScCustomerEdit=ScCustomerEdit$1,defineCustomElement=defineCustomElement$1;export{ScCustomerEdit,defineCustomElement};