"use client"; import React from "react"; import { useRouter } from "next/navigation"; import { ChevronLeft, Layers, RefreshCcw } from "lucide-react"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { useModal } from "@/context/ModalContext"; import { useAuthStore } from "@/stores/authStore"; import { useTimerStore } from "@/stores/timerStore"; import { useExamStore } from "@/stores/examStore"; import { BsPatchCheckFill } from "react-icons/bs"; interface HeaderProps { displayUser?: boolean; displaySubject?: string; displayTabTitle?: string; } const Header = ({ displayUser, displaySubject, displayTabTitle, }: HeaderProps) => { const router = useRouter(); const { open } = useModal(); const { cancelExam } = useExamStore(); const { stopTimer, timeRemaining } = useTimerStore(); const { user } = useAuthStore(); const showExitDialog = () => { const confirmed = window.confirm("Are you sure you want to quit the exam?"); if (confirmed) { stopTimer(); cancelExam(); router.replace("/categories"); } }; const handleBackClick = () => { router.back(); }; // format time from context const hours = Math.floor(timeRemaining / 3600); const minutes = Math.floor((timeRemaining % 3600) / 60); const seconds = timeRemaining % 60; return (
{displayUser && (
{user?.username ? ( user.username.charAt(0).toUpperCase() ) : (
)}
Hello, {user?.username ? user.username.split(" ")[0] : "User"}{" "}
)} {displayTabTitle && (
{displayTabTitle}
)} {displaySubject && (
{displaySubject}
)} {/* Exam timer header */} {timeRemaining > 0 && (
{String(hours).padStart(2, "0")} Hrs
{String(minutes).padStart(2, "0")} Mins
{String(seconds).padStart(2, "0")} Secs
)}
); }; export default Header;