<template>
  <div class="airport-information">
    <div class="title"
      >无人机信息：<span>
        <template
          v-if="uavInformation.sub_device && uavInformation.sub_device.device_online_status == 1"
          >开机</template
        >
        <template v-else>关机</template>
      </span></div
    >
    <div class="content">
      <div class="content-title">
        {{ time }}
        <!-- <span>临近或已接近夜晚</span> -->
      </div>
      <div class="content-item">
        <div class="item-div">
          <img src="@/assets/images/flightoperation/project.png" alt="" />
          {{ uavInformation.wireless_link ? uavInformation.wireless_link.dongle_number : 0 }}
        </div>
        <a-divider type="vertical" style="border-color: #4e5778" />
        <!-- <div class="item-div">
          <img src="@/assets/images/flightoperation/arrow.png" alt="" />
          0%
        </div> -->
        <div class="item-div">
          <img src="@/assets/images/flightoperation/electricity.png" alt="" />
          {{
            uavInformation.drone_battery_maintenance_info
              ? uavInformation.drone_battery_maintenance_info.capacity_percent
              : 0
          }}
        </div>
      </div>
      <div class="content-item">
        <div class="item-div">
          <img src="@/assets/images/flightoperation/sdr.png" alt="" />
          <!-- sdr_link_state -->
          <template
            v-if="uavInformation.wireless_link && uavInformation.wireless_link.sdr_link_state == 1"
            >连接</template
          >
          <template v-else>断开</template>
        </div>
        <a-divider type="vertical" style="border-color: #4e5778" />
        <div class="item-div">
          <img src="@/assets/images/flightoperation/4g.png" alt="" />
          <template
            v-if="
              uavInformation.wireless_link && uavInformation.wireless_link['4g_link_state'] == 1
            "
            >连接</template
          >
          <template v-else>断开</template>
        </div>
      </div>
      <!-- sdr_freq_band sdr_quality 4g_freq_band 4g_quality -->
      <div class="content-item">
        <div class="item-div">
          <img src="@/assets/images/flightoperation/sdr.png" alt="" />
          {{ uavInformation.wireless_link ? uavInformation.wireless_link.sdr_quality : 0 }}
        </div>
        <a-divider type="vertical" style="border-color: #4e5778" />
        <div class="item-div">
          <img src="@/assets/images/flightoperation/4g.png" alt="" />
          {{ uavInformation.wireless_link ? uavInformation.wireless_link['4g_quality'] : 0 }}
        </div>
      </div>
      <div class="content-item">
        <div class="item-div">
          <img src="@/assets/images/flightoperation/sdr.png" alt="" />
          {{ uavInformation.wireless_link ? uavInformation.wireless_link.sdr_freq_band : 0 }}
        </div>
        <a-divider type="vertical" style="border-color: #4e5778" />
        <div class="item-div">
          <img src="@/assets/images/flightoperation/4g.png" alt="" />
          {{ uavInformation.wireless_link ? uavInformation.wireless_link['4g_freq_band'] : 0 }}
        </div>
      </div>
      <div class="content-edit">
        飞行器夜航灯
        <div>
          <a-input v-model:value="data.navigationLight" />
          <EditOutlined style="color: #0a99eb; cursor: pointer" />
        </div>
      </div>
      <div class="content-edit">
        备降转移高度
        <div>
          <a-input v-model:value="data.altitude" readonly />
        </div>
      </div>
      <div class="content-edit">
        限高
        <div>
          <a-input v-model:value="data.heightPermitted" />
          <EditOutlined style="color: #0a99eb; cursor: pointer" />
        </div>
      </div>
      <div class="content-edit">
        限远
        <div>
          <a-input v-model:value="data.limitedRange" />
          <EditOutlined style="color: #0a99eb; cursor: pointer" />
        </div>
      </div>
      <div class="content-edit">
        避障
        <div>
          <a-input v-model:value="data.obstacleAvoidance" />
          <EditOutlined style="color: #0a99eb; cursor: pointer" />
        </div>
      </div>
      <div class="content-button">
        <a-button type="primary" style="background: #3a57e8" @click="emits('changeFlightControl')"
          >飞行控制</a-button
        >
        <a-button type="primary" style="background: #0a99eb" @click="emits('changeLoadControl')"
          >云台相机控制</a-button
        >
      </div>
      <div class="content-button">
        <a-button
          type="primary"
          style="background: #3a57e8; width: 100%"
          @click="emits('loadLiveStreaming')"
          >负载直播</a-button
        >
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
  import { reactive, ref, watch } from 'vue';
  import { CopyOutlined, EditOutlined } from '@ant-design/icons-vue';
  import { timestampToFormattedDate } from '@/utils/index';
  import { buildGUID } from '@/utils/uuid';
  import { servicesTopic, services_replyTopic } from '@/utils/debugging/remote';

  // const emits = defineEmits(['loadLiveStreaming', 'changeLoadControl']);
  // 负载直播测试
  // const loadLiveStreaming = async () => {
  // const querys = {
  //   bid: buildGUID(),
  //   method: 'live_start_push',
  //   tid: buildGUID(),
  //   timestamp: new Date().getTime(),
  //   data: {
  //     url_type: 1, // 0 = 自适应；如需 RTMP 改为 1；GB28181 为 3；WebRTC 为 4
  //     url: 'rtmp://221.2.83.254:1935/live/2',
  //     //video_id = "1581F8HGX254V00A0BUY/0-100-1/normal-0",
  //     video_id: '8UUXN5400A079H/165-0-7/normal-0',
  //     video_quality: 1, // 0=自适应，1=流畅，2=标清，3=高清，4=超清
  //   },
  // };
  // servicesTopic(querys);
  // services_replyTopic();
  // };

  const emits = defineEmits(['changeLoadControl', 'changeFlightControl', 'loadLiveStreaming']);
  const props = defineProps({
    msgData: Object,
  });
  const data = reactive({
    navigationLight: '关闭',
    altitude: '70m',
    heightPermitted: '100m',
    limitedRange: '500m',
    obstacleAvoidance: '500m',
  });
  const uavInformation = ref({
    sub_device: {
      // 飞行器状态
      device_online_status: 0,
    },
    drone_battery_maintenance_info: {
      // 电池剩余电量
      capacity_percent: 0,
    },
    wireless_link: {
      // 飞行器上 Dongle 数量
      dongle_number: 0,
      sdr_quality: 0,
      '4g_quality': 0,
      '4g_uav_quality': 0,
      '4g_gnd_quality': 0,
      remain_upload: 0,
      sdr_link_state: 0,
      sdr_freq_band: 0,
    },
  });
  const time = ref(timestampToFormattedDate(new Date().getTime()));
  watch(
    () => props.msgData,
    (val) => {
      if (val.topic == 'thing/product/8UUXN5400A079H/osd') {
        if (val.message.data.sub_device) {
          uavInformation.value.sub_device = val.message.data.sub_device;
          time.value = timestampToFormattedDate(val.message.timestamp);
        }
        if (val.message.data.drone_battery_maintenance_info) {
          uavInformation.value.drone_battery_maintenance_info =
            val.message.data.drone_battery_maintenance_info;
          time.value = timestampToFormattedDate(val.message.timestamp);
        }
        if (val.message.data.wireless_link) {
          uavInformation.value.wireless_link = val.message.data.wireless_link;
          time.value = timestampToFormattedDate(val.message.timestamp);
        }
      }
    },
  );
</script>
<style lang="less" scoped>
  .airport-information {
    position: absolute;
    top: 320px;
    left: 0;
    z-index: 999;
    width: 260px;
    padding: 10px;
    background: #0d0e15;
    margin: 10px 0 0 10px;
    box-shadow:
      0px 10px 30px 0px rgba(0, 0, 6, 0.15),
      inset 0px 0px 36px 0px rgba(58, 87, 232, 0.73);
    border-radius: 6px;
    backdrop-filter: blur(3px);
    color: #fff;
    .title {
      width: 100%;
      padding: 10px 0;
      box-shadow: 0px 10px 30px 0px rgba(0, 0, 6, 0.15);
      border-bottom: 1px solid #4e5778;
      span {
        color: #3a57e8;
      }
    }
    .content-title {
      font-size: 14px;
      padding: 10px 0;
      span {
        font-size: 12px;
      }
    }
    .content-item {
      display: flex;
      align-items: center;
      border-bottom: 1px solid #4e5778;
      padding: 10px 0;
      .item-div {
        width: 49%;
        img {
          width: 20px;
        }
      }
    }
    .content-button {
      margin-top: 10px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .content-edit {
      display: flex;
      align-items: center;
      justify-content: space-between;
      border: 1px solid #4e5778;
      margin-top: 10px;
      padding: 2px 10px;
      border-radius: 4px;
      font-size: 12px;
      input {
        background: none;
        border: none;
        width: 100px;
        text-align: right;
        color: #fff;
        font-size: 12px;
      }
    }
  }
</style>
