import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{a as t,o as n}from"./query-BtP_B6q9.js";import{c as r,n as i,u as a}from"./react-CdhQMFNz.js";import{A as o,j as s}from"./vendor-B2maTQLc.js";import{_ as c,h as l,i as u,l as d,n as f}from"./Logo-CWvlQZMc.js";import{t as p}from"./passwordPolicy-DEzphgFW.js";import{t as m}from"./AuthLayout-Cc_D8XEr.js";var h=e(n(),1),g=t();function _(){let[e]=a(),t=r(),n=e.get(`token`)??``,_=e.get(`email`)??``,[v,y]=(0,h.useState)(``),[b,x]=(0,h.useState)(``),[S,C]=(0,h.useState)(!1),[w,T]=(0,h.useState)(null),[E,D]=(0,h.useState)(!1);return n===``||_===``?(0,g.jsxs)(m,{title:`Reset link incomplete`,children:[(0,g.jsx)(c,{tone:`error`,title:`This link is not usable`,children:`Open the most recent reset link from your email, or request a new one.`}),(0,g.jsx)(`div`,{className:`mt-5`,children:(0,g.jsx)(i,{to:`/forgot-password`,children:(0,g.jsx)(l,{variant:`secondary`,fullWidth:!0,children:`Request a new link`})})})]}):(0,g.jsx)(m,{title:`Choose a new password`,description:`Resetting the password for ${_}.`,children:(0,g.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),T(null),D(!0);try{await u.post(`/auth/reset-password`,{token:n,email:_,password:v,password_confirmation:b}),t(`/login`,{replace:!0,state:{notice:`Your password has been updated. Sign in with your new password.`}})}catch(e){if(e instanceof f)T(e);else throw e}finally{D(!1)}},className:`flex flex-col gap-4`,noValidate:!0,children:[w!==null&&!w.isValidation&&(0,g.jsx)(c,{tone:`error`,title:`Cannot reset password`,children:w.message}),w?.errorFor(`email`)!==void 0&&(0,g.jsx)(c,{tone:`error`,title:`This link has expired`,children:w.errorFor(`email`)}),(0,g.jsx)(d,{label:`New password`,type:S?`text`:`password`,value:v,onChange:e=>y(e.target.value),autoComplete:`new-password`,autoFocus:!0,required:!0,hint:p,error:w?.errorFor(`password`),trailingSlot:(0,g.jsx)(`button`,{type:`button`,onClick:()=>C(e=>!e),"aria-label":S?`Hide password`:`Show password`,className:`flex size-8 items-center justify-center rounded-md text-text-muted hover:text-text-primary`,children:S?(0,g.jsx)(s,{"aria-hidden":!0,className:`size-4`}):(0,g.jsx)(o,{"aria-hidden":!0,className:`size-4`})})}),(0,g.jsx)(d,{label:`Confirm new password`,type:S?`text`:`password`,value:b,onChange:e=>x(e.target.value),autoComplete:`new-password`,required:!0,error:b!==``&&b!==v?`The passwords do not match.`:void 0}),(0,g.jsx)(`p`,{className:`text-sm text-text-muted`,children:`For your security, this will sign you out on all other devices.`}),(0,g.jsx)(l,{type:`submit`,size:`lg`,fullWidth:!0,isLoading:E,children:`Update password`})]})})}export{_ as ResetPasswordPage};
//# sourceMappingURL=ResetPasswordPage-s9IlpT_D.js.map