"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__, {
    ResourceNode: ()=>ResourceNode
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const index_cjs_namespaceObject = require("../../../icons/index.cjs");
const external_layouts_index_cjs_namespaceObject = require("../../../layouts/index.cjs");
const external_utils_index_cjs_namespaceObject = require("../../../utils/index.cjs");
const react_cjs_namespaceObject = require("../../../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const external_types_cjs_namespaceObject = require("../../../types.cjs");
const BaseNode_cjs_namespaceObject = require("../../BaseNode/BaseNode.cjs");
const BaseNodeConfigContext_cjs_namespaceObject = require("../../BaseNode/BaseNodeConfigContext.cjs");
const ExecutionStatusIcon_cjs_namespaceObject = require("../../ExecutionStatusIcon/ExecutionStatusIcon.cjs");
const ToolResourceIcon_index_cjs_namespaceObject = require("../components/ToolResourceIcon/index.cjs");
const agent_flow_store_cjs_namespaceObject = require("../store/agent-flow-store.cjs");
const alwaysShowNotches = ()=>true;
const ResourceNode = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(({ data, selected, id, mode, hasError = false, hasSuccess = false, hasRunning = false, onEnable, onDisable, onAddBreakpoint, onRemoveBreakpoint, onAddGuardrail, onGoToSource, onErrorAction, translations, suggestionTranslations, suggestionGroupVersion, ...nodeProps })=>{
    const { nodes: _nodes, deleteNode, actOnSuggestion } = (0, agent_flow_store_cjs_namespaceObject.useAgentFlowStore)();
    const edges = (0, agent_flow_store_cjs_namespaceObject.useEdges)();
    const connectedHandlePosition = (0, external_react_namespaceObject.useMemo)(()=>{
        const nodeEdge = edges.find((e)=>e.target === id);
        return nodeEdge?.targetHandle;
    }, [
        edges,
        id
    ]);
    const displayTooltips = 'design' === mode;
    const hasBreakpoint = data.hasBreakpoint ?? false;
    const hasGuardrails = data.hasGuardrails ?? false;
    const isCurrentBreakpoint = data.isCurrentBreakpoint ?? false;
    const isDisabled = data.isDisabled ?? false;
    const isSuggestion = data.isSuggestion ?? false;
    const suggestionId = data.suggestionId;
    const suggestionType = isSuggestion ? data.suggestionType : void 0;
    const suggestTranslations = suggestionTranslations ?? external_types_cjs_namespaceObject.DefaultSuggestionTranslations;
    const errorAction = data.errorAction ?? void 0;
    const handleClickEnable = (0, external_react_namespaceObject.useCallback)(()=>{
        onEnable?.(id, data);
    }, [
        id,
        data,
        onEnable
    ]);
    const handleClickDisable = (0, external_react_namespaceObject.useCallback)(()=>{
        onDisable?.(id, data);
    }, [
        id,
        data,
        onDisable
    ]);
    const handleClickAddBreakpoint = (0, external_react_namespaceObject.useCallback)(()=>{
        onAddBreakpoint?.(id, data);
    }, [
        id,
        data,
        onAddBreakpoint
    ]);
    const handleClickRemoveBreakpoint = (0, external_react_namespaceObject.useCallback)(()=>{
        onRemoveBreakpoint?.(id, data);
    }, [
        id,
        data,
        onRemoveBreakpoint
    ]);
    const handleClickAddGuardrail = (0, external_react_namespaceObject.useCallback)(()=>{
        onAddGuardrail?.(id, data);
    }, [
        id,
        data,
        onAddGuardrail
    ]);
    const handleClickGoToSource = (0, external_react_namespaceObject.useCallback)(()=>{
        onGoToSource?.(id, data);
    }, [
        id,
        data,
        onGoToSource
    ]);
    const handleClickRemove = (0, external_react_namespaceObject.useCallback)(()=>{
        deleteNode(id);
    }, [
        id,
        deleteNode
    ]);
    const handleClickErrorAction = (0, external_react_namespaceObject.useCallback)(()=>{
        onErrorAction?.(id, data);
    }, [
        id,
        data,
        onErrorAction
    ]);
    const handleActOnSuggestion = (0, external_react_namespaceObject.useCallback)((suggestionId, action)=>{
        actOnSuggestion(suggestionId, action);
    }, [
        actOnSuggestion
    ]);
    const executionStatus = (0, external_react_namespaceObject.useMemo)(()=>{
        if (isCurrentBreakpoint) return 'Paused';
        if (hasError) return 'Failed';
        if (hasSuccess) return 'Completed';
        if (hasRunning) return 'InProgress';
    }, [
        hasError,
        hasSuccess,
        hasRunning,
        isCurrentBreakpoint
    ]);
    const resourceIcon = (0, external_react_namespaceObject.useMemo)(()=>{
        let icon;
        switch(data.type){
            case 'context':
                icon = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ContextIcon, {
                    w: 40,
                    h: 40
                });
                break;
            case 'escalation':
                icon = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_utils_index_cjs_namespaceObject.CanvasIcon, {
                    icon: "user",
                    size: 40
                });
                break;
            case 'memorySpace':
                icon = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.MemoryIcon, {
                    w: 40,
                    h: 40
                });
                break;
            case 'mcp':
                icon = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.McpIcon, {
                    w: 40,
                    h: 40
                });
                break;
            case 'a2a':
                icon = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.A2aIcon, {
                    w: 40,
                    h: 40
                });
                break;
            case 'tool':
                icon = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ToolResourceIcon_index_cjs_namespaceObject.ToolResourceIcon, {
                    size: 48,
                    tool: data
                });
                break;
            default:
                icon = void 0;
                break;
        }
        return icon ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_layouts_index_cjs_namespaceObject.Row, {
            style: {
                color: 'var(--canvas-foreground-de-emp)'
            },
            children: icon
        }) : null;
    }, [
        data
    ]);
    const toolbarConfig = (0, external_react_namespaceObject.useMemo)(()=>{
        if ('view' === mode || data.isPlaceholder && (!isSuggestion || !suggestionId)) return null;
        if (isSuggestion && suggestionId) {
            if ('0.0.1' === suggestionGroupVersion) return null;
            const rejectAction = {
                id: 'reject-suggestion',
                icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_utils_index_cjs_namespaceObject.CanvasIcon, {
                    icon: "X",
                    size: 14
                }),
                label: suggestTranslations.reject,
                disabled: false,
                onAction: ()=>handleActOnSuggestion(suggestionId, 'reject')
            };
            const acceptAction = {
                id: 'accept-suggestion',
                icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_utils_index_cjs_namespaceObject.CanvasIcon, {
                    icon: "check",
                    size: 14
                }),
                label: suggestTranslations.accept,
                disabled: false,
                onAction: ()=>handleActOnSuggestion(suggestionId, 'accept')
            };
            return {
                actions: [
                    rejectAction,
                    acceptAction
                ],
                overflowActions: [],
                overflowLabel: '',
                position: 'top',
                align: 'center'
            };
        }
        const toggleBreakpointAction = {
            id: 'toggle-breakpoint',
            icon: void 0,
            label: (hasBreakpoint ? translations?.removeBreakpoint : translations?.addBreakpoint) ?? '',
            disabled: false,
            onAction: hasBreakpoint ? handleClickRemoveBreakpoint : handleClickAddBreakpoint
        };
        const addGuardrailAction = {
            id: 'add-guardrail',
            icon: void 0,
            label: translations?.addGuardrail ?? '',
            disabled: false,
            onAction: handleClickAddGuardrail
        };
        const goToSourceAction = {
            id: 'go-to-source',
            icon: void 0,
            label: translations?.goToSource ?? '',
            disabled: false,
            onAction: handleClickGoToSource
        };
        const removeAction = {
            id: 'remove',
            icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_utils_index_cjs_namespaceObject.CanvasIcon, {
                icon: "trash",
                size: 14
            }),
            label: translations?.remove ?? '',
            disabled: false,
            onAction: handleClickRemove
        };
        const errorCtaAction = {
            id: 'error-cta',
            icon: errorAction?.icon ?? '',
            label: errorAction?.label ?? '',
            disabled: false,
            onAction: handleClickErrorAction
        };
        const toggleEnabledAction = {
            id: 'toggle-enabled',
            icon: void 0,
            label: (isDisabled ? translations?.enable : translations?.disable) ?? '',
            disabled: false,
            onAction: isDisabled ? handleClickEnable : handleClickDisable
        };
        const separator = {
            id: 'separator',
            icon: void 0,
            label: void 0,
            disabled: false,
            onAction: ()=>{}
        };
        const actions = [
            removeAction,
            ...errorAction ? [
                errorCtaAction
            ] : []
        ];
        const overflowActions = [
            toggleBreakpointAction,
            ...'tool' === data.type ? [
                addGuardrailAction
            ] : [],
            ...data.projectId ? [
                goToSourceAction
            ] : [],
            ...'tool' === data.type ? [
                separator,
                toggleEnabledAction
            ] : []
        ];
        return {
            actions,
            overflowActions,
            overflowLabel: translations?.moreOptions ?? '',
            position: 'top',
            align: 'center'
        };
    }, [
        mode,
        data.projectId,
        data.type,
        data.isPlaceholder,
        hasBreakpoint,
        isDisabled,
        isSuggestion,
        suggestionId,
        suggestionGroupVersion,
        handleClickEnable,
        handleClickDisable,
        handleClickRemoveBreakpoint,
        handleClickAddBreakpoint,
        translations,
        handleClickAddGuardrail,
        handleClickGoToSource,
        handleClickRemove,
        handleClickErrorAction,
        handleActOnSuggestion,
        suggestTranslations,
        errorAction
    ]);
    const toolTopHandles = (0, external_react_namespaceObject.useMemo)(()=>[
            {
                id: react_cjs_namespaceObject.Position.Top,
                type: 'target',
                handleType: 'artifact',
                showButton: false
            }
        ], []);
    const toolBottomHandles = (0, external_react_namespaceObject.useMemo)(()=>[
            {
                id: react_cjs_namespaceObject.Position.Bottom,
                type: 'source',
                handleType: 'artifact',
                showButton: false
            }
        ], []);
    const contextHandles = (0, external_react_namespaceObject.useMemo)(()=>[
            {
                id: react_cjs_namespaceObject.Position.Top,
                type: 'source',
                handleType: 'artifact',
                showButton: false
            }
        ], []);
    const escalationHandles = (0, external_react_namespaceObject.useMemo)(()=>[
            {
                id: react_cjs_namespaceObject.Position.Bottom,
                type: 'target',
                handleType: 'artifact',
                showButton: false
            }
        ], []);
    const memoryHandles = (0, external_react_namespaceObject.useMemo)(()=>[
            {
                id: react_cjs_namespaceObject.Position.Bottom,
                type: 'target',
                handleType: 'artifact',
                showButton: false
            }
        ], []);
    const breakpointAdornment = (0, external_react_namespaceObject.useMemo)(()=>{
        if (!hasBreakpoint) return;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_utils_index_cjs_namespaceObject.CanvasIcon, {
            icon: "circle",
            size: 14,
            color: "#cc3d45",
            fill: "#cc3d45"
        });
    }, [
        hasBreakpoint
    ]);
    const statusAdornment = (0, external_react_namespaceObject.useMemo)(()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ExecutionStatusIcon_cjs_namespaceObject.ExecutionStatusIcon, {
            status: executionStatus,
            size: 16
        }), [
        executionStatus
    ]);
    const guardrailsAdornment = (0, external_react_namespaceObject.useMemo)(()=>{
        if (!hasGuardrails) return;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_utils_index_cjs_namespaceObject.CanvasIcon, {
            icon: "shield-check",
            size: 18,
            color: "var(--canvas-icon-default)"
        });
    }, [
        hasGuardrails
    ]);
    const suggestionAdornment = (0, external_react_namespaceObject.useMemo)(()=>{
        if (!isSuggestion) return;
        let iconName = 'arrow-left-right';
        let color = 'var(--canvas-warning-icon)';
        if ('add' === suggestionType) {
            iconName = 'circle-plus';
            color = 'var(--canvas-success-icon)';
        } else if ('delete' === suggestionType) {
            iconName = 'circle-minus';
            color = 'var(--canvas-error-icon)';
        }
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_utils_index_cjs_namespaceObject.CanvasIcon, {
            icon: iconName,
            size: 18,
            color: color
        });
    }, [
        isSuggestion,
        suggestionType
    ]);
    const handleConfigurations = (0, external_react_namespaceObject.useMemo)(()=>[
            {
                position: react_cjs_namespaceObject.Position.Top,
                handles: toolTopHandles,
                visible: ('tool' === data.type || 'mcp' === data.type || 'a2a' === data.type) && connectedHandlePosition === react_cjs_namespaceObject.Position.Top
            },
            ...data.isExpandable ? [
                {
                    position: react_cjs_namespaceObject.Position.Bottom,
                    handles: toolBottomHandles,
                    visible: ('tool' === data.type || 'mcp' === data.type || 'a2a' === data.type) && connectedHandlePosition === react_cjs_namespaceObject.Position.Bottom
                }
            ] : [],
            {
                position: react_cjs_namespaceObject.Position.Top,
                handles: contextHandles,
                visible: 'context' === data.type && connectedHandlePosition === react_cjs_namespaceObject.Position.Top
            },
            {
                position: react_cjs_namespaceObject.Position.Bottom,
                handles: escalationHandles,
                visible: 'escalation' === data.type && connectedHandlePosition === react_cjs_namespaceObject.Position.Bottom
            },
            {
                position: react_cjs_namespaceObject.Position.Bottom,
                handles: memoryHandles,
                visible: 'memorySpace' === data.type && connectedHandlePosition === react_cjs_namespaceObject.Position.Bottom
            }
        ], [
        data.type,
        data.isExpandable,
        connectedHandlePosition,
        toolTopHandles,
        toolBottomHandles,
        contextHandles,
        escalationHandles,
        memoryHandles
    ]);
    const getResourceNodeType = ()=>{
        switch(data.type){
            case 'context':
                return 'uipath.resource.context';
            case 'tool':
                return 'uipath.resource.tool';
            case 'mcp':
                return 'uipath.resource.mcp';
            case 'escalation':
                return 'uipath.resource.escalation';
            case 'memorySpace':
                return 'uipath.resource.memory';
            case 'a2a':
                return 'uipath.resource.a2a';
            default:
                return 'uipath.resource.tool';
        }
    };
    const baseNodeConfig = (0, external_react_namespaceObject.useMemo)(()=>({
            labelTooltip: displayTooltips ? data.description : void 0,
            labelBackgroundColor: 'var(--canvas-background-secondary)',
            disabled: isDisabled,
            executionStatusOverride: executionStatus,
            suggestionType,
            iconComponent: resourceIcon,
            handleConfigurations,
            toolbarConfig,
            adornments: {
                topLeft: breakpointAdornment,
                topRight: statusAdornment,
                bottomLeft: suggestionAdornment,
                bottomRight: guardrailsAdornment
            },
            shouldShowButtonHandleNotchesFn: alwaysShowNotches
        }), [
        displayTooltips,
        data.description,
        isDisabled,
        executionStatus,
        suggestionType,
        resourceIcon,
        handleConfigurations,
        toolbarConfig,
        breakpointAdornment,
        statusAdornment,
        suggestionAdornment,
        guardrailsAdornment
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(BaseNodeConfigContext_cjs_namespaceObject.BaseNodeOverrideConfigProvider, {
        value: baseNodeConfig,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(BaseNode_cjs_namespaceObject.BaseNode, {
            ...nodeProps,
            type: getResourceNodeType(),
            data: {
                ...data,
                display: {
                    iconBackground: 'var(--canvas-background-secondary)',
                    label: data.name,
                    subLabel: data.originalName,
                    shape: 'circle'
                }
            },
            id: id,
            selected: selected,
            draggable: false,
            selectable: true,
            deletable: !isSuggestion
        })
    });
});
exports.ResourceNode = __webpack_exports__.ResourceNode;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ResourceNode"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
