1import{j as e,Z as z,C as Q,f as V,G as X,d as $,e as J,A as W,B as C,m as q,r as v,w as Y,a0 as I,x as U,y as ee,z as te,L as w,I as H,c as se,o as re,a as ie,p as ae,k as N,V as S,X as le}from"./index-IxvR3ybE.js";import{I as O}from"./info-zb8jj5B_.js";import{T as B}from"./triangle-alert-D0eYfDp9.js";import{T as oe,a as ne,b as ce,c as de}from"./tooltip-Dr0ZINUZ.js";import{A as me,a as ue,b as he,c as xe,d as ge,e as pe,f as fe,g as je,h as ye}from"./alert-dialog-LkDSbIL4.js";import{S as ve}from"./square-pen-DP9ydQSt.js";import{T as be}from"./trash-2-DklbPQfi.js";import{f as we}from"./format-DUXQdFez.js";import{T as Ne}from"./textarea-DABzMORD.js";import{S as k,a as F,b as L,c as M,d as j}from"./select-C66k4zpo.js";import{u as Ce}from"./index.esm-YY-db2T-.js";import{u as Ee}from"./useFormPersistence-BBjXdKHe.js";import{t as Se,o as Re,e as Te,s as R}from"./zod-DQT37IJW.js";import{P as T}from"./plus-ByP2IBiw.js";import{E as De}from"./EventSelector-Bpv922Gw.js";import{P as Ae}from"./PaymentGuard-CsV7Fhnv.js";import"./index-PCA-xeVB.js";import"./en-US-CujKlCMr.js";import"./startOfWeek-CKe6unVT.js";import"./index-BdQq_4o_.js";import"./chevron-up-Kie37_ZB.js";import"./usePaystackConfig-BiPyfAu1.js";import"./usePayment-DbOsPFvK.js";import"./loader-IuTMkbZP.js";import"./credit-card-CqkMcI0L.js";import"./circle-check-big-DrZso9hg.js";import"./useReferralCode-DoUD49Ha.js";import"./AccessCodeInput-MBolaJC1.js";import"./lock-open-BznoiT3l.js";import"./key-p_SgkhAy.js";const Pe=[{key:"total",icon:O,bg:"from-blue-400 to-indigo-400",label:"Total Rules"},{key:"highPriority",icon:B,bg:"from-red-300 to-orange-400",label:"High Priority"},{key:"categories",icon:z,bg:"from-green-300 to-emerald-400",label:"Categories"}],qe=({total:s,highPriority:o,categories:d,loading:t})=>{const i={total:s,highPriority:o,categories:d};return e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-5",children:Pe.map(n=>e.jsxs(Q,{className:X("glass-card flex items-center p-4 min-h-[84px] relative",t&&"animate-pulse"),children:[e.jsx("div",{className:`bg-gradient-to-br ${n.bg} rounded-full p-3 mr-4 flex items-center justify-center`,children:e.jsx(n.icon,{className:"text-white w-5 h-5"})}),e.jsxs(V,{className:"p-0 flex flex-col",children:[e.jsx("span",{className:"text-2xl font-bold",children:t?"â":i[n.key]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1 font-medium",children:n.label})]})]},n.key))})},ke=({rule:s,isDeleting:o,onEdit:d,onDelete:t})=>e.jsxs(Q,{className:"glass-card overflow-hidden hover:shadow-xl transition-all",children:[e.jsxs($,{className:"pb-2 flex flex-row items-start justify-between",children:[e.jsxs("div",{children:[e.jsx(J,{className:"text-lg font-semibold",children:s.title}),e.jsxs(W,{className:"text-xs mt-1",children:["Created: ",we(new Date(s.created_at),"MMM d, yyyy")]})]}),e.jsxs("div",{className:"flex space-x-1",children:[e.jsx(oe,{children:e.jsxs(ne,{children:[e.jsx(ce,{asChild:!0,children:e.jsxs(C,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0",onClick:()=>d(s),children:[e.jsx(ve,{size:16}),e.jsx("span",{className:"sr-only",children:"Edit"})]})}),e.jsx(de,{children:"Edit Rule"})]})}),e.jsxs(me,{children:[e.jsx(ue,{asChild:!0,children:e.jsxs(C,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",disabled:o,children:[e.jsx(be,{size:16}),e.jsx("span",{className:"sr-only",children:"Delete"})]})}),e.jsxs(he,{children:[e.jsxs(xe,{children:[e.jsx(ge,{children:"Delete Rule"}),e.jsx(pe,{children:"Are you sure you want to delete this rule? This action cannot be undone."})]}),e.jsxs(fe,{children:[e.jsx(je,{children:"Cancel"}),e.jsx(ye,{onClick:()=>t(s),children:"Delete"})]})]})]})]})]}),e.jsxs(V,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[s.category&&e.jsx(q,{variant:"outline",className:"text-xs capitalize",children:s.category}),s.priority&&e.jsx(q,{className:s.priority==="high"?"bg-red-100 text-red-800 hover:bg-red-200":s.priority==="medium"?"bg-yellow-100 text-yellow-800 hover:bg-yellow-200":"bg-blue-100 text-blue-800 hover:bg-blue-200",children:e.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[s.priority==="high"&&e.jsx(B,{className:"h-3 w-3"}),s.priority==="medium"&&e.jsx(z,{className:"h-3 w-3"}),s.priority==="low"&&e.jsx(O,{className:"h-3 w-3"}),e.jsx("span",{className:"capitalize",children:s.priority})]})})]}),s.content&&e.jsx("div",{className:"mt-3 text-sm text-muted-foreground",children:s.content})]})]}),Fe=Re({title:R().min(2,{message:"Title must be at least 2 characters."}),content:R().min(10,{message:"Content must be at least 10 characters."}),category:R().optional(),priority:Te(["high","medium","low"]).default("medium")}),_=({open:s,setOpen:o,onSubmit:d,isSubmitting:t,editingRule:i})=>{var y,b;const n=Ce({resolver:Se(Fe),defaultValues:i||{title:"",content:"",category:"",priority:"medium"}}),{register:u,handleSubmit:m,setValue:l,reset:x,watch:g,formState:{errors:r}}=n,{clearSavedData:c}=Ee("rule-form",n,!i);v.useEffect(()=>{i?(l("title",i.title||""),l("content",i.content||""),l("category",i.category||""),l("priority",i.priority||"medium")):x({title:"",content:"",category:"",priority:"medium"})},[i,l,x]);const h=g("category"),p=g("priority"),E=f=>{d(f),x(),c(),o(!1)};return e.jsxs(Y,{open:s,onOpenChange:o,children:[e.jsx(I,{asChild:!0,children:e.jsxs(C,{children:[e.jsx(T,{size:16,className:"mr-1"}),i?"Edit Rule":"Create Rule"]})}),e.jsxs(U,{children:[e.jsx(ee,{children:e.jsx(te,{children:i?"Edit Rule":"Add Rule"})}
1),e.jsxs("form",{onSubmit:m(E),className:"space-y-4 mt-3",children:[e.jsxs("div",{children:[e.jsx(w,{htmlFor:"title",children:"Rule Title *"}),e.jsx(H,{id:"title",...u("title"),placeholder:"Enter rule title"}),((y=r.title)==null?void 0:y.message)&&e.jsx("p",{className:"text-sm text-destructive",children:r.title.message})]}),e.jsxs("div",{children:[e.jsx(w,{htmlFor:"content",children:"Rule Content *"}),e.jsx(Ne,{id:"content",...u("content"),placeholder:"Enter detailed rule description",rows:3}),((b=r.content)==null?void 0:b.message)&&e.jsx("p",{className:"text-sm text-destructive",children:r.content.message})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(w,{children:"Category"}),e.jsxs(k,{value:h,onValueChange:f=>l("category",f),children:[e.jsx(F,{children:e.jsx(L,{placeholder:"Select category"})}),e.jsxs(M,{children:[e.jsx(j,{value:"general",children:"General"}),e.jsx(j,{value:"conduct",children:"Conduct"}),e.jsx(j,{value:"safety",children:"Safety"}),e.jsx(j,{value:"networking",children:"Networking"})]})]})]}),e.jsxs("div",{children:[e.jsx(w,{children:"Priority"}),e.jsxs(k,{value:p,onValueChange:f=>l("priority",f),children:[e.jsx(F,{children:e.jsx(L,{placeholder:"Select priority"})}),e.jsxs(M,{children:[e.jsx(j,{value:"high",children:"High"}),e.jsx(j,{value:"medium",children:"Medium"}),e.jsx(j,{value:"low",children:"Low"})]})]})]})]}),e.jsx(C,{type:"submit",disabled:t,className:"w-full",children:t?i?"Updating...":"Creating...":i?"Update Rule":"Create Rule"})]})]})]})},Le=s=>{const{toast:o}=se(),d=re(),{currentUser:t}=ie(),i=!!(t!=null&&t.id)&&!!s,{data:n=[],isLoading:u,error:m}=ae({queryKey:["rules",t==null?void 0:t.id,s],queryFn:async()=>{if(!(t!=null&&t.id))throw new Error("User not authenticated");if(!s)return[];try{console.log("Fetching rules for admin:",t.id,"event:",s);const{data:r,error:c}=await N.from("rules").select("*").eq("created_by",t.id).eq("event_id",s).order("created_at",{ascending:!1});if(c)throw console.error("Error fetching rules:",c),c;return console.log("Rules fetched successfully:",(r==null?void 0:r.length)||0),r||[]}catch(r){throw console.error("Unexpected error fetching rules:",r),r}},enabled:i}),l=S({mutationFn:async r=>{if(!(t!=null&&t.id))throw new Error("User not authenticated");if(!s)throw new Error("No event selected");const{data:c,error:h}=await N.from("rules").insert({title:r.title,content:r.content,category:r.category,priority:r.priority||"medium",created_by:t.id,event_id:s}).select().single();if(h)throw h;return c},onSuccess:()=>{d.invalidateQueries({queryKey:["rules",t==null?void 0:t.id,s]}),o({title:"Rule Created",description:"The rule has been created successfully for this event."})},onError:r=>{o({title:"Error",description:(r==null?void 0:r.message)||"Failed to create rule. Please try again.",variant:"destructive"}),console.error("Error creating rule:",r)}}),x=S({mutationFn:async({id:r,...c})=>{if(!(t!=null&&t.id))throw new Error("User not authenticated");if(!s)throw new Error("No event selected");const{data:h,error:p}=await N.from("rules").update({...c}).eq("id",r).eq("created_by",t.id).eq("event_id",s).select().single();if(p)throw p;return h},onSuccess:()=>{d.invalidateQueries({queryKey:["rules",t==null?void 0:t.id,s]}),o({title:"Rule Updated",description:"The rule has been updated successfully."})},onError:r=>{o({title:"Error",description:(r==null?void 0:r.message)||"Failed to update rule. Please try again.",variant:"destructive"}),console.error("Error updating rule:",r)}}),g=S({mutationFn:async r=>{if(!(t!=null&&t.id))throw new Error("User not authenticated");if(!s)throw new Error("No event selected");const{error:c}=await N.from("rules").delete().eq("id",r).eq("created_by",t.id).eq("event_id",s);if(c)throw c},onSuccess:()=>{d.invalidateQueries({queryKey:["rules",t==null?void 0:t.id,s]}),o({title:"Rule Deleted",description:"The rule has been removed successfully."})},onError:r=>{o({title:"Error",description:(r==null?void 0:r.message)||"Failed to delete rule. Please try again.",variant:"destructive"}),console.error("Error deleting rule:",r)}});return{rules:n,isLoading:u,error:m,createRule:l.mutate,updateRule:x.mutate,deleteRule:g.mutate,isCreating:l.isPending,isUpdating:x.isPending,isDeleting:g.isPending}},Me=()=>{const[s,o]=v.useState(""),[d,t]=v.useState(!1),[i,n]=v.useState(null),{selectedEventId:u,selectedEvent:m}=le(),{rules:l,isLoading:x,createRule:g,updateRule:r,deleteRule:c,isCreating:h,isUpdating:p,isDeleting:E,error:y}=Le(u),b=l.length,f=l.filter(a=>a.priority==="high").length,G=v.useMemo(()=>Array.from(new Set(l.map(a=>
1a.category).filter(Boolean))).length,[l]),D=l.filter(a=>a.title.toLowerCase().includes(s.toLowerCase())||a.content.toLowerCase().includes(s.toLowerCase())||(a.category||"").toLowerCase().includes(s.toLowerCase())),K=a=>{n(a),t(!0)},Z=a=>{c(a.id)},A=a=>{i?(r({id:i.id,...a}),n(null)):g(a)},P=a=>{a||n(null),t(a)};return e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsx(De,{})}),!u&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"p-4 rounded-full bg-primary/10 inline-block mb-4",children:e.jsx(T,{className:"h-8 w-8 text-primary"})}),e.jsx("p",{className:"text-muted-foreground text-lg mb-2",children:"No event selected"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please select an event above to manage rules"})]}),u&&e.jsxs(Ae,{eventId:u,eventName:(m==null?void 0:m.name)||"this event",feature:"Event Rules",children:[e.jsxs("div",{className:"p-8 rounded-2xl bg-gradient-to-br from-primary-100 via-blue-100 to-indigo-50 text-primary-900 dark:text-white shadow-2xl shadow-primary/10 mb-2 relative overflow-hidden",children:[e.jsx("div",{className:"absolute -top-12 -right-10 w-56 h-56 bg-white/10 rounded-full opacity-40 blur-2xl pointer-events-none"}),e.jsx("div",{className:"absolute -bottom-14 -left-14 w-36 h-36 bg-white/20 rounded-full opacity-30 pointer-events-none"}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("h1",{className:"text-4xl font-bold tracking-tight",children:"Event Guidelines"}),e.jsxs("p",{className:"mt-2 max-w-2xl text-primary-700 dark:text-primary-100",children:["Manage guidelines for ",e.jsx("span",{className:"font-semibold",children:m==null?void 0:m.name}),"."]}),e.jsx("div",{className:"mt-6",children:e.jsx(qe,{total:b,highPriority:f,categories:G,loading:x})})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Rules"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Define and manage event rules for your attendees."})]}),e.jsx(_,{open:d,setOpen:P,onSubmit:A,isSubmitting:h||p,editingRule:i?{title:i.title,content:i.content,category:i.category,priority:i.priority}:null})]}),e.jsx("div",{className:"flex justify-between mb-4",children:e.jsx(H,{placeholder:"Search rules...",value:s,onChange:a=>o(a.target.value),className:"max-w-sm"})}),e.jsx("div",{className:"space-y-4",children:D.length>0?D.map(a=>e.jsx(ke,{rule:a,isDeleting:E,onEdit:K,onDelete:Z},a.id)):e.jsxs("div",{className:"col-span-2 text-center py-8",children:[e.jsx(T,{className:"mx-auto h-12 w-12 text-muted-foreground opacity-30"}),e.jsx("h3",{className:"mt-4 text-lg font-medium",children:"No rules found"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"No rules match your search criteria."}),e.jsx(_,{open:d,setOpen:P,onSubmit:A,isSubmitting:h||p,editingRule:null})]})}),y&&e.jsxs("div",{className:"bg-destructive/10 text-destructive p-3 rounded-lg text-sm",children:["Error loading rules: ",y.message]})]})]})},ht=Me;export{ht as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.