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, getTaskContextMenuItems } = props;
    const hasBuiltInTaskActions = !!(onReplaceTaskFromToolbox || onTaskGroupModification);
    const labels = useStageNodeLabels();
    const getEventDrivenContextMenuItems = useCallback((task)=>{
        const items = [];
        const replaceTaskMenuItem = generateReplaceTaskMenuItemForTask(task.id, false);
        if (replaceTaskMenuItem) items.push(replaceTaskMenuItem);
        const additionalMenuItems = getTaskContextMenuItems?.({
            task,
            taskGroupType: 'event-driven',
            isParallel: false
        }) ?? [];
        items.push(...additionalMenuItems);
        const deleteTaskMenuItem = generateDeleteTaskMenuItemForTask(task.id);
        if (deleteTaskMenuItem) items.push(deleteTaskMenuItem);
        return items;
    }, [
        generateReplaceTaskMenuItemForTask,
        getTaskContextMenuItems,
        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];
                    const customItems = isReadOnly || hasBuiltInTaskActions ? [] : getTaskContextMenuItems?.({
                        task,
                        taskGroupType: 'event-driven',
                        isParallel: false
                    }) ?? [];
                    const hasMenu = !isReadOnly && (hasBuiltInTaskActions || customItems.length > 0);
                    return /*#__PURE__*/ jsx(EventDrivenTaskItem, {
                        task: task,
                        taskExecution: taskExecution,
                        isSelected: selectedTaskId === task.id,
                        onTaskClick: handleTaskClick,
                        isTaskLoading: loadingTaskIds?.has(task.id),
                        getContextMenuItems: hasMenu ? getEventDrivenContextMenuItems : void 0
                    }, task.id);
                })
            })
        ]
    });
};
const StageNodeEventDrivenTaskGroups = /*#__PURE__*/ memo(StageNodeEventDrivenTaskGroupsInner);
export { StageNodeEventDrivenTaskGroups };
