"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CircularProgressIndicator = void 0;
var _styles = require("./styles");
var _reactNativeSvg = require("react-native-svg");
var _react = require("react");
var _reactNative = require("react-native");
const CircularProgressIndicator = ({
  progress,
  size = 50,
  strokeWidth = 4,
  backgroundColor = 'rgba(255, 255, 255, 0.5)',
  progressColor = 'white',
  backgroundOpacity = 1,
  duration = 1000
}) => {
  const styles = (0, _styles.useStyles)();
  const rotateAnim = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
  const radius = (size - strokeWidth) / 2;
  const circumference = radius * 2 * Math.PI;
  const isProgressMode = progress !== undefined;
  const strokeDashoffset = isProgressMode ? circumference - progress / 100 * circumference : 0;
  (0, _react.useEffect)(() => {
    if (!isProgressMode) {
      _reactNative.Animated.loop(_reactNative.Animated.timing(rotateAnim, {
        toValue: 1,
        duration,
        useNativeDriver: true
      })).start();
    }
  }, [rotateAnim, duration, isProgressMode]);
  const rotate = rotateAnim.interpolate({
    inputRange: [0, 1],
    outputRange: ['0deg', '360deg']
  });
  const renderProgressVersion = () => /*#__PURE__*/React.createElement(_reactNativeSvg.Svg, {
    width: size,
    height: size,
    style: _reactNative.StyleSheet.absoluteFillObject
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.Circle, {
    cx: size / 2,
    cy: size / 2,
    r: radius,
    stroke: backgroundColor,
    strokeWidth: strokeWidth,
    fill: "transparent",
    opacity: backgroundOpacity
  }), /*#__PURE__*/React.createElement(_reactNativeSvg.Circle, {
    cx: size / 2,
    cy: size / 2,
    r: radius,
    stroke: progressColor,
    strokeWidth: strokeWidth,
    fill: "transparent",
    strokeDasharray: `${circumference} ${circumference}`,
    strokeDashoffset: strokeDashoffset,
    strokeLinecap: "round",
    transform: `rotate(-90 ${size / 2} ${size / 2})`
  }));
  const renderRotatingVersion = () => /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
    style: [_reactNative.StyleSheet.absoluteFillObject, {
      transform: [{
        rotate
      }]
    }]
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.Svg, {
    width: size,
    height: size
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.Circle, {
    cx: size / 2,
    cy: size / 2,
    r: radius,
    stroke: backgroundColor,
    strokeWidth: strokeWidth,
    fill: "transparent",
    opacity: backgroundOpacity,
    strokeDasharray: `${circumference} ${circumference}`
  }), /*#__PURE__*/React.createElement(_reactNativeSvg.Circle, {
    cx: size / 2,
    cy: size / 2,
    r: radius,
    stroke: progressColor,
    strokeWidth: strokeWidth,
    fill: "transparent",
    strokeDasharray: `${circumference * 0.25} ${circumference * 0.75}`,
    strokeLinecap: "round",
    transform: `rotate(-90 ${size / 2} ${size / 2})`
  })));
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: [styles.container, {
      width: size,
      height: size
    }]
  }, isProgressMode ? renderProgressVersion() : renderRotatingVersion());
};
exports.CircularProgressIndicator = CircularProgressIndicator;
//# sourceMappingURL=CircularProgressIndicator.js.map