/**
 * Settings section: first landing path when opening `/settings` or the sidebar “Settings” item.
 * Order mirrors TLP-style priority (organization → users → roles → audit).
 */

import { normalizePermissionList } from "../utils/permissionList";

export const SETTINGS_CHILD_ROUTES = [
  { path: "/settings/organization", permission: "settings.organization.view" },
  { path: "/settings/users", permission: "users.view" },
  { path: "/settings/roles", permission: "roles.view" },
  { path: "/settings/activity-log", permission: "activitylog.view" },
];

/** @param {unknown} permissions */
export function getFirstPermittedSettingsPath(permissions) {
  const perms = normalizePermissionList(permissions);
  const hit = SETTINGS_CHILD_ROUTES.find((r) => perms.includes(r.permission));
  if (hit) {
    return hit.path;
  }
  /** No settings screens permitted — show CORE access-denied instead of bouncing to /dashboard. */
  return "/auth/access";
}
