import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:marco/helpers/services/auth_service.dart';
import 'package:marco/view/auth/forgot_password_screen.dart';
import 'package:marco/view/auth/login_screen.dart';
import 'package:marco/view/auth/register_account_screen.dart';
import 'package:marco/view/auth/reset_password_screen.dart';
import 'package:marco/view/error_pages/coming_soon_screen.dart';
import 'package:marco/view/error_pages/error_404_screen.dart';
import 'package:marco/view/error_pages/error_500_screen.dart';
import 'package:marco/view/dashboard/dashboard_screen.dart';
import 'package:marco/view/dashboard/Attendence/attendance_screen.dart';
import 'package:marco/view/taskPlaning/daily_task_planing.dart';
import 'package:marco/view/taskPlaning/daily_progress.dart';
import 'package:marco/view/employees/employees_screen.dart';
import 'package:marco/view/auth/login_option_screen.dart';
import 'package:marco/view/auth/mpin_screen.dart';
import 'package:marco/view/auth/mpin_auth_screen.dart';
import 'package:marco/view/directory/directory_main_screen.dart';
import 'package:marco/view/expense/expense_screen.dart';

class AuthMiddleware extends GetMiddleware {
  @override
  RouteSettings? redirect(String? route) {
    return AuthService.isLoggedIn
        ? null
        : RouteSettings(name: '/auth/login-option');
  }
}

getPageRoute() {
  var routes = [
    GetPage(
        name: '/',
        page: () => DashboardScreen(),
        middlewares: [AuthMiddleware()]),
    GetPage(
      name: '/home',
      page: () => DashboardScreen(), // or your actual home screen
      middlewares: [AuthMiddleware()],
    ),

    // Dashboard
    GetPage(
        name: '/dashboard/attendance',
        page: () => AttendanceScreen(),
        middlewares: [AuthMiddleware()]),
    GetPage(
        name: '/dashboard',
        page: () => DashboardScreen(),
        middlewares: [AuthMiddleware()]),
    GetPage(
        name: '/dashboard/employees',
        page: () => EmployeesScreen(),
        middlewares: [AuthMiddleware()]),
    // Daily Task Planning
    GetPage(
        name: '/dashboard/daily-task-planing',
        page: () => DailyTaskPlaningScreen(),
        middlewares: [AuthMiddleware()]),
    GetPage(
        name: '/dashboard/daily-task-progress',
        page: () => DailyProgressReportScreen(),
        middlewares: [AuthMiddleware()]),
    GetPage(
        name: '/dashboard/directory-main-page',
        page: () => DirectoryMainScreen(),
        middlewares: [AuthMiddleware()]),
    // Expense 
    GetPage(
        name: '/dashboard/expense-main-page',
        page: () => ExpenseMainScreen(),
        middlewares: [AuthMiddleware()]),
    // Authentication
    GetPage(name: '/auth/login', page: () => LoginScreen()),
    GetPage(name: '/auth/login-option', page: () => LoginOptionScreen()),
    GetPage(name: '/auth/mpin', page: () => MPINScreen()),
    GetPage(name: '/auth/mpin-auth', page: () => MPINAuthScreen()),
    GetPage(
        name: '/auth/register_account',
        page: () => const RegisterAccountScreen()),
    GetPage(name: '/auth/forgot_password', page: () => ForgotPasswordScreen()),
    GetPage(
        name: '/auth/reset_password', page: () => const ResetPasswordScreen()),
    // Error
    GetPage(
        name: '/error/coming_soon',
        page: () => ComingSoonScreen(),
        middlewares: [AuthMiddleware()]),
    GetPage(
        name: '/error/500',
        page: () => Error500Screen(),
        middlewares: [AuthMiddleware()]),
    GetPage(
        name: '/error/404',
        page: () => Error404Screen(),
        middlewares: [AuthMiddleware()]),
  ];
  return routes
      .map((e) => GetPage(
          name: e.name,
          page: e.page,
          middlewares: e.middlewares,
          transition: Transition.noTransition))
      .toList();
}
