'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useQuery } from '@tanstack/react-query'; import { BatteryMedium, ChevronRight, Command, Monitor, Search, Wifi } from 'lucide-react'; import { getProfile } from '@/api/profile'; import ThemeToggle from '@/components/theme/ThemeToggle'; const defaultProfile = { githubUrl: 'https://github.com', email: 'user@example.com', }; const getCategoryTitle = (pathname: string) => { const encodedName = pathname.split('/category/')[1]?.split('/')[0] || ''; const decodedName = decodeURIComponent(encodedName); return decodedName === 'uncategorized' ? '미분류' : decodedName; }; const getAppTitle = (pathname: string) => { if (pathname.startsWith('/admin/posts/new')) return 'Write'; if (pathname.startsWith('/admin/posts')) return 'Post Manager'; if (pathname.startsWith('/admin/comments')) return 'Comment Center'; if (pathname.startsWith('/admin/categories')) return 'Category Studio'; if (pathname.startsWith('/admin/profile')) return 'Profile Panel'; if (pathname.startsWith('/admin')) return 'Admin Console'; if (pathname.startsWith('/archive')) return 'Archive'; if (pathname.startsWith('/category')) return getCategoryTitle(pathname); if (pathname.startsWith('/posts')) return 'Reader'; if (pathname.startsWith('/chess')) return 'Maia Chess'; if (pathname.startsWith('/play/chess')) return 'Chess'; if (pathname.startsWith('/login')) return 'Login'; if (pathname.startsWith('/signup')) return 'Signup'; return '홈'; }; const formatMenuTime = (date: Date | null) => { if (!date) return ''; return new Intl.DateTimeFormat('ko-KR', { month: 'short', day: 'numeric', weekday: 'short', hour: '2-digit', minute: '2-digit', }).format(date); }; export default function DesktopMenuBar() { const pathname = usePathname(); const [now, setNow] = useState(null); const { data: profile } = useQuery({ queryKey: ['profile'], queryFn: getProfile, retry: 0, }); useEffect(() => { const updateTime = () => setNow(new Date()); const frameId = window.requestAnimationFrame(updateTime); const timerId = window.setInterval(updateTime, 60_000); return () => { window.cancelAnimationFrame(frameId); window.clearInterval(timerId); }; }, []); const githubUrl = profile?.githubUrl || defaultProfile.githubUrl; const email = profile?.email || defaultProfile.email; const menuLinkClass = 'hidden rounded px-2 py-1 text-xs font-semibold text-[var(--color-text-muted)] transition hover:bg-[var(--card-bg)] hover:text-[var(--color-text)] xl:inline-flex'; const systemIconClass = 'text-[var(--color-text-muted)]'; return (
WYPark
{getAppTitle(pathname)} {profile?.name || 'WYPark'}
GitHub Email {formatMenuTime(now)}
); }