import { ref, computed } from 'vue'
import { DISPATCH_TABS } from '../constants'

/**
 * 力量调度逻辑
 */
export function useForceDispatch() {
  // 当前激活的标签页
  const activeTab = ref('personnel')

  // 标签页列表
  const tabs = ref(DISPATCH_TABS)

  // 现场单兵数据
  const personnelList = ref([
    {
      id: 1,
      name: '张维',
      department: '安全部',
      distance: 0.6,
      status: 'active'
    },
    {
      id: 2,
      name: '王强',
      department: '安全部',
      distance: 0.42,
      status: 'active'
    },
    {
      id: 3,
      name: '刘建国',
      department: '安全部',
      distance: 0.6,
      status: 'active'
    }
  ])

  // 现场设备数据
  const equipmentList = ref([
    {
      id: 1,
      name: '挖掘机-001',
      type: '挖掘机',
      distance: 1.2,
      status: 'ready'
    },
    {
      id: 2,
      name: '挖掘机-002',
      type: '挖掘机',
      distance: 1.2,
      status: 'ready'
    },
    {
      id: 3,
      name: '运输车-002',
      type: '运输车',
      distance: 0.8,
      status: 'ready'
    }
  ])

  // 现场无人机数据
  const droneList = ref([
    {
      id: 1,
      name: '无人机-001',
      altitude: 120,
      battery: 85,
      status: 'flying'
    },
  ])

  // 切换标签页
  const changeTab = (tabKey) => {
    activeTab.value = tabKey
  }

  // 获取当前标签页数据
  const currentList = computed(() => {
    switch (activeTab.value) {
      case 'personnel':
        return personnelList.value
      case 'equipment':
        return equipmentList.value
      case 'drone':
        return droneList.value
      default:
        return []
    }
  })

  // 联动操作
  const linkToItem = (item) => {
    console.log('联动:', item)
    // 实际实现：在地图上定位该项目，打开详情弹窗等
  }

  return {
    activeTab,
    tabs,
    personnelList,
    equipmentList,
    droneList,
    currentList,
    changeTab,
    linkToItem
  }
}
