<template>
  <el-container style="min-height: 100vh">
    <el-aside width="220px" style="background: #304156">
      <div class="logo">笑话管理后台</div>
      <el-menu
        :default-active="$route.path"
        :unique-opened="true"
        background-color="#304156"
        text-color="#bfcbd9"
        active-text-color="#409EFF"
        router
      >
        <el-sub-menu index="/dashboard">
          <template #title>
            <span>首页</span>
          </template>
          <el-menu-item index="/dashboard">仪表盘</el-menu-item>
        </el-sub-menu>

        <el-sub-menu index="/content">
          <template #title>
            <span>内容管理</span>
          </template>
          <el-menu-item index="/jokes">笑话管理</el-menu-item>
          <el-menu-item index="/category/type">类型管理</el-menu-item>
          <el-menu-item index="/category/crowd">人群管理</el-menu-item>
        </el-sub-menu>

        <el-sub-menu index="/system">
          <template #title>
            <span>系统管理</span>
          </template>
          <el-menu-item index="/settings">AI 配置</el-menu-item>
          <el-menu-item index="/links">友链管理</el-menu-item>
          <el-menu-item index="/feedbacks">反馈管理</el-menu-item>
          <el-menu-item index="/users">用户管理</el-menu-item>
        </el-sub-menu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header style="display: flex; align-items: center; justify-content: flex-end; border-bottom: 1px solid #e6e6e6">
        <el-button @click="handleLogout" size="small">退出登录</el-button>
      </el-header>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'

const router = useRouter()
const authStore = useAuthStore()

const handleLogout = () => {
  authStore.logout()
  router.push('/login')
}
</script>

<style scoped>
.logo {
  height: 60px;
  line-height: 60px;
  text-align: center;
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  background: #2b3a4a;
  letter-spacing: 2px;
}
.el-aside {
  background: #304156;
}
/* 多级菜单样式 */
:deep(.el-sub-menu__title) {
  font-size: 14px;
  font-weight: 600;
}
:deep(.el-menu-item) {
  font-size: 13px;
  padding-left: 54px !important;
}
:deep(.el-menu-item.is-active) {
  background-color: #263445 !important;
}
:deep(.el-sub-menu .el-menu-item) {
  min-width: 0;
  height: 44px;
  line-height: 44px;
}
</style>
