import { defineComponent, inject, ref, getCurrentInstance, computed, onMounted, onUnmounted, createVNode, mergeProps } from 'vue';
import '../../slot/index.mjs';
import { useTooltipProps, tooltipEmits } from './props.mjs';
import { groupToolTipInjectKey } from './utils.mjs';
import Main from './main.mjs';
import { OnlyChild } from '../../slot/src/only-child.mjs';

const Tooltip = defineComponent({
  name: "ElTooltip",
  props: useTooltipProps,
  emits: tooltipEmits,
  setup(props, ctx) {
    const groupData = inject(groupToolTipInjectKey, null);
    const main = ref();
    const instance = getCurrentInstance();
    const computedData = computed(() => {
      return {
        ...instance.vnode.props || {},
        ...props,
        content: ctx.slots.content ? ctx.slots.content : props.content,
        __provides__: instance == null ? void 0 : instance.provides,
        __tooltipRef__: main
      };
    });
    const exposeValue = new Proxy({}, {
      get(target, key) {
        var _a;
        return (_a = main.value) == null ? void 0 : _a[key];
      },
      has(target, p) {
        return main.value ? Reflect.has(main.value, p) : false;
      }
    });
    ctx.expose(exposeValue);
    if (groupData && !props.boolGroupTooltipUncontrolled) {
      onMounted(() => {
        groupData.instanceData.set(instance.proxy.$el, computedData);
      });
      onUnmounted(() => {
        groupData.instanceData.delete(instance.proxy.$el);
        groupData.destructionTooltipFn(instance.proxy.$el);
      });
      return () => {
        return createVNode(OnlyChild, {
          "class": groupData.key
        }, {
          default: () => {
            var _a;
            return [ctx.slots.default({
              visible: (_a = main.value) == null ? void 0 : _a.open
            })[0]];
          }
        });
      };
    } else {
      const emits = tooltipEmits.reduce((em, item) => {
        em[`on-${item}`.replace(/-(\w)/g, (_, c) => c.toUpperCase())] = (...args) => ctx.emit(item, ...args);
        return em;
      }, {});
      return () => {
        return createVNode(Main, mergeProps({
          "ref": main
        }, props, emits), ctx.slots);
      };
    }
  }
});

export { Tooltip };
//# sourceMappingURL=render.mjs.map
