// @ts-nocheck
let zindex = 10000;
import { createVNode, render } from 'vue';
export const getZIndex = (): number => ++zindex;

export function mount(component, { props, children, element, app } = {}) {
  let el = element;
  let vNode = createVNode(component, props, children);

  if (app && app._context) vNode.appContext = app._context;
  if (el) render(vNode, el);
  else if (typeof document !== 'undefined') {
    render(vNode, (el = document.createElement('div')));
  }

  const destroy = () => {
    if (el) render(null, el);
    el = null;
    vNode = null;
  };

  return { vNode, destroy, el };
}

export function setup(...Components) {
  Components.forEach((Component) => {
    Component.install = function (app) {
      Component.use && Component.use(app);
      app.component(Component.name, Component);
    };
  });

  return Components;
}
export const objectToString = Object.prototype.toString;
export const toTypeString = (value) => objectToString.call(value);
// 获取制定对象的类型比如toRawType(1) Number
export const toRawType = (value) => toTypeString(value).slice(8, -1);

/**
 * 判断是否函数
 * @param {any} target 参数对象
 */
export const isFunction = (target) => toRawType(target) === 'Function';

/**
 * 获取忽略指定属性的对象
 * @param {Object} obj 源对象
 * @param  {...any} props 忽略属性
 */
export function omit(obj, ...props) {
  const result = { ...obj };
  props.forEach(function (prop) {
    delete result[prop];
  });
  return result;
}
