// /utils/loadLoopChartData.ts
import { createLoopChart } from "./chartUtils";

export const loadLoopChartData = (
  slotIndex: number,
  setLoopMeasurementCurveChartData: (data: any) => void
) => {
  const environment = process.env.NODE_ENV || "production";
  const fileData =
    environment === "production"
      ? `/CPL?/CPL/4000values/slot${slotIndex}.json`
      : `/CPLmockData/4000values/slot${slotIndex}.json`;

  fetch(fileData)
    .then((response) => response.json())
    .then((data) => {
      setLoopMeasurementCurveChartData(data);
      createLoopChart(data, "Schleifenmesskurve");
    })
    .catch((error) =>
      console.error("Fehler beim Laden der Schleifenmesskurvendaten:", error)
    );
};
