type CustomFieldValue = string | number | boolean | null | undefined;

export const formatLabel = (key: string) => {
  return key
    .replace(/_/g, " ")
    .replace(/([a-z])([A-Z])/g, "$1 $2") // camelCase → words
    .replace(/\w\S*/g, (txt) => txt[0].toUpperCase() + txt.slice(1));
};

export const normalizeCustomFields = (
  customFields?: Record<string, CustomFieldValue>
) => {
  if (!customFields || typeof customFields !== "object") return [];

  return Object.entries(customFields)
    .filter(
      ([_, value]) => value !== null && value !== undefined && value !== ""
    )
    .map(([key, value]) => ({
      label: formatLabel(key),
      value: String(value),
    }));
};
