export function cdcGpsfUiKey(prefix: string, key: string) {
  return `${prefix}.${key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/\s+/g, "_").toLowerCase()}`;
}

export function resolveCdcGpsfUiLabels<T extends object>(
  defaults: T,
  dictionary: Record<string, string>,
  prefix: string,
): T {
  return Object.fromEntries(Object.entries(defaults).map(([key, fallback]) => {
    const value = dictionary[cdcGpsfUiKey(prefix, key)];
    return [key, typeof fallback === "string" && typeof value === "string" && value.trim()
      ? value
      : fallback];
  })) as T;
}
