"use client" /** * ExamLockResumeAuthDialog — proctor password gate after Retry on a hard pause. * Demo default code is `proctor`. Production would verify against the session API. */ import * as React from "react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Field, FieldLabel } from "@/components/ui/field" import { FloatingSheetPanel, FloatingSheetPanelBody, FloatingSheetPanelContent, FloatingSheetPanelFooter, FloatingSheetPanelHeader, FloatingSheetPanelToolbar, } from "@/components/ui/floating-sheet-panel" import { Input } from "@/components/ui/input" /** Demo-only resume code. Replace with session/proctor verification in production. */ export const EXAM_LOCK_DEMO_PROCTOR_PASSWORD = "proctor" export interface ExamLockResumeAuthDialogProps { open: boolean onOpenChange: (open: boolean) => void /** Called after a valid password. Parent should resume the session. */ onAuthorized: () => void /** Expected password. Defaults to the demo proctor code. */ expectedPassword?: string } export function ExamLockResumeAuthDialog({ open, onOpenChange, onAuthorized, expectedPassword = EXAM_LOCK_DEMO_PROCTOR_PASSWORD, }: ExamLockResumeAuthDialogProps) { const inputRef = React.useRef(null) const [password, setPassword] = React.useState("") const [error, setError] = React.useState(null) const [instructionsOpen, setInstructionsOpen] = React.useState(false) React.useEffect(() => { if (!open) { setInstructionsOpen(false) return } setPassword("") setError(null) }, [open]) React.useEffect(() => { if (!open || instructionsOpen) return const id = window.requestAnimationFrame(() => inputRef.current?.focus()) return () => window.cancelAnimationFrame(id) }, [instructionsOpen, open]) const submit = React.useCallback( (event?: React.FormEvent) => { event?.preventDefault() if (password === expectedPassword) { setError(null) onOpenChange(false) onAuthorized() return } setError("Incorrect password. Ask your proctor for the resume code.") inputRef.current?.select() }, [expectedPassword, onAuthorized, onOpenChange, password], ) return ( <> { if (!instructionsOpen) onOpenChange(nextOpen) }} > Enter proctor password A proctor must authorize resume before the exam continues. Your timer stays paused.
Proctor password { setPassword(event.target.value) if (error) setError(null) }} /> {error ? ( ) : (

Demo code: {expectedPassword}

)}
{ if (!nextOpen) setInstructionsOpen(false) }} >
    {[ "Keep this exam open. The timer remains paused.", "Ask your proctor to review the pause status.", "Your proctor enters the resume password.", "Select Resume exam to continue.", ].map((instruction, index) => (
  1. {instruction}
  2. ))}
) }