import React from "react";
import { Pressable as NPressable, IPressableProps } from "native-base";
import debounce from "lodash.debounce";
import type { GestureResponderEvent } from "react-native";

export const Pressable: React.FC<
  IPressableProps & {
    debounceDuration?: number;
  }
> = (props) => {
  const { onPress, debounceDuration, ...rest } = props;

  const onPressDebounce = debounce(
    (event: GestureResponderEvent) => onPress?.(event),
    debounceDuration ?? 500,
    {
      leading: true,
      trailing: false,
    }
  );

  return <NPressable onPress={onPressDebounce} {...rest} />;
};

export default Pressable;
