'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 PortalWrapper = require('../../portal/src/PortalWrapper.cjs');
var Dialog = require('./Dialog.cjs');
var IDialogPropTypes$1 = require('./IDialogPropTypes.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');

const IDialogPropTypes = IDialogPropTypes$1.dialogPropTypes();
const DialogWrap = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "DialogWrap",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(IDialogPropTypes, {
    visible: false
  }),
  setup(props, {
    attrs,
    slots
  }) {
    const animatedVisible = vue.ref(props.visible);
    context.useProvidePortal({}, {
      inTriggerContext: false
    });
    vue.watch(() => props.visible, () => {
      if (props.visible)
        animatedVisible.value = true;
    }, {
      flush: "post"
    });
    return () => {
      const {
        visible,
        getContainer,
        forceRender,
        destroyOnClose = false,
        afterClose
      } = props;
      let dialogProps = {
        ...props,
        ...attrs,
        ref: "_component",
        key: "dialog"
      };
      if (getContainer === false) {
        return vue.createVNode(Dialog.default, {
          ...dialogProps,
          "getOpenCount": () => 2
        }, slots);
      }
      if (!forceRender && destroyOnClose && !animatedVisible.value)
        return null;
      return vue.createVNode(PortalWrapper.default, {
        "autoLock": true,
        "visible": visible,
        "forceRender": forceRender,
        "getContainer": getContainer
      }, {
        default: (childProps) => {
          dialogProps = {
            ...dialogProps,
            ...childProps,
            afterClose: () => {
              afterClose == null ? void 0 : afterClose();
              animatedVisible.value = false;
            }
          };
          return vue.createVNode(Dialog.default, dialogProps, slots);
        }
      });
    };
  }
});

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