"use client";
import { useSession } from "next-auth/react";

const COST_ROLES = ["ADMIN", "MANAGER", "CONTROLLER"] as const;
const EDIT_ROLES = ["ADMIN", "MANAGER"] as const;
const SCORE_ROLES = ["ADMIN", "MANAGER"] as const;

export function usePermissions() {
  const { data: session } = useSession();
  const role = (session?.user as { role?: string } | undefined)?.role ?? "USER";

  return {
    canViewCosts: COST_ROLES.includes(role as typeof COST_ROLES[number]),
    canEdit: EDIT_ROLES.includes(role as typeof EDIT_ROLES[number]),
    canManageUsers: role === "ADMIN",
    canManageBlueprints: role === "ADMIN",
    canViewScores: SCORE_ROLES.includes(role as typeof SCORE_ROLES[number]),
    role,
  };
}
