import type { TFunction } from "i18next";

/** 与 {@link AdminBreadcrumb} / 侧栏共用：仅用 i18n，避免 API 旧 label 作 defaultValue 导致水合不一致 */
const NAV_SEGMENT_I18N_KEYS: Record<string, string> = {
  dashboard: "dashboard",
  admin_users: "admin_users",
  admin_roles: "admin_roles",
  players: "players",
  currencies: "currencies",
  wallet: "wallet",
  draws: "draws",
  rules_plays: "rules_plays",
  rules_odds: "rules_odds",
  jackpot: "jackpot",
  risk_cap: "risk_cap",
  risk: "risk",
  settlement: "settlement",
  settlement_center: "settlement_center",
  reconcile: "reconcile",
  reports: "reports",
  tickets: "tickets",
  audit: "audit",
  settings: "settings",
  integration: "integration",
  agents: "agents",
  config: "config",
};

const LEGACY_NAV_SEGMENT_I18N_KEYS: Record<string, string> = {
  agent_list: "agents",
};

export function adminNavLabel(
  segment: string,
  t: TFunction,
  apiLabel?: string | null,
): string {
  const key = NAV_SEGMENT_I18N_KEYS[segment] ?? LEGACY_NAV_SEGMENT_I18N_KEYS[segment];
  if (key) {
    return t(`nav.${key}`, { ns: "common" });
  }

  return apiLabel?.trim() ? apiLabel : segment;
}
