"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__, {
    StageNodeHeader: ()=>StageNodeHeader
});
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_react_namespaceObject = require("react");
const external_icons_index_cjs_namespaceObject = require("../../../icons/index.cjs");
const external_icons_index_cjs_namespaceObject_1 = require("../../icons/index.cjs");
const icon_registry_cjs_namespaceObject = require("../../utils/icon-registry.cjs");
const external_CanvasTooltip_cjs_namespaceObject = require("../CanvasTooltip.cjs");
const external_ExecutionStatusIcon_index_cjs_namespaceObject = require("../ExecutionStatusIcon/index.cjs");
const ExecutionStatusIcon_cjs_namespaceObject = require("../ExecutionStatusIcon/ExecutionStatusIcon.cjs");
const external_StageNode_styles_cjs_namespaceObject = require("./StageNode.styles.cjs");
const external_StageNode_types_cjs_namespaceObject = require("./StageNode.types.cjs");
const external_StageTitleInput_cjs_namespaceObject = require("./StageTitleInput.cjs");
const external_useExecutionStatusLabel_cjs_namespaceObject = require("./useExecutionStatusLabel.cjs");
const external_useStageNodeLabels_cjs_namespaceObject = require("./useStageNodeLabels.cjs");
const SLA_ICON_CONFIG = {
    warning: {
        icon: 'triangle-alert',
        iconColor: 'var(--canvas-warning-icon)'
    },
    error: {
        icon: 'circle-alert',
        iconColor: 'var(--canvas-error-icon)'
    }
};
const CHIP_ICONS = {
    [external_StageNode_types_cjs_namespaceObject.StageHeaderChipType.Entry]: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icons_index_cjs_namespaceObject_1.EntryConditionIcon, {
        w: apollo_core_namespaceObject.Icon.IconXs,
        h: apollo_core_namespaceObject.Icon.IconXs
    }),
    [external_StageNode_types_cjs_namespaceObject.StageHeaderChipType.Exit]: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icons_index_cjs_namespaceObject_1.ExitConditionIcon, {
        w: apollo_core_namespaceObject.Icon.IconXs,
        h: apollo_core_namespaceObject.Icon.IconXs
    }),
    [external_StageNode_types_cjs_namespaceObject.StageHeaderChipType.Completion]: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icons_index_cjs_namespaceObject.ChecklistIcon, {
        size: 16
    }),
    [external_StageNode_types_cjs_namespaceObject.StageHeaderChipType.ReturnToOrigin]: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icons_index_cjs_namespaceObject_1.ReturnToOriginIcon, {
        w: apollo_core_namespaceObject.Icon.IconXs,
        h: apollo_core_namespaceObject.Icon.IconXs
    }),
    [external_StageNode_types_cjs_namespaceObject.StageHeaderChipType.Optional]: null,
    [external_StageNode_types_cjs_namespaceObject.StageHeaderChipType.EndsCase]: null
};
const STATUS_BADGE_CONFIG = {
    [external_StageNode_types_cjs_namespaceObject.StageHeaderChipType.Optional]: {
        className: 'bg-background-secondary text-foreground-muted',
        hoverClassName: 'hover:bg-background-secondary/80',
        testId: 'optional',
        labelKey: 'optionalBadge'
    },
    [external_StageNode_types_cjs_namespaceObject.StageHeaderChipType.EndsCase]: {
        className: 'bg-error-icon text-foreground-inverse',
        hoverClassName: 'hover:bg-error-icon/80',
        testId: 'ends-case',
        labelKey: 'endsCaseBadge'
    }
};
const STATUS_BADGE_BASE_CLASS = 'inline-flex h-6 items-center justify-center whitespace-nowrap rounded-[10px] border border-transparent px-2 text-xs font-normal';
const StageStatusBadge = ({ label, tooltip, className, hoverClassName, testId, onClick })=>{
    const badge = onClick ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
        type: "button",
        "data-testid": testId,
        onClick: (e)=>{
            e.stopPropagation();
            onClick();
        },
        className: `${STATUS_BADGE_BASE_CLASS} ${className} ${hoverClassName} cursor-pointer transition-colors focus-visible:outline-2 focus-visible:outline-offset-2`,
        children: label
    }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
        "data-testid": testId,
        className: `${STATUS_BADGE_BASE_CLASS} ${className}`,
        children: label
    });
    if (tooltip) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
        placement: "bottom",
        content: tooltip,
        children: badge
    });
    return badge;
};
const StageNodeHeaderInner = ({ props, isReadOnly, isException, status, handleTaskAddClick })=>{
    const labels = (0, external_useStageNodeLabels_cjs_namespaceObject.useStageNodeLabels)();
    const getStatusName = (0, external_useExecutionStatusLabel_cjs_namespaceObject.useExecutionStatusLabel)();
    const { id, stageDetails, execution, onStatusClick, onTaskAdd, onAddTaskFromToolbox, onStageTitleChange, loadingTaskIds } = props;
    const isAddTaskDisabled = (loadingTaskIds?.size ?? 0) > 0;
    const icon = stageDetails?.icon;
    const statusLabel = execution?.stageStatus?.label;
    const stageDuration = execution?.stageStatus?.duration;
    const slaText = execution?.stageStatus?.slaText;
    const slaIcon = execution?.stageStatus?.slaIcon;
    const slaIndicator = slaIcon ? SLA_ICON_CONFIG[slaIcon] : void 0;
    const statusFallbackName = status ? getStatusName(status) : '';
    const statusTooltip = statusLabel || statusFallbackName;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_StageNode_styles_cjs_namespaceObject.StageHeader, {
        isException: isException,
        "data-testid": `stage-header-${id}`,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                className: "flex items-start justify-between gap-1",
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Row, {
                        gap: apollo_core_namespaceObject.Spacing.SpacingMicro,
                        align: "center",
                        flex: 1,
                        minW: 0,
                        children: [
                            icon,
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_StageTitleInput_cjs_namespaceObject.StageTitleInput, {
                                stageId: id,
                                label: stageDetails.label,
                                onChange: isReadOnly ? void 0 : onStageTitleChange,
                                className: "flex-1 min-w-0"
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(index_cjs_namespaceObject.Row, {
                        gap: apollo_core_namespaceObject.Spacing.SpacingMicro,
                        align: "start",
                        py: apollo_core_namespaceObject.Padding.PadS,
                        children: [
                            status && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
                                content: statusTooltip,
                                placement: "top",
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Button, {
                                    variant: "ghost",
                                    size: "icon",
                                    className: "h-6 w-6",
                                    "aria-label": statusTooltip,
                                    "data-testid": `stage-status-${id}`,
                                    onClick: onStatusClick ? (e)=>{
                                        e.stopPropagation();
                                        onStatusClick();
                                    } : void 0,
                                    children: 'NotExecuted' === status ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                                        icon: "hourglass",
                                        size: 20,
                                        color: (0, ExecutionStatusIcon_cjs_namespaceObject.getExecutionStatusColor)('NotExecuted')
                                    }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_ExecutionStatusIcon_index_cjs_namespaceObject.ExecutionStatusIcon, {
                                        status: status,
                                        size: 20
                                    })
                                })
                            }),
                            (onTaskAdd || onAddTaskFromToolbox) && !isReadOnly && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
                                content: labels.addTask,
                                placement: "top",
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Button, {
                                    variant: "ghost",
                                    size: "icon",
                                    className: "h-6 w-6",
                                    onClick: handleTaskAddClick,
                                    "aria-label": labels.addTask,
                                    disabled: isAddTaskDisabled,
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                                        icon: "plus",
                                        size: 20
                                    })
                                })
                            })
                        ]
                    })
                ]
            }),
            (slaText || stageDetails.headerChips && stageDetails.headerChips.length > 0) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                className: "flex min-h-8 flex-wrap items-center justify-between gap-x-2 gap-y-2",
                children: [
                    slaText && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("span", {
                        className: "inline-flex items-center gap-1 text-xs text-foreground-muted",
                        "data-testid": `stage-sla-${id}`,
                        "data-sla-icon": slaIcon,
                        children: [
                            slaIndicator && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                                icon: slaIndicator.icon,
                                size: 16,
                                color: slaIndicator.iconColor
                            }),
                            slaText
                        ]
                    }),
                    stageDetails.headerChips && stageDetails.headerChips.length > 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                        className: "flex flex-wrap items-center gap-x-1 gap-y-2",
                        children: stageDetails.headerChips.map((chip)=>{
                            const statusBadge = STATUS_BADGE_CONFIG[chip.type];
                            if (statusBadge) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(StageStatusBadge, {
                                testId: `stage-${statusBadge.testId}-badge-${id}`,
                                className: statusBadge.className,
                                hoverClassName: statusBadge.hoverClassName,
                                label: chip.label || labels[statusBadge.labelKey],
                                tooltip: chip.tooltip,
                                onClick: chip.onClick
                            }, chip.type);
                            const button = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_StageNode_styles_cjs_namespaceObject.StageChip, {
                                type: "button",
                                "aria-label": 'string' == typeof chip.tooltip ? chip.tooltip : chip.type,
                                onClick: (e)=>{
                                    e.stopPropagation();
                                    chip.onClick?.();
                                },
                                children: [
                                    CHIP_ICONS[chip.type],
                                    void 0 !== chip.count && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                                        className: "text-xs",
                                        children: chip.count
                                    })
                                ]
                            }, chip.type);
                            if (chip.tooltip) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
                                placement: "bottom",
                                content: chip.tooltip,
                                children: button
                            }, chip.type);
                            return button;
                        })
                    })
                ]
            }),
            stageDuration && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                className: "flex min-h-8 items-center text-xs text-foreground-muted",
                children: stageDuration
            })
        ]
    });
};
const StageNodeHeader = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(StageNodeHeaderInner);
exports.StageNodeHeader = __webpack_exports__.StageNodeHeader;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "StageNodeHeader"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
