1import{r as o,u as R,j as e,g as i,F as k,t as U,o as F,s as L}from"./index-DUOydnzc.js";import{C as O}from"./circle-check-big-2dOsRwbQ.js";import{A as b}from"./arrow-left-TUuuc_wm.js";import{M as P}from"./mail-Da6uiiP_.js";import{C as j}from"./circle-alert-BjNYhZL6.js";const I=F({rut:L().min(1,"El RUT es requerido").regex(/^[0-9]+[-]?[0-9kK]{1}$/,"RUT inválido (formato: 12345678-9)")}),$=n=>{const t=n.replace(/[.\s-]/g,"");if(!t)return"";const c=t.slice(0,-1),d=t.slice(-1).toUpperCase();return`${c}-${d}`},D=()=>{const[n,t]=o.useState(!1),[c,d]=o.useState(!1),[x,l]=o.useState(""),[m,y]=o.useState(""),[h,N]=o.useState(""),[f,g]=o.useState(!1),{register:v,handleSubmit:w,formState:{errors:p},watch:S,setValue:T}=R({resolver:U(I)}),u=S("rut"),C=r=>{const a=r.target.value,s=$(a);T("rut",s)},E=f?async()=>{t(!0),l("");try{const r=await fetch("/api/auth/forgot-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rut:u})}),a=r.headers.get("content-type");if(!a||!a.includes("application/json"))throw new Error("La respuesta del servidor no es JSON. Por favor, contacta al administrador.");const s=await r.json();if(!s.success)throw new Error(s.error||"Error al procesar la solicitud");d(!0),s.resetToken&&y(s.resetToken)}catch(r){console.error("Error en forgot password:",r),l(r.message||"Error de conexión")}finally{t(!1)}}:async r=>{t(!0),l("");try{const s=await(await fetch("/api/auth/find-user-by-rut",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rut:r.rut})})).json();if(!s.success)throw new Error(s.error||"No se encontró un usuario con ese RUT");N(s.data.email),g(!0)}catch(a){console.error("Error buscando usuario:",a),l(a.message||"Error de conexión")}finally{t(!1)}};return c?e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-orange-50 to-red-50 flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8",children:e.jsxs("div",{className:"max-w-md w-full space-y-8",children:[e.jsxs("div",{className:"text-center",children:[e.jsx(O,{className:"mx-auto h-16 w-16 text-green-500"}),e.jsx("h2",{className:"mt-6 text-3xl font-extrabold text-gray-900",children:"Revisa tu Email"}),e.jsxs("p",{className:"mt-2 text-sm text-gray-600",children:["Se ha enviado un enlace de recuperación al email ",e.jsx("strong",{children:h})," asociado al RUT ",e.jsx("strong",{children:u}),"."]})]}),m&&e.jsxs("div",{className:"mt-6 p-4 bg-yellow-50 border border-yellow-200 rounded-lg",children:[e.jsx("h3",{className:"text-sm font-medium text-yellow-800 mb-2",children:"ð§ Modo Desarrollo - Token de Reset:"}),e.jsx("code",{className:"text-xs bg-yellow-100 p-2 rounded block break-all",children:m}),e.jsx(i,{to:`/reset-password?token=${m}`,className:"mt-2 inline-block text-sm text-yellow-700 underline",children:"Ir directamente al reset de contraseña"})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs(i,{to:"/auth",className:"group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-orange-600 hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500 transition-all duration-200",children:[e.jsx(b,{className:"h-4 w-4 mr-2"}),"Volver al Login"]})})]})}):e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-orange-50 to-red-50 flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8",children:e.jsxs("div",{className:"max-w-md w-full space-y-8",children:[e.jsxs("div",{children:[e.jsxs(i,{to:"/auth",className:"inline-flex items-center text-sm text-gray-600 hover:text-gray-900 mb-6 transition-colors",children:[e.jsx(b,{className:"h-4 w-4 mr-1"}),"Volver"]}),e.jsxs("div",{className:"text-center",children:[e.jsx(P,{className:"mx-auto h-12 w-12 text-orange-600"}),e.jsx("h2",{className:"mt-6 text-3xl font-extrabold text-gray-900",children:"¿Olvidaste tu contraseña?"}),e.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Ingresa tu RUT y confirma tu email para recibir un enlace de recuperación"})]})]}),e.jsxs("form",{className:"mt-8 space-y-6",onSubmit:w(E),children:[x&&e.jsx("div",{className:"rounded-md bg-red-50 p-4 border border-red-200",children:e.jsxs("div",{className:"flex",children:[e.jsx(j,{className:"h-5 w-5 text-red-400"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("h3",{className:"text-sm font-medium text-red-800",children:"Error"}),e.jsx("p",{className:"mt-1 text-sm text-red-700",children:x})]})]})}),f?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md bg-blue-50 p-4 border border-blue-200",children:e.jsxs("div",{className:"flex",children:[e.jsx(j,{className:"h-5 w-5 text-blue-400"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("h3",{className:"text-sm font-medium text-blue-800",children:"Confirmación"}),e.jsx("p",{className:"mt-2 text-sm text-blue-700",children:"Se enviará un enlace de recuperación al email:"}),e.jsx("p",{className:"mt-1 text-base font-semibold text-blue-900",children:h}),e.jsxs("p",{className:"mt-2 text-xs text-blue-600",children:["asociado al RUT: ",e.jsx("strong",{children:u})]})]})]})}),e.jsxs("div",{className:"flex space-x-3",children:[e.jsx("button",{type:"button",onClick:()=>g(!1),className:"flex-1 py-3 px-4 border border-gray-300 text-sm font-medium rounded-lg text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500 transition-all duration-200",children:"Cancelar"}),e.jsx("button",{type:"submit",disabled:n,className:"flex-1 py-3 px-4 border border-transparent text-sm font-medium rounded-lg text-white bg-orange-600 hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200",children:n?"Enviando...":"Confirmar y enviar"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"rut",className:"sr-only",children:"RUT"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(k,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{...v("rut"),type:"text",autoComplete:"username",onChange:C,className:"block w-full pl-10 pr-3 py-3 border border-gray-300 rounded-lg placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-2 focus:ring-orange-500 focus:border-orange-500 sm:text-sm transition-all duration-200",placeholder:"Tu RUT (12345678-9)"})]}),p.rut&&e.jsx("p",{className:"mt-2 text-sm text-red-600",children:p.rut.message})]}),e.jsx("div",{children:e.jsx("button",{type:"submit",disabled:n,className:"group relative w-full flex justify-center py-3 px-4 border border-transparent text-sm font-medium rounded-lg text-white bg-orange-600 hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200",children:n?"Buscando...":"Bu
1scar cuenta"})})]}),e.jsx("div",{className:"text-center",children:e.jsx(i,{to:"/auth",className:"font-medium text-orange-600 hover:text-orange-500 text-sm transition-colors",children:"¿Recordaste tu contraseña? Inicia sesión"})})]})]})})};export{D as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.