"use client" /** * Design OS — Exam lock template showcase. * One question at a time, header tools, settings popover, demo overlays. */ import * as React from "react" import { ExamLockAnswerProgress, ExamLockHeaderToolbar, ExamLockInterruptionPanel, ExamLockQuestionBody, ExamLockQuestionNav, ExamLockQuestionRenderer, ExamLockResumeAuthDialog, ExamLockTimerDisplay, EXAM_LOCK_DEMO_CLINICAL_FIGURE, isExamLockQuestionAnswered, useExamLockColorMode, useExamLockSessionController, type ExamLockAnswerValue, type ExamLockDeliveryQuestion, } from "@/components/exam-lock" import { ExamLockTemplate } from "@/components/templates/exam-lock-template" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Shortcut } from "@/components/ui/dropdown-menu" import { Separator } from "@/components/ui/separator" import { NAV_USER } from "@/lib/mock/navigation" import { cn } from "@/lib/utils" import { useNavigate } from "react-router" const EXAM_TITLE = "Clinical reasoning sample exam" const INITIAL_SECONDS = 45 * 60 const MOCK_QUESTION_DEFS = [ { type: "mcq_single", questionId: "q1", stem: "Review the monitor strip, then select the priority assessment before pharmacologic intervention for acute shortness of breath with bilateral crackles.", stemMedia: EXAM_LOCK_DEMO_CLINICAL_FIGURE, options: [ "Obtain a 12-lead ECG", "Auscultate posterior lung fields", "Measure oxygen saturation and apply supplemental O₂ if indicated", "Order a chest X-ray", ], }, { type: "true_false", questionId: "q2", stem: "Jugular venous distension with peripheral edema supports prioritizing fluid restriction in heart failure exacerbation.", }, { type: "fill_blank", questionId: "q3", stem: "Before administering a new medication, the nurse performs the {{blank}} check to reduce the risk of {{blank}}.", formatHint: "Use clinical terms. One or two words per blank.", }, { type: "essay", questionId: "q4", stem: "Describe your nursing priorities in the first 10 minutes of care for a patient with acute shortness of breath and bilateral crackles.", maxCharacters: 2000, formatHint: "Write in complete sentences. Address assessment, safety, and communication.", }, ] as const function mockQuestionAt(index: number): ExamLockDeliveryQuestion { const def = MOCK_QUESTION_DEFS[index]! return { ...def, questionNumber: index + 1 } as ExamLockDeliveryQuestion } const KEYBOARD_ROWS = [ ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"], ["A", "S", "D", "F", "G", "H", "J", "K", "L"], ["Z", "X", "C", "V", "B", "N", "M"], ] as const const CALCULATOR_TOP_ROW = ["C", "÷", "×", "⌫"] as const const CALCULATOR_ROWS = [ ["7", "8", "9", "−"], ["4", "5", "6", "+"], ["1", "2", "3", "="], ] as const function ExamCalculator({ className }: { className?: string }) { const [display, setDisplay] = React.useState("0") const [pending, setPending] = React.useState(null) const [operator, setOperator] = React.useState(null) const appendDigit = (digit: string) => { setDisplay(prev => (prev === "0" ? digit : `${prev}${digit}`)) } const clearAll = () => { setDisplay("0") setPending(null) setOperator(null) } const applyOperator = (op: string) => { setPending(display) setOperator(op) setDisplay("0") } const equals = () => { if (pending == null || operator == null) return const a = Number.parseFloat(pending) const b = Number.parseFloat(display) let result = 0 switch (operator) { case "+": result = a + b break case "−": result = a - b break case "×": result = a * b break case "÷": result = b === 0 ? 0 : a / b break default: return } setDisplay(String(Number.isInteger(result) ? result : result.toFixed(2))) setPending(null) setOperator(null) } const onKey = (key: string) => { if (key === "C") { clearAll() return } if (key === "⌫") { setDisplay(prev => (prev.length <= 1 ? "0" : prev.slice(0, -1))) return } if (key === "=") { equals() return } if (["+", "−", "×", "÷"].includes(key)) { applyOperator(key) return } if (key === ".") { setDisplay(prev => (prev.includes(".") ? prev : `${prev}.`)) return } appendDigit(key) } const topRow = CALCULATOR_TOP_ROW const rows = CALCULATOR_ROWS return (
{display}
{topRow.map(key => ( ))} {rows.flat().map(key => ( ))}
) } type ExamLockInterruptionPanelProps = React.ComponentProps type AnswerMap = Record function removeAnswer(answers: AnswerMap, qid: string): AnswerMap { const next = { ...answers } delete next[qid] return next } /** A cleared text field or a fill-blank map whose entries are all blank. */ function isEmptyAnswerValue(value: ExamLockAnswerValue): boolean { if (value === "") return true if (typeof value !== "object" || Array.isArray(value)) return false return Object.values(value).every(entry => !entry.trim()) } function applyAnswerValue(answers: AnswerMap, qid: string, value: ExamLockAnswerValue): AnswerMap { return isEmptyAnswerValue(value) ? removeAnswer(answers, qid) : { ...answers, [qid]: value } } function toggleEliminatedOption( eliminated: Record, qid: string, option: string, ): Record { const current = eliminated[qid] ?? [] const next = current.includes(option) ? current.filter(item => item !== option) : [...current, option] return { ...eliminated, [qid]: next } } function isChoiceQuestion(question: ExamLockDeliveryQuestion): boolean { return question.type === "mcq_single" || question.type === "true_false" } function emptyAnswerFor(question: ExamLockDeliveryQuestion): ExamLockAnswerValue { return question.type === "fill_blank" ? {} : "" } /** Routes the interruption "Retry" action through the resume-authorisation dialog. */ function withResumeAuthRetry( props: ExamLockInterruptionPanelProps | null | undefined, requestResumeAuth: () => void, ): ExamLockInterruptionPanelProps | null { if (!props) return null if (!props.supportActions?.retry) return props return { ...props, supportActions: { ...props.supportActions, retry: { ...props.supportActions.retry, onClick: requestResumeAuth }, }, } } function ShowcaseSimulateToggle({ label, hint, checked, onCheckedChange, }: { label: string hint: string checked: boolean onCheckedChange: (checked: boolean) => void }) { return ( ) } function ShowcaseSettingsContent({ simulateOffline, onSimulateOfflineChange, simulateBlur, onSimulateBlurChange, onExitRequest, }: { simulateOffline: boolean onSimulateOfflineChange: (checked: boolean) => void simulateBlur: boolean onSimulateBlurChange: (checked: boolean) => void onExitRequest: () => void }) { return (