import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/curtain_module/bloc/curtain_module_bloc.dart';
import 'package:syncrow_web/pages/device_managment/curtain_module/widgets/accurate_dialog_widget.dart';
import 'package:syncrow_web/pages/device_managment/curtain_module/widgets/calibrate_completed_dialog.dart';
import 'package:syncrow_web/pages/device_managment/curtain_module/widgets/normal_text_body_for_dialog.dart';
import 'package:syncrow_web/utils/color_manager.dart';

class AccurteCalibratingDialog extends StatelessWidget {
  final String deviceId;
  final BuildContext parentContext;
  const AccurteCalibratingDialog({
    super.key,
    required this.deviceId,
    required this.parentContext,
  });

  @override
  Widget build(_) {
    return AlertDialog(
      backgroundColor: ColorsManager.whiteColors,
      contentPadding: EdgeInsets.zero,
      content: AccurateDialogWidget(
        title: 'Calibrating',
        body: const NormalTextBodyForDialog(
          title: '',
          step1:
              'Click Close Button to make the Curtain run to Full Close and Position.',
          step2: 'click Next to complete the Calibration.',
        ),
        leftOnTap: () => Navigator.of(parentContext).pop(),
        rightOnTap: () {
          parentContext.read<CurtainModuleBloc>().add(
                CurCalibrationEvent(
                  deviceId: deviceId,
                ),
              );
          Navigator.of(parentContext).pop();
          showDialog(
            context: parentContext,
            builder: (_) => CalibrateCompletedDialog(
              parentContext: parentContext,
              deviceId: deviceId,
            ),
          );
        },
      ),
    );
  }
}
