/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-37d5b9c4.js';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, computed, nextTick } from '@vue/composition-api';
import { CloseCircleFilledIcon } from 'tdesign-icons-vue';
import { Input } from '../input/index.js';
import props from './props.js';
import { prefix } from '../config.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import useTagScroll from './useTagScroll.js';
import useTagList from './useTagList.js';
import useHover from './useHover.js';
import useDefaultValue from '../hooks/useDefaultValue.js';
import '../input/addon.js';
import 'vue';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import '../utils/mixins.js';
import '../utils/classnames.js';
import '../utils/event.js';
import '../input/props.js';
import '../input/input-group.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../input/type.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag/type.js';
import '../hooks/useVModel.js';
import '../hooks/tnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../hooks/render-tnode.js';
import 'lodash/isString';
import 'lodash/isObject';

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 NAME_CLASS = "".concat(prefix, "-tag-input");
var CLEAR_CLASS = "".concat(prefix, "-tag-input__suffix-clear");
var BREAK_LINE_CLASS = "".concat(prefix, "-tag-input--break-line");
var _TagInput = defineComponent({
  name: "TTagInput",
  props: _objectSpread({}, props),
  setup: function setup(props2, context) {
    var _toRefs = toRefs(props2),
        inputValue = _toRefs.inputValue;

    var _useDefaultValue = useDefaultValue(inputValue, props2.defaultInputValue, props2.onInputChange, "inputValue", "input-change"),
        _useDefaultValue2 = _slicedToArray(_useDefaultValue, 2),
        tInputValue = _useDefaultValue2[0],
        setTInputValue = _useDefaultValue2[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 _useTagScroll = useTagScroll(props2),
        scrollToRight = _useTagScroll.scrollToRight,
        onWheel = _useTagScroll.onWheel,
        scrollToRightOnEnter = _useTagScroll.scrollToRightOnEnter,
        scrollToLeftOnLeave = _useTagScroll.scrollToLeftOnLeave,
        tagInputRef = _useTagScroll.tagInputRef;

    var _useTagList = useTagList(props2),
        tagValue = _useTagList.tagValue,
        onInnerEnter = _useTagList.onInnerEnter,
        onInputBackspaceKeyUp = _useTagList.onInputBackspaceKeyUp,
        clearAll = _useTagList.clearAll,
        renderLabel = _useTagList.renderLabel,
        onClose = _useTagList.onClose;

    var classes = computed(function () {
      return [NAME_CLASS, _defineProperty({}, BREAK_LINE_CLASS, excessTagsDisplayType.value === "break-line")];
    });
    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, context2) {
      setTInputValue("", {
        e: context2.e,
        trigger: "enter"
      });
      onInnerEnter(value, context2);
      nextTick(function () {
        scrollToRight();
      });
    };

    var onClick = function onClick() {
      tagInputRef.value.focus();
    };

    var onClearClick = function onClearClick(ctx) {
      var _props2$onClear;

      clearAll(ctx);
      setTInputValue("", {
        e: ctx.e,
        trigger: "clear"
      });
      (_props2$onClear = props2.onClear) === null || _props2$onClear === void 0 ? void 0 : _props2$onClear.call(props2, ctx);
      context.emit("clear", ctx);
    };

    return {
      tagValue: tagValue,
      tInputValue: tInputValue,
      isHover: isHover,
      tagInputPlaceholder: tagInputPlaceholder,
      showClearIcon: showClearIcon,
      tagInputRef: tagInputRef,
      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,
      classes: classes
    };
  },
  render: function render(h) {
    var _this = this;

    var suffixIconNode = this.showClearIcon ? h(CloseCircleFilledIcon, {
      "class": CLEAR_CLASS,
      "on": {
        "click": this.onClearClick
      }
    }) : renderTNodeJSX(this, "suffixIcon");
    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 h(Input, helper([{
      "ref": "tagInputRef",
      "attrs": {
        "readonly": this.readonly
      }
    }, this.inputProps, {
      "attrs": {
        "value": this.tInputValue,
        "autoWidth": this.autoWidth,
        "size": this.size,
        "disabled": this.disabled,
        "label": function label() {
          return _this.renderLabel({
            displayNode: displayNode,
            label: _label
          }, h);
        },
        "tips": this.tips,
        "status": this.status,
        "placeholder": this.tagInputPlaceholder,
        "suffix": this.suffix,
        "suffixIcon": function suffixIcon() {
          return suffixIconNode;
        }
      },
      "on": {
        "change": function change(val, context) {
          _this.setTInputValue(val, _objectSpread(_objectSpread({}, context), {}, {
            trigger: "input"
          }));
        },
        "mousewheel": this.onWheel,
        "enter": this.onInputEnter,
        "keyup": this.onInputBackspaceKeyUp,
        "mouseenter": function mouseenter(context) {
          _this.addHover(context);

          _this.scrollToRightOnEnter();
        },
        "mouseleave": function mouseleave(context) {
          _this.cancelHover(context);

          _this.scrollToLeftOnLeave();
        },
        "focus": function focus(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
          });

          _this.$emit("focus", _this.tagValue, {
            e: context.e,
            inputValue: inputValue
          });
        },
        "blur": function blur(inputValue, context) {
          var _this$onBlur;

          (_this$onBlur = _this.onBlur) === null || _this$onBlur === void 0 ? void 0 : _this$onBlur.call(_this, _this.tagValue, {
            e: context.e,
            inputValue: inputValue
          });

          _this.$emit("blur", _this.tagValue, {
            e: context.e,
            inputValue: inputValue
          });
        },
        "paste": function paste(context) {
          var _this$onPaste;

          (_this$onPaste = _this.onPaste) === null || _this$onPaste === void 0 ? void 0 : _this$onPaste.call(_this, context);

          _this.$emit("paste", context);
        }
      },
      "class": this.classes
    }]));
  }
});

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