import 'package:flutter/material.dart';

import 'package:pshared/models/payment/type.dart';

import 'package:pweb/utils/payment/label.dart';

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


class PaymentMethodTypeSelector extends StatelessWidget {
  final PaymentType? value;
  final ValueChanged<PaymentType?> onChanged;

  const PaymentMethodTypeSelector({
    super.key,
    required this.value,
    required this.onChanged,
  });

  @override
  Widget build(BuildContext context) {
    final l10n = AppLocalizations.of(context)!;

    return DropdownButtonFormField<PaymentType>(
      initialValue: value,
      decoration: InputDecoration(labelText: l10n.paymentType),
      items: PaymentType.values.map((type) {
        final label = getPaymentTypeLabel(context, type);
        return DropdownMenuItem(value: type, child: Text(label));
      }).toList(),
      onChanged: onChanged,
      validator: (val) => val == null ? l10n.selectPaymentType : null,
    );
  }
}