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

import 'data/autopilot_state.dart';
import 'theme/theme_provider.dart';
import 'screens/cockpit/cockpit_screen.dart';
import 'screens/settings/appearance_settings.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final themeProvider = await AutopilotThemeProvider.load();
  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider<AutopilotThemeProvider>.value(
          value: themeProvider,
        ),
        // AutopilotState drives the cockpit UI.
        // Sprint 4: internal demo timer (vessel simulation).
        // Sprint 7: replace with AutopilotStateModbus or wire Modbus RTU here.
        ChangeNotifierProvider<AutopilotState>(
          create: (_) => AutopilotState(),
        ),
      ],
      child: const ArAutopilotApp(),
    ),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AR-Autopilot',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(useMaterial3: true),
      initialRoute: CockpitScreen.routeName,
      routes: {
        CockpitScreen.routeName: (_) => const CockpitScreen(),
        AppearanceSettingsScreen.routeName: (_) =>
            const AppearanceSettingsScreen(),
      },
    );
  }
}
