import 'package:flutter/material.dart';
import 'adjust/adjust_service.dart';
import 'screens/game_screen_flame.dart';
import 'screens/loading_screen.dart';
import 'screens/start_screen.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await AdjustService.instance.init('ewkk4whk2mtc');
  runApp(const MyApp());
}

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

  static const String routeLoading = '/loading';
  static const String routeStart = '/start';
  static const String routeGame = '/game';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Kawaii Flip Friends',
      theme: ThemeData(useMaterial3: false),
      initialRoute: routeLoading,
      onGenerateRoute: (settings) {
        switch (settings.name) {
          case routeLoading:
            return MaterialPageRoute(
              builder: (_) => const LoadingScreen(),
              settings: settings,
            );

          case routeStart:
            return MaterialPageRoute(
              builder: (_) => const StartScreen(),
              settings: settings,
            );

          case routeGame:
            final args = settings.arguments as Map<String, dynamic>?;
            final levelId = args?['levelId'] as int? ?? 1;

            return MaterialPageRoute(
              builder: (_) => GameScreenFlame(levelId: levelId),
              settings: settings,
            );

          default:
            return MaterialPageRoute(
              builder: (_) => const LoadingScreen(),
              settings: settings,
            );
        }
      },
    );
  }
}
