/** * QuestionTimer - Countdown Timer Component for Strict/High-Pressure Interviews * * Shows remaining time for current question with visual urgency indicators. */ import React, { useMemo } from 'react'; import { Clock, AlertTriangle } from 'lucide-react'; import './QuestionTimer.css'; export default function QuestionTimer({ timeRemaining, totalTime, isRunning, onTimeUp, showWarnings = true }) { // Calculate percentage for progress bar const percentage = totalTime > 0 ? (timeRemaining / totalTime) * 100 : 100; // Determine urgency level const urgency = useMemo(() => { if (timeRemaining <= 10) return 'critical'; // Last 10 seconds if (timeRemaining <= 30) return 'warning'; // Last 30 seconds if (percentage <= 25) return 'low'; // Last quarter return 'normal'; }, [timeRemaining, percentage]); // Format time as MM:SS const formattedTime = useMemo(() => { const minutes = Math.floor(timeRemaining / 60); const seconds = timeRemaining % 60; return `${minutes}:${seconds.toString().padStart(2, '0')}`; }, [timeRemaining]); // Don't render if no time limit if (totalTime <= 0) return null; return (
{urgency === 'critical' ? ( ) : ( )} Time Remaining
{formattedTime}
{showWarnings && urgency === 'warning' && (
⚠️ 30 seconds remaining!
)} {showWarnings && urgency === 'critical' && (
🚨 Wrap up your answer!
)} {timeRemaining === 0 && (
⏰ Time's up!
)}
); }