import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:pshared/provider/payment/amount.dart';

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


class FeePayerSwitch extends StatelessWidget {
  final double spacing;
  final TextStyle? style;

  const FeePayerSwitch({super.key, required this.spacing, this.style});

  @override
  Widget build(BuildContext context) => Consumer<PaymentAmountProvider>(
    builder: (context, provider, _) {
      final recipientPaysFee = !provider.payerCoversFee;
      final textStyle = style ?? Theme.of(context).textTheme.bodySmall;
      void updateRecipientPaysFee(bool value) {
        provider.setPayerCoversFee(!value);
      }

      return InkWell(
        borderRadius: BorderRadius.circular(6),
        onTap: () => updateRecipientPaysFee(!recipientPaysFee),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Checkbox(
              value: recipientPaysFee,
              onChanged: (val) => updateRecipientPaysFee(val ?? false),
              visualDensity: VisualDensity.compact,
              materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
            ),
            SizedBox(width: spacing),
            Text(AppLocalizations.of(context)!.recipientPaysFee, style: textStyle),
          ],
        ),
      );
    },
  );
}
