import { forwardRef } from 'react';
import { Pressable, Text, View } from 'react-native';
import type { RsSkinlessButtonProps } from '../../types/props';

type ViewRef = View;

const RsButton = forwardRef<ViewRef, RsSkinlessButtonProps>(
  (
    {
      label,
      children,
      onPress,
      onLongPress,
      disabled,
      style,
      labelStyle,
      accessibilityLabel,
    },
    ref
  ) => {
    return (
      <Pressable
        ref={ref}
        onPress={onPress}
        onLongPress={onLongPress}
        disabled={disabled}
        style={style}
        accessibilityRole="button"
        accessibilityLabel={accessibilityLabel}
        accessibilityState={{ disabled }}
      >
        {children ?? (label ? <Text style={labelStyle}>{label}</Text> : null)}
      </Pressable>
    );
  }
);

RsButton.displayName = 'RsButton';

export default RsButton;
