'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
var FormItemContext = require('../../form/src/FormItemContext.cjs');
var util = require('./util.cjs');
var vueTypes = require('../../../utils/vue/vueTypes.cjs');
var propType = require('../../../utils/vue/propType.cjs');
var _class = require('../../../utils/dom/class.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');
var statusUtils = require('../../../utils/statusUtils.cjs');

const ClearableInputType = ["text", "input"];
var ClearableLabeledInput = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ClearableLabeledInput",
  inheritAttrs: false,
  props: {
    prefixCls: String,
    inputType: vueTypes.default.oneOf(propType.tuple("text", "input")),
    value: propType.anyType(),
    defaultValue: propType.anyType(),
    allowClear: {
      type: Boolean,
      default: void 0
    },
    element: propType.anyType(),
    handleReset: Function,
    disabled: {
      type: Boolean,
      default: void 0
    },
    direction: {
      type: String
    },
    size: {
      type: String
    },
    suffix: propType.anyType(),
    prefix: propType.anyType(),
    addonBefore: propType.anyType(),
    addonAfter: propType.anyType(),
    readonly: {
      type: Boolean,
      default: void 0
    },
    focused: {
      type: Boolean,
      default: void 0
    },
    bordered: {
      type: Boolean,
      default: true
    },
    triggerFocus: {
      type: Function
    },
    hidden: Boolean,
    status: String,
    hashId: String
  },
  setup(props, {
    slots,
    attrs
  }) {
    const statusContext = FormItemContext.FormItemInputContext.useInject();
    const renderClearIcon = (prefixCls) => {
      const {
        value,
        disabled,
        readonly,
        handleReset,
        suffix = slots.suffix
      } = props;
      const needClear = !disabled && !readonly && value;
      const className = `${prefixCls}-clear-icon`;
      return vue.createVNode(iconsVue.CloseCircleFilled, {
        "onClick": handleReset,
        "onMousedown": (e) => e.preventDefault(),
        "class": _class.classNames({
          [`${className}-hidden`]: !needClear,
          [`${className}-has-suffix`]: !!suffix
        }, className),
        "role": "button"
      }, null);
    };
    const renderTextAreaWithClearIcon = (prefixCls, element) => {
      const {
        value,
        allowClear,
        direction,
        bordered,
        hidden,
        status: customStatus,
        addonAfter = slots.addonAfter,
        addonBefore = slots.addonBefore,
        hashId
      } = props;
      const {
        status: contextStatus,
        hasFeedback
      } = statusContext;
      if (!allowClear) {
        return vnode.cloneElement(element, {
          value,
          disabled: props.disabled
        });
      }
      const affixWrapperCls = _class.classNames(`${prefixCls}-affix-wrapper`, `${prefixCls}-affix-wrapper-textarea-with-clear-btn`, statusUtils.getStatusClassNames(`${prefixCls}-affix-wrapper`, statusUtils.getMergedStatus(contextStatus, customStatus), hasFeedback), {
        [`${prefixCls}-affix-wrapper-rtl`]: direction === "rtl",
        [`${prefixCls}-affix-wrapper-borderless`]: !bordered,
        // className will go to addon wrapper
        [`${attrs.class}`]: !util.hasAddon({
          addonAfter,
          addonBefore
        }) && attrs.class
      }, hashId);
      return vue.createVNode("span", {
        "class": affixWrapperCls,
        "style": attrs.style,
        "hidden": hidden
      }, [vnode.cloneElement(element, {
        style: null,
        value,
        disabled: props.disabled
      }), renderClearIcon(prefixCls)]);
    };
    return () => {
      var _a;
      const {
        prefixCls,
        inputType,
        element = (_a = slots.element) == null ? void 0 : _a.call(slots)
      } = props;
      if (inputType === ClearableInputType[0])
        return renderTextAreaWithClearIcon(prefixCls, element);
      return null;
    };
  }
});

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