import React from "react";
import { IconButton as NIconButton, IIconButtonProps } from "native-base";
import debounce from "lodash/debounce";
import type { GestureResponderEvent } from "react-native";

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

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

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

export default IconButton;
