import 'dart:io';

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';

import 'controller/firebase.dart';
import 'controller/functions/encrypt_decrypt.dart';
import 'controller/functions/initilize.dart';
import 'controller/local/local_controller.dart';
import 'controller/local/translations.dart';
import 'firebase_options.dart';
import 'login_page.dart';

final box = GetStorage();
const storage = FlutterSecureStorage();

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // if (Platform.isAndroid || Platform.isIOS) {
  //   await Firebase.initializeApp(
  //     options: DefaultFirebaseOptions.currentPlatform,
  //   );
  //   await FirebaseMessagesController().requestFirebaseMessagingPermission();

  //   // FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);

  //   List<Future> initializationTasks = [
  //     FirebaseMessagesController().getNotificationSettings(),
  //     FirebaseMessagesController().getToken(),
  //   ];
  //   // cameras = await availableCameras();
  //   await Future.wait(initializationTasks);
  //   SystemChrome.setPreferredOrientations([
  //     DeviceOrientation.portraitUp,
  //     DeviceOrientation.portraitDown,
  //   ]);
  // }
  final AppInitializer initializer = AppInitializer();

  await initializer.initializeApp();
  await Future.delayed(Duration.zero);
  await EncryptionHelper.initialize();

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({super.key});
  LocaleController localController = Get.put(LocaleController());

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Sefer Service'.tr,
      debugShowCheckedModeBanner: false,
      translations: MyTranslation(),
      locale: localController.language,
      theme: localController.appTheme,
      key: UniqueKey(),
      home: LoginPage(),
    );
  }
}
