import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:flutter/material.dart';
import 'package:medora/controllers/consultation_center_controller.dart';
import 'package:medora/data/models/consultation_center.dart';
import 'package:medora/data/models/doctor.dart';
import 'package:medora/data/services/navigation_service.dart';
import 'package:medora/screens/authentication/launch_screen.dart';
import 'package:medora/route/route_names.dart';
import 'package:medora/screens/authentication/sign_up_screen.dart';
import 'package:medora/screens/common/loading_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_consultation_schedule/business_center_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_consultation_schedule/center_fee_and_duration_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_consultation_schedule/consultation_day_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_consultation_schedule/consultation_centers_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_consultation_schedule/consultation_time_slot_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_dashboard/doctor_dashboard_home_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_dashboard/doctor_dashboard_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_dashboard/doctor_landing_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_dashboard/doctor_personal_profile_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_dashboard/doctor_services_menu_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_profile_screens/achivements_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_profile_screens/address_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_profile_screens/digital_signature_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_profile_screens/doctor_profile_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_profile_screens/experience_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_profile_screens/profile_description_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_profile_screens/qualifications_screen.dart';
import 'package:medora/screens/doctor_screen/doctor_profile_screens/specialities_selection_screen.dart';
import 'package:medora/screens/splash_screen.dart';

import '../controllers/doctor_controller.dart';

final Map<String, Widget Function(BuildContext)> routes = {
  // RouteNames.launch: (context) => const LaunchScreen(),
  RouteNames.signIn: (context) => SignInScreen(
        providers: [EmailAuthProvider(), PhoneAuthProvider()],
        showAuthActionSwitch: false,
        footerBuilder: (context, action) {
          return Padding(
            padding: const EdgeInsets.only(top: 16),
            child: TextButton(
              onPressed: () {
                Navigator.pushNamed(context, RouteNames.signUp);
              },
              child: const Text(
                "Don't have an account? Sign up",
              ),
            ),
          );
        },
        actions: [
          AuthStateChangeAction<SignedIn>((context, state) {
            print("Sign in successful");
            NavigationService.handleUserNavigation(context);
          }),
          AuthStateChangeAction<AuthFailed>((context, state) {
            print("Sign in failed: ${state.exception}");
          }),
        ],
      ),
  RouteNames.signUp: (context) => const SignUpScreen(),
  // RouteNames.userProfile: (context) {
  //   var user = ModalRoute.of(context)!.settings.arguments as TelemedUser?;
  //   return UserProfileScreen(user: user);
  // },
  // RouteNames.userHome: (context) => const UserScreen(),
  RouteNames.doctorLandingScreen: (context) => const DoctorLandingScreen(),
  RouteNames.qualificationsScreen: (context) {
    final controller =
        ModalRoute.of(context)!.settings.arguments as DoctorController?;
    return QualificationsScreen(
      controller: controller ?? DoctorController(), // Provide fallback
    );
  },
  RouteNames.profileUpload: (context) => const ProfileUploadPage(),
  RouteNames.doctorAddressScreen: (context) {
    final controller =
        ModalRoute.of(context)!.settings.arguments as DoctorController?;
    return DoctorAddressScreen(
      controller: controller ?? DoctorController(), // Provide fallback
    );
  },
  RouteNames.profileDescriptionScreen: (context) {
    final controller =
        ModalRoute.of(context)!.settings.arguments as DoctorController?;
    return ProfileDescriptionScreen(
      controller: controller ?? DoctorController(),
    );
  },
  RouteNames.experienceScreen: (context) {
    final controller =
        ModalRoute.of(context)!.settings.arguments as DoctorController?;
    return ExperienceScreen(
      controller: controller ?? DoctorController(),
    );
  },
  RouteNames.specialitiesScreeen: (context) {
    final controller =
        ModalRoute.of(context)!.settings.arguments as DoctorController?;
    return SpecialitiesScreen(
      controller: controller ?? DoctorController(),
    );
  },
  RouteNames.digitalSignatureScreeen: (context) {
    final controller =
        ModalRoute.of(context)!.settings.arguments as DoctorController?;
    return DigitalSignatureScreen(
      controller: controller ?? DoctorController(),
    );
  },
  RouteNames.achievementsScreen: (context) {
    final controller =
        ModalRoute.of(context)!.settings.arguments as DoctorController?;
    return AchievementsScreen(
      controller: controller ?? DoctorController(),
    );
  },
  RouteNames.doctorDashbordScreen: (context) => const DoctorDashboardScreen(),
  RouteNames.doctorHomeScreen: (context) => const DoctorDashboardHomeScreen(),
  RouteNames.doctorPersonalProfileScreen: (context) =>
      const DoctorPersonalProfileScreen(),
  RouteNames.doctorServicesMenuScreen: (context) =>
      const DoctorServicesMenuScreen(),
  RouteNames.scheduleConsultationScreen: (context) =>
      const ScheduleConsultationScreen(),
  RouteNames.businessCenterScreen: (context) {
    final controller = ModalRoute.of(context)!.settings.arguments
        as ConsultationCenterController?;
    return BusinessCenterScreen(
      controller: controller ?? ConsultationCenterController(),
    );
  },
  RouteNames.centerFeeAndDuration: (context) {
    final controller = ModalRoute.of(context)!.settings.arguments
        as ConsultationCenterController?;
    return CenterFeeAndDurationScreen(
      controller: controller ?? ConsultationCenterController(),
    );
  },
  RouteNames.consultationTimeSlotScreen: (context) {
    final controller = ModalRoute.of(context)!.settings.arguments
        as ConsultationCenterController?;
    return ConsultationTimeSlotScreen(
      controller: controller ?? ConsultationCenterController(),
      selectedDay: '',
    );
  },
  RouteNames.consultationDayScreen: (context) {
    final controller = ModalRoute.of(context)!.settings.arguments
        as ConsultationCenterController?;
    return ConsultationDayScreen(
      controller: controller ?? ConsultationCenterController(),
    );
  },
  RouteNames.loadingScreen: (context) => const LoadingScreen(),
  RouteNames.splashScreen: (context) => const SplashScreen(),
};
