import{r as i,c as s,h as t,H as o}from"./p-dfbe004d.js";import{_ as a}from"./p-8415f806.js";import"./p-fd56940f.js";import{c as r}from"./p-85821e4e.js";import{g as e}from"./p-6c2a2148.js";import{s as l}from"./p-6daff5d1.js";import{a as n,o as c}from"./p-10aa7556.js";import"./p-9a7a47e8.js";import"./p-699b9e85.js";import"./p-ea78c070.js";import"./p-35c4916d.js";import"./p-a41f5fb3.js";import"./p-7393a06c.js";import"./p-1c2e2695.js";import"./p-4d73f82a.js";const h=class{constructor(t){i(this,t),this.scChange=s(this,"scChange",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.scUpdateOrderState=s(this,"scUpdateOrderState",7),this.scUpdateAbandonedCart=s(this,"scUpdateAbandonedCart",7),this.scLoginPrompt=s(this,"scLoginPrompt",7),this.size="medium",this.value=e("email"),this.pill=!1,this.showLabel=!0,this.help="",this.disabled=!1,this.readonly=!1,this.required=!1,this.invalid=!1}async handleChange(){this.value=this.input.value,this.scChange.emit();try{n.checkout=await r({id:n.checkout.id,data:{email:this.input.value}})}catch(i){console.log(i)}}async reportValidity(){var i,s;return null===(s=null===(i=this.input)||void 0===i?void 0:i.reportValidity)||void 0===s?void 0:s.call(i)}handleSessionChange(){var i,s,t,o,a,r;if(this.value)return;if(l.loggedIn)return void(this.value=(null===(s=null===(i=null==n?void 0:n.checkout)||void 0===i?void 0:i.customer)||void 0===s?void 0:s.email)||(null===(t=null==n?void 0:n.checkout)||void 0===t?void 0:t.email));const c=e("email");this.value=l.loggedIn||!c?(null===(o=null==n?void 0:n.checkout)||void 0===o?void 0:o.email)||(null===(r=null===(a=null==n?void 0:n.checkout)||void 0===a?void 0:a.customer)||void 0===r?void 0:r.email):c}componentWillLoad(){this.handleSessionChange(),this.removeCheckoutListener=c("checkout",(()=>this.handleSessionChange()))}disconnectedCallback(){this.removeCheckoutListener()}renderOptIn(){return this.trackingConfirmationMessage?!1!==n.abandonedCheckoutEnabled?t("div",{class:"tracking-confirmation-message"},t("span",null,this.trackingConfirmationMessage)," ",t("a",{href:"#",onClick:i=>{i.preventDefault(),this.scUpdateAbandonedCart.emit(!1)}},a("No Thanks","surecart"))):t("div",{class:"tracking-confirmation-message"},t("span",null," ",a("You won't receive further emails from us.","surecart"))):null}render(){return t(o,null,t("sc-input",{exportparts:"base, input, form-control, label, help-text, prefix, suffix",type:"email",name:"email",ref:i=>this.input=i,value:this.value,help:this.help,label:this.label,autocomplete:"email",placeholder:this.placeholder,disabled:!!l.loggedIn,readonly:this.readonly,required:!0,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.renderOptIn())}};h.style=":host{display:block}a{color:var(--sc-color-primary-500)}a.customer-email__login-link{color:var(--sc-customer-login-link-color, var(--sc-input-placeholder-color));text-decoration:none;font-size:var(--sc-font-size-small)}.tracking-confirmation-message{font-size:var(--sc-font-size-xx-small)}.tracking-confirmation-message span{opacity:0.75}";export{h as sc_customer_email}