"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__, {
    useEdgeToolbarState: ()=>useEdgeToolbarState
});
const react_cjs_namespaceObject = require("../../../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const external_constants_cjs_namespaceObject = require("../../../constants.cjs");
const useCanvasNodeLayout_cjs_namespaceObject = require("../../../hooks/useCanvasNodeLayout.cjs");
const createPreviewGraph_cjs_namespaceObject = require("../../../utils/createPreviewGraph.cjs");
const createPreviewNode_cjs_namespaceObject = require("../../../utils/createPreviewNode.cjs");
const BaseCanvasModeProvider_cjs_namespaceObject = require("../../BaseCanvas/BaseCanvasModeProvider.cjs");
const LoopNode_helpers_cjs_namespaceObject = require("../../LoopNode/LoopNode.helpers.cjs");
const external_useEdgeToolbarPositioning_cjs_namespaceObject = require("./useEdgeToolbarPositioning.cjs");
function useEdgeToolbarState({ edgeId, pathElementRef, isHovered, source, target, sourceHandleId, targetHandleId, sourcePosition, targetPosition, ignoredNodeTypes }) {
    const reactFlow = (0, react_cjs_namespaceObject.useReactFlow)();
    const { getManifestForNode } = (0, useCanvasNodeLayout_cjs_namespaceObject.useCanvasNodeLayout)();
    const { mode } = (0, BaseCanvasModeProvider_cjs_namespaceObject.useBaseCanvasMode)();
    const isDesignMode = 'design' === mode;
    const previewEdge = (0, createPreviewNode_cjs_namespaceObject.isPreviewEdge)({
        id: edgeId,
        source,
        target
    });
    const { positionData, handleMouseMoveOnPath } = (0, external_useEdgeToolbarPositioning_cjs_namespaceObject.useEdgeToolbarPositioning)({
        pathElementRef,
        isEnabled: isHovered && isDesignMode && !previewEdge,
        targetPosition
    });
    const handleAddNodeOnEdge = (0, external_react_namespaceObject.useCallback)((position)=>{
        const originalEdge = reactFlow.getEdges().find((edge)=>edge.id === edgeId);
        if (!originalEdge) return;
        const sourceEndpoint = {
            nodeId: source,
            handleId: sourceHandleId ?? external_constants_cjs_namespaceObject.DEFAULT_SOURCE_HANDLE_ID
        };
        const containerOverrides = (0, LoopNode_helpers_cjs_namespaceObject.resolveContainerAddNodePreview)({
            source: sourceEndpoint,
            sourceHandleType: 'source',
            reactFlowInstance: reactFlow,
            getManifestForNode,
            replacedEdge: originalEdge
        });
        (0, createPreviewGraph_cjs_namespaceObject.showPreviewGraph)({
            source: sourceEndpoint,
            reactFlowInstance: reactFlow,
            position,
            positionMode: 'drop',
            data: {
                originalEdge
            },
            sourceHandleType: 'source',
            handlePosition: sourcePosition,
            ignoredNodeTypes: ignoredNodeTypes ?? [],
            target: {
                nodeId: target,
                handleId: targetHandleId
            },
            ...containerOverrides ?? {}
        });
    }, [
        sourcePosition,
        source,
        sourceHandleId,
        reactFlow,
        getManifestForNode,
        target,
        targetHandleId,
        edgeId,
        ignoredNodeTypes
    ]);
    const config = (0, external_react_namespaceObject.useMemo)(()=>({
            actions: [
                {
                    id: 'add-node',
                    icon: 'plus',
                    label: 'Add node',
                    disabled: false,
                    onAction: (_edgeId, position)=>{
                        handleAddNodeOnEdge(position);
                    }
                }
            ]
        }), [
        handleAddNodeOnEdge
    ]);
    const showToolbar = isHovered && isDesignMode && null !== positionData && !previewEdge;
    return {
        showToolbar,
        toolbarPositioning: positionData,
        config,
        handleMouseMoveOnPath
    };
}
exports.useEdgeToolbarState = __webpack_exports__.useEdgeToolbarState;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "useEdgeToolbarState"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
