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

2 lines
3.5 KiB
JavaScript

import{r as L,u as O,b as F,j as e}from"./vendor-BKmmeuxg.js";import{I as V}from"./input-error-LaPr_4wd.js";import{L as z}from"./loading-button-BnTVAMJ7.js";import{T as E}from"./tabs-D0Mbb5M5.js";import{T as m}from"./tag-input-BqUWHOBp.js";import{D as H,a as M,b as k,c as A,d as J}from"./dialog-B2gN9MvT.js";import{I as Q}from"./input-DM0goJrn.js";import{L as o}from"./label-HmIcv5Yx.js";import{S as B}from"./scroll-area-C8HGru-R.js";import{S as P,a as R,b as W,c as G,d as K}from"./select-CD9o3HN1.js";import{T as U,a as g}from"./tabs-Ifouhv9A.js";import{k as X}from"./richtor-CRcM6Du2.js";import"./utils-DxSsnXxD.js";import"./button-BpNwv2aE.js";import"./index-WW_1X1qx.js";const Y=n=>[{value:"single",label:n.dashboard.single_choice,flag:!1},{value:"multiple",label:n.dashboard.multiple_choice,flag:!1},{value:"boolean",label:n.dashboard.true_false,flag:!1}],he=({title:n,handler:x,quiz:i,question:a})=>{const[u,c]=L.useState(!1),{props:f}=O(),{translate:p}=f,{frontend:d,dashboard:h,input:r,button:j}=p,b=Y(p),w=i.quiz_questions.length>0?Math.max(...i.quiz_questions.map(s=>s.sort)):0,v=a!=null&&a.options?typeof a.options=="string"?JSON.parse(a.options):a.options:[],T=a!=null&&a.answer?typeof a.answer=="string"?JSON.parse(a.answer):a.answer:[],{data:l,setData:t,post:y,put:S,reset:_,processing:C,errors:N}=F({title:(a==null?void 0:a.title)||"",type:(a==null?void 0:a.type)||"single",options:v,answer:T,sort:(a==null?void 0:a.sort)||w+1,section_quiz_id:i.id}),D=s=>{s.preventDefault(),a?S(route("quiz.question.update",{id:a.id}),{onSuccess:()=>c(!1)}):y(route("quiz.question.store"),{onSuccess:()=>{_(),c(!1)}})};return e.jsxs(H,{open:u,onOpenChange:c,children:[e.jsx(M,{children:x}),e.jsx(k,{className:"p-0",children:e.jsxs(B,{className:"max-h-[90vh] p-6",children:[e.jsx(A,{className:"mb-6",children:e.jsx(J,{children:n})}),e.jsxs("form",{onSubmit:D,className:"relative space-y-4 p-0.5",children:[e.jsxs("div",{children:[e.jsx(o,{children:h.question_type}),e.jsxs(P,{value:l.type,onValueChange:s=>{t("type",s),s==="boolean"?t("answer",["True"]):t("answer",[])},children:[e.jsx(R,{children:e.jsx(W,{placeholder:r.question_type})}),e.jsx(G,{children:b.map(s=>e.jsx(K,{value:s.value,children:s.label},s.value))})]})]}),e.jsxs("div",{children:[e.jsx(o,{children:h.question_title}),e.jsx(X,{ssr:!0,output:"html",placeholder:{paragraph:"Type your content here...",imageCaption:"Type caption for image (optional)"},contentMinHeight:256,contentMaxHeight:640,initialContent:l.title,onContentChange:s=>t(I=>({...I,title:s}))}),e.jsx(V,{message:N.title})]}),l.type!=="boolean"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(o,{children:r.options}),e.jsx(m,{defaultTags:l.options,placeholder:r.question_options_placeholder,onChange:s=>t("options",s)})]}),l.type==="multiple"?e.jsxs("div",{children:[e.jsx(o,{children:r.answer}),e.jsx(m,{defaultTags:l.answer,whitelist:l.options,enforceWhitelist:!0,placeholder:r.answer_options_placeholder,onChange:s=>t("answer",s)})]}):e.jsxs("div",{children:[e.jsx(o,{children:r.answer}),e.jsx(Q,{type:"text",value:l.answer,placeholder:r.answer_placeholder,onChange:s=>t("answer",[s.target.value])})]})]}),l.type==="boolean"&&e.jsxs("div",{children:[e.jsx(o,{children:r.answer}),e.jsx(E,{defaultValue:"True",value:l.answer[0],onValueChange:s=>t("answer",[s]),children:e.jsxs(U,{className:"w-full",children:[e.jsx(g,{value:"True",className:"w-full",children:d.true}),e.jsx(g,{value:"False",className:"w-full",children:d.false})]})})]}),e.jsx(z,{loading:C,className:"absolute right-0 -bottom-16",children:j.submit})]})]})})]})};export{he as default};