"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    StageEdgeLabel: ()=>StageEdgeLabel,
    StageEdge: ()=>StageEdge
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const styled_namespaceObject = require("@emotion/styled");
var styled_default = /*#__PURE__*/ __webpack_require__.n(styled_namespaceObject);
const react_cjs_namespaceObject = require("../../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const StageEdgeLabel = styled_default().div`
  position: absolute;
  color: var(--canvas-foreground);
  background: var(--canvas-background);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--canvas-border);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  pointer-events: all;

  &:hover {
    background: var(--canvas-background-hover);
    border-color: var(--canvas-border-hover);
  }
`;
function stageEdgeGeometryEquality(previous, next) {
    return previous.sourceX === next.sourceX && previous.sourceY === next.sourceY && previous.targetX === next.targetX && previous.targetY === next.targetY;
}
function getArrowFromBezier(path, arrowSize) {
    const pathEl = document.createElementNS('http://www.w3.org/2000/svg', 'path');
    pathEl.setAttribute('d', path);
    const totalLength = pathEl.getTotalLength();
    const endPoint = pathEl.getPointAtLength(totalLength);
    const prevPoint = pathEl.getPointAtLength(totalLength - arrowSize);
    const angle = Math.atan2(endPoint.y - prevPoint.y, endPoint.x - prevPoint.x);
    return {
        endX: endPoint.x,
        endY: endPoint.y,
        angle
    };
}
function StageEdgeInner({ geometry, sourcePosition, targetPosition, selected, style, stroke = 'var(--canvas-foreground-emp)', strokeWidth = 2, arrowSize = 8, ...rest }) {
    const [pathData, labelX, labelY, _ex, _ey] = (0, react_cjs_namespaceObject.getSmoothStepPath)({
        sourceX: geometry.sourceX,
        sourceY: geometry.sourceY,
        sourcePosition,
        targetX: geometry.targetX - 1,
        targetY: geometry.targetY,
        targetPosition,
        borderRadius: 40
    });
    const { endX, endY, angle } = (0, external_react_namespaceObject.useMemo)(()=>getArrowFromBezier(pathData, arrowSize), [
        pathData,
        arrowSize
    ]);
    const arrowLineLength = arrowSize;
    const strokeColor = selected ? 'var(--canvas-selection-indicator)' : stroke;
    const strokeWidthValue = selected ? strokeWidth + 1 : strokeWidth;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("g", {
                className: `react-flow__edge stage-edge ${selected ? 'selected' : ''}`,
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("path", {
                        d: pathData,
                        stroke: strokeColor,
                        strokeWidth: strokeWidthValue,
                        strokeLinecap: "round",
                        strokeLinejoin: "round",
                        fill: "none",
                        style: style
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("line", {
                        x1: endX,
                        y1: endY,
                        x2: endX - arrowLineLength * Math.cos(angle - Math.PI / 6),
                        y2: endY - arrowLineLength * Math.sin(angle - Math.PI / 6),
                        stroke: strokeColor,
                        strokeWidth: strokeWidthValue
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("line", {
                        x1: endX,
                        y1: endY,
                        x2: endX - arrowLineLength * Math.cos(angle + Math.PI / 6),
                        y2: endY - arrowLineLength * Math.sin(angle + Math.PI / 6),
                        stroke: strokeColor,
                        strokeWidth: strokeWidthValue
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("path", {
                        d: pathData,
                        stroke: "transparent",
                        strokeWidth: 20,
                        fill: "none",
                        pointerEvents: "stroke"
                    })
                ]
            }),
            rest.label && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_cjs_namespaceObject.EdgeLabelRenderer, {
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(StageEdgeLabel, {
                    style: {
                        transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`
                    },
                    className: "nodrag nopan",
                    children: rest.label
                })
            })
        ]
    });
}
const StageEdgeInnerMemo = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(StageEdgeInner);
function StageEdgeComponent({ sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, selected, style, stroke, strokeWidth, arrowSize, ...rest }) {
    const geometry = (0, react_cjs_namespaceObject.useStore)((state)=>{
        const sourceNode = state.nodeLookup.get(rest.source);
        const targetNode = state.nodeLookup.get(rest.target);
        return {
            sourceX: sourceNode ? sourceNode.position.x + (sourceNode.measured?.width ?? 0) : sourceX,
            sourceY: sourceNode ? sourceNode.position.y + 32 : sourceY,
            targetX: targetNode?.position.x ?? targetX,
            targetY: targetNode ? targetNode.position.y + 32 : targetY
        };
    }, stageEdgeGeometryEquality);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(StageEdgeInnerMemo, {
        geometry: geometry,
        sourcePosition: sourcePosition,
        targetPosition: targetPosition,
        selected: selected,
        style: style,
        stroke: stroke,
        strokeWidth: strokeWidth,
        arrowSize: arrowSize,
        ...rest
    });
}
const StageEdge = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(StageEdgeComponent);
exports.StageEdge = __webpack_exports__.StageEdge;
exports.StageEdgeLabel = __webpack_exports__.StageEdgeLabel;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "StageEdge",
    "StageEdgeLabel"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
