import { redirect } from "next/navigation";
import { getSession } from "@/lib/auth";

export default async function Account({ searchParams }: { searchParams: Promise<{ error?: string; updated?: string }> }) {
  const user = await getSession(); if (!user) redirect("/login"); const query = await searchParams;
  return <><h1>帳號設定</h1>{query.error && <p className="error">{query.error}</p>}{query.updated && <p>密碼已更新。</p>}<section className="card"><p className="meta">帳號：{user.username}</p><h2>變更密碼</h2><form action="/api/auth/password" method="post"><label>目前密碼<input name="currentPassword" type="password" autoComplete="current-password" required /></label><label>新密碼<input name="newPassword" type="password" autoComplete="new-password" minLength={10} required /></label><label>確認新密碼<input name="confirmPassword" type="password" autoComplete="new-password" minLength={10} required /></label><button>更新密碼</button></form></section></>;
}
