'use client';

import { useContext } from 'react';

import { MediaControlContext } from '../context/media-control.provider';

export function useMediaController() {
  const context = useContext(MediaControlContext);
  if (context === undefined) {
    throw new Error(
      'useMediaController must be used within a MediaControlProvider',
    );
  }

  if (typeof context.m !== 'function') {
    throw new Error('Media function (m) is not available');
  }

  return context;
}
