(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7243,2930],{48626:function(e,t,s){Promise.resolve().then(s.t.bind(s,231,23)),Promise.resolve().then(s.bind(s,25440))},60291:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"RouterContext",{enumerable:!0,get:function(){return i}});let i=s(99920)._(s(2265)).default.createContext(null)},95826:function(e,t,s){"use strict";var i=s(57437);t.Z=e=>{let{label:t,type:s="text",register:l,name:r,defaultValue:a,error:n,hidden:o,inputProps:d}=e;return(0,i.jsxs)("div",{className:o?"hidden":"flex flex-col gap-2 w-full md:w-1/4",children:[(0,i.jsx)("label",{className:"text-xs text-medium-gray font-body",children:t}),(0,i.jsx)("input",{type:s,...l(r),className:"ring-[1.5px] ring-light-gray p-2 rounded-md text-sm w-full focus:ring-professional-green font-body",...d,defaultValue:a}),(null==n?void 0:n.message)&&(0,i.jsx)("p",{className:"text-xs text-red-400 font-body",children:n.message.toString()})]})}},25440:function(e,t,s){"use strict";var i=s(57437),l=s(31014),r=s(39343),a=s(95826),n=s(45238),o=s(16463),d=s(2265),c=s(95956);t.default=e=>{var t,s;let{type:x="create",data:u,redirectPath:m="/admin/school-life/events"}=e,{register:f,handleSubmit:g,formState:{errors:p}}=(0,r.cI)({resolver:(0,l.F)(n.L),defaultValues:u?{...u,date:u.date?new Date(u.date).toISOString().split("T")[0]:void 0}:void 0}),[h,v]=(0,d.useState)(!1),b=(0,o.useRouter)(),y=async e=>{v(!0);try{let t="create"===x?"/api/school-life/events":"/api/school-life/events/".concat(u.id);if(!(await fetch(t,{method:"create"===x?"POST":"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok)throw Error("Failed to save event");c.Am.success("Event ".concat("create"===x?"created":"updated"," successfully!")),b.push(m),b.refresh()}catch(e){console.error(e),c.Am.error("Something went wrong!")}finally{v(!1)}};return(0,i.jsxs)("form",{className:"flex flex-col gap-6 bg-white p-8 rounded-xl shadow-sm border border-gray-100 max-w-2xl mx-auto",onSubmit:g(y),children:[(0,i.jsx)("h1",{className:"text-xl font-semibold text-gray-800",children:"create"===x?"Create New Event":"Update Event"}),(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsx)(a.Z,{label:"Event Title",name:"title",register:f,error:p.title}),(0,i.jsxs)("div",{className:"flex flex-col gap-2 w-full md:w-1/4",children:[(0,i.jsx)("label",{className:"text-xs text-gray-500",children:"Description"}),(0,i.jsx)("textarea",{...f("description"),className:"ring-[1.5px] ring-gray-300 p-2 rounded-md text-sm w-full",rows:4}),(null===(t=p.description)||void 0===t?void 0:t.message)&&(0,i.jsx)("p",{className:"text-xs text-red-400",children:p.description.message})]}),(0,i.jsxs)("div",{className:"flex flex-col md:flex-row gap-4",children:[(0,i.jsx)(a.Z,{label:"Date",name:"date",type:"date",register:f,error:p.date}),(0,i.jsx)(a.Z,{label:"Time",name:"time",register:f,error:p.time})]}),(0,i.jsxs)("div",{className:"flex flex-col md:flex-row gap-4",children:[(0,i.jsx)(a.Z,{label:"Location",name:"location",register:f,error:p.location}),(0,i.jsxs)("div",{className:"flex flex-col gap-2 w-full md:w-1/4",children:[(0,i.jsx)("label",{className:"text-xs text-gray-500",children:"Visibility"}),(0,i.jsxs)("select",{...f("visibility"),className:"ring-[1.5px] ring-gray-300 p-2 rounded-md text-sm w-full",children:[(0,i.jsx)("option",{value:"PUBLIC",children:"Public"}),(0,i.jsx)("option",{value:"CLASS_ONLY",children:"Class Only"}),(0,i.jsx)("option",{value:"CLUB_ONLY",children:"Club Only"})]}),(null===(s=p.visibility)||void 0===s?void 0:s.message)&&(0,i.jsx)("p",{className:"text-xs text-red-400",children:p.visibility.message})]})]})]}),(0,i.jsx)("button",{disabled:h,className:"bg-vibrant-gold hover:bg-opacity-90 text-white p-3 rounded-md transition-all font-medium disabled:opacity-50",children:h?"Saving...":"create"===x?"Create Event":"Update Event"})]})}},45238:function(e,t,s){"use strict";s.d(t,{L:function(){return l},i:function(){return r}});var i=s(59772);let l=i.z.object({title:i.z.string().min(1,{message:"Title is required"}),description:i.z.string().optional(),date:i.z.coerce.date({message:"Date is required"}),time:i.z.string().optional(),location:i.z.string().optional(),visibility:i.z.enum(["PUBLIC","CLASS_ONLY","CLUB_ONLY"],{message:"Visibility is required"})}),r=i.z.object({name:i.z.string().min(1,{message:"Club Name is required"}),description:i.z.string().optional()})}},function(e){e.O(0,[5945,231,9772,1014,2971,7023,1744],function(){return e(e.s=48626)}),_N_E=e.O()}]);