import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../core/design/tokens.dart'; import '../../../core/design/tripz_colors.dart'; import '../../../core/di.dart'; import '../../../core/l10n/l10n.dart'; import '../../../core/ui/empty_view.dart'; import '../../../core/ui/tripz_button.dart'; import '../../../core/ui/tripz_scaffold.dart'; import '../../../core/ui/tripz_sheet.dart'; import '../../../core/ui/tripz_text_field.dart'; import '../cubit/wallet_cubit.dart'; import '../cubit/wallet_state.dart'; import 'widgets/balance_card.dart'; import 'widgets/txn_tile.dart'; /// محفظة الراكب — **رصيدٌ دفعه ولم يستهلكه**، أي التزامٌ على المنصّة. /// شاشة السائق مختلفة عمداً (أرباح + سحب): لا تُوحَّدان (docs/39 §4). class WalletPage extends StatefulWidget { const WalletPage({super.key}); @override State createState() => _WalletPageState(); } class _WalletPageState extends State { late final WalletCubit _cubit = sl()..load(); @override void dispose() { _cubit.close(); super.dispose(); } @override Widget build(BuildContext context) { final l10n = context.l10n; return BlocProvider.value( value: _cubit, child: BlocConsumer( listenWhen: (p, n) => p.action != n.action, listener: (context, state) { if (state.action == WalletAction.topupFailed) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(l10n.walletTopupFailed)), ); } }, builder: (context, state) { return TripzScaffold( title: l10n.walletTitle, status: state.status, error: state.error, onRetry: _cubit.load, child: ListView( children: [ BalanceCard( label: l10n.walletBalance, balance: state.wallet?.balance, currency: state.currency, action: TripzButton.primary( label: l10n.walletTopup, loading: state.action == WalletAction.toppingUp, onPressed: () => _openTopup(context), ), ), const SizedBox(height: Space.lg), Text(l10n.walletTransactions, style: context.texts.titleMedium), const SizedBox(height: Space.xs), if (state.transactions.isEmpty) Padding( padding: const EdgeInsets.only(top: Space.xl), child: EmptyView( icon: Icons.receipt_long_outlined, message: l10n.walletEmpty, ), ) else for (final txn in state.transactions) TxnTile(txn: txn, currency: state.currency), ], ), ); }, ), ); } void _openTopup(BuildContext context) { final l10n = context.l10n; final controller = TextEditingController(); TripzSheet.show( context, title: l10n.walletTopup, child: TripzTextField( controller: controller, label: l10n.walletTopupAmount, numeric: true, autofocus: true, keyboardType: const TextInputType.numberWithOptions(decimal: true), ), bottomAction: TripzButton.primary( label: l10n.walletTopup, onPressed: () { final amount = num.tryParse(controller.text.trim()); Navigator.of(context).pop(); if (amount != null) _cubit.topup(amount); }, ), ); } }