import { USER_ROLES_CONFIG } from "../lib/config/index.js";
function createUserRolesConstants(availableRoles) {
  const roles = {};
  availableRoles.forEach((role) => {
    const key = role.toUpperCase();
    roles[key] = role;
  });
  return roles;
}
const USER_ROLES = createUserRolesConstants(USER_ROLES_CONFIG.availableRoles);
const ROLE_HIERARCHY = USER_ROLES_CONFIG.hierarchy;
const isCoreRole = (role) => {
  return USER_ROLES_CONFIG.coreRoles.includes(role);
};
const isThemeRole = (role) => {
  return !isCoreRole(role);
};
const roleHelpers = {
  /**
   * Check if a role has hierarchy level equal or higher than required role
   */
  hasRoleLevel: (userRole, requiredRole) => {
    return ROLE_HIERARCHY[userRole] >= ROLE_HIERARCHY[requiredRole];
  },
  /**
   * Check if user is admin or higher
   */
  isAdmin: (userRole) => {
    return roleHelpers.hasRoleLevel(userRole, USER_ROLES.ADMIN);
  },
  /**
   * Check if user is superadmin
   */
  isSuperAdmin: (userRole) => {
    return userRole === USER_ROLES.SUPERADMIN;
  },
  /**
   * Check if user is developer
   */
  isDeveloper: (userRole) => {
    return userRole === USER_ROLES.DEVELOPER;
  },
  /**
   * Check if user can access Admin Panel (superadmin or developer)
   */
  canAccessAdmin: (userRole) => {
    return userRole === USER_ROLES.SUPERADMIN || userRole === USER_ROLES.DEVELOPER;
  },
  /**
   * Get role display name translation key
   * Use with i18n: t(getRoleDisplayKey(role))
   */
  getRoleDisplayKey: (role) => {
    return USER_ROLES_CONFIG.displayNames[role];
  },
  /**
   * Get all roles ordered by hierarchy (highest permissions first)
   */
  getAllRolesByHierarchy: () => {
    return USER_ROLES_CONFIG.availableRoles.slice().sort(
      (a, b) => ROLE_HIERARCHY[b] - ROLE_HIERARCHY[a]
    );
  }
};
export {
  ROLE_HIERARCHY,
  USER_ROLES,
  isCoreRole,
  isThemeRole,
  roleHelpers
};
