import 'package:flutter/material.dart';
import 'package:mc_common_app/extensions/int_extensions.dart';
import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/theme/colors.dart';
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';

class CheckBoxWithTitleDescription extends StatelessWidget {
  final bool isSelected;
  final String title, description;
  final Function(bool) onSelection;
  final bool isDisabled;
  final CrossAxisAlignment? crossAxisAlignment;

  const CheckBoxWithTitleDescription({
    required this.isSelected,
    required this.title,
    required this.description,
    required this.onSelection,
    this.crossAxisAlignment,
    this.isDisabled = false,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: isDisabled
          ? null
          : () {
              onSelection(!isSelected);
            },
      child: SizedBox(
        width: double.infinity,
        child: Row(
          crossAxisAlignment: crossAxisAlignment == null ? (description.isNotEmpty ? CrossAxisAlignment.start : CrossAxisAlignment.center) : crossAxisAlignment!,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Checkbox(
              value: isSelected,
              activeColor: isDisabled ? MyColors.lightIconColor : MyColors.darkPrimaryColor,
              onChanged: isDisabled
                  ? null
                  : (bool? v) {
                      onSelection(v ?? false);
                    },
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  title.toText(fontSize: 14, isBold: true),
                  if (description.isNotEmpty) ...[
                    description.toText(fontSize: 12, color: MyColors.lightTextColor),
                  ]
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class CircleCheckBoxWithTitle extends StatelessWidget {
  final bool isChecked;
  final String title;
  final Function() onSelected;
  final Color selectedColor;

  const CircleCheckBoxWithTitle({super.key, required this.title, required this.isChecked, required this.onSelected, required this.selectedColor});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Container(
            height: 20,
            width: 20,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: isChecked ? selectedColor : Colors.transparent,
              border: Border.all(
                color: isChecked ? Colors.transparent : MyColors.darkTextColor,
              ),
            ),
            child: const Center(child: Icon(Icons.check_rounded, size: 16, color: MyColors.white)),
          ),
          5.width,
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                title.toText(fontSize: 14),
              ],
            ),
          ),
        ],
      ).onPress(() {
        onSelected();
      }),
    );
  }
}
