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/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/generated/assets.dart';

class ACTempWidget extends StatelessWidget {
  const ACTempWidget({
    required this.deviceModel,
    required this.temp,
    super.key,
  });

  final DeviceModel deviceModel;
  final int temp;

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ACsBloc, AcsState>(
      builder: (context, state) {
        return DefaultContainer(
          height: 60,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              SizedBox.square(
                dimension: 24,
                child: InkWell(
                  onTap: () {
                    double tempC = temp / 10;
                    BlocProvider.of<ACsBloc>(context).add(DecreaseCoolToTemp(
                        value: tempC,
                        deviceId: deviceModel.uuid ?? '',
                        productId: deviceModel.productUuid ?? ''));
                  },
                  child: SvgPicture.asset(
                    Assets.assetsIconsMinus,
                  ),
                ),
              ),
              BodyLarge(
                text: '${temp / 10} °C',
                style: context.bodyLarge.copyWith(
                  color: ColorsManager.primaryColor.withOpacity(0.6),
                  fontSize: 23,
                ),
              ),
              SizedBox.square(
                dimension: 24,
                child: InkWell(
                  onTap: () {
                    double tempC = temp / 10;
                    BlocProvider.of<ACsBloc>(context).add(IncreaseCoolToTemp(
                        value: tempC,
                        deviceId: deviceModel.uuid ?? '',
                        productId: deviceModel.productUuid ?? ''));
                  },
                  child: SvgPicture.asset(
                    Assets.assetsIconsPlus,
                    height: 24,
                    width: 24,
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
