/**
 * useSceneProgress Hook
 *
 * Returns 0-1 progress within a scene based on current frame.
 */

import { useCurrentFrame, useVideoConfig } from 'remotion';
import { msToFrames } from '../lib/timing';
import type { Scene } from '../types/video-script';

/**
 * Get progress (0-1) within a scene.
 */
export function useSceneProgress(scene: Scene): number {
  const frame = useCurrentFrame();
  const { fps } = useVideoConfig();

  const startFrame = msToFrames(scene.startMs, fps);
  const durationFrames = msToFrames(scene.durationMs, fps);

  if (durationFrames === 0) return 0;

  const relativeFrame = frame - startFrame;
  const progress = relativeFrame / durationFrames;

  return Math.max(0, Math.min(1, progress));
}
