'use client';

/**
 * Dispatches `source.type` to the right canvas. Single-switch indirection
 * keeps `<VideoPlayer>` simple and isolates engine-specific imports inside
 * the canvas files so tree-shakers can drop unused providers.
 */

import type { VideoSource, VideoPlayerSettings } from '../types';
import { NativeCanvas } from './native-canvas';
import { YouTubeCanvas } from './youtube-canvas';
import { VimeoCanvas } from './vimeo-canvas';
import { HlsCanvas } from './hls-canvas';
import { IframeCanvas } from './iframe-canvas';

export interface CanvasDispatcherProps extends VideoPlayerSettings {
  readonly source: VideoSource;
}

export function CanvasDispatcher({ source, ...settings }: CanvasDispatcherProps) {
  switch (source.type) {
    case 'youtube':
      return <YouTubeCanvas source={source} {...settings} />;
    case 'vimeo':
      return <VimeoCanvas source={source} {...settings} />;
    case 'hls':
      return <HlsCanvas source={source} {...settings} />;
    case 'iframe':
      return <IframeCanvas source={source} />;
    case 'url':
    default:
      return <NativeCanvas source={source} {...settings} />;
  }
}
