import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_tab/analytics_tab_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/analytics_data_loading_strategy_factory.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/widgets/sidebar/analytics_space_tree_view.dart';

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

  @override
  Widget build(BuildContext context) {
    final selectedTab = context.watch<AnalyticsTabBloc>().state;
    final strategy = AnalyticsDataLoadingStrategyFactory.getStrategy(selectedTab);

    return Expanded(
      child: AnalyticsSpaceTreeView(
        onSelectCommunity: (community, spaces) {
          strategy.onCommunitySelected(context, community, spaces);
        },
        onSelectSpace: (community, space) {
          strategy.onSpaceSelected(context, community, space);
        },
        onSelectChildSpace: (community, child) {
          strategy.onSpaceSelected(context, community, child);
        },
      ),
    );
  }
}
