import 'package:common/localization/l10n_utils.dart';
import 'package:concierge/presentation/screens/receipt/widgets/receipt_action_bar.dart';
import 'package:concierge/presentation/screens/receipt/widgets/receipt_card.dart';
import 'package:concierge/presentation/theme/app_colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:concierge/presentation/screens/receipt/bloc/receipt_cubit.dart';
import 'package:concierge/presentation/screens/receipt/bloc/receipt_state.dart';
import 'package:gap/gap.dart';

class ReceiptScreen extends StatelessWidget {
  const ReceiptScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ReceiptCubit, ReceiptState>(
      builder: (context, state) {
        final cubit = context.read<ReceiptCubit>();
        return MultiBlocListener(
          listeners: [
            BlocListener<ReceiptCubit, ReceiptState>(
              listenWhen: (prev, curr) => prev.isLoading && curr.error.isError,
              listener: (context, state) {},
            ),
          ],
          child: Scaffold(
            backgroundColor: AppColors.sandColor,
            bottomNavigationBar: ReceiptActionBar(),
            body: Center(
              child: Column(
                children: [
                  SafeArea(
                    child: Row(
                      children: [
                        Spacer(),
                        CloseButton(
                          color: Colors.black,
                          style: ButtonStyle(backgroundColor: WidgetStatePropertyAll(Colors.white)),
                        ),
                      ],
                    ),
                  ),
                  Gap(32),
                  Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 50.0),
                    child: Builder(
                      builder: (context) {
                        if (state.isLoading) {
                          return Center(child: CircularProgressIndicator());
                        }
                        return ReceiptCard();
                      },
                    ),
                  ),
                  Gap(32),
                  Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 100),
                    child: Text(
                      context.strings.contact_comwell_for_changes,
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        fontSize: 12,
                        color: Colors.white.withAlpha((0.65 * 255).toInt()),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}