import { cloneVNode, isVNode, render } from 'vue';
import { devWarning } from '../log.mjs';
import { filterEmpty } from './props.mjs';

function cloneElement(vnode, nodeProps = {}, override = true, mergeRef = false) {
  let ele = vnode;
  if (Array.isArray(vnode))
    ele = filterEmpty(vnode)[0];
  if (!ele)
    return null;
  const node = cloneVNode(ele, nodeProps, mergeRef);
  node.props = override ? { ...node.props, ...nodeProps } : node.props;
  devWarning(typeof node.props.class !== "object", "class must be string");
  return node;
}
function cloneVNodes(vnodes, nodeProps = {}, override = true) {
  return vnodes.map((vnode) => cloneElement(vnode, nodeProps, override));
}
function deepCloneElement(vnode, nodeProps = {}, override = true, mergeRef = false) {
  if (Array.isArray(vnode)) {
    return vnode.map((item) => deepCloneElement(item, nodeProps, override, mergeRef));
  } else {
    if (!isVNode(vnode))
      return vnode;
    const cloned = cloneElement(vnode, nodeProps, override, mergeRef);
    if (Array.isArray(cloned.children))
      cloned.children = deepCloneElement(cloned.children);
    return cloned;
  }
}
function triggerVNodeUpdate(vm, attrs, dom) {
  render(cloneVNode(vm, { ...attrs }), dom);
}

export { cloneElement, cloneVNodes, deepCloneElement, triggerVNodeUpdate };
//# sourceMappingURL=vnode.mjs.map
