/* index.tsx generated by @compiled/babel-plugin v0.40.0 */
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import "./index.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
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) { _defineProperty(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; }
import { useMemo } from 'react';
import { useIntl } from 'react-intl';
import AtlaskitAvatarGroup from '@atlaskit/avatar-group';
import { ElementName } from '../../../../../../constants';
import { messages } from '../../../../../../messages';
import { getFormattedMessageAsString } from '../../../utils';
var styles = null;
var getPersonNameWithPrefix = function getPersonNameWithPrefix(elementName, personName, intl) {
  switch (elementName) {
    case ElementName.AssignedToGroup:
      return getFormattedMessageAsString(intl, messages.assigned_to, personName);
    case ElementName.OwnedByGroup:
      return getFormattedMessageAsString(intl, messages.owned_by, personName);
    case ElementName.AuthorGroup:
      return getFormattedMessageAsString(intl, 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 = useIntl();
  var data = useMemo(function () {
    if (!items.length && showFallbackAvatar) {
      switch (name) {
        case ElementName.AssignedToGroup:
          return [{
            name: getFormattedMessageAsString(intl, 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: ax(["_1ul91ns9 _1e0c116y _1kvxu2gc _102oidpf", className])
  }, /*#__PURE__*/React.createElement(AtlaskitAvatarGroup, {
    maxCount: maxCount,
    appearance: "stack",
    size: "small",
    data: data,
    testId: testId
  }));
};
export default BaseAvatarGroup;
export var toAvatarGroupProps = function toAvatarGroupProps(items, showFallbackAvatar) {
  return items ? {
    items: items
  } : showFallbackAvatar ? {
    items: []
  } : undefined;
};