import React from 'react';
import { Pressable as PressableNative, PressableProps, Vibration } from 'react-native';

const androidRippleConfig = { color: '#eee' };

export const Pressable: React.FunctionComponent<PressableProps & { ripple?: boolean }> = (props) => {
   const { children, ripple } = props as any;

   // Todo: verificar se foi enviado onPress, se não, não vibrar som
   return (
      <PressableNative
         delayLongPress={200}
         android_ripple={ripple ? { color: '#eee', borderless: false } : {}}
         {...props}
         onPress={(ev) => {
            Vibration.vibrate(25);
            if (props.onPress) props.onPress(ev);
         }}
         onLongPress={(ev) => {
            Vibration.vibrate(25);
            if (props.onLongPress) props.onLongPress(ev);
         }}
      >
         {typeof children === 'function' ? ({ pressed }) => children({ pressed }) : children}
      </PressableNative>
   );
};
