<script setup>
import { computed, ref, watch } from "vue";
import { RouterLink, useRoute } from "vue-router";
import { Icon } from "@iconify/vue";

const route = useRoute();
const mobileOpen = ref(false);

const navItems = [
  { label: "首页", to: "/" },
  { label: "产品", to: "/products" },
  { label: "解决方案", to: "/solutions" },
  { label: "客户案例", to: "/cases" },
  { label: "新闻动态", to: "/news" },
  { label: "关于我们", to: "/about" },
];

watch(
  () => route.fullPath,
  () => {
    mobileOpen.value = false;
  },
);

const mobileLabel = computed(() =>
  mobileOpen.value ? "关闭菜单" : "打开菜单",
);
</script>

<template>
  <header class="app-header">
    <div class="app-header__inner">
      <RouterLink class="brand" to="/" aria-label="工业互联网门户">
        <img
          src="../../assets//images/logo.png"
          alt=""
          style="width: auto; height: 36px"
        />
        <!-- <span class="brand__text">
          <span class="brand__name">工业互联网门户</span>
          <span class="brand__tag muted">Industrial Internet Portal</span>
        </span> -->
      </RouterLink>

      <nav class="nav" aria-label="主导航">
        <RouterLink
          v-for="item in navItems"
          :key="item.to"
          class="nav__link"
          :to="item.to"
        >
          {{ item.label }}
        </RouterLink>
      </nav>

      <div class="actions">
        <RouterLink class="btn actions__login" to="/contact">登录</RouterLink>
        <RouterLink class="btn btn-primary" to="/contact">免费注册</RouterLink>

        <button
          class="hamburger"
          type="button"
          :aria-label="mobileLabel"
          :aria-expanded="mobileOpen ? 'true' : 'false'"
          @click="mobileOpen = !mobileOpen"
        >
          <Icon icon="lucide:menu" width="24" height="24" />
        </button>
      </div>
    </div>

    <div v-if="mobileOpen" class="mobile">
      <div class="mobile__inner container">
        <RouterLink
          v-for="item in navItems"
          :key="item.to"
          class="mobile__link"
          :to="item.to"
        >
          {{ item.label }}
        </RouterLink>
        <div class="divider"></div>
        <RouterLink class="mobile__link" to="/contact">联系咨询</RouterLink>
      </div>
    </div>
  </header>
</template>

<style scoped>
.app-header {
  position: fixed;
  z-index: 50;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 0.5px solid var(--border);
}

.app-header__inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
}

.brand__mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: radial-gradient(
    circle at 30% 30%,
    var(--brand-200),
    var(--brand-600)
  );
  box-shadow: 0 12px 20px rgba(29, 78, 216, 0.22);
}

.brand__text {
  display: grid;
  line-height: 1.1;
}

.brand__name {
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand__tag {
  font-size: 12px;
}

.nav {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.nav__link {
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--slate-700);
  font-size: 14px;
}

.nav__link:hover {
  background: rgba(15, 23, 42, 0.04);
}

.nav__link.router-link-exact-active {
  background: rgba(37, 99, 235, 0.1);
  color: var(--brand-700);
}

.actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.hamburger {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}

.hamburger > span {
  display: block;
  height: 2px;
  background: var(--slate-700);
  margin: 5px 10px;
  border-radius: 2px;
}

.mobile {
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.mobile__inner {
  padding: 14px 0 18px;
  display: grid;
  gap: 8px;
}

.mobile__link {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-weight: 650;
}

.mobile__link.router-link-exact-active {
  border-color: rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.08);
  color: var(--brand-700);
}

@media (max-width: 1024px) {
  .brand {
    min-width: auto;
  }

  .nav {
    display: none;
  }

  .actions__login {
    display: none;
  }

  .actions__cta {
    display: none;
  }

  .hamburger {
    display: inline-block;
  }
}
</style>
