// import 'package:barcode_scan/barcode_scan.dart';
import 'dart:io';

import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/presentation/screens/codes/bloc/stamp_bloc.dart';
import 'package:farm_tpf/presentation/screens/codes/cubit/detail_stamp_cubit.dart';
import 'package:farm_tpf/presentation/screens/plot/bloc/plot_bloc.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';
import 'app.dart';
// import 'data/repository/auth_repository.dart';
import 'data/repository/authentication_repository.dart';
import 'environment/app_config.dart';
import 'presentation/screens/task/bloc/task_bloc.dart';

final GlobalKey<NavigatorState> globalNavigator = GlobalKey<NavigatorState>();
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  Firebase.initializeApp();
  // if (Platform.isAndroid) {
  //   await Firebase.initializeApp(
  //     options: DefaultFirebaseOptions.currentPlatform,
  //   );
  // } else {
  //   await Firebase.initializeApp();
  // }
  // await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(alert: true, badge: true, sound: true);
  // FirebaseMessaging.onBackgroundMessage(FirebaseMessages.firebaseMessagingBackgroundHandler);
  // FirebaseMessaging.onMessageOpenedApp.listen(FirebaseMessages.firebaseMessagingBackgroundHandler);

  await SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitDown,
    DeviceOrientation.portraitUp,
  ]);
  setFlavorDevelopment();
  final appDocumentDirectory = await getApplicationDocumentsDirectory();
  Hive..init(appDocumentDirectory.path);
  await Hive.openBox('LocalDBName');
  runApp(
    MultiBlocProvider(
      providers: [
        BlocProvider(
          create: (_) => StampBloc(
            Repository(),
          ),
        ),
        BlocProvider(
          create: (_) => TaskBloc(
            Repository(),
          ),
        ),
        BlocProvider(
          create: (_) => PlotBloc(
            repository: Repository(),
          ),
        ),
        BlocProvider(
          create: (_) => DetailStampCubit(),
        ),
      ],
      child: App(
        authenticationRepository: AuthenticationRepository(),
      ),
    ),
  );
}
