/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import "./index.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { useMemo } from 'react';
import { useIntl } from 'react-intl-next';
import AtlaskitAvatarGroup from '@atlaskit/avatar-group';
import { ElementName } from '../../../../../../constants';
import { messages } from '../../../../../../messages';
import { getFormattedMessageAsString } from '../../../utils';
const styles = null;
const 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
 */
const BaseAvatarGroup = ({
  items = [],
  maxCount = 4,
  name,
  className,
  testId = 'smart-element-avatar-group',
  showNamePrefix = false,
  showFallbackAvatar = true
}) => {
  const intl = useIntl();
  const data = useMemo(() => {
    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(person => {
        return {
          ...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 const toAvatarGroupProps = (items, showFallbackAvatar) => {
  return items ? {
    items
  } : showFallbackAvatar ? {
    items: []
  } : undefined;
};