import React, { useState } from 'react'; import Image from 'next/image'; import useNavigationStore from '@/app/store/navigationStore'; interface ToolbarButton { icon: string; label: string; onClick: () => void; onMouseDown?: () => void; onMouseUp?: () => void; active?: boolean; children?: ToolbarButton[]; } interface SceneToolbarProps { onZoomIn?: () => void; onZoomOut?: () => void; onTopView?: () => void; onPan?: () => void; onSelectModel?: (modelPath: string) => void; panActive?: boolean; navMenuActive?: boolean; } const SceneToolbar: React.FC = ({ onZoomIn, onZoomOut, onTopView, onPan, onSelectModel, panActive = false, navMenuActive = false, }) => { const [isZoomOpen, setIsZoomOpen] = useState(false); const { PREFERRED_MODEL, showMonitoring, openMonitoring, closeMonitoring } = useNavigationStore(); const handleToggleNavMenu = () => { if (showMonitoring) { closeMonitoring(); } else { openMonitoring(); } }; const handleHomeClick = async () => { if (onSelectModel) { try { const res = await fetch('/api/big-models/list'); if (!res.ok) { throw new Error('Failed to fetch models list'); } const data = await res.json(); const items: { name: string; path: string }[] = Array.isArray(data?.models) ? data.models : []; const preferredModelName = PREFERRED_MODEL.split('/').pop()?.split('.').slice(0, -1).join('.') || ''; const preferredModel = items.find(model => (model.path.split('/').pop()?.split('.').slice(0, -1).join('.') || '') === preferredModelName); if (preferredModel) { onSelectModel(preferredModel.path); } else { console.error('Preferred model not found in the list'); } } catch (error) { console.error('Error fetching models list:', error); } } }; const defaultButtons: ToolbarButton[] = [ { icon: '/icons/Zoom.png', label: 'Zoom', onClick: () => setIsZoomOpen(!isZoomOpen), active: isZoomOpen, children: [ { icon: '/icons/plus.svg', label: 'Zoom In', onClick: onZoomIn || (() => {}), }, { icon: '/icons/minus.svg', label: 'Zoom Out', onClick: onZoomOut || (() => {}), }, ] }, { icon: '/icons/Video.png', label: "Top View", onClick: onTopView || (() => console.log('Top View')), }, { icon: '/icons/Pointer.png', label: 'Pan', onClick: onPan || (() => console.log('Pan')), active: panActive, }, { icon: '/icons/Warehouse.png', label: 'Home', onClick: handleHomeClick, }, { icon: '/icons/Layers.png', label: 'Levels', onClick: handleToggleNavMenu, active: navMenuActive, }, ]; return (
{defaultButtons.map((button, index) => (
{button.active && button.children && (
{button.children.map((childButton, childIndex) => ( ))}
)}
))}
); }; export default SceneToolbar;