import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { cn } from "../../lib/utils";
import { Loader2, User, Bot, Circle, Ban, AlertTriangle, Shield, GitBranch, } from "lucide-react";
import { DeleteIcon } from "../../components/ui/delete-icon";
import { getDisplayableAssignee } from "../assigneeDisplay";
import { Badge } from "../../components/ui/badge";
import { getTaskExecutionDisplayFromTask } from "../taskExecutionStatus";
import { normalizeTaskStatus, getTaskStatusLabel } from "../taskStatus";
import { TaskAssigneePicker } from "./TaskAssigneePicker";
const priorityDotColors = {
    Critical: "border-l-feedback-red-strong",
    High: "border-l-orange-500",
    Medium: "border-l-blue-500",
    Low: "border-l-neutral-grey-15",
};
export function TaskRow(props) {
    const { task, selected, onClick, onDelete, projectId, canEditAssignee = false, onAssigneeChange, } = props;
    const taskStatus = normalizeTaskStatus(task.status, task.executionState);
    const executionDisplay = getTaskExecutionDisplayFromTask({
        taskStatus: task.status,
        executionState: task.executionState,
    });
    const isPlanTask = String(task.taskType ?? "").toLowerCase() === "plan" ||
        task.title === "Project Plan";
    const isDecisionPointTask = String(task.taskType ?? "").toLowerCase() === "decisionpoint";
    const assigneeValue = getDisplayableAssignee(task, { isPlanTask });
    const executionIconTitle = executionDisplay?.label ?? "Execution idle";
    const priorityBorderClass = task.priority
        ? priorityDotColors[task.priority]
        : "border-l-transparent";
    const canEditInlineAssignee = !!projectId && !!onAssigneeChange && canEditAssignee && !isPlanTask;
    const isBlocked = task.executionState === "WaitingForDependency";
    return (_jsxs("div", { "data-testid": `taskboard-task-row-${task.taskId}`, className: cn("grid w-full grid-cols-[minmax(0,1fr)_6rem_7rem_2.5rem] gap-2.5 border-l-2 px-3.5 py-1.5 text-xs transition-colors", priorityBorderClass, selected ? "bg-primary/5 shadow-sm" : "hover:bg-neutral-grey-5"), children: [_jsxs("button", { type: "button", onClick: onClick, className: "contents text-left", "data-testid": `taskboard-task-row-button-${task.taskId}`, children: [_jsxs("div", { className: "flex min-w-0 items-center gap-1.5", children: [_jsx("span", { className: cn("inline-flex h-4 w-4 shrink-0 items-center justify-center", executionDisplay?.showSpinner && "text-primary", executionDisplay?.needsAttention && "text-feedback-orange", !executionDisplay && "text-neutral-grey-50"), title: executionIconTitle, children: executionDisplay?.showSpinner ? (_jsx(Loader2, { className: "h-3 w-3 animate-spin" })) : isBlocked ? (_jsx(Ban, { className: "h-3 w-3" })) : executionDisplay?.needsAttention ? (_jsx(AlertTriangle, { className: "h-3 w-3" })) : (_jsx(Circle, { className: "h-2.5 w-2.5" })) }), _jsx("span", { "data-testid": `taskboard-task-title-${task.taskId}`, className: cn("truncate font-medium tracking-tight", selected ? "text-primary" : "text-neutral-grey-100"), title: task.description
                                    ? `${task.title} - ${task.description} (Priority: ${task.priority ?? "None"})`
                                    : `${task.title} (Priority: ${task.priority ?? "None"})`, children: task.title }), isDecisionPointTask && (_jsx(GitBranch, { className: "text-highlight-100 h-3.5 w-3.5 shrink-0" }))] }), _jsx("div", { className: "flex items-center", children: _jsx(Badge, { variant: "outline", size: "sm", className: "text-2xs font-semibold", "data-testid": `taskboard-task-status-${task.taskId}`, children: getTaskStatusLabel(taskStatus) }) })] }), _jsx("div", { className: "text-neutral-grey-50 flex items-center gap-1.5", children: canEditInlineAssignee ? (_jsx(TaskAssigneePicker, { projectId: projectId, assigneeType: task.assigneeType ?? null, value: task.assigneeId ?? null, displayValue: task.assigneeDisplayName ?? task.assigneeId ?? null, onChange: onAssigneeChange, placeholder: "Assign user or agent", buttonClassName: "h-[29px] w-full min-w-0 justify-between rounded-md bg-neutral-grey-5 text-2xs font-medium", buttonTestId: `taskboard-task-assignee-${task.taskId}` })) : (_jsxs(_Fragment, { children: [task.assigneeType === "Agent" ? (_jsx(Bot, { className: "text-neutral-grey-50 h-3 w-3 shrink-0" })) : task.assigneeType === "Role" ? (_jsx(Shield, { className: "text-neutral-grey-50 h-3 w-3 shrink-0" })) : (_jsx(User, { className: "text-neutral-grey-50 h-3 w-3 shrink-0" })), _jsx("span", { className: "truncate text-[11px] font-medium", title: assigneeValue, "data-testid": `taskboard-task-assignee-${task.taskId}`, children: assigneeValue })] })) }), _jsx("div", { className: "flex items-center justify-end", children: onDelete ? (_jsx("button", { type: "button", className: "text-neutral-grey-50 hover:bg-neutral-grey-5 hover:text-neutral-grey-50 rounded-md p-1 transition-colors", title: "Delete task", onClick: onDelete, "data-testid": `taskboard-task-delete-${task.taskId}`, children: _jsx(DeleteIcon, { size: "md" }) })) : null })] }));
}
//# sourceMappingURL=TaskRow.js.map