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

function Portal(props) {
    this.isPortal = true;
    this.container = props.container;
    this.children = props._children;
}
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 props = this.props;
        console.log(this.props);
        let updateQueue = this.updater.updateQueue;
        vnode.props.children = this.children;
        let updater = new DOMUpdater(vnode);
        let children = this.__children = fiberizeChildren(props._children, updater);
        Refs.mountChildren(vnode, children, {}, 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,
        _children: children
    });
    // container.return = portal;
    return portal;
}
