1import{j as e}from"./vendor-ui-G-YrU37Q.js";import{r as h,f as V}from"./vendor-react-BM7Mjnmg.js";import{u as K,s as d,C as x,d as u,a as f,b as j,L as m,I as M,B as R,Z as X,z as B,P as Y,T as Z}from"./index-CxMl47VI.js";import{T as J,a as $,b as L,c as I}from"./tabs-DcOMWqad.js";import{R as ee}from"./RegistrationApproval-NcGonpAK.js";import{u as se,b as te,c as ae}from"./vendor-query-DVwyB0sA.js";import{T as re}from"./textarea-dLdgyKvj.js";import{Q as ie,a as ne}from"./QRScanner-qDnqvvPL.js";import{S as ce}from"./search-CDNGeXX9.js";import{C as de}from"./camera-CIYQKWbq.js";import{U as le}from"./user-check-BJzd5lpk.js";import{C as A}from"./circle-check-big-Dd44LNj-.js";import{C as W}from"./circle-x-h7qEKlNe.js";import{C as oe}from"./clock-DNraVdon.js";import"./vendor-supabase-z-MrzYB5.js";import"./table-B46xmeyg.js";import"./paymentUtils-BAgAWYEe.js";import"./driveUrl-CTLvT1UV.js";import"./alert-dialog-9cew_lDZ.js";import"./refresh-cw-BMi0X0dq.js";import"./eye-wcpoEGve.js";import"./play-B6Stvj74.js";import"./dollar-sign-DW_-T6hv.js";import"./trash-2-DNT1YvFM.js";import"./circle-alert-Bvv6-wnk.js";const me=()=>{var P,U;const[N,w]=h.useState(""),[p,S]=h.useState(""),[r,b]=h.useState(null),[E,g]=h.useState(""),[q,y]=h.useState(!1),{toast:C}=K(),n=se(),{data:t,isLoading:_}=te({queryKey:["staff-registrations"],queryFn:async()=>{const{data:{user:s},error:i}=await d.auth.getUser();if(i||!s)throw new Error("User not authenticated");const{data:a,error:v}=await d.from("user_roles").select("role, partner_id").eq("user_id",s.id);if(v)throw v;let c=d.from("event_registrations").select(` 2 id, 3 team_name, 4 contact_email, 5 contact_phone, 6 participants_count, 7 check_in_status, 8 checked_in_at, 9 qr_code, 10 events!inner ( 11 name, 12 event_date, 13 partner_id 14 ), 15 event_categories ( 16 name 17 ) 18 `).eq("payment_status","paid").order("created_at",{ascending:!1});if(a&&a.length>0){const Q=a.find(o=>o.role==="admin"&&o.partner_id),H=a.find(o=>o.role==="partner");if(Q&&Q.partner_id)c=c.eq("events.partner_id",Q.partner_id);else if(H){const{data:o,error:D}=await d.from("partners").select("id").eq("user_id",s.id).maybeSingle();if(D)throw D;o!=null&&o.id&&(c=c.eq("events.partner_id",o.id))}}const{data:k,error:he}=await c;return k}}),l=ae({mutationFn:async({registrationId:s,notes:i})=>{const{data:{user:a}}=await d.auth.getUser();if(!a)throw new Error("Not authenticated");const{error:v}=await d.from("event_registrations").update({check_in_status:"checked_in",checked_in_at:new Date().toISOString(),checked_in_by:a.id}).eq("id",s);if(v)throw v;const c=t==null?void 0:t.find(k=>k.id===s);if(c){const{error:k}=await d.from("registration_checkins").insert({registration_id:s,event_id:c.events?c.id:s,checked_in_by:a.id,notes:i||null});k&&console.error("Error creating audit record:",k)}return s},onSuccess:()=>{C({title:"Check-in Successful",description:"Team has been checked in successfully."}),n.invalidateQueries({queryKey:["staff-registrations"]}),b(null),w(""),g("")},onError:s=>{C({title:"Check-in Failed",description:s.message,variant:"destructive"})}}),T=()=>{N.trim()&&F(N.trim())},F=s=>{let i=t==null?void 0:t.find(a=>a.qr_code===s);if(!i&&s.startsWith("REG:")){const a=s.split(":");if(a.length>=3){const v=a[2];i=t==null?void 0:t.find(c=>c.qr_code===v)}}i||(i=t==null?void 0:t.find(a=>s.includes(a.id))),i?(b(i),w(""),y(!1)):C({title:"Registration Not Found",description:"Could not find a registration matching this QR code.",variant:"destructive"})},z=s=>{F(s)},G=s=>{b(s),S("")},O=(t==null?void 0:t.filter(s=>{var i;return s.team_name.toLowerCase().includes(p.toLowerCase())||s.contact_email.toLowerCase().includes(p.toLowerCase())||((i=s.qr_code)==null?void 0:i.toLowerCase().includes(p.toLowerCase()))}))||[];return _?e.jsx(x,{children:e.jsx(u,{className:"py-8",children:e.jsx("div",{className:"text-center",children:"Loading registrations..."})})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs(x,{children:[e.jsx(f,{children:e.jsxs(j,{className:"flex items-center gap-2",children:[e.jsx(ie,{className:"w-5 h-5"}),"Registration Check-In"]})}),e.jsxs(u,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"qr-input",children:"Scan QR Code"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(M,{id:"qr-input",placeholder:"Paste or type QR code here...",value:N,onChange:s=>w(s.target.value),onKeyDown:s=>s.key==="Enter"&&T()}),e.jsx(R,{onClick:T,disabled:!N.trim(),children:e.jsx(ce,{className:"w-4 h-4"})}),e.jsxs(R,{onClick:()=>y(!0),variant:"outline",className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-4 h-4"}),"Camera"]})]})]}),e.jsx(X,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"search-input",children:"Or Search by Team Name / Email"}),e.jsx(M,{id:"search-input",placeholder:"Search teams...",value:p,onChange:s=>S(s.target.value)}),p&&O.length>0&&e.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto border rounded-md",children:O.slice(0,10).map(s=>{var i,a;return e.jsx("div",{className:"p-3 hover:bg-muted cursor-pointer border-b last:border-b-0",onClick:()=>G(s),children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.team_name}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s.contact_email}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[(i=s.events)==null?void 0:i.name," - ",(a=s.event_categories)==null?void 0:a.name]})]}),e.jsx(B,{variant:s.check_in_status==="checked_in"?"default":"secondary",children:s.check_in_status==="checked_in"?"Checked In":"Pending"})]})},s.id)})})]})]})]}),r&&e.jsxs(x,{children:[e.jsx(f,{children:e.jsxs(j,{className:"flex items-center gap-2",children:[e.jsx(le,{className:"w-5 h-5"}),"Registration Details"]}
18)}),e.jsxs(u,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Team Name"}),e.jsx("p",{className:"text-lg",children:r.team_name})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Contact Email"}),e.jsx("p",{children:r.contact_email})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Event"}),e.jsx("p",{children:(P=r.events)==null?void 0:P.name})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Category"}),e.jsx("p",{children:(U=r.event_categories)==null?void 0:U.name})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Participants"}),e.jsx("p",{children:r.participants_count})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Check-in Status"}),e.jsx(B,{variant:r.check_in_status==="checked_in"?"default":"secondary",className:"mt-1",children:r.check_in_status==="checked_in"?e.jsxs(e.Fragment,{children:[e.jsx(A,{className:"w-3 h-3 mr-1"})," Checked In"]}):e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"w-3 h-3 mr-1"})," Pending"]})})]})]}),r.check_in_status==="checked_in"?e.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-lg p-4",children:[e.jsx("p",{className:"text-green-800 font-medium",children:"â
Already Checked In"}),r.checked_in_at&&e.jsxs("p",{className:"text-green-700 text-sm",children:["Checked in on ",new Date(r.checked_in_at).toLocaleString()]})]}):e.jsxs("div",{className:"space-y-4 pt-4 border-t",children:[e.jsxs("div",{children:[e.jsx(m,{htmlFor:"notes",children:"Check-in Notes (Optional)"}),e.jsx(re,{id:"notes",placeholder:"Add any notes about this check-in...",value:E,onChange:s=>g(s.target.value),rows:3})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(R,{onClick:()=>l.mutate({registrationId:r.id,notes:E}),disabled:l.isPending,className:"flex-1",children:[e.jsx(A,{className:"w-4 h-4 mr-2"}),l.isPending?"Checking In...":"Check In Team"]}),e.jsx(R,{variant:"outline",onClick:()=>b(null),children:"Cancel"})]})]})]})]}),e.jsxs(x,{children:[e.jsx(f,{children:e.jsx(j,{children:"Check-in Statistics"})}),e.jsx(u,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-primary",children:(t==null?void 0:t.length)||0}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Total Registrations"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-green-600",children:(t==null?void 0:t.filter(s=>s.check_in_status==="checked_in").length)||0}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Checked In"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-orange-600",children:(t==null?void 0:t.filter(s=>s.check_in_status==="pending").length)||0}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Pending"})]})]})})]}),e.jsx(ne,{isActive:q,onScan:z,onClose:()=>y(!1),title:"Scan Registration QR Code"})]})},Pe=()=>{const[N,w]=h.useState(!0),[p,S]=h.useState(null),[r,b]=h.useState({pendingRegistrations:0,approvedRegistrations:0,rejectedRegistrations:0,totalRegistrations:0}),{toast:E}=K(),g=V();h.useEffect(()=>{q(),y()},[]);const q=async()=>{try{const{data:n}=await d.auth.getUser();if(!n.user){g("/auth");return}const{data:t,error:_}=await d.from("staff_members").select("*").eq("user_id",n.user.id).eq("is_active",!0).single();if(_||!t){E({title:"Access Denied",description:"You don't have staff access",variant:"destructive"}),g("/");return}S(t)}catch(n){console.error("Error checking staff access:",n),g("/")}finally{w(!1)}},y=async()=>{try{const{data:n,error:t}=await d.from("event_registrations").select("approval_status");if(t)throw t;const _=n==null?void 0:n.reduce((l,T)=>{switch(l.totalRegistrations++,T.approval_status){case"pending":l.pendingRegistrations++;break;case"approved":l.approvedRegistrations++;break;case"rejected":l.rejectedRegistrations++;break}return l},{pendingRegistrations:0,approvedRegistrations:0,rejectedRegistrations:0,totalRegistrations:0});_&&b(_)}catch(n){console.error("Error fetching stats:",n)}},C=async()=>{await d.auth.signOut(),g("/")};return N?e.jsx("div",{className:"min-h-screen bg-gradient-main flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"}),e.jsx("p",{className:"mt-4 text-muted-foreground",children:"Loading staff dashboard..."})]})}):e.jsxs("div",{className:"min-h-screen bg-gradient-main",children:[e.jsx("div",{className:"bg-background/95 backdrop-blur-sm border-b border-border",children:e.jsx("div",{className:"container mx-auto px-4 py-4",children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:"Staff Dashboard"}),p&&e.jsxs("p",{className:"text-muted-foreground",children:["Welcome back, ",p.name]})]}),e.jsxs(R,{variant:"outline",onClick:C,children:[e.jsx(Y,{className:"w-4 h-4 mr-2"}),"Sign Out"]})]})})}),e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-6 mb-8",children:[e.jsxs(x,{className:"bg-card/50 backdrop-blur-sm border-primary/20",children:[e.jsxs(f,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(j,{className:"text-sm font-medium",children:"Pending"}),e.jsx(oe,{className:"h-4 w-4 text-yellow-600"})]}),e.jsxs(u,{children:[e.jsx("div",{className:"text-2xl font-bold text-yellow-600",children:r.pendingRegistrations}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Awaiting review"})]})]}),e.jsxs(x,{className:"bg-card/50 backdrop-blur-sm border-primary/20",children:[e.jsxs(f,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(j,{className:"text-sm font-medium",children:"Approved"}),e.jsx(A,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(u,{children:[e.jsx("div",{className:"text-2xl font-bold text-green-600",children:r.approvedRegistrations}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ready to compete"})]})]}),e.jsxs(x,{className:"bg-card/50 backdrop-blur-sm border-primary/20",children:[e.jsxs(f,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(j,{className:"text-sm font-medium",children:"Rejected"}),e.jsx(W,{className:"h-4 w-4 text-red-600"})]}),e.jsxs(u,{children:[e.jsx("div",{className:"text-2xl font-bold text-red-600",children:r.rejectedRegistrations}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Need attention"})]})]}),e.jsxs(x,{className:"bg-card/50 backdrop-blur-sm border-primary/20",children:[e.jsxs(f,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(j,{className:"text-sm font-medium",children:"Total"}),e.jsx(Z,{className:"h-4 w-4 text-primary"})]}),e.jsxs(u,{children:[e.jsx("div",{className:"text-2xl font-bold text-primary",children:r.totalRegistrations}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"All registrations"})]})]})]}),e.jsxs(J,{defaultValue:"overview",className:"space-y-6",children:[e.jsxs($,{className:"grid w-full grid-cols-3",children:[e.jsx(L,{value:"overview",children:"Overview"}),e.jsx(L,{value:"registrations",children:"Registrations"}),e.jsx(L,{value:"checkin",children:"Check-In"})]}),e.jsx(I,{value:"overview",children:e.jsxs(x,{className:"bg-card/50 backdrop-blur-sm border-primary/20",children:[e.jsx(f,{children:e.jsx(j,{children:"Staff Dashboard Overview"})}),e.jsx(u,{children:e.jsx("p",{className:"text-muted-foreground",children:"Manage event registrations and check-in participants from the tabs above."})})]})}),e.jsx(I,{value:"registrations",children:e.jsx(ee,{})}),e.jsx(I,{value:"checkin",children:e.jsx(me,{})})]})]})]})};export{Pe as StaffDashboard};
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.