"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.iconSizer = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));var _react = _interopRequireDefault(require("react"));

var _forwardRefAndName = require("../../lib/forwardRefAndName");



var _iconConstants = require("./iconConstants");var _excluded = ["size"];







var isAlias = function isAlias(size) {return (
    typeof size === 'string' && Object.keys(_iconConstants.ALIASES_TO_SIZES).includes(size));};

var getAliasFromSize = function getAliasFromSize(size) {return (
    Object.entries(_iconConstants.ALIASES_TO_SIZES).sort(function (_ref, _ref2) {var a = _ref[1];var b = _ref2[1];return (
        Math.abs(size - a) > Math.abs(size - b) ? 1 : -1);}
    )[0][0]);};

var iconSizer = exports.iconSizer = function iconSizer(sizes, iconName) {return (
    (0, _forwardRefAndName.forwardRefAndIconName)(
      iconName,
      function (_ref3, ref) {var _ref3$size = _ref3.size,size = _ref3$size === void 0 ? _iconConstants.DEFAULT_ICON_ALIAS : _ref3$size,props = (0, _objectWithoutPropertiesLoose2.default)(_ref3, _excluded);
        var alias = _iconConstants.DEFAULT_ICON_ALIAS;
        if (size !== alias && isAlias(size)) {
          alias = size;
        } else if (typeof size === 'number') {
          alias = getAliasFromSize(size);
        }
        var Icon = sizes[alias]();

        return /*#__PURE__*/_react.default.cloneElement(Icon, (0, _extends2.default)({ ref: ref }, props));
      }
    ));};