import{n as e,t}from"./useQuery-BGE2QjQQ.js";import{n,r,t as i}from"./server-preference-BpqGozbp.js";import{i as a,n as ee,r as te,s as ne,t as o}from"./short-sha-DQWvhT6m.js";import{B as s,H as c,P as re,a as ie,q as l,t as ae}from"./index-DjQIajtc.js";import{t as u}from"./compiler-runtime-JzGT6-yI.js";import{n as d}from"./clsx-D8eYare0.js";import{c as oe,s as se}from"./lib-Dl7gm4yF.js";var ce=d(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),f=l(c(),1),le=u(),p=s();function ue(e){let t=(0,le.c)(3),{message:n}=e,r=n===void 0?`refreshed`:n,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,p.jsx)(ce,{size:16,className:`text-moss`,"aria-hidden":`true`}),t[0]=i):i=t[0];let a;return t[1]===r?a=t[2]:(a=(0,p.jsxs)(`div`,{className:`fixed left-1/2 bottom-6 -translate-x-1/2 z-50 inline-flex items-center gap-2 bg-ink text-bg font-mono text-xs px-3 py-2 rounded-sm`,children:[i,(0,p.jsx)(`span`,{children:r})]}),t[1]=r,t[2]=a),a}function m(e){return e.map(e=>{let t=e.startLineNumber??e.lineNumber??0,n=e.endLineNumber??e.lineNumber??t;return{id:e.id,path:e.path,side:e.side,author:e.author,body:e.body,createdAt:e.createdAt,startLineNumber:t,endLineNumber:n}})}function de(e){let t=`rust-sa:comments:${e}`,[n,r]=(0,f.useState)(()=>{if(typeof window>`u`)return[];try{let e=window.localStorage.getItem(t);return e?m(JSON.parse(e)):[]}catch{return[]}});return(0,f.useEffect)(()=>{typeof window>`u`||window.localStorage.setItem(t,JSON.stringify(n))},[t,n]),{comments:n,add:e=>{let t={...e,id:crypto.randomUUID(),createdAt:new Date().toISOString()};return r(e=>[...e,t]),t},remove:e=>r(t=>t.filter(t=>t.id!==e)),clear:()=>r([])}}function fe(e,t,n=800){let r=(0,f.useRef)(t);r.current=t,(0,f.useEffect)(()=>{if(typeof window>`u`)return;let t=new EventSource(e),i=0,a=``;return t.onmessage=e=>{a=e.data,i!==0&&window.clearTimeout(i),i=window.setTimeout(()=>{i=0,r.current(a)},n)},()=>{i!==0&&window.clearTimeout(i),t.close()}},[e,n])}function pe(e){let t=`rust-sa:viewed:${e}`,[n,r]=(0,f.useState)(()=>{if(typeof window>`u`)return new Set;try{let e=window.localStorage.getItem(t);return e?new Set(JSON.parse(e)):new Set}catch{return new Set}});return(0,f.useEffect)(()=>{typeof window>`u`||window.localStorage.setItem(t,JSON.stringify([...n]))},[t,n]),{viewed:n,isViewed:e=>n.has(e),toggle:e=>r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}}function h(e){return e===`added`||e===`deleted`||e===`modified`||e===`renamed`?e:`modified`}var me=e`
  query Files($rev: String!, $repo: String!, $w: Boolean) {
    files(rev: $rev, repo: $repo, w: $w) {
      path
      status
      additions
      deletions
    }
  }
`,g=[`compact`,`regular`,`comfy`],he=e=>g[(g.indexOf(e)+1)%g.length];function ge(e){if(e.includes(`...`)){let[t,n]=e.split(`...`,2);return{base:t,head:n,separator:`···`}}if(e.includes(`..`)){let[t,n]=e.split(`..`,2);return{base:t,head:n,separator:`··`}}return{base:e,head:e,separator:null}}function _e(e){let t=e.toUpperCase();return t===`WORKING`?`working`:t===`STAGING`?`staging`:o(e)}function ve(){let e=(0,le.c)(103),o=re(),[s,c]=n(`rust-sa:mode`,`unified`),[l]=i(),[u,d]=n(`rust-sa:density`,`regular`),[ce,m]=n(`rust-sa:compare-tree-w`,`280`),h=Number(ce)||280,[g,ve]=(0,f.useState)(!1),[De,ke]=(0,f.useState)(0);r(`data-theme`,l),r(`data-density`,u);let{rev:_,repo:v,files:Ae,w:y}=ae.useLoaderData(),b;e[0]!==o||e[1]!==_?(b=e=>{o({to:`/compare/$`,params:{_splat:_},search:t=>({...t,w:e?1:void 0}),replace:!0})},e[0]=o,e[1]=_,e[2]=b):b=e[2];let je=b,x;e[3]!==o||e[4]!==v?(x=e=>{e===`graph`&&o({to:`/graph`,search:{repo:v}})},e[3]=o,e[4]=v,e[5]=x):x=e[5];let Me=x,[S,Ne]=(0,f.useState)(0),C;e[6]!==v||e[7]!==_||e[8]!==y?(C={rev:_,repo:v,w:y},e[6]=v,e[7]=_,e[8]=y,e[9]=C):C=e[9];let Pe=S===0,w;e[10]!==C||e[11]!==Pe?(w={variables:C,skip:Pe},e[10]=C,e[11]=Pe,e[12]=w):w=e[12];let{data:Fe,refetch:Ie}=t(me,w),T=S===0?Ae:Fe?.files??Ae,[Le,Re]=(0,f.useState)(!1),E;e[13]!==T||e[14]!==Ie?(E=async()=>{let e=(await Ie()).data?.files??[],t=Ee;t(e)!==t(T)&&(Ne(Te),Re(!0),window.setTimeout(()=>Re(!1),1200))},e[13]=T,e[14]=Ie,e[15]=E):E=e[15],fe(`${ie}/api/events?repo=${encodeURIComponent(v)}`,E,1500);let D=T.map(we),O=D.map(Ce),{isViewed:k,toggle:A}=pe(_),j;e[16]===k?j=e[17]:(j=e=>k(e),e[16]=k,e[17]=j);let ze=O.filter(j).length,{comments:M,add:Be,remove:Ve,clear:He}=de(_),N=O[De]??O[0],{base:Ue,head:We,separator:Ge}=ge(_),P;e[18]===M?P=e[19]:(P=()=>{if(M.length===0)return;let e=M.toSorted(Se).map(xe).join(`

`);navigator.clipboard?.writeText(e)},e[18]=M,e[19]=P);let Ke=P,F;e[20]===Symbol.for(`react.memo_cache_sentinel`)?(F={hotkey:{key:`/`,shift:!0},callback:()=>ve(be)},e[20]=F):F=e[20];let I;e[21]!==s||e[22]!==c?(I={hotkey:`S`,callback:()=>c(s===`unified`?`split`:`unified`)},e[21]=s,e[22]=c,e[23]=I):I=e[23];let L;e[24]!==u||e[25]!==d?(L={hotkey:`.`,callback:()=>d(he(u))},e[24]=u,e[25]=d,e[26]=L):L=e[26];let R;e[27]!==N||e[28]!==A?(R={hotkey:`V`,callback:()=>N&&A(N)},e[27]=N,e[28]=A,e[29]=R):R=e[29];let z;e[30]===O.length?z=e[31]:(z={hotkey:`]`,callback:()=>O.length&&ke(e=>Math.min(e+1,O.length-1))},e[30]=O.length,e[31]=z);let B;e[32]===O.length?B=e[33]:(B={hotkey:`[`,callback:()=>O.length&&ke(ye)},e[32]=O.length,e[33]=B);let V;e[34]!==o||e[35]!==v?(V={hotkey:`G`,callback:()=>o({to:`/graph`,search:{repo:v}})},e[34]=o,e[35]=v,e[36]=V):V=e[36];let qe;e[37]!==L||e[38]!==R||e[39]!==z||e[40]!==B||e[41]!==V||e[42]!==I?(qe=[F,I,L,R,z,B,V],e[37]=L,e[38]=R,e[39]=z,e[40]=B,e[41]=V,e[42]=I,e[43]=qe):qe=e[43];let Je;e[44]===Symbol.for(`react.memo_cache_sentinel`)?(Je={preventDefault:!0,ignoreInputs:!0},e[44]=Je):Je=e[44],ne(qe,Je);let Ye=ee,Xe=_e(Ue),Ze=Ge?_e(We):void 0,Qe=Ge??void 0,$e=M.length>0?Ke:void 0,et=`copy ${M.length}`,tt=M.length>0?He:void 0,nt=`clear ${M.length}`,H;e[45]!==Ye||e[46]!==s||e[47]!==Me||e[48]!==O.length||e[49]!==c||e[50]!==je||e[51]!==Xe||e[52]!==Ze||e[53]!==Qe||e[54]!==$e||e[55]!==et||e[56]!==tt||e[57]!==nt||e[58]!==ze||e[59]!==y?(H=(0,p.jsx)(Ye,{base:Xe,head:Ze,separator:Qe,mode:s,onModeChange:c,view:`diff`,onViewChange:Me,viewedCount:ze,totalCount:O.length,onCopyPrompts:$e,copyPromptsLabel:et,onClearPrompts:tt,clearPromptsLabel:nt,isLive:!0,ignoreWhitespace:y,onIgnoreWhitespaceChange:je}),e[45]=Ye,e[46]=s,e[47]=Me,e[48]=O.length,e[49]=c,e[50]=je,e[51]=Xe,e[52]=Ze,e[53]=Qe,e[54]=$e,e[55]=et,e[56]=tt,e[57]=nt,e[58]=ze,e[59]=y,e[60]=H):H=e[60];let rt=`${h}px auto 1fr`,U;e[61]===rt?U=e[62]:(U={gridTemplateColumns:rt},e[61]=rt,e[62]=U);let W;e[63]===O.length?W=e[64]:(W=(0,p.jsx)(Oe,{count:O.length}),e[63]=O.length,e[64]=W);let G;e[65]!==D||e[66]!==O||e[67]!==W?(G=(0,p.jsx)(`aside`,{className:`bg-bg-soft border-r border-hairline min-h-0 overflow-hidden`,children:(0,p.jsx)(oe,{paths:O,gitStatus:D,header:W})}),e[65]=D,e[66]=O,e[67]=W,e[68]=G):G=e[68];let K;e[69]===m?K=e[70]:(K=e=>m(String(Math.round(e))),e[69]=m,e[70]=K);let q;e[71]!==K||e[72]!==h?(q=(0,p.jsx)(se,{width:h,onWidthChange:K,min:200,max:600,ariaLabel:`resize file tree`}),e[71]=K,e[72]=h,e[73]=q):q=e[73];let J;e[74]===Be?J=e[75]:(J=e=>Be({...e,author:`you`}),e[74]=Be,e[75]=J);let Y;e[76]!==M||e[77]!==k||e[78]!==T||e[79]!==s||e[80]!==S||e[81]!==Ve||e[82]!==v||e[83]!==_||e[84]!==J||e[85]!==l||e[86]!==A||e[87]!==y?(Y=(0,p.jsx)(`main`,{className:`overflow-y-auto bg-bg min-w-0`,children:(0,p.jsx)(a,{rev:_,refreshKey:S,files:T,repo:v,layout:s,theme:l,comments:M,isViewed:k,onToggleViewed:A,onAddComment:J,onDeleteComment:Ve,ignoreWhitespace:y})}),e[76]=M,e[77]=k,e[78]=T,e[79]=s,e[80]=S,e[81]=Ve,e[82]=v,e[83]=_,e[84]=J,e[85]=l,e[86]=A,e[87]=y,e[88]=Y):Y=e[88];let X;e[89]!==U||e[90]!==G||e[91]!==q||e[92]!==Y?(X=(0,p.jsxs)(`div`,{className:`grid min-h-0 border-t border-hairline`,style:U,children:[G,q,Y]}),e[89]=U,e[90]=G,e[91]=q,e[92]=Y,e[93]=X):X=e[93];let Z;e[94]===g?Z=e[95]:(Z=(0,p.jsx)(te,{isOpen:g,onOpenChange:ve}),e[94]=g,e[95]=Z);let Q;e[96]===Le?Q=e[97]:(Q=Le&&(0,p.jsx)(ue,{}),e[96]=Le,e[97]=Q);let $;return e[98]!==H||e[99]!==X||e[100]!==Z||e[101]!==Q?($=(0,p.jsxs)(`div`,{className:`grid grid-rows-[var(--topbar-h)_1fr] h-screen bg-bg text-ink`,children:[H,X,Z,Q]}),e[98]=H,e[99]=X,e[100]=Z,e[101]=Q,e[102]=$):$=e[102],$}function ye(e){return Math.max(e-1,0)}function be(e){return!e}function xe(e){let t=e.startLineNumber===e.endLineNumber?`L${e.startLineNumber}`:`L${e.startLineNumber}–L${e.endLineNumber}`;return`Re: ${e.path}:${t}\n${e.body}`}function Se(e,t){return e.path.localeCompare(t.path)||e.startLineNumber-t.startLineNumber}function Ce(e){return e.path}function we(e){return{path:e.path,status:h(e.status)}}function Te(e){return e+1}function Ee(e){return e.map(De).join(`|`)}function De(e){return`${e.path}:${e.additions}:${e.deletions}`}function Oe(e){let t=(0,le.c)(3),{count:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,p.jsx)(`span`,{children:`files`}),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,p.jsxs)(`div`,{className:`px-3 pt-4 pb-3 border-b border-hairline flex items-center justify-between font-mono text-xs uppercase tracking-widest text-mute`,children:[r,(0,p.jsxs)(`span`,{className:`text-ink normal-case tracking-normal text-xs`,children:[`0 / `,n,` viewed`]})]}),t[1]=n,t[2]=i),i}export{ve as component};