import '../types';

export const ShadowDOM = Symbol('ShadowDOM');

/**
 * Takes care of rendering a ShadowDOM-node
 *
 * @class
 * @implements {VNodeRenderer}
 */
export const ShadowNodeRenderer = {
    /**
     * @param {VRenderItem} item
     */
    create(item) {
        if (!item.parent) throw new Error("ShadowDOM node cannot appear as a top-level element unless a parent is provided");
        else return item.parent.shadowRoot || item.parent.attachShadow({ mode: 'open' });// TODO Pass props as options? (e.g. delegateFocus, mode)
    },
    
    /**
     * @param {VRenderItem} item
     */
    remove(item){
        // TODO there is no detachShadow function provided by the DOM, how would one ever remove a shadowRoot??
    },
    
    /**
     * @param {VRenderItem} item
     */
    update(item) {
        item.host = item.host || item.parent.shadowRoot;
    },
};
