lms/public/build/assets/question-dialog-DeJfEfRF.js
2025-12-15 12:26:23 +01:00

2 lines
4.5 KiB
JavaScript

import{r as a,b as I,j as e}from"./vendor-BKmmeuxg.js";import{I as p}from"./input-error-LaPr_4wd.js";import{L as Q}from"./loading-button-BnTVAMJ7.js";import{B as w}from"./button-BpNwv2aE.js";import{D as T,a as L,b as N,c as B,d as O}from"./dialog-B2gN9MvT.js";import{I as b}from"./input-DM0goJrn.js";import{L as u}from"./label-HmIcv5Yx.js";import{S as A,a as H,b as U,c as V,d as R}from"./select-CD9o3HN1.js";import{o as z}from"./inertia-SZXqLvQm.js";import{k as G}from"./richtor-CRcM6Du2.js";import J from"./fill-blank-form-D0Ep5llL.js";import K from"./listening-form-JPfVJits.js";import P from"./matching-form-DGgyfKHG.js";import W from"./multiple-choice-form-Dm-x1oeK.js";import X from"./ordering-form-DjRuOH93.js";import Y from"./short-answer-form-Ct6uyXHG.js";import"./utils-DxSsnXxD.js";import"./index-WW_1X1qx.js";import"./chunked-uploader-input-D0XPVOTS.js";import"./index-D9-QKOod.js";import"./radio-group-C0C2vfl-.js";import"./textarea-CyndvowL.js";import"./checkbox-BBZKtHnN.js";const Z=[{value:"multiple_choice",label:"Multiple Choice"},{value:"multiple_select",label:"Multiple Select"},{value:"matching",label:"Matching"},{value:"fill_blank",label:"Fill in the Blank"},{value:"ordering",label:"Ordering"},{value:"short_answer",label:"Short Answer"},{value:"listening",label:"Listening"}],ve=({exam:v,question:t,handler:S})=>{const[h,c]=a.useState(!1),[l,i]=a.useState(!1),[C,g]=a.useState(!1),[x,m]=a.useState(!1),F={exam_id:v.id,title:(t==null?void 0:t.title)||"",description:(t==null?void 0:t.description)||"",marks:(t==null?void 0:t.marks)||1,options:(t==null?void 0:t.options)||{},question_options:((t==null?void 0:t.question_options)||[]).map(r=>({id:r.id?Number(r.id):void 0,option_text:r.option_text,is_correct:r.is_correct,sort:r.sort})),question_type:(t==null?void 0:t.question_type)||"multiple_choice",exam_question_id:t!=null&&t.id?Number(t.id):null},{data:s,setData:o,post:k,put:y,errors:n,processing:f,reset:j,clearErrors:D}=I(F),E=r=>{var d;if(r.preventDefault(),s.question_type==="listening"&&((d=s.options)==null?void 0:d.audio_source)==="upload"&&(!t||C)&&!x){i(!0);return}_()},_=()=>{D(),t?y(route("exam-questions.update",t.id),{preserveScroll:!0,onSuccess:()=>{c(!1),j(),i(!1),m(!1)}}):k(route("exam-questions.store"),{preserveScroll:!0,onSuccess:()=>{c(!1),j(),i(!1),m(!1)}})};a.useEffect(()=>{x&&l&&_()},[x,l]),a.useEffect(()=>{h||(i(!1),g(!1),m(!1))},[h]);const M=()=>{const r={data:s,setData:o,errors:n};switch(s.question_type){case"multiple_choice":case"multiple_select":return e.jsx(W,{...r,isMultipleSelect:s.question_type==="multiple_select"});case"matching":return e.jsx(P,{...r});case"fill_blank":return e.jsx(J,{...r});case"ordering":return e.jsx(X,{...r});case"short_answer":return e.jsx(Y,{...r});case"listening":return e.jsx(K,{...r,isSubmit:l,setIsSubmit:i,setIsFileSelected:g,setIsFileUploaded:m});default:return null}};return e.jsxs(T,{open:h,onOpenChange:c,children:[e.jsx(L,{children:S}),e.jsxs(N,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(B,{children:e.jsx(O,{children:t?"Edit Question":"Create Question"})}),e.jsxs("form",{onSubmit:E,className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Question Type *"}),e.jsxs(A,{value:s.question_type,onValueChange:r=>o("question_type",r),disabled:!!t,children:[e.jsx(H,{children:e.jsx(U,{placeholder:"Select question type"})}),e.jsx(V,{children:Z.map(r=>e.jsx(R,{value:r.value,children:r.label},r.value))})]}),e.jsx(p,{message:n.question_type})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Marks *"}),e.jsx(b,{type:"number",step:"0.5",min:"0.5",name:"marks",value:s.marks.toString(),onChange:r=>o("marks",parseFloat(r.target.value)||0),placeholder:"Enter marks"}),e.jsx(p,{message:n.marks})]})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Question Title *"}),e.jsx(b,{name:"title",value:s.title,onChange:r=>z(r,o),placeholder:"Enter question title"}),e.jsx(p,{message:n.title})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Description (Optional)"}),e.jsx(G,{ssr:!0,output:"html",placeholder:{paragraph:"Add additional context or instructions...",imageCaption:"Add additional context or instructions..."},contentMinHeight:150,contentMaxHeight:300,initialContent:s.description,onContentChange:r=>o(d=>({...d,description:r}))}),e.jsx(p,{message:n.description})]}),M(),e.jsxs("div",{className:"flex justify-end gap-3 border-t pt-4",children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>c(!1),disabled:f||l,children:"Cancel"}),e.jsx(Q,{loading:f||l,disabled:f||l,children:t?"Update Question":"Create Question"})]})]})]})]})};export{ve as default};