<template>
  <div class="custom-navi" :class="['navi-bg03', naviColors]">

    <div class="navi-body">
      <div v-for="list in navis" :key="list.path" class="navi-group">
        <!-- 如果有子项，显示分组标题 -->
        <div v-if="list.items.length" class="navi-group-title" @click="toggleGroup(list.group)">
          <div class="navi-icon">
            <v-icon :icon="list.icon" size="24"></v-icon>
          </div>
          <div class="navi-text">{{ list.title }}</div>
          <div class="navi-arrow">
            <v-icon :icon="expandedGroups.includes(list.group) ? 'mdi-chevron-up' : 'mdi-chevron-down'" size="16"></v-icon>
          </div>
        </div>

        <!-- 子项列表 -->
        <div v-if="list.items.length && expandedGroups.includes(list.group)" class="navi-items">
          <div 
            v-for="item in list.items" 
            :key="item.title" 
            class="navi-item"
            :class="{ 'navi-item-active': activePath === item.path }"
            @click="navigate(item.path)"
          >
            <div class="navi-content">
              <div class="navi-icon">
                <v-icon :icon="item.icon" size="20"></v-icon>
              </div>
              <div class="navi-text">{{ item.title }}</div>
            </div>
          </div>
        </div>

        <!-- 单个菜单项 -->
        <div 
          v-else 
          class="navi-item"
          :class="{ 'navi-item-active': activePath === list.path }"
          @click="navigate(list.path)"
        >
          <div class="navi-content">
            <div class="navi-icon">
              <v-icon :icon="list.icon" size="20"></v-icon>
            </div>
            <div class="navi-text">{{ list.title }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed, ref } from 'vue'
import { useSettingsStore } from '@/stores/settings'
import logoImg from '@/assets/logo.svg'

const store = useSettingsStore()

// 获取主题颜色和导航状态
const naviColors = computed(() => {

    let cleanClass = store.getNaviColors
  if (typeof cleanClass === 'string') {
    // 去除首尾的单引号或双引号
    cleanClass = cleanClass.replace(/^['"]|['"]$/g, '')
  }
  return cleanClass
})
const naviActive = computed(() => store.getNaviActive)


// 导航数据
const navis = [
  {
    title: "资源",
    path: "/datas/docx",
    icon: "mdi-clipboard-multiple",
    group: "/datas",
    items: []
  },
]

// 当前激活的路径
const activePath = ref('/datas/docx')

// 控制分组展开状态
const expandedGroups = ref([''])

// 切换分组展开状态
const toggleGroup = (group) => {
  if (expandedGroups.value.includes(group)) {
    expandedGroups.value = expandedGroups.value.filter(g => g !== group)
  } else {
    expandedGroups.value.push(group)
  }
}

// 导航到指定路径
const navigate = (path) => {
  activePath.value = path
  // 这里可以添加路由跳转逻辑
}
</script>

<style scoped>
.custom-navi {
  width: 68px;
  height: calc(100vh - 64px);
  position: absolute;
  top: 64px;
  left: 0;
  background-color: #1a1a1a;
  border-right: 1px solid #333;
  overflow-y: auto;
  transition: all 0.3s ease;
}

.navi-hd {
  padding: 20px 0;
  text-align: center;
}

.navi-hd img {
  width: 40px;
  height: 40px;
}

.navi-body {
  /* padding: 16px 0; */
}

.navi-group {
  margin-bottom: 16px;
}

.navi-group-title {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 4px;
}

.navi-group-title:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.navi-icon {
  display: flex;
  justify-content: center;
  align-items: center;
}

.navi-text {
  font-size: 14px;
  color: #ffffff;
  opacity: 0.9;
  text-align: center;
  padding-top: 4px;
}

.navi-arrow {
  margin-left: auto;
  opacity: 0.7;
}

.navi-items {
  margin-top: 8px;
}

.navi-item {
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.navi-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.navi-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.navi-item-active {
  background-color: rgba(255, 255, 255, 0.1);
  border-left: 4px solid #00bfff;
  padding-left: 12px;
}

/* 白色主题 */
.navi-bg03.light {
  background-color: #ffffff;
  border-right: 1px solid #e5e7eb;
}

/* 黑色主题 */
.navi-bg03.dark {
  background-color: #363636;
  border-right: 1px solid #333;
}


/* 白色主题下的文字和图标颜色 */
 .navi-bg03.light .navi-item .navi-text,
 .navi-bg03.light .navi-item .navi-icon .v-icon {
  color: #000000;
}

/* 黑色主题下的文字和图标颜色 */
 .navi-bg03.dark .navi-item .navi-text,
 .navi-bg03.dark .navi-item .navi-icon .v-icon {
  color: #ffffff;
}

/* 选中状态下的图标和文字颜色 */
.navi-bg03.light .navi-item-active .navi-text,
.navi-bg03.light .navi-item-active .navi-icon .v-icon,
.navi-bg03.dark .navi-item-active .navi-icon .v-icon,
.navi-bg03.dark .navi-item-active .navi-text {
  color: #2196f3;
}

/* 活动状态样式 */
.navi-bg03.dark .navi-item-active,
.navi-bg03.light .navi-item-active {
  background-color: rgba(0, 0, 0, 0.1);
  border-left-color: #2196f3;
}
</style>