var H=Object.defineProperty,M=Object.defineProperties;var V=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var E=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var g=(l,r,t)=>r in l?H(l,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[r]=t,u=(l,r)=>{for(var t in r||(r={}))E.call(r,t)&&g(l,t,r[t]);if(x)for(var t of x(r))J.call(r,t)&&g(l,t,r[t]);return l},j=(l,r)=>M(l,V(r));import{r as A,aT as Q,aU as B,j as e}from"./react-vendor-xYZnmIII.js";import{I as K}from"./input-error-_LAmvivg.js";import{L as P}from"./loading-button-D7aXR3K4.js";import{T as R}from"./tabs-eeNoRD9t.js";import{T as f}from"./tag-input-DsZaHbN4.js";import{J as U,K as W,M as k,e as G,N as X,O as Y,L as c,at as Z,au as $,av as q,aw as ee,ax as ae,I as se,y as le,z as w}from"./ui-components-CQM92IK3.js";import{j as re}from"./richtor-BECSBxkh.js";import"./inertia-vendor-cBbDTmhJ.js";import"./ui-vendor-Ds9iwIxa.js";import"./interactive-vendor-B1OgcAgP.js";const te=l=>[{value:"single",label:l.dashboard.single_choice,flag:!1},{value:"multiple",label:l.dashboard.multiple_choice,flag:!1},{value:"boolean",label:l.dashboard.true_false,flag:!1}],je=({title:l,handler:r,quiz:t,question:a})=>{const[b,p]=A.useState(!1),{props:v}=Q(),{translate:d}=v,{frontend:h,dashboard:m,input:o,button:T}=d,y=te(d),_=t.quiz_questions.length>0?Math.max(...t.quiz_questions.map(s=>s.sort)):0,S=a!=null&&a.options?typeof a.options=="string"?JSON.parse(a.options):a.options:[],C=a!=null&&a.answer?typeof a.answer=="string"?JSON.parse(a.answer):a.answer:[],{data:n,setData:i,post:N,put:D,reset:I,processing:O,errors:L}=B({title:(a==null?void 0:a.title)||"",type:(a==null?void 0:a.type)||"single",options:S,answer:C,sort:(a==null?void 0:a.sort)||_+1,section_quiz_id:t.id}),z=s=>{s.preventDefault(),a?D(route("quiz.question.update",{id:a.id}),{onSuccess:()=>p(!1)}):N(route("quiz.question.store"),{onSuccess:()=>{I(),p(!1)}})};return e.jsxs(U,{open:b,onOpenChange:p,children:[e.jsx(W,{children:r}),e.jsx(k,{className:"p-0",children:e.jsxs(G,{className:"max-h-[90vh] p-6",children:[e.jsx(X,{className:"mb-6",children:e.jsx(Y,{children:l})}),e.jsxs("form",{onSubmit:z,className:"relative space-y-4 p-0.5",children:[e.jsxs("div",{children:[e.jsx(c,{children:m.question_type}),e.jsxs(Z,{value:n.type,onValueChange:s=>{i("type",s),s==="boolean"?i("answer",["True"]):i("answer",[])},children:[e.jsx($,{children:e.jsx(q,{placeholder:o.question_type})}),e.jsx(ee,{children:y.map(s=>e.jsx(ae,{value:s.value,children:s.label},s.value))})]})]}),e.jsxs("div",{children:[e.jsx(c,{children:m.question_title}),e.jsx(re,{ssr:!0,output:"html",placeholder:{paragraph:"Type your content here...",imageCaption:"Type caption for image (optional)"},contentMinHeight:256,contentMaxHeight:640,initialContent:n.title,onContentChange:s=>i(F=>j(u({},F),{title:s}))}),e.jsx(K,{message:L.title})]}),n.type!=="boolean"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(c,{children:o.options}),e.jsx(f,{defaultTags:n.options,placeholder:o.question_options_placeholder,onChange:s=>i("options",s)})]}),n.type==="multiple"?e.jsxs("div",{children:[e.jsx(c,{children:o.answer}),e.jsx(f,{defaultTags:n.answer,whitelist:n.options,enforceWhitelist:!0,placeholder:o.answer_options_placeholder,onChange:s=>i("answer",s)})]}):e.jsxs("div",{children:[e.jsx(c,{children:o.answer}),e.jsx(se,{type:"text",value:n.answer,placeholder:o.answer_placeholder,onChange:s=>i("answer",[s.target.value])})]})]}),n.type==="boolean"&&e.jsxs("div",{children:[e.jsx(c,{children:o.answer}),e.jsx(R,{defaultValue:"True",value:n.answer[0],onValueChange:s=>i("answer",[s]),children:e.jsxs(le,{className:"w-full",children:[e.jsx(w,{value:"True",className:"w-full",children:h.true}),e.jsx(w,{value:"False",className:"w-full",children:h.false})]})})]}),e.jsx(P,{loading:O,className:"absolute right-0 -bottom-16",children:T.submit})]})]})})]})};export{je as default};
