import { defineComponent, onBeforeMount, watch, onUpdated, nextTick, onBeforeUnmount, createVNode, Teleport } from 'vue';
import { useInjectPortal } from '../../vc-trigger/context.mjs';

var Portal = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "Portal",
  inheritAttrs: false,
  props: {
    getContainer: {
      type: Function,
      required: true
    },
    didUpdate: Function
  },
  setup(props, {
    slots
  }) {
    let isSSR = true;
    let container;
    const {
      shouldRender
    } = useInjectPortal();
    onBeforeMount(() => {
      isSSR = false;
      if (shouldRender.value)
        container = props.getContainer();
    });
    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);
      });
    });
    onBeforeUnmount(() => {
      if (container && container.parentNode)
        container.parentNode.removeChild(container);
    });
    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
