import 'package:flutter/material.dart';

import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:logger/web.dart' show DateTimeFormat, Logger, PrettyPrinter;
import 'package:fotodocumentation/controller/login_controller.dart';
import 'package:fotodocumentation/l10n/app_localizations.dart';
import 'package:fotodocumentation/utils/di_container.dart';
import 'package:fotodocumentation/utils/main_utils.dart';
import 'package:fotodocumentation/utils/global_router.dart';

import 'package:intl/date_symbol_data_local.dart';

var logger = Logger(
  printer: PrettyPrinter(methodCount: 2, errorMethodCount: 8, colors: true, printEmojis: true, dateTimeFormat: DateTimeFormat.onlyTimeAndSinceStart),
);

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  DiContainer.instance.initState();

  final theme = await ThemeLoader.loadTheme();

  await initializeDateFormatting('de_DE', null);
  LoginController loginController = DiContainer.get();
  await loginController.isUsingJwtAuth();
  runApp(FotoDocumentationApp(theme: theme));
}

class FotoDocumentationApp extends StatelessWidget {
  final ThemeData theme;

  const FotoDocumentationApp({super.key, required this.theme});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
        title: 'Hartmann Foto App',
        localizationsDelegates: [
          AppLocalizations.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
        ],
        supportedLocales: [
          Locale('de'),
        ],
        scrollBehavior: MyCustomScrollBehavior(), // <== needed for web horizontal scroll behavior
        theme: theme,
        routerConfig: GlobalRouter.router);
  }
}
