import { useState, useEffect } from "react";

const ROLE_KEY = "mbg_user_role";

export const ROLES = {
  ADMIN: "admin",
  PEMERINTAH: "pemerintah",
  SPPG: "sppg",
  VALIDATOR: "validator",
  PUBLIK: "publik",
};

export const ROLE_LABELS = {
  admin: "Admin",
  pemerintah: "Pemerintah",
  sppg: "SPPG",
  validator: "Validator",
  publik: "Masyarakat",
};

export const ROLE_COLORS = {
  admin: "bg-red-100 text-red-700",
  pemerintah: "bg-blue-100 text-blue-700",
  sppg: "bg-green-100 text-green-700",
  validator: "bg-purple-100 text-purple-700",
  publik: "bg-gray-100 text-gray-700",
};

export function useRole() {
  const [role, setRoleState] = useState(() => localStorage.getItem(ROLE_KEY) || ROLES.PUBLIK);

  const setRole = (r) => {
    localStorage.setItem(ROLE_KEY, r);
    setRoleState(r);
  };

  return { role, setRole, ROLES, ROLE_LABELS, ROLE_COLORS };
}