import { useCallback, useMemo } from "react";
import { useOptionalNodeTypeRegistry } from "../core/index.js";
import { getExpandedSize } from "../utils/collapse.js";
import { getContainerFitGeometry, getNodeDimensions as container_js_getNodeDimensions, isContainerNodeManifest } from "../utils/container.js";
function useNodeManifestResolver() {
    const registry = useOptionalNodeTypeRegistry();
    return useCallback((node)=>node.type ? registry?.getManifest(node.type) : void 0, [
        registry
    ]);
}
function useCanvasNodeLayout() {
    const getManifestForNode = useNodeManifestResolver();
    return useMemo(()=>{
        const getNodeDimensions = (node)=>{
            const manifest = getManifestForNode(node);
            return container_js_getNodeDimensions(node, getExpandedSize(manifest?.display.shape));
        };
        const isContainerNode = (node)=>isContainerNodeManifest(getManifestForNode(node));
        return {
            getManifestForNode,
            getNodeDimensions,
            isContainerNode,
            getContainerFitGeometry: (node)=>isContainerNode(node) ? getContainerFitGeometry() : null
        };
    }, [
        getManifestForNode
    ]);
}
export { useCanvasNodeLayout, useNodeManifestResolver };
