import { WalletIcon } from "../../icons/3dChartIcons"; import { useEffect, useRef, useState } from "react"; import { Line } from "react-chartjs-2"; import { useDroppedObjectsStore, Zones } from "../../../store/useDroppedObjectsStore"; const DroppedObjects: React.FC = () => { const zones = useDroppedObjectsStore((state) => state.zones); const updateObjectPosition = useDroppedObjectsStore((state) => state.updateObjectPosition); const [draggingIndex, setDraggingIndex] = useState<{ zone: string; index: number } | null>(null); const [offset, setOffset] = useState<[number, number] | null>(null); const positionRef = useRef<[number, number] | null>(null); const animationRef = useRef(null); // useEffect(() => { // const initialZones: Record = { // "Zone 1": { // zoneName: "Zone 1", // zoneId: "2e996073-546c-470c-8323-55bd3700c6aa", // objects: [ // { // header: "Today’s Money", // value: 53000, // ✅ Converted to number // per: "+55%", // className: "floating total-card", // position: [146, 214], // ✅ No need for 'as' here // }, // { // header: "New Clients", // value: 250, // ✅ Converted to number // per: "+12%", // className: "floating total-card", // position: [344, 295], // }, // ], // }, // }; // useDroppedObjectsStore.setState({ zones: initialZones }); // }, []); const zoneEntries = Object.entries(zones); if (zoneEntries.length === 0) return null; // No zone, nothing to render const [zoneName, zone] = zoneEntries[0]; // Only render the first zone function handlePointerDown(event: React.PointerEvent, index: number) { const obj = zone.objects[index]; const offsetX = event.clientX - obj.position[1]; const offsetY = event.clientY - obj.position[0]; setDraggingIndex({ zone: zoneName, index }); setOffset([offsetY, offsetX]); } function handlePointerMove(event: React.PointerEvent) { if (!draggingIndex || !offset) return; const container = document.getElementById("real-time-vis-canvas"); if (!container) return; const rect = container.getBoundingClientRect(); let newX = event.clientX - offset[1]; let newY = event.clientY - offset[0]; newX = Math.max(0, Math.min(rect.width - 50, newX)); newY = Math.max(0, Math.min(rect.height - 50, newY)); positionRef.current = [newY, newX]; if (!animationRef.current) { animationRef.current = requestAnimationFrame(() => { if (positionRef.current) { updateObjectPosition(zoneName, draggingIndex.index, positionRef.current); } animationRef.current = null; }); } } function handlePointerUp() { setDraggingIndex(null); setOffset(null); if (animationRef.current) { cancelAnimationFrame(animationRef.current); animationRef.current = null; } } return (
{zone.objects.map((obj, index) => (
handlePointerDown(event, index)} > {obj.className === "floating total-card" ? (
{obj.header}
{obj.value}
{obj.per}
) : obj.className === "warehouseThroughput floating" ? (

Warehouse Throughput

(+5) more in 2025

{/* */}
) : obj.className === "fleetEfficiency floating" ? (

Fleet Efficiency

0%
{obj.per}%
Optimal
100%
) : null}
))}
); }; export default DroppedObjects; // import { Html } from "@react-three/drei"; // import { useDroppedObjectsStore } from "../../../store/store"; // import { CartIcon, DocumentIcon, GlobeIcon, WalletIcon } from "../../icons/3dChartIcons"; // import SimpleCard from "../realTimeVis/floating/SimpleCard"; // const ICON_MAP: Record>> = { // WalletIcon, // GlobeIcon, // DocumentIcon, // CartIcon // }; // const DroppedObjects: React.FC = () => { // const objects = useDroppedObjectsStore((state) => state.objects); // Get objects from Zustand store // // return ( // <> // {objects.map((obj, index) => { // const IconComponent = obj.Icon || WalletIcon; // Use obj.Icon directly if it exists // return ( // // ); // })} // // ); // }; // export default DroppedObjects;