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

import { h as helper } from '../_chunks/dep-c89aafbb.js';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { toRefs, ref, computed } from '@vue/composition-api';
import isObject from 'lodash/isObject';
import { TagInput } from '../tag-input/index.js';
import { Loading } from '../loading/index.js';
import useDefaultValue from '../hooks/useDefaultValue.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import '../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../tag-input/tag-input.js';
import '@ldesign/icons-vue';
import '../input/index.js';
import '../utils/map-props.js';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../_common/js/utils/helper.js';
import 'lodash/isString';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../utils/helper.js';
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 '../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../_chunks/dep-67ff4010.js';
import '../config-provider/type.js';
import '../utils/mixins.js';
import '../utils/event.js';
import '../utils/render-tnode.js';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../input/props.js';
import '../input/input-group.js';
import '../input/style/css.js';
import '../input/type.js';
import '../hooks/useGlobalIcon.js';
import '../config-provider/useConfig.js';
import '../tag-input/props.js';
import '../tag-input/hooks/useTagScroll.js';
import 'lodash/isFunction';
import '../tag-input/useTagList.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/style/css.js';
import '../tag/type.js';
import '../hooks/useVModel.js';
import '../hooks/tnode.js';
import 'lodash/isEmpty';
import '../hooks/render-tnode.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../tag-input/style/css.js';
import '../tag-input/type.js';
import '../tag-input/interface.js';
import '../loading/directive.js';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../loading/plugin.js';
import '../config.js';
import '../utils/dom.js';
import 'raf';
import '../utils/easing.js';
import '../loading/loading.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../loading/style/css.js';
import '../loading/type.js';

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(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 = toRefs(props),
    inputValue = _toRefs.inputValue;
  var classPrefix = usePrefixClass();
  var tagInputRef = ref();
  var _useDefaultValue = useDefaultValue(inputValue, props.defaultInputValue, props.onInputChange, "inputValue", "input-change"),
    _useDefaultValue2 = _slicedToArray(_useDefaultValue, 2),
    tInputValue = _useDefaultValue2[0],
    setTInputValue = _useDefaultValue2[1];
  var iKeys = computed(function () {
    return _objectSpread(_objectSpread({}, DEFAULT_KEYS), props.keys);
  });
  var tags = computed(function () {
    if (!Array.isArray(props.value)) return isObject(props.value) ? [props.value[iKeys.value.label]] : [props.value];
    return props.value.map(function (item) {
      return isObject(item) ? item[iKeys.value.label] : item;
    });
  });
  var tPlaceholder = 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({}, "".concat(classPrefix.value, "-input--focused"), p.popupVisible)
      }, props.inputProps),
      suffixIcon: !props.disabled && props.loading ? function () {
        return h(Loading, {
          "attrs": {
            "loading": true,
            "size": "small"
          }
        });
      } : props.suffixIcon
    }, props.tagInputProps);
    var _context$slots = context.slots,
      tips = _context$slots.tips,
      slots = _objectWithoutProperties(_context$slots, _excluded);
    var newListeners = _objectSpread({}, context.listeners);
    delete newListeners.blur;
    return h(TagInput, 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
  };
}

export { useMultiple as default };
//# sourceMappingURL=useMultiple.js.map
