import { redirect } from "next/navigation";

import { auth } from "@/src/auth";
import StabilimentiManager from "@/src/components/StabilimentiManager";
import { getPermissions, normalizeRole } from "@/src/lib/permissions";

export default async function StabilimentiPage() {
  const session = await auth();
  if (!session?.user) {
    redirect("/login");
  }

  const ruolo = normalizeRole(session.user.ruolo);
  if (!ruolo || !getPermissions(ruolo).canManageStabilimenti) {
    redirect("/");
  }

  return (
    <div className="min-h-screen bg-black -mx-4 -my-6 px-4 py-6">
      <StabilimentiManager />
    </div>
  );
}
