"use strict";(self.webpackChunkui=self.webpackChunkui||[]).push([[47],{119(e,a,n){n.d(a,{a:()=>m});var t=n(0),o=n(2),r=n(1),s=n(25),i=n(65),c=n(69),l=n(71),u=n(9),d=n(144);function m({loginOnly:e,returnTo:a}){const n=(0,u.e)(),m=function(){const[e,a]=(0,r.k)((()=>"undefined"!=typeof window&&"#recover"===window.location.hash));return(0,r.c)((()=>{const e=()=>a("#recover"===window.location.hash);return window.addEventListener("hashchange",e),e(),()=>window.removeEventListener("hashchange",e)}),[]),e}(),h=!e&&m,w=(0,r.h)((()=>h?"Reset password":"Sign in"),[h]),p=(0,r.h)((()=>h?"We will send you an email to reset your password":""),[h]),[v,g]=(0,r.k)({email:"",password:""}),[f,b]=(0,r.k)({}),[y,x]=(0,r.k)(!1),[j,k]=(0,r.k)(null),L=(0,r.a)((()=>{const e={};return v.email.trim()?(0,i.b)(v.email)||(e.email="Please enter a valid email."):e.email="Email is required.",h||v.password||(e.password="Password is required."),b(e),0===Object.keys(e).length}),[v,h]),N=(0,r.a)((e=>a=>{const n=a.target.value;g((a=>Object.assign(Object.assign({},a),{[e]:n}))),b((a=>Object.assign(Object.assign({},a),{[e]:void 0}))),j&&k(null)}),[j]),S=(0,r.a)((e=>{return n=this,t=void 0,i=function*(){var n,t,r,i;if(e.preventDefault(),L()){x(!0),k(null);try{if(h){const e=yield(0,o.getLazyState)("initRecoverPassword",{email:v.email.trim()});if("success"!==(null==e?void 0:e.status))throw new Error("Something went wrong.");k({type:"success",text:"If that email exists in our system, you’ll receive reset instructions shortly."})}else{const e=new URLSearchParams(window.location.search),c=yield(0,o.getLazyState)("customerAccessTokenCreate",{email:v.email.trim(),password:v.password,return_to:null!==(n=null!=a?a:e.get("return_to"))&&void 0!==n?n:void 0});if(!c||(null==c?void 0:c.error))throw new Error(null!==(t=null==c?void 0:c.error)&&void 0!==t?t:"Something went wrong.");const l=null===(r=c.data)||void 0===r?void 0:r.accessToken,u=null===(i=c.multipassLoginUrl)||void 0===i?void 0:i.url;if(!l||!u)throw new Error("Authentication failed.");(0,s.b)("customer_token",l,{expires:7}),window.location.href=u}}catch(e){console.error("LoginForm error:",e),k({type:"error",text:"Something went wrong—please try again."})}finally{x(!1)}}},new((r=void 0)||(r=Promise))((function(e,a){function o(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(a){var n;a.done?e(a.value):(n=a.value,n instanceof r?n:new r((function(e){e(n)}))).then(o,s)}c((i=i.apply(n,t||[])).next())}));var n,t,r,i}),[v,h,L,a]);return(0,t.b)("div",{className:c.a.accountWrapper,children:[(0,t.b)("div",{className:c.a.accountFormHeader,children:[(0,t.jsx)("h1",{children:w}),p&&(0,t.jsx)("p",{children:p})]}),j&&(0,t.jsx)("div",{className:"error"===j.type?c.a.messageError:c.a.messageSuccess,children:j.text}),(0,t.b)("form",{className:c.a.accountForm,onSubmit:S,children:[(0,t.b)("div",{className:c.a.accountInputs,children:[(0,t.jsx)(l.a,{label:"Email",name:"email",type:"email",placeholder:"Email",autocomplete:"email",value:v.email,onChange:N("email"),errormessage:f.email}),!h&&(0,t.jsx)(l.a,{label:"Password",name:"password",type:"password",placeholder:"Password",autocomplete:"current-password",value:v.password,onChange:N("password"),errormessage:f.password})]}),h?(0,t.jsx)("button",{type:"submit",className:`${c.a.accountButton} ${c.a.accountButtonCenter}`,children:"Submit"}):(0,t.b)(t.a,{children:[(0,t.jsx)("button",{type:"submit",className:`${c.a.accountButton} ${c.a.accountButtonCenter}`,disabled:y,children:(0,t.b)("span",{className:c.a.buttonContent,children:[y&&(0,t.jsx)("span",{className:c.a.buttonLoader}),(0,t.jsx)("span",{children:"Login"})]})}),(0,t.b)("div",{className:c.a.accountFooter,children:[(0,t.jsx)("a",{href:(0,d.a)(n("/account/register"),a),className:c.a.accountFooterLink,children:"Create account"}),(0,t.jsx)("a",{href:`${n("/account/login")}#recover`,className:c.a.accountFooterLink,children:"Forgot your password?"})]})]})]})]})}},144(e,a,n){function t(e,a){const n=null!=a?a:"undefined"!=typeof window?new URLSearchParams(window.location.search).get("return_to"):null;return n?`${e}?return_to=${encodeURIComponent(n)}`:e}n.d(a,{a:()=>t})}}]);