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{n as r,t as i}from"./eye-D1dB40_o.js";import{t as a}from"./loader-circle-C4hhXLgp.js";import{c as o}from"./vendor-router-CCECILJ0.js";import{M as s,j as c}from"./index-CH6sBa3Q.js";import{t as l}from"./label-0BvGVXvZ.js";var u=e(t(),1),d=n();function f(){let e=o(),[t,n]=(0,u.useState)(``),[f,p]=(0,u.useState)(``),[m,h]=(0,u.useState)(!1),[g,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(``);(0,u.useEffect)(()=>{fetch(`/api/auth/status`).then(e=>e.json()).then(({hasCredentials:t})=>{t||e(`/`,{replace:!0})}).catch(()=>{})},[]);async function b(n){n.preventDefault(),y(``),_(!0);try{let n=await fetch(`/api/auth/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({email:t,password:f})}),r=await n.json();if(!n.ok){y(r.error||`Credenciales inválidas`);return}localStorage.setItem(`hive-auth-token`,r.authToken),e(`/`,{replace:!0})}catch{y(`No se pudo conectar al servidor`)}finally{_(!1)}}return(0,d.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-background`,children:(0,d.jsxs)(`div`,{className:`w-full max-w-sm space-y-6 p-8`,children:[(0,d.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,d.jsx)(`div`,{className:`text-4xl`,children:`🐝`}),(0,d.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:`Hive`}),(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Inicia sesión para continuar`})]}),(0,d.jsxs)(`form`,{onSubmit:b,className:`space-y-4`,children:[(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsx)(l,{htmlFor:`email`,children:`Email`}),(0,d.jsx)(c,{id:`email`,type:`email`,autoComplete:`email`,placeholder:`tu@email.com`,value:t,onChange:e=>n(e.target.value),required:!0,disabled:g})]}),(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsx)(l,{htmlFor:`password`,children:`Contraseña`}),(0,d.jsxs)(`div`,{className:`relative`,children:[(0,d.jsx)(c,{id:`password`,type:m?`text`:`password`,autoComplete:`current-password`,placeholder:`••••••••`,value:f,onChange:e=>p(e.target.value),required:!0,disabled:g,className:`pr-10`}),(0,d.jsx)(`button`,{type:`button`,className:`absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>h(e=>!e),tabIndex:-1,children:m?(0,d.jsx)(r,{className:`h-4 w-4`}):(0,d.jsx)(i,{className:`h-4 w-4`})})]})]}),v&&(0,d.jsx)(`p`,{className:`text-sm text-destructive`,children:v}),(0,d.jsxs)(s,{type:`submit`,className:`w-full`,disabled:g,children:[g&&(0,d.jsx)(a,{className:`mr-2 h-4 w-4 animate-spin`}),`Iniciar Sesión`]})]}),(0,d.jsx)(`div`,{className:`text-center`,children:(0,d.jsx)(`button`,{type:`button`,onClick:()=>e(`/recover`),className:`text-sm text-muted-foreground hover:text-foreground underline underline-offset-4`,children:`¿Olvidaste tu contraseña?`})})]})})}export{f as default};