import 'package:flutter/material.dart';
import 'package:sigap/src/features/personalization/data/models/models/roles_model.dart';
import 'package:sigap/src/utils/constants/sizes.dart';

class RoleCard extends StatelessWidget {
  final RoleModel role;
  final bool isSelected;
  final VoidCallback onTap;
  final IconData? icon; // Add optional icon parameter

  const RoleCard({
    super.key,
    required this.role,
    required this.isSelected,
    required this.onTap,
    this.icon, // Optional icon parameter
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    // Use provided icon or fall back to role.iconData
    final IconData displayIcon = icon ?? role.iconData;

    return GestureDetector(
      onTap: onTap,
      child: Container(
        margin: const EdgeInsets.only(bottom: TSizes.spaceBtwItems),
        padding: const EdgeInsets.all(TSizes.md),
        decoration: BoxDecoration(
          color:
              isSelected
                  ? theme.primaryColor.withOpacity(0.1)
                  : theme.cardColor,
          borderRadius: BorderRadius.circular(TSizes.cardRadiusMd),
          border: Border.all(
            color: isSelected ? theme.primaryColor : theme.dividerColor,
            width: isSelected ? 2 : 1,
          ),
        ),
        child: Row(
          children: [
            Container(
              width: TSizes.imageThumbSize - 24,
              height: TSizes.imageThumbSize - 24,
              decoration: BoxDecoration(
                color: isSelected ? theme.primaryColor : theme.cardColor,
                borderRadius: BorderRadius.circular(TSizes.borderRadiusMd),
              ),
              child: Icon(
                displayIcon, // Use the display icon
                color:
                    isSelected
                        ? theme.colorScheme.onPrimary
                        : theme.primaryColor,
                size: TSizes.iconLg - 4,
              ),
            ),
            const SizedBox(width: TSizes.md),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    role.name,
                    style: theme.textTheme.titleMedium?.copyWith(
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  const SizedBox(height: TSizes.xs),
                  Text(
                    role.description!,
                    style: theme.textTheme.bodyMedium,
                  ),
                ],
              ),
            ),
            Icon(
              isSelected ? Icons.check_circle : Icons.circle_outlined,
              color:
                  isSelected
                      ? theme.primaryColor
                      : theme.textTheme.bodySmall?.color,
              size: TSizes.iconMd,
            ),
          ],
        ),
      ),
    );
  }
}
