<template>
  <div class="head-mian">
    <div class="color-bar"></div>
    <div class="head-top-content">
      <div class="max-width-content fix-align-c">
        <nuxt-link to="/">
          <img class="big-logo" src="https://webapp-pub.ezijing.com/website/base/logo.svg" />
          <div class="line">｜</div>
          <img src="/images/logo.png" style="height: 90px;" />
          <img style="margin-left:20px" src="/images/logo2.png" />
        </nuxt-link>
        <div class="user" v-if="user.id">
          <span>{{ user.realname || user.nickname }}</span
          ><em>|</em><span class="logout" @click="logout">{{ $t('menu.out') }}</span>
        </div>
        <div class="login-btn-box" v-else>
          <div class="login">
            <a :href="loginURL">{{ $t('menu.fastLogin') }}</a>
          </div>
          <div class="register">
            <a :href="registerURL">{{ $t('menu.register') }}</a>
          </div>
        </div>
        <!-- <div class="language">
          <span @click="switchLocale('zh-CN')">中文</span> / <span @click="switchLocale('en-US')">EN</span>
        </div> -->
      </div>
    </div>
    <div class="head-nav-content max-width-content">
      <app-menu></app-menu>
      <div class="search-box"></div>
    </div>
  </div>
</template>
<script>
import AppMenu from './Menu'
export default {
  components: {
    AppMenu,
  },
  data() {
    return {}
  },
  methods: {
    logout() {
      this.$store.dispatch('logout')
    },
    switchLocale(locale) {
      this.$i18n.locale = locale
      this.$cookies.set('lang', locale)
      process.client && location.reload()
    },
  },
  computed: {
    user() {
      return this.$store.state.user || {}
    },
    loginURL() {
      return process.client
        ? `${process.env.loginURL}/login/index?redirect_uri=${encodeURIComponent(
            location.origin + this.$route.fullPath
          )}`
        : ''
    },
    registerURL() {
      return process.client
        ? `${process.env.loginURL}/register?redirect_uri=${encodeURIComponent(location.origin + this.$route.fullPath)}`
        : ''
    },
  },
}
</script>
<style lang="scss" scoped>
ul,
li {
  margin: 0;
  padding: 0;
  list-style: none;
}
.head-mian {
  width: 100%;
  background: #fff;
  min-width: 1200px;
  .color-bar {
    height: 10px;
    background: #aa1941;
  }
  .head-top-content {
    // width: 1200px;
    // margin: 0 auto;
    border: 1px solid #ebebeb;
    // padding: 23px 0 22px;
    .max-width-content {
      display: flex;
      align-items: center;
      .line {
        font-size: 40px;
        font-weight: 200;
        color: #aa1941;
      }
      ::v-deep {
        a {
          display: flex;
          align-items: center;
          img {
            height: 55px;
            cursor: pointer;
            display: block;
          }
          img:first-child {
            margin-right: 10px;
          }
          .big-logo {
            height: 55px;
          }
        }
      }
      .user {
        margin-left: auto;
        font-size: 14px;
        em {
          font-size: 14px;
          font-style: normal;
          padding: 0 14px;
        }
        .logout {
          cursor: pointer;
        }
      }
      .login-btn-box {
        margin-left: auto;
        display: flex;
        div {
          width: 72px;
          height: 24px;
          box-sizing: border-box;
          text-align: center;
          line-height: 24px;
          font-size: 12px;
          border-radius: 6px;
          margin-left: 10px;
          cursor: pointer;
        }
        .login {
          background: #aa1941;
          color: #fff;
          display: flex;
          justify-content: center;
        }
        .register {
          color: #333333;
          border: 1px solid #eaeaea;
          display: flex;
          justify-content: center;
        }
      }
      .language {
        margin-left: 24px;
        font-size: 14px;
        color: #333;
        cursor: pointer;
      }
    }
  }
  .max-width-content {
    width: 1200px;
    margin: 0 auto;
  }
  .head-nav-content {
    height: 72px;
    display: flex;
    align-items: center;
  }
}
</style>
