import { useState, useRef, useEffect, useMemo } from 'react' import type { MainTab } from '../../types/navigation' import { useAuthStore } from '../../store/authStore' import { useMenuStore } from '../../store/menuStore' import { useMapStore } from '../../store/mapStore' interface TopBarProps { activeTab: MainTab onTabChange: (tab: MainTab) => void } export function TopBar({ activeTab, onTabChange }: TopBarProps) { const [showQuickMenu, setShowQuickMenu] = useState(false) const quickMenuRef = useRef(null) const { hasPermission, user, logout } = useAuthStore() const { menuConfig, isLoaded } = useMenuStore() const { mapToggles, toggleMap } = useMapStore() const tabs = useMemo(() => { if (!isLoaded || menuConfig.length === 0) return [] return menuConfig .filter((m) => m.enabled && hasPermission(m.id)) .sort((a, b) => a.order - b.order) }, [hasPermission, user?.permissions, menuConfig, isLoaded]) useEffect(() => { const handler = (e: MouseEvent) => { if (quickMenuRef.current && !quickMenuRef.current.contains(e.target as Node)) setShowQuickMenu(false) } if (showQuickMenu) document.addEventListener('mousedown', handler) return () => document.removeEventListener('mousedown', handler) }, [showQuickMenu]) return (
{/* Left Section */}
{/* Logo */}
WING 해양환경 위기대응
{/* Divider */}
{/* Tabs */}
{tabs.map((tab) => { const isIncident = tab.id === 'incidents' return ( ) })}
{/* Right Section */}
{/* Status Badge */}
사고 진행중
{/* Icon Buttons */} {hasPermission('admin') && ( )} {user && (
{user.name}
)} {/* Quick Menu */}
{showQuickMenu && (
{/* 거리·면적 계산 */}
📐 거리·면적 계산
{/* 출력 */}
🖨 출력
{/* 지도 유형 */}
🗺 지도 유형
{([ { key: 's57' as const, label: 'S-57 전자해도', icon: '🗺' }, { key: 's101' as const, label: 'S-101 전자해도', icon: '🗺' }, { key: 'threeD' as const, label: '3D 지도', icon: '🗺' }, { key: 'satellite' as const, label: '위성 영상', icon: '🛰' }, ]).map(item => ( ))}
)}
) }