import 'package:flutter/material.dart';

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

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


class PaymentTypeSelector extends StatelessWidget {
  final MethodMap availableTypes;
  final PaymentType selectedType;
  final ValueChanged<PaymentType> onSelected;
  final Set<PaymentType> disabledTypes;

  const PaymentTypeSelector({
    super.key,
    required this.availableTypes,
    required this.selectedType,
    required this.onSelected,
    this.disabledTypes = const {},
  });

  static const double _chipSpacing = 12.0;
  static const double _chipBorderRadius = 10.0;

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return Wrap(
      spacing: _chipSpacing,
      runSpacing: _chipSpacing,
      children: availableTypes.keys.map((type) {
        final isSelected = selectedType == type;
        final isDisabled = disabledTypes.contains(type);
        final labelColor = isSelected
            ? theme.colorScheme.onPrimary
            : theme.colorScheme.onSurface.withValues(alpha: isDisabled ? 0.55 : 1.0);

        return ChoiceChip(
          label: Text(
            getPaymentTypeLabel(context, type),
            style: theme.textTheme.titleMedium!.copyWith(
              color: labelColor,
            ),
          ),
          selected: isSelected,
          showCheckmark: false,
          selectedColor: theme.colorScheme.primary,
          backgroundColor: theme.colorScheme.onSecondary,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(_chipBorderRadius),
          ),
          onSelected: isDisabled ? null : (_) => onSelected(type),
        );
      }).toList(),
    );
  }
}
