1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/rankForPoints-CLM0aQiz.js","assets/index-DnLpPdJu.js","assets/index-Cl6hHy8i.css"])))=>i.map(i=>d[i]); 2import{$ as Ie,r as n,s as k,j as e,g as se,L as Q,a6 as ze,Z as Me,B as H,D as He,h as Ke,_ as Ue,i as Ye,I as le,q as he,a as Be,n as Ve,d as Ge,Y as We,A as ke,e as Xe,f as Ce,a5 as Je,T as Se,bj as Ze,F as Qe}from"./index-DnLpPdJu.js";import{B as de}from"./badge-Ci6bMlns.js";import{d as Pe,C as Fe,f as et}from"./tournaments-BXkCUYTe.js";import"./progress-CbPWIxA8.js";import{S as Ae}from"./skeleton-R0uEhm4p.js";import{A as tt}from"./award-BFZ1jn96.js";import{A as ce}from"./arrow-right--C-6tBwN.js";import{A as st}from"./AdminAlertsCard-DxWnoHSI.js";import{A as at,b as nt,c as rt,d as it,e as lt,f as ot,g as ct,h as dt}from"./alert-dialog-nspHFgQS.js";import{P as mt}from"./plus-eYXrVnZo.js";import{T as Le}from"./trending-down-Ctqs23fe.js";import{T as ae}from"./trending-up-BICJ--wK.js";import{T as De}from"./trash-2-9vLPNF96.js";import{c as ut}from"./rankingEvolution-DPeILJkB.js";import{C as Te}from"./calendar-r-k-P1fG.js";import{M as pt}from"./medal-DfuRjZv3.js";import{aT as xt,aU as ht,aV as ft,aW as gt,aX as jt,aY as Nt}from"./CartesianChart-h1_zno8a.js";import{L as yt}from"./LineChart-D-03LQHz.js";import{U as vt}from"./users-BdNpofaM.js";import"./textarea-BGHgl9MJ.js";/** 3 * @license lucide-react v0.462.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const _t=Ie("ChevronsUpDown",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]]),bt=["P25","P50","P100","P250","P500"],wt=({license:i})=>{const[u,N]=n.useState(null),[j,D]=n.useState(!0);return n.useEffect(()=>{const r=(i??"").trim();if(!r){N(null),D(!1);return}let v=!1;return D(!0),(async()=>{const p=new Date,L=new Date(p.getFullYear(),p.getMonth()-11,1).toISOString().slice(0,10),x=new Date(p.getFullYear(),p.getMonth()+1,1).toISOString().slice(0,10),Y=await Promise.all(bt.map(async M=>{const{data:f}=await k.rpc("get_public_rankings",{_start:L,_end:x,_category:M}),E=f??[];let y=Number.POSITIVE_INFINITY,O=0;const F=E.map(_=>{const A=Number(_.points);return A!==y&&(O+=1,y=A),{..._,_rank:O}}).find(_=>(_.license||"").toLowerCase()===r.toLowerCase());return F?{category:M,rank:F._rank,total:E.length,points:Number(F.points),wins:Number(F.wins),played:Number(F.tournaments_played)}:null}));if(v)return;const h=Y.filter(Boolean);N(h.length?h:null),D(!1)})(),()=>{v=!0}},[i]),e.jsxs(se,{className:"p-4 md:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-3",children:[e.jsxs("h2",{className:"font-display text-xl flex items-center gap-2",children:[e.jsx(tt,{className:"h-5 w-5 text-primary"})," La ligue PADEL AC"]}),e.jsx(de,{variant:"outline",className:"text-[10px] shrink-0",children:"12 derniers mois"})]}),j?e.jsxs("div",{className:"space-y-2","aria-hidden":!0,children:[e.jsx(Ae,{className:"h-14 w-full rounded-lg"}),e.jsx(Ae,{className:"h-14 w-full rounded-lg"})]}):u&&u.length>0?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground -mt-1 mb-1",children:"Classement par catégorie de tournoi"}),[...u].sort((r,v)=>r.rank-v.rank).map(r=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(de,{variant:"secondary",className:"shrink-0",children:r.category}),e.jsxs("div",{className:"text-2xl font-display text-primary leading-none",children:["#",r.rank]}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"du club"})]}),e.jsxs("div",{className:"flex items-center gap-4 text-right shrink-0",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold leading-none",children:r.points}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"pts"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold leading-none",children:r.wins}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"victoires"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold leading-none",children:r.played}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"tournois"})]})]})]},r.category)),e.jsxs(Q,{to:"/ligue",className:"inline-flex items-center gap-1 text-sm font-semibold text-primary pt-1",children:["Voir le classement complet ",e.jsx(ce,{className:"h-4 w-4"})]})]}):e.jsx("div",{className:"text-sm text-muted-foreground",children:i?"Pas encore classé au club â joue ton premier tournoi pour apparaître ici.":"Ajoute ta licence FFT dans ton profil pour apparaître au classement du club."})]})},kt=["P25","P50","P100","P250","P500"],ee=i=>i.toISOString().slice(0,10),be=(i,u)=>new Date(i.getFullYear(),i.getMonth()+u,i.getDate()),ge=i=>new Date(i+"T12:00").toLocaleDateString("fr-FR",{day:"numeric",month:"short",year:"2-digit"});function Ct({userId:i,gender:u,currentRank:N,currentPoints:j}){const[D,r]=n.useState([]),[v,p]=n.useState([]),[L,x]=n.useState(null),[Y,h]=n.useState(!1),[M,f]=n.useState(!1),[E,y]=n.useState(0),[O,P]=n.useState(!1),[F,_]=n.useState(null);n.useEffect(()=>{const t=u==="F"?"F":"H";k.from("fft_rankings").select("snapshot_month").eq("gender",t).order("snapshot_month",{ascending:!1}).limit(1).then(({data:s})=>{var a;return _(((a=s==null?void 0:s[0])==null?void 0:a.snapshot_month)??null)})},[u]);const A=new Date,I=F?(()=>{const[t,s]=F.split("-").map(Number);return new Date(t,s,1)}
7)():new Date(A.getFullYear(),A.getMonth()+1,1),m=ee(be(A,-12)),C=ee(be(I,-12));n.useEffect(()=>{(async()=>{const{data:t}=await k.from("registrations").select("id, player_id, partner_user_id, registration_source, registered_by_staff_id, tournaments(title, category, tournament_date, status)").or(`player_id.eq.${i},partner_user_id.eq.${i}`),s=(t??[]).filter(o=>{var U;return((U=o.tournaments)==null?void 0:U.status)!=="cancelled"&&!(o.registration_source==="phone"&&o.player_id===i&&o.registered_by_staff_id===i&&o.partner_user_id!==i)}),a=s.map(o=>o.id),{data:c}=a.length?await k.from("tournament_results").select("registration_id, final_rank, points").in("registration_id",a):{data:[]},l=new Map(s.map(o=>[o.id,o]));r((c??[]).filter(o=>(o.points??0)>0).map(o=>{const U=l.get(o.registration_id).tournaments;return{id:o.registration_id,title:U.title,category:U.category,date:U.tournament_date,points:o.points,external:!1,place:o.final_rank}}));const{data:d}=await k.from("external_player_results").select("*").eq("user_id",i);P((d??[]).some(o=>o.source==="tenup")),p((d??[]).map(o=>({id:o.id,title:o.title,category:o.category,date:o.tournament_date,points:o.points,external:!0,place:o.place})))})()},[i,E]);const S=n.useMemo(()=>[...D,...v],[D,v]),g=ee(I),T=(t,s=g)=>S.filter(a=>a.date>=t&&a.date<s&&a.date<=ee(A)).sort((a,c)=>c.points-a.points).slice(0,12),$=n.useMemo(()=>T(m),[S,g]),B=n.useMemo(()=>T(C),[S,g]),ne=new Date(I.getFullYear(),I.getMonth()+1,1),re=n.useMemo(()=>S.filter(t=>t.date>=g).sort((t,s)=>t.date.localeCompare(s.date)),[S,g]),me=n.useMemo(()=>T(ee(be(ne,-12)),"9999-12-31"),[S,g]),je=me.reduce((t,s)=>t+s.points,0),z=new Set(me.map(t=>t.id)),R=ne.toLocaleDateString("fr-FR",{month:"long"}),b=t=>t.reduce((s,a)=>s+a.points,0),V=b($),G=b(B),q=new Set(B.map(t=>t.id)),K=$.filter(t=>!q.has(t.id)),ue=B.filter(t=>!$.some(s=>s.id===t.id));n.useEffect(()=>{if(!G){x(null);return}(async()=>{const{rankForPoints:t}=await ze(async()=>{const{rankForPoints:s}=await import("./rankForPoints-CLM0aQiz.js");return{rankForPoints:s}},__vite__mapDeps([0,1,2]));x(await t(u==="F"?"F":"H",G))})()},[G,u]);const[w,W]=n.useState(null),pe=async t=>{await k.from("external_player_results").delete().eq("id",t),y(s=>s+1)},Ne=M?$:$.slice(0,5),X=N&&L?N-L:null,te=I.toLocaleDateString("fr-FR",{month:"long"});return e.jsxs(se,{className:"p-4 md:p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("h2",{className:"font-display text-xl flex items-center gap-2",children:[e.jsx(Me,{className:"h-5 w-5 text-primary"})," Mes 12 meilleurs tournois"]}),e.jsxs(H,{size:"sm",variant:"outline",className:"h-10",onClick:()=>h(!0),children:[e.jsx(mt,{className:"h-4 w-4 mr-1"}),"Ajouter"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground -mt-2",children:["Ton classement FFT = la somme de tes 12 meilleurs tournois des 12 derniers mois."," ",O?"Tes tournois Ten'Up sont déjà récupérés : ajoute seulement ceux qui manquent (ex : joués ce mois-ci, pas encore sur Ten'Up) pour simuler tes prochains classements.":"Ajoute ceux joués hors Padel AC pour un calcul complet."]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded-xl border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"Aujourd'hui (relevé FFT)"}),e.jsxs("div",{className:"text-3xl font-display leading-tight",children:[j??V,e.jsx("span",{className:"text-sm text-muted-foreground",children:" pts"})]}),N?e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Classement actuel #",N.toLocaleString("fr-FR")]}):null]}),e.jsxs("div",{className:"rounded-xl border border-primary/40 bg-primary/5 p-3",children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-primary",children:["Projeté ",te]}),e.jsxs("div",{className:"text-3xl font-display leading-tight text-primary",children:[G,e.jsx("span",{className:"text-sm text-muted-foreground",children:" pts"})]}),L?e.jsxs("div",{className:"text-xs flex items-center gap-1",children:["â #",L.toLocaleString("fr-FR"),X?e.jsxs("span",{className:X>0?"text-emerald-600":"text-destructive",children:["(",X>
70?"+":"",X.toLocaleString("fr-FR")," places)"]}):null]}):null]})]}),j!=null&&j>V&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Ton relevé FFT affiche ",j," pts : il manque sûrement des tournois joués ailleurs, ajoute-les avec « Ajouter »."]}),j!=null&&j<V&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Ton relevé FFT affiche ",j," pts : tes derniers tournois n'y sont pas encore comptés, ils le seront au prochain relevé."]}),(K.length>0||ue.length>0)&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"text-xs font-semibold text-muted-foreground",children:["Changements au 1er ",te]}),K.map(t=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border p-2 text-sm",children:[e.jsx(Le,{className:"h-4 w-4 text-destructive shrink-0"}),e.jsxs("span",{className:"flex-1 truncate",children:[t.title," ",e.jsx("span",{className:"text-xs text-muted-foreground",children:"· sort (plus de 12 mois)"})]}),e.jsxs("span",{className:"font-semibold text-destructive",children:["â",t.points]})]},"l"+t.id)),ue.map(t=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border p-2 text-sm",children:[e.jsx(ae,{className:"h-4 w-4 text-emerald-600 shrink-0"}),e.jsxs("span",{className:"flex-1 truncate",children:[t.title," ",e.jsx("span",{className:"text-xs text-muted-foreground",children:"· entre dans le top 12"})]}),e.jsxs("span",{className:"font-semibold text-emerald-600",children:["+",t.points]})]},"e"+t.id))]}),e.jsxs("div",{className:"space-y-1.5",children:[$.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Aucun tournoi avec des points sur les 12 derniers mois."}),Ne.map((t,s)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border p-2 text-sm",children:[e.jsx("span",{className:"w-5 text-xs text-muted-foreground",children:s+1}),e.jsx(de,{className:`${Pe[t.category]??"bg-muted text-foreground"} border-transparent shrink-0`,children:t.category}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:t.title}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[ge(t.date),t.place?` · ${t.place}e`:""," · ",t.external?"Hors Padel AC":"Padel AC"]})]}),e.jsx("span",{className:"font-semibold",children:t.points}),t.external&&e.jsx("button",{"aria-label":"Supprimer",className:"p-2 text-muted-foreground",onClick:()=>W(t),children:e.jsx(De,{className:"h-4 w-4"})})]},t.id)),$.length>5&&e.jsx(H,{variant:"ghost",className:"w-full h-10",onClick:()=>f(t=>!t),children:M?"Voir moins":`Voir les ${$.length}`}),v.filter(t=>t.date<g&&!$.some(s=>s.id===t.id)).length>0&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[v.filter(t=>t.date<g&&!$.some(s=>s.id===t.id)).length," tournoi(s) ajouté(s) hors top 12 ou trop ancien(s)."]})]}),re.length>0&&e.jsxs("div",{className:"rounded-xl border border-dashed border-primary/40 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-semibold flex items-center gap-1.5",children:[e.jsx(ae,{className:"h-4 w-4 text-primary"})," Prochainement au relevé de ",R]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Joués depuis le 1er ",te," : ils compteront au relevé de ",R,"."]})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsxs("div",{className:"text-xl font-display text-primary leading-none",children:[je,e.jsx("span",{className:"text-xs text-muted-foreground",children:" pts"})]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:["projeté ",R]})]})]}),re.map(t=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border bg-card p-2 text-sm",children:[e.jsx(de,{className:`${Pe[t.category]??"bg-muted text-foreground"} border-transparent shrink-0`,children:t.category}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:t.title}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[ge(t.date),t.place?` · ${t.place}e`:""," · ",z.has(t.id)?"entrera dans ton top 12":"hors top 12"]})]}),e.jsxs("span",{className:`font-semibold ${z.has(t.id)?"text-emerald-600":"text-muted-foreground"}`,children:["+",t.points]}),t.external&&e.jsx("button",{"aria-label":"Supprimer",className:"p-2 text-muted-foreground",onClick:()=>W(t),children:e.jsx(De,{className:"h-4 w-4"})})]},"p"+t.id))]}),e.jsx(St,{open:Y,onOpenChange:h,userId:i,existing:S,onSaved:()=>y(t=>t+1)}),e.jsx(at,{open:!!w,onOpenChange:t=>!t&&W(null),children:e.jsxs(nt,{children:[e.jsxs(rt,{children:[e.jsx(it,{children:"Supprimer ce tournoi ?"}),e.jsxs(lt,{children:[w==null?void 0:w.title," (",w?ge(w.date):"",") · ",w==null?void 0:w.points," pts sera retiré de ta liste."]})]}),e.jsxs(ot,{children:[e.jsx(ct,{className:"min-h-11",children:"Annuler"}),e.jsx(dt,{className:"min-h-11 bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{w&&pe(w.id),W(null)},children:"Supprimer"})]})]})})]})}function St({open:i,onOpenChange:u,userId:N,existing:j,onSaved:D}){const[r,v]=n.useState(""),[p,L]=n.useState("P100"),[x,Y]=n.useState(ee(new Date)),[h,M]=n.useState("16"),[f,E]=n.useState(""),[y,O]=n.useState(""),[P,F]=n.useState(null),[_,A]=n.useState(!1);n.useEffect(()=>{const m=Number(f),C=Number(h);if(!m||!C){F(null);return}(async()=>{const{data:S}=await k.from("points_scale").select("points, valid_to").eq("category",p).eq("rank",m).lte("min_pairs",C).gte("max_pairs",C).lte("valid_from",x),g=(S??[]).find(T=>!T.valid_to||T.valid_to>=x);F(g?g.points:null)})()},[p,h,f,x]);const I=async()=>{const m=Number(y||P||0);if(!m)return he.error("Indique ta place (ou les points gagnés).");const C=j.find(g=>g.category===p&&g.date===x);if(C)return he.error(`Ce tournoi est déjà dans ta liste : ${C.title} (${ge(C.date)}).`);A(!0);const{error:S}=await k.from("external_player_results").insert({user_id:N,title:r.trim()||`${p} hors Padel AC`,category:p,tournament_date:x,pairs:Number(h)||null,place:Number(f)||null,points:m});if(A(!1),S)return he.error("Impossible d'enregistrer le tournoi.");he.success("Tournoi ajouté"),v(""),E(""),O(""),u(!1),D()};return e.jsx(He,{open:i,onOpenChange:u,children:e.jsxs(Ke,{className:"max-w-md",children:[e.jsx(Ue,{children:e.jsx(Ye,{children:"Ajouter un tournoi joué ailleurs"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(le,{className:"h-11",placeholder:"Nom (ex
7: P100 du Country)",value:r,onChange:m=>v(m.target.value)}),e.jsx("div",{className:"flex flex-wrap gap-2",children:kt.map(m=>e.jsx(H,{type:"button",size:"sm",variant:p===m?"default":"outline",className:"h-10",onClick:()=>L(m),children:m},m))}),e.jsxs("div",{className:"grid grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)_minmax(0,1fr)] gap-2",children:[e.jsxs("label",{className:"text-xs text-muted-foreground space-y-1 min-w-0 block",children:["Date",e.jsx(le,{type:"date",className:"h-11 w-full min-w-0 max-w-full appearance-none px-2 text-sm",value:x,max:ee(new Date),onChange:m=>Y(m.target.value)})]}),e.jsxs("label",{className:"text-xs text-muted-foreground space-y-1 min-w-0 block",children:["Paires",e.jsx(le,{type:"number",inputMode:"numeric",className:"h-11",value:h,onChange:m=>M(m.target.value)})]}),e.jsxs("label",{className:"text-xs text-muted-foreground space-y-1 min-w-0 block",children:["Ta place",e.jsx(le,{type:"number",inputMode:"numeric",className:"h-11",value:f,onChange:m=>E(m.target.value)})]})]}),e.jsxs("label",{className:"text-xs text-muted-foreground space-y-1 block",children:["Points gagnés",e.jsx(le,{type:"number",inputMode:"numeric",className:"h-11",placeholder:P!=null?`${P} (calculé avec le barème)`:"Calculé avec ta place",value:y,onChange:m=>O(m.target.value)})]}),P!=null&&!y&&e.jsxs("p",{className:"text-xs text-primary",children:["Barème FFT : ",P," pts"]}),e.jsx(H,{className:"w-full h-11",disabled:_,onClick:I,children:"Ajouter"})]})]})})}const Pt=i=>{const[u,N,j]=i.split("-");return`${j}/${N}/${u.slice(2)}`},$e=()=>new Date().toISOString().slice(0,10),Wt=()=>{var X,te;const{user:i,loading:u,isAdmin:N}=Be(),j=Ve(),{data:D}=Ge(),[r,v]=n.useState(null);n.useEffect(()=>{D&&!r&&v(D)},[D,r]);const[p,L]=n.useState([]),[x,Y]=n.useState([]),[h,M]=n.useState("points"),[f,E]=n.useState(null),[y,O]=n.useState(null),[P,F]=n.useState([]),[_,A]=n.useState([]),[I,m]=n.useState(!1);n.useEffect(()=>{i&&(async()=>{var l;const[{data:t},{data:s}]=await Promise.all([k.from("profiles").select("*").eq("id",i.id).maybeSingle(),k.from("registrations").select("id, player_id, partner_user_id, registration_source, registered_by_staff_id, status, payment_status, forfeit, partner_first_name, partner_last_name, player_first_name, player_last_name, tournaments(id,title,category,gender,tournament_date,start_time,status)").or(`player_id.eq.${i.id},partner_user_id.eq.${i.id}`).order("registered_at",{ascending:!1})]);v(t);const a=(s??[]).filter(d=>!(d.registration_source==="phone"&&d.player_id===i.id&&d.registered_by_staff_id===i.id&&d.partner_user_id!==i.id));L(a);const c=a.map(d=>d.id);if(c.length){const{data:d}=await k.from("tournament_results").select("registration_id, final_rank, points").in("registration_id",c);Y(d??[])}if(t!=null&&t.first_name&&(t!=null&&t.last_name)&&(t!=null&&t.ranking)){const d=ye=>ye.toLowerCase().normalize("NFD").replace(new RegExp("\\p{Diacritic}","gu"),"").replace(/\s+/g," ").trim(),o=d(`${t.last_name} ${t.first_name}`),U=d(`${t.first_name} ${t.last_name}`),{data:J}=await k.from("fft_rankings").select("snapshot_month, rank, points, evolution").in("player_name_normalized",[o,U]).order("snapshot_month",{ascending:!0}),ie=J&&J.length?J[J.length-1]:null,Re=!ie||Number(t.ranking)===ie.rank;if(J&&J.length&&Re)F(J),E({rank:ie.rank,points:ie.points,evolution:ie.evolution??0});else if(t!=null&&t.ranking&&Number.isFinite(Number(t.ranking))){const ye=Number(t.ranking),{data:ve}=await k.from("fft_rankings").select("snapshot_month").order("snapshot_month",{ascending:!1}).limit(1),_e=(l=ve==null?void 0:ve[0])==null?void 0:l.snapshot_month;if(_e){const{data:qe}=await k.from("fft_rankings").select("points").eq("snapshot_month",_e).eq("rank",ye),we=(qe??[]).map(Z=>Z.points).filter(Z=>Number.isFinite(Z));if(we.length>0){const Z=new Map;we.forEach(xe=>Z.set(xe,(Z.get(xe)??0)+1));const Ee=[...Z.entries()].sort((xe,Oe)=>Oe[1]-xe[1])[0][0];O({points:Ee,month:_e})}}}}try{const{data:d}=await k.from("profile_ranking_history").select("snapshot_date, classement, points, estimated").eq("profile_id",i.id).order("snapshot_date",{ascending:!0});d&&d.length?(A(d.map(o=>({date:o.snapshot_date,classement:o.classement,points:o.points,estimated:!!o.estimated}))),m(d.some(o=>o.estimated))):(A([]),m(!1))}catch{}})()},[i]);const C=n.useMemo(()=>{const t=x.length,s=x.filter(l=>l.final_rank===1).length,a=x.filter(l=>l.final_rank<=3).length,c=x.reduce((l,d)=>l+(d.points||0),0);return{finished:t,wins:s,podiums:a,totalPoints:c}},[x]),S=n.useMemo(()=>p.filter(t=>t.tournaments&&t.tournaments.tournament_date>=$e()&&!["withdrawn","rejected","cancelled"].includes(t.status)&&!["pending","canceled"].includes(t.payment_status??"")).sort((t,s)=>t.tournaments.tournament_date.localeCompare(s.tournaments.tournament_date)).slice(0,3),[p]),g=n.useMemo(()=>{const t=new Map(x.map(s=>[s.registration_id,s]));return p.filter(s=>s.tournaments&&s.tournaments.tournament_date<$e()).filter(s=>{var a;return((a=s.tournaments)==null?void 0:a.status)!=="cancelled"}).filter(s=>!["withdrawn","rejected","cancelled","canceled"].includes((s.status??"").toLowerCase())).filter(s=>!["pending","canceled","cancelled","refunded"].includes((s.payment_status??"").toLowerCase())).sort((s,a)=>a.tournaments.tournament_date.localeCompare(s.tournaments.tournament_date)).map(s=>({reg:s,res:t.get(s.id)})).slice(0,10)},[p,x]),[T,$]=n.useState("date"),[B,ne]=n.useState(!1),re=["P25","P50","P100","P250","P500","P1000","P2000"],me=n.useMemo(()=>{const t=g.map(({reg:a,res:c})=>{const l=a.tournaments,o=(a.partner_user_id===(i==null?void 0:i.id)?`${a.player_first_name??""} ${a.player_last_name??""}`:`${a.partner_first_name??""} ${a.partner_last_name??""}`).trim();return{reg:a,t:l,partnerName:o,rank:(c==null?void 0:c.final_rank)??null,pts:(c==null?void 0:c.points)??0}}),s=B?1:-1;return t.sort((a,c)=>{switch(T){case"category":return s*(re.indexOf(a.t.category)-re.indexOf(c.t.category));
7case"title":return s*a.t.title.localeCompare(c.t.title);case"partner":return s*a.partnerName.localeCompare(c.partnerName);case"rank":return s*((a.rank??9999)-(c.rank??9999));case"points":return s*(a.pts-c.pts);default:return s*a.t.tournament_date.localeCompare(c.t.tournament_date)}})},[g,T,B,i==null?void 0:i.id]),je=t=>{t===T?ne(s=>!s):($(t),ne(t==="rank"||t==="title"||t==="partner"||t==="category"))},z=({label:t,sortKey:s,align:a="left",className:c=""})=>e.jsx("th",{className:`px-2 md:px-3 py-2 ${a==="center"?"text-center":a==="right"?"text-right":"text-left"} ${c}`,children:e.jsxs("button",{type:"button",onClick:()=>je(s),className:`inline-flex items-center gap-1 font-semibold uppercase tracking-wider min-h-[36px] ${T===s?"text-foreground":"text-muted-foreground"}`,children:[t,T===s?B?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(Qe,{className:"h-3 w-3"}):e.jsx(_t,{className:"h-3 w-3 opacity-50"})]})}),R=n.useMemo(()=>{const t=l=>new Date(l).toLocaleDateString("fr-FR",{month:"short",year:"2-digit"});if(_.length)return _.map(l=>({label:t(l.date),points:l.points,rank:l.classement})).filter(l=>l.rank!=null||l.points!=null);if(!P.length){const l=r!=null&&r.ranking?Number(r.ranking):null;return l&&!Number.isNaN(l)?[{label:y?t(y.month):new Date().toLocaleDateString("fr-FR",{month:"short",year:"2-digit"}),points:(y==null?void 0:y.points)??null,rank:l}]:[]}const s=P.map(l=>({label:t(l.snapshot_month),points:l.points,rank:l.rank})),a=P[0];if(a&&typeof a.evolution=="number"&&a.evolution!==0){const l=new Date(a.snapshot_month);l.setMonth(l.getMonth()-1),s.unshift({label:l.toLocaleDateString("fr-FR",{month:"short",year:"2-digit"}),points:a.points-a.evolution,rank:null})}const c=new Map(s.map(l=>[l.label,l]));return Array.from(c.values())},[_,P,r,y]),b=n.useMemo(()=>ut(_.map(t=>({snapshot_date:t.date,classement:t.classement,points:t.points})),{rank:(r==null?void 0:r.ranking)!=null&&/^\d+$/.test(String(r.ranking).trim())?Number(r.ranking):null}),[_,r==null?void 0:r.ranking]),V=n.useMemo(()=>R.some(t=>typeof t.points=="number"),[R]),G=n.useRef(!1);n.useEffect(()=>{G.current||R.length>0&&!V&&(M("rank"),G.current=!0)},[R,V]);const q=n.useMemo(()=>{var s;const t=new Map;for(const a of p){if(!i||a.status!=="confirmed"||a.forfeit)continue;const l=a.player_id===i.id?`${a.partner_first_name} ${a.partner_last_name}`.trim():`${a.player_first_name} ${a.player_last_name}`.trim();if(!l)continue;const d=((s=a.tournaments)==null?void 0:s.tournament_date)??"",o=t.get(l)??{name:l,count:0,last:""};o.count+=1,d>o.last&&(o.last=d),t.set(l,o)}return Array.from(t.values()).sort((a,c)=>c.count-a.count||c.last.localeCompare(a.last))},[p,i]),[K,ue]=n.useState(!1),[w,W]=n.useState(""),pe=n.useMemo(()=>{if(!K)return q.slice(0,5);const t=w.trim().toLowerCase();return t?q.filter(s=>s.name.toLowerCase().includes(t)):q},[q,K,w]);if(u)return e.jsx("div",{className:"container py-20 text-center text-muted-foreground",children:"Chargementâ¦"});if(!i)return e.jsx(We,{to:"/auth"});if(!r)return e.jsx("div",{className:"container py-20 text-center text-muted-foreground",children:"Chargement de votre espaceâ¦"});const Ne=`${((X=r.first_name)==null?void 0:X[0])??""}${((te=r.last_name)==null?void 0:te[0])??""}`.toUpperCase();return e.jsxs("div",{className:"container py-6 md:py-10 max-w-5xl space-y-6",children:[(r==null?void 0:r.id)&&e.jsx(st,{userId:r.id}),e.jsxs("div",{className:"rounded-2xl bg-court text-primary-foreground p-5 md:p-8 shadow-court",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(ke,{className:"h-16 w-16 md:h-20 md:w-20 border-2 border-white/30",children:[e.jsx(Xe,{src:r.avatar_url??void 0}),e.jsx(Ce,{className:"bg-white/10 text-primary-foreground text-xl",children:Ne||"?"})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs uppercase tracking-widest opacity-80",children:"Mon espace compétition"}),e.jsxs("h1",{className:"font-display text-2xl md:text-4xl truncate",children:[r.first_name," ",r.last_name]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1 text-sm opacity-90",children:[r.fft_license&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Je,{className:"h-3.5 w-3.5"})," Licence ",r.fft_license]}),(r.ranking||f||b.rank!=null)&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-white/15 px-2 py-0.5 text-xs font-semibold",children:[e.jsx(ae,{className:"h-3 w-3"})," #",b.rank??r.ranking??(f==null?void 0:f.rank)," FFT",(b.points??(f==null?void 0:f.points))!=null&&` · ${b.points??(f==null?void 0:f.points)} pts`]}),b.deltaPlaces!=null&&b.deltaPlaces!==0&&e.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-semibold ${b.deltaPlaces>0?"bg-emerald-400/25":"bg-red-400/25"}`,children:[b.deltaPlaces>0?e.jsx(ae,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"}),b.deltaPlaces>0?"+":"",b.deltaPlaces," places"]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2 md:gap-3 mt-5",children:[e.jsx(fe,{label:"Tournois joués",value:C.finished,icon:e.jsx(Te,{className:"h-4 w-4"})}),e.jsx(fe,{label:"Victoires",value:C.wins,icon:e.jsx(Se,{className:"h-4 w-4"})}),e.jsx(fe,{label:"Podiums",value:C.podiums,icon:e.jsx(pt,{className:"h-4 w-4"})}),e.jsx(fe,{label:"Points gagnés",value:C.totalPoints,icon:e.jsx(Me,{className:"h-4 w-4"})})]})]}),!1,e.jsx(wt,{license:r==null?void 0:r.fft_license}),i&&e.jsx(Ct,{userId:i.id,gender:r==null?void 0:r.gender,currentRank:b.rank,currentPoints:b.points}),e.jsxs(se,{className:"p-4 md:p-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3",children:[e.jsx("h2",{className:"font-display text-xl",children:h==="points"?"Ãvolution de mes points FFT":"Ãvolution de mon classement FFT"}),e.jsxs("div",{className:"inline-flex rounded-full border bg-muted/40 p-0.5 text-xs font-semibold",children:[e.jsx("button",{type:"button",onClick:()=>M("points"),className:`rounded-full px-3 py-1.5 transition-colors ${h==="points"?"bg-primary text-primary-foreground":"text-muted-foreground"}`,children:"Points"}),e.jsx("button",{type:"button",onClick:()=>M("rank"),className:`rounded-full px-3 py-1.5 transition-colors ${h==="rank"?"bg-primary text-primary-foreground":"text-muted-foreground"}`,children:"Classement"})]})]}),R.length===0?e.jsx(oe,{icon:e.jsx(ae,{className:"h-6 w-6"}),title:"Pas de classement FFT trouvé",desc:"Ton classement FFT apparaîtra ici dès qu'on te retrouve dans les données officielles."}):h==="points"&&!V?e.jsx(oe,{icon:e.jsx(ae,{className:"h-6 w-6"}),title:"Points FFT pas encore disponibles",desc:"On a ton classement mais pas encore le détail des points. Bascule sur « Classement » pour voir ton évolution."}):e.jsx("div",{className:"h-56 md:h-72",children:e.jsx(xt,{width:"100%",height:"100%",children:e.jsxs(yt,{data:R,margin:{top:16,right:10,left:-6,bottom:0},children:[e.jsx(ht,{strokeDasharray:"3 3",opacity:.2}),e.jsx(ft,{dataKey:"label",fontSize:11}),e.jsx(gt,{fontSize:11,reversed:h==="rank",domain:h==="rank"?[t=>Math.max(1,Math.floor(t*.95)),t=>Math.ceil(t*1.05)]:["auto","auto"],allowDecimals:!1,width:48}),e.jsx(jt,{formatter:t=>h==="points"?[`${t} pts`,"Points FFT"]:[`#${t}`,"Classement FFT"]}),e.jsx(Nt,{type:"monotone",dataKey:h,stroke:"hsl(var(--primary))",strokeWidth:2.5,dot:{r:4},activeDot:{r:6},connectNulls:!0})]})})}),_.length>0&&I&&e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:"Estimation basée sur ta position dans le classement Padel FFT (profil masqué sur Ten'Up)."})]}),e.jsxs(se,{className:"p-4 md:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"font-display text-xl",children:"Mes proch
7ains tournois"}),e.jsx(H,{asChild:!0,variant:"ghost",size:"sm",className:"gap-1",children:e.jsxs(Q,{to:"/mes-tournois",children:["Tout voir ",e.jsx(ce,{className:"h-3.5 w-3.5"})]})})]}),S.length===0?e.jsx(oe,{icon:e.jsx(Te,{className:"h-6 w-6"}),title:"Aucun tournoi à venir",desc:"Trouvez votre prochain défi parmi les tournois ouverts.",cta:e.jsx(H,{asChild:!0,className:"mt-3 bg-court",children:e.jsx(Q,{to:"/tournois",children:"Voir les tournois"})})}):e.jsx("div",{className:"space-y-3",children:S.map(t=>{const s=t.tournaments;return e.jsxs(Q,{to:`/tournois/${s.id}`,className:"flex items-center gap-3 rounded-lg border p-3 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center min-w-14 rounded-md bg-muted px-2 py-1.5 text-center",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:new Date(s.tournament_date).toLocaleDateString("fr-FR",{month:"short"})}),e.jsx("div",{className:"font-display text-xl leading-none",children:new Date(s.tournament_date).getDate()})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded border ${Fe[s.category]}`,children:s.category}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:s.gender})]}),e.jsx("div",{className:"font-medium truncate",children:s.title}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:["avec ",t.player_id===i.id?`${t.partner_first_name} ${t.partner_last_name}`:`${t.player_first_name} ${t.player_last_name}`]})]}),e.jsx(ce,{className:"h-4 w-4 text-muted-foreground shrink-0"})]},t.id)})})]}),e.jsxs(se,{className:"p-4 md:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"font-display text-xl",children:"Mon palmarès"}),e.jsx(H,{asChild:!0,variant:"ghost",size:"sm",className:"gap-1",children:e.jsxs(Q,{to:"/mes-tournois?tab=past",children:["Historique complet ",e.jsx(ce,{className:"h-3.5 w-3.5"})]})})]}),g.length===0?e.jsx(oe,{icon:e.jsx(Se,{className:"h-6 w-6"}),title:"Pas encore de tournoi terminé",desc:"Vos résultats s'afficheront ici après chaque tournoi."}):e.jsx(e.Fragment,{children:e.jsx("div",{className:"overflow-x-auto -mx-2",children:e.jsxs("table",{className:"w-full text-xs md:text-sm",children:[e.jsx("thead",{className:"text-[10px] md:text-xs",children:e.jsxs("tr",{className:"border-b",children:[e.jsx(z,{label:"Date",sortKey:"date"}),e.jsx(z,{label:"Cat.",sortKey:"category"}),e.jsx(z,{label:"Tournoi",sortKey:"title"}),e.jsx(z,{label:"Partenaire",sortKey:"partner",className:"hidden md:table-cell"}),e.jsx(z,{label:"Class.",sortKey:"rank",align:"center"}),e.jsx(z,{label:"Pts",sortKey:"points",align:"right"})]})}),e.jsx("tbody",{children:me.map(({reg:t,t:s,partnerName:a,rank:c,pts:l})=>{const d=c===1?"ð¥":c===2?"ð¥":c===3?"ð¥":null;return e.jsxs("tr",{onClick:()=>j(`/tournois/${s.id}`),className:"border-b last:border-0 hover:bg-muted/40 transition-colors cursor-pointer active:bg-muted/60",children:[e.jsxs("td",{className:"px-2 md:px-3 py-2.5 whitespace-nowrap text-muted-foreground",children:[e.jsx("span",{className:"md:hidden",children:Pt(s.tournament_date)}),e.jsx("span",{className:"hidden md:inline capitalize",children:et(s.tournament_date)})]}),e.jsx("td",{className:"px-2 md:px-3 py-2.5",children:e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded border ${Fe[s.category]}`,children:s.category})}),e.jsx("td",{className:"px-2 md:px-3 py-2.5",children:e.jsx(Q,{to:`/tournois/${s.id}`,className:"font-medium hover:text-primary",children:s.title})}),e.jsx("td",{className:"px-2 md:px-3 py-2.5 truncate max-w-[180px] hidden md:table-cell",children:a||e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx("td",{className:"px-2 md:px-3 py-2.5 text-center whitespace-nowrap",children:c?e.jsxs("span",{className:"font-display",children:[d&&e.jsx("span",{className:"mr-1",children:d}),c===1?"1er":`${c}e`]}):e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"â"})}),e.jsx("td",{className:"px-2 md:px-3 py-2.5 text-right whitespace-nowrap",children:l>0?e.jsxs("span",{className:"font-bold text-success",children:["+",l]}):e.jsx("span",{className:"text-muted-foreground",children:"â"})})]},t.id)})})]})})})]}),e.jsxs(se,{className:"p-4 md:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"font-display text-xl",children:"Mes partenaires"}),e.jsx(H,{asChild:!0,variant:"ghost",size:"sm",className:"gap-1",children:e.jsxs(Q,{to:"/partenaires",children:["Trouver un partenaire ",e.jsx(ce,{className:"h-3.5 w-3.5"})]})})]}),q.length===0?e.jsx(oe,{icon:e.jsx(vt,{className:"h-6 w-6"}),title:"Pas encore de partenaire",desc:"Inscrivez-vous avec un partenaire ou utilisez le Finder."}):e.jsxs("div",{className:"space-y-2",children:[K&&q.length>5&&e.jsx("input",{value:w,onChange:t=>W(t.target.value),placeholder:"Rechercher un partenaireâ¦",className:"w-full h-11 rounded-lg border bg-background px-3 text-sm"}),pe.map(t=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border p-3",children:[e.jsx(ke,{className:"h-9 w-9",children:e.jsx(Ce,{className:"text-xs bg-muted",children:t.name.split(" ").map(s=>s[0]).join("").slice(0,2).toUpperCase()})}),e.jsx("div",{className:"flex-1 font-medium truncate",children:t.name}),e.jsxs(de,{variant:"secondary",children:[t.count," tournoi",t.count>1?"s":""]})]},t.name)),K&&pe.length===0&&e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:"Aucun partenaire trouvé."}),q.length>5&&e.jsx(H,{variant:"outline",className:"w-full h-11",onClick:()=>{ue(t=>!t),W("")},children:K?"Afficher moins":`Afficher tous mes partenaires (${q.length})`})]})]})]})},fe=({label:i,value:u,icon:N})=>e.jsxs("div",{className:"rounded-xl bg-white/10 backdrop-blur px-3 py-2.5 md:py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] uppercase tracking-wide opacity-80",children:[N," ",e.jsx("span",{className:"truncate",children:i})]}),e.jsx("div",{className:"font-display text-2xl md:text-3xl mt-0.5",children:u})]}),oe=({icon:i,title:u,desc:N,cta:j})=>e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center",children:[e.jsx("div",{className:"mx-auto mb-2 flex h-10 w-10 items-center justify-center rounded-full bg-muted text-muted-foreground",children:i}),e.jsx("div",{className:"font-medium",children:u}),e.jsx("div",{className:"text-sm text-muted-foreground mt-1",children:N}),j]});
7export{Wt 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.