/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _objectWithoutProperties } from '../_chunks/dep-b6a73f93.mjs';
import { _ as _defineProperty } from '../_chunks/dep-eb20e23f.mjs';
import { defineComponent, computed, createVNode, mergeProps } from 'vue';
import { BrowseIcon, BrowseOffIcon, CloseCircleFilledIcon } from '@ldesign/icons-vue-next';
import { i as isUndefined_1 } from '../_chunks/dep-30451c48.mjs';
import { useFormDisabled } from '../form/hooks.mjs';
import { usePrefixClass, useCommonClassName } from '../hooks/useConfig.mjs';
import { useGlobalIcon } from '../hooks/useGlobalIcon.mjs';
import { useTNodeJSX } from '../hooks/tnode.mjs';
import props from './props.mjs';
import useInput from './useInput.mjs';
import useInputEventHandler from './useInputEventHandler.mjs';
import useInputWidth from './useInputWidth.mjs';
import { useConfig } from '../config-provider/useConfig.mjs';
import '../_chunks/dep-b4041200.mjs';
import '../_chunks/dep-a0b4a044.mjs';
import '../_chunks/dep-6b22dd27.mjs';
import '../_chunks/dep-c959a6fb.mjs';
import '../_chunks/dep-0f0c89ff.mjs';
import '../_chunks/dep-f6649a46.mjs';
import '../_chunks/dep-37ba476d.mjs';
import '../_chunks/dep-e3b14d70.mjs';
import '../_chunks/dep-66d6733b.mjs';
import '../_chunks/dep-be27d184.mjs';
import '../_chunks/dep-c31e1d9e.mjs';
import '../_chunks/dep-1fe0ad42.mjs';
import '../_chunks/dep-d54f2690.mjs';
import '../_chunks/dep-59c8420d.mjs';
import '../_chunks/dep-74848b92.mjs';
import '../_chunks/dep-c4e1a112.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-bd03960e.mjs';
import '../_chunks/dep-44f056cd.mjs';
import '../_chunks/dep-a9c8a5d5.mjs';
import '../_chunks/dep-10085c61.mjs';
import '../_chunks/dep-1b058de3.mjs';
import '../_chunks/dep-39cc276d.mjs';
import '../_chunks/dep-8f777748.mjs';
import '../_chunks/dep-05fa17c9.mjs';
import '../_chunks/dep-92e7085e.mjs';
import '../_chunks/dep-1cf2b129.mjs';
import '../_chunks/dep-55846619.mjs';
import '../_chunks/dep-cfcedf47.mjs';
import '../form/const.mjs';
import '../hooks/index.mjs';
import '../hooks/icon.mjs';
import '../hooks/slot.mjs';
import '../hooks/useCommonClassName.mjs';
import '../hooks/useDefaultValue.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../_chunks/dep-99920870.mjs';
import '../_chunks/dep-79821ff2.mjs';
import '../_chunks/dep-0bfbf721.mjs';
import '../_chunks/dep-ae357f26.mjs';
import '../_chunks/dep-352691c2.mjs';
import '../_chunks/dep-2cfd5b3a.mjs';
import '../_chunks/dep-c852a61a.mjs';
import '../_chunks/dep-c7e9ce16.mjs';
import '../_chunks/dep-3afa94cf.mjs';
import '../_chunks/dep-ba3c0b2e.mjs';
import '../_chunks/dep-ee57d235.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-6b4aa943.mjs';
import '../_chunks/dep-d52291a9.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useVirtualScroll.mjs';
import '../hooks/useVModel.mjs';
import './useLengthLimit.mjs';
import '../_chunks/dep-6eea369f.mjs';
import '../_common/js/log/index.mjs';
import '../_common/js/log/log.mjs';
import '../_common/js/utils/helper.mjs';
import '../_chunks/dep-e091cfd9.mjs';
import '../_chunks/dep-6f89b77e.mjs';
import '../_chunks/dep-44417261.mjs';
import '../_chunks/dep-bf74f1c2.mjs';
import '../_chunks/dep-23a0f453.mjs';
import '../config-provider/type.mjs';

var _excluded = ["isHover", "tStatus", "inputRef", "renderType", "showClear", "focused", "inputValue", "isComposition", "compositionValue", "innerValue", "limitNumber"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function getValidAttrs(obj) {
  var newObj = {};
  Object.keys(obj).forEach(function (key) {
    if (!isUndefined_1(obj[key])) newObj[key] = obj[key];
  });
  return newObj;
}
var _Input = defineComponent({
  name: "TInput",
  props: _objectSpread(_objectSpread({}, props), {}, {
    showInput: {
      type: Boolean,
      "default": true
    },
    keepWrapperWidth: {
      type: Boolean,
      "default": false
    },
    allowTriggerBlur: {
      type: Boolean,
      "default": true
    }
  }),
  setup: function setup(props2, _ref) {
    var expose = _ref.expose;
    var _useConfig = useConfig("input"),
      globalConfig = _useConfig.globalConfig;
    var _useGlobalIcon = useGlobalIcon({
        BrowseIcon: BrowseIcon,
        BrowseOffIcon: BrowseOffIcon,
        CloseCircleFilledIcon: CloseCircleFilledIcon
      }),
      BrowseIcon$1 = _useGlobalIcon.BrowseIcon,
      BrowseOffIcon$1 = _useGlobalIcon.BrowseOffIcon,
      CloseCircleFilledIcon$1 = _useGlobalIcon.CloseCircleFilledIcon;
    var disabled = useFormDisabled();
    var COMPONENT_NAME = usePrefixClass("input");
    var INPUT_WRAP_CLASS = usePrefixClass("input__wrap");
    var INPUT_TIPS_CLASS = usePrefixClass("input__tips");
    var _useCommonClassName = useCommonClassName(),
      STATUS = _useCommonClassName.STATUS,
      SIZE = _useCommonClassName.SIZE;
    var classPrefix = usePrefixClass();
    var renderTNodeJSX = useTNodeJSX();
    var _useInput = useInput(props2, expose),
      isHover = _useInput.isHover,
      tStatus = _useInput.tStatus,
      inputRef = _useInput.inputRef,
      renderType = _useInput.renderType,
      showClear = _useInput.showClear,
      focused = _useInput.focused,
      inputValue = _useInput.inputValue,
      isComposition = _useInput.isComposition,
      compositionValue = _useInput.compositionValue,
      innerValue = _useInput.innerValue,
      limitNumber = _useInput.limitNumber,
      inputHandle = _objectWithoutProperties(_useInput, _excluded);
    var _useInputWidth = useInputWidth(props2, inputRef, innerValue),
      inputPreRef = _useInputWidth.inputPreRef;
    var inputEventHandler = useInputEventHandler(props2, isHover);
    var tPlaceholder = computed(function () {
      var _props2$placeholder;
      return (_props2$placeholder = props2.placeholder) !== null && _props2$placeholder !== void 0 ? _props2$placeholder : globalConfig.value.placeholder;
    });
    var inputAttrs = computed(function () {
      var _props2$autocomplete;
      return getValidAttrs({
        autofocus: props2.autofocus,
        disabled: disabled.value,
        readonly: props2.readonly,
        placeholder: tPlaceholder.value,
        maxlength: !props2.allowInputOverMax && props2.maxlength || void 0,
        name: props2.name || void 0,
        type: renderType.value,
        autocomplete: (_props2$autocomplete = props2.autocomplete) !== null && _props2$autocomplete !== void 0 ? _props2$autocomplete : globalConfig.value.autocomplete || void 0,
        unselectable: props2.readonly ? "on" : void 0
      });
    });
    var wrapClasses = computed(function () {
      return [INPUT_WRAP_CLASS.value, _defineProperty({}, "".concat(COMPONENT_NAME.value, "--auto-width"), props2.autoWidth && !props2.keepWrapperWidth)];
    });
    var inputEvents = getValidAttrs({
      onFocus: function onFocus(e) {
        return inputHandle.emitFocus(e);
      },
      onBlur: inputHandle.formatAndEmitBlur,
      onKeydown: inputEventHandler.handleKeydown,
      onKeyup: inputEventHandler.handleKeyUp,
      onKeypress: inputEventHandler.handleKeypress,
      onPaste: inputEventHandler.onHandlePaste,
      onCompositionend: inputHandle.onHandleCompositionend,
      onCompositionstart: inputHandle.onHandleCompositionstart
    });
    return function () {
      var _ref3, _compositionValue$val, _inputValue$value;
      var prefixIcon = renderTNodeJSX("prefixIcon");
      var suffixIcon = renderTNodeJSX("suffixIcon");
      var passwordIcon = renderTNodeJSX("passwordIcon");
      var label = renderTNodeJSX("label", {
        silent: true
      });
      var suffix = renderTNodeJSX("suffix");
      var limitNode = limitNumber.value && props2.showLimitNumber ? createVNode("div", {
        "class": "".concat(classPrefix.value, "-input__limit-number")
      }, [limitNumber.value]) : null;
      var labelContent = label ? createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__prefix")
      }, [label]) : null;
      var suffixContent = suffix || limitNode ? createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__suffix")
      }, [suffix, limitNode]) : null;
      if (props2.type === "password") {
        if (renderType.value === "password") {
          suffixIcon = createVNode(BrowseOffIcon$1, {
            "class": "".concat(COMPONENT_NAME.value, "__suffix-clear"),
            "onClick": inputHandle.emitPassword
          }, null);
        } else if (renderType.value === "text") {
          suffixIcon = createVNode(BrowseIcon$1, {
            "class": "".concat(COMPONENT_NAME.value, "__suffix-clear"),
            "onClick": inputHandle.emitPassword
          }, null);
        }
      }
      if (showClear.value) {
        if (props2.type === "password") {
          passwordIcon = createVNode(CloseCircleFilledIcon$1, {
            "ref": inputHandle.clearIconRef,
            "class": "".concat(COMPONENT_NAME.value, "__suffix-clear"),
            "onClick": inputHandle.emitClear,
            "onMousedown": inputHandle.onClearIconMousedown
          }, null);
        } else {
          suffixIcon = createVNode(CloseCircleFilledIcon$1, {
            "ref": inputHandle.clearIconRef,
            "class": "".concat(COMPONENT_NAME.value, "__suffix-clear"),
            "onClick": inputHandle.emitClear,
            "onMousedown": inputHandle.onClearIconMousedown
          }, null);
        }
      }
      var classes = [COMPONENT_NAME.value, props2.inputClass, (_ref3 = {}, _defineProperty(_ref3, SIZE.value[props2.size], props2.size !== "medium"), _defineProperty(_ref3, STATUS.value.disabled, disabled.value), _defineProperty(_ref3, STATUS.value.focused, focused.value), _defineProperty(_ref3, "".concat(classPrefix.value, "-is-").concat(tStatus.value), tStatus.value && tStatus.value !== "default"), _defineProperty(_ref3, "".concat(classPrefix.value, "-align-").concat(props2.align), props2.align !== "left"), _defineProperty(_ref3, "".concat(classPrefix.value, "-is-readonly"), props2.readonly), _defineProperty(_ref3, "".concat(COMPONENT_NAME.value, "--prefix"), prefixIcon || labelContent), _defineProperty(_ref3, "".concat(COMPONENT_NAME.value, "--suffix"), suffixIcon || suffixContent), _defineProperty(_ref3, "".concat(COMPONENT_NAME.value, "--focused"), focused.value), _ref3)];
      var tips = renderTNodeJSX("tips");
      return createVNode("div", {
        "class": wrapClasses.value
      }, [createVNode("div", {
        "class": classes,
        "onClick": inputHandle.onRootClick,
        "onMouseenter": inputEventHandler.onInputMouseenter,
        "onMouseleave": inputEventHandler.onInputMouseleave,
        "onWheel": inputEventHandler.onHandleMousewheel
      }, [prefixIcon ? createVNode("span", {
        "class": ["".concat(COMPONENT_NAME.value, "__prefix"), "".concat(COMPONENT_NAME.value, "__prefix-icon")]
      }, [prefixIcon]) : null, labelContent, props2.showInput && createVNode("input", mergeProps({
        "class": "".concat(COMPONENT_NAME.value, "__inner")
      }, inputAttrs.value, inputEvents, {
        "ref": inputRef,
        "value": isComposition.value ? (_compositionValue$val = compositionValue.value) !== null && _compositionValue$val !== void 0 ? _compositionValue$val : "" : (_inputValue$value = inputValue.value) !== null && _inputValue$value !== void 0 ? _inputValue$value : "",
        "onInput": function onInput(e) {
          return inputHandle.handleInput(e);
        }
      }), null), props2.autoWidth && createVNode("span", {
        "ref": inputPreRef,
        "class": "".concat(classPrefix.value, "-input__input-pre")
      }, [innerValue.value || tPlaceholder.value]), suffixContent, passwordIcon ? createVNode("span", {
        "class": ["".concat(COMPONENT_NAME.value, "__suffix"), "".concat(COMPONENT_NAME.value, "__suffix-icon"), "".concat(COMPONENT_NAME.value, "__clear")]
      }, [passwordIcon]) : null, suffixIcon ? createVNode("span", {
        "class": ["".concat(COMPONENT_NAME.value, "__suffix"), "".concat(COMPONENT_NAME.value, "__suffix-icon"), _defineProperty({}, "".concat(COMPONENT_NAME.value, "__clear"), showClear.value)]
      }, [suffixIcon]) : null]), tips && createVNode("div", {
        "class": "".concat(INPUT_TIPS_CLASS.value, " ").concat(classPrefix.value, "-input__tips--").concat(tStatus.value || "default")
      }, [tips])]);
    };
  }
});

export { _Input as default };
//# sourceMappingURL=input.mjs.map
