import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../core/design/tokens.dart'; import '../../../core/l10n/l10n.dart'; import '../../../core/tenant/tenant_cubit.dart'; import '../../../core/ui/failure_text.dart'; import '../../../core/ui/form_header.dart'; import '../../../core/ui/phone_field.dart'; import '../../../core/ui/tripz_button.dart'; import '../../../core/ui/tripz_scaffold.dart'; import '../cubit/login_cubit.dart'; import '../cubit/login_state.dart'; class PhoneView extends StatefulWidget { const PhoneView({super.key}); @override State createState() => _PhoneViewState(); } class _PhoneViewState extends State { final _phone = TextEditingController(); @override void initState() { super.initState(); _phone.addListener( () => context.read().phoneChanged(_phone.text), ); // الدولة الافتراضية من المستأجر — يُطبَّق بعد أول إطار كي يتوفّر السياق. WidgetsBinding.instance.addPostFrameCallback((_) { if (!mounted) return; context .read() .applyTenantCountry(context.read().state.countryPack); }); } @override void dispose() { _phone.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final l10n = context.l10n; return BlocBuilder( buildWhen: (p, n) => p.status != n.status || p.phoneError != n.phoneError || p.country != n.country || p.failure != n.failure, builder: (context, state) { final cubit = context.read(); return TripzScaffold( showAppBar: false, bottomAction: TripzButton.primary( label: l10n.phoneSend, loading: state.isSubmitting, onPressed: cubit.submitPhone, ), child: ListView( children: [ const SizedBox(height: Space.xl), FormHeader( icon: Icons.phone_outlined, title: l10n.phoneTitle, lead: l10n.phoneLead, ), const SizedBox(height: Space.lg), PhoneField( controller: _phone, country: state.country, onCountryChanged: cubit.countryChanged, label: l10n.phoneLabel, hint: l10n.phoneHint, enabled: !state.isSubmitting, onSubmitted: (_) => cubit.submitPhone(), errorText: state.phoneError == null ? null : ApiFailureText.phoneMessageOf(context, state.phoneError!), ), if (state.failure != null) ApiFailureText(failure: state.failure!), ], ), ); }, ); } }