import React from "react";
import { colorStyleFunction, layoutStyleFunction, positionStyleFunction, spacingStyleFunction } from "../../../theme/src/style-functions";
import { useAtomicComponentConfig } from "../../../hooks/useAtomicComponentConfig";
import { StyleSheet } from "react-native";
import BallIndicator from "./indicators/ball";
import BarIndicator from "./indicators/bar";
import DotIndicator from "./indicators/dot";
import MaterialIndicator from "./indicators/material";
import PacmanIndicator from "./indicators/pacman";
import PulseIndicator from "./indicators/pulse";
import SkypeIndicator from "./indicators/skype";
import ActivityIndicator from "./indicators/activity";
import WaveIndicator from "./indicators/wave";
import { useResponsiveProp } from "../../../hooks/useResponsiveProp";
import { useMotiWithStyleProps } from "../../../hooks/useMotiWithStyleProps";
const indicatorStyleFunctions = [colorStyleFunction, spacingStyleFunction, layoutStyleFunction, positionStyleFunction];
const IndicatorTypeToComponentMap = {
  ball: BallIndicator,
  bar: BarIndicator,
  dot: DotIndicator,
  spinner: MaterialIndicator,
  pacman: PacmanIndicator,
  pulse: PulseIndicator,
  skype: SkypeIndicator,
  activity: ActivityIndicator,
  wave: WaveIndicator
};

/**
 * 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.memo( /*#__PURE__*/React.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 = useAtomicComponentConfig("Spinner", rest, {
    size: rest.size,
    variant: rest.variant
  }, colorScheme, indicatorStyleFunctions);

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

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

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

  // Create and return the Spinner component
  return /*#__PURE__*/React.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 ? StyleSheet.absoluteFill : {
      alignSelf: "flex-start"
    }, {
      flex: 0,
      ...props.style
    }],
    ref: ref
  });
}));
Spinner.displayName = "Spinner";
export default Spinner;
//# sourceMappingURL=spinner.js.map