import 'package:fforte/screens/Excursion/excursion_main.dart';
import 'package:fforte/screens/addCam/add_cam_main.dart';
import 'package:fforte/screens/intro_screen.dart';
import 'package:fforte/screens/settings.dart';
import 'package:fforte/screens/viewCam/view_cams.dart';
import 'package:flutter/material.dart';
import 'package:flex_color_scheme/flex_color_scheme.dart';
mport 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'home.dart';
import 'l10n/l10n.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SharedPreferences prefs = await SharedPreferences.getInstance();
  bool isFirstLaunch = prefs.getBool('isFirstLaunch') ?? true;
  await prefs.setString('kTage1', "28");
  await prefs.setString('kTage2', "48");
  await prefs.setString(
      'apiAddress', 'http://192.168.1.106/www.dbb-wolf.de/data/app24.php');
  runApp(MyApp(isFirstLaunch: isFirstLaunch));
}

class MyApp extends StatelessWidget {
  final bool isFirstLaunch;
  const MyApp({super.key, required this.isFirstLaunch});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'FFOrte',
      theme: FlexThemeData.light(scheme: FlexScheme.gold, useMaterial3: true),
      darkTheme:
          FlexThemeData.dark(scheme: FlexScheme.greenM3, useMaterial3: true),
      themeMode: ThemeMode.system,
      initialRoute: isFirstLaunch ? '/introScreen' : '/home',
      supportedLocales: L10n.all,
      localizationsDelegates: const [
        AppLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      routes: {
        '/home': (context) => const HomePage(),
        '/addCamMain': (context) => const AddCamMain(),
        '/viewCams': (context) => const ViewCams(),
        '/introScreen': (context) => const IntroScreen(),
        '/settings': (context) => const Settings(),
        '/excursion': (context) => const ExcursionMain(),
      },
    );
  }
}
