'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var context = require('../../vc-trigger/src/context.cjs');
var vueTypes = require('../../../utils/vue/vueTypes.cjs');

var Portal = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "Portal",
  inheritAttrs: false,
  props: {
    getContainer: vueTypes.default.func.isRequired,
    didUpdate: Function
  },
  setup(props, {
    slots
  }) {
    let isSSR = true;
    let container;
    const {
      shouldRender
    } = context.useInjectPortal();
    function setContainer() {
      if (shouldRender.value)
        container = props.getContainer();
    }
    vue.onBeforeMount(() => {
      isSSR = false;
      setContainer();
    });
    vue.onMounted(() => {
      if (container)
        return;
      setContainer();
    });
    const stopWatch = vue.watch(shouldRender, () => {
      if (shouldRender.value && !container)
        container = props.getContainer();
      if (container)
        stopWatch();
    });
    vue.onUpdated(() => {
      vue.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 ? vue.createVNode(vue.Teleport, {
        "to": container
      }, slots) : null;
    };
  }
});

exports.default = Portal;
//# sourceMappingURL=Portal.cjs.map
