import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/space_management_community_structure.dart';
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/space_management_templates_view.dart';
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart';
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/widgets/space_management_communities_tree.dart';

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

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        const SpaceManagementCommunitiesTree(),
        Expanded(
          child: BlocBuilder<CommunitiesTreeSelectionBloc,
              CommunitiesTreeSelectionState>(
            buildWhen: (previous, current) =>
                previous.selectedCommunity != current.selectedCommunity,
            builder: (context, state) => Visibility(
              visible: state.selectedCommunity == null,
              replacement: const SpaceManagementCommunityStructure(),
              child: const SpaceManagementTemplatesView(),
            ),
          ),
        ),
      ],
    );
  }
}
