import { useWidgetStore } from "../../../store/useWidgetStore"; import ProgressCard from "../realTimeVis/charts/ProgressCard"; import PieGraphComponent from "../realTimeVis/charts/PieGraphComponent"; import BarGraphComponent from "../realTimeVis/charts/BarGraphComponent"; import LineGraphComponent from "../realTimeVis/charts/LineGraphComponent"; import RadarGraphComponent from "../realTimeVis/charts/RadarGraphComponent"; import DoughnutGraphComponent from "../realTimeVis/charts/DoughnutGraphComponent"; import PolarAreaGraphComponent from "../realTimeVis/charts/PolarAreaGraphComponent"; export const DraggableWidget = ({ widget, hiddenPanels, // Add this prop to track hidden panels index, onReorder }: { widget: any; hiddenPanels: string[]; // Array of hidden panel names index: number; onReorder: (fromIndex: number, toIndex: number) => void }) => { const { selectedChartId, setSelectedChartId } = useWidgetStore(); const handlePointerDown = () => { if (selectedChartId?.id !== widget.id) { setSelectedChartId(widget); } }; // Determine if the widget's panel is hidden const isPanelHidden = hiddenPanels.includes(widget.panel); const handleDragStart = (event: React.DragEvent) => { event.dataTransfer.setData('text/plain', index.toString()); // Store the index of the dragged widget }; const handleDragEnter = (event: React.DragEvent) => { event.preventDefault(); // Allow drop }; const handleDragOver = (event: React.DragEvent) => { event.preventDefault(); // Allow drop }; const handleDrop = (event: React.DragEvent) => { event.preventDefault(); const fromIndex = parseInt(event.dataTransfer.getData('text/plain'), 10); // Get the dragged widget's index const toIndex = index; // The index of the widget where the drop occurred if (fromIndex !== toIndex) { onReorder(fromIndex, toIndex); // Call the reorder function passed as a prop } }; return ( <> ); };