<template>
  <div class="admin-container">
    <!-- 页面标题 -->
    <el-breadcrumb separator="/" class="breadcrumb">
      <el-breadcrumb-item><router-link to="/">首页</router-link></el-breadcrumb-item>
      <el-breadcrumb-item>管理员中心</el-breadcrumb-item>
    </el-breadcrumb>
    
    <div class="admin-content">
      <!-- 侧边栏 -->
      <aside class="admin-sidebar">
        <el-menu
          :default-active="activeMenu"
          class="sidebar-menu"
          @select="handleMenuSelect"
        >
          <el-menu-item index="/admin/algorithms">
            <template #icon>
              <div class="menu-icon algorithms-icon">
                <el-icon><data-analysis /></el-icon>
              </div>
            </template>
            <span>算法仓库管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/services">
            <template #icon>
              <div class="menu-icon services-icon">
                <el-icon><cpu /></el-icon>
              </div>
            </template>
            <span>算法服务管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/api">
            <template #icon>
              <div class="menu-icon api-icon">
                <el-icon><link /></el-icon>
              </div>
            </template>
            <span>API管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/users">
            <template #icon>
              <div class="menu-icon users-icon">
                <el-icon><user /></el-icon>
              </div>
            </template>
            <span>用户管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/config">
            <template #icon>
              <div class="menu-icon config-icon">
                <el-icon><setting /></el-icon>
              </div>
            </template>
            <span>配置管理</span>
          </el-menu-item>

        </el-menu>
      </aside>
      
      <!-- 主内容区 -->
      <main class="admin-main">
        <router-view v-slot="{ Component }">
          <transition name="fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </main>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { DataAnalysis, User, Link, Cpu, Setting } from '@element-plus/icons-vue'

// 获取路由和路由器
const route = useRoute()
const router = useRouter()

// 计算当前激活的菜单
const activeMenu = computed(() => {
  return route.path
})

// 处理菜单选择
const handleMenuSelect = (key: string) => {
  router.push(key)
}
</script>

<style scoped>
.admin-container {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.breadcrumb {
  margin-bottom: 20px;
}

.admin-content {
  display: flex;
  gap: 20px;
}

.admin-sidebar {
  width: 140px;
  min-width: 140px;
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  padding: 16px 8px;
}

.sidebar-menu {
  border-right: none;
  background: transparent;
}

.sidebar-menu .el-menu-item {
  height: 48px;
  line-height: 48px;
  margin: 4px 0;
  border-radius: 10px;
  transition: all 0.3s ease;
}

.sidebar-menu .el-menu-item:hover {
  background-color: #f5f7fa;
}

.sidebar-menu .el-menu-item.is-active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}

.sidebar-menu .el-menu-item.is-active .el-icon {
  color: #fff;
}

.sidebar-menu .el-menu-item .el-icon {
  font-size: 20px;
  margin-right: 12px;
}

.menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  margin-right: 10px;
}

.algorithms-icon {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.services-icon {
  background: linear-gradient(135deg, #409eff 0%, #67c23a 100%);
  color: white;
}

.api-icon {
  background: linear-gradient(135deg, #e6a23c 0%, #f56c6c 100%);
  color: white;
}

.users-icon {
  background: linear-gradient(135deg, #909399 0%, #c0c4cc 100%);
  color: white;
}

.config-icon {
  background: linear-gradient(135deg, #f3514e 0%, #f78955 100%);
  color: white;
}

.admin-main {
  flex: 1;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 20px;
  min-height: 600px;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

@media (max-width: 768px) {
  .admin-content {
    flex-direction: column;
  }
  
  .admin-sidebar {
    width: 100%;
  }
  
  .sidebar-menu {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
  }
  
  .admin-main {
    min-height: 400px;
  }
}
</style>
