import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:pshared/controllers/balance_mask/wallets.dart';
import 'package:pshared/models/payment/wallet.dart';
import 'package:pshared/utils/currency.dart';


class BalanceAmount extends StatelessWidget {
  final Wallet wallet;
  final VoidCallback onToggleMask;

  const BalanceAmount({
    super.key,
    required this.wallet,
    required this.onToggleMask,
  });

  static const double _iconSpacing = 12.0;
  static const double _iconSize = 24.0;

  @override
  Widget build(BuildContext context) {
    final textTheme = Theme.of(context).textTheme;
    final colorScheme = Theme.of(context).colorScheme;
    final currencyBalance = currencyCodeToSymbol(wallet.currency);
    final wallets = context.watch<WalletsController>();
    final isMasked = wallets.isBalanceMasked(wallet.id);

    return Row(
      children: [
        Text(
          isMasked ? '•••• $currencyBalance' : '${amountToString(wallet.balance)} $currencyBalance',
          style: textTheme.headlineSmall?.copyWith(
            fontWeight: FontWeight.bold,
            color: colorScheme.onSurface,
          ),
        ),
        const SizedBox(width: _iconSpacing),
        GestureDetector(
          onTap: onToggleMask,
          child: Icon(
            isMasked ? Icons.visibility_off : Icons.visibility,
            size: _iconSize,
            color: colorScheme.onSurface,
          ),
        ),
      ],
    );
  }
}
