/**
 * Settings submenu: first permitted child path.
 * Order matches backend config/navigation.php so sidebar and guard stay in sync.
 */

export const SETTINGS_CHILD_ROUTES = [
  { path: "/settings/company", permission: "settings.company.view" },
  { path: "/users", permission: "users.view" },
  { path: "/roles", permission: "roles.view" },
  { path: "/settings/groups", permission: "groups.view" },
  { path: "/settings/activity-log", permission: "activitylog.view" },
  { path: "/sectors", permission: "sectors.view" },
  { path: "/settings/job-functions", permission: "jobfunctions.view" },
  { path: "/settings/departments", permission: "departments.view" },
  { path: "/settings/subsidy-themes", permission: "subsidythemes.view" },
  { path: "/settings/subsidy-grantors", permission: "subsidygrantors.view" },
  { path: "/settings/checklists", permission: "checklists.view" },
  { path: "/settings/default-tasks", permission: "default_tasks.view" },
  { path: "/settings/default-documents", permission: "default_documents.view" },
];

/**
 * Returns the first settings child path the user may access, or null if none.
 * @param {string[]} permissions - From useAuth().permissions
 * @returns {string|null}
 */
export function getFirstPermittedSettingsPath(permissions) {
  if (!Array.isArray(permissions)) return null;
  const r = SETTINGS_CHILD_ROUTES.find((route) =>
    permissions.includes(route.permission),
  );
  return r ? r.path : null;
}
