"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__, {
    useAddNodeOnConnectEnd: ()=>useAddNodeOnConnectEnd
});
const react_cjs_namespaceObject = require("../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const LoopNode_helpers_cjs_namespaceObject = require("../components/LoopNode/LoopNode.helpers.cjs");
const index_cjs_namespaceObject = require("../utils/index.cjs");
const external_useCanvasNodeLayout_cjs_namespaceObject = require("./useCanvasNodeLayout.cjs");
const EMPTY_IGNORED_NODE_TYPES = [];
function getClientPosition(event) {
    if ('clientX' in event) return {
        x: event.clientX,
        y: event.clientY
    };
    const touch = event.changedTouches?.[0] ?? event.touches?.[0];
    return touch ? {
        x: touch.clientX,
        y: touch.clientY
    } : null;
}
function useAddNodeOnConnectEnd(ignoredNodeTypes = EMPTY_IGNORED_NODE_TYPES) {
    const reactFlowInstance = (0, react_cjs_namespaceObject.useReactFlow)();
    const getManifestForNode = (0, external_useCanvasNodeLayout_cjs_namespaceObject.useNodeManifestResolver)();
    return (0, external_react_namespaceObject.useCallback)((event, connectionState)=>{
        if (!(reactFlowInstance && connectionState.fromNode && connectionState.fromHandle) || connectionState.toHandle) return;
        const clientPosition = getClientPosition(event);
        if (!clientPosition) return;
        const flowDropPosition = reactFlowInstance.screenToFlowPosition(clientPosition);
        const source = {
            nodeId: connectionState.fromNode.id,
            handleId: connectionState.fromHandle.id ?? 'output'
        };
        const containerId = (0, LoopNode_helpers_cjs_namespaceObject.getInnerHandleContainerId)({
            source,
            reactFlowInstance,
            getManifestForNode
        });
        (0, index_cjs_namespaceObject.showPreviewGraph)({
            source,
            reactFlowInstance,
            position: flowDropPosition,
            sourceHandleType: connectionState.fromHandle.type,
            handlePosition: connectionState.fromHandle.position,
            ignoredNodeTypes,
            ...containerId ? {
                containerId
            } : {}
        });
    }, [
        reactFlowInstance,
        getManifestForNode,
        ignoredNodeTypes
    ]);
}
exports.useAddNodeOnConnectEnd = __webpack_exports__.useAddNodeOnConnectEnd;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "useAddNodeOnConnectEnd"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
