// YouTube IFrame API type definitions
declare global {
  interface Window {
    YT: {
      Player: new (
        element: HTMLElement | string,
        options: YTPlayerOptions
      ) => YTPlayer;
      PlayerState: {
        PLAYING: number;
        PAUSED: number;
        ENDED: number;
        BUFFERING: number;
        CUED: number;
      };
    };
    onYouTubeIframeAPIReady?: () => void;
  }
}

export interface YTPlayerOptions {
  height?: string | number;
  width?: string | number;
  videoId?: string;
  playerVars?: {
    autoplay?: 0 | 1;
    controls?: 0 | 1;
    modestbranding?: 0 | 1;
    rel?: 0 | 1;
    fs?: 0 | 1;
    playsinline?: 0 | 1;
  };
  events?: {
    onReady?: (event: YTPlayerEvent) => void;
    onStateChange?: (event: YTStateChangeEvent) => void;
    onError?: (event: YTErrorEvent) => void;
  };
}

export interface YTPlayer {
  playVideo(): void;
  pauseVideo(): void;
  stopVideo(): void;
  loadVideoById(videoId: string, startSeconds?: number): void;
  cueVideoById(videoId: string, startSeconds?: number): void;
  setVolume(volume: number): void;
  getVolume(): number;
  mute(): void;
  unMute(): void;
  isMuted(): boolean;
  getCurrentTime(): number;
  getDuration(): number;
  getPlayerState(): number;
  destroy(): void;
}

export interface YTPlayerEvent {
  target: YTPlayer;
}

export interface YTStateChangeEvent {
  target: YTPlayer;
  data: number;
}

export interface YTErrorEvent {
  target: YTPlayer;
  data: number;
}

// SoundCloud Widget API type definitions
export interface SCWidgetOptions {
  auto_play?: boolean;
  buying?: boolean;
  sharing?: boolean;
  download?: boolean;
  show_artwork?: boolean;
  show_playcount?: boolean;
  show_user?: boolean;
  callback?: () => void;
}

export interface SCWidget {
  load(url: string, options?: SCWidgetOptions): void;
  play(): void;
  pause(): void;
  toggle(): void;
  setVolume(volume: number): void;
  getVolume(callback: (volume: number) => void): void;
  bind(event: string, callback: () => void): void;
  unbind(event: string): void;
  getCurrentSound(callback: (sound: object) => void): void;
  getPosition(callback: (position: number) => void): void;
  seekTo(milliseconds: number): void;
}

export interface SCWidgetConstructor {
  (iframe: HTMLIFrameElement | string): SCWidget;
  Events: {
    PLAY: string;
    PAUSE: string;
    FINISH: string;
    READY: string;
    PLAY_PROGRESS: string;
    LOAD_PROGRESS: string;
    SEEK: string;
    ERROR: string;
  };
}

declare global {
  interface Window {
    SC?: {
      Widget: SCWidgetConstructor;
    };
  }
}

export {};
