"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MotiPressable = void 0;
var _moti = require("moti");
var _context = require("moti/build/interactions/pressable/context");
var _hoverable = require("moti/build/interactions/pressable/hoverable");
var _interactions = require("moti/interactions");
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _reactNativeReanimated = require("react-native-reanimated");
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 && Object.prototype.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; }
const MotiPressable = exports.MotiPressable = /*#__PURE__*/(0, _react.forwardRef)(function MotiPressable(props, ref) {
  const {
    animate,
    from,
    exit,
    children,
    exitTransition,
    transition: transitionProp,
    style,
    onPressOut,
    onPressIn,
    onHoverIn,
    onHoverOut,
    onKeyDown,
    onKeyUp,
    onPress,
    onLongPress,
    hitSlop,
    disabled,
    containerStyle,
    dangerouslySilenceDuplicateIdsWarning = false,
    id,
    hoveredValue,
    pressedValue,
    onLayout,
    onContainerLayout,
    accessibilityActions,
    accessibilityElementsHidden,
    accessibilityHint,
    accessibilityIgnoresInvertColors,
    accessibilityLabel,
    accessibilityLiveRegion,
    accessibilityRole,
    accessibilityState,
    accessibilityValue,
    accessibilityViewIsModal,
    accessible,
    onAccessibilityTap,
    onAccessibilityAction,
    onAccessibilityEscape,
    importantForAccessibility,
    onFocus,
    onBlur,
    href,
    testID
  } = props;
  const _hovered = (0, _reactNativeReanimated.useSharedValue)(false);
  const _pressed = (0, _reactNativeReanimated.useSharedValue)(false);
  const hovered = hoveredValue || _hovered;
  const pressed = pressedValue || _pressed;
  const interaction = (0, _reactNativeReanimated.useDerivedValue)(() => ({
    hovered: hovered.value,
    pressed: pressed.value
  }), [hovered, pressed]);
  const transition = (0, _reactNativeReanimated.useDerivedValue)(() => {
    if (typeof transitionProp === "function") {
      return transitionProp(interaction.value);
    }
    return transitionProp || {};
  }, [transitionProp, interaction]);
  const __state = (0, _reactNativeReanimated.useDerivedValue)(() => {
    if (typeof animate === "function") {
      return animate(interaction.value);
    }
    return animate;
  }, [animate, interaction]);
  const state = (0, _react.useMemo)(() => ({
    __state
  }), [__state]);
  const updateInteraction = (event, enabled, callback) => () => {
    "worklet";

    if (event === "hovered") {
      hovered.value = enabled;
    } else if (event === "pressed") {
      pressed.value = enabled;
    }
    if (callback) {
      (0, _reactNativeReanimated.runOnJS)(callback)();
    }
  };
  const child = /*#__PURE__*/_react.default.createElement(_moti.MotiView, {
    from: from,
    exit: exit,
    transition: transition,
    exitTransition: exitTransition,
    state: state,
    style: style,
    onLayout: onLayout
  }, typeof children == "function" ? children(interaction) : children);
  let node;
  // if (Platform.OS === 'web' || Platform.OS === 'android') {
  node = /*#__PURE__*/_react.default.createElement(_hoverable.Hoverable, {
    onHoverIn: updateInteraction("hovered", true, onHoverIn),
    onHoverOut: updateInteraction("hovered", false, onHoverOut),
    childRef: ref
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Pressable, {
    onLongPress: onLongPress,
    hitSlop: hitSlop,
    disabled: disabled,
    style: containerStyle,
    onPress: onPress,
    onPressIn: updateInteraction("pressed", true, onPressIn),
    onPressOut: updateInteraction("pressed", false, onPressOut),
    ref: ref,
    onLayout: onContainerLayout,
    accessibilityActions: accessibilityActions,
    accessibilityElementsHidden: accessibilityElementsHidden,
    accessibilityHint: accessibilityHint,
    accessibilityIgnoresInvertColors: accessibilityIgnoresInvertColors,
    accessibilityLabel: accessibilityLabel,
    accessibilityLiveRegion: accessibilityLiveRegion,
    accessibilityRole: accessibilityRole,
    accessibilityState: accessibilityState,
    accessibilityValue: accessibilityValue,
    accessibilityViewIsModal: accessibilityViewIsModal,
    accessible: accessible,
    onAccessibilityTap: onAccessibilityTap,
    onAccessibilityAction: onAccessibilityAction,
    onAccessibilityEscape: onAccessibilityEscape,
    importantForAccessibility: importantForAccessibility,
    testID: testID
    // @ts-expect-error RNW types
    ,
    onKeyDown: onKeyDown,
    onKeyUp: onKeyUp,
    onFocus: onFocus,
    onBlur: onBlur,
    href: href
  }, child));
  const context = (0, _interactions.useMotiPressableContext)();
  if (!dangerouslySilenceDuplicateIdsWarning && id && context?.containers && id in context.containers) {
    console.error(`[MotiPressable] Duplicate id ${id} used. This means that you incorrectly placed a <MotiPressable id="${id}" /> component inside another one with the same id.

To silence this warning without solving the actual issue, you can use the dangerouslySilenceDuplicateIdsWarning prop. But you should probably refactor your code instead.`);
  }
  return /*#__PURE__*/_react.default.createElement(_context.MotiPressableContext.Provider, {
    value: (0, _react.useMemo)(() => {
      const interactions = {
        containers: {
          ...context?.containers,
          [_context.INTERACTION_CONTAINER_ID]: interaction
        }
      };
      if (id) {
        interactions.containers[id] = interaction;
      }
      return interactions;
    }, [context?.containers, id, interaction])
  }, node);
});
//# sourceMappingURL=moti-pressable.js.map