<template>
  <div class="navbar">
    <hamburger
      id="hamburger-container"
      :is-active="sidebar.opened"
      class="hamburger-container"
      @toggleClick="toggleSideBar"
    />

    <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />

    <div class="right-menu">
      <template v-if="device !== 'mobile'">
        <!-- <search id="header-search" class="right-menu-item" />

        <error-log class="errLog-container right-menu-item hover-effect" /> -->

        <screenfull id="screenfull" class="right-menu-item hover-effect" />

        <!-- <lang-select class="right-menu-item hover-effect" /> -->
      </template>

      <el-dropdown
        class="avatar-container right-menu-item hover-effect"
        trigger="click"
      >
        <div class="avatar-wrapper">
          <img
            src="/pic/common/logo@2x.png"
            alt=""
            style="height:30px; width:auto;margin-left:10px;margin-right:10px;"
          />
          <i class="el-icon-caret-bottom" />
          <div class="user-nick"><span v-if="adminPhone">{{ adminPhone | maskPhone }}</span></div>
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/">
            <el-dropdown-item>
              {{ $t('navbar.dashboard') }}
            </el-dropdown-item>
          </router-link>
          <el-dropdown-item divided @click.native="showAdminEditDialog">
            {{ $t('navbar.modify') }}
          </el-dropdown-item>
          <el-dropdown-item divided @click.native="logout">
            <span style="display:block;">{{ $t('navbar.logOut') }}</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <AdminInfoDialog></AdminInfoDialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import AdminInfoDialog from '@/components/AdminInfoDialog'
// import ErrorLog from '@/components/ErrorLog'
import Screenfull from '@/components/Screenfull'
import { maskPhone } from '@/filters'
// import SizeSelect from '@/components/SizeSelect'
// import LangSelect from '@/components/LangSelect'
// import Search from '@/components/HeaderSearch'

export default {
  components: {
    Breadcrumb,
    Hamburger,
    AdminInfoDialog,
    // ErrorLog,
    Screenfull
    // SizeSelect,
    // LangSelect,
    // Search
  },
  filters: {
    maskPhone
  },
  computed: {
    ...mapGetters(['sidebar', 'avatar', 'device']),
    adminPhone() {
      return this.$store.state['admin-info'].adminInfo.phone
    }
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    },
    showAdminEditDialog() {
      this.$store.dispatch('admin-info/initAdminInfo', true)
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/styles/mixin.scss';

.navbar {
  height: 64px;
  overflow: hidden;
  position: relative;
  //@include linearGradient(-90deg, #3660a5, #234c90);
  @include linearGradient(90deg, #3660A5 0%, #234C90 100%);
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);

  .hamburger-container {
    line-height: 56px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 64px;
    // background-image: url('/pic/layout/navbar_bg@2x.png');
    background-size: 100%;
    background-repeat: no-repeat;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #fff;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        height: 100%;

        .user-avatar {
          display: block;
          cursor: pointer;
          width: 43px;
          height: 43px;
          border-radius: 50%;
          margin-right: 14px;
        }

        .user-nick {
          font-size: 14px;
          font-weight: 400;
          color: #ffffff;
          line-height: 20px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }

    .version-container {
      display: inline-block;
      height: 100%;
      margin-right: 24px;
      vertical-align: text-bottom;

      .inner {
        display: flex;
        align-content: center;
        justify-content: flex-start;
        flex-flow: row wrap;
        width: 75px;
        height: 25px;
        background: #184186;
        border-radius: 5px;
        padding: 0 6px;
        margin-top: 20px;

        .title {
          color: #fff;
          font-size: 14px;
        }

        .diamond {
          font-size: 14px;
          margin-right: 6px;
        }
      }
    }
  }
  &::v-deep .el-breadcrumb__inner a {
    color: #1890ff;
  }
}
</style>
