import 'package:bot_toast/bot_toast.dart';
import 'package:didvan/config/theme_data.dart';
import 'package:didvan/providers/theme_provider.dart';
import 'package:didvan/providers/user_provider.dart';
import 'package:didvan/routes/route_generator.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';

void main() {
  runApp(const Didvan());
}

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

class Didvan extends StatelessWidget {
  const Didvan({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider<UserProvider>(
          create: (context) => UserProvider(),
        ),
        ChangeNotifierProvider<ThemeProvider>(
          create: (context) => ThemeProvider(),
        ),
      ],
      child: Consumer<ThemeProvider>(
        builder: (context, themeProvider, child) => MaterialApp(
          key: materialKey,
          navigatorKey: navigatorKey,
          debugShowCheckedModeBanner: false,
          title: 'Didvan',
          theme: LightThemeConfig.themeData.copyWith(
              textTheme: LightThemeConfig.themeData.textTheme.apply(
            fontFamily: themeProvider.fontFamily,
          )),
          darkTheme: DarkThemeConfig.themeData.copyWith(
              textTheme: DarkThemeConfig.themeData.textTheme.apply(
            fontFamily: themeProvider.fontFamily,
          )),
          color: LightThemeConfig.themeData.primaryColor,
          themeMode: themeProvider.themeMode,
          onGenerateRoute: (settings) => RouteGenerator.generateRoute(settings),
          builder: BotToastInit(), //1. call BotToastInit
          navigatorObservers: [BotToastNavigatorObserver()],
          initialRoute: '/',
          localizationsDelegates: const [
            GlobalCupertinoLocalizations.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
          ],
          supportedLocales: const [
            Locale("fa", "IR"),
          ],
          locale: const Locale("fa", "IR"),
        ),
      ),
    );
  }
}
