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:pweb/models/state/visibility.dart';
import 'package:pweb/pages/dashboard/buttons/balance/amount.dart';
import 'package:pweb/pages/payout_page/wallet/currency_symbol_avatar.dart';
import 'package:pweb/widgets/refresh_balance/wallet.dart';

import 'package:pweb/generated/i18n/app_localizations.dart';


class WalletCard extends StatelessWidget {
  final Wallet wallet;
  final VoidCallback onTap;

  const WalletCard({super.key, required this.wallet, required this.onTap});

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

    return Card(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      elevation: theme.cardTheme.elevation ?? 4,
      color: theme.colorScheme.onSecondary,
      child: InkWell(
        borderRadius: BorderRadius.circular(12),
        onTap: onTap,
        child: Container(
          padding: const EdgeInsets.only(left: 50, top: 16, bottom: 16),
          child: Row(
            spacing: 3,
            children: [
              CurrencySymbolAvatar(wallet: wallet),
              const SizedBox(width: 16),
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        BalanceAmount(
                          wallet: wallet,
                          onToggleMask: () {
                            context.read<WalletsController>().toggleBalanceMask(
                              wallet.id,
                            );
                          },
                        ),
                        WalletBalanceRefreshButton(
                          walletRef: wallet.id,
                          iconOnly: VisibilityState.hidden,
                        ),
                      ],
                    ),
                    Text(
                      AppLocalizations.of(context)!.paymentTypeCryptoWallet,
                      style: theme.textTheme.bodyLarge!.copyWith(
                        fontWeight: FontWeight.w600,
                        color: theme.colorScheme.onSurface,
                      ),
                    ),
                    if (wallet.tokenSymbol != null) ...[
                      const SizedBox(height: 4),
                      Text(
                        wallet.tokenSymbol!,
                        style: theme.textTheme.bodyMedium?.copyWith(
                          color: theme.colorScheme.onSurfaceVariant,
                        ),
                      ),
                    ],
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
