import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/bookable_spaces_params.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_bloc.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/steps_cubit/cubit/steps_cubit.dart';
import 'package:syncrow_web/utils/color_manager.dart';

class ButtonsDividerBottomDialogWidget extends StatelessWidget {
  final String title;
  final void Function()? onNextPressed;
  final void Function() onCancelPressed;
  const ButtonsDividerBottomDialogWidget({
    super.key,
    required this.title,
    required this.onNextPressed,
    required this.onCancelPressed,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        const Divider(
          thickness: 0.5,
          height: 1,
        ),
        Row(
          children: [
            Expanded(
              child: InkWell(
                borderRadius: const BorderRadius.only(
                  bottomLeft: Radius.circular(26),
                ),
                onTap: onCancelPressed,
                child: Container(
                  height: 40,
                  alignment: Alignment.center,
                  decoration: const BoxDecoration(
                    border: Border(
                      right: BorderSide(
                        color: ColorsManager.grayBorder,
                      ),
                    ),
                    borderRadius: BorderRadius.only(
                      bottomLeft: Radius.circular(26),
                    ),
                  ),
                  child: const Text(
                    'Cancel',
                    style: TextStyle(color: ColorsManager.blackColor),
                  ),
                ),
              ),
            ),
            Expanded(
              child:
                  BlocConsumer<NonBookableSpacesBloc, NonBookableSpacesState>(
                listener: (context, nonBookableState) {
                  if (nonBookableState is NonBookableSpacesInitial) {
                    context.pop();
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(
                        content: Text(
                          'Spaces Added Successfully',
                          style: TextStyle(color: ColorsManager.activeGreen),
                        ),
                        duration: Duration(seconds: 2),
                        behavior: SnackBarBehavior.floating,
                      ),
                    );
                    context.read<BookableSpacesBloc>().add(
                          LoadBookableSpacesEvent(
                            BookableSpacesParams(currentPage: 1),
                          ),
                        );
                  } else if (nonBookableState is NonBookableSpacesError) {
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(
                        content: Text(
                          nonBookableState.error,
                          style:
                              const TextStyle(color: ColorsManager.activeGreen),
                        ),
                        duration: const Duration(seconds: 2),
                        behavior: SnackBarBehavior.floating,
                      ),
                    );
                  }
                },
                builder: (context, nonBookableState) {
                  return TextButton(
                    onPressed: onNextPressed,
                    child: Text(
                      title,
                    ),
                  );
                },
              ),
            )
          ],
        )
      ],
    );
  }
}
