import 'package:autos/core/routing/route_paths.dart';
import 'package:autos/presentation/screens/auth/forgot_password_screen.dart';
import 'package:autos/presentation/screens/auth/login_screen.dart';
import 'package:autos/presentation/screens/auth/sign_up_screen.dart';
import 'package:autos/presentation/screens/brands/brands_screen.dart';
import 'package:autos/presentation/screens/dashboard/dashboard_screen.dart';
import 'package:autos/presentation/screens/ebay/ebay_screen.dart';
import 'package:autos/presentation/screens/imports/imports_screen.dart';
import 'package:autos/presentation/screens/my_account/account_screen.dart';
import 'package:autos/presentation/screens/pricing/pricing_screen.dart';
import 'package:autos/presentation/screens/products/products_screen.dart';
import 'package:autos/presentation/screens/store/create_location_screen.dart';
import 'package:autos/presentation/screens/store/store.dart';
import 'package:autos/presentation/screens/turn14_screen/turn14_screen.dart';
import 'package:flutter/material.dart';

class AppRouter {
  /// Slide transition route
  static PageRouteBuilder slideRoute(Widget page) {
    return PageRouteBuilder(
      pageBuilder: (context, animation, secondaryAnimation) => page,
      transitionDuration: const Duration(milliseconds: 300),
      transitionsBuilder: (context, animation, secondaryAnimation, child) {
        const begin = Offset(1.0, 0.0);
        const end = Offset.zero;
        const curve = Curves.easeInOut;

        final tween = Tween(
          begin: begin,
          end: end,
        ).chain(CurveTween(curve: curve));

        return SlideTransition(position: animation.drive(tween), child: child);
      },
    );
  }

  /// Generate routes
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case AppRoutePaths.auth:
        return slideRoute(const LoginScreen());

      case AppRoutePaths.signup:
        return slideRoute(const SignUpScreen());

      case AppRoutePaths.forgotPassword:
        return slideRoute(const ForgotPasswordScreen());

      case AppRoutePaths.dashboard:
        return slideRoute(const DashboardScreen());

      case AppRoutePaths.turn14:
        return slideRoute(const Turn14Screen());

      case AppRoutePaths.ebay:
        return slideRoute(EbayScreen());

      case AppRoutePaths.store:
        return slideRoute(StoreScreen());

      case AppRoutePaths.createStoreLocation:
        return slideRoute(CreateLocationScreen());

      case AppRoutePaths.brands:
        return slideRoute(BrandsScreen());

      case AppRoutePaths.products:
        return slideRoute(ProductsScreen());

      case AppRoutePaths.pricing:
        return slideRoute(PricingScreen());

      case AppRoutePaths.myAccount:
        return slideRoute(AccountScreen());

      case AppRoutePaths.imports:
        return slideRoute(ImportsScreen());

      default:
        return _defaultFallback(settings);
    }
  }

  /// Fallback route
  static Route<dynamic> _defaultFallback(RouteSettings settings) {
    return slideRoute(
      Scaffold(
        appBar: AppBar(
          title: Text(settings.name?.replaceAll('/', '') ?? "Page"),
          leading: BackButton(),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: const [
              Icon(Icons.construction, size: 80, color: Colors.orange),
              SizedBox(height: 20),
              Text(
                "This section is under development.",
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                textAlign: TextAlign.center,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
