// import 'package:firebase_core/firebase_core.dart';
// import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:taafee_mobile/common/const/const.dart';
import 'package:taafee_mobile/core/init/dependency_injection.dart';
import 'package:taafee_mobile/core/init/language_init.dart';
import 'package:taafee_mobile/core/localization/localization.dart';
import 'package:taafee_mobile/core/routing/routing_manager.dart';
// import 'package:taafee_mobile/features/card/data_layer/source/card_service.dart';
// import 'common/widgets/notification_message.dart';
import 'core/local_storage/cache_service.dart';
// import 'core/local_storage/local_storage.dart';
import 'core/utils/utils.dart';
// import 'features/card/data_layer/model/card_model.dart';

String? fcmToken;
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  DependencyInjection.injectDependencies();
  await CacheService.inite();
  await GetStorage.init();
  // await Firebase.initializeApp();
  // if (LocalStorage().getFCMToken() == null) {
  // fcmToken = await FirebaseMessaging.instance.getToken();
  //   if (fcmToken != null) {
  //     LocalStorage().saveFCMToken(fcmToken!);
  //   }
  // } else {
  //   fcmToken = LocalStorage().getFCMToken();
  // }
  // FirebaseMessaging.onMessageOpenedApp.listen((remoteMessage) async {
  //   int cardId = int.parse(remoteMessage.data['id']);
  //   CardModel cardModel = await CardService().showCard(cardId: cardId);
  //   RoutingManager.to(RouteName.cardDetails, arguments: cardModel);
  // });
  // await FirebaseMessaging.instance.requestPermission();
  // FirebaseMessaging.onMessage.listen((remoteMessage) async {
  //   int cardId = int.parse(remoteMessage.data['id']);
  //   CardModel cardModel = await CardService().showCard(cardId: cardId);

  //   notificationMessage(
  //     remoteMessage,
  //     cardModel,
  //   );
  // });
  LanguageInit.langugeInite();
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(
        const SystemUiOverlayStyle(statusBarColor: Colors.grey));
    return GestureDetector(
      onTap: () {
        FocusManager.instance.primaryFocus?.unfocus();
      },
      child: GetMaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'T3afi',
        theme: ThemeData(
          primarySwatch: Utils.createMaterialColor(AppColors.primeColor),
        ),
        initialRoute: RouteName.splash,
        getPages: RoutingManager.pages,
        translations: PagesTranslations(),
        locale: Locale(LanguageInit.language ?? 'en'),
      ),
    );
  }
}
