import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../application/auth/auth_bloc.dart';
import '../../router/app_router.gr.dart';
import 'widgets/bottom_navbar.dart';

@RoutePage()
class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  @override
  initState() {
    super.initState();
    context.read<AuthBloc>().add(const AuthEvent.fetchCurrentUser());
  }

  @override
  Widget build(BuildContext context) {
    return AutoTabsRouter.pageView(
      routes: [HomeRoute(), VoucherRoute(), OrderRoute(), ProfileRoute()],
      physics: const NeverScrollableScrollPhysics(),
      builder: (context, child, pageController) => Scaffold(
        body: child,
        bottomNavigationBar: MainBottomNavbar(
          tabsRouter: AutoTabsRouter.of(context),
        ),
      ),
    );
  }
}
