import 'package:flutter/material.dart';

import 'package:pshared/models/payment/chain_network.dart';
import 'package:pshared/utils/currency.dart';
import 'package:pshared/utils/l10n/chain.dart';
import 'package:pshared/models/payment/wallet.dart';

import 'package:pweb/pages/wallet_top_up/details.dart';
import 'package:pweb/pages/wallet_top_up/header.dart';
import 'package:pweb/pages/wallet_top_up/meta.dart';
import 'package:pweb/utils/dimensions.dart';


class WalletTopUpContent extends StatelessWidget {
  final Wallet wallet;
  final VoidCallback onBack;

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

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

    final address = _resolveAddress(wallet);
    final network = wallet.network;
    final networkLabel = (network == null || network == ChainNetwork.unspecified)
      ? null
      : network.localizedName(context);
    final assetLabel = wallet.tokenSymbol ?? currencyCodeToSymbol(wallet.currency);

    return Align(
      alignment: Alignment.topCenter,
      child: SingleChildScrollView(
        child: ConstrainedBox(
          constraints: const BoxConstraints(maxWidth: 960),
          child: Padding(
            padding: EdgeInsets.symmetric(vertical: dimensions.paddingLarge),
            child: Material(
              elevation: dimensions.elevationSmall,
              color: theme.colorScheme.onSecondary,
              borderRadius: BorderRadius.circular(dimensions.borderRadiusMedium),
              child: Padding(
                padding: EdgeInsets.all(dimensions.paddingXLarge),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    WalletTopUpHeader(
                      onBack: onBack,
                      tokenSymbol: assetLabel,
                    ),
                    SizedBox(height: dimensions.paddingLarge),
                    WalletTopUpMeta(
                      assetLabel: assetLabel,
                      network: networkLabel,
                      walletId: wallet.walletUserID,
                    ),
                    SizedBox(height: dimensions.paddingXLarge),
                    WalletTopUpDetails(
                      address: address,
                      dimensions: dimensions,
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

  String? _resolveAddress(Wallet wallet) {
    final candidate = wallet.depositAddress?.trim();
    if (candidate == null || candidate.isEmpty) return null;
    return candidate;
  }
}
