import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../../../application/printer/print_struck/print_struck_bloc.dart';
import '../../../../../application/void/void_form/void_form_bloc.dart';
import '../../../../../common/theme/theme.dart';
import '../../../../components/spaces/space.dart';
import '../../../../components/toast/flushbar.dart';
import 'widgets/void_success_left_panel.dart';
import 'widgets/void_success_right_panel.dart';

@RoutePage()
class VoidSuccessPage extends StatelessWidget {
  const VoidSuccessPage({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocListener<PrintStruckBloc, PrintStruckState>(
      listenWhen: (previous, current) =>
          previous.failureOrPrintStruck != current.failureOrPrintStruck,
      listener: (context, state) {
        state.failureOrPrintStruck.fold(
          () {},
          (either) => either.fold(
            (f) => AppFlushbar.showPrinterFailureToast(context, f),
            (success) {
              AppFlushbar.showSuccess(context, "Struck berhasil dicetak");
            },
          ),
        );
      },
      child: Scaffold(
        backgroundColor: AppColor.background,
        body: BlocBuilder<VoidFormBloc, VoidFormState>(
          builder: (context, state) {
            return SafeArea(
              child: Padding(
                padding: const EdgeInsets.all(24.0),
                child: Row(
                  children: [
                    Expanded(
                      flex: 35,
                      child: VoidSuccessLeftPanel(state: state),
                    ),
                    const SpaceWidth(16),
                    Expanded(
                      flex: 65,
                      child: VoidSuccessRightPanel(state: state),
                    ),
                  ],
                ),
              ),
            );
          },
        ),
      ),
    );
  }
}
