"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.LoadingSpinner = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireDefault(require("react-native-reanimated"));
var _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
var _context = require("../../context");
var _IOColors = require("../../core/IOColors");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
 * Size scale
 */

const spinKeyframes = {
  from: {
    transform: [{
      rotateZ: "0deg"
    }]
  },
  to: {
    transform: [{
      rotateZ: "360deg"
    }]
  }
};
const strokeMap = {
  24: 3,
  48: 5
};
const LoadingSpinner = ({
  color: customColor,
  size = 24,
  durationMs = 850,
  accessibilityHint,
  accessibilityLabel,
  testID = "LoadingSpinnerTestID"
}) => {
  const theme = (0, _context.useIOTheme)();
  const id = (0, _react.useId)();
  const stroke = strokeMap[size];
  const color = customColor ?? _IOColors.IOColors[theme["interactiveElem-default"]];
  const secondHalfId = `${id}-secondHalf`;
  const firstHalfId = `${id}-firstHalf`;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: {
      width: size,
      height: size
    },
    accessible: true,
    accessibilityRole: "progressbar",
    accessibilityHint: accessibilityHint,
    accessibilityLabel: accessibilityLabel,
    testID: testID,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
      testID: "LoadingSpinnerAnimatedTestID",
      style: {
        animationName: spinKeyframes,
        animationDuration: durationMs,
        animationIterationCount: "infinite",
        animationTimingFunction: "linear",
        transformOrigin: "center"
      },
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeSvg.default, {
        width: size,
        height: size,
        viewBox: `0 0 ${size} ${size}`,
        fill: "none",
        children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeSvg.Defs, {
          children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeSvg.LinearGradient, {
            id: secondHalfId,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Stop, {
              offset: "0%",
              stopOpacity: "0",
              stopColor: color
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Stop, {
              offset: "100%",
              stopOpacity: "1",
              stopColor: color
            })]
          }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeSvg.LinearGradient, {
            id: firstHalfId,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Stop, {
              offset: "0%",
              stopOpacity: "1",
              stopColor: color
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Stop, {
              offset: "100%",
              stopOpacity: "1",
              stopColor: color
            })]
          })]
        }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeSvg.G, {
          strokeWidth: stroke,
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.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__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.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__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.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}`
          })]
        })]
      })
    })
  });
};
exports.LoadingSpinner = LoadingSpinner;
//# sourceMappingURL=LoadingSpinner.js.map