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

export { script as default };
//# sourceMappingURL=dialog.vue2.mjs.map
