"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Avatar = void 0;
var _react = _interopRequireWildcard(require("react"));
var _native = _interopRequireDefault(require("styled-components/native"));
var _hashcolor = require("../../helpers/hashcolor");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const AvatarCircle = _native.default.View`
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background-color: ${({
  bgColor
}) => bgColor};
  align-items: center;
  justify-content: center;
  shadow-color: rgba(0, 0, 0, 0.2);
  shadow-offset: 0px 4px;
  shadow-opacity: 0.2;
  shadow-radius: 4px;
  elevation: 4;
`;
const AvatarText = _native.default.Text`
  font-size: 16px;
  font-weight: bold;
  // Pastel backgrounds from nameToColor() are all light (#E2F4FB,
  // #EEE6F9, #F5F2BC, ...). White text on light = invisible — web
  // uses default-black text on the same palette. Match it.
  color: #141414;
`;
const Avatar = ({
  username,
  firstName,
  lastName,
  style
}) => {
  const backgroundColor = (0, _react.useMemo)(() => {
    if (!username && !firstName) {
      return {
        backgroundColor: 'transparent'
      };
    }
    return (0, _hashcolor.nameToColor)(username ? username : firstName || '');
  }, [username, firstName]);
  const getInitials = () => {
    const isAlphabetic = char => /^[a-zA-Zа-яА-ЯёЁ]$/.test(char);
    if (firstName && lastName) {
      const firstInitial = isAlphabetic(firstName[0]) ? firstName[0].toUpperCase() : '';
      const lastInitial = isAlphabetic(lastName[0]) ? lastName[0].toUpperCase() : '';
      return `${firstInitial}${lastInitial}`;
    } else if (username) {
      const names = username.split(' ');
      if (names.length > 1) {
        const firstInitial = isAlphabetic(names[0][0]) ? names[0][0].toUpperCase() : '';
        const secondInitial = isAlphabetic(names[1][0]) ? names[1][0].toUpperCase() : '';
        return `${firstInitial}${secondInitial}`;
      } else {
        const singleInitial = isAlphabetic(names[0][0]) ? names[0][0].toUpperCase() : '';
        return `${singleInitial}`;
      }
    }
    return '??';
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(AvatarCircle, {
    style: style,
    bgColor: backgroundColor?.backgroundColor,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AvatarText, {
      children: getInitials()
    })
  });
};
exports.Avatar = Avatar;
//# sourceMappingURL=Avatar.js.map