"use strict";

import React, { useMemo } from 'react';
import { EditIcon } from '../../assets/icons';
import { AvatarCircle, AvatarImage, InitialsText, Overlay, RemoveButton, RemoveButtonText, Wrapper } from '../styled/StyledComponents';
import { nameToColor } from '../../helpers/hashcolor';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export const ProfileImagePlaceholder = ({
  name,
  icon,
  click,
  size = 64,
  upload,
  remove,
  role,
  active = false,
  placeholderIcon,
  disableOverlay
}) => {
  const backgroundColor = useMemo(() => {
    if (!name) {
      return {
        backgroundColor: 'transparent'
      };
    }
    return 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__*/_jsxs(Wrapper, {
    bgColor: icon ? 'transparent' : backgroundColor?.backgroundColor,
    size: size,
    isClickable: active || !!upload?.active,
    children: [/*#__PURE__*/_jsxs(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__*/_jsx(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).
      _jsx(InitialsText, {
        size: size,
        color: "#141414",
        children: getInitials()
      }), upload?.active && !disableOverlay && /*#__PURE__*/_jsx(Overlay, {
        children: /*#__PURE__*/_jsx(EditIcon, {
          style: {
            fontSize: size / 2
          },
          color: "#141414"
        })
      })]
    }), remove?.enabled && icon && role !== 'participant' && /*#__PURE__*/_jsx(RemoveButton, {
      onPress: remove.onRemoveClick,
      children: /*#__PURE__*/_jsx(RemoveButtonText, {
        children: "\xD7"
      })
    })]
  });
};
//# sourceMappingURL=ProfileImagePlaceholder.js.map