import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; // 🔹 1. Добавлен импорт
import 'package:bot_toast/bot_toast.dart';
import 'package:be_happy/presentation/event/edit_profile_event.dart';
import 'package:be_happy/presentation/event/profile_event.dart';
import 'package:be_happy/presentation/event/scooter_detail_event.dart';
import 'package:be_happy/presentation/navigation/app_router.dart';
import 'package:be_happy/presentation/screens/payment_confirm_screen.dart';
import 'package:be_happy/presentation/screens/splash_screen.dart';
import 'package:be_happy/presentation/state/splash_state.dart';
import 'package:be_happy/presentation/viewmodel/auth_bloc.dart';
import 'package:be_happy/presentation/viewmodel/edit_profile_bloc.dart';
import 'package:be_happy/presentation/viewmodel/map_bloc.dart';
import 'package:be_happy/presentation/viewmodel/payment_confirm_bloc.dart';
import 'package:be_happy/presentation/viewmodel/pin_bloc.dart';
import 'package:be_happy/presentation/viewmodel/profile_bloc.dart';
import 'package:be_happy/presentation/viewmodel/scooter_detail_bloc.dart';
import 'package:be_happy/presentation/viewmodel/splash_bloc.dart';
import 'package:be_happy/presentation/viewmodel/verify_code_bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'di/service_locator.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  SystemChrome.setEnabledSystemUIMode(
    SystemUiMode.manual,
    overlays: [SystemUiOverlay.top],
  );

  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.light,
      statusBarBrightness: Brightness.dark,
    ),
  );

  await setupDependencies();

  runApp(const MyApp());
}


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

  @override
  Widget build(BuildContext context) {
    final appRouter = AppRouter(getIt<SplashBloc>());

    return MultiBlocProvider(
      providers: [
        BlocProvider.value(value: getIt<SplashBloc>()),

        BlocProvider(create: (context) => getIt<PhoneAuthBloc>()),
        BlocProvider(create: (context) => getIt<VerifyCodeBloc>()),
        BlocProvider(create: (context) => getIt<PinBloc>()),
        BlocProvider(create: (context) => getIt<MapBloc>()),
      ],
      child: BlocListener<SplashBloc, SplashState>(
        listener: (context, state) {
          print(
            '!!! Состояние AuthBloc изменилось на: ${state.runtimeType} !!!',
          );
        },
        child: MaterialApp.router(
          title: 'BeHappy',
          debugShowCheckedModeBanner: false,
          theme: ThemeData.dark(),
          builder: BotToastInit(),
          routerConfig: appRouter.router,
        ),
      ),
    );
  }
}
