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

import 'package:provider/provider.dart';

import 'package:pshared/provider/payment/wallets.dart';

import 'package:pweb/pages/dashboard/buttons/balance/amount.dart';
import 'package:pweb/widgets/wallet_balance_refresh_button.dart';


class WalletEditFields extends StatelessWidget {
  const WalletEditFields({super.key});

  @override
  Widget build(BuildContext context) {
    return Consumer<WalletsProvider>(
      builder: (context, provider, child) {
        final wallet = provider.selectedWallet;
        
        if (wallet == null) {
          return SizedBox.shrink();
        }

        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Expanded(
                  child: BalanceAmount(
                    wallet: wallet,
                    onToggleVisibility: () {
                      context.read<WalletsProvider>().toggleVisibility(wallet.id);
                    },
                  ),
                ),
                WalletBalanceRefreshButton(walletId: wallet.id),
              ],
            ),
            const SizedBox(height: 8),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(wallet.walletUserID, style: Theme.of(context).textTheme.bodyLarge),
                IconButton(
                  icon: Icon(Icons.copy), 
                  iconSize: 18,
                  onPressed: () => Clipboard.setData(ClipboardData(text: wallet.walletUserID)),
                ),
              ],
            ),
          ],
        );
      },
    );
  }
}
