/**
 * PlayerContext — React contexts for the Bradly Player.
 *
 * Provides frame number, video config, and play/pause state
 * to all descendant components (Sequence, Video, Audio, useCurrentFrame, etc.)
 */
import { createContext, useContext } from 'react';
import type { VideoConfig } from './types';

// ═══ Player State Context ═══

interface PlayerStateContextValue {
  frame: number;
  playing: boolean;
}

export const PlayerStateContext = createContext<PlayerStateContextValue>({
  frame: 0,
  playing: false,
});

/**
 * Hook to access the player's play/pause state.
 * Used internally by Video/Audio components to sync playback.
 */
export function usePlayerState(): PlayerStateContextValue {
  return useContext(PlayerStateContext);
}

// ═══ Video Config Context ═══

export const VideoConfigContext = createContext<VideoConfig>({
  fps: 30,
  width: 1080,
  height: 1920,
  durationInFrames: 150,
});

// ═══ Sequence Frame Context ═══

/**
 * Used by <Sequence> to provide shifted frame numbers to children.
 * When null, the parent PlayerStateContext frame is used directly.
 */
export const SequenceFrameContext = createContext<number | null>(null);
