"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__, {
    CanvasEdge: ()=>CanvasEdge_CanvasEdge
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const react_cjs_namespaceObject = require("../../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const createPreviewNode_cjs_namespaceObject = require("../../utils/createPreviewNode.cjs");
const BaseCanvasModeProvider_cjs_namespaceObject = require("../BaseCanvas/BaseCanvasModeProvider.cjs");
const index_cjs_namespaceObject = require("../Toolbar/index.cjs");
const areEdgePropsEqual_cjs_namespaceObject = require("./shared/areEdgePropsEqual.cjs");
const constants_cjs_namespaceObject = require("./shared/constants.cjs");
const geometry_cjs_namespaceObject = require("./shared/geometry.cjs");
const hooks_index_cjs_namespaceObject = require("./shared/hooks/index.cjs");
const primitives_index_cjs_namespaceObject = require("./shared/primitives/index.cjs");
const resolveEdgeColor_cjs_namespaceObject = require("./shared/resolveEdgeColor.cjs");
const CanvasEdge_CanvasEdge = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(function({ id, selected, animated, source, target, sourceX, sourceY, sourcePosition = react_cjs_namespaceObject.Position.Right, targetX, targetY, targetPosition = react_cjs_namespaceObject.Position.Left, sourceHandleId, targetHandleId, style, data }) {
    const isReadOnly = 'readonly' === (0, BaseCanvasModeProvider_cjs_namespaceObject.useBaseCanvasMode)().mode;
    const [isHovered, setIsHovered] = (0, external_react_namespaceObject.useState)(false);
    const onMouseEnter = (0, external_react_namespaceObject.useCallback)(()=>setIsHovered(true), []);
    const onMouseLeave = (0, external_react_namespaceObject.useCallback)(()=>setIsHovered(false), []);
    const pathRef = (0, external_react_namespaceObject.useRef)(null);
    const routing = data?.routing ?? 'waypoint';
    const storedWaypoints = data?.waypoints ?? constants_cjs_namespaceObject.EMPTY_WAYPOINTS;
    const strokeStyle = data?.strokeStyle ?? 'solid';
    const hideArrowHead = !!data?.hideArrowHead;
    const label = data?.label;
    const editingEnabled = !!data?.enableEditing && 'waypoint' === routing && !isReadOnly;
    const waypoints = (0, hooks_index_cjs_namespaceObject.useNodeDragRebalance)({
        edgeId: id,
        source,
        target,
        sourceX,
        sourceY,
        sourcePosition,
        targetX,
        targetY,
        targetPosition,
        waypoints: storedWaypoints,
        enabled: editingEnabled,
        onChange: data?.onWaypointsChange
    });
    const routedWaypoints = data?.routedWaypoints ?? constants_cjs_namespaceObject.EMPTY_WAYPOINTS;
    const effectiveWaypoints = waypoints.length > 0 ? waypoints : routedWaypoints;
    const executionEnabled = !!data?.enableExecution;
    const toolbarEnabled = !!data?.enableToolbar && !isReadOnly;
    const previewEdge = (0, createPreviewNode_cjs_namespaceObject.isPreviewEdge)({
        id,
        source,
        target
    });
    const geometry = (0, hooks_index_cjs_namespaceObject.useEdgeGeometry)({
        routing,
        sourceNodeId: source,
        targetNodeId: target,
        sourceHandleId,
        targetHandleId,
        sourceX,
        sourceY,
        sourcePosition,
        targetX,
        targetY,
        targetPosition,
        waypoints: effectiveWaypoints,
        enableSegments: editingEnabled,
        hideArrowHead
    });
    const editor = (0, hooks_index_cjs_namespaceObject.useWaypointEditor)({
        edgeId: id,
        waypoints,
        pathPoints: geometry.pathPoints,
        enabled: editingEnabled,
        onChange: data?.onWaypointsChange
    });
    const execution = (0, hooks_index_cjs_namespaceObject.useExecutionEdge)({
        edgeId: id,
        target,
        edgePath: geometry.edgePath,
        enabled: executionEnabled
    });
    const isDiffRemoved = data?.isDiffRemoved ?? false;
    const color = (0, resolveEdgeColor_cjs_namespaceObject.resolveEdgeColor)({
        selected,
        isHovered,
        isInvalid: data?.isInvalid ?? false,
        isDiffAdded: data?.isDiffAdded ?? false,
        isDiffRemoved,
        previewEdge,
        statusColor: execution.statusColor
    });
    const toolbar = (0, index_cjs_namespaceObject.useEdgeToolbarState)({
        edgeId: id,
        pathElementRef: pathRef,
        isHovered: toolbarEnabled && isHovered,
        source,
        target,
        sourceHandleId,
        targetHandleId,
        sourcePosition,
        targetPosition
    });
    const showEditingChrome = editingEnabled && (isHovered || selected || editor.isDragging);
    const opacity = style?.opacity ?? 1;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("g", {
                onMouseEnter: onMouseEnter,
                onMouseLeave: onMouseLeave,
                onMouseMove: toolbarEnabled ? toolbar.handleMouseMoveOnPath : void 0,
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(primitives_index_cjs_namespaceObject.EdgePath, {
                        id: id,
                        d: geometry.edgePath,
                        color: color,
                        selected: selected,
                        animated: animated,
                        strokeStyle: previewEdge || isDiffRemoved ? 'dashed' : strokeStyle,
                        isReadOnly: isReadOnly,
                        style: style,
                        opacity: opacity,
                        pathRef: pathRef
                    }),
                    showEditingChrome && geometry.segments.map((segment, index)=>{
                        if (!(0, geometry_cjs_namespaceObject.isSegmentInteractable)(segment) || !(0, geometry_cjs_namespaceObject.isSegmentPerpendicular)(segment)) return null;
                        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(primitives_index_cjs_namespaceObject.SegmentDragHandle, {
                            segment: segment,
                            segmentIndex: index,
                            handlers: editor.segmentHandlers
                        }, segment.id);
                    }),
                    editingEnabled && waypoints.map((waypoint, index)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(primitives_index_cjs_namespaceObject.WaypointHandle, {
                            waypoint: waypoint,
                            index: index,
                            forceVisible: showEditingChrome,
                            handlers: editor.waypointHandlers
                        }, waypoint.id)),
                    !hideArrowHead && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(primitives_index_cjs_namespaceObject.EdgeArrow, {
                        target: {
                            x: targetX,
                            y: targetY
                        },
                        angle: geometry.arrow.angle,
                        offset: geometry.arrow.offset,
                        color: color,
                        opacity: opacity
                    }),
                    execution.animation,
                    'string' == typeof label && label.length > 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(primitives_index_cjs_namespaceObject.EdgeLabel, {
                        x: geometry.labelPoint.x,
                        y: geometry.labelPoint.y,
                        text: label,
                        selected: selected
                    })
                ]
            }),
            toolbarEnabled && toolbar.showToolbar && toolbar.toolbarPositioning && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.EdgeToolbar, {
                edgeId: id,
                visible: toolbar.showToolbar,
                positioning: toolbar.toolbarPositioning,
                config: toolbar.config,
                onMouseEnter: onMouseEnter,
                onMouseLeave: onMouseLeave
            })
        ]
    });
}, areEdgePropsEqual_cjs_namespaceObject.areEdgePropsEqual);
exports.CanvasEdge = __webpack_exports__.CanvasEdge;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "CanvasEdge"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
