/// Dashboard Membre Actif - Activity Center Personnalisé
/// Interface personnalisée pour participation active
library active_member_dashboard;

import 'package:flutter/material.dart';
import '../../../../../core/design_system/tokens/tokens.dart';
import '../../widgets/widgets.dart';

/// Dashboard Activity Center pour Membre Actif
class ActiveMemberDashboard extends StatelessWidget {
  const ActiveMemberDashboard({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorTokens.surface,
      body: CustomScrollView(
        slivers: [
          // App Bar Membre Actif
          SliverAppBar(
            expandedHeight: 160,
            floating: false,
            pinned: true,
            backgroundColor: const Color(0xFF00B894), // Vert communauté
            flexibleSpace: FlexibleSpaceBar(
              title: const Text(
                'Activity Center',
                style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
              ),
              background: Container(
                decoration: const BoxDecoration(
                  gradient: LinearGradient(
                    colors: [Color(0xFF00B894), Color(0xFF00A085)],
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight,
                  ),
                ),
                child: const Center(
                  child: Icon(Icons.groups, color: Colors.white, size: 60),
                ),
              ),
            ),
          ),
          
          SliverToBoxAdapter(
            child: Padding(
              padding: const EdgeInsets.all(SpacingTokens.md),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // Bienvenue personnalisé
                  _buildPersonalizedWelcome(),
                  const SizedBox(height: SpacingTokens.xl),
                  
                  // Mes statistiques
                  _buildMyStats(),
                  const SizedBox(height: SpacingTokens.xl),
                  
                  // Actions membres
                  _buildMemberActions(),
                  const SizedBox(height: SpacingTokens.xl),
                  
                  // Événements à venir
                  _buildUpcomingEvents(),
                  const SizedBox(height: SpacingTokens.xl),
                  
                  // Mon activité
                  _buildMyActivity(),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildPersonalizedWelcome() {
    return Container(
      padding: const EdgeInsets.all(SpacingTokens.lg),
      decoration: BoxDecoration(
        gradient: const LinearGradient(
          colors: [Color(0xFF00B894), Color(0xFF00CEC9)],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        borderRadius: BorderRadius.circular(RadiusTokens.lg),
      ),
      child: Row(
        children: [
          const CircleAvatar(
            radius: 30,
            backgroundColor: Colors.white,
            child: Icon(Icons.person, color: Color(0xFF00B894), size: 30),
          ),
          const SizedBox(width: SpacingTokens.md),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  'Bonjour, Marie !',
                  style: TypographyTokens.headlineMedium.copyWith(
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Text(
                  'Membre depuis 2 ans • Niveau Actif',
                  style: TypographyTokens.bodyMedium.copyWith(
                    color: Colors.white.withOpacity(0.9),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildMyStats() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          'Mes Statistiques',
          style: TypographyTokens.headlineMedium.copyWith(fontWeight: FontWeight.bold),
        ),
        const SizedBox(height: SpacingTokens.md),
        DashboardStatsGrid(
          stats: [
            DashboardStat(
              icon: Icons.event_available,
              value: '12',
              title: 'Événements',
              color: const Color(0xFF00B894),
              onTap: () {},
            ),
            DashboardStat(
              icon: Icons.volunteer_activism,
              value: '3',
              title: 'Solidarité',
              color: const Color(0xFF00CEC9),
              onTap: () {},
            ),
            DashboardStat(
              icon: Icons.payment,
              value: 'À jour',
              title: 'Cotisations',
              color: const Color(0xFF0984E3),
              onTap: () {},
            ),
            DashboardStat(
              icon: Icons.star,
              value: '4.8',
              title: 'Engagement',
              color: const Color(0xFFE17055),
              onTap: () {},
            ),
          ],
          onStatTap: (type) {},
        ),
      ],
    );
  }

  Widget _buildMemberActions() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          'Actions Rapides',
          style: TypographyTokens.headlineMedium.copyWith(fontWeight: FontWeight.bold),
        ),
        const SizedBox(height: SpacingTokens.md),
        DashboardQuickActionsGrid(
          actions: [
            DashboardQuickAction(
              icon: Icons.event,
              title: 'Créer Événement',
              subtitle: 'Organiser activité',
              color: const Color(0xFF00B894),
              onTap: () {},
            ),
            DashboardQuickAction(
              icon: Icons.volunteer_activism,
              title: 'Demande Aide',
              subtitle: 'Solidarité',
              color: const Color(0xFF00CEC9),
              onTap: () {},
            ),
            DashboardQuickAction(
              icon: Icons.account_circle,
              title: 'Mon Profil',
              subtitle: 'Modifier infos',
              color: const Color(0xFF0984E3),
              onTap: () {},
            ),
            DashboardQuickAction(
              icon: Icons.message,
              title: 'Contacter',
              subtitle: 'Support',
              color: const Color(0xFFE17055),
              onTap: () {},
            ),
          ],
          onActionTap: (type) {},
        ),
      ],
    );
  }

  Widget _buildUpcomingEvents() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Text(
              'Événements à Venir',
              style: TypographyTokens.headlineMedium.copyWith(fontWeight: FontWeight.bold),
            ),
            const Spacer(),
            TextButton(
              onPressed: () {},
              child: const Text('Voir tout'),
            ),
          ],
        ),
        const SizedBox(height: SpacingTokens.md),
        Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(RadiusTokens.md),
            boxShadow: [
              BoxShadow(
                color: Colors.black.withOpacity(0.05),
                blurRadius: 10,
                offset: const Offset(0, 2),
              ),
            ],
          ),
          child: Column(
            children: [
              ListTile(
                leading: Container(
                  width: 50,
                  height: 50,
                  decoration: BoxDecoration(
                    color: const Color(0xFF00B894).withOpacity(0.1),
                    borderRadius: BorderRadius.circular(25),
                  ),
                  child: const Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text('15', style: TextStyle(fontWeight: FontWeight.bold)),
                      Text('DÉC', style: TextStyle(fontSize: 10)),
                    ],
                  ),
                ),
                title: const Text('Assemblée Générale'),
                subtitle: const Text('Salle communale • 19h00'),
                trailing: const Icon(Icons.arrow_forward_ios, size: 16),
              ),
              const Divider(height: 1),
              ListTile(
                leading: Container(
                  width: 50,
                  height: 50,
                  decoration: BoxDecoration(
                    color: const Color(0xFF00CEC9).withOpacity(0.1),
                    borderRadius: BorderRadius.circular(25),
                  ),
                  child: const Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text('22', style: TextStyle(fontWeight: FontWeight.bold)),
                      Text('DÉC', style: TextStyle(fontSize: 10)),
                    ],
                  ),
                ),
                title: const Text('Soirée de Noël'),
                subtitle: const Text('Restaurant Le Gourmet • 20h00'),
                trailing: const Icon(Icons.arrow_forward_ios, size: 16),
              ),
            ],
          ),
        ),
      ],
    );
  }

  Widget _buildMyActivity() {
    return DashboardRecentActivitySection(
      activities: [
        DashboardActivity(
          title: 'Participation confirmée',
          subtitle: 'Assemblée Générale',
          icon: Icons.check_circle,
          color: const Color(0xFF00B894),
          time: 'Il y a 2h',
        ),
        DashboardActivity(
          title: 'Cotisation payée',
          subtitle: 'Décembre 2024',
          icon: Icons.payment,
          color: const Color(0xFF0984E3),
          time: 'Il y a 1j',
        ),
        DashboardActivity(
          title: 'Événement créé',
          subtitle: 'Sortie ski de fond',
          icon: Icons.event,
          color: const Color(0xFF00CEC9),
          time: 'Il y a 3j',
        ),
      ],
      onActivityTap: (id) {},
    );
  }
}
