import{r as n,u as y,b as w,j as e,e as _,T as D,c1 as T}from"./vendor-BKmmeuxg.js";import{D as C}from"./data-sort-modal-B2Yf_crJ.js";import{D as S}from"./delete-modal-D1GJlb1P.js";import{B as l}from"./button-BpNwv2aE.js";import{C as O}from"./card-D9_SJYq6.js";import{D as Q,a as M,b as z,c as E,d as F,e as P,f as k}from"./dialog-B2gN9MvT.js";import{S as A}from"./scroll-area-C8HGru-R.js";import{T as B,a as H}from"./tabs-Ifouhv9A.js";import{c as J}from"./utils-DxSsnXxD.js";import{e as L}from"./richtor-CRcM6Du2.js";import d from"./question-form-BYtkaE3L.js";import"./index-WW_1X1qx.js";import"./input-error-LaPr_4wd.js";import"./loading-button-BnTVAMJ7.js";import"./tabs-D0Mbb5M5.js";import"./tag-input-BqUWHOBp.js";import"./input-DM0goJrn.js";import"./label-HmIcv5Yx.js";import"./select-CD9o3HN1.js";const I=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}],fe=({title:i,handler:m,quiz:r,question:s})=>{const[o,p]=n.useState(!1),[x,h]=n.useState(s?"add-question":"questions"),{props:f}=y(),{translate:c}=f,{input:R,button:t,dashboard:j,frontend:g}=c;I(c);const u=r.quiz_questions.length>0?Math.max(...r.quiz_questions.map(a=>a.sort)):0,b=s!=null&&s.options?typeof s.options=="string"?JSON.parse(s.options):s.options:[],v=s!=null&&s.answer?typeof s.answer=="string"?JSON.parse(s.answer):s.answer:[],{data:G,setData:K,post:U,put:V,reset:N,processing:W,errors:X}=w({title:(s==null?void 0:s.title)||"",type:(s==null?void 0:s.type)||"single",options:b,answer:v,sort:(s==null?void 0:s.sort)||u+1,section_quiz_id:r.id});return n.useEffect(()=>{o||(N(),h(s?"add-question":"questions"))},[o]),e.jsxs(Q,{open:o,onOpenChange:p,children:[e.jsx(M,{children:m}),e.jsx(z,{className:"p-0",children:e.jsxs(A,{className:"max-h-[90vh] p-6",children:[e.jsx(E,{className:"mb-6",children:e.jsx(F,{children:i})}),e.jsxs("div",{className:"space-y-7",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(d,{quiz:r,title:t.add_question,question:s,handler:e.jsx(l,{variant:"secondary",className:"h-8 text-xs",children:t.add_question})}),e.jsx(C,{title:t.sort,data:r.quiz_questions,handler:e.jsx(l,{variant:"secondary",className:"h-8 text-xs",children:t.sort}),onOrderChange:a=>{_.post(route("quiz.question.sort"),{sortedData:a},{preserveScroll:!0})},renderContent:a=>e.jsx(O,{className:"w-full px-4 py-3",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:a.title}})})})]}),e.jsx("div",{className:"space-y-2",children:r.quiz_questions.length>0?r.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:r,title:j.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(P,{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:t.close})}),e.jsx(B,{className:"p-0",children:e.jsx(H,{asChild:!0,value:"questions",className:J(x==="questions"?"hidden":"block"),children:e.jsx(l,{children:t.back})})})]})})]})})]})};export{fe as default};