/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { prefix } from '../config.js';
import props from './avatar-group-props.js';
import _Avatar from './avatar.js';
import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js';
import '../utils/classnames.js';
import './props.js';
import '@babel/runtime/helpers/typeof';
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 = "".concat(prefix, "-avatar-group");
var _AvatarGroup = Vue.extend({
  name: "TAvatarGroup",
  components: {
    Avatar: _Avatar
  },
  props: _objectSpread({}, props),
  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, {
          "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 = renderContent(this, "collapseAvatar", "content");
        }
      } else {
        content = "+".concat(children.length - this.max);
      }

      return content;
    },
    isIcon: function isIcon() {
      var content = renderTNodeJSX(this, "collapseAvatar");
      return (content === null || content === void 0 ? void 0 : content.context) instanceof Vue;
    }
  },
  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(name), (_ref = {}, _defineProperty(_ref, "".concat(prefix, "-avatar--offset-right"), cascading === "right-up"), _defineProperty(_ref, "".concat(prefix, "-avatar--offset-left"), cascading === "left-up"), _ref)];
    var content = [children];

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

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

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