import type { ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; import { retryBlockingMigration } from '../hooks/useMigrationOrchestrator'; import { useMigrationStore } from '../store/migrationStore'; function MigrationModal() { const { t } = useTranslation(); const phase = useMigrationStore(s => s.phase); const step = useMigrationStore(s => s.step); const progress = useMigrationStore(s => s.progress); const genreTagsProgress = useMigrationStore(s => s.genreTagsProgress); const inspect = useMigrationStore(s => s.inspect); const error = useMigrationStore(s => s.lastError); const isGenreTags = step === 'genreTags'; const migratedRows = (inspect?.library.totalLegacyRows ?? 0) + (inspect?.analysis.totalLegacyRows ?? 0); return (
{phase === 'inspecting' && ( <>

{isGenreTags ? t('migration.genreTagsTitle') : t('migration.preparing')}

{isGenreTags ? t('migration.genreTagsBody') : t('migration.preparingBody')}

)} {phase === 'running' && ( <>

{isGenreTags ? t('migration.genreTagsTitle') : t('migration.migrating')}

{isGenreTags ? t('migration.genreTagsBody') : (progress ? `${progress.stage} - ${progress.table}` : t('migration.working'))}

{isGenreTags ? (genreTagsProgress ? `${genreTagsProgress.done} / ${genreTagsProgress.total}` : t('migration.working')) : (progress ? `${progress.done} / ${progress.total}` : t('migration.working'))}

{!isGenreTags && inspect?.hasSkippedUnknownServerRows ? (

{t('migration.skippedRows')}

) : null} )} {phase === 'error' && ( <>

{isGenreTags ? t('migration.genreTagsFailed') : t('migration.failed')}

{String(error ?? '').slice(0, 200)}

)} {phase === 'completed' && ( <>

{t('migration.complete')}

{t('migration.completeRows', { count: migratedRows })}

)}
); } export default function BlockingMigrationGate({ children }: { children: ReactNode }) { const phase = useMigrationStore(s => s.phase); const isBlocking = phase === 'inspecting' || phase === 'running' || phase === 'error'; return ( <> {children} {isBlocking ? : null} ); }