<template>
  <nav class="navbar">
    <div class="navbar-container">
      <!-- Logo & Brand -->
      <div class="navbar-brand" @click="$router.push('/')">
        <img src="https://download.xn--xhq44jb2fzpc.com/images/logo-hd.png" alt="NEU小站" class="logo" />
        <span class="brand-text">课程评分</span>
        <span class="version-badge">V2</span>
      </div>

      <!-- Desktop Menu -->
      <div class="navbar-menu desktop-only">
        <template v-for="item in menuItems" :key="item.name">
          <a 
            v-if="item.isExternal"
            :href="item.path"
            target="_blank"
            rel="noopener noreferrer"
            class="nav-item"
          >
            {{ item.label }}
            <span v-if="item.isNew" class="new-badge">NEW</span>
          </a>
          <router-link 
            v-else
            :to="item.path"
            class="nav-item"
            active-class="active"
          >
            {{ item.label }}
            <span v-if="item.isNew" class="new-badge">NEW</span>
          </router-link>
        </template>
      </div>

      <!-- Mobile Menu Toggle -->
      <button class="navbar-toggle mobile-only" @click="toggleMenu" aria-label="Toggle navigation">
        <span class="hamburger-box">
          <span class="hamburger-inner" :class="{ 'is-active': isMenuOpen }"></span>
        </span>
      </button>
    </div>

    <!-- Mobile Menu Overlay/Drawer -->
    <transition name="fade">
      <div v-if="isMenuOpen" class="mobile-menu-overlay" @click="closeMenu"></div>
    </transition>
    
    <transition name="slide-down">
      <div v-if="isMenuOpen" class="mobile-menu-content">
        <div class="mobile-menu-header">
           <span class="mobile-menu-title">菜单</span>
        </div>
        <div class="mobile-links">
          <template v-for="item in menuItems" :key="item.name">
            <a 
              v-if="item.isExternal"
              :href="item.path"
              target="_blank"
              rel="noopener noreferrer"
              class="mobile-nav-item"
              @click="closeMenu"
            >
              {{ item.label }}
              <span v-if="item.isNew" class="new-badge">NEW</span>
            </a>
            <router-link 
              v-else
              :to="item.path"
              class="mobile-nav-item"
              active-class="active"
              @click="closeMenu"
            >
              {{ item.label }}
              <span v-if="item.isNew" class="new-badge">NEW</span>
            </router-link>
          </template>
        </div>
        <div class="mobile-footer">
           © 2024-{{ currentYear }} <a href="https://www.xn--xhq44jb2fzpc.com" target="_blank" style="color: inherit; text-decoration: none;">NEU小站</a>
        </div>
      </div>
    </transition>
  </nav>
</template>

<script>
export default {
  name: 'NavBar',
  data() {
    return {
      isMenuOpen: false,
      currentYear: new Date().getFullYear(),
      menuItems: [
        { label: '使用必看', path: '/', name: 'home' },
        { label: '选修课评分', path: '/rating', name: 'rating' },
        { label: '必修课评分', path: '/ratingforcomp', name: 'ratingforcomp' },
        { label: '我的课程', path: '/courses', name: 'course-list' },
        { label: '我的追问', path: '/qa', name: 'my-qa', isNew: true },
        // { label: '我的聊天', path: '/chat', name: 'chat' },
        { label: '关于', path: '/about', name: 'about' },
        { label: 'NEU小站', path: 'https://www.xn--xhq44jb2fzpc.com', name: 'neuxz', isExternal: true },
      ]
    };
  },
  methods: {
    toggleMenu() {
      this.isMenuOpen = !this.isMenuOpen;
    },
    closeMenu() {
      this.isMenuOpen = false;
    }
  }
};
</script>

<style scoped>
.navbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
  background: linear-gradient(to right, #ffffff, #f8f9fa);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  height: 64px;
}

.navbar-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Brand */
.navbar-brand {
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: opacity 0.3s;
}

.navbar-brand:hover {
  opacity: 0.8;
}

.logo {
  height: 40px;
  margin-right: 12px;
}

.brand-text {
  font-size: 1.5rem;
  font-weight: 700;
  color: #333;
  letter-spacing: 0.5px;
}

.version-badge {
  background: linear-gradient(135deg, #225fc9 0%, #5390E6 100%); /* Brighter blue gradient */
  color: white;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  margin-left: 10px;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  /* border: 1px solid rgba(255, 255, 255, 0.2); */
}

/* Reflective Shine Effect */
.version-badge::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.4),
    transparent
  );
  transform: skewX(-20deg);
  animation: shine 2s infinite;
}

@keyframes shine {
  0% {
    left: -100%;
  }
  20% {
    left: 200%;
  }
  100% {
    left: 200%;
  }
}

/* Desktop Menu */
.navbar-menu {
  display: flex;
  gap: 30px;
  align-items: center;
}

.nav-item {
  text-decoration: none;
  color: #555;
  font-weight: 500;
  font-size: 16px;
  padding: 8px 0;
  position: relative;
  transition: color 0.3s;
}

.nav-item:hover {
  color: #409eff; /* Element Plus primary blue */
}

.nav-item.active {
  color: #409eff;
  font-weight: 600;
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #409eff;
  border-radius: 2px;
}

.new-badge {
  display: inline-block;
  background-color: #f56c6c;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  margin-left: 2px;
  position: relative;
  top: -8px;
}

/* Mobile Toggle */
.navbar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  display: none; /* Hidden on desktop */
  margin-right: -10px; /* Align with container padding */
}

.hamburger-box {
  width: 24px;
  height: 24px;
  display: flex; /* Changed to flex for better alignment */
  align-items: center;
  justify-content: center;
  position: relative;
}

.hamburger-inner, .hamburger-inner::before, .hamburger-inner::after {
  width: 24px;
  height: 2px;
  background-color: #333;
  border-radius: 2px;
  position: absolute;
  transition: transform 0.3s cubic-bezier(0.4, 0.01, 0.165, 0.99), 
              opacity 0.3s cubic-bezier(0.4, 0.01, 0.165, 0.99),
              top 0.3s cubic-bezier(0.4, 0.01, 0.165, 0.99),
              bottom 0.3s cubic-bezier(0.4, 0.01, 0.165, 0.99); /* Enhanced transition for smooth animation */
  left: 0; /* Ensure consistent alignment */
}

.hamburger-inner {
  top: 50%;
  transform: translateY(-50%);
}

.hamburger-inner::before {
  content: '';
  top: -8px;
}

.hamburger-inner::after {
  content: '';
  bottom: -8px;
}

/* Hamburger Animation State */
.hamburger-inner.is-active {
  transform: rotate(45deg);
}

.hamburger-inner.is-active::before {
  top: 0;
  opacity: 0;
}

.hamburger-inner.is-active::after {
  bottom: 0;
  transform: rotate(-90deg);
}

/* Mobile Menu Styles */
.mobile-menu-overlay {
  position: fixed;
  top: 64px; /* Below navbar */
  left: 0;
  width: 100%;
  height: calc(100vh - 64px);
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 998;
}

.mobile-menu-content {
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  background-color: white;
  z-index: 999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.mobile-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
}

.mobile-menu-title {
  font-size: 1.2rem;
  font-weight: bold;
  color: #333;
}

.close-btn {
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  color: #999;
}

.mobile-links {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.mobile-nav-item {
  text-decoration: none;
  color: #333;
  font-size: 1.1rem;
  padding: 10px;
  border-radius: 8px;
  background-color: #f9f9f9;
  text-align: center;
  transition: background-color 0.2s;
}

.mobile-nav-item.active {
  background-color: #ecf5ff;
  color: #409eff;
  font-weight: 600;
}

.mobile-footer {
  margin-top: 30px;
  text-align: center;
  color: #999;
  font-size: 0.8rem;
}

/* Responsive Breakpoints */
@media (max-width: 768px) {
  .desktop-only {
    display: none;
  }

  .mobile-only {
    display: block;
  }
  
  .navbar-container {
    padding: 0 15px;
  }
}

/* Transitions */
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}

.slide-down-enter-active, .slide-down-leave-active {
  transition: transform 0.3s ease, opacity 0.3s;
}
.slide-down-enter-from, .slide-down-leave-to {
  transform: translateY(-20px);
  opacity: 0;
}
</style>
