"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _styleFunctions = require("../../../theme/src/style-functions");
var _interactions = require("moti/interactions");
var _usePressedState = require("../../../hooks/state/usePressedState");
var _useDisabledState = require("../../../hooks/state/useDisabledState");
var _useStyleProps = require("../../../hooks/useStyleProps");
var _useMotiWithStyleProps = require("../../../hooks/useMotiWithStyleProps");
var _motiPressable = require("./moti-pressable");
var _lodash = _interopRequireDefault(require("lodash"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
// Define the properties for the BasePressable component

const STYLE_PROPS_FOR_CONTAINER = ["width", "height", "flex", "alignSelf", "position", "top", "right", "bottom", "left"];

/**
 * Pressable is a functional component use to make interactive elements such as buttons, links, and more.
 * @returns A MotiPressable component with updated props and styles.
 */
const Pressable = /*#__PURE__*/_react.default.memo( /*#__PURE__*/_react.default.forwardRef(({
  children,
  onPressInDelay = 100,
  isDisabled = false,
  accessibilityLabel = "Press me!",
  accessibilityState = undefined,
  onPress = undefined,
  onPressIn = undefined,
  onPressOut = undefined,
  onLongPress = undefined,
  ...props
}, ref) => {
  props = (0, _useStyleProps.useStyleProps)(props, _styleFunctions.boxStyleFunctions);
  props = (0, _useMotiWithStyleProps.useMotiWithStyleProps)(props, _styleFunctions.boxStyleFunctions);

  // Use State for dynamic styles
  const {
    setPressed,
    propsWithPressedStyles
  } = (0, _usePressedState.usePressedState)(props, _styleFunctions.boxStyleFunctions);
  // Update props with pressed styles
  props = propsWithPressedStyles;

  // Use State for disabled styles
  const {
    propsWithDisabledStyles
  } = (0, _useDisabledState.useDisabledState)(props, _styleFunctions.boxStyleFunctions, "basic", true, isDisabled);
  // Update props with disabled styles
  props = propsWithDisabledStyles;
  const containerStyles = {
    alignSelf: "flex-start",
    ..._lodash.default.pick(props.style, STYLE_PROPS_FOR_CONTAINER)
  };
  const childStyles = _lodash.default.omit(props.style || {}, STYLE_PROPS_FOR_CONTAINER);

  // Methods to handle local pressable state
  const onPressInHandler = () => {
    setPressed(true);
    if (onPressIn) onPressIn();
  };
  const onPressOutHandler = () => {
    setPressed(false);
    if (onPressOut) onPressOut();
  };
  return /*#__PURE__*/_react.default.createElement(_motiPressable.MotiPressable, _extends({
    ref: ref,
    accessibilityLabel: accessibilityLabel,
    onPress: !isDisabled ? onPress : undefined,
    onPressIn: !isDisabled ? onPressInHandler : undefined,
    onPressOut: !isDisabled ? onPressOutHandler : undefined,
    onLongPress: !isDisabled ? onLongPress : undefined,
    disabled: isDisabled,
    transition: {
      duration: 50
    }
  }, props, {
    styles: childStyles,
    containerStyle: containerStyles,
    accessibilityRole: "button",
    animate: interaction => {
      "worklet";

      // Merge the interaction and animate props
      return (0, _interactions.mergeAnimateProp)(interaction, props.animate);
    }
  }), children);
}));
Pressable.displayName = "Pressable";
var _default = exports.default = Pressable;
//# sourceMappingURL=pressable.js.map