/*
 * File: navigationUtils.ts
 * Description: Navigation utilities for Dashboard module
 * Design & Developed by Tech4Biz Solutions
 * Copyright (c) Spurrin Innovations. All rights reserved.
 */

import { DashboardNavigationProp } from './navigationTypes';
import { Patient, Alert as AlertType } from '../../../shared/types';

/**
 * DashboardNavigationUtils - Utility functions for Dashboard module navigation
 * 
 * This module provides helper functions for common navigation patterns
 * within the Dashboard module, ensuring consistent navigation behavior.
 */

/**
 * Navigate to ER Dashboard screen
 * @param navigation - Navigation prop from React Navigation
 * @param params - Optional parameters for the dashboard
 */
export const navigateToERDashboard = (
  navigation: DashboardNavigationProp,
  params?: {
    filter?: 'all' | 'critical' | 'active' | 'pending';
    refresh?: boolean;
  }
): void => {
  navigation.navigate('ERDashboard', params);
};

/**
 * Navigate to Patient Details screen
 * @param navigation - Navigation prop from React Navigation
 * @param patientId - Required patient ID
 * @param patient - Optional patient data
 * @param fromScreen - Optional source screen
 */
export const navigateToPatientDetails = (
  navigation: DashboardNavigationProp,
  patientId: string,
  patient?: Patient,
  fromScreen?: keyof import('./navigationTypes').DashboardStackParamList
): void => {
  navigation.navigate('PatientDetails', {
    patientId,
    patient,
    fromScreen,
  });
};

/**
 * Navigate to Alert Details screen
 * @param navigation - Navigation prop from React Navigation
 * @param alertId - Required alert ID
 * @param alert - Optional alert data
 * @param fromScreen - Optional source screen
 */
export const navigateToAlertDetails = (
  navigation: DashboardNavigationProp,
  alertId: string,
  alert?: AlertType,
  fromScreen?: keyof import('./navigationTypes').DashboardStackParamList
): void => {
  navigation.navigate('AlertDetails', {
    alertId,
    alert,
    fromScreen,
  });
};

/**
 * Navigate to Department Stats screen
 * @param navigation - Navigation prop from React Navigation
 * @param department - Required department name
 * @param dateRange - Optional date range for statistics
 */
export const navigateToDepartmentStats = (
  navigation: DashboardNavigationProp,
  department: string,
  dateRange?: {
    start: Date;
    end: Date;
  }
): void => {
  navigation.navigate('DepartmentStats', {
    department,
    dateRange,
  });
};

/**
 * Navigate to Quick Actions screen
 * @param navigation - Navigation prop from React Navigation
 * @param actionType - Optional action type to pre-select
 * @param patientId - Optional patient ID for patient-specific actions
 */
export const navigateToQuickActions = (
  navigation: DashboardNavigationProp,
  actionType?: 'emergency' | 'scan' | 'report' | 'consultation',
  patientId?: string
): void => {
  navigation.navigate('QuickActions', {
    actionType,
    patientId,
  });
};

/**
 * Go back to previous screen
 * @param navigation - Navigation prop from React Navigation
 */
export const goBack = (navigation: DashboardNavigationProp): void => {
  if (navigation.canGoBack()) {
    navigation.goBack();
  }
};

/**
 * Reset navigation stack to ER Dashboard screen
 * @param navigation - Navigation prop from React Navigation
 * @param params - Optional parameters for the dashboard
 */
export const resetToERDashboard = (
  navigation: DashboardNavigationProp,
  params?: {
    filter?: 'all' | 'critical' | 'active' | 'pending';
    refresh?: boolean;
  }
): void => {
  navigation.reset({
    index: 0,
    routes: [{ name: 'ERDashboard', params }],
  });
};

/**
 * Replace current screen with ER Dashboard screen
 * @param navigation - Navigation prop from React Navigation
 * @param params - Optional parameters for the dashboard
 */
export const replaceWithERDashboard = (
  navigation: DashboardNavigationProp,
  params?: {
    filter?: 'all' | 'critical' | 'active' | 'pending';
    refresh?: boolean;
  }
): void => {
  navigation.replace('ERDashboard', params);
};

/**
 * Navigate to ER Dashboard and clear back stack
 * @param navigation - Navigation prop from React Navigation
 * @param params - Optional parameters for the dashboard
 */
export const navigateToERDashboardAndClearStack = (
  navigation: DashboardNavigationProp,
  params?: {
    filter?: 'all' | 'critical' | 'active' | 'pending';
    refresh?: boolean;
  }
): void => {
  navigation.reset({
    index: 0,
    routes: [{ name: 'ERDashboard', params }],
  });
};

/**
 * Navigate to Patient Details and clear back stack
 * @param navigation - Navigation prop from React Navigation
 * @param patientId - Required patient ID
 * @param patient - Optional patient data
 */
export const navigateToPatientDetailsAndClearStack = (
  navigation: DashboardNavigationProp,
  patientId: string,
  patient?: Patient
): void => {
  navigation.reset({
    index: 0,
    routes: [{ name: 'PatientDetails', params: { patientId, patient } }],
  });
};

/**
 * Navigate to Alert Details and clear back stack
 * @param navigation - Navigation prop from React Navigation
 * @param alertId - Required alert ID
 * @param alert - Optional alert data
 */
export const navigateToAlertDetailsAndClearStack = (
  navigation: DashboardNavigationProp,
  alertId: string,
  alert?: AlertType
): void => {
  navigation.reset({
    index: 0,
    routes: [{ name: 'AlertDetails', params: { alertId, alert } }],
  });
};

/*
 * End of File: navigationUtils.ts
 * Design & Developed by Tech4Biz Solutions
 * Copyright (c) Spurrin Innovations. All rights reserved.
 */ 