import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useEffect, useState } from "react";
import { useAuth } from "@/hooks/use-auth";
import { Button } from "@/components/ui/button";
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Checkbox } from "@/components/ui/checkbox";
import { Card } from "@/components/ui/card";
import { Sparkles } from "lucide-react";
import LoadingScreen from "@/components/ui/LoadingScreen";
import { useLocation } from "wouter";
import { loginSchema } from "@repo/db/types";
const DAILY_PALETTES = [
{ bg: "#f8fafc", blobs: ["#a78bfa", "#38bdf8", "#f472b6", "#fb923c"], textColor: "#1e293b" },
{ bg: "#faf5ff", blobs: ["#c084fc", "#22d3ee", "#fb7185", "#facc15"], textColor: "#1e1b4b" },
{ bg: "#f0f9ff", blobs: ["#60a5fa", "#a78bfa", "#34d399", "#f97316"], textColor: "#0c4a6e" },
{ bg: "#fdf4ff", blobs: ["#e879f9", "#38bdf8", "#fbbf24", "#4ade80"], textColor: "#4a044e" },
{ bg: "#f0fdf4", blobs: ["#4ade80", "#818cf8", "#fb923c", "#f472b6"], textColor: "#052e16" },
{ bg: "#fffbeb", blobs: ["#fbbf24", "#f87171", "#a78bfa", "#22d3ee"], textColor: "#78350f" },
{ bg: "#f8fafc", blobs: ["#38bdf8", "#e879f9", "#34d399", "#fb923c"], textColor: "#0f172a" },
{ bg: "#fef2f2", blobs: ["#fb7185", "#a78bfa", "#38bdf8", "#4ade80"], textColor: "#7f1d1d" },
{ bg: "#ecfdf5", blobs: ["#34d399", "#818cf8", "#f472b6", "#facc15"], textColor: "#064e3b" },
{ bg: "#f5f3ff", blobs: ["#8b5cf6", "#f472b6", "#22d3ee", "#fb923c"], textColor: "#2e1065" },
{ bg: "#fff7ed", blobs: ["#fb923c", "#a78bfa", "#22d3ee", "#4ade80"], textColor: "#7c2d12" },
{ bg: "#f0f9ff", blobs: ["#22d3ee", "#c084fc", "#f97316", "#34d399"], textColor: "#0c4a6e" },
{ bg: "#fdf2f8", blobs: ["#f472b6", "#60a5fa", "#facc15", "#34d399"], textColor: "#831843" },
{ bg: "#f8fafc", blobs: ["#818cf8", "#f97316", "#22d3ee", "#f472b6"], textColor: "#1e293b" },
];
function getDailyPalette() {
const now = new Date();
const start = new Date(now.getFullYear(), 0, 0);
const dayOfYear = Math.floor((now.getTime() - start.getTime()) / 86400000);
return DAILY_PALETTES[dayOfYear % DAILY_PALETTES.length];
}
export default function AuthPage() {
const { isLoading, user, loginMutation } = useAuth();
const [, navigate] = useLocation();
const [greeting, setGreeting] = useState("How can I help you today?");
const palette = getDailyPalette();
useEffect(() => {
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL_BACKEND ?? "";
fetch(`${API_BASE_URL}/api/greeting`)
.then((r) => r.json())
.then((data) => { if (data.greeting)
setGreeting(data.greeting); })
.catch(() => { });
}, []);
const loginForm = useForm({
resolver: zodResolver(loginSchema),
defaultValues: {
username: "",
password: "",
rememberMe: false,
},
});
const onLoginSubmit = (data) => {
loginMutation.mutate({ username: data.username, password: data.password });
};
if (isLoading) {
return
Driven By Multiple AI Agents
{greeting}