import{r as i,c as s,h as t}from"./p-dfbe004d.js";import{_ as o}from"./p-8415f806.js";import"./p-fd56940f.js";import{g as a}from"./p-6c2a2148.js";import{s as h}from"./p-6daff5d1.js";import{a as e,o as r}from"./p-10aa7556.js";import{c as l}from"./p-85821e4e.js";import"./p-9a7a47e8.js";import"./p-35c4916d.js";import"./p-1c2e2695.js";import"./p-699b9e85.js";import"./p-ea78c070.js";import"./p-a41f5fb3.js";import"./p-7393a06c.js";import"./p-4d73f82a.js";const d=class{constructor(t){i(this,t),this.scChange=s(this,"scChange",7),this.scUpdateOrderState=s(this,"scUpdateOrderState",7),this.scClear=s(this,"scClear",7),this.scInput=s(this,"scInput",7),this.scFocus=s(this,"scFocus",7),this.scBlur=s(this,"scBlur",7),this.scUpdateCustomer=s(this,"scUpdateCustomer",7),this.size="medium",this.value=a("first_name"),this.pill=!1,this.showLabel=!0,this.help="",this.disabled=!1,this.readonly=!1,this.required=!1,this.invalid=!1}async reportValidity(){var i,s,t,a,h;null===(s=null===(i=this.input)||void 0===i?void 0:i.setCustomValidity)||void 0===s||s.call(i,""),(null===(t=this.input)||void 0===t?void 0:t.value.trim().length)||this.input.setCustomValidity(o("Field must not be empty.","surecart"));return await(null===(h=null===(a=this.input)||void 0===a?void 0:a.reportValidity)||void 0===h?void 0:h.call(a))||!1}async handleChange(){this.value=this.input.value;try{e.checkout=await l({id:e.checkout.id,data:{first_name:this.input.value}})}catch(i){console.error(i)}}handleSessionChange(){var i,s,t,o,r,l;if(this.value)return;const d=a("first_name");this.value=h.loggedIn||!d?h.loggedIn?(null===(o=null==e?void 0:e.checkout)||void 0===o?void 0:o.first_name)||(null===(l=null===(r=null==e?void 0:e.checkout)||void 0===r?void 0:r.customer)||void 0===l?void 0:l.first_name):(null===(s=null===(i=null==e?void 0:e.checkout)||void 0===i?void 0:i.customer)||void 0===s?void 0:s.first_name)||(null===(t=null==e?void 0:e.checkout)||void 0===t?void 0:t.first_name):d}componentWillLoad(){this.handleSessionChange(),this.removeCheckoutListener=r("checkout",(()=>this.handleSessionChange()))}disconnectedCallback(){this.removeCheckoutListener()}render(){return t("sc-input",{type:"text",name:"first_name",ref:i=>this.input=i,value:this.value,disabled:!!h.loggedIn,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()})}};d.style=":host{display:block}";export{d as sc_customer_firstname}