/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toAvatarGroupProps = exports.default = void 0;
require("./index.compiled.css");
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _runtime = require("@compiled/react/runtime");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _reactIntlNext = require("react-intl-next");
var _avatarGroup = _interopRequireDefault(require("@atlaskit/avatar-group"));
var _constants = require("../../../../../../constants");
var _messages = require("../../../../../../messages");
var _utils = require("../../../utils");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var styles = null;
var getPersonNameWithPrefix = function getPersonNameWithPrefix(elementName, personName, intl) {
  switch (elementName) {
    case _constants.ElementName.AssignedToGroup:
      return (0, _utils.getFormattedMessageAsString)(intl, _messages.messages.assigned_to, personName);
    case _constants.ElementName.OwnedByGroup:
      return (0, _utils.getFormattedMessageAsString)(intl, _messages.messages.owned_by, personName);
    case _constants.ElementName.AuthorGroup:
      return (0, _utils.getFormattedMessageAsString)(intl, _messages.messages.created_by, personName);
    default:
      return personName;
  }
};
/**
 * A base element that displays a group of avatars.
 * @internal
 * @param {BaseAvatarGroupElementProps} BaseAvatarGroupElementProps - The props necessary for the AvatarGroup.
 * @see AuthorGroup
 * @see CollaboratorGroup
 */
var BaseAvatarGroup = function BaseAvatarGroup(_ref) {
  var _ref$items = _ref.items,
    items = _ref$items === void 0 ? [] : _ref$items,
    _ref$maxCount = _ref.maxCount,
    maxCount = _ref$maxCount === void 0 ? 4 : _ref$maxCount,
    name = _ref.name,
    className = _ref.className,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-element-avatar-group' : _ref$testId,
    _ref$showNamePrefix = _ref.showNamePrefix,
    showNamePrefix = _ref$showNamePrefix === void 0 ? false : _ref$showNamePrefix,
    _ref$showFallbackAvat = _ref.showFallbackAvatar,
    showFallbackAvatar = _ref$showFallbackAvat === void 0 ? true : _ref$showFallbackAvat;
  var intl = (0, _reactIntlNext.useIntl)();
  var data = (0, _react.useMemo)(function () {
    if (!items.length && showFallbackAvatar) {
      switch (name) {
        case _constants.ElementName.AssignedToGroup:
          return [{
            name: (0, _utils.getFormattedMessageAsString)(intl, _messages.messages.unassigned)
          }];
        default:
          return [];
      }
    }

    //show a name prefix if there is one Avatar in a group only
    if (name && items.length === 1 && showNamePrefix) {
      return items.map(function (person) {
        return _objectSpread(_objectSpread({}, person), {}, {
          name: getPersonNameWithPrefix(name, person.name, intl) || person.name
        });
      });
    }
    return items;
  }, [name, items, showNamePrefix, showFallbackAvatar, intl]);
  if (!data.length) {
    return null;
  }
  return /*#__PURE__*/React.createElement("span", {
    "data-separator": true,
    "data-smart-element": name,
    "data-smart-element-avatar-group": true,
    "data-testid": testId
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
    ,
    className: (0, _runtime.ax)(["_1ul91ns9 _1e0c116y _1kvxu2gc _102oidpf", className])
  }, /*#__PURE__*/React.createElement(_avatarGroup.default, {
    maxCount: maxCount,
    appearance: "stack",
    size: "small",
    data: data,
    testId: testId
  }));
};
var _default = exports.default = BaseAvatarGroup;
var toAvatarGroupProps = exports.toAvatarGroupProps = function toAvatarGroupProps(items, showFallbackAvatar) {
  return items ? {
    items: items
  } : showFallbackAvatar ? {
    items: []
  } : undefined;
};