<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>
              <el-icon><data-analysis /></el-icon>
            </template>
            <span>算法仓库管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/services">
            <template #icon>
              <el-icon><cpu /></el-icon>
            </template>
            <span>算法服务管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/api">
            <template #icon>
              <el-icon><link /></el-icon>
            </template>
            <span>API管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/users">
            <template #icon>
              <el-icon><user /></el-icon>
            </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 } 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: 200px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

.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>
