"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _constants = require("../../../../../constants");
var _messages = require("../../../../../messages");
var _flexibleUiContext = require("../../../../../state/flexible-ui-context");
var _common = require("../common");
var UserAttributesElement = function UserAttributesElement(props) {
  var context = (0, _flexibleUiContext.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 = (0, _common.toFormattedTextProps)(_messages.messages.user_attributes, userAttributes[key]);
        if (data) {
          attributes.push( /*#__PURE__*/_react.default.createElement(_common.BaseTextElement, (0, _extends2.default)({
            key: key
          }, data, {
            testId: "smart-element-text-".concat(key)
          }, props, {
            name: _constants.ElementName.UserAttributes
          })));
        }
      }
    });
    return attributes.length > 0 ? attributes : null;
  };
  var elements = context ? renderUserAttributes(context.userAttributes) : null;
  return elements ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, elements) : null;
};
var _default = exports.default = UserAttributesElement;