"use client"; import Image from "next/image"; import { FormEvent, useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { Loader2, LogIn } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { BrandLogo, BrandMark } from "@/components/brand/logo"; import { ThemeToggle } from "@/components/theme-toggle"; import { BRAND_ASSETS } from "@/lib/brand"; import { notify } from "@/lib/notifications/store"; export default function LoginPage() { const router = useRouter(); const searchParams = useSearchParams(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); async function handleSubmit(event: FormEvent) { event.preventDefault(); setLoading(true); try { const res = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), }); const data = await res.json(); if (!res.ok) { notify({ type: "error", title: data.error ?? "登入失敗" }); setLoading(false); return; } const next = searchParams.get("next"); if (data.needsThreadsBind) { router.replace("/matrix?bind_threads=1"); return; } router.replace(next && next.startsWith("/") ? next : "/matrix"); } catch { notify({ type: "error", title: "連線失敗,請稍後再試" }); setLoading(false); } } return (