import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';

class RadioListTileWidget<T> extends StatelessWidget {
  final T value;
  final T? groupValue;
  final String title;
  final Widget? subtitleWidget;
  final String? subtitle;
  final ValueChanged<T?> onChanged;
  final bool enabled;

  const RadioListTileWidget({
    super.key,
    required this.value,
    required this.groupValue,
    required this.title,
    this.subtitleWidget,
    this.subtitle,
    required this.onChanged,
    this.enabled = true,
  });

  @override
  Widget build(BuildContext context) {
    final bool isSelected = value == groupValue;

    return InkWell(
      onTap: enabled ? () => onChanged(value) : null,
      child: Container(
        decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
          color: AppColors.whiteColor,
          borderRadius: 24.h,
          hasShadow: false,
        ),
        margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 6.h),
        padding: EdgeInsets.all(16.h),
        child: Row(
          children: [
            Container(
              width: 20.h,
              height: 20.h,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                border: Border.all(
                  color: isSelected ? AppColors.primaryRedColor : const Color(0xff9E9E9E),
                  width: 2,
                ),
              ),
              child: isSelected
                  ? Center(
                      child: Container(
                        width: 10.h,
                        height: 10.h,
                        decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          color: AppColors.primaryRedColor,
                        ),
                      ),
                    )
                  : null,
            ),
            SizedBox(width: 16.w),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  title.toText15(isBold: true, letterSpacing: -0.64),
                  if (subtitleWidget != null) ...[subtitleWidget!],
                  if (subtitle != null) ...[
                    SizedBox(height: 4.h),
                    title.toText13(
                      weight: FontWeight.w400,
                      color: AppColors.greyTextColor,
                      letterSpacing: -0.56,
                    ),
                  ],
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
