import 'package:flutter/material.dart';

import 'package:pshared/models/payment/methods/card.dart';
import 'package:pshared/models/payment/methods/crypto_address.dart';
import 'package:pshared/models/payment/methods/data.dart';
import 'package:pshared/models/payment/methods/iban.dart';
import 'package:pshared/models/payment/methods/ledger.dart';
import 'package:pshared/models/payment/methods/russian_bank.dart';
import 'package:pshared/models/payment/methods/wallet.dart';
import 'package:pshared/models/payment/type.dart';

import 'package:pweb/pages/payment_methods/add/card.dart';
import 'package:pweb/pages/payment_methods/add/crypto_address.dart';
import 'package:pweb/pages/payment_methods/add/iban.dart';
import 'package:pweb/pages/payment_methods/add/ledger.dart';
import 'package:pweb/pages/payment_methods/add/russian_bank.dart';
import 'package:pweb/pages/payment_methods/add/wallet.dart';


class PaymentMethodForm extends StatelessWidget {
  final PaymentType? selectedType;
  final ValueChanged<PaymentMethodData?> onChanged;
  final PaymentMethodData? initialData;
  final bool isEditable;

  const PaymentMethodForm({
    super.key,
    required this.selectedType,
    required this.onChanged,
    this.initialData,
    this.isEditable = true,
  });

  @override
  Widget build(BuildContext context) {
    return switch (selectedType) {
      PaymentType.card => CardFormMinimal(
        onChanged: onChanged,
        initialData: initialData as CardPaymentMethod?,
        isEditable: isEditable,
      ),
      PaymentType.iban => IbanForm(
        onChanged: onChanged,
        initialData: initialData as IbanPaymentMethod?,
        isEditable: isEditable,
      ),
      PaymentType.wallet => WalletForm(
        onChanged: onChanged,
        initialData: initialData as WalletPaymentMethod?,
        isEditable: isEditable,
      ),
      PaymentType.bankAccount => RussianBankForm(
        onChanged: onChanged,
        initialData: initialData as RussianBankAccountPaymentMethod?,
        isEditable: isEditable,
      ),
      PaymentType.externalChain => CryptoAddressForm(
        onChanged: onChanged,
        initialData: initialData as CryptoAddressPaymentMethod?,
        isEditable: isEditable,
      ),
      PaymentType.ledger => LedgerForm(
        onChanged: onChanged,
        initialData: initialData as LedgerPaymentMethod?,
        isEditable: isEditable,
      ),
      _ => const SizedBox.shrink(),
    };
  }
}
