import { computed, inject, ref, useSlots, getCurrentInstance, Text } from 'vue';
import { noop } from 'lodash-unified';
import '../../../hooks/index.mjs';
import '../../../tokens/index.mjs';
import { useDeprecated } from '../../../hooks/use-deprecated/index.mjs';
import { buttonGroupContextKey } from '../../../tokens/button.mjs';
import { useGlobalConfig } from '../../../hooks/use-global-config/index.mjs';
import { useFormItem } from '../../../hooks/use-form-item/index.mjs';
import { useSize, useDisabled } from '../../../hooks/use-common-props/index.mjs';

const useButton = (props, emit) => {
  useDeprecated({
    from: "type.text",
    replacement: "link",
    version: "3.0.0",
    scope: "props",
    ref: "https://element-plus.org/en-US/component/button.html#button-attributes"
  }, computed(() => props.type === "text"));
  const buttonGroupContext = inject(buttonGroupContextKey, void 0);
  const globalConfig = useGlobalConfig("button");
  const { form } = useFormItem();
  const _size = useSize(computed(() => buttonGroupContext == null ? void 0 : buttonGroupContext.size));
  const _disabled = useDisabled();
  const _ref = ref();
  const slots = useSlots();
  const instance = getCurrentInstance();
  if (!instance.appContext.directives["http-loading"]) {
    instance.appContext.directives["http-loading"] = noop;
  }
  const _type = computed(() => {
    const _ = props.type || (buttonGroupContext == null ? void 0 : buttonGroupContext.type) || "";
    if (_ === "textDanger") {
      return "danger";
    }
    return _;
  });
  const _link = computed(() => {
    return props.type === "textDanger" || props.link;
  });
  const autoInsertSpace = 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 = 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) === 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
  };
};

export { useButton };
//# sourceMappingURL=use-button.mjs.map
