import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
import 'package:flutter/material.dart';

class ApplyClubPoints extends StatelessWidget {
  final bool applyClubPoints;
  final int clubPoints;
  final void Function(bool) onApplyClubPointsChanged;

  const ApplyClubPoints({
    super.key,
    required this.applyClubPoints,
    required this.clubPoints,
    required this.onApplyClubPointsChanged,
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return Row(
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(context.strings.checkout_page_payment_club_points_title),
              Text(
                clubPoints > 0
                    ? context.strings.checkout_page_payment_club_points_subtitle(
                        "$clubPoints",
                        "$clubPoints",
                      )
                    : context.strings.checkout_page_payment_club_points_subtitle_zero,
                style: theme.textTheme.bodySmall?.copyWith(color: colorBlack[65]),
              ),
            ],
          ),
        ),
        const SizedBox(width: 10),
        if (clubPoints > 0)
          Switch(
            value: applyClubPoints,
            thumbColor: WidgetStateProperty.resolveWith((states) {
              if (states.contains(WidgetState.selected)) {
                return sandColor[80];
              }
              return Colors.white;
            }),
            trackColor: WidgetStateProperty.resolveWith((states) {
              if (!states.contains(WidgetState.selected)) {
                return Colors.grey[200];
              }
              return null;
            }),
            trackOutlineColor: const WidgetStatePropertyAll(Colors.white),
            onChanged: (value) {
              onApplyClubPointsChanged(value);
            },
          ),
      ],
    );
  }
}