"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Avatar = void 0;
var _react = _interopRequireDefault(require("react"));
var _uniqolor3 = _interopRequireDefault(require("uniqolor"));
require("../styles/avatar.css");
var Avatar = function Avatar(_ref) {
  var source = _ref.source,
    name = _ref.name,
    size = _ref.size,
    hash = _ref.hash;
  if (source) {
    return /*#__PURE__*/_react.default.createElement("img", {
      className: "avatar",
      style: {
        width: size,
        height: size
      },
      src: source,
      title: name
    });
  } else {
    if (name) {
      var backgroundColor = (0, _uniqolor3.default)(name, {
        saturation: 90,
        lightness: [80, 90]
      });
      var _uniqolor = (0, _uniqolor3.default)(name),
        color = _uniqolor.color;
      var initials = name.match(/\b\w/g) || [];
      initials = ((initials.shift() || '') + (initials.pop() || '')).toUpperCase();
    } else {
      var initials = '?';
      if (hash) {
        var backgroundColor = (0, _uniqolor3.default)(hash, {
          saturation: 90,
          lightness: [80, 90]
        });
        var _uniqolor2 = (0, _uniqolor3.default)(hash),
          color = _uniqolor2.color;
      } else {
        var backgroundColor = _uniqolor3.default.random({
          saturation: 90,
          lightness: [80, 90]
        });
        var _uniqolor$random = _uniqolor3.default.random(),
          color = _uniqolor$random.color;
      }
    }
    return /*#__PURE__*/_react.default.createElement("div", {
      className: "avatar",
      style: {
        width: size,
        height: size,
        backgroundColor: backgroundColor.color
      },
      src: source,
      title: name || 'Anonymous'
    }, /*#__PURE__*/_react.default.createElement("label", {
      className: "initials",
      style: {
        color: color
      }
    }, initials));
  }
};
exports.Avatar = Avatar;