import{proxyCustomElement,HTMLElement,createEvent,h}from"@stencil/core/internal/client";import{d as createOrUpdateCheckout}from"./index4.js";import{s as state$1}from"./store4.js";import{s as state,o as onChange}from"./mutations2.js";import{b as getValueFromUrl}from"./util.js";import{d as defineCustomElement$4}from"./sc-form-control2.js";import{d as defineCustomElement$3}from"./sc-input2.js";import{d as defineCustomElement$2}from"./sc-visually-hidden2.js";const scCustomerNameCss=":host{display:block}",ScCustomerNameStyle0=scCustomerNameCss,ScCustomerName$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.scInput=createEvent(this,"scInput",7),this.scFocus=createEvent(this,"scFocus",7),this.scBlur=createEvent(this,"scBlur",7),this.size="medium",this.value=null,this.pill=!1,this.label=void 0,this.showLabel=!0,this.help="",this.placeholder=void 0,this.disabled=!1,this.readonly=!1,this.required=!1,this.invalid=!1,this.autofocus=void 0,this.hasFocus=void 0}async reportValidity(){return this.input.reportValidity()}async handleChange(){this.value=this.input.value;try{state.checkout=await createOrUpdateCheckout({id:state.checkout.id,data:{name:this.input.value}})}catch(e){console.error(e)}}handleSessionChange(){var e,t,s,o,i,a;if(this.value)return;const l=getValueFromUrl("full_name");state$1.loggedIn||!l?state$1.loggedIn?this.value=(null===(t=null===(e=null==state?void 0:state.checkout)||void 0===e?void 0:e.customer)||void 0===t?void 0:t.name)||(null===(s=null==state?void 0:state.checkout)||void 0===s?void 0:s.name):this.value=(null===(o=null==state?void 0:state.checkout)||void 0===o?void 0:o.name)||(null===(a=null===(i=null==state?void 0:state.checkout)||void 0===i?void 0:i.customer)||void 0===a?void 0:a.name):this.value=l}componentWillLoad(){this.handleSessionChange(),this.removeCheckoutListener=onChange("checkout",(()=>this.handleSessionChange()))}disconnectedCallback(){this.removeCheckoutListener()}render(){return h("sc-input",{key:"405c3f6ce8a692f29b4e85ac29bfdb9dba7d0f2e",type:"text",name:"name",ref:e=>this.input=e,value:this.value,label:this.label,help:this.help,autocomplete:"name",placeholder:this.placeholder,readonly:this.readonly,required:this.required,invalid:this.invalid,autofocus:this.autofocus,hasFocus:this.hasFocus,onScChange:()=>this.handleChange(),onScInput:()=>this.scInput.emit(),onScFocus:()=>this.scFocus.emit(),onScBlur:()=>this.scBlur.emit(),...this.disabled&&{disabled:!0}})}static get style(){return ScCustomerNameStyle0}},[1,"sc-customer-name",{size:[513],value:[1032],pill:[516],label:[1],showLabel:[4,"show-label"],help:[1],placeholder:[1],disabled:[516],readonly:[516],required:[516],invalid:[1540],autofocus:[4],hasFocus:[1540,"has-focus"],reportValidity:[64]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-customer-name","sc-form-control","sc-input","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-customer-name":customElements.get(e)||customElements.define(e,ScCustomerName$1);break;case"sc-form-control":customElements.get(e)||defineCustomElement$4();break;case"sc-input":customElements.get(e)||defineCustomElement$3();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$2()}}))}const ScCustomerName=ScCustomerName$1,defineCustomElement=defineCustomElement$1;export{ScCustomerName,defineCustomElement};