"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Avatar = void 0;

var _react = _interopRequireDefault(require("react"));

var _native = _interopRequireDefault(require("styled-components/native"));

var _styledSystem = require("styled-system");

var _customProps = require("../../../utils/customProps");

var _primitives = require("../../primitives");

var _theme = require("../../../theme");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

const initials = name => {
  const [firstName, lastName] = name.split(' ');
  return firstName && lastName ? "".concat(firstName.charAt(0)).concat(lastName.charAt(0)) : firstName.charAt(0);
};

const StyledAvatar = (0, _native.default)(_primitives.Box)(_styledSystem.layout, _styledSystem.space, _styledSystem.border, _styledSystem.flex, _customProps.customBorder);

const Avatar = props => {
  const {
    size,
    name,
    style,
    source,
    children,
    ...remainingProps
  } = props;
  const {
    color,
    fontSize,
    fontWeight,
    ...newProps
  } = (0, _theme.usePropsConfig)('Avatar', { ...remainingProps,
    name,
    size
  });
  const textProps = {
    color,
    fontSize,
    fontWeight
  };
  const imageFitStyle = {
    height: '100%',
    width: '100%'
  };
  return /*#__PURE__*/_react.default.createElement(StyledAvatar, _extends({}, newProps, {
    style: style
  }), source ? /*#__PURE__*/_react.default.createElement(_primitives.Image, {
    borderRadius: newProps.borderRadius,
    source: source,
    alt: name ? initials(name) : '--',
    textProps: {
      color,
      fontSize,
      fontWeight
    },
    style: [style, imageFitStyle]
  }) : /*#__PURE__*/_react.default.createElement(_primitives.Text, textProps, name ? initials(name) : '--'), children);
};

exports.Avatar = Avatar;
//# sourceMappingURL=Avatar.js.map