import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'core/theme_manager.dart';
import 'logic/game_controller.dart';
import 'ui/home/home_screen.dart';
import 'services/storage_service.dart'; // <-- Importiamo il servizio
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

void main() async {
  // Assicuriamoci che i motori di Flutter siano pronti
  WidgetsFlutterBinding.ensureInitialized();

  // 1. Accendiamo Firebase! (Questo ti era sfuggito)
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  // 2. Accendiamo la Memoria Locale!
  await StorageService.instance.init();

  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => ThemeManager()),
        ChangeNotifierProvider(create: (_) => GameController()),
      ],
      child: const TetraQApp(),
    ),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'TetraQ',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        fontFamily: 'Roboto',
        useMaterial3: true,
      ),
      home: const HomeScreen(),
    );
  }
}