import { defineComponent, ref, openBlock, createElementBlock, Fragment, createBlock, unref, mergeProps, withCtx, createElementVNode, toDisplayString, renderSlot, createVNode, createTextVNode, createCommentVNode } from 'vue';
import { ElPopover, ElButton } from 'element-plus';
import { MeMessage } from '../../message/index.mjs';
import { MeButton } from '../../button/index.mjs';

"use strict";
const _hoisted_1 = { style: { "padding-bottom": "10px" } };
const _hoisted_2 = { style: { "text-align": "right", "margin": "0" } };
const __default__ = defineComponent({
  name: "me-confirm-button"
});
var script = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    data: { type: Object, required: false },
    confirmHandle: { type: Function, required: true },
    tip: { type: String, required: false, default: "\u786E\u5B9A\u8981\u5220\u9664\u5417\uFF1F" },
    mode: { type: String, required: false, default: "normal" },
    type: { type: null, required: false, default: "danger" }
  },
  setup(__props) {
    ;
    const props = __props;
    const loading = ref(false);
    const buttonRef = ref();
    const popoverRef = ref();
    const handleConfirm = async () => {
      popoverRef.value.hide();
      try {
        loading.value = true;
        await props.confirmHandle();
      } finally {
        loading.value = false;
      }
    };
    const handleCancel = () => {
      popoverRef.value.hide();
    };
    const handleDialogConfirm = () => {
      const data = props.data || {
        normal: {
          title: "\u63D0\u793A",
          message: props.tip,
          loading: false,
          type: props.type
        },
        process: {
          loading: true
        }
      };
      MeMessage(
        data,
        {
          confirm: (res) => {
            return props.confirmHandle();
          },
          cancel: () => {
            return true;
          }
        }
      );
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock(
        Fragment,
        null,
        [
          __props.mode === "normal" ? (openBlock(), createBlock(unref(ElPopover), mergeProps({
            key: 0,
            ref_key: "popoverRef",
            ref: popoverRef,
            "virtual-ref": buttonRef.value,
            trigger: "click",
            placement: "top"
          }, _ctx.$attrs), {
            reference: withCtx(() => [
              createVNode(unref(MeButton), mergeProps({ type: __props.type }, _ctx.$attrs, { loading: loading.value }), {
                default: withCtx(() => [
                  !loading.value ? renderSlot(_ctx.$slots, "default", { key: 0 }, () => [
                    _cache[2] || (_cache[2] = createTextVNode(
                      "\u5220\u9664",
                      -1
                      /* CACHED */
                    ))
                  ]) : createCommentVNode("v-if", true)
                ]),
                _: 3
                /* FORWARDED */
              }, 16, ["type", "loading"])
            ]),
            default: withCtx(() => [
              createElementVNode(
                "p",
                _hoisted_1,
                toDisplayString(__props.tip),
                1
                /* TEXT */
              ),
              createElementVNode("div", _hoisted_2, [
                renderSlot(_ctx.$slots, "cancel", {}, () => [
                  createVNode(unref(ElButton), {
                    size: "small",
                    text: "",
                    onClick: handleCancel
                  }, {
                    default: withCtx(() => [..._cache[0] || (_cache[0] = [
                      createTextVNode(
                        "\u53D6\u6D88",
                        -1
                        /* CACHED */
                      )
                    ])]),
                    _: 1
                    /* STABLE */
                  })
                ]),
                renderSlot(_ctx.$slots, "confirm", {}, () => [
                  createVNode(unref(ElButton), {
                    size: "small",
                    type: "primary",
                    onClick: handleConfirm
                  }, {
                    default: withCtx(() => [..._cache[1] || (_cache[1] = [
                      createTextVNode(
                        " \u786E\u5B9A ",
                        -1
                        /* CACHED */
                      )
                    ])]),
                    _: 1
                    /* STABLE */
                  })
                ])
              ])
            ]),
            _: 3
            /* FORWARDED */
          }, 16, ["virtual-ref"])) : createCommentVNode("v-if", true),
          __props.mode === "dialog" ? (openBlock(), createBlock(unref(ElButton), mergeProps({
            key: 1,
            type: __props.type,
            onClick: handleDialogConfirm
          }, _ctx.$attrs), {
            default: withCtx(() => [
              renderSlot(_ctx.$slots, "default", {}, () => [
                _cache[3] || (_cache[3] = createTextVNode(
                  "\u5220\u9664",
                  -1
                  /* CACHED */
                ))
              ])
            ]),
            _: 3
            /* FORWARDED */
          }, 16, ["type"])) : createCommentVNode("v-if", true)
        ],
        64
        /* STABLE_FRAGMENT */
      );
    };
  }
});

export { script as default };
//# sourceMappingURL=confirm-button.vue2.mjs.map
