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

import '../application/auth/auth_bloc.dart';
import '../application/auth/logout_form/logout_form_bloc.dart';
import '../application/customer/customer_point_loader/customer_point_loader_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<LogoutFormBloc>()),
        BlocProvider(create: (context) => getIt<CustomerPointLoaderBloc>()),
      ],
      child: MaterialApp.router(
        debugShowCheckedModeBanner: false,
        title: AppConstant.appName,
        theme: ThemeApp.theme,
        routerConfig: _appRouter.config(
          navigatorObservers: () => <NavigatorObserver>[AppRouteObserver()],
        ),
      ),
    );
  }
}
