import{r as n,aT as y,aU as w,j as e,aX as _,a$ as D,d8 as T}from"./react-vendor-xYZnmIII.js";import{D as C}from"./data-sort-modal-CwRlZIXA.js";import{D as S}from"./delete-modal-h3jQBOO6.js";import{J as O,K as Q,M,e as P,N as z,O as E,B as l,a as F,Q as J,U as k,y as A,z as B,c as H}from"./ui-components-CQM92IK3.js";import{P as L}from"./richtor-BECSBxkh.js";import d from"./question-form-AivXFWFF.js";import"./inertia-vendor-cBbDTmhJ.js";import"./ui-vendor-Ds9iwIxa.js";import"./interactive-vendor-B1OgcAgP.js";import"./input-error-_LAmvivg.js";import"./loading-button-D7aXR3K4.js";import"./tabs-eeNoRD9t.js";import"./tag-input-DsZaHbN4.js";const U=i=>[{value:"single",label:i.dashboard.single_choice,flag:!1},{value:"multiple",label:i.dashboard.multiple_choice,flag:!1},{value:"boolean",label:i.dashboard.true_false,flag:!1}],ce=({title:i,handler:p,quiz:t,question:s})=>{const[o,m]=n.useState(!1),[x,h]=n.useState(s?"add-question":"questions"),{props:j}=y(),{translate:c}=j,{input:I,button:r,dashboard:f,frontend:g}=c;U(c);const u=t.quiz_questions.length>0?Math.max(...t.quiz_questions.map(a=>a.sort)):0,v=s!=null&&s.options?typeof s.options=="string"?JSON.parse(s.options):s.options:[],N=s!=null&&s.answer?typeof s.answer=="string"?JSON.parse(s.answer):s.answer:[],{data:K,setData:R,post:W,put:X,reset:b,processing:$,errors:G}=w({title:(s==null?void 0:s.title)||"",type:(s==null?void 0:s.type)||"single",options:v,answer:N,sort:(s==null?void 0:s.sort)||u+1,section_quiz_id:t.id});return n.useEffect(()=>{o||(b(),h(s?"add-question":"questions"))},[o]),e.jsxs(O,{open:o,onOpenChange:m,children:[e.jsx(Q,{children:p}),e.jsx(M,{className:"p-0",children:e.jsxs(P,{className:"max-h-[90vh] p-6",children:[e.jsx(z,{className:"mb-6",children:e.jsx(E,{children:i})}),e.jsxs("div",{className:"space-y-7",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(d,{quiz:t,title:r.add_question,question:s,handler:e.jsx(l,{variant:"secondary",className:"h-8 text-xs",children:r.add_question})}),e.jsx(C,{title:r.sort,data:t.quiz_questions,handler:e.jsx(l,{variant:"secondary",className:"h-8 text-xs",children:r.sort}),onOrderChange:a=>{_.post(route("quiz.question.sort"),{sortedData:a},{preserveScroll:!0})},renderContent:a=>e.jsx(F,{className:"w-full px-4 py-3",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:a.title}})})})]}),e.jsx("div",{className:"space-y-2",children:t.quiz_questions.length>0?t.quiz_questions.map(a=>e.jsxs("div",{className:"group border-border flex w-full items-center justify-between rounded-md border px-4 py-3",children:[e.jsx(L,{value:a.title}),e.jsxs("div",{className:"invisible flex items-center gap-2 group-hover:visible",children:[e.jsx(S,{routePath:route("quiz.question.delete",{id:a.id}),actionComponent:e.jsx(l,{size:"icon",variant:"secondary",className:"text-destructive h-7 w-7",children:e.jsx(D,{className:"h-3 w-3"})})}),e.jsx(d,{quiz:t,title:f.edit_question,question:a,handler:e.jsx(l,{size:"icon",variant:"secondary",className:"h-7 w-7",children:e.jsx(T,{className:"h-3 w-3"})})})]})]},a.id)):e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground text-sm",children:g.no_results})})})]}),e.jsx(J,{className:"w-full justify-between space-x-2 pt-8",children:e.jsxs("div",{className:"flex w-full items-center gap-4",children:[e.jsx(k,{asChild:!0,children:e.jsx(l,{type:"button",variant:"outline",children:r.close})}),e.jsx(A,{className:"p-0",children:e.jsx(B,{asChild:!0,value:"questions",className:H(x==="questions"?"hidden":"block"),children:e.jsx(l,{children:r.back})})})]})})]})})]})};export{ce as default};
