import React, { useState } from 'react';
import { AvatarWrap } from "./AvatarWrap";
import redError from "../../../styles/assets/icon/redError.svg";
import { jsx as _jsx } from "react/jsx-runtime";
const Avatar = ({
  imgSrc,
  onClick,
  fallback: _fallback = redError,
  size: _size = 'default',
  borderless: _borderless = false
}) => {
  const [imageLoadedError, setImageLoadedError] = useState(false);
  let sizeNumber = 40;
  if (typeof _size === 'string') {
    if (parseInt(_size, 10).toString() === _size) {
      sizeNumber = parseInt(_size, 10);
    } else {
      switch (_size) {
        case 'default':
          sizeNumber = 40;
          break;
        case 'large':
          sizeNumber = 64;
          break;
        case 'small':
          sizeNumber = 32;
          break;
        default:
          sizeNumber = 40;
          break;
      }
    }
  } else {
    sizeNumber = _size;
  }
  return /*#__PURE__*/_jsx(AvatarWrap, {
    size: sizeNumber,
    borderless: _borderless,
    children: /*#__PURE__*/_jsx("div", {
      className: "avatarContainer",
      onClick: e => {
        e.stopPropagation();
        onClick === null || onClick === void 0 ? void 0 : onClick();
      },
      children: /*#__PURE__*/_jsx("img", {
        className: "avatar",
        src: imageLoadedError ? _fallback : imgSrc,
        onError: () => {
          setImageLoadedError(true);
        }
      })
    })
  });
};
export default Avatar;