import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { cn } from "../../lib/utils";
import { Loader2, User, Bot, Calendar, AlertCircle, CheckCircle2, Shield, GitBranch, } from "lucide-react";
import { getDisplayableAssignee } from "../assigneeDisplay";
import { Badge } from "../../components/ui/badge";
import { format } from "date-fns";
import { getTaskExecutionDisplayFromTask } from "../taskExecutionStatus";
import { TaskAssigneePicker } from "./TaskAssigneePicker";
const priorityColors = {
    Critical: "bg-feedback-red-strong",
    High: "bg-component-shared",
    Medium: "bg-feedback-blue",
    Low: "bg-neutral-grey-50",
};
const prioritySelectedColors = {
    Critical: "border-feedback-red-strong ring-feedback-red-strong",
    High: "border-component-shared ring-component-shared",
    Medium: "border-feedback-blue ring-feedback-blue",
    Low: "border-neutral-grey-50 ring-neutral-grey-50",
};
const defaultSelectedColor = "border-feedback-blue ring-feedback-blue";
const priorityHoverColors = {
    Critical: "hover:border-feedback-red-strong/50",
    High: "hover:border-component-shared/50",
    Medium: "hover:border-feedback-blue/50",
    Low: "hover:border-neutral-grey-50/50",
};
const defaultHoverColor = "hover:border-neutral-grey-10/50";
export function TaskCard(props) {
    const { task, selected, onClick, dependencyTaskIds = [], isBlocked = false, showDoneCheckmark = false, projectId, canEditAssignee = false, onAssigneeChange, } = props;
    const executionDisplay = getTaskExecutionDisplayFromTask({
        taskStatus: task.status,
        executionState: task.executionState,
        isBlocked,
    });
    const priorityColor = task.priority
        ? priorityColors[task.priority]
        : "bg-neutral-grey-10";
    const selectedColor = task.priority
        ? prioritySelectedColors[task.priority]
        : defaultSelectedColor;
    const hoverColor = task.priority
        ? priorityHoverColors[task.priority]
        : defaultHoverColor;
    const displayTaskId = task.taskKey || task.taskId.slice(0, 8).toUpperCase();
    const isPlanTask = String(task.taskType ?? "").toLowerCase() === "plan" ||
        task.title === "Project Plan";
    const isDecisionPointTask = String(task.taskType ?? "").toLowerCase() === "decisionpoint";
    const assigneeValue = getDisplayableAssignee(task, { isPlanTask });
    const canEditInlineAssignee = !!projectId && !!onAssigneeChange && canEditAssignee && !isPlanTask;
    const handleKeyDown = (event) => {
        if (event.key !== "Enter" && event.key !== " ")
            return;
        event.preventDefault();
        event.currentTarget.click();
    };
    return (_jsxs("div", { role: "button", tabIndex: 0, onClick: onClick, onKeyDown: handleKeyDown, className: cn("group relative w-full overflow-hidden rounded-lg border bg-white p-3 text-left shadow-sm transition-all hover:shadow-md", hoverColor, selected && cn("shadow-lg ring-2", selectedColor)), children: [_jsx("div", { className: cn("absolute inset-y-0 left-0 w-1", priorityColor) }), _jsxs("div", { className: "flex flex-col gap-2.5", children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("div", { className: "text-muted-foreground mb-1 text-[10px] font-semibold tracking-widest", children: displayTaskId }), _jsx("div", { className: "line-clamp-2 text-sm leading-snug font-semibold", children: task.title })] }), _jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [isDecisionPointTask && (_jsx(GitBranch, { className: "text-highlight-100 h-4 w-4" })), showDoneCheckmark && task.status === "Done" && (_jsx(CheckCircle2, { className: "text-feedback-green h-4 w-4" })), task.priority === "Critical" && (_jsx(AlertCircle, { className: "text-feedback-red-strong h-4 w-4" }))] })] }), task.description && (_jsx("div", { className: "text-muted-foreground line-clamp-1 text-xs italic", children: task.description })), dependencyTaskIds.length > 0 && (_jsxs("div", { className: "text-muted-foreground line-clamp-1 text-[10px] font-medium", children: ["Depends on: ", dependencyTaskIds.join(", ")] })), _jsxs("div", { className: "mt-0.5 flex flex-wrap items-center gap-2", children: [isDecisionPointTask && (_jsx(Badge, { variant: "outline", size: "sm", className: "text-2xs border-highlight-100 bg-highlight-10 text-highlight-100", children: "Decision Point" })), canEditInlineAssignee ? (_jsx("div", { className: "min-w-0", onClick: (event) => event.stopPropagation(), onMouseDown: (event) => event.stopPropagation(), children: _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-auto max-w-[220px] gap-1 rounded-md border-0 bg-neutral-grey-5 badge-pad-sm text-2xs font-medium text-muted-foreground shadow-none hover:bg-neutral-grey-5", buttonTestId: `taskboard-task-assignee-${task.taskId}`, showChevron: false, showAssigneeIcon: true }) })) : (_jsxs("div", { className: "text-muted-foreground badge-pad-sm bg-neutral-grey-5 flex items-center gap-1 rounded-md text-xs", children: [task.assigneeType === "Agent" ? (_jsx(Bot, { className: "h-3 w-3" })) : task.assigneeType === "Role" ? (_jsx(Shield, { className: "h-3 w-3" })) : (_jsx(User, { className: "h-3 w-3" })), _jsx("span", { className: "max-w-[160px] truncate", title: assigneeValue, children: assigneeValue })] })), task.dueDate && (_jsxs("div", { className: "text-muted-foreground badge-pad-sm bg-neutral-grey-5 flex items-center gap-1 rounded-md text-xs", children: [_jsx(Calendar, { className: "h-3 w-3" }), _jsx("span", { children: format(new Date(task.dueDate), "MMM d") })] })), executionDisplay ? (_jsxs(Badge, { variant: executionDisplay.variant, size: "sm", className: cn("font-bold", executionDisplay.className), title: executionDisplay.needsAttention
                                    ? "Assigned agent requires attention"
                                    : undefined, children: [executionDisplay.showSpinner && (_jsx(Loader2, { className: "mr-1 h-2.5 w-2.5 animate-spin" })), executionDisplay.label] })) : null] })] })] }));
}
//# sourceMappingURL=TaskCard.js.map