import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:firebase_core/firebase_core.dart';
import 'services/whatsapp_service.dart';
import 'services/firebase_service.dart';
import 'services/contacts_service.dart';
import 'screens/conversations_screen.dart';
import 'theme/app_theme.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // Initialize Firebase (Requires flutterfire configure)
  try {
    await Firebase.initializeApp();
  } catch (e) {
    print('Firebase initialization error: $e');
  }

  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    statusBarIconBrightness: Brightness.light,
  ));
  
  // Register services before app starts
  Get.put(ContactsService(), permanent: true);
  Get.put(WhatsAppService(), permanent: true);
  Get.put(FirebaseService(), permanent: true);
  
  // Initialize Contacts Service
  await Get.find<ContactsService>().init();
  Get.find<FirebaseService>().init();
  
  runApp(const WhatsAppApp());
}

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

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'WhatsApp App',
      debugShowCheckedModeBanner: false,
      theme: AppTheme.dark,
      home: const ConversationsScreen(),
      defaultTransition: Transition.cupertino,
    );
  }
}
