import { createPortal } from 'react-dom' import { useEffect } from 'react' interface Props { /** Tracks the user selected. */ total: number /** Unlocked tracks that already have a beatgrid. */ existing: number /** Tracks whose grid is locked — skipped whatever is chosen here. */ locked: number onChoose: (replaceExisting: boolean) => void onClose: () => void } /** Asked only when a batch analysis would meet existing grids: re-analysing a * grid someone may have hand-fixed is a decision, not a default. */ export function AnalyzeGridDialog({ total, existing, locked, onChoose, onClose }: Props) { // "Skip them" would leave nothing to do when every unlocked track has a grid. const canSkip = existing < total - locked useEffect(() => { const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose() window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }, [onClose]) return createPortal(
{existing}{' '} {existing === 1 ? 'already has a beatgrid' : 'already have a beatgrid'}. Replacing discards any hand edits to {existing === 1 ? 'it' : 'them'}.
{locked > 0 && ({locked} {locked === 1 ? 'is' : 'are'} locked and will be skipped either way.
)}