import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_bloc.dart';
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_event.dart';
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_state.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 ScheduleGarageDoorModeSelector extends StatelessWidget {
  final GarageDoorLoadedState state;

  const ScheduleGarageDoorModeSelector({super.key, required this.state});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          'Type:',
          style: context.textTheme.bodySmall!.copyWith(
            fontSize: 13,
            color: ColorsManager.grayColor,
          ),
        ),
        const SizedBox(height: 4),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            _buildRadioTile(context, 'Schedule', ScheduleModes.schedule, state),
          ],
        ),
      ],
    );
  }

  Widget _buildRadioTile(BuildContext context, String label, ScheduleModes mode, GarageDoorLoadedState state) {
    return Flexible(
      child: ListTile(
        contentPadding: EdgeInsets.zero,
        title: Text(
          label,
          style: context.textTheme.bodySmall!.copyWith(
            fontSize: 13,
            color: ColorsManager.blackColor,
          ),
        ),
        leading: Radio<ScheduleModes>(
          value: mode,
          groupValue: state.scheduleMode,
          onChanged: (ScheduleModes? value) {
            if (value != null) {
              if (value == ScheduleModes.schedule) {
                context.read<GarageDoorBloc>().add(
                      FetchGarageDoorSchedulesEvent(
                        category: 'switch_1',
                        deviceId: state.status.uuid,
                      ),
                    );
              }
            }
          },
        ),
      ),
    );
  }
}
