import 'package:flutter/material.dart';

import '../features/landing/splash_screen.dart';
import '../features/landing/landing_page.dart';
import '../features/auth/login_page.dart';
import '../features/auth/register_page.dart';
import '../features/iot/page/main_page.dart';

class AppRoutes {
  AppRoutes._();

  static const String splash   = '/';
  static const String landing  = '/landing';
  static const String login    = '/login';
  static const String register = '/register';
  static const String main     = '/main';

  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case splash:
        return _fadeRoute(const SplashScreen());
      case landing:
        return _fadeRoute(const LandingPage());
      case login:
        return _fadeRoute(const LoginPage());
      case register:
        return _fadeRoute(const RegisterPage());
      case main:
        return _fadeRoute(const MainPage());
      default:
        return _fadeRoute(const SplashScreen());
    }
  }

  static PageRouteBuilder<dynamic> _fadeRoute(Widget page) {
    return PageRouteBuilder(
      transitionDuration: const Duration(milliseconds: 400),
      pageBuilder: (context, state, childState) => page,
      transitionsBuilder: (context, animation, secondaryAnimation, child) {
        return FadeTransition(
          opacity: CurvedAnimation(parent: animation, curve: Curves.easeInOut),
          child: child,
        );
      },
    );
  }
}
