import { ReactNode } from "react"
import { redirect } from "next/navigation"

import { requireAuthenticatedSession } from "@/lib/auth-server"
import { isStaff } from "@/lib/authz"

export const dynamic = "force-dynamic"
export const runtime = "nodejs"

export default async function AdminLayout({ children }: { children: ReactNode }) {
  const session = await requireAuthenticatedSession()
  const role = session.user.role ?? "agent"
  if (!isStaff(role)) {
    // agentes (staff) podem acessar; visitantes sem papel de staff caem no portal.
    redirect("/portal")
  }
  return <>{children}</>
}
