"use strict";

import * as React from 'react';
import { Platform, StyleSheet, View } from 'react-native';
import { Pressable } from './Pressable';
import { getTouchableRippleColors } from './utils';
// Settings context not needed - removed dependency
const SettingsContext = /*#__PURE__*/React.createContext({
  rippleEffectEnabled: true
});
import { useInternalTheme } from '../theming';
import { forwardRef } from '../utils/forwardRef';
import hasTouchHandler from '../utils/hasTouchHandler';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
const ANDROID_VERSION_LOLLIPOP = 21;
const ANDROID_VERSION_PIE = 28;
const TouchableRipple = ({
  style,
  background,
  borderless = false,
  disabled: disabledProp,
  rippleColor,
  underlayColor,
  children,
  theme: themeOverrides,
  ...rest
}, ref) => {
  const theme = useInternalTheme(themeOverrides);
  const {
    rippleEffectEnabled
  } = React.useContext(SettingsContext);
  const {
    onPress,
    onLongPress,
    onPressIn,
    onPressOut
  } = rest;
  const hasPassedTouchHandler = hasTouchHandler({
    onPress,
    onLongPress,
    onPressIn,
    onPressOut
  });
  const disabled = disabledProp || !hasPassedTouchHandler;
  const {
    calculatedRippleColor,
    calculatedUnderlayColor
  } = getTouchableRippleColors({
    theme,
    rippleColor,
    underlayColor
  });

  // A workaround for ripple on Android P is to use useForeground + overflow: 'hidden'
  // https://github.com/facebook/react-native/issues/6480
  const useForeground = Platform.OS === 'android' && Platform.Version >= ANDROID_VERSION_PIE && borderless;
  if (TouchableRipple.supported) {
    const androidRipple = rippleEffectEnabled ? background ?? {
      color: calculatedRippleColor,
      borderless,
      foreground: useForeground
    } : undefined;
    return /*#__PURE__*/_jsx(Pressable, {
      ...rest,
      ref: ref,
      disabled: disabled,
      style: [borderless && styles.overflowHidden, style],
      android_ripple: androidRipple,
      children: React.Children.only(children)
    });
  }
  return /*#__PURE__*/_jsx(Pressable, {
    ...rest,
    ref: ref,
    disabled: disabled,
    style: [borderless && styles.overflowHidden, style],
    children: ({
      pressed
    }) => /*#__PURE__*/_jsxs(_Fragment, {
      children: [pressed && rippleEffectEnabled && /*#__PURE__*/_jsx(View, {
        testID: "touchable-ripple-underlay",
        style: [styles.underlay, {
          backgroundColor: calculatedUnderlayColor
        }]
      }), React.Children.only(children)]
    })
  });
};
TouchableRipple.supported = Platform.OS === 'android' && Platform.Version >= ANDROID_VERSION_LOLLIPOP;
const styles = StyleSheet.create({
  overflowHidden: {
    overflow: 'hidden'
  },
  underlay: {
    ...StyleSheet.absoluteFillObject,
    zIndex: 2
  }
});
const Component = forwardRef(TouchableRipple);
export default Component;
//# sourceMappingURL=TouchableRipple.native.js.map