<template>
  <a-menu v-model:selectedKeys="state.selectedKeys" mode="horizontal">
    <a-menu-item :key="1">
      任务列表
    </a-menu-item>
    <a-menu-item :key="2">
      航线管理
    </a-menu-item>
  </a-menu>
  <template v-if="state.selectedKeys[0] === 1">
    <TaskList />
  </template>
  <template v-else-if="state.selectedKeys[0] === 2">
    <WaylineList />
  </template>
</template>

<script lang="ts" setup>
import { reactive } from 'vue';
import TaskList from './taskList/index.vue'
import WaylineList from './waylineList/index.vue'
import { useConnectWebSocket } from '/@/hooks/use-connect-websocket';
import { useMyStore } from '/@/store'
import { EBizCode } from '/@/types'

const state = reactive({
  selectedKeys: [1],
})

const store = useMyStore();

const messageHandler = async (payload: any) => {
  if (!payload) {
    return
  }
  switch (payload.biz_code) {
    case EBizCode.FlightTaskProgress: {// 机场任务
      store.commit('SET_DOCK_TASK', payload.data)
      break
    }
    case EBizCode.GatewayOsd: {
      store.commit('SET_GATEWAY_INFO', payload.data)
      break
    }
    case EBizCode.DeviceOsd: {
      store.commit('SET_DEVICE_INFO', payload.data)
      break
    }
    case EBizCode.DockOsd: {
      store.commit('SET_DOCK_INFO', payload.data)
      break
    }
    case EBizCode.DeviceOnline: {
      store.commit('SET_DEVICE_ONLINE', payload.data)
      break
    }
    case EBizCode.DeviceOffline: {
      store.commit('SET_DEVICE_OFFLINE', payload.data)
      break
    }
    case EBizCode.DeviceHms: {
      store.commit('SET_DEVICE_HMS_INFO', payload.data)
      break
    }
    default:
      break
  }
}

// 监听ws 消息
useConnectWebSocket(messageHandler)
</script>

<style lang="scss" scoped></style>