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';
var UserAttributesElement = function UserAttributesElement(props) {
  var context = useFlexibleUiContext();
  var renderUserAttributes = function renderUserAttributes(userAttributes) {
    if (!userAttributes) {
      return null;
    }
    var attributeKeys = ['pronouns', 'role', 'department', 'location'];
    var attributes = [];
    attributeKeys.forEach(function (key) {
      if (userAttributes[key]) {
        var data = toFormattedTextProps(messages.user_attributes, userAttributes[key]);
        if (data) {
          attributes.push( /*#__PURE__*/React.createElement(BaseTextElement, _extends({
            key: key
          }, data, {
            testId: "smart-element-text-".concat(key)
          }, props, {
            name: ElementName.UserAttributes
          })));
        }
      }
    });
    return attributes.length > 0 ? attributes : null;
  };
  var elements = context ? renderUserAttributes(context.userAttributes) : null;
  return elements ? /*#__PURE__*/React.createElement(React.Fragment, null, elements) : null;
};
export default UserAttributesElement;