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

import 'package:provider/provider.dart';

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

import 'package:pweb/pages/dashboard/buttons/balance/amount.dart';
import 'package:pweb/pages/payout_page/wallet/edit/fields/shared/copyable_value_row.dart';
import 'package:pweb/widgets/refresh_balance/wallet.dart';


class WalletSection extends StatelessWidget {
  final Wallet wallet;

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

  @override
  Widget build(BuildContext context) {
    final depositAddress = wallet.depositAddress?.trim();
    final hasDepositAddress =
        depositAddress != null && depositAddress.isNotEmpty;
    final copyAddress = hasDepositAddress ? depositAddress : '';

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Expanded(
              child: BalanceAmount(
                wallet: wallet,
                onToggleMask: () {
                  context.read<WalletsController>().toggleBalanceMask(
                    wallet.id,
                  );
                },
              ),
            ),
            WalletBalanceRefreshButton(walletRef: wallet.id),
          ],
        ),
        const SizedBox(height: 8),
        CopyableValueRow(
          value: hasDepositAddress ? depositAddress : '-',
          canCopy: hasDepositAddress,
          onCopy: hasDepositAddress
              ? () {
                  Clipboard.setData(ClipboardData(text: copyAddress));
                }
              : null,
        ),
      ],
    );
  }
}
