import 'package:car_provider_app/classes/app_state.dart';
import 'package:car_provider_app/config/app_provider.dart';
import 'package:car_provider_app/models/post_params_model.dart';
import 'package:car_provider_app/theme/app_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';

import 'config/routes.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await EasyLocalization.ensureInitialized();
  runApp(
    EasyLocalization(
      supportedLocales: [
        Locale('ar', 'SA'),
        Locale('en', 'US')

      ],
      fallbackLocale: Locale('en', 'US'),
      // startLocale: Locale('ar', 'SA'),
      path: 'resources/langs',
      child: MyApp(),
    ),
  );
}

// todo terminal command to genertate translation files
// flutter pub run easy_localization:generate --source-dir ./resources/langs
// todo terminal command to genertate translation keys
// flutter pub run easy_localization:generate --source-dir ./resources/langs -f keys -o locale_keys.g.dart
// command to generate languages data from json

class MyApp extends StatelessWidget {
//This widget is the root of your application.
  MyApp() {}

  @override
  Widget build(BuildContext context) {
    return AppProvider(
      child: Sizer(
        builder: (context, orientation, deviceType) {
          AppState().setPostParamsModel(
            PostParamsModel(languageID: EasyLocalization.of(context)?.locale.languageCode == "ar" ? 1 : 2,),
          );
          return MaterialApp(
            theme: AppTheme.getTheme(EasyLocalization.of(context)?.locale.languageCode == "ar"),
            debugShowCheckedModeBanner: false,
            localizationsDelegates: context.localizationDelegates,
            supportedLocales: context.supportedLocales,
            locale: context.locale,
            initialRoute: AppRoutes.initialRoute,
            routes: AppRoutes.routes,
          );
        },
      ),
    );
  }
}
// class MyApp extends StatelessWidget {
//   // This widget is the root of your application.
//   MyApp() {}
//
//   @override
//   Widget build(BuildContext context) {
//     return AppProvider(
//       child: Sizer(
//         builder: (context, orientation, deviceType) {
//           return MaterialApp(
//             theme: AppTheme.getTheme(),
//             debugShowCheckedModeBanner: false,
//             localizationsDelegates: context.localizationDelegates,
//             supportedLocales: context.supportedLocales,
//             locale: context.locale,
//             initialRoute: AppRoutes.initialRoute,
//             routes: AppRoutes.routes,
//           );
//         },
//       ),
//     );
//   }
// }
