/// Widget des statistiques des organisations
/// Respecte le design system avec les mêmes patterns que les autres stats
library organisation_stats_widget;

import 'package:flutter/material.dart';

/// Widget des statistiques avec design cohérent
class OrganisationStatsWidget extends StatelessWidget {
  final Map<String, int> stats;
  final Function(String)? onStatTap;

  const OrganisationStatsWidget({
    super.key,
    required this.stats,
    this.onStatTap,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8), // RadiusTokens cohérent
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 4,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            'Statistiques',
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold,
              color: Color(0xFF6C5CE7), // ColorTokens cohérent
            ),
          ),
          const SizedBox(height: 12),
          Row(
            children: [
              Expanded(
                child: _buildStatCard(
                  title: 'Total',
                  value: stats['total']?.toString() ?? '0',
                  icon: Icons.business,
                  color: const Color(0xFF6C5CE7),
                  onTap: () => onStatTap?.call('total'),
                ),
              ),
              const SizedBox(width: 8),
              Expanded(
                child: _buildStatCard(
                  title: 'Actives',
                  value: stats['actives']?.toString() ?? '0',
                  icon: Icons.check_circle,
                  color: const Color(0xFF10B981),
                  onTap: () => onStatTap?.call('actives'),
                ),
              ),
            ],
          ),
          const SizedBox(height: 8),
          Row(
            children: [
              Expanded(
                child: _buildStatCard(
                  title: 'Inactives',
                  value: stats['inactives']?.toString() ?? '0',
                  icon: Icons.pause_circle,
                  color: const Color(0xFF6B7280),
                  onTap: () => onStatTap?.call('inactives'),
                ),
              ),
              const SizedBox(width: 8),
              Expanded(
                child: _buildStatCard(
                  title: 'Membres',
                  value: stats['totalMembres']?.toString() ?? '0',
                  icon: Icons.people,
                  color: const Color(0xFF3B82F6),
                  onTap: () => onStatTap?.call('membres'),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  /// Carte de statistique individuelle
  Widget _buildStatCard({
    required String title,
    required String value,
    required IconData icon,
    required Color color,
    VoidCallback? onTap,
  }) {
    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: onTap,
        borderRadius: BorderRadius.circular(6),
        child: Container(
          padding: const EdgeInsets.all(12),
          decoration: BoxDecoration(
            color: color.withOpacity(0.05),
            borderRadius: BorderRadius.circular(6),
            border: Border.all(
              color: color.withOpacity(0.1),
              width: 1,
            ),
          ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Icon(
                  icon,
                  size: 16,
                  color: color,
                ),
                const SizedBox(width: 6),
                Expanded(
                  child: Text(
                    title,
                    style: TextStyle(
                      fontSize: 11,
                      fontWeight: FontWeight.w500,
                      color: color,
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
              ],
            ),
            const SizedBox(height: 4),
            Text(
              value,
              style: TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: color,
              ),
            ),
          ],
        ),
      ),
      ),
    );
  }
}
