import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import 'package:habitrack_app/infrastructure/bottom_navigation.dart';
import 'package:habitrack_app/pages/dashboard_page.dart';
import 'package:habitrack_app/pages/widget_page.dart';

// navigators, root and each destination of bottom navigation bar
final _rootNavigatorKey = GlobalKey<NavigatorState>();

final _shellNavigatorWidgetWallKey =
    GlobalKey<NavigatorState>(debugLabel: 'widgetWall');

final _shellNavigatorDashboardKey =
    GlobalKey<NavigatorState>(debugLabel: 'dashboard');

const String _widgetWallPath = '/widgetWall';
const String _dashboardPath = '/dashboard';

final goRouter = GoRouter(
  initialLocation: _widgetWallPath,
  navigatorKey: _rootNavigatorKey,
  debugLogDiagnostics: true,
  routes: [
    StatefulShellRoute.indexedStack(
      builder: (context, state, navigationShell) {
        return ScaffoldWithBottomNavigationBar(
          navigationShell: navigationShell,
        );
      },
      branches: [
        StatefulShellBranch(
          navigatorKey: _shellNavigatorWidgetWallKey,
          routes: [
            GoRoute(
              path: _widgetWallPath,
              pageBuilder: (context, state) => const NoTransitionPage(
                child: WidgetPage(),
              ),
            ),
          ],
        ),
        StatefulShellBranch(
          navigatorKey: _shellNavigatorDashboardKey,
          routes: [
            GoRoute(
              path: _dashboardPath,
              pageBuilder: (context, state) => const NoTransitionPage(
                child: DashboardPage(),
              ),
            ),
          ],
        ),
      ],
    ),
  ],
);
