import 'package:flutter/material.dart';
import 'friendship_status.dart';

/// [FriendshipStatusBadge] est un widget qui affiche le statut de l'amitié sous forme de badge.
/// Il peut afficher des statuts comme "En attente", "Acceptée", "Rejetée".
class FriendshipStatusBadge extends StatelessWidget { // Le statut de l'amitié (PENDING, ACCEPTED, REJECTED)

  const FriendshipStatusBadge({
    required this.status, super.key,
  });
  final FriendshipStatus status;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
      decoration: BoxDecoration(
        color: _getStatusColor(status).withOpacity(0.1),
        borderRadius: BorderRadius.circular(12),
        border: Border.all(
          color: _getStatusColor(status),
        ),
      ),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Icon(
            _getStatusIcon(status),
            color: _getStatusColor(status),
            size: 16,
          ),
          const SizedBox(width: 8),
          Text(
            _getStatusText(status),
            style: TextStyle(
              color: _getStatusColor(status),
              fontSize: 12,
              fontWeight: FontWeight.bold,
            ),
          ),
        ],
      ),
    );
  }

  /// Retourne la couleur associée au statut.
  Color _getStatusColor(FriendshipStatus status) {
    switch (status) {
      case FriendshipStatus.PENDING:
        return Colors.orange;
      case FriendshipStatus.ACCEPTED:
        return Colors.green;
      case FriendshipStatus.REJECTED:
        return Colors.red;
      default:
        return Colors.grey;
    }
  }

  /// Retourne l'icône associée au statut.
  IconData _getStatusIcon(FriendshipStatus status) {
    switch (status) {
      case FriendshipStatus.PENDING:
        return Icons.hourglass_empty;
      case FriendshipStatus.ACCEPTED:
        return Icons.check_circle;
      case FriendshipStatus.REJECTED:
        return Icons.cancel;
      default:
        return Icons.help_outline;
    }
  }

  /// Retourne le texte associé au statut.
  String _getStatusText(FriendshipStatus status) {
    switch (status) {
      case FriendshipStatus.PENDING:
        return 'En attente';
      case FriendshipStatus.ACCEPTED:
        return 'Acceptée';
      case FriendshipStatus.REJECTED:
        return 'Rejetée';
      default:
        return 'Inconnu';
    }
  }
}
