/**
 * useCurrentFrame — Hook to read the current frame from the player context.
 *
 * Respects Sequence frame shifting: if inside a <Sequence>, returns
 * the shifted frame (relative to Sequence start).
 *
 * Drop-in replacement for `import { useCurrentFrame } from 'remotion'`.
 */
import { useContext } from 'react';
import { PlayerStateContext, SequenceFrameContext } from './PlayerContext';

export function useCurrentFrame(): number {
  const sequenceFrame = useContext(SequenceFrameContext);
  const { frame } = useContext(PlayerStateContext);

  // If inside a <Sequence>, use the shifted frame
  if (sequenceFrame !== null) {
    return sequenceFrame;
  }

  return frame;
}
