import { createFileRoute, redirect } from "@tanstack/react-router";

import LoginForm from "@/components/auth/LoginForm";
import { z } from "zod";

export const Route = createFileRoute("/login")({
    component: RouteComponent,
    beforeLoad: () => {
        const isLoggedIn = localStorage.getItem("auth_token");
        if (isLoggedIn) {
            throw redirect({
                to: "/",
            });
        }
    },
    validateSearch: z.object({
        redirect: z.string().optional(),
    }),
});

function RouteComponent() {
    return (
        <div className="ml-[25%]">
            <LoginForm />
        </div>
    );
}
