"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    TaskContent: ()=>TaskContent
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const apollo_core_namespaceObject = require("@uipath/apollo-core");
const index_cjs_namespaceObject = require("../../layouts/index.cjs");
const apollo_wind_namespaceObject = require("@uipath/apollo-wind");
const external_debounce_namespaceObject = require("debounce");
var external_debounce_default = /*#__PURE__*/ __webpack_require__.n(external_debounce_namespaceObject);
const external_react_namespaceObject = require("react");
const external_icons_index_cjs_namespaceObject = require("../../icons/index.cjs");
const external_CanvasTooltip_cjs_namespaceObject = require("../CanvasTooltip.cjs");
const external_ExecutionStatusIcon_index_cjs_namespaceObject = require("../ExecutionStatusIcon/index.cjs");
const external_StageNode_styles_cjs_namespaceObject = require("./StageNode.styles.cjs");
const external_StageTaskEntryConditionIcon_cjs_namespaceObject = require("./StageTaskEntryConditionIcon.cjs");
const ProcessCanvasIcon = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("svg", {
        viewBox: "0 0 24 24",
        fill: "none",
        stroke: "currentColor",
        strokeWidth: "1.5",
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("rect", {
                x: "3",
                y: "3",
                width: "7",
                height: "7",
                rx: "1"
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("rect", {
                x: "14",
                y: "3",
                width: "7",
                height: "7",
                rx: "1"
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("rect", {
                x: "3",
                y: "14",
                width: "7",
                height: "7",
                rx: "1"
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("rect", {
                x: "14",
                y: "14",
                width: "7",
                height: "7",
                rx: "1"
            })
        ]
    });
const generateBadgeText = (taskExecution)=>{
    if (!taskExecution.badge) return;
    if (taskExecution.retryCount && taskExecution.retryCount > 1) return `${taskExecution.badge} x${taskExecution.retryCount}`;
    return taskExecution.badge;
};
const TaskPlayButton = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(({ taskId, onTaskPlay, small })=>{
    const [playLoading, setPlayLoading] = (0, external_react_namespaceObject.useState)(false);
    const debouncedTaskPlay = (0, external_react_namespaceObject.useMemo)(()=>external_debounce_default()(async (id)=>{
            setPlayLoading(true);
            try {
                await onTaskPlay(id);
            } catch  {} finally{
                setPlayLoading(false);
            }
        }, 500, {
            immediate: true
        }), [
        onTaskPlay
    ]);
    const handlePlayClick = (0, external_react_namespaceObject.useCallback)((e)=>{
        e.stopPropagation();
        e.preventDefault();
        debouncedTaskPlay(taskId);
    }, [
        debouncedTaskPlay,
        taskId
    ]);
    const iconSize = small ? 18 : 22;
    const buttonSize = small ? '20px' : apollo_core_namespaceObject.Spacing.SpacingL;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
        content: "Trigger task",
        placement: "top",
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Button, {
            variant: "ghost",
            size: "icon",
            "data-testid": `stage-task-play-${taskId}`,
            onClick: handlePlayClick,
            onMouseDown: (e)=>e.stopPropagation(),
            onKeyDown: (e)=>e.stopPropagation(),
            className: "task-menu-icon-button",
            style: {
                color: 'var(--canvas-icon-default)',
                minWidth: 'unset',
                width: buttonSize,
                height: buttonSize,
                padding: 0,
                ...small && {
                    marginRight: '-2px'
                }
            },
            children: playLoading ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Spinner, {
                size: "sm",
                style: {
                    width: iconSize - 2,
                    height: iconSize - 2
                }
            }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icons_index_cjs_namespaceObject.TimelinePlayIcon, {
                w: iconSize,
                h: iconSize
            })
        })
    });
});
const TaskContent = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(({ task, taskExecution, isDragging, onTaskPlay })=>{
    const hasExecutionStatus = !!taskExecution?.status;
    const hasSecondRowContent = taskExecution && (taskExecution.duration || taskExecution.retryDuration || taskExecution.badge);
    const showPlayButtonSmall = onTaskPlay && hasExecutionStatus;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Column, {
        flex: 1,
        style: {
            overflow: 'hidden',
            textOverflow: 'ellipsis',
            whiteSpace: 'nowrap'
        },
        gap: apollo_core_namespaceObject.Padding.PadXs,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Row, {
                align: "center",
                justify: "space-between",
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Row, {
                        gap: apollo_core_namespaceObject.Spacing.SpacingXs,
                        align: "center",
                        style: {
                            overflow: 'hidden',
                            textOverflow: 'ellipsis',
                            whiteSpace: 'nowrap'
                        },
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_StageNode_styles_cjs_namespaceObject.StageTaskIcon, {
                                children: task.icon ?? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ProcessCanvasIcon, {})
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
                                content: task.label,
                                placement: "top",
                                smartTooltip: true,
                                ...isDragging && {
                                    isOpen: false
                                },
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                                    className: "text-sm truncate",
                                    children: task.label
                                })
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Row, {
                        align: "center",
                        gap: apollo_core_namespaceObject.Spacing.SpacingXs,
                        style: {
                            flexShrink: 0
                        },
                        children: [
                            hasExecutionStatus && (taskExecution.message ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
                                content: taskExecution.message,
                                placement: "top",
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Button, {
                                    variant: "ghost",
                                    size: "icon",
                                    className: "h-4 w-4",
                                    "aria-label": taskExecution.message,
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_ExecutionStatusIcon_index_cjs_namespaceObject.ExecutionStatusIcon, {
                                        status: taskExecution.status
                                    })
                                })
                            }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_ExecutionStatusIcon_index_cjs_namespaceObject.ExecutionStatusIcon, {
                                status: taskExecution.status
                            })),
                            !hasSecondRowContent && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_StageTaskEntryConditionIcon_cjs_namespaceObject.StageTaskEntryConditionIcon, {
                                task: task,
                                small: !!hasExecutionStatus
                            }),
                            showPlayButtonSmall && !hasSecondRowContent && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TaskPlayButton, {
                                taskId: task.id,
                                onTaskPlay: onTaskPlay,
                                small: true
                            }),
                            onTaskPlay && !hasExecutionStatus && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TaskPlayButton, {
                                taskId: task.id,
                                onTaskPlay: onTaskPlay
                            })
                        ]
                    })
                ]
            }),
            taskExecution && hasSecondRowContent && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Row, {
                align: "center",
                justify: "space-between",
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Row, {
                        gap: '2px',
                        children: [
                            taskExecution?.duration && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                                className: "text-xs text-foreground-muted",
                                children: taskExecution.duration
                            }),
                            taskExecution?.retryDuration && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_StageNode_styles_cjs_namespaceObject.StageTaskRetryDuration, {
                                status: taskExecution.badgeStatus ?? 'warning',
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                                    className: "text-xs",
                                    children: `(+${taskExecution.retryDuration})`
                                })
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Row, {
                        align: "center",
                        gap: apollo_core_namespaceObject.Spacing.SpacingXs,
                        children: [
                            taskExecution?.badge && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Badge, {
                                variant: taskExecution.badgeStatus,
                                children: generateBadgeText(taskExecution) ?? ''
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_StageTaskEntryConditionIcon_cjs_namespaceObject.StageTaskEntryConditionIcon, {
                                task: task,
                                small: true
                            }),
                            showPlayButtonSmall && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TaskPlayButton, {
                                taskId: task.id,
                                onTaskPlay: onTaskPlay,
                                small: true
                            })
                        ]
                    })
                ]
            })
        ]
    });
});
exports.TaskContent = __webpack_exports__.TaskContent;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "TaskContent"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
