integratedhub/utils/quizModes.ts
2026-01-20 09:02:26 -06:00

93 lines
2.6 KiB
TypeScript

// utils/quizModes.ts
// Shared canonical quiz mode definitions matching QuizConfigure.tsx
/**
* Ordered list of quiz modes from easiest to hardest.
* This order is used for mode progression in BrainStudy.
*
* Mode meanings:
* - photo-see-bisaya: Show photo, display Bisaya text, user types English
* - photo-see-english: Show photo, display English text, user types Bisaya
* - photo-hide-bisaya: Show photo, hide Bisaya (audio only), user types Bisaya
* - photo-hide-english: Show photo, hide English, user types English
* - blank-see-bisaya: No photo, display Bisaya text, user types English
* - blank-see-english: No photo, display English text, user types Bisaya
*/
export const QUIZ_MODES = [
"photo-see-bisaya",
"photo-see-english",
"photo-hide-bisaya",
"photo-hide-english",
"blank-see-bisaya",
"blank-see-english",
] as const;
export type QuizMode = typeof QUIZ_MODES[number];
/**
* Default/starting mode for new cards
*/
export const DEFAULT_QUIZ_MODE: QuizMode = QUIZ_MODES[0];
/**
* Get the index of a mode in the progression order
*/
export function getModeIndex(mode: string): number {
const index = QUIZ_MODES.indexOf(mode as QuizMode);
return index >= 0 ? index : 0;
}
/**
* Get the next mode in the progression
* Returns null if already at the final mode
*/
export function getNextMode(currentMode: string): QuizMode | null {
const currentIndex = getModeIndex(currentMode);
if (currentIndex >= QUIZ_MODES.length - 1) {
return null; // Already at final mode
}
return QUIZ_MODES[currentIndex + 1];
}
/**
* Check if a mode is the final mode in the progression
*/
export function isFinalMode(mode: string): boolean {
return getModeIndex(mode) === QUIZ_MODES.length - 1;
}
/**
* Get display label for a mode
*/
export function getModeLabel(mode: string): string {
const labels: Record<string, string> = {
"photo-see-bisaya": "Photo, See Bisaya",
"photo-see-english": "Photo, See English",
"photo-hide-bisaya": "Blank, Hide Bisaya",
"photo-hide-english": "Photo, Hide English",
"blank-see-bisaya": "Blank, See Bisaya",
"blank-see-english": "Blank, See English",
};
return labels[mode] || mode;
}
/**
* Get mode display info for UI
*/
export function getModeDisplayInfo(mode: string): {
index: number;
total: number;
label: string;
isFirst: boolean;
isFinal: boolean;
} {
const index = getModeIndex(mode);
return {
index: index + 1, // 1-based for display
total: QUIZ_MODES.length,
label: getModeLabel(mode),
isFirst: index === 0,
isFinal: index === QUIZ_MODES.length - 1,
};
}