<script setup lang="ts">
import { useUserStore } from '@/store/modules/user'
import { useAppStore } from '@/store/modules/app'
import ThemeToggle from '@/components/ThemeToggle/index.vue'

const userStore = useUserStore()
const appStore = useAppStore()

function logout() {
  userStore.logout()
}
</script>

<template>
  <header class="header">
    <div class="header-left">
      <el-icon class="collapse-btn" @click="appStore.toggleSidebar()">
        <Operation />
      </el-icon>
    </div>
    <div class="header-right">
      <ThemeToggle />
      <el-dropdown>
        <div class="user-info">
          <el-icon>
            <User />
          </el-icon>
          <span>{{ userStore.name || 'admin' }}</span>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item divided @click="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </header>
</template>

<style scoped lang="scss">
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  height: 100%;
  padding: 0 20px;
  color: var(--admin-text-primary);

  .title {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    color: var(--admin-text-primary);
  }

  .header-left {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .collapse-btn {
    cursor: pointer;
    font-size: 20px;
    color: var(--admin-text-secondary);

    &:hover {
      color: var(--admin-text-primary);
    }
  }

  .header-right {
    display: flex;
    gap: 40px;
  }

  .user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--admin-text-secondary);

    &:hover {
      color: var(--admin-text-primary);
    }
  }
}
</style>
