'use strict';

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

var vue = require('vue');
var context = require('../../vc-trigger/context.js');

var Portal = /* @__PURE__ */ vue.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
    } = context.useInjectPortal();
    vue.onBeforeMount(() => {
      isSSR = false;
      if (shouldRender.value)
        container = props.getContainer();
    });
    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);
      });
    });
    vue.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 ? vue.createVNode(vue.Teleport, {
        "to": container
      }, slots) : null;
    };
  }
});

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