"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PressableModuleBase = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeHapticFeedback = _interopRequireDefault(require("react-native-haptic-feedback"));
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _core = require("../../core");
var _context = require("../../context");
var _hooks = require("../../hooks");
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); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const PressableModuleBase = ({
  onPress,
  withLooseSpacing = false,
  accessibilityLabel,
  accessibilityHint,
  testID,
  children
}) => {
  const theme = (0, _context.useIOTheme)();
  const reducedMotion = (0, _reactNativeReanimated.useReducedMotion)();
  const {
    onPressIn,
    onPressOut,
    scaleAnimatedStyle
  } = (0, _hooks.useScaleAnimation)(reducedMotion ? "slight" : "medium");
  /* We use a slight scaleEffect if `reducedMotion` is enabled.
  We don't disable it completely because that's the only
  difference between the two states "default" and "pressed".
  If we remove it, they they won't be able to understand
  if there's an ongoing interaction. */

  const handleOnPress = (0, _react.useCallback)(event => {
    if (onPress) {
      _reactNativeHapticFeedback.default.trigger("impactLight");
      onPress(event);
    }
  }, [onPress]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
    onPress: handleOnPress,
    testID: testID,
    accessible: true,
    onPressIn: onPressIn,
    onPressOut: onPressOut,
    onTouchEnd: onPressOut,
    accessibilityLabel: accessibilityLabel,
    accessibilityHint: accessibilityHint,
    accessibilityRole: "button",
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
      style: [_core.IOModuleStyles.button, {
        borderColor: _core.IOColors[theme["cardBorder-default"]]
      }, withLooseSpacing && {
        paddingVertical: _core.IOModuleIDPSavedVSpacing
      }, scaleAnimatedStyle],
      children: children
    })
  });
};
exports.PressableModuleBase = PressableModuleBase;
//# sourceMappingURL=PressableModuleBase.js.map