import { getNodeDimensions } from "../../utils/container.js";
import { showPreviewGraph } from "../../utils/createPreviewGraph.js";
import { getAbsolutePosition, snapToGrid } from "../../utils/NodeUtils.js";
import { getContainerRelativeBodyCenter } from "./LoopNode.helpers.js";
function showCenteredContainerPreview({ containerId, reactFlowInstance, previewHandles, trailingEdgeId }) {
    const containerNode = reactFlowInstance.getNode(containerId);
    if (!containerNode) return;
    const allNodes = reactFlowInstance.getNodes();
    const containerAbsolutePosition = getAbsolutePosition(containerNode, allNodes);
    const relativeCenter = getContainerRelativeBodyCenter(containerNode);
    const containerSize = getNodeDimensions(containerNode);
    const previewCenter = {
        x: snapToGrid(containerAbsolutePosition.x + relativeCenter.x),
        y: snapToGrid(containerAbsolutePosition.y + containerSize.height / 2)
    };
    const placement = {
        containerId,
        sourceNodeId: containerId,
        targetNodeId: containerId,
        mode: 'first-child'
    };
    showPreviewGraph({
        source: {
            nodeId: containerId,
            handleId: previewHandles.sourceHandleId
        },
        reactFlowInstance,
        position: previewCenter,
        positionMode: 'center',
        handlePosition: previewHandles.sourceHandlePosition,
        target: {
            nodeId: containerId,
            handleId: previewHandles.targetHandleId
        },
        data: {
            placement
        },
        containerId,
        trailingEdgeId
    });
}
export { showCenteredContainerPreview };
