import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/data/remote_non_bookable_spaces.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/non_bookable_spaces_params.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/pages/access_management/manage_bookable_spaces/presentation/widgets/details_steps_widget.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/next_first_step_button.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/save_second_step_button.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/stepper_part_widget.dart';
import 'package:syncrow_web/services/api/http_service.dart';
import 'package:syncrow_web/utils/color_manager.dart';

class SetupBookableSpacesDialog extends StatelessWidget {
  final TextEditingController pointsController = TextEditingController();
  SetupBookableSpacesDialog({super.key});
  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
      providers: [
        BlocProvider<StepsCubit>(
          create: (context) => StepsCubit()..initDialogValue(),
        ),
        BlocProvider<NonBookableSpacesBloc>(
          create: (context) => NonBookableSpacesBloc(
            RemoteNonBookableSpaces(HTTPService()),
          )..add(
              LoadUnBookableSpacesEvent(
                nonBookableSpacesParams:
                    NonBookableSpacesParams(currentPage: 1),
              ),
            ),
        ),
      ],
      child: AlertDialog(
        backgroundColor: ColorsManager.whiteColors,
        contentPadding: EdgeInsets.zero,
        title: Center(
          child: Text(
            'Set Up a Bookable Spaces',
            style: TextStyle(
              fontWeight: FontWeight.w700,
              color: ColorsManager.dialogBlueTitle,
              fontSize: 15,
            ),
          ),
        ),
        content: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            const Divider(),
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                const Expanded(
                  flex: 3,
                  child: StepperPartWidget(),
                ),
                const SizedBox(
                  height: 588,
                  child: VerticalDivider(
                    thickness: 0.5,
                    width: 1,
                  ),
                ),
                Expanded(
                  flex: 7,
                  child: DetailsStepsWidget(
                    pointsController: pointsController,
                  ),
                )
              ],
            ),
            Builder(builder: (context) {
              final stepsState = context.watch<StepsCubit>().state;
              final nonBookableBloc = context.watch<NonBookableSpacesBloc>();
              final selectedSpaces = nonBookableBloc.selectedBookableSpaces;
              return stepsState is StepOneState
                  ? NextFirstStepButton(selectedSpaces: selectedSpaces)
                  : SaveSecondStepButton(
                      selectedSpaces: selectedSpaces,
                      pointsController: pointsController);
            }),
          ],
        ),
      ),
    );
  }
}
