"use strict";(self.webpackChunkui=self.webpackChunkui||[]).push([[48],{204:(e,a,t)=>{t.d(a,{a:()=>h});var n=t(0),s=t(2),o=t(1),r=t(48),i=t(164),c=t(77),l=t(109),u=t(10),d=t(238),m=function(e,a,t,n){return new(t||(t=Promise))((function(s,o){function r(e){try{c(n.next(e))}catch(e){o(e)}}function i(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var a;e.done?s(e.value):(a=e.value,a instanceof t?a:new t((function(e){e(a)}))).then(r,i)}c((n=n.apply(e,a||[])).next())}))};function h({loginOnly:e,returnTo:a}){const t=(0,u.j)(),h=function(){const[e,a]=(0,o.useState)((()=>"undefined"!=typeof window&&"#recover"===window.location.hash));return(0,o.useEffect)((()=>{const e=()=>a("#recover"===window.location.hash);return window.addEventListener("hashchange",e),e(),()=>window.removeEventListener("hashchange",e)}),[]),e}(),w=!e&&h,p=(0,o.useMemo)((()=>w?"Reset password":"Sign in"),[w]),v=(0,o.useMemo)((()=>w?"We will send you an email to reset your password":""),[w]),[g,f]=(0,o.useState)({email:"",password:""}),[y,x]=(0,o.useState)({}),[j,b]=(0,o.useState)(!1),[S,k]=(0,o.useState)(null),C=(0,o.useCallback)((()=>{const e={};return g.email.trim()?(0,i.b)(g.email)||(e.email="Please enter a valid email."):e.email="Email is required.",w||g.password||(e.password="Password is required."),x(e),0===Object.keys(e).length}),[g,w]),L=(0,o.useCallback)((e=>a=>{const t=a.target.value;f((a=>Object.assign(Object.assign({},a),{[e]:t}))),x((a=>Object.assign(Object.assign({},a),{[e]:void 0}))),S&&k(null)}),[S]),N=(0,o.useCallback)((e=>m(this,void 0,void 0,(function*(){var t,n,o,i;if(e.preventDefault(),C()){b(!0),k(null);try{if(w){const e=yield(0,s.getLazyState)("initRecoverPassword",{email:g.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,s.getLazyState)("customerAccessTokenCreate",{email:g.email.trim(),password:g.password,return_to:null!==(t=null!=a?a:e.get("return_to"))&&void 0!==t?t:void 0});if(!c||(null==c?void 0:c.error))throw new Error(null!==(n=null==c?void 0:c.error)&&void 0!==n?n:"Something went wrong.");const l=null===(o=c.data)||void 0===o?void 0:o.accessToken,u=null===(i=c.multipassLoginUrl)||void 0===i?void 0:i.url;if(!l||!u)throw new Error("Authentication failed.");(0,r.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{b(!1)}}}))),[g,w,C,a]);return(0,n.jsxs)("div",{className:c.a.accountWrapper,children:[(0,n.jsxs)("div",{className:c.a.accountFormHeader,children:[(0,n.jsx)("h1",{children:p}),v&&(0,n.jsx)("p",{children:v})]}),S&&(0,n.jsx)("div",{className:"error"===S.type?c.a.messageError:c.a.messageSuccess,children:S.text}),(0,n.jsxs)("form",{className:c.a.accountForm,onSubmit:N,children:[(0,n.jsxs)("div",{className:c.a.accountInputs,children:[(0,n.jsx)(l.a,{label:"Email",name:"email",type:"email",placeholder:"Email",autocomplete:"email",value:g.email,onChange:L("email"),errormessage:y.email}),!w&&(0,n.jsx)(l.a,{label:"Password",name:"password",type:"password",placeholder:"Password",autocomplete:"current-password",value:g.password,onChange:L("password"),errormessage:y.password})]}),w?(0,n.jsx)("button",{type:"submit",className:`${c.a.accountButton} ${c.a.accountButtonCenter}`,children:"Submit"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"submit",className:`${c.a.accountButton} ${c.a.accountButtonCenter}`,disabled:j,children:(0,n.jsxs)("span",{className:c.a.buttonContent,children:[j&&(0,n.jsx)("span",{className:c.a.buttonLoader}),(0,n.jsx)("span",{children:"Login"})]})}),(0,n.jsxs)("div",{className:c.a.accountFooter,children:[(0,n.jsx)("a",{href:(0,d.a)(t("/account/register"),a),className:c.a.accountFooterLink,children:"Create account"}),(0,n.jsx)("a",{href:`${t("/account/login")}#recover`,className:c.a.accountFooterLink,children:"Forgot your password?"})]})]})]})]})}},238:(e,a,t)=>{function n(e,a){const t=null!=a?a:"undefined"!=typeof window?new URLSearchParams(window.location.search).get("return_to"):null;return t?`${e}?return_to=${encodeURIComponent(t)}`:e}t.d(a,{a:()=>n})}}]);