<template>
  <div class="admin-layout">
    <header class="admin-header">
      <div class="header-title">管理后台</div>
      <el-dropdown>
        <div class="header-user">
          <span>{{ auth.user?.email }}</span>
          <el-icon><ArrowDown /></el-icon>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="logout">退出登入</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </header>
    <div class="admin-body">
      <aside class="admin-aside">
        <el-menu router :default-active="$route.path" background-color="#B80006" text-color="#fff" active-text-color="#FFD0D2">
          <el-menu-item index="/admin/dashboard">数据概览</el-menu-item>
          <el-menu-item index="/admin/jobs">职位管理</el-menu-item>
          <el-menu-item index="/admin/applications">投递管理</el-menu-item>
          <template v-if="auth.isSuperAdmin">
            <el-menu-item index="/admin/organizations">组织架构</el-menu-item>
            <el-menu-item index="/admin/users">用户管理</el-menu-item>
          </template>
          <el-menu-item index="/home">返回首页</el-menu-item>
        </el-menu>
      </aside>
      <main class="admin-main">
        <router-view />
      </main>
    </div>
  </div>
</template>
<script setup>
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { ArrowDown } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const router = useRouter()
const auth = useAuthStore()

function logout() {
  localStorage.clear()
  ElMessage.success('已退出登入')
  router.push({ name: 'Login' })
}
</script>
<style scoped>
.admin-layout {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.admin-header {
  height: 56px;
  flex-shrink: 0;
  background: #B80006;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid #333;
}
.header-title {
  color: #fff;
  font-weight: bold;
  font-size: 16px;
}
.header-user {
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.admin-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.admin-aside {
  width: 200px;
  flex-shrink: 0;
  background: #B80006;
  overflow-y: auto;
}
.admin-main {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f5f6fa;
}
</style>
