'use strict';

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

var vue = require('vue');
var elementPlus = require('element-plus');
var index = require('../../message/index.js');
var index$1 = require('../../button/index.js');

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

exports.default = script;
//# sourceMappingURL=confirm-button.vue2.js.map
