import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { useState } from "react";

export const Route = createFileRoute("/auth/mail")({
	component: RouteComponent,
});

function RouteComponent() {
	const [email, setEmail] = useState("");
	const navigate = useNavigate();

	const handleSubmit = () => {
		if (email.trim() === "") return;
		navigate({
			to: "/auth/code",
			viewTransition: { types: ["warp"] },
		});
	};

	return (
		<div className="flex items-center justify-center h-full gap-10 tracking-[-2%] flex-col">
			<div className="text-brand-gray text-center">
				<p className="font-medium text-[48px] leading-[120%] ">
					Welcome to Cytonic!
				</p>
				<p className="font-medium text-[32px] leading-[120%]">Sign in</p>
			</div>

			<div className="space-y-6 w-[300px]">
				<form
					onSubmit={(e) => {
						e.preventDefault();
						handleSubmit();
					}}
				>
					<Input
						label="Email"
						placeholder="Email@example.com"
						value={email}
						onChange={(e) => setEmail(e.target.value)}
					/>
				</form>

				<Button
					className="text-[18px] w-full"
					disabled={email.trim() === ""}
					onClick={handleSubmit}
				>
					Send code
				</Button>
			</div>
		</div>
	);
}
