<template>
  <div class="left-sidebar" :class="{ contracted: isContracted }">
    <div class="stats">
      <div class="stat-item" v-for="(item, index) in warningDay" :key="index">
        <div class="stat-name">{{ item.name }}</div>
        <div class="stat-name">{{ item.value }} 次</div>
      </div>
    </div>
    <div class="drone-list">
      <div class="title">
        <img src="@/assets/img/uavTitle.png" alt="" />
      </div>
      <ul>
        <li v-for="(drone, index) in drones" :key="index">
          <div class="top">
            <div class="left">
              {{ index < 9 ? "0" + (index + 1) : index + 1 }}
            </div>
            <div class="text">{{ drone.id }}</div>
          </div>
          <div class="main">
            <div class="top_main">
              <div class="text">时间：{{ drone.time }}</div>
              <div class="text">来源：{{ drone.source }}</div>
            </div>
            <div class="top_main">
              <div class="text">频段：{{ drone.sn }}</div>
              <div class="text">型号：{{ drone.model }}</div>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <div class="left-contract" @click="handleContractClick">
      <img :src="isContracted ? rightContract : leftContract" alt="" />
    </div>
  </div>
</template>

<script>
export default {
  name: "LeftSidebar",
  props: {
    homeData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      leftContract: require("@/assets/img/left-contract.png"),
      rightContract: require("@/assets/img/right-contract.png"),
      warningDay: [
        {
          id: "1",
          name: "今日预警",
          value: 20
        },
        {
          id: "2",
          name: "累计预警",
          value: 20
        },
        {
          id: "3",
          name: "今日处置",
          value: 0
        },
        {
          id: "4",
          name: "累计处置",
          value: 0
        }
      ],
      drones: [
        {
          id: "781DE06",
          time: "10:34:26",
          model: "大疆精灵4P",
          source: "信号源1",
          sn: "SN123456789"
        },
        {
          id: "781DE06",
          time: "10:34:26",
          model: "大疆精灵4P",
          source: "信号源1",
          sn: "SN123456789"
        },
        {
          id: "781DE06",
          time: "10:34:26",
          model: "大疆精灵4P",
          source: "信号源1",
          sn: "SN123456789"
        },
        {
          id: "781DE06",
          time: "10:34:26",
          model: "大疆精灵4P",
          source: "信号源1",
          sn: "SN123456789"
        },
        {
          id: "781DE06",
          time: "10:34:26",
          model: "大疆精灵4P",
          source: "信号源1",
          sn: "SN123456789"
        },
        {
          id: "781DE06",
          time: "10:34:26",
          model: "大疆精灵4P",
          source: "信号源1",
          sn: "SN123456789"
        },
        {
          id: "781DE06",
          time: "10:34:26",
          model: "大疆精灵4P",
          source: "信号源1",
          sn: "SN123456789"
        }
      ],
      isContracted: false,
      homeView: {}
    };
  },
  watch: {
    homeData: {
      handler(newVal) {
        this.homeView = newVal;
        this.warningDay[0].value = newVal.alarmCount.todaywaring;
        this.warningDay[1].value = newVal.alarmCount.totalcount;
        this.warningDay[2].value = newVal.alarmCount.todayhandle;
        this.warningDay[3].value = newVal.alarmCount.totalhandle;
      },
      deep: true
    }
  },
  methods: {
    handleContractClick() {
      this.isContracted = !this.isContracted; // 切换状态
    }
  }
};
</script>

<style lang="scss" scoped>
.left-sidebar {
  transition: transform 0.5s;
}

.left-sidebar.contracted {
  transform: translateX(-90%);
}
</style>
