import{r as a,j as s,d0 as T,bh as _,d1 as P,aj as V}from"./vendor-BKmmeuxg.js";import{B as y}from"./button-BpNwv2aE.js";import{L as $}from"./label-HmIcv5Yx.js";import{R as k,a as I}from"./radio-group-C0C2vfl-.js";import{S as N}from"./slider-CUN53q6N.js";import"./index-WW_1X1qx.js";import"./utils-DxSsnXxD.js";const O=({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)})},R=()=>{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(T,{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:R,children:[s.jsx(V,{className:"mr-2 h-4 w-4"}),"Clear Selection"]})]}),s.jsx(k,{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(I,{value:e.id.toString(),id:`option-${e.id}`,className:"mt-0.5"}),s.jsx($,{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{O as default};
