import LoginLayout from "@/features/login/components/layout";
import LoginFlow from "@/features/login/components/login-flow";
import { redirect, createFileRoute } from "@tanstack/react-router";
import z from "zod";

const loginSearchSchema = z.object({
  stage: z.enum(["code", "name"]).optional(),
  number: z.string().optional(),
  callback: z.string().optional(),
});

export const Route = createFileRoute("/login")({
  validateSearch: loginSearchSchema,
  beforeLoad: async ({ context }) => {
    if (context.auth?.user) {
      throw redirect({ to: "/" });
    }
  },
  component: () => {
    return (
      <LoginLayout>
        <LoginFlow />
      </LoginLayout>
    );
  },
});
