import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t}from"./vendor-charts-Bu2lyBKP.js";import{o as n}from"./vendor-query-DsWPbQdG.js";import{t as r}from"./arrow-left-CBcbX5EZ.js";import{n as i,t as a}from"./eye-D1dB40_o.js";import{t as o}from"./loader-circle-C4hhXLgp.js";import{c as s}from"./vendor-router-CCECILJ0.js";import{M as c,j as l}from"./index-CH6sBa3Q.js";import{t as u}from"./label-0BvGVXvZ.js";var d=e(t(),1),f=n();function p(){let e=s(),[t,n]=(0,d.useState)(``),[p,m]=(0,d.useState)(``),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(!1),[x,S]=(0,d.useState)(``);async function C(n){if(n.preventDefault(),S(``),p!==h){S(`Las contraseñas no coinciden`);return}if(p.length<8){S(`La contraseña debe tener al menos 8 caracteres`);return}b(!0);try{let n=await fetch(`/api/auth/recover`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recoveryKey:t,newPassword:p})}),r=await n.json();if(!n.ok){S(r.error||`Recovery key inválido`);return}localStorage.setItem(`hive-auth-token`,r.authToken),e(`/`,{replace:!0})}catch{S(`No se pudo conectar al servidor`)}finally{b(!1)}}return(0,f.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-background`,children:(0,f.jsxs)(`div`,{className:`w-full max-w-sm space-y-6 p-8`,children:[(0,f.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,f.jsx)(`div`,{className:`text-4xl`,children:`🐝`}),(0,f.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:`Recuperar acceso`}),(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Usa tu recovery key para restablecer la contraseña`})]}),(0,f.jsxs)(`form`,{onSubmit:C,className:`space-y-4`,children:[(0,f.jsxs)(`div`,{className:`space-y-2`,children:[(0,f.jsx)(u,{htmlFor:`recoveryKey`,children:`Recovery Key`}),(0,f.jsx)(l,{id:`recoveryKey`,type:`text`,placeholder:`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,value:t,onChange:e=>n(e.target.value),required:!0,disabled:y,className:`font-mono text-sm`}),(0,f.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Encuéntralo en `,(0,f.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`~/.hive/.auth_token`})]})]}),(0,f.jsxs)(`div`,{className:`space-y-2`,children:[(0,f.jsx)(u,{htmlFor:`newPassword`,children:`Nueva contraseña`}),(0,f.jsxs)(`div`,{className:`relative`,children:[(0,f.jsx)(l,{id:`newPassword`,type:_?`text`:`password`,placeholder:`••••••••`,value:p,onChange:e=>m(e.target.value),required:!0,disabled:y,className:`pr-10`}),(0,f.jsx)(`button`,{type:`button`,className:`absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>v(e=>!e),tabIndex:-1,children:_?(0,f.jsx)(i,{className:`h-4 w-4`}):(0,f.jsx)(a,{className:`h-4 w-4`})})]})]}),(0,f.jsxs)(`div`,{className:`space-y-2`,children:[(0,f.jsx)(u,{htmlFor:`confirmPassword`,children:`Confirmar contraseña`}),(0,f.jsx)(l,{id:`confirmPassword`,type:_?`text`:`password`,placeholder:`••••••••`,value:h,onChange:e=>g(e.target.value),required:!0,disabled:y})]}),x&&(0,f.jsx)(`p`,{className:`text-sm text-destructive`,children:x}),(0,f.jsxs)(c,{type:`submit`,className:`w-full`,disabled:y,children:[y&&(0,f.jsx)(o,{className:`mr-2 h-4 w-4 animate-spin`}),`Recuperar acceso`]})]}),(0,f.jsx)(`div`,{className:`text-center`,children:(0,f.jsxs)(`button`,{type:`button`,onClick:()=>e(`/login`),className:`text-sm text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,f.jsx)(r,{className:`h-3 w-3`}),`Volver al login`]})})]})})}export{p as default};