import { create } from "zustand";

interface Measurement {
  name: string;
  fields: string;
}

interface MeasurementStore {
  measurements: Record<string, Measurement>;  // Change array to Record<string, Measurement>
  interval: number;
  duration: string;
  name: string;
  setMeasurements: (newMeasurements: Record<string, Measurement>) => void;
  updateDuration: (newDuration: string) => void;
  updateName: (newName: string) => void;
}

const useChartStore = create<MeasurementStore>((set) => ({
  measurements: {}, // Initialize as an empty object
  interval: 1000,
  duration: "1h",
  name:'',

  setMeasurements: (newMeasurements) =>
    set(() => ({ measurements: newMeasurements })),

  updateDuration: (newDuration) =>
    set(() => ({ duration: newDuration })),
  
  updateName: (newName) =>
    set(() => ({ duration: newName })),
}));

export default useChartStore;

