import { jsx, jsxs } from "react/jsx-runtime";
import { memo, useCallback } from "react";
import { EventDrivenTaskItem } from "./EventDrivenTask.js";
import { StageAdditionalTasksHeaderSection, StageAdditionalTasksSection, StageTaskList } from "./StageNode.styles.js";
import { useStageNodeLabels } from "./useStageNodeLabels.js";
const StageNodeEventDrivenTaskGroupsInner = ({ props, eventDrivenTasks, isReadOnly, selectedTaskId, marginTop, handleTaskClick, generateReplaceTaskMenuItemForTask, generateDeleteTaskMenuItemForTask })=>{
    const { execution, onTaskGroupModification, onReplaceTaskFromToolbox, loadingTaskIds } = props;
    const labels = useStageNodeLabels();
    const getEventDrivenContextMenuItems = 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 === eventDrivenTasks.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: labels.eventDrivenTasks
                })
            }),
            /*#__PURE__*/ jsx(StageTaskList, {
                children: eventDrivenTasks.map(({ task })=>{
                    const taskExecution = execution?.taskStatus?.[task.id];
                    return /*#__PURE__*/ jsx(EventDrivenTaskItem, {
                        task: task,
                        taskExecution: taskExecution,
                        isSelected: selectedTaskId === task.id,
                        onTaskClick: handleTaskClick,
                        isTaskLoading: loadingTaskIds?.has(task.id),
                        ...(onTaskGroupModification || onReplaceTaskFromToolbox) && !isReadOnly && {
                            getContextMenuItems: ()=>getEventDrivenContextMenuItems(task.id)
                        }
                    }, task.id);
                })
            })
        ]
    });
};
const StageNodeEventDrivenTaskGroups = /*#__PURE__*/ memo(StageNodeEventDrivenTaskGroupsInner);
export { StageNodeEventDrivenTaskGroups };
