let cache: Record<string, string> | null = null;

export async function loadZoneLabels(): Promise<Record<string, string>> {
  if (cache) return cache;
  const res = await fetch("/data/zone_labels.json");
  const data = await res.json();
  // The JSON has a "_meta" key + numeric string keys → filter to numeric only
  cache = Object.fromEntries(
    Object.entries(data).filter(([k]) => /^\d+$/.test(k))
  ) as Record<string, string>;
  return cache;
}

export function getZoneLabelSync(zoneId: number, labels: Record<string, string> | null): string {
  return labels?.[String(zoneId)] ?? `зона ${zoneId}`;
}
