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

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);
        console.log("移除");
    },
    componentWillReceiveProps(nextProps, context) {
        var root = root;
        Refs.receiveVnode(root, nextProps.container, context, this.updater.updateQueue, []);
    },
    componentWillMount() {
        var root = this.container;
        Refs.mountVnode(root,{}, this.updater.updateQueue, [] );
        //  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.updater.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;
}
