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

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 {string[]|undefined} permissions */
export function getFirstPermittedSettingsPath(permissions = []) {
  const perms = Array.isArray(permissions) ? 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";
}
