import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { isAgentReadOnly } from "../editor/services/agentService";
import { isAgentClosed, isRunningAgentStatus, } from "../editor/services/agentStatus";
import { getAgentStatusConfig } from "../editor/ai/AgentStatusBadge";
import { cn } from "../lib/utils";
import { AlertCircle, CheckCircle2, Clock, DollarSign, HelpCircle, MoreHorizontal, Pencil, Trash2, } from "lucide-react";
import { CloseButton } from "../components/ui/close-button";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "../components/ui/dropdown-menu";
import { Spinner } from "../editor/ui/Spinner";
import { AgentProfileIcon } from "./AgentProfileIcon";
/**
 * Returns visual treatment for genuinely actionable states only.
 * Plain "completed" / "idle" agents are intentionally NOT highlighted as needing
 * attention — the status dot already conveys their state and the row should stay quiet.
 */
function getAttentionInfo(agent) {
    switch (agent.status) {
        case "waitingForApproval":
            return {
                icon: _jsx(Clock, { className: "size-3", strokeWidth: 1 }),
                label: "Needs Approval",
                chipClass: "bg-feedback-orange-light text-feedback-orange",
                barClass: "bg-feedback-orange",
                rowTintClass: "bg-feedback-orange-light/30 hover:bg-feedback-orange-light/60",
                priority: 1,
            };
        case "waitingForInput":
            return {
                icon: _jsx(HelpCircle, { className: "size-3", strokeWidth: 1 }),
                label: "Input Required",
                chipClass: "bg-feedback-orange-light text-feedback-orange",
                barClass: "bg-feedback-orange",
                rowTintClass: "bg-feedback-orange-light/30 hover:bg-feedback-orange-light/60",
                priority: 0,
            };
        case "costLimitReached":
            return {
                icon: _jsx(DollarSign, { className: "size-3", strokeWidth: 1 }),
                label: "Budget Exceeded",
                chipClass: "bg-feedback-orange-light text-feedback-orange",
                barClass: "bg-feedback-orange",
                priority: 2,
            };
        case "error":
            return {
                icon: _jsx(AlertCircle, { className: "size-3", strokeWidth: 1 }),
                label: "Error",
                chipClass: "bg-feedback-red-light text-feedback-red",
                barClass: "bg-feedback-red",
                priority: 3,
            };
        default:
            return null;
    }
}
/**
 * Priority order used by the inbox to sort agents.
 * Lower number = shown higher in the list.
 */
export function getInboxAttentionPriority(agent) {
    const info = getAttentionInfo(agent);
    if (info)
        return info.priority;
    if (agent.status === "completed")
        return 5;
    return 4;
}
export function AgentCard({ agent, onClick, onResume, onDelete, onDismiss, onRename, formatDateTime, selected = false, density = "default", showProfileIcon = true, }) {
    const statusConfig = getAgentStatusConfig(agent);
    const isClosed = isAgentClosed(agent.status);
    const isRunning = isRunningAgentStatus(agent.status);
    const readOnly = isAgentReadOnly(agent);
    const showOverflowMenu = !readOnly && (!!onRename || !!onDelete);
    const attention = getAttentionInfo(agent);
    const attentionRowTintClass = attention?.rowTintClass;
    const profileLabel = agent.profileName?.trim() || agent.description?.trim() || "Agent";
    const isCompact = density === "compact";
    const handleCardClick = (event) => {
        if (isClosed && onResume) {
            onResume(agent, event);
        }
        else {
            onClick(agent, event);
        }
    };
    const lastActivity = agent.lastMessageDate
        ? formatDateTime(agent.lastMessageDate)
        : formatDateTime(agent.updatedDate);
    return (_jsxs("div", { className: cn("group relative flex cursor-pointer items-center transition-colors", isCompact
            ? "gap-2 rounded border border-transparent py-2 pr-2 pl-2"
            : "gap-3 rounded-md px-2.5 py-2", attentionRowTintClass
            ? attentionRowTintClass
            : isCompact
                ? "hover:border-border-default hover:bg-neutral-grey-5"
                : "hover:bg-neutral-grey-5/70", selected &&
            !attentionRowTintClass &&
            (isCompact
                ? "border-border-default bg-neutral-grey-10"
                : "bg-neutral-grey-5")), onClick: handleCardClick, "data-testid": "agent-list-row", "data-agent-id": agent.id, title: `${agent.name}\n${profileLabel}\nLast activity: ${lastActivity}\nID: ${agent.id}\nAlt-click to open in a new pane`, children: [attention && (_jsx("div", { className: cn("absolute top-2 bottom-2 left-0 w-0.5 rounded-r", attention.barClass) })), showProfileIcon && (_jsx(AgentProfileIcon, { svgIcon: agent.profileSvgIcon, selected: selected, size: "list" })), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [_jsx("p", { className: "text-neutral-grey-50 min-w-0 truncate text-[10px] leading-5 font-normal", children: profileLabel }), !isRunning && !isCompact && (_jsx("span", { className: cn("h-1.5 w-1.5 shrink-0 rounded-full", statusConfig.color, statusConfig.shouldPulse && "animate-pulse"), title: statusConfig.label })), attention && (_jsxs("span", { className: cn("rounded-badge badge-pad-sm text-2xs inline-flex shrink-0 items-center gap-1 font-medium", attention.chipClass), children: [attention.icon, attention.label] })), agent.isShared && (_jsx("span", { className: "rounded-badge bg-feedback-blue-light badge-pad-sm text-2xs text-feedback-blue shrink-0 font-bold", children: "Shared" }))] }), _jsx("h4", { className: "text-neutral-grey-100 truncate text-[12px] leading-5 font-normal", children: agent.name })] }), _jsx("div", { className: "flex shrink-0 items-center gap-1 self-center opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 has-[[data-state=open]]:opacity-100", children: onDismiss ? (_jsx(CloseButton, { onClick: (e) => {
                        e.stopPropagation();
                        onDismiss(agent.id, agent.name);
                    }, label: "Dismiss" })) : (showOverflowMenu && (
                // modal={false}: a modal menu's body pointer-events lock conflicts
                // with the rename dialog opened from a menu item and leaves the
                // page unclickable after the dialog closes.
                _jsxs(DropdownMenu, { modal: false, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { type: "button", onClick: (e) => e.stopPropagation(), className: "text-neutral-grey-50 hover:bg-neutral-grey-5 hover:text-neutral-grey-100 flex h-7 w-7 items-center justify-center rounded-md transition-colors", "aria-label": "Agent actions", title: "Agent actions", "data-testid": "agent-card-menu-trigger", children: _jsx(MoreHorizontal, { className: "size-4", strokeWidth: 1 }) }) }), _jsxs(DropdownMenuContent, { align: "end", onClick: (e) => e.stopPropagation(), children: [onRename && (_jsxs(DropdownMenuItem, { onClick: () => onRename(agent.id, agent.name), "data-testid": "agent-card-menu-rename", children: [_jsx(Pencil, { className: "size-4", strokeWidth: 1 }), "Rename"] })), onDelete && (_jsxs(DropdownMenuItem, { variant: "destructive", onClick: (e) => onDelete(agent.id, agent.name, e), "data-testid": "agent-card-menu-delete", children: [_jsx(Trash2, { className: "size-4", strokeWidth: 1 }), "Delete"] }))] })] }))) }), !isRunning && isCompact && (_jsx("span", { title: statusConfig.label, className: "flex w-4 shrink-0 items-center justify-center self-center", "data-testid": "agent-card-status-indicator", children: agent.status === "completed" ? (_jsx(CheckCircle2, { className: "text-feedback-green size-3.5", strokeWidth: 1 })) : (_jsx("span", { className: cn("h-2 w-2 rounded-full", statusConfig.color, statusConfig.shouldPulse && "animate-pulse") })) })), isRunning && (_jsx("span", { title: statusConfig.label, className: "text-neutral-grey-100 flex shrink-0 items-center self-center px-1", children: _jsx(Spinner, { size: "sm" }) }))] }, agent.id));
}
//# sourceMappingURL=AgentCard.js.map