import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Download, Trash2, Loader2, FileText } from "lucide-react"; import type { TemplateComponent } from "@/types/template"; interface ComponentCardProps { component: TemplateComponent; onInstall: () => Promise; onUninstall: () => Promise; onViewDetail: () => void; } // 组件类型图标映射 const componentTypeIcons: Record = { agent: "🤖", command: "⚡", mcp: "🔌", setting: "⚙️", hook: "🪝", skill: "💡", }; export function ComponentCard({ component, onInstall, onUninstall, onViewDetail, }: ComponentCardProps) { const { t } = useTranslation(); const [loading, setLoading] = useState(false); const handleInstall = async () => { setLoading(true); try { await onInstall(); } finally { setLoading(false); } }; const handleUninstall = async () => { setLoading(true); try { await onUninstall(); } finally { setLoading(false); } }; const typeIcon = componentTypeIcons[component.componentType] || "📦"; return (
{typeIcon}
{component.name} {component.category && ( {component.category} )}
{component.installed && ( {t("templates.installed", { defaultValue: "已安装" })} )}

{component.description || t("templates.noDescription", { defaultValue: "暂无描述" })}

{component.installed ? ( ) : ( )} ); }