'use client'; import { useEffect, useState } from 'react'; import { Scale, Search, Bookmark, MessageSquare, Home, BookOpen, FileText, Menu, X, ChevronLeft, Grid3x3, FileSearch, Wand2, Database } from 'lucide-react'; import { useNavigation } from '@/lib/navigation'; import { PersonaSwitcher } from '@/components/onboarding/PersonaSwitcher'; import { RecentlyViewed } from '@/components/common/RecentlyViewed'; import { cn } from '@/lib/utils'; const NAV_ITEMS = [ { view: { name: 'home' } as const, label: 'หน้าแรก', icon: Home }, { view: { name: 'ask' } as const, label: 'ถาม AI', icon: MessageSquare, badge: 'AI' }, { view: { name: 'pdf-builder' } as const, label: 'สร้างเอกสาร', icon: Wand2 }, { view: { name: 'risk-matrix' } as const, label: 'Risk Matrix', icon: Grid3x3 }, { view: { name: 'contract-analysis' } as const, label: 'วิเคราะห์สัญญา', icon: FileSearch }, { view: { name: 'laws' } as const, label: 'กฎหมาย', icon: BookOpen }, { view: { name: 'judgments' } as const, label: 'คำพิพากษา', icon: Scale }, { view: { name: 'search' } as const, label: 'ค้นหา', icon: Search }, { view: { name: 'templates' } as const, label: 'เทมเพลต', icon: FileText, badge: '63' }, { view: { name: 'data-dashboard' } as const, label: 'สถานะข้อมูล', icon: Database }, { view: { name: 'bookmarks' } as const, label: 'บันทึก', icon: Bookmark }, ]; // Logged-in user email (single-tenant app — could be replaced with real auth session) const USER_EMAIL = 'siriwat@panya-ai.co.th'; export function Sidebar() { const { getView, navigate } = useNavigation(); const [currentView, setCurrentView] = useState<{ name: string }>({ name: 'home' }); const [collapsed, setCollapsed] = useState(false); const [mobileOpen, setMobileOpen] = useState(false); useEffect(() => { const update = () => setCurrentView(getView() as any); update(); window.addEventListener('popstate', update); return () => window.removeEventListener('popstate', update); }, [getView]); return ( <> {/* Mobile toggle button — fixed top-left, only on mobile. When sidebar is open on mobile, this button hides so it doesn't overlap with the logo inside the sidebar. */} {!mobileOpen && ( setMobileOpen(true)} className="fixed top-4 left-4 z-50 md:hidden flex h-10 w-10 items-center justify-center rounded-lg bg-card-soft border border-border/60 shadow-lg" aria-label="เปิดเมนู" > )} {/* Mobile overlay — native so it's keyboard-accessible & screen-reader friendly */} {mobileOpen && ( setMobileOpen(false)} className="fixed inset-0 z-40 bg-black/50 md:hidden cursor-default" aria-label="ปิดเมนู" /> )} {/* Sidebar */} > ); }