'use strict';

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

var vue = require('vue');
var antDesignVue = require('ant-design-vue');
require('../../index.js');
require('../../../utils/index.js');
var lodashEs = require('lodash-es');
var modal = require('./modal.js');
var createNamespace = require('../../../utils/create-namespace.js');
var index = require('../../button/index.js');

"use strict";
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{ name: "LlModal" },
  __name: "modal",
  props: modal.modalProps,
  emits: modal.modalEmits,
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const attrs = vue.useAttrs();
    const bem = createNamespace.createNamespace("modal");
    const modal$1 = vue.ref();
    const hasScroll = vue.ref(false);
    const scrollTop = vue.ref(0);
    const currentClass = vue.ref("");
    const symbolClass = vue.ref(`ll-modal-${(/* @__PURE__ */ new Date()).getTime()}`);
    const symbolComparedClass = vue.ref(`model-content-${(/* @__PURE__ */ new Date()).getTime()}`);
    const getBindValue = vue.computed(() => {
      const result = {
        ...lodashEs.omit({ ...attrs }, [...Object.keys(modal.modalProps), "wrapClassName"])
      };
      if (props.showFooter === false) {
        result.footer = null;
      }
      return result;
    });
    const handleCancel = () => {
      emits("cancel");
      emits("update:open");
    };
    const handleOk = () => {
      emits("ok");
    };
    const handleResize = async (value) => {
      await vue.nextTick();
      const ele = document.getElementsByClassName(symbolClass.value)[0];
      const modalBody = ele.getElementsByClassName(symbolComparedClass.value)[0];
      const resizeObserver = new ResizeObserver((entries) => {
        const { clientHeight } = entries[0].target;
        const scrollHeight = ele.clientHeight;
        hasScroll.value = clientHeight > scrollHeight;
      });
      if (value) {
        resizeObserver.observe(modalBody);
        ele.addEventListener("scroll", () => {
          scrollTop.value = ele.scrollTop;
        });
      } else {
        resizeObserver.unobserve(modalBody);
        ele.removeEventListener("scroll", () => {
          scrollTop.value = 0;
        });
      }
    };
    const onScrollTop = async () => {
      await vue.nextTick();
      if (!hasScroll.value) return;
      const ele = document.getElementsByClassName(symbolClass.value)[0];
      ele.scrollTop = 0;
    };
    vue.watch(
      () => props.open,
      (val) => {
        handleResize(val);
        if (val) {
          currentClass.value = `modal-${(/* @__PURE__ */ new Date()).getTime()}`;
          vue.nextTick().then(() => {
            const dom = document.querySelector(
              `.${currentClass.value}`
            );
            if (dom) {
              dom.focus();
            }
          });
        }
      }
    );
    __expose({
      onScrollTop
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.Modal), vue.mergeProps(getBindValue.value, {
        ref_key: "modal",
        ref: modal$1,
        open: props.open,
        title: props.title,
        keyboard: _ctx.keyboard,
        "wrap-class-name": `${vue.unref(bem).b()} ${props.wrapClassName} ${currentClass.value}`,
        class: [
          props.class,
          hasScroll.value ? vue.unref(bem).is("has-scroll") : "",
          vue.unref(bem).is(props.isConfirmModel ? "confirm-model" : "")
        ],
        onCancel: handleCancel,
        onOk: handleOk
      }), vue.createSlots({
        default: vue.withCtx(() => [
          _ctx.$slots.step ? (vue.openBlock(), vue.createElementBlock(
            "div",
            {
              key: 0,
              class: vue.normalizeClass(vue.unref(bem).e("step"))
            },
            [
              vue.renderSlot(_ctx.$slots, "step")
            ],
            2
            /* CLASS */
          )) : vue.createCommentVNode("v-if", true),
          vue.createElementVNode(
            "div",
            {
              class: vue.normalizeClass([vue.unref(bem).e("container"), symbolClass.value, vue.unref(bem).is(props.type)])
            },
            [
              hasScroll.value && scrollTop.value > 0 ? (vue.openBlock(), vue.createElementBlock(
                "div",
                {
                  key: 0,
                  class: vue.normalizeClass(vue.unref(bem).e("shadow"))
                },
                null,
                2
                /* CLASS */
              )) : vue.createCommentVNode("v-if", true),
              vue.createElementVNode(
                "div",
                {
                  class: vue.normalizeClass([symbolComparedClass.value])
                },
                [
                  vue.renderSlot(_ctx.$slots, "default")
                ],
                2
                /* CLASS */
              )
            ],
            2
            /* CLASS */
          )
        ]),
        _: 2
        /* DYNAMIC */
      }, [
        props.showFooter ? {
          name: "footer",
          fn: vue.withCtx(() => [
            vue.renderSlot(_ctx.$slots, "footer", {}, () => [
              vue.createCommentVNode(" \u786E\u8BA4\u6846 "),
              vue.createElementVNode(
                "div",
                {
                  class: vue.normalizeClass(vue.unref(bem).e("footer"))
                },
                [
                  props.showCancel && props.type !== "confirm" ? (vue.openBlock(), vue.createBlock(vue.unref(index.LlButton), {
                    key: 0,
                    label: props.cancelText ? props.cancelText : "\u53D6\u6D88",
                    size: "middle",
                    onClick: handleCancel
                  }, null, 8, ["label"])) : vue.createCommentVNode("v-if", true),
                  vue.createVNode(vue.unref(index.LlButton), {
                    type: "primary",
                    loading: props.loading,
                    size: "middle",
                    label: props.confirmText ? props.confirmText : props.type === "confirm" ? "\u77E5\u9053\u4E86" : "\u786E\u8BA4",
                    onClick: handleOk
                  }, null, 8, ["loading", "label"])
                ],
                2
                /* CLASS */
              )
            ])
          ]),
          key: "0"
        } : void 0
      ]), 1040, ["open", "title", "keyboard", "wrap-class-name", "class"]);
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=modal.vue2.js.map
