<template>
  <a-layout-sider class="sider">
    <h2 style="padding: 0;">
      <!-- 四维工地管家 -->

      <img :src="`./images/sync_logo.png`" />
    </h2>

    <a-menu
      mode="inline"
      theme="dark"
      :selected-keys="selectedNames"
      class="sider-menu"
      @select="selectMenu"
    >
      <a-menu-item v-for="menu in menus" :key="menu" class="sider-menu-item">
        <template #icon>
          <i class="iconfont" :class="routesMetas[menu].icon" />
        </template>
        <span>{{ routesMetas[menu].title }}</span>
      </a-menu-item>
    </a-menu>
  </a-layout-sider>
</template>

<script setup lang="ts">
import { RoutesName, routesMetas } from '@/router'
import { computed } from 'vue'
import { router, getRouteTreePaths } from '@/router'
import { useUserStore } from '@/store'
import { lang, langNameEum } from '@/lang'

import type { MenuProps } from 'ant-design-vue/es/menu'

defineOptions({ name: 'LayoutSider' })

type MenuName = typeof allMenus[number]
const userStore = useUserStore()
const allMenus = [RoutesName.personal, RoutesName.projects] as const

const menus = computed(() => {
  const roleMenus = userStore.roleMenus
  console.log(roleMenus)
  return allMenus.filter(menu => roleMenus.includes(menu))
})
const selectMenu: MenuProps['onSelect'] = ({ key }) => {
  router.push({ name: key as RoutesName })
}

const selectedNames = computed(() => {
  const routeName = router.currentRoute.value.name as MenuName
  return getRouteTreePaths(routeName) || []
})
</script>

<style scoped lang="scss">
.sider {
  background-color: #001529;
}
h2 {
  background: #002140;
  margin: 0;
  padding: 16px 20px;
  font-size: 22px;
  font-weight: bold;
  color: #fff;
  // text-align: center;

  img {
    width: 100%;
  }
}
</style>

<style lang="scss">
.sider {
  background-color: #001529;

  .sider-menu {
    .sider-menu-item {
      margin-top: 0;
      margin-bottom: 0;
      height: 60px;
      line-height: 60px;
      position: relative;
      transition: all 0.3s ease;

      &::after {
        content: '';
        position: absolute;
        width: 0px;
        top: 0;
        bottom: 0;
        right: 0;
        background-color: #00b3ec;
        transition: width 0.3s ease;
      }

      &.ant-menu-item-selected {
        background-color: rgba(24, 144, 255, 0.05);

        &::after {
          width: 4px;
        }
      }
    }
  }
}
</style>
