import { Position, getSmoothStepPath } from "../../../node_modules/@xyflow/system/dist/esm/index.js";
var SELF_LOOP_OFFSET = 75, SELF_LOOP_EXTEND = 20, SELF_LOOP_NODE_W = 130, SELF_LOOP_NODE_H = 70;
function selfLoopPath(n, s, c) {
	if (c === Position.Bottom || c === Position.Top) {
		let e = n, a = s - SELF_LOOP_NODE_H;
		return {
			path: `M ${n} ${s} C ${n + SELF_LOOP_OFFSET} ${s + SELF_LOOP_EXTEND}, ${e + SELF_LOOP_OFFSET} ${a - SELF_LOOP_EXTEND}, ${e} ${a}`,
			labelX: n + SELF_LOOP_OFFSET + 8,
			labelY: (s + a) / 2
		};
	}
	let l = n - SELF_LOOP_NODE_W, u = s;
	return {
		path: `M ${n} ${s} C ${n + SELF_LOOP_EXTEND} ${s + SELF_LOOP_OFFSET}, ${l - SELF_LOOP_EXTEND} ${u + SELF_LOOP_OFFSET}, ${l} ${u}`,
		labelX: (n + l) / 2,
		labelY: s + SELF_LOOP_OFFSET + 8
	};
}
var BACK_EDGE_MIN_OFFSET = 60;
function backEdgePath(n, r, i, a, o) {
	if (o === Position.Bottom) {
		let e = Math.abs(n - i), o = Math.max(e * .3, BACK_EDGE_MIN_OFFSET);
		return {
			path: `M ${n} ${r} C ${n} ${r + o}, ${i} ${a + o}, ${i} ${a}`,
			labelX: (n + i) / 2,
			labelY: Math.max(r, a) + o + 10
		};
	}
	let s = Math.abs(r - a), l = Math.max(s * .3, BACK_EDGE_MIN_OFFSET);
	return {
		path: `M ${n} ${r} C ${n + l} ${r}, ${i + l} ${a}, ${i} ${a}`,
		labelX: Math.max(n, i) + l + 10,
		labelY: (r + a) / 2
	};
}
function forwardEdgePath(e) {
	let [r, i, a] = getSmoothStepPath(e);
	return {
		path: r,
		labelX: i,
		labelY: a
	};
}
function resolveEdgePath(e, n) {
	return n.isSelfLoop ? selfLoopPath(e.sourceX, e.sourceY, e.sourcePosition) : n.isBackEdge ? backEdgePath(e.sourceX, e.sourceY, e.targetX, e.targetY, e.sourcePosition) : forwardEdgePath(e);
}
export { resolveEdgePath };
