<template>
  <div class="right-menu">
    <div class="menu-container">
      <div style="position: relative; margin-top: 60px">
        <div ref="scrollListRef" :class="!menuState.showMenu ? 'menu-list' : 'menu-list menu-list-right'">
          <div
            v-for="(item, index) in menuState.menuData"
            :key="index"
            :class="menuState.activeIndex === index ? 'menu-item menu-active' : 'menu-item'"
            @click="clickMenu(index)"
          >
            <div :class="item.meta?.icon + ' ' + item.meta?.icon + '_checked'"></div>
            <div class="gradient-text text">{{ item.name }}</div>
          </div>
        </div>
        <div v-show="menuState.menuData.length > 0" :class="menuState.showMenu ? 'right-btn' : 'left-btn'" @click="clickContractMenu"></div>
        <div v-show="menuState.menuData.length > 7" class="btn-box">
          <div class="up-btn" @click="clickBtn('up')"></div>
          <div class="down-btn" @click="clickBtn('down')"></div>
        </div>
      </div>
      <div v-show="menuState.showMenu">
        <!--图层分析-->
        <LayerAnalysis v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '图层分析'" :point-type="pointType" />
        <!--空间分析-->
        <SpatialAnalysis
          v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '空间分析'"
          :update-location="location"
          @handle-menu="handleMenu"
        />
        <!--江湖河库-->
        <Reservoir v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '江湖河库'" />
        <!--路网视频-->
        <RoadNetworkVideo v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '路网视频'" />
        <!--防溺水视频-->
        <PreventDrowning v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '防溺水'" />
        <!--水库监测-->
        <ReservoirMonitor v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '水库监测'" />
        <!--河道监测-->
        <RiverMonitor v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '河道监测'" />
        <!--无人机-->
        <UAV v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '无人机'" @handle-menu="handleMenu" />
        <!--实时标绘-->
        <OnlinePlotting v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '实时标绘'" />
        <!--雨情监测-->
        <RainMonitor v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '雨情监测'" />
        <!--铁塔运行监测-->
        <TowerStatus v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '铁塔运行监测'" />
        <!--预警信号-->
        <WarningInfo v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '预警信号'" @handle-menu="handleMenu" />
        <!--森林防火-->
        <Fireproofing v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '森林防火'" @handle-menu="handleMenu" />
        <!--防灾救援-->
        <Mitigation v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '防灾救援'" @handle-menu="handleMenu" />
        <!--易涝隐患点-->
        <PotentialFloodHazard
          v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '易涝隐患点'"
          @handle-menu="handleMenu"
        />
        <!--通讯保障-->
        <CommunicationSupport v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '通讯保障'" @handle-menu="handleMenu" />
        <!--手机工作平台-->
        <MobilePlatform v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '手机工作台'" @handle-menu="handleMenu" />
        <!--重点车辆-->
        <KeyVehicles v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '重点车辆'" @handle-menu="handleMenu" />
        <!--卫星电话-->
        <SatellitePhone v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '卫星电话'" @handle-menu="handleMenu" />
        <!--机动无人机-->
        <MobileUnmannedVehicle
          v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '机动无人机'"
          @handle-menu="handleMenu"
        />
        <!--移动指挥车-->
        <MobileCommandVehicle
          v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '移动指挥车'"
          @handle-menu="handleMenu"
        />
        <!--直升机-->
        <Helicopter v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '直升机'" @handle-menu="handleMenu" />
        <!--台风视频-->
        <TyphoonVideo v-if="menuState.showMenu && menuState.menuData[menuState.activeIndex]?.name === '台风视频'" @handle-menu="handleMenu" />
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup name="rightMenu">
import RiverMonitor from './RiverMonitor.vue';
import ReservoirMonitor from './ReservoirMonitor.vue';
import RoadNetworkVideo from './RoadNetworkVideo.vue';
import Reservoir from './Reservoir.vue';
import SpatialAnalysis from './SpatialAnalysis.vue';
import LayerAnalysis from './LayerAnalysis.vue';
import OnlinePlotting from './OnlinePlotting/index.vue';
import UAV from './UAV.vue';
import WarningInfo from './WarningInfo.vue';
import { PointType } from '@/api/globalMap/type';
import RainMonitor from './RainMonitor/index.vue';
import PreventDrowning from './PreventDrowning.vue';
import Fireproofing from './Fireproofing.vue';
import Mitigation from './Mitigation.vue';
import PotentialFloodHazard from './PotentialFloodHazard.vue';
import TowerStatus from './TowerStatus.vue';
import CommunicationSupport from './CommunicationSupport.vue';
import MobilePlatform from './MobilePlatform.vue';
import KeyVehicles from './KeyVehicles.vue';
import SatellitePhone from './SatellitePhone.vue';
import MobileUnmannedVehicle from './MobileUnmannedVehicle.vue';
import MobileCommandVehicle from './MobileCommandVehicle.vue';
import Helicopter from './Helicopter.vue';
import TyphoonVideo from './TyphoonVideo.vue';
interface Props {
  pointType: PointType[];
}

withDefaults(defineProps<Props>(), {});
const emits = defineEmits(['update:drawing']);
const scrollListRef = ref();
const menuState = reactive({
  showMenu: false,
  activeIndex: 0,
  menuData: []
});

const activeName = computed(() => {
  let name = '';
  if (!!menuState.menuData && menuState.menuData.length > 0 && !!menuState.menuData[menuState.activeIndex]) {
    name = menuState.menuData[menuState.activeIndex].name;
  }
  return name;
});

// 点击收缩展开
const clickContractMenu = () => {
  menuState.showMenu = !menuState.showMenu;
};
// 菜单上下移动
const clickBtn = (direction: string) => {
  const len = menuState.menuData.length;
  if (direction === 'up' && scrollListRef.value.scrollTop - 168 >= 0) {
    scrollListRef.value.scrollTop -= 168;
  } else if (direction === 'down' && scrollListRef.value.scrollTop + 168 <= 168 * len) {
    scrollListRef.value.scrollTop += 168;
  }
};
const showIndexMenu = (name) => {
  let index = menuState.menuData.findIndex((item) => {
    return item.name === name;
  });
  if (index > -1) {
    clickMenu(index);
  }
};
// 点击菜单
const clickMenu = (index) => {
  menuState.showMenu = true;
  menuState.activeIndex = index;
};
let location = ref([]);
// 显示菜单
const handleMenu = (name, data) => {
  let index = menuState.menuData.findIndex((item) => {
    return item.name === name;
  });
  if (name === '空间分析') {
    menuState.showMenu = true;
    menuState.activeIndex = index;
    nextTick(() => {
      location.value = data;
    });
  } else if (index > -1) {
    clickMenu(index);
  }
};

// 新增菜单 type 1 新增 2 删除
const updateMenu = (type, menu) => {
  if (type === '1') {
    if (menu.name === '图层分析') {
      let index = menuState.menuData.findIndex((item) => {
        return item.name === menu.name;
      });
      if (index === -1) {
        menuState.menuData.push(menu);
      }
    } else {
      menuState.menuData.push(menu);
    }
    clickMenu(menuState.menuData.length - 1);
  } else if (type === '2') {
    let index = menuState.menuData.findIndex((item) => item.name === menu.name);
    if (index > -1) {
      menuState.menuData.splice(index, 1);
      menuState.activeIndex = 0;
    }
  }
};
const getMenuState = () => {
  return menuState;
};
defineExpose({ handleMenu, showIndexMenu, clickContractMenu, updateMenu, getMenuState });
</script>

<style lang="scss" scoped>
.right-menu {
  position: absolute;
  top: 100px;
  right: 0;
  z-index: 20;
}
.expand-btn {
  width: 70px;
  height: 240px;
  font-size: 32px;
  background: #d7d7d7;
  padding: 10px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.menu-container {
  display: flex;
  .menu-list-right {
    margin-right: -115px;
  }
  .menu-list {
    position: relative;
    max-height: 1176px;
    overflow: hidden;
    .menu-item {
      width: 470px;
      height: 168px;
      font-size: 32px;
      padding: 30px 18px 10px 40px;
      cursor: pointer;
      display: flex;
      align-items: center;
      background: url('@/assets/images/map/rightMenu/box.png') no-repeat;
      .text {
        font-size: 48px;
      }
      &:hover {
        background: url('@/assets/images/map/rightMenu/box_checked.png') no-repeat;
      }
    }
    .menu-active {
      background: url('@/assets/images/map/rightMenu/box_checked.png') no-repeat;
    }
  }
  .left-btn,
  .right-btn {
    position: absolute;
    top: 50%;
    right: -80px;
    transform: translateY(-50%);
    z-index: 2;
  }
  .right-btn {
    width: 177px;
    height: 151px;
    cursor: pointer;
    background: url('@/assets/images/map/rightMenu/right.png') no-repeat;
    cursor: pointer;
  }
  .left-btn {
    right: 20px;
    width: 125px;
    height: 151px;
    background: url('@/assets/images/map/rightMenu/left.png') no-repeat;
    cursor: pointer;
  }
  .btn-box {
    width: 100%;
    display: flex;
    margin-left: 45px;
    .up-btn {
      width: 151px;
      height: 178px;
      background: url('@/assets/images/map/rightMenu/up.png') no-repeat;
      cursor: pointer;
    }
    .down-btn {
      height: 177px;
      width: 151px;
      background: url('@/assets/images/map/rightMenu/down.png') no-repeat;
      cursor: pointer;
    }
  }
}
.icon1 {
  width: 99px;
  height: 92px;
  background: url('@/assets/images/map/rightMenu/icon2.png') no-repeat;
  cursor: pointer;
}
.icon1_checked {
  background: url('@/assets/images/map/rightMenu/icon2_checked.png') no-repeat;
}
.icon2 {
  width: 99px;
  height: 92px;
  background: url('@/assets/images/map/rightMenu/icon2.png') no-repeat;
  cursor: pointer;
}
.icon2_checked {
  background: url('@/assets/images/map/rightMenu/icon2_checked.png') no-repeat;
}
.icon3 {
  width: 92px;
  height: 92px;
  background: url('@/assets/images/map/rightMenu/icon3.png') no-repeat;
  cursor: pointer;
}
.icon3_checked {
  background: url('@/assets/images/map/rightMenu/icon3_checked.png') no-repeat;
}
.icon4 {
  width: 90px;
  height: 85px;
  background: url('@/assets/images/map/rightMenu/icon4.png') no-repeat;
  cursor: pointer;
}
.icon4_checked {
  background: url('@/assets/images/map/rightMenu/icon4_checked.png') no-repeat;
}
.icon5 {
  width: 91px;
  height: 82px;
  background: url('@/assets/images/map/rightMenu/icon5.png') no-repeat;
  cursor: pointer;
}
.icon5_checked {
  background: url('@/assets/images/map/rightMenu/icon5_checked.png') no-repeat;
}
.icon6 {
  width: 89px;
  height: 87px;
  background: url('@/assets/images/map/rightMenu/icon6.png') no-repeat;
  cursor: pointer;
}
.icon6_checked {
  background: url('@/assets/images/map/rightMenu/icon6_checked.png') no-repeat;
}
//
.icon7 {
  width: 89px;
  height: 87px;
  background: url('@/assets/images/map/rightMenu/icon7.png') no-repeat;
  cursor: pointer;
}
.icon7_checked {
  background: url('@/assets/images/map/rightMenu/icon7_checked.png') no-repeat;
}
.icon8 {
  width: 89px;
  height: 87px;
  background: url('@/assets/images/map/rightMenu/icon8.png') no-repeat;
  cursor: pointer;
}
.icon8_checked {
  background: url('@/assets/images/map/rightMenu/icon8_checked.png') no-repeat;
}
.icon9 {
  width: 89px;
  height: 87px;
  background: url('@/assets/images/map/rightMenu/icon9.png') no-repeat;
  cursor: pointer;
}
.icon9_checked {
  background: url('@/assets/images/map/rightMenu/icon9_checked.png') no-repeat;
}
.icon10 {
  width: 89px;
  height: 87px;
  background: url('@/assets/images/map/rightMenu/icon10.png') no-repeat;
  cursor: pointer;
}
.icon10_checked {
  background: url('@/assets/images/map/rightMenu/icon10_checked.png') no-repeat;
}
.icon11 {
  width: 89px;
  height: 87px;
  background: url('@/assets/images/map/rightMenu/icon11.png') no-repeat;
  cursor: pointer;
}
.icon11_checked {
  background: url('@/assets/images/map/rightMenu/icon11_checked.png') no-repeat;
}
.icon12 {
  width: 89px;
  height: 87px;
  background: url('@/assets/images/map/rightMenu/icon12.png') no-repeat;
  cursor: pointer;
}
.icon12_checked {
  background: url('@/assets/images/map/rightMenu/icon12_checked.png') no-repeat;
}
</style>
