import 'package:flutter/material.dart';
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
import 'package:rasadyar_auth/auth.dart';
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
import 'package:rasadyar_core/core.dart';

import 'infrastructure/di/di.dart';
import 'infrastructure/service/auth_service.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await setupInjection();
  Get.put(TokenStorageService());
  var tokenService = Get.find<TokenStorageService>();
  await tokenService.init();
  Get.put(AuthMiddleware());
  Get.put(AuthService());

  runApp(MyApp());
  // runApp(DevicePreview(builder: (context) => ForDevicePreview(),));
}

/*class ForDevicePreview extends StatelessWidget {
  const ForDevicePreview({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      useInheritedMediaQuery: true,
      locale: DevicePreview.locale(context),
      builder: DevicePreview.appBuilder,
      title: 'رصدیار',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: AppColor.blueNormal),
      ),
      initialRoute: AppPages.initRoutes,
      initialBinding: BindingsBuilder.put(() => UserService()),
      getPages: AppPages.pages,
    );
  }
}*/

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

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(412, 917),
      minTextAdapt: true,
      splitScreenMode: true,
      child: GetMaterialApp(
        title: 'رصدیار',
        theme: ThemeData(
          fontFamily: 'yekan',
          colorScheme: ColorScheme.fromSeed(seedColor: AppColor.blueNormal),
        ),
        initialRoute: AppPages.initRoutes,
        getPages: AppPages.pages,
        locale: const Locale("fa", "IR"),
        supportedLocales: const [Locale("fa", "IR")],
        localizationsDelegates: [
          PersianMaterialLocalizations.delegate,
          PersianCupertinoLocalizations.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
        ],
      ),
    );
  }
}
