'use strict';

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

var vue = require('vue');
var lodashEs = require('lodash');
var elementPlus = require('element-plus');
var index = require('../../svg-icon/index.js');

"use strict";
const _hoisted_1 = {
  key: 0,
  style: { "margin-right": "6px" }
};
const __default__ = vue.defineComponent({
  name: "me-button"
});
var script = /* @__PURE__ */ vue.defineComponent({
  ...__default__,
  props: {
    click: { type: Function, required: false, default: void 0 },
    clickHandle: { type: Function, required: false, default: void 0 },
    delay: { type: Number, required: false, default: 0 },
    backPath: { type: String, required: false },
    shine: { type: Boolean, required: false, default: false },
    icon: { type: String, required: false }
  },
  setup(__props) {
    ;
    const props = __props;
    const loading = vue.ref(false);
    const loadingClick = async () => {
      let clickFn = null;
      if (props.click) {
        clickFn = props.click;
      }
      if (props.clickHandle) {
        clickFn = props.clickHandle;
      }
      if (clickFn) {
        const res = clickFn();
        if (res instanceof Promise) {
          loading.value = true;
          res.then(() => {
            if (props.backPath) {
            }
          }).catch((error) => {
            console.error(error);
          }).finally(() => {
            loading.value = false;
          });
        }
      }
      if (props.backPath) {
      }
    };
    const debounceClick = lodashEs.debounce(loadingClick, props.delay);
    const onClick = vue.computed(() => {
      if (props.delay) {
        return debounceClick;
      } else {
        return loadingClick;
      }
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElButton), vue.mergeProps({
        class: ["me-button", { shine: __props.shine }],
        loading: loading.value
      }, _ctx.$attrs, { onClick: onClick.value }), {
        loading: vue.withCtx(() => [
          vue.renderSlot(_ctx.$slots, "loading", {}, () => [
            _cache[0] || (_cache[0] = vue.createElementVNode(
              "div",
              { class: "loader" },
              null,
              -1
              /* CACHED */
            ))
          ])
        ]),
        default: vue.withCtx(() => [
          __props.icon ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_1, [
            vue.createVNode(vue.unref(index.MeSvgIcon), { name: __props.icon }, null, 8, ["name"])
          ])) : vue.createCommentVNode("v-if", true),
          !loading.value ? vue.renderSlot(_ctx.$slots, "default", { key: 1 }) : vue.createCommentVNode("v-if", true)
        ]),
        _: 3
        /* FORWARDED */
      }, 16, ["class", "loading", "onClick"]);
    };
  }
});

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