import 'package:flutter/material.dart';

import 'package:pshared/models/payment/wallet.dart';
import 'package:pshared/models/recipient/recipient.dart';
import 'package:pshared/provider/recipient/provider.dart';

import 'package:pweb/pages/dashboard/payouts/form.dart';
import 'package:pweb/pages/payment_methods/payment_page/back_button.dart';
import 'package:pweb/pages/payment_methods/payment_page/header.dart';
import 'package:pweb/pages/payment_methods/payment_page/method_selector.dart';
import 'package:pweb/pages/payment_methods/payment_page/send_button.dart';
import 'package:pweb/pages/payment_methods/widgets/payment_info_section.dart';
import 'package:pweb/pages/payment_methods/widgets/recipient_section.dart';
import 'package:pweb/pages/payment_methods/widgets/section_title.dart';
import 'package:pweb/utils/dimensions.dart';
import 'package:pweb/widgets/sidebar/destinations.dart';

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


class PaymentPageContent extends StatelessWidget {
  final ValueChanged<Recipient?>? onBack;
  final Recipient? recipient;
  final RecipientsProvider recipientProvider;
  final ValueChanged<Wallet> onWalletSelected;
  final PayoutDestination fallbackDestination;
  final TextEditingController searchController;
  final FocusNode searchFocusNode;
  final ValueChanged<String> onSearchChanged;
  final ValueChanged<Recipient> onRecipientSelected;
  final VoidCallback onRecipientCleared;
  final VoidCallback onSend;

  const PaymentPageContent({
    super.key,
    required this.onBack,
    required this.recipient,
    required this.recipientProvider,
    required this.onWalletSelected,
    required this.fallbackDestination,
    required this.searchController,
    required this.searchFocusNode,
    required this.onSearchChanged,
    required this.onRecipientSelected,
    required this.onRecipientCleared,
    required this.onSend,
  });

  @override
  Widget build(BuildContext context) {
    final dimensions = AppDimensions();
    final loc = AppLocalizations.of(context)!;
    
    return Align(
      alignment: Alignment.topCenter,
      child: ConstrainedBox(
        constraints: BoxConstraints(maxWidth: dimensions.maxContentWidth),
        child: Material(
          elevation: dimensions.elevationSmall,
          borderRadius: BorderRadius.circular(dimensions.borderRadiusMedium),
          color: Theme.of(context).colorScheme.onSecondary,
          child: Padding(
            padding: EdgeInsets.all(dimensions.paddingLarge),
            child: SingleChildScrollView(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  PaymentBackButton(
                    onBack: onBack,
                    recipient: recipient,
                    fallbackDestination: fallbackDestination,
                  ),
                  SizedBox(height: dimensions.paddingSmall),
                  PaymentHeader(),
                  SizedBox(height: dimensions.paddingXXLarge),
                  SectionTitle(loc.sourceOfFunds),
                  SizedBox(height: dimensions.paddingSmall),
                  PaymentMethodSelector(
                    onMethodChanged: onWalletSelected,
                  ),
                  SizedBox(height: dimensions.paddingXLarge),
                  RecipientSection(
                    recipient: recipient,
                    dimensions: dimensions,
                    recipientProvider: recipientProvider,
                    searchController: searchController,
                    searchFocusNode: searchFocusNode,
                    onSearchChanged: onSearchChanged,
                    onRecipientSelected: onRecipientSelected,
                    onRecipientCleared: onRecipientCleared,
                  ),
                  SizedBox(height: dimensions.paddingXLarge),
                  PaymentInfoSection(dimensions: dimensions),
                  SizedBox(height: dimensions.paddingLarge),
                  const PaymentFormWidget(),
                  SizedBox(height: dimensions.paddingXXXLarge),
                  SendButton(onPressed: onSend),
                  SizedBox(height: dimensions.paddingLarge),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
