/**
 * useSceneFrame Hook
 *
 * Returns the frame number relative to the start of a scene.
 */

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

/**
 * Get frame number relative to scene start.
 */
export function useSceneFrame(scene: Scene): number {
  const frame = useCurrentFrame();
  const { fps } = useVideoConfig();

  const startFrame = msToFrames(scene.startMs, fps);
  return frame - startFrame;
}
