import{_ as n,ax as o,B as t,ay as e,az as a,aA as i,Z as s,aB as c,as as r,aC as u,y as l,aD as d,aE as f,aF as m,aG as w,aH as h,aI as p,aJ as v,e as _,s as y,f as b,g,aK as I}from"./chunk.common_3e0b8cdf.esm.js";function k(){return n(this,void 0,void 0,(function*(){try{if(o(window.location.pathname).endsWith("/account"))return void function(){const n=i("analytics_trace_id");if(n){new e({elementName:"shop-login-button",flowVersion:a.SignIn,analyticsTraceId:n}).trackClassicCustomerAccountsAccountPageImpression()}const o=s(m);if(o){const n=JSON.parse(decodeURIComponent(JSON.parse(`"${o.replace(/"/g,'\\"')}"`))),t=null==n?void 0:n.analytics_trace_id,i=null==n?void 0:n.email;if(!t)throw new E("Missing analytics trace ID in Sign in with Shop cookie");if(!c(i))throw new E("Tried to show Login with Shop on customer account page with an invalid email",t);const s=document.createElement("shop-login-button");s.setAttribute("client-id",""),s.setAttribute("action","default"),s.setAttribute("version","2"),s.setAttribute("flow-version",a.SignIn),s.setAttribute("analytics-context",r.ClassicCustomerAccounts),s.setAttribute("analytics-trace-id",t),s.setAttribute("hide-button","true"),s.setAttribute("email-verification-required","true"),document.body.appendChild(s),s.requestShow(i),u(m,"/account");new e({elementName:"shop-login-button",analyticsTraceId:t,flowVersion:a.SignIn}).trackClassicCustomerAccountsAccountPageImpression()}}();!function(){const n=l(),o=new e({elementName:"shop-login-button",flowVersion:a.SignIn,analyticsTraceId:n}),i=new WeakMap;let s=null;const c=d({onVisible:_,onFallback:n=>{n.addEventListener("focus",u,{once:!0}),o.trackShopPayLoginWithSdkErrorEvents({apiKey:"",errorCode:"fallback_to_focus_event",errorMessage:"Fallback to focus event for classic customer accounts"})}});function u(n){_(n.target)}function m(n,o){var t,e;const a=null===(t=n.elements.namedItem("checkout_url"))||void 0===t?void 0:t.value,i=null===(e=n.elements.namedItem("return_url"))||void 0===e?void 0:e.value,s=new URLSearchParams(Object.assign(Object.assign({analytics_trace_id:o},a&&{checkout_url:a}),i&&{return_url:i}));return`${window.location.origin}/account/redirect?${s.toString()}`}function _(e){var c;const u=e.form;if(!u)return void t.notify(new Error("Email form missing for classic customer accounts"));i.has(e)&&(t.notify(new Error("Input listener already exists for input")),null===(c=i.get(e))||void 0===c||c.destroy(),i.delete(e));const l=document.createElement("input");l.type="hidden",l.name="login_with_shop[analytics_trace_id]",l.value=n,u.appendChild(l),s||(s=function(n){const o=document.createElement("shop-login-button");return o.setAttribute("client-id",""),o.setAttribute("action","default"),o.setAttribute("version","2"),o.setAttribute("flow-version",a.SignIn),o.setAttribute("analytics-context",r.ClassicCustomerAccounts),o.setAttribute("analytics-trace-id",n),o.setAttribute("hide-button","true"),o.setAttribute("email-verification-required","true"),o.setAttribute("disable-sign-up","true"),o.setAttribute("auto-open","true"),document.body.appendChild(o),o}(n),o.trackClassicCustomerAccountsLoginPageImpression(),s.addEventListener("completed",(()=>{const o=m(u,n);window.location.assign(o)})),s.addEventListener("modalclosed",(()=>{h(v,"true")}))),s.email=e.value,i.set(e,new p(e,(n=>{s.email=n})))}f({selector:w,onElementFound:n=>c.observe(n)})}()}catch(n){if(n instanceof Error&&t.notify(n),n instanceof E){new e({elementName:"shop-login-button",flowVersion:a.SignIn,analyticsTraceId:n.analyticsTraceId}).trackShopPayLoginWithSdkErrorEvents({apiKey:"",errorCode:n.code,errorMessage:n.message})}}}))}class E extends Error{constructor(n,o=l()){super(n),this.analyticsTraceId=o,this.name="InitCustomerAccountsError",this.code="init_customer_accounts_error"}}_()&&(y({bundle:"initCustomerAccounts",bundleLocale:"en"}),b(),g(),I("initCustomerAccounts",k));
//# sourceMappingURL=client.init-customer-accounts_6131902e.en.esm.js.map
