import{r as a,j as s,eT as R,cJ as _,eU as P,X as V}from"./react-vendor-xYZnmIII.js";import{B as y,aM as N,R as $,f as k,L as I}from"./ui-components-CQM92IK3.js";import"./inertia-vendor-cBbDTmhJ.js";import"./ui-vendor-Ds9iwIxa.js";import"./interactive-vendor-B1OgcAgP.js";const U=({question:o,answer:l,onAnswerChange:x})=>{var v;const r=a.useRef(null),[d,p]=a.useState(!1),[h,f]=a.useState(0),[c,b]=a.useState(0),[m,S]=a.useState(.8),u=(l==null?void 0:l.option_id)||"",n=((v=o.options)==null?void 0:v.audio_url)||"",E=o.question_options||[];a.useEffect(()=>{const e=r.current;if(!e)return;const t=()=>f(e.currentTime),i=()=>b(e.duration),g=()=>p(!1);return e.addEventListener("timeupdate",t),e.addEventListener("loadedmetadata",i),e.addEventListener("ended",g),()=>{e.removeEventListener("timeupdate",t),e.removeEventListener("loadedmetadata",i),e.removeEventListener("ended",g)}},[]),a.useEffect(()=>{r.current&&(r.current.volume=m)},[m]);const L=()=>{const e=r.current;e&&(d?e.pause():e.play(),p(!d))},C=e=>{const t=r.current;t&&(t.currentTime=e[0],f(e[0]))},w=e=>{x({question_id:o.id,option_id:parseInt(e)})},T=()=>{x(null)},j=e=>{const t=Math.floor(e/60),i=Math.floor(e%60);return`${t}:${i.toString().padStart(2,"0")}`};return s.jsxs("div",{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-gray-600",children:"Listen to the audio carefully and select the correct answer:"}),s.jsxs("div",{className:"from-primary/10 to-primary/5 rounded-lg border bg-gradient-to-br p-6",children:[s.jsx("audio",{ref:r,src:n,preload:"metadata"}),s.jsx("div",{className:"mb-4 flex justify-center",children:s.jsx(y,{onClick:L,size:"lg",className:"h-16 w-16 rounded-full",disabled:!n,children:d?s.jsx(R,{className:"h-6 w-6"}):s.jsx(_,{className:"ml-1 h-6 w-6"})})}),s.jsx("div",{className:"mb-2",children:s.jsx(N,{value:[h],max:c||100,step:.1,onValueChange:C,disabled:!n||!c,className:"cursor-pointer"})}),s.jsxs("div",{className:"mb-4 flex justify-between text-sm text-gray-600",children:[s.jsx("span",{children:j(h)}),s.jsx("span",{children:j(c)})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(P,{className:"h-4 w-4 text-gray-600"}),s.jsx(N,{value:[m],max:1,step:.1,onValueChange:e=>S(e[0]),className:"w-24"})]})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-3 flex items-start justify-between",children:[s.jsx("p",{className:"text-sm font-semibold text-gray-700",children:"Select your answer:"}),u&&s.jsxs(y,{variant:"ghost",size:"sm",onClick:T,children:[s.jsx(V,{className:"mr-2 h-4 w-4"}),"Clear Selection"]})]}),s.jsx($,{value:u.toString(),onValueChange:w,children:s.jsx("div",{className:"space-y-3",children:E.map(e=>s.jsxs("div",{className:`flex items-start space-x-3 rounded-lg border-2 p-4 transition-colors ${u===e.id?"border-primary bg-primary/5":"border-gray-200 hover:border-gray-300"}`,children:[s.jsx(k,{value:e.id.toString(),id:`option-${e.id}`,className:"mt-0.5"}),s.jsx(I,{htmlFor:`option-${e.id}`,className:"flex-1 cursor-pointer font-normal",children:e.option_text})]},e.id))})})]}),!n&&s.jsx("div",{className:"rounded-lg bg-yellow-50 p-3",children:s.jsxs("p",{className:"text-sm text-yellow-800",children:[s.jsx("span",{className:"font-semibold",children:"Note:"})," Audio file is not available for this question."]})})]})};export{U as default};
