import 'package:flutter/material.dart';

/// Drawer personnalisé avec navigation et design moderne.
///
/// Ce widget fournit un drawer de navigation avec des options
/// stylisées et cohérentes avec le thème de l'application.
///
/// **Usage:**
/// ```dart
/// Scaffold(
///   drawer: CustomDrawer(),
///   body: MyContent(),
/// )
/// ```
class CustomDrawer extends StatelessWidget {
  const CustomDrawer({super.key});

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return Drawer(
      child: Column(
        children: [
          _buildHeader(theme),
          Expanded(
            child: _buildMenuItems(context, theme),
          ),
          _buildFooter(theme),
        ],
      ),
    );
  }

  /// Construit l'en-tête du drawer.
  Widget _buildHeader(ThemeData theme) {
    return DrawerHeader(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [
            theme.colorScheme.primary,
            theme.colorScheme.secondary,
          ],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(
            Icons.event,
            size: 48,
            color: theme.colorScheme.onPrimary,
          ),
          const SizedBox(height: 12),
          Text(
            'AfterWork',
            style: theme.textTheme.headlineSmall?.copyWith(
              color: theme.colorScheme.onPrimary,
              fontWeight: FontWeight.bold,
            ),
          ),
        ],
      ),
    );
  }

  /// Construit les éléments du menu.
  Widget _buildMenuItems(BuildContext context, ThemeData theme) {
    return ListView(
      padding: EdgeInsets.zero,
      children: [
        _buildMenuItem(
          context,
          theme,
          icon: Icons.home,
          title: 'Accueil',
          route: '/home',
        ),
        _buildMenuItem(
          context,
          theme,
          icon: Icons.event,
          title: 'Événements',
          route: '/event',
        ),
        _buildMenuItem(
          context,
          theme,
          icon: Icons.camera_alt,
          title: 'Story',
          route: '/story',
        ),
        _buildMenuItem(
          context,
          theme,
          icon: Icons.people,
          title: 'Amis',
          route: '/friends',
        ),
        _buildMenuItem(
          context,
          theme,
          icon: Icons.settings,
          title: 'Paramètres',
          route: '/settings',
        ),
      ],
    );
  }

  /// Construit un élément de menu.
  Widget _buildMenuItem(
    BuildContext context,
    ThemeData theme, {
    required IconData icon,
    required String title,
    required String route,
  }) {
    return ListTile(
      leading: Icon(
        icon,
        color: theme.colorScheme.primary,
      ),
      title: Text(title),
      onTap: () {
        Navigator.pop(context);
        Navigator.pushNamed(context, route);
      },
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(8),
      ),
    );
  }

  /// Construit le pied de page du drawer.
  Widget _buildFooter(ThemeData theme) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        border: Border(
          top: BorderSide(
            color: theme.colorScheme.outline.withOpacity(0.2),
          ),
        ),
      ),
      child: Text(
        'Version 1.0.0',
        style: theme.textTheme.bodySmall?.copyWith(
          color: theme.colorScheme.onSurface.withOpacity(0.6),
        ),
        textAlign: TextAlign.center,
      ),
    );
  }
}
