import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:routemaster/routemaster.dart';

import 'Controller/background_task_controller.dart';
import 'Controller/local_notifications.dart';
import 'Controller/port_controller.dart';
import 'Services/navigation_service.dart';
import 'Services/router_service.dart';
import 'Services/theme_service.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  PortController();
  BackgroundTaskController();

  if (!kIsWeb) {
    LocalNotifications();
  }

  runApp(
    MaterialApp.router(
      routerDelegate: RoutemasterDelegate(
        routesBuilder: (final BuildContext context) => RouterService.routes,
        navigatorKey: NavigationService.navigatorKey,
      ),
      routeInformationParser: const RoutemasterParser(),

      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: const [Locale('de')],

      title: 'DragonLedger 🐉📒',
      theme: ThemeService.getLightTheme(),
      darkTheme: ThemeService.getDarkTheme(),
    ),
  );
}
