'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var props = require('./props.js');
var main = require('./main.js');

const tooltipEmitsVNodeKeys = props.tooltipEmits.map((item) => {
  return `on${item[0].toUpperCase()}${item.slice(1).replace(/-(\w)/g, (_, c) => c.toUpperCase())}`;
});
function renderTooltip(props$1, e) {
  if (props$1.disabled)
    return;
  if (Reflect.get(e, "__tooltip__")) {
    return;
  }
  Reflect.set(e, "__tooltip__", 1);
  const domList = document.querySelectorAll(".group-tooltip-list-item");
  Array.from(domList).forEach((item) => item.remove());
  const container = document.createElement("div");
  container.className = "group-tooltip-list-item";
  let vNode;
  let destroyTooltip;
  const tooltipRef = vue.ref();
  const renderComponent = vue.defineComponent({
    setup() {
      const isRender = vue.ref(true);
      getAllKeys(props$1.__provides__).forEach((key) => {
        vue.provide(key, props$1.__provides__[key]);
      });
      destroyTooltip = () => {
        setTimeout(() => {
          var _a;
          isRender.value = false;
          vNode = null;
          vue.render(null, container);
          container.remove();
          Reflect.set(e, "__tooltip__", null);
          tooltipRef.value = null;
          (_a = props$1.closeUseTooltip) == null ? void 0 : _a.call(props$1);
        }, Math.max(0, props$1.hideAfter, props$1.showAfter) + 50);
      };
      return () => {
        if (!isRender.value) {
          return null;
        }
        return vue.createVNode(main["default"], {
          ...props$1,
          content: typeof props$1.content === "string" ? props$1.content : "",
          virtualTriggering: true,
          virtualRef: e,
          ref: tooltipRef,
          onHide(value) {
            var _a;
            (_a = props$1.onHide) == null ? void 0 : _a.call(props$1, value);
            destroyTooltip == null ? void 0 : destroyTooltip();
          }
        }, {
          content: typeof props$1.content !== "string" ? props$1.content : void 0
        });
      };
    }
  });
  vNode = vue.createVNode(renderComponent);
  vNode.appContext = props.tooltipAppContext._context;
  vue.render(vNode, container);
  document.body.appendChild(container);
  function unUseTooltip() {
    destroyTooltip == null ? void 0 : destroyTooltip();
    destroyTooltip = null;
  }
  unUseTooltip.ref = tooltipRef.value;
  return unUseTooltip;
}
function useTooltip(props, e) {
  const unUseTooltip = renderTooltip(props, e);
  if (props.trigger === "hover") {
  } else if (props.trigger === "click") {
    e.click();
  }
  return unUseTooltip;
}
function getAllKeys(obj) {
  const keys = Reflect.ownKeys(obj);
  const parent = Reflect.getPrototypeOf(obj);
  if (parent === Object.prototype) {
    return [];
  }
  if (parent) {
    return keys.concat(getAllKeys(parent));
  } else {
    return keys;
  }
}

exports.getAllKeys = getAllKeys;
exports.renderTooltip = renderTooltip;
exports.useTooltip = useTooltip;
//# sourceMappingURL=method.js.map
