'use strict';

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

var vue = require('vue');
var types = require('../../utils/types.js');
var elementPlus = require('element-plus');
var index$1 = require('../../button/index.js');
var index$2 = require('../../icon-button/index.js');
var index = require('../../loading/index.js');
var vueRouter = require('vue-router');

"use strict";
const _hoisted_1 = { style: { "font-size": "18px", "font-weight": "700" } };
const _hoisted_2 = { style: { "width": "auto" } };
const _hoisted_3 = {
  key: 0,
  style: { "display": "flex", "justify-content": "flex-end", "width": "100%", "align-items": "center" }
};
const _hoisted_4 = {
  key: 0,
  style: { "margin-right": "10px" }
};
const __default__ = vue.defineComponent({
  name: "me-dialog"
});
var script = /* @__PURE__ */ vue.defineComponent({
  ...__default__,
  props: /* @__PURE__ */ vue.mergeModels({
    showFullscreen: { type: Boolean, required: false },
    showClose: { type: Boolean, required: false, default: true },
    showCancelButton: { type: Boolean, required: false, default: true },
    title: { type: String, required: false, default: "\u6807\u9898" },
    line: { type: String, required: false, default: "" },
    confirmHandler: { type: Function, required: false },
    cancelHandler: { type: Function, required: false },
    closeHandler: { type: Function, required: false },
    isScroll: { type: Boolean, required: false, default: true },
    loading: { type: Boolean, required: false, default: false }
  }, {
    "modelValue": { default: false },
    "modelModifiers": {}
  }),
  emits: /* @__PURE__ */ vue.mergeModels(["closeEvent", "fullScreenChangeEvent"], ["update:modelValue"]),
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const visible = vue.useModel(__props, "modelValue");
    const maxHeight = vue.computed(() => {
      return isFullScreen.value ? "100%" : "90%";
    });
    const route = vueRouter.useRoute();
    let path = route?.fullPath;
    let isOpen = false;
    vueRouter.onBeforeRouteLeave((to, from) => {
      console.log("\u{1F680} ~ onBeforeRouteLeave:", from);
      path = from?.fullPath;
      isOpen = visible.value;
      visible.value = false;
    });
    vue.watch(
      () => route?.fullPath,
      (newVal) => {
        console.log("\u{1F680} ~ path:", path);
        if (path === newVal && isOpen) {
          visible.value = true;
        }
      }
    );
    let isFullScreen = vue.ref(false);
    let fullScreenIcon = vue.ref("ri-fullscreen-line");
    let gap = vue.computed(() => {
      if (props.line == "" || props.line == "none") {
        return "0px";
      } else {
        return "10px";
      }
    });
    vue.watch(visible, async (newValue) => {
      if (!newValue) {
        isFullScreen.value = false;
        fullScreenIcon.value = "ri-fullscreen-line";
      }
    });
    const close = () => {
      visible.value = false;
      emit("closeEvent");
    };
    const closeEventHandler = () => {
      if (props.closeHandler) {
        types.delegateBoolean(props.closeHandler, (res) => {
          if (res) {
            close();
          }
        });
      } else {
        close();
      }
    };
    const cancelEventHandler = () => {
      if (props.cancelHandler) {
        types.delegateBoolean(props.cancelHandler, (res) => {
          if (res) {
            close();
          }
        });
      } else {
        close();
      }
    };
    const confirmEventHandler = () => {
      if (props.confirmHandler) {
        types.delegateBoolean(props.confirmHandler, (res) => {
          if (res) {
            close();
          }
        });
      } else {
        close();
      }
    };
    const fullScreenHandler = () => {
      isFullScreen.value = !isFullScreen.value;
      fullScreenIcon.value = isFullScreen.value ? "ri-fullscreen-exit-line" : "ri-fullscreen-line";
      emit("fullScreenChangeEvent", isFullScreen.value);
    };
    return (_ctx, _cache) => {
      const _component_me_flex_box = vue.resolveComponent("me-flex-box");
      return vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElDialog), vue.mergeProps({
        ref: "dialogRef",
        modelValue: visible.value,
        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => visible.value = $event),
        class: "me-dialog",
        "append-to-body": "",
        "show-close": false,
        "close-on-click-modal": false,
        "close-on-press-escape": false,
        "destroy-on-close": true,
        fullscreen: vue.unref(isFullScreen),
        "align-center": ""
      }, _ctx.$attrs, {
        style: [{ "border-radius": "8px" }, { maxHeight: maxHeight.value }],
        "modal-class": "me-dialog-modal"
      }), {
        header: vue.withCtx(({ close: close2, titleId, titleClass }) => [
          vue.createElementVNode(
            "div",
            {
              class: "me-dialog-header",
              style: vue.normalizeStyle({ borderBottom: __props.line, paddingBottom: vue.unref(gap) })
            },
            [
              vue.renderSlot(_ctx.$slots, "me-dialog-header", {}, () => [
                vue.createElementVNode("span", _hoisted_1, [
                  vue.renderSlot(_ctx.$slots, "title", {}, () => [
                    vue.createTextVNode(
                      vue.toDisplayString(props.title),
                      1
                      /* TEXT */
                    )
                  ])
                ])
              ]),
              vue.createElementVNode("div", _hoisted_2, [
                props.showFullscreen ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.MeIconButton), {
                  key: 0,
                  hover: "",
                  icon: vue.unref(fullScreenIcon),
                  style: { "cursor": "pointer", "font-size": "20px", "color": "var(--el-text-color-primary)" },
                  onClick: fullScreenHandler
                }, null, 8, ["icon"])) : vue.createCommentVNode("v-if", true),
                props.showClose ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.MeIconButton), {
                  key: 1,
                  hover: "",
                  icon: "ri-close-line",
                  "icon-size": 20,
                  style: { "cursor": "pointer", "font-size": "20px", "color": "var(--el-text-color-primary)" },
                  onClick: closeEventHandler
                })) : vue.createCommentVNode("v-if", true)
              ])
            ],
            4
            /* STYLE */
          )
        ]),
        footer: vue.withCtx(() => [
          vue.createElementVNode(
            "div",
            {
              class: "me-dialog-footer",
              style: vue.normalizeStyle([{}, { borderTop: __props.line, paddingTop: vue.unref(gap) }])
            },
            [
              _ctx.$slots["me-dialog-footer-right"] ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3, [
                vue.renderSlot(_ctx.$slots, "me-dialog-footer-right")
              ])) : vue.createCommentVNode("v-if", true),
              !_ctx.$slots["me-dialog-footer-right"] ? vue.renderSlot(_ctx.$slots, "me-dialog-footer", { key: 1 }, () => [
                vue.createVNode(_component_me_flex_box, { end: true }, {
                  default: vue.withCtx(() => [
                    _ctx.$props.showCancelButton ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, [
                      vue.createVNode(vue.unref(index$1.MeButton), { onClick: cancelEventHandler }, {
                        default: vue.withCtx(() => [..._cache[1] || (_cache[1] = [
                          vue.createTextVNode(
                            "\u53D6\u6D88",
                            -1
                            /* CACHED */
                          )
                        ])]),
                        _: 1
                        /* STABLE */
                      })
                    ])) : vue.createCommentVNode("v-if", true),
                    vue.createElementVNode("div", null, [
                      vue.createVNode(vue.unref(index$1.MeButton), {
                        type: "primary",
                        onClick: confirmEventHandler
                      }, {
                        default: vue.withCtx(() => [..._cache[2] || (_cache[2] = [
                          vue.createTextVNode(
                            "\u786E\u5B9A",
                            -1
                            /* CACHED */
                          )
                        ])]),
                        _: 1
                        /* STABLE */
                      })
                    ])
                  ]),
                  _: 1
                  /* STABLE */
                })
              ]) : vue.createCommentVNode("v-if", true)
            ],
            4
            /* STYLE */
          )
        ]),
        default: vue.withCtx(() => [
          __props.loading ? (vue.openBlock(), vue.createBlock(vue.unref(index.MeLoading), {
            key: 0,
            style: { "width": "100%", "height": "100%" },
            show: __props.loading
          }, null, 8, ["show"])) : vue.createCommentVNode("v-if", true),
          vue.createElementVNode(
            "div",
            {
              style: vue.normalizeStyle([{ "flex": "1" }, __props.isScroll ? { overflow: "auto" } : { overflow: "hidden" }]),
              class: "me-div-scroller"
            },
            [
              vue.renderSlot(_ctx.$slots, "default")
            ],
            4
            /* STYLE */
          )
        ]),
        _: 3
        /* FORWARDED */
      }, 16, ["modelValue", "fullscreen", "style"]);
    };
  }
});

exports.default = script;
//# sourceMappingURL=dialog.vue2.js.map
