import{proxyCustomElement,HTMLElement,createEvent,h}from"@stencil/core/internal/client";import{b as getValueFromUrl}from"./util.js";import{s as state$1}from"./store4.js";import{s as state,o as onChange}from"./mutations2.js";import{d as createOrUpdateCheckout}from"./index4.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 scCustomerFirstnameCss=":host{display:block}",ScCustomerFirstnameStyle0=":host{display:block}",ScCustomerFirstname$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.scChange=createEvent(this,"scChange",7),this.scUpdateOrderState=createEvent(this,"scUpdateOrderState",7),this.scClear=createEvent(this,"scClear",7),this.scInput=createEvent(this,"scInput",7),this.scFocus=createEvent(this,"scFocus",7),this.scBlur=createEvent(this,"scBlur",7),this.scUpdateCustomer=createEvent(this,"scUpdateCustomer",7),this.loggedIn=void 0,this.size="medium",this.value=getValueFromUrl("first_name"),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:{first_name:this.input.value}})}catch(e){console.error(e)}}handleSessionChange(){var e,t,s,i,o,a;if(this.value)return;const n=getValueFromUrl("first_name");state$1.loggedIn||!n?state$1.loggedIn?this.value=(null===(i=null==state?void 0:state.checkout)||void 0===i?void 0:i.first_name)||(null===(a=null===(o=null==state?void 0:state.checkout)||void 0===o?void 0:o.customer)||void 0===a?void 0:a.first_name):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.first_name)||(null===(s=null==state?void 0:state.checkout)||void 0===s?void 0:s.first_name):this.value=n}componentWillLoad(){this.handleSessionChange(),this.removeCheckoutListener=onChange("checkout",(()=>this.handleSessionChange()))}disconnectedCallback(){this.removeCheckoutListener()}render(){return h("sc-input",{key:"430e820b69b4750f5e8d51afbafbc3163b53bf8c",type:"text",name:"first_name",ref:e=>this.input=e,value:this.value,label:this.label,help:this.help,autocomplete:"first_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":host{display:block}"}},[1,"sc-customer-firstname",{loggedIn:[4,"logged-in"],size:[513],value:[1025],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-firstname","sc-form-control","sc-input","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-customer-firstname":customElements.get(e)||customElements.define(e,ScCustomerFirstname$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 ScCustomerFirstname=ScCustomerFirstname$1,defineCustomElement=defineCustomElement$1;export{ScCustomerFirstname,defineCustomElement};