"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_lucide_react_namespaceObject = require("lucide-react");
const external_react_namespaceObject = require("react");
const external_i18n_index_cjs_namespaceObject = require("../../../i18n/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 external_useExecutionStatusLabel_cjs_namespaceObject = require("./useExecutionStatusLabel.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 TaskPlayButton = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(({ taskId, onTaskPlay, small })=>{
    const [playLoading, setPlayLoading] = (0, external_react_namespaceObject.useState)(false);
    const { _ } = (0, external_i18n_index_cjs_namespaceObject.useSafeLingui)();
    const triggerTaskLabel = _({
        id: 'stage-node.trigger-task',
        message: 'Trigger task'
    });
    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
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
        content: triggerTaskLabel,
        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(),
            "aria-label": triggerTaskLabel,
            className: small ? 'task-menu-icon-button h-4 w-4 [&_svg]:size-3.5' : 'task-menu-icon-button h-4 w-4',
            style: {
                color: 'var(--canvas-icon-default)',
                minWidth: 'unset',
                padding: 0
            },
            children: playLoading ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Spinner, {
                size: "sm"
            }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_lucide_react_namespaceObject.CirclePlay, {})
        })
    });
});
const TaskContent = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(({ task, taskExecution, isDragging, onTaskPlay })=>{
    const { _ } = (0, external_i18n_index_cjs_namespaceObject.useSafeLingui)();
    const getStatusName = (0, external_useExecutionStatusLabel_cjs_namespaceObject.useExecutionStatusLabel)();
    const hasExecutionStatus = !!taskExecution?.status;
    const badgeText = (0, external_react_namespaceObject.useMemo)(()=>{
        if (!taskExecution?.badge) return;
        if (taskExecution.retryCount && taskExecution.retryCount > 1) {
            if ('InProgress' === taskExecution.status) return _({
                id: 'stage-node.task-badge.running-again',
                message: 'Running again'
            });
            return _({
                id: 'stage-node.task-badge.ran-n-times',
                message: '{count, plural, one {Ran # time} other {Ran # times}}',
                values: {
                    count: taskExecution.retryCount
                }
            });
        }
        return taskExecution.badge;
    }, [
        taskExecution?.badge,
        taskExecution?.retryCount,
        taskExecution?.status,
        _
    ]);
    const hasSecondRowContent = taskExecution && (taskExecution.duration || taskExecution.retryDuration || badgeText);
    const showTaskPlayButton = onTaskPlay && hasExecutionStatus;
    const taskStatusFallbackName = hasExecutionStatus ? getStatusName(taskExecution?.status) : '';
    const taskStatusTooltip = taskExecution?.message || taskStatusFallbackName;
    const durationLabel = (0, external_react_namespaceObject.useMemo)(()=>taskExecution?.duration ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
            className: "text-xs text-foreground-muted",
            children: taskExecution.duration
        }) : null, [
        taskExecution?.duration
    ]);
    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",
                gap: apollo_core_namespaceObject.Spacing.SpacingXs,
                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.jsxs)(index_cjs_namespaceObject.Row, {
                                    gap: '2px',
                                    align: "center",
                                    style: {
                                        overflow: 'hidden',
                                        textOverflow: 'ellipsis',
                                        whiteSpace: 'nowrap'
                                    },
                                    children: [
                                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                                            className: "text-sm truncate",
                                            style: {
                                                minWidth: 0
                                            },
                                            children: task.label
                                        }),
                                        task.isRequired && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                                            className: "text-sm",
                                            style: {
                                                flexShrink: 0
                                            },
                                            children: '*'
                                        })
                                    ]
                                })
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Row, {
                        align: "center",
                        gap: apollo_core_namespaceObject.Spacing.SpacingXs,
                        style: {
                            flexShrink: 0
                        },
                        children: [
                            hasExecutionStatus && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
                                content: taskStatusTooltip,
                                placement: "top",
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Button, {
                                    variant: "ghost",
                                    size: "icon",
                                    className: "h-4 w-4",
                                    "aria-label": taskStatusTooltip,
                                    children: /*#__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
                            }),
                            showTaskPlayButton && !hasSecondRowContent && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TaskPlayButton, {
                                taskId: task.id,
                                onTaskPlay: onTaskPlay
                            }),
                            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: [
                            durationLabel && (taskExecution?.durationTooltip ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
                                content: taskExecution.durationTooltip,
                                placement: "top",
                                hide: isDragging,
                                children: durationLabel
                            }) : durationLabel),
                            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: [
                            badgeText && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Badge, {
                                variant: taskExecution.badgeStatus,
                                children: badgeText
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_StageTaskEntryConditionIcon_cjs_namespaceObject.StageTaskEntryConditionIcon, {
                                task: task,
                                small: true
                            }),
                            showTaskPlayButton && /*#__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
});
