"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.sizeToButtonSpacing = exports.importIcon = exports.hasWhiteSpace = exports.getPrimitivesInlineSpaceBySize = exports.getMaxLines = exports.getMaxLineHeight = exports.getIconWidth = exports.getFormattedMessageAsString = exports.getFormattedMessage = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireDefault(require("react"));
var _reactIntlNext = require("react-intl-next");
var _reactLoadable = _interopRequireDefault(require("react-loadable"));
var _constants = require("../../../constants");
var sizeToButtonSpacing = exports.sizeToButtonSpacing = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _constants.SmartLinkSize.Small, 'none'), _constants.SmartLinkSize.Medium, 'compact'), _constants.SmartLinkSize.Large, 'compact'), _constants.SmartLinkSize.XLarge, 'default');
var getFormattedMessage = exports.getFormattedMessage = function getFormattedMessage(message) {
  if (message) {
    var descriptor = message.descriptor,
      values = message.values;
    return /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, (0, _extends2.default)({}, descriptor, {
      values: values
    }));
  }
};
var getFormattedMessageAsString = exports.getFormattedMessageAsString = function getFormattedMessageAsString(intl, message, context) {
  var formatMessage = intl.formatMessage;
  return message ? formatMessage(message, {
    context: context
  }) : '';
};
var getIconWidth = exports.getIconWidth = function getIconWidth(size) {
  switch (size) {
    case _constants.SmartLinkSize.XLarge:
    case _constants.SmartLinkSize.Large:
      return "var(--ds-space-300, 24px)";
    case _constants.SmartLinkSize.Medium:
    case _constants.SmartLinkSize.Small:
    default:
      return "var(--ds-space-200, 16px)";
  }
};
var importIcon = exports.importIcon = function importIcon(importFn) {
  return (0, _reactLoadable.default)({
    loader: function loader() {
      return importFn().then(function (module) {
        return module.default;
      });
    },
    loading: function loading() {
      return null;
    }
  }); // Because we're using dynamic loading here, TS will not be able to infer the type.
};
var getMaxLineHeight = exports.getMaxLineHeight = function getMaxLineHeight(size) {
  // The maximum line height based on all elements in specific size.
  // These heights belongs to AvatarGroup.
  switch (size) {
    case _constants.SmartLinkSize.XLarge:
    case _constants.SmartLinkSize.Large:
      return 1.75;
    case _constants.SmartLinkSize.Medium:
    case _constants.SmartLinkSize.Small:
    default:
      return 1.5;
  }
};
var getMaxLines = exports.getMaxLines = function getMaxLines(value, defaultValue, max, min) {
  if (value > max) {
    return defaultValue;
  }
  if (value < min) {
    return min;
  }
  return value;
};

/**
 * A space between element based on smart link size
 * To replace blocks/utils.tsz getGapSize() with space token for primitives
 */
var getPrimitivesInlineSpaceBySize = exports.getPrimitivesInlineSpaceBySize = function getPrimitivesInlineSpaceBySize(size) {
  switch (size) {
    case _constants.SmartLinkSize.XLarge:
      return 'space.250';
    case _constants.SmartLinkSize.Large:
      return 'space.200';
    case _constants.SmartLinkSize.Medium:
      return 'space.100';
    case _constants.SmartLinkSize.Small:
    default:
      return 'space.050';
  }
};
var hasWhiteSpace = exports.hasWhiteSpace = function hasWhiteSpace(str) {
  return str.search(/\s/) >= 0;
};