2 lines
2.5 KiB
JavaScript
2 lines
2.5 KiB
JavaScript
import{r as i,j as t,cs as C,d2 as I,d3 as A}from"./vendor-BKmmeuxg.js";import{B as f}from"./button-BpNwv2aE.js";import{C as O}from"./card-D9_SJYq6.js";import"./index-WW_1X1qx.js";import"./utils-DxSsnXxD.js";const U=({question:m,answer:o,onAnswerChange:b})=>{var g,N;const p=((g=m.options)==null?void 0:g.items)||[],n=i.useMemo(()=>p.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:""}}),[p]),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(f,{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(f,{variant:"outline",size:"sm",onClick:()=>j(s,"up"),disabled:s===0,children:t.jsx(I,{className:"h-4 w-4"})}),t.jsx(f,{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};
|