lms/public/build/assets/multiple-choice-form-Dm-x1oeK.js
2025-12-15 12:26:23 +01:00

2 lines
2.5 KiB
JavaScript

import{r as u,j as t,bm as N,T as v}from"./vendor-BKmmeuxg.js";import{I as x}from"./input-error-LaPr_4wd.js";import{B as h}from"./button-BpNwv2aE.js";import{C as w}from"./checkbox-BBZKtHnN.js";import{I as C}from"./input-DM0goJrn.js";import{L as O}from"./label-HmIcv5Yx.js";import{R as b,a as q}from"./radio-group-C0C2vfl-.js";import"./utils-DxSsnXxD.js";import"./index-WW_1X1qx.js";const L=({data:_,setData:i,errors:c,isMultipleSelect:a})=>{const r=_.question_options||[],d=()=>{const s=[...r,{option_text:"",is_correct:!1,sort:r.length}];i("question_options",s)},f=s=>{const o=r.filter((e,n)=>n!==s);i("question_options",o)},j=(s,o,e)=>{const n=[...r];n[s]={...n[s],[o]:e},i("question_options",n)},l=(s,o)=>{const e=[...r];a?e[s].is_correct=o:e.forEach((n,m)=>{e[m].is_correct=m===s?o:!1}),i("question_options",e)},[p,g]=u.useState(!1);return u.useEffect(()=>{!p&&r.length===0&&(i("question_options",[{option_text:"",is_correct:!1,sort:0},{option_text:"",is_correct:!1,sort:1},{option_text:"",is_correct:!1,sort:2},{option_text:"",is_correct:!1,sort:3}]),g(!0))},[p,r.length]),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(O,{children:"Answer Options *"}),t.jsxs(h,{type:"button",variant:"outline",size:"sm",onClick:d,children:[t.jsx(N,{className:"h-4 w-4"}),"Add Option"]})]}),t.jsx("p",{className:"text-sm text-gray-600",children:a?"Check all correct answers (students can select multiple options)":"Select the correct answer (students can select only one)"}),t.jsx("div",{className:"space-y-3",children:r.map((s,o)=>t.jsxs("div",{className:"flex items-start gap-3",children:[a?t.jsx(w,{checked:s.is_correct,onCheckedChange:e=>l(o,e===!0),className:"mt-3"}):t.jsx(b,{value:r.findIndex(e=>e.is_correct).toString(),onValueChange:e=>l(parseInt(e),!0),children:t.jsx(q,{value:o.toString(),className:"mt-3"})}),t.jsxs("div",{className:"flex-1",children:[t.jsx(C,{placeholder:`Option ${o+1}`,value:s.option_text,onChange:e=>j(o,"option_text",e.target.value),className:s.is_correct?"border-green-500 bg-green-50":""}),t.jsx(x,{message:c[`question_options.${o}.option_text`]})]}),r.length>2&&t.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>f(o),className:"mt-2 text-red-600",children:t.jsx(v,{className:"h-4 w-4"})})]},o))}),r.length>0&&!r.some(s=>s.is_correct)&&t.jsx("p",{className:"text-sm text-amber-600",children:"⚠️ Please mark at least one option as correct"}),t.jsx(x,{message:c.question_options})]})};export{L as default};