"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _styleFunctions = require("../../../theme/src/style-functions");
var _useAtomicComponentConfig = require("../../../hooks/useAtomicComponentConfig");
var _reactNative = require("react-native");
var _ball = _interopRequireDefault(require("./indicators/ball"));
var _bar = _interopRequireDefault(require("./indicators/bar"));
var _dot = _interopRequireDefault(require("./indicators/dot"));
var _material = _interopRequireDefault(require("./indicators/material"));
var _pacman = _interopRequireDefault(require("./indicators/pacman"));
var _pulse = _interopRequireDefault(require("./indicators/pulse"));
var _skype = _interopRequireDefault(require("./indicators/skype"));
var _activity = _interopRequireDefault(require("./indicators/activity"));
var _wave = _interopRequireDefault(require("./indicators/wave"));
var _useResponsiveProp = require("../../../hooks/useResponsiveProp");
var _useMotiWithStyleProps = require("../../../hooks/useMotiWithStyleProps");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const indicatorStyleFunctions = [_styleFunctions.colorStyleFunction, _styleFunctions.spacingStyleFunction, _styleFunctions.layoutStyleFunction, _styleFunctions.positionStyleFunction];
const IndicatorTypeToComponentMap = {
  ball: _ball.default,
  bar: _bar.default,
  dot: _dot.default,
  spinner: _material.default,
  pacman: _pacman.default,
  pulse: _pulse.default,
  skype: _skype.default,
  activity: _activity.default,
  wave: _wave.default
};

/**
 * A component used to provide a visual cue that an action is either processing, awaiting a course of change or a result.
 */
const Spinner = /*#__PURE__*/_react.default.memo( /*#__PURE__*/_react.default.forwardRef(({
  isLoading = true,
  isExpanded = false,
  animationDuration = 1200,
  colorScheme = "primary",
  ...rest
}, ref) => {
  // Set default variant to "spinner"
  rest.variant = rest.variant ?? "spinner";

  // Get props for the Spinner
  let props = (0, _useAtomicComponentConfig.useAtomicComponentConfig)("Spinner", rest, {
    size: rest.size,
    variant: rest.variant
  }, colorScheme, indicatorStyleFunctions);

  // Add style props to props using useMotiWithStyleProps
  props = (0, _useMotiWithStyleProps.useMotiWithStyleProps)(props, indicatorStyleFunctions);

  // Get variant for current screen size
  const variantForCurrentScreenSize = (0, _useResponsiveProp.useResponsiveProp)(rest.variant);

  // If isLoading is false, return null
  if (!isLoading) return null;

  // Create and return the Spinner component
  return /*#__PURE__*/_react.default.createElement(IndicatorTypeToComponentMap[variantForCurrentScreenSize], {
    ...props,
    color: props.style.color,
    size: props.sizeMultiplier ? props.sizeMultiplier * props.rawSize : props.rawSize,
    accessible: true,
    accessibilityLabel: rest.accessibilityLabel ? rest.accessibilityLabel : "Loading indicator",
    accessibilityRole: "progressbar",
    style: [isExpanded ? _reactNative.StyleSheet.absoluteFill : {
      alignSelf: "flex-start"
    }, {
      flex: 0,
      ...props.style
    }],
    ref: ref
  });
}));
Spinner.displayName = "Spinner";
var _default = exports.default = Spinner;
//# sourceMappingURL=spinner.js.map