import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:firebase_core/firebase_core.dart';
import 'app/routes/app_pages.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter/foundation.dart' show kIsWeb;

final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if (kIsWeb) {
    await Firebase.initializeApp(
      options: const FirebaseOptions(
        apiKey: 'AIzaSyC3wWpfHyLqGYD0pRvDSXHYCEBborrrW7M',
        appId: '1:98122794680:web:dummyappid', // Ganti dengan appId web dari Firebase Console jika ada
        messagingSenderId: '98122794680',
        projectId: 'nutriplant-579c9',
        databaseURL: 'https://nutriplant-579c9-default-rtdb.firebaseio.com',
        storageBucket: 'nutriplant-579c9.firebasestorage.app',
      ),
    );
  } else {
    await Firebase.initializeApp(); // Inisialisasi default untuk mobile
  }
  await initializeDateFormatting('id_ID', null);
  await _initLocalNotification(); // Inisialisasi notifikasi lokal

  runApp(
    GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: "NutriPlant",
      initialRoute: Routes.SPLASH_SCREEN,
      getPages: AppPages.routes,
    ),
  );
}

// Dipindah ke luar dari main()
Future<void> _initLocalNotification() async {
  const AndroidInitializationSettings androidSettings =
      AndroidInitializationSettings('@mipmap/ic_launcher');

  const InitializationSettings initSettings =
      InitializationSettings(android: androidSettings);

  await flutterLocalNotificationsPlugin.initialize(initSettings);
}
