import 'package:flutter/material.dart';

/// Gélule de sélection du statut utilisateur (fiches admin parent / AM).
class AdminStatusCapsule extends StatelessWidget {
  final String statut;
  final ValueChanged<String>? onChanged;

  static const statuts = ['actif', 'en_attente', 'suspendu', 'refuse'];

  const AdminStatusCapsule({
    super.key,
    required this.statut,
    this.onChanged,
  });

  static String displayStatus(String status) {
    switch (status) {
      case 'actif':
        return 'Actif';
      case 'en_attente':
        return 'En attente';
      case 'suspendu':
        return 'Suspendu';
      case 'refuse':
        return 'Refusé';
      default:
        return status;
    }
  }

  @override
  Widget build(BuildContext context) {
    final value = statuts.contains(statut) ? statut : statuts.first;
    return Container(
      height: 34,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(18),
        border: Border.all(color: Colors.black26),
      ),
      padding: const EdgeInsets.symmetric(horizontal: 12),
      child: DropdownButtonHideUnderline(
        child: DropdownButton<String>(
          value: value,
          isExpanded: true,
          isDense: true,
          style: const TextStyle(fontSize: 13, color: Colors.black87),
          icon: const Icon(Icons.arrow_drop_down, size: 20),
          items: statuts
              .map(
                (s) => DropdownMenuItem(
                  value: s,
                  child: Text(displayStatus(s)),
                ),
              )
              .toList(),
          onChanged: onChanged == null
              ? null
              : (v) {
                  if (v != null) onChanged!(v);
                },
        ),
      ),
    );
  }
}
