"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ProgressLoader = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _context = require("../../context");
var _core = require("../../core");
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); }
/**
 * ProgressLoader component
 * @param progress - the progress percentage
 * @param color - IOColors value or undefined to define the color of the progress bar
 */
const ProgressLoader = ({
  progress,
  accessibilityLabel,
  color: customColor
}) => {
  const theme = (0, _context.useIOTheme)();
  const [width, setWidth] = (0, _react.useState)(0);
  const progressWidth = (0, _reactNativeReanimated.useSharedValue)(0);
  const backgroundColor = _core.IOColors[theme["appBackground-primary"]];
  const foregroundColor = customColor ?? theme["interactiveElem-default"];
  (0, _react.useEffect)(() => {
    // eslint-disable-next-line functional/immutable-data
    progressWidth.value = (0, _reactNativeReanimated.withSpring)(progress / 100 * width, _core.IOSpringValues.accordion);
  }, [progressWidth, progress, width]);
  const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
    width: progressWidth.value
  }));
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    focusable: true
    /* We set a fixed height to make the component focusable on Android */,
    style: {
      width: "100%",
      height: 16,
      justifyContent: "center",
      backgroundColor
    },
    onLayout: e => setWidth(e.nativeEvent.layout.width),
    importantForAccessibility: "yes",
    accessibilityLabel: accessibilityLabel,
    accessible: true,
    accessibilityRole: "progressbar",
    accessibilityValue: {
      min: 0,
      max: 100,
      now: progress
    },
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
      style: [animatedStyle, {
        height: 4,
        backgroundColor: _core.IOColors[foregroundColor]
      }]
    })
  });
};
exports.ProgressLoader = ProgressLoader;
//# sourceMappingURL=ProgressLoader.js.map