import 'package:frontend_eccp_mobile/app/core/constants/globalkey.dart';
import 'package:frontend_eccp_mobile/app/core/navigation/app_routes.dart';
import 'package:frontend_eccp_mobile/app/core/navigation/main_navigation_page.dart';
import 'package:frontend_eccp_mobile/modules/auth/login/presentation/screen/login_page.dart';
import 'package:frontend_eccp_mobile/modules/splash/presentation/screen/splash_screen.dart';
import 'package:frontend_eccp_mobile/modules/update/presentation/update_page.dart';
import 'package:go_router/go_router.dart';

class AppRouter {
  AppRouter._();

  static final router = GoRouter(
    initialLocation: AppRoutes.splash,

    navigatorKey: navigatorKey,

    routes: [
      GoRoute(
        path: AppRoutes.splash,
        builder: (context, state) => const SplashScreen(),
      ),
      GoRoute(
        path: AppRoutes.updateApp,
        builder: (context, state) {
          final extra = state.extra as Map<String, dynamic>?;

          final version = extra?['version'] as String? ?? '';
          final link = extra?['link'] as String? ?? '';

          return UpdatePage(
            version: version,
            link: link,
          );
        },
      ),
      GoRoute(
        path: AppRoutes.login,
        builder: (context, state) => const LoginPage(),
      ),
      GoRoute(
        path: AppRoutes.home,
        builder: (context, state) => const MainNavigationPage(),
      ),
      GoRoute(
        path: AppRoutes.berkas,
        builder: (context, state) => const MainNavigationPage(
          initialIndex: 1,
        ),
      ),

      GoRoute(
        path: AppRoutes.settings,
        builder: (context, state) => const MainNavigationPage(
          initialIndex: 2,
        ),
      ),
    ],
  );
}
