"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.useAvatarBadgeStyle = exports.avatarStyle = exports.avatarSizes = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _ThemeProvider = require("../ThemeProvider");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

// Found this on StackOverflow :)
function string2Hex(str) {
  var hash = 0;
  if (str.length === 0) return hash;

  for (var i = 0; i < str.length; i++) {
    hash = str.charCodeAt(i) + ((hash << 5) - hash);
    hash = hash & hash;
  }

  var color = '#';

  for (var j = 0; j < 3; j++) {
    var value = hash >> j * 8 & 255;
    color += ('00' + value.toString(16)).substr(-2);
  }

  return color;
}

var avatarSizes = {
  '2xs': 4,
  xs: 6,
  sm: 8,
  md: 12,
  lg: 16,
  xl: 24,
  '2xl': 32,
  full: 'full'
};
exports.avatarSizes = avatarSizes;

var avatarStyle = function avatarStyle(_ref, theme) {
  var size = _ref.size,
      showBorder = _ref.showBorder,
      name = _ref.name;
  return {
    style: _objectSpread(_objectSpread({
      display: 'inline-flex',
      verticalAlign: 'top',
      rounded: 'full',
      alignItems: 'center',
      flexShrink: '0',
      justifyContent: 'center',
      position: 'relative',
      bg: name ? string2Hex(name) : 'gray.400',
      size: avatarSizes[size]
    }, showBorder && {
      border: '2px',
      borderColor: 'white'
    }), {}, {
      fontSize: "calc(".concat(theme.sizes[avatarSizes[size]], " / 2.5)") // lineHeight: avatarSizes[size],

    })
  };
};

exports.avatarStyle = avatarStyle;

var useAvatarStyle = function useAvatarStyle(props) {
  var theme = (0, _ThemeProvider.useTheme)();
  var styles = theme['styles'].avatar ? theme['styles'].avatar(props, theme) : avatarStyle(props, theme);
  return styles.style;
};

var useAvatarBadgeStyle = function useAvatarBadgeStyle(_ref2) {
  var _ref2$color = _ref2.color,
      color = _ref2$color === void 0 ? 'success' : _ref2$color,
      _ref2$borderColor = _ref2.borderColor,
      borderColor = _ref2$borderColor === void 0 ? 'pageBg' : _ref2$borderColor;
  return {
    position: 'absolute',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    transform: 'translate(25%, 25%)',
    bottom: '0',
    right: '0',
    border: '0.2em solid',
    borderColor: borderColor,
    bg: "".concat(color, ".500"),
    rounded: 'full'
  }; // const borderColor = { light: 'white', dark: 'gray.800' };
};

exports.useAvatarBadgeStyle = useAvatarBadgeStyle;
var _default = useAvatarStyle;
exports["default"] = _default;
//# sourceMappingURL=styles.js.map