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

type ViewRef = View;

const RsBadge = forwardRef<ViewRef, RsSkinlessBadgeProps>(
  ({ count, visible = true, children, style }, ref) => {
    return (
      <View ref={ref} style={style}>
        {children}
        {visible && count !== undefined && count > 0 ? (
          <View style={{ position: 'absolute', top: 0, right: 0 }}>
            <Text>{count}</Text>
          </View>
        ) : null}
      </View>
    );
  }
);

RsBadge.displayName = 'RsBadge';

export default RsBadge;
