content: import 'package:expenz/models/expence_model.dart';
  import 'package:expenz/models/income_model.dart';
  import 'package:expenz/utils/colors.dart';
  import 'package:fl_chart/fl_chart.dart';
  import 'package:flutter/material.dart';
  
  class Chart extends StatefulWidget {
    final Map<ExpenseCategory, double> expenseCategoryTotals;
    final Map<IncomeCategory, double> incomeCategoryTotals;
    final bool isExpense;
  
    const Chart({
      Key? key,
      required this.expenseCategoryTotals,
      required this.incomeCategoryTotals,
      required this.isExpense,
    }) : super(key: key);
  
    @override
    State<Chart> createState() => _ChartState();
  }
  
  class _ChartState extends State<Chart> {
    List<PieChartSectionData> getSections() {
      if (widget.isExpense) {
        return [
          PieChartSectionData(
            color: expenseCategoryColors[ExpenseCategory.food],
            value: widget.expenseCategoryTotals[ExpenseCategory.health] ?? 0,
            showTitle: false,
            radius: 60,
          ),
          PieChartSectionData(
            color: expenseCategoryColors[ExpenseCategory.shopping],
            value: widget.expenseCategoryTotals[ExpenseCategory.shopping] ?? 0,
            showTitle: false,
            radius: 60,
          ),
          PieChartSectionData(
            color: expenseCategoryColors[ExpenseCategory.transport],
            value: widget.expenseCategoryTotals[ExpenseCategory.transport] ?? 0,
            showTitle: false,
            radius: 60,
          ),
          PieChartSectionData(
            color: expenseCategoryColors[ExpenseCategory.subscription],
            value:
                widget.expenseCategoryTotals[ExpenseCategory.subscription] ?? 0,
            showTitle: false,
            radius: 60,
          ),
          PieChartSectionData(
            color: expenseCategoryColors[ExpenseCategory.food],
            value: widget.expenseCategoryTotals[ExpenseCategory.food] ?? 0,
            showTitle: false,
            radius: 60,
          ),
        ];
      } else {
        return [
          PieChartSectionData(
            color: incomeCategoryColors[IncomeCategory.salary],
            value: widget.incomeCategoryTotals[IncomeCategory.salary] ?? 0,
            showTitle: false,
            radius: 60,
          ),
          PieChartSectionData(
            color: incomeCategoryColors[IncomeCategory.freelance],
            value: widget.incomeCategoryTotals[IncomeCategory.freelance] ?? 0,
            showTitle: false,
            radius: 60,
          ),
          PieChartSectionData(
            color: incomeCategoryColors[IncomeCategory.passive],
            value: widget.incomeCategoryTotals[IncomeCategory.passive] ?? 0,
            showTitle: false,
            radius: 60,
          ),
          PieChartSectionData(
            color: incomeCategoryColors[IncomeCategory.freelance],
            value: widget.incomeCategoryTotals[IncomeCategory.sales] ?? 0,
            showTitle: false,
            radius: 60,
          ),
        ];
      }
    }
  
    @override
    Widget build(BuildContext context) {
      final PieChartData pieChartData = PieChartData(
        sectionsSpace: 0,
        centerSpaceRadius: 70,
        startDegreeOffset: -90,
        sections: getSections(),
        borderData: FlBorderData(show: false),
      );
  
      return Container(
        height: 250,
        padding: const EdgeInsets.all(16),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16),
        ),
        child: Stack(
          alignment: Alignment.center,
          children: [
            PieChart(
              pieChartData,
            ),
            const Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  "70%",
                  style: TextStyle(
                    color: kBlack,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(height: 8),
                Text(
                  "of 100%",
                  style: TextStyle(
                    color: Colors.grey,
                  ),
                )
              ],
            ),
          ],
        ),
      );
    }
  }
  