import 'package:hmg_patient_app/widgets/data_display/text.dart';
import 'package:flutter/material.dart';

class StarRating extends StatelessWidget {

  final double totalAverage;
  final double size;
  final int totalCount;
  final bool forceStars;

  StarRating({Key? key, this.totalAverage= 0.0, this.size= 16.0, this.totalCount=5, this.forceStars = false}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget> [
          if (!forceStars && (totalAverage==null || totalAverage==0))
            Texts("New", style: "caption"),
          if (forceStars || (totalAverage!=null && totalAverage>0))
            ...List.generate(5, (index) =>
                Padding(
                  padding: EdgeInsets.only(right: 1.0),
                  child: Icon(
                      (index+1) <= (totalAverage ?? 0) ? Icons.star : Icons.star_border_outlined,
                      size: size,
                      color: (index+1) <= (totalAverage ?? 0) ? Color.fromRGBO(255, 186, 0, 1.0) : Theme.of(context).hintColor
                  ),
                )
            ),
          if (totalCount!=null)
            SizedBox(width: 5.0),
          if (totalCount!=null)
            Texts("("+totalCount.toString()+")", style: "overline", color: Colors.grey[400]!,)
        ]
    );
  }
}