import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/features/my_finance/presentation/cubit/user_cards_cubit/user_cards_cubit.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/svg.dart'; import 'package:url_launcher/url_launcher.dart'; class CardWidget extends StatelessWidget { const CardWidget({super.key, this.isSelected = false, this.enabledAddCard = false, this.cardId = 0, this.cardNumber = ''}); final int cardId; final bool isSelected; final bool enabledAddCard; final String cardNumber; @override Widget build(BuildContext context) { final s = S.of(context); return Stack( children: [ GestureDetector( onTap: enabledAddCard ? () async { final addCardUrl = await context.read().addCard(); if (addCardUrl != null) { final uri = Uri.parse(addCardUrl.paymentUrl); if (await canLaunchUrl(uri)) { await launchUrl(uri, mode: LaunchMode.externalApplication); } } } : () { context.read().markAsDefault(id: cardId); }, child: Container( padding: const EdgeInsets.all(4), decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), border: Border.all(color: isSelected ? appTheme.blueA400 : const Color(0xFFF1F2F6), width: 2), ), child: enabledAddCard ? Container( width: 148, padding: const EdgeInsets.all(10), decoration: BoxDecoration(color: const Color(0xFFF1F2F6), borderRadius: BorderRadius.circular(4)), child: Column( children: [ SvgPicture.asset('assets/icons/add_card.svg'), const SizedBox(height: 24), Text(s.new_card, style: TextStyles.textSSemibold.copyWith(color: appTheme.black)), ], ), ) : Container( width: 148, padding: const EdgeInsets.all(10), decoration: BoxDecoration(color: const Color(0xFFF1F2F6), borderRadius: BorderRadius.circular(4)), child: Column( children: [ SvgPicture.asset('assets/icons/card.svg'), const SizedBox(height: 24), Text(cardNumber, style: TextStyles.textSSemibold.copyWith(color: appTheme.black)), ], ), ), ), ), if (!enabledAddCard) Positioned( top: 12, right: 12, child: GestureDetector( child: SvgPicture.asset('assets/images/img_close_blue_gray_900.svg'), onTap: () => context.read().deleteCard(id: cardId), ), ), ], ); } }