<template>
  <header class="header" :class="{ 'no-shadow': !shadow }">
    <div class="container">
      <div class="logo">
        <span class="logo_text">
          <img src="../assets/logo.png" height="40px" />
        </span>
      </div>
      <nav class="navbar">
        <ul class="navbar_item_wrap">
          <li
            class="navbar_item"
            :class="{ active: active === item.path }"
            v-for="item in navbar"
            @click="changePath"
            :key="item.path">
            <router-link :to="item.path">{{ item.name }}</router-link>
          </li>
        </ul>
      </nav>
      <div class="right_btn">
        <!-- <el-button type="primary" size="mini" @click="login">登录</el-button>
        <el-button size="mini" @click="register">注册</el-button> -->
        <div class="user-operate">
          <span class="login-btn" @click="login">登录</span>
          <span class="reg-btn" @click="register">注册</span>
        </div>

        <el-button type="primary">免费试用</el-button>
      </div>
    </div>
  </header>
</template>

<script>
export default {
  props: {
    shadow: { type: Boolean },
  },
  inject: {
    scrollParent: 'scrollParent',
  },
  data() {
    return {
      navbar: [
        { name: '首页', path: '/home' },
        { name: '核心功能', path: '/function' },
        { name: '价格', path: '/price' },
        { name: '需求痛点', path: '/demand_pain_point' },
        { name: '关于我们', path: '/about_us' },
      ],
    }
  },
  computed: {
    active() {
      return this.$route.path
    },
  },
  methods: {
    changePath() {
      this.scrollParent().scrollTo({
        behavior: 'smooth',
        top: 0,
      })
    },
    login() {
      this.$router.push('/login')
    },
    register() {
      this.$router.push('/register')
    },
  },
}
</script>

<style scoped>
.header {
  position: fixed;
  z-index: 999;
  /* background: #0089ff; */
  top: 0;
  right: 0;
  left: 0;
  /* box-shadow: 0 2px 10px 0 rgb(0 39 98 / 66%); */
}

.header.no-shadow {
  box-shadow: none !important;
}

.logo {
  float: left;
  margin-top: 10px;
}
.navbar {
  float: left;
  margin-left: 100px;
}
.navbar_item {
  float: left;
  position: relative;
}

.navbar_item:hover a {
  color: #f19240;
}
.navbar_item + .navbar_item {
  margin-left: 30px;
}
.navbar_item a {
  display: block;
  height: 60px;
  line-height: 60px;
  text-decoration: none;
  padding: 0 20px;
  color: #fff;
}
.right_btn {
  display: flex;
  align-items: center;
  margin-left: auto;
}

.login-btn {
  position: relative;
  margin-right: 20px;
  cursor: pointer;
  color: #fff;
}

.reg-btn {
  cursor: pointer;
  color: #fff;
}

.login-btn::after {
  content: '';
  width: 1px;
  height: 15px;
  position: absolute;
  display: inline-block;
  margin-left: 10px;
  top: 4px;
  background-color: #fff;
}

.user-operate {
  margin-right: 10px;
}

.active a {
  color: #f19240;
  font-weight: bold;
}

.active::after {
  content: '';
  width: 20px;
  height: 2px;
  background-color: #f19240;
  border-radius: 4px;
  display: block;
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
}
</style>
