import 'package:flutter/cupertino.dart';
import 'package:flutter_svg/flutter_svg.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';
import 'package:syncrow_web/utils/extension/build_context_x.dart';

class ToggleWidget extends StatelessWidget {
  final bool value;
  final String code;
  final String deviceId;
  final String label;
  final String? icon;
  final Widget? labelWidget;
  final Function(dynamic value) onChange;
  final bool showToggle;
  final bool showIcon;

  const ToggleWidget({
    super.key,
    required this.value,
    required this.code,
    required this.deviceId,
    required this.label,
    required this.onChange,
    this.icon,
    this.labelWidget,
    this.showToggle = true,
    this.showIcon = true,
  });

  @override
  Widget build(BuildContext context) {
    return DeviceControlsContainer(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.only(right: 12),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                icon == '-1'
                    ? const SizedBox(
                        height: 60,
                        width: 60,
                      )
                    : ClipOval(
                        child: Container(
                        height: 60,
                        width: 60,
                        padding: const EdgeInsets.all(8),
                        color: ColorsManager.whiteColors,
                        child: SvgPicture.asset(
                          icon ?? Assets.lightPulp,
                          width: 35,
                          height: 35,
                          fit: BoxFit.contain,
                        ),
                      )),
                if (showToggle)
                  Container(
                    child: CupertinoSwitch(
                      value: value,
                      activeColor: ColorsManager.dialogBlueTitle,
                      onChanged: onChange,
                    ),
                  ),
              ],
            ),
          ),
          labelWidget ??
              Text(
                label,
                style: context.textTheme.titleMedium!.copyWith(
                  fontWeight: FontWeight.w400,
                  color: ColorsManager.blackColor,
                ),
              ),
        ],
      ),
    );
  }
}
