'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var inputProps = require('./inputProps.cjs');
var commonUtils = require('./utils/commonUtils.cjs');
var _class = require('../../../utils/dom/class.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');

var BaseInput = /* @__PURE__ */ vue.defineComponent({
  name: "BaseInput",
  inheritAttrs: false,
  props: inputProps.baseInputProps(),
  setup(props, {
    slots,
    attrs
  }) {
    const containerRef = vue.ref();
    const onInputMouseDown = (e) => {
      var _a;
      if ((_a = containerRef.value) == null ? void 0 : _a.contains(e.target)) {
        const {
          triggerFocus
        } = props;
        triggerFocus == null ? void 0 : triggerFocus();
      }
    };
    const getClearIcon = () => {
      var _a;
      const {
        allowClear,
        value,
        disabled,
        readonly,
        handleReset,
        suffix = slots.suffix,
        prefixCls
      } = props;
      if (!allowClear)
        return null;
      const needClear = !disabled && !readonly && value;
      const className = `${prefixCls}-clear-icon`;
      const iconNode = ((_a = slots.clearIcon) == null ? void 0 : _a.call(slots)) || "*";
      return vue.createVNode("span", {
        "onClick": handleReset,
        "onMousedown": (e) => e.preventDefault(),
        "class": _class.classNames({
          [`${className}-hidden`]: !needClear,
          [`${className}-has-suffix`]: !!suffix
        }, className),
        "role": "button",
        "tabindex": -1
      }, [iconNode]);
    };
    return () => {
      var _a, _b;
      const {
        focused,
        value,
        disabled,
        allowClear,
        readonly,
        hidden,
        prefixCls,
        prefix = (_a = slots.prefix) == null ? void 0 : _a.call(slots),
        suffix = (_b = slots.suffix) == null ? void 0 : _b.call(slots),
        addonAfter = slots.addonAfter,
        addonBefore = slots.addonBefore,
        inputElement,
        affixWrapperClassName,
        wrapperClassName,
        groupClassName
      } = props;
      let element = vnode.cloneElement(inputElement, {
        value,
        hidden
      });
      if (commonUtils.hasPrefixSuffix({
        prefix,
        suffix,
        allowClear
      })) {
        const affixWrapperPrefixCls = `${prefixCls}-affix-wrapper`;
        const affixWrapperCls = _class.classNames(affixWrapperPrefixCls, {
          [`${affixWrapperPrefixCls}-disabled`]: disabled,
          [`${affixWrapperPrefixCls}-focused`]: focused,
          [`${affixWrapperPrefixCls}-readonly`]: readonly,
          [`${affixWrapperPrefixCls}-input-with-clear-btn`]: suffix && allowClear && value
        }, !commonUtils.hasAddon({
          addonAfter,
          addonBefore
        }) && attrs.class, affixWrapperClassName);
        const suffixNode = (suffix || allowClear) && vue.createVNode("span", {
          "class": `${prefixCls}-suffix`
        }, [getClearIcon(), suffix]);
        element = vue.createVNode("span", {
          "class": affixWrapperCls,
          "style": attrs.style,
          "hidden": !commonUtils.hasAddon({
            addonAfter,
            addonBefore
          }) && hidden,
          "onMousedown": onInputMouseDown,
          "ref": containerRef
        }, [prefix && vue.createVNode("span", {
          "class": `${prefixCls}-prefix`
        }, [prefix]), vnode.cloneElement(inputElement, {
          style: null,
          value,
          hidden: null
        }), suffixNode]);
      }
      if (commonUtils.hasAddon({
        addonAfter,
        addonBefore
      })) {
        const wrapperCls = `${prefixCls}-group`;
        const addonCls = `${wrapperCls}-addon`;
        const mergedWrapperClassName = _class.classNames(`${prefixCls}-wrapper`, wrapperCls, wrapperClassName);
        const mergedGroupClassName = _class.classNames(`${prefixCls}-group-wrapper`, attrs.class, groupClassName);
        return vue.createVNode("span", {
          "class": mergedGroupClassName,
          "style": attrs.style,
          "hidden": hidden
        }, [vue.createVNode("span", {
          "class": mergedWrapperClassName
        }, [addonBefore && vue.createVNode("span", {
          "class": addonCls
        }, [addonBefore]), vnode.cloneElement(element, {
          style: null,
          hidden: null
        }), addonAfter && vue.createVNode("span", {
          "class": addonCls
        }, [addonAfter])])]);
      }
      return element;
    };
  }
});

exports.default = BaseInput;
//# sourceMappingURL=BaseInput.cjs.map
