1import{r as c,j as e}from"./react-NqbtPKX2.js";import{a$ as b,a1 as U,n as _,b0 as i,b1 as B,A as T,b2 as S,b3 as A,b4 as K,k as w,b5 as y,b6 as Y,b7 as G,b8 as O,b9 as L,ba as W,bb as z,F as Q}from"../app.js";import"./firebase-app-check-CIcxtdQQ.js";import"./firebase-core-jbjb5lj7.js";import"./firebase-storage-DPmt4kV5.js";import"./archive-d6nEYruE.js";import"./firebase-auth-DyJV_xjV.js";function k(n){return`/profile/friends/user/${encodeURIComponent(n)}`}function V(n){const t=n.highlight,a=t?.user?.displayName||t?.user?.handle||"";switch(t?.type){case"incomingRequest":return i("FRIENDS_HIGHLIGHT_REQUEST","%@ wants to be friends",[a]);case"rhythmAtRisk":return i("FRIENDS_HIGHLIGHT_RHYTHM","%@ needs your support today",[a]);case"encouragement":return i("FRIENDS_HIGHLIGHT_ENCOURAGEMENT","%@ sent you encouragement â keep going!",[a]);case"rhythmComplete":return i("FRIENDS_HIGHLIGHT_TOGETHER","You both studied today â your week is on track!");case"rhythmWeekBroken":return i("FRIENDS_HIGHLIGHT_WEEK_BROKEN","Your week with %@ is broken",[a]);case"rankGap":return i("FRIENDS_HIGHLIGHT_GAP","Just %1$lld XP to overtake %2$@",[t.xpGap??1,a]);case"leading":return i("FRIENDS_HIGHLIGHT_LEADING","Youâre leading by %lld XP",[t.xpLead??0]);default:return n.friendCount===0?i("FRIENDS_EMPTY_TITLE","Learning is easier together"):i("FRIENDS_HIGHLIGHT_DEFAULT","See how your friends are doing")}}function P(n,t){const a=`${n?.uid||""}:${t}`,s=c.useRef(a);s.current=a;const u=c.useRef(0),[h,d]=c.useState(()=>n&&!n.isAnonymous?L(n.uid,t):null),[R,N]=c.useState(null),[g,m]=c.useState(!h),I=c.useCallback(async(x=!1)=>{if(!n||n.isAnonymous){m(!1);return}const E=++u.current;try{const l=await W(n,t,x);s.current===a&&E===u.current&&(d(l),N(null))}catch(l){if(s.current===a&&E===u.current){if(l instanceof b&&["STALE_RESPONSE","SESSION_CHANGED"].includes(l.code))return;l instanceof b&&l.code==="FEATURE_OFF"&&d(null),N(l)}}finally{s.current===a&&E===u.current&&m(!1)}},[n,t,a]);return c.useEffect(()=>{const x=n&&!n.isAnonymous?L(n.uid,t):null;d(x),N(null),m(!x),I();const E=()=>{I()},l=()=>{I(!0)};return window.addEventListener("lingard-friends-updated",l),window.addEventListener("focus",E),()=>{u.current++,window.removeEventListener("focus",E),window.removeEventListener("lingard-friends-updated",l)}},[I,n,t]),{home:h,setHome:d,loading:g&&!h,error:R,refresh:I}}function X(){return e.jsxs("div",{className:"friends-empty",children:[e.jsx("p",{children:i("FRIENDS_SIGN_IN_REQUIRED","Sign in to use Friends.")}),e.jsx(T,{className:"friends-button",href:"/login?returnTo=%2Fprofile%2Ffriends",children:i("AUTH_SIGN_IN","Sign in")})]})}function ae({user:n,language:t,weeklyXp:a=0}){const{home:s,loading:u,error:h,refresh:d}=P(n,t),R=c.useRef(a);c.useEffect(()=>{R.current!==a&&(R.current=a,d(!0))},[a,d]);const N=c.useRef(null),g=c.useRef(null),m=c.useRef(null),[I,x]=c.useState(!1),E=!n||n.isAnonymous?i("FRIENDS_SIGN_IN_REQUIRED","Sign in to use Friends."):s?V(s):u?i("FRIENDS_LOADING","Loading your friendsâ¦"):i("FRIENDS_RETRY","Friends are temporarily unavailable"),l=s?.friendCount===0?i("FRIENDS_EMPTY_DETAIL","Invite your first friend"):s?.highlight?.rank&&s.highlight.total?i("FRIENDS_RANK_DETAIL","%1$d of %2$d among friends this week",[s.highlight.rank,s.highlight.total]):s?w("FRIENDS_COUNT",s.friendCount,"%d friends"):i("FRIENDS_TAP_TO_OPEN","Tap to try again"),r=s?.friendCount===0&&(!s.highlight||s.highlight.type==="empty"),f=[...s?.entries.filter(o=>!o.isMe)||[],...s?.otherEntries||[]].slice(0,3),p=s?.friendCount===1?f[0]:void 0,C=p&&A(s,p.userId);if(c.useLayoutEffect(()=>{const o=()=>{if(!g.current||!N.current)return;const F=getComputedStyle(g.current),D=parseFloat(F.lineHeight)||20,v=g.current.scrollHeight,H=m.current?.scrollHeight||0;x(v>D*2+1||v+H+4>N.current.clientHeight-(r?34:0))};o();const j=typeof ResizeObserver>"u"?null:new ResizeObserver(o);return N.current&&j?.observe(N.current),()=>j?.disconnect()},[E,l,C,r]),h instanceof b&&h.code==="FEATURE_OFF")return null;const $=()=>{!n||n.isAnonymous?_("/login?returnTo=%2Fprofile%2Ffriends"):s?.friendCount===0&&s.pendingRequests.length===0?_("/profile/friends/invite"):_("/profile/friends")};return e.jsxs("article",{className:`profile-native-card profile-friends-card${r?" is-empty":""}`,"data-no-localize":!0,children:[e.jsx("button",{className:"profile-stat-open",type:"button","aria-label":i("FRIENDS_TITLE","Friends"),onClick:$}),e.jsx("h2",{children:i("FRIENDS_TITLE","Friends")}),s&&s.friendCount>0&&e.jsx("button",{type:"button",className:"friends-card-add","aria-label":i("FRIENDS_INVITE_ACTION","Invite"),onClick:()=>_("/profile/friends/invite"),children:"â"}),!!s?.incomingCount&&e.jsx("b",{className:"friends-count-badge",children:s.incomingCount}),e.jsx("div",{className:"friends-card-flames","aria-label":i("FRIENDS_TOGETHER","Together"),children:s?.rhythms.filter(o=>o.status==="active").sort((o,j)=>(j.currentCount||0)-(o.currentCount||0)).slice(0,2).map((o,j)=>{const F=o.currentCount||0,D=F>0&&o.weekOnTrack!==!1,v=[o.user?.displayName||o.user?.handle,w("FRIENDS_TOGETHER_WEEKS",F,"Together for %d weeks")].filter(
1Boolean).join(", "),H=D?{kind:"complete",progress:1}:{kind:"lost"},M=j===0?y:Y;return e.jsx(M,{count:F,state:H,label:v},o.userId)})}),e.jsxs("div",{className:"friends-card-body",children:[!!f.length&&e.jsx("div",{className:"friends-card-avatars",children:f.map(o=>e.jsx(S,{user:o},o.userId))}),e.jsxs("div",{ref:N,className:`friends-card-copy${I?" is-expanded":""}`,children:[e.jsx("strong",{ref:g,dir:"auto",children:E}),e.jsx("span",{ref:m,"aria-hidden":I,children:l}),r&&e.jsxs("svg",{className:"friends-card-empty-add",width:"28",height:"28",viewBox:"0 0 28 28",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"14",cy:"14",r:"11.5",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("path",{d:"M14 8v12M8 14h12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})]}),C&&e.jsx(G,{round:!0,onSend:async()=>{await O(n,p.userId,t)},onSent:()=>{d(!0)}},p.userId)]})]})}function q({entry:n,canNudge:t,user:a,language:s,onNudged:u}){const h=n.wordRank||0,d=h>=1e4?"C2":h>=5e3?"C1":h>=2500?"B2":h>=1200?"B1":h>=600?"A2":"A1";return e.jsxs("div",{className:`friends-rank-row${n.isMe?" is-me":""}`,children:[e.jsx("span",{className:"friends-rank","aria-label":String(n.rank),children:["ð¥","ð¥","ð¥"][n.rank-1]||n.rank}),e.jsx(S,{user:n,size:46}),e.jsxs("div",{className:"friends-person-copy",children:[n.isMe?e.jsx("strong",{dir:"auto",children:n.displayName||`@${n.handle}`}):e.jsx(T,{className:"friends-person-link",href:k(n.userId),children:n.displayName||`@${n.handle}`}),e.jsxs("small",{dir:"auto",children:["@",n.handle]})]}),t?e.jsx(G,{onSend:async()=>{await O(a,n.userId,s)},onSent:u}):e.jsx("b",{className:`friends-cefr is-${d.toLowerCase()}`,children:d}),e.jsxs("strong",{className:"friends-xp",children:[n.weeklyXp.toLocaleString(Q())," XP"]})]})}function J({rhythm:n,user:t}){const a=n.status==="active",s=n.currentCount||0,u=n.weekOnTrack===!1;return e.jsxs(T,{className:"friends-together-card",href:k(n.userId),children:[e.jsx(S,{user:t,size:46}),e.jsxs("span",{className:"friends-together-identity",children:[e.jsx("strong",{dir:"auto",children:t.displayName||(t.handle?`@${t.handle}`:i("FRIENDS_FRIEND","Friend"))}),a?e.jsxs(e.Fragment,{children:[t.handle&&e.jsxs("small",{className:"friends-together-handle",dir:"auto",children:["@",t.handle]}),u&&e.jsx("small",{className:"friends-together-broken",children:i("FRIENDS_TOGETHER_WEEK_BROKEN","This week's streak is broken")})]}):e.jsx("small",{className:"friends-together-status",children:n.invitedByMe?i("FRIENDS_TOGETHER_PENDING","Together invitation pending"):i("FRIENDS_TOGETHER_INVITE","Invited you to learn Together")})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"friends-together-divider","aria-hidden":"true"}),e.jsx(y,{count:s,state:s>0&&!u?{kind:"complete",progress:1}:{kind:"lost"},label:w("FRIENDS_TOGETHER_WEEKS",s,"Together for %d weeks")})]})]})}function oe({user:n,language:t,onBack:a}){const{home:s,setHome:u,loading:h,error:d,refresh:R}=P(n,t),[N,g]=c.useState(null),[m,I]=c.useState(""),x=async(r,f)=>{if(!m){I(f),g(null);try{await z(n,r,{targetUid:f,targetLang:t}),await R(!0)}catch(p){g(p)}finally{I("")}}},E=n&&!n.isAnonymous,l=d instanceof b&&d.code==="FEATURE_OFF";return e.jsxs("main",{className:"content native-content friends-page friends-list-page app-tab-page","data-no-localize":!0,children:[e.jsx(U,{title:i("FRIENDS_TITLE","Friends"),leading:e.jsx("button",{type:"button",className:"app-tab-icon-button","aria-label":i("BACK","Back"),onClick:a,children:e.jsx("svg",{className:"app-header-action-icon",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"m14.5 5-7 7 7 7"})})}),actions:E&&!l?e.jsx(e.Fragment,{children:e.jsx("button",{type:"button",className:"app-tab-icon-button","aria-label":i("FRIENDS_INVITE_ACTION","Invite"),onClick:()=>_("/profile/friends/invite"),children:e.jsx("svg",{className:"app-header-action-icon is-add",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})})}):void 0}),e.jsx("div",{className:"friends-list-content",children:E?e.jsxs(e.Fragment,{children:[e.jsx(B,{error:N||d}),d!=null&&e.jsx("button",{className:"friends-button is-secondary",onClick:()=>{R(!0)},children:i("RETRY","Try again")}),h&&e.jsxs("div",{className:"friends-loading",role:"status",children:[e.jsx("span",{className:"friends-loading-spinner","aria-hidden":"true"}),i("FRIENDS_LOADING","Loading your friendsâ¦")]}),s&&e.jsxs(e.Fragment,{children:[s.friendCount===0&&e.jsxs("section",{className:"friends-empty",children:[e.jsx("h2",{children:i("FRIENDS_EMPTY_TITLE","
1Learning is easier together")}),e.jsx("p",{children:i("FRIENDS_EMPTY_DETAIL","Invite your first friend")}),e.jsx(T,{className:"friends-button",href:"/profile/friends/invite",children:i("FRIENDS_INVITE_ACTION","Invite")})]}),!!s.pendingRequests.length&&e.jsxs("section",{className:"friends-section",children:[e.jsx("h2",{children:i("FRIENDS_REQUESTS","Requests")}),s.pendingRequests.map(r=>e.jsxs("div",{className:"friends-request-row",children:[e.jsx(S,{user:r.user}),e.jsxs("div",{className:"friends-person-copy",children:[e.jsx(T,{className:"friends-person-link",href:k(r.user.userId),children:r.user.displayName||`@${r.user.handle}`}),e.jsx("small",{children:r.direction==="incoming"?i("FRIENDS_INVITATION","Friend invitation"):i("FRIENDS_REQUEST_OUTGOING","Request sent")})]}),e.jsxs("div",{className:"friends-row-actions",children:[r.direction==="incoming"&&e.jsx("button",{disabled:!!m,onClick:()=>{x("acceptRequest",r.user.userId)},children:i("ACCEPT","Accept")}),e.jsx("button",{disabled:!!m,onClick:()=>{x(r.direction==="incoming"?"declineRequest":"cancelRequest",r.user.userId)},children:r.direction==="incoming"?i("DECLINE","Decline"):i("CANCEL","Cancel")})]})]},r.pairId))]}),!!s.rhythms.length&&e.jsxs("section",{className:"friends-section friends-together-section",children:[e.jsx("h2",{children:i("FRIENDS_TOGETHER_STREAK","Streak together")}),e.jsx("div",{className:"friends-together-list",children:s.rhythms.map(r=>e.jsx(J,{rhythm:r,user:r.user||s.entries.find(f=>f.userId===r.userId)||{userId:r.userId,displayName:i("FRIENDS_FRIEND","Friend"),handle:""}},r.userId))}),e.jsx("p",{className:"friends-together-description",children:i("FRIENDS_TOGETHER_DESC","A week counts when you both come through it without breaking your own streak â each by your own goals. If either streak breaks, the week does not count.")})]}),s.entries.some(r=>!r.isMe)&&e.jsxs("section",{className:"friends-section",children:[e.jsx("h2",{children:i("FRIENDS_WEEKLY_RANKING","This week")}),e.jsx("div",{className:"friends-ranking",children:s.entries.map(r=>e.jsx(q,{entry:r,user:n,language:t,canNudge:A(s,r.userId),onNudged:()=>u(f=>f&&{...f,rhythms:f.rhythms.map(p=>p.userId===r.userId?{...p,canNudge:!1}:p)})},r.userId))})]}),!!s.otherEntries?.length&&e.jsxs("section",{className:"friends-section",children:[e.jsx("h2",{children:i("FRIENDS_OTHER_TIT
1LE","Other friends")}),s.otherEntries.map(r=>e.jsxs("div",{className:"friends-request-row",children:[e.jsx(S,{user:r}),e.jsxs("div",{className:"friends-person-copy",children:[e.jsx(T,{className:"friends-person-link",href:k(r.userId),children:r.displayName||`@${r.handle}`}),r.learningLangs?.length?e.jsx("small",{dir:"auto",children:r.learningLangs.map(K).join(" ")}):!!r.handle&&e.jsxs("small",{dir:"auto",children:["@",r.handle]})]})]},r.userId))]})]})]}):e.jsx(X,{})})]})}export{oe as FriendsPage,ae as ProfileFriendsCard,k as friendPath,V as friendsHighlight};
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.