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