"use client" import { useState } from "react" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Users, Mail, Eye, Heart, Trophy, Star, MessageSquare, ImageIcon, Mic, TrendingUp, Brain, Zap, ExternalLink, Bot, Code, Database, Palette, Volume2, Search, BarChart3, Camera, Smartphone, Monitor, Globe, FileText, } from "lucide-react" import { useAuth } from "@/contexts/auth-context" import { LikeButton } from "@/components/like-button" import { AppDetailDialog } from "@/components/app-detail-dialog" interface TeamDetailDialogProps { open: boolean onOpenChange: (open: boolean) => void team: any } // 圖標映射函數 const getIconComponent = (iconName: string) => { const iconMap: { [key: string]: any } = { 'Brain': Brain, 'Bot': Bot, 'Code': Code, 'Database': Database, 'Palette': Palette, 'Volume2': Volume2, 'Search': Search, 'BarChart3': BarChart3, 'Mic': Mic, 'ImageIcon': ImageIcon, 'MessageSquare': MessageSquare, 'Zap': Zap, 'TrendingUp': TrendingUp, 'Camera': Camera, 'Smartphone': Smartphone, 'Monitor': Monitor, 'Globe': Globe, 'FileText': FileText, }; return iconMap[iconName] || Bot; } // App data for team apps - get from team data const getAppDetails = (appId: string, team: any) => { const appDetail = team.appsDetails?.find((app: any) => app.id === appId); if (appDetail) { return { id: appDetail.id, name: appDetail.name || "未命名應用", type: appDetail.type || "未知類型", description: appDetail.description || "無描述", icon: getIconComponent(appDetail.icon) || Brain, iconColor: appDetail.icon_color || "from-blue-500 to-purple-500", fullDescription: appDetail.description || "無描述", features: [], author: appDetail.creator_name || "未知作者", department: appDetail.creator_department || "未知部門", category: appDetail.category || "未分類", tags: [], demoUrl: "", sourceUrl: "", likes: appDetail.likes_count || 0, views: appDetail.views_count || 0, rating: Number(appDetail.rating) || 0, createdAt: appDetail.created_at }; } return { id: appId, name: "未命名應用", type: "未知類型", description: "無描述", icon: Brain, fullDescription: "無描述", features: [], author: "未知作者", category: "未分類", tags: [], demoUrl: "", sourceUrl: "", likes: 0, views: 0, rating: 0 }; } const getTypeColor = (type: string) => { const colors = { 文字處理: "bg-blue-100 text-blue-800 border-blue-200", 圖像生成: "bg-purple-100 text-purple-800 border-purple-200", 語音辨識: "bg-green-100 text-green-800 border-green-200", 推薦系統: "bg-orange-100 text-orange-800 border-orange-200", } return colors[type as keyof typeof colors] || "bg-gray-100 text-gray-800 border-gray-200" } export function TeamDetailDialog({ open, onOpenChange, team }: TeamDetailDialogProps) { const { getLikeCount, getViewCount, getAppRating } = useAuth() const [selectedTab, setSelectedTab] = useState("overview") const [selectedApp, setSelectedApp] = useState(null) const [appDetailOpen, setAppDetailOpen] = useState(false) if (!team) return null const leader = team.members.find((m: any) => m.user_id === team.leader) const handleAppClick = (appId: string) => { const appDetails = getAppDetails(appId, team) // Create app object that matches AppDetailDialog interface const app = { id: appId, // 保持為字符串,API 期望字符串 ID name: appDetails.name, type: appDetails.type, department: appDetails.department, // Use app's creator department description: appDetails.description, icon: appDetails.icon, iconColor: appDetails.iconColor, // Pass icon color creator: appDetails.author, featured: false, judgeScore: appDetails.rating || 0, // 使用 AppDetailDialog 期望的屬性名 likesCount: appDetails.likes || 0, viewsCount: appDetails.views || 0, rating: appDetails.rating || 0, reviewsCount: 0, // 可以從 API 獲取,暫時設為 0 createdAt: appDetails.createdAt, // Pass creation date } setSelectedApp(app) setAppDetailOpen(true) } // 使用從數據庫獲取的真實數據 const totalLikes = team.totalLikes || 0 const totalViews = team.totalViews || 0 return ( <> {team.name} 團隊詳細資訊與成員介紹
{/* Team Overview */} 團隊概覽
{team.members.length}
團隊成員
{team.apps.length}
提交應用
{totalLikes}
總按讚數
{totalViews}
總瀏覽數
{/* Tab Navigation */}
{/* Tab Content */} {selectedTab === "overview" && (
基本資訊

{team.name}

{team.department}

{leader?.name || '未指定'}

{team.contact_email || '未提供'}

競賽表現
{team.popularityScore}
人氣指數
{totalViews}
總瀏覽數
{totalLikes}
總按讚數
)} {selectedTab === "members" && ( 團隊成員 ({team.members.length}人)
{team.members.map((member: any, index: number) => (
{member.name[0]}

{member.name}

{member.id === team.leader && ( 隊長 )}

{member.role}

{member.department}

))}
)} {selectedTab === "apps" && ( 提交應用 ({team.apps.length}個)
{team.apps.map((appId: string) => { const app = getAppDetails(appId, team) // 如果沒有圖標,使用默認的 Brain 圖標 const IconComponent = app.icon || Brain const likes = app.likes || 0 const views = app.views || 0 const rating = app.rating || 0 return ( handleAppClick(appId)} >

{app.name}

{app.type}

{app.description}

{views}
{Number(rating).toFixed(1)}
e.stopPropagation()}>
) })}
)}
{/* App Detail Dialog */} {selectedApp && } ) }