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/utils/extension/build_context_x.dart';

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

  const CountdownModeButtons({
    super.key,
    required this.isActive,
    required this.deviceId,
    required this.hours,
    required this.minutes,
    required this.countDownCode,
  });

  @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(
                            mode: ScheduleModes.countdown,
                            deviceId: deviceId,
                            countdownCode: countDownCode,
                          ),
                        );
                  },
                  backgroundColor: Colors.red,
                  child: const Text('Stop'),
                )
              : DefaultButton(
                  height: 40,
                  onPressed: () {
                    context.read<ScheduleBloc>().add(
                          StartScheduleEvent(
                              mode: ScheduleModes.countdown,
                              hours: hours,
                              minutes: minutes,
                              countDownCode: countDownCode),
                        );
                  },
                  backgroundColor: ColorsManager.primaryColor,
                  child: const Text('Save'),
                ),
        ),
      ],
    );
  }
}
