<template>
  <div class="navbar">
    <!-- 汉堡 -->
    <hamburger class="hamburger" />
    <breadcrumb id="guide-breadcrumb" class="breadcrumb-container" />
    <div class="right-menu">
      <!-- <header-search
        id="guide-search"
        class="right-menu-item hover-effect"
      ></header-search> -->
      <screenfull class="right-menu-item hover-effect"></screenfull>
      <!-- 头像 -->
      <el-dropdown class="avatar-container" trigger="click">
        <div class="avatar-wrapper">
          <img
            style="
              width: 30px;
              height: 30px;
              border: 1px solid #ddd;
              border-radius: 50%;
            "
            :src="headImgUrl"
          />
        </div>
        <template #dropdown>
          <el-dropdown-menu class="user-dropdown">
            <router-link to="/">
              <el-dropdown-item>主页</el-dropdown-item>
            </router-link>
            <el-dropdown-item divided @click="logout"
              >退出登录</el-dropdown-item
            >
            <el-dropdown-item @click="changePwd">修改密码</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
      <div class="username">
        欢迎回来，{{
          $store.getters.userInfo.username
            ? $store.getters.userInfo.username
            : '管理员'
        }}
      </div>
    </div>
  </div>
</template>

<script setup>
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import Hamburger from '@/components/Hamburger'
import Breadcrumb from '@/components/Breadcrumb'
import Screenfull from '@/components/Screenfull/index'
import defaultHeadImg from '@/assets/images/defaultHeadImg.jpg'
// import HeaderSearch from '@/components/HeaderSearch/index'

const store = useStore()
const logout = () => {
  store.dispatch('user/logout')
}

const router = useRouter()
const changePwd = () => {
  router.push('/user/changePwd')
}

const headImgUrl = store.getters.userInfo.headImgUrl
  ? store.getters.userInfo.headImgUrl
  : defaultHeadImg
</script>

<style lang="scss" scoped>
.username {
  padding-left: 18px;
}
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    //hover动画
    transition: background 0.5s;
    &:hover {
      background: rgba($color: #000000, $alpha: 0.1);
    }
  }

  .right-menu {
    display: flex;
    align-items: center;
    flex: right;
    padding-right: 16px;
    float: right;

    :deep(.right-menu-item) {
      display: inline-block;
      padding: 0 18px 0 0;
      font-size: 24px;
      color: #5a5e66;
      vertical-align: text-bottom;
      &.hover-effect {
        cursor: pointer;
      }
    }

    :deep(.avatar-container) {
      cursor: pointer;
      .avatar-wrapper {
        margin-top: 5px;
        position: relative;
        .el-avatar {
          --el-avatar-background-color: none;
          margin-right: 12px;
        }
      }
    }
  }
}
</style>
