var V=Object.defineProperty,z=Object.defineProperties;var J=Object.getOwnPropertyDescriptors;var u=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var f=(t,l,o)=>l in t?V(t,l,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[l]=o,b=(t,l)=>{for(var o in l||(l={}))j.call(l,o)&&f(t,o,l[o]);if(u)for(var o of u(l))A.call(l,o)&&f(t,o,l[o]);return t},w=(t,l)=>z(t,J(l));import{jsxs as i,jsx as a,Fragment as E}from"react/jsx-runtime";import{I as Q}from"./input-error-BbsDx4-P.js";import{L as B}from"./loading-button-B_LaGOAp.js";import{T as K}from"./tabs-DqFmhKFO.js";import{T as v}from"./tag-input-DBQ_pLC2.js";import{H as P,J as W,K as k,e as G,M as R,N as U,L as c,as as X,at as Y,au as Z,av as $,aw as q,I as ee,x as ae,y as T}from"./ui-components-B24mpb8o.js";import{usePage as re,useForm as te}from"@inertiajs/react";import{useState as le}from"react";import{Editor as oe}from"richtor";/* empty css                */import"lucide-react";import"@yaireo/tagify";import"next-themes";import"sonner";import"@radix-ui/react-label";import"class-variance-authority";import"@radix-ui/react-checkbox";import"@radix-ui/react-avatar";import"@radix-ui/react-dropdown-menu";import"@radix-ui/react-scroll-area";import"@radix-ui/react-popover";import"@radix-ui/react-radio-group";import"@radix-ui/react-dialog";import"@radix-ui/react-slot";import"clsx";import"@radix-ui/react-separator";import"@radix-ui/react-tooltip";import"@radix-ui/react-tabs";import"@radix-ui/react-accordion";import"@radix-ui/react-progress";import"@radix-ui/react-select";import"cmdk";import"@radix-ui/react-switch";import"react-day-picker";import"@radix-ui/react-slider";import"embla-carousel-react";import"@radix-ui/react-toggle-group";import"vaul";import"tailwind-merge";const ie=t=>[{value:"single",label:t.dashboard.single_choice,flag:!1},{value:"multiple",label:t.dashboard.multiple_choice,flag:!1},{value:"boolean",label:t.dashboard.true_false,flag:!1}],Ue=({title:t,handler:l,quiz:o,question:e})=>{const[y,m]=le(!1),{props:S}=re(),{translate:d}=S,{frontend:h,dashboard:g,input:n,button:_}=d,C=ie(d),N=o.quiz_questions.length>0?Math.max(...o.quiz_questions.map(r=>r.sort)):0,x=e!=null&&e.options?typeof e.options=="string"?JSON.parse(e.options):e.options:[],D=e!=null&&e.answer?typeof e.answer=="string"?JSON.parse(e.answer):e.answer:[],{data:s,setData:p,post:I,put:L,reset:O,processing:F,errors:H}=te({title:(e==null?void 0:e.title)||"",type:(e==null?void 0:e.type)||"single",options:x,answer:D,sort:(e==null?void 0:e.sort)||N+1,section_quiz_id:o.id});return i(P,{open:y,onOpenChange:m,children:[a(W,{children:l}),a(k,{className:"p-0",children:i(G,{className:"max-h-[90vh] p-6",children:[a(R,{className:"mb-6",children:a(U,{children:t})}),i("form",{onSubmit:r=>{r.preventDefault(),e?L(route("quiz.question.update",{id:e.id}),{onSuccess:()=>m(!1)}):I(route("quiz.question.store"),{onSuccess:()=>{O(),m(!1)}})},className:"relative space-y-4 p-0.5",children:[i("div",{children:[a(c,{children:g.question_type}),i(X,{value:s.type,onValueChange:r=>{p("type",r),r==="boolean"?p("answer",["True"]):p("answer",[])},children:[a(Y,{children:a(Z,{placeholder:n.question_type})}),a($,{children:C.map(r=>a(q,{value:r.value,children:r.label},r.value))})]})]}),i("div",{children:[a(c,{children:g.question_title}),a(oe,{ssr:!0,output:"html",placeholder:{paragraph:"Type your content here...",imageCaption:"Type caption for image (optional)"},contentMinHeight:256,contentMaxHeight:640,initialContent:s.title,onContentChange:r=>p(M=>w(b({},M),{title:r}))}),a(Q,{message:H.title})]}),s.type!=="boolean"&&i(E,{children:[i("div",{children:[a(c,{children:n.options}),a(v,{defaultTags:s.options,placeholder:n.question_options_placeholder,onChange:r=>p("options",r)})]}),s.type==="multiple"?i("div",{children:[a(c,{children:n.answer}),a(v,{defaultTags:s.answer,whitelist:s.options,enforceWhitelist:!0,placeholder:n.answer_options_placeholder,onChange:r=>p("answer",r)})]}):i("div",{children:[a(c,{children:n.answer}),a(ee,{type:"text",value:s.answer,placeholder:n.answer_placeholder,onChange:r=>p("answer",[r.target.value])})]})]}),s.type==="boolean"&&i("div",{children:[a(c,{children:n.answer}),a(K,{defaultValue:"True",value:s.answer[0],onValueChange:r=>p("answer",[r]),children:i(ae,{className:"w-full",children:[a(T,{value:"True",className:"w-full",children:h.true}),a(T,{value:"False",className:"w-full",children:h.false})]})})]}),a(B,{loading:F,className:"absolute right-0 -bottom-16",children:_.submit})]})]})})]})};export{Ue as default};
