<template>
  <div :class="['header', shownNavBg ? 'navBg' : '']">
    <div class="header-logo">
      <img class="header-logo-img" src="./../assets/images/header-logo.png" alt="" />
    </div>
    <div class="header-nav">
      <div class="nav-item">
        <NuxtLink :to="{ path: '/' }">首页</NuxtLink>
      </div>
      <div class="nav-item">
        <NuxtLink :to="{ path: '/products/666' }">产品介绍</NuxtLink>
      </div>
      <div class="nav-item">
        <NuxtLink :to="{ path: '/solution' }">行业解决案例</NuxtLink>
      </div>
      <div class="nav-item">
        <NuxtLink :to="{ path: '/developer' }">开发者工具</NuxtLink>
      </div>
      <div class="nav-item">
        <NuxtLink :to="{ path: '/AboutUs' }">关于我们</NuxtLink>
      </div>
    </div>
    <div class="header-right">
      <div class="manage-btn">
        <img src="./../assets/images/manage-icon.png" />
        <span>管理中心</span>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref, onBeforeMount, onBeforeUnmount } from "vue";

const shownNavBg = ref(false);

const handleScroll = () => {
  let num = window.scrollY;
  if (num > 50 && !shownNavBg.value) {
    shownNavBg.value = true;
  } else if (num <= 50 && shownNavBg.value) {
    shownNavBg.value = false;
  }
};

onBeforeMount(() => {
  window.addEventListener("scroll", handleScroll);
});

onBeforeUnmount(() => {
  window.removeEventListener("scroll", handleScroll);
});
</script>
<style lang="scss" scoped>
.navBg {
  background-color: #fff;
}
.header {
  width: 100%;
  height: var(--nav-height);
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: var(--header-z-index);
  padding: 0 var(--size-60);
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  .header-logo {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    .header-logo-img {
      width: 110px;
      height: 38px;
      object-fit: contain;
    }
  }
  .header-nav {
    flex: 1;
    padding: 0 var(--size-100);
    display: flex;
    align-items: stretch;
    .nav-item {
      display: flex;
      align-items: center;
      padding-right: 50px;
      cursor: pointer;
      font-size: 16px;
      font-family: Microsoft YaHei, Microsoft YaHei-Regular;
      font-weight: 400;
      text-align: left;
      color: #1a1a1a;
      line-height: 54px;
    }
  }
  .header-right {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    cursor: pointer;
    .manage-btn {
      width: 147px;
      height: 35px;
      background: #006efe;
      border-radius: 18px;
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
      font-size: 16px;
      font-family: Microsoft YaHei, Microsoft YaHei-Regular;
      font-weight: 400;
      text-align: left;
      color: #ffffff;
      line-height: 54px;
      span {
        padding-left: 9px;
      }
    }
  }
}
</style>
