var S=Object.defineProperty,C=Object.defineProperties;var k=Object.getOwnPropertyDescriptors;var g=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var f=(a,e,c)=>e in a?S(a,e,{enumerable:!0,configurable:!0,writable:!0,value:c}):a[e]=c,h=(a,e)=>{for(var c in e||(e={}))A.call(e,c)&&f(a,c,e[c]);if(g)for(var c of g(e))O.call(e,c)&&f(a,c,e[c]);return a},y=(a,e)=>C(a,k(e));import{r,j as t}from"./react-vendor-xYZnmIII.js";import{B as E,L as B,at as L,au as R,av as V,aw as z,ax as Q}from"./ui-components-CQM92IK3.js";import"./inertia-vendor-cBbDTmhJ.js";import"./ui-vendor-Ds9iwIxa.js";import"./interactive-vendor-B1OgcAgP.js";const I=({question:a,answer:e,onAnswerChange:c})=>{var p;const d=((p=a.options)==null?void 0:p.matches)||[],o=()=>Array.isArray(e==null?void 0:e.matches)?e.matches.reduce((l,n)=>(l[n.id]=n.answer,l),{}):e!=null&&e.matches&&typeof e.matches=="object"?h({},e.matches):{},[i,m]=r.useState(o);r.useEffect(()=>{m(o())},[a.id]);const x=s=>{m(s);const l=Object.entries(s).map(([n,N])=>({id:Number(n),answer:N}));c({matches:l})},b=(s,l)=>{x(y(h({},i),{[s]:l}))},M=()=>{x({})},j=r.useMemo(()=>d.map(s=>({id:s.id,text:s.question})),[d]),u=r.useMemo(()=>d.map(s=>({id:s.id,text:s.answer})),[d]),v=r.useMemo(()=>[...u].sort(()=>Math.random()-.5),[u]);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:"Match each item on the left with the correct item on the right:"}),t.jsx(E,{variant:"ghost",size:"sm",onClick:M,disabled:Object.keys(i).length===0,children:"Clear All"})]}),t.jsx("div",{className:"space-y-3",children:j.map(s=>t.jsxs("div",{className:"grid grid-cols-1 gap-3 rounded-lg border p-4 md:grid-cols-2",children:[t.jsx("div",{className:"flex items-center",children:t.jsx("div",{className:"flex-1",children:t.jsx(B,{className:"font-normal",children:s.text})})}),t.jsx("div",{children:t.jsxs(L,{value:i[s.id]||"",onValueChange:l=>b(s.id,l),children:[t.jsx(R,{children:t.jsx(V,{placeholder:"Select a match..."})}),t.jsx(z,{children:v.map(l=>t.jsx(Q,{value:l.text,children:l.text},l.id))})]})})]},s.id))}),Object.keys(i).length>0&&t.jsxs("p",{className:"text-sm text-gray-600",children:["Matched: ",t.jsx("span",{className:"font-semibold",children:Object.keys(i).length})," of ",j.length]})]})};export{I as default};
