import { create } from 'zustand';
import type { VideoSource } from '../types/player';

interface PlayerStore {
  source: VideoSource | null;
  playing: boolean;
  currentTime: number;
  duration: number;
  fps: number;
  volume: number;
  muted: boolean;
  playbackRate: number;
  hlsReady: boolean;
  setSource: (source: VideoSource | null) => void;
  setPlaying: (playing: boolean) => void;
  setCurrentTime: (t: number) => void;
  setDuration: (d: number) => void;
  setFps: (fps: number) => void;
  setVolume: (v: number) => void;
  setMuted: (m: boolean) => void;
  setPlaybackRate: (r: number) => void;
  setHlsReady: (ready: boolean) => void;
}

export const usePlayerStore = create<PlayerStore>((set) => ({
  source: null,
  playing: false,
  currentTime: 0,
  duration: 0,
  fps: 30,
  volume: 1,
  muted: false,
  playbackRate: 1,
  hlsReady: false,
  setSource: (source) => set({ source, hlsReady: false }),
  setPlaying: (playing) => set({ playing }),
  setCurrentTime: (currentTime) => set({ currentTime }),
  setDuration: (duration) => set({ duration }),
  setFps: (fps) => set({ fps }),
  setVolume: (volume) => set({ volume }),
  setMuted: (muted) => set({ muted }),
  setPlaybackRate: (playbackRate) => set({ playbackRate }),
  setHlsReady: (hlsReady) => set({ hlsReady }),
}));
