'use strict';

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

var vue = require('vue');
var vueRouter = require('vue-router');
var lodashEs = require('lodash-es');
var button = require('./button.js');
var is = require('../../../../utils/src/is.js');
var index = require('../../../../utils/src/clarity/index.js');

var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "GmButton",
    inheritAttrs: false
  },
  __name: "Button",
  props: button.buttonProps,
  setup(__props, { expose: __expose }) {
    const slots = vue.useSlots();
    const attrs = vue.useAttrs();
    const props = __props;
    const route = vueRouter.useRoute();
    const bindAttrs = vue.computed(() => {
      return { ...lodashEs.omit(attrs, "onClick"), ...props };
    });
    const elRef = vue.ref();
    const isLoading = vue.ref(false);
    const realLoading = vue.computed(() => {
      if (is.isBoolean(props.loading)) {
        return props.loading;
      }
      return isLoading.value;
    });
    const sendClarityEvent = () => {
      if (!index.Clarity.isAvailable()) {
        return;
      }
      const buttonText = elRef.value?.$el?.innerText?.trim() || "";
      const actionName = props.eventName || buttonText;
      if (!actionName) {
        return;
      }
      const routeIdentifier = route.meta?.title || route.name || route.path;
      const clarityEventName = `${routeIdentifier} - ${actionName}`;
      index.Clarity.event(clarityEventName);
    };
    const handleClick = async (evt) => {
      try {
        isLoading.value = true;
        const result = await attrs.onClick?.(evt);
        sendClarityEvent();
        return result;
      } finally {
        isLoading.value = false;
      }
    };
    __expose({
      elRef
    });
    return (_ctx, _cache) => {
      const _component_el_button = vue.resolveComponent("el-button");
      return vue.openBlock(), vue.createBlock(_component_el_button, vue.mergeProps({
        ref_key: "elRef",
        ref: elRef
      }, bindAttrs.value, {
        type: _ctx.disabled ? "info" : _ctx.type,
        loading: realLoading.value,
        onClick: handleClick
      }), vue.createSlots({
        _: 2
        /* DYNAMIC */
      }, [
        vue.unref(slots).loading ? {
          name: "loading",
          fn: vue.withCtx((slotValue) => [
            vue.renderSlot(_ctx.$slots, "loading", vue.normalizeProps(vue.guardReactiveProps(slotValue)))
          ]),
          key: "0"
        } : void 0,
        vue.unref(slots).default ? {
          name: "default",
          fn: vue.withCtx(() => [
            vue.renderSlot(_ctx.$slots, "default")
          ]),
          key: "1"
        } : void 0,
        vue.unref(slots).icon ? {
          name: "icon",
          fn: vue.withCtx((slotValue) => [
            vue.renderSlot(_ctx.$slots, "icon", vue.normalizeProps(vue.guardReactiveProps(slotValue)))
          ]),
          key: "2"
        } : void 0
      ]), 1040, ["type", "loading"]);
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=Button.vue2.js.map
