import 'package:auto_route/auto_route.dart';
import 'package:component_library/component_library.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:golek_flutter_new/routes/app_router.gr.dart';
import 'package:golek_flutter_new/screen_view_observer.dart';
import 'package:monitoring/monitoring.dart';

import 'l10n/app_localizations.dart';

class GolekTruk extends StatefulWidget {
  const GolekTruk({Key? key}) : super(key: key);

  @override
  State<GolekTruk> createState() => _GolekTrukState();
}

class _GolekTrukState extends State<GolekTruk> {
  final _lightTheme = LightGolekThemeData();
  final _darkTheme = DarkGolekThemeData();
  final _appRouter = AppRouter();
  final _analyticsService = AnalyticsService();

  @override
  Widget build(BuildContext context) {
    return GolekTheme(
      darkTheme: _darkTheme,
      lightTheme: _lightTheme,
      child: MaterialApp.router(
        debugShowCheckedModeBanner: false,
        title: 'GolekTruk',
        darkTheme: _darkTheme.materialThemeData,
        theme: _lightTheme.materialThemeData,
        themeMode: ThemeMode.light,
        localizationsDelegates: const [
          GlobalCupertinoLocalizations.delegate,
          GlobalMaterialLocalizations.delegate,
          AppLocalizations.delegate,
          ComponentLibraryLocalizations.delegate,
        ],
        supportedLocales: const [
          Locale('en', ''),
          Locale('id', 'ID'),
        ],
        backButtonDispatcher: RootBackButtonDispatcher(),
        routeInformationParser: _appRouter.defaultRouteParser(),
        routerDelegate: AutoRouterDelegate(
          _appRouter,
          navigatorObservers: () => [
            AutoRouteObserver(),
            ScreenViewObserver(analyticsService: _analyticsService)
          ],
        ),
      ),
    );
  }
}
