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

import '../../../application/split_bill/split_bill_form/split_bill_form_bloc.dart';
import '../../../common/theme/theme.dart';
import '../../../domain/order/order.dart';
import '../../../injection.dart';
import 'widgets/split_bill_left_panel.dart';
import 'widgets/split_bill_right_panel.dart';

@RoutePage()
class SplitBillPage extends StatelessWidget implements AutoRouteWrapper {
  final Order order;
  const SplitBillPage({super.key, required this.order});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.background,
      body: SafeArea(
        child: BlocBuilder<SplitBillFormBloc, SplitBillFormState>(
          builder: (context, state) {
            return Row(
              children: [
                Expanded(flex: 2, child: SplitBillLeftPanel(state: state)),
                Expanded(flex: 4, child: SplitBillRightPanel(state: state)),
              ],
            );
          },
        ),
      ),
    );
  }

  @override
  Widget wrappedRoute(BuildContext context) => BlocProvider(
    create: (_) =>
        getIt<SplitBillFormBloc>()..add(SplitBillFormEvent.setOrder(order)),
    child: this,
  );
}
