import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_controls_container.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';

class AcToggle extends StatelessWidget {
  const AcToggle({
    super.key,
    required this.value,
    required this.code,
    required this.deviceId,
    this.icon,
    this.description,
  });

  final bool value;
  final String code;
  final String deviceId;
  final String? icon;
  final String? description;

  @override
  Widget build(BuildContext context) {
    return DeviceControlsContainer(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 60,
                height: 60,
                decoration: const BoxDecoration(
                  shape: BoxShape.circle,
                  color: ColorsManager.whiteColors,
                ),
                padding: const EdgeInsets.all(8),
                child: ClipOval(
                  child: SvgPicture.asset(
                    icon ?? Assets.lightPulp,
                    fit: BoxFit.contain,
                  ),
                ),
              ),
              SizedBox(
                height: 20,
                width: 35,
                child: CupertinoSwitch(
                  activeColor: ColorsManager.dialogBlueTitle,
                  value: value,
                  onChanged: (newValue) {
                    context.read<AcBloc>().add(
                          AcControlEvent(
                            deviceId: deviceId,
                            code: code,
                            value: newValue,
                          ),
                        );
                  },
                ),
              ),
            ],
          ),
          const Spacer(),
          Center(
            child: Text(
              description ?? 'ThermoState',
              style: const TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 14,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
