"use client" import { useCompetition } from "@/contexts/competition-context" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Users, Bot, Trophy, TrendingUp, Eye, Heart, MessageSquare, Award, Activity, Loader2 } from "lucide-react" import { useState, useEffect } from "react" interface DashboardStats { totalUsers: number activeUsers: number totalApps: number totalCompetitions: number totalReviews: number totalViews: number totalLikes: number newAppsThisMonth: number activeCompetitions: number growthRate: number } interface RecentActivity { id: string type: string message: string time: string icon: string color: string } interface TopApp { id: string name: string description: string views: number likes: number rating: number category: string created_at: string } export function AdminDashboard() { const { competitions } = useCompetition() const [stats, setStats] = useState({ totalUsers: 0, activeUsers: 0, totalApps: 0, totalCompetitions: 0, totalReviews: 0, totalViews: 0, totalLikes: 0, newAppsThisMonth: 0, activeCompetitions: 0, growthRate: 0 }) const [recentActivities, setRecentActivities] = useState([]) const [topApps, setTopApps] = useState([]) const [isLoading, setIsLoading] = useState(true) useEffect(() => { loadDashboardData() }, []) const loadDashboardData = async () => { try { setIsLoading(true) const response = await fetch('/api/admin/dashboard') const data = await response.json() if (data.success) { setStats(data.data.stats) setRecentActivities(data.data.recentActivities) setTopApps(data.data.topApps) } } catch (error) { console.error('載入儀表板數據錯誤:', error) } finally { setIsLoading(false) } } const getActivityIcon = (iconName: string) => { const iconMap: { [key: string]: any } = { 'Users': Users, 'Bot': Bot, 'Trophy': Trophy, 'Activity': Activity, 'Eye': Eye, 'Heart': Heart, 'MessageSquare': MessageSquare, 'Award': Award } return iconMap[iconName] || Activity } return (
{/* Welcome Section */}

管理儀表板

歡迎回到 AI 展示平台管理後台

{/* Stats Cards */}
總用戶數 {isLoading ? (
載入中...
) : ( <>
{stats.totalUsers}

活躍用戶 {stats.activeUsers} 人

)}
AI 應用數 {isLoading ? (
載入中...
) : ( <>
{stats.totalApps}

本月新增 {stats.newAppsThisMonth} 個應用

)}
競賽活動 {isLoading ? (
載入中...
) : ( <>
{stats.totalCompetitions}

{stats.activeCompetitions} 個進行中

)}
總瀏覽量 {isLoading ? (
載入中...
) : ( <>
{stats.totalViews.toLocaleString()}

{stats.growthRate > 0 ? `比上月增長 ${stats.growthRate}%` : '與上月持平'}

)}
{/* Recent Activities */} 最新活動 系統最新動態 {isLoading ? (
載入中...
) : recentActivities.length > 0 ? (
{recentActivities.map((activity) => { const IconComponent = getActivityIcon(activity.icon) return (

{activity.message}

{activity.time}

) })}
) : (

暫無最新活動

)}
{/* Top Performing Apps */} 熱門應用 表現最佳的 AI 應用 {isLoading ? (
載入中...
) : topApps.length > 0 ? (
{topApps.map((app, index) => (

{app.name}

{app.description}

{app.views}
{app.likes}
{app.category}
{app.rating} ⭐
))}
) : (

暫無應用數據

)}
{/* Quick Actions */} 快速操作 常用管理功能
) }