import type { Node, NodePathMap } from "godot"
import * as Reconciler from "./Reconciler.js"


const ConcurrentRoot = 1

export const render = (element: React.ReactNode, container: Node<NodePathMap>, callback?: () => void): number => {
    const reconciler = Reconciler.make()

    if (!(container as any)._rootContainer)
        (container as any)._rootContainer = (reconciler as any).createContainer(
            container,
            ConcurrentRoot,
            null,
            false,
            false,
            "",
            console.error,
        )

    return reconciler.updateContainer(
        element,
        (container as any)._rootContainer,
        null,
        callback,
    )
}
