"use strict";

exports.__esModule = true;
exports.default = exports.ICON_PADDING = exports.ICON_LUMINOSITY = exports.DEFAULT_WRAPPER_SIZE = exports.DEFAULT_PRESET = exports.DEFAULT_ICON_COLOR = void 0;
exports.getForegroundColor = getForegroundColor;
exports.propTypes = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _reactFontawesome = require("@fortawesome/react-fontawesome");
var _proSolidSvgIcons = require("@fortawesome/pro-solid-svg-icons");
var _fontawesomeSvgCore = require("@fortawesome/fontawesome-svg-core");
var _toLower = _interopRequireDefault(require("lodash/fp/toLower"));
var _merge = _interopRequireDefault(require("lodash/fp/merge"));
var _getOr = _interopRequireDefault(require("lodash/fp/getOr"));
var _cssColorFunction = require("css-color-function");
var _getBackgroundGradientColor = require("../../util/get-background-gradient-color");
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
_fontawesomeSvgCore.library.add(_proSolidSvgIcons.fas);
const DEFAULT_PRESET = exports.DEFAULT_PRESET = 'm';
const ICON_LUMINOSITY = exports.ICON_LUMINOSITY = 32;
const DEFAULT_WRAPPER_SIZE = exports.DEFAULT_WRAPPER_SIZE = 40;
const ICON_PADDING = exports.ICON_PADDING = 8;
const DEFAULT_ICON_COLOR = exports.DEFAULT_ICON_COLOR = 'hsl(0, 0%, 32%)';
function getForegroundColor(backgroundColor) {
  return (0, _cssColorFunction.convert)(`color(${backgroundColor} lightness(${ICON_LUMINOSITY}%))`);
}
const SIZE_CONFIGS = {
  s: {
    faSize: 12,
    wrapperSize: 32
  },
  m: {
    faSize: 16,
    wrapperSize: DEFAULT_WRAPPER_SIZE
  },
  xl: {
    faSize: 20,
    wrapperSize: 48
  }
};
const Icon = ({
  iconName,
  iconColor,
  backgroundColor,
  gradientBackground,
  borderRadius,
  preset = DEFAULT_PRESET,
  size,
  customStyle
}) => {
  const effectiveIconColor = iconColor || (backgroundColor ? getForegroundColor(backgroundColor) : DEFAULT_ICON_COLOR);
  const effectiveSize = size ? (0, _merge.default)(SIZE_CONFIGS[DEFAULT_PRESET], size) : (0, _getOr.default)(SIZE_CONFIGS[DEFAULT_PRESET], (0, _toLower.default)(preset), SIZE_CONFIGS);
  const hasBackground = backgroundColor || gradientBackground;
  if (!hasBackground) {
    return /*#__PURE__*/_react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
      icon: `fa-${iconName}`,
      color: effectiveIconColor,
      fontSize: effectiveSize.faSize,
      style: customStyle
    });
  }
  const wrapperSize = effectiveSize.wrapperSize - ICON_PADDING * 2;
  const iconWrapperStyle = {
    background: gradientBackground ? (0, _getBackgroundGradientColor.createGradientBackground)(effectiveIconColor, '81%', '91%') : backgroundColor,
    borderRadius,
    width: wrapperSize,
    height: wrapperSize,
    padding: ICON_PADDING
  };
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.iconWrapper,
    style: {
      ...iconWrapperStyle,
      ...customStyle
    }
  }, /*#__PURE__*/_react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
    icon: `fa-${iconName}`,
    color: effectiveIconColor,
    fontSize: effectiveSize.faSize
  }));
};
const propTypes = exports.propTypes = {
  iconName: _propTypes.default.string.isRequired,
  iconColor: _propTypes.default.string,
  backgroundColor: _propTypes.default.string,
  gradientBackground: _propTypes.default.bool,
  borderRadius: _propTypes.default.string,
  preset: _propTypes.default.oneOf(['s', 'm', 'xl']),
  size: _propTypes.default.shape({
    faSize: _propTypes.default.number.isRequired,
    wrapperSize: _propTypes.default.number.isRequired
  }),
  customStyle: _propTypes.default.objectOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]))
};

// const MemoizedIcon = React.memo(Icon) as React.MemoExoticComponent<React.FC<IconProps>> & {
//   propTypes?: React.WeakValidationMap<IconProps>;
//   defaultProps?: Partial<IconProps>;
// };

Icon.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
// MemoizedIcon.propTypes = Icon.propTypes;
var _default = exports.default = Icon;
//# sourceMappingURL=index.js.map