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-red-500",
    High: "bg-orange-500",
    Medium: "bg-blue-500",
    Low: "bg-slate-400",
};
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-slate-200";
    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:border-primary/50 hover:shadow-md", selected && "border-primary ring-1 ring-primary/30 shadow-md"), 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: "mb-1 text-[10px] font-semibold uppercase tracking-widest text-muted-foreground", children: displayTaskId }), _jsx("div", { className: "line-clamp-2 text-sm font-semibold leading-snug group-hover:text-primary transition-colors", children: task.title })] }), _jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [isDecisionPointTask && (_jsx(GitBranch, { className: "h-4 w-4 text-violet-600" })), showDoneCheckmark && task.status === "Done" && (_jsx(CheckCircle2, { className: "h-4 w-4 text-emerald-600" })), task.priority === "Critical" && (_jsx(AlertCircle, { className: "h-4 w-4 text-red-500" }))] })] }), task.description && (_jsx("div", { className: "line-clamp-1 text-xs text-muted-foreground italic", children: task.description })), dependencyTaskIds.length > 0 && (_jsxs("div", { className: "line-clamp-1 text-[10px] font-medium text-muted-foreground", children: ["Depends on: ", dependencyTaskIds.join(", ")] })), _jsxs("div", { className: "flex flex-wrap items-center gap-2 mt-0.5", children: [isDecisionPointTask && (_jsx(Badge, { variant: "outline", className: "h-5 border-violet-200 bg-violet-50 px-1.5 text-[10px] uppercase tracking-wide text-violet-700", 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-gray-50 px-1.5 py-0.5 text-xs font-medium text-muted-foreground shadow-none hover:bg-gray-100", buttonTestId: `taskboard-task-assignee-${task.taskId}`, showChevron: false, showAssigneeIcon: true }) })) : (_jsxs("div", { className: "flex items-center gap-1 text-xs text-muted-foreground bg-gray-50 px-1.5 py-0.5 rounded-md", 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: "flex items-center gap-1 text-xs text-muted-foreground bg-gray-50 px-1.5 py-0.5 rounded-md", children: [_jsx(Calendar, { className: "h-3 w-3" }), _jsx("span", { children: format(new Date(task.dueDate), "MMM d") })] })), executionDisplay ? (_jsxs(Badge, { variant: executionDisplay.variant, className: cn("h-5 px-1.5 text-[10px] uppercase tracking-wider 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