import { createFileRoute, redirect } from "@tanstack/react-router" import { useState } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Separator } from "@/components/ui/separator" import { Mail, Lock, Eye, EyeOff, Loader2, Shield } from "lucide-react" export const Route = createFileRoute("/login")({ validateSearch: (search) => ({ redirect: (search.redirect as string) || "/dashboard", }), beforeLoad: ({ context, search }) => { if (context.auth.isAuthenticated) { throw redirect({ to: search.redirect }) } }, component: LoginComponent, }) function LoginComponent() { const { auth } = Route.useRouteContext() const { redirect } = Route.useSearch() const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState("") const [showPassword, setShowPassword] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError("") try { await auth.login(email, password) window.location.href = redirect } catch (err: any) { setError(err.message || "No fue posible iniciar sesión") } finally { setIsLoading(false) } } return (