import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from "react";
import { ChevronDown, ChevronUp, CornerDownRight, Copy, GripVertical, Info, ListTree, MoreHorizontal, Target, } from "lucide-react";
import { DeleteIcon } from "../../../../components/ui/delete-icon";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "../../../../components/ui/dropdown-menu";
import { formatDateTime, formatTime } from "../../../utils";
import { TimeWithTooltip } from "../../TimeWithTooltip";
export const QueuedPromptsPanel = ({ queuedPrompts, onPushQueuedPrompt, onDeleteQueuedPrompt, pushDisabled = false, deleteDisabled = false, }) => {
    const [expandedQueuedTriggerIds, setExpandedQueuedTriggerIds] = useState({});
    const [expandedDetailIds, setExpandedDetailIds] = useState({});
    if (queuedPrompts.length === 0)
        return null;
    return (_jsx("div", { className: "border-border-default border-t bg-white", "data-testid": "queued-prompts-section", children: _jsx("div", { className: "px-3 py-2.5", children: _jsx("div", { className: "border-border-default divide-border-default max-h-64 divide-y overflow-y-auto rounded-lg border bg-white", children: queuedPrompts.map((qp) => {
                    let triggerName = "";
                    if (qp.data) {
                        try {
                            const parsed = JSON.parse(qp.data);
                            triggerName = parsed?.triggerName?.trim() || "";
                        }
                        catch {
                            // Ignore invalid JSON metadata and render as regular queued prompt.
                        }
                    }
                    const isTriggerQueuedPrompt = !qp.sourceAgentName && triggerName.length > 0;
                    const isTriggerExpanded = !!expandedQueuedTriggerIds[qp.id];
                    if (isTriggerQueuedPrompt) {
                        return (_jsxs("div", { className: "text-[11px]", "data-testid": "queued-prompt-item", children: [_jsxs("div", { className: "hover:bg-neutral-grey-5 flex items-center gap-1 px-1 transition-colors", children: [_jsxs("button", { type: "button", onClick: () => setExpandedQueuedTriggerIds((prev) => ({
                                                ...prev,
                                                [qp.id]: !prev[qp.id],
                                            })), className: "text-neutral-grey-100 flex min-w-0 flex-1 items-center gap-1.5 rounded px-1.5 py-1 text-left", "data-testid": "queued-trigger-toggle", "data-expanded": isTriggerExpanded ? "true" : "false", children: [_jsx(Target, { className: "text-neutral-grey-50 h-3.5 w-3.5 shrink-0", strokeWidth: 1.75 }), _jsx("span", { className: "truncate font-medium", children: triggerName }), qp.createdDate && (_jsx(TimeWithTooltip, { date: new Date(qp.createdDate), className: "text-neutral-grey-50 ml-1 shrink-0 text-[10px]" })), _jsx("span", { className: "text-neutral-grey-50 ml-auto shrink-0", children: isTriggerExpanded ? (_jsx(ChevronUp, { className: "h-3 w-3" })) : (_jsx(ChevronDown, { className: "h-3 w-3" })) })] }), onDeleteQueuedPrompt ? (_jsx("button", { type: "button", className: "text-neutral-grey-50 hover:text-neutral-grey-100 hover:bg-neutral-grey-10 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded transition-colors disabled:cursor-not-allowed disabled:opacity-50", title: "Delete queued prompt", "aria-label": "Delete queued prompt", "data-testid": "queued-prompt-delete-button", disabled: deleteDisabled, onClick: () => onDeleteQueuedPrompt(qp), children: _jsx(DeleteIcon, { size: "md" }) })) : null] }), isTriggerExpanded && (_jsx("div", { className: "border-neutral-grey-10 text-neutral-grey-50 mt-0.5 border-l-2 pl-5 text-[11px]", children: qp.prompt }))] }, qp.id));
                    }
                    const isDetailExpanded = !!expandedDetailIds[qp.id];
                    const hasSchedule = qp.scheduledFor &&
                        new Date(qp.scheduledFor).getTime() >
                            new Date(qp.createdDate || 0).getTime() + 1000;
                    return (_jsxs("div", { className: "group/qp", "data-testid": "queued-prompt-item", children: [_jsxs("div", { className: "hover:bg-neutral-grey-5 relative flex items-center gap-2 px-2.5 py-2 transition-colors", children: [_jsx("span", { className: "text-neutral-grey-50 -ml-1.5 flex h-4 w-3 shrink-0 cursor-grab items-center justify-center opacity-0 transition-opacity group-hover/qp:opacity-100", "aria-hidden": "true", children: _jsx(GripVertical, { className: "h-3.5 w-3.5", strokeWidth: 1.75 }) }), _jsx(ListTree, { className: "text-neutral-grey-50 h-4 w-4 shrink-0", strokeWidth: 1.75 }), _jsx("span", { className: "text-neutral-grey-100 min-w-0 flex-1 truncate text-[13px]", "data-testid": "queued-prompt-text", title: qp.prompt, children: qp.prompt }), _jsxs("div", { className: "text-neutral-grey-50 flex shrink-0 items-center gap-1", children: [onPushQueuedPrompt ? (_jsxs("button", { type: "button", className: "hover:text-neutral-grey-100 hover:bg-neutral-grey-10 inline-flex h-7 items-center gap-1 rounded px-2 text-[13px] transition-colors disabled:cursor-not-allowed disabled:opacity-50", title: "Steer the agent with this prompt now", "aria-label": "Steer the agent with this prompt now", "data-testid": "queued-prompt-push-button", disabled: pushDisabled, onClick: () => onPushQueuedPrompt(qp), children: [_jsx(CornerDownRight, { className: "h-3.5 w-3.5", strokeWidth: 1.75 }), "Steer"] })) : null, onDeleteQueuedPrompt ? (_jsx("button", { type: "button", className: "hover:text-neutral-grey-100 hover:bg-neutral-grey-10 inline-flex h-7 w-7 items-center justify-center rounded transition-colors disabled:cursor-not-allowed disabled:opacity-50", title: "Delete queued prompt", "aria-label": "Delete queued prompt", "data-testid": "queued-prompt-delete-button", disabled: deleteDisabled, onClick: () => onDeleteQueuedPrompt(qp), children: _jsx(DeleteIcon, { size: "md" }) })) : null, _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { type: "button", className: "hover:text-neutral-grey-100 hover:bg-neutral-grey-10 data-[state=open]:bg-neutral-grey-10 data-[state=open]:text-neutral-grey-100 inline-flex h-7 w-7 items-center justify-center rounded transition-colors", title: "More actions", "aria-label": "More actions", "data-testid": "queued-prompt-more-button", children: _jsx(MoreHorizontal, { className: "h-4 w-4", strokeWidth: 1.75 }) }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-44", children: [_jsxs(DropdownMenuItem, { onSelect: () => {
                                                                    void navigator.clipboard?.writeText(qp.prompt);
                                                                }, children: [_jsx(Copy, {}), "Copy prompt"] }), _jsxs(DropdownMenuItem, { onSelect: () => setExpandedDetailIds((prev) => ({
                                                                    ...prev,
                                                                    [qp.id]: !prev[qp.id],
                                                                })), children: [_jsx(Info, {}), isDetailExpanded ? "Hide details" : "Show details"] })] })] })] })] }), isDetailExpanded && (_jsxs("div", { className: "border-neutral-grey-10 text-neutral-grey-50 mt-0.5 mb-1 ml-6 border-l pl-3 text-[11px]", children: [_jsxs("div", { className: "mb-1 flex flex-wrap items-center gap-x-2 gap-y-0.5", children: [_jsx("span", { className: "text-neutral-grey-100 font-medium", children: qp.sourceAgentName
                                                    ? `From ${qp.sourceAgentName}`
                                                    : "From User" }), qp.priority > 5 && (_jsx("span", { className: "bg-feedback-red-light badge-pad-sm text-feedback-red rounded text-[10px] font-medium", children: "High Priority" })), qp.createdDate && (_jsxs("span", { children: ["Queued", " ", _jsx(TimeWithTooltip, { date: new Date(qp.createdDate) })] })), hasSchedule && (_jsxs("span", { className: "text-feedback-orange font-medium", children: ["Scheduled for", " ", new Date(qp.scheduledFor).toDateString() ===
                                                        new Date().toDateString()
                                                        ? formatTime(new Date(qp.scheduledFor))
                                                        : formatDateTime(new Date(qp.scheduledFor))] }))] }), _jsx("div", { className: "wrap-break-word whitespace-pre-wrap", children: qp.prompt })] }))] }, qp.id));
                }) }) }) }));
};
//# sourceMappingURL=QueuedPromptsPanel.js.map