import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'game/data/item_table.dart';
import 'game/data/enemy_table.dart';
import 'game/data/player_table.dart';
import 'providers.dart';
import 'screens.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await ItemTable.load();
  await EnemyTable.load();
  await PlayerTable.load();
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (_) => SettingsProvider(),
        ), // Register SettingsProvider
        ChangeNotifierProvider(create: (_) => ShopProvider()),
        ChangeNotifierProxyProvider<ShopProvider, BattleProvider>(
          create: (context) => BattleProvider(
            shopProvider: Provider.of<ShopProvider>(context, listen: false),
          ),
          update: (context, shopProvider, battleProvider) =>
              battleProvider ?? BattleProvider(shopProvider: shopProvider),
        ),
      ],
      child: MaterialApp(
        title: "Colosseum's Choice",
        theme: ThemeData.dark(),
        home: const MainMenuScreen(),
      ),
    );
  }
}
