import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { FilePenLine, FileText, Loader2 } from "lucide-react";
import { MarkdownDisplay } from "../../components/MarkdownDisplay";
import { Button } from "../../components/ui/button";
import { CloseButton } from "../../components/ui/close-button";
import { Textarea } from "../../components/ui/textarea";
import { getDisplayableAssignee } from "../assigneeDisplay";
import { TaskAttachmentsSection } from "./TaskAttachmentsSection";
import { TaskReviewActions } from "./TaskReviewActions";
import { compactMarkdownComponents, WizardTaskStatusBadge, } from "./WizardCommunicationShared";
import { TaskboardPersistentLogPanel } from "./TaskboardPersistentLogPanel";
const sectionHeadingClass = "text-xs font-bold tracking-wider text-neutral-grey-50 ";
export function WizardTaskDetailsPanel(props) {
    const { task, agentId, executionDisplay, canEdit, isPlanTask, isEditingDescription, localDescriptionMarkdown, isSavingDescription, isEditingPlan, localPlanMarkdown, isSavingPlan, shouldCollapseApprovalCommunication, openChatButton, onDescriptionEdit, onDescriptionChange, onDescriptionSave, onDescriptionCancel, onPlanEdit, onPlanChange, onPlanSave, onPlanCancel, onTaskChanged, onTaskApproved, onCloseTask, } = props;
    if (!task) {
        return null;
    }
    const hasReviewActions = Boolean(onTaskChanged && onTaskApproved !== undefined);
    return (_jsx("div", { className: "flex min-h-0 flex-1 flex-col overflow-hidden px-5 pt-4", children: _jsxs("div", { className: "flex min-h-0 flex-1 flex-col overflow-hidden", children: [_jsxs("div", { className: "flex shrink-0 items-start justify-between gap-3", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx("h2", { className: "text-neutral-grey-100 mt-1 mb-2 text-lg font-semibold", children: task.title }) }), _jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [_jsx(TaskboardPersistentLogPanel, { scope: "task", projectId: task.projectId, taskId: task.taskId, title: "Execution Log", emptyMessage: "No task-scoped log entries yet.", refreshKey: `${task.taskId}:${task.executionUpdatedAt ?? task.updatedAt ?? ""}:${task.executionState}:${task.status}`, testId: "taskboard-wizard-task-log-panel" }), canEdit && !isEditingDescription ? (_jsxs(Button, { type: "button", variant: "outline", size: "sm", className: "h-7 px-2 text-[11px]", onClick: onDescriptionEdit, children: [_jsx(FileText, { className: "h-3.5 w-3.5" }), "Edit description"] })) : null, onCloseTask ? (_jsx(CloseButton, { label: "Close current task", "data-testid": "taskboard-wizard-close-task", onClick: onCloseTask })) : null] })] }), _jsx("div", { className: `min-h-0 flex-1 overflow-y-auto pr-2 ${hasReviewActions ? "pb-6" : "pb-4"}`, children: _jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: "flex flex-wrap gap-2 text-xs", children: [_jsx(WizardTaskStatusBadge, { status: task.status, testId: "taskboard-wizard-communication-task-status" }), executionDisplay ? (_jsx("span", { className: `rounded-badge badge-pad text-2xs border font-medium ${executionDisplay.className ||
                                            (executionDisplay.needsAttention
                                                ? "border-feedback-orange bg-feedback-orange-light text-feedback-orange"
                                                : "border-border-default bg-neutral-grey-5 text-neutral-grey-100")}`, children: executionDisplay.label })) : null, (() => {
                                        const assignee = getDisplayableAssignee(task, { isPlanTask });
                                        return assignee !== "Unassigned" ? (_jsx("span", { className: "rounded-badge badge-pad text-2xs border-border-default bg-neutral-grey-5 text-neutral-grey-100 border font-medium", children: assignee })) : null;
                                    })()] }), _jsxs("div", { className: "pt-2", children: [_jsx("div", { className: "flex items-center justify-between gap-2", children: _jsx("div", { className: sectionHeadingClass, children: "Description" }) }), isEditingDescription ? (_jsxs("div", { className: "mt-1 space-y-2", children: [_jsx(Textarea, { value: localDescriptionMarkdown, onChange: (event) => onDescriptionChange(event.target.value), rows: 8, disabled: isSavingDescription, className: "min-h-[180px] font-mono text-sm" }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsxs(Button, { type: "button", size: "sm", onClick: onDescriptionSave, disabled: isSavingDescription, children: [isSavingDescription ? (_jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin" })) : null, "Save description"] }), _jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: onDescriptionCancel, disabled: isSavingDescription, children: "Cancel" })] })] })) : task.description?.trim() ? (_jsx(MarkdownDisplay, { source: task.description, className: "text-neutral-grey-50 mt-1 text-xs", components: compactMarkdownComponents })) : (_jsx("p", { className: "text-neutral-grey-50 mt-1 text-xs", children: "No task description yet." }))] }), task.resultData?.trim() || (isPlanTask && canEdit) ? (_jsxs("div", { className: "pt-2", children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("div", { className: sectionHeadingClass, children: "Results" }), isPlanTask && canEdit && !isEditingPlan ? (_jsxs(Button, { type: "button", variant: "outline", size: "sm", className: "h-7 px-2 text-[11px]", onClick: onPlanEdit, children: [_jsx(FilePenLine, { className: "h-3.5 w-3.5" }), "Edit plan"] })) : null] }), isPlanTask && isEditingPlan ? (_jsxs("div", { className: "mt-1 space-y-2", children: [_jsx(Textarea, { value: localPlanMarkdown, onChange: (event) => onPlanChange(event.target.value), rows: 12, disabled: isSavingPlan, className: "min-h-[220px] font-mono text-sm" }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsxs(Button, { type: "button", size: "sm", onClick: onPlanSave, disabled: isSavingPlan, children: [isSavingPlan ? (_jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin" })) : null, "Save plan"] }), _jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: onPlanCancel, disabled: isSavingPlan, children: "Cancel" })] })] })) : task.resultData?.trim() ? (_jsx(MarkdownDisplay, { source: task.resultData, className: "text-neutral-grey-50 mt-1 text-xs", components: compactMarkdownComponents })) : (_jsx("p", { className: "text-neutral-grey-50 mt-1 text-xs", children: "No plan has been written yet." }))] })) : null, _jsx(TaskAttachmentsSection, { task: task, canEdit: canEdit, onTaskChanged: onTaskChanged, className: "pt-4" })] }) }), onTaskChanged ? (_jsx("div", { className: "border-border-default shrink-0 border-t bg-white px-1 py-3", children: _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(TaskReviewActions, { task: task, agentId: agentId, canEdit: canEdit, onTaskChanged: onTaskChanged, onTaskApproved: onTaskApproved, className: "flex flex-wrap items-center gap-2" }), shouldCollapseApprovalCommunication ? openChatButton : null] }) })) : null] }) }));
}
//# sourceMappingURL=WizardTaskDetailsPanel.js.map