import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_bloc.dart';
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_event.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';

class CurtainToggle extends StatelessWidget {
  final bool value;
  final String code;
  final String deviceId;
  final String label;

  const CurtainToggle({
    super.key,
    required this.value,
    required this.code,
    required this.deviceId,
    required this.label,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(20),
        color: ColorsManager.greyColor.withOpacity(0.2),
        border: Border.all(color: ColorsManager.boxDivider),
      ),
      padding: const EdgeInsets.all(16),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              ClipOval(
                child: Container(
                  color: ColorsManager.whiteColors,
                  child: SvgPicture.asset(
                    Assets.curtainIcon,
                    width: 60,
                    height: 60,
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              SizedBox(
                height: 20,
                width: 35,
                child: CupertinoSwitch(
                  value: value,
                  activeColor: ColorsManager.dialogBlueTitle,
                  onChanged: (newValue) {
                    context.read<CurtainBloc>().add(
                          CurtainControl(
                            deviceId: deviceId,
                            code: code,
                            value: newValue,
                          ),
                        );
                  },
                ),
              ),
            ],
          ),
          const Spacer(),
          Text(
            label,
            style: const TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 14,
            ),
          ),
        ],
      ),
    );
  }
}
