import { create } from "zustand";

export interface Widget {
  id: string;
  type: string; // Can be chart type or "progress"
  panel: "top" | "bottom" | "left" | "right";
  title: string;
  fontFamily?: string;
  fontSize?: string;
  fontWeight?: string;
  data?: any;
  Data?:any;
}

interface WidgetStore {
  draggedAsset: Widget | null; // The currently dragged widget asset
  widgets: Widget[]; // List of all widgets
  selectedChartId: any;
  setDraggedAsset: (asset: Widget | null) => void; // Setter for draggedAsset
  addWidget: (widget: Widget) => void; // Add a new widget
  setWidgets: (widgets: Widget[]) => void; // Replace the entire widgets array
  setSelectedChartId: (widget: any | null) => void; // Set the selected chart/widget
}

// Create the store with Zustand
export const useWidgetStore = create<WidgetStore>((set) => ({
  draggedAsset: null,
  widgets: [],
  selectedChartId: null, // Initialize as null, not as an array
  setDraggedAsset: (asset) => set({ draggedAsset: asset }),
  addWidget: (widget) =>
    set((state) => ({ widgets: [...state.widgets, widget] })),
  setWidgets: (widgets) => set({ widgets }),
  setSelectedChartId: (widget) => set({ selectedChartId: widget }),
}));
