import { createVnode, createElement } from "./createElement";
import { Refs } from "./Refs";
import { disposeVnode } from "./dispose";

function Portal(props) {
    this.isPortal = true;
    this.container = props.container;
}
Portal.prototype = {
    constructor: Portal,
    componentWillUnmount() {
        var root = this.container;
        disposeVnode(root, this.updater.updateQueue);
    },
    componentWillReceiveProps(nextProps, context) {
        var root = root;
        Refs.receiveVnode(root, nextProps.container, context, this.updater.updateQueue, []);
    },
    componentWillMount() {
        let vnode = this.container;
        let updateQueue = this.updater.updateQueue;
        let updater = new DOMUpdater(vnode);
        let children = fiberizeChildren(vnode.props.children, updater);
        Refs.mountChildren(vnode, children, {}, updateQueue, []);
        updater.init(updateQueue);
       

        // root.return = root._return;
        //  container.return = null;
        // console.log(root);
        //  Refs.mountVnode(root,{}, this.updater.updateQueue, [] );
    },
    render() {
        return null;
    }
};
//[Top API] ReactDOM.createPortal
export function createPortal(children, node) {
    var container = createVnode(node);
    var props = container.props;
    props.children = children;
    var portal = createElement(Portal, {
        container
    });
    container._return = portal;
    return portal;
}
