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

import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
import 'package:syncrow_app/features/app_layout/view/widgets/app_body.dart';
import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart';
import 'package:syncrow_app/features/app_layout/view/widgets/default_nav_bar.dart';
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => HomeCubit.getInstance(),
      child: BlocBuilder<HomeCubit, HomeState>(
        builder: (context, state) {
          return DefaultScaffold(
            appBar: HomeCubit.getInstance().spaces != null &&
                    HomeCubit.getInstance().spaces!.isNotEmpty
                ? const DefaultAppBar()
                : null,
            bottomNavBar: const DefaultNavBar(),
            child: const AppBody(),
          );
        },
      ),
    );
  }
}
