import { jsx } from "react/jsx-runtime";
import { useReactFlow } from "../../xyflow/react.js";
import { memo, useCallback, useMemo } from "react";
import { useOptionalNodeTypeRegistry } from "../../core/index.js";
import { LoopNode } from "./LoopNode.js";
import { resolveContainerPreviewConnectionHandles } from "./LoopNode.helpers.js";
import { showCenteredContainerPreview } from "./LoopNodePreview.js";
function LoopCanvasNodeComponent(props) {
    const reactFlow = useReactFlow();
    const nodeTypeRegistry = useOptionalNodeTypeRegistry();
    const nodeManifest = useMemo(()=>props.type ? nodeTypeRegistry?.getManifest(props.type) : void 0, [
        nodeTypeRegistry,
        props.type
    ]);
    const containerPreviewHandles = useMemo(()=>resolveContainerPreviewConnectionHandles(nodeManifest, {
            ...props.data ?? {},
            nodeId: props.id
        }), [
        nodeManifest,
        props.data,
        props.id
    ]);
    const handleAddFirstChild = useCallback(()=>{
        if (!containerPreviewHandles) return;
        showCenteredContainerPreview({
            containerId: props.id,
            reactFlowInstance: reactFlow,
            previewHandles: containerPreviewHandles
        });
    }, [
        containerPreviewHandles,
        props.id,
        reactFlow
    ]);
    return /*#__PURE__*/ jsx(LoopNode, {
        ...props,
        onAddFirstChild: containerPreviewHandles ? handleAddFirstChild : void 0
    });
}
const LoopCanvasNode = /*#__PURE__*/ memo(LoopCanvasNodeComponent);
export { LoopCanvasNode };
