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); }
import { useEffect, useRef } from 'react';
import { Animated, View } from 'react-native';
import { useStyles } from './styles';
function useSkeletonColor(shimmer = true) {
  const {
    styles,
    colors
  } = useStyles();
  const opacity = useRef(new Animated.Value(1)).current;
  useEffect(() => {
    if (!shimmer) return () => {};
    const pulse = Animated.loop(Animated.sequence([Animated.timing(opacity, {
      toValue: 0.4,
      duration: 800,
      useNativeDriver: true
    }), 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(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(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(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(Animated.View, _extends({
    style: [styles.line, {
      width,
      height,
      opacity,
      marginBottom: bottom
    }, style]
  }, props));
}
Skeleton.Square = Square;
Skeleton.Circle = Circle;
Skeleton.Line = Line;
export default Skeleton;
//# sourceMappingURL=Skeleton.js.map