// /services/fetchAllTDRChartDataService.ts

export const fetchAllTDRChartDataFromServer = async (): Promise<any[]> => {
  const isDev = process.env.NEXT_PUBLIC_NODE_ENV === "development";

  const basePath = isDev
    ? "/apiMockData/LastTDR/jsonDatei"
    : "/CPL?/CPL/LastTDR";

  const fileNames = Array.from({ length: 32 }, (_, i) => `slot${i}.json`);

  const fetchPromises = fileNames.map(async (fileName) => {
    try {
      const response = await fetch(`${basePath}/${fileName}`);
      if (!response.ok)
        throw new Error(`Fehler bei ${fileName}: ${response.statusText}`);
      return await response.json();
    } catch (error) {
      console.error(`❌ Fehler beim Laden von ${fileName}:`, error);
      return null;
    }
  });

  return await Promise.all(fetchPromises);
};
