<template>
  <div v-if="isShowMenu == -1" class="bottom-side" :class="{ 'bottom-size-show': isShowMenu }">
    <FourBorderBg class="four-border-bg" v-for="(menu, index) in menuModules" :key="index">
      <div class="vent-flex-row">
        <div class="parent-menu">
          {{ menu.name }}
        </div>
        <div class="vent-flex-row-wrap child-menu">
          <div class="child-menu-item" v-for="(childMenu, childIndex) in menu.children" :key="childIndex"
            @click="handleMenuClick(childMenu)">
            {{ childMenu.name }}
          </div>
        </div>
      </div>
    </FourBorderBg>
    <div class="vent-flex-row-between menu-button-group">
      <div class="vent-flex-row program-group">
        <div v-for="(programMenu, index) in programMenus" class="program-menu" :key="index">{{ programMenu.title }}
        </div>
      </div>
      <div class="setting-group">
        <SvgIcon class="icon-style" size="18" name="home" />
        <SvgIcon class="icon-style" size="18" name="fixed" />
        <SvgIcon class="icon-style" size="18" name="enter" />
        <SvgIcon class="icon-style" size="18" name="setting" />
        <SvgIcon class="icon-style" size="18" name="hidden" />
      </div>
    </div>
  </div>
  <div v-else-if="isShowMenu == 0" class="menu-show-icon">
    <div class="icon" :class="themeIcon == 'styleTwo' ? 'icon-2' : 'icon-1'" @click="openMenu"></div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
import type { Menu } from '/@/router/types';
import FourBorderBg from '/@/components/vent/fourBorderBg.vue';
import { Icon as SvgIcon } from '/@/components/Icon';
import { getMenus } from '/@/router/menus';
import { useGo } from '/@/hooks/web/usePage';
import { useAppStore } from '/@/store/modules/app';

export default defineComponent({
  name: 'BottomSider',
  components: { FourBorderBg, SvgIcon },
  setup() {
    // const appStore = useAppStore();
    // const themeIcon = appStore.getDarkMode
    const themeIcon=ref('styleTwo')
    const isShowMenu = ref(0);
    let menuModules = ref<Menu[]>([]);
    const go = useGo();
    const programMenus = [
      {
        title: '通风系统',
        path: '',
      },
      {
        title: '防尘系统',
        path: '',
      },
      {
        title: '防灭火系统',
        path: '',
      },
    ];

    function handleMenuClick(path: Menu) {
      go(path.path);
      isShowMenu.value = 0;
    }
    const closeMenu = () => {
      isShowMenu.value = 0;
      window.removeEventListener('click', closeMenu);
    };

    function openMenu() {
      isShowMenu.value = -1;
      window.addEventListener('click', closeMenu, true);
    }

    onMounted(async () => {
      menuModules.value = await getMenus();
    });
    return {
      themeIcon,
      menuModules,
      isShowMenu,
      handleMenuClick,
      openMenu,
      programMenus,
    };
  },
});
</script>

<style lang="less" scoped>
@keyframes menuShow {
  0% {
    width: 0;
    height: 0;
  }

  100% {
    width: 480px;
    height: 436px;
  }
}

.bottom-side {
  width: 480px;
  height: 436px;
  position: fixed;
  bottom: 2px;
  left: 0px;
  z-index: 99999;
  color: #fff;
  border: 1px solid #0099e6;
  background-color: #06115a;
  backdrop-filter: blur(8px);

  .four-border-bg {
    margin: 5px;
    background-color: #ffffff00;

    .main-container {
      background-color: #ffffff00 !important;
      box-shadow: 0 0 3px #ffffff33 inset;
    }

    .parent-menu {
      width: 100px;
    }

    .child-menu {
      width: 340px;
      font-size: 13px;
    }

    .child-menu-item {
      width: 100px;
      background-color: #0c3898;
      border-radius: 2px;
      text-align: center;
      margin: 5px;
      cursor: pointer;
      box-shadow: 0 0 3px #ffffff22 inset;

      &:hover {
        background-color: #0069ed;
      }
    }
  }

  .menu-button-group {
    margin-bottom: 5px;

    .program-menu {
      width: 90px;
      background: linear-gradient(#214ea5, #0f3075);
      margin-left: 5px;
      text-align: center;
      border-radius: 2px;
      cursor: pointer;
    }

    .icon-style {
      margin-right: 10px;

      &:last-child {
        margin-right: 5px;
      }
    }
  }
}

.bottom-size-show {
  animation: menuShow 0.4s;
  animation-iteration-count: 1;
  animation-fill-mode: forwards;
  animation-timing-function: ease-in;
  /* Safari and Chrome */
  -webkit-animation: menuShow 0.4s;
  -webkit-animation-iteration-count: 1;
  -webkit-animation-fill-mode: forwards;
  -webkit-animation-timing-function: ease-in;
}

.menu-show-icon {
  position: fixed;
  bottom: 5px;
  left: 5px;
  z-index: 1000000;

  .icon {
    width: 60px;
    height: 60px;
    position: relative;


    &:before {
      content: '';
      display: block;
      width: 60px;
      height: 60px;
      position: absolute;
      background: url('/@/assets/images/vent/bottom-icon/menu-icon-inner.png') no-repeat;
      background-position: center;
    }

    &:after {
      content: '';
      display: block;
      width: 60px;
      height: 60px;
      position: absolute;
      animation-timing-function: ease-in;
      animation: fadenum 8s infinite;
    }

    @keyframes fadenum {
      0% {
        transform: rotate(0deg);
      }

      10% {
        transform: rotate(360deg);
      }

      100% {
        transform: rotate(360deg);
      }
    }
  }

  .icon-1 {
    background-image: url('/@/assets/images/vent/bottom-icon/menu-icon-outer.png');
    background-position: center;

    &:after {
      background: url('/@/assets/images/vent/bottom-icon/menu-icon-center.png') no-repeat;
      background-position: center;
    }
  }

  .icon-2 {
    background-image: url('/@/assets/images/vent/bottom-icon/1.png');
    background-position: center;

    &:after {
      background: url('/@/assets/images/vent/bottom-icon/2.png') no-repeat;
      background-position: center;
    }
  }
}
</style>
