1import{n as H,b as e,U as qe,ax as ye,ay as fe,az as he,aA as pn,d8 as tt,bf as zt,hV as jn,hW as Ue,hX as kn,hY as Ae,hM as wn,hZ as nt,h_ as J,aJ as D,hr as bn,a as f,e as Ye,h$ as vn,af as N,i0 as Nn,dR as Ht,bm as _n,i1 as Cn,K as L,i2 as Rn,i3 as He,dq as En,dr as Sn,ds as Tn,dt as Fn,eo as Kn,eR as It,bT as Oe,h as xe,q as Gt,Q as Ln,u as st,d1 as at,i4 as Mn,fu as Xe,L as se,s as Vt,i5 as Pn,i6 as wt,i7 as Fe,i8 as qn,i9 as bt,ia as On,ib as be,ic as An,id as Dn,ie as Un,p as Yn,bU as Ke,ig as Qn,ih as vt,ii as Nt,ij as Bn,d as $n,f2 as zn,c$ as Hn,ag as In,aE as Gn,d0 as Vn,ik as Wn,f5 as Zn,il as _t,im as Jn,fp as Xn,fI as es,fJ as Ie,fK as ts,fL as ns,fl as ss,d4 as as,d5 as rs,d2 as is,cL as os,cP as ls,cQ as Ge,d7 as Ve,io as cs,fg as ds,ip as us,iq as Le,ir as ms,is as xs,it as ys,iu as Ct,iv as fs}from"./index-COxKkHg0.js";import{C as hs}from"./CommunityCard-CZjgmbuE.js";import{S as Rt,a as Et,b as St,c as Tt,d as Z,e as Me,f as Pe,g as Ft}from"./select-CwLGt-CP.js";import{h as gs,F as ps,p as js,M as ks,a as ws,H as bs}from"./federation-board-B4vqW3pt.js";import{R as vs}from"./ReferFriendScreen-DYvL2LqG.js";import{u as Ns}from"./use-czpadel-ranking-DzBNUrCg.js";import{I as _s}from"./id-card-B2dTXsrj.js";import{M as Cs}from"./medal-C4VQavPs.js";import{p as Rs,f as Es,E as Kt,P as Ss}from"./community-directory-CXlwBAOY.js";import{M as Ts}from"./map-E_QPg49U.js";import{C as Lt}from"./compass-BpZuD7Ey.js";import"./chevron-up-UAozN4W5.js";import"./locate-fixed-D3WaRchg.js";import"./gift-DTZVQ6gI.js";function Fs({communities:t,onCommunityClick:o,showTitle:n=!0}){const{t:a}=H("community"),{lightImpact:m}=tt();if(t.length===0)return null;const c=d=>{m(),o(d)};return e.jsxs("div",{children:[n&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[e.jsx(qe,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"text-sm font-medium text-muted-foreground uppercase tracking-wider",children:a("discover.yourCommunities")})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-3 bg-gradient-to-r from-background to-transparent z-10 pointer-events-none"}),e.jsx("div",{className:"absolute right-0 top-0 bottom-0 w-3 bg-gradient-to-l from-background to-transparent z-10 pointer-events-none"}),e.jsx("div",{className:"flex gap-3 overflow-x-auto pb-2 px-3 scrollbar-hide",style:{WebkitOverflowScrolling:"touch"},children:t.map(d=>e.jsxs("button",{type:"button",className:"flex flex-col items-center gap-1.5 flex-shrink-0 w-[72px] active:scale-95 transition-transform",style:{WebkitTapHighlightColor:"transparent"},onClick:()=>c(d.id),children:[e.jsx("div",{className:"h-[68px] w-[68px] rounded-full bg-gradient-to-br from-primary to-primary/60 p-[2.5px]",children:e.jsxs(ye,{className:"h-full w-full border-[2.5px] border-background",children:[d.avatar_url&&e.jsx(fe,{src:d.avatar_url,className:"object-cover"}),e.jsx(he,{className:"bg-primary/10 text-primary text-base font-semibold",children:pn(d.name)})]})}),e.jsx("span",{className:"text-[11px] text-center leading-tight line-clamp-2 w-full text-muted-foreground",children:d.name})]},d.id))})]})]})}function Ks(){return e.jsxs(zt,{className:"p-4 animate-pulse",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-full bg-muted"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"h-3.5 w-28 rounded bg-muted"}),e.jsx("div",{className:"h-3 w-20 rounded bg-muted"})]})]}),e.jsxs("div",{className:"space-y-2 mb-3",children:[e.jsx("div",{className:"h-3.5 w-full rounded bg-muted"}),e.jsx("div",{className:"h-3.5 w-3/4 rounded bg-muted"})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-3",children:[e.jsx("div",{className:"h-6 w-16 rounded-full bg-muted"}),e.jsx("div",{className:"h-6 w-12 rounded-full bg-muted"})]})]})}function Ls({count:t=3}){return e.jsx("div",{className:"space-y-3",children:Array.from({length:t}).map((o,n)=>e.jsx(Ks,{},n))})}function Mt(t){if(!t||t.home_city_key===void 0)return{state:"unknown",cityKey:null};const o=jn(t);return o?{state:"city",cityKey:o}:{state:(typeof t.home_city_key=="string"?t.home_city_key.trim():"")===Ue?"other":"none",cityKey:null}}function Pt(t,o,n){const a=typeof t=="string"?t.trim():"";if(!a||a===Ue)return null;const m=kn(a);
1return m?Ae(m,n):(typeof o=="string"?o.trim():"")||null}function qt(t){const o=typeof t=="string"&&t.trim()!==""?Number(t):t;return typeof o!="number"||!Number.isFinite(o)?null:Math.floor(o)}function Ms(t){const o=Array.isArray(t)?t[0]:t;if(!o||typeof o!="object")return null;const n=o,a=qt(n.total_count);if(a===null||a<0)return null;if(n.rank===null||n.rank===void 0)return{rank:null,total:a};const m=qt(n.rank);return m===null||m<1?null:{rank:m,total:Math.max(a,m)}}function We(t,o){const n=typeof t=="string"?wn(t.trim()):void 0;if(n)return n.toUpperCase();const a=typeof o=="string"?o.trim().toUpperCase():"";return/^[A-Z]{2}$/.test(a)?a:null}const Ot=t=>typeof t=="number"&&Number.isFinite(t)&&t>=0?Math.floor(t):null;function Ps(t){return Ot(t.myRankTotal)??Ot(t.listTotal)??(t.listLoadedEmpty?0:null)}const Wt=10*60*1e3;function Zt(t,o,n=Wt){if(typeof t!="number"||!Number.isFinite(t))return!1;const a=o-t;return a>=0&&a<n}let _e=null,Ne=null;const ve=new Set;function et(){for(const t of[...ve])try{t()}catch{}}function Jt(){Ne!==null&&clearTimeout(Ne),Ne=null}function De(t=Date.now()){return Zt(_e,t)}function Xt(t=Date.now()){Zt(_e,t)||(_e=t,Jt(),Ne=setTimeout(()=>{Ne=null,et()},Wt),et())}function qs(){_e!==null&&(_e=null,Jt(),et())}const At=()=>qs();function en(t){const o=ve.size===0;return ve.add(t),o&&typeof window<"u"&&window.addEventListener("focus",At),()=>{ve.delete(t),ve.size===0&&typeof window<"u"&&window.removeEventListener("focus",At)}}function Os(t){if(t.savedFilter||t.playerPicked)return{status:"keep"};if(!t.profileLoaded)return{status:"pending",provisional:null};const o=t.profileCountry?{kind:"country",country:nt(t.profileCountry)}:null,n=rt(t.profileGender),a=(g,j)=>({status:"final",filter:g&&n?J(g,n):g,persist:j}),m=g=>a(g,g!==null&&!t.homeCityUnknown),c=typeof t.homeCityKey=="string"?t.homeCityKey.trim():"",d=c&&c!==Ue?c:null,h=typeof t.homeCityCountry=="string"?t.homeCityCountry.trim().toUpperCase():"";return!d||!h?m(o):t.cityBoardAvailable?m({kind:"city",country:h,cityKey:d}):a(o,!1)}function As(t,o,n,a){if(t)return t;const m=typeof(n==null?void 0:n.key)=="string"?n.key.trim():"",c=typeof(n==null?void 0:n.country)=="string"?n.country.trim().toUpperCase():"";let d;if(m&&m!==Ue&&c)d={kind:"city",country:c,cityKey:m};else if(o)d={kind:"country",country:nt(o)};else return{kind:"all"};const h=rt(a);return h?J(d,h):d}function rt(t){return t==="male"||t==="female"?t:null}const Ds=["venue-facets","padel"];function Us(t){const o=typeof t=="string"?t.trim().toUpperCase():"",n=D({queryKey:Ds,queryFn:()=>bn("padel"),staleTime:10*60*1e3,enabled:o!==""}),a=f.useMemo(()=>{if(!o)return null;const m=gs({country:o,facets:n.data,isError:n.isError});return m.kind==="cities"?m.tiles:null},[o,n.data,n.isError]);return{rows:a,loading:a===null&&o!==""&&n.isFetching,error:a===null&&o!==""&&n.isError&&!n.isFetching}}const Ys="my-city-rank";async function Qs(t){const n=await N.rpc.bind(N)("get_my_city_rank_v2",Nn(t));if(n.error){if(Ht(n.error,n.status))return Xt(),null;throw n.error}return Ms(n.data)}function Dt(t){const{user:o}=Ye(),n=f.useSyncExternalStore(en,De,De),a=!!t&&vn(t.cityKey)&&!!t.country,m=!!(o!=null&&o.id)&&a&&!n,c=D({queryKey:[Ys,o==null?void 0:o.id,(t==null?void 0:t.country)??null,(t==null?void 0:t.cityKey)??null,(t==null?void 0:t.gender)??null,t?t.cityStrings.join("|"):null],queryFn:()=>Qs(t),enabled:m,staleTime:2*60*1e3,retry:!1});return m?{data:c.data??null,isLoading:c.isLoading,isError:c.isError}:{data:null,isLoading:!1,isError:!1}}function Bs({placeName:t,totalCount:o,target:n,escapeLabel:a,onEscape:m}){const{t:c}=H("community"),[d,h]=f.useState(!1),{current:g,target:j,percent:r}=Rn(o,n);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 flex flex-col items-center text-center",children:[e.jsx("div",{className:"h-14 w-14 rounded-full bg-primary/10 flex items-center justify-center mb-4",children:e.jsx(_n,{className:"h-6 w-6 text-primary","aria-hidden":"true"})}),e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("h3",{className:"mt-1 text-lg font-bold",children:c("ranking.locked.title",{count:j,target:j})}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground max-w-xs",children:c("ranking.locked.body")}),e.jsxs("div",{className:"w-full mt-5 space-y-2",children:[e.jsx(Cn,{value:r,className:"h-2"}),e.jsxs("p",{className:"text-sm font-bold tabular-nums",children:[g," / ",j]})]}),e.jsx(L,{className:"w-full mt-5 rounded-xl h-11",onClick:()=>h(!0),children:c("ranking.locked.cta")}),e.jsx("button",{type:"button",onClick:m,className:"mt-3 min-h-11 text-sm text-muted-foreground underline underline-offset-4",children:a})]}),d&&e.jsx(vs,{onClose:()=>h(!1)})]})}function $s(t,o,n){const a=He(o.trim());return a?t.filter(m=>He(n(m)).includes(a)||He(m.label).includes(a)):t}const zs=8;function Hs({open:t,onOpenChange:o,countryName:n,rows:a,selectedKey:m,homeCity:c,canManageHomeCity:d,onBrowse:h,onShowHomeCity:g,onManageHomeCity:j}){const{t:r}=H("community"),{t:S}=H("match"),{lightImpact:Y}=tt(),[P,Q]=f.useState(""),C=f.useMemo(()=>$s(a,P,x=>Ae(x,S)),[a,P,S]),R=()=>{Q(""),o(!1)},q=x=>{Y(),h(x),R()};return e.jsx(En,{open:t,onOpenChange:x=>{x||Q(""),o(x)},children:e.jsxs(Sn,{className:"max-h-[85vh]",children:[e.jsxs(Tn,{className:"pb-2 text-center",children:[e.jsx(Fn,{children:r("ranking.cities.title")}),e.jsx(Kn,{className:"sr-only",children:r("ranking.cities.description")})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain px-4 pb-6","data-testid":"ranking-city-sheet",children:[(c||d)&&e.jsx("p",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("ranking.cities.yourCity")}),c?e.jsxs("div",{className:"mb-5 flex items-center gap-3 rounded-2xl border border-border bg-card p-3",children:[e.jsxs("button",{type:"button",onClick:()=>{c.key&&(Y(),g(),R())},disabled:!c.key,className:"flex min-w-0 flex-1 items-center gap-3 text-left disabled:cursor-default","data-testid":"ranking-home-city",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-primary/15 text-primary","aria-hidden":"true",children:e.jsx(It,{className:"h-5 w-5"})}),e.jsx("span",{className:"min-w-0 truncate text-base font-semibold",children:c.label})]}),d&&e.jsx(L,{type:"button",variant:"ghost",className:"h-10 shrink-0 rounded-full px-4 text-sm font-semibold text-primary",onClick:()=>{R(),j()},children:r("ranking.cities.change")})]}):d?e.jsxs("div",{className:"mb-5 rounded-2xl border border-dashed border-border p-4",children:[e.jsx("p",{className:"text-sm font-semibold",children:r("ranking.cities.setTitle")}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:r("ranking.cities.setBody")}),e.jsx(L,{type:"button",className:"mt-3 h-11 w-full rounded-full text-sm font-semibold",onClick:()=>{R(),j()},children:r("ranking.cities.setCta")})]}):null,e.jsx("p",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n}),a.length>zs&&e.jsxs("div",{className:"relative mb-2",children:[e.jsx(Oe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{type:"search",value:P,onChange:x=>Q(x.target.value),placeholder:r("ranking.cities.search"),"aria-label":r("ranking.cities.search"),className:"h-11 w-full rounded-xl border-0 bg-muted pl-9 pr-3 text-base outline-none focus:ring-2 focus:ring-primary/50"})]}),e.jsxs("ul",{className:"flex flex-col",role:"list",children:[!P.trim()&&e.jsx(Ut,{label:r("ranking.filter.allCities"),selected:m===null,onClick:()=>q(null)}),C.map(x=>e.jsx(Ut,{label:Ae(x,S),selected:m===x.key,isHome:(c==null?void 0:c.key)===x.key,homeHint:r("ranking.cities.yourCityShort"),onClick:()=>q(x.key)},x.key))]}),C.length===0&&P.trim()&&e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:r("ranking.cities.noResults")})]})]})})}function Ut({label:t,selected:o,isHome:n=!1,homeHint:a,onClick:m}){return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:m,"aria-current":o?"true":void 0,className:xe("flex h-12 w-full items-center gap-3 rounded-xl px-3 text-left text-base transition-colors hover:bg-muted/60",o&&"bg-muted font-semibold"),children:[e.jsx(Gt,{className:xe("h-4 w-4 shrink-0",o?"text-primary":"text-muted-foreground"),"aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),n&&a&&e.jsx("span",{className:"shrink-0 rounded-full bg-primary/15 px-2 py-0.5 text-xs font-semibold text-primary",children:a}),o&&e.jsx(Ln,{className:"h-4 w-4 shrink-0 text-primary","aria-hidden":"true"})]})})}const Yt=50;function Is({board:t,gender:o}){var R,q;
1const{t:n}=H("community"),{t:a}=H("profile"),m=st(),{user:c,profile:d}=Ye(),h=at({queryKey:[ps,t,o],queryFn:async({pageParam:x=0})=>{const v=await N.rpc("get_federation_board_v1",Mn(t,o,Yt,x));if(v.error)throw v.error;return js(v.data)},initialPageParam:0,getNextPageParam:(x,v)=>x.length<Yt?void 0:v.reduce((ae,T)=>ae+T.length,0),enabled:!!(c!=null&&c.id),staleTime:10*60*1e3}),g=D({queryKey:[ks,c==null?void 0:c.id,t,o],queryFn:async()=>{const x=await N.rpc("get_my_federation_board_rank_v1",{_board:t,_gender:o});if(x.error)throw x.error;return ws(x.data)},enabled:!!(c!=null&&c.id),staleTime:10*60*1e3}),j=Xe((d==null?void 0:d.country)??null),r=Ns(c==null?void 0:c.id,j),S=j&&r.isSuccess&&!r.data,Y=((R=h.data)==null?void 0:R.pages.flat())??[],P=x=>a("czpadel.pointsShort",{points:x}),Q=S?e.jsxs("div",{className:"rounded-2xl border border-dashed border-border p-4","data-testid":"federation-add-id",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-primary/15 text-primary","aria-hidden":"true",children:e.jsx(_s,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold",children:n("ranking.federation.addIdTitle")}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:n("ranking.federation.addIdBody")})]})]}),e.jsx(L,{className:"mt-3 h-11 w-full rounded-full text-sm font-semibold",onClick:()=>m("/profile/edit"),children:n("ranking.federation.addIdCta")})]}):null;if(h.isLoading)return e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(se,{className:"h-5 w-5 animate-spin text-muted-foreground"})});if(h.isError)return e.jsxs("div",{className:"flex flex-col items-center py-8 text-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:n("ranking.federation.loadFailed")}),e.jsx(L,{variant:"outline",size:"sm",className:"mt-3 rounded-full",onClick:()=>void h.refetch(),children:n("ranking.federation.retry")})]});const C=g.data&&g.data.rank!==null?g.data:null;return e.jsxs("div",{className:"space-y-4",children:[C?e.jsxs("div",{className:"flex items-center gap-3 px-3 py-3 rounded-xl bg-primary/10","data-testid":"federation-my-rank",children:[e.jsxs("span",{className:"min-w-[2.75rem] px-0.5 text-center text-sm font-bold tabular-nums shrink-0 text-primary",children:["#",C.rank]}),e.jsxs(ye,{className:"h-10 w-10",children:[e.jsx(fe,{src:(d==null?void 0:d.avatar_url)||""}),e.jsx(he,{className:"bg-primary/20 text-primary text-sm font-medium",children:((q=d==null?void 0:d.full_name)==null?void 0:q.charAt(0))||"?"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium truncate block",children:d==null?void 0:d.full_name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("ranking.outOf",{count:C.total,total:C.total})})]}),e.jsx("span",{className:"text-sm font-bold px-2.5 py-0.5 rounded-full shrink-0 bg-primary/20 text-primary tabular-nums",children:P(C.points)})]}):Q,Y.length===0?e.jsxs("div",{className:"flex flex-col items-center py-8 text-center","data-testid":"federation-empty",children:[e.jsx(Vt,{className:"h-8 w-8 text-muted-foreground/50 mb-2"}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:n("ranking.federation.emptyTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground/70 mt-1 max-w-xs",children:n(t==="fip"?"ranking.federation.emptyFip":"ranking.federation.emptyBody")})]}):e.jsxs("div",{className:"space-y-1",children:[Y.map(x=>{var v;return e.jsxs("button",{onClick:()=>m(`/player/${x.user_id}`),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-muted/50 active:scale-[0.98] transition-all text-left",children:[e.jsx("span",{className:`min-w-[2.25rem] px-0.5 text-center text-sm font-bold tabular-nums shrink-0 ${x.rank<=3?"text-primary":"text-muted-foreground"}`,children:x.rank}),e.jsxs(ye,{className:"h-10 w-10",children:[e.jsx(fe,{src:x.avatar_url||""}),e.jsx(he,{className:"bg-primary/20 text-primary text-sm font-medium",children:((v=x.full_name)==null?void 0:v.charAt(0))||"?"})]}),e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium truncate",children:x.full_name}),t==="czpadel"&&e.jsx("span",{className:"block text-xs text-muted-foreground tabular-nums",children:n("ranking.federation.nationalPlace",{position:x.federation_position})})]}),e.jsx("span",{className:"text-sm font-bold px-2.5 py-0.5 rounded-full shrink-0 bg-muted tabular-nums",children:P(x.points)})]}
1,x.user_id)}),h.hasNextPage&&e.jsx("div",{className:"flex justify-center pt-2 pb-4",children:e.jsxs(L,{variant:"outline",size:"sm",onClick:()=>void h.fetchNextPage(),disabled:h.isFetchingNextPage,className:"rounded-full",children:[h.isFetchingNextPage?e.jsx(se,{className:"h-4 w-4 animate-spin mr-2"}):null,n("ranking.loadMore")]})})]})]})}const Ze=t=>{const o=typeof t=="string"?t.trim().toUpperCase():"";return/^[A-Z]{2}$/.test(o)?o:null},Je=50,Gs=350,Qt="everyone";function Vs(){var gt,pt,jt,kt;const{t,i18n:o}=H("community"),{user:n,profile:a}=Ye(),m=st(),{lightImpact:c}=tt(),{t:d}=H("match"),{t:h}=H("profile"),g=f.useRef(void 0);g.current===void 0&&(g.current=Pn());const j=g.current,[r,S]=f.useState(()=>{const i=Mt(a).cityKey;return As(j,(a==null?void 0:a.country)??null,{key:i,country:We(i,a==null?void 0:a.country)},(a==null?void 0:a.gender)??null)}),[Y,P]=f.useState(!1),Q=f.useRef(!1),[C,R]=f.useState(()=>!!j),[q,x]=f.useState(!1),[v,ae]=f.useState(!1),T=f.useSyncExternalStore(en,De,De),B=Mt(a),w=B.cityKey,X=We(w,a==null?void 0:a.country),O=r.kind==="country"||r.kind==="city"?r.country:null,U=Us(T?null:O),p=r.kind==="city",re=r.kind==="federation",ie=p?((gt=U.rows)==null?void 0:gt.find(i=>i.key===r.cityKey))??null:null,ee=ie?ie.cityStrings:null,E=f.useMemo(()=>r.kind==="city"&&ee&&!T?{cityKey:r.cityKey,country:r.country,cityStrings:ee,gender:r.gender??null}:null,[r,ee,T]),oe=ie?Ae(ie,d):p&&r.cityKey===w?Pt(w,a==null?void 0:a.home_city,d):null,M=i=>{Q.current=!0,P(!0),S(i),be(i)},{data:I}=D({queryKey:["my-communities",n==null?void 0:n.id],queryFn:async()=>{const{data:i,error:y}=await N.from("community_members").select("community_id, communities(id, name)").eq("user_id",n.id).eq("status","active");if(y)throw y;return(i||[]).map(b=>({id:b.communities.id,name:b.communities.name}))},enabled:!!(n!=null&&n.id),staleTime:10*60*1e3}),F=wt(r),le=Fe(r),{data:$,isLoading:ge,isError:ce,refetch:A,fetchNextPage:Ce,hasNextPage:pe,isFetchingNextPage:Re}=at({queryKey:p?["city-ranking",le,(ee==null?void 0:ee.join("|"))??null]:["global-ranking",le],queryFn:async({pageParam:i=0})=>{if(p||!F){const ne=await N.rpc("get_city_ranking_v2",qn(E,Je,i));if(ne.error){if(Ht(ne.error,ne.status))return Xt(),[];throw ne.error}return Array.isArray(ne.data)?ne.data:[]}const{data:y,error:b}=await N.rpc("get_global_ranking",{_sport:"padel",...F,_limit:Je,_offset:i});if(b)throw b;return y||[]},initialPageParam:0,getNextPageParam:(i,y)=>{if(!(!i||i.length<Je))return y.flat().length},enabled:!re&&(!p||!!E),staleTime:2*60*1e3}),te=ge||p&&!E&&U.loading,{data:G,isLoading:je}=D({queryKey:["my-global-rank",n==null?void 0:n.id,le],queryFn:async()=>{if(!F)return null;const{data:i,error:y}=await N.rpc("get_my_global_rank",{_user_id:n.id,_sport:"padel",...F});if(y)throw y;const b=i;return b&&b.length>0?b[0]:null},enabled:!!(n!=null&&n.id)&&!p&&!re,staleTime:2*60*1e3}),{data:V,isSuccess:Qe}=D({queryKey:["my-rating-confidence",n==null?void 0:n.id],queryFn:async()=>{const{data:i,error:y}=await N.from("player_ratings").select("sigma, confidence_pct, display_level").eq("player_id",n.id).eq("sport","padel").maybeSingle();if(y)throw y;return i},enabled:!!(n!=null&&n.id),staleTime:2*60*1e3}),W=Dt(p?E:null),z=($==null?void 0:$.pages.flat())||[],Ee=z.length>0?z[0].total_count:null,s=Ps({myRankTotal:p?(pt=W.data)==null?void 0:pt.total:G==null?void 0:G.total_count,listTotal:Ee,listLoadedEmpty:!!$&&z.length===0}),u=bt(r)!==null&&!!r.gender,k=Dt(u&&E?{...E,gender:null}:null),K=u&&r.kind==="country"?wt(J(r,null)):null,{data:_,isLoading:ke}=D({queryKey:["global-ranking-count",Fe(J(r,null))],queryFn:async()=>{const{data:i,error:y}=await N.rpc("get_global_ranking",{_sport:"padel",...K,_limit:1,_offset:0});if(y)throw y;const b=i||[];return b.length>0?Number(b[0].total_count):0},enabled:!!K,staleTime:2*60*1e3}),de=u?p?((jt=k.data)==null?void 0:jt.total)??null:typeof _=="number"&&Number.isFinite(_)?_:null:s,Se=u?p?k.isLoading||!E&&U.loading:ke:!1,ue=(p?te||W.isLoading:te||!!(n!=null&&n.id)&&je)||Se,nn=On({filter:r,totalCount:de,isLoading:ue}),sn=!ue&&s===null&&z.length===0,we=f.useMemo(()=>Os({savedFilter:j,playerPicked:Y||C,profileLoaded:!!a,profileCountry:(a==null?void 0:a.country)??null,homeCityKey:w,homeCityCountry:X,cityBoardAvailable:!T,profileGender:(a==null?void 0:a.gender)??null,homeCityUnknown:B.state==="unknown"}),[j,Y,C,a,w,X,T,B.state]);f.useEffect(()=>{if(C||Q.current)return;if(we.status==="keep"){R(!0);return}if(we.status==="pending")return;const i=we.filter;i?(Fe(i)!==Fe(r)&&S(i),we.persist&&be(i),R(!0)):w&&R(!0)},[we,C,r,w]),f.useEffect(()=>{if(r.kind!=="city")return;const i=T||U.rows!==null&&!U.rows.some(ne=>ne.key===r.cityKey),y=U.error;if(!i&&!y)return;if(y&&!i){S(J({kind:"country",country:r.country},r.gender??null));return}const b=J({kind:"country",country:r.country},r.gender??null);S(b),T||be(b)},[T,r,U.rows,U.error]),f.useEffect(()=>{if(r.kind!=="federation"||!a||Xe(a.country??null))return;const i=Ze(a.country),y=J(i?{kind:"country",country:i}:{kind:"all"},r.gender??null);S(y),be(y)},[r,a]),f.useEffect(()=>{if(r.kind!=="community"||!I||I.some(b=>b.id===r.communityId))return;const i=Ze(a==null?void 0:a.country),y=J(i?{kind:"country",country:i}:{kind:"all"},r.gender??null);S(y),be(y)},[r,I,a==null?void 0:a.country]);const an=i=>{const y=Bn(i,r.gender);y&&M(y)},Be=i=>{if(!O)return;const y=r.gender?{gender:r.gender}:{};M(i?{kind:"city",country:O,cityKey:i,...y}:{kind:"country",country:O,...y})},$e=i=>{const y=We(i,a==null?void 0:a.country);if(!i||i==="other"||!y)return;const b=r.gender?{gender:r.gender}:{};M({kind:"city",country:y,cityKey:i,...b})},rn=i=>$e(i),on=i=>{if(!i)return;c(),M(J(r,i==="male"||i==="female"?i:null))},it=()=>{const i=r.gender?{gender:r.gender}:{};return r.kind==="city"&&w&&r.cityKey!==w&&X?{label:t("ranking.locked.backToMyCity"),go:()=>$e(w)}:r.kind==="city"?{label:t("ranking.locked.wholeCountry"),go:()=>M({kind:"country",country:r.country,...i})}:{label:t("ranking.locked.allCountries"),go:()=>M({kind:"all",...i})}},ln=i=>r.kind==="city"&&r.country===i?{onPointerUp:()=>Be(null),onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&Be(null)}}:{},me=p?W.data&&W.data.rank!==null?{rank:W.data.rank,total:W.data.total,level:(V==null?void 0:V.display_level)??null}:null:G?{rank:G.rank,total:G.total_count,level:G.display_level}:null,cn=p?W.isLoading:je,ot=An((a==null?void 0:a.country)??null),lt=new Set([...a!=null&&a.country?[nt(a.country)]:[],...Dn]).size,ct=i=>({code:i,name:Ke(i,o.language)}),dn=ot.slice(0,lt).map(ct),dt=ot.slice(lt).map(ct).sort((i,y)=>i.name.localeCompare(y.name,o.language)),ut=Xe((a==null?void 0:a.country)??null),mt=U.rows??[],un=!!O&&!T&&mt.length>0,xt=p?oe??t("ranking.filter.allCities"):t("ranking.filter.allCities"),yt=Pt(w,a==null?void 0:a.home_city,d),mn=w&&X&&yt?{key:w,label:yt}:B.state==="other"?{key:null,label:h("homeCity.other")}:null,xn=r.gender??Qt,ft=X??Ze(a==null?void 0:a.country),yn=rt(a==null?void 0:a.gender),ht=O!==null&&O===ft,Te=p&&!!w&&r.cityKey===w,fn=!!ft&&!ht,hn=p?!Te:ht&&!!w,gn=(r.gender??null)!==yn,ze=i=>xe("h-9 w-auto min-w-0 gap-1 rounded-full border-0 px-3 py-0 text-sm font-medium focus:ring-0 focus:border-0 [&>svg]:shrink-0 max-[359px]:[&>svg:last-child]:hidden",i?"bg-primary/15 text-primary":"bg-muted text-foreground");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Rt,{value:Un(r),onValueChange:an,children:[e.jsx(Et,{className:xe(ze(fn),"shrink-[3]"),"aria-label":t("ranking.filter.place"),children:e.jsx(St,{})}),e.jsxs(Tt,{children:[e.jsx(Z,{value:"all",children:t("ranking.filter.allCountries")}),e.jsx(Me,{}),e.jsx(Pe,{children:dn.map(i=>e.jsx(Z,{value:`country:${i.code}`,...ln(i.code),children:i.name},i.code))}),ut&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsxs(Pe,{children:[e.jsx(Ft,{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("ranking.filter.federation")}),e.jsx(Z,{value:"federation:czpadel",children:t("ranking.filter.czpadel")}),e.jsx(Z,{value:"federation:fip",children:t("ranking.filter.fip")})]})]}),dt.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsx(Pe,{children:dt.map(i=>e.jsx(Z,{value:`country:${i.code}`,children:i.name},i.code))})]}),I&&I.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsxs(Pe,{children:[e.jsx(Ft,{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("ranking.filter.yourCommunities")}),I.map(i=>e.jsx(Z,{value:`community:${i.id}`,children:i.name},i.id))]})]})]})]}),un&&e.jsxs("button",{type:"button",onClick:()=>{c(),ae(!0)},"aria-label":`${t("ranking.filter.city")}: ${xt}${Te?`, ${t("ranking.cities.yourCity")}`:""}`,"aria-haspopup":"dialog",className:xe("flex shrink items-center",ze(hn)),"data-testid":"ranking-city-button","data-own-city":Te?"true":void 0,children:[Te?e.jsx(It,{className:"h-3.5 w-3.5","aria-hidden":"true"}):p&&e.jsx(Gt,{className:"h-3.5 w-3.5","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 truncate",children:xt}),e.jsx(Yn,{className:"h-4 w-4 opacity-50","aria-hidden":"true"})]}),e.jsxs(Rt,{value:xn,onValueChange:on,children:[e.jsx(Et,{className:xe(ze(gn),"shrink-0"),"aria-label":t("ranking.filter.gender"),children:e.jsx(St,{})}),e.jsxs(Tt,{children:[e.jsx(Z,{value:Qt,children:t("ranking.filter.everyone")}),e.jsx(Z,{value:"male",children:t("ranking.filter.men")}),e.jsx(Z,{value:"female",children:t("ranking.filter.women")})]})]})]}),r.kind==="federation"?ut?e.jsx(Is,{board:r.board,gender:r.gender??null}):e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(se,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):ce&&z.length===0?e.jsxs("div",{className:"flex flex-col items-center py-8 text-center","data-testid":"ranking-load-failed",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("ranking.federation.loadFailed")}),e.jsx(L,{variant:"outline",size:"sm",className:"mt-3 rounded-full",onClick:()=>void A(),children:t("ranking.federation.retry")})]}):sn?e.jsx("div",{className:"flex justify-center py-8","data-testid":"ranking-count-unknown",children:e.jsx(se,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):nn?e.jsx(Bs,{placeName:r.kind==="country"?Ke(r.country,o.language):r.kind==="city"?oe??Ke(r.country,o.language):"",totalCount:de,target:bt(r)??Qn,escapeLabel:it().label,onEscape:()=>it().go()}):e.jsxs(e.Fragment,{children:[me?e.jsxs("div",{className:"flex items-center gap-3 px-3 py-3 rounded-xl bg-primary/10",children:[e.jsxs("span",{className:"min-w-[2.75rem] px-0.5 text-center text-sm font-bold tabular-nums shrink-0 text-primary",children:["#",me.rank]}),e.jsxs(ye,{className:"h-10 w-10",children:[e.jsx(fe,{src:(a==null?void 0:a.avatar_url)||""}),e.jsx(he,{className:"bg-primary/20 text-primary text-sm font-medium",children:((kt=a==null?void 0:a.full_name)==null?void 0:kt.charAt(0))||"?"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium truncate block",children:a==null?void 0:a.full_name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:t("ranking.outOf",{count:me.total,total:me.total})})]}),me.level!==null&&e.jsx("span",{className:"text-sm font-bold px-2.5 py-0.5 rounded-full shrink-0",style:vt(V),children:Nt(me.level)})]}):n&&!te&&!cn&&Qe&&!V?e.jsxs("div",{className:"flex items-center gap-3 px-3 py-3 rounded-xl bg-muted/50",children:[e.jsx(Cs,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("ranking.noRating")})]}):null,te?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(se,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):z.length===0?e.jsxs("div",{className:"flex flex-col items-center py-8",children:[e.jsx(Vt,{className:"h-8 w-8 text-muted-foreground
1/50 mb-2"}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:t("ranking.empty")}),e.jsx("p",{className:"text-xs text-muted-foreground/70 mt-1 text-center max-w-xs",children:t("ranking.emptyDesc")})]}):e.jsxs("div",{className:"space-y-1",children:[z.map(i=>{var y;return e.jsxs("button",{onClick:()=>m(`/player/${i.user_id}`),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-muted/50 active:scale-[0.98] transition-all text-left",children:[e.jsx("span",{className:`min-w-[2.25rem] px-0.5 text-center text-sm font-bold tabular-nums shrink-0 ${i.rank<=3?"text-primary":"text-muted-foreground"}`,children:i.rank}),e.jsxs(ye,{className:"h-10 w-10",children:[e.jsx(fe,{src:i.avatar_url||""}),e.jsx(he,{className:"bg-primary/20 text-primary text-sm font-medium",children:((y=i.full_name)==null?void 0:y.charAt(0))||"?"})]}),e.jsx("span",{className:"flex-1 min-w-0 text-sm font-medium truncate",children:i.full_name}),e.jsx("span",{className:"text-sm font-bold px-2.5 py-0.5 rounded-full shrink-0",style:vt(i),children:Nt(i.display_level)})]},i.user_id)}),pe&&e.jsx("div",{className:"flex justify-center pt-2 pb-4",children:e.jsxs(L,{variant:"outline",size:"sm",onClick:()=>Ce(),disabled:Re,className:"rounded-full",children:[Re?e.jsx(se,{className:"h-4 w-4 animate-spin mr-2"}):null,t("ranking.loadMore")]})})]})]}),O&&e.jsx(Hs,{open:v,onOpenChange:ae,countryName:Ke(O,o.language),rows:mt,selectedKey:p?r.cityKey:null,homeCity:mn,canManageHomeCity:B.state!=="unknown",onBrowse:Be,onShowHomeCity:()=>$e(w),onManageHomeCity:()=>{window.setTimeout(()=>x(!0),Gs)}}),e.jsx(bs,{open:q,onOpenChange:x,onSaved:rn})]})}const Ws=["CZ"],Zs=["68311435-db56-4ac3-bea8-f51201d18c09","d24c6835-3728-4083-b16b-6e3768427631","49d7fdef-5315-4145-8aa4-f729e0a74791","b822f1de-581e-4362-baf5-e3d962f3cb30","828abc71-3576-462e-85d1-a222bd42da84","90124583-2ecb-4df6-bc99-8e623a54606e"],tn=6;function Js(t,o){if(Number.isFinite(t)&&t>0)return"friendsOfFriends";const n=typeof o=="string"?o.trim().toUpperCase():"";return!n||Ws.includes(n)?"seeds":"topPlayers"}function Xs(t,o){return t!=="topPlayers"||typeof o!="number"||!Number.isFinite(o)?!1:o<tn}function Bt({profile:t,isFollowing:o,showFollowButton:n=!0,followerCount:a,onFollowToggle:m,onCardClick:c}){var g;const{t:d}=H("common"),h=f.useRef(!1);return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>{if(h.current){h.current=!1;return}c(t.id)},children:[e.jsxs(ye,{className:"h-12 w-12",children:[e.jsx(fe,{src:t.avatar_url||""}),e.jsx(he,{className:"bg-primary/20 text-primary",children:((g=t.full_name)==null?void 0:g.charAt(0))||"U"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:t.full_name}),t.username&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["@",t.username]}),a!=null&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[ys(a)," ",d("common:label.followers").toLowerCase()]})]}),n&&e.jsx(L,{variant:o?"outline":"default",size:"sm",className:"rounded-full px-4 h-8 text-xs font-semibold min-w-[72px]",onClick:j=>{j.stopPropagation(),j.preventDefault(),h.current=!0,m(t.id)},children:d(o?"action.following":"action.follow")})]})}const $t="community-active-tab";function ya(){const{t,tg:o}=$n("community"),{user:n,profile:a,profileLoading:m}=Ye(),c=(a==null?void 0:a.country)??null,{isBlocked:d}=zn(),{toast:h}=Hn(),g=st(),j=In(),r=Gn(),[S,Y]=f.useState(()=>{var s;return((s=j.state)==null?void 0:s.tab)||sessionStorage.getItem($t)||"activity"});Vn({key:"community-tab"});const[P,Q]=f.useState(!1),[C,R]=f.useState(!1),[q,x]=f.useState({}),v=f.useRef(new Set),ae=10,T=f.useRef(null),{data:B,isLoading:w,fetchNextPage:X,hasNextPage:O,isFetchingNextPage:U}=at({queryKey:["unified-feed",n==null?void 0:n.id],queryFn:async({pageParam:s})=>{const{data:l,error:u}=await N.rpc("get_unified_feed",{p_user_id:n.id,p_cursor:(s==null?void 0:s.sort_date)??null,p_cursor_id:(s==null?void 0:s.item_id)??null,p_limit:ae});if(u)throw u;return Wn(l)},initialPageParam:null,getNextPageParam:s=>{if(!(s.rawCount<ae))return s.cursor??void 0},enabled:!!(n!=null&&n.id),staleTime:2*60*1e3}),p=f.useMemo(()=>((B==null?void 0:B.pages.flatMap(l=>l.items))||[]).filter(l=>l.item_type==="post"&&l.post?!d(l.post.author_id):l.item_type==="match"&&l.match?!l.match.players.some(u=>d(u.id)):!0),[B,d]),re=f.useMemo(()=>{const s=new Set;return p.filter(l=>{var u;if(l.item_type==="match"&&((u=l.match)!=null&&u.session_id)){if(s.has(l.match.session_id))return!1;s.add(l.match.session_id)}return!0})}
1,[p]),ie=f.useMemo(()=>re.flatMap(s=>s.item_type==="tournament"&&s.tournament?[s.tournament.id]:[]),[re]),ee=Zn(ie),{data:E}=D({queryKey:["following-ids",n==null?void 0:n.id],queryFn:async()=>{if(!(n!=null&&n.id))return[];const{data:s}=await N.from("follows").select("following_id").eq("follower_id",n.id);return(s==null?void 0:s.map(l=>l.following_id))||[]},enabled:!!(n!=null&&n.id),staleTime:2*60*1e3}),oe=f.useMemo(()=>{const s=new Set(E||[]);for(const[l,u]of Object.entries(q))u?s.add(l):s.delete(l);return s},[E,q]);f.useEffect(()=>{if(!E||Object.keys(q).length===0)return;const s=new Set(E),l=Object.entries(q).filter(([u,k])=>k?s.has(u):!s.has(u));l.length>0&&x(u=>{const k={...u};for(const[K]of l)delete k[K];return Object.keys(k).length===0?{}:k})},[E]);const{data:M}=D({queryKey:["suggested-players",n==null?void 0:n.id,c],queryFn:async()=>n!=null&&n.id?_t(E||[],Ct,c):[],enabled:!!(n!=null&&n.id)&&p.length===0&&E!==void 0&&(!!a||!m),staleTime:10*60*1e3}),I=M!==void 0&&Jn(M.length,Ct),{data:F,isLoading:le}=D({queryKey:["discover-suggestions",n==null?void 0:n.id,c],queryFn:async()=>{if(!(n!=null&&n.id))return{source:"seeds",players:[]};const{data:s}=await N.from("follows").select("following_id").eq("follower_id",n.id),l=(s==null?void 0:s.map(_=>_.following_id))||[],u=Js(l.length,c);if(u==="topPlayers"){const _=await _t([],tn,c);return{source:u,players:_}}let k;if(u==="seeds")k=Zs.filter(_=>_!==n.id);else{const _=l.slice(0,150),ke=new Set([n.id,...l]),{data:de}=await N.from("follows").select("following_id").in("follower_id",_).limit(500),Se=[...new Set((de==null?void 0:de.map(ue=>ue.following_id))||[])].filter(ue=>!ke.has(ue));if(Se.length===0)return{source:u,players:[]};k=Se.slice(0,6)}const{data:K}=await N.from("profiles").select("id, full_name, username, avatar_url, country, bio").in("id",k).eq("onboarding_completed",!0);return{source:u,players:K||[]}},enabled:!!(n!=null&&n.id)&&(!!a||!m),staleTime:10*60*1e3}),$=F==null?void 0:F.players,ge=Xs(F==null?void 0:F.source,F==null?void 0:F.players.length),ce=Xn(a==null?void 0:a.country),{data:A}=D({queryKey:Rs(ce),queryFn:()=>Es(ce,Ss),enabled:!!(n!=null&&n.id)&&(!!a||!m),staleTime:10*60*1e3}),Ce=!!ce&&A!==void 0&&A.length===0,{data:pe}=D({queryKey:["my-communities",n==null?void 0:n.id],queryFn:async()=>{if(!(n!=null&&n.id))return[];const{data:s,error:l}=await N.from("community_members").select("community_id, communities(id, name, avatar_url, sport, city)").eq("user_id",n.id).eq("status","active");if(l)throw l;return s?s.map(u=>u.communities).filter(Boolean):[]},enabled:!!(n!=null&&n.id),staleTime:10*60*1e3}),[Re,te]=f.useState({});f.useEffect(()=>{const s=p.filter(l=>{var u;return l.item_type==="match"&&((u=l.match)==null?void 0:u.score)}).map(l=>l.item_id);s.length===0||!(n!=null&&n.id)||es(s,n.id).then(te).catch(()=>{})},[p.length,n==null?void 0:n.id]),f.useEffect(()=>{const s=T.current;if(!s||!O)return;const l=new IntersectionObserver(([u])=>{u.isIntersecting&&X()},{rootMargin:"200px"});return l.observe(s),()=>l.disconnect()},[O,X]);const G=f.useCallback(async(s,l)=>{if(!(n!=null&&n.id))return;let u=Ie(),k="add";te(K=>{u=K[s]||Ie();const _=ts(u,l);return k=_.action,{...K,[s]:_.next}});try{await ns(s,n.id,l,k)}catch(K){te(ke=>({...ke,[s]:u}));const _=ss(K);_&&h({title:t(`common:${_}`),variant:"destructive"})}},[n==null?void 0:n.id,h,t]);f.useEffect(()=>{const s=()=>Q(window.scrollY>8);return window.addEventListener("scroll",s,{passive:!0}),()=>window.removeEventListener("scroll",s)},[]);const je=f.useCallback(s=>{Y(s),sessionStorage.setItem($t,s)},[]),V=()=>{r.invalidateQueries({queryKey:["unified-feed"]}),r.invalidateQueries({queryKey:["following-ids"]})},Qe=async s=>{if(n!=null&&n.id&&!v.current.has(s)){v.current.add(s),x(l=>({...l,[s]:!0})),r.setQueryData(["following-ids",n.id],l=>[...l||[],s]);try{const{error:l}=await N.from("follows").insert({follower_id:n.id,following_id:s}).select("id");if(l){if(l.code==="23505"){h({title:t("toast.following"),description:t("toast.followingDesc")}),V();return}throw l}h({title:t("toast.following"),description:t("toast.followingDesc")}),V()}catch(l){if(console.error("[Community Follow] Error:",l),x(u=>{const k={...u};return delete k[s],k}),r.invalidateQueries({queryKey:["following-ids"]}),fs(l))h({title:t("common:toast.followRateLimited"),description:t("common:error.followRateLimited"),variant:"destructive"});else{const u=l instanceof Error?l.message:t("common:error.generic");h({title:t("toast.error"),description:u,variant:"destructive"})}}finally{v.current.delete(s)}}},W=async s=>{if(n!=null&&n.id&&!v.current.has(s)){v.current.add(s),x(l=>({...l,[s]:!1})),r.setQueryData(["following-ids",n.id],l=>(l||[]).filter(u=>u!==s));try{const{error:l}=await N.from("follows").delete().eq("follower_id",n.id).eq("following_id",s);if(l)throw l;h({title:t("toast.unfollowed"),description:o("toast.unfollowedDesc")}),V(),r.invalidateQueries({queryKey:["discover-suggestions"]})}catch(l){console.error("[Community Unfollow] Error:",l),x(k=>{const K={...k};return delete K[s],K}),r.invalidateQueries({queryKey:["following-ids"]});const u=l instanceof Error?l.message:t("common:error.generic");h({title:t("toast.error"),description:u,variant:"destructive"})}finally{v.current.delete(s)}}},z=s=>{v.current.has(s)||(oe.has(s)?W(s):Qe(s))},Ee=s=>{g(`/player/${s}`)};return e.jsxs(as,{showNav:!C,children:[e.jsx(rs,{onRefresh:async()=>{await Promise.all([r.invalidateQueries({queryKey:["unified-feed"]}),r.invalidateQueries({queryKey:["following-ids"]}),r.invalidateQueries({queryKey:["discover-suggestions"]}),r.invalidateQueries({queryKey:["popular-communities"]}),r.invalidateQueries({queryKey:["my-communities"]}),r.invalidateQueries({queryKey:["global-ranking"]}),r.invalidateQueries({queryKey:["my-global-rank"]})])},children:e.jsxs("div",{className:"flex flex-col min-h-screen bg-background",children:[e.jsxs(is,{className:`transition-all duration-200 ${P?"bg-background/70 backdrop-blur-xl saturate-150":"bg-background"}`,children:[e.jsx("div",{className:"pt-safe"}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[e.jsx("h1",{className:"text-2xl font-bold",children:t("title")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>g("/padel-map"),className:"h-10 w-10 flex items-center justify-center transition-colors",children:e.jsx(Ts,{className:"h-6 w-6 text-foreground"})}),e.jsx("button",{onClick:()=>R(!0),className:"h-10 w-10 flex items-center justify-center transition-colors",children:e.jsx(Oe,{className:"h-6 w-6 text-foreground"})})]})]})]}),e.jsx("div",{className:"flex-1",children:e.jsxs(os,{value:S,onValueChange:je,className:"p-4",children:[e.jsxs(ls,{className:"grid w-full grid-cols-3 mb-4",children:[e.jsx(Ge,{value:"activity",children:t("tab.activity")}),e.jsx(Ge,{value:"ranking",children:t("tab.ranking")}),e.jsx(Ge,{value:"discover",children:t("tab.discover")})]}),e.jsx(Ve,{value:"activity",className:"space-y-3",children:w?e.jsx(Ls,{count:3}):re.length>0?e.jsxs(e.Fragment,{children:[re.map(s=>{var l,u;return s.item_type==="match"&&s.match?e.jsx(cs,{match:{id:s.match.id,scheduled_at:s.match.scheduled_at,venue_name:s.match.venue_name,sport:s.match.sport,status:s.match.status,players:s.match.players||[],session_id:s.match.session_id,score:s.match.score},reactions:Re[s.item_id]||Ie(),onReactionToggle:G,commentCount:(l=s.match)==null?void 0:l.comment_count,recentComments:(u=s.match)==null?void 0:u.recent_comments},`match-${s.item_id}`):s.item_type==="post"&&s.post?e.jsx(ds,{post:{id:s.post.id,community_id:s.post.community_id,author_id:s.post.author_id,content:s.post.content,image_urls:s.post.image_urls||[],created_at:s.post.created_at},author:{id:s.post.author_id,full_name:s.post.author_name,avatar_url:s.post.author_avatar},community:{name:s.post.community_name,avatar_url:s.post.community_avatar},commentCount:s.post.comment_count,recentComments:s.post.recent_comments},`post-${s.item_id}`):s.item_type==="tournament"&&s.tournament?e.jsx(us,{tournament:s.tournament,entryFee:ee.get(s.tournament.id)},`tournament-${s.item_id}`):null}),e.jsx("div",{ref:T,className:"flex justify-center py-4",children:U&&e.jsx(se,{className:"h-5 w-5 animate-spin text-muted-foreground"})})]}):e.jsxs("div",{className:"flex flex-col items-center py-16 px-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-muted/60 flex items-center justify-center mb-4",children:e.jsx(qe,{className:"h-7 w-7 text-muted-foreground
1/70"})}),e.jsx("h3",{className:"font-semibold text-lg mb-2",children:t("activity.noRecentActivity")}),e.jsx("p",{className:"text-sm text-muted-foreground text-center max-w-[280px] mb-6",children:t("activity.noRecentActivityDesc")}),e.jsxs("div",{className:"flex w-full flex-wrap justify-center gap-3",children:[e.jsxs(L,{variant:"outline",size:"sm",className:"min-h-11 max-w-full",onClick:()=>R(!0),children:[e.jsx(Oe,{className:"h-4 w-4 mr-1.5 shrink-0"}),e.jsx("span",{className:"truncate",children:t("discover.findPlayers")})]}),e.jsxs(L,{variant:"outline",size:"sm",className:"min-h-11 max-w-full",onClick:()=>je("discover"),children:[e.jsx(Lt,{className:"h-4 w-4 mr-1.5 shrink-0"}),e.jsx("span",{className:"truncate",children:t("activity.exploreCommunities")})]})]}),((M??[]).length>0||I)&&e.jsxs("div",{className:"w-full mt-8",children:[(M??[]).length>0&&e.jsx("h4",{className:"text-sm font-medium text-muted-foreground mb-3 px-1",children:t("activity.suggestedToFollow")}),e.jsxs("div",{className:"space-y-1",children:[(M??[]).map(s=>e.jsx(Bt,{profile:s,isFollowing:oe.has(s.id),onFollowToggle:z,onCardClick:Ee},s.id)),I&&e.jsx(Le,{variant:"row",surface:"community_activity",className:(M??[]).length>0?"mt-2":""})]})]})]})}),e.jsx(Ve,{value:"ranking",children:e.jsx(Vs,{})}),e.jsxs(Ve,{value:"discover",className:"space-y-6",children:[pe&&pe.length>0&&e.jsx(Fs,{communities:pe,onCommunityClick:s=>g(`/community/${s}`)}),A&&A.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[e.jsx(qe,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"text-sm font-medium text-muted-foreground uppercase tracking-wider",children:t("discover.popularCommunities")})]}),e.jsx("div",{className:"space-y-3",children:A.slice(0,3).map(s=>e.jsx(hs,{community:s,memberCount:s.memberCount,variant:"large"},s.id))}),A.length>3&&e.jsx(L,{variant:"outline",className:"w-full mt-3",onClick:()=>g("/community/discover"),children:t("discover.seeAllCommunities")}),!!ce&&e.jsx("button",{type:"button",onClick:()=>g("/community/discover",{state:Kt}),className:"mx-auto mt-1 block min-h-11 px-4 text-[15px] font-medium text-muted-foreground underline underline-offset-4 active:opacity-70",children:t("common:directory.showEverywhere")})]}),Ce&&e.jsxs(zt,{className:"p-5 text-center",children:[e.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-primary/10",children:e.jsx(qe,{className:"h-6 w-6 text-primary"})}),e.jsx("h3",{className:"text-base font-semibold",children:t("common:directory.communities.emptyTitle")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t("common:directory.communities.emptyBody")}),e.jsx(L,{className:"mt-4 min-h-11 w-full",onClick:()=>g("/create-community"),children:t("common:directory.communities.createCta")}),e.jsx("button",{type:"button",onClick:()=>g("/community/discover",{state:Kt}),className:"mx-auto mt-1 block min-h-11 px-4 text-[15px] font-medium text-muted-foreground underline underline-offset-4 active:opacity-70",children:t("common:directory.showEverywhere")})]}),le?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(se,{className:"h-6 w-6 animate-spin text-primary"})}):$&&$.length>0?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[e.jsx(ms,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"text-sm font-medium text-muted-foreground uppercase tracking-wider",children:t("discover.playersYouMightKnow")})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3 px-1",children:t("discover.playersYouMightKnowDesc")}),e.jsxs("div",{className:"space-y-1",children:[$.map(s=>e.jsx(Bt,{profile:s,isFollowing:oe.has(s.id),onFollowToggle:z,onCardClick:Ee},s.id)),ge&&e.jsx(Le,{variant:"row",surface:"community_discover",className:"mt-2"})]})]}):ge&&A&&A.length>0?e.jsx(Le,{variant:"row",surface:"community_discover"}):null,(!A||A.length===0)&&(!$||$.length===0)&&!le&&e.jsxs("div",{className:Ce?"flex flex-col items-center justify-center pb-10":"flex flex-col items-center justify-center py-20",children:[e.jsx("div",{className:"h-16 w-16 rounded-full bg-primary/10 flex items-center justify-center mb-4",children:e.jsx(Lt,{className:"h-8 w-8 text-primary"})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:t("discover.noTopPlayers")}),e.jsx("p",{className:"text-sm text-muted-foreground text-center max-w-xs",children:t("discover.noTopPlayersDesc")}),e.jsxs(L,{onClick:()=>R(!0),variant:"outline",className:"mt-4",children:[e.jsx(Oe,{className:"h-4 w-4 mr-2"}),t("discover.findPlayers")]}),ge&&e.jsx(Le,{variant:"row",surface:"community_discover",className:"mt-8 w-full text-left"})]})]})]})})]})}),e.jsx(xs,{open:C,onOpenChange:R})]})}export{ya 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.