import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState } from "react";
import { ChevronDown, ChevronUp, Play, Target } from "lucide-react";
import { DeleteIcon } from "../../../../components/ui/delete-icon";
import { formatDateTime, formatTime } from "../../../utils";
import { TimeWithTooltip } from "../../TimeWithTooltip";
export const QueuedPromptsPanel = ({ queuedPrompts, onPushQueuedPrompt, onDeleteQueuedPrompt, pushDisabled = false, deleteDisabled = false, }) => {
    const [expandedQueuedTriggerIds, setExpandedQueuedTriggerIds] = useState({});
    if (queuedPrompts.length === 0)
        return null;
    return (_jsx("div", { className: "border-border-default bg-feedback-orange-light/50 border-t", "data-testid": "queued-prompts-section", children: _jsxs("div", { className: "px-4 pt-2.5 pb-2", children: [_jsxs("div", { className: "mb-1.5 flex items-center gap-1.5", children: [_jsx("div", { className: "bg-feedback-orange h-1.5 w-1.5 animate-pulse rounded-full" }), _jsxs("span", { className: "text-feedback-orange text-[10px] font-medium tracking-wide", "data-testid": "queued-prompts-count", children: ["Queued (", queuedPrompts.length, ")"] })] }), _jsx("div", { className: "max-h-64 space-y-0.5 overflow-y-auto", 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: "flex items-center gap-1", children: [_jsxs("button", { type: "button", onClick: () => setExpandedQueuedTriggerIds((prev) => ({
                                                    ...prev,
                                                    [qp.id]: !prev[qp.id],
                                                })), className: "text-feedback-orange hover:bg-feedback-orange-light/60 flex min-w-0 flex-1 items-center gap-1.5 rounded px-1 py-0.5 text-left transition-colors", "data-testid": "queued-trigger-toggle", "data-expanded": isTriggerExpanded ? "true" : "false", children: [_jsx(Target, { className: "text-feedback-orange h-3 w-3 shrink-0", strokeWidth: 2 }), _jsx("span", { className: "truncate font-medium", children: triggerName }), qp.createdDate && (_jsx(TimeWithTooltip, { date: new Date(qp.createdDate), className: "text-feedback-orange ml-1 shrink-0 text-[10px]" })), _jsx("span", { className: "text-feedback-orange 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-feedback-orange hover:bg-feedback-orange-light inline-flex h-6 w-6 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-feedback-orange text-feedback-orange/80 mt-0.5 border-l-2 pl-5 text-[11px]", children: qp.prompt }))] }, qp.id));
                        }
                        return (_jsx("div", { className: "border-feedback-orange rounded-md border bg-white p-2.5 text-[11px]", "data-testid": "queued-prompt-item", children: _jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("div", { className: "mb-1 flex items-center gap-1.5", children: qp.sourceAgentName ? (_jsxs(_Fragment, { children: [_jsxs("span", { className: "text-neutral-grey-100 font-medium", children: ["From ", qp.sourceAgentName] }), qp.priority > 5 && (_jsx("span", { className: "bg-feedback-red-light badge-pad-sm text-feedback-red rounded text-[11px] font-medium", children: "High Priority" }))] })) : (_jsx("span", { className: "text-neutral-grey-100 font-medium", children: "From User" })) }), _jsx("div", { className: "text-neutral-grey-50 wrap-break-word whitespace-pre-wrap", "data-testid": "queued-prompt-text", children: qp.prompt }), _jsxs("div", { className: "text-neutral-grey-50 mt-1.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px]", children: [qp.createdDate && (_jsxs("span", { children: ["Queued", " ", _jsx(TimeWithTooltip, { date: new Date(qp.createdDate) })] })), qp.scheduledFor &&
                                                        new Date(qp.scheduledFor).getTime() >
                                                            new Date(qp.createdDate || 0).getTime() + 1000 && (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-neutral-grey-50", children: "\u2022" }), _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))] })] }))] })] }), _jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [onPushQueuedPrompt ? (_jsx("button", { type: "button", className: "border-feedback-orange text-feedback-orange hover:bg-feedback-orange-light inline-flex h-7 w-7 items-center justify-center rounded border transition-colors disabled:cursor-not-allowed disabled:opacity-50", title: "Run this queued prompt now", "aria-label": "Run this queued prompt now", "data-testid": "queued-prompt-push-button", disabled: pushDisabled, onClick: () => onPushQueuedPrompt(qp), children: _jsx(Play, { className: "h-3.5 w-3.5", strokeWidth: 2 }) })) : null, onDeleteQueuedPrompt ? (_jsx("button", { type: "button", className: "border-feedback-orange text-feedback-orange hover:bg-feedback-orange-light inline-flex h-7 w-7 items-center justify-center rounded border 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] })] }) }, qp.id));
                    }) })] }) }));
};
//# sourceMappingURL=QueuedPromptsPanel.js.map