import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
import 'package:syncrow_web/pages/device_managment/schedule_device/bloc/schedule_bloc.dart';
import 'package:syncrow_web/pages/device_managment/water_heater/models/water_heater_status_model.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/pages/device_managment/water_heater/bloc/water_heater_bloc.dart'
    hide StopScheduleEvent;
import 'package:syncrow_web/utils/extension/build_context_x.dart';

class InchingModeButtons extends StatelessWidget {
  final bool isActive;
  final String deviceId;
  final int hours;
  final int minutes;

  const InchingModeButtons({
    Key? key,
    required this.isActive,
    required this.deviceId,
    required this.hours,
    required this.minutes,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Expanded(
          child: DefaultButton(
            height: 40,
            onPressed: () => Navigator.pop(context),
            backgroundColor: ColorsManager.boxColor,
            child: Text('Cancel', style: context.textTheme.bodyMedium),
          ),
        ),
        const SizedBox(width: 20),
        Expanded(
          child: isActive
              ? DefaultButton(
                  height: 40,
                  onPressed: () {
                    context.read<ScheduleBloc>().add(
                          StopScheduleEvent(
                              deviceId: deviceId,
                              mode: ScheduleModes.inching,
                              countdownCode: ''),
                        );
                  },
                  backgroundColor: Colors.red,
                  child: const Text('Stop'),
                )
              : DefaultButton(
                  height: 40,
                  onPressed: () {
                    context.read<WaterHeaterBloc>().add(
                          ToggleWaterHeaterEvent(
                            deviceId: deviceId,
                            code: 'switch_inching',
                            value: Duration(hours: hours, minutes: minutes)
                                .inSeconds,
                          ),
                        );
                  },
                  backgroundColor: ColorsManager.primaryColor,
                  child: const Text('Save'),
                ),
        ),
      ],
    );
  }
}
