<template>
  <div class="menu relative">
    <div class="appLine">
      <img
        :src="logo"
        alt=""
        :style="{
          width: iconWidth,
        }"
        class="mx-auto"
      />
    </div>
    <div
      v-for="(menu, index) in menuList"
      :key="index"
      style="width: 100%; display: flex; justify-content: center"
    >
      <MenuItem
        v-if="menu.type === 'menuItem'"
        :name="menu.name!"
        @click="handleClickMenu(menu)"
        :active="isMenuActive(menu)"
      >
        <template #icon>
          <Icon
            :icon-name="isMenuActive(menu) ? menu.icon?.active.iconName! : menu.icon?.notActive.iconName!"
            v-bind="isMenuActive(menu) ? menu.icon?.active.props! : menu.icon?.notActive.props!"
          ></Icon>
        </template>
      </MenuItem>
      <div
        class="menuDivideLine"
        v-else-if="menu.type === 'menuDivideLine'"
      ></div>
      <div class="menuGroupName" v-else-if="menu.type === 'menuGroupName'">
        {{ menu.name }}
      </div>
    </div>
    <ChainBrowser
      class="absolute bottom-9 left-1/2 transform -translate-x-1/2 cursor-pointer"
      @click="handleClickChainBrowser"
    ></ChainBrowser>
  </div>
</template>
<script lang="ts" setup>
import { router } from "@/router";
import { useRoute } from "vue-router";
import MenuItem from "./MenuItem.vue";
import Icon from "../Icon/index.vue";
import ChainBrowser from "./ChainBrowser.vue";
import { globalState } from "@/store/state";

const route = useRoute();

const isMenuActive = (obj: any) => {
  return (
    obj.path === route.path ||
    obj.otherActivePath?.includes(route.path) ||
    false
  );
};

const logo = import.meta.env.VITE_menuTopIconSrc as string;
const iconWidth = (import.meta.env.VITE_menuTopIconWidth as string) || "161px";

const menuList = [
  {
    type: "menuItem",
    name: "溯源管理",
    path: "/tracingManagement",
    icon: {
      active: { iconName: "iconsuyuan2", props: { color: "#3A3A3A" } },
      notActive: { iconName: "iconsuyuan1", props: { color: "#3A3A3A" } },
    },
  },
  // {
  //   type: "menuItem",
  //   name: "版权管理",
  //   path: "/copyrightManagement",
  //   otherActivePath: ["/draftBox"],
  //   icon: {
  //     active: { iconName: "iconbanquan2", props: { color: "#3A3A3A" } },
  //     notActive: { iconName: "iconbanquan1", props: { color: "#3A3A3A" } },
  //   },
  // },
  {
    type: "menuItem",
    name: "藏品管理",
    path: "/collectionManagement",
    otherActivePath: [
      "/albumManagement",
      "/albumDetail",
      "/transferRecords",
      "/issuedAlbumDetail",
      "/issuedDerivativesDetail",
    ],
    icon: {
      active: { iconName: "iconzichan21", props: { color: "#3A3A3A" } },
      notActive: {
        iconName: "iconzichan21",
        props: { color: "var(--sy-gray)" },
      },
    },
  },
  {
    type: "menuGroupName",
    name: "配置管理",
  },
  {
    type: "menuItem",
    name: "模板管理",
    path: "/templateManagement",
    otherActivePath: [],
    icon: {
      active: { iconName: "iconmoban2", props: {} },
      notActive: { iconName: "iconmoban1", props: {} },
    },
  },
  {
    type: "menuDivideLine",
  },
  {
    type: "menuItem",
    name: "回收站",
    path: "/recycleBin",
    otherActivePath: [],
    icon: {
      active: { iconName: "iconhuishouzhan2", props: {} },
      notActive: { iconName: "iconhuishouzhan1", props: {} },
    },
  },
];

const handleClickMenu = (obj: typeof menuList[0]) => {
  router.push({
    path: obj.path!,
  });
};

const handleClickChainBrowser = () => {
  window.open(globalState.urlList.chain_browser_url);
};
</script>
<style lang="scss" scoped>
.menu {
  width: 230px;
  height: 100vh;
  background-color: #f9f9f9;
  .appLine {
    display: flex;
    align-items: center;
    padding-top: 39px;
    margin-bottom: 29px;
    .icon {
      margin-left: 38px;
    }
    .appName {
      margin-left: 8px;
      font-size: 24px;
      font-family: Arial-Black, Arial;
      font-weight: 900;
      color: #191919;
      line-height: 33px;
      letter-spacing: 1px;
    }
  }
  .menuDivideLine {
    width: 190px;
    height: 1px;
    border-bottom: 1px solid #eeeeee;
  }
  .menuGroupName {
    width: 100%;
    padding-left: 50px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    height: 43px;
    line-height: 43px;
    color: #a3a3a3;
  }
}
</style>
