<template>
  <div class="menu">
    <div class="appLine">
      <div class="icon"></div>
      <div class="appName">SLC</div>
    </div>
    <div
      v-for="(obj, index) in menuList"
      :key="index"
      style="width: 100%; display: flex; justify-content: center"
    >
      <MenuItem
        v-if="obj.type === 'menuItem'"
        :name="obj.name!"
        @click="handleClickMenu(obj)"
        :active="isMenuActive(obj)"
      >
        <template #icon>
          <Icon
            :icon-name="isMenuActive(obj) ? obj.icon?.active.iconName! : obj.icon?.notActive.iconName!"
            v-bind="isMenuActive(obj) ? obj.icon?.active.props! : obj.icon?.notActive.props!"
          ></Icon>
        </template>
      </MenuItem>
      <div
        class="menuDivideLine"
        v-else-if="obj.type === 'menuDivideLine'"
      ></div>
      <div class="menuGroupName" v-else-if="obj.type === 'menuGroupName'">
        {{ obj.name }}
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { router } from "@/router";
import { useRoute } from "vue-router";
import MenuItem from "./MenuItem.vue";
import { syIcon } from "cqk-sy-ui";
import Icon from "../Icon/index.vue";

const route = useRoute();

const isMenuActive = (obj: typeof menuList[0]) => {
  return (
    obj.path === route.path ||
    obj.otherActivePath?.includes(route.path) ||
    false
  );
};

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"],
    icon: {
      active: { iconName: "iconzichan21", props: { color: "#3A3A3A" } },
      notActive: { iconName: "iconzichan21", props: { color: "#959595" } },
    },
  },
  {
    type: "menuGroupName",
    name: "配置管理",
  },
  {
    type: "menuItem",
    name: "模板管理",
    path: "/templateManagement",
    icon: {
      active: { iconName: "iconmoban2", props: {} },
      notActive: { iconName: "iconmoban1", props: {} },
    },
  },
  {
    type: "menuDivideLine",
  },
  {
    type: "menuItem",
    name: "回收站",
    path: "/recycleBin",
    icon: {
      active: { iconName: "iconhuishouzhan2", props: {} },
      notActive: { iconName: "iconhuishouzhan1", props: {} },
    },
  },
];

const handleClickMenu = (obj: typeof menuList[0]) => {
  router.push({
    path: obj.path!,
  });
};
</script>
<style lang="scss">
.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: 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>
