import { useState } from "react"; import { useWidgetStore } from "../../../../../store/useWidgetStore"; import ChartComponent from "../../../sidebarLeft/visualization/widgets/ChartComponent"; import RegularDropDown from "../../../../ui/inputs/RegularDropDown"; // Define Props Interface interface Widget { id: string; type: string; // Chart type (e.g., "bar", "line") panel: "top" | "bottom" | "left" | "right"; // Panel location title: string; fontFamily?: string; fontSize?: string; fontWeight?: string; data: { labels: string[]; datasets: { data: number[]; backgroundColor: string; borderColor: string; borderWidth: number; }[]; }; // Data for the chart } const Design = () => { const [selectedName, setSelectedName] = useState("drop down"); console.log("selectedName: ", selectedName); const [selectedElement, setSelectedElement] = useState("drop down"); console.log("selectedElement: ", selectedElement); const [selectedFont, setSelectedFont] = useState("drop down"); console.log("selectedFont: ", selectedFont); const [selectedSize, setSelectedSize] = useState("drop down"); console.log("selectedSize: ", selectedSize); const [selectedWeight, setSelectedWeight] = useState("drop down"); console.log("selectedWeight: ", selectedWeight); const [elementColor, setElementColor] = useState("#6f42c1"); // Default color for elements const [showColorPicker, setShowColorPicker] = useState(false); // Manage visibility of the color picker // Zustand Store Hooks const { selectedChartId, setSelectedChartId, widgets, setWidgets } = useWidgetStore(); // Handle Widget Updates const handleUpdateWidget = (updatedProperties: Partial) => { if (!selectedChartId) return; // Update the selectedChartId const updatedChartId = { ...selectedChartId, ...updatedProperties, }; setSelectedChartId(updatedChartId); // Update the widgets array const updatedWidgets = widgets.map((widget) => widget.id === selectedChartId.id ? { ...widget, ...updatedProperties } : widget ); setWidgets(updatedWidgets); }; // Default Chart Data const defaultChartData = { labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"], datasets: [ { data: [65, 59, 80, 81, 56, 55, 40], backgroundColor: elementColor, // Default background color borderColor: "#ffffff", // Default border color borderWidth: 1, }, ], }; return (
{/* Title of the Selected Widget */}
{selectedChartId?.title || "Widget 1"}
{/* Chart Component */}
{selectedChartId && ( )}
{/* Options Container */}
{/* Name Dropdown */}
Name { setSelectedName(value); handleUpdateWidget({ title: value }); }} />
{/* Element Dropdown */}
Element { setSelectedElement(value); handleUpdateWidget({ type: value }); }} />
{/* Font Family Dropdown */}
Font Family { setSelectedFont(value); handleUpdateWidget({ fontFamily: value }); }} />
{/* Size Dropdown */}
Size { setSelectedSize(value); handleUpdateWidget({ fontSize: value }); }} />
{/* Weight Dropdown */}
Weight { setSelectedWeight(value); handleUpdateWidget({ fontWeight: value }); }} />
{/* Element Color Picker */}
setShowColorPicker((prev) => !prev)} > Element Color
{" "} {/* Change icon based on the visibility */}
{/* Show color picker only when 'showColorPicker' is true */} {showColorPicker && (
{ setElementColor(e.target.value); handleUpdateWidget({ data: { labels: selectedChartId?.data?.labels || [], datasets: [ { ...selectedChartId?.data?.datasets[0], backgroundColor: e.target.value, // Update the element color }, ], }, }); }} /> {/* Display the selected color value */} {elementColor}
)}
); }; export default Design;