import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:payment_plugin/themes/light_theme.dart';

class RemoveCardButton extends StatelessWidget {
  final void Function() onRemoveCard;

  const RemoveCardButton({super.key, required this.onRemoveCard});

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return InkWell(
      onTap: () async {
        final response = await showDialog<dynamic>(
            context: context,
            builder: (context) {
              return Dialog(
                backgroundColor: colorBackground,
                child: Padding(
                  padding: const EdgeInsets.all(24.0),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Text(
                        "payment_cards_confirm_remove_title".tr(),
                        textAlign: TextAlign.center,
                        style: theme.textTheme.headlineMedium,
                      ),
                      const SizedBox(height: 32),
                      Text(
                        "payment_cards_confirm_remove_subtitle".tr(),
                        style: theme.textTheme.bodySmall
                            ?.copyWith(color: colorHeadlineText),
                        textAlign: TextAlign.center,
                      ),
                      const SizedBox(height: 32),
                      ElevatedButton(
                        style: ButtonStyle(
                          minimumSize: const WidgetStatePropertyAll(
                              Size(double.infinity, 50)),
                          shape: WidgetStatePropertyAll(RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(30),
                          )),
                        ),
                        onPressed: () {
                          context.pop(true);
                        },
                        child: Text(
                          "generic_confirm".tr(),
                          style: theme.textTheme.bodyMedium?.copyWith(color: colorBackground),
                        ),
                      ),
                      const SizedBox(height: 8),
                      OutlinedButton(
                          style: ButtonStyle(
                            minimumSize: const WidgetStatePropertyAll(
                                Size(double.infinity, 50)),
                            shape:
                                WidgetStatePropertyAll(RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(30),
                            )),
                          ),
                          child: Text(
                            "cancel".tr(),
                            style: theme.textTheme.bodyMedium,
                          ),
                          onPressed: () {
                            context.pop(false);
                          }),
                    ],
                  ),
                ),
              );
            });
        if (response is bool && response == true) {
          onRemoveCard();
          if (context.mounted) {
            context.pop();
          }
        }
      },
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(
            color: colorDivider,
          ),
          borderRadius: BorderRadius.circular(30),
        ),
        child: Padding(
          padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 32),
          child: Text(
            "payment_cards_remove_card_button".tr(),
            style: theme.textTheme.bodySmall?.copyWith(color: Theme.of(context).colorScheme.error),
          ),
        ),
      ),
    );
  }
}