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