"use client"; import React, { useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/utils"; import { Suggestion, SuggestionType, SUGGESTION_TYPE_CONFIG, PRIORITY_CONFIG, DIFFICULTY_CONFIG, STATUS_CONFIG, } from "@/types/suggestion"; import { FileText, Monitor, GitCompare, Search, Quote, ChevronDown, ChevronUp, Check, X, Play, RefreshCw, Loader2, Lightbulb, } from "lucide-react"; // 类型图标映射 const TYPE_ICONS: Record = { content_optimization: , platform_targeting: , competitor_gap: , query_expansion: , citation_improvement: , }; interface SuggestionCardProps { suggestion: Suggestion; brandId: string; onStatusChange?: (suggestionId: string, newStatus: string) => void; compact?: boolean; } /** * 单条优化建议卡片组件 */ export function SuggestionCard({ suggestion, brandId: _brandId, onStatusChange, compact = false, }: SuggestionCardProps) { const [expanded, setExpanded] = useState(false); const [loading, setLoading] = useState(false); const typeConfig = SUGGESTION_TYPE_CONFIG[suggestion.type]; const priorityConfig = PRIORITY_CONFIG[suggestion.priority]; const difficultyConfig = DIFFICULTY_CONFIG[suggestion.difficulty]; const statusConfig = STATUS_CONFIG[suggestion.status]; const handleStatusChange = async (newStatus: string) => { setLoading(true); try { await onStatusChange?.(suggestion.id, newStatus); } finally { setLoading(false); } }; const isCompleted = suggestion.status === "completed"; const isDismissed = suggestion.status === "dismissed"; const _isInProgress = suggestion.status === "in_progress"; return (
{/* 类型图标 */}
{TYPE_ICONS[suggestion.type]}
{/* 内容区域 */}
{/* 标题行 */}
{typeConfig.label} {priorityConfig.label} {statusConfig.label} {suggestion.source === "llm" && ( AI生成 )}
{/* 标题 */}

{suggestion.title}

{/* 描述 */}

{suggestion.description}

{/* 展开区域 */} {expanded && (
{/* 操作步骤 */} {suggestion.action && (
操作步骤
{suggestion.action}
)} {/* 预期效果 */} {suggestion.expected_impact && (
预期效果

{suggestion.expected_impact}

)} {/* 难度 */}
难度: {difficultyConfig.label}
)} {/* 操作按钮 */}
{/* 展开/收起 */} {!compact && (suggestion.action || suggestion.expected_impact) && ( )} {/* 状态操作按钮 */} {suggestion.status === "pending" && ( )} {suggestion.status === "in_progress" && ( )} {suggestion.status === "pending" && ( )}
); } interface SuggestionListProps { suggestions: Suggestion[]; brandId: string; onStatusChange?: (suggestionId: string, newStatus: string) => void; loading?: boolean; onRegenerate?: () => void; className?: string; compact?: boolean; maxItems?: number; } /** * 优化建议列表组件 */ export function SuggestionList({ suggestions, brandId, onStatusChange, loading = false, onRegenerate, className, compact = false, maxItems, }: SuggestionListProps) { const displaySuggestions = maxItems ? suggestions.slice(0, maxItems) : suggestions; if (loading) { return ( 优化建议
{[1, 2, 3].map((i) => (
))}
); } return (
优化建议 {suggestions.length > 0 && ( {suggestions.length} )} {onRegenerate && ( )}
{displaySuggestions.length === 0 ? (

暂无优化建议

) : (
{displaySuggestions.map((suggestion) => ( ))} {maxItems && suggestions.length > maxItems && ( )}
)}
); }