import { createFileRoute, redirect } from "@tanstack/react-router";
import SignInForm from "@/components/sign-in-form";
import { isOnboardingNeeded } from "@/utils/functions";

export const Route = createFileRoute("/login")({
	component: RouteComponent,
	beforeLoad: async () => {
		const needsOnboarding = await isOnboardingNeeded();
		if (needsOnboarding.needsOnboarding) {
			throw redirect({
				to: "/welcome",
			});
		}
	},
	head: () => ({
		meta: [
			{
				title: "Sign In - Nontara",
			},
		],
	}),
});

function RouteComponent() {
	return (
		<div className="flex min-h-screen items-center justify-center p-4">
			<SignInForm />
		</div>
	);
}
