import 'package:legacy_dashboard_shell/src/presentation/legacy_main_shell_view_model.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:legacy_dashboard_shell/src/presentation/legacy_main_shell_view_state.dart';
import 'package:navigation/navigation.dart';
import 'package:sf_localizations/sf_localizations.dart';

final mainShellViewModelProvider =
    NotifierProvider.autoDispose<LegacyMainShellViewModel, LegacyMainShellViewState>(
      () => LegacyMainShellViewModel(),
    );

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

  const LegacyDashboardScreen({
    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: [
          NavigationDestination(
            icon: Icon(Icons.home_outlined),
            label: context.translate(I18n.home),
          ),
          NavigationDestination(
            icon: Icon(SFIcons.functions),
            label: context.translate(I18n.functions),
          ),
          NavigationDestination(
            icon: Icon(SFIcons.locationOutlined),
            label: context.translate(I18n.location),
          ),
          NavigationDestination(
            icon: Icon(SFIcons.chat),
            label: context.translate(I18n.chat),
          ),
        ],
      ),
    );
  }
}
