"use client"; import React from "react"; import Link from "next/link"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import type { ActionItemProps, NextAction, NextActionCardProps } from "@/types/next-action"; import { Target, Lightbulb, Bell } from "lucide-react"; // 优先级图标映射 const PRIORITY_ICONS: Record = { primary: , secondary: , optional: , }; // 优先级标签映射 const PRIORITY_LABELS: Record = { primary: "主要", secondary: "次要", optional: "可选", }; // 优先级颜色配置 const PRIORITY_COLORS: Record = { primary: { border: "border-l-4 border-l-orange-500 border-orange-200", bg: "bg-orange-50", icon: "text-orange-500", }, secondary: { border: "border-l-4 border-l-blue-500 border-blue-200", bg: "bg-blue-50", icon: "text-blue-500", }, optional: { border: "border-l-4 border-l-gray-400 border-gray-200", bg: "bg-gray-50", icon: "text-gray-500", }, }; /** * 单个行动项组件 */ function ActionItem({ action, onClick }: ActionItemProps) { const colors = PRIORITY_COLORS[action.priority]; return (
{/* 优先级图标 */}
{PRIORITY_ICONS[action.priority]}
{/* 内容区域 */}
{/* 标题和描述 */}
{PRIORITY_LABELS[action.priority]} {action.icon}

{action.title}

{action.description}

{/* 操作按钮 */}
{action.actionUrl.startsWith("/") ? ( ) : ( )}
); } /** * 下一步行动建议卡片组件 */ export function NextActionCard({ context, className, onActionClick }: NextActionCardProps) { // 动态导入以避免循环依赖 const [actions, setActions] = React.useState([]); const [loading, setLoading] = React.useState(true); React.useEffect(() => { async function loadActions() { try { const { generateNextActions } = await import("@/lib/next-action"); const generatedActions = generateNextActions(context); setActions(generatedActions); } catch (error) { console.error("生成行动建议失败:", error); } finally { setLoading(false); } } loadActions(); }, [context]); if (loading) { return ( 为您推荐的下一步行动
{[1, 2, 3].map((i) => (
))}
); } if (actions.length === 0) { return null; } return ( 为您推荐的下一步行动
{actions.map((action) => ( onActionClick?.(action)} /> ))}
); } export { ActionItem };