import '../../../../../food_delivery_client.dart';

class MainPage extends StatelessWidget with MainPageMixin {
  MainPage({super.key});

  @override
  Widget build(BuildContext context) {
    final List<String> labels = [
      context.loc.home,
      context.loc.browse,
      context.loc.baskets,
      context.loc.account,
    ];
    return BlocProvider(
      create: (context) => sl<MainBloc>(),
      child: BlocBuilder<MainBloc, MainState>(
        builder: (context, state) {
          return Scaffold(
            body: IndexedStack(
              index: state.currentIndex,
              sizing: StackFit.expand,
              alignment: AlignmentGeometry.center,
              children: pages,
            ),
            bottomNavigationBar: BottomNavigationBar(
              onTap: (value) {
                context.read<MainBloc>().add(MainEvent.loaded(value));
              },
              currentIndex: state.currentIndex,
              items: List.generate(
                defaultIcons.length,
                (index) => BottomNavigationBarItem(
                  icon: defaultIcons[index].paddingOnly(bottom: 4.85),
                  activeIcon: activeIcons[index].paddingOnly(bottom: 4.85),
                  label: labels[index],
                  tooltip: labels[index],
                  backgroundColor: AppColors.cFFFFFF,
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}
