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/models/bookable_space_model.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/widgets/buttons_divider_bottom_dialog_widget.dart';

class SaveSecondStepButton extends StatelessWidget {
  final List<BookableSpacemodel> selectedSpaces;
  final TextEditingController pointsController;

  const SaveSecondStepButton({
    super.key,
    required this.selectedSpaces,
    required this.pointsController,
  });

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<NonBookableSpacesBloc, NonBookableSpacesState>(
      builder: (context, state) {
        return ButtonsDividerBottomDialogWidget(
          title: 'Save',
          onNextPressed: state is UnValidSaveButtonState
              ? null
              : () {
                  if (selectedSpaces.any(
                    (element) => element.isValid,
                  )) {
                    context.read<NonBookableSpacesBloc>().add(
                          SendBookableSpacesToApi(),
                        );
                  }
                },
          onCancelPressed: () => context.pop(),
        );
      },
    );
  }
}
