import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_domain/krow_domain.dart';

import 'route_paths.dart';

/// Typed navigation extension for the Staff application.
///
/// This extension provides type-safe navigation methods for all routes
/// in the Staff app. All staff navigation should use these methods
/// instead of hardcoding route strings.
///
/// Usage:
/// ```dart
/// import 'package:flutter_modular/flutter_modular.dart';
/// import 'package:krow_core/routing.dart';
///
/// // In your widget or bloc
/// Modular.to.toStaffHome();
/// Modular.to.toShiftDetails(shift);
/// Modular.to.toPhoneVerification('login'); // 'login' or 'signup'
/// ```
///
/// See also:
///  * [StaffPaths] for route path constants
///  * [ClientNavigator] for Client app navigation
extension StaffNavigator on IModularNavigator {
  // ==========================================================================
  // AUTHENTICATION FLOWS
  // ==========================================================================

  /// Navigates to the root get started/authentication screen.
  /// 
  /// This effectively logs out the user by navigating to root.
  /// Used when signing out or session expires.
  void toGetStarted() {
    navigate(StaffPaths.root);
  }

  /// Navigates to the phone verification page.
  ///
  /// Used for both login and signup flows to verify phone numbers via OTP.
  ///
  /// Parameters:
  ///  * [mode] - The authentication mode: 'login' or 'signup'
  ///
  /// The mode is passed as an argument and used by the verification page
  /// to determine the appropriate flow.
  void toPhoneVerification(String mode) {
    pushNamed(
      StaffPaths.phoneVerification,
      arguments: <String, String>{'mode': mode},
    );
  }

  /// Navigates to the profile setup page, replacing the current route.
  ///
  /// This is typically called after successful phone verification for new
  /// staff members. Uses pushReplacement to prevent going back to verification.
  void toProfileSetup() {
    pushReplacementNamed(StaffPaths.profileSetup);
  }

  // ==========================================================================
  // MAIN NAVIGATION
  // ==========================================================================

  /// Navigates to the staff home dashboard.
  ///
  /// This is the main landing page for authenticated staff members.
  /// Displays shift cards, quick actions, and notifications.
  void toStaffHome() {
    pushNamed(StaffPaths.home);
  }

  /// Navigates to the staff main shell.
  ///
  /// This is the container with bottom navigation. Navigates to home tab
  /// by default. Usually you'd navigate to a specific tab instead.
  void toStaffMain() {
    navigate('${StaffPaths.main}/home/');
  }

  // ==========================================================================
  // MAIN NAVIGATION TABS
  // ==========================================================================

  /// Navigates to the Shifts tab.
  ///
  /// Browse available shifts, accepted shifts, and shift history.
  ///
  /// Parameters:
  ///  * [selectedDate] - Optional date to pre-select in the shifts view
  ///  * [initialTab] - Optional initial tab (via query parameter)
  void toShifts({DateTime? selectedDate, String? initialTab}) {
    final Map<String, dynamic> args = <String, dynamic>{};
    if (selectedDate != null) {
      args['selectedDate'] = selectedDate;
    }
    if (initialTab != null) {
      args['initialTab'] = initialTab;
    }
    navigate(
      StaffPaths.shifts,
      arguments: args.isEmpty ? null : args,
    );
  }

  /// Navigates to the Payments tab.
  ///
  /// View payment history, earnings breakdown, and tax information.
  void toPayments() {
    navigate(StaffPaths.payments);
  }

  /// Navigates to the Clock In tab.
  ///
  /// Access time tracking interface for active shifts.
  void toClockIn() {
    navigate(StaffPaths.clockIn);
  }

  /// Navigates to the Profile tab.
  ///
  /// Manage personal information, documents, and preferences.
  void toProfile() {
    navigate(StaffPaths.profile);
  }

  // ==========================================================================
  // SHIFT MANAGEMENT
  // ==========================================================================

  /// Navigates to the shift details page for a specific shift.
  ///
  /// Displays comprehensive information about a shift including location,
  /// time, pay rate, and action buttons for accepting/declining/applying.
  ///
  /// Parameters:
  ///  * [shift] - The shift entity to display details for
  ///
  /// The shift object is passed as an argument and can be retrieved
  /// in the details page.
  void toShiftDetails(Shift shift) {
    navigate(
      StaffPaths.shiftDetails(shift.id),
      arguments: shift,
    );
  }

  /// Pushes the shift details page (alternative method).
  ///
  /// Same as [toShiftDetails] but using pushNamed instead of navigate.
  /// Use this when you want to add the details page to the stack rather
  /// than replacing the current route.
  void pushShiftDetails(Shift shift) {
    pushNamed(
      StaffPaths.shiftDetails(shift.id),
      arguments: shift,
    );
  }

  // ==========================================================================
  // ONBOARDING & PROFILE SECTIONS
  // ==========================================================================

  /// Pushes the personal information page.
  ///
  /// Collect or edit basic personal information.
  void toPersonalInfo() {
    pushNamed(StaffPaths.onboardingPersonalInfo);
  }

  /// Pushes the emergency contact page.
  ///
  /// Manage emergency contact details for safety purposes.
  void toEmergencyContact() {
    pushNamed(StaffPaths.emergencyContact);
  }

  /// Pushes the work experience page.
  ///
  /// Record previous work experience and qualifications.
  void toExperience() {
    pushNamed(StaffPaths.experience);
  }

  /// Pushes the attire preferences page.
  ///
  /// Record sizing and appearance information for uniform allocation.
  void toAttire() {
    pushNamed(StaffPaths.attire);
  }

  // ==========================================================================
  // COMPLIANCE & DOCUMENTS
  // ==========================================================================

  /// Pushes the documents management page.
  ///
  /// Upload and manage required documents like ID and work permits.
  void toDocuments() {
    pushNamed(StaffPaths.documents);
  }

  /// Pushes the certificates management page.
  ///
  /// Manage professional certificates (e.g., food handling, CPR).
  void toCertificates() {
    pushNamed(StaffPaths.certificates);
  }

  // ==========================================================================
  // FINANCIAL INFORMATION
  // ==========================================================================

  /// Pushes the bank account information page.
  ///
  /// Manage banking details for direct deposit payments.
  void toBankAccount() {
    pushNamed(StaffPaths.bankAccount);
  }

  /// Pushes the tax forms page.
  ///
  /// Manage W-4, tax withholding, and related tax documents.
  void toTaxForms() {
    pushNamed(StaffPaths.taxForms);
  }

  /// Pushes the time card page.
  ///
  /// View detailed time entries and timesheets.
  void toTimeCard() {
    pushNamed(StaffPaths.timeCard);
  }

  // ==========================================================================
  // SCHEDULING & AVAILABILITY
  // ==========================================================================

  /// Pushes the availability management page.
  ///
  /// Define when the staff member is available to work.
  void toAvailability() {
    pushNamed(StaffPaths.availability);
  }

  // ==========================================================================
  // ADDITIONAL FEATURES
  // ==========================================================================

  /// Pushes the Krow University page (placeholder).
  ///
  /// Access training materials and educational courses.
  void toKrowUniversity() {
    pushNamed(StaffPaths.krowUniversity);
  }

  /// Pushes the trainings page (placeholder).
  ///
  /// View and complete required training modules.
  void toTrainings() {
    pushNamed(StaffPaths.trainings);
  }

  /// Pushes the leaderboard page (placeholder).
  ///
  /// View performance rankings and achievements.
  void toLeaderboard() {
    pushNamed(StaffPaths.leaderboard);
  }

  /// Pushes the FAQs page.
  ///
  /// Access frequently asked questions and help resources.
  void toFaqs() {
    pushNamed(StaffPaths.faqs);
  }

  /// Pushes the privacy and security settings page.
  ///
  /// Manage privacy preferences and security settings.
  void toPrivacy() {
    pushNamed(StaffPaths.privacy);
  }

  /// Pushes the messages page (placeholder).
  ///
  /// Access internal messaging system.
  void toMessages() {
    pushNamed(StaffPaths.messages);
  }

  /// Pushes the settings page (placeholder).
  ///
  /// General app settings and preferences.
  void toSettings() {
    pushNamed(StaffPaths.settings);
  }
}
