// =============================================================================
// HeadlineSift.com — Authenticated Admin Layout
// =============================================================================
//
// This layout wraps only pages inside the (authenticated) route group.
// /admin/login is OUTSIDE this group — no auth check, no admin chrome.

import { redirect } from "next/navigation";
import { getSession } from "@/lib/auth";
import { SidebarProvider } from "./sidebar-context";
import { AuthenticatedShell } from "./authenticated-shell";

export default async function AuthenticatedAdminLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const session = await getSession();

  if (!session) {
    redirect("/admin/login");
  }

  return (
    <SidebarProvider>
      <AuthenticatedShell
        userName={session.name}
        userEmail={session.email}
        userRole={session.role}
      >
        {children}
      </AuthenticatedShell>
    </SidebarProvider>
  );
}
