'use strict';

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

var vue = require('vue');
require('../../transition/index.cjs');
var IDialogPropTypes = require('./IDialogPropTypes.cjs');
var util = require('./util.cjs');
var transition = require('../../transition/src/transition.cjs');

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

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