import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/menu/bloc/menu_cubit.dart';
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
import 'package:syncrow_app/navigation/navigation_service.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
import 'package:syncrow_app/utils/resource_manager/theme_manager.dart';
import 'features/scene/bloc/scene_bloc/scene_bloc.dart';
import 'navigation/router.dart' as router;
import 'navigation/routing_constants.dart';

class MyApp extends StatelessWidget {
  final Locale locale;

  const MyApp(this.locale, {super.key});

  @override
  Widget build(BuildContext context) {
    Constants.appBarHeight =
        MediaQuery.sizeOf(context).height * Constants.appBarHeightPercentage;
    Constants.bottomNavBarHeight = MediaQuery.sizeOf(context).height *
        Constants.bottomNavBarHeightPercentage;
    return MultiBlocProvider(
      providers: [
        BlocProvider<DevicesCubit>(
          create: (context) => DevicesCubit.getInstance(),
        ),
        BlocProvider(create: (context) => AuthCubit()),
        BlocProvider(
          create: (context) => EffectPeriodBloc(),
        ),
        BlocProvider(create: (context) => SmartSceneSelectBloc()),
        BlocProvider(create: (context) => CreateSceneBloc()),
        BlocProvider(create: (context) => SceneBloc()),
        BlocProvider(create: (context) => ProfileBloc()),
        BlocProvider(create: (context) => MenuCubit()), //DevicesCubit
      ],
      child: MaterialApp(
        navigatorKey: NavigationService.navigatorKey,
        scaffoldMessengerKey: NavigationService.snackbarKey,
        debugShowCheckedModeBanner: false,
        color: ColorsManager.primaryColor,
        title: 'Syncrow App',
        onGenerateRoute: router.Router.generateRoute,
        initialRoute: Routes.splash,
        themeMode: ThemeMode.system,
        theme: ThemeManager.selectTheme(),
        supportedLocales: const [
          Locale('en', ''), // English, no country code
          Locale('ar', ''), // Arabic, no country code
        ],
        // locale: locale,
        locale: const Locale('en', ''),
      ),
    );
  }
}
