"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    StageNodeAdhocTaskGroups: ()=>StageNodeAdhocTaskGroups
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const external_AdhocTask_cjs_namespaceObject = require("./AdhocTask.cjs");
const external_StageNode_styles_cjs_namespaceObject = require("./StageNode.styles.cjs");
const external_useStageNodeLabels_cjs_namespaceObject = require("./useStageNodeLabels.cjs");
const StageNodeAdhocTaskGroupsInner = ({ props, adhocTasks, isReadOnly, selectedTaskId, marginTop, handleTaskClick, generateReplaceTaskMenuItemForTask, generateDeleteTaskMenuItemForTask })=>{
    const { execution, onTaskGroupModification, onReplaceTaskFromToolbox, onTaskPlay, loadingTaskIds, getTaskContextMenuItems } = props;
    const hasBuiltInTaskActions = !!(onReplaceTaskFromToolbox || onTaskGroupModification);
    const labels = (0, external_useStageNodeLabels_cjs_namespaceObject.useStageNodeLabels)();
    const getAdhocContextMenuItems = (0, external_react_namespaceObject.useCallback)((task)=>{
        const items = [];
        const replaceTaskMenuItem = generateReplaceTaskMenuItemForTask(task.id, false);
        if (replaceTaskMenuItem) items.push(replaceTaskMenuItem);
        const additionalMenuItems = getTaskContextMenuItems?.({
            task,
            taskGroupType: 'adhoc',
            isParallel: false
        }) ?? [];
        items.push(...additionalMenuItems);
        const deleteTaskMenuItem = generateDeleteTaskMenuItemForTask(task.id);
        if (deleteTaskMenuItem) items.push(deleteTaskMenuItem);
        return items;
    }, [
        generateReplaceTaskMenuItemForTask,
        getTaskContextMenuItems,
        generateDeleteTaskMenuItemForTask
    ]);
    if (0 === adhocTasks.length) return null;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_StageNode_styles_cjs_namespaceObject.StageAdditionalTasksSection, {
        style: {
            marginTop
        },
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_StageNode_styles_cjs_namespaceObject.StageAdditionalTasksHeaderSection, {
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                    className: "text-xs font-bold text-foreground-muted",
                    children: labels.adhocTasks
                })
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_StageNode_styles_cjs_namespaceObject.StageTaskList, {
                children: adhocTasks.map(({ task })=>{
                    const taskExecution = execution?.taskStatus?.[task.id];
                    const customItems = isReadOnly || hasBuiltInTaskActions ? [] : getTaskContextMenuItems?.({
                        task,
                        taskGroupType: 'adhoc',
                        isParallel: false
                    }) ?? [];
                    const hasMenu = !isReadOnly && (hasBuiltInTaskActions || customItems.length > 0);
                    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AdhocTask_cjs_namespaceObject.AdhocTaskItem, {
                        task: task,
                        taskExecution: taskExecution,
                        isSelected: selectedTaskId === task.id,
                        onTaskClick: handleTaskClick,
                        onTaskPlay: onTaskPlay,
                        isTaskLoading: loadingTaskIds?.has(task.id),
                        getContextMenuItems: hasMenu ? getAdhocContextMenuItems : void 0
                    }, task.id);
                })
            })
        ]
    });
};
const StageNodeAdhocTaskGroups = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(StageNodeAdhocTaskGroupsInner);
exports.StageNodeAdhocTaskGroups = __webpack_exports__.StageNodeAdhocTaskGroups;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "StageNodeAdhocTaskGroups"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
