/**
 * Tabs hidden from navigation and staff permission UI until features ship.
 * Routes, pages, and backend permissions stay in place — flip flags to re-enable.
 */
export const HIDDEN_TAB_FEATURE_FLAGS = {
  billing: true,
  reports: true,
} as const;

const HIDDEN_PATHS: readonly string[] = [
  ...(HIDDEN_TAB_FEATURE_FLAGS.billing ? (['/billing'] as const) : []),
  ...(HIDDEN_TAB_FEATURE_FLAGS.reports ? (['/reports'] as const) : []),
];

const HIDDEN_PERMISSIONS: readonly string[] = [
  ...(HIDDEN_TAB_FEATURE_FLAGS.billing
    ? (['TAB_BILLING_READ', 'TAB_BILLING_EDIT'] as const)
    : []),
  ...(HIDDEN_TAB_FEATURE_FLAGS.reports
    ? (['TAB_REPORTS_READ', 'TAB_REPORTS_EDIT'] as const)
    : []),
];

const HIDDEN_PATH_SET = new Set<string>(HIDDEN_PATHS);
const HIDDEN_PERMISSION_SET = new Set<string>(HIDDEN_PERMISSIONS);

export function isHiddenTabPath(path: string): boolean {
  return HIDDEN_PATH_SET.has(path);
}

export function isHiddenTabPermission(permission: string): boolean {
  return HIDDEN_PERMISSION_SET.has(permission);
}

/** Keep hidden-tab grants when saving staff permissions the UI no longer shows. */
export function preserveHiddenTabPermissions(
  fromForm: string[],
  existing?: string[] | null,
): string[] {
  if (!existing?.length) return fromForm;
  const preserved = existing.filter((p) => isHiddenTabPermission(p));
  if (!preserved.length) return fromForm;
  return [...new Set([...fromForm, ...preserved])];
}
