import { useLocation, useNavigate } from 'react-router'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import { PAGE_FLOW } from '@/shared/constants/pageFlow'; function findCurrentIndex(pathname: string): number { return PAGE_FLOW.findIndex((p) => p.exact ? pathname === p.prefix : pathname.startsWith(p.prefix) ); } function getNavigatePath(prefix: string, currentPath: string): string { // 동적 라우트의 경우 현재 report/plan ID를 보존하려고 시도 if (prefix === '/') return '/'; // 현재 경로에서 ID 추출 (예: /report/abc123 → abc123) const idMatch = currentPath.match(/\/(report|plan|studio|clinic)\/(.+)/); const currentId = idMatch?.[2] || 'live'; if (prefix.endsWith('/')) { return `${prefix}${currentId}`; } return prefix; } export default function PageNavigator() { const location = useLocation(); const navigate = useNavigate(); const currentIndex = findCurrentIndex(location.pathname); if (currentIndex === -1) return null; const prev = currentIndex > 0 ? PAGE_FLOW[currentIndex - 1] : null; const next = currentIndex < PAGE_FLOW.length - 1 ? PAGE_FLOW[currentIndex + 1] : null; return (