import 'package:dashboard_shell/src/presentation/main_shell_view_model.dart';
import 'package:dashboard_shell/src/presentation/main_shell_view_state.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:navigation/navigation.dart';

final mainShellViewModelProvider =
    NotifierProvider.autoDispose<MainShellViewModel, MainShellViewState>(
      () => MainShellViewModel(),
    );

class DashboardScreen extends ConsumerWidget {
  final NavigationContract navigationContract;
  final StatefulNavigationShell navigationShell;

  const DashboardScreen({
    super.key,
    required this.navigationContract,
    required this.navigationShell,
  });

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final theme = ref.watch(themePortProvider);
    final viewState = ref.watch(mainShellViewModelProvider);
    final viewModel = ref.read(mainShellViewModelProvider.notifier);

    return Scaffold(
      body: navigationShell,
      bottomNavigationBar: NavigationBar(
        backgroundColor: theme.getColorFor(ThemeCode.backgroundPrimary),
        selectedIndex: viewState.selectedIndex,
        onDestinationSelected: (index) {
          viewModel.onTabChanged(index);
          navigationShell.goBranch(index);
        },
        destinations: const [
          NavigationDestination(icon: Icon(Icons.home_outlined), label: "Home"),
          NavigationDestination(
            icon: Icon(Icons.watch_outlined),
            label: "Activity",
          ),
          NavigationDestination(
            icon: Icon(Icons.notifications_outlined),
            label: "Notifications",
          ),
          NavigationDestination(
            icon: Icon(Icons.person_outline_outlined),
            label: "Profile",
          ),
        ],
      ),
    );
  }
}
