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{s as a}from"./p-6daff5d1.js";import{a as l,o as h}from"./p-10aa7556.js";import{g as n}from"./p-6c2a2148.js";import{c as e}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.scInput=s(this,"scInput",7),this.scFocus=s(this,"scFocus",7),this.scBlur=s(this,"scBlur",7),this.size="medium",this.value=null,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,l;return 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")),await(null===(l=null===(a=this.input)||void 0===a?void 0:a.reportValidity)||void 0===l?void 0:l.call(a))}async handleChange(){this.value=this.input.value;try{l.checkout=await e({id:l.checkout.id,data:{last_name:this.input.value}})}catch(i){console.error(i)}}handleSessionChange(){var i,s,t,o,h,e;if(this.value)return;const d=n("last_name");this.value=a.loggedIn||!d?a.loggedIn?(null===(s=null===(i=null==l?void 0:l.checkout)||void 0===i?void 0:i.customer)||void 0===s?void 0:s.last_name)||(null===(t=null==l?void 0:l.checkout)||void 0===t?void 0:t.last_name):(null===(o=null==l?void 0:l.checkout)||void 0===o?void 0:o.last_name)||(null===(e=null===(h=null==l?void 0:l.checkout)||void 0===h?void 0:h.customer)||void 0===e?void 0:e.last_name):d}componentWillLoad(){this.handleSessionChange(),this.removeCheckoutListener=h("checkout",(()=>this.handleSessionChange()))}disconnectedCallback(){this.removeCheckoutListener()}render(){return t("sc-input",{type:"text",name:"last_name",ref:i=>this.input=i,value:this.value,disabled:!!a.loggedIn,label:this.label,help:this.help,autocomplete:"last_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_lastname}