1import{r as l,j as e,t as U}from"./react-vendor-Q2BSRknM.js";import{a as q}from"./query-BLOP9k_M.js";import{b2 as D,c as v,aZ as F,b3 as H,b4 as K,aY as V,s as j,C as Q,R,B as A,b5 as Y,b6 as W,h as C,b7 as M,b8 as G}from"./index-BgCZMvjj.js";import{S as B,f as _,e as L,b0 as Z,w as $,R as J}from"./lucide-Ckh7y__x.js";import"./capacitor-DSpR9wll.js";import"./ui-radix-DzQ_orwq.js";import"./supabase-DoZmW4Yf.js";import"./date-utils-DaNoSKVa.js";function X(t){const n=(t||"").toLowerCase();return n==="wd"?"border-l-womens-dubs":n==="md"?"border-l-mens-dubs":n.startsWith("mxd")?"border-l-emerald-600":n==="db"||n==="dreambreaker"?"border-l-amber-500":n==="ws"?"border-l-rose-600":n==="ms"?"border-l-mens-singles":"border-l-slate-600"}function ee({match:t,onMatchClick:n}){const[p,u]=l.useState(!1),m=t.team1||[],d=t.team2||[],{h2h:r}=D(m,d,t.event,t.id,!0),h=!!r&&r.totalMatches>0;return e.jsxs("div",{className:v("overflow-hidden bc-surface bc-elev-2 bc-cut-tr border-l-4",X(t.event)),style:{background:"var(--gradient-page, var(--gradient-match-card))"},children:[e.jsxs("div",{className:"relative",children:[e.jsx(F,{match:t,onClick:n,showWinProbability:!0,winProbabilityAsBar:!0,readOnlyFanVote:!0,hideBell:!0,transparent:!0}),h&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),u(a=>!a)},className:v("absolute bottom-2 right-2 z-10 flex items-center gap-1 px-2 py-0.5 rounded-[var(--bc-radius-sm)]","bc-glass bc-surface bc-surface-quiet bc-elev-1","text-muted-foreground hover:text-foreground transition-colors"),children:[e.jsx(B,{className:"h-3 w-3"}),e.jsxs("span",{className:"bc-label text-[10px]",children:["H2H · ",r.totalMatches," ",r.totalMatches===1?"MATCH":"MATCHES"]}),p?e.jsx(_,{className:"h-3 w-3"}):e.jsx(L,{className:"h-3 w-3"})]})]}),h&&p&&e.jsx("div",{className:"border-t border-border/40 px-3 pt-3 pb-3",children:e.jsx(H,{team1:m,team2:d,h2h:r,isLightTheme:!1,onMatchClick:i=>{const a=r.matches.find(c=>c.id===i);a&&n({id:a.id,tournament:a.tournament,event:a.event,round:a.round,time:a.time,status:"completed",team1:m,team2:d})}})})]})}function S({row:t,sponsors:n,standingsLookup:p,onMatchClick:u}){const[m,d]=l.useState(!1),{h2h:r}=K(t.team1_uuid,t.team2_uuid,t.id,!0),h=!!r&&r.totalMatches>0;return e.jsxs("div",{className:"rounded-xl overflow-hidden border border-l-4 border-border/50 border-l-slate-600",style:{background:"var(--gradient-page, var(--gradient-match-card))"},children:[e.jsxs("div",{className:"relative",children:[e.jsx(V,{row:t,sponsors:n,standingsLookup:p,onMatchClick:u,winProbabilityAsBar:!0,readOnlyFanVote:!0,hideBell:!0}),h&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),d(a=>!a)},className:v("absolute bottom-2 right-2 z-10 flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-medium","bg-black/40 backdrop-blur-sm border border-white/10","text-muted-foreground hover:text-foreground hover:bg-black/60 transition-colors"),children:[e.jsx(B,{className:"h-3 w-3"}),e.jsxs("span",{className:"font-score tracking-wider uppercase",children:["H2H · ",r.totalMatches," ",r.totalMatches===1?"MATCH":"MATCHES"]}),m?e.jsx(_,{className:"h-3 w-3"}):e.jsx(L,{className:"h-3 w-3"})]})]}),h&&m&&e.jsx("div",{className:"border-t border-border/40 px-3 pt-3 pb-3",children:e.jsx(H,{team1:[t.team1_name||""],team2:[t.team2_name||""],h2h:r,isLightTheme:!1,mlp:{team1Name:t.team1_name||"",team2Name:t.team2_name||""}})})]})}function de(){const[t]=U(),n=window.location.search.replace(/^\?/,""),p=n&&!n.includes("=")?decodeURIComponent(n):"",u=(t.get("key")||p||"").trim(),[m,d]=l.useState(!1),[r,h]=l.useState(!1);if(l.useEffect(()=>{if(!u){d(!0),h(!1);return}let i=!1;return(async()=>{const{data:a,error:c}=await j.functions.invoke("broadcast-dashboard",{body:{key:u}});i||(h(!c&&!!(a!=null&&a.authorized)),d(!0))})(),()=>{i=!0}},[u]),!m)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background text-foreground",children:"Loadingâ¦"});if(!r){const i=a=>{const c=a.trim();if(!c)return;const b=new URL(window.location.href);b.searchParams.set("key",c),window.location.href=b.toString()};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background text-foreground p-6",children:e.jsxs(Q,{className:"p-6 max-w-md w-full",children:[e.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Broadcast Access Required"}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["Append your access key as a query parameter, e.g. ",e.jsx("code",{children:"/broadcast?key=YOUR_KEY"}),"."]}),e.jsxs("form",{className:"flex gap-2",onSubmit:a=>{a.preventDefault();const c=a.currentTarget.elements.namedItem("key");i((c==null?void 0:c.value)||"")},children:[e.jsx(R,{name:"key",placeholder:"Paste keyâ¦",defaultValue:u,className:"flex-1"}),e.jsx(A,{type:"submit",children:"Submit"})]})]})})}return e.jsx(te,{})}function te(){const{matches:t,refetch:n,loading:p}=Y(),u=q(),[m,d]=l.useState(!1),[r,h]=l.useState(null),[i,a]=l.useState(!1),c=s=>{h(s),a(!0)},[b,P]=l.useState(""),w=l.useMemo(()=>(t||[]).filter(s=>s.status==="live"||s.status==="upcoming"),[t]),y=l.useMemo(()=>{const s=b.trim().toLowerCase();return w.filter(o=>s?[o.tournament,o.round,o.event,o.court,...o.team1||[],...o.team2||[]].join(" ").toLowerCase().includes(s):!0).sort((o,x)=>
1{if(o.status!==x.status)return o.status==="live"?-1:1;const f=o.time?new Date(o.time).getTime():1/0,g=x.time?new Date(x.time).getTime():1/0;return f-g})},[w,b]),[T,I]=l.useState(0),[E,z]=l.useState(0);l.useEffect(()=>{let s=!1;const o=async()=>{const[{count:f},{count:g}]=await Promise.all([j.from("mlp_event_matchups").select("id",{count:"exact",head:!0}).eq("status","in_progress"),j.from("mlp_event_matchups").select("id",{count:"exact",head:!0}).eq("status","upcoming")]);s||(I(f||0),z(g||0))};o();const x=setInterval(o,15e3);return()=>{s=!0,clearInterval(x)}},[]);const k=(t||[]).filter(s=>s.status==="live").length+T,O=(t||[]).filter(s=>s.status==="upcoming").length+E,N=b.trim();return e.jsxs("div",{className:"relative min-h-screen bg-background text-foreground",children:[e.jsxs("header",{className:"sticky top-0 z-10 border-b border-border bg-background/95 backdrop-blur",children:[e.jsxs("div",{className:"max-w-6xl mx-auto px-4 py-3 flex items-center gap-2.5 min-w-0 flex-wrap",children:[e.jsx("img",{src:W,alt:"PickleballTV",className:"h-6 w-auto shrink-0 rounded-md ring-1 ring-white/10"}),e.jsx("h1",{className:"font-score text-2xl tracking-wide truncate",children:"BROADCAST"}),k>0&&e.jsxs(C,{variant:"secondary",className:"shrink-0 font-score tracking-wider ml-1",children:[e.jsx("span",{className:"text-primary mr-1",children:k})," LIVE"]}),e.jsxs(C,{variant:"outline",className:"shrink-0 font-score tracking-wider",children:[O," UPCOMING"]}),e.jsx(Z,{className:"w-4 h-4 text-primary animate-pulse shrink-0 ml-auto"})]}),e.jsx("div",{className:"max-w-6xl mx-auto px-4 pb-3",children:e.jsxs("div",{className:"relative",children:[e.jsx($,{className:"w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(R,{value:b,onChange:s=>P(s.target.value),placeholder:"Search players or teamsâ¦",className:"pl-8 h-9 text-xs placeholder:text-xs"})]})})]}),e.jsxs("main",{className:"p-4 max-w-6xl mx-auto space-y-3 pb-24",children:[e.jsx(M,{status:"in_progress",emptyFallback:null,onMatchClick:c,searchQuery:N,renderRow:({row:s,sponsors:o,standingsLookup:x})=>e.jsx(S,{row:s,sponsors:o,standingsLookup:x,onMatchClick:c})}),p&&y.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:"Loading matchesâ¦"}):y.map(s=>e.jsx(ee,{match:s,onMatchClick:c},s.id)),e.jsx(M,{status:"upcoming",emptyFallback:null,onMatchClick:c,searchQuery:N,renderRow:({row:s,sponsors:o,standingsLookup:x})=>e.jsx(S,{row:s,sponsors:o,standingsLookup:x,onMatchClick:c})})]}),e.jsx(G,{match:r,open:i,onOpenChange:a},(r==null?void 0:r.id)??"no-match"),e.jsx(A,{onClick:async()=>{d(!0);try{await Promise.all([n(),u.invalidateQueries({queryKey:["mlp-feed"]})])}finally{setTimeout(()=>d(!1),600)}},size:"icon",variant:"outline",className:"fixed bottom-6 right-6 z-50 h-12 w-12 rounded-full shadow-lg bg-neutral-900 text-white border-white/15 hover:bg-neutral-800 hover:text-white","aria-label":"Refresh",children:e.jsx(J,{className:`w-5 h-5 ${m?"animate-spin":""}`})})]})}export{de 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.