import Link from 'next/link';

import { LogoutButton } from '@/components/admin/LogoutButton';
import { getSessionUser } from '@/lib/auth/session';
import style from '@/styles/admin.module.scss';

export default async function AdminDashboardPage() {
  const user = await getSessionUser();
  if (!user) {
    return null;
  }

  return (
    <div className={style.card}>
      <h1 className={style.title}>Admin</h1>
      <p className={style.sub}>
        Signed in as <strong>{user.email}</strong>
        {user.is_admin ? ' (administrator)' : ''}
      </p>
      {!user.is_admin && (
        <p className={style.error}>
          You do not have permission to edit content. Ask an administrator to grant admin access.
        </p>
      )}
      {user.is_admin && (
        <ul style={{ lineHeight: 1.8 }}>
          <li>
            <Link href="/admin/users">Users (approval &amp; roles)</Link>
          </li>
          <li>
            <Link href="/admin/players">Players</Link>
          </li>
          <li>
            <Link href="/admin/guide">Guide</Link>
          </li>
          <li>
            <Link href="/admin/archive">Archive</Link>
          </li>
          <li>
            <Link href="/admin/qa">Q&amp;A</Link>
          </li>
        </ul>
      )}
      <div style={{ marginTop: 16 }}>
        <LogoutButton />
      </div>
    </div>
  );
}
