/// Dashboard Page Stable - Redirecteur vers Dashboard Adaptatif
/// Redirige automatiquement vers le nouveau système de dashboard adaptatif
library dashboard_page_stable;

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

/// Page Dashboard Stable - Maintenant un redirecteur
/// 
/// Cette page redirige automatiquement vers le nouveau système
/// de dashboard adaptatif basé sur les rôles utilisateurs.
class DashboardPageStable extends StatefulWidget {
  const DashboardPageStable({super.key});

  @override
  State<DashboardPageStable> createState() => _DashboardPageStableState();
}

class _DashboardPageStableState extends State<DashboardPageStable> {
  @override
  void initState() {
    super.initState();
    // Rediriger automatiquement vers le dashboard adaptatif
    WidgetsBinding.instance.addPostFrameCallback((_) {
      _redirectToAdaptiveDashboard();
    });
  }

  /// Redirige vers le dashboard adaptatif
  void _redirectToAdaptiveDashboard() {
    Navigator.of(context).pushReplacement(
      PageRouteBuilder(
        pageBuilder: (context, animation, secondaryAnimation) =>
            const AdaptiveDashboardPage(),
        transitionsBuilder: (context, animation, secondaryAnimation, child) {
          return FadeTransition(
            opacity: animation,
            child: SlideTransition(
              position: Tween<Offset>(
                begin: const Offset(0.0, 0.1),
                end: Offset.zero,
              ).animate(CurvedAnimation(
                parent: animation,
                curve: Curves.easeInOutCubic,
              )),
              child: child,
            ),
          );
        },
        transitionDuration: const Duration(milliseconds: 600),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    // Afficher un écran de chargement pendant la redirection
    return Scaffold(
      body: Container(
        decoration: const BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              Color(0xFF6C5CE7),
              Color(0xFF5A4FCF),
            ],
          ),
        ),
        child: const Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              // Logo
              Icon(
                Icons.dashboard,
                color: Colors.white,
                size: 80,
              ),
              
              SizedBox(height: 24),
              
              // Titre
              Text(
                'UnionFlow',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 32,
                  fontWeight: FontWeight.bold,
                ),
              ),
              
              SizedBox(height: 16),
              
              // Indicateur de chargement
              SizedBox(
                width: 40,
                height: 40,
                child: CircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
                  strokeWidth: 3,
                ),
              ),
              
              SizedBox(height: 16),
              
              // Message
              Text(
                'Chargement de votre dashboard...',
                style: TextStyle(
                  color: Colors.white70,
                  fontSize: 16,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
