"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Box = Box;
exports.Circle = Circle;
exports.Col = Col;
exports.Pill = Pill;
exports.Row = Row;
exports.Text = Text;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _useTheme = require("../theme/use-theme.js");
var _nativeDriver = require("../styles/native-driver.js");
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 SHIMMER_DURATION = 1500;
const SHIMMER_MIN_OPACITY = 0.4;
const SHIMMER_MAX_OPACITY = 1;
function useShimmer() {
  const opacity = (0, _react.useRef)(new _reactNative.Animated.Value(SHIMMER_MAX_OPACITY)).current;
  (0, _react.useEffect)(() => {
    const loop = _reactNative.Animated.loop(_reactNative.Animated.sequence([_reactNative.Animated.timing(opacity, {
      toValue: SHIMMER_MIN_OPACITY,
      duration: SHIMMER_DURATION / 2,
      useNativeDriver: _nativeDriver.SUPPORTS_NATIVE_DRIVER
    }), _reactNative.Animated.timing(opacity, {
      toValue: SHIMMER_MAX_OPACITY,
      duration: SHIMMER_DURATION / 2,
      useNativeDriver: _nativeDriver.SUPPORTS_NATIVE_DRIVER
    })]));
    loop.start();
    return () => loop.stop();
  }, [opacity]);
  return opacity;
}
function Text({
  blend,
  style
}) {
  const {
    colors
  } = (0, _useTheme.useTheme)();
  const shimmer = useShimmer();
  const flattened = _reactNative.StyleSheet.flatten(style);
  const width = flattened?.width;
  const lineHeight = flattened?.lineHeight || 14;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: [styles.textOuter, {
      maxWidth: width
    }, {
      paddingVertical: lineHeight * 0.15
    }],
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
      style: [styles.textInner, {
        backgroundColor: colors.contrast50,
        height: lineHeight * 0.7,
        opacity: _reactNative.Animated.multiply(shimmer, blend ? 0.6 : 1)
      }]
    })
  });
}
Text.displayName = 'Skeleton.Text';
function Circle({
  children,
  size,
  blend,
  style
}) {
  const {
    colors
  } = (0, _useTheme.useTheme)();
  const shimmer = useShimmer();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
    style: [styles.circle, {
      backgroundColor: colors.contrast50,
      width: size,
      height: size,
      opacity: _reactNative.Animated.multiply(shimmer, blend ? 0.6 : 1)
    }, style],
    children: children
  });
}
Circle.displayName = 'Skeleton.Circle';
function Pill({
  size,
  blend,
  style
}) {
  const {
    colors
  } = (0, _useTheme.useTheme)();
  const shimmer = useShimmer();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
    style: [styles.pill, {
      backgroundColor: colors.contrast50,
      width: size * 1.618,
      height: size,
      opacity: _reactNative.Animated.multiply(shimmer, blend ? 0.6 : 1)
    }, style]
  });
}
Pill.displayName = 'Skeleton.Pill';

/**
 * Generic rectangular shimmering placeholder. Use for image/card/banner
 * placeholders where neither {@link Pill} (forced borderRadius: 999) nor
 * {@link Circle} fit. Defaults to a small borderRadius (8). Pass `0` for
 * sharp corners or any larger number / percentage string for custom shapes.
 */
function Box({
  width,
  height,
  borderRadius = 8,
  blend,
  style
}) {
  const {
    colors
  } = (0, _useTheme.useTheme)();
  const shimmer = useShimmer();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
    style: [{
      backgroundColor: colors.contrast50,
      width,
      height,
      borderRadius,
      opacity: _reactNative.Animated.multiply(shimmer, blend ? 0.6 : 1)
    }, style]
  });
}
Box.displayName = 'Skeleton.Box';
function Col({
  children,
  style
}) {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: [styles.col, style],
    children: children
  });
}
Col.displayName = 'Skeleton.Col';
function Row({
  children,
  style
}) {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: [styles.row, style],
    children: children
  });
}
Row.displayName = 'Skeleton.Row';
const styles = _reactNative.StyleSheet.create({
  textOuter: {
    flex: 1
  },
  textInner: {
    borderRadius: 8
  },
  circle: {
    justifyContent: 'center',
    alignItems: 'center',
    borderRadius: 999
  },
  pill: {
    borderRadius: 999
  },
  col: {
    flex: 1
  },
  row: {
    flexDirection: 'row'
  }
});
//# sourceMappingURL=index.js.map