2 lines
2.1 KiB
JavaScript
2 lines
2.1 KiB
JavaScript
import{r as u,j as e}from"./vendor-BKmmeuxg.js";import{I as f}from"./input-DM0goJrn.js";import{L as v}from"./label-HmIcv5Yx.js";import"./utils-DxSsnXxD.js";import"./index-WW_1X1qx.js";const C=({question:n,answer:l,onAnswerChange:g})=>{var x,h;const r=(x=n.options)==null?void 0:x.blanks,o=(r==null?void 0:r.length)??1,m=()=>{if(Array.isArray(l==null?void 0:l.answers)){const s=l==null?void 0:l.answers;return Array.from({length:o},(t,a)=>s[a]||"")}if(l!=null&&l.answers&&typeof l.answers=="object"){const s=l.answers;return Array.from({length:o},(t,a)=>s[a]||"")}return Array.from({length:o},()=>"")},[c,p]=u.useState(m);u.useEffect(()=>{p(m())},[n.id]);const j=s=>{p(s),g({answers:s})},d=(s,t)=>{const a=[...c];a[s]=t,j(a)},i=n.description||"",y=r?i.split(/\[BLANK_(\d+)\]/g):[i];return e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Fill in the blanks with appropriate answers:"}),e.jsx("div",{className:"rounded-lg bg-gray-50 p-6",children:e.jsx("div",{className:"prose prose-sm max-w-none",children:r?y.map((s,t)=>{if(t%2===0)return e.jsx("span",{dangerouslySetInnerHTML:{__html:s}},t);const a=parseInt(s,10);return e.jsx("span",{className:"inline-block align-middle",children:e.jsx(f,{type:"text",value:c[a]||"",onChange:N=>d(a,N.target.value),placeholder:`Blank ${a+1}`,className:"mx-2 inline-block w-48",autoComplete:"off"})},t)}):e.jsx("span",{dangerouslySetInnerHTML:{__html:i}})})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"text-sm font-semibold",children:"Your Answers:"}),Array.from({length:o}).map((s,t)=>e.jsxs("div",{className:"flex items-center gap-3 rounded border p-2",children:[e.jsxs("span",{className:"text-sm font-semibold text-gray-600",children:["Blank ",t+1,":"]}),e.jsx(f,{type:"text",value:c[t]||"",onChange:a=>d(t,a.target.value),placeholder:"Your answer",className:"flex-1",autoComplete:"off"})]},t))]}),((h=n.options)==null?void 0:h.case_sensitive)&&e.jsxs("p",{className:"text-sm text-yellow-600",children:[e.jsx("span",{className:"font-semibold",children:"Note:"})," Answers are case-sensitive."]})]})};export{C as default};
|