import{jsx as r,jsxs as m}from"react/jsx-runtime";import{a as g,l as x,g as N}from"./ui-components-B24mpb8o.js";import{router as v}from"@inertiajs/react";import{AlertTriangle as w,Clock as S}from"lucide-react";import{useState as p,useEffect as b}from"react";import"next-themes";import"sonner";import"@radix-ui/react-label";import"class-variance-authority";import"@radix-ui/react-checkbox";import"@radix-ui/react-avatar";import"@radix-ui/react-dropdown-menu";import"@radix-ui/react-scroll-area";import"@radix-ui/react-popover";import"@radix-ui/react-radio-group";import"@radix-ui/react-dialog";import"@radix-ui/react-slot";import"clsx";import"@radix-ui/react-separator";import"@radix-ui/react-tooltip";import"@radix-ui/react-tabs";import"@radix-ui/react-accordion";import"@radix-ui/react-progress";import"@radix-ui/react-select";import"cmdk";import"@radix-ui/react-switch";import"react-day-picker";import"@radix-ui/react-slider";import"embla-carousel-react";import"@radix-ui/react-toggle-group";import"vaul";import"tailwind-merge";const rt=({endTime:a,onTimeUp:s,attempt:n,questionIndex:f})=>{const[u,l]=p(0),[i,d]=p(!1);return b(()=>{const e=()=>{if(!a)return 0;const t=new Date(a).getTime();if(Number.isNaN(t))return 0;const c=new Date().getTime(),h=t-c;return Math.max(0,Math.floor(h/1e3))};l(e());const o=setInterval(()=>{const t=e();l(t),t<=300&&t>0&&d(!0),t===0&&(clearInterval(o),s?s():v.post(route("exam-attempts.submit",n.id)))},1e3);return()=>clearInterval(o)},[a,n.id,s]),r(g,{className:`${i?"border-destructive":""}`,children:m(x,{className:"p-4",children:[m("div",{className:"flex items-center justify-between",children:[m("h6",{className:"flex items-center gap-2",children:[i?r(w,{className:"text-destructive h-5 w-5"}):r(S,{className:"h-5 w-5 text-gray-600"}),r("span",{className:"font-semibold text-gray-700",children:"Time Remaining"})]}),r(N,{variant:i?"destructive":"secondary",className:"font-mono text-lg",children:(e=>{const o=Math.floor(e/3600),t=Math.floor(e%3600/60),c=e%60;return`${o.toString().padStart(2,"0")}:${t.toString().padStart(2,"0")}:${c.toString().padStart(2,"0")}`})(u)})]}),m("p",{className:"pl-7 text-sm text-gray-600",children:["Question ",f+1," of ",n.exam.questions.length]}),i&&r("p",{className:"text-destructive mt-2 text-sm",children:"Less than 5 minutes remaining! The exam will auto-submit when time runs out."})]})})};export{rt as default};
