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

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

  @override
  Widget build(BuildContext context) {
    final selectionBloc = context.watch<CommunitiesTreeSelectionBloc>().state;
    final selectedCommunity = selectionBloc.selectedCommunity;
    final selectedSpace = selectionBloc.selectedSpace;
    const spacer = Spacer(flex: 10);
    return Visibility(
      visible: selectedCommunity!.spaces.isNotEmpty,
      replacement: const Row(
        children: [spacer, Expanded(child: CreateSpaceButton()), spacer],
      ),
      child: CommunityStructureCanvas(
        community: selectedCommunity,
        selectedSpace: selectedSpace,
      ),
    );
  }
}
