import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from "react";
import { ChevronDown, ChevronUp, Target, User } from "lucide-react";
import { formatTime } from "../utils";
import { MarkdownDisplay } from "../../components/MarkdownDisplay";
import { userMessageMarkdownComponents } from "./agentMessageMarkdown";
export const UserMessage = ({ message }) => {
    const content = message.content || "";
    const [isTriggerExpanded, setIsTriggerExpanded] = useState(false);
    const triggerPattern = /^\[Trigger: ([^\]]+)\]:\s*(.*)$/s;
    const triggerMatch = content.match(triggerPattern);
    const triggerName = triggerMatch?.[1]?.trim() || "";
    const triggerContent = triggerMatch?.[2] || "";
    const isTriggerMessage = triggerName.length > 0;
    if (isTriggerMessage) {
        return (_jsx("div", { className: "px-4 py-2", children: _jsxs("div", { className: "text-[11px]", children: [_jsxs("button", { type: "button", onClick: () => setIsTriggerExpanded((expanded) => !expanded), className: "text-theme-secondary hover:bg-theme-hover flex w-full items-center gap-2 rounded-md border-l-2 border-cyan-200 px-2 py-1 text-left transition-colors", "data-testid": "trigger-message-toggle", "data-expanded": isTriggerExpanded ? "true" : "false", children: [_jsx(Target, { className: "h-3.5 w-3.5 shrink-0", strokeWidth: 1.5 }), _jsxs("span", { className: "truncate font-medium", children: ["Trigger: ", triggerName] }), message.createdDate && (_jsx("span", { className: "ml-1 shrink-0 text-[10px] text-gray-400", children: formatTime(new Date(message.createdDate)) })), _jsx("span", { className: "ml-auto shrink-0", children: isTriggerExpanded ? (_jsx(ChevronUp, { className: "h-3.5 w-3.5" })) : (_jsx(ChevronDown, { className: "h-3.5 w-3.5" })) })] }), isTriggerExpanded && (_jsx("div", { className: "mt-1 border-l-2 border-cyan-100 pl-[1.35rem] text-[11px] text-gray-600", children: _jsx(MarkdownDisplay, { source: triggerContent, components: userMessageMarkdownComponents }) }))] }) }));
    }
    const fromPattern = /^\[From ([^\]]+)\]:\s*(.*)$/s;
    const match = content.match(fromPattern);
    let sourceAgentName;
    let displayContent = content;
    if (match && match[1]) {
        const extractedName = match[1];
        if (extractedName.toLowerCase() === "user") {
            sourceAgentName = undefined;
            displayContent = content;
        }
        else {
            sourceAgentName = extractedName;
            displayContent = match[2] || "";
        }
    }
    else {
        sourceAgentName =
            message.sourceAgentName ||
                message.metadata?.sourceAgentName ||
                message.sourceAgent?.name;
    }
    const displayName = sourceAgentName ? `[From ${sourceAgentName}]` : "You";
    return (_jsxs("div", { className: "flex gap-3 p-4", children: [_jsx("div", { className: "shrink-0", children: _jsx(User, { className: "text-theme-secondary h-5 w-5", strokeWidth: 1 }) }), _jsxs("div", { className: "min-w-0 flex-1 select-text", children: [_jsxs("div", { className: "mb-1 flex items-center gap-2", children: [_jsx("span", { className: "text-[12px] font-medium text-gray-900", children: displayName }), message.createdDate && (_jsx("span", { className: "text-[12px] text-gray-400", "data-testid": "user-message-timestamp", "data-timestamp": message.createdDate, children: formatTime(new Date(message.createdDate)) }))] }), _jsx("div", { className: "prose prose max-w-none text-[12px] text-gray-700 select-text", children: _jsx(MarkdownDisplay, { source: displayContent, components: userMessageMarkdownComponents }) })] })] }));
};
//# sourceMappingURL=UserMessage.js.map