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

function Portal(props) {
    this.__isPortal = true;
    this.container = props.container;
}
Portal.prototype = {
    constructor: Portal,
    componentWillUnmount() {
        this.updater.children = this.portalUpdater.children;
        //  disposeChildren(this.portalUpdater.children, queue)
        console.log("移除");
        // options.diffChildren(this.portalUpdater.children, {}, parentVnode, {}, [], []);
    },
    componentWillReceiveProps(nextProps, context) {
        var parentVnode = this.container;
        options.receiveVnode(parentVnode, nextProps.container, context, this.updater.updateQueue, []);
    },
    componentWillMount() {
        var parentVnode = this.container;
        var updater = new DOMUpdater(parentVnode);
        this.portalUpdater = updater;
        console.log(this.updater.updateQueue);
        var nextChildren = fiberizeChildren(parentVnode.props.children, updater);
        options.diffChildren({}, nextChildren, parentVnode, {}, this.updateQueue, []);
        //  drainQueue(queue);
    },
    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;
}
