// /services/fetchAllTDRReferenceChartData.ts

const getTDRReferenceBasePath = () => {
  if (typeof window !== "undefined") {
    return window.location.hostname === "localhost"
      ? "/CPLMockData/tdr-reference-curves"
      : "/CPL?/CPL/tdr-reference-curves";
  }
  return "";
};

export const fetchAllTDRReferenceChartData = async () => {
  const maxSlots = 32;
  const results = [];
  const basePath = getTDRReferenceBasePath();

  for (let i = 0; i < maxSlots; i++) {
    try {
      const response = await fetch(`${basePath}/slot${i}.json`);
      if (!response.ok) {
        results[i] = null;
        continue;
      }
      const json = await response.json();
      results[i] = json;
    } catch (error) {
      results[i] = null;
    }
  }

  return results;
};
