import { defineComponent, ref, computed, nextTick, createVNode, Transition, withDirectives, vShow } from 'vue';
import '../../transition/index.mjs';
import { dialogPropTypes } from './IDialogPropTypes.mjs';
import { offset } from './util.mjs';
import { getTransitionProps } from '../../transition/src/transition.mjs';

const sentinelStyle = {
  width: 0,
  height: 0,
  overflow: "hidden",
  outline: "none"
};
var Content = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "DialogContent",
  inheritAttrs: false,
  props: {
    ...dialogPropTypes(),
    motionName: String,
    ariaId: String,
    onVisibleChanged: Function,
    onMousedown: Function,
    onMouseup: Function
  },
  setup(props, {
    expose,
    slots,
    attrs
  }) {
    const sentinelStartRef = ref();
    const sentinelEndRef = ref();
    const dialogRef = ref();
    expose({
      focus: () => {
        var _a;
        (_a = sentinelStartRef.value) == null ? void 0 : _a.focus();
      },
      changeActive: (next) => {
        const {
          activeElement
        } = document;
        if (next && activeElement === sentinelEndRef.value)
          sentinelStartRef.value.focus();
        else if (!next && activeElement === sentinelStartRef.value)
          sentinelEndRef.value.focus();
      }
    });
    const transformOrigin = ref();
    const contentStyleRef = computed(() => {
      const {
        width,
        height
      } = props;
      const contentStyle = {};
      if (width !== void 0)
        contentStyle.width = typeof width === "number" ? `${width}px` : width;
      if (height !== void 0)
        contentStyle.height = typeof height === "number" ? `${height}px` : height;
      if (transformOrigin.value)
        contentStyle.transformOrigin = transformOrigin.value;
      return contentStyle;
    });
    const onPrepare = () => {
      nextTick(() => {
        if (dialogRef.value) {
          const elementOffset = offset(dialogRef.value);
          transformOrigin.value = props.mousePosition ? `${props.mousePosition.x - elementOffset.left}px ${props.mousePosition.y - elementOffset.top}px` : "";
        }
      });
    };
    const onVisibleChanged = (visible) => {
      props.onVisibleChanged(visible);
    };
    return () => {
      var _a, _b, _c, _d;
      const {
        prefixCls,
        footer = (_a = slots.footer) == null ? void 0 : _a.call(slots),
        title = (_b = slots.title) == null ? void 0 : _b.call(slots),
        ariaId,
        closable,
        closeIcon = (_c = slots.closeIcon) == null ? void 0 : _c.call(slots),
        onClose,
        bodyStyle,
        bodyProps,
        onMousedown,
        onMouseup,
        visible,
        modalRender = slots.modalRender,
        destroyOnClose,
        motionName
      } = props;
      let footerNode;
      if (footer)
        footerNode = createVNode("div", {
          "class": `${prefixCls}-footer`
        }, [footer]);
      let headerNode;
      if (title) {
        headerNode = createVNode("div", {
          "class": `${prefixCls}-header`
        }, [createVNode("div", {
          "class": `${prefixCls}-title`,
          "id": ariaId
        }, [title])]);
      }
      let closer;
      if (closable) {
        closer = createVNode("button", {
          "type": "button",
          "onClick": onClose,
          "aria-label": "Close",
          "class": `${prefixCls}-close`
        }, [closeIcon || createVNode("span", {
          "class": `${prefixCls}-close-x`
        }, null)]);
      }
      const content = createVNode("div", {
        "class": `${prefixCls}-content`
      }, [closer, headerNode, createVNode("div", {
        "class": `${prefixCls}-body`,
        "style": bodyStyle,
        ...bodyProps
      }, [(_d = slots.default) == null ? void 0 : _d.call(slots)]), footerNode]);
      const transitionProps = getTransitionProps(motionName);
      return createVNode(Transition, {
        ...transitionProps,
        "onBeforeEnter": onPrepare,
        "onAfterEnter": () => onVisibleChanged(true),
        "onAfterLeave": () => onVisibleChanged(false)
      }, {
        default: () => [visible || !destroyOnClose ? withDirectives(createVNode("div", {
          ...attrs,
          "ref": dialogRef,
          "key": "dialog-element",
          "role": "document",
          "style": [contentStyleRef.value, attrs.style],
          "class": [prefixCls, attrs.class],
          "onMousedown": onMousedown,
          "onMouseup": onMouseup
        }, [createVNode("div", {
          "tabindex": 0,
          "ref": sentinelStartRef,
          "style": sentinelStyle,
          "aria-hidden": "true"
        }, null), modalRender ? modalRender({
          originVNode: content
        }) : content, createVNode("div", {
          "tabindex": 0,
          "ref": sentinelEndRef,
          "style": sentinelStyle,
          "aria-hidden": "true"
        }, null)]), [[vShow, visible]]) : null]
      });
    };
  }
});

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