import Link from "next/link";
import { requireAdmin } from "@/lib/auth";
import LogoutButton from "@/components/LogoutButton";

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

  return (
    <div className="min-h-dvh flex flex-col">
      <header className="border-b border-slate-200 bg-white">
        <div className="mx-auto max-w-7xl px-4 py-3 flex items-center gap-6">
          <Link href="/admin" className="font-semibold tracking-tight">
            MRP <span className="text-slate-400 font-normal">· Admin</span>
          </Link>
          <nav className="flex gap-4 text-sm text-slate-600">
            <Link href="/admin" className="hover:text-slate-900">Dashboard</Link>
            <Link href="/admin/projects" className="hover:text-slate-900">Projects</Link>
            <Link href="/admin/machines" className="hover:text-slate-900">Machines</Link>
            <Link href="/admin/operations" className="hover:text-slate-900">Operation templates</Link>
            <Link href="/admin/users" className="hover:text-slate-900">Users</Link>
          </nav>
          <div className="ml-auto flex items-center gap-3 text-sm">
            <span className="text-slate-500">{user.name}</span>
            <LogoutButton />
          </div>
        </div>
      </header>
      <main className="flex-1">{children}</main>
    </div>
  );
}
