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

import '../application/auth/auth_bloc.dart';
import '../application/auth/logout/logout_bloc.dart';
import '../application/category/category_loader/category_loader_bloc.dart';
import '../application/checkout/checkout_form/checkout_form_bloc.dart';
import '../application/customer/customer_loader/customer_loader_bloc.dart';
import '../application/order/order_form/order_form_bloc.dart';
import '../application/order/order_loader/order_loader_bloc.dart';
import '../application/outlet/outlet_loader/outlet_loader_bloc.dart';
import '../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
import '../application/printer/bluetooth/bluetooth_connect/bluetooth_connect_bloc.dart';
import '../application/printer/bluetooth/bluetooth_loader/bluetooth_loader_bloc.dart';
import '../application/printer/print_struck/print_struck_bloc.dart';
import '../application/printer/printer_form/printer_form_bloc.dart';
import '../application/printer/printer_loader/printer_loader_bloc.dart';
import '../application/product/product_loader/product_loader_bloc.dart';
import '../application/sync/sync_setting/sync_setting_bloc.dart';
import '../application/table/table_form/table_form_bloc.dart';
import '../application/table/table_loader/table_loader_bloc.dart';
import '../application/void/void_form/void_form_bloc.dart';
import '../common/theme/theme.dart';
import '../common/constant/app_constant.dart';
import '../injection.dart';
import 'router/app_router.dart';
import 'router/app_router_observer.dart';

class AppWidget extends StatefulWidget {
  const AppWidget({super.key});

  @override
  State<AppWidget> createState() => _AppWidgetState();
}

class _AppWidgetState extends State<AppWidget> {
  final _appRouter = getIt<AppRouter>();

  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
      providers: [
        BlocProvider(create: (context) => getIt<AuthBloc>()),
        BlocProvider(create: (context) => getIt<OutletLoaderBloc>()),
        BlocProvider(create: (context) => getIt<CategoryLoaderBloc>()),
        BlocProvider(create: (context) => getIt<ProductLoaderBloc>()),
        BlocProvider(create: (context) => getIt<CheckoutFormBloc>()),
        BlocProvider(create: (context) => getIt<TableLoaderBloc>()),
        BlocProvider(create: (context) => getIt<TableFormBloc>()),
        BlocProvider(create: (context) => getIt<PaymentMethodLoaderBloc>()),
        BlocProvider(create: (context) => getIt<OrderFormBloc>()),
        BlocProvider(create: (context) => getIt<OrderLoaderBloc>()),
        BlocProvider(create: (context) => getIt<CustomerLoaderBloc>()),
        BlocProvider(create: (context) => getIt<VoidFormBloc>()),
        BlocProvider(create: (context) => getIt<BluetoothLoaderBloc>()),
        BlocProvider(create: (context) => getIt<BluetoothConnectBloc>()),
        BlocProvider(create: (context) => getIt<PrinterFormBloc>()),
        BlocProvider(create: (context) => getIt<PrinterLoaderBloc>()),
        BlocProvider(create: (context) => getIt<PrintStruckBloc>()),
        BlocProvider(create: (context) => getIt<SyncSettingBloc>()),
        BlocProvider(create: (context) => getIt<LogoutBloc>()),
      ],
      child: MaterialApp.router(
        debugShowCheckedModeBanner: false,
        title: AppConstant.appName,
        theme: ThemeApp.theme,
        routerConfig: _appRouter.config(
          navigatorObservers: () => <NavigatorObserver>[AppRouteObserver()],
        ),
      ),
    );
  }
}
