import 'package:food_delivery_client/feature/main/presentation/pages/main_page/widgtes/w_bottom_navbar_item.dart';

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

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

  @override
  Widget build(BuildContext context) {
    final List<String> inActiveIcons = [
      context.appThemeIcons.icHome,
      context.appThemeIcons.icDiscover,
      context.appThemeIcons.icCart1,
      context.appThemeIcons.icTransactions,
      context.appThemeIcons.icProfile,
    ];
    final List<String> titles = [
      context.loc.home,
      context.loc.discover,
      context.loc.cart,
      context.loc.transactions,
      context.loc.profile,
    ];

    return BlocProvider(
      create: (context) => sl<MainBloc>(),
      child: BlocBuilder<MainBloc, MainState>(
        builder: (context, state) {
          return Scaffold(
            body: IndexedStack(index: state.currentIndex, children: pages),
            bottomNavigationBar: DecoratedBox(
              decoration: BoxDecoration(
                color: context.appThemeColors.iconColor,
                boxShadow: [
                  BoxShadow(
                    blurStyle: BlurStyle.inner,
                    spreadRadius: 0,
                    color: AppColors.cA7AEC1.newWithOpacity(.15),
                    blurRadius: 80,
                    offset: const Offset(0, 4),
                  ),
                ],
              ),
              child: BottomNavigationBar(
                onTap: (value) {
                  context.read<MainBloc>().add(MainEvent.loaded(value));
                },
                currentIndex: state.currentIndex,
                items: List.generate(titles.length, (index) {
                  return BottomNavigationBarItem(
                    label: titles[index],
                    tooltip: "",
                    icon: WBottomNavbarItem(
                      iconPath: inActiveIcons[index],
                      activeIconPath: activeIcons[index],
                      title: titles[index],
                      isActive: index == state.currentIndex,
                    ),
                  );
                }),
              ),
            ),
          );
        },
      ),
    );
  }
}
