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); }
import React from "react";
import { boxStyleFunctions } from "../../../theme/src/style-functions";
import { mergeAnimateProp } from "moti/interactions";
import { usePressedState } from "../../../hooks/state/usePressedState";
import { useDisabledState } from "../../../hooks/state/useDisabledState";
import { useStyleProps } from "../../../hooks/useStyleProps";
import { useMotiWithStyleProps } from "../../../hooks/useMotiWithStyleProps";
import { MotiPressable } from "./moti-pressable";
import _ from "lodash";

// 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.memo( /*#__PURE__*/React.forwardRef(({
  children,
  onPressInDelay = 100,
  isDisabled = false,
  accessibilityLabel = "Press me!",
  accessibilityState = undefined,
  onPress = undefined,
  onPressIn = undefined,
  onPressOut = undefined,
  onLongPress = undefined,
  ...props
}, ref) => {
  props = useStyleProps(props, boxStyleFunctions);
  props = useMotiWithStyleProps(props, boxStyleFunctions);

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

  // Use State for disabled styles
  const {
    propsWithDisabledStyles
  } = useDisabledState(props, boxStyleFunctions, "basic", true, isDisabled);
  // Update props with disabled styles
  props = propsWithDisabledStyles;
  const containerStyles = {
    alignSelf: "flex-start",
    ..._.pick(props.style, STYLE_PROPS_FOR_CONTAINER)
  };
  const childStyles = _.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.createElement(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 mergeAnimateProp(interaction, props.animate);
    }
  }), children);
}));
Pressable.displayName = "Pressable";
export default Pressable;
//# sourceMappingURL=pressable.js.map