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

type ViewRef = View;

const RsToggleButton = forwardRef<ViewRef, RsSkinlessToggleButtonProps>(
  ({ value, onToggle, disabled, style, accessibilityLabel }, ref) => {
    return (
      <Pressable
        ref={ref}
        onPress={() => onToggle(!value)}
        disabled={disabled}
        style={style}
        accessibilityRole="switch"
        accessibilityLabel={accessibilityLabel}
        accessibilityState={{ checked: value, disabled }}
      />
    );
  }
);

RsToggleButton.displayName = 'RsToggleButton';

export default RsToggleButton;
