import { defineComponent, onBeforeMount, onMounted, watch, onUpdated, nextTick, createVNode, Teleport } from 'vue';
import '../../../utils/index.mjs';
import { useInjectPortal } from '../../vc-trigger/src/context.mjs';
import PropTypes from '../../../utils/vue/vueTypes.mjs';

var Portal = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "Portal",
  inheritAttrs: false,
  props: {
    getContainer: PropTypes.func.isRequired,
    didUpdate: Function
  },
  setup(props, {
    slots
  }) {
    let isSSR = true;
    let container;
    const {
      shouldRender
    } = useInjectPortal();
    function setContainer() {
      if (shouldRender.value)
        container = props.getContainer();
    }
    onBeforeMount(() => {
      isSSR = false;
      setContainer();
    });
    onMounted(() => {
      if (container)
        return;
      setContainer();
    });
    const stopWatch = watch(shouldRender, () => {
      if (shouldRender.value && !container)
        container = props.getContainer();
      if (container)
        stopWatch();
    });
    onUpdated(() => {
      nextTick(() => {
        var _a;
        if (shouldRender.value)
          (_a = props.didUpdate) == null ? void 0 : _a.call(props, props);
      });
    });
    return () => {
      var _a;
      if (!shouldRender.value)
        return null;
      if (isSSR)
        return (_a = slots.default) == null ? void 0 : _a.call(slots);
      return container ? createVNode(Teleport, {
        "to": container
      }, slots) : null;
    };
  }
});

export { Portal as default };
//# sourceMappingURL=Portal.mjs.map
