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;
  header: string;
  flotingDuration: string;
  flotingMeasurements: Record<string, Measurement>;  // Change array to Record<string, Measurement>
  setMeasurements: (newMeasurements: Record<string, Measurement>) => void;
  updateDuration: (newDuration: string) => void;
  updateName: (newName: string) => void;
  updateHeader: (newHeader: string) => void;
  updateFlotingDuration: (newFlotingDuration: string) => void;
  setFlotingMeasurements: (newFlotingMeasurements: Record<string, Measurement>) => void;
}

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

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

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

  updateHeader: (newHeader) =>
    set(() => ({ header: newHeader })),

  updateFlotingDuration: (newFlotingDuration) =>
    set(() => ({ flotingDuration: newFlotingDuration })),

  setFlotingMeasurements: (newFlotingMeasurements) =>
    set(() => ({ flotingMeasurements: newFlotingMeasurements })),
}));

export default useChartStore;

