import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/space_management_body.dart';
import 'package:syncrow_web/pages/space_management_v2/modules/communities/data/services/debounced_communities_service.dart';
import 'package:syncrow_web/pages/space_management_v2/modules/communities/data/services/remote_communities_service.dart';
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.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/services/api/http_service.dart';
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
import 'package:syncrow_web/web_layout/web_scaffold.dart';

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

  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
      providers: [
        BlocProvider(
          create: (context) => CommunitiesBloc(
            communitiesService: DebouncedCommunitiesService(
              RemoteCommunitiesService(HTTPService()),
            ),
          )..add(const LoadCommunities(LoadCommunitiesParam())),
        ),
        BlocProvider(create: (context) => CommunitiesTreeSelectionBloc()),
      ],
      child: WebScaffold(
        appBarTitle: Text(
          'Space Management',
          style: ResponsiveTextTheme.of(context).deviceManagementTitle,
        ),
        enableMenuSidebar: false,
        centerBody: Text(
          'Community Structure',
          style: Theme.of(context).textTheme.bodyLarge!.copyWith(
                fontWeight: FontWeight.bold,
              ),
        ),
        rightBody: const NavigateHomeGridView(),
        scaffoldBody: const SpaceManagementBody(),
      ),
    );
  }
}
