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 List<PaymentType> types;
  final Set<PaymentType> disabledTypes;
  final ValueChanged<PaymentType?> onChanged;

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

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

    return DropdownButtonFormField<PaymentType>(
      initialValue: value,
      decoration: InputDecoration(labelText: l10n.paymentType),
      items: types.map((type) {
        final label = getPaymentTypeLabel(context, type);
        final isDisabled = disabledTypes.contains(type);
        final effectiveLabel = isDisabled ? '$label - ${l10n.paymentMethodComingSoon}' : label;
        return DropdownMenuItem(
          value: type,
          enabled: !isDisabled,
          child: Text(effectiveLabel),
        );
      }).toList(),
      onChanged: onChanged,
      validator: (val) => val == null ? l10n.selectPaymentType : null,
    );
  }
}
