lms/public/build/assets/timer-component-CSkSxcXX.js
2025-12-15 12:26:23 +01:00

2 lines
1.6 KiB
JavaScript

import{r as m,e as g,j as t,cZ as p,k as j}from"./vendor-BKmmeuxg.js";import{B as N}from"./badge-AQfLLMpR.js";import{C as v,b as w}from"./card-D9_SJYq6.js";import"./index-WW_1X1qx.js";import"./utils-DxSsnXxD.js";const I=({endTime:n,onTimeUp:i,attempt:o,questionIndex:u})=>{const[x,l]=m.useState(0),[r,f]=m.useState(!1);m.useEffect(()=>{const s=()=>{if(!n)return 0;const e=new Date(n).getTime();if(Number.isNaN(e))return 0;const c=new Date().getTime(),h=e-c;return Math.max(0,Math.floor(h/1e3))};l(s());const a=setInterval(()=>{const e=s();l(e),e<=300&&e>0&&f(!0),e===0&&(clearInterval(a),i?i():g.post(route("exam-attempts.submit",o.id)))},1e3);return()=>clearInterval(a)},[n,o.id,i]);const d=s=>{const a=Math.floor(s/3600),e=Math.floor(s%3600/60),c=s%60;return`${a.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${c.toString().padStart(2,"0")}`};return t.jsx(v,{className:`${r?"border-destructive":""}`,children:t.jsxs(w,{className:"p-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("h6",{className:"flex items-center gap-2",children:[r?t.jsx(p,{className:"text-destructive h-5 w-5"}):t.jsx(j,{className:"h-5 w-5 text-gray-600"}),t.jsx("span",{className:"font-semibold text-gray-700",children:"Time Remaining"})]}),t.jsx(N,{variant:r?"destructive":"secondary",className:"font-mono text-lg",children:d(x)})]}),t.jsxs("p",{className:"pl-7 text-sm text-gray-600",children:["Question ",u+1," of ",o.exam.questions.length]}),r&&t.jsx("p",{className:"text-destructive mt-2 text-sm",children:"Less than 5 minutes remaining! The exam will auto-submit when time runs out."})]})})};export{I as default};