import 'package:flutter/material.dart';

import 'package:syncfusion_flutter_charts/charts.dart';

import 'package:pweb/pages/report/charts/payout_volumes/aggregator.dart';
import 'package:pweb/pages/report/charts/payout_volumes/palette.dart';


class PayoutVolumesPieChart extends StatelessWidget {
  final List<CurrencyTotal> totals;

  const PayoutVolumesPieChart({super.key, required this.totals});

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final palette = payoutVolumesPalette(theme);

    return SfCircularChart(
      legend: Legend(isVisible: false),
      tooltipBehavior: TooltipBehavior(enable: true),
      series: <PieSeries<CurrencyTotal, String>>[
        PieSeries<CurrencyTotal, String>(
          dataSource: totals,
          xValueMapper: (item, _) => item.currency,
          yValueMapper: (item, _) => item.amount,
          dataLabelMapper: (item, _) => item.currency,
          dataLabelSettings: const DataLabelSettings(
            isVisible: true,
            labelPosition: ChartDataLabelPosition.inside,
          ),
          pointColorMapper: (item, index) =>
              palette[index % palette.length],
          radius: '100%',
        ),
      ],
    );
  }
}
