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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var avatar_avatarGroupProps = require('./avatar-group-props.js');
var avatar_avatar = require('./avatar.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.js');
require('./props.js');
require('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');
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');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

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 classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("avatar");
var _AvatarGroup = utils_mixins["default"](classPrefixMixins).extend({
  name: "TAvatarGroup",
  components: {
    Avatar: avatar_avatar["default"]
  },
  props: _objectSpread({}, avatar_avatarGroupProps["default"]),
  provide: function provide() {
    return {
      avatarGroup: this
    };
  },
  methods: {
    renderEllipsisAvatar: function renderEllipsisAvatar(children) {
      var h = this.$createElement;

      if ((children === null || children === void 0 ? void 0 : children.length) > this.max) {
        var content = this.setEllipsisContent(children);
        var outAvatar = children.slice(0, this.max);
        outAvatar.push(h(avatar_avatar["default"], {
          "attrs": {
            "size": this.size,
            "icon": this.isIcon() ? this.collapseAvatar : null
          }
        }, [content]));
        return [outAvatar];
      }

      return [children];
    },
    setEllipsisContent: function setEllipsisContent(children) {
      var content = "";

      if (this.collapseAvatar) {
        if (!this.isIcon()) {
          content = utils_renderTnode.renderContent(this, "collapseAvatar", "content");
        }
      } else {
        content = "+".concat(children.length - this.max);
      }

      return content;
    },
    isIcon: function isIcon() {
      var content = utils_renderTnode.renderTNodeJSX(this, "collapseAvatar");
      return (content === null || content === void 0 ? void 0 : content.context) instanceof Vue__default["default"];
    }
  },
  render: function render() {
    var _ref;

    var h = arguments[0];
    var $scopedSlots = this.$scopedSlots;
    var children = $scopedSlots["default"] && $scopedSlots["default"](null);
    var _this$$props = this.$props,
        cascading = _this$$props.cascading,
        max = _this$$props.max;
    var groupClass = ["".concat(this.componentName, "-group"), (_ref = {}, _defineProperty__default["default"](_ref, "".concat(this.componentName, "--offset-right"), cascading === "right-up"), _defineProperty__default["default"](_ref, "".concat(this.componentName, "--offset-left"), cascading === "left-up"), _ref)];
    var content = [children];

    if (max && max >= 0) {
      content = [this.renderEllipsisAvatar(children)];
    }

    return h("div", {
      "class": groupClass
    }, [content]);
  }
});

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