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