import 'package:flutter/material.dart';
import 'package:tour_travel_agr/page/history/history.dart';
import 'package:tour_travel_agr/page/profile/change_password/change_password.dart';
import 'package:tour_travel_agr/page/forgot_password/forgot_password.dart';
import 'package:tour_travel_agr/page/login/login.dart';
import 'package:tour_travel_agr/page/otp_verification/otp_verification.dart';
import 'package:tour_travel_agr/page/home/home.dart';
import 'package:tour_travel_agr/page/profile/edit_profile/edit_profile.dart';
import 'package:tour_travel_agr/page/profile/profile.dart';
import 'package:tour_travel_agr/page/register/register.dart';
import 'package:tour_travel_agr/page/reimbursement/reimbursement.dart';
import 'package:tour_travel_agr/page/reset_password/reset_password.dart';
import 'package:tour_travel_agr/page/splash/splash.dart';

class Routes {
  static const String splashRoute = "/splash";
  static const String loginRoute = "/login";
  static const String registerRoute = "/register";
  static const String verificationRoute = "/verification";
  static const String forgotPasswordRoute = "/forgot-password";
  static const String resetPasswordRoute = "/reset-password";
  static const String changePasswordRoute = "/change-password";
  static const String homeRoute = "/home";
  static const String profileRoute = "/profile";
  static const String editProfileRoute = "/edit-profile";
  static const String reimburseRoute = "/reimbursement";
  static const String historyRoute = "/history";
}

class RouteGenerator {
  static Route<dynamic> getRoute(RouteSettings routeSettings) {
    switch (routeSettings.name) {
      case Routes.splashRoute:
        return pageRouteCustom(const SplashView(),
            nameRoute: Routes.splashRoute);
      case Routes.loginRoute:
        return pageRouteCustom(LoginView(), nameRoute: Routes.loginRoute);
      case Routes.registerRoute:
        return pageRouteCustom(const RegisterView(),
            nameRoute: Routes.registerRoute);
      case Routes.verificationRoute:
        return pageRouteCustom(const OtpVerificationView(),
            nameRoute: Routes.verificationRoute);
      case Routes.forgotPasswordRoute:
        return pageRouteCustom(const ForgotPasswordView(),
            nameRoute: Routes.forgotPasswordRoute);
      case Routes.resetPasswordRoute:
        return pageRouteCustom(const ResetPasswordView(),
            nameRoute: Routes.resetPasswordRoute);
      case Routes.homeRoute:
        return pageRouteCustom(const HomeView(), nameRoute: Routes.homeRoute);
      case Routes.profileRoute:
        return pageRouteCustom(const ProfileView(),
            nameRoute: Routes.profileRoute);
      case Routes.changePasswordRoute:
        return pageRouteCustom(const ChangePasswordView(),
            nameRoute: Routes.changePasswordRoute);
      case Routes.editProfileRoute:
        return pageRouteCustom(const EditProfileView(),
            nameRoute: Routes.editProfileRoute);
      case Routes.reimburseRoute:
        return pageRouteCustom(const ReimbursementView(),
            nameRoute: Routes.reimburseRoute);
      case Routes.historyRoute:
        return pageRouteCustom(const HistoryView(),
            nameRoute: Routes.historyRoute);
      default:
        return unDefinedRoute();
    }
  }

  static PageRouteBuilder<dynamic> pageRouteCustom(Widget target,
      {required String nameRoute}) {
    return PageRouteBuilder(
      pageBuilder: (context, a, b) => target,
      transitionDuration: Duration.zero,
      reverseTransitionDuration: Duration.zero,
      settings: RouteSettings(name: nameRoute.replaceFirst("/", "")),
    );
  }

  static Route<dynamic> unDefinedRoute() {
    return MaterialPageRoute(
      builder: (_) => Scaffold(
        appBar: AppBar(
          title: const Text("No Route Found"),
        ),
        body: const Center(
          child: Text("No Route Found"),
        ),
      ),
    );
  }
}
