<template>
  <header id="header">
    <!-- 主导航 (桌面端) -->
    <nav class="header-nav container hidden-xs">
      <router-link to="/" class="header-logo">
        <div class="logo-wrapper">
          <div class="logo-glow"></div>
          <img src="@/assets/img/logo_black.svg" alt="Logo">
        </div>
      </router-link>
      <router-link to="/" class="header-company-name">
        <div class="name-wrapper">
          <span>上海展域航空技术有限公司</span>
        </div>
      </router-link>
      <ul class="nav-menu">
        <li
          v-for="(item, index) in navList"
          :key="index"
          :class="{ active: index === navIndex, 'nav-item-contact': item.name === '联系我们' }"
          @click="navClick(index, item.name)"
        >
          <router-link :to="item.path">
            {{ item.name }}
            <i v-if="item.children.length > 0" class="glyphicon glyphicon-menu-down"></i>
            <span class="nav-underline"></span>
          </router-link>
          <!-- 二级菜单 -->
          <ul v-if="item.children.length > 0" class="submenu">
            <li v-for="(child, n) in item.children" :key="n">
              <router-link :to="child.path">{{ child.name }}</router-link>
            </li>
          </ul>
        </li>
      </ul>
    </nav>

    <!-- 手机导航 -->
    <div class="header-nav-m container-fuild visible-xs">
      <router-link to="/home" class="header-nav-m-logo">
        <img class="center-block" src="@/assets/img/logo_black.svg" alt="logo">
      </router-link>
      <!-- 导航栏 -->
      <div class="header-nav-m-menu text-center">
        {{ menuName }}
        <div
          class="header-nav-m-menu-wrapper"
          data-toggle="collapse"
          data-target="#menu"
          @click="menuClick"
        >
          <span :class="menuClass"></span>
        </div>
        <!-- 导航内容 -->
        <ul id="menu" class="header-nav-m-wrapper collapse">
          <li
            v-for="(item,index) in navList"
            :key="index"
            :class="index==navIndex?'active':''"
            @click="navClick(index,item.name)"
            data-toggle="collapse"
            data-target="#menu"
          >
            <router-link :to="item.path">
              {{ item.name }}
              <i class="glyphicon glyphicon-chevron-right"></i>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
  </header>
</template>

<script>
import { navConfig } from '@/config/nav-config'

export default {
  name: "Header",
  data() {
    return {
      navIndex: sessionStorage.getItem('navIndex') || 0,
      menuName: "首页",
      menuClass: "glyphicon glyphicon-menu-down",
      navList: navConfig
    };
  },
  methods: {
    navClick(index, name) {
      this.navIndex = index;
      sessionStorage.setItem('navIndex', index);
      this.menuName = name;
    },
    menuClick() {
      if (this.menuClass === "glyphicon glyphicon-menu-down") {
        this.menuClass = "glyphicon glyphicon-menu-up";
      } else {
        this.menuClass = "glyphicon glyphicon-menu-down";
      }
    }
  }
};
</script>

<style scoped>
/* ===== CSS 变量 ===== */
#header {
  --header-bg: rgba(255, 255, 255, 0.95);
  --header-glass: rgba(255, 255, 255, 0.8);
  --header-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --nav-text: #333;
  --nav-hover: #1e73be;
  --nav-active: #1e73be;
  --submenu-bg: #fff;
  --submenu-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --transition: all 0.3s ease;
  --glow-blue: 0 0 20px rgba(30, 115, 190, 0.3);
}

/* ===== 基础样式 ===== */
#header {
  background: var(--header-glass);
  backdrop-filter: blur(10px);
  box-shadow: var(--header-shadow);
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 1px solid rgba(30, 115, 190, 0.1);
}

/* ===== 主导航 ===== */
.header-nav {
  display: flex;
  align-items: center;
  height: 80px;
  padding: 0;
}

/* Logo */
.header-logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  text-decoration: none;
}

.header-logo .logo-wrapper {
  position: relative;
  display: inline-block;
  padding: 8px;
  border-radius: 12px;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  overflow: visible;
}

.header-logo .logo-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  width: 70%;
  height: 70%;
  background: conic-gradient(
    from 0deg,
    rgba(255, 140, 50, 0),
    rgba(255, 140, 50, 0.4),
    rgba(255, 160, 80, 0.5),
    rgba(255, 120, 40, 0.4),
    rgba(255, 140, 50, 0)
  );
  border-radius: 12px;
  filter: blur(12px);
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 0;
  animation: rotate-glow 3s linear infinite;
}

@keyframes rotate-glow {
  0% { transform: translate(-50%, -50%) scale(0.8) rotate(0deg); }
  100% { transform: translate(-50%, -50%) scale(0.8) rotate(360deg); }
}

.header-logo .logo-wrapper::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 12px;
  background: linear-gradient(
    135deg,
    rgba(255, 140, 50, 0.08),
    rgba(255, 160, 80, 0.12),
    rgba(255, 140, 50, 0.08)
  );
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 1;
}

.header-logo .logo-wrapper img {
  position: relative;
  z-index: 2;
  height: 50px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(255, 140, 50, 0.2));
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.header-logo:hover .logo-wrapper {
  transform: scale(1.08);
}

.header-logo:hover .logo-wrapper::before {
  opacity: 1;
}

.header-logo:hover .logo-glow {
  opacity: 1;
}

.header-logo:hover .logo-wrapper img {
  transform: scale(1.05);
  filter: drop-shadow(0 4px 12px rgba(255, 140, 50, 0.4));
}

/* 企业名称 */
.header-company-name {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding-left: 16px;
  margin-left: 16px;
  border-left: 1px solid rgba(30, 115, 190, 0.2);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.header-company-name:hover {
  opacity: 0.85;
}

.header-company-name .name-wrapper {
  position: relative;
  display: inline-block;
  padding: 8px 16px;
  border-radius: 12px;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  overflow: hidden;
}

.header-company-name .name-wrapper::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 12px;
  background: linear-gradient(
    135deg,
    rgba(255, 140, 50, 0.08),
    rgba(255, 160, 80, 0.12),
    rgba(255, 140, 50, 0.08)
  );
  opacity: 0;
  transition: opacity 0.4s ease;
}

.header-company-name span {
  position: relative;
  z-index: 2;
  font-size: 20px; /* 修改这个值调整字体大小 */
  font-weight: 600;
  color: #806D61;
  letter-spacing: 1px;
  line-height: 1.4;
  white-space: nowrap;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.header-company-name:hover .name-wrapper {
  transform: scale(1.03);
}

.header-company-name:hover .name-wrapper::before {
  opacity: 1;
}

.header-company-name:hover span {
  color: #2c2c2c;
}

/* 导航菜单 */
.nav-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
  margin-left: auto;
}

.nav-menu > li {
  position: relative;
}

/* 联系我们按钮样式 */
.nav-menu > li.nav-item-contact {
  margin-left: 10px;
}

.nav-menu > li.nav-item-contact > a {
  background: linear-gradient(135deg, #1e73be 0%, #3b82f6 100%);
  color: #fff !important;
  padding: 10px 24px;
  border-radius: 6px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(30, 115, 190, 0.3);
  transition: all 0.3s ease;
}

.nav-menu > li.nav-item-contact > a:hover {
  background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(30, 115, 190, 0.4);
}

.nav-menu > li.nav-item-contact > a .nav-underline {
  display: none;
}

.nav-menu > li.nav-item-contact > a i {
  display: none;
}

.nav-menu > li > a {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 18px;
  color: var(--nav-text);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  transition: var(--transition);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.nav-menu > li > a::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 3px;
  background: var(--primary-gradient, linear-gradient(135deg, #1e73be, #3b82f6));
  transition: all 0.3s ease;
  transform: translateX(-50%);
  border-radius: 3px 3px 0 0;
}

.nav-menu > li > a:hover::before,
.nav-menu > li.active > a::before {
  width: 80%;
}

.nav-menu > li > a:hover,
.nav-menu > li.active > a {
  color: var(--nav-hover);
  background: rgba(30, 115, 190, 0.05);
}

.nav-menu > li > a i {
  font-size: 10px;
  transition: transform 0.3s ease;
}

.nav-menu > li > a:hover i {
  transform: rotate(180deg);
}

/* 二级菜单 */
.submenu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 180px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(20px);
  border-radius: 12px;
  box-shadow: var(--submenu-shadow), var(--glow-blue);
  list-style: none;
  margin-top: 8px;
  padding: 8px 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: var(--transition);
  border: 1px solid rgba(30, 115, 190, 0.1);
}

.nav-menu > li:hover .submenu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.submenu li a {
  display: block;
  padding: 12px 20px;
  color: var(--nav-text);
  font-size: 14px;
  text-decoration: none;
  transition: var(--transition);
  position: relative;
}

.submenu li a::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 0;
  background: var(--primary-gradient, linear-gradient(135deg, #1e73be, #3b82f6));
  transition: height 0.3s ease;
}

.submenu li a:hover::before {
  height: 100%;
}

.submenu li a:hover {
  background: linear-gradient(90deg, rgba(30, 115, 190, 0.05), transparent);
  color: var(--nav-hover);
  padding-left: 24px;
}

/* ===== 移动端导航 ===== */
@media screen and (max-width: 997px) {
  /* 桌面端元素不在移动端显示 */
  .header-company-name {
    display: none;
  }

  /* 移动端 Header 容器 - 移除底部边框 */
  #header {
    border-bottom: none !important;
  }

  /* 移动端 Logo 区域 */
  #header .header-nav-m .header-nav-m-logo {
    height: 70px;
    position: relative;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(30, 115, 190, 0.08);
    display: block;
    text-decoration: none;
  }

  #header .header-nav-m .header-nav-m-logo img {
    width: 160px;
    height: 50px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
  }

  /* 移动端导航条 - 蓝色玻璃效果 */
  #header .header-nav-m .header-nav-m-menu {
    height: 44px;
    font-size: 14px;
    line-height: 44px;
    background: rgba(30, 115, 190, 0.95);
    backdrop-filter: blur(10px);
    position: relative;
    box-shadow: 0 4px 16px rgba(30, 115, 190, 0.35);
    color: #fff;
    font-weight: 500;
  }

  #header .header-nav-m .header-nav-m-menu-wrapper {
    position: absolute;
    top: 50%;
    right: 16px;
    margin-top: -16px;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    transition: all 0.3s ease;
    cursor: pointer;
  }

  #header .header-nav-m .header-nav-m-menu-wrapper:hover {
    background: rgba(255, 255, 255, 0.25);
  }

  #header .header-nav-m .header-nav-m-menu-wrapper span {
    font-size: 14px;
    color: #fff;
  }

  /* 下拉导航菜单 */
  #header .header-nav-m .header-nav-m-wrapper {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 8px 0;
    margin: 0;
  }

  #header .header-nav-m .header-nav-m-wrapper > li {
    margin: 4px 12px;
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.3s ease;
  }

  #header .header-nav-m .header-nav-m-wrapper > li > a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    color: #333;
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.3s ease;
  }

  #header .header-nav-m .header-nav-m-wrapper > li > a i {
    font-size: 12px;
    color: #ccc;
    transition: transform 0.3s ease;
  }

  #header .header-nav-m .header-nav-m-wrapper > li > a:hover {
    background: rgba(30, 115, 190, 0.08);
    color: #1e73be;
  }

  #header .header-nav-m .header-nav-m-wrapper > li > a:hover i {
    transform: translateX(4px);
    color: #1e73be;
  }

  /* 激活状态 */
  #header .header-nav-m .header-nav-m-wrapper > li.active {
    background: rgba(30, 115, 190, 0.1);
  }

  #header .header-nav-m .header-nav-m-wrapper > li.active > a {
    color: #1e73be;
    font-weight: 600;
  }

  #header .header-nav-m .header-nav-m-wrapper > li.active > a i {
    color: #1e73be;
  }

  /* 联系我们特殊样式 */
  #header .header-nav-m .header-nav-m-wrapper > li.nav-item-contact {
    margin: 16px 12px 8px;
  }

  #header .header-nav-m .header-nav-m-wrapper > li.nav-item-contact > a {
    background: linear-gradient(135deg, #1e73be 0%, #3b82f6 100%);
    color: #fff !important;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(30, 115, 190, 0.3);
  }

  #header .header-nav-m .header-nav-m-wrapper > li.nav-item-contact > a i {
    display: none;
  }

  #header .header-nav-m .header-nav-m-wrapper > li.nav-item-contact:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(30, 115, 190, 0.4);
  }

  #header .header-nav .header-nav-wrapper > li > a > span {
    font-size: 10px;
  }
}
</style>
