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

import { _ as _slicedToArray } from '../_chunks/dep-84acf3c2.mjs';
import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { defineComponent, toRefs, ref, reactive, computed, nextTick, createVNode, mergeProps } from 'vue';
import { CloseCircleFilledIcon } from '@ldesign/icons-vue-next';
import { i as isArray_1 } from '../_chunks/dep-b57180d0.mjs';
import { Input } from '../input/index.mjs';
import { renderTNodeJSX } from '../utils/render-tnode.mjs';
import { useConfig } from '../config-provider/useConfig.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import { useGlobalIcon } from '../hooks/useGlobalIcon.mjs';
import useDefaultValue from '../hooks/useDefaultValue.mjs';
import props from './props.mjs';
import useTagScroll from './hooks/useTagScroll.mjs';
import useTagList from './useTagList.mjs';
import useHover from './hooks/useHover.mjs';
import useDragSorter from './hooks/useDragSorter.mjs';
import '../_chunks/dep-b8d7992c.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../utils/withInstall.mjs';
import '../input/input.mjs';
import '../_chunks/dep-60fae668.mjs';
import '../_chunks/dep-78847b2e.mjs';
import '../form/hooks.mjs';
import '../hooks/tnode.mjs';
import '../_chunks/dep-5717e263.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../input/props.mjs';
import '../input/useInput.mjs';
import '../form/const.mjs';
import '../hooks/index.mjs';
import '../hooks/icon.mjs';
import '../hooks/slot.mjs';
import '../hooks/useCommonClassName.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../_chunks/dep-40d69a9c.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useVirtualScroll.mjs';
import '../hooks/useVModel.mjs';
import '../input/useLengthLimit.mjs';
import '../_chunks/dep-3f21269a.mjs';
import '../_common/js/log/index.mjs';
import '../_common/js/log/log.mjs';
import '../_common/js/utils/helper.mjs';
import '../_chunks/dep-bf1e33c8.mjs';
import '../_chunks/dep-876fb3ec.mjs';
import '../_chunks/dep-ed5ebb35.mjs';
import '../input/useInputEventHandler.mjs';
import '../input/useInputWidth.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../config-provider/type.mjs';
import '../input/input-group.mjs';
import '../input/input-group-props.mjs';
import '../input/style/css.mjs';
import '../input/type.mjs';
import '../tag/index.mjs';
import '../tag/tag.mjs';
import '../tag/props.mjs';
import '../tag/check-tag.mjs';
import '../tag/check-tag-props.mjs';
import '../tag/style/css.mjs';
import '../tag/type.mjs';

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; }
var useComponentClassName = function useComponentClassName() {
  return {
    NAME_CLASS: usePrefixClass("tag-input"),
    CLEAR_CLASS: usePrefixClass("tag-input__suffix-clear"),
    BREAK_LINE_CLASS: usePrefixClass("tag-input--break-line")
  };
};
var _TagInput = defineComponent({
  name: "TTagInput",
  props: _objectSpread({}, props),
  setup: function setup(props2) {
    var _useComponentClassNam = useComponentClassName(),
      NAME_CLASS = _useComponentClassNam.NAME_CLASS,
      CLEAR_CLASS = _useComponentClassNam.CLEAR_CLASS,
      BREAK_LINE_CLASS = _useComponentClassNam.BREAK_LINE_CLASS;
    var _useGlobalIcon = useGlobalIcon({
        CloseCircleFilledIcon: CloseCircleFilledIcon
      }),
      CloseCircleFilledIcon$1 = _useGlobalIcon.CloseCircleFilledIcon;
    var _toRefs = toRefs(props2),
      inputValue = _toRefs.inputValue,
      inputProps = _toRefs.inputProps;
    var _useDefault = useDefaultValue(inputValue, props2.defaultInputValue, props2.onInputChange, "inputValue"),
      _useDefault2 = _slicedToArray(_useDefault, 2),
      tInputValue = _useDefault2[0],
      setTInputValue = _useDefault2[1];
    var _toRefs2 = toRefs(props2),
      excessTagsDisplayType = _toRefs2.excessTagsDisplayType,
      readonly = _toRefs2.readonly,
      disabled = _toRefs2.disabled,
      clearable = _toRefs2.clearable,
      placeholder = _toRefs2.placeholder;
    var _useHover = useHover({
        readonly: props2.readonly,
        disabled: props2.disabled,
        onMouseenter: props2.onMouseenter,
        onMouseleave: props2.onMouseleave
      }),
      isHover = _useHover.isHover,
      addHover = _useHover.addHover,
      cancelHover = _useHover.cancelHover;
    var isComposition = ref(false);
    var _useConfig = useConfig(),
      classPrefix = _useConfig.classPrefix;
    var _useDragSorter = useDragSorter(_objectSpread(_objectSpread({}, props2), {}, {
        sortOnDraggable: props2.dragSort,
        onDragOverCheck: {
          x: true,
          targetClassNameRegExp: new RegExp("^".concat(classPrefix.value, "-tag"))
        }
      })),
      getDragProps = _useDragSorter.getDragProps;
    var _useTagScroll = useTagScroll(props2),
      scrollToRight = _useTagScroll.scrollToRight,
      onWheel = _useTagScroll.onWheel,
      scrollToRightOnEnter = _useTagScroll.scrollToRightOnEnter,
      scrollToLeftOnLeave = _useTagScroll.scrollToLeftOnLeave,
      tagInputRef = _useTagScroll.tagInputRef;
    var _useTagList = useTagList(reactive(_objectSpread(_objectSpread({}, toRefs(props2)), {}, {
        getDragProps: getDragProps
      }))),
      tagValue = _useTagList.tagValue,
      onInnerEnter = _useTagList.onInnerEnter,
      onInputBackspaceKeyUp = _useTagList.onInputBackspaceKeyUp,
      clearAll = _useTagList.clearAll,
      renderLabel = _useTagList.renderLabel,
      onClose = _useTagList.onClose;
    var classes = computed(function () {
      var _ref;
      var isEmpty = !(isArray_1(tagValue.value) && tagValue.value.length);
      return [NAME_CLASS.value, (_ref = {}, _defineProperty(_ref, BREAK_LINE_CLASS.value, excessTagsDisplayType.value === "break-line"), _defineProperty(_ref, "".concat(classPrefix.value, "-is-empty"), isEmpty), _defineProperty(_ref, "".concat(classPrefix.value, "-tag-input--with-tag"), !isEmpty), _ref)];
    });
    var tagInputPlaceholder = computed(function () {
      var _tagValue$value;
      return !((_tagValue$value = tagValue.value) !== null && _tagValue$value !== void 0 && _tagValue$value.length) ? placeholder.value : "";
    });
    var showClearIcon = computed(function () {
      var _tagValue$value2;
      return Boolean(!readonly.value && !disabled.value && clearable.value && isHover.value && (((_tagValue$value2 = tagValue.value) === null || _tagValue$value2 === void 0 ? void 0 : _tagValue$value2.length) || tInputValue.value));
    });
    var onInputEnter = function onInputEnter(value, context) {
      var _context$e, _context$e$preventDef;
      (_context$e = context.e) === null || _context$e === void 0 ? void 0 : (_context$e$preventDef = _context$e.preventDefault) === null || _context$e$preventDef === void 0 ? void 0 : _context$e$preventDef.call(_context$e);
      setTInputValue("", {
        e: context.e,
        trigger: "enter"
      });
      !isComposition.value && onInnerEnter(value, context);
      nextTick(function () {
        scrollToRight();
        isComposition.value = false;
      });
    };
    var onInputCompositionstart = function onInputCompositionstart(value, context) {
      var _inputProps$value, _inputProps$value$onC;
      isComposition.value = true;
      (_inputProps$value = inputProps.value) === null || _inputProps$value === void 0 ? void 0 : (_inputProps$value$onC = _inputProps$value.onCompositionstart) === null || _inputProps$value$onC === void 0 ? void 0 : _inputProps$value$onC.call(_inputProps$value, value, context);
    };
    var onInputCompositionend = function onInputCompositionend(value, context) {
      var _inputProps$value2, _inputProps$value2$on;
      isComposition.value = false;
      (_inputProps$value2 = inputProps.value) === null || _inputProps$value2 === void 0 ? void 0 : (_inputProps$value2$on = _inputProps$value2.onCompositionend) === null || _inputProps$value2$on === void 0 ? void 0 : _inputProps$value2$on.call(_inputProps$value2, value, context);
    };
    var onClick = function onClick(ctx) {
      var _props2$onClick;
      tagInputRef.value.focus();
      (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, ctx);
    };
    var onClearClick = function onClearClick(context) {
      var _props2$onClear;
      clearAll(context);
      setTInputValue("", {
        e: context.e,
        trigger: "clear"
      });
      (_props2$onClear = props2.onClear) === null || _props2$onClear === void 0 ? void 0 : _props2$onClear.call(props2, context);
    };
    return {
      CLEAR_CLASS: CLEAR_CLASS,
      CloseCircleFilledIcon: CloseCircleFilledIcon$1,
      tagValue: tagValue,
      tInputValue: tInputValue,
      isHover: isHover,
      tagInputPlaceholder: tagInputPlaceholder,
      showClearIcon: showClearIcon,
      tagInputRef: tagInputRef,
      classPrefix: classPrefix,
      setTInputValue: setTInputValue,
      addHover: addHover,
      cancelHover: cancelHover,
      onInputEnter: onInputEnter,
      onInnerEnter: onInnerEnter,
      onInputBackspaceKeyUp: onInputBackspaceKeyUp,
      renderLabel: renderLabel,
      onWheel: onWheel,
      scrollToRightOnEnter: scrollToRightOnEnter,
      scrollToLeftOnLeave: scrollToLeftOnLeave,
      onClick: onClick,
      onClearClick: onClearClick,
      onClose: onClose,
      onInputCompositionstart: onInputCompositionstart,
      onInputCompositionend: onInputCompositionend,
      classes: classes
    };
  },
  render: function render() {
    var _this = this,
      _this$inputProps,
      _this$tagValue;
    var CloseCircleFilledIcon = this.CloseCircleFilledIcon;
    var suffixIconNode = this.showClearIcon ? createVNode(CloseCircleFilledIcon, {
      "class": this.CLEAR_CLASS,
      "onClick": this.onClearClick
    }, null) : renderTNodeJSX(this, "suffixIcon");
    var suffixClass = "".concat(this.classPrefix, "-tag-input__with-suffix-icon");
    if (suffixIconNode && !this.classes.includes(suffixClass)) this.classes.push(suffixClass);
    var displayNode = renderTNodeJSX(this, "valueDisplay", {
      params: {
        value: this.tagValue,
        onClose: function onClose(index, item) {
          return _this.onClose({
            index: index,
            item: item
          });
        }
      }
    });
    var _label = renderTNodeJSX(this, "label", {
      silent: true
    });
    return createVNode(Input, mergeProps({
      "ref": "tagInputRef",
      "readonly": this.readonly,
      "value": this.tInputValue,
      "autoWidth": true,
      "size": this.size,
      "disabled": this.disabled,
      "label": function label() {
        return _this.renderLabel({
          displayNode: displayNode,
          label: _label
        });
      },
      "class": this.classes,
      "tips": this.tips,
      "status": this.status,
      "placeholder": this.tagInputPlaceholder,
      "suffix": this.suffix,
      "suffixIcon": function suffixIcon() {
        return suffixIconNode;
      },
      "showInput": !((_this$inputProps = this.inputProps) !== null && _this$inputProps !== void 0 && _this$inputProps.readonly) || !this.tagValue || !((_this$tagValue = this.tagValue) !== null && _this$tagValue !== void 0 && _this$tagValue.length),
      "keepWrapperWidth": !this.autoWidth,
      "onWheel": this.onWheel,
      "onChange": function onChange(val, context) {
        _this.setTInputValue(val, _objectSpread(_objectSpread({}, context), {}, {
          trigger: "input"
        }));
      },
      "onPaste": this.onPaste,
      "onEnter": this.onInputEnter,
      "onKeydown": this.onInputBackspaceKeyUp,
      "onMouseenter": function onMouseenter(context) {
        _this.addHover(context);
        _this.scrollToRightOnEnter();
      },
      "onMouseleave": function onMouseleave(context) {
        _this.cancelHover(context);
        _this.scrollToLeftOnLeave();
      },
      "onFocus": function onFocus(inputValue, context) {
        var _this$onFocus;
        (_this$onFocus = _this.onFocus) === null || _this$onFocus === void 0 ? void 0 : _this$onFocus.call(_this, _this.tagValue, {
          e: context.e,
          inputValue: inputValue
        });
      },
      "onBlur": function onBlur(inputValue, context) {
        var _this$onBlur;
        _this.setTInputValue("", {
          e: context.e,
          trigger: "blur"
        });
        (_this$onBlur = _this.onBlur) === null || _this$onBlur === void 0 ? void 0 : _this$onBlur.call(_this, _this.tagValue, {
          e: context.e,
          inputValue: ""
        });
      },
      "onClick": this.onClick,
      "onCompositionstart": this.onInputCompositionstart,
      "onCompositionend": this.onInputCompositionend
    }, this.inputProps), {
      suffix: this.$slots.suffix
    });
  }
});

export { _TagInput as default };
//# sourceMappingURL=tag-input.mjs.map
