"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__, {
    SequenceEdge: ()=>SequenceEdge_SequenceEdge
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const react_cjs_namespaceObject = require("../../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const index_cjs_namespaceObject = require("../../hooks/index.cjs");
const createPreviewNode_cjs_namespaceObject = require("../../utils/createPreviewNode.cjs");
const BaseCanvasModeProvider_cjs_namespaceObject = require("../BaseCanvas/BaseCanvasModeProvider.cjs");
const external_Toolbar_index_cjs_namespaceObject = require("../Toolbar/index.cjs");
const external_EdgeUtils_cjs_namespaceObject = require("./EdgeUtils.cjs");
const ARROW_SIZE = 10;
const ANGLE_MAP = {
    [react_cjs_namespaceObject.Position.Left]: 0,
    [react_cjs_namespaceObject.Position.Right]: Math.PI,
    [react_cjs_namespaceObject.Position.Top]: Math.PI / 2,
    [react_cjs_namespaceObject.Position.Bottom]: -Math.PI / 2
};
const ARROW_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
    }
};
function areEdgePropsEqual(prevProps, nextProps) {
    if (prevProps.id !== nextProps.id) return false;
    if (prevProps.selected !== nextProps.selected) return false;
    if (prevProps.source !== nextProps.source) return false;
    if (prevProps.target !== nextProps.target) return false;
    if (prevProps.sourcePosition !== nextProps.sourcePosition) return false;
    if (prevProps.targetPosition !== nextProps.targetPosition) return false;
    if (prevProps.data !== nextProps.data) return false;
    if (prevProps.style !== nextProps.style) return false;
    const threshold = 0.5;
    if (Math.abs(prevProps.sourceX - nextProps.sourceX) > threshold) return false;
    if (Math.abs(prevProps.sourceY - nextProps.sourceY) > threshold) return false;
    if (Math.abs(prevProps.targetX - nextProps.targetX) > threshold) return false;
    if (Math.abs(prevProps.targetY - nextProps.targetY) > threshold) return false;
    return true;
}
const SequenceEdge_SequenceEdge = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(function({ id, selected, source, sourceX, sourceY, sourcePosition, sourceHandleId, target, targetX, targetY, targetPosition, targetHandleId, style, data }) {
    const [isHovered, setIsHovered] = (0, external_react_namespaceObject.useState)(false);
    const pathElementRef = (0, external_react_namespaceObject.useRef)(null);
    const { mode } = (0, BaseCanvasModeProvider_cjs_namespaceObject.useBaseCanvasMode)();
    const isReadOnly = 'readonly' === mode;
    const previewEdge = (0, createPreviewNode_cjs_namespaceObject.isPreviewEdge)({
        id,
        source,
        target
    });
    const executionStatus = (0, index_cjs_namespaceObject.useEdgeExecutionState)(id, target);
    const { validationStatus } = (0, index_cjs_namespaceObject.useElementValidationStatus)(id) ?? {
        validationStatus: void 0
    };
    const status = executionStatus ? executionStatus?.status ?? executionStatus : validationStatus;
    const isDiffAdded = data?.isDiffAdded === true;
    const isDiffRemoved = data?.isDiffRemoved === true;
    const hideArrowHead = data?.hideArrowHead === true;
    const hideToolbar = data?.hideToolbar === true;
    const angle = ANGLE_MAP[targetPosition];
    const { x: offsetX, y: offsetY } = ARROW_OFFSETS[targetPosition];
    const { edgePath, labelX, labelY } = (0, index_cjs_namespaceObject.useEdgePath)({
        sourceNodeId: source,
        targetNodeId: target,
        sourceHandleId,
        targetHandleId,
        sourceX,
        sourceY,
        sourcePosition,
        targetX: hideArrowHead ? targetX + offsetX : targetX,
        targetY: hideArrowHead ? targetY + offsetY : targetY,
        targetPosition
    });
    const { showToolbar, toolbarPositioning, config: toolbarConfig, handleMouseMoveOnPath } = (0, external_Toolbar_index_cjs_namespaceObject.useEdgeToolbarState)({
        edgeId: id,
        pathElementRef,
        isHovered,
        sourceHandleId,
        targetHandleId,
        sourcePosition,
        targetPosition,
        source,
        target
    });
    const getEdgeColor = ()=>{
        if (isDiffAdded) return 'var(--canvas-success-icon)';
        if (isDiffRemoved) return 'var(--canvas-error-icon)';
        if (previewEdge) return 'var(--canvas-primary)';
        if (selected) return 'var(--canvas-primary)';
        if (isHovered) return 'var(--canvas-primary-hover)';
        if (status) return external_EdgeUtils_cjs_namespaceObject.edgeTargetStatusToEdgeColor[status] ?? 'var(--canvas-border)';
        return 'var(--canvas-border)';
    };
    const edgeColor = getEdgeColor();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("g", {
                onMouseEnter: ()=>setIsHovered(true),
                onMouseLeave: ()=>setIsHovered(false),
                onMouseMove: handleMouseMoveOnPath,
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("path", {
                        className: "react-flow__edge-interaction",
                        d: edgePath,
                        fill: "none",
                        stroke: "transparent",
                        strokeWidth: 20,
                        style: {
                            pointerEvents: 'stroke',
                            cursor: isReadOnly ? 'default' : 'pointer'
                        }
                    }),
                    selected && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("path", {
                        className: "react-flow__edge-outline",
                        d: edgePath,
                        fill: "none",
                        stroke: "var(--canvas-primary)",
                        strokeWidth: 10,
                        opacity: 0.3,
                        style: {
                            pointerEvents: 'none',
                            transition: 'opacity 0.2s ease'
                        }
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("path", {
                        id: id,
                        className: "react-flow__edge-path",
                        d: edgePath,
                        strokeWidth: style?.strokeWidth || 2,
                        style: {
                            stroke: edgeColor,
                            strokeDasharray: isDiffRemoved ? style?.strokeDasharray || '5,5' : previewEdge ? '5,5' : '0',
                            opacity: style?.opacity !== void 0 ? style.opacity : 1,
                            transition: 'stroke 0.2s ease, opacity 0.2s ease'
                        },
                        ref: pathElementRef
                    }),
                    !hideArrowHead && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("polygon", {
                        points: `
              ${targetX},${targetY}
              ${targetX - ARROW_SIZE * Math.cos(angle - Math.PI / 6)},${targetY - ARROW_SIZE * Math.sin(angle - Math.PI / 6)}
              ${targetX - ARROW_SIZE * Math.cos(angle + Math.PI / 6)},${targetY - ARROW_SIZE * Math.sin(angle + Math.PI / 6)}
            `,
                        fill: edgeColor,
                        style: {
                            pointerEvents: 'none',
                            opacity: style?.opacity !== void 0 ? style.opacity : 1,
                            transition: 'fill 0.2s ease, opacity 0.2s ease',
                            transform: `translate(${offsetX}px, ${offsetY}px)`
                        }
                    }),
                    (0, external_EdgeUtils_cjs_namespaceObject.getStatusAnimation)(status, edgePath),
                    'string' == typeof data?.label && data.label.length > 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("foreignObject", {
                        x: labelX,
                        y: labelY,
                        width: 1,
                        height: 1,
                        overflow: "visible",
                        style: {
                            pointerEvents: 'none'
                        },
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                            className: "react-flow__edge-label nodrag nopan",
                            style: {
                                position: 'absolute',
                                transform: 'translate(-50%, -50%)',
                                whiteSpace: 'nowrap',
                                pointerEvents: 'none',
                                color: 'var(--canvas-foreground)',
                                background: 'var(--canvas-background)',
                                padding: '4px 8px',
                                borderRadius: '4px',
                                fontSize: '12px',
                                fontWeight: 500,
                                border: `1px solid ${selected ? 'var(--canvas-primary)' : 'var(--canvas-border)'}`,
                                boxShadow: '0 1px 3px 0 rgba(0, 0, 0, 0.1)'
                            },
                            children: data.label
                        })
                    })
                ]
            }),
            !hideToolbar && showToolbar && toolbarPositioning && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_Toolbar_index_cjs_namespaceObject.EdgeToolbar, {
                edgeId: id,
                visible: showToolbar,
                positioning: toolbarPositioning,
                config: toolbarConfig,
                onMouseEnter: ()=>setIsHovered(true),
                onMouseLeave: ()=>setIsHovered(false)
            })
        ]
    });
}, areEdgePropsEqual);
exports.SequenceEdge = __webpack_exports__.SequenceEdge;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "SequenceEdge"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
