import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tanami_app/features/MainScreens/Academy/presentation/pages/academy_screen.dart';
import 'package:tanami_app/features/MainScreens/Invest/presentation/pages/invest_screen.dart';
import 'package:tanami_app/features/MainScreens/Portfolio/presentation/pages/portfolio_screen.dart';
import 'package:tanami_app/features/MainScreens/Settings/presentation/pages/settings_Screen.dart';
import 'package:tanami_app/features/MainScreens/Wallet/presentation/pages/walletScreen.dart';
import 'package:tanami_app/shared/components/common_bottom_navigation.dart';

import '../../shared/components/bloc/bottom_nav_bar/bottom_navigation_bloc.dart';
import '../../shared/components/bloc/bottom_nav_bar/bottom_navigation_event.dart';
import '../../shared/components/bloc/bottom_nav_bar/bottom_navigation_state.dart';
import '../../shared/components/exit_app_dialog.dart';

var currentTab = [
  const WalletScreen(),
  // const KYCScreen(),
  const PortfolioScreen(),
  const InvestScreen(),
  const AcademyScreen(),
  const SettingsScreen(),
];

var selectedIndex = 1;

class MainScreen extends StatelessWidget {
  const MainScreen({super.key});
  @override
  Widget build(BuildContext context) {
    context.read<BottomNavigationBloc>().add(TabChanged(1));
    final PageController pageController = PageController(initialPage: 1);

    return BlocBuilder<BottomNavigationBloc, BottomNavigationState>(
      builder: (context, state) {
        int selectedIndex = (state as TabState).selectedIndex;
        return WillPopScope(
          onWillPop: () async {
            exitAppDialog(context);
            return false;
          },
          child: Scaffold(
            backgroundColor: const Color.fromARGB(255, 121, 104, 104),
            body: PageView(
              controller: pageController,
              physics: const NeverScrollableScrollPhysics(),
              onPageChanged: (index) {
                context.read<BottomNavigationBloc>().add(TabChanged(index));
              },
              children: const [
                WalletScreen(),
                PortfolioScreen(),
                InvestScreen(),
                AcademyScreen(),
                SettingsScreen(),
              ],
            ),
            bottomNavigationBar:
                bottomnavigationbar(context, selectedIndex, pageController),
          ),
        );
      },
    );
  }
}
