<template>
  <div class="navbar-container">
    <div class="navbar-background">
      <div class="navbar-content">
        <div class="navbar-logo">
          <h1 class="logo-text">智能知识库</h1>
        </div>
        <el-menu
            :default-active="activeRoute"
            mode="horizontal"
            @select="handleSelect"
            class="custom-nav-menu"
        >
          <el-menu-item index="/" class="nav-item">
            <span class="nav-icon">📚</span>
            知识库
          </el-menu-item>
          <el-menu-item index="/search" class="nav-item">
            <span class="nav-icon">🔍</span>
            搜索
          </el-menu-item>
          <el-menu-item index="/qanda" class="nav-item">
            <span class="nav-icon">💬</span>
            问答
          </el-menu-item>
        </el-menu>
<!--        <div class="navbar-actions">-->
<!--          <div class="user-info">-->
<!--            <span class="user-avatar">👤</span>-->
<!--            <span class="user-name">用户</span>-->
<!--          </div>-->
<!--        </div>-->
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue';
import { useRoute, useRouter } from 'vue-router';

export default defineComponent({
  name: 'AppNavbar',
  setup() {
    const route = useRoute();
    const router = useRouter();

    // 动态计算激活的路由
    const activeRoute = computed(() => {
      if (route.path.startsWith('/knowledge/content')) {
        return '/'; // 知识库页面时，设置为高亮 "知识库"
      }
      return route.path;
    });

    const handleSelect = (index: string) => {
      router.push(index);
    };

    return {
      activeRoute,
      handleSelect,
    };
  },
});
</script>

<style scoped>
.navbar-container {
  width: 100%;
  z-index: 1000;
}

.navbar-background {
  background: linear-gradient(135deg, #667eea 0%, rgba(118, 75, 162, 0.88) 100%);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.navbar-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 70px;
}

.navbar-logo {
  display: flex;
  align-items: center;
}

.logo-text {
  color: white;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  background: linear-gradient(135deg, #fff 0%, #e2e8f0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* 自定义导航菜单样式 */
.custom-nav-menu {
  background: transparent !important;
  border: none !important;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: center;
}

.custom-nav-menu :deep(.el-menu--horizontal) {
  border: none;
  background: transparent;
}

.custom-nav-menu :deep(.el-menu-item) {
  background: rgba(255, 255, 255, 0.1) !important;
  color: rgba(255, 255, 255, 0.9) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  border-radius: 12px !important;
  padding: 12px 24px !important;
  margin: 0 8px !important;
  font-size: 16px !important;
  font-weight: 500 !important;
  transition: all 0.3s ease !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  height: auto !important;
  line-height: 1.5 !important;
}

.custom-nav-menu :deep(.el-menu-item:hover) {
  background: rgba(255, 255, 255, 0.2) !important;
  color: white !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 15px rgba(255, 255, 255, 0.2) !important;
}

.custom-nav-menu :deep(.el-menu-item.is-active) {
  background: rgba(255, 255, 255, 0.25) !important;
  color: white !important;
  border-color: rgba(255, 255, 255, 0.4) !important;
  box-shadow: 0 4px 20px rgba(255, 255, 255, 0.3) !important;
}

.nav-icon {
  font-size: 1.2rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.navbar-actions {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.1);
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  transition: all 0.3s ease;
}

.user-info:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.user-avatar {
  font-size: 1.2rem;
}

.user-name {
  font-weight: 500;
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .navbar-content {
    padding: 0 16px;
    height: 60px;
  }

  .logo-text {
    font-size: 1.25rem;
  }

  .custom-nav-menu :deep(.el-menu-item) {
    padding: 10px 16px !important;
    font-size: 14px !important;
    margin: 0 4px !important;
  }

  .nav-icon {
    font-size: 1rem;
  }

  .user-info {
    padding: 6px 12px;
  }

  .user-name {
    display: none;
  }
}

@media (max-width: 480px) {
  .navbar-content {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 16px;
  }

  .navbar-logo {
    order: 1;
    flex: 1;
  }

  .custom-nav-menu {
    order: 3;
    width: 100%;
    margin-top: 12px;
    justify-content: space-around;
  }

  .navbar-actions {
    order: 2;
  }

  .custom-nav-menu :deep(.el-menu-item) {
    flex: 1;
    justify-content: center;
    margin: 0 2px !important;
    padding: 8px 12px !important;
  }

  .nav-icon {
    margin-right: 4px;
  }
}
</style>