<template>
  <div class="leftMenu">
    <div class="leftMenuContent">
      <div class="leftMenuContent_2" v-if="leftMenuShow">
        <div class="leftMenuContent_title">
          {{ showMenuInfoName }}
        </div>
        <div class="leftMenuContent_list">
          <!-- 地图作业区域 -->
          <div v-if="showMenuInfoName == '地图作业区域'" style="margin: 10px 10px 20px 16px">
            <a-select
              v-model:value="areatype"
              style="width: 120px; margin-right: 15px;background: #151823;"
              @change="handleChangeAreaSelect"
            >
              <a-select-option value="all">全部类型</a-select-option>
              <a-select-option value="dfence">全部作业区</a-select-option>
              <a-select-option value="nfz">全部限飞区</a-select-option>
              <a-select-option value="noland">全部禁降区</a-select-option>
            </a-select>
            <a-select
              v-model:value="areastate"
              style="width: 120px"
              @change="handleChangeAreaSelect"
            >
              <a-select-option value="all">全部状态</a-select-option>
              <a-select-option value="0">已启用</a-select-option>
              <a-select-option value="1">已禁用</a-select-option>
            </a-select>
          </div>
          <!-- 列表 -->
          <div v-for="show in showMenuInfoList" :key="show.id">
            <!-- 地图作业区域 -->
            <div
              class="showMenuInfo_area"
              :style="{
                outline:
                  props.nowShowAreaData && props.nowShowAreaData.id == show.id
                    ? '2px solid #2D8CF0'
                    : '',
              }"
            >
              <a-tooltip placement="right">
                <template #title> {{ show.name }} </template>
                <div
                  class="name"
                  @click="setNowShowAreaData(show)"
                  :style="{
                    color: show.state == 0 ? '#ffffff' : '#ffffff55',
                  }"
                >
                  {{ show.name }}
                </div>
                <div class="line"></div>
                <div class="work">所属项目：{{show.workSpaceName}}</div>
              </a-tooltip>
              <div
                class="type"
                @click="setNowShowAreaData(show)"
                :style="{
                  color: show.state == 0 ? '#ffffff' : '#ffffff55',
                }"
              >
                <!-- 自定义禁降区 -->
                <div
                  v-if="show.type == 'noland'"
                  :style="{
                    width: '13px',
                    height: '13px',
                    outline: `2px solid #FF9900`,
                    'margin-right': '6px',
                  }"
                />
                <!-- 自定义作业区 -->
                <div
                  v-if="show.type == 'dfence'"
                  :style="{
                    width: '13px',
                    height: '13px',
                    outline: `2px solid #00FF00`,
                    'margin-right': '6px',
                    'border-radius': show.geomtype == 'Circle' ? '6.5px' : '0px',
                  }"
                />
                <!-- 自定义限飞区 -->
                <div
                  v-if="show.type == 'nfz'"
                  :style="{
                    width: '13px',
                    height: '13px',
                    outline: `2px solid #FF0000`,
                    background: `#FF000055`,
                    'margin-right': '6px',
                    'border-radius': show.geomtype == 'Circle' ? '6.5px' : '0px',
                  }"
                />
                <span>{{ getType(show.type) }}</span>
              </div>
              <div class="buttonlist">
                <div class="button" v-if="show.state == 1">
                  <a-popconfirm
                    title="将会影响到项目内设备的作业范围，是否启用该区域？"
                    ok-text="启用"
                    cancel-text="取消"
                    placement="right"
                    @confirm="enableThisArea(show)"
                  >
                    <a-tooltip placement="top">
                      <template #title>
                        <span>可点击启用该区域</span>
                      </template>
                      <CheckCircleOutlined />
                    </a-tooltip>
                  </a-popconfirm>
                </div>
                <div class="button" v-if="show.state == 0">
                  <a-popconfirm
                    title="将会影响到项目内设备的作业范围，是否禁用该区域？"
                    ok-text="禁用"
                    cancel-text="取消"
                    placement="right"
                    @confirm="disableThisArea(show)"
                  >
                    <a-tooltip placement="top">
                      <template #title>
                        <span>可点击禁用该区域</span>
                      </template>
                      <StopOutlined />
                    </a-tooltip>
                  </a-popconfirm>
                </div>
                <div class="button">
                  <a-tooltip placement="top">
                    <template #title>
                      <span>回中</span>
                    </template>
                    <AimOutlined @click="handlerLocation(show)" />
                  </a-tooltip>
                </div>
                <div class="button">
                  <a-popconfirm
                    title="将会影响到项目内设备的作业范围，是否删除该区域？"
                    ok-text="删除"
                    cancel-text="取消"
                    placement="right"
                    @confirm="deleteArea(show)"
                  >
                    <a-tooltip placement="top">
                      <template #title>
                        <span>删除</span>
                      </template>
                      <DeleteOutlined />
                    </a-tooltip>
                  </a-popconfirm>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- <div class="suojinButton" @click="changeLeftMenuShow">
      <DoubleLeftOutlined v-if="leftMenuShow" style="font-size: 16px" />
      <DoubleRightOutlined v-if="!leftMenuShow" style="font-size: 16px" />
    </div> -->
  </div>
</template>
<script lang="ts" setup>
  import { ref, watch, onMounted } from 'vue';
  import {
    CloseOutlined,
    AntDesignOutlined,
    DoubleLeftOutlined,
    DoubleRightOutlined,
    EnvironmentOutlined,
    CodeSandboxOutlined,
    ExpandAltOutlined,
    BorderOutlined,
    LogoutOutlined,
    EyeOutlined,
    EyeInvisibleOutlined,
    AimOutlined,
    DeleteOutlined,
    FileImageOutlined,
    CheckCircleOutlined,
    StopOutlined,
  } from '@ant-design/icons-vue';
  import { UpdateWorkArea, UpdateAnnotation } from '@/api/demo/mediaLibrary';
  import { cloneDeep } from 'lodash-es';
  import { useMessage } from '@/hooks/web/useMessage';
  const { createMessage, createConfirm } = useMessage();

  const props = defineProps([
    'leftMenuShow',
    'allWorkspaceDataList',
    'allAreaDataList',
    'nowShowAreaData',
  ]);
  const emits = defineEmits([
    'changeLeftMenuShow',
    'handlerLocation',
    'setNowShowAreaData',
    'setAllAreaData',
    'deleteArea',
  ]);
  const showMenuInfoList = ref(props.allAreaDataList);
  const showMenuInfoName = ref('地图作业区域');
  onMounted(() => {
      // 查询地图工作区域
      setTimeout(() =>{
        handleChangeAreaSelect();
      },1000) 
  });
  function updateShowMenuInfoList(type) {
    handleChangeAreaSelect();
  }

  // 目录-隐藏或者显示
  function changeLeftMenuShow() {
    emits('changeLeftMenuShow');
  }
  // 地图作业区域-------------------------------------------------
  // 地图作业区域-单选
  const areatype = ref('all');
  const areastate = ref('all');
  // 地图作业区域-获取类别区分
  function getType(type) {
    let name = '';
    switch (type) {
      case 'nfz':
        name = '自定义限飞区';
        break;
      case 'dfence':
        name = '自定义作业区';
        break;
      case 'noland':
        name = '自定义禁降区';
        break;
    }
    return name;
  }
  // 地图作业区域-下拉框
  const filterAfterAreaDataList = ref(props.allAreaDataList);
  function handleChangeAreaSelect() {
    let filterAreaData = props.allAreaDataList;
    if (areatype.value !== 'all') {
      filterAreaData = filterAreaData.filter((item) => item.type == areatype.value);
    }
    if (areastate.value !== 'all') {
      filterAreaData = filterAreaData.filter((item) => item.state == areastate.value);
    }
    filterAreaData.forEach((annotation) => {
      props.allWorkspaceDataList.forEach((tree) => {
        if (tree.Id == annotation.workSpaceId) {
          annotation.workSpaceName = tree.WorkspaceName
        }
      });
    });
    filterAfterAreaDataList.value = filterAreaData;
    showMenuInfoList.value = filterAfterAreaDataList.value;
  }

  // 地图作业区域-启用该区域
  function enableThisArea(value) {
    setNowShowAreaData({
      ...value,
      state: 0,
    });
    UpdateWorkArea({
      ...value,
      properties: JSON.stringify(value.properties),
      state: 0,
    }).then((res) => {
      emits('setAllAreaData');
    });
  }
  // 地图作业区域-禁用该区域
  function disableThisArea(value) {
    setNowShowAreaData({
      ...value,
      state: 1,
    });
    UpdateWorkArea({
      ...value,
      properties: JSON.stringify(value.properties),
      state: 1,
    }).then((res) => {
      emits('setAllAreaData');
    });
  }
  // 地图作业区域-删除此区域
  function deleteArea(show) {
    emits('deleteArea', show);
  }

  // 设定当前区域
  function setNowShowAreaData(value) {
    emits('setNowShowAreaData', value);
  }

  // ------------------------------------------------------------------
  // 移动到中心位置
  function handlerLocation(position) {
    if (showMenuInfoName.value == '地图作业区域') {
      if (position.geomtype == 'Circle') {
        emits('handlerLocation', {
          lng: position.properties.centerPoint[0],
          lat: position.properties.centerPoint[1],
        });
      } else {
        emits('handlerLocation', {
          lng: position.properties.centerPoint[0],
          lat: position.properties.centerPoint[1],
        });
      }
    }
  }

  defineExpose({
    updateShowMenuInfoList,
  });
</script>
<style lang="less" scoped>
  .leftMenu {
    width:100%;
    height:100%;
    background: #0D0E15;
    box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15), 0px 10px 30px 1px rgba(0,0,6,0.15), inset 0px 0px 20px 8px rgba(58,87,232,0.73);
    border-radius: 6px;
    position:relative;

    .leftMenuTitle {
      position: relative;
      width: 100%;
      height: 50px;
      padding: 10px;
      border-bottom: 1px solid #ffffff55;
      .title {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        font-size: 20px;
        color: #ffffff;
        width: 100%;

        /* 关键属性 */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }

    .leftMenuContent {
      position: relative;
      display: flex;
      width: 100%;
      height: calc(100%-50px);
      // height: 800px;

      .leftMenuContent_1 {
        position: relative;
        width: 64px;
        height: 100%;
        border-right: 1px solid #ffffff55;
        // padding-top: 10px;
        // padding-bottom: 10px;

        .leftMenu_closeButton {
          position: relative;
          padding-top: 7px;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 10px;
        }

        .leftMenu_buttonList {
          position: relative;
          width: 50px;
          height: 100%;
          border-radius: 10px;
          background: #1a375a;
          margin-top: 15px;
          margin-left: 7px;
          margin-right: 7px;
          padding-top: 5px;
          padding-bottom: 5px;
          gap: 10px;

          .leftMenu_buttonList_annotation {
            position: relative;
            border-radius: 5px;
            height: 40px;
            width: 40px;
            margin: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
          }
          .leftMenu_buttonList_image {
            position: relative;
            border-radius: 5px;
            height: 40px;
            width: 40px;
            margin: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
          }
          .leftMenu_buttonList_area {
            position: relative;
            border-radius: 5px;
            height: 40px;
            width: 40px;
            margin: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
          }
        }
      }

      .leftMenuContent_2 {
        position: relative;
        width: 100%;
        height: 100%;

        .leftMenuContent_title {
          font-size: 16px;
          padding:15px 15px;
          color:#fff;
          border-bottom:1px solid rgba(255,255,255,0.15);
        }

        .leftMenuContent_list {
          overflow-y: auto;
          max-height: 720px;

          // 地图标注
          .showMenuInfo_annotation {
            position: relative;
            display: flex;
            align-items: center;
            justify-content: flex-start;
            color: #ffffff;
            height: 30px;
            padding-left: 15px;
            gap: 10px;

            .eye {
              display: flex;
              align-items: center;
              justify-content: center;
              width: 20px;
              height: 20px;
            }
            .buttonRight2 {
              position: absolute;
              right: 30px;
              width: 20px;
              height: 20px;
              display: flex;
              align-items: center;
              justify-content: center;
            }
            .buttonRight1 {
              position: absolute;
              right: 5px;
              width: 20px;
              height: 20px;
              display: flex;
              align-items: center;
              justify-content: center;
            }
          }
          // 地图照片
          .showMenuInfo_image {
            display: flex;
            align-items: center;
            justify-content: flex-start;
            color: #ffffff;
            height: 30px;
            padding-left: 15px;
            gap: 10px;

            .eye {
              display: flex;
              align-items: center;
              justify-content: center;
              width: 20px;
              height: 20px;
            }
            .buttonRight2 {
              position: absolute;
              right: 35px;
            }
            .buttonRight1 {
              position: absolute;
              right: 10px;
            }
          }
          // 地图作业区域
          .showMenuInfo_area {
            position: relative;
            display: flex;
            align-items: center;
            justify-content: flex-start;
            height: 100px;
            margin: 10px 15px;
            background: #313C62;
            box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
            border-radius: 6px; 
            .name {
              position: absolute;
              top: 2px;
              left: 16px;
              color: #ffffff;
              font-size: 14px;
              width: 90%;
              height: 34px;
              line-height: 34px;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
            }
            .work{
              position: absolute;
              top: 33px;
              left: 16px;
              color: #ffffff;
              font-size: 13px;
            }
            .line{
              width: 310px;
              height: 1px;
              box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
              border: 1px solid;
              opacity: 0.2;
              border-image: linear-gradient(270deg, rgba(96, 107, 146, 0), rgba(154, 164, 196, 1)) 1 1;
              margin-top: 12px;
            }
            .type {
              position: absolute;
              display: inline-flex;
              align-items: center;
              justify-content: flex-start;
              bottom: 13px;
              left: 16px;
              color: #ffffff;
              font-size: 12px;
              width: 165px;
            }
            .buttonlist {
              position: absolute;
              bottom: 6px;
              right: 6px;
              width: 75px;
              height: 25px;
              display: flex;
              gap: 1px;

              .button {
                display: flex;
                align-items: center;
                justify-content: center;
                color: #ffffff;
                font-size: 16px;
                width: 25px;
                height: 25px;
              }
            }
          }
        }
      }
    }
  }

  .suojinButton {
    position: absolute;
    top: 45%;
    right: -18px;
    height: 90px;
    width: 18px;
    background: #ffffff;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
  }
</style>
