PageSourceSearch

https://mindgolf.ai/assets/OrgChat-DnVrXQDR.js

js mindgolf.ai collected 2026-10-05 14:52:26 UTC 40,828 bytes, 16 lines download raw bytes

1import{r as N,j as e,n as xe,q as pe,m as he}from"./vendor-ahVw9cdH.js";import{a as ge,u as U,b as I,k as fe}from"./query-CeIq2NOR.js";import{Z as ne,O as M,f8 as ye,bC as je,V as O,R as q,dU as ve,eM as V,eN as H,eO as Q,a3 as be,t as E,a7 as W,gB as _e,aH as Ne,cj as we,cx as Ce,cy as ke,cz as Se,cA as Ae,cB as Le,be as Me,bf as De,a9 as Oe,aa as ie,ab as oe,en as Te,af as B,T as ce,eT as z,bg as Pe,c$ as Re,bh as P,ds as le,ep as K,bW as Ee,aE as Be,d9 as qe,aK as Fe,aO as $e,aP as Ie,hJ as Ge,hK as Ke,hL as Ue,da as de,a5 as Ve,a6 as He,hM as Qe,hN as G,hO as We,hP as ze,gh as Je,gi as Ye,gl as Ze,gm as Z,gn as X,b0 as Xe,b1 as es,bY as ss,b3 as ts,az as ee,b4 as as,aj as rs,_ as ns,bB as is,c0 as os,gp as cs,bN as ls,bO as ds,bP as ms,bQ as us,bR as xs,bS as ps,bT as hs,bU as gs,bV as fs,eS as ys,fs as js,bX as se}from"./index-DXi0I5ak.js";import{s as vs,u as bs,a as _s,g as Ns,M as ws,b as Cs,C as ks,c as Ss,d as As,e as Ls,A as Ms,S as Ds,f as Os}from"./ChatLayout-BG9JVo5v.js";import{A as me}from"./archive-restore-g3rke2xo.js";import{u as Ts,O as Ps,C as Rs}from"./CoachExerciseDrawer-B7lyAZNb.js";import{u as Es}from"./useOrgPlayerDetail-D7oymwZh.js";import{C as Bs}from"./CoachRosterRoundEntryDialog-qXDT5AX4.js";import{M as qs}from"./MetricsTriad-CuybctGl.js";import{M as te}from"./MentalScoreCards-rJ3INKf6.js";import{u as Fs,O as $s}from"./useOrgActivityFeed-BLPM9Trf.js";import{S as Is,C as Gs}from"./CourseStatsAnalyticsView-Bs_EIc3Q.js";import{P as Ks}from"./PlayerMentalImpactHeatmapCard-DebSbfRW.js";import{R as Us}from"./RoundScopeLoadingBoundary-BWc5-A9a.js";import{u as Vs}from"./useCommunityBenchmarkData-BCk3n4dv.js";import{S as Hs}from"./SGRankingGrid-ByCFXOBv.js";import{F as Qs}from"./FilterEmptyState-DFgd4Gz6.js";import{L as Ws}from"./layout-grid-DpixKk_C.js";import{A as zs}from"./archive-DZnuCQDg.js";import{O as Js}from"./OrgPageSkeleton-CB7vwaU8.js";import{O as Ys,u as Zs}from"./OrgInviteDialogContext-BRLMIEmZ.js";import{B as Xs,a as et,b as ae,d as st,e as tt,c as at}from"./breadcrumb-C59QT_kB.js";import{u as rt}from"./useOrgPlayers-nTFYOIIv.js";import"./radix--pSzM2y8.js";import"./supabase-DYrB2Yg5.js";import"./charts-CSweoJhv.js";import"./forms-Cc1FL3tT.js";import"./isYesterday-D1Tb--tn.js";import"./isSameDay-CFziqlbR.js";import"./PriorityIndicator-Dc7WZoHC.js";import"./SGImportWizard-M_WQQhmG.js";import"./slider-C_IZaYBN.js";import"./useUnifiedCoachChat-BsErDRXx.js";import"./score-utils-CbzbcqzZ.js";import"./markdown-BiKHWscL.js";import"./CourseCombobox-BysBvuu6.js";import"./command-CK_xWGRQ.js";import"./chevrons-up-down-DYfEac18.js";import"./useExternalSGImport-DBeOARlz.js";import"./elite-sg-applicability-CWAcEzPE.js";import"./useImportProfiles---0LjDzK.js";import"./exceljs.min-CrWE-Rna.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./LikertOptions-BoJtRtBk.js";import"./clipboard-check-DOi-ALrE.js";import"./battery-cUvfyqgx.js";import"./moon-BoHG4F4i.js";import"./wind-DDM9daqs.js";import"./club-constants-CuFYEor4.js";import"./useRoundDetail-pT4ZcXk-.js";import"./TierLegend-eS4dvAPO.js";import"./golf-stat-tiers-B_t78XU2.js";import"./CircularProgress-BuIze6Y1.js";import"./download-B1xImY38.js";import"./useBottomUpKpiCategoryImpacts-DwUJ4siq.js";import"./useBottomUpReadinessMatrix-Bw0kRfNF.js";import"./RecordingQuickViewSheet-BWlxmGo4.js";import"./RecordingChecklistContent-DUePdraQ.js";import"./circle-help-BWJGwUEn.js";import"./calendar-VJ0tAwC5.js";import"./setYear-lX1ccTYE.js";import"./endOfWeek-CvZ6jUGu.js";import"./parseISO-UaVqcKYW.js";import"./ruler-B9FVQEL6.js";import"./save-B9yLpn_M.js";import"./useMentalKPIBenchmark-CyBjbaoP.js";import"./usePlayerBaselineSummary-DsQboNTY.js";import"./goal-profile-to-dashboard-C5sJoTpD.js";import"./canonicalBenchmarkOverlay-CcgraKzh.js";import"./useMentalPerfBenchmark-BHEDYq5Q.js";import"./useWhoopSourceFlag-CUglCXLw.js";import"./MentalScoreJourneyChart-BOGFcl0p.js";import"./InfoTooltip-CpjFUwGS.js";import"./useTrendDefinitions-BxLQgFuE.js";import"./subject-copy-B85nrqvU.js";import"./RoundPreviewCard-68e0NU-r.js";import"./AssignShadowRoundDialog-BPt1pnB4.js";import"./user-check-BZoKlDGY.js";import"./TrendChartEmptyState-BEf0QVo9.js";import"./arrow-up-8F0XduxV.js";import"./TraditionalStatsBenchmarkCard-D21Mv5sK.js";import"./SGComparisonCard-Cdaae3UQ.js";import"./ImpactModeToggle-uvM9Lheq.js";import"./useWhoopSubMetricSGImpact-Bp6cHv_N.js";import"./useReconciledReadinessFactorSGImpact-J0VqM6MF.js";import"./zap-FPBcTry6.js";import"./ShadowAthletePanel-DBvOOaRJ.js";import"./circle-x-gCUm4_Za.js";import"./ProBadge-f4y6d5B9.js";import"./pro-status-ITwCcTPD.js";import"./ProStatusFields-8mC-r4Tv.js";import"./useShadowAthleteMutations-Bl6BIj_J.js";import"./ShadowAvatarUpload-BS-Ep1w_.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const nt=ne("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}
6]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const re=ne("StickyNote",[["path",{d:"M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z",key:"qazsjp"}],["path",{d:"M15 3v4a2 2 0 0 0 2 2h4",key:"40519r"}]]),it=s=>{const t=ge(),m=U({queryKey:["org-staff-conversations",s],queryFn:async()=>{if(!s)return[];const{data:a,error:o}=await M.from("org_conversation_metadata").select(`
12          *,
13          profiles!org_conversation_metadata_player_id_fkey (
14            id, name, avatar_url
15          )
16        `).eq("organization_id",s).order("last_message_at",{ascending:!1});if(o)throw o;return(a||[]).map(c=>({...c,player:c.profiles}))},enabled:!!s,placeholderData:fe});N.useEffect(()=>{if(!s)return;const a=()=>{t.invalidateQueries({queryKey:["org-staff-conversations",s]}),t.invalidateQueries({queryKey:["chat-unread"]})},o=M.channel(`org-staff-conversations-${s}`).on("postgres_changes",{event:"*",schema:"public",table:"org_conversation_metadata",filter:`organization_id=eq.${s}`},a).on("postgres_changes",{event:"INSERT",schema:"public",table:"player_org_messages",filter:`organization_id=eq.${s}`},a).subscribe(d=>{d==="SUBSCRIBED"&&a()}),c=()=>{document.visibilityState==="visible"&&a()};return document.addEventListener("visibilitychange",c),window.addEventListener("focus",c),()=>{M.removeChannel(o),document.removeEventListener("visibilitychange",c),window.removeEventListener("focus",c)}},[s,t]);const u=I({mutationFn:async a=>{await M.from("org_conversation_metadata").update({org_unread_count:0}).eq("organization_id",s).eq("player_id",a)},onSuccess:()=>{t.invalidateQueries({queryKey:["org-staff-conversations",s]}),t.invalidateQueries({queryKey:["chat-unread"]})}}),p=I({mutationFn:async a=>{await M.from("org_conversation_metadata").update({is_archived_by_org:!0}).eq("organization_id",s).eq("player_id",a)},onSuccess:()=>{t.invalidateQueries({queryKey:["org-staff-conversations",s]})}}),i=I({mutationFn:async a=>{await M.from("org_conversation_metadata").update({is_archived_by_org:!1}).eq("organization_id",s).eq("player_id",a)},onSuccess:()=>{t.invalidateQueries({queryKey:["org-staff-conversations",s]})}}),f=(m.data||[]).reduce((a,o)=>a+o.org_unread_count,0);return{conversations:m.data||[],isLoading:m.isLoading,totalUnread:f,markRead:u,archiveConversation:p,unarchiveConversation:i}};function ot({conversations:s,isLoading:t,selectedPlayerId:m,onSelect:u,onUnarchive:p}){const[i,f]=N.useState(""),[a,o]=N.useState("all"),c=s.filter(r=>a==="archived"?r.is_archived_by_org:!r.is_archived_by_org).filter(r=>a==="unread"?r.org_unread_count>0:!0).filter(r=>{var y,j;return i.trim()?(j=(y=r.player)==null?void 0:y.name)==null?void 0:j.toLowerCase().includes(i.toLowerCase()):!0}),d=s.filter(r=>r.is_archived_by_org).length,v=a==="archived"?"No archived conversations":a==="unread"?"No unread messages":"No conversations yet";return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"p-3 space-y-2 border-b",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h2",{className:"text-lg font-bold",children:"Player Messages"})}),e.jsxs("div",{className:"relative",children:[e.jsx(ye,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(je,{placeholder:"Search players...",value:i,onChange:r=>f(r.target.value),className:"pl-9 h-9"})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(O,{size:"sm",variant:a==="all"?"default":"ghost",className:"h-7 text-xs",onClick:()=>o("all"),children:"All"}),e.jsx(O,{size:"sm",variant:a==="unread"?"default":"ghost",className:"h-7 text-xs",onClick:()=>o("unread"),children:"Unread"}),e.jsxs(O,{size:"sm",variant:a==="archived"?"default":"ghost",className:"h-7 text-xs",onClick:()=>o("archived"),children:["Archived",d>0&&` (${d})`]})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:t?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(q,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):c.length===0?e.jsxs("div",{className:"text-center py-8 px-4 space-y-2",children:[e.jsx(ve,{className:"h-8 w-8 text-muted-foreground
16/30 mx-auto"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:v})]}):c.map(r=>{var y,j,g,k;return e.jsxs("button",{onClick:()=>u(r.player_id),className:`w-full flex items-center gap-3 px-3 py-3 hover:bg-muted/50 transition-colors text-left border-b ${m===r.player_id?"bg-muted/50":""}`,children:[e.jsxs(V,{className:"h-10 w-10 flex-shrink-0",children:[((y=r.player)==null?void 0:y.avatar_url)&&e.jsx(H,{src:r.player.avatar_url,alt:((j=r.player)==null?void 0:j.name)||"Player"}),e.jsx(Q,{className:"bg-primary/10 text-primary",children:(g=r.player)!=null&&g.name?r.player.name.charAt(0).toUpperCase():e.jsx(be,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:((k=r.player)==null?void 0:k.name)||"Player"}),e.jsx("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:r.last_message_at?E(new Date(r.last_message_at),{addSuffix:!1}):""})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:vs(r.last_message_preview)||"No messages yet"}),a==="archived"&&p?e.jsx(O,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 ml-1 shrink-0",onClick:C=>{C.stopPropagation(),p(r.player_id)},children:e.jsx(me,{className:"h-3.5 w-3.5 text-muted-foreground"})}):r.org_unread_count>0?e.jsx(W,{className:"h-5 min-w-[20px] flex items-center justify-center text-[10px] rounded-full bg-primary ml-1",children:r.org_unread_count}):null]})]})]},r.player_id)})})]})}function ct(s,t=5){return U({queryKey:["shared-player-memories",s,t],enabled:!!s,queryFn:async()=>{if(!s)return[];const[m,u]=await Promise.all([M.from("manual_memory_entries").select("id, entry_type, title, content, created_at, updated_at, expires_at").eq("user_id",s).eq("is_active",!0).order("updated_at",{ascending:!1}).limit(t*2),M.from("voice_memory_notes").select("id, transcript, created_at").eq("user_id",s).order("created_at",{ascending:!1}).limit(t)]),p=(m.data??[]).map(d=>({id:d.id,kind:"manual",entry_type:d.entry_type,title:d.title,content:d.content,created_at:d.created_at,updated_at:d.updated_at,expires_at:d.expires_at??null})),i=(u.data??[]).map(d=>({id:d.id,kind:"voice",entry_type:"voice",title:"Voice note",content:d.transcript??"",created_at:d.created_at,updated_at:d.created_at,expires_at:null})),f=Date.now(),a=d=>d.kind==="manual"&&!!d.expires_at&&new Date(d.expires_at).getTime()<f,o=[...p,...i].filter(d=>!a(d)).sort((d,v)=>+new Date(v.updated_at)-+new Date(d.updated_at)).slice(0,t),c=p.filter(a).sort((d,v)=>+new Date(v.expires_at??0)-+new Date(d.expires_at??0)).slice(0,t);return[...o,...c]},staleTime:6e4})}const lt=[{key:"overview",label:"Overview",icon:Ws},{key:"mental",label:"Mental",icon:Oe},{key:"sg",label:"SG",icon:ie},{key:"course",label:"Course",icon:oe},{key:"insights",label:"Insights",icon:Te},{key:"impact",label:"Impact",icon:B},{key:"training",label:"Training",icon:ce},{key:"activity",label:"Activity",icon:z}];function dt({playerId:s,organizationId:t,slug:m,open:u,onOpenChange:p,hideMessageCta:i=!1,defaultTab:f="overview"}){const a=xe(),[o,c]=N.useState(!1);_e(()=>p(!1),u);const[d,v]=N.useState(f),{roundFilter:r,customDateRange:y,customN:j,setRoundFilter:g,setCustomDateRange:k,setCustomN:C}=Ne(),[b]=N.useState(we()),{data:x,isLoading:S}=Es({organizationId:t,playerId:s,roundFilter:r,customDateRange:y,customN:j}),w=(x==null?void 0:x.consentStatus)==="accepted",l=(x==null?void 0:x.profile.fullName)||"Player",n=(A,L={})=>{const D=new URLSearchParams({scope:"individual",playerId:s,tab:A,window:r,...L});return r==="custom"&&j&&D.set("n",String(j)),r==="custom"&&y&&(D.set("from",y.from.toISOString()),D.set("to",y.to.toISOString())),`/org/${m}/analytics?${D.toString()}`},_=A=>{p(!1),a(A)};return e.jsxs(Ce,{open:u,onOpenChange:p,children:[e.jsx(ke,{side:"right",className:"w-full sm:max-w-[420px] p-0 flex flex-col gap-0",children:S||!x?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(q,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsxs(e.Fragment,{children:[e.jsx(Se,{className:"px-4 pt-5 pb-3 space-y-3 border-b",children:e.jsxs("div",{className:"flex items-center gap-3 text-left",children:[e.jsxs(V,{className:"h-12 w-12 shrink-0",children:[x.profile.avatarUrl&&e.jsx(H,{src:x.profile.avatarUrl,alt:l}),e.jsx(Q,{className:"bg-primary/10 text-primary text-lg",children:l.charAt(0).toUpperCase()})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(Ae,{className:"truncate",children:l}),e.jsxs(Le,{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(W,{variant:w?"default":"secondary",className:"text-[10px] px-1.5 py-0",children:x.consentStatus}),x.isAnonymized&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Anonymized"}),x.lastActiveDate&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["· ",E(new Date(x.lastActiveDate),{addSuffix:!0})]})]})]})]})}),e.jsxs(Me,{value:d,onValueChange:A=>v(A),className:"flex-1 flex flex-col min-h-0",children:[e.jsx(De,{className:"w-full justify-start gap-0 rounded-none border-b bg-transparent p-0 h-auto overflow-x-auto",children:lt.map(({key:A,label:L,mobileLabel:D,icon:$})=>e.jsxs(Pe,{value:A,className:"flex-col gap-0.5 h-auto py-2 px-3 rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none shrink-0",title:L,children:[e.jsx($,{className:"h-4 w-4"}),e.jsxs("span",{className:"text-[10px] font-medium",children:[e.jsx("span",{className:"sm:hidden",children:D??L}),e.jsx("span",{className:"hidden sm:inline",children:L})]})]},A))}),w&&d!=="overview"&&e.jsx("div",{className:"px-4 pt-3 pb-1 border-b",children:e.jsx(Re,{value:r,onChange:g,customN:j,onCustomNChange:C,customDateRange:y,onCustomDateRangeChange:k,subjectPlayerId:s})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx(Us,{variant:"cards",children:w?e.jsxs(e.Fragment,{children:[e.jsx(P,{value:"overview",className:"m-0 p-4 space-y-3",children:e.jsx(mt,{player:x,playerId:s})}),e.jsxs(P,{value:"mental",className:"m-0 p-4 space-y-4",children:[e.jsx(te,{userId:s,roundFilter:r,customDateRange:y,benchmarkType:b,section:"gauge",subjectMode:"player",playerName:l}),e.jsx(qs,{userId:s,roundFilter:r,customDateRange:y,benchmarkType:b,subjectMode:"player",playerName:l,analyticsBasePath:`/org/${m}/analytics`}),e.jsx(te,{userId:s,roundFilter:r,customDateRange:y,benchmarkType:b,section:"trend",subjectMode:"player",playerName:l}),e.jsx("div",{className:"space-y-2",children:e.jsx(F,{label:"Full mental factor breakdown",onClick:()=>_(n("execution"))})})]}),e.jsx(P,{value:"sg",className:"m-0 p-4 space-y-3",children:e.jsx(xt,{player:x,playerUuid:x.profile.playerId,roundFilter:r,customDateRange:y??void 0,customN:j,benchmarkType:b,onOpen:()=>_(n("benchmark",{benchmarkSubTab:"strokes-gained"}))})}),e.jsx(P,{value:"course",className:"m-0 p-4 space-y-3",children:e.jsx(ht,{roundCount:x.roundCount,playerUuid:x.profile.playerId,roundFilter:r,customDateRange:y??void 0,benchmarkType:b,onOpen:()=>_(n("benchmark",{benchmarkSubTab:"course-stats"}))})}),e.jsx(P,{value:"insights",className:"m-0 p-4 space-y-3",children:e.jsx(pt,{playerId:s,playerName:l,organizationId:t,slug:m,roundFilter:r,customDateRange:y??void 0,customN:j})}),e.jsx(P,{value:"impact",className:"m-0 p-4 space-y-3",children:e.jsx(gt,{roundCount:x.roundCount,playerId:s,roundFilter:r,customDateRange:y,customN:j,onSwitchWindow:g,onOpen:()=>_(n("mental"))})}),e.jsx(P,{value:"training",className:"m-0 p-4 space-y-3",children:e.jsx(ft,{roundCount:x.roundCount,playerUuid:x.profile.playerId,playerName:l,organizationId:t,roundFilter:r,customDateRange:y??void 0,onOpen:()=>_(`/org/${m}/training?player=${s}`)})}),e.jsx(P,{value:"activity",className:"m-0 p-4 space-y-3",children:e.jsx(yt,{playerId:s,playerName:l,slug:m,onClose:()=>p(!1),onOpenFull:()=>_(`/org/${m}/activity?playerId=${s}`)})})]}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"This player hasn't accepted data sharing yet. Tabs will unlock once consent is granted."})})})]}),e.jsx("div",{className:"border-t p-3 flex flex-col gap-2 bg-background",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(O,{className:"flex-1 gap-2",onClick:()=>c(!0),children:[e.jsx(le,{className:"h-4 w-4"}),"Add a new round"]}
16),!i&&e.jsxs(O,{variant:"outline",className:"gap-2",onClick:()=>_(`/org/${m}/chat?player=${s}`),children:[e.jsx(K,{className:"h-4 w-4"}),"Message"]})]})})]})}),x&&e.jsx(Bs,{rosterPlayerId:s,rosterDisplayName:l,organizationId:t,open:o,onOpenChange:c})]})}function mt({player:s,playerId:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-lg border p-3 space-y-2",children:[s.profile.handicap!=null&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(nt,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("span",{children:["Handicap: ",s.profile.handicap]})]}),s.profile.email&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ee,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"truncate",children:s.profile.email})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(z,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("span",{children:[s.roundCount," round",s.roundCount!==1?"s":"",s.lastActiveDate&&e.jsxs(e.Fragment,{children:[" ","· Last active"," ",E(new Date(s.lastActiveDate),{addSuffix:!0})]})]})]}),s.joinedAt&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Joined"," ",new Date(s.joinedAt).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})]}),s.sourceOrgName&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["via ",s.sourceOrgName]})]}),e.jsx(ut,{playerId:t})]})}function ut({playerId:s}){const{data:t,isLoading:m}=ct(s),[u,p]=N.useState(!1),{active:i,expired:f}=N.useMemo(()=>{const o=Date.now(),c=[],d=[];for(const v of t??[])(v.kind==="manual"&&!!v.expires_at&&new Date(v.expires_at).getTime()<o?d:c).push(v);return{active:c,expired:d}},[t]),a=(o,c=!1)=>e.jsxs("li",{className:ee("rounded-md border bg-card/50 p-2 space-y-1",c&&"opacity-60 border-dashed"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[o.kind==="voice"?e.jsx(rs,{className:"h-3 w-3 text-muted-foreground shrink-0"}):e.jsx(re,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-xs font-medium truncate",children:o.title})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:c&&o.expires_at?`Expired ${new Date(o.expires_at).toLocaleDateString()}`:E(new Date(o.updated_at),{addSuffix:!0})})]}),o.content&&e.jsx("p",{className:"text-[11px] text-muted-foreground line-clamp-2",children:o.content}),o.kind==="manual"&&e.jsx(W,{variant:"outline",className:"text-[9px] px-1 py-0 h-3.5",children:o.entry_type})]},`${o.kind}-${o.id}`);return e.jsxs("div",{className:"rounded-lg border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Player's Mental Memory"})]}),m?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(q,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):i.length===0&&f.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No memories shared yet."}):e.jsxs(e.Fragment,{children:[i.length>0&&e.jsx("ul",{className:"space-y-2",children:i.map(o=>a(o,!1))}),f.length>0&&e.jsxs(Xe,{open:u,onOpenChange:p,className:"pt-1",children:[e.jsx(es,{asChild:!0,children:e.jsxs("button",{type:"button",className:"w-full flex items-center justify-between rounded-md border border-dashed bg-muted/30 px-2 py-1.5 text-left hover:bg-muted/50 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[e.jsx(ss,{className:"h-3 w-3"}),"History · ",f.length," expired"]}),e.jsx(ts,{className:ee("h-3.5 w-3.5 text-muted-foreground transition-transform",u&&"rotate-180")})]})}),e.jsx(as,{className:"mt-2",children:e.jsx("ul",{className:"space-y-2",children:f.map(o=>a(o,!0))})})]})]})]})}function xt({player:s,playerUuid:t,roundFilter:m,customDateRange:u,customN:p,benchmarkType:i,onOpen:f}){const{data:a,isLoading:o}
16=qe("year",0,m,u??null,t,p??null),c=Vs(i,"sg",m,u??null,t);return!a||a.totalSG==null?e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center space-y-2",children:[e.jsx(ie,{className:"h-7 w-7 text-muted-foreground/50 mx-auto"}),e.jsx("h3",{className:"text-sm font-medium",children:"Strokes Gained unlocks after first round"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Import a round via CSV to see this player's Strokes Gained breakdown."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Hs,{categoryBreakdown:a.categoryBreakdown,totalSG:a.totalSG,bestRound:a.bestRound,worstRound:a.worstRound,benchmarkType:i,isLoading:o,communityBenchmarkTotal:c.benchmarkTotal,communityBenchmarkCategories:c.benchmarkCategories,communityBenchmarkLabel:c.benchmarkLabel,communityBestRound:c.bestRound,communityWorstRound:c.worstRound,communityIsLoading:c.isLoading,roundFilter:m}),a.perRoundSeries.length>=2&&e.jsx(Is,{rounds:a.perRoundSeries}),e.jsx(F,{label:"Strokes Gained breakdown",onClick:f})]})}function pt({playerId:s,playerName:t,organizationId:m,slug:u,roundFilter:p,customDateRange:i,customN:f}){const[a,o]=N.useState("category"),{data:c}=Fe(s),d=N.useMemo(()=>{if(!(c!=null&&c.length))return[];const l=c.filter(n=>n.processingStatus==="approved");return $e(l.map(n=>({...n,date:n.roundDate})),p,"date",{customDateRange:i,customN:f})},[c,p,i,f,Ie()]),v=d.length,{data:r,isLoading:y}=Ge(p,i,s),{data:j,isLoading:g}=Ke(p,i??null,{overridePlayerId:s}),{data:k,isLoading:C}=Ue(p,i??null,{subjectPlayerId:s}),b=N.useMemo(()=>{const l=d.filter(n=>{var _;return((_=n.metrics)==null?void 0:_.commitment_kpi)!==null});return l.length===0?null:{commitment_kpi:l.reduce((n,_)=>n+(_.metrics.commitment_kpi||0),0)/l.length,emotions_kpi:l.reduce((n,_)=>n+(_.metrics.emotions_kpi||0),0)/l.length,focus_kpi:l.reduce((n,_)=>n+(_.metrics.focus_kpi||0),0)/l.length}},[d]),{recommendations:x}=de(b);if(p!=="last_1"&&v===0)return e.jsx(Qs,{roundFilter:p,context:"round data",variant:"org"});if(v<3)return e.jsx(Ve,{className:"border-dashed",children:e.jsxs(He,{className:"py-6 text-center space-y-2",children:[e.jsx(B,{className:"h-7 w-7 text-muted-foreground/50 mx-auto"}),e.jsx("h3",{className:"text-sm font-medium",children:"Not enough rounds for insights"}),e.jsxs("p",{className:"text-xs text-muted-foreground max-w-xs mx-auto",children:["Assistant insights require at least 3 rounds. This player has ",v," round",v!==1?"s":""," in this timeframe. Try a wider date range."]})]})});const w={playerId:s,playerName:t||"Player",organizationId:m,chatRoute:`/org/${u}/chat?player=${s}`};return e.jsx("div",{className:"space-y-4",children:a==="category"?e.jsx(Qe,{insights:r??[],eliteInsights:j??[],eliteLoading:g,isLoading:y,roundCount:v,roundFilter:p,recommendations:x,headerSlot:e.jsx(G,{value:a,onChange:o}),coachShareTarget:w}):a==="reflection"?e.jsx(We,{userId:s,headerSlot:e.jsx(G,{value:a,onChange:o}),isCoachView:!0,coachShareTarget:w}):e.jsx(ze,{insights:(k==null?void 0:k.insights)??[],isLoading:C,roundCount:(k==null?void 0:k.roundCount)??v,viewerRole:"coach_player",headerSlot:e.jsx(G,{value:a,onChange:o}),coachShareTarget:w})})}function ht({roundCount:s,playerUuid:t,roundFilter:m,customDateRange:u,benchmarkType:p,onOpen:i}){return s<1?e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center space-y-2",children:[e.jsx(oe,{className:"h-7 w-7 text-muted-foreground/50 mx-auto"}),e.jsx("h3",{className:"text-sm font-medium",children:"Course stats unlock after first round"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Once this player records or imports their first roun
16d, course stats will appear here."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Gs,{roundFilter:m,customDateRange:u,playerIds:[t],benchmarkType:p}),e.jsx(F,{label:"Open course stats",onClick:i})]})}function gt({roundCount:s,playerId:t,roundFilter:m,customDateRange:u,customN:p,onSwitchWindow:i,onOpen:f}){return s<3?e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center space-y-2",children:[e.jsx(B,{className:"h-7 w-7 text-muted-foreground/50 mx-auto"}),e.jsx("h3",{className:"text-sm font-medium",children:"Not enough rounds yet"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Mental Impact analysis unlocks after 3 matched rounds. This player has ",s,"."]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ks,{playerId:t,roundFilter:m,customDateRange:u,customN:p,onSwitchWindow:i}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Tap a cell on the analytics page for per-category attribution and contributor drilldowns."}),e.jsx(F,{label:"Open full Mental Impact",onClick:f})]})}function ft({roundCount:s,playerUuid:t,playerName:m,organizationId:u,roundFilter:p,customDateRange:i,onOpen:f}){const[a,o]=N.useState(!1),c=N.useMemo(()=>[t],[t]),{exercises:d,isLoading:v}=Je(c),{recommendations:r,isLoading:y}=de(null,{limit:30,userId:t}),j=v||y,{data:g=[]}=Ye(u,c),{data:k=[]}=Ts(u),C=N.useMemo(()=>new Set(g.map(w=>w.exercise_id)),[g]),b=N.useMemo(()=>{const w=new Map;for(const l of d)w.set(l.exercise.id,l);for(const l of r)w.has(l.exercise.id)||w.set(l.exercise.id,{...l,playerCount:1,playerIds:[t]});for(const l of g){if(w.has(l.exercise_id))continue;const n=Ze(l.exercise_id);n&&w.set(l.exercise_id,{exercise:n,reason:n.description,priority:0,sgImpactPotential:0,relatedMetric:n.targetKpis[0]||"focus",relatedCategory:void 0,isDataBacked:!1,applicableCategories:X(n),targetContributors:Z(n),playerCount:1,playerIds:[t]})}for(const l of k)w.has(l.id)||w.set(l.id,{exercise:l,reason:l.description,priority:0,sgImpactPotential:0,relatedMetric:l.targetKpis[0]||"focus",relatedCategory:void 0,isDataBacked:!1,applicableCategories:X(l),targetContributors:Z(l),playerCount:1,playerIds:c});return Array.from(w.values()).sort((l,n)=>n.priority-l.priority)},[d,r,g,k,t,c]);if(s<3)return e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center space-y-2",children:[e.jsx(ce,{className:"h-7 w-7 text-muted-foreground/50 mx-auto"}),e.jsx("h3",{className:"text-sm font-medium",children:"Training unlocks after 3 rounds"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Personalized exercises unlock once this player has recorded 3 matched rounds. Currently at ",s,"."]})]});const x=new Map([[t,m]]),S=()=>{};return e.jsxs(e.Fragment,{children:[e.jsxs(O,{variant:"outline",size:"sm",className:"w-full gap-1.5",onClick:()=>o(!0),children:[e.jsx(le,{className:"h-4 w-4"}),"Create exercise for ",m]}),j?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(q,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):b.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center space-y-2",children:[e.jsx(B,{className:"h-7 w-7 text-muted-foreground/50 mx-auto"}),e.jsx("h3",{className:"text-sm font-medium",children:"No exercises yet"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Recommendations appear once ",m," has enough data, or create a custom exercise above."]})]}):e.jsx(Ps,{exercises:b,recommendedExerciseIds:C,onToggleRecommend:S,playerMap:x,onViewExercise:f}),e.jsx(F,{label:"Open training & assign exercises",onClick:f}),e.jsx(Rs,{open:a,onOpenChange:o,organizationId:u,players:[{player_id:t,full_name:m}]})]})}function yt({playerId:s,playerName:t,slug:m,onClose:u,onOpenFull:p}){const{feed:i,isLoading:f}=Fs([s],[s]),a=i.filter(c=>c.type==="round"),o=new Map([[s,t]]);return f?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(q,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):a.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center space-y-2",children:[e.jsx(z,{className:"h-7 w-7 text-muted-foreground/50 mx-auto"}),e.jsx("h3",{className:"text-sm font-medium",children:"No rounds in selected timeframe"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Once this player records or imports a round, it will appear here."})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{onClickCapture:u,children:e.jsx($s,{items:a,playerNameMap:o,orgSlug:m})}),e.jsx(F,{label:"Open full activity",onClick:p})]})}function F({label:s,onClick:t}){return e.jsxs("button",{onClick:t,className:"w-full flex items-center justify-between rounded-lg border p-3 text-sm hover:bg-accent/50 transition-colors",children:[e.jsx("span",{className:"font-medium",children:s}),e.jsx(Be,{className:"h-4 w-4 text-muted-foreground"})]})}function jt(s,t){const m=s.toLowerCase();if(m.includes("@mindgolf")||m.startsWith("mindgolf,")||m.startsWith("mindgolf "))return!0;
16if(t.length>0){const u=t[t.length-1];if(u.sender_type==="system"||u.message_type==="ai_assist")return!0}return!1}function vt({conversation:s,organizationId:t,slug:m,onBack:u,onArchive:p,onUnarchive:i}){var J,Y;const[f,a]=N.useState(""),[o,c]=N.useState(!1),[d,v]=N.useState(!1),[r,y]=N.useState(!1),j=s.player_id,g=((J=s.player)==null?void 0:J.name)||"Player",k=N.useRef(s.org_unread_count||0),{messages:C,isLoading:b,sendMessage:x}=bs(j,t,"org_staff");N.useEffect(()=>{if(C.length>0){const h=C[C.length-1];(h.sender_type==="system"||h.message_type==="ai_assist")&&r&&y(!1)}},[C.length]),N.useEffect(()=>{(async()=>{const{data:{user:T}}=await M.auth.getUser();T&&await M.from("notifications").update({read_at:new Date().toISOString()}).eq("user_id",T.id).eq("type","player_message_received").is("read_at",null)})()},[j,C.length]);const S=_s(f,a),w=N.useRef(null),l=ns("MINDGOLF_CHAT_ASSISTANT_INVOCATION_ENABLED"),{data:n}=Ns(j,t,!0),_=!!s.isPending,A=(n==null?void 0:n.consentOn)===!0&&!_&&C.length>0,L=()=>{if(!f.trim())return;const h=f.trim(),T=l&&jt(h,C);x.mutate({content:h,senderType:"org_staff"},{onSuccess:()=>{a(""),T&&(y(!0),M.functions.invoke("generate-chat-assists",{body:{player_id:j,organization_id:t,invoker_role:"org_staff"}}).then(({error:R})=>{R&&(console.error("[MindGolf assist] invoke error",R),y(!1))}).catch(R=>{console.error("[MindGolf assist] invoke threw",R),y(!1)}))}})},D=e.jsxs("div",{className:"flex items-center gap-3 p-3 border-b bg-card",children:[u&&e.jsx(O,{size:"icon",variant:"ghost",onClick:u,className:"h-8 w-8",children:e.jsx(is,{className:"h-4 w-4"})}),e.jsxs("button",{type:"button",className:"group flex items-center gap-3 min-w-0 rounded-md px-2 py-1 -mx-1 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring transition-colors cursor-pointer",onClick:()=>c(!0),title:"View player profile","aria-label":`View ${g}'s profile`,children:[e.jsxs(V,{className:"h-10 w-10",children:[((Y=s.player)==null?void 0:Y.avatar_url)&&e.jsx(H,{src:s.player.avatar_url,alt:g}),e.jsx(Q,{className:"bg-primary/10 text-primary",children:g.charAt(0).toUpperCase()})]}),e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-left truncate text-primary group-hover:underline",children:g}),e.jsx(os,{className:"h-3.5 w-3.5 text-primary flex-shrink-0"})]})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[A&&e.jsx(O,{size:"icon",variant:"ghost",className:"h-8 w-8 text-muted-foreground",onClick:()=>v(!0),title:"Conversation summary",children:e.jsx(cs,{className:"h-4 w-4"})}),!_&&e.jsxs(ls,{children:[e.jsx(ds,{asChild:!0,children:e.jsx(O,{size:"icon",variant:"ghost",className:"h-8 w-8 text-muted-foreground",children:s.is_archived_by_org?e.jsx(me,{className:"h-4 w-4"}):e.jsx(zs,{className:"h-4 w-4"})})}),e.jsxs(ms,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:s.is_archived_by_org?"Unarchive conversation?":"Archive conversation?"}),e.jsx(ps,{children:s.is_archived_by_org?"This conversation will be moved back to your All tab.":"This conversation will be moved to your Archived tab. You can unarchive it anytime."})]}),e.jsxs(hs,{children:[e.jsx(gs,{children:"Cancel"}),e.jsx(fs,{onClick:s.is_archived_by_org?i:p,children:s.is_archived_by_org?"Unarchive":"Archive"})]})]})]})]})]}),$=e.jsx("div",{className:"border-t bg-card",children:e.jsx(ws,{ref:S.inputRef,value:f,onChange:S.bind.onChange,onKeyUp:S.bind.onKeyUp,onKeyDown:h=>{S.onKeyDown(h,T=>{var R;return((R=w.current)==null?void 0:R.call(w,T))??!1})},onSend:L,isSending:x.isPending,placeholder:l?"Type a message... @mindgolf for help":"Type a message...",overlay:e.jsx(Cs,{query:S.query,onSelect:h=>{h===""?S.dismiss():S.applyMention(h)},onActiveKey:h=>{w.current=h}})})}),ue=h=>{var T;return h.sender_type==="system"||h.message_type==="ai_assist"?e.jsx("div",{id:`m-${h.id}`,className:"flex justify-center",children:e.jsxs("div",{className:"max-w-[85%] rounded-lg px-3 py-2 text-sm bg-violet-500/5 border border-violet-500/20",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-violet-600 dar
16k:text-violet-400 font-medium mb-1",children:[e.jsx(B,{className:"h-3 w-3"}),"MindGolf Assistant"]}),e.jsx("p",{className:"text-foreground",children:h.content}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:E(new Date(h.created_at),{addSuffix:!0})}),e.jsx(Ms,{text:h.content,messageId:h.id,surface:"b2b"})]})}):h.message_type==="insight_share"&&h.shared_insight_data?e.jsx("div",{id:`m-${h.id}`,className:`flex ${h.sender_type==="org_staff"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:"max-w-[80%] space-y-1",children:[e.jsx(Ds,{insightData:h.shared_insight_data,content:h.content}),h.content&&h.content!==((T=h.shared_insight_data)==null?void 0:T.insight)&&e.jsx("div",{className:`rounded-lg px-3 py-2 text-sm ${h.sender_type==="org_staff"?"bg-primary text-primary-foreground":"bg-muted"}`,children:e.jsx("p",{children:h.content})}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:E(new Date(h.created_at),{addSuffix:!0})})]})}):e.jsx("div",{id:`m-${h.id}`,className:`flex ${h.sender_type==="org_staff"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] rounded-lg px-3 py-2 text-sm ${h.sender_type==="org_staff"?"bg-primary text-primary-foreground":"bg-muted"}`,children:[e.jsx("p",{className:"whitespace-pre-wrap break-words",children:h.content}),e.jsx("p",{className:"text-[10px] opacity-60 mt-1",children:E(new Date(h.created_at),{addSuffix:!0})})]})})};return e.jsxs(e.Fragment,{children:[e.jsx(ks,{header:D,composer:$,onBack:u,children:e.jsx(Ss,{messages:C,renderMessage:ue,loading:b,initialUnreadCount:k.current,loadingNode:e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(q,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),emptyNode:e.jsx(As,{playerId:j,organizationId:t,viewerRole:"org_staff",onPick:a}),footer:r?e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"max-w-[85%] rounded-lg px-3 py-2 text-sm bg-violet-500/5 border border-violet-500/20",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-violet-600 dark:text-violet-400 font-medium",children:[e.jsx(B,{className:"h-3 w-3 animate-pulse"}),"MindGolf Assistant is thinking..."]})})}):null})}),e.jsx(dt,{playerId:j,organizationId:t,slug:m,open:o,onOpenChange:c,hideMessageCta:!0}),e.jsx(Ls,{open:d,onOpenChange:v,playerId:j,organizationId:t,viewerRole:"coach"})]})}const or=()=>{const{slug:s}=pe(),[t,m]=he(),u=t.get("player"),p=b=>{const x=new URLSearchParams(t);b?x.set("player",b):x.delete("player"),m(x,{replace:!1})};N.useEffect(()=>{if(!u)return;const b=window.location.hash;if(!b.startsWith("#m-"))return;const x=setTimeout(()=>{const S=document.getElementById(b.slice(1));S==null||S.scrollIntoView({behavior:"smooth",block:"center"})},400);return()=>clearTimeout(x)},[u]);const{data:i,isLoading:f}=U({queryKey:["org-by-slug",s],queryFn:async()=>{const{data:b,error:x}=await M.from("organizations").select("id, name").eq("slug",s).single();if(x)throw x;return b},enabled:!!s}),{conversations:a,isLoading:o,markRead:c,archiveConversation:d,unarchiveConversation:v}=it(i==null?void 0:i.id),{data:r,isLoading:y}=rt({organizationId:i==null?void 0:i.id,consentFilter:"accepted"}),j=N.useMemo(()=>{const b=((r==null?void 0:r.players)||[]).filter(n=>n.kind!=="shadow"),x=new Map(b.map(n=>[n.player_id,n])),S=new Set(a.map(n=>n.player_id)),w=a.map(n=>{var A,L,D;const _=x.get(n.player_id);return _?{...n,player:{id:((A=n.player)==null?void 0:A.id)||_.player_id,name:_.full_name||((L=n.player)==null?void 0:L.name)||"Player",avatar_url:_.avatar_url||((D=n.player)==null?void 0:D.avatar_url)||void 0}}:n}),l=b.filter(n=>!S.has(n.player_id)).map(n=>({id:null,player_id:n.player_id,organization_id:(i==null?void 0:i.id)||"",last_message_at:null,last_message_preview:null,player_unread_count:0,org_unread_count:0,is_archived_by_player:!1,is_archived_by_org:!1,isPending:!0,player:{id:n.player_id,name:n.full_name||"Player",avatar_url:n.avatar_url||void 0}})).sort((n,_)=>{var A,L;return(((A=n.player)==null?void 0:A.name)||"").localeCompare(((L=_.player)==null?void 0:L.name)||"")});return[...w,...l]},[a,r==null?void 0:r.players,i==null?void 0:i.id]),g=j.find(b=>b.player_id===u);N.useEffect(()=>{u&&g&&!g.isPending&&g.org_unread_count>0&&c.mutate(u)},[u,g==null?void 0:g.id,g==null?void 0:g.org_unread_count,g==null?void 0:g.isPending]);const k=f||o||y,C=e.jsxs(e.Fragment,{children:[e.jsx(Xs,{children:e.jsxs(et,{children:[e.jsx(ae,{children:e.jsx(st,{href:ys(s||""),children:"Home"})}),e.jsx(tt,{}),e.jsx(ae,{children:e.jsx(at,{children:"Chat"})})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx(K,{className:"h-5 w-5 text-primary"}),e.jsx("h1",{className:"text-xl font-bold",children:"Chat"})]}),e.jsx("p",{className:"text-sm text-muted-foreground -mt-2",children:"Message connected players, share insights, and keep coaching conversations in one place."})]});return k?e.jsxs("div",{className:"space-y-4",children:[C,e.jsx(Js,{contentRows:3})]}):j.length===0?e.jsx(Ys,{organizationId:i==null?void 0:i.id,children:e.jsxs("div",{className:"space-y-4",children:[C,e.jsx(bt,{})]})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:`${u?"hidden md:block":""} space-y-4`,children:C}),e.jsx(Os,{isThreadOpen:!!g&&!!i,list:e.jsx(ot,{conversations:j,isLoading:!1,selectedPlayerId:u,onSelect:p,onUnarchive:b=>v.mutate(b)}),thread:g&&i?e.jsx(vt,{conversation:g,organizationId:i.id,slug:s,onBack:()=>p(null),onArchive:()=>{d.mutate(g.player_id),p(null)},onUnarchive:()=>{v.mutate(g.player_id),p(null)}}):null,placeholder:e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(K,{className:"h-12 w-12 text-muted-foreground
16/20 mx-auto"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a conversation"})]})})})]})},bt=()=>{const{openInviteDialog:s,openShadowAthleteDialog:t}=Zs();return e.jsx(js,{page:"org-chat",hideProgress:!0,ctaOverride:{label:"Invite players",icon:se,onClick:s},secondaryCta:{label:"Create shadow athlete",icon:se,onClick:t}})};export{or 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.