import { defineComponent, ref, watch, createVNode } from 'vue';
import '../../../utils/index.mjs';
import { useProvidePortal } from '../../vc-trigger/src/context.mjs';
import PortalWrapper from '../../portal/src/PortalWrapper.mjs';
import Dialog from './Dialog.mjs';
import { dialogPropTypes } from './IDialogPropTypes.mjs';
import { initDefaultProps } from '../../../utils/vue/initDefaultProps.mjs';

const IDialogPropTypes = dialogPropTypes();
const DialogWrap = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "DialogWrap",
  inheritAttrs: false,
  props: initDefaultProps(IDialogPropTypes, {
    visible: false
  }),
  setup(props, {
    attrs,
    slots
  }) {
    const animatedVisible = ref(props.visible);
    useProvidePortal({}, {
      inTriggerContext: false
    });
    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 createVNode(Dialog, {
          ...dialogProps,
          "getOpenCount": () => 2
        }, slots);
      }
      if (!forceRender && destroyOnClose && !animatedVisible.value)
        return null;
      return createVNode(PortalWrapper, {
        "autoLock": true,
        "visible": visible,
        "forceRender": forceRender,
        "getContainer": getContainer
      }, {
        default: (childProps) => {
          dialogProps = {
            ...dialogProps,
            ...childProps,
            afterClose: () => {
              afterClose == null ? void 0 : afterClose();
              animatedVisible.value = false;
            }
          };
          return createVNode(Dialog, dialogProps, slots);
        }
      });
    };
  }
});

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