import 'package:flutter/material.dart';

class SecondaryTextComponent extends StatelessWidget {
  final String title;
  final int? rank;

  const SecondaryTextComponent(this.title, this.rank,{Key? key,}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final TextStyle textStyle = TextStyle(
      color: Colors.grey.shade500,
      fontSize: 14,
      fontWeight: FontWeight.bold,
    );

    Widget textWidget;

    if (rank != null) {
      textWidget = Container(
        decoration: BoxDecoration(
          color: getRankColor(rank!),
          borderRadius: BorderRadius.circular(15),
        ),
        padding: const EdgeInsets.all(8),
        child: Row(
          children: [
            Text(
              '$rank.',
              style: rank! <= 3 ? textStyle.copyWith(color: Colors.white) :textStyle.copyWith(color: Colors.grey),
            ),
            const SizedBox(width: 4),
            Text(
              title.toString(),
              style: rank! <= 3 ? textStyle.copyWith(color: Colors.white) :textStyle.copyWith(color: Colors.grey),
            ),
          ],
        ),
      );
    } else {
      textWidget = Text(
        title.toString(),
        style: textStyle,
      );
    }

    return Padding(
      padding: const EdgeInsets.only(top: 8.0),
      child: textWidget,
    );
  }

  Color getRankColor(int rank) {
    if (rank == 1) {
      return Colors.amber;
    } else if (rank == 2) {
      return Colors.grey;
    } else if (rank == 3) {
      return Colors.brown;
    } else {
      return Colors.transparent;
    }
  }
}
