import{r as i,j as s}from"./vendor-react-wBh_31cN.js";import{aq as S,G as m,r as c,ar as C,as as k,at as R,au as L}from"./index-dNe6i2rS.js";import{u as F,d as H}from"./vendor-router-D1GqFWiT.js";import{j as K,u as h}from"./vendor-redux-CJZrIb6x.js";import{u as q,F as E}from"./index.esm-CAGtek53.js";import{o as V}from"./yup-XkUC3UEH.js";import{I as p}from"./input-DFI7JniT.js";import{L as w}from"./label-gPWmc6ow.js";import{C as $,a as D,b as I,c as M}from"./card-BeQtvmcJ.js";import{H as z}from"./Hero-ILcN0sPk.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./theme-colors-BFneJNsI.js";const B=C().shape({newPassword:L.label("Password"),confirmedPassword:k().equals([R("newPassword")],"Passwords must match")}),rs=()=>{var f,u;const d=F(),n=K(),[j]=H(),o=j.get("key"),[a,l]=i.useState(),[g,v]=i.useState(!1),[P,N]=i.useState(!1),x=h(t=>t.loading.effects.auth.resetPassword),y=h(t=>t.loading.effects.auth.validateResetKey);i.useEffect(()=>{async function t(){if(o){const r=await n.auth.validateResetKey({key:o});l(r),r!=null&&r.error&&d(c.auth.login),N(!0)}else d(c.auth.login)}t()},[n.auth,o,d]);const e=q({shouldUnregister:!1,resolver:V(B),reValidateMode:"onChange",mode:"onChange"}),b=i.useCallback(async t=>{if(o){l(null);const r=await n.auth.resetPassword({key:o,newPassword:t.newPassword,confirmPassword:t.confirmedPassword});l(r),r!=null&&r.error||v(!0)}},[n.auth,o]);return y||!P?s.jsx(S,{}):s.jsxs("div",{className:"flex flex-col items-center mt-[50px]",children:[s.jsx(z,{}),s.jsx("span",{className:"mb-[60px] mt-[15px] text-lg text-quartz-primary",children:"Hopsworks"}),(a==null?void 0:a.error)&&s.jsx("div",{className:"w-[466px] mb-5 rounded-md border border-destructive bg-destructive/10 p-3 text-sm text-destructive",children:a==null?void 0:a.message}),s.jsxs($,{className:"w-[466px]",children:[s.jsx(D,{children:s.jsx(I,{children:"Password recovery"})}),s.jsx(M,{children:g?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"text-sm font-semibold",children:"Done"}),s.jsx("div",{className:"mt-2",children:s.jsx("span",{className:"text-xs",children:((u=(f=a==null?void 0:a.data)==null?void 0:f.data)==null?void 0:u.successMessage)||"Your password was successfully changed."})})]}),s.jsx("div",{className:"flex justify-end mt-5",children:s.jsx(m,{variant:"secondary",onClick:()=>d(c.auth.login),children:"Login"})})]}):s.jsx(E,{...e,children:s.jsxs("form",{onSubmit:e.handleSubmit(b),className:"flex flex-col",children:[s.jsxs("div",{className:"flex gap-5",children:[s.jsxs("div",{className:"flex-1",children:[s.jsx(w,{className:"mb-1.5",children:"New password"}),s.jsx(p,{type:"password",placeholder:"••••••",disabled:x,...e.register("newPassword"),"aria-invalid":!!e.formState.errors.newPassword}),e.formState.errors.newPassword&&s.jsx("p",{className:"text-xs text-destructive mt-1",children:e.formState.errors.newPassword.message})]}),s.jsxs("div",{className:"flex-1",children:[s.jsx(w,{className:"mb-1.5",children:"Confirm new password"}),s.jsx(p,{type:"password",placeholder:"••••••",disabled:x,...e.register("confirmedPassword"),"aria-invalid":!!e.formState.errors.confirmedPassword}),e.formState.errors.confirmedPassword&&s.jsx("p",{className:"text-xs text-destructive mt-1",children:e.formState.errors.confirmedPassword.message})]})]}),s.jsxs("div",{className:"flex justify-end mt-5 gap-5",children:[s.jsx(m,{variant:"secondary",type:"button",onClick:()=>d(c.auth.login),children:"Login"}),s.jsx(m,{type:"submit",children:"Reset"})]})]})})})]})]})};export{rs as default,B as schema};
