<template>
  <header class="header" :class="{ 'header-hidden': isHidden }" role="banner">
    <div class="header-left">
      <a href="/" class="brand" aria-label="Home">
        <img src="/logo.png" alt="DDAC logo" class="brand-logo" width="34" height="34" />
        <h1 class="brand-title">DDAC</h1>
      </a>
    </div>
    <nav class="header-nav" role="navigation" aria-label="Main navigation">
      <div class="nav-item">首页</div>
      <div class="nav-item">产品</div>
      <div class="nav-item">行业解决方案</div>
      <div class="nav-item">文档中心</div>
      <div class="nav-item">了解我们</div>
    </nav>
    <div class="header-right">
      <div>登录</div>
      <div class="register">注册</div>
    </div>
  </header>
</template>
<script setup>
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">
.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: #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-family: Roboto;
      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 {
    margin: 0 15px;
    cursor: pointer;
    color: #FFF;
    font-family: "Source Han Sans CN";
    font-size: 14px;
    font-style: normal;
    font-weight: 400;
    line-height: 14px;

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

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

  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;
  }
}
</style>