import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'presentation/pages/main_page.dart';
import 'presentation/pages/pokemon_detail.dart';
import 'presentation/pages/game_over_page.dart';
import 'presentation/providers/theme_provider.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
    sqfliteFfiInit();
    databaseFactory = databaseFactoryFfi;
  }
  runApp(const ProviderScope(child: MyApp()));
}

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

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final paletteIndex = ref.watch(themeProvider);
    final palette = appPalettes[paletteIndex];

    return MaterialApp(
      title: 'Pokéguess',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: palette.primary,
          surface: palette.surface,
        ),
        textTheme: GoogleFonts.vt323TextTheme(
          Theme.of(context).textTheme,
        ).apply(
          bodyColor: Colors.black87,
          displayColor: Colors.black87,
        ),
        useMaterial3: true,
      ),
      debugShowCheckedModeBanner: false,
      routes: {
        '/': (context) => const MainPage(),
        '/pokemon-detail': (context) => const PokemonDetailPage(),
        '/game-over': (context) => const GameOverPage(),
      },
    );
  }
}
