"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.IOSkeleton = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _reactNativeReanimated = 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); }
const ANIMATION_DURATION = 1250;
const [OPACITY_MIN, OPACITY_MAX] = [0.35, 0.75];
const OPACITY_REDUCED_MOTION = (OPACITY_MAX + OPACITY_MIN) / 2;
const IOSkeleton = ({
  shape,
  size,
  width,
  height,
  radius: borderRadius,
  color,
  testID
}) => {
  const reduceMotion = (0, _reactNativeReanimated.useReducedMotion)();
  const theme = (0, _context.useIOTheme)();
  const opacity = (0, _react.useRef)(new _reactNative.Animated.Value(OPACITY_MAX)).current;
  const backgroundColor = color ?? _core.IOColors[theme["skeleton-background"]];
  const baseStyle = (0, _react.useMemo)(() => ({
    backgroundColor,
    width: shape === "square" ? size : width,
    height: shape === "square" ? size : height,
    borderRadius,
    borderCurve: "continuous"
  }), [backgroundColor, shape, size, width, height, borderRadius]);
  (0, _react.useEffect)(() => {
    if (reduceMotion) {
      opacity.setValue(OPACITY_REDUCED_MOTION);
      return;
    }
    const animation = _reactNative.Animated.loop(_reactNative.Animated.sequence([_reactNative.Animated.timing(opacity, {
      toValue: OPACITY_MIN,
      duration: ANIMATION_DURATION / 2,
      easing: _reactNative.Easing.inOut(_reactNative.Easing.sin),
      useNativeDriver: true
    }), _reactNative.Animated.timing(opacity, {
      toValue: OPACITY_MAX,
      duration: ANIMATION_DURATION / 2,
      easing: _reactNative.Easing.inOut(_reactNative.Easing.sin),
      useNativeDriver: true
    })]));
    animation.start();
    return () => {
      animation.stop();
    };
  }, [opacity, reduceMotion]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
    testID: testID,
    style: [baseStyle, {
      opacity
    }]
  });
};
exports.IOSkeleton = IOSkeleton;
//# sourceMappingURL=IOSkeleton.js.map