/**
 * 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 _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var VueCompositionAPI = require('@vue/composition-api');
var isObject = require('lodash/isObject');
var tagInput_index = require('../tag-input/index.js');
var loading_index = require('../loading/index.js');
var hooks_useDefaultValue = require('../hooks/useDefaultValue.js');
var hooks_useConfig = require('../hooks/useConfig.js');
require('../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../tag-input/tag-input.js');
require('@ldesign/icons-vue');
require('../input/index.js');
require('../utils/map-props.js');
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('../utils/render-tnode.js');
require('../_common/js/log/log.js');
require('../input/props.js');
require('../input/input-group.js');
require('../hooks/useGlobalIcon.js');
require('../config-provider/useConfig.js');
require('../tag-input/props.js');
require('../tag-input/hooks/useTagScroll.js');
require('lodash/isFunction');
require('../tag-input/useTagList.js');
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('../tag-input/hooks/useHover.js');
require('../tag-input/hooks/useDragSorter.js');
require('../loading/directive.js');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../loading/plugin.js');
require('../config.js');
require('../utils/dom.js');
require('raf');
require('../utils/easing.js');
require('../loading/loading.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');

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

var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);

var _excluded = ["tips"];
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 DEFAULT_KEYS = {
  label: "label",
  value: "value",
  children: "children"
};
function useMultiple(props, context) {
  var _toRefs = VueCompositionAPI.toRefs(props),
    inputValue = _toRefs.inputValue;
  var classPrefix = hooks_useConfig.usePrefixClass();
  var tagInputRef = VueCompositionAPI.ref();
  var _useDefaultValue = hooks_useDefaultValue["default"](inputValue, props.defaultInputValue, props.onInputChange, "inputValue", "input-change"),
    _useDefaultValue2 = _slicedToArray__default["default"](_useDefaultValue, 2),
    tInputValue = _useDefaultValue2[0],
    setTInputValue = _useDefaultValue2[1];
  var iKeys = VueCompositionAPI.computed(function () {
    return _objectSpread(_objectSpread({}, DEFAULT_KEYS), props.keys);
  });
  var tags = VueCompositionAPI.computed(function () {
    if (!Array.isArray(props.value)) return isObject__default["default"](props.value) ? [props.value[iKeys.value.label]] : [props.value];
    return props.value.map(function (item) {
      return isObject__default["default"](item) ? item[iKeys.value.label] : item;
    });
  });
  var tPlaceholder = VueCompositionAPI.computed(function () {
    return !tags.value || !tags.value.length ? props.placeholder : "";
  });
  var onTagInputChange = function onTagInputChange(val, ctx) {
    var _ctx$e, _props$onTagChange;
    if (ctx.trigger === "tag-remove") (_ctx$e = ctx.e) === null || _ctx$e === void 0 ? void 0 : _ctx$e.stopPropagation();
    (_props$onTagChange = props.onTagChange) === null || _props$onTagChange === void 0 ? void 0 : _props$onTagChange.call(props, val, ctx);
    context.emit("tag-change", val, ctx);
  };
  var renderSelectMultiple = function renderSelectMultiple(p, h) {
    var tagInputProps = _objectSpread(_objectSpread({}, p.commonInputProps), {}, {
      tagProps: props.tagProps,
      label: props.label,
      autoWidth: props.autoWidth,
      readonly: props.readonly,
      placeholder: tPlaceholder.value,
      minCollapsedNum: props.minCollapsedNum,
      collapsedItems: props.collapsedItems,
      tag: props.tag,
      valueDisplay: props.valueDisplay,
      value: tags.value,
      inputValue: tInputValue.value || "",
      inputProps: _objectSpread({
        readonly: !props.allowInput || props.readonly,
        inputClass: _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-input--focused"), p.popupVisible)
      }, props.inputProps),
      suffixIcon: !props.disabled && props.loading ? function () {
        return h(loading_index.Loading, {
          "attrs": {
            "loading": true,
            "size": "small"
          }
        });
      } : props.suffixIcon
    }, props.tagInputProps);
    var _context$slots = context.slots;
      _context$slots.tips;
      var slots = _objectWithoutProperties__default["default"](_context$slots, _excluded);
    var newListeners = _objectSpread({}, context.listeners);
    delete newListeners.blur;
    return h(tagInput_index.TagInput, helper.helper([{
      "ref": "tagInputRef",
      "scopedSlots": slots
    }, {
      "props": tagInputProps
    }, {}, {
      "on": _objectSpread(_objectSpread({
        "input-change": function inputChange(val, ctx) {
          if (ctx.trigger === "enter" || ctx.trigger === "blur") return;
          setTInputValue(val, {
            trigger: ctx.trigger,
            e: ctx.e
          });
        }
      }, newListeners), {}, {
        "change": onTagInputChange,
        "clear": p.onInnerClear,
        "focus": function focus(val, ctx) {
          var _props$onFocus;
          var params = _objectSpread(_objectSpread({}, ctx), {}, {
            tagInputValue: val
          });
          (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, props.value, params);
          context.emit("focus", props.value, params);
        },
        "enter": function enter(val, ctx) {
          var _props$onEnter;
          var params = _objectSpread(_objectSpread({}, ctx), {}, {
            tagInputValue: val
          });
          (_props$onEnter = props.onEnter) === null || _props$onEnter === void 0 ? void 0 : _props$onEnter.call(props, props.value, params);
          context.emit("focus", props.value, params);
        }
      })
    }]));
  };
  return {
    tags: tags,
    tPlaceholder: tPlaceholder,
    tagInputRef: tagInputRef,
    multipleInputValue: tInputValue,
    renderSelectMultiple: renderSelectMultiple
  };
}

exports["default"] = useMultiple;
//# sourceMappingURL=useMultiple.js.map
