import { Navigate } from 'react-router-dom';
import { useShellOutletContext } from '@/app/shellOutletContext';
import { getDefaultRoutePathForRole } from '@/shared/constants/moduleRoutes';

/**
 * Sends the index route (`/`) to the first module the current role can access,
 * so every role lands on a page it is allowed to see.
 */
export function IndexRedirect() {
  const shell = useShellOutletContext();

  return (
    <Navigate to={getDefaultRoutePathForRole(shell.userRole)} replace />
  );
}
