import 'package:flutter/material.dart';

import 'package:pshared/models/payment/methods/data.dart';
import 'package:pshared/models/payment/type.dart';
import 'package:pshared/models/recipient/payment_method_draft.dart';

import 'package:pweb/pages/payment_methods/form.dart';


class PaymentMethodPanelEntryForm extends StatelessWidget {
  final PaymentType selectedType;
  final int selectedIndex;
  final RecipientMethodDraft entry;
  final bool isEditable;
  final ValueChanged<PaymentMethodData>? onChanged;

  const PaymentMethodPanelEntryForm({
    super.key,
    required this.selectedType,
    required this.selectedIndex,
    required this.entry,
    required this.isEditable,
    this.onChanged,
  });

  @override
  Widget build(BuildContext context) {
    return PaymentMethodForm(
      key: ValueKey(
        '${selectedType.name}-${entry.existing?.id ?? selectedIndex}-form',
      ),
      selectedType: selectedType,
      initialData: entry.data,
      isEditable: isEditable,
      onChanged: (data) {
        if (data == null) return;
        onChanged?.call(data);
      },
    );
  }
}
