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

import '../blocs/client_main_cubit.dart';
import '../blocs/client_main_state.dart';
import '../widgets/client_main_bottom_bar.dart';

/// The main page for the Client app, acting as a shell for the bottom navigation.
///
/// It follows KROW Clean Architecture by:
/// - Being a [StatelessWidget].
/// - Delegating state management to [ClientMainCubit].
/// - Using [RouterOutlet] for nested navigation.
class ClientMainPage extends StatelessWidget {
  const ClientMainPage({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider<ClientMainCubit>(
      create: (BuildContext context) => Modular.get<ClientMainCubit>(),
      child: Scaffold(
        extendBody: true,
        body: const RouterOutlet(),
        bottomNavigationBar: BlocBuilder<ClientMainCubit, ClientMainState>(
          builder: (BuildContext context, ClientMainState state) {
            return ClientMainBottomBar(
              currentIndex: state.currentIndex,
              onTap: (int index) {
                BlocProvider.of<ClientMainCubit>(context).navigateToTab(index);
              },
            );
          }, 
        ),
      ),
    );
  }
}
