import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_event.dart';
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_state.dart';
import '../bloc/center_body_bloc.dart';

class CenterBodyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<CenterBodyBloc, CenterBodyState>(
      builder: (context, state) {
        if (state is InitialState) {
          context.read<CenterBodyBloc>().add(CommunityStructureSelectedEvent());
        }
        if (state is CommunityStructureState) {
          context.read<SpaceManagementBloc>().add(BlankStateEvent(context));
        }

        if (state is SpaceModelState) {
          context.read<SpaceManagementBloc>().add(SpaceModelLoadEvent(context));
        }

        return Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  GestureDetector(
                    onTap: state is CommunityStructureState ||
                            state is CommunitySelectedState
                        ? null
                        : () {
                            context
                                .read<CenterBodyBloc>()
                                .add(CommunityStructureSelectedEvent());
                          },
                    child: Text(
                      'Community Structure',
                      style: Theme.of(context).textTheme.bodyLarge!.copyWith(
                            fontWeight: state is CommunityStructureState ||
                                    state is CommunitySelectedState
                                ? FontWeight.bold
                                : FontWeight.normal,
                            color: state is CommunityStructureState ||
                                    state is CommunitySelectedState
                                ? Theme.of(context).textTheme.bodyLarge!.color
                                : Theme.of(context)
                                    .textTheme
                                    .bodyLarge!
                                    .color!
                                    .withOpacity(0.5),
                          ),
                    ),
                  ),
                  const SizedBox(width: 20),
                  // GestureDetector(
                  //   onTap: () {
                  //     context.read<CenterBodyBloc>().add(SpaceModelSelectedEvent());
                  //   },
                  //   child: Text(
                  //     'Space Model',
                  //     style: Theme.of(context).textTheme.bodyLarge!.copyWith(
                  //           fontWeight: state is SpaceModelState
                  //               ? FontWeight.bold
                  //               : FontWeight.normal,
                  //           color: state is SpaceModelState
                  //               ? Theme.of(context).textTheme.bodyLarge!.color
                  //               : Theme.of(context)
                  //                   .textTheme
                  //                   .bodyLarge!
                  //                   .color!
                  //                   .withOpacity(0.5),
                  //         ),
                  //   ),
                  // ),
                ],
              ),
            ],
          ),
        );
      },
    );
  }
}
