"use strict";

exports.__esModule = true;
exports.default = void 0;
var _reactNative = require("react-native");
var _react = _interopRequireWildcard(require("react"));
var _templateContext = require("../../template/app-review/template-context");
var _analytics = require("../../variables/analytics");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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); }
const hitSlop = {
  left: 12,
  right: 12,
  bottom: 12,
  top: 12
};
const logEvent = (eventName, analyticsID, analytics, analyticsParams) => {
  analytics && analytics.logEvent(eventName, {
    ...(analyticsParams || {}),
    id: analyticsID
  });
};
const Touchable = props => {
  const templateContext = (0, _templateContext.useTemplateContext)();
  const {
    theme,
    vibration,
    analytics
  } = templateContext;
  const {
    analyticsID,
    analyticsParams,
    accessibilityLabel,
    onPress,
    onLongPress,
    isWithoutFeedback,
    isHighlight,
    activeOpacity,
    disabled
  } = props;
  const handlePress = (0, _react.useMemo)(() => event => {
    if (!onPress) return;
    vibration?.vibrate();
    analytics && analyticsID && logEvent(_analytics.ANALYTICS_EVENT_TYPE.PRESS, analyticsID, analytics, analyticsParams);
    onPress(event);
  }, [analytics, analyticsID, analyticsParams, onPress, vibration]);
  const handleLongPress = (0, _react.useMemo)(() => event => {
    if (!onLongPress) return;
    vibration?.vibrate();
    analytics && analyticsID && logEvent(_analytics.ANALYTICS_EVENT_TYPE.LONG_PRESS, analyticsID, analytics, analyticsParams);
    onLongPress(event);
  }, [analytics, analyticsID, analyticsParams, onLongPress, vibration]);
  if (isHighlight) {
    return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableHighlight, _extends({}, props, {
      accessibilityLabel: accessibilityLabel,
      hitSlop: hitSlop,
      underlayColor: theme.colors.gray.light,
      onPress: handlePress,
      onLongPress: handleLongPress,
      activeOpacity: activeOpacity || (disabled ? 1 : 0.85)
    }));
  }
  return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, _extends({}, props, {
    accessibilityLabel: accessibilityLabel,
    hitSlop: hitSlop,
    onPress: handlePress,
    onLongPress: handleLongPress,
    activeOpacity: isWithoutFeedback && 1 || activeOpacity || (disabled ? 1 : 0.2)
  }));
};
var _default = exports.default = Touchable;
//# sourceMappingURL=index.native.js.map