/** * [F11-S2] ErrorNav — Previous/Next error navigation buttons with counter */ import React, { useCallback, useMemo } from 'react'; import { findNextError, findPrevError, getErrorPosition } from '../../hooks/useErrorIndices'; export interface ErrorNavProps { errorIndices: number[]; currentIndex: number; onNavigate: (index: number) => void; } export function ErrorNav({ errorIndices, currentIndex, onNavigate, }: ErrorNavProps): React.ReactElement | null { if (errorIndices.length === 0) return null; const nextIdx = useMemo(() => findNextError(errorIndices, currentIndex), [errorIndices, currentIndex]); const prevIdx = useMemo(() => findPrevError(errorIndices, currentIndex), [errorIndices, currentIndex]); const position = useMemo(() => getErrorPosition(errorIndices, currentIndex), [errorIndices, currentIndex]); const handlePrev = useCallback(() => { if (prevIdx !== null) onNavigate(prevIdx); }, [prevIdx, onNavigate]); const handleNext = useCallback(() => { if (nextIdx !== null) onNavigate(nextIdx); }, [nextIdx, onNavigate]); return (
{position > 0 ? `Error ${position} of ${errorIndices.length}` : `${errorIndices.length} error${errorIndices.length !== 1 ? 's' : ''}`}
); }