import './types';
import {
    HostNodeRenderer, Host,
    ShadowNodeRenderer, ShadowDOM,
    PrimitiveRenderer, Primitive,
    NodeTreeRenderer, NativeRenderer
} from "./renderers";

/**
 * Meta data used to handle a node in the render lope
 * @typedef {VNodeRendererMeta} VNodeMeta
 * @category VDOM.renderer
 * @property {VNodeRenderer} renderer - The renderer to use to update, create or delete this node
 * @property {VNodeType} normedType - Normed type of the node
 **/


/**
 *
 * @param vnode
 * @returns {VNodeMeta|undefined}
 */
export function getNodeMeta(vnode) {
    if (vnode === undefined || vnode === null) return undefined; // Indicate it shouldn't render
    if (vnode instanceof Node){
        return {
            ...NativeRenderer.meta(),
            renderer: NativeRenderer,
            normedType: Node
        };
    }
    let type = vnode?.type;
    if (!type){
        return {
            ...PrimitiveRenderer.meta(),
            renderer: PrimitiveRenderer,
            normedType: Primitive
        };
    } else if (type === Host){
        return {
            ...HostNodeRenderer.meta(),
            renderer: HostNodeRenderer,
            normedType: Host
        };
    } else if (type === ShadowDOM){
        return {
            ...ShadowNodeRenderer.meta(),
            renderer: ShadowNodeRenderer,
            normedType: ShadowDOM
        };
    } else {
        return {
            ...NodeTreeRenderer.meta(),
            renderer: NodeTreeRenderer,
            normedType: window.customElements?.get(type) ?? type
        };
    }
}