import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:provider/provider.dart';

// [C] 공통 서비스
import 'package:service_api/service_api.dart';
// [A] 공통 UI 셸 (인트로 화면)
import 'package:feature_common/feature_common.dart'; 
// [B] 카드 뒤집기 게임 (로비 화면)
import 'package:feature_game_cardflip/feature_game_cardflip.dart'; 

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await MobileAds.instance.initialize();

  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => ThemeNotifier()),
        ChangeNotifierProvider(create: (_) => SessionNotifier()),
        Provider(create: (_) => PuzzleService()),
        Provider(create: (_) => IdentityService()),
      ],
      child: const MyApp(),
    ),
  );
}

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

  @override
  Widget build(BuildContext context) {
    final themeData = context.select((ThemeNotifier n) => n.currentTheme);
    final darkThemeData = context.select((ThemeNotifier n) => n.currentDarkTheme);
    final themeMode = context.select((ThemeNotifier n) => n.currentThemeMode);

    return MaterialApp(
      title: '기억력 카드 뒤집기',
      theme: themeData,
      darkTheme: darkThemeData,
      themeMode: themeMode,
      debugShowCheckedModeBanner: false,

      // 🔽 CardFlipLobbyScreen으로 연결
      home: IntroScreen(
        nextScreenBuilder: (context) => const CardFlipLobbyScreen(),
      ),
    );
  }
}