import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/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/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/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';

class UniversalACTemp extends StatelessWidget {
  const UniversalACTemp({super.key, required this.temp, required this.allTempSame});
  final int temp;
  final bool allTempSame;

  @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 temperature = temp / 10;
                    BlocProvider.of<ACsBloc>(context).add(DecreaseAllTemp(value: temperature));
                  },
                  child: SvgPicture.asset(
                    Assets.assetsIconsMinus,
                  ),
                ),
              ),
              BodyLarge(
                text: '${allTempSame ? temp / 10 : '-'} °C',
                style: context.bodyLarge.copyWith(
                  color: ColorsManager.primaryColor.withOpacity(0.6),
                  fontSize: 23,
                ),
              ),
              SizedBox.square(
                dimension: 24,
                child: InkWell(
                  onTap: () {
                    double temperature = temp / 10;
                    BlocProvider.of<ACsBloc>(context).add(IncreaseAllTemp(value: temperature));
                  },
                  child: SvgPicture.asset(
                    Assets.assetsIconsPlus,
                    height: 24,
                    width: 24,
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
