import { getSession } from "../../lib/auth/session";
import Link from "next/link";

export default async function AccountPage() {
  const session = await getSession();

  if (!session) {
    return (
      <main className="max-w-5xl mx-auto px-6 py-16">
        <h1 className="text-3xl font-bold text-slate-900 dark:text-white">👤 Account</h1>
        <p className="text-gray-600 dark:text-gray-400 mt-3">Please sign in to view your account.</p>
      </main>
    );
  }

  if (session.forcePasswordReset) {
    return (
      <main className="max-w-5xl mx-auto px-6 py-16">
        <h1 className="text-3xl font-bold text-slate-900 dark:text-white">⚠️ Action required</h1>
        <p className="text-gray-600 dark:text-gray-400 mt-3">
          You must reset your password before continuing.
        </p>
        <Link className="inline-block mt-6 btn-primary" href="/account/reset-password">
          🔐 Reset password
        </Link>
      </main>
    );
  }

  return (
    <main className="max-w-5xl mx-auto px-6 py-16">
      <h1 className="text-3xl font-bold text-slate-900 dark:text-white">👤 Account</h1>
      <p className="text-gray-600 dark:text-gray-400 mt-3">
        Signed in as <span className="font-semibold text-primary">{session.email}</span>
      </p>

      <div className="mt-10 space-y-3 flex flex-col w-fit">
        <Link className="btn-secondary" href="/account/settings">
          ⚙️ Settings
        </Link>
        <Link className="btn-secondary" href="/account/webinars">
          📚 My Webinars
        </Link>
        {session.role === "ADMIN" && (
          <Link className="btn-primary" href="/admin">
            🔧 Admin Dashboard
          </Link>
        )}
      </div>
    </main>
  );
}
