<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div class="New-nav">
    <div class="main-title">{{ Title }}</div>
    <!-- menu区域 -->
    <div class="nav-menu">
      <div class="nav-menu-left">
        <div v-for="(item, index) in leftMenus" :key="index">
          <div :class="activeIndex == index ? 'nav-menu-active' : 'nav-menu-unactive'" :key="index" @click="menuClick({ item, index })">
            <div style="color: #ddd">{{ item.name }}</div>

            <div v-if="activeIndex == index && isShowMenuItem" class="nav-menu-item">
              <div class="nav-menu-content">
                <div class="nav-menu-List">
                  <div
                    :class="menuItemActive == ind ? 'menu-item-active' : 'menu-item-unactive'"
                    v-for="(ite, ind) in item.MenuItemList"
                    :key="ind"
                    @click.stop="menuItemClick(ind)"
                    >{{ ite.name }}</div
                  >
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="nav-menu-right">
        <div v-for="(item, index) in rightMenus" :key="index + 4">
          <div :class="activeIndex == index + 4 ? 'nav-menu-active' : 'nav-menu-unactive'" :key="index + 4" @click="menuClick(index + 4)">
            <div style="color: #ddd">{{ item.name }}</div>
            <div v-if="activeIndex == index + 4 && isShowMenuItem" class="nav-menu-item">
              <div class="nav-menu-content">
                <div class="nav-menu-List">
                  <div
                    :class="menuItemActive == ind ? 'menu-item-active' : 'menu-item-unactive'"
                    v-for="(ite, ind) in item.MenuItemList"
                    :key="ind"
                    @click.stop="menuItemClick(ind)"
                    >{{ ite.name }}</div
                  >
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- <div class="userInfo">
      <div class="userName">admin</div>
    </div> -->
  </div>
</template>
<script lang="ts" setup>
import { onMounted, onUnmounted, ref, watch, computed } from 'vue';
import { useRouter } from 'vue-router';
let props = defineProps({
  Title: {
    type: String,
    default: '',
  },
});

let menuList = ref<any[]>([
  {
    name: '智能通风',
    MenuItemList: [{ name: '多灾融合预警' }, { name: '通风监测预警' }, { name: '火灾监测预警' }, { name: '粉尘监测预警' }, { name: '瓦斯监测预警' }],
  },
  {
    name: '火灾监控',
    // MenuItemList: [{ name: '多灾融合预警' }, { name: '通风监测预警' }, { name: '火灾监测预警' }, { name: '粉尘监测预警' }, { name: '瓦斯监测预警' }],
    targatUrl: '/configurable/fireNew/home',
  },
  {
    name: '粉尘监控',
    // MenuItemList: [{ name: '多灾融合预警' }, { name: '通风监测预警' }, { name: '火灾监测预警' }, { name: '粉尘监测预警' }, { name: '瓦斯监测预警' }],
    targatUrl: '/configurable/dustNew/home',
  },
  {
    name: '瓦斯监控',
    MenuItemList: [{ name: '多灾融合预警' }, { name: '通风监测预警' }, { name: '火灾监测预警' }, { name: '粉尘监测预警' }, { name: '瓦斯监测预警' }],
  },
  {
    name: '灾害预警',
    MenuItemList: [{ name: '多灾融合预警' }, { name: '通风监测预警' }, { name: '火灾监测预警' }, { name: '粉尘监测预警' }, { name: '瓦斯监测预警' }],
  },
]); //一级菜单列表
let activeIndex = ref(0); //当前激活menu索引
let activeIndexL = ref(0); //当前激活menu索引
let activeIndexR = ref(null); //当前激活menu索引
const router = useRouter();
let isShowMenuItem = ref(false); //是否显示menuItem下拉选项菜单
let isShowMenuItemL = ref(false); //是否显示menuItem下拉选项菜单
let isShowMenuItemR = ref(false); //是否显示menuItem下拉选项菜单
let menuItemActive = ref(0); //menuItem当前激活选项
const leftMenus = computed(() => menuList.value.slice(0, 4));
const rightMenus = computed(() => menuList.value.slice(4));
//menu选项切换
function menuLeftClick(index) {
  activeIndexL.value = index;
  isShowMenuItemL.value = !isShowMenuItemL.value;
}
//menuItem选项切换
function menuItemLeftClick(index) {
  menuItemActive.value = index;
  isShowMenuItemL.value = false;
}
function menuRightClick(index) {
  activeIndexR.value = index;
  isShowMenuItemR.value = !isShowMenuItemR.value;
}
function menuItemRightClick(index) {
  menuItemActive.value = index;
  isShowMenuItemL.value = false;
}
function menuClick(data) {
  activeIndex.value = data.index;
  isShowMenuItem.value = !isShowMenuItem.value;
  router.push({ path: data.item.targatUrl });
}
function menuItemClick(index) {
  menuItemActive.value = index;
  isShowMenuItem.value = false;
}
</script>
<style lang="less" scoped>
@import '/@/design/theme.less';

@font-face {
  font-family: 'douyuFont';
  src: url('/@/assets/font/douyuFont.otf');
}

.New-nav {
  position: relative;
  width: 100%;
  height: 100%;

  .main-title {
    width: 518px;
    height: 100%;
    display: flex;
    align-items: center;
    font-family: 'douyuFont';
    font-size: 25px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    padding: 0;
  }

  .nav-menu {
    position: absolute;
    top: 0;
    left: 675px;
    height: 100%;
    display: flex;
    position: static; // 移除绝对定位
    display: flex;
    width: auto;
    .nav-menu-left {
      display: flex;
      flex-direction: row;
      align-items: center;
      float: left;
    }
    .nav-menu-right {
      display: flex;
      flex-direction: row;
      align-items: center;
      float: left;
      margin-left: 40%;
    }
    .nav-menu-active {
      position: relative;
      cursor: pointer;
      width: 120px;
      height: 60px;
      margin-top: 20px;
      line-height: 45px;
      text-align: center;
      font-size: 16px;
      letter-spacing: 2px;
      background: url('@/assets/images/vent/homeNew/Select-btn.png') no-repeat;
      background-size: 100% 100%;
    }

    .nav-menu-unactive {
      position: relative;
      width: 120px;
      height: 60px;
      line-height: 65px;
      text-align: center;
      margin: 0px 10px;
      font-size: 16px;
      letter-spacing: 2px;
      background-size: 100% 100%;
      cursor: pointer;
    }

    .nav-menu-item {
      position: absolute;
      top: 23px;
      width: 130px;
      display: flex;
      flex-direction: column;
      align-items: center;
      box-sizing: border-box;

      .nav-menu-content {
        width: 100%;
        height: 100%;
        overflow-y: auto;
        margin-top: 25%;
        .nav-menu-List {
          background: url('@/assets/images/vent/homeNew/menuList.png') no-repeat;
          background-size: 100% 100%;
        }
        .menu-item-active {
          color: #ddd;
          z-index: 999;
          width: 100%;
          height: 36px;
          line-height: 36px;
          font-size: 14px;
          background: url('@/assets/images/vent/homeNew/selectActive.png') no-repeat;
          background-size: 100% 100%;
        }

        .menu-item-unactive {
          color: #ddd;
          width: 100%;
          height: 40px;
          line-height: 40px;
          font-size: 14px;
        }
      }
    }

    @keyframes fadeIn {
      from {
        opacity: 0;
      }

      to {
        opacity: 1;
      }
    }

    /* 定义淡出动画 */
    @keyframes fadeOut {
      from {
        opacity: 1;
      }

      to {
        opacity: 0;
      }
    }
  }

  .userInfo {
    width: 120px;
    float: right;
    background: url(/src/assets/images/vent/homeNew/user.png) no-repeat;
    background-size: 100% 100%;
    position: absolute;
    top: 14px;
    right: 0;
    .userName {
      margin-left: 40px;
      font-size: 20px;
    }
  }
}
</style>
