import 'package:fforte/addCam/add_cam_main.dart';
import 'package:fforte/intro_screen.dart';
import 'package:fforte/settings.dart';
import 'package:fforte/viewCam/view_cams.dart';
import 'package:flutter/material.dart';
import 'package:flex_color_scheme/flex_color_scheme.dart';
import '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 {
  runApp(const MyApp());
} */

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SharedPreferences prefs = await SharedPreferences.getInstance();
  bool isFirstLaunch = prefs.getBool('isFirstLaunch') ?? true;
  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(),
      },
    );
  }
}
