"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _AvatarWrap = require("./AvatarWrap");
var _redError = _interopRequireDefault(require("../../../styles/assets/icon/redError.svg"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const Avatar = ({
  imgSrc,
  onClick,
  fallback: _fallback = _redError.default,
  size: _size = 'default',
  borderless: _borderless = false
}) => {
  const [imageLoadedError, setImageLoadedError] = (0, _react.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__*/(0, _jsxRuntime.jsx)(_AvatarWrap.AvatarWrap, {
    size: sizeNumber,
    borderless: _borderless,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: "avatarContainer",
      onClick: e => {
        e.stopPropagation();
        onClick === null || onClick === void 0 ? void 0 : onClick();
      },
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
        className: "avatar",
        src: imageLoadedError ? _fallback : imgSrc,
        onError: () => {
          setImageLoadedError(true);
        }
      })
    })
  });
};
var _default = Avatar;
exports.default = _default;