import type { TFunction } from "i18next";

const LABEL_NAMESPACES = [
  "migration.columns",
  "toogle",
  "common",
  "contentManagement",
  "organization",
] as const;

export function getColumnToggleLabel(columnId: string, t: TFunction): string {
  const normalizedId = columnId.includes(".")
    ? (columnId.split(".").pop() ?? columnId)
    : columnId;

  for (const namespace of LABEL_NAMESPACES) {
    const key = `${namespace}.${normalizedId}`;
    const label = t(key);
    if (label !== key) return label;
  }

  return normalizedId
    .replace(/([a-z])([A-Z])/g, "$1 $2")
    .replace(/[_-]/g, " ")
    .replace(/^\w/, (char) => char.toUpperCase());
}
