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

function Portal(props) {
    this.isPortal = true;
    this.container = props.container;
}
Portal.prototype = {
    constructor: Portal,
    componentWillUnmount() {
        var vnode = this.container;
        disposeChildren(vnode.updater.children, this.updater.updateQueue);
    },
    componentWillReceiveProps(nextProps, context) {
        var vnode = this.container;
        Refs.receiveVnode(vnode, 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);
        mountChildren(vnode, children, context, updateQueue, []);
        // vnode._disposed = true;
        //  Refs.mountVnode(vnode,{}, this.updater.updateQueue, [] );
        //  vnode._disposed = false;
    },
    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;
}
