import _extends from "@babel/runtime/helpers/extends";
import React from 'react';
import { ElementName } from '../../../../../constants';
import { messages } from '../../../../../messages';
import { useFlexibleUiContext } from '../../../../../state/flexible-ui-context';
import { BaseTextElement, toFormattedTextProps } from '../common';
const UserAttributesElement = props => {
  const context = useFlexibleUiContext();
  const renderUserAttributes = userAttributes => {
    if (!userAttributes) {
      return null;
    }
    const attributeKeys = ['pronouns', 'role', 'department', 'location'];
    const attributes = [];
    attributeKeys.forEach(key => {
      if (userAttributes[key]) {
        const data = toFormattedTextProps(messages.user_attributes, userAttributes[key]);
        if (data) {
          attributes.push( /*#__PURE__*/React.createElement(BaseTextElement, _extends({
            key: key
          }, data, {
            testId: `smart-element-text-${key}`
          }, props, {
            name: ElementName.UserAttributes
          })));
        }
      }
    });
    return attributes.length > 0 ? attributes : null;
  };
  const elements = context ? renderUserAttributes(context.userAttributes) : null;
  return elements ? /*#__PURE__*/React.createElement(React.Fragment, null, elements) : null;
};
export default UserAttributesElement;