1import{i as B,r as d,l as p,s as f,j as e,m as o,o as j,q as _,p as y,I as k,_ as E,n as M,v as N,B as I,A as P}from"./index-Ct8eLu1I.js";import{T as F,a as K,b as w}from"./tabs-BxjRtXE_.js";import{U}from"./user-check-BwC8fXcP.js";import{S as D}from"./search-BsvfnwMH.js";function Y(){const R=B(),[l,S]=d.useState("pending"),[x,L]=d.useState(""),{data:m=[],isLoading:z}=p({queryKey:["super-admin-rider-match-reviews"],queryFn:async()=>{const{data:s,error:a}=await f.from("rider_match_reviews").select("id, status, event_id, created_at").order("created_at",{ascending:!1}).limit(5e3);if(a)throw a;return s||[]}}),g=d.useMemo(()=>Array.from(new Set(m.map(s=>s.event_id).filter(Boolean))),[m]),{data:u=[]}=p({queryKey:["super-admin-rider-match-events",g],enabled:g.length>0,queryFn:async()=>{const{data:s,error:a}=await f.from("events").select("id, name, organization_id").in("id",g);if(a)throw a;return s||[]}}),h=d.useMemo(()=>Array.from(new Set(u.map(s=>s.organization_id).filter(Boolean))),[u]),{data:b=[]}=p({queryKey:["super-admin-rider-match-orgs",h],enabled:h.length>0,queryFn:async()=>{const{data:s,error:a}=await f.from("organizations").select("id, name, slug").in("id",h);if(a)throw a;return s||[]}}),c=d.useMemo(()=>{const s=new Map(u.map(t=>[t.id,t])),a=new Map(b.map(t=>[t.id,t])),v=new Map;for(const t of m){const r=s.get(t.event_id);if(!r)continue;const i=a.get(r.organization_id),q=t.event_id;let n=v.get(q);n||(n={event_id:t.event_id,event_name:r.name,organization_id:r.organization_id,org_name:(i==null?void 0:i.name)||"Unknown Org",org_slug:(i==null?void 0:i.slug)||"",pending:0,resolved:0,total:0,latest_created_at:t.created_at},v.set(q,n)),n.total+=1,t.status==="pending"?n.pending+=1:n.resolved+=1,t.created_at>n.latest_created_at&&(n.latest_created_at=t.created_at)}return Array.from(v.values()).sort((t,r)=>r.pending-t.pending||r.total-t.total)},[m,u,b]),C=d.useMemo(()=>{const s=x.trim().toLowerCase();return c.filter(a=>l==="pending"&&a.pending===0||l==="resolved"&&a.resolved===0?!1:s?a.event_name.toLowerCase().includes(s)||a.org_name.toLowerCase().includes(s)||a.org_slug.toLowerCase().includes(s):!0)},[c,l,x]),T=c.reduce((s,a)=>s+a.pending,0),A=c.reduce((s,a)=>s+a.resolved,0);return e.jsx("section",{className:"py-8 bg-background min-h-screen",children:e.jsxs("div",{className:"container mx-auto px-4 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(U,{className:"h-8 w-8 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-3xl md:text-4xl text-foreground",children:"Rider Match Review"}),e.jsx("p",{className:"text-muted-foreground",children:"Cross-org queue of registrations that need identity matching"})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(o,{children:e.jsxs(j,{className:"pb-2",children:[e.jsx(_,{children:"Pending"}),e.jsx(y,{className:"text-3xl",children:T})]})}),e.jsx(o,{children:e.jsxs(j,{className:"pb-2",children:[e.jsx(_,{children:"Resolved"}),e.jsx(y,{className:"text-3xl",children:A})]})}),e.jsx(o,{children:e.jsxs(j,{className:"pb-2",children:[e.jsx(_,{children:"Events with reviews"}),e.jsx(y,{className:"text-3xl",children:c.length})]})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 items-stretch sm:items-center",children:[e.jsx(F,{value:l,onValueChange:s=>S(s),children:e.jsxs(K,{children:[e.jsx(w,{value:"pending",children:"Pending"}),e.jsx(w,{value:"resolved",children:"Resolved"}),e.jsx(w,{value:"all",children:"All"})]})}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(D,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(k,{placeholder:"Search event or organization...",value:x,onChange:s=>L(s.target.value),className:"pl-10"})]})]}),z?e.jsxs("div",{className:"flex items-center justify-center py-16 text-muted-foreground",children:[e.jsx(E,{className:"h-6 w-6 animate-spin mr-2"})," Loading review queue..."]}):C.length===0?e.jsx(o,{children:e.jsx(M,{className:"py-16 text-center text-muted-foreground",children:l==="pending"?"No pending rider matches. You are all caught up.":"No reviews match your filters."})}):e.jsx("div",{className:"grid gap-3",children:C.map(s=>e.jsx(o,{className:"hover:border-primary/50 transition-colors",children:e.jsxs(M,{className:"py-4 flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium truncate",children:s.event_name}),e.jsx(N,{variant:"outline",className:"text-xs",children:s.org_name})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Last review ",new Date(s.latest_created_at).toLocaleStr
1ing()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s.pending>0&&e.jsxs(N,{variant:"destructive",children:[s.pending," pending"]}),s.resolved>0&&e.jsxs(N,{variant:"secondary",children:[s.resolved," resolved"]})]}),e.jsxs(I,{size:"sm",onClick:()=>R(`/admin/events/${s.event_id}/registrations?rmrTab=review`),children:["Open Review",e.jsx(P,{className:"h-4 w-4 ml-1"})]})]})},s.event_id))})]})})}export{Y 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.