import { jsx, jsxs } from "react/jsx-runtime";
import { memo, useCallback } from "react";
import { AdhocTaskItem } from "./AdhocTask.js";
import { StageAdditionalTasksHeaderSection, StageAdditionalTasksSection, StageTaskList } from "./StageNode.styles.js";
const StageNodeAdhocTaskGroupsInner = ({ props, adhocTasks, isReadOnly, selectedTaskId, marginTop, handleTaskClick, generateReplaceTaskMenuItemForTask, generateDeleteTaskMenuItemForTask })=>{
    const { execution, onTaskGroupModification, onReplaceTaskFromToolbox, onTaskPlay, loadingTaskIds } = props;
    const getAdhocContextMenuItems = useCallback((taskId)=>{
        const items = [];
        const replaceTaskMenuItem = generateReplaceTaskMenuItemForTask(taskId, false);
        if (replaceTaskMenuItem) items.push(replaceTaskMenuItem);
        const deleteTaskMenuItem = generateDeleteTaskMenuItemForTask(taskId);
        if (deleteTaskMenuItem) items.push(deleteTaskMenuItem);
        return items;
    }, [
        generateReplaceTaskMenuItemForTask,
        generateDeleteTaskMenuItemForTask
    ]);
    if (0 === adhocTasks.length) return null;
    return /*#__PURE__*/ jsxs(StageAdditionalTasksSection, {
        style: {
            marginTop
        },
        children: [
            /*#__PURE__*/ jsx(StageAdditionalTasksHeaderSection, {
                children: /*#__PURE__*/ jsx("span", {
                    className: "text-xs font-bold text-foreground-muted",
                    children: "Ad hoc tasks"
                })
            }),
            /*#__PURE__*/ jsx(StageTaskList, {
                children: adhocTasks.map(({ task })=>{
                    const taskExecution = execution?.taskStatus?.[task.id];
                    return /*#__PURE__*/ jsx(AdhocTaskItem, {
                        task: task,
                        taskExecution: taskExecution,
                        isSelected: selectedTaskId === task.id,
                        onTaskClick: handleTaskClick,
                        onTaskPlay: onTaskPlay,
                        isTaskLoading: loadingTaskIds?.has(task.id),
                        ...(onTaskGroupModification || onReplaceTaskFromToolbox) && !isReadOnly && {
                            getContextMenuItems: ()=>getAdhocContextMenuItems(task.id)
                        }
                    }, task.id);
                })
            })
        ]
    });
};
const StageNodeAdhocTaskGroups = /*#__PURE__*/ memo(StageNodeAdhocTaskGroupsInner);
export { StageNodeAdhocTaskGroups };
