'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var componentsTheming = require('@wise/components-theming');
var clsx = require('clsx');
var React = require('react');
var Body = require('../body/Body.js');
require('../common/theme.js');
require('../common/direction.js');
require('@transferwise/neptune-tokens');
require('../common/propsValues/control.js');
var size = require('../common/propsValues/size.js');
var typography = require('../common/propsValues/typography.js');
require('../common/propsValues/width.js');
require('../common/propsValues/type.js');
require('../common/propsValues/dateMode.js');
require('../common/propsValues/monthFormat.js');
require('../common/propsValues/position.js');
require('../common/propsValues/layouts.js');
require('../common/propsValues/status.js');
require('../common/propsValues/sentiment.js');
require('../common/propsValues/profileType.js');
require('../common/propsValues/variant.js');
require('../common/propsValues/scroll.js');
require('../common/propsValues/markdownNodeType.js');
require('../common/fileType.js');
require('@transferwise/formatting');
require('@transferwise/icons');
require('react-intl');
require('../common/closeButton/CloseButton.messages.js');
var jsxRuntime = require('react/jsx-runtime');

const Loader = ({
  small = false,
  size: size$1 = size.Size.MEDIUM,
  displayInstantly = false,
  label,
  classNames = {},
  ...restProps
}) => {
  const {
    theme
  } = componentsTheming.useTheme();
  const [hasDebounced, setHasDebounced] = React.useState(displayInstantly);
  React.useEffect(() => {
    let cancelled;
    let timeout;
    if (!displayInstantly) {
      timeout = setTimeout(() => {
        if (!cancelled) {
          setHasDebounced(true);
        }
      }, 1000);
    }
    return () => {
      cancelled = true;
      clearTimeout(timeout);
    };
  }, []);
  const style = className => classNames[className] || className;
  const legacySize = small ? size.Size.SMALL : size$1;
  const supportedSize = getSupportedSize(legacySize);
  if (theme === 'forest-green') {
    // eslint-disable-next-line no-console
    console.warn('Loader is forbidden to use with Forest Green theme. Check the https://docs.wise.design/components/screen-loader for more info.');
    return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {});
  }
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: style('tw-loader'),
    "data-testid": restProps['data-testid'],
    children: [/*#__PURE__*/jsxRuntime.jsx("div", {
      className: clsx.clsx(style('tw-loader-asset'), style(`tw-loader-asset--${supportedSize}`), {
        'tw-loader-asset--visible': hasDebounced
      })
    }), label && hasDebounced && /*#__PURE__*/jsxRuntime.jsx(Body.default, {
      type: typography.Typography.BODY_LARGE_BOLD,
      as: "span",
      className: style('text-secondary'),
      children: label
    })]
  });
};
const getSupportedSize = size$1 => {
  switch (size$1) {
    case size.Size.SMALL:
    case size.Size.EXTRA_SMALL:
      return size.Size.SMALL;
    case size.Size.EXTRA_LARGE:
    case size.Size.LARGE:
    case size.Size.MEDIUM:
    default:
      return size.Size.MEDIUM;
  }
};

exports.default = Loader;
//# sourceMappingURL=Loader.js.map
