import 'package:baseproject/core/common/index.dart';
import 'package:baseproject/core/components/alice.dart';
import 'package:baseproject/core/language/app_localizations.dart';
import 'package:baseproject/core/theme/custom_theme.dart';
import 'package:baseproject/features/presentation/app/bloc/user_bloc.dart';
import 'package:baseproject/features/route/route_const.dart';
import 'package:baseproject/features/route/route_generator.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  final UserBloc _userBloc = getItSuper<UserBloc>();
  String _getLanguage() {
    return 'vi';
  }

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => _userBloc,
      child: MaterialApp(
          // navigatorObservers: [CustomNavigatorObserver()],
          debugShowCheckedModeBanner: false,
          theme: getTheme(context, true),
          // navigatorKey: navigatorKey,
          locale: Locale(_getLanguage()),
          supportedLocales: AppLocalizations.locales,
          localizationsDelegates: <LocalizationsDelegate<dynamic>>[
            AppLocalizations.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate
          ],
          navigatorKey: navigatorKey,
          localeResolutionCallback: AppLocalizations.localeResolutionCallback,
          initialRoute: appInitRouteName,
          onGenerateRoute: RouteGenerator.generatorRoute,
          builder: EasyLoading.init(builder: (BuildContext context, Widget? child) {
            EasyLoading.instance.userInteractions = false;
            return Container(
              child: kDebugMode
                  ? Stack(
                      children: <Widget>[
                        child!,
                        Positioned(
                          bottom: 10,
                          right: 10,
                          child: Container(
                            width: 30,
                            height: 30,
                            child: FloatingActionButton(
                              onPressed: () {
                                CustomAlice.showScreen();
                              },
                              backgroundColor: Colors.red,
                              child: const Text("A"),
                            ),
                          ),
                        ),
                      ],
                    )
                  : child!,
            );
          })),
    );
  }
}
