<template>
  <div class="navbar">
    <breadcrumb v-if="!topNav" id="breadcrumb-container" class="breadcrumb-container" />
    <top-nav v-if="topNav" id="topmenu-container" class="topmenu-container" />

    <div class="right-menu">
      <template v-if="device!=='mobile'">
 

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

        <el-tooltip content="布局大小" effect="dark" placement="bottom">
          <size-select id="size-select" class="right-menu-item hover-effect" />
        </el-tooltip>

      </template>

      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="hover">
        <div class="avatar-wrapper">
          <img :src="avatar" class="user-avatar">
          <span class="user-nickname"> {{ nickName }} </span>
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/user/profile">
            <el-dropdown-item>个人中心</el-dropdown-item>
          </router-link>
          <el-dropdown-item divided @click.native="logout">
            <span>退出登录</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>

      <div class="right-menu-item hover-effect setting" @click="setLayout" v-if="setting">
        <svg-icon icon-class="more-up" />
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import TopNav from '@/components/TopNav'
import Screenfull from '@/components/Screenfull'
import SizeSelect from '@/components/SizeSelect'
import Search from '@/components/HeaderSearch'
import RuoYiGit from '@/components/RuoYi/Git'
import RuoYiDoc from '@/components/RuoYi/Doc'

export default {
  emits: ['setLayout'],
  components: {
    Breadcrumb,
    TopNav,
    Screenfull,
    SizeSelect,
    Search,
    RuoYiGit,
    RuoYiDoc
  },
  computed: {
    ...mapGetters([
      'avatar',
      'device',
      'nickName'
    ]),
    setting: {
      get() {
        return this.$store.state.settings.showSettings
      }
    },
    topNav: {
      get() {
        return this.$store.state.settings.topNav
      }
    }
  },
  methods: {
    setLayout(event) {
      this.$emit('setLayout')
    },
    logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          this.$router.push('/login')
        })
      }).catch(() => {})
    }
  }
}
</script>

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

  // 移动端优化
  @media (max-width: 768px) {
    height: 48px;
    padding: 0 5px;
  }

  .breadcrumb-container {
    float: left;
    
    @media (max-width: 768px) {
      display: none; // 移动端隐藏面包屑
    }
  }

  .topmenu-container {
    position: absolute;
    left: 0;
    
    @media (max-width: 768px) {
      left: 0;
    }
  }

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

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;
    display: flex;
    align-items: center;
    gap: 5px;

    @media (max-width: 768px) {
      line-height: 48px;
      gap: 2px;
    }

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 0 8px;
      height: 100%;
      min-width: 44px; // 增大触摸目标
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      @media (max-width: 768px) {
        padding: 0 6px;
        font-size: 16px;
        min-width: 40px;
      }

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

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
        
        &:active {
          background: rgba(0, 0, 0, .05)
        }
      }
    }

    .avatar-container {
      margin-right: 0px;
      padding-right: 0px;

      @media (max-width: 768px) {
        margin-right: 0;
      }

      .avatar-wrapper {
        margin-top: 10px;
        position: relative;
        display: flex;
        align-items: center;
        gap: 6px;
        cursor: pointer;
        padding: 0 4px;
        min-height: 44px; // 增大触摸目标

        @media (max-width: 768px) {
          margin-top: 8px;
          gap: 4px;
        }

        .user-avatar {
          cursor: pointer;
          width: 30px;
          height: 30px;
          border-radius: 50%;
          flex-shrink: 0;

          @media (max-width: 768px) {
            width: 28px;
            height: 28px;
          }
        }

        .user-nickname{
          position: relative;
          font-size: 14px;
          font-weight: bold;
          white-space: nowrap;
          max-width: 80px;
          overflow: hidden;
          text-overflow: ellipsis;

          @media (max-width: 768px) {
            font-size: 13px;
            max-width: 60px;
            display: none; // 移动端隐藏昵称
          }
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          font-size: 12px;
          flex-shrink: 0;

          @media (max-width: 768px) {
            font-size: 10px;
          }
        }
      }
    }
    
    .setting {
      @media (max-width: 768px) {
        display: none; // 移动端隐藏设置按钮
      }
    }
  }
}
</style>
