import{r as i,j as t,ds as C,eV as I,eW as A}from"./react-vendor-xYZnmIII.js";import{B as p,a as O}from"./ui-components-CQM92IK3.js";import"./inertia-vendor-cBbDTmhJ.js";import"./ui-vendor-Ds9iwIxa.js";import"./interactive-vendor-B1OgcAgP.js";const U=({question:m,answer:o,onAnswerChange:b})=>{var g,N;const f=((g=m.options)==null?void 0:g.items)||[],n=i.useMemo(()=>f.map((e,s)=>{if(typeof e=="string")return{id:s,text:e};if(e&&typeof e=="object"){const r=typeof e.text=="string"?e.text:typeof e.label=="string"?e.label:"";return{id:s,text:r}}return{id:s,text:""}}),[f]),d=i.useMemo(()=>{var a;const e=c=>{if(!c||c.length!==n.length||new Set(c).size!==n.length)return null;const v=c.map(u=>n.find(w=>w.id===Number(u))).filter(u=>!!u);return v.length===n.length?v:null},s=e(o==null?void 0:o.order);if(s)return s;const r=e((a=m.options)==null?void 0:a.correct_order);return r||[...n].sort(()=>Math.random()-.5)},[o==null?void 0:o.order,(N=m.options)==null?void 0:N.correct_order,n]),[l,h]=i.useState(d);i.useEffect(()=>{h(d)},[d]);const x=e=>{h(e),b({order:e.map(s=>s.id)})},j=(e,s)=>{if(s==="up"&&e===0||s==="down"&&e===l.length-1)return;const r=[...l],a=s==="up"?e-1:e+1;[r[e],r[a]]=[r[a],r[e]],x(r)},y=()=>{const e=[...l].sort(()=>Math.random()-.5);x(e)};return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("p",{className:"text-sm text-gray-600",children:"Arrange the following items in the correct order:"}),t.jsx(p,{variant:"ghost",size:"sm",onClick:y,children:"Shuffle"})]}),t.jsx("div",{className:"space-y-2",children:l.map((e,s)=>t.jsx(O,{className:"p-4",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(C,{className:"h-5 w-5 text-gray-400"}),t.jsx("div",{className:"bg-primary flex h-8 w-8 items-center justify-center rounded-full text-sm font-semibold text-white",children:s+1})]}),t.jsx("div",{className:"flex-1",children:t.jsx("p",{className:"font-medium",children:e.text})}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(p,{variant:"outline",size:"sm",onClick:()=>j(s,"up"),disabled:s===0,children:t.jsx(I,{className:"h-4 w-4"})}),t.jsx(p,{variant:"outline",size:"sm",onClick:()=>j(s,"down"),disabled:s===l.length-1,children:t.jsx(A,{className:"h-4 w-4"})})]})]})},e.id))}),t.jsxs("p",{className:"text-sm text-gray-600",children:[t.jsx("span",{className:"font-semibold",children:"Tip:"})," Use the arrow buttons to move items up or down."]})]})};export{U as default};
