'use strict';

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

var vue = require('vue');
var lodashUnified = require('lodash-unified');
require('../../../hooks/index.js');
require('../../../tokens/index.js');
var button = require('../../../tokens/button.js');
var index = require('../../../hooks/use-global-config/index.js');
var index$1 = require('../../../hooks/use-form-item/index.js');
var index$2 = require('../../../hooks/use-common-props/index.js');

const useButton = (props, emit) => {
  const buttonGroupContext = vue.inject(button.buttonGroupContextKey, void 0);
  const globalConfig = index.useGlobalConfig("button");
  const { form } = index$1.useFormItem();
  const _size = index$2.useSize(vue.computed(() => buttonGroupContext == null ? void 0 : buttonGroupContext.size));
  const _disabled = index$2.useDisabled();
  const _ref = vue.ref();
  const slots = vue.useSlots();
  const instance = vue.getCurrentInstance();
  if (!instance.appContext.directives["http-loading"]) {
    instance.appContext.directives["http-loading"] = lodashUnified.noop;
  }
  const _type = vue.computed(() => {
    const _ = props.type || (buttonGroupContext == null ? void 0 : buttonGroupContext.type) || "";
    if (_ === "textDanger") {
      return "danger";
    }
    return _;
  });
  const _link = vue.computed(() => {
    return props.type === "textDanger" || props.link;
  });
  const autoInsertSpace = vue.computed(() => {
    var _a, _b, _c;
    return (_c = (_b = props.autoInsertSpace) != null ? _b : (_a = globalConfig.value) == null ? void 0 : _a.autoInsertSpace) != null ? _c : false;
  });
  const shouldAddSpace = vue.computed(() => {
    var _a;
    const defaultSlot = (_a = slots.default) == null ? void 0 : _a.call(slots);
    if (autoInsertSpace.value && (defaultSlot == null ? void 0 : defaultSlot.length) === 1) {
      const slot = defaultSlot[0];
      if ((slot == null ? void 0 : slot.type) === vue.Text) {
        const text = slot.children;
        return /^\p{Unified_Ideograph}{2}$/u.test(text.trim());
      }
    }
    return false;
  });
  const handleClick = (evt) => {
    if (props.nativeType === "reset") {
      form == null ? void 0 : form.resetFields();
    }
    emit("click", evt);
  };
  return {
    _link,
    _disabled,
    _size,
    _type,
    _ref,
    shouldAddSpace,
    handleClick
  };
};

exports.useButton = useButton;
//# sourceMappingURL=use-button.js.map
