import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import { FormattedMessage } from 'react-intl';
import Loadable from 'react-loadable';
import { SmartLinkSize } from '../../../constants';
export var sizeToButtonSpacing = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, SmartLinkSize.Small, 'none'), SmartLinkSize.Medium, 'compact'), SmartLinkSize.Large, 'compact'), SmartLinkSize.XLarge, 'default');
export var getFormattedMessage = function getFormattedMessage(message) {
  if (message) {
    var descriptor = message.descriptor,
      values = message.values;
    return /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, descriptor, {
      values: values
    }));
  }
};
export var getFormattedMessageAsString = function getFormattedMessageAsString(intl, message, context) {
  var formatMessage = intl.formatMessage;
  return message ? formatMessage(message, {
    context: context
  }) : '';
};
export var getIconWidth = function getIconWidth(size) {
  switch (size) {
    case SmartLinkSize.XLarge:
    case SmartLinkSize.Large:
      return "var(--ds-space-300, 24px)";
    case SmartLinkSize.Medium:
    case SmartLinkSize.Small:
    default:
      return "var(--ds-space-200, 16px)";
  }
};
export var importIcon = function importIcon(importFn) {
  return Loadable({
    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.
};
export var getMaxLineHeight = function getMaxLineHeight(size) {
  // The maximum line height based on all elements in specific size.
  // These heights belongs to AvatarGroup.
  switch (size) {
    case SmartLinkSize.XLarge:
    case SmartLinkSize.Large:
      return 1.75;
    case SmartLinkSize.Medium:
    case SmartLinkSize.Small:
    default:
      return 1.5;
  }
};
export var 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
 */
export var getPrimitivesInlineSpaceBySize = function getPrimitivesInlineSpaceBySize(size) {
  switch (size) {
    case SmartLinkSize.XLarge:
      return 'space.250';
    case SmartLinkSize.Large:
      return 'space.200';
    case SmartLinkSize.Medium:
      return 'space.100';
    case SmartLinkSize.Small:
    default:
      return 'space.050';
  }
};
export var hasWhiteSpace = function hasWhiteSpace(str) {
  return str.search(/\s/) >= 0;
};