'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
var index = require('../_util/vue-types/index.js');
var vnode = require('../_util/vnode.js');
var classNames = require('../_util/classNames.js');
var type = require('../_util/type.js');
var FormItemContext = require('../form/FormItemContext.js');
var statusUtils = require('../_util/statusUtils.js');
var util = require('./util.js');

const ClearableInputType = ["text", "input"];
var ClearableLabeledInput = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ClearableLabeledInput",
  inheritAttrs: false,
  props: {
    prefixCls: String,
    inputType: index.default.oneOf(type.tuple("text", "input")),
    value: type.anyType(),
    defaultValue: type.anyType(),
    allowClear: {
      type: Boolean,
      default: void 0
    },
    element: type.anyType(),
    handleReset: Function,
    disabled: {
      type: Boolean,
      default: void 0
    },
    direction: {
      type: String
    },
    size: {
      type: String
    },
    suffix: type.anyType(),
    prefix: type.anyType(),
    addonBefore: type.anyType(),
    addonAfter: type.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(CloseOutlined.CloseCircleFilled, {
        "onClick": handleReset,
        "onMousedown": (e) => e.preventDefault(),
        "class": classNames.default({
          [`${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 = classNames.default(`${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.js.map
