import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { useAccountStore } from "@/contexts/AccountContext";
import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { observer } from "mobx-react-lite";
import { useState } from "react";

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

const RouteComponent = observer(() => {
	const [username, setUsername] = useState("");
	const navigate = useNavigate();
	const { setUserId } = useAccountStore();

	const handleSubmit = () => {
		if (username.trim() === "") return;

		setUserId("ID");
		navigate({
			to: "/",
			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>
				<p className="text-text-light-200 whitespace-nowrap mt-4">
					Create a username
				</p>
			</div>

			<div className="space-y-6 w-[300px]">
				<form
					onSubmit={(e) => {
						e.preventDefault();
						handleSubmit();
					}}
				>
					<Input
						label="Username"
						placeholder="Pink Axolotl"
						value={username}
						onChange={(e) => setUsername(e.target.value)}
					/>
				</form>

				<div className="space-y-2">
					<Button
						className="text-[18px] w-full"
						disabled={username.trim() === ""}
						onClick={handleSubmit}
					>
						Confirm
					</Button>
					<Button
						variant={"secondary"}
						className="text-[18px] w-full"
						onClick={() => {
							navigate({ to: "/", viewTransition: { types: ["warp"] } });
						}}
					>
						Skip for now
					</Button>
				</div>
			</div>
		</div>
	);
});
