import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
var _excluded = ["size", "border", "spaced", "imgSrc", "className", "link", "ariaLinkLabel", "alt"];

var _ICON_SIZE;

import * as React from 'react';
import classNames from 'classnames';
import Icon, { ICON_COLOR } from '../icons/Icon';
import { __DEV__, invariant } from '../utils';
export var SIZE = {
  XS: 'xs',
  S: 's',
  M: 'm',
  L: 'l',
  XL: 'xl',
  XXL: 'xxl'
};
export var ICON_SIZE = (_ICON_SIZE = {}, _defineProperty(_ICON_SIZE, SIZE.XS, 24), _defineProperty(_ICON_SIZE, SIZE.S, 32), _defineProperty(_ICON_SIZE, SIZE.M, 40), _defineProperty(_ICON_SIZE, SIZE.L, 56), _defineProperty(_ICON_SIZE, SIZE.XL, 80), _defineProperty(_ICON_SIZE, SIZE.XXL, 104), _ICON_SIZE);

var Avatar = function Avatar(_ref) {
  var _classNames;

  var _ref$size = _ref.size,
      size = _ref$size === void 0 ? SIZE.S : _ref$size,
      _ref$border = _ref.border,
      border = _ref$border === void 0 ? false : _ref$border,
      spaced = _ref.spaced,
      imgSrc = _ref.imgSrc,
      className = _ref.className,
      link = _ref.link,
      ariaLinkLabel = _ref.ariaLinkLabel,
      _ref$alt = _ref.alt,
      alt = _ref$alt === void 0 ? '' : _ref$alt,
      props = _objectWithoutProperties(_ref, _excluded);

  var avatarClass = classNames('sg-avatar', (_classNames = {}, _defineProperty(_classNames, "sg-avatar--".concat(size), size !== SIZE.S), _defineProperty(_classNames, 'sg-avatar--with-border', border), _classNames), className);
  var isImgSrcDefined = imgSrc !== undefined && imgSrc !== null && imgSrc !== '';
  var imageClass = classNames('sg-avatar__image', {
    'sg-avatar--spaced': spaced,
    'sg-avatar__image--icon': !isImgSrcDefined
  });

  if (__DEV__) {
    invariant(!(ariaLinkLabel && !link), 'Using `ariaLinkLabel` prop has no effect when `link` prop is not set.');
    invariant(!(alt && !isImgSrcDefined), 'Using `alt` prop has no effect when `imgSrc` prop is not set.');
  }

  var avatarContent = /*#__PURE__*/React.createElement("div", _extends({}, props, {
    className: avatarClass
  }), isImgSrcDefined ? /*#__PURE__*/React.createElement("img", {
    className: imageClass,
    src: imgSrc,
    alt: alt
  }) : /*#__PURE__*/React.createElement("div", {
    className: imageClass
  }, /*#__PURE__*/React.createElement(Icon, {
    className: "sg-avatar__icon",
    type: "profile",
    color: ICON_COLOR['icon-gray-40'],
    size: ICON_SIZE[size],
    "aria-hidden": "true"
  })));

  if (link !== undefined && link !== '') {
    return /*#__PURE__*/React.createElement("a", {
      href: link,
      "aria-label": ariaLinkLabel,
      className: "sg-avatar__wrapper-link"
    }, avatarContent);
  }

  return avatarContent;
};

export default Avatar;