"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ProfileImagePlaceholder = void 0;
var _react = _interopRequireWildcard(require("react"));
var _icons = require("../../assets/icons");
var _StyledComponents = require("../styled/StyledComponents");
var _hashcolor = require("../../helpers/hashcolor");
var _jsxRuntime = require("react/jsx-runtime");
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 ProfileImagePlaceholder = ({
  name,
  icon,
  click,
  size = 64,
  upload,
  remove,
  role,
  active = false,
  placeholderIcon,
  disableOverlay
}) => {
  const backgroundColor = (0, _react.useMemo)(() => {
    if (!name) {
      return {
        backgroundColor: 'transparent'
      };
    }
    return (0, _hashcolor.nameToColor)(name);
  }, [name]);
  const getTwoUppercaseLetters = fullName => {
    if (!fullName) {
      return '';
    }
    const words = fullName.trim().split(' ').filter(word => word.length > 0);
    if (words.length === 0) {
      return '';
    }
    if (words.length >= 2) {
      const firstLetter = /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[0]?.[0] || '') ? words[0][0].toUpperCase() : '';
      const secondLetter = /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[1]?.[0] || '') ? words[1][0].toUpperCase() : '';
      return firstLetter + secondLetter;
    }
    if (words.length === 1 && words[0].length >= 2) {
      const firstLetter = /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[0][0] || '') ? words[0][0].toUpperCase() : '';
      const secondLetter = /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[0][1] || '') ? words[0][1].toUpperCase() : '';
      return firstLetter + secondLetter;
    }
    if (words.length === 1 && words[0].length === 1) {
      return /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[0][0] || '') ? words[0][0].toUpperCase() : '';
    }
    return '';
  };
  const getInitials = () => !icon && name ? getTwoUppercaseLetters(name) : '';
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StyledComponents.Wrapper, {
    bgColor: icon ? 'transparent' : backgroundColor?.backgroundColor,
    size: size,
    isClickable: active || !!upload?.active,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_StyledComponents.AvatarCircle, {
      bgColor: icon ? 'transparent' : backgroundColor?.backgroundColor,
      size: size,
      isClickable: active || !!upload?.active,
      onPress: upload?.active ? upload.onUpload : click?.isClick ? click.onPress : undefined,
      children: [icon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.AvatarImage, {
        source: typeof icon === 'string' ? {
          uri: icon
        } : icon,
        size: size
      }) : placeholderIcon ? placeholderIcon :
      /*#__PURE__*/
      // Black initials on the pastel hash-color bg — white text
      // on these light backgrounds is unreadable (matches web's
      // default-color behavior).
      (0, _jsxRuntime.jsx)(_StyledComponents.InitialsText, {
        size: size,
        color: "#141414",
        children: getInitials()
      }), upload?.active && !disableOverlay && /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.Overlay, {
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.EditIcon, {
          style: {
            fontSize: size / 2
          },
          color: "#141414"
        })
      })]
    }), remove?.enabled && icon && role !== 'participant' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.RemoveButton, {
      onPress: remove.onRemoveClick,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.RemoveButtonText, {
        children: "\xD7"
      })
    })]
  });
};
exports.ProfileImagePlaceholder = ProfileImagePlaceholder;
//# sourceMappingURL=ProfileImagePlaceholder.js.map