"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__, {
    useEdgePath: ()=>useEdgePath
});
const react_cjs_namespaceObject = require("../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const external_constants_cjs_namespaceObject = require("../constants.cjs");
const LOOP_HEIGHT = 6 * external_constants_cjs_namespaceObject.GRID_SPACING;
const LOOP_SUCCESS_HEIGHT = 7 * external_constants_cjs_namespaceObject.GRID_SPACING;
const LOOP_RIGHT_EXTENSION = 3 * external_constants_cjs_namespaceObject.GRID_SPACING;
const LOOP_SUCCESS_RIGHT_EXTENSION = 4 * external_constants_cjs_namespaceObject.GRID_SPACING;
const LOOP_LEFT_EXTENSION = 2 * external_constants_cjs_namespaceObject.GRID_SPACING;
const LOOP_CORNER_RADIUS = external_constants_cjs_namespaceObject.GRID_SPACING;
const SOURCE_OFFSETS = {
    [react_cjs_namespaceObject.Position.Left]: {
        x: 8,
        y: 0
    },
    [react_cjs_namespaceObject.Position.Right]: {
        x: -8,
        y: 0
    },
    [react_cjs_namespaceObject.Position.Top]: {
        x: 0,
        y: 8
    },
    [react_cjs_namespaceObject.Position.Bottom]: {
        x: 0,
        y: -8
    }
};
const snapToGrid = (value)=>Math.round(value / external_constants_cjs_namespaceObject.GRID_SPACING) * external_constants_cjs_namespaceObject.GRID_SPACING;
const createLoopPath = ({ sourceX, sourceY, sourcePosition, targetX, targetY, sourceHandleId })=>{
    const offsets = SOURCE_OFFSETS[sourcePosition];
    const sourceOffsetX = sourceX + offsets.x;
    const sourceOffsetY = sourceY + offsets.y;
    const loopHeight = 'success' === sourceHandleId ? LOOP_SUCCESS_HEIGHT : LOOP_HEIGHT;
    const bottomY = Math.max(sourceOffsetY, targetY) + loopHeight;
    const rightExtension = 'success' === sourceHandleId ? LOOP_SUCCESS_RIGHT_EXTENSION : LOOP_RIGHT_EXTENSION;
    const rightPoint = snapToGrid(sourceX + rightExtension);
    const leftPoint = snapToGrid(targetX - LOOP_LEFT_EXTENSION);
    const path = `
    M ${sourceOffsetX} ${sourceOffsetY}
    L ${rightPoint - LOOP_CORNER_RADIUS} ${sourceOffsetY}
    Q ${rightPoint} ${sourceOffsetY} ${rightPoint} ${sourceOffsetY + LOOP_CORNER_RADIUS}
    L ${rightPoint} ${bottomY - LOOP_CORNER_RADIUS}
    Q ${rightPoint} ${bottomY} ${rightPoint - LOOP_CORNER_RADIUS} ${bottomY}
    L ${leftPoint + LOOP_CORNER_RADIUS} ${bottomY}
    Q ${leftPoint} ${bottomY} ${leftPoint} ${bottomY - LOOP_CORNER_RADIUS}
    L ${leftPoint} ${targetY + LOOP_CORNER_RADIUS}
    Q ${leftPoint} ${targetY} ${leftPoint + LOOP_CORNER_RADIUS} ${targetY}
    L ${targetX} ${targetY}
  `.trim().replace(/\s+/g, ' ');
    return {
        path,
        loopHeight
    };
};
function useEdgePath({ sourceNodeId, sourceHandleId, sourceX, sourceY, sourcePosition, targetNodeId, targetHandleId, targetX, targetY, targetPosition }) {
    return (0, external_react_namespaceObject.useMemo)(()=>{
        const isSelfLoop = sourceNodeId === targetNodeId;
        const isLoopBackEdge = 'loopBack' === targetHandleId;
        const needsCustomPath = isSelfLoop || isLoopBackEdge;
        let edgePath;
        let labelX;
        let labelY;
        if (needsCustomPath) {
            const { path, loopHeight } = createLoopPath({
                sourceX,
                sourceY,
                sourceNodeId,
                sourceHandleId,
                sourcePosition,
                targetNodeId,
                targetHandleId,
                targetX,
                targetY,
                targetPosition
            });
            edgePath = path;
            labelX = (sourceX + targetX) / 2;
            labelY = Math.max(sourceY, targetY) + loopHeight;
        } else {
            const { sourceOffsetX, sourceOffsetY } = {
                sourceOffsetX: sourceX + SOURCE_OFFSETS[sourcePosition].x,
                sourceOffsetY: sourceY + SOURCE_OFFSETS[sourcePosition].y
            };
            [edgePath, labelX, labelY] = (0, react_cjs_namespaceObject.getSmoothStepPath)({
                sourceX: sourceOffsetX,
                sourceY: sourceOffsetY,
                sourcePosition,
                targetX,
                targetY,
                targetPosition,
                borderRadius: 16
            });
        }
        return {
            edgePath,
            labelX,
            labelY,
            isLoopEdge: needsCustomPath
        };
    }, [
        sourceNodeId,
        targetNodeId,
        targetHandleId,
        sourceHandleId,
        sourceX,
        sourceY,
        targetX,
        targetY,
        sourcePosition,
        targetPosition
    ]);
}
exports.useEdgePath = __webpack_exports__.useEdgePath;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "useEdgePath"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
