/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var Vue = require('vue');
var utils_renderNode = require('../../utils/render-node.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var components_avatar_avatar = require('./avatar.js');
var components_avatar_props = require('./props.js');
require('lodash');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

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

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

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("avatar");
var _AvatarGroup = utils_mixins["default"](classPrefixMixins).extend({
  name: "LAvatarGroup",
  components: {
    LAvatar: components_avatar_avatar["default"]
  },
  props: {
    ...components_avatar_props.AvatarGroupProps
  },
  provide() {
    return {
      avatarGroup: this
    };
  },
  methods: {
    renderEllipsisAvatar(children) {
      const h = this.$createElement;
      if ((children === null || children === void 0 ? void 0 : children.length) > this.max) {
        const content = this.setEllipsisContent(children);
        const outAvatar = children.slice(0, this.max);
        outAvatar.push(h("l-avatar", {
          "attrs": {
            "size": this.size,
            "icon": this.isIcon() ? this.collapseAvatar : null
          }
        }, [content]));
        return [outAvatar];
      }
      return [children];
    },
    setEllipsisContent(children) {
      let content = "";
      if (this.collapseAvatar) {
        if (!this.isIcon()) content = utils_renderNode.renderContent(this, "collapseAvatar", "content");
      } else {
        content = `+${children.length - this.max}`;
      }
      return content;
    },
    isIcon() {
      const content = utils_renderNode.renderLNodeJSX(this, "collapseAvatar");
      return (content === null || content === void 0 ? void 0 : content.context) instanceof Vue__default["default"];
    }
  },
  render() {
    const h = arguments[0];
    const {
      $scopedSlots
    } = this;
    const children = $scopedSlots.default && $scopedSlots.default(null);
    const {
      cascading,
      max
    } = this.$props;
    const groupClass = [`${this.componentName}-group`, {
      [`${this.componentName}--offset-right`]: cascading === "right-up",
      [`${this.componentName}--offset-left`]: cascading === "left-up"
    }];
    let content = [children];
    if (max && max >= 0) content = [this.renderEllipsisAvatar(children)];
    return h("div", {
      "class": groupClass
    }, [content]);
  }
});

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