import Link from 'next/link';
import { requireAdmin } from '@/lib/auth/admin-guard';
import { AdminNav } from './admin-nav';

export const dynamic = 'force-dynamic';

export default async function AdminLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const user = await requireAdmin();

  return (
    <div className="admin-shell">
      <aside className="admin-sidebar">
        <div className="admin-brand">Admin</div>
        <AdminNav />
        <div className="admin-sidebar-footer">
          <div className="muted" style={{ wordBreak: 'break-all' }}>
            {user.email}
          </div>
          <Link href="/dashboard" className="admin-back">
            ← Back to dashboard
          </Link>
        </div>
      </aside>
      <section className="admin-content">{children}</section>
    </div>
  );
}
