content: import 'package:fl_chart/fl_chart.dart';
  import 'package:flutter/material.dart';
  import 'package:logger/utils/locale.dart';
  
  class WeekdayBarChart extends StatelessWidget {
    final List<double> weekdayPercentages;
  
    const WeekdayBarChart({super.key, required this.weekdayPercentages});
  
    @override
    Widget build(BuildContext context) {
      final List<String> weekdays = AppLocaleHelpers.getWeekdays(context);
  
      final double maxY =
          (weekdayPercentages.reduce((a, b) => a > b ? a : b) * 1.2);
  
      return AspectRatio(
        aspectRatio: 1.2,
        child: BarChart(
          BarChartData(
            alignment: BarChartAlignment.spaceAround,
            maxY: maxY,
            barTouchData: BarTouchData(
              enabled: true,
              touchTooltipData: BarTouchTooltipData(
                getTooltipItem: (group, groupIndex, rod, rodIndex) {
                  final value = rod.toY;
                  final weekday = weekdays[group.x.toInt()];
                  return BarTooltipItem(
                    '$weekday\n${value.round()}%',
                    const TextStyle(color: Colors.white),
                  );
                },
              ),
            ),
            titlesData: FlTitlesData(
              leftTitles: AxisTitles(
                sideTitles: SideTitles(
                  showTitles: true,
                  reservedSize: 40,
                  getTitlesWidget: (value, meta) {
                    return Text('${value.round()}%');
                  },
                ),
              ),
              rightTitles: AxisTitles(
                sideTitles: SideTitles(showTitles: false),
              ),
              topTitles: AxisTitles(
                sideTitles: SideTitles(showTitles: false),
              ),
              bottomTitles: AxisTitles(
                sideTitles: SideTitles(
                  showTitles: true,
                  getTitlesWidget: (value, meta) {
                    int index = value.toInt();
                    if (index >= 0 && index < weekdays.length) {
                      return Text(weekdays[index]);
                    }
                    return const Text('');
                  },
                ),
              ),
            ),
            borderData: FlBorderData(show: false),
            gridData: FlGridData(show: false),
            barGroups: List.generate(weekdayPercentages.length, (i) {
              return BarChartGroupData(
                x: i,
                barRods: [
                  BarChartRodData(
                    toY: weekdayPercentages[i],
                    color: Colors.blueAccent,
                    width: 20,
                    borderRadius: BorderRadius.circular(4),
                  ),
                ],
              );
            }),
          ),
        ),
      );
    }
  }
  