"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SpinnerIcon = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _lazyRequire = require("../utils/lazy-require.js");
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); }
// react-native-svg is loaded lazily so the loading module can fall back to
// ActivityIndicator when the host app doesn't ship SVG support. Reanimated,
// by contrast, MUST be statically imported: the worklets Babel plugin
// performs build-time closure analysis (`__closure` metadata) that fails on
// runtime requires, which would crash the UI thread with
// "Tried to synchronously call a non-worklet function `addListener`".

const getSvgModule = (0, _lazyRequire.lazyRequire)('react-native-svg');
/**
 * Inner component that unconditionally calls Reanimated hooks.
 * Only rendered when react-native-svg is available.
 */
const AnimatedSpinner = ({
  color = 'currentColor',
  size = 26,
  className,
  style,
  svg
}) => {
  const {
    default: Svg,
    Rect
  } = svg;
  const rotation = (0, _reactNativeReanimated.useSharedValue)(0);
  (0, _react.useEffect)(() => {
    rotation.value = (0, _reactNativeReanimated.withRepeat)((0, _reactNativeReanimated.withTiming)(360, {
      duration: 400,
      easing: _reactNativeReanimated.Easing.linear
    }), -1, false);
    // rotation is a stable shared value reference; withRepeat/withTiming/Easing
    // are module-level constants from a static import and are stable too.
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
    transform: [{
      rotate: `${rotation.value}deg`
    }]
  }));
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
    style: [{
      width: size,
      height: size,
      alignItems: 'center',
      justifyContent: 'center'
    }, animatedStyle, style],
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Svg, {
      viewBox: "0 0 100 100",
      width: size,
      height: size,
      ...(className ? {
        className
      } : {}),
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Rect, {
        fill: color,
        height: "10",
        opacity: "0",
        rx: "5",
        ry: "5",
        transform: "rotate(-90 50 50)",
        width: "28",
        x: "67",
        y: "45"
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Rect, {
        fill: color,
        height: "10",
        opacity: "0.125",
        rx: "5",
        ry: "5",
        transform: "rotate(-45 50 50)",
        width: "28",
        x: "67",
        y: "45"
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Rect, {
        fill: color,
        height: "10",
        opacity: "0.25",
        rx: "5",
        ry: "5",
        transform: "rotate(0 50 50)",
        width: "28",
        x: "67",
        y: "45"
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Rect, {
        fill: color,
        height: "10",
        opacity: "0.375",
        rx: "5",
        ry: "5",
        transform: "rotate(45 50 50)",
        width: "28",
        x: "67",
        y: "45"
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Rect, {
        fill: color,
        height: "10",
        opacity: "0.5",
        rx: "5",
        ry: "5",
        transform: "rotate(90 50 50)",
        width: "28",
        x: "67",
        y: "45"
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Rect, {
        fill: color,
        height: "10",
        opacity: "0.625",
        rx: "5",
        ry: "5",
        transform: "rotate(135 50 50)",
        width: "28",
        x: "67",
        y: "45"
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Rect, {
        fill: color,
        height: "10",
        opacity: "0.75",
        rx: "5",
        ry: "5",
        transform: "rotate(180 50 50)",
        width: "28",
        x: "67",
        y: "45"
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Rect, {
        fill: color,
        height: "10",
        opacity: "0.875",
        rx: "5",
        ry: "5",
        transform: "rotate(225 50 50)",
        width: "28",
        x: "67",
        y: "45"
      })]
    })
  });
};

/**
 * iOS-style SVG spinner with 8 rotating rectangles and an opacity gradient trail.
 * Requires react-native-svg (lazy) and react-native-reanimated (static).
 * Falls back to ActivityIndicator if react-native-svg is missing.
 */
const SpinnerIcon = ({
  color = 'currentColor',
  size = 26,
  className,
  style
}) => {
  const svg = getSvgModule();
  if (!svg) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
      size: size > 30 ? 'large' : 'small',
      color: color
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(AnimatedSpinner, {
    color: color,
    size: size,
    className: className,
    style: style,
    svg: svg
  });
};
exports.SpinnerIcon = SpinnerIcon;
SpinnerIcon.displayName = 'SpinnerIcon';
//# sourceMappingURL=SpinnerIcon.js.map