import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Badge, Button } from "@vertesia/ui/core";
import { AlertCircle, CheckCircle, Circle, Clock, X } from "lucide-react";
export default function InlineSlidingPlanPanel({ plan, workstreamStatus, isOpen, onClose, plans = [], activePlanIndex = 0, onChangePlan = () => { }, }) {
    // Don't render if panel is closed
    if (!isOpen) {
        return null;
    }
    // Render the normal panel
    return (_jsxs("div", { className: "h-full shadow-xl border border-muted/20 overflow-hidden", children: [_jsxs("div", { className: "flex items-center justify-between p-3 border-b border-muted/20", children: [_jsx("h3", { className: "font-bold text-base", children: "Plan" }), _jsxs(Button, { variant: "ghost", onClick: onClose, children: [_jsx(X, { className: "size-4" }), _jsx("span", { className: "sr-only", children: "Close" })] })] }), _jsxs("div", { className: "p-3 overflow-y-auto", style: {
                    height: "calc(100% - 44px)",
                    maxHeight: "calc(100vh - 150px)",
                }, children: [_jsxs("div", { className: "mb-3 p-2 bg-info rounded-md border border-info", children: [_jsx("div", { className: "text-xs font-medium text-info mb-1", children: "Task Progress" }), _jsx("div", { className: "flex items-center gap-2", children: (() => {
                                    // Get all tasks from the plan itself
                                    const planTasks = plan.plan || [];
                                    const totalTasks = planTasks.length;
                                    // Count completed tasks by checking their status in workstreamStatus
                                    let completedTasks = 0;
                                    if (totalTasks > 0) {
                                        // Count each completed task from the plan
                                        planTasks.forEach((task) => {
                                            if (task && task.id) {
                                                const taskId = task.id.toString();
                                                const taskStatus = workstreamStatus.get(taskId);
                                                if (taskStatus === "completed") {
                                                    completedTasks++;
                                                }
                                            }
                                        });
                                    }
                                    // Calculate percentage
                                    const progressPercentage = totalTasks > 0
                                        ? Math.round((completedTasks / totalTasks) * 100)
                                        : 0;
                                    return (_jsxs(_Fragment, { children: [_jsx("div", { className: "w-full bg-muted rounded-full h-2", children: _jsx("div", { className: "bg-background h-2 rounded-full", style: { width: `${progressPercentage}%` } }) }), _jsx("span", { className: "text-xs text-muted", children: totalTasks > 0 ? `${completedTasks}/${totalTasks}` : "0/0" })] }));
                                })() })] }), plans.length > 1 && (_jsxs("div", { className: "mb-3 flex items-center justify-between", children: [_jsx(Button, { variant: "ghost", onClick: () => onChangePlan(Math.min(plans.length - 1, activePlanIndex + 1)), disabled: activePlanIndex >= plans.length - 1, children: "Older Plan" }), _jsx("div", { className: "text-xs text-muted", children: plans[activePlanIndex]?.timestamp
                                    ? new Date(plans[activePlanIndex].timestamp).toLocaleTimeString()
                                    : "Unknown time" }), _jsx(Button, { variant: "ghost", onClick: () => onChangePlan(Math.max(0, activePlanIndex - 1)), disabled: activePlanIndex <= 0, children: "Newer Plan" })] })), _jsxs("div", { className: "rounded-md border border-muted/30", children: [_jsx("div", { className: "p-2 border-b border-muted/30 bg-muted", children: _jsx("div", { className: "font-medium text-xs", children: "Step-by-Step Plan" }) }), _jsx("div", { className: "divide-y divide-muted/20 max-h-[calc(100vh-350px)] overflow-y-auto", children: plan.plan && plan.plan.length > 0 ? (plan.plan.map((task, index) => {
                                    // Extract task info with null checks
                                    const taskId = task.id ? task.id.toString() : `task-${index}`;
                                    const taskGoal = task.goal || `Task ${index + 1}`;
                                    // Determine task status - use task.status if available or lookup from workstream
                                    let status = task.status || "pending";
                                    if (workstreamStatus.has(taskId)) {
                                        status = workstreamStatus.get(taskId);
                                    }
                                    // Determine status icon and style
                                    let StatusIcon = Circle;
                                    let statusColor = "text-muted";
                                    if (status === "in_progress") {
                                        StatusIcon = Clock;
                                        statusColor = "text-info";
                                    }
                                    else if (status === "completed") {
                                        StatusIcon = CheckCircle;
                                        statusColor = "text-success";
                                    }
                                    return (_jsxs("div", { className: `flex p-3 my-1`, children: [_jsx("div", { className: `mr-2 mt-0.5 flex-shrink-0 text-muted`, children: taskId }), _jsxs("div", { className: "w-full", children: [_jsx("div", { className: "text-sm font-medium mb-2 text-muted", children: taskGoal }), _jsxs("div", { className: "mt-1 flex justify-end items-center", children: [_jsx("div", { className: `mr-2 mt-0.5 flex-shrink-0 ${statusColor}`, children: _jsx(StatusIcon, { className: "size-3.5" }) }), _jsx(Badge, { variant: status === "completed" ? "success" : status === "in_progress" ? "info" : "default", children: status === "completed"
                                                                    ? "Completed"
                                                                    : status === "in_progress"
                                                                        ? "In Progress"
                                                                        : "Pending" })] })] })] }, index));
                                })) : (_jsxs("div", { className: "p-3 text-center text-muted italic", children: [_jsx(AlertCircle, { className: "size-4 mx-auto mb-2 text-attention" }), _jsx("p", { className: "text-xs", children: "No plan has been detected yet" }), _jsx("p", { className: "text-xs mt-1", children: "Plans will appear here when the agent creates one" })] })) })] }), (() => {
                        // Get all task IDs from the plan for filtering
                        const planTaskIds = new Set((plan.plan || [])
                            .filter((task) => task && task.id)
                            .map((task) => task.id.toString()));
                        // Filter out 'main' workstream and any IDs that are tasks in the plan
                        const workstreamEntries = Array.from(workstreamStatus.entries()).filter(([id]) => id !== "main" && !planTaskIds.has(id));
                        // Only show the section if there are actual workstreams (not tasks or main)
                        return workstreamEntries.length > 0 ? (_jsxs("div", { className: "mt-3 rounded-md border border-gray-200 dark:border-gray-800", children: [_jsx("div", { className: "p-2 border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/50", children: _jsx("div", { className: "font-medium text-xs", children: "Workstreams" }) }), _jsx("div", { className: "p-3", children: _jsx("div", { className: "grid grid-cols-1 gap-2", children: workstreamEntries.map(([id, status]) => {
                                            let StatusIcon = Circle;
                                            let statusColor = "text-gray-400";
                                            let statusBg = "bg-gray-100 dark:bg-gray-800";
                                            let statusText = "Pending";
                                            if (status === "in_progress") {
                                                StatusIcon = Clock;
                                                statusColor = "text-info";
                                                statusBg = "bg-info/20";
                                                statusText = "In Progress";
                                            }
                                            else if (status === "completed") {
                                                StatusIcon = CheckCircle;
                                                statusColor = "text-success";
                                                statusBg = "bg-success/20";
                                                statusText = "Completed";
                                            }
                                            return (_jsxs("div", { className: `flex items-center p-1.5 rounded ${statusBg}`, children: [_jsx("div", { className: `mr-1.5 ${statusColor}`, children: _jsx(StatusIcon, { className: "h-3.5 w-3.5" }) }), _jsx("div", { className: "flex-1", children: _jsx("span", { className: "text-xs font-medium text-gray-800 dark:text-gray-300", children: id }) }), _jsx("span", { className: "text-xs font-medium", children: statusText })] }, id));
                                        }) }) })] })) : null;
                    })()] })] }));
}
//# sourceMappingURL=InlineSlidingPlanPanel.js.map