import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import { redirect } from "next/navigation";

export default async function AdminLayout({ children }: { children: React.ReactNode }) {
  const session = await getServerSession(authOptions);
  const userEmail = (session?.user as any)?.email as string | undefined;
  const adminEmail = process.env.ADMIN_EMAIL;

  if (!session || !adminEmail || userEmail !== adminEmail) {
    redirect("/dashboard");
  }

  return (
    <div className="min-h-screen" style={{ background: "var(--bg-base)" }}>
      {/* Admin top bar */}
      <div className="border-b border-red-500/20 px-6 py-3 flex items-center gap-3"
        style={{ background: "rgba(239,68,68,0.05)" }}>
        <div className="w-2 h-2 bg-red-500 rounded-full animate-pulse" />
        <span className="text-xs font-bold text-red-400 uppercase tracking-widest">Admin Panel</span>
        <span className="text-xs text-slate-600 ml-2">— {userEmail}</span>
        <a href="/dashboard" className="ml-auto text-xs text-slate-500 hover:text-white transition-colors">
          ← Inapoi la dashboard
        </a>
      </div>
      {children}
    </div>
  );
}
