import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/model/ac_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';

class ACModeControlUnit extends StatelessWidget {
  const ACModeControlUnit(
      {super.key, required this.acStatus, required this.deviceId, this.productId = ''});

  final AcStatusModel acStatus;
  final String deviceId;
  final String? productId;

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ACsBloc, AcsState>(
      builder: (context, state) {
        return Row(
          children: [
            Flexible(
              child: GestureDetector(
                onTap: () {
                  if (state is! AcChangeLoading && state is! AcsLoadingState) {
                    BlocProvider.of<ACsBloc>(context).add(ChangeFanSpeed(
                        fanSpeeds: acStatus.acFanSpeed,
                        deviceId: deviceId,
                        productId: productId ?? ''));
                  }
                  // else if (state is AcModifyingState) {
                  //   BlocProvider.of<ACsBloc>(context)
                  //       .add(ChangeFanSpeed(fanSpeeds: state.acStatusModel.acFanSpeed));
                  // }
                },
                child: DefaultContainer(
                  height: 55,
                  child: Center(child: SvgPicture.asset(fanSpeedsIconMap[acStatus.acFanSpeed]!)),
                ),
              ),
            ),
            const SizedBox(width: 10),
            Flexible(
              child: GestureDetector(
                onTap: () {
                  // if (state is GetAcStatusState) {
                  //   BlocProvider.of<ACsBloc>(context)
                  //       .add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
                  // } else if (state is AcModifyingState) {
                  //   BlocProvider.of<ACsBloc>(context)
                  //       .add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
                  // }
                  if (state is! AcChangeLoading && state is! AcsLoadingState) {
                    BlocProvider.of<ACsBloc>(context).add(ChangeAcMode(
                        tempModes: acStatus.acMode,
                        deviceId: deviceId,
                        productId: productId ?? ''));
                  }
                },
                child: DefaultContainer(
                  height: 55,
                  child: Center(
                    child: SvgPicture.asset(tempModesIconMap[acStatus.acMode]!),
                  ),
                ),
              ),
            ),
          ],
        );
      },
    );
  }
}
