"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _styles = require("./styles");
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function useSkeletonColor(shimmer = true) {
  const {
    styles,
    colors
  } = (0, _styles.useStyles)();
  const opacity = (0, _react.useRef)(new _reactNative.Animated.Value(1)).current;
  (0, _react.useEffect)(() => {
    if (!shimmer) return () => {};
    const pulse = _reactNative.Animated.loop(_reactNative.Animated.sequence([_reactNative.Animated.timing(opacity, {
      toValue: 0.4,
      duration: 800,
      useNativeDriver: true
    }), _reactNative.Animated.timing(opacity, {
      toValue: 1,
      duration: 800,
      useNativeDriver: true
    })]));
    pulse.start();
    return () => pulse.stop();
  }, [opacity, shimmer]);
  return {
    opacity,
    styles,
    backgroundColor: colors.baseShade4
  };
}
function Skeleton({
  children,
  style,
  ...props
}) {
  return /*#__PURE__*/React.createElement(_reactNative.View, _extends({
    style: style
  }, props), children);
}
function Square({
  width,
  height,
  bottom,
  radius = 4,
  shimmer = true,
  style,
  ...props
}) {
  const {
    opacity,
    styles
  } = useSkeletonColor(shimmer);
  return /*#__PURE__*/React.createElement(_reactNative.Animated.View, _extends({
    style: [styles.square, {
      width,
      height,
      borderRadius: radius,
      opacity,
      marginBottom: bottom
    }, style]
  }, props));
}
function Circle({
  width,
  height,
  style,
  bottom,
  shimmer = true,
  ...props
}) {
  const {
    opacity,
    styles
  } = useSkeletonColor(shimmer);
  const size = 9999;
  return /*#__PURE__*/React.createElement(_reactNative.Animated.View, _extends({
    style: [styles.circle, {
      width,
      height,
      borderRadius: size / 2,
      opacity,
      marginBottom: bottom
    }, style]
  }, props));
}
function Line({
  width,
  height,
  style,
  bottom,
  shimmer = true,
  ...props
}) {
  const {
    opacity,
    styles
  } = useSkeletonColor(shimmer);
  return /*#__PURE__*/React.createElement(_reactNative.Animated.View, _extends({
    style: [styles.line, {
      width,
      height,
      opacity,
      marginBottom: bottom
    }, style]
  }, props));
}
Skeleton.Square = Square;
Skeleton.Circle = Circle;
Skeleton.Line = Line;
var _default = exports.default = Skeleton;
//# sourceMappingURL=Skeleton.js.map