import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:pshared/controllers/balance_mask/ledger_accounts.dart';
import 'package:pshared/models/ledger/account.dart';

import 'package:pweb/pages/payout_page/wallet/edit/fields/ledger/balance_formatter.dart';


class LedgerBalanceAmount extends StatelessWidget {
  final LedgerAccount account;

  const LedgerBalanceAmount({super.key, required this.account});

  @override
  Widget build(BuildContext context) {
    final textTheme = Theme.of(context).textTheme;
    final colorScheme = Theme.of(context).colorScheme;

    return Consumer<LedgerBalanceMaskController>(
      builder: (context, controller, _) {
        final isMasked = controller.isBalanceMasked(account.ledgerAccountRef);
        final balance = isMasked
            ? LedgerBalanceFormatter.formatMasked(account)
            : LedgerBalanceFormatter.format(context, account);

        return Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              balance,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: textTheme.headlineSmall?.copyWith(
                fontWeight: FontWeight.bold,
                color: colorScheme.primary,
              ),
            ),
            const SizedBox(width: 12),
            GestureDetector(
              onTap: () {
                controller.toggleBalanceMask(account.ledgerAccountRef);
              },
              child: Icon(
                isMasked ? Icons.visibility_off : Icons.visibility,
                size: 24,
                color: colorScheme.primary,
              ),
            ),
          ],
        );
      },
    );
  }
}
