import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';

class AppBody extends StatelessWidget {
  const AppBody({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return BlocConsumer<HomeCubit, HomeState>(
      listener: (context, state) {
        if (state is GetSpacesError) {
          ScaffoldMessenger.of(context).removeCurrentSnackBar();
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(
              content: Text(state.errMessage),
            ),
          );
        }
      },
      builder: (context, state) {
        return state is! GetSpacesLoading
            ? state is! GetSpaceRoomsLoading
                ? HomeCubit.getInstance().pages[HomeCubit.pageIndex]
                : const Center(child: CircularProgressIndicator())
            : const Center(child: CircularProgressIndicator());
      },
    );
  }
}
