import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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';

class CommunitiesTreeFailureWidget extends StatelessWidget {
  const CommunitiesTreeFailureWidget({super.key, this.errorMessage});

  final String? errorMessage;

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              errorMessage ?? 'Something went wrong',
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: () => context.read<CommunitiesBloc>().add(
                    LoadCommunities(
                      LoadCommunitiesParam(
                        search: context.read<CommunitiesBloc>().state.searchQuery,
                      ),
                    ),
                  ),
              child: const Text('Retry'),
            ),
          ],
        ),
      ),
    );
  }
}
