import { createVnode, restoreChildren, fiberizeChildren, createElement } from "./createElement";
import { options } from "./util";

function Portal(props){
    this.container = props.container;
}
Portal.prototype = {
    constructor: Portal,
    componentWillUnmount(){
        var parentVnode = this.container;
        var lastChildren = restoreChildren(parentVnode);
        options.diffChildren(lastChildren, [], parentVnode, {}, []);
    },
    componentWillMount(){
        var parentVnode = this.container;
        var nextChildren = fiberizeChildren(parentVnode);
        options.diffChildren([], nextChildren, parentVnode, {}, []);
        parentVnode.batchMount();
    },
    render(){
        return null;
    }
};
//[Top API] ReactDOM.createPortal
export function createPortal(children, node) {
    var container = createVnode(node);
    container.props = container.props || {};
    var props = container.props;
    props.children = children;
    return createElement(Portal, {
        container
    });
}
