'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
var lodashEs = require('lodash-es');
require('../../../utils/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../../button/index.cjs');
var props = require('./props.cjs');
var Input = require('./Input.cjs');
var vueTypes = require('../../../utils/vue/vueTypes.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');
var _class = require('../../../utils/dom/class.cjs');
var omit = require('../../../utils/lang/omit.cjs');

var AInputSearch = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AInputSearch",
  inheritAttrs: false,
  props: {
    ...props.inputProps(),
    inputPrefixCls: String,
    // 不能设置默认值 https://github.com/vueComponent/ant-design-vue/issues/1916
    enterButton: vueTypes.default.any,
    onSearch: {
      type: Function
    }
  },
  setup(props, {
    slots,
    attrs,
    expose,
    emit
  }) {
    const inputRef = vue.shallowRef();
    const composedRef = vue.shallowRef(false);
    const focus = () => {
      var _a;
      (_a = inputRef.value) == null ? void 0 : _a.focus();
    };
    const blur = () => {
      var _a;
      (_a = inputRef.value) == null ? void 0 : _a.blur();
    };
    expose({
      focus,
      blur
    });
    const onChange = (e) => {
      emit("update:value", e.target.value);
      if (e && e.target && e.type === "click")
        emit("search", e.target.value, e);
      emit("change", e);
    };
    const onMousedown = (e) => {
      var _a;
      if (document.activeElement === ((_a = inputRef.value) == null ? void 0 : _a.input))
        e.preventDefault();
    };
    const onSearch = (e) => {
      var _a, _b;
      emit("search", (_b = (_a = inputRef.value) == null ? void 0 : _a.input) == null ? void 0 : _b.stateValue, e);
    };
    const onPressEnter = (e) => {
      if (composedRef.value || props.loading)
        return;
      onSearch(e);
    };
    const handleOnCompositionStart = (e) => {
      composedRef.value = true;
      emit("compositionstart", e);
    };
    const handleOnCompositionEnd = (e) => {
      composedRef.value = false;
      emit("compositionend", e);
    };
    const {
      prefixCls,
      getPrefixCls,
      direction,
      size
    } = useConfigInject.default("input-search", props);
    const inputPrefixCls = vue.computed(() => getPrefixCls("input", props.inputPrefixCls));
    return () => {
      var _a, _b, _c, _d;
      const {
        disabled,
        loading,
        addonAfter = (_a = slots.addonAfter) == null ? void 0 : _a.call(slots),
        suffix = (_b = slots.suffix) == null ? void 0 : _b.call(slots),
        ...restProps
      } = props;
      let {
        enterButton = (_d = (_c = slots.enterButton) == null ? void 0 : _c.call(slots)) != null ? _d : false
      } = props;
      enterButton = enterButton || enterButton === "";
      const searchIcon = typeof enterButton === "boolean" ? vue.createVNode(iconsVue.SearchOutlined, null, null) : null;
      const btnClassName = `${prefixCls.value}-button`;
      const enterButtonAsElement = Array.isArray(enterButton) ? enterButton[0] : enterButton;
      let button;
      const isAntdButton = enterButtonAsElement.type && lodashEs.isPlainObject(enterButtonAsElement.type) && enterButtonAsElement.type.__ANT_BUTTON;
      if (isAntdButton || enterButtonAsElement.tagName === "button") {
        button = vnode.cloneElement(enterButtonAsElement, {
          onMousedown,
          onClick: onSearch,
          key: "enterButton",
          ...isAntdButton ? {
            class: btnClassName,
            size: size.value
          } : {}
        }, false);
      } else {
        const iconOnly = searchIcon && !enterButton;
        button = vue.createVNode(index.Button, {
          "class": btnClassName,
          "type": enterButton ? "primary" : void 0,
          "size": size.value,
          "disabled": disabled,
          "key": "enterButton",
          "onMousedown": onMousedown,
          "onClick": onSearch,
          "loading": loading,
          "icon": iconOnly ? searchIcon : null
        }, {
          default: () => [iconOnly ? null : searchIcon || enterButton]
        });
      }
      if (addonAfter)
        button = [button, addonAfter];
      const cls = _class.classNames(prefixCls.value, {
        [`${prefixCls.value}-rtl`]: direction.value === "rtl",
        [`${prefixCls.value}-${size.value}`]: !!size.value,
        [`${prefixCls.value}-with-button`]: !!enterButton
      }, attrs.class);
      return vue.createVNode(Input.default, {
        "ref": inputRef,
        ...omit.omit(restProps, ["onUpdate:value", "onSearch", "enterButton"]),
        ...attrs,
        "onPressEnter": onPressEnter,
        "onCompositionstart": handleOnCompositionStart,
        "onCompositionend": handleOnCompositionEnd,
        "size": size.value,
        "prefixCls": inputPrefixCls.value,
        "addonAfter": button,
        "suffix": suffix,
        "onChange": onChange,
        "class": cls,
        "disabled": disabled
      }, slots);
    };
  }
});

exports.default = AInputSearch;
//# sourceMappingURL=Search.cjs.map
