import { ref } from 'vue'
import { VIDEO_MONITORS } from '../constants'

/**
 * 视频监控状态管理
 */
export function useVideoMonitor() {
  // 视频监控列表
  const monitors = ref(VIDEO_MONITORS)

  // 当前选中的视频
  const activeMonitor = ref(null)

  // 全屏显示的监控（弹窗）
  const zoomedMonitor = ref(null)

  // 视频控制状态
  const controlState = ref({
    volume: 50,
    isRecording: false,
    isMegaphoneActive: false
  })

  // 选择视频
  const selectMonitor = (monitorId) => {
    const monitor = monitors.value.find((m) => m.id === monitorId)
    if (monitor) {
      activeMonitor.value = monitor
    }
  }

  // 切换喊话
  const toggleMegaphone = (monitorId) => {
    console.log(`Toggle megaphone for monitor: ${monitorId}`)
    controlState.value.isMegaphoneActive = !controlState.value.isMegaphoneActive
    // 未来接入真实喊话系统
  }

  // 切换录制
  const toggleRecording = () => {
    controlState.value.isRecording = !controlState.value.isRecording
  }

  // 调整音量
  const setVolume = (volume) => {
    controlState.value.volume = Math.max(0, Math.min(100, volume))
  }

  // 窗口放大 - 打开全屏弹窗
  const zoomMonitor = (monitorId) => {
    const monitor = monitors.value.find((m) => m.id === monitorId)
    if (monitor) {
      zoomedMonitor.value = monitor
    }
  }

  // 关闭全屏弹窗
  const closeZoom = () => {
    zoomedMonitor.value = null
  }

  // 切换音频
  const toggleAudio = (monitorId) => {
    console.log(`Toggle audio for monitor: ${monitorId}`)
    // 未来接入真实音频控制
  }

  // 视角移动（用于无人机等设备的方向控制）
  const moveView = (monitorId, direction) => {
    console.log(`Move view for monitor ${monitorId} to ${direction}`)
    // 未来接入 3D 引擎的视角控制 API
  }

  return {
    monitors,
    activeMonitor,
    zoomedMonitor,
    controlState,
    selectMonitor,
    toggleMegaphone,
    toggleRecording,
    setVolume,
    zoomMonitor,
    closeZoom,
    toggleAudio,
    moveView
  }
}
