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

'use strict';

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

var helper = require('../_chunks/dep-c3e1ffac.js');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var input_index = require('../input/index.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var hooks_useDefaultValue = require('../hooks/useDefaultValue.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
var tagInput_props = require('./props.js');
var tagInput_hooks_useTagScroll = require('./hooks/useTagScroll.js');
var tagInput_useTagList = require('./useTagList.js');
var tagInput_hooks_useHover = require('./hooks/useHover.js');
var tagInput_hooks_useDragSorter = require('./hooks/useDragSorter.js');
require('../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('vue');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../input/input.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../_common/js/utils/helper.js');
require('lodash/isString');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('../utils/helper.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/mixins.js');
require('../utils/event.js');
require('../_common/js/log/log.js');
require('../input/props.js');
require('../input/input-group.js');
require('lodash/isFunction');
require('../tag/index.js');
require('../tag/tag.js');
require('../tag/props.js');
require('../tag/check-tag.js');
require('../tag/check-tag-props.js');
require('../hooks/useVModel.js');
require('../hooks/tnode.js');
require('lodash/isEmpty');
require('../hooks/render-tnode.js');
require('lodash/isObject');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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__default["default"](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 _TagInput = VueCompositionAPI.defineComponent({
  name: "TTagInput",
  props: _objectSpread({}, tagInput_props["default"]),
  setup: function setup(props2, context) {
    var _toRefs = VueCompositionAPI.toRefs(props2),
      inputValue = _toRefs.inputValue,
      inputProps = _toRefs.inputProps;
    var isComposition = VueCompositionAPI.ref(false);
    var COMPONENT_NAME = configProvider_useConfig.usePrefixClass("tag-input");
    var classPrefix = configProvider_useConfig.usePrefixClass();
    var _useDefaultValue = hooks_useDefaultValue["default"](inputValue, props2.defaultInputValue, props2.onInputChange, "inputValue", "input-change"),
      _useDefaultValue2 = _slicedToArray__default["default"](_useDefaultValue, 2),
      tInputValue = _useDefaultValue2[0],
      setTInputValue = _useDefaultValue2[1];
    var _toRefs2 = VueCompositionAPI.toRefs(props2),
      excessTagsDisplayType = _toRefs2.excessTagsDisplayType,
      readonly = _toRefs2.readonly,
      disabled = _toRefs2.disabled,
      clearable = _toRefs2.clearable,
      placeholder = _toRefs2.placeholder;
    var _useHover = tagInput_hooks_useHover["default"]({
        readonly: props2.readonly,
        disabled: props2.disabled,
        onMouseenter: props2.onMouseenter,
        onMouseleave: props2.onMouseleave
      }, context),
      isHover = _useHover.isHover,
      addHover = _useHover.addHover,
      cancelHover = _useHover.cancelHover;
    var _useDragSorter = tagInput_hooks_useDragSorter["default"](_objectSpread(_objectSpread({}, props2), {}, {
        sortOnDraggable: props2.dragSort,
        onDragOverCheck: {
          x: true,
          targetClassNameRegExp: new RegExp("^".concat(classPrefix.value, "-tag"))
        }
      }), context),
      getDragProps = _useDragSorter.getDragProps;
    var _useTagScroll = tagInput_hooks_useTagScroll["default"](props2),
      scrollToRight = _useTagScroll.scrollToRight,
      onWheel = _useTagScroll.onWheel,
      scrollToRightOnEnter = _useTagScroll.scrollToRightOnEnter,
      scrollToLeftOnLeave = _useTagScroll.scrollToLeftOnLeave,
      tagInputRef = _useTagScroll.tagInputRef;
    var _useTagList = tagInput_useTagList["default"](props2, context, getDragProps),
      tagValue = _useTagList.tagValue,
      onInnerEnter = _useTagList.onInnerEnter,
      onInputBackspaceKeyUp = _useTagList.onInputBackspaceKeyUp,
      onInputBackspaceKeyDown = _useTagList.onInputBackspaceKeyDown,
      clearAll = _useTagList.clearAll,
      renderLabel = _useTagList.renderLabel,
      onClose = _useTagList.onClose;
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        CloseCircleFilledIcon: iconsVue.CloseCircleFilledIcon
      }),
      CloseCircleFilledIcon = _useGlobalIcon.CloseCircleFilledIcon;
    var classes = VueCompositionAPI.computed(function () {
      var _ref;
      var isEmpty = !(Array.isArray(tagValue.value) && tagValue.value.length);
      return [COMPONENT_NAME.value, (_ref = {}, _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--break-line"), excessTagsDisplayType.value === "break-line"), _defineProperty__default["default"](_ref, "".concat(classPrefix.value, "-is-empty"), isEmpty), _defineProperty__default["default"](_ref, "".concat(classPrefix.value, "-tag-input--with-tag"), !isEmpty), _ref)];
    });
    var tagInputPlaceholder = VueCompositionAPI.computed(function () {
      var _tagValue$value;
      return !((_tagValue$value = tagValue.value) !== null && _tagValue$value !== void 0 && _tagValue$value.length) ? placeholder.value : "";
    });
    var showClearIcon = VueCompositionAPI.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 onInputCompositionstart = function onInputCompositionstart(value, context2) {
      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, context2);
    };
    var onInputCompositionend = function onInputCompositionend(value, context2) {
      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, context2);
    };
    var onInputEnter = function onInputEnter(value, context2) {
      var _context2$e;
      (_context2$e = context2.e) === null || _context2$e === void 0 ? void 0 : _context2$e.preventDefault();
      setTInputValue("", {
        e: context2.e,
        trigger: "enter"
      });
      !isComposition.value && onInnerEnter(value, context2);
      VueCompositionAPI.nextTick(function () {
        scrollToRight();
        isComposition.value = false;
      });
    };
    var onInnerClick = function onInnerClick(params) {
      var _props2$onClick;
      (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, params);
      context.emit("click", params);
    };
    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,
      classPrefix: classPrefix,
      classes: classes,
      componentName: COMPONENT_NAME,
      setTInputValue: setTInputValue,
      addHover: addHover,
      cancelHover: cancelHover,
      onInputEnter: onInputEnter,
      onInnerEnter: onInnerEnter,
      onInputBackspaceKeyUp: onInputBackspaceKeyUp,
      onInputBackspaceKeyDown: onInputBackspaceKeyDown,
      renderLabel: renderLabel,
      onWheel: onWheel,
      scrollToRightOnEnter: scrollToRightOnEnter,
      scrollToLeftOnLeave: scrollToLeftOnLeave,
      onClearClick: onClearClick,
      onInnerClick: onInnerClick,
      onClose: onClose,
      onInputCompositionstart: onInputCompositionstart,
      onInputCompositionend: onInputCompositionend,
      CloseCircleFilledIcon: CloseCircleFilledIcon
    };
  },
  render: function render(h) {
    var _this = this,
      _this$inputProps,
      _this$inputProps2,
      _this$inputProps3,
      _this$tagValue;
    var CloseCircleFilledIcon = this.CloseCircleFilledIcon;
    var suffixIconNode = this.showClearIcon ? h(CloseCircleFilledIcon, {
      "class": "".concat(this.componentName, "__suffix-clear"),
      "on": {
        "click": this.onClearClick
      }
    }) : utils_renderTnode.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 = utils_renderTnode.renderTNodeJSX(this, "valueDisplay", {
      params: {
        value: this.tagValue,
        onClose: function onClose(index, item) {
          return _this.onClose({
            index: index,
            item: item
          });
        }
      }
    });
    var _label = utils_renderTnode.renderTNodeJSX(this, "label", {
      silent: true
    });
    return h(input_index.Input, helper.helper([{
      "ref": "tagInputRef",
      "attrs": {
        "readonly": this.readonly || ((_this$inputProps = this.inputProps) === null || _this$inputProps === void 0 ? void 0 : _this$inputProps.readonly),
        "inputClass": (_this$inputProps2 = this.inputProps) === null || _this$inputProps2 === void 0 ? void 0 : _this$inputProps2.inputClass,
        "value": this.tInputValue,
        "showInput": !((_this$inputProps3 = this.inputProps) !== null && _this$inputProps3 !== void 0 && _this$inputProps3.readonly) || !this.tagValue || !((_this$tagValue = this.tagValue) !== null && _this$tagValue !== void 0 && _this$tagValue.length),
        "keepWrapperWidth": !this.autoWidth,
        "autoWidth": true,
        "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;
        }
      },
      "class": this.classes
    }, {
      "props": this.inputProps
    }, {
      "scopedSlots": this.$scopedSlots
    }, {
      "on": {
        change: function change(val, context) {
          _this.setTInputValue(val, _objectSpread(_objectSpread({}, context), {}, {
            trigger: "input"
          }));
        },
        enter: this.onInputEnter,
        keyup: this.onInputBackspaceKeyUp,
        keydown: this.onInputBackspaceKeyDown,
        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.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: ""
          });
          _this.$emit("blur", _this.tagValue, {
            e: context.e,
            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);
        },
        click: this.onInnerClick,
        compositionstart: this.onInputCompositionstart,
        compositionend: this.onInputCompositionend,
        mousewheel: this.onWheel
      }
    }]));
  }
});

exports["default"] = _TagInput;
//# sourceMappingURL=tag-input.js.map
