import { createElement, __ref, CurrentOwner } from "./createElement";

export function cloneElement(vnode, props) {
    if (Array.isArray(vnode)) {
        vnode = vnode[0];
    }
    if (!vnode.vtype) {
        return Object.assign({}, vnode);
    }
    var configs = {
        key: vnode.key,
        ref: vnode.__refKey || vnode.ref
    };

    Object.assign(configs, vnode.props, props)
    console.log(vnode._owner,"cloneElement中途插入")
    //vnode._owner可能不存在
    CurrentOwner.set(vnode._owner || CurrentOwner.cur[0])
    var ret = createElement(
        vnode.type,
        configs,
        arguments.length > 2 ? [].slice.call(arguments, 2) : configs.children
    );
    CurrentOwner.reset()
    console.log(CurrentOwner.cur[0],"cloneElement中途退出")
    return ret
}
