"use strict";

import { useId } from "react";
import { View } from "react-native";
import Animated from "react-native-reanimated";
import Svg, { Defs, G, LinearGradient, Path, Stop } from "react-native-svg";
import { useIOTheme } from "../../context";
import { IOColors } from "../../core/IOColors";

/**
 * Size scale
 */
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const spinKeyframes = {
  from: {
    transform: [{
      rotateZ: "0deg"
    }]
  },
  to: {
    transform: [{
      rotateZ: "360deg"
    }]
  }
};
const strokeMap = {
  24: 3,
  48: 5
};
export const LoadingSpinner = ({
  color: customColor,
  size = 24,
  durationMs = 850,
  accessibilityHint,
  accessibilityLabel,
  testID = "LoadingSpinnerTestID"
}) => {
  const theme = useIOTheme();
  const id = useId();
  const stroke = strokeMap[size];
  const color = customColor ?? IOColors[theme["interactiveElem-default"]];
  const secondHalfId = `${id}-secondHalf`;
  const firstHalfId = `${id}-firstHalf`;
  return /*#__PURE__*/_jsx(View, {
    style: {
      width: size,
      height: size
    },
    accessible: true,
    accessibilityRole: "progressbar",
    accessibilityHint: accessibilityHint,
    accessibilityLabel: accessibilityLabel,
    testID: testID,
    children: /*#__PURE__*/_jsx(Animated.View, {
      testID: "LoadingSpinnerAnimatedTestID",
      style: {
        animationName: spinKeyframes,
        animationDuration: durationMs,
        animationIterationCount: "infinite",
        animationTimingFunction: "linear",
        transformOrigin: "center"
      },
      children: /*#__PURE__*/_jsxs(Svg, {
        width: size,
        height: size,
        viewBox: `0 0 ${size} ${size}`,
        fill: "none",
        children: [/*#__PURE__*/_jsxs(Defs, {
          children: [/*#__PURE__*/_jsxs(LinearGradient, {
            id: secondHalfId,
            children: [/*#__PURE__*/_jsx(Stop, {
              offset: "0%",
              stopOpacity: "0",
              stopColor: color
            }), /*#__PURE__*/_jsx(Stop, {
              offset: "100%",
              stopOpacity: "1",
              stopColor: color
            })]
          }), /*#__PURE__*/_jsxs(LinearGradient, {
            id: firstHalfId,
            children: [/*#__PURE__*/_jsx(Stop, {
              offset: "0%",
              stopOpacity: "1",
              stopColor: color
            }), /*#__PURE__*/_jsx(Stop, {
              offset: "100%",
              stopOpacity: "1",
              stopColor: color
            })]
          })]
        }), /*#__PURE__*/_jsxs(G, {
          strokeWidth: stroke,
          children: [/*#__PURE__*/_jsx(Path, {
            stroke: `url(#${secondHalfId})`,
            d: `M ${stroke / 2} ${size / 2} A ${size / 2 - stroke / 2} ${size / 2 - stroke / 2} 0 0 1 ${size - stroke / 2} ${size / 2}`
          }), /*#__PURE__*/_jsx(Path, {
            stroke: `url(#${firstHalfId})`,
            d: `M ${size - stroke / 2} ${size / 2} A ${size / 2 - stroke / 2} ${size / 2 - stroke / 2} 0 0 1 ${stroke / 2} ${size / 2}`
          }), /*#__PURE__*/_jsx(Path, {
            stroke: color,
            strokeLinecap: "round",
            d: `M ${stroke / 2} ${size / 2} A ${size / 2 - stroke / 2} ${size / 2 - stroke / 2} 0 0 1 ${stroke / 2} ${size / 2 - stroke / 4}`
          })]
        })]
      })
    })
  });
};
//# sourceMappingURL=LoadingSpinner.js.map