<template>
  <header class="header" :class="{ 'header-hidden': isHidden }" role="banner">
    <div class="header-left">
      <a href="/" class="brand" aria-label="Home">
        <NuxtImg src="/logo.png" alt="DDAC logo" class="brand-logo" width="34" height="34" />
        <h1 class="brand-title">{{ title }}</h1>
      </a>
    </div>
    <nav class="header-nav" role="navigation" aria-label="Main navigation">
      <NuxtLink to="/web" class="nav-item">首页</NuxtLink>
      <div class="nav-item-wrapper">
        <div class="nav-item">
          <span>产品</span>
          <Icon name="line-md:chevron-down" class="nav-item-icon" />
        </div>
        <div class="dropdown-menu">
          <NuxtLink to="/web/products/sdk" class="dropdown-item">
            <img class="item-img" src="~/assets/svg/header/icon1.svg" alt="SDK 安全加固">
            <div class="item-text">
              <p>SDK 安全加固</p>
              <span>三合一：抗 D、消 C、挡 W</span>
            </div>
          </NuxtLink>
          <NuxtLink to="/web/products/web" class="dropdown-item">
            <img class="item-img" src="~/assets/svg/header/icon2.svg" alt="Web 安全加速">
            <div class="item-text">
              <p>Web 安全加速</p>
              <span>部署 30 秒，省心 365 天</span>
            </div>
          </NuxtLink>
          <!-- <NuxtLink to="/web/products/dns" class="dropdown-item">
            <img class="item-img" src="~/assets/svg/header/icon3.svg" alt="DNS 全球解析">
            <div class="item-text">
              <p>DNS 全球解析</p>
              <span>把地球缩成局域网——全球 280+ 节点实时同步</span>
            </div>
          </NuxtLink> -->
          <NuxtLink to="/web/products/boost" class="dropdown-item">
            <img class="item-img" src="~/assets/svg/header/icon4.svg" alt="高防服务器">
            <div class="item-text">
              <p>高防服务器</p>
              <span>单台扛 1.5T，秒级自动扩容</span>
            </div>
          </NuxtLink>
        </div>
      </div>
      <NuxtLink to="/web/solutions" class="nav-item">行业解决方案</NuxtLink>
      <NuxtLink to="/web/docs" class="nav-item">文档中心</NuxtLink>
      <NuxtLink to="/web/about" class="nav-item">了解我们</NuxtLink>
    </nav>
    <div class="header-right">
      <div>登录</div>
      <div class="register">注册</div>
    </div>
  </header>
</template>
<script setup>
const title = import.meta.env.VITE_APP_NAME
const { y: scrollY } = useWindowScroll()
const lastScrollY = ref(0)
const isHidden = ref(false)

watchEffect(() => {
  if (scrollY.value > lastScrollY.value && scrollY.value > 60) {
    isHidden.value = true
  } else {
    isHidden.value = false
  }
  lastScrollY.value = scrollY.value
})
</script>
<style lang="scss" scoped>
.header {
  box-sizing: border-box;
  padding: 22px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  // background: transparent;
  background: #030014;
  transition: transform 0.3s ease;

  &.header-hidden {
    transform: translateY(-100%);
  }
}

.header-left {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: right;

  .brand {
    display: flex;
    align-items: center;
    text-decoration: none;

    .brand-logo {
      margin-right: 8px;
    }

    .brand-title {
      color: #FFF;
      font-size: 30px;
      font-style: normal;
      font-weight: 700;
      line-height: 36px;
    }
  }
}

.header-nav {
  flex: 2;
  display: flex;
  justify-content: center;
  align-items: center;

  .nav-item {
    display: flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    margin: 0 15px;
    cursor: pointer;
    color: #FFF;
    font-size: 16px;
    font-style: normal;
    font-weight: 400;
    line-height: 16px;

    &:hover {
      // color: #000;
    }
  }
}

.nav-item-icon {
  transition: transform 0.3s ease;
}

.nav-item-wrapper:hover .nav-item-icon {
  transform: rotate(180deg);
}

.header-right {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: left;
  color: #FFF;
  font-size: 16px;

  div {
    margin-left: 20px;
    cursor: pointer;
  }

  .register {
    display: flex;
    width: 100px;
    height: 40px;
    justify-content: center;
    align-items: center;
    gap: 10px;
    border-radius: 10px;
    border: 1px solid #7D46FF;
    background: #030014;
    box-shadow: 0.5px 0.5px 18px 0 rgba(125, 70, 255, 0.45) inset;
  }
}

.nav-item-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;

  &:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 30px);
  }
}

.dropdown-menu {
  position: absolute;
  display: flex;
  flex-direction: column;
  top: 100%;
  left: 50%;
  transform: translate(-50%, 0);
  border-radius: 4px;
  min-width: 284px;
  opacity: 0;
  border-top: 1px solid #7D46FF;
  background: rgba(63, 63, 63, 0.60);
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(30px);
  z-index: 1001;
  margin-top: 5px;

  .dropdown-item {
    padding: 12px;
    display: flex;
    align-items: center;
    color: #FFF;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
    text-align: center;
    gap: 24px;

    &:hover {
      background: rgba(255, 255, 255, 0.1);
    }

    .item-img {
      width: 34px;
      height: 34px;
    }

    .item-text {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: flex-start;
      gap: 10px;

      p {
        color: #FFF;
        font-size: 16px;
        font-style: normal;
        font-weight: 500;
        line-height: 16px;
      }

      span {
        color: rgba(255, 255, 255, 0.60);
        font-size: 14px;
        font-style: normal;
        font-weight: 400;
        line-height: 22px;
        text-align: left;
      }
    }
  }
}
</style>
