import { ref, defineComponent, provide, render, createVNode } from 'vue';
import { tooltipEmits } from './props.mjs';
import Main from './main.mjs';

const tooltipEmitsVNodeKeys = tooltipEmits.map((item) => {
  return `on${item[0].toUpperCase()}${item.slice(1).replace(/-(\w)/g, (_, c) => c.toUpperCase())}`;
});
function renderTooltip(props, e) {
  if (props.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 = ref();
  const renderComponent = defineComponent({
    setup() {
      const isRender = ref(true);
      getAllKeys(props.__provides__).forEach((key) => {
        provide(key, props.__provides__[key]);
      });
      destroyTooltip = () => {
        setTimeout(() => {
          var _a;
          isRender.value = false;
          vNode = null;
          render(null, container);
          container.remove();
          Reflect.set(e, "__tooltip__", null);
          tooltipRef.value = null;
          (_a = props.closeUseTooltip) == null ? void 0 : _a.call(props);
        }, Math.max(0, props.hideAfter, props.showAfter) + 50);
      };
      return () => {
        if (!isRender.value) {
          return null;
        }
        return createVNode(Main, {
          ...props,
          content: typeof props.content === "string" ? props.content : "",
          virtualTriggering: true,
          virtualRef: e,
          ref: tooltipRef,
          onHide(value) {
            var _a;
            (_a = props.onHide) == null ? void 0 : _a.call(props, value);
            destroyTooltip == null ? void 0 : destroyTooltip();
          }
        }, {
          content: typeof props.content !== "string" ? props.content : void 0
        });
      };
    }
  });
  vNode = createVNode(renderComponent);
  render(vNode, container);
  document.body.appendChild(container);
  function callback() {
    destroyTooltip == null ? void 0 : destroyTooltip();
    destroyTooltip = null;
  }
  return callback;
}
function useTooltip(props, e) {
  const callback = renderTooltip(props, e);
  if (props.trigger === "hover") {
  } else if (props.trigger === "click") {
    e.click();
  }
  return callback;
}
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;
  }
}

export { getAllKeys, renderTooltip, useTooltip };
//# sourceMappingURL=method.mjs.map
