import 'package:flutter/material.dart';

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

import 'package:pweb/widgets/sidebar/destinations.dart';
import 'package:pweb/pages/payment_methods/widgets/state_view.dart';
import 'package:pweb/pages/payment_methods/payment_page/page.dart';

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


class PaymentPageBody extends StatelessWidget {
  final ValueChanged<Recipient?>? onBack;
  final Recipient? recipient;
  final Recipient? previousRecipient;
  final RecipientsProvider recipientProvider;
  final String searchQuery;
  final List<Recipient> filteredRecipients;
  final PaymentMethodsProvider methodsProvider;
  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 PaymentPageBody({
    super.key,
    required this.onBack,
    required this.recipient,
    required this.previousRecipient,
    required this.recipientProvider,
    required this.searchQuery,
    required this.filteredRecipients,
    required this.methodsProvider,
    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 loc = AppLocalizations.of(context)!;

    if (methodsProvider.isLoading) {
      return const PaymentMethodsLoadingView();
    }

    if (methodsProvider.error != null) {
      return PaymentMethodsErrorView(
        message: loc.notificationError(methodsProvider.error ?? loc.noErrorInformation),
      );
    }

    return PaymentPageContent(
      onBack: onBack,
      recipient: recipient,
      previousRecipient: previousRecipient,
      recipientProvider: recipientProvider,
      searchQuery: searchQuery,
      filteredRecipients: filteredRecipients,
      onWalletSelected: onWalletSelected,
      fallbackDestination: fallbackDestination,
      searchController: searchController,
      searchFocusNode: searchFocusNode,
      onSearchChanged: onSearchChanged,
      onRecipientSelected: onRecipientSelected,
      onRecipientCleared: onRecipientCleared,
      onSend: onSend,
    );
  }
}
