import type { ProgressEvent } from '@ffmpeg/ffmpeg';

export function normalizeProgress(event: ProgressEvent): ProgressEvent {
  const finiteProgress = Number.isFinite(event.progress) ? event.progress : 0;
  const finiteTime = Number.isFinite(event.time) ? event.time : 0;
  return {
    progress: Math.min(1, Math.max(0, finiteProgress)),
    time: Math.max(0, finiteTime),
  };
}

export function progressPercent(event: ProgressEvent): number {
  return Math.round(normalizeProgress(event).progress * 100);
}
