import { defineComponent, ref, computed, openBlock, createBlock, unref, mergeProps, withCtx, createElementBlock, createVNode, createCommentVNode, renderSlot, createElementVNode } from 'vue';
import { debounce } from 'lodash-es';
import { ElButton } from 'element-plus';
import { MeSvgIcon } from '../../svg-icon/index.mjs';

"use strict";
const _hoisted_1 = {
  key: 0,
  style: { "margin-right": "6px" }
};
const __default__ = defineComponent({
  name: "me-button"
});
var script = /* @__PURE__ */ 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 = 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 = debounce(loadingClick, props.delay);
    const onClick = computed(() => {
      if (props.delay) {
        return debounceClick;
      } else {
        return loadingClick;
      }
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(ElButton), mergeProps({
        class: ["me-button", { shine: __props.shine }],
        loading: loading.value
      }, _ctx.$attrs, { onClick: onClick.value }), {
        loading: withCtx(() => [
          renderSlot(_ctx.$slots, "loading", {}, () => [
            _cache[0] || (_cache[0] = createElementVNode(
              "div",
              { class: "loader" },
              null,
              -1
              /* CACHED */
            ))
          ])
        ]),
        default: withCtx(() => [
          __props.icon ? (openBlock(), createElementBlock("span", _hoisted_1, [
            createVNode(unref(MeSvgIcon), { name: __props.icon }, null, 8, ["name"])
          ])) : createCommentVNode("v-if", true),
          !loading.value ? renderSlot(_ctx.$slots, "default", { key: 1 }) : createCommentVNode("v-if", true)
        ]),
        _: 3
        /* FORWARDED */
      }, 16, ["class", "loading", "onClick"]);
    };
  }
});

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