1import{K as L,a as R,r as i,s as o,j as e,B as p,L as D,al as U,Z as k,g as _,S as N,am as z,an as G,ao as J,T as O,D as H,h as K,_ as Z,i as Q,a1 as V,q as c}from"./index-DnLpPdJu.js";import{B as v}from"./badge-Ci6bMlns.js";import{T as A}from"./textarea-BGHgl9MJ.js";import{f as W}from"./tournaments-BXkCUYTe.js";import{A as X}from"./arrow-left-Br53sykA.js";import{S as Y}from"./scale--t5cMFVs.js";import{U as ee}from"./users-round-BlHgCQgv.js";import{M as se}from"./map-pin-ByK1t2i2.js";import{S as te}from"./send-DeHfzYDf.js";const F=t=>t==="droite"?"Droite":t==="gauche"?"Gauche":t==="indifferent"?"Indifférent":"â",ue=()=>{const{id:t}=L(),{user:a}=R(),[m,f]=i.useState(null),[u,I]=i.useState([]),[M,b]=i.useState(!0),[x,j]=i.useState(!1),[g,y]=i.useState(""),[P,w]=i.useState({}),[r,h]=i.useState(null),[S,C]=i.useState("");i.useEffect(()=>{!t||!a||(async()=>{b(!0);const[{data:s},{data:n},{data:l},{data:E}]=await Promise.all([o.from("tournaments").select("*").eq("id",t).maybeSingle(),o.from("partner_search").select("*").eq("tournament_id",t).eq("user_id",a.id).maybeSingle(),o.from("partner_invitations").select("to_user_id,status").eq("tournament_id",t).eq("from_user_id",a.id),o.rpc("find_partners_for_tournament",{_tournament_id:t,_limit:30})]);f(s),j(!!n),y((n==null?void 0:n.message)??"");const T={};l==null||l.forEach(q=>T[q.to_user_id]=q.status),w(T),I(E??[]),b(!1)})()},[t,a]);const $=async()=>{if(!(!a||!t))if(x){const{error:s}=await o.from("partner_search").delete().eq("tournament_id",t).eq("user_id",a.id);if(s)return c.error(s.message);j(!1),c.success("Tu n'apparais plus dans les recherches")}else{const{error:s}=await o.from("partner_search").upsert({tournament_id:t,user_id:a.id,message:g||null},{onConflict:"tournament_id,user_id"});if(s)return c.error(s.message);j(!0),c.success("Tu apparais maintenant dans les recherches !")}},B=async()=>{if(!a||!t||!r)return;const{error:s}=await o.from("partner_invitations").insert({tournament_id:t,from_user_id:a.id,to_user_id:r.user_id,message:S||null,compatibility_score:r.score.total,status:"pending"});if(s)return c.error(s.message);w(n=>({...n,[r.user_id]:"pending"})),c.success(`Invitation envoyée à ${r.first_name} !`),h(null),C("")};return a?M||!m?e.jsx("div",{className:"container py-20 text-center text-muted-foreground",children:"Chargementâ¦"}):e.jsx(U,{children:e.jsxs("div",{className:"container py-8 max-w-5xl",children:[e.jsxs(D,{to:`/tournois/${t}`,className:"inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground mb-4",children:[e.jsx(X,{className:"h-4 w-4"})," Retour au tournoi"]}),e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(k,{className:"h-5 w-5 text-court"}),e.jsx("span",{className:"text-xs uppercase tracking-widest text-court font-bold",children:"Finder de partenaire"})]}),e.jsx("h1",{className:"font-display text-3xl md:text-4xl",children:m.title}),e.jsx("p",{className:"text-muted-foreground capitalize text-sm mt-1",children:W(m.tournament_date)})]}),e.jsx(_,{className:"p-5 mb-6 bg-gradient-to-br from-court/5 to-accent/5 border-court/30",children:e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex-1 min-w-[200px]",children:[e.jsxs("h3",{className:"font-display text-xl mb-1 flex items-center gap-2",children:[e.jsx(N,{className:"h-4 w-4"}),"Je cherche un partenaire"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active cette option pour apparaître en tête des recherches des autres joueurs."}),x&&e.jsx(A,{value:g,onChange:s=>y(s.target.value),onBlur:async()=>{await o.from("partner_search").update({message:g||null}).eq("tournament_id",t).eq("user_id",a.id)},placeholder:"Optionnel : un mot pour les autres joueurs (style de jeu, dispoâ¦)",className:"mt-3"})]}),e.jsx(p,{onClick:$,variant:x?"outline":"default",className:x?"":"bg-court",children:x?"Désactiver":"Je cherche un partenaire"})]})}),e.jsx("h2",{className:"font-display text-2xl mb-4",children:"Partenaires recommandés"}),u.length===0?e.jsx(_,{className:"p-8 text-center text-muted-foreground",children:"Aucun joueur disponible pour ce tournoi pour le moment."}):e.jsx("div",{className:"space-y-3",children:u.map(s=>{const n=P[s.user_id],l=s.score.fft_points_a!=null&&s.score.fft_points_b!=null?Math.abs(s.score.fft_points_a-s.score.fft_points_b):null;return e.jsx(_,{className:"p-4 hover:shadow-md transition-shadow",children:e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex-shrink-0 w-14 h-14 roun
1ded-full bg-gradient-to-br from-court to-accent flex items-center justify-center text-primary-foreground font-display text-lg",children:[s.first_name[0],s.last_name[0]]}),e.jsxs("div",{className:"flex-1 min-w-[180px]",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"font-semibold",children:[s.first_name," ",s.last_name]}),s.is_searching&&e.jsxs(v,{variant:"outline",className:"border-court text-court text-xs",children:[e.jsx(N,{className:"h-3 w-3 mr-1"})," cherche aussi"]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground mt-1 flex-wrap",children:[s.score.fft_points_b!=null&&e.jsxs("span",{children:[s.score.fft_points_b," pts FFT"]}),s.ranking&&e.jsxs("span",{children:["· classement ",s.ranking]}),e.jsxs("span",{children:["· côté ",F(s.preferred_side)]}),s.score.history_count>0&&e.jsxs(v,{variant:"secondary",className:"text-xs",children:[s.score.history_count," match",s.score.history_count>1?"s":""," ensemble",s.score.history_wins>0?` · ${s.score.history_wins} ð`:""]})]})]}),e.jsxs(z,{children:[e.jsx(G,{asChild:!0,children:e.jsxs("div",{className:"flex flex-col items-center cursor-help",children:[e.jsx("div",{className:`text-3xl font-display ${s.score.total>=75?"text-court":s.score.total>=55?"text-accent":"text-muted-foreground"}`,children:s.score.total}),e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"compat."})]})}),e.jsx(J,{side:"left",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsx("div",{className:"font-bold mb-2 text-sm",children:"Détail du score"}),e.jsx(d,{icon:e.jsx(Y,{className:"h-3 w-3"}),label:"Niveau",val:s.score.level,max:30,sub:l!=null?`écart ${l} pts FFT`:void 0}),e.jsx(d,{icon:e.jsx(O,{className:"h-3 w-3"}),label:"Forme",val:s.score.form,max:20}),e.jsx(d,{icon:e.jsx(ee,{className:"h-3 w-3"}),label:"Côté G/D",val:s.score.side,max:20,sub:`${F(s.preferred_side)}`}),e.jsx(d,{icon:e.jsx(k,{className:"h-3 w-3"}),label:"Alchimie",val:s.score.history,max:15,sub:s.score.history_count?`${s.score.history_count} match(s)`:"jamais joué"}),e.jsx(d,{icon:e.jsx(se,{className:"h-3 w-3"}),label:"Social",val:s.score.social,max:10}),e.jsx(d,{icon:e.jsx(N,{className:"h-3 w-3"}),label:"Intention",val:s.score.intent,max:5})]})})]}),n?e.jsx(v,{variant:n==="accepted"?"default":"secondary",children:n==="pending"?"Invitation envoyée":n==="accepted"?"Acceptée â":n==="declined"?"Refusée":"Annulée"}):e.jsxs(p,{size:"sm",onClick:()=>h(s),className:"bg-court",children:[e.jsx(te,{className:"h-3 w-3 mr-1"})," Proposer"]})]})},s.user_id)})}),e.jsx(H,{open:!!r,onOpenChange:s=>!s&&h(null),children:e.jsxs(K,{children:[e.jsx(Z,{children:e.jsxs(Q,{children:["Proposer une équipe à ",r==null?void 0:r.first_name]})}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Score de compatibilité : ",e.jsxs("span",{className:"font-bold text-court",children:[r==null?void 0:r.score.total,"/100"]})]}),e.jsx(A,{value:S,onChange:s=>C(s.target.value),placeholder:"Un petit mot (optionnel) : ton style, pourquoi tu proposesâ¦",rows:4}),e.jsxs(V,{children:[e.jsx(p,{variant:"outline",onClick:()=>h(null),children:"Annuler"}),e.jsx(p,{className:"bg-court",onClick:B,children:"Envoyer l'invitation"})]})]})})]})}):e.jsxs("div",{className:"container py-20 text-center",children:[e.jsx("p",{className:"mb-4",children:"Connecte-toi pour utiliser le Finder."}),e.jsx(p,{asChild:!0,className:"bg-court",children:e.jsx(D,{to:"/auth",children:"Se connecter"})})]})},d=({icon:t,label:a,val:m,max:f,sub:u})=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[t,e.jsx("span",{children:a}),u&&e.jsxs("span",{className:"text-muted-foreground",children:["· ",u]})]}),e.jsxs("span",{className:"font-mono",children:[m,"/",f]})]});export{ue 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.