import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

class AccountCounter extends StatelessWidget {
  final Map<String, double> accountsTotals;

  const AccountCounter({super.key, required this.accountsTotals});

  List<Row> _renderAccountTotals(BuildContext context) {
    return accountsTotals.entries.toList().map((entry) => Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Flexible(
          child: Text(
            entry.key,
            overflow: TextOverflow.ellipsis,
          )
        ),
        Text(
          NumberFormat('#######.00 €', 'fr_FR').format(entry.value),
          style: TextStyle(
            fontFamily: 'NovaMono',
            fontSize: 15,
            color: entry.value > 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error
        )),
      ],
    )).toList();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(10),
      margin: const EdgeInsets.only(bottom: 10),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(15),
        color: Theme.of(context).colorScheme.primaryContainer,
      ),
      alignment: Alignment.centerRight,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.end,
        children: _renderAccountTotals(context),
      ),
    );
  }
}