import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hl_lieferservice/widget/home/bloc/navigation_bloc.dart';
import 'package:hl_lieferservice/widget/home/bloc/navigation_event.dart';
import 'package:hl_lieferservice/widget/home/bloc/navigation_state.dart';

class AppNavigationBar extends StatefulWidget {
  const AppNavigationBar({super.key});

  @override
  State<StatefulWidget> createState() => _AppNavigationBarState();
}

class _AppNavigationBarState extends State<AppNavigationBar> {
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<NavigationBloc, NavigationState>(
      builder: (context, state) {
        if (state is NavigationInfo) {
          return NavigationBar(
            selectedIndex: state.navigationIndex,
            destinations: const [
              NavigationDestination(
                icon: Icon(Icons.barcode_reader),
                label: "Beladung",
              ),
              NavigationDestination(
                icon: Icon(Icons.fire_truck),
                label: "Auslieferung",
              ),
              NavigationDestination(
                icon: Icon(Icons.local_shipping),
                label: "Fahrzeuge",
              ),
            ],
            onDestinationSelected: (int index) {
              context.read<NavigationBloc>().add(NavigateToIndex(index: index));
            },
          );
        }

        return Container();
      },
    );
  }
}
