import{r as L,u as R,b as V,j as e}from"./vendor-BKmmeuxg.js";import{C as x}from"./combobox-Byd5-E0j.js";import{I as m}from"./input-error-LaPr_4wd.js";import{L as I}from"./loading-button-BnTVAMJ7.js";import{D as F,a as G,b as O,c as T,d as U}from"./dialog-B2gN9MvT.js";import{L as r}from"./label-HmIcv5Yx.js";import{R as z,a as A}from"./radio-group-C0C2vfl-.js";import{S as B}from"./scroll-area-C8HGru-R.js";import"./button-BpNwv2aE.js";import"./index-WW_1X1qx.js";import"./utils-DxSsnXxD.js";import"./popover-B4kBsMuI.js";const Z=({type:a,title:u,handler:p})=>{const[h,l]=L.useState(!1),{users:j,exams:f,courses:g,prices:_,translate:b}=R().props,{input:i,button:S}=b,{data:t,setData:o,post:c,reset:d,errors:n,processing:v}=V({user_id:"",exam_id:"",course_id:"",enrollment_type:"free"}),C=s=>{s.preventDefault(),a==="exam"?c(route("exam-enrollments.store"),{onSuccess:()=>{d(),l(!1)}}):c(route("enrollments.store"),{onSuccess:()=>{d(),l(!1)}})},N=j.map(s=>({label:s.name,value:s.id})),D=a==="exam"?f.map(s=>({label:s.title,value:s.id})):[],E=a==="course"?g.map(s=>({label:s.title,value:s.id})):[];return e.jsxs(F,{open:h,onOpenChange:l,children:[e.jsx(G,{asChild:!0,children:p}),e.jsx(O,{className:"p-0",children:e.jsxs(B,{className:"max-h-[90vh] p-6",children:[e.jsx(T,{className:"mb-6",children:e.jsx(U,{children:u})}),e.jsxs("form",{onSubmit:C,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx(r,{children:"Select User"}),e.jsx(x,{data:N,defaultValue:t.user_id,placeholder:i.select,onSelect:s=>o("user_id",s.value)}),e.jsx(m,{message:n.user_id})]}),e.jsxs("div",{children:[e.jsx(r,{children:a==="exam"?"Select Exam":"Select Course"}),e.jsx(x,{data:a==="exam"?D:E,defaultValue:t.course_id,placeholder:a==="exam"?"Select Exam":"Select Course",onSelect:s=>o(a==="exam"?"exam_id":"course_id",s.value)}),e.jsx(m,{message:n[a==="exam"?"exam_id":"course_id"]})]}),e.jsxs("div",{children:[e.jsx(r,{children:i.enrollment_type}),e.jsx(z,{defaultValue:t.enrollment_type,className:"flex items-center space-x-4 pt-2 pb-1",onValueChange:s=>o("enrollment_type",s),children:_.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(A,{className:"cursor-pointer",id:s,value:s}),e.jsx(r,{htmlFor:s,className:"capitalize",children:s})]},s))}),e.jsx(m,{message:n.enrollment_type})]}),e.jsx("div",{className:"col-span-2 mt-6 text-right",children:e.jsx(I,{loading:v,children:S.submit})})]})]})})]})};export{Z as default};
