<template>
  <div class="control-left" :class="{ collapse: listCollapse }">
    <div class="left-bar-item item" @click="onClickTask">
      <img class="left-bar-item__icon" src="./assets/images/task.svg" />
      <div class="left-bar-item__text">任务</div>
    </div>
    <TaskList class="task-list" v-if="!useAirway && openTask"></TaskList>
    <AirwayList class="task-list" v-if="useAirway && openTask"></AirwayList>
    <div class="left-bar-item item" @click="onClickAI">
      <img class="left-bar-item__icon" src="./assets/images/ai.svg" />
      <div class="left-bar-item__text">智能识别</div>
    </div>
    <div class="ai-list" :class="{ active: openAIList }">
      <div class="left-bar-item item" @click.stop="switchAI(0)">
        <img class="left-bar-item__icon" src="./assets/images/face.svg" />
        <div class="left-bar-item__text">人脸识别</div>
      </div>
      <div class="left-bar-item item" @click.stop="switchAI(1)">
        <img class="left-bar-item__icon" src="./assets/images/car.svg" />
        <div class="left-bar-item__text">车辆识别</div>
      </div>

      <!-- <div class="left-bar-item item" @click.stop="switchAI(2)">
        <img class="left-bar-item__icon" src="./assets/images/traffic.png" />
        <div class="left-bar-item__text">交通指引</div>
      </div>
      <div class="left-bar-item item" @click.stop="switchAI(3)">
        <img class="left-bar-item__icon" src="./assets/images/ksjm.png" />
        <div class="left-bar-item__text">快速建模</div>
      </div>-->
      <Face v-if="openFace" class="ai-dialog" :uavId="uav.deviceId" @close="openFace = false" />
      <Car v-if="openPlate" class="ai-dialog" :uavId="uav.deviceId" @close="openPlate = false" />
      <Traffic
        v-if="openTraffic"
        class="ai-dialog"
        :uavId="uav.deviceId"
        @close="openTraffic = false"
      />
      <Jm v-if="openModeling" :device="device" class="jm-dialog" @close="openModeling = false"></Jm>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import Car from "./components/car";
import Face from "./components/face";
import Jm from "./components/Jm";
import TaskList from "./components/taskList";
import AirwayList from "./components/airwayList";
import Traffic from "./components/traffic";

export default {
  name: "ControlLeft",
  components: {
    Car,
    Jm,
    TaskList,
    AirwayList,
    Traffic,
    Face,
  },
  data() {
    return {
      openTask: true, //打开任务
      openAIList: false, //打开AI列表
      openTraffic: false, //打开交通指引
      openFace: false, //打开人脸识别
      openPlate: false, //车牌识别
      openModeling: false, //打开建模
    };
  },
  computed: {
    ...mapState("MMCFlightControlCenter", ["useAirway"]),
    ...mapState("MMCFlightControlCenter/uav", ["uav"]),
    // 收起列表按钮
    listCollapse: {
      get() {
        return this.$store.state.MMCFlightControlCenter.listCollapse;
      },
      set(val) {
        this.$store.commit("MMCFlightControlCenter/setState", {
          key: "listCollapse",
          value: val,
        });
      },
    },
  },
  watch: {
    hangar() {
      this.openTask = false;
      this.openAIList = false;
      this.$nextTick(() => {
        this.openTask = true;
      });
    },
  },
  methods: {
    onClickTask() {
      this.openTask = !this.openTask;
      this.openAIList = false;
      this.closeAI();
    },
    onClickAI() {
      this.openTask = false;
      this.openAIList = !this.openAIList;
      this.closeAI();
    },
    /**
     * 切换AI功能
     */
    switchAI(type) {
      this.openFace = false;
      this.openPlate = false;
      this.openTraffic = false;
      this.openModeling = false;
      switch (type) {
        case 0:
          this.openFace = !this.openFace;
          break;

        case 1:
          this.openPlate = !this.openPlate;
          break;

        case 2:
          if (this.taskId == null) {
            return this.$message.error("暂无绑定任务！");
          }
          this.openTraffic = !this.openTraffic;
          break;
        case 3:
          this.openModeling = !this.openModeling;

          break;
      }
    },
    /**
     * 关闭所有ai
     */
    closeAI() {
      this.openFace = false;
      this.openPlate = false;
      this.openTraffic = false;
      this.openModeling = false;
    },
  },
};
</script>

<style scoped lang="scss">
.task-list {
  position: absolute;
  left: 60px;
  top: -30px;
  cursor: initial;
}
.control-left {
  z-index: 1;
  position: absolute;
  left: 470px;
  top: 13%;
  transition: 0.3s;

  &.collapse {
    left: 10px;
  }

  .left-bar-item {
    cursor: pointer;
    position: relative;
    width: 48px;
    height: 48px;
    background: #ffffff;
    border-radius: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-bottom: 2px;

    .left-bar-item__icon {
      width: 24px;
      height: 24px;
      margin-bottom: 2px;
    }

    .left-bar-item__text {
      font-size: 9px;
      // transform: scale(0.6);
      white-space: nowrap;
      color: #000;
    }
  }

  .ai-list {
    // width: 0;
    position: absolute;
    left: 52px;
    top: 60px;
    display: none;
    gap: 4px;

    &.active {
      display: flex;
    }

    .left-bar-item {
    }
  }
}

.ai-dialog {
  position: absolute;
  top: 56px;
  left: 0;
}
</style>