import { useLocation, useNavigate } from 'react-router'; import { ChevronLeft, ChevronRight } from 'lucide-react'; /** * Page flow uses path prefixes for dynamic routes. * Matching is done via startsWith so /report/{any-id} matches '/report/'. */ const PAGE_FLOW = [ { prefix: '/', label: '랜딩', exact: true }, { prefix: '/report/', label: '마케팅 분석' }, { prefix: '/plan/', label: '콘텐츠 기획' }, { prefix: '/studio/', label: '콘텐츠 제작' }, { prefix: '/channels', label: '채널 연결', exact: true }, { prefix: '/distribute', label: '콘텐츠 배포', exact: true }, { prefix: '/performance', label: '성과 관리', exact: true }, ]; 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 { // For dynamic routes, try to preserve the current report/plan ID if (prefix === '/') return '/'; // Extract ID from current path (e.g., /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 (
{/* Back */} {/* Page Indicators */}
{PAGE_FLOW.map((page, i) => (
{/* Next */}
); }