diff --git a/internal/webapp/frontend/e2e/browse.spec.ts b/internal/webapp/frontend/e2e/browse.spec.ts
index b010a35..acf25f6 100644
--- a/internal/webapp/frontend/e2e/browse.spec.ts
+++ b/internal/webapp/frontend/e2e/browse.spec.ts
@@ -380,14 +380,56 @@ test("public link: the file page says it is shared, and revokes without a reload
await expect(banner).toContainText("no expiry");
expect((await page.request.get(url)).status()).toBe(200);
- // Revoking from the file page kills the link and updates in place.
- await banner.locator(".ai-del").click();
+ // Revoking from the file page kills the link and updates in place. Queried
+ // by its accessible name (BEA-100), so the aria-label can't regress into a
+ // control only a CSS selector can find.
+ await page.getByRole("button", { name: /revoke/i }).click();
await page.click(".modal .danger-btn");
await expectToast(page, "Share revoked");
await expect(banner).toHaveCount(0);
expect((await page.request.get(url)).status()).toBe(404);
});
+// BEA-100: a persona reported the file page's Revoke as unreachable by its
+// accessible name. It is reachable — except while the Share dialog is open,
+// because Radix's modal aria-hides the rest of the page, leaving the banner's
+// button in the DOM and out of the accessibility tree. Both states are pinned
+// here so the recorded repro can't go stale, and so the answer stays a
+// sentence in the dialog rather than a second destructive control (BEA-32).
+test("revoke answers to its accessible name, and the open dialog says where it lives", async ({
+ page,
+}) => {
+ await login(page);
+ const pid = await wikiId(page);
+ const minted = await page.request.post(`/api/p/${pid}/shares`, { data: { path: "guide.md" } });
+ const url = (await minted.json()).url as string;
+ await page.goto(`/${pid}/guide.md`);
+ const revoke = page.getByRole("button", { name: /revoke/i });
+
+ // Dialog closed: the banner's Revoke answers to the query that timed out.
+ await expect(page.locator(".share-banner")).toBeVisible();
+ await expect(revoke).toHaveCount(1);
+
+ // Dialog open: same query, nothing to find — the banner is still rendered,
+ // its ancestor is aria-hidden. The dialog names where Revoke lives instead
+ // of growing one of its own.
+ await page.click("#share-btn");
+ await page.waitForSelector(".modal-url");
+ await expect(page.locator(".share-banner")).toHaveCount(1);
+ await expect(page.locator("#main")).toHaveAttribute("aria-hidden", "true");
+ await expect(revoke).toHaveCount(0);
+ await expect(page.locator(".modal .ai-del")).toHaveCount(0);
+ await expect(page.locator(".modal")).toContainText("Publicly shared");
+
+ // Closed again: reachable, and it still revokes end to end.
+ await page.click(".modal button:has-text('Done')");
+ await revoke.click();
+ await page.click(".modal .danger-btn");
+ await expectToast(page, "Share revoked");
+ await expect(page.locator(".share-banner")).toHaveCount(0);
+ expect((await page.request.get(url)).status()).toBe(404);
+});
+
test("project settings lists this project's public links and revokes them", async ({ page }) => {
await login(page);
const pid = await wikiId(page);
diff --git a/internal/webapp/frontend/src/components/ShareDialog.tsx b/internal/webapp/frontend/src/components/ShareDialog.tsx
index a77b149..7f73c8f 100644
--- a/internal/webapp/frontend/src/components/ShareDialog.tsx
+++ b/internal/webapp/frontend/src/components/ShareDialog.tsx
@@ -78,6 +78,12 @@ export function ShareDialog({
Anyone with this link can view this file — no account needed. It always shows the
latest version until it expires or you revoke it.
+ {/* BEA-100: the one thing a user opens this dialog for and cannot do
+ here. Radix aria-hides the page behind an open modal, so the
+ banner's Revoke is unreachable — to assistive tech and to the
+ user — until this closes. A sentence, not a second button. */}{" "}
+ To revoke it, close this — Revoke is on the file itself, in the “Publicly shared”
+ banner.
{url}
diff --git a/internal/webapp/static/assets/index-Cg3Ijtd_.js b/internal/webapp/static/assets/index-BAns3BK4.js
similarity index 92%
rename from internal/webapp/static/assets/index-Cg3Ijtd_.js
rename to internal/webapp/static/assets/index-BAns3BK4.js
index df4309c..41711cc 100644
--- a/internal/webapp/static/assets/index-Cg3Ijtd_.js
+++ b/internal/webapp/static/assets/index-BAns3BK4.js
@@ -119,4 +119,4 @@ bdrive init --project `+e.id;return f.jsxs("div",{className:"guide",children:[f.
to set up a new BearDrive project on `+window.location.origin+". Ask me which folder to sync."}),f.jsx("p",{className:"ob-alt",children:f.jsx("a",{href:"https://docs.beardrive.ai/manual/setup-by-hand/",target:"_blank",rel:"noreferrer",children:"Or start a project manually →"})})]})]})}const BC="__existing__";function nI({templates:e,onCreate:n,onClose:r}){const i=[...e.map(x=>({value:x.name,title:x.title,blurb:x.blurb,rule:!1})),{value:BC,title:"I already have a folder",blurb:"nothing is seeded — connect it and your files stay as they are",rule:!0},{value:"",title:"Empty project",blurb:"just the folder",rule:!1}],[o,l]=S.useState(""),[u,d]=S.useState(i[0].value),[m,p]=S.useState(""),[y,v]=S.useState(!1),b=async()=>{if(!y){if(!o.trim()){p("Give it a name.");return}v(!0);try{await n(o.trim(),u)}finally{v(!1)}}};return f.jsx(Ju,{open:!0,onOpenChange:x=>!x&&r(),children:f.jsxs(Wu,{className:"modal",showCloseButton:!1,children:[f.jsx(_l,{asChild:!0,children:f.jsx("h3",{children:"New project"})}),f.jsx("label",{className:"modal-label",htmlFor:"modal-input",children:"Name"}),f.jsx("input",{className:"modal-input",type:"text",autoComplete:"off",id:"modal-input",autoFocus:!0,value:o,"aria-invalid":!!m,"aria-describedby":m?"modal-input-err":void 0,onChange:x=>{l(x.currentTarget.value),m&&p("")},onKeyDown:x=>x.key==="Enter"&&b()}),m&&f.jsx("span",{id:"modal-input-err",role:"alert",className:"field-err",children:m}),i.length>1&&f.jsxs("fieldset",{className:"start-points",children:[f.jsx("legend",{className:"modal-label",children:"Starting point"}),i.map((x,w)=>f.jsxs("label",{className:"start-point"+(u===x.value?" on":"")+(x.rule?" sp-rule":""),children:[f.jsx("input",{type:"radio",name:"template",value:x.value,checked:u===x.value,onChange:()=>d(x.value)}),f.jsxs("span",{className:"sp-text",children:[f.jsxs("span",{className:"sp-title",children:[x.title,w===0&&f.jsx("span",{className:"sp-rec",children:"Recommended"})]}),f.jsx("span",{className:"sp-blurb",children:x.blurb})]})]},x.value))]}),f.jsxs("div",{className:"modal-actions",children:[f.jsx(vt,{variant:"subtle",onClick:r,children:"Cancel"}),f.jsx(vt,{variant:"primary",onClick:b,disabled:y,children:"Create"})]})]})})}function sw(e,n,r){if(!e)return null;if(!r)return e[n]||null;const i={human:0,agent:0,share:0};for(const[o,l]of Object.entries(e))o.startsWith(n+"/")&&(i.human+=l.human||0,i.agent+=l.agent||0,i.share+=l.share||0);return i.human||i.agent||i.share?i:null}function ka(e){return(e.human||0)+(e.agent||0)+(e.share||0)}function Jo(e){const n=ka(e);if(!n)return"";const r=n+(n===1?" read":" reads");if(!e.agent&&!e.share)return r;const i=[];return e.human&&i.push(e.human+" human"),e.agent&&i.push(e.agent+" agent"),e.share&&i.push(e.share+" shared"),r+" ("+i.join(", ")+")"}function rI(e){const n=ka(e);return n?n<3?1:n<10?2:n<30?3:4:0}function aI(e){const n=ka(e);return n?{agent:(e.agent||0)/n,human:(e.human||0)/n,share:(e.share||0)/n}:{agent:0,human:0,share:0}}function iI(e,n){return e?Object.keys(e).filter(r=>!n.has(r)).sort():[]}const sI=7;function oI(e){if(!e.length)return null;let n=e[0],r=e[0];for(const i of e)ir&&(r=i);return{min:n,max:r}}const lI=(e,n)=>n-el.reads-o.reads).slice(0,uI)){const o=i.path.split("/").pop();let l=i.cx+i.r+4,u="start";l+o.length*dI>n.right&&(l=i.cx-i.r-4,u="end");const d=p=>r.every(y=>Math.abs(y.y-p)>=rm);let m=i.cy;for(;m<=n.bottom&&!d(m);)m+=rm;if(m>n.bottom)for(m=i.cy;m>=n.top&&!d(m);)m-=rm;r.push({path:i.path,name:o,x:l,y:Math.min(n.bottom,Math.max(n.top,m)),anchor:u})}return r}function hI(e,n=!0){const r=Pt({queryKey:["tree",e],queryFn:()=>Bt(e+"tree"),enabled:n,refetchInterval:15e3}),i=S.useMemo(()=>{const o=[],l=new Map,u=d=>{for(const m of d.children||[])m.dir?(l.set(m.path,m),u(m)):o.push(m)};return r.data&&u(r.data),{flatFiles:o,dirIndex:l}},[r.data]);return{tree:r.data,...i,loaded:!!r.data}}function mI(e,n){return Pt({queryKey:["heat",e],queryFn:()=>Bt(e+"heat?days=30"),enabled:n,staleTime:6e4,refetchInterval:6e4}).data?.entries??null}function pI(e,n,r){return Pt({queryKey:["history",e,"prefix",n,20],queryFn:()=>Bt(e+"history?prefix="+encodeURIComponent(n)+"&n=20"),enabled:r,staleTime:15e3}).data?.entries??null}function gI(e,n,r){const i=new Array(e);return new Proxy(i,{get(o,l,u){if(typeof l=="string"){const d=l.charCodeAt(0);if(d>=48&&d<=57){const m=+l;if(Number.isInteger(m)&&m>=0&&mi[y]!==p))&&(i=d,o=n(...d),r?.onChange&&!(l&&r.skipInitialOnChange)&&r.onChange(o),l=!1),o}return u.updateDeps=d=>{i=d},u}function ow(e,n){if(e===void 0)throw new Error("Unexpected undefined");return e}const vI=(e,n)=>Math.abs(e-n)<1.01,yI=(e,n,r)=>{let i;return function(...o){e.clearTimeout(i),i=e.setTimeout(()=>n.apply(this,o),r)}};let Go;const am=()=>{if(Go!==void 0)return Go;if(typeof navigator>"u")return Go=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Go=!0;const e=navigator.maxTouchPoints;return Go=navigator.platform==="MacIntel"&&e!==void 0&&e>0},lw=e=>{const{offsetWidth:n,offsetHeight:r}=e;return{width:n,height:r}},bI=e=>e,xI=e=>{const n=Math.max(e.startIndex-e.overscan,0),i=Math.min(e.endIndex+e.overscan,e.count-1)-n+1,o=new Array(i);for(let l=0;l{const r=e.scrollElement;if(!r)return;const i=e.targetWindow;if(!i)return;const o=u=>{const{width:d,height:m}=u;n({width:Math.round(d),height:Math.round(m)})};if(o(lw(r)),!i.ResizeObserver)return()=>{};const l=new i.ResizeObserver(u=>{const d=()=>{const m=u[0];if(m?.borderBoxSize){const p=m.borderBoxSize[0];if(p){o({width:p.inlineSize,height:p.blockSize});return}}o(lw(r))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(d):d()});return l.observe(r,{box:"border-box"}),()=>{l.unobserve(r)}},Ou={passive:!0},SI=typeof window>"u"?!0:"onscrollend"in window,_I=(e,n,r)=>{const i=e.scrollElement;if(!i)return;const o=e.targetWindow;if(!o)return;const l=e.options.useScrollendEvent&&SI;let u=0;const d=l?null:yI(o,()=>n(u,!1),e.options.isScrollingResetDelay),m=v=>()=>{u=r(i),d?.(),n(u,v)},p=m(!0),y=m(!1);return i.addEventListener("scroll",p,Ou),l&&i.addEventListener("scrollend",y,Ou),()=>{i.removeEventListener("scroll",p),l&&i.removeEventListener("scrollend",y)}},CI=(e,n)=>_I(e,n,r=>{const{horizontal:i,isRtl:o}=e.options;return i?r.scrollLeft*(o&&-1||1):r.scrollTop}),EI=(e,n,r)=>{if(r.options.useCachedMeasurements){const i=r.indexFromElement(e),o=r.options.getItemKey(i);return r.itemSizeCache.get(o)??r.options.estimateSize(i)}if(n?.borderBoxSize){const i=n.borderBoxSize[0];if(i)return Math.round(i[r.options.horizontal?"inlineSize":"blockSize"])}if(!n){const i=r.indexFromElement(e),o=r.options.getItemKey(i),l=r.itemSizeCache.get(o);if(l!==void 0)return l}return e[r.options.horizontal?"offsetWidth":"offsetHeight"]},RI=(e,{adjustments:n=0,behavior:r},i)=>{var o,l;(l=(o=i.scrollElement)==null?void 0:o.scrollTo)==null||l.call(o,{[i.options.horizontal?"left":"top"]:e+n,behavior:r})},jI=RI;class TI{constructor(n){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var r,i,o;return((o=(i=(r=this.targetWindow)==null?void 0:r.performance)==null?void 0:i.now)==null?void 0:o.call(i))??Date.now()},this.observer=(()=>{let r=null;const i=()=>r||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:r=new this.targetWindow.ResizeObserver(o=>{o.forEach(l=>{const u=()=>{const d=l.target,m=this.indexFromElement(d);if(!d.isConnected){this.observer.unobserve(d);for(const[p,y]of this.elementsCache)if(y===d){this.elementsCache.delete(p);break}return}this.shouldMeasureDuringScroll(m)&&this.resizeItem(m,this.options.measureElement(d,l,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(u):u()})}));return{disconnect:()=>{var o;(o=i())==null||o.disconnect(),r=null},observe:o=>{var l;return(l=i())==null?void 0:l.observe(o,{box:"border-box"})},unobserve:o=>{var l;return(l=i())==null?void 0:l.unobserve(o)}}})(),this.range=null,this.setOptions=r=>{var i,o;const l={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:bI,rangeExtractor:xI,onChange:()=>{},measureElement:EI,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const b in r){const x=r[b];x!==void 0&&(l[b]=x)}const u=this.options;let d=null,m=null,p=!1;if(u!==void 0&&u.enabled&&l.enabled&&l.anchorTo==="end"&&this.scrollElement!==null){const b=u.count,x=l.count,w=this.getMeasurements(),_=b>0?((i=w[0])==null?void 0:i.key)??u.getItemKey(0):null,E=b>0?((o=w[b-1])==null?void 0:o.key)??u.getItemKey(b-1):null;if(x!==b||b>0&&x>0&&(l.getItemKey(0)!==_||l.getItemKey(x-1)!==E)){p=!0;const O=b>0?this.getVirtualItemForOffset(this.getScrollOffset())??w[0]:null;O&&(d=[O.key,this.getScrollOffset()-O.start]);const N=l.followOnAppend===!0?"auto":l.followOnAppend||null;N&&x>b&&this.isAtEnd(u.scrollEndThreshold)&&(b===0||l.getItemKey(x-1)!==E)&&(m=N)}}this.options=l,p&&(this.pendingMin=0,this.itemSizeCacheVersion++);let y=!1,v=0;if(d&&this.scrollOffset!==null){const[b,x]=d,w=this.getMeasurements(),{count:_,getItemKey:E}=this.options;let R=0;for(;R<_&&E(R)!==b;)R++;if(R<_){const T=w[R];if(T){const O=T.start+x;O!==this.scrollOffset&&(v=O-this.scrollOffset,this.scrollOffset=O,y=!0)}}}(y||m)&&(this.pendingScrollAnchor=[y?d[0]:null,y?d[1]:0,m,v])},this.notify=r=>{var i,o;(o=(i=this.options).onChange)==null||o.call(i,this,r)},this.maybeNotify=Os(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),r=>{this.notify(r)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(r=>r()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var r;const i=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==i){if(this.cleanup(),!i){this.maybeNotify();return}if(this.scrollElement=i,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((r=this.scrollElement)==null?void 0:r.window)??null,this.elementsCache.forEach(l=>{this.observer.observe(l)}),this.unsubs.push(this.options.observeElementRect(this,l=>{this.scrollRect=l,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(l,u)=>{if(u&&this._intendedScrollOffset===null&&l===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(l-this._intendedScrollOffset)<1.5&&(l=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const d=this.getScrollOffset();this.scrollDirection=u?d===l?this.scrollDirection:d{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},d=()=>{this._iosTouching=!1,!(!am()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};l.addEventListener("touchstart",u,Ou),l.addEventListener("touchend",d,Ou),this.unsubs.push(()=>{l.removeEventListener("touchstart",u),l.removeEventListener("touchend",d),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const o=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,o&&this.scrollElement&&this.options.enabled){const[l,u,d,m]=o;l!==null&&!d&&(am()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?m!==0&&(this._iosDeferredAdjustment+=m):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),d&&this.scrollToEnd({behavior:d})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const r=this.getScrollOffset(),i=this.getMaxScrollOffset();if(r<0||r>i)return;const o=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(r,{adjustments:this.scrollAdjustments+=o,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=Os(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(r,i,o,l,u,d,m,p)=>(this.prevLanes!==void 0&&this.prevLanes!==d&&(this.lanesChangedFlag=!0),this.prevLanes=d,this.pendingMin=null,{count:r,paddingStart:i,scrollMargin:o,getItemKey:l,enabled:u,lanes:d,laneAssignmentMode:m,gap:p}),{key:!1}),this.getMeasurements=Os(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:r,paddingStart:i,scrollMargin:o,getItemKey:l,enabled:u,lanes:d,laneAssignmentMode:m,gap:p},y)=>{const v=this.itemSizeCache;if(!u)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>r)for(const R of this.laneAssignments.keys())R>=r&&this.laneAssignments.delete(R);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(R=>{this.itemSizeCache.set(R.key,R.size)}));const b=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===r&&(this.lanesSettling=!1),d===1){const R=r*2;let T=this._flatMeasurements;if(!T||T.length0&&z.set(T.subarray(0,b*2)),T=z,this._flatMeasurements=T}let O;if(b===0)O=i+o;else{const z=b-1;O=T[z*2]+T[z*2+1]+p}for(let z=b;z1){N=O;const ye=w[N],me=ye!==void 0?x[ye]:void 0;z=me?me.end+p:i+o}else if(E===d){let ye=0,me=_[0],de=w[0];for(let le=1;lethis.options.debug}),this.calculateRange=Os(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(r,i,o,l)=>r.length===0||i===0?(this.range=null,null):(this.range=AI(r,i,o,l,l===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Os(()=>{let r=null,i=null;const o=this.calculateRange();return o&&(r=o.startIndex,i=o.endIndex),this.maybeNotify.updateDeps([this.isScrolling,r,i]),[this.options.rangeExtractor,this.options.overscan,this.options.count,r,i]},(r,i,o,l,u)=>l===null||u===null?[]:r({startIndex:l,endIndex:u,overscan:i,count:o}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=r=>{const i=this.options.indexAttribute,o=r.getAttribute(i);return o?parseInt(o,10):(console.warn(`Missing attribute name '${i}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=r=>{var i;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const o=this.scrollState.index??((i=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:i.index);if(o!==void 0&&this.range){const l=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),u=Math.max(0,o-l),d=Math.min(this.options.count-1,o+l);return r>=u&&r<=d}return!0},this.measureElement=r=>{if(!r){this.elementsCache.forEach((u,d)=>{u.isConnected||(this.observer.unobserve(u),this.elementsCache.delete(d))});return}const i=this.indexFromElement(r),o=this.options.getItemKey(i),l=this.elementsCache.get(o);l!==r&&(l&&this.observer.unobserve(l),this.observer.observe(r),this.elementsCache.set(o,r)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(i)&&this.resizeItem(i,this.options.measureElement(r,void 0,this))},this.resizeItem=(r,i)=>{var o,l;if(r<0||r>=this.options.count)return;let u,d,m;const p=this._flatMeasurements;if(this.options.lanes===1&&p!==null)m=this.options.getItemKey(r),d=p[r*2],u=p[r*2+1];else{const b=this.measurementsCache[r];if(!b)return;m=b.key,d=b.start,u=b.size}const y=this.itemSizeCache.get(m)??u,v=i-y;if(v!==0){const b=this.options.anchorTo==="end"&&((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,x=b?this.getTotalSize():0,w=((l=this.scrollState)==null?void 0:l.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[r]??{index:r,key:m,start:d,size:u,end:d+u,lane:0},v,this):d[this.getVirtualIndexes(),this.getMeasurements()],(r,i)=>{const o=[];for(let l=0,u=r.length;lthis.options.debug}),this.getVirtualItemForOffset=r=>{const i=this.getMeasurements();if(i.length===0)return;const o=this._flatMeasurements,l=this.options.lanes===1&&o!=null,u=qC(0,i.length-1,l?d=>o[d*2]:d=>ow(i[d]).start,r);return ow(i[u])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const r=this.scrollElement.document.documentElement;return this.options.horizontal?r.scrollWidth-this.scrollElement.innerWidth:r.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(r=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=r,this.getOffsetForAlignment=(r,i,o=0)=>{if(!this.scrollElement)return 0;const l=this.getSize(),u=this.getScrollOffset();i==="auto"&&(i=r>=u+l?"end":"start"),i==="center"?r+=(o-l)/2:i==="end"&&(r-=l);const d=this.getMaxScrollOffset();return Math.max(Math.min(d,r),0)},this.getOffsetForIndex=(r,i="auto")=>{r=Math.max(0,Math.min(r,this.options.count-1));const o=this.getSize(),l=this.getScrollOffset(),u=this.measurementsCache[r];if(!u)return;if(i==="auto")if(u.end>=l+o-this.options.scrollPaddingEnd)i="end";else if(u.start<=l+this.options.scrollPaddingStart)i="start";else return[l,i];if(i==="end"&&r===this.options.count-1)return[this.getMaxScrollOffset(),i];const d=i==="end"?u.end+this.options.scrollPaddingEnd:u.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(d,i,u.size),i]},this.scrollToOffset=(r,{align:i="start",behavior:o="auto"}={})=>{const l=this.getOffsetForAlignment(r,i),u=this.now();this.scrollState={index:null,align:i,behavior:o,startedAt:u,lastTargetOffset:l,stableFrames:0},this._scrollToOffset(l,{adjustments:void 0,behavior:o}),this.scheduleScrollReconcile()},this.scrollToIndex=(r,{align:i="auto",behavior:o="auto"}={})=>{r=Math.max(0,Math.min(r,this.options.count-1));const l=this.getOffsetForIndex(r,i);if(!l)return;const[u,d]=l,m=this.now();this.scrollState={index:r,align:d,behavior:o,startedAt:m,lastTargetOffset:u,stableFrames:0},this._scrollToOffset(u,{adjustments:void 0,behavior:o}),this.scheduleScrollReconcile()},this.scrollBy=(r,{behavior:i="auto"}={})=>{const o=this.getScrollOffset()+r,l=this.now();this.scrollState={index:null,align:"start",behavior:i,startedAt:l,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:r="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:r});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:r})},this.getTotalSize=()=>{var r;const i=this.getMeasurements();let o;if(i.length===0)o=this.options.paddingStart;else if(this.options.lanes===1){const l=i.length-1,u=this._flatMeasurements;u!=null?o=u[l*2]+u[l*2+1]:o=((r=i[l])==null?void 0:r.end)??0}else{const l=Array(this.options.lanes).fill(null);let u=i.length-1;for(;u>=0&&l.some(d=>d===null);){const d=i[u];l[d.lane]===null&&(l[d.lane]=d.end),u--}o=Math.max(...l.filter(d=>d!==null))}return Math.max(o-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const r=[];if(this.itemSizeCache.size===0)return r;const i=this.getMeasurements();for(const o of i)o&&this.itemSizeCache.has(o.key)&&r.push({index:o.index,key:o.key,start:o.start,size:o.size,end:o.end,lane:o.lane});return r},this._scrollToOffset=(r,{adjustments:i,behavior:o})=>{this._intendedScrollOffset=r+(i??0),this.options.scrollToFn(r,{behavior:o,adjustments:i},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(n)}applyScrollAdjustment(n,r){n!==0&&(am()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=n:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=n,behavior:r}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const i=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,o=i?i[0]:this.scrollState.lastTargetOffset,l=1,u=o!==this.scrollState.lastTargetOffset;if(!u&&vI(o,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=l){this.getScrollOffset()!==o&&this._scrollToOffset(o,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,u){const d=this.getSize()||600,m=Math.abs(o-this.getScrollOffset()),p=this.scrollState.behavior==="smooth"&&m>d;this.scrollState.lastTargetOffset=o,p||(this.scrollState.behavior="auto"),this._scrollToOffset(o,{adjustments:void 0,behavior:p?"smooth":"auto"})}this.scheduleScrollReconcile()}}const qC=(e,n,r,i)=>{for(;e<=n;){const o=(e+n)/2|0,l=r(o);if(li)n=o-1;else return o}return e>0?e-1:0};function OI(e,n,r){let i=0;for(;i<=n;){const o=(i+n)/2|0,l=e[o*2];if(lr)n=o-1;else return o}return i>0?i-1:0}function AI(e,n,r,i,o){const l=e.length-1;if(e.length<=i)return{startIndex:0,endIndex:l};if(i===1&&o!==null){const p=OI(o,l,r);let y=p;const v=r+n;for(;ye[p].start,r),m=d;if(i===1)for(;m1){const p=Array(i).fill(0);for(;mv=0&&y.some(v=>v>=r);){const v=e[d];y[v.lane]=v.start,d--}d=Math.max(0,d-d%i),m=Math.min(l,m+(i-1-m%i))}return{startIndex:d,endIndex:m}}const im=typeof document<"u"?S.useLayoutEffect:S.useEffect;function MI({useFlushSync:e=!0,directDomUpdates:n=!1,directDomUpdatesMode:r="transform",...i}){const o=S.useReducer(p=>p+1,0)[1],l=S.useRef({enabled:n,mode:r,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});l.current.enabled=n,l.current.mode=r;const u=p=>{const y=l.current;if(!y.enabled||!y.container)return;const v=p.getTotalSize();if(v!==y.lastSize){y.lastSize=v;const R=p.options.horizontal?"width":"height";y.container.style[R]=`${v}px`}const b=!!p.options.horizontal,x=y.mode==="transform",w=b?"left":"top",_=p.options.scrollMargin,E=p.getVirtualItems();for(const R of E){const T=R.start-_,O=p.elementsCache.get(R.key);O&&y.lastPositions.get(O)!==T&&(y.lastPositions.set(O,T),x?O.style.transform=b?`translate3d(${T}px, 0, 0)`:`translate3d(0, ${T}px, 0)`:O.style[w]=`${T}px`)}},d={...i,onChange:(p,y)=>{var v;const b=l.current;let x=!0;if(b.enabled){u(p);const w=p.range,_=b.prevRange;x=!_||_.isScrolling!==p.isScrolling||_.startIndex!==w?.startIndex||_.endIndex!==w?.endIndex,x&&(b.prevRange=w?{startIndex:w.startIndex,endIndex:w.endIndex,isScrolling:p.isScrolling}:null)}x&&(e&&y?Ni.flushSync(o):o()),(v=i.onChange)==null||v.call(i,p,y)}},[m]=S.useState(()=>{const p=new TI(d);return Object.assign(p,{containerRef:y=>{const v=l.current;if(v.container=y,v.lastSize=null,y&&v.enabled){const b=p.getTotalSize();v.lastSize=b;const x=p.options.horizontal?"width":"height";y.style[x]=`${b}px`}}})});return m.setOptions(d),im(()=>m._didMount(),[]),im(()=>m._willUpdate()),im(()=>{u(m)}),m}function NI(e){return MI({observeElementRect:wI,observeElementOffset:CI,scrollToFn:jI,...e})}function DI(e,n){const r=[],i=(o,l)=>{for(const u of o)r.push({node:u,depth:l}),u.dir&&n.has(u.path)&&i(u.children||[],l+1)};return i(e?.children||[],0),r}function zI(e){const{root:n,expanded:r,onToggle:i,currentPath:o,listingShowing:l,onOpen:u}=e,d=S.useRef(null),m=S.useMemo(()=>DI(n,r),[n,r]),p=NI({count:m.length,getScrollElement:()=>d.current,estimateSize:()=>window.matchMedia("(max-width: 768px)").matches?44:28,overscan:12,getItemKey:y=>m[y].node.path});return S.useEffect(()=>{if(!o)return;const y=m.findIndex(v=>v.node.path===o);y>=0&&p.scrollToIndex(y,{align:"auto"})},[o,m]),f.jsx("nav",{id:"tree","aria-label":"Files",ref:d,children:f.jsx("div",{style:{height:p.getTotalSize(),position:"relative"},children:p.getVirtualItems().map(y=>{const{node:v,depth:b}=m[y.index],x=v.dir?r.has(v.path):!1,w=()=>{if(v.dir&&o===v.path&&l){i(v.path);return}u(v.path),v.dir||mr()};return f.jsxs("div",{className:"row "+(v.dir?"dir":"file")+(o===v.path?" active":"")+(v.dir&&!x?" collapsed":""),"data-path":v.path,tabIndex:0,role:"button",title:v.name,"aria-expanded":v.dir?x:void 0,style:{position:"absolute",top:0,left:0,right:0,transform:`translateY(${y.start}px)`,paddingLeft:8+b*13},onClick:w,onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),w())},children:[Array.from({length:b},(_,E)=>f.jsx("span",{className:"tguide",style:{left:8+E*13+5},"aria-hidden":"true"},E)),f.jsx("span",{className:"chev",onClick:_=>{v.dir&&(_.stopPropagation(),i(v.path))},children:f.jsx(ut,{name:"chevd"})}),f.jsx("span",{className:"ticon",children:f.jsx(ut,{name:v.dir?"folder":"doc"})}),f.jsx("span",{className:"label",children:v.name})]},y.key)})})})}function kI(e){const n=e.split("/"),r=[];let i="";for(let o=0;o{i=i?i+"/"+o:o;const u=i,d=l===r.length-1;return f.jsxs("span",{children:[l>0&&f.jsx("span",{className:"crumb-sep",children:"/"}),d?f.jsx("span",{children:o}):f.jsx("span",{className:"crumb-seg",title:u,onClick:()=>n(u),children:o})]},u)})})}function cw(e){if(e==="")return[];const n=e.split(`
`);return n[n.length-1]===""&&n.pop(),n}const $I=4e6;function II(e,n){let r=0;for(;ro.push({op:"-",line:l[v],an:r+v+1}),y=v=>o.push({op:"+",line:u[v],bn:r+v+1});if(d*m>$I){for(let v=0;v=0;w--)for(let _=m-1;_>=0;_--)v[w][_]=l[w]===u[_]?v[w+1][_+1]+1:Math.max(v[w+1][_],v[w][_+1]);let b=0,x=0;for(;b=v[b][x+1]?p(b++):y(x++);for(;bi.op==="+").length,del:r.filter(i=>i.op==="-").length}}const GC=1<<20,FI=8192;function VI(e){if(e.byteLength>GC)return{kind:"too-large",size:e.byteLength};if(e.subarray(0,FI).includes(0))return{kind:"binary"};try{return{kind:"text",text:new TextDecoder("utf-8",{fatal:!0}).decode(e)}}catch{return{kind:"binary"}}}function Jm(e,n,r,i){let o=e+"blob?sha="+encodeURIComponent(n);return r&&(o+="&name="+encodeURIComponent(r)),i&&(o+="&download=1"),o}async function UI(e){const n=await yj(e),r=Number(n.headers.get("Content-Length"));return r>GC?{kind:"too-large",size:r}:VI(new Uint8Array(await n.arrayBuffer()))}function ZC(e,n,r,i){return Pt({queryKey:n,queryFn:()=>UI(e),enabled:r,...i?{staleTime:1/0,gcTime:1/0}:{},retry:!1})}function uw(e,n,r){return ZC(n?Jm(e,n):"",["blob",e,n],!!n,!0)}function HI(e){return e.slice(e.lastIndexOf("/")+1)}function BI({apiBase:e,path:n,prev:r,cur:i}){const o=HI(n);return f.jsxs("span",{className:"dv-dl",children:[f.jsx("a",{href:Jm(e,r,o,!0),children:"download previous"}),f.jsx("a",{href:Jm(e,i,o,!0),children:"download this version"})]})}function qI({apiBase:e,path:n,prev:r,cur:i}){const o=uw(e,r),l=uw(e,i),u=o.data?.kind==="text"&&l.data?.kind==="text",d=S.useMemo(()=>o.data?.kind==="text"&&l.data?.kind==="text"?PI(o.data.text,l.data.text):null,[o.data,l.data]);if(o.error||l.error)return f.jsx("div",{className:"dv dv-msg",children:"Could not load one of the versions."});if(!o.data||!l.data)return f.jsx("div",{className:"dv dv-msg",children:"Loading changes…"});if(!u){const v=o.data.kind==="too-large"||l.data.kind==="too-large";return f.jsxs("div",{className:"dv dv-msg",children:[v?"Too large to diff — download to compare.":"Binary file — no diff available.",f.jsx(BI,{apiBase:e,path:n,prev:r,cur:i})]})}const{lines:m,add:p,del:y}=d;return f.jsxs("div",{className:"dv",children:[f.jsxs("div",{className:"dv-head",children:[f.jsxs("span",{className:"dv-stat",children:[f.jsxs("span",{className:"dv-add",children:["+",p]})," ",f.jsxs("span",{className:"dv-del",children:["−",y]})]}),p===0&&y===0&&f.jsx("span",{className:"dv-same",children:"No line changes"})]}),f.jsx("div",{className:"dv-body",children:m.map((v,b)=>f.jsxs("div",{className:"dv-line dv-"+(v.op==="="?"ctx":v.op==="+"?"ins":"rm"),children:[f.jsx("span",{className:"dv-n",children:v.an??""}),f.jsx("span",{className:"dv-n",children:v.bn??""}),f.jsx("span",{className:"dv-mark",children:v.op==="="?" ":v.op}),f.jsx("span",{className:"dv-text",children:v.line||" "})]},b))})]})}const GI={add:"added",edit:"edited",delete:"deleted"};function KC({text:e}){return f.jsx(f.Fragment,{children:e.split(/(https?:\/\/\S+)/).map((n,r)=>/^https?:\/\//.test(n)?f.jsx("a",{href:n,target:"_blank",rel:"noopener",children:n},r):n)})}function pg({entry:e,apiBase:n,onOpen:r,diff:i,restore:o,remove:l,restoreSha:u,recreates:d,inRun:m,read:p}){const[y,v]=S.useState(!1),[b,x]=S.useState(!1),w=e.kind==="put"?"edit":e.kind,_=dd(e),E=[e.device.name||e.device.id,e.device.os].filter(Boolean).join(" · "),R=w!=="delete",T=!!i&&w!=="delete"&&!!e.blob,O=!!m&&w==="add",N=!!o&&!!u&&!O,z=!!l&&O,U=!!o?.busy&&o.busy===e.path+u,$=!!l?.busy&&l.busy===e.path,F=R&&!!e.blob,ve=e.path.split("/").pop()||e.path,ye=new Date(e.time).toLocaleString(),me=n+"blob?sha="+e.blob+"&name="+encodeURIComponent(ve)+"&download=1",de=()=>x(!b),le=te=>{te.target.tagName!=="A"&&R&&r(e.path,e.blob)};return f.jsxs("div",{className:"hentry "+w+(R?" clickable":""),tabIndex:R?0:void 0,role:R?"button":void 0,onClick:le,onKeyDown:te=>{R&&(te.key==="Enter"||te.key===" ")&&(te.preventDefault(),r(e.path,e.blob))},children:[f.jsxs("div",{className:"hline",children:[f.jsx("span",{className:"hkind",children:GI[w]||w}),p&&f.jsx("span",{className:"hread",title:"This run read this file before changing it",children:"read"}),f.jsx("span",{className:"hpath",children:e.path}),f.jsx("span",{className:"htime",children:ye})]}),f.jsxs("div",{className:"hmeta",children:[f.jsx("span",{className:"hwho",children:_}),f.jsx("span",{className:"hdev",children:E}),f.jsx("span",{className:"hsize",children:e.size?mg(e.size):""}),N&&f.jsxs("button",{type:"button",className:"hrestore-btn",disabled:U,title:"Put this version of "+e.path+" back as a new change",onClick:te=>{te.stopPropagation(),o.onRestore(e.path,u,!!d)},onKeyDown:te=>te.stopPropagation(),children:[f.jsx(ut,{name:"hist"}),U?"restoring…":"restore"]}),z&&f.jsxs("button",{type:"button",className:"hremove-btn",disabled:$,title:"Remove "+e.path+" — this run created it",onClick:te=>{te.stopPropagation(),l.onRemove(e.path)},onKeyDown:te=>te.stopPropagation(),children:[f.jsx(ut,{name:"trash"}),$?"removing…":"undo — remove file"]})]}),e.note&&!m&&f.jsx("div",{className:"hnote"+(y?" open":""),tabIndex:0,role:"button",title:y?"Collapse note":"Show full note","aria-expanded":y,onClick:te=>{te.stopPropagation(),te.target.tagName!=="A"&&v(!y)},onKeyDown:te=>{(te.key==="Enter"||te.key===" ")&&(te.preventDefault(),te.stopPropagation(),v(!y))},children:f.jsx(KC,{text:e.note})}),(T||F)&&f.jsxs("div",{className:"hactions",children:[T&&(i.prev?f.jsxs("button",{type:"button",className:"hdiff-btn"+(b?" open":""),"aria-expanded":b,onClick:te=>{te.stopPropagation(),de()},onKeyDown:te=>te.stopPropagation(),children:[f.jsx(ut,{name:b?"chevd":"chev"}),b?"hide changes":"show changes"]}):f.jsx("div",{className:"hdiff-none",children:"First version — nothing to compare against"})),F&&f.jsxs(f.Fragment,{children:[f.jsxs("button",{type:"button",className:"hver-btn","aria-label":`Open ${ve} as of ${ye}`,onClick:te=>{te.stopPropagation(),r(e.path,e.blob)},onKeyDown:te=>te.stopPropagation(),children:[f.jsx(ut,{name:"clock"}),"Open this version"]}),f.jsxs("a",{className:"hver-btn",download:!0,href:me,"aria-label":`Download ${ve} as of ${ye}`,onClick:te=>te.stopPropagation(),onKeyDown:te=>{te.stopPropagation(),te.key===" "&&(te.preventDefault(),te.currentTarget.click())},children:[f.jsx(ut,{name:"download"}),"Download"]})]})]}),T&&i.prev&&b&&f.jsx("div",{onClick:te=>te.stopPropagation(),children:f.jsx(qI,{apiBase:i.apiBase,path:e.path,prev:i.prev,cur:e.blob})})]})}function ZI(e){const{node:n,heatMap:r,onOpen:i}=e,o=(n.children||[]).slice().sort((p,y)=>Number(y.dir||!1)-Number(p.dir||!1)||p.name.localeCompare(y.name)),l=o.filter(p=>p.dir).length,u=o.length-l,d=[];l&&d.push(l+(l===1?" folder":" folders")),u&&d.push(u+(u===1?" file":" files"));const m=sw(r,n.path,!0);return m&&d.push(Jo(m)+" in 30 days"),f.jsxs("div",{className:"dirlist",children:[f.jsxs("h1",{className:"dl-title",children:[f.jsx("span",{className:"dl-title-icon",children:f.jsx(ut,{name:"folder"})}),f.jsx("span",{children:n.name})]}),f.jsx("p",{className:"dl-sub",children:d.join(" · ")||"Empty folder"}),o.length===0?f.jsx("div",{className:"dl-empty",children:"Nothing in this folder yet."}):f.jsx("div",{className:"dl-items",children:o.map(p=>{let y="";if(p.dir){const b=(p.children||[]).length;y=b+(b===1?" item":" items")}else y=[p.size?mg(p.size):"",p.time?new Date(p.time).toLocaleDateString():""].filter(Boolean).join(" · ");const v=sw(r,p.path,!!p.dir);return v&&(y=Jo(v)+(y?" · "+y:"")),f.jsxs("div",{className:"dl-row",tabIndex:0,role:"button",title:p.path,onClick:()=>i(p.path),onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),i(p.path))},children:[f.jsx("span",{className:"ticon",children:f.jsx(ut,{name:p.dir?"folder":"doc"})}),f.jsx("span",{className:"dl-name",children:p.name}),v&&f.jsx("span",{className:"heatdot lvl"+rI(v),role:"img","aria-label":Jo(v)+" in 30 days",title:Jo(v)+" in 30 days"}),f.jsx("span",{className:"dl-meta",children:y})]},p.path)})}),e.hub&&f.jsx(KI,{apiBase:e.apiBase,prefix:n.path+"/",onOpen:i,onFullHistory:()=>e.onFullHistory(n.path+"/"),onRendered:e.onRendered})]})}function KI(e){const n=pI(e.apiBase,e.prefix,!0),{onRendered:r}=e;return S.useEffect(()=>{n&&n.length&&r&&r()},[n,r]),!n||n.length===0?null:f.jsxs("div",{className:"dl-history",children:[f.jsx("h3",{className:"dl-h3",children:"Recent changes"}),f.jsx("div",{className:"history dl-hlist",children:n.map((i,o)=>f.jsx(pg,{entry:i,apiBase:e.apiBase,onOpen:e.onOpen},o))}),f.jsx("button",{className:"ai-btn dl-more",onClick:e.onFullHistory,children:"Full history"})]})}const YC=5e3;function YI(e,n,r=YC){const i=[];let o=[],l="",u=!1,d=0;const m=()=>{o.push(l),l="",i.length()=>o(""),[r,o]),w$.test(r)?f.jsx(WI,{...e}):OC.test(r)?f.jsx("iframe",{className:"htmlview",sandbox:"allow-scripts",src:l,title:r,onLoad:e.onRendered}):AC.test(r)?f.jsx("iframe",{className:"pdfview",src:l,title:r,onLoad:e.onRendered}):S$.test(r)?f.jsx(nP,{src:l,alt:r,version:i,onRendered:e.onRendered}):_$.test(r)?f.jsx(dw,{...e,fileURL:l,delim:/\.tsv$/i.test(r)?" ":","}):C$.test(r)?f.jsx(dw,{...e,fileURL:l}):f.jsx(XI,{...e,fileURL:l})}function XI(e){const{apiBase:n,path:r,version:i,fileURL:o,onRendered:l}=e,{data:u,error:d}=ZC(o,["text",o],!0,!!i);return S.useEffect(()=>{u&&l?.()},[u,l]),d?f.jsx(fd,{version:i,err:d}):u?u.kind==="text"?f.jsx("pre",{className:"plain",children:u.text},r):f.jsx(JI,{apiBase:n,path:r,version:i,fileURL:o,children:u.kind==="too-large"?`Too large to preview (${mg(u.size)}).`:"No preview for this file type."}):null}function JI(e){const{apiBase:n,path:r,version:i,fileURL:o}=e;return f.jsxs("div",{className:"filecard",children:[f.jsx("div",{className:"name",children:r.split("/").pop()}),f.jsx("p",{children:e.children}),f.jsx("a",{className:"btn",download:!0,href:i?o+"&download=1":n+"download?path="+encodeURIComponent(r),children:"Download"})]})}function WI(e){const{apiBase:n,path:r,version:i,heatMap:o,flatFiles:l,onOpenFile:u,onMeta:d,onRendered:m}=e,{data:p,error:y}=Pt({queryKey:["render",n,r,i||""],queryFn:()=>Bt(n+"render?path="+encodeURIComponent(r)+(i?"&sha="+i:"")),retry:i?!1:void 0}),v=S.useMemo(()=>p?tP(p.html,r,n):"",[p,r,n]),[b,x]=S.useState(null);return S.useEffect(()=>{if(x(null),!y2(v))return;let w=!1;return b2(v).then(_=>{w||x(_)}),()=>{w=!0}},[v]),S.useEffect(()=>{if(!p)return;const w=[];(p.user_name||p.user||p.author)&&w.push(dd(p)+(p.device?" on "+p.device:"")),p.time&&w.push(new Date(p.time).toLocaleString());const _=i?null:o&&o[p.path];_&&ka(_)&&w.push(Jo(_)+" / 30d"),d(w.join(" · ")),m?.()},[p,i,o,d,m]),y?f.jsx(fd,{version:i,err:y}):p?f.jsx("div",{dangerouslySetInnerHTML:{__html:b??v},onClick:w=>eP(w,r,l,u)}):null}function eP(e,n,r,i){const o=e.target.closest("a");if(!o||!e.currentTarget.contains(o))return;const l=o.getAttribute("href")||"",u=n.includes("/")?n.slice(0,n.lastIndexOf("/")):"";l.startsWith("wiki:")?(e.preventDefault(),aP(decodeURIComponent(l.slice(5)),r,i)):/^([a-z]+:|\/|#)/i.test(l)||(e.preventDefault(),i(MC(u,decodeURIComponent(l))))}function tP(e,n,r){const i=n.includes("/")?n.slice(0,n.lastIndexOf("/")):"",o=u=>r+"file?path="+encodeURIComponent(u),l=new DOMParser().parseFromString(e,"text/html");for(const u of l.querySelectorAll("img")){const d=u.getAttribute("src")||"";/^\s*data:image\/svg/i.test(d)?u.removeAttribute("src"):/^([a-z]+:|\/)/i.test(d)||u.setAttribute("src",o(MC(i,d)))}for(const u of l.querySelectorAll("a")){const d=u.getAttribute("href")||"";/^\s*data:/i.test(d)?u.removeAttribute("href"):/^https?:/i.test(d)&&(u.setAttribute("target","_blank"),u.setAttribute("rel","noopener"))}return l.body.innerHTML}function nP(e){const[n,r]=S.useState(!1);return n?f.jsx(fd,{version:e.version,err:new Error("could not be loaded")}):f.jsx("img",{src:e.src,alt:e.alt,onLoad:e.onRendered,onError:()=>r(!0)})}function fd({version:e,err:n}){return f.jsx("div",{className:"empty",children:e?"That version isn't available.":"Could not load file: "+n.message})}function dw(e){const{path:n,version:r,fileURL:i,delim:o,onRendered:l}=e,{data:u,error:d}=Pt({queryKey:["text",i],queryFn:async()=>{const p=await fetch(i);if(!p.ok)throw new Error(await p.text());return p.text()},retry:r?!1:void 0});S.useEffect(()=>{u!=null&&l?.()},[u,l]);const m=S.useMemo(()=>o&&u!=null?YI(u,o,YC):null,[u,o]);return d?f.jsx(fd,{version:r,err:d}):u==null?null:m?f.jsx(rP,{csv:m},n):f.jsx("pre",{className:"plain",children:u},n)}function rP({csv:e}){const[n,...r]=e.rows,i=e.rows.reduce((l,u)=>Math.max(l,u.length),0),o=Array.from({length:i},(l,u)=>u);return f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"csvbox",children:f.jsxs("table",{className:"csvview",children:[f.jsx("thead",{children:f.jsx("tr",{children:o.map(l=>f.jsx("th",{children:n[l]??""},l))})}),f.jsx("tbody",{children:r.map((l,u)=>f.jsx("tr",{children:o.map(d=>f.jsx("td",{children:l[d]??""},d))},u))})]})}),e.truncated>0&&f.jsxs("p",{className:"csvnote",children:["showing ",e.rows.length.toLocaleString()," of"," ",(e.rows.length+e.truncated).toLocaleString()," rows — Download for the rest"]})]})}function aP(e,n,r){const i=e.toLowerCase(),o=n.find(l=>l.path.toLowerCase()===i||l.path.toLowerCase()===i+".md")||n.find(l=>{const u=l.name.toLowerCase();return u===i||u===i+".md"});o&&r(o.path)}const iP=[{value:"",label:"Never"},{value:"24h",label:"In 24 hours"},{value:"168h",label:"In 7 days"},{value:"720h",label:"In 30 days"}];function sP({url:e,copied:n,onClose:r}){const i=e.split("/s/")[1],[o,l]=S.useState(""),[u,d]=S.useState(),[m,p]=S.useState(!1),y=S.useRef(null);async function v(b){const x=o;l(b),p(!0);try{const w=await Wn("PATCH","/api/shares/"+i,{expires_in:b});d(w.expires)}catch(w){Ke(w.message,!0),l(x)}finally{p(!1)}}return f.jsx(Ju,{open:!0,onOpenChange:b=>!b&&r(),children:f.jsxs(Wu,{className:"modal",showCloseButton:!1,onOpenAutoFocus:b=>{b.preventDefault(),y.current?.focus()},children:[f.jsx(_l,{asChild:!0,children:f.jsx("h3",{children:"Public link"})}),f.jsxs("p",{children:[f.jsx("b",{children:"Anyone with this link can view this file"})," — no account needed. It always shows the latest version until it expires or you revoke it."]}),f.jsx("div",{className:"modal-url",children:e}),f.jsxs("div",{className:"modal-expiry",children:[f.jsx("label",{htmlFor:"share-expiry",children:"Expires"}),f.jsx("select",{id:"share-expiry",value:o,disabled:m,onChange:b=>v(b.target.value),children:iP.map(b=>f.jsx("option",{value:b.value,children:b.label},b.value))}),f.jsx("span",{className:"modal-expiry-note",children:zC(u)})]}),f.jsxs("div",{className:"modal-actions",children:[f.jsx(vt,{ref:y,variant:"primary",onClick:()=>qs(e).then(b=>Ke(b?"Copied.":"Select and copy the link above.")),children:n?"Copied ✓":"Copy link"}),f.jsx(vt,{variant:"subtle",onClick:()=>window.open(e,"_blank"),children:"Open"}),f.jsx(vt,{variant:"subtle",onClick:r,children:"Done"})]})]})})}function oP({shares:e,canRevoke:n,onChanged:r}){return e.length===0?null:f.jsxs("div",{className:"share-banner",role:"status",children:[f.jsxs("div",{className:"sb-head",children:[f.jsx(ut,{name:"share"}),f.jsx("b",{children:"Publicly shared"}),f.jsxs("span",{className:"sb-count",children:[e.length," active link",e.length>1?"s":""]})]}),f.jsxs("p",{className:"sb-note",children:[f.jsx("b",{children:"Anyone with this link can view this file"})," — no account needed. It always shows the latest version until you revoke it.",e.some(i=>i.opens!==void 0)&&f.jsxs(f.Fragment,{children:[" ",LC]})]}),e.map(i=>f.jsxs("div",{className:"sb-link",children:[f.jsx("span",{className:"sb-url mono",title:i.url,children:i.url}),f.jsx("span",{className:"sb-meta",children:kC(i,!1)}),f.jsxs("span",{className:"sb-actions",children:[f.jsx(vt,{variant:"subtle",onClick:()=>qs(i.url).then(o=>Ke(o?"Copied.":"Select and copy the link.")),children:"Copy link"}),f.jsx(vt,{variant:"subtle",onClick:()=>window.open(i.url,"_blank"),children:"Open"}),n&&f.jsx("button",{className:"ai-del","aria-label":`Revoke the share of ${i.path}`,onClick:()=>IC(i,r),children:"Revoke"})]})]},i.token))]})}var fw=1,lP=.9,cP=.8,uP=.17,sm=.1,om=.999,dP=.9999,fP=.99,hP=/[\\\/_+.#"@\[\(\{&]/,mP=/[\\\/_+.#"@\[\(\{&]/g,pP=/[\s-]/,QC=/[\s-]/g;function Wm(e,n,r,i,o,l,u){if(l===n.length)return o===e.length?fw:fP;var d=`${o},${l}`;if(u[d]!==void 0)return u[d];for(var m=i.charAt(l),p=r.indexOf(m,o),y=0,v,b,x,w;p>=0;)v=Wm(e,n,r,i,p+1,l+1,u),v>y&&(p===o?v*=fw:hP.test(e.charAt(p-1))?(v*=cP,x=e.slice(o,p-1).match(mP),x&&o>0&&(v*=Math.pow(om,x.length))):pP.test(e.charAt(p-1))?(v*=lP,w=e.slice(o,p-1).match(QC),w&&o>0&&(v*=Math.pow(om,w.length))):(v*=uP,o>0&&(v*=Math.pow(om,p-o))),e.charAt(p)!==n.charAt(l)&&(v*=dP)),(vv&&(v=b*sm)),v>y&&(y=v),p=r.indexOf(m,p+1);return u[d]=y,y}function hw(e){return e.toLowerCase().replace(QC," ")}function gP(e,n,r){return e=r&&r.length>0?`${e+" "+r.join(" ")}`:e,Wm(e,n,hw(e),hw(n),0,0,{})}var Zo='[cmdk-group=""]',lm='[cmdk-group-items=""]',vP='[cmdk-group-heading=""]',XC='[cmdk-item=""]',mw=`${XC}:not([aria-disabled="true"])`,ep="cmdk-item-select",As="data-value",yP=(e,n,r)=>gP(e,n,r),JC=S.createContext(void 0),jl=()=>S.useContext(JC),WC=S.createContext(void 0),gg=()=>S.useContext(WC),eE=S.createContext(void 0),tE=S.forwardRef((e,n)=>{let r=Ms(()=>{var M,B;return{search:"",value:(B=(M=e.value)!=null?M:e.defaultValue)!=null?B:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),i=Ms(()=>new Set),o=Ms(()=>new Map),l=Ms(()=>new Map),u=Ms(()=>new Set),d=nE(e),{label:m,children:p,value:y,onValueChange:v,filter:b,shouldFilter:x,loop:w,disablePointerSelection:_=!1,vimBindings:E=!0,...R}=e,T=dn(),O=dn(),N=dn(),z=S.useRef(null),U=OP();Ai(()=>{if(y!==void 0){let M=y.trim();r.current.value=M,$.emit()}},[y]),Ai(()=>{U(6,le)},[]);let $=S.useMemo(()=>({subscribe:M=>(u.current.add(M),()=>u.current.delete(M)),snapshot:()=>r.current,setState:(M,B,X)=>{var Y,ce,ae,be;if(!Object.is(r.current[M],B)){if(r.current[M]=B,M==="search")de(),ye(),U(1,me);else if(M==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let xe=document.getElementById(N);xe?xe.focus():(Y=document.getElementById(T))==null||Y.focus()}if(U(7,()=>{var xe;r.current.selectedItemId=(xe=te())==null?void 0:xe.id,$.emit()}),X||U(5,le),((ce=d.current)==null?void 0:ce.value)!==void 0){let xe=B??"";(be=(ae=d.current).onValueChange)==null||be.call(ae,xe);return}}$.emit()}},emit:()=>{u.current.forEach(M=>M())}}),[]),F=S.useMemo(()=>({value:(M,B,X)=>{var Y;B!==((Y=l.current.get(M))==null?void 0:Y.value)&&(l.current.set(M,{value:B,keywords:X}),r.current.filtered.items.set(M,ve(B,X)),U(2,()=>{ye(),$.emit()}))},item:(M,B)=>(i.current.add(M),B&&(o.current.has(B)?o.current.get(B).add(M):o.current.set(B,new Set([M]))),U(3,()=>{de(),ye(),r.current.value||me(),$.emit()}),()=>{l.current.delete(M),i.current.delete(M),r.current.filtered.items.delete(M);let X=te();U(4,()=>{de(),X?.getAttribute("id")===M&&me(),$.emit()})}),group:M=>(o.current.has(M)||o.current.set(M,new Set),()=>{l.current.delete(M),o.current.delete(M)}),filter:()=>d.current.shouldFilter,label:m||e["aria-label"],getDisablePointerSelection:()=>d.current.disablePointerSelection,listId:T,inputId:N,labelId:O,listInnerRef:z}),[]);function ve(M,B){var X,Y;let ce=(Y=(X=d.current)==null?void 0:X.filter)!=null?Y:yP;return M?ce(M,r.current.search,B):0}function ye(){if(!r.current.search||d.current.shouldFilter===!1)return;let M=r.current.filtered.items,B=[];r.current.filtered.groups.forEach(Y=>{let ce=o.current.get(Y),ae=0;ce.forEach(be=>{let xe=M.get(be);ae=Math.max(xe,ae)}),B.push([Y,ae])});let X=z.current;ge().sort((Y,ce)=>{var ae,be;let xe=Y.getAttribute("id"),Oe=ce.getAttribute("id");return((ae=M.get(Oe))!=null?ae:0)-((be=M.get(xe))!=null?be:0)}).forEach(Y=>{let ce=Y.closest(lm);ce?ce.appendChild(Y.parentElement===ce?Y:Y.closest(`${lm} > *`)):X.appendChild(Y.parentElement===X?Y:Y.closest(`${lm} > *`))}),B.sort((Y,ce)=>ce[1]-Y[1]).forEach(Y=>{var ce;let ae=(ce=z.current)==null?void 0:ce.querySelector(`${Zo}[${As}="${encodeURIComponent(Y[0])}"]`);ae?.parentElement.appendChild(ae)})}function me(){let M=ge().find(X=>X.getAttribute("aria-disabled")!=="true"),B=M?.getAttribute(As);$.setState("value",B||void 0)}function de(){var M,B,X,Y;if(!r.current.search||d.current.shouldFilter===!1){r.current.filtered.count=i.current.size;return}r.current.filtered.groups=new Set;let ce=0;for(let ae of i.current){let be=(B=(M=l.current.get(ae))==null?void 0:M.value)!=null?B:"",xe=(Y=(X=l.current.get(ae))==null?void 0:X.keywords)!=null?Y:[],Oe=ve(be,xe);r.current.filtered.items.set(ae,Oe),Oe>0&&ce++}for(let[ae,be]of o.current)for(let xe of be)if(r.current.filtered.items.get(xe)>0){r.current.filtered.groups.add(ae);break}r.current.filtered.count=ce}function le(){var M,B,X;let Y=te();Y&&(((M=Y.parentElement)==null?void 0:M.firstChild)===Y&&((X=(B=Y.closest(Zo))==null?void 0:B.querySelector(vP))==null||X.scrollIntoView({block:"nearest"})),Y.scrollIntoView({block:"nearest"}))}function te(){var M;return(M=z.current)==null?void 0:M.querySelector(`${XC}[aria-selected="true"]`)}function ge(){var M;return Array.from(((M=z.current)==null?void 0:M.querySelectorAll(mw))||[])}function L(M){let B=ge()[M];B&&$.setState("value",B.getAttribute(As))}function K(M){var B;let X=te(),Y=ge(),ce=Y.findIndex(be=>be===X),ae=Y[ce+M];(B=d.current)!=null&&B.loop&&(ae=ce+M<0?Y[Y.length-1]:ce+M===Y.length?Y[0]:Y[ce+M]),ae&&$.setState("value",ae.getAttribute(As))}function re(M){let B=te(),X=B?.closest(Zo),Y;for(;X&&!Y;)X=M>0?jP(X,Zo):TP(X,Zo),Y=X?.querySelector(mw);Y?$.setState("value",Y.getAttribute(As)):K(M)}let W=()=>L(ge().length-1),ne=M=>{M.preventDefault(),M.metaKey?W():M.altKey?re(1):K(1)},D=M=>{M.preventDefault(),M.metaKey?L(0):M.altKey?re(-1):K(-1)};return S.createElement($e.div,{ref:n,tabIndex:-1,...R,"cmdk-root":"",onKeyDown:M=>{var B;(B=R.onKeyDown)==null||B.call(R,M);let X=M.nativeEvent.isComposing||M.keyCode===229;if(!(M.defaultPrevented||X))switch(M.key){case"n":case"j":{E&&M.ctrlKey&&ne(M);break}case"ArrowDown":{ne(M);break}case"p":case"k":{E&&M.ctrlKey&&D(M);break}case"ArrowUp":{D(M);break}case"Home":{M.preventDefault(),L(0);break}case"End":{M.preventDefault(),W();break}case"Enter":{M.preventDefault();let Y=te();if(Y){let ce=new Event(ep);Y.dispatchEvent(ce)}}}}},S.createElement("label",{"cmdk-label":"",htmlFor:F.inputId,id:F.labelId,style:MP},m),md(e,M=>S.createElement(WC.Provider,{value:$},S.createElement(JC.Provider,{value:F},M))))}),bP=S.forwardRef((e,n)=>{var r,i;let o=dn(),l=S.useRef(null),u=S.useContext(eE),d=jl(),m=nE(e),p=(i=(r=m.current)==null?void 0:r.forceMount)!=null?i:u?.forceMount;Ai(()=>{if(!p)return d.item(o,u?.id)},[p]);let y=rE(o,l,[e.value,e.children,l],e.keywords),v=gg(),b=qa(U=>U.value&&U.value===y.current),x=qa(U=>p||d.filter()===!1?!0:U.search?U.filtered.items.get(o)>0:!0);S.useEffect(()=>{let U=l.current;if(!(!U||e.disabled))return U.addEventListener(ep,w),()=>U.removeEventListener(ep,w)},[x,e.onSelect,e.disabled]);function w(){var U,$;_(),($=(U=m.current).onSelect)==null||$.call(U,y.current)}function _(){v.setState("value",y.current,!0)}if(!x)return null;let{disabled:E,value:R,onSelect:T,forceMount:O,keywords:N,...z}=e;return S.createElement($e.div,{ref:Fs(l,n),...z,id:o,"cmdk-item":"",role:"option","aria-disabled":!!E,"aria-selected":!!b,"data-disabled":!!E,"data-selected":!!b,onPointerMove:E||d.getDisablePointerSelection()?void 0:_,onClick:E?void 0:w},e.children)}),xP=S.forwardRef((e,n)=>{let{heading:r,children:i,forceMount:o,...l}=e,u=dn(),d=S.useRef(null),m=S.useRef(null),p=dn(),y=jl(),v=qa(x=>o||y.filter()===!1?!0:x.search?x.filtered.groups.has(u):!0);Ai(()=>y.group(u),[]),rE(u,d,[e.value,e.heading,m]);let b=S.useMemo(()=>({id:u,forceMount:o}),[o]);return S.createElement($e.div,{ref:Fs(d,n),...l,"cmdk-group":"",role:"presentation",hidden:v?void 0:!0},r&&S.createElement("div",{ref:m,"cmdk-group-heading":"","aria-hidden":!0,id:p},r),md(e,x=>S.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":r?p:void 0},S.createElement(eE.Provider,{value:b},x))))}),wP=S.forwardRef((e,n)=>{let{alwaysRender:r,...i}=e,o=S.useRef(null),l=qa(u=>!u.search);return!r&&!l?null:S.createElement($e.div,{ref:Fs(o,n),...i,"cmdk-separator":"",role:"separator"})}),SP=S.forwardRef((e,n)=>{let{onValueChange:r,...i}=e,o=e.value!=null,l=gg(),u=qa(p=>p.search),d=qa(p=>p.selectedItemId),m=jl();return S.useEffect(()=>{e.value!=null&&l.setState("search",e.value)},[e.value]),S.createElement($e.input,{ref:n,...i,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":m.listId,"aria-labelledby":m.labelId,"aria-activedescendant":d,id:m.inputId,type:"text",value:o?e.value:u,onChange:p=>{o||l.setState("search",p.target.value),r?.(p.target.value)}})}),_P=S.forwardRef((e,n)=>{let{children:r,label:i="Suggestions",...o}=e,l=S.useRef(null),u=S.useRef(null),d=qa(p=>p.selectedItemId),m=jl();return S.useEffect(()=>{if(u.current&&l.current){let p=u.current,y=l.current,v,b=new ResizeObserver(()=>{v=requestAnimationFrame(()=>{let x=p.offsetHeight;y.style.setProperty("--cmdk-list-height",x.toFixed(1)+"px")})});return b.observe(p),()=>{cancelAnimationFrame(v),b.unobserve(p)}}},[]),S.createElement($e.div,{ref:Fs(l,n),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":d,"aria-label":i,id:m.listId},md(e,p=>S.createElement("div",{ref:Fs(u,m.listInnerRef),"cmdk-list-sizer":""},p)))}),CP=S.forwardRef((e,n)=>{let{open:r,onOpenChange:i,overlayClassName:o,contentClassName:l,container:u,...d}=e;return S.createElement(hp,{open:r,onOpenChange:i},S.createElement(pp,{container:u},S.createElement(gp,{"cmdk-overlay":"",className:o}),S.createElement(vp,{"aria-label":e.label,"cmdk-dialog":"",className:l},S.createElement(tE,{ref:n,...d}))))}),EP=S.forwardRef((e,n)=>qa(r=>r.filtered.count===0)?S.createElement($e.div,{ref:n,...e,"cmdk-empty":"",role:"presentation"}):null),RP=S.forwardRef((e,n)=>{let{progress:r,children:i,label:o="Loading...",...l}=e;return S.createElement($e.div,{ref:n,...l,"cmdk-loading":"",role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},md(e,u=>S.createElement("div",{"aria-hidden":!0},u)))}),hd=Object.assign(tE,{List:_P,Item:bP,Input:SP,Group:xP,Separator:wP,Dialog:CP,Empty:EP,Loading:RP});function jP(e,n){let r=e.nextElementSibling;for(;r;){if(r.matches(n))return r;r=r.nextElementSibling}}function TP(e,n){let r=e.previousElementSibling;for(;r;){if(r.matches(n))return r;r=r.previousElementSibling}}function nE(e){let n=S.useRef(e);return Ai(()=>{n.current=e}),n}var Ai=typeof window>"u"?S.useEffect:S.useLayoutEffect;function Ms(e){let n=S.useRef();return n.current===void 0&&(n.current=e()),n}function qa(e){let n=gg(),r=()=>e(n.snapshot());return S.useSyncExternalStore(n.subscribe,r,r)}function rE(e,n,r,i=[]){let o=S.useRef(),l=jl();return Ai(()=>{var u;let d=(()=>{var p;for(let y of r){if(typeof y=="string")return y.trim();if(typeof y=="object"&&"current"in y)return y.current?(p=y.current.textContent)==null?void 0:p.trim():o.current}})(),m=i.map(p=>p.trim());l.value(e,d,m),(u=n.current)==null||u.setAttribute(As,d),o.current=d}),o}var OP=()=>{let[e,n]=S.useState(),r=Ms(()=>new Map);return Ai(()=>{r.current.forEach(i=>i()),r.current=new Map},[e]),(i,o)=>{r.current.set(i,o),n({})}};function AP(e){let n=e.type;return typeof n=="function"?n(e.props):"render"in n?n.render(e.props):e}function md({asChild:e,children:n},r){return e&&S.isValidElement(n)?S.cloneElement(AP(n),{ref:n.ref},r(n.props.children)):r(n)}var MP={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};function NP({className:e,...n}){return f.jsx(hd,{"data-slot":"command",className:Je("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...n})}function DP({className:e,...n}){return f.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[f.jsx(b_,{className:"size-4 shrink-0 opacity-50"}),f.jsx(hd.Input,{"data-slot":"command-input",className:Je("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...n})]})}function zP({className:e,...n}){return f.jsx(hd.List,{"data-slot":"command-list",className:Je("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",e),...n})}function kP({className:e,...n}){return f.jsx(hd.Item,{"data-slot":"command-item",className:Je("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...n})}function pw(e,n){if(!e)return{score:0,hits:[]};const r=e.toLowerCase(),i=n.toLowerCase();let o=0,l=0,u=0;const d=[];for(let m=0;m3&&i.endsWith("ies")?o=i.slice(0,-3)+"y":i.length>3&&i.endsWith("es")?o=i.slice(0,-2):i.length>2&&i.endsWith("s")&&(o=i.slice(0,-1)),o?pw(o,n):null}function $P({text:e,hits:n}){const r=[];let i=0;return n.forEach((o,l)=>{o>i&&r.push(e.slice(i,o)),r.push(f.jsx("b",{children:e[o]},l)),i=o+1}),r.push(e.slice(i)),f.jsx("span",{className:"plabel",children:r})}function IP({open:e,onClose:n,candidates:r}){const[i,o]=S.useState(""),l=S.useMemo(()=>{if(!e)return[];const d=[];for(const m of r()){const p=LP(i,m.label);p&&d.push({...m,score:p.score,hits:p.hits})}return d.sort((m,p)=>p.score-m.score),d.slice(0,40)},[e,i,r]);S.useEffect(()=>{e&&o("")},[e]);const u=d=>{n(),d.run()};return f.jsx(Ju,{open:e,onOpenChange:d=>!d&&n(),children:f.jsxs(Wu,{id:"palette",className:"palette",showCloseButton:!1,"aria-describedby":void 0,children:[f.jsx(_l,{className:"sr-only",children:"Search and quick actions"}),f.jsxs(NP,{shouldFilter:!1,loop:!0,children:[f.jsxs("div",{id:"palette-inputwrap",children:[f.jsx(ut,{name:"search"}),f.jsx(DP,{placeholder:"Search file names, projects, actions…",autoComplete:"off",spellCheck:!1,value:i,onValueChange:o})]}),f.jsx(zP,{children:l.length===0?f.jsx("div",{className:"pempty",children:"No matches — search covers file names, projects, and actions"}):l.map(d=>f.jsxs(kP,{value:d.kind+":"+d.label,onSelect:()=>u(d),children:[f.jsx("span",{className:"picon",children:f.jsx(ut,{name:d.icon})}),f.jsx($P,{text:d.label,hits:d.hits}),f.jsx("span",{className:"pkind",children:d.kind})]},d.kind+":"+d.label))}),f.jsx("footer",{id:"palette-hint",children:"↑↓ navigate · ⏎ select · esc close"})]})]})})}const Wo=3,Ns=30;function PP(e,n){return Pt({queryKey:["heatDevices",e],queryFn:()=>Bt(e+"heat?by=device&days=30"),enabled:n,retry:!1,staleTime:6e4}).data?.devices??null}const FP=["all","human","agent","share"],VP={all:"All reads",human:"Human reads",agent:"Agent reads",share:"Shared reads"},UP={agent:{agent:1,human:0,share:0},human:{agent:0,human:1,share:0},share:{agent:0,human:0,share:1}};function gw(e){const[n,r]=S.useState("all"),{flatFiles:i,heatMap:o,devices:l,scope:u}=e,d=w=>!u||w===u||w.startsWith(u+"/"),m=u?i.filter(w=>d(w.path)):i;if(!e.loading&&!m.length)return f.jsxs("div",{className:"insights",children:[f.jsxs("h1",{className:"in-title",children:["Knowledge insights",u?f.jsxs("span",{className:"in-scope",children:[" · ",u]}):null]}),f.jsxs("div",{className:"dl-empty in-blank",children:[f.jsx("p",{children:u?`Nothing in ${u} to chart yet.`:"Nothing to chart yet."}),f.jsx("p",{children:u?`No files under ${u} are syncing here yet.`:"This project has no files. Once a device syncs files here, the map, the reads × freshness plot and the hot path fill in on their own."}),e.installHref&&f.jsx("a",{className:"pbtn",...Bs(e.installHref),children:"Set up a device →"})]})]});const p=l&&u?l.map(w=>{const _=Object.create(null);for(const[E,R]of Object.entries(w.folders||{}))d(E)&&(_[E]=R);return{...w,folders:_}}).filter(w=>Object.keys(w.folders).length>0):l,y=Date.now(),v=m.map(w=>{const _=o&&o[w.path]||{},E=w.time?Math.max(0,(y-new Date(w.time).getTime())/864e5):0,R=n==="all"?ka(_):_[n]||0;return{path:w.path,reads:R,agent:_.agent||0,human:_.human||0,share:_.share||0,total:ka(_),days:E,danger:R>=Wo&&E>=Ns}}),b=iI(o,new Set(i.map(w=>w.path))).filter(d).map(w=>{const _=o[w];return{path:w,reads:n==="all"?ka(_):_[n]||0,agent:_.agent||0,human:_.human||0,share:_.share||0,total:ka(_),days:0,danger:!1,orphan:!0}}).filter(w=>w.reads>0),x=b.length>0?f.jsxs("p",{className:"in-legend in-orphan-note",children:[tp(b.length,"file")," with reads ",b.length===1?"is":"are"," no longer in the project — see Hot path."]}):null;return f.jsxs("div",{className:"insights",children:[f.jsxs("h1",{className:"in-title",children:["Knowledge insights",u?f.jsxs("span",{className:"in-scope",children:[" · ",u]}):null]}),f.jsx("p",{className:"dl-sub",children:u?`Reads over the last 30 days × freshness, for ${u} and everything in it.`:"Reads over the last 30 days × how long since each file changed. Hot but stale knowledge — read a lot, maintained by nobody — is the danger zone."}),f.jsx("div",{className:"in-lens",children:FP.map(w=>f.jsx("button",{className:"in-lens-btn"+(w===n?" active":""),onClick:()=>r(w),children:VP[w]},w))}),f.jsx("h3",{className:"dl-h3",children:"Map — cell size = reads, color = freshness (scale below)"}),f.jsx(BP,{pts:v,onOpenFile:e.onOpenFile,onOpenFolder:e.onOpenFolder,isFolder:e.isFolder}),x,f.jsxs("h3",{className:"dl-h3 in-h3-row",children:["Reads × freshness",f.jsx("span",{className:"in-cap",children:"dot size = agent share of reads"})]}),f.jsx(GP,{pts:v,onOpenFile:e.onOpenFile}),x,f.jsx("h3",{className:"dl-h3",children:"Hot path — top files by reads"}),f.jsx(ZP,{pts:[...v,...b],lens:n,onOpenFile:e.onOpenFile,onOpenHistory:e.onOpenHistory}),p&&p.length>0&&f.jsxs(f.Fragment,{children:[f.jsx("h3",{className:"dl-h3",children:"Agent coverage — which agents read which areas"}),f.jsx(KP,{devices:p})]})]})}const HP="rgb(150,156,164)";function aE(e){const n=[[76,195,138],[232,196,84],[224,93,93]],r=Math.min(1,Math.max(0,e/300))*(n.length-1),i=Math.min(n.length-2,Math.floor(r)),o=r-i,l=n[i].map((u,d)=>Math.round(u+(n[i+1][d]-u)*o));return`rgb(${l[0]},${l[1]},${l[2]})`}function vw(e,n,r,i,o){const l=e.reduce((p,y)=>p+y.value,0);if(!l||i<=0||o<=0)return[];const u=e.slice().sort((p,y)=>y.value-p.value).map(p=>({it:p,a:p.value/l*i*o})),d=(p,y)=>{const b=p.reduce((w,_)=>w+_.a,0)/y;let x=0;for(const w of p){const _=w.a/b;x=Math.max(x,_/b,b/_)}return x},m=[];for(;u.length;){const p=i>=o,y=p?o:i,v=[u.shift()];for(;u.length&&d(v.concat(u[0]),y)<=d(v,y);)v.push(u.shift());const b=v.reduce((w,_)=>w+_.a,0)/y;let x=0;for(const w of v){const _=w.a/b;p?m.push({item:w.it,x:n,y:r+x,w:b,h:_}):m.push({item:w.it,x:n+x,y:r,w:_,h:b}),x+=_}p?(n+=b,i-=b):(r+=b,o-=b)}return m}const cm=15;function yw(e,n,r){const i=Math.floor((r-8)/6),o=`${e} · ${n}`;return o.length<=i?{label:o,fit:i}:{label:e.length>i?e.slice(0,Math.max(1,i-1))+"…":e,fit:i}}const tp=(e,n)=>`${e} ${n}${e===1?"":"s"}`;function BP({pts:e,onOpenFile:n,onOpenFolder:r,isFolder:i}){const u=oI(e.map(y=>y.days)),d=!!u&&lI(u.min,u.max),m=new Map;for(const y of e){const v=y.path.includes("/")?y.path.split("/")[0]:"/";let b=m.get(v);b||m.set(v,b={name:v,files:[],value:0,reads:0}),b.files.push(y),b.value+=y.reads+1,b.reads+=y.reads}const p=[];for(const y of vw([...m.values()],0,0,720,480)){const v=y.item,b=v.name==="/"?"":v.name,x=v.name==="/"?"(root)":v.name;if(p.push(f.jsx("rect",{x:y.x+1,y:y.y+1,width:Math.max(0,y.w-2),height:Math.max(0,y.h-2),rx:3,className:"in-tm-group","data-dir":b,children:f.jsx("title",{children:`${v.name==="/"?"(root)":v.name+"/"} — ${tp(v.reads,"read")}/30d · ${tp(v.files.length,"file")}`})},"g"+v.name)),y.w>46&&y.h>cm+10){const{label:_}=yw(x,v.reads,y.w);p.push(f.jsx("text",{x:y.x+5,y:y.y+12,className:"in-tm-glabel","data-dir":b,children:_},"gl"+v.name))}const w=vw(v.files.map(_=>({..._,name:_.path.split("/").pop(),value:_.reads+1})),y.x+2,y.y+cm,Math.max(0,y.w-4),Math.max(0,y.h-cm-2));for(const _ of w)if(p.push(f.jsx("rect",{x:_.x+.6,y:_.y+.6,width:Math.max(.4,_.w-1.2),height:Math.max(.4,_.h-1.2),rx:1.5,fill:d?HP:aE(_.item.days),className:"in-tm-cell","data-path":_.item.path,children:f.jsx("title",{children:`${_.item.path} — ${_.item.reads} read${_.item.reads===1?"":"s"}/30d · changed ${Math.round(_.item.days)}d ago`})},_.item.path)),_.w>54&&_.h>16){const{label:E,fit:R}=yw((_.item.danger?"⚠ ":"")+_.item.name,_.item.reads,_.w);R>=5&&p.push(f.jsx("text",{x:_.x+4.5,y:_.y+12.5,className:"in-tm-label","data-path":_.item.path,children:E},"l"+_.item.path))}}return f.jsxs(f.Fragment,{children:[f.jsx("svg",{viewBox:"0 0 720 480",className:"in-chart in-treemap",onClick:y=>{const v=y.target.closest("[data-path], [data-dir]");if(!v)return;const b=v.getAttribute("data-path");if(b)return n(b);const x=v.getAttribute("data-dir");x&&i(x)&&r(x)},children:p}),f.jsx(qP,{range:u,flat:d})]})}function qP({range:e,flat:n}){if(!e)return null;const r=cI(e.min,e.max);return f.jsxs("p",{className:"in-legend in-tm-legend",children:["freshness 0d",f.jsx("span",{className:"in-sw in-sw-age"+(n?" in-sw-flat":""),style:{background:`linear-gradient(to right, ${[0,60,150,300].map(aE).join(", ")})`}}),"300d+",f.jsx("span",{className:"in-tm-range",children:n?`all files here: ${r} old — colour off, not enough range to rank`:`observed: ${r} old`})]})}function GP({pts:e,onOpenFile:n}){const o={l:44,r:16,t:20,b:34},l=Math.max(Ns*2,...e.map(w=>w.days)),u=Math.max(Wo*2,...e.map(w=>w.reads)),d=w=>Math.log10(w+1)/Math.log10(l+1),m=w=>Math.log10(w+1)/Math.log10(u+1),p=w=>3+4*w,y=p(1),v=w=>o.l+y+d(w)*(720-o.l-o.r-2*y),b=w=>360-o.b-y-m(w)*(360-o.t-o.b-2*y),x=fI(e.filter(w=>w.danger).map(w=>({path:w.path,reads:w.reads,cx:v(w.days),cy:b(w.reads),r:p(w.total?(w.agent||0)/w.total:0)})),{right:720-o.r,top:o.t+8,bottom:360-o.b-4});return f.jsxs("svg",{viewBox:"0 0 720 360",className:"in-chart",children:[f.jsx("rect",{x:v(Ns),y:o.t,width:720-o.r-v(Ns),height:b(Wo)-o.t,className:"in-danger-zone"}),f.jsx("line",{x1:v(Ns),y1:o.t,x2:v(Ns),y2:360-o.b,className:"in-threshold"}),f.jsx("line",{x1:o.l,y1:b(Wo),x2:720-o.r,y2:b(Wo),className:"in-threshold"}),f.jsx("line",{x1:o.l,y1:360-o.b,x2:720-o.r,y2:360-o.b,className:"in-axis"}),f.jsx("line",{x1:o.l,y1:o.t,x2:o.l,y2:360-o.b,className:"in-axis"}),f.jsx("text",{x:(o.l+720-o.r)/2,y:352,className:"in-label",children:"days since last change →"}),f.jsx("text",{x:12,y:(o.t+360-o.b)/2,className:"in-label",transform:`rotate(-90 12 ${(o.t+360-o.b)/2})`,children:"reads / 30d →"}),f.jsx("text",{x:720-o.r-6,y:o.t+14,className:"in-quad in-quad-danger",textAnchor:"end",children:"hot + stale"}),f.jsx("text",{x:o.l+6,y:o.t+14,className:"in-quad",children:"hot + fresh"}),f.jsx("text",{x:720-o.r-6,y:360-o.b-8,className:"in-quad",textAnchor:"end",children:"cold + stale"}),f.jsx("text",{x:o.l+6,y:360-o.b-8,className:"in-quad",children:"cold + fresh"}),e.map(w=>{const _=w.total?(w.agent||0)/w.total:0;return f.jsx("circle",{cx:Number(v(w.days).toFixed(1)),cy:Number(b(w.reads).toFixed(1)),r:Number(p(_).toFixed(1)),className:"in-pt"+(w.danger?" danger":w.reads?"":" cold"),onClick:()=>n(w.path),children:f.jsx("title",{children:`${w.path} — ${w.reads} read${w.reads===1?"":"s"} / 30d · changed ${Math.round(w.days)}d ago`})},w.path)}),x.map(w=>f.jsx("text",{x:Number(w.x.toFixed(1)),y:Number(w.y.toFixed(1)),textAnchor:w.anchor,className:"in-pt-label",children:w.name},w.path))]})}function ZP({pts:e,lens:n,onOpenFile:r,onOpenHistory:i}){const o=e.filter(d=>d.reads>0).sort((d,m)=>m.reads-d.reads||m.days-d.days).slice(0,20);if(!o.length)return f.jsx("div",{className:"dl-empty",children:"No reads in the window yet."});const l=o[0].reads,u=o.some(d=>d.share>0);return f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"in-hotpath",children:o.map(d=>{const m=UP[n]??aI(d),p=d.reads/l*100,y=()=>d.orphan?i(d.path):r(d.path);return f.jsxs("div",{className:"in-hp-row",tabIndex:0,role:"button",title:d.orphan?`${d.reads} read${d.reads===1?"":"s"}/30d · no longer in the project — open its history`:d.danger?`${d.reads} read${d.reads===1?"":"s"}/30d · unchanged ${Math.round(d.days)}d — review this file`:d.path,onClick:y,onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),y())},children:[f.jsx("span",{className:"in-hp-name"+(d.danger?" danger":""),children:d.path+(d.danger?" ⚠":"")}),d.orphan&&f.jsx("span",{className:"in-hp-gone",children:"· no longer in the project"}),f.jsxs("span",{className:"in-hp-bar",children:[f.jsx("span",{className:"in-hp-agent",style:{width:(p*m.agent).toFixed(1)+"%"}}),f.jsx("span",{className:"in-hp-human",style:{width:(p*m.human).toFixed(1)+"%"}}),f.jsx("span",{className:"in-hp-share",style:{width:(p*m.share).toFixed(1)+"%"}})]}),f.jsx("span",{className:"in-hp-count",children:d.reads})]},d.path)})}),f.jsxs("p",{className:"in-legend",children:[f.jsx("span",{className:"in-sw agent"})," agent reads ",f.jsx("span",{className:"in-sw human"})," human reads",u&&f.jsxs(f.Fragment,{children:[" ",f.jsx("span",{className:"in-sw share"})," shared reads"]})]})]})}function KP({devices:e}){const n=new Map;for(const b of e)for(const[x,w]of Object.entries(b.folders||{}))n.set(x,(n.get(x)||0)+w);const r=[...n.entries()].sort((b,x)=>x[1]-b[1]).slice(0,12).map(b=>b[0]),i=e.slice(0,12),o=140,l=6,u=Math.min(76,Math.max(34,(720-o-8)/r.length)),d=26,m=720,p=l+i.length*d+58,y=Math.max(1,...i.flatMap(b=>r.map(x=>(b.folders||{})[x]||0))),v=b=>{const x=[23,25,31],w=[245,166,35],_=x.map((E,R)=>Math.round(E+(w[R]-E)*b));return`rgb(${_[0]},${_[1]},${_[2]})`};return f.jsxs("svg",{viewBox:`0 0 ${m} ${p}`,className:"in-chart in-matrix",children:[i.map((b,x)=>{let w=b.name||b.id||"";return w.length>20&&(w=w.slice(0,19)+"…"),f.jsxs("g",{children:[f.jsx("text",{x:o-8,y:l+x*d+17,textAnchor:"end",className:"in-label",children:w}),r.map((_,E)=>{const R=(b.folders||{})[_]||0;return f.jsx("rect",{x:o+E*u,y:l+x*d,width:u-4,height:d-4,rx:3,fill:v(Math.sqrt(R/y)),children:f.jsx("title",{children:`${b.name||b.id} × ${_||"(root)"}: ${R} read${R===1?"":"s"}/30d`})},_)})]},b.id||x)}),r.map((b,x)=>{const w=o+x*u+(u-4)/2,_=l+i.length*d+14;return f.jsx("text",{x:w,y:_,className:"in-label",textAnchor:"end",transform:`rotate(-28 ${w} ${_})`,children:b||"(root)"},b)})]})}function iE(e){return new Set(e.entries.map(n=>n.path)).size}function YP(e){const n=l=>(l.session?"s\0"+l.session:"n\0"+l.note)+"\0"+(l.device?.id??""),r=new Map;e.forEach((l,u)=>{if(!l.note&&!l.session)return;const d=r.get(n(l));if(d){d.entries.push(l),d.idx.push(u);return}r.set(n(l),{note:l.note??"",session:l.session,entries:[l],idx:[u]})});const i=[],o=new Set;return e.forEach((l,u)=>{const d=l.note||l.session?r.get(n(l)):void 0;if(!d||iE(d)<2){i.push({i:u});return}o.has(d)||(o.add(d),i.push({run:d,i:u}))}),i}function QP(e){const{filters:n,authors:r,onChange:i}=e,o=(y,v)=>i({...n,[y]:v||void 0}),[l,u]=S.useState(n?.q??""),d=S.useRef(!1);S.useEffect(()=>{d.current||u(n?.q??"")},[n?.q]),S.useEffect(()=>{if(!d.current)return;const y=setTimeout(()=>{d.current=!1,l!==(n?.q??"")&&o("q",l)},250);return()=>clearTimeout(y)},[l]);const m=n?.user&&!r.includes(n.user)?[n.user,...r]:r,p=Zp(n);return f.jsxs("div",{className:"hfilters",children:[f.jsxs("label",{className:"hf-search",children:[f.jsx(ut,{name:"search"}),f.jsx(du,{type:"search",value:l,placeholder:"path contains…","aria-label":"Filter by path",onChange:y=>{d.current=!0,u(y.target.value)}})]}),f.jsxs("select",{className:"hf-user",value:n?.user??"","aria-label":"Filter by author",onChange:y=>o("user",y.target.value),children:[f.jsx("option",{value:"",children:"Anyone"}),m.map(y=>f.jsx("option",{value:y,children:y},y))]}),f.jsxs("span",{className:"hf-dates",children:[f.jsx("span",{className:"hf-lbl",children:"UTC"}),f.jsx(du,{type:"date",className:"hf-date",value:n?.since??"","aria-label":"From date (UTC)",onChange:y=>o("since",y.target.value)}),f.jsx("span",{className:"hf-dash",children:"–"}),f.jsx(du,{type:"date",className:"hf-date",value:n?.until??"","aria-label":"To date (UTC)",onChange:y=>o("until",y.target.value)})]}),p&&f.jsx("button",{type:"button",className:"hf-clear",onClick:()=>i({}),children:"Clear"})]})}function XP(e){const n=new Set;for(const r of e)r.user&&n.add(r.user);return[...n].sort()}function JP(e){const{apiBase:n,target:r,isFolder:i,onMeta:o,onRendered:l,restore:u,remove:d,filters:m}=e,p=r?i(r)?{prefix:r+"/"}:{path:r}:{prefix:""},y=("path"in p&&p.path!==void 0?"path="+encodeURIComponent(p.path):"prefix="+encodeURIComponent(p.prefix??""))+N_(m).replace("?","&"),{data:v,error:b,fetchNextPage:x,hasNextPage:w,isFetchingNextPage:_}=mj({queryKey:["history",n,y],queryFn:({pageParam:$})=>Bt(n+"history?"+y+"&n=100"+($?"&cursor="+encodeURIComponent($):"")),initialPageParam:"",getNextPageParam:$=>$.next_cursor,staleTime:15e3}),E=S.useRef(new Set);S.useEffect(()=>{b&&o("History unavailable: "+b.message)},[b,o]),S.useEffect(()=>{v&&l?.()},[v,l]);const R=v?v.pages.flatMap($=>$.entries||[]):[];for(const $ of XP(R))E.current.add($);const T=e.onFilters&&f.jsx(QP,{filters:m,authors:[...E.current].sort(),onChange:e.onFilters});if(!v)return T?f.jsx("div",{className:"history",children:T}):null;const O=$=>{for(let F=$+1;F{const F=R[$].kind==="delete"?O($):R[$].blob;return F&&F===N.get(R[$].path)?void 0:F},U=$=>N.get(R[$].path)==="";return f.jsxs("div",{className:"history",children:[T,R.length===0&&(Zp(m)?f.jsxs("div",{className:"empty",children:["No changes match these filters.",f.jsx("br",{}),f.jsx("button",{type:"button",className:"btn hf-clear-empty",onClick:()=>e.onFilters?.({}),children:"Clear filters"})]}):f.jsx("div",{className:"empty",children:"No history yet."})),YP(R).map(($,F)=>$.run?f.jsx(WP,{run:$.run,onOpen:e.onOpen,apiBase:n,prevBlob:O,restoreSha:z,recreates:U,restore:u,remove:d},"g"+F):f.jsx(pg,{entry:R[$.i],apiBase:n,onOpen:e.onOpen,diff:{apiBase:n,prev:O($.i)},restore:u,restoreSha:z($.i),recreates:U($.i)},"r"+$.i)),w&&f.jsx("button",{type:"button",className:"btn hmore",onClick:()=>x(),disabled:_,children:_?"Loading…":"Load more"})]})}function WP({run:e,onOpen:n,apiBase:r,prevBlob:i,restoreSha:o,recreates:l,restore:u,remove:d}){const[m,p]=S.useState(!0),y=e.entries[0],v=dd(y),b=[y.device.name||y.device.id,y.device.os].filter(Boolean).join(" · "),x=y.session,w=y.device?.id,{data:_}=Pt({queryKey:["session-reads",r,x,w],queryFn:()=>Bt(r+"heat?session="+encodeURIComponent(x)+"&device="+encodeURIComponent(w)),enabled:!!x&&!!w,staleTime:3e4}),E=new Set(_?.paths??[]),R=new Set(e.entries.map(U=>U.path)),T=[...E].filter(U=>!R.has(U)).sort(),O=e.entries.map(U=>new Date(U.time).getTime()),N=eF(Math.min(...O),Math.max(...O)),z=iE(e);return f.jsxs("div",{className:"hrun"+(m?" open":""),children:[f.jsxs("div",{className:"hrun-head",children:[f.jsx("button",{type:"button",className:"hrun-toggle","aria-expanded":m,title:m?"Collapse this run":"Expand this run",onClick:()=>p(!m),children:f.jsx(ut,{name:m?"chevd":"chev"})}),f.jsx("span",{className:"hrun-note",children:f.jsx(KC,{text:e.note})}),f.jsxs("span",{className:"hrun-meta",children:[E.size>0?`read ${E.size} · changed ${z}`:`${z} file${z===1?"":"s"}`," ·"," ",v,b?" · "+b:""]}),f.jsx("span",{className:"hrun-time",children:N})]}),m&&f.jsxs("div",{className:"hrun-body",children:[e.entries.map((U,$)=>f.jsx(pg,{entry:U,apiBase:r,onOpen:n,diff:{apiBase:r,prev:i(e.idx[$])},restore:u,remove:d,restoreSha:o(e.idx[$]),recreates:l(e.idx[$]),inRun:!0,read:E.has(U.path)},$)),T.length>0&&f.jsxs("div",{className:"hrun-reads",children:[f.jsx("div",{className:"hrun-reads-head",children:"Read, not changed"}),T.map(U=>f.jsxs("button",{type:"button",className:"hrun-read",onClick:()=>n(U),children:[f.jsx("span",{className:"hkind",children:"read"}),f.jsx("span",{className:"hpath",children:U})]},U))]}),x&&f.jsx("div",{className:"hrun-foot",children:"Reads shown only for files the project still has."})]})]})}function eF(e,n){const r=new Date(e),i=new Date(n),o=u=>u.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(r.toDateString()!==i.toDateString())return r.toLocaleString()+" – "+i.toLocaleString();const l=i.toLocaleDateString();return e===n?l+" "+o(i):l+" "+o(r)+" – "+o(i)}function tF(e,n){return e?n(e)?e+"/ (folder)":e:"all changes"}function nF(e){const{apiBase:n,path:r,version:i}=e,o="path="+encodeURIComponent(r),{data:l}=Pt({queryKey:["history",n,o,200],queryFn:()=>Bt(n+"history?"+o+"&n=200"),staleTime:15e3}),u=l?.entries?.find(y=>y.blob===i),d=u?dd(u):"",m=u?.time?new Date(u.time).toLocaleString():"",p=n+"blob?sha="+i+"&name="+encodeURIComponent(r.split("/").pop()||r)+"&download=1";return f.jsxs("div",{className:"vbanner",role:"status",children:[f.jsx("span",{className:"vb-icon",children:f.jsx(ut,{name:"clock"})}),f.jsxs("div",{className:"vb-text",children:[f.jsx("b",{children:[m&&"Version from "+m,d&&"by "+d].filter(Boolean).join(" ")||"Earlier version"}),f.jsx("span",{children:"This is not the current file."})]}),f.jsxs("div",{className:"vb-actions",children:[f.jsx("button",{className:"ai-btn",onClick:e.onViewCurrent,children:"View current"}),f.jsx("a",{className:"ai-btn",download:!0,href:p,children:"Download this version"})]})]})}const rF={aws_access_key_id:"an AWS access key",openai_api_key:"an OpenAI API key",github_pat:"a GitHub token",slack_token:"a Slack token",private_key:"a private key",gitlab_pat:"a GitLab token"};function aF(e=[]){const n=e.map(i=>`${rF[i.rule]??i.rule} (line ${i.line})`);return`BearDrive found ${n.length>1?n.slice(0,-1).join(", ")+" and "+n[n.length-1]:n[0]||"something credential-shaped"} in this file. The check covers the file at the moment you share it — a link always serves the file's latest content, so later changes are never checked. Share anyway?`}function sE(e){const{config:n,apiBase:r,route:i,hub:o,project:l}=e,u=Yp(),d=Mi(),{tree:m,flatFiles:p,dirIndex:y,loaded:v}=hI(r,!o||!!l),b=mI(r,o&&!!l&&!!n.reads?.enabled),x=o&&!!l&&!i.path&&!i.view,w=i.view==="dashboard"||x,_=PP(r,w);S.useEffect(()=>{w&&d.invalidateQueries({queryKey:["heat",r]})},[w,r,d]);const E=i.path,R=i.view?void 0:i.version,T=E||(i.view==="dashboard"||i.view==="history")&&i.viewTarget||"",O=!!E&&y.has(E),N=!!E&&v&&!O&&p.some(Z=>Z.path===E),z=!!E&&v&&!O&&!N,U=O&&!i.view,{data:$}=Pt({queryKey:["resolve",r,E],queryFn:()=>Bt(r+"resolve?path="+encodeURIComponent(E)),enabled:z,retry:!1,staleTime:6e4}),[F,ve]=S.useState(null);S.useEffect(()=>{!z||!$?.to||(ve({from:E,to:$.to}),Kt(fl($.to,l?.id),{replace:!0}))},[z,$,E,l?.id]);const[ye,me]=S.useState(()=>new Set),de=S.useRef(!0);S.useEffect(()=>{if(!m||!de.current)return;de.current=!1;const Z=(m.children||[]).filter(J=>J.dir);Z.length===1&&me(J=>new Set(J).add(Z[0].path))},[m]),S.useEffect(()=>{!T||!v||me(Z=>{const J=new Set(Z);for(const fe of kI(T))J.add(fe);return y.has(T)&&J.add(T),J})},[T,v,y]);const le=S.useCallback(Z=>{me(J=>{const fe=new Set(J);return fe.has(Z)?fe.delete(Z):fe.add(Z),fe})},[]),te=S.useRef(null),ge=S.useRef(new Map),L=S.useRef({key:"",want:0,attempts:0});S.useEffect(()=>{L.current={key:u,want:z3()==="POP"?ge.current.get(u)??0:0,attempts:0}},[u]);const K=S.useCallback(()=>{const Z=te.current,J=L.current;!Z||J.key!==u||J.attempts>=3||(J.attempts++,Z.scrollTo({top:J.want,behavior:"instant"}))},[u]),re=S.useCallback(()=>{te.current&&ge.current.set(u,te.current.scrollTop)},[u]),W=S.useCallback((Z,J)=>{Kt(fl(Z,l?.id,J)),mr()},[l?.id]),ne=S.useCallback(Z=>Kt(Pn("history",l?.id,Z)),[l?.id]),[D,M]=S.useState(""),[B,X]=S.useState(null),[Y,ce]=S.useState(!1),[ae,be]=S.useState(!1);S.useEffect(()=>HD(()=>be(!0)),[]);const xe=S.useRef(null),Oe=e.panel??null,Ie=!Oe&&o&&!!l&&N&&Si(l.perm,"write"),{data:Ve}=j_(l?.id,o&&!!l),it=S.useCallback(()=>{d.invalidateQueries({queryKey:["shares",l?.id]})},[d,l?.id]),Qe=N?(Ve||[]).filter(Z=>Z.path===E):[],fn=!Oe&&o&&!!l,hn=!Oe&&N,Qt=!Oe&&(N||o&&!!l&&O),br=R?r+"blob?sha="+R+"&name="+encodeURIComponent(E)+"&download=1":r+"download?path="+encodeURIComponent(E),jt=S.useCallback(async()=>{const Z=J=>fetch(r+"shares",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J?{path:E,confirm:!0}:{path:E})});try{let J=await Z(!1);if(J.status===409){const{findings:_e}=await J.json();if(!await wi("This file may contain credentials",aF(_e),"Share anyway",!0))return;J=await Z(!0)}if(!J.ok)throw new Error(await J.text());const fe=await J.json();zw("share_created");const we=await qs(fe.url);X({url:fe.url,copied:we}),it()}catch(J){Ke("Share failed: "+J.message,!0)}},[r,E,it]),[rr,xr]=S.useState(""),Tt=o&&!!l&&Si(l?.perm,"write"),Vn=S.useCallback(async(Z,J,fe)=>{if(await wi("Restore this version of "+Z+"?","It syncs to every device as a new change. "+(fe?"The file comes back on every device. Removing it again isn't available from History yet.":"You can restore any other version afterwards."),"Restore")){xr(Z+J);try{await _i(r+"restore",{path:Z,sha:J}),d.invalidateQueries({queryKey:["history",r]}),d.invalidateQueries({queryKey:["tree",r]}),d.invalidateQueries({queryKey:["render",r,Z]}),d.invalidateQueries({queryKey:["text"]}),Ke("Restored "+Z+" — it syncs to every device like any other change.")}catch(we){Ke("Restore failed: "+we.message,!0)}finally{xr("")}}},[r,d]),[Dt,kr]=S.useState(""),ar=S.useCallback(async Z=>{if(await wi("Remove "+Z+"?","It disappears from every synced device. History keeps it — you can restore it from the DELETED row afterwards.","Remove file",!0)){kr(Z);try{await _i(r+"remove",{path:Z}),d.invalidateQueries({queryKey:["history",r]}),d.invalidateQueries({queryKey:["tree",r]}),d.invalidateQueries({queryKey:["render",r,Z]}),d.invalidateQueries({queryKey:["text"]}),Ke("Removed "+Z+" — it syncs to every device like any other change.")}catch(J){Ke("Remove failed: "+J.message,!0)}finally{kr("")}}},[r,d]),ir=S.useCallback(()=>{if(!E)return ne("");ne(O?E+"/":E)},[E,O,ne]);S.useEffect(()=>{const Z=J=>{(J.metaKey||J.ctrlKey)&&J.key.toLowerCase()==="k"&&(J.preventDefault(),be(fe=>!fe))};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[]);const wr=S.useCallback(()=>{const Z=[],J=(fe,we,_e,Xe)=>Z.push({icon:fe,label:we,kind:_e,run:Xe});if(o&&l){const fe=l.id,we=_e=>()=>{e.onClosePanel?.(),Kt(_e)};J("folder","Go to project root","action",we("/"+fe)),J("dashboard","Dashboard","action",we(Pn("dashboard",fe))),J("terminal","Installation","action",we(Pn("install",fe))),J("gear","Settings","action",we(Pn("settings",fe)))}if(o&&l&&E&&(N&&J("share","Share: "+E,"action",jt),J("hist","History: "+E,"action",ir),N&&J("download","Download: "+E,"action",()=>xe.current?.click())),o&&l&&J("hist","History: whole project","action",()=>ne("")),o)for(const fe of e.projects||[])(!l||fe.id!==l.id)&&J("folder","Switch to project: "+fe.name,"project",()=>Kt("/"+fe.id));n.auth?.enabled&&J("power","Sign out","action",()=>window.location.href="/auth/logout");for(const fe of y.keys())J("folder",fe,"folder",()=>W(fe));for(const fe of p)J("doc",fe.path,"file",()=>W(fe.path));return Z},[o,l,E,N,n.auth?.enabled,y,p,e.projects,e.onClosePanel,jt,ir,ne,W]);S.useEffect(()=>{if(!Y)return;const Z=()=>ce(!1);return document.addEventListener("click",Z),()=>document.removeEventListener("click",Z)},[Y]);const sr=S.useCallback(Z=>y.has(Z),[y]);let mn="app",A,P;Oe?P=Oe.body:i.view==="dashboard"?P=f.jsx(gw,{flatFiles:p,heatMap:b,devices:_,scope:i.viewTarget||"",loading:!v,installHref:l?Pn("install",l.id):void 0,onOpenFile:W,onOpenFolder:W,onOpenHistory:ne,isFolder:sr}):i.view==="history"?P=f.jsx(JP,{apiBase:r,target:i.viewTarget||"",isFolder:sr,onOpen:W,onMeta:M,onRendered:K,restore:Tt?{onRestore:Vn,busy:rr}:void 0,remove:Tt?{onRemove:ar,busy:Dt}:void 0,filters:i.filters,onFilters:Z=>Kt(Pn("history",l?.id,i.viewTarget||"",Z))}):E?v?z?P=f.jsxs("div",{className:"notfound",children:[f.jsx("h1",{children:"Couldn't find that"}),f.jsxs("p",{children:[f.jsx("code",{children:E})," isn't in this project right now."]}),f.jsx("p",{className:"nf-sub",children:"If it was just created, it may still be uploading or syncing from a teammate's device — this page checks again automatically every few seconds, so refresh or come back in a moment."}),f.jsx("button",{className:"pbtn",onClick:()=>d.invalidateQueries({queryKey:["tree",r]}),children:"Check again"})]}):O?P=f.jsx(ZI,{node:y.get(E),heatMap:b,hub:o&&!!l,apiBase:r,onOpen:W,onFullHistory:ne,onRendered:K}):(mn=OC.test(E)||AC.test(E)?"wide":"read",A="markdown",P=f.jsxs(f.Fragment,{children:[R&&f.jsx(nF,{apiBase:r,path:E,version:R,onViewCurrent:()=>W(E)}),f.jsx(QI,{apiBase:r,path:E,version:R,heatMap:b,flatFiles:p,onOpenFile:W,onMeta:M,onRendered:K})]})):P=f.jsx("div",{className:"empty",children:"Loading…"}):x?P=f.jsxs(f.Fragment,{children:[f.jsx(HC,{project:l,existing:i.connect==="existing"}),f.jsx("div",{className:"home-insights",children:f.jsx(gw,{flatFiles:p,heatMap:b,devices:_,loading:!v,onOpenFile:W,onOpenFolder:W,onOpenHistory:ne,isFolder:sr})})]}):P=f.jsx("div",{className:"empty",children:"Select a file to read it."}),F&&F.to===E&&(P=f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"vbanner",role:"status",children:[f.jsx("span",{className:"vb-icon",children:f.jsx(ut,{name:"link"})}),f.jsxs("div",{className:"vb-text",children:[f.jsxs("b",{children:["Moved from ",F.from]}),f.jsx("span",{children:"The URL has been updated."})]})]}),P]}));const V=Oe?Oe.crumb:E?f.jsx(LI,{path:E,onOpenFolder:W}):i.view==="dashboard"?"Dashboard — "+(i.viewTarget||l?.name||""):i.view==="history"?"History — "+tF(i.viewTarget||"",sr):x?l.name:null,ue=f.jsx(dl,{crumb:V,meta:D,actions:f.jsxs(f.Fragment,{children:[Ie&&f.jsx(vt,{id:"share-btn",variant:"toolbar",className:"icon-only",title:"Share","aria-label":"Share",onClick:jt,children:f.jsx(ut,{name:"share"})}),fn&&!E&&!i.view&&f.jsxs(vt,{id:"history-btn",variant:"toolbar",onClick:ir,children:[f.jsx(ut,{name:"hist"})," ",f.jsx("span",{className:"lbl",children:"History"})]}),hn&&f.jsx("a",{id:"download",hidden:!0,download:!0,href:br,ref:xe,children:"Download"}),Qt&&f.jsx(vt,{id:"more-btn",variant:"toolbar",className:"icon-only",title:"More actions","aria-label":"More actions",onClick:Z=>{Z.stopPropagation(),ce(!Y)},children:f.jsx(ut,{name:"dots"})}),Y&&f.jsxs("div",{id:"more-menu",role:"menu",children:[fn&&f.jsx("button",{className:"more-item",onClick:ir,children:"History"}),hn&&f.jsx("button",{className:"more-item",onClick:()=>xe.current?.click(),children:"Download"}),o&&!!l&&f.jsx("button",{className:"more-item",onClick:()=>{e.onClosePanel?.(),Kt(Pn("dashboard",l?.id,E))},children:"Dashboard"})]})]})});return f.jsxs(f.Fragment,{children:[f.jsx(ul,{vault:e.sidebar.vault,projectsNav:e.sidebar.projectsNav,orgBar:e.sidebar.orgBar,tree:f.jsx(zI,{root:m,expanded:ye,onToggle:le,currentPath:T,listingShowing:U,onOpen:W}),topbar:ue,contentRef:te,onContentScroll:re,children:f.jsxs(Su,{width:mn,className:A,children:[!Oe&&N&&f.jsx(oP,{shares:Qe,canRevoke:!!l&&Si(l.perm,"write"),onChanged:it}),P]})}),B&&f.jsx(sP,{url:B.url,copied:B.copied,onClose:()=>{X(null),it()}}),f.jsx(IP,{open:ae,onClose:()=>be(!1),candidates:wr})]})}function iF({config:e}){const n=Yp(),r=O_(),[i,o]=S.useState(null),[l,u]=S.useState(null);S.useEffect(()=>u(null),[n]);const d=S.useMemo(()=>{const ge=n.split("?")[0].match(/^\/join\/([0-9a-f]+)\/?$/);return ge?ge[1]:null},[n]),{data:m}=j3(!d),{data:p}=T3(!d),y=!!e.auth.admin,{data:v}=T_(y),b=S.useMemo(()=>D_(n,"hub"),[n]),[x,w]=S.useState(!1),_=e.upload.enabled,E=async(ge,L)=>{const K=L===BC;try{const re=await _i("/api/projects",{name:ge,template:K?"":L});w(!1),await r(),Kt("/"+re.project.id+(K?"?connect=existing":"")),Ke(`Created “${re.project.name}”.`)}catch(re){Ke("Could not create the project: "+re.message,!0)}},R=x?f.jsx(nI,{templates:e.templates??[],onCreate:E,onClose:()=>w(!1)}):null,T=S.useMemo(()=>m&&(m.find(ge=>ge.id===b.project)||i&&m.find(ge=>ge.org===i)||m.find(ge=>ge.id===E$())||m[0])||null,[m,b.project,i]);if(S.useEffect(()=>{document.title=T?T.name+" — BearDrive":e.brand||"BearDrive",T&&R$(T.id)},[T,e]),d)return f.jsx(sF,{token:d,onDone:async ge=>{o(ge),await r(),Kt("/",{replace:!0})}});const O=e.brand||"BearDrive",N=T&&p?.find(ge=>ge.id===T.org)||null,z=f.jsx(Xu,{name:O,onHome:()=>Kt("/"),search:!!T,beta:O==="BearDrive"}),U=e.me?f.jsx(Z$,{me:e.me,org:N,orgActive:!!b.org,billing:e.billing,admin:y?{pending:v?.length||0,onClick:()=>{u({kind:"hub"}),mr()}}:void 0}):void 0;if(!m||!p)return f.jsx(ul,{vault:z,topbar:f.jsx(dl,{}),children:f.jsx(Su,{children:f.jsx("div",{className:"empty",children:"Loading…"})})});if(!T)return f.jsxs(ul,{vault:z,projectsNav:f.jsx(aw,{projects:m,onNew:()=>w(!0)}),orgBar:U,topbar:f.jsx(dl,{}),children:[f.jsx(Su,{children:f.jsx(tI,{onNew:()=>w(!0),canCreate:_})}),R]});const $=l?.kind==="hub"?{crumb:"Signup & access",body:f.jsx($$,{})}:null,F=b.org?p.find(ge=>ge.id===b.org):null,ye=b.org&&!F?{crumb:"Organization",body:f.jsxs("div",{className:"empty",children:[f.jsx("h3",{children:"Organization not found"}),f.jsx("p",{children:"This organization doesn't exist, or you're no longer a member."}),f.jsx("p",{children:f.jsxs("a",{...Bs("/"+T.id),children:["Back to ",T.name]})})]})}:F?{crumb:"Organization",body:f.jsx(z$,{org:F,projects:m,myEmail:e.me?.email||""})}:null,me=!!b.project&&!m.some(ge=>ge.id===b.project),de=me?{crumb:"Project",body:f.jsxs("div",{className:"empty",children:[f.jsx("h3",{children:"Project not found"}),f.jsx("p",{children:"This project doesn't exist, or you're no longer a member."}),f.jsx("p",{children:f.jsxs("a",{...Bs("/"+T.id),children:["Back to ",T.name]})})]})}:null,le=b.billing?{crumb:"Billing",body:e.billing?f.jsx(K$,{url:e.billing.url}):f.jsxs("div",{className:"empty",children:[f.jsx("h3",{children:"No billing on this hub"}),f.jsx("p",{children:"This BearDrive hub doesn't have a billing surface."})]})}:null,te=b.view==="settings"?{crumb:"Project settings",body:f.jsx(X$,{project:T,org:N,onDeleted:async()=>{await r(),Kt("/")}})}:b.view==="install"?{crumb:"Installation",body:f.jsx(HC,{project:T,existing:b.connect==="existing"})}:null;if(!me){if(!b.org&&!b.billing&&b.project!==T.id)return f.jsx(Qo,{to:"/"+T.id});if(b.legacyView&&b.view)return f.jsx(Qo,{to:Pn(b.view,T.id,b.viewTarget,b.filters)});if(b.queryTarget&&b.view)return f.jsx(Qo,{to:Pn(b.view,T.id,b.viewTarget,b.filters)});if(b.trailingSlash&&b.path)return f.jsx(Qo,{to:fl(b.path,T.id,b.version)})}return f.jsxs(f.Fragment,{children:[f.jsx(sE,{config:e,apiBase:"/api/p/"+T.id+"/",route:b,hub:!0,project:T,projects:m,sidebar:{vault:z,projectsNav:f.jsx(aw,{projects:m,currentId:T.id,onNew:()=>w(!0),menu:{active:l?null:b.view==="dashboard"&&!b.viewTarget?"dashboard":b.view==="install"?"install":b.view==="history"&&!b.viewTarget?"history":b.view==="settings"?"settings":null,onDashboard:()=>{u(null),Kt(Pn("dashboard",T.id)),mr()},onInstall:()=>{u(null),Kt(Pn("install",T.id)),mr()},onHistory:()=>{u(null),Kt(Pn("history",T.id)),mr()},onSettings:()=>{u(null),Kt(Pn("settings",T.id)),mr()}}}),orgBar:U},panel:$||ye||de||le||te,onClosePanel:()=>u(null)},T.id),R]})}function sF({token:e,onDone:n}){return S.useEffect(()=>{let r=!1;return _i("/api/invites/"+e).then(i=>{r||(Ke(`Welcome — you joined the “${i.org.name}” team. Opening its projects…`),n(i.org.id))}).catch(i=>{r||String(i.message).includes("signing in")||(Ke("Could not accept the invite: "+i.message,!0),n(null))}),()=>{r=!0}},[e]),f.jsx(ul,{vault:f.jsx(Xu,{name:"BearDrive",beta:!0}),topbar:f.jsx(dl,{}),children:f.jsx(Su,{children:f.jsx("div",{className:"empty",children:"Joining…"})})})}function oF({config:e}){const n=Yp(),r=e.volume||"BearDrive";S.useEffect(()=>{document.title=e.brand||r},[e,r]);const i=S.useMemo(()=>D_(n,"volume"),[n]);return i.trailingSlash&&i.path?f.jsx(Qo,{to:fl(i.path)}):f.jsx(sE,{config:e,apiBase:"/api/",route:i,hub:!1,sidebar:{vault:f.jsx(Xu,{name:r,showSignout:e.auth.enabled,search:!0})}})}function lF(){const{data:e}=bj();return f.jsxs(PD,{delayDuration:150,children:[e?e.mode==="hub"?f.jsx(iF,{config:e}):f.jsx(oF,{config:e}):f.jsx(ul,{vault:f.jsx(Xu,{name:"…",showSignout:!1}),topbar:f.jsx(dl,{}),children:f.jsx("div",{className:"empty",children:"Loading…"})}),f.jsx(b3,{}),f.jsx(C3,{})]})}class cF extends S.Component{state={error:null};static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,r){console.error("BearDrive: unhandled render error",n,r.componentStack)}render(){return this.state.error?f.jsxs("div",{className:"mx-auto max-w-lg p-8 text-sm",children:[f.jsx("h1",{className:"mb-2 text-lg font-semibold",children:"This page didn’t load"}),f.jsx("p",{className:"mb-4 opacity-80",children:"Something went wrong rendering this view. The rest of BearDrive is fine."}),f.jsx("p",{className:"mb-4",children:f.jsx("a",{className:"underline",href:"/",children:"Go to the project list"})}),f.jsx("pre",{className:"overflow-x-auto rounded bg-black/5 p-3 text-xs dark:bg-white/10",children:String(this.state.error)})]}):this.props.children}}const uF=new nj({defaultOptions:{queries:{retry:1,refetchOnWindowFocus:!1}}});O2.createRoot(document.getElementById("root")).render(f.jsx(S.StrictMode,{children:f.jsx(cF,{children:f.jsx(rj,{client:uF,children:f.jsx(lF,{})})})}));
+`)continue;l+=y}}return u||((l!==""||o.length)&&m(),!i.length)||i[0].length<2?null:{rows:i,truncated:d}}function QI(e){const{apiBase:n,path:r,version:i,onMeta:o}=e,l=i?n+"blob?sha="+i+"&name="+encodeURIComponent(r):n+"file?path="+encodeURIComponent(r);return S.useEffect(()=>()=>o(""),[r,o]),w$.test(r)?f.jsx(WI,{...e}):OC.test(r)?f.jsx("iframe",{className:"htmlview",sandbox:"allow-scripts",src:l,title:r,onLoad:e.onRendered}):AC.test(r)?f.jsx("iframe",{className:"pdfview",src:l,title:r,onLoad:e.onRendered}):S$.test(r)?f.jsx(nP,{src:l,alt:r,version:i,onRendered:e.onRendered}):_$.test(r)?f.jsx(dw,{...e,fileURL:l,delim:/\.tsv$/i.test(r)?" ":","}):C$.test(r)?f.jsx(dw,{...e,fileURL:l}):f.jsx(XI,{...e,fileURL:l})}function XI(e){const{apiBase:n,path:r,version:i,fileURL:o,onRendered:l}=e,{data:u,error:d}=ZC(o,["text",o],!0,!!i);return S.useEffect(()=>{u&&l?.()},[u,l]),d?f.jsx(fd,{version:i,err:d}):u?u.kind==="text"?f.jsx("pre",{className:"plain",children:u.text},r):f.jsx(JI,{apiBase:n,path:r,version:i,fileURL:o,children:u.kind==="too-large"?`Too large to preview (${mg(u.size)}).`:"No preview for this file type."}):null}function JI(e){const{apiBase:n,path:r,version:i,fileURL:o}=e;return f.jsxs("div",{className:"filecard",children:[f.jsx("div",{className:"name",children:r.split("/").pop()}),f.jsx("p",{children:e.children}),f.jsx("a",{className:"btn",download:!0,href:i?o+"&download=1":n+"download?path="+encodeURIComponent(r),children:"Download"})]})}function WI(e){const{apiBase:n,path:r,version:i,heatMap:o,flatFiles:l,onOpenFile:u,onMeta:d,onRendered:m}=e,{data:p,error:y}=Pt({queryKey:["render",n,r,i||""],queryFn:()=>Bt(n+"render?path="+encodeURIComponent(r)+(i?"&sha="+i:"")),retry:i?!1:void 0}),v=S.useMemo(()=>p?tP(p.html,r,n):"",[p,r,n]),[b,x]=S.useState(null);return S.useEffect(()=>{if(x(null),!y2(v))return;let w=!1;return b2(v).then(_=>{w||x(_)}),()=>{w=!0}},[v]),S.useEffect(()=>{if(!p)return;const w=[];(p.user_name||p.user||p.author)&&w.push(dd(p)+(p.device?" on "+p.device:"")),p.time&&w.push(new Date(p.time).toLocaleString());const _=i?null:o&&o[p.path];_&&ka(_)&&w.push(Jo(_)+" / 30d"),d(w.join(" · ")),m?.()},[p,i,o,d,m]),y?f.jsx(fd,{version:i,err:y}):p?f.jsx("div",{dangerouslySetInnerHTML:{__html:b??v},onClick:w=>eP(w,r,l,u)}):null}function eP(e,n,r,i){const o=e.target.closest("a");if(!o||!e.currentTarget.contains(o))return;const l=o.getAttribute("href")||"",u=n.includes("/")?n.slice(0,n.lastIndexOf("/")):"";l.startsWith("wiki:")?(e.preventDefault(),aP(decodeURIComponent(l.slice(5)),r,i)):/^([a-z]+:|\/|#)/i.test(l)||(e.preventDefault(),i(MC(u,decodeURIComponent(l))))}function tP(e,n,r){const i=n.includes("/")?n.slice(0,n.lastIndexOf("/")):"",o=u=>r+"file?path="+encodeURIComponent(u),l=new DOMParser().parseFromString(e,"text/html");for(const u of l.querySelectorAll("img")){const d=u.getAttribute("src")||"";/^\s*data:image\/svg/i.test(d)?u.removeAttribute("src"):/^([a-z]+:|\/)/i.test(d)||u.setAttribute("src",o(MC(i,d)))}for(const u of l.querySelectorAll("a")){const d=u.getAttribute("href")||"";/^\s*data:/i.test(d)?u.removeAttribute("href"):/^https?:/i.test(d)&&(u.setAttribute("target","_blank"),u.setAttribute("rel","noopener"))}return l.body.innerHTML}function nP(e){const[n,r]=S.useState(!1);return n?f.jsx(fd,{version:e.version,err:new Error("could not be loaded")}):f.jsx("img",{src:e.src,alt:e.alt,onLoad:e.onRendered,onError:()=>r(!0)})}function fd({version:e,err:n}){return f.jsx("div",{className:"empty",children:e?"That version isn't available.":"Could not load file: "+n.message})}function dw(e){const{path:n,version:r,fileURL:i,delim:o,onRendered:l}=e,{data:u,error:d}=Pt({queryKey:["text",i],queryFn:async()=>{const p=await fetch(i);if(!p.ok)throw new Error(await p.text());return p.text()},retry:r?!1:void 0});S.useEffect(()=>{u!=null&&l?.()},[u,l]);const m=S.useMemo(()=>o&&u!=null?YI(u,o,YC):null,[u,o]);return d?f.jsx(fd,{version:r,err:d}):u==null?null:m?f.jsx(rP,{csv:m},n):f.jsx("pre",{className:"plain",children:u},n)}function rP({csv:e}){const[n,...r]=e.rows,i=e.rows.reduce((l,u)=>Math.max(l,u.length),0),o=Array.from({length:i},(l,u)=>u);return f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"csvbox",children:f.jsxs("table",{className:"csvview",children:[f.jsx("thead",{children:f.jsx("tr",{children:o.map(l=>f.jsx("th",{children:n[l]??""},l))})}),f.jsx("tbody",{children:r.map((l,u)=>f.jsx("tr",{children:o.map(d=>f.jsx("td",{children:l[d]??""},d))},u))})]})}),e.truncated>0&&f.jsxs("p",{className:"csvnote",children:["showing ",e.rows.length.toLocaleString()," of"," ",(e.rows.length+e.truncated).toLocaleString()," rows — Download for the rest"]})]})}function aP(e,n,r){const i=e.toLowerCase(),o=n.find(l=>l.path.toLowerCase()===i||l.path.toLowerCase()===i+".md")||n.find(l=>{const u=l.name.toLowerCase();return u===i||u===i+".md"});o&&r(o.path)}const iP=[{value:"",label:"Never"},{value:"24h",label:"In 24 hours"},{value:"168h",label:"In 7 days"},{value:"720h",label:"In 30 days"}];function sP({url:e,copied:n,onClose:r}){const i=e.split("/s/")[1],[o,l]=S.useState(""),[u,d]=S.useState(),[m,p]=S.useState(!1),y=S.useRef(null);async function v(b){const x=o;l(b),p(!0);try{const w=await Wn("PATCH","/api/shares/"+i,{expires_in:b});d(w.expires)}catch(w){Ke(w.message,!0),l(x)}finally{p(!1)}}return f.jsx(Ju,{open:!0,onOpenChange:b=>!b&&r(),children:f.jsxs(Wu,{className:"modal",showCloseButton:!1,onOpenAutoFocus:b=>{b.preventDefault(),y.current?.focus()},children:[f.jsx(_l,{asChild:!0,children:f.jsx("h3",{children:"Public link"})}),f.jsxs("p",{children:[f.jsx("b",{children:"Anyone with this link can view this file"})," — no account needed. It always shows the latest version until it expires or you revoke it."," ","To revoke it, close this — ",f.jsx("b",{children:"Revoke"})," is on the file itself, in the “Publicly shared” banner."]}),f.jsx("div",{className:"modal-url",children:e}),f.jsxs("div",{className:"modal-expiry",children:[f.jsx("label",{htmlFor:"share-expiry",children:"Expires"}),f.jsx("select",{id:"share-expiry",value:o,disabled:m,onChange:b=>v(b.target.value),children:iP.map(b=>f.jsx("option",{value:b.value,children:b.label},b.value))}),f.jsx("span",{className:"modal-expiry-note",children:zC(u)})]}),f.jsxs("div",{className:"modal-actions",children:[f.jsx(vt,{ref:y,variant:"primary",onClick:()=>qs(e).then(b=>Ke(b?"Copied.":"Select and copy the link above.")),children:n?"Copied ✓":"Copy link"}),f.jsx(vt,{variant:"subtle",onClick:()=>window.open(e,"_blank"),children:"Open"}),f.jsx(vt,{variant:"subtle",onClick:r,children:"Done"})]})]})})}function oP({shares:e,canRevoke:n,onChanged:r}){return e.length===0?null:f.jsxs("div",{className:"share-banner",role:"status",children:[f.jsxs("div",{className:"sb-head",children:[f.jsx(ut,{name:"share"}),f.jsx("b",{children:"Publicly shared"}),f.jsxs("span",{className:"sb-count",children:[e.length," active link",e.length>1?"s":""]})]}),f.jsxs("p",{className:"sb-note",children:[f.jsx("b",{children:"Anyone with this link can view this file"})," — no account needed. It always shows the latest version until you revoke it.",e.some(i=>i.opens!==void 0)&&f.jsxs(f.Fragment,{children:[" ",LC]})]}),e.map(i=>f.jsxs("div",{className:"sb-link",children:[f.jsx("span",{className:"sb-url mono",title:i.url,children:i.url}),f.jsx("span",{className:"sb-meta",children:kC(i,!1)}),f.jsxs("span",{className:"sb-actions",children:[f.jsx(vt,{variant:"subtle",onClick:()=>qs(i.url).then(o=>Ke(o?"Copied.":"Select and copy the link.")),children:"Copy link"}),f.jsx(vt,{variant:"subtle",onClick:()=>window.open(i.url,"_blank"),children:"Open"}),n&&f.jsx("button",{className:"ai-del","aria-label":`Revoke the share of ${i.path}`,onClick:()=>IC(i,r),children:"Revoke"})]})]},i.token))]})}var fw=1,lP=.9,cP=.8,uP=.17,sm=.1,om=.999,dP=.9999,fP=.99,hP=/[\\\/_+.#"@\[\(\{&]/,mP=/[\\\/_+.#"@\[\(\{&]/g,pP=/[\s-]/,QC=/[\s-]/g;function Wm(e,n,r,i,o,l,u){if(l===n.length)return o===e.length?fw:fP;var d=`${o},${l}`;if(u[d]!==void 0)return u[d];for(var m=i.charAt(l),p=r.indexOf(m,o),y=0,v,b,x,w;p>=0;)v=Wm(e,n,r,i,p+1,l+1,u),v>y&&(p===o?v*=fw:hP.test(e.charAt(p-1))?(v*=cP,x=e.slice(o,p-1).match(mP),x&&o>0&&(v*=Math.pow(om,x.length))):pP.test(e.charAt(p-1))?(v*=lP,w=e.slice(o,p-1).match(QC),w&&o>0&&(v*=Math.pow(om,w.length))):(v*=uP,o>0&&(v*=Math.pow(om,p-o))),e.charAt(p)!==n.charAt(l)&&(v*=dP)),(vv&&(v=b*sm)),v>y&&(y=v),p=r.indexOf(m,p+1);return u[d]=y,y}function hw(e){return e.toLowerCase().replace(QC," ")}function gP(e,n,r){return e=r&&r.length>0?`${e+" "+r.join(" ")}`:e,Wm(e,n,hw(e),hw(n),0,0,{})}var Zo='[cmdk-group=""]',lm='[cmdk-group-items=""]',vP='[cmdk-group-heading=""]',XC='[cmdk-item=""]',mw=`${XC}:not([aria-disabled="true"])`,ep="cmdk-item-select",As="data-value",yP=(e,n,r)=>gP(e,n,r),JC=S.createContext(void 0),jl=()=>S.useContext(JC),WC=S.createContext(void 0),gg=()=>S.useContext(WC),eE=S.createContext(void 0),tE=S.forwardRef((e,n)=>{let r=Ms(()=>{var M,B;return{search:"",value:(B=(M=e.value)!=null?M:e.defaultValue)!=null?B:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),i=Ms(()=>new Set),o=Ms(()=>new Map),l=Ms(()=>new Map),u=Ms(()=>new Set),d=nE(e),{label:m,children:p,value:y,onValueChange:v,filter:b,shouldFilter:x,loop:w,disablePointerSelection:_=!1,vimBindings:E=!0,...R}=e,T=dn(),O=dn(),N=dn(),z=S.useRef(null),U=OP();Ai(()=>{if(y!==void 0){let M=y.trim();r.current.value=M,$.emit()}},[y]),Ai(()=>{U(6,le)},[]);let $=S.useMemo(()=>({subscribe:M=>(u.current.add(M),()=>u.current.delete(M)),snapshot:()=>r.current,setState:(M,B,X)=>{var Y,ce,ae,be;if(!Object.is(r.current[M],B)){if(r.current[M]=B,M==="search")de(),ye(),U(1,me);else if(M==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let xe=document.getElementById(N);xe?xe.focus():(Y=document.getElementById(T))==null||Y.focus()}if(U(7,()=>{var xe;r.current.selectedItemId=(xe=te())==null?void 0:xe.id,$.emit()}),X||U(5,le),((ce=d.current)==null?void 0:ce.value)!==void 0){let xe=B??"";(be=(ae=d.current).onValueChange)==null||be.call(ae,xe);return}}$.emit()}},emit:()=>{u.current.forEach(M=>M())}}),[]),F=S.useMemo(()=>({value:(M,B,X)=>{var Y;B!==((Y=l.current.get(M))==null?void 0:Y.value)&&(l.current.set(M,{value:B,keywords:X}),r.current.filtered.items.set(M,ve(B,X)),U(2,()=>{ye(),$.emit()}))},item:(M,B)=>(i.current.add(M),B&&(o.current.has(B)?o.current.get(B).add(M):o.current.set(B,new Set([M]))),U(3,()=>{de(),ye(),r.current.value||me(),$.emit()}),()=>{l.current.delete(M),i.current.delete(M),r.current.filtered.items.delete(M);let X=te();U(4,()=>{de(),X?.getAttribute("id")===M&&me(),$.emit()})}),group:M=>(o.current.has(M)||o.current.set(M,new Set),()=>{l.current.delete(M),o.current.delete(M)}),filter:()=>d.current.shouldFilter,label:m||e["aria-label"],getDisablePointerSelection:()=>d.current.disablePointerSelection,listId:T,inputId:N,labelId:O,listInnerRef:z}),[]);function ve(M,B){var X,Y;let ce=(Y=(X=d.current)==null?void 0:X.filter)!=null?Y:yP;return M?ce(M,r.current.search,B):0}function ye(){if(!r.current.search||d.current.shouldFilter===!1)return;let M=r.current.filtered.items,B=[];r.current.filtered.groups.forEach(Y=>{let ce=o.current.get(Y),ae=0;ce.forEach(be=>{let xe=M.get(be);ae=Math.max(xe,ae)}),B.push([Y,ae])});let X=z.current;ge().sort((Y,ce)=>{var ae,be;let xe=Y.getAttribute("id"),Oe=ce.getAttribute("id");return((ae=M.get(Oe))!=null?ae:0)-((be=M.get(xe))!=null?be:0)}).forEach(Y=>{let ce=Y.closest(lm);ce?ce.appendChild(Y.parentElement===ce?Y:Y.closest(`${lm} > *`)):X.appendChild(Y.parentElement===X?Y:Y.closest(`${lm} > *`))}),B.sort((Y,ce)=>ce[1]-Y[1]).forEach(Y=>{var ce;let ae=(ce=z.current)==null?void 0:ce.querySelector(`${Zo}[${As}="${encodeURIComponent(Y[0])}"]`);ae?.parentElement.appendChild(ae)})}function me(){let M=ge().find(X=>X.getAttribute("aria-disabled")!=="true"),B=M?.getAttribute(As);$.setState("value",B||void 0)}function de(){var M,B,X,Y;if(!r.current.search||d.current.shouldFilter===!1){r.current.filtered.count=i.current.size;return}r.current.filtered.groups=new Set;let ce=0;for(let ae of i.current){let be=(B=(M=l.current.get(ae))==null?void 0:M.value)!=null?B:"",xe=(Y=(X=l.current.get(ae))==null?void 0:X.keywords)!=null?Y:[],Oe=ve(be,xe);r.current.filtered.items.set(ae,Oe),Oe>0&&ce++}for(let[ae,be]of o.current)for(let xe of be)if(r.current.filtered.items.get(xe)>0){r.current.filtered.groups.add(ae);break}r.current.filtered.count=ce}function le(){var M,B,X;let Y=te();Y&&(((M=Y.parentElement)==null?void 0:M.firstChild)===Y&&((X=(B=Y.closest(Zo))==null?void 0:B.querySelector(vP))==null||X.scrollIntoView({block:"nearest"})),Y.scrollIntoView({block:"nearest"}))}function te(){var M;return(M=z.current)==null?void 0:M.querySelector(`${XC}[aria-selected="true"]`)}function ge(){var M;return Array.from(((M=z.current)==null?void 0:M.querySelectorAll(mw))||[])}function L(M){let B=ge()[M];B&&$.setState("value",B.getAttribute(As))}function K(M){var B;let X=te(),Y=ge(),ce=Y.findIndex(be=>be===X),ae=Y[ce+M];(B=d.current)!=null&&B.loop&&(ae=ce+M<0?Y[Y.length-1]:ce+M===Y.length?Y[0]:Y[ce+M]),ae&&$.setState("value",ae.getAttribute(As))}function re(M){let B=te(),X=B?.closest(Zo),Y;for(;X&&!Y;)X=M>0?jP(X,Zo):TP(X,Zo),Y=X?.querySelector(mw);Y?$.setState("value",Y.getAttribute(As)):K(M)}let W=()=>L(ge().length-1),ne=M=>{M.preventDefault(),M.metaKey?W():M.altKey?re(1):K(1)},D=M=>{M.preventDefault(),M.metaKey?L(0):M.altKey?re(-1):K(-1)};return S.createElement($e.div,{ref:n,tabIndex:-1,...R,"cmdk-root":"",onKeyDown:M=>{var B;(B=R.onKeyDown)==null||B.call(R,M);let X=M.nativeEvent.isComposing||M.keyCode===229;if(!(M.defaultPrevented||X))switch(M.key){case"n":case"j":{E&&M.ctrlKey&&ne(M);break}case"ArrowDown":{ne(M);break}case"p":case"k":{E&&M.ctrlKey&&D(M);break}case"ArrowUp":{D(M);break}case"Home":{M.preventDefault(),L(0);break}case"End":{M.preventDefault(),W();break}case"Enter":{M.preventDefault();let Y=te();if(Y){let ce=new Event(ep);Y.dispatchEvent(ce)}}}}},S.createElement("label",{"cmdk-label":"",htmlFor:F.inputId,id:F.labelId,style:MP},m),md(e,M=>S.createElement(WC.Provider,{value:$},S.createElement(JC.Provider,{value:F},M))))}),bP=S.forwardRef((e,n)=>{var r,i;let o=dn(),l=S.useRef(null),u=S.useContext(eE),d=jl(),m=nE(e),p=(i=(r=m.current)==null?void 0:r.forceMount)!=null?i:u?.forceMount;Ai(()=>{if(!p)return d.item(o,u?.id)},[p]);let y=rE(o,l,[e.value,e.children,l],e.keywords),v=gg(),b=qa(U=>U.value&&U.value===y.current),x=qa(U=>p||d.filter()===!1?!0:U.search?U.filtered.items.get(o)>0:!0);S.useEffect(()=>{let U=l.current;if(!(!U||e.disabled))return U.addEventListener(ep,w),()=>U.removeEventListener(ep,w)},[x,e.onSelect,e.disabled]);function w(){var U,$;_(),($=(U=m.current).onSelect)==null||$.call(U,y.current)}function _(){v.setState("value",y.current,!0)}if(!x)return null;let{disabled:E,value:R,onSelect:T,forceMount:O,keywords:N,...z}=e;return S.createElement($e.div,{ref:Fs(l,n),...z,id:o,"cmdk-item":"",role:"option","aria-disabled":!!E,"aria-selected":!!b,"data-disabled":!!E,"data-selected":!!b,onPointerMove:E||d.getDisablePointerSelection()?void 0:_,onClick:E?void 0:w},e.children)}),xP=S.forwardRef((e,n)=>{let{heading:r,children:i,forceMount:o,...l}=e,u=dn(),d=S.useRef(null),m=S.useRef(null),p=dn(),y=jl(),v=qa(x=>o||y.filter()===!1?!0:x.search?x.filtered.groups.has(u):!0);Ai(()=>y.group(u),[]),rE(u,d,[e.value,e.heading,m]);let b=S.useMemo(()=>({id:u,forceMount:o}),[o]);return S.createElement($e.div,{ref:Fs(d,n),...l,"cmdk-group":"",role:"presentation",hidden:v?void 0:!0},r&&S.createElement("div",{ref:m,"cmdk-group-heading":"","aria-hidden":!0,id:p},r),md(e,x=>S.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":r?p:void 0},S.createElement(eE.Provider,{value:b},x))))}),wP=S.forwardRef((e,n)=>{let{alwaysRender:r,...i}=e,o=S.useRef(null),l=qa(u=>!u.search);return!r&&!l?null:S.createElement($e.div,{ref:Fs(o,n),...i,"cmdk-separator":"",role:"separator"})}),SP=S.forwardRef((e,n)=>{let{onValueChange:r,...i}=e,o=e.value!=null,l=gg(),u=qa(p=>p.search),d=qa(p=>p.selectedItemId),m=jl();return S.useEffect(()=>{e.value!=null&&l.setState("search",e.value)},[e.value]),S.createElement($e.input,{ref:n,...i,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":m.listId,"aria-labelledby":m.labelId,"aria-activedescendant":d,id:m.inputId,type:"text",value:o?e.value:u,onChange:p=>{o||l.setState("search",p.target.value),r?.(p.target.value)}})}),_P=S.forwardRef((e,n)=>{let{children:r,label:i="Suggestions",...o}=e,l=S.useRef(null),u=S.useRef(null),d=qa(p=>p.selectedItemId),m=jl();return S.useEffect(()=>{if(u.current&&l.current){let p=u.current,y=l.current,v,b=new ResizeObserver(()=>{v=requestAnimationFrame(()=>{let x=p.offsetHeight;y.style.setProperty("--cmdk-list-height",x.toFixed(1)+"px")})});return b.observe(p),()=>{cancelAnimationFrame(v),b.unobserve(p)}}},[]),S.createElement($e.div,{ref:Fs(l,n),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":d,"aria-label":i,id:m.listId},md(e,p=>S.createElement("div",{ref:Fs(u,m.listInnerRef),"cmdk-list-sizer":""},p)))}),CP=S.forwardRef((e,n)=>{let{open:r,onOpenChange:i,overlayClassName:o,contentClassName:l,container:u,...d}=e;return S.createElement(hp,{open:r,onOpenChange:i},S.createElement(pp,{container:u},S.createElement(gp,{"cmdk-overlay":"",className:o}),S.createElement(vp,{"aria-label":e.label,"cmdk-dialog":"",className:l},S.createElement(tE,{ref:n,...d}))))}),EP=S.forwardRef((e,n)=>qa(r=>r.filtered.count===0)?S.createElement($e.div,{ref:n,...e,"cmdk-empty":"",role:"presentation"}):null),RP=S.forwardRef((e,n)=>{let{progress:r,children:i,label:o="Loading...",...l}=e;return S.createElement($e.div,{ref:n,...l,"cmdk-loading":"",role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},md(e,u=>S.createElement("div",{"aria-hidden":!0},u)))}),hd=Object.assign(tE,{List:_P,Item:bP,Input:SP,Group:xP,Separator:wP,Dialog:CP,Empty:EP,Loading:RP});function jP(e,n){let r=e.nextElementSibling;for(;r;){if(r.matches(n))return r;r=r.nextElementSibling}}function TP(e,n){let r=e.previousElementSibling;for(;r;){if(r.matches(n))return r;r=r.previousElementSibling}}function nE(e){let n=S.useRef(e);return Ai(()=>{n.current=e}),n}var Ai=typeof window>"u"?S.useEffect:S.useLayoutEffect;function Ms(e){let n=S.useRef();return n.current===void 0&&(n.current=e()),n}function qa(e){let n=gg(),r=()=>e(n.snapshot());return S.useSyncExternalStore(n.subscribe,r,r)}function rE(e,n,r,i=[]){let o=S.useRef(),l=jl();return Ai(()=>{var u;let d=(()=>{var p;for(let y of r){if(typeof y=="string")return y.trim();if(typeof y=="object"&&"current"in y)return y.current?(p=y.current.textContent)==null?void 0:p.trim():o.current}})(),m=i.map(p=>p.trim());l.value(e,d,m),(u=n.current)==null||u.setAttribute(As,d),o.current=d}),o}var OP=()=>{let[e,n]=S.useState(),r=Ms(()=>new Map);return Ai(()=>{r.current.forEach(i=>i()),r.current=new Map},[e]),(i,o)=>{r.current.set(i,o),n({})}};function AP(e){let n=e.type;return typeof n=="function"?n(e.props):"render"in n?n.render(e.props):e}function md({asChild:e,children:n},r){return e&&S.isValidElement(n)?S.cloneElement(AP(n),{ref:n.ref},r(n.props.children)):r(n)}var MP={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};function NP({className:e,...n}){return f.jsx(hd,{"data-slot":"command",className:Je("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...n})}function DP({className:e,...n}){return f.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[f.jsx(b_,{className:"size-4 shrink-0 opacity-50"}),f.jsx(hd.Input,{"data-slot":"command-input",className:Je("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...n})]})}function zP({className:e,...n}){return f.jsx(hd.List,{"data-slot":"command-list",className:Je("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",e),...n})}function kP({className:e,...n}){return f.jsx(hd.Item,{"data-slot":"command-item",className:Je("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...n})}function pw(e,n){if(!e)return{score:0,hits:[]};const r=e.toLowerCase(),i=n.toLowerCase();let o=0,l=0,u=0;const d=[];for(let m=0;m3&&i.endsWith("ies")?o=i.slice(0,-3)+"y":i.length>3&&i.endsWith("es")?o=i.slice(0,-2):i.length>2&&i.endsWith("s")&&(o=i.slice(0,-1)),o?pw(o,n):null}function $P({text:e,hits:n}){const r=[];let i=0;return n.forEach((o,l)=>{o>i&&r.push(e.slice(i,o)),r.push(f.jsx("b",{children:e[o]},l)),i=o+1}),r.push(e.slice(i)),f.jsx("span",{className:"plabel",children:r})}function IP({open:e,onClose:n,candidates:r}){const[i,o]=S.useState(""),l=S.useMemo(()=>{if(!e)return[];const d=[];for(const m of r()){const p=LP(i,m.label);p&&d.push({...m,score:p.score,hits:p.hits})}return d.sort((m,p)=>p.score-m.score),d.slice(0,40)},[e,i,r]);S.useEffect(()=>{e&&o("")},[e]);const u=d=>{n(),d.run()};return f.jsx(Ju,{open:e,onOpenChange:d=>!d&&n(),children:f.jsxs(Wu,{id:"palette",className:"palette",showCloseButton:!1,"aria-describedby":void 0,children:[f.jsx(_l,{className:"sr-only",children:"Search and quick actions"}),f.jsxs(NP,{shouldFilter:!1,loop:!0,children:[f.jsxs("div",{id:"palette-inputwrap",children:[f.jsx(ut,{name:"search"}),f.jsx(DP,{placeholder:"Search file names, projects, actions…",autoComplete:"off",spellCheck:!1,value:i,onValueChange:o})]}),f.jsx(zP,{children:l.length===0?f.jsx("div",{className:"pempty",children:"No matches — search covers file names, projects, and actions"}):l.map(d=>f.jsxs(kP,{value:d.kind+":"+d.label,onSelect:()=>u(d),children:[f.jsx("span",{className:"picon",children:f.jsx(ut,{name:d.icon})}),f.jsx($P,{text:d.label,hits:d.hits}),f.jsx("span",{className:"pkind",children:d.kind})]},d.kind+":"+d.label))}),f.jsx("footer",{id:"palette-hint",children:"↑↓ navigate · ⏎ select · esc close"})]})]})})}const Wo=3,Ns=30;function PP(e,n){return Pt({queryKey:["heatDevices",e],queryFn:()=>Bt(e+"heat?by=device&days=30"),enabled:n,retry:!1,staleTime:6e4}).data?.devices??null}const FP=["all","human","agent","share"],VP={all:"All reads",human:"Human reads",agent:"Agent reads",share:"Shared reads"},UP={agent:{agent:1,human:0,share:0},human:{agent:0,human:1,share:0},share:{agent:0,human:0,share:1}};function gw(e){const[n,r]=S.useState("all"),{flatFiles:i,heatMap:o,devices:l,scope:u}=e,d=w=>!u||w===u||w.startsWith(u+"/"),m=u?i.filter(w=>d(w.path)):i;if(!e.loading&&!m.length)return f.jsxs("div",{className:"insights",children:[f.jsxs("h1",{className:"in-title",children:["Knowledge insights",u?f.jsxs("span",{className:"in-scope",children:[" · ",u]}):null]}),f.jsxs("div",{className:"dl-empty in-blank",children:[f.jsx("p",{children:u?`Nothing in ${u} to chart yet.`:"Nothing to chart yet."}),f.jsx("p",{children:u?`No files under ${u} are syncing here yet.`:"This project has no files. Once a device syncs files here, the map, the reads × freshness plot and the hot path fill in on their own."}),e.installHref&&f.jsx("a",{className:"pbtn",...Bs(e.installHref),children:"Set up a device →"})]})]});const p=l&&u?l.map(w=>{const _=Object.create(null);for(const[E,R]of Object.entries(w.folders||{}))d(E)&&(_[E]=R);return{...w,folders:_}}).filter(w=>Object.keys(w.folders).length>0):l,y=Date.now(),v=m.map(w=>{const _=o&&o[w.path]||{},E=w.time?Math.max(0,(y-new Date(w.time).getTime())/864e5):0,R=n==="all"?ka(_):_[n]||0;return{path:w.path,reads:R,agent:_.agent||0,human:_.human||0,share:_.share||0,total:ka(_),days:E,danger:R>=Wo&&E>=Ns}}),b=iI(o,new Set(i.map(w=>w.path))).filter(d).map(w=>{const _=o[w];return{path:w,reads:n==="all"?ka(_):_[n]||0,agent:_.agent||0,human:_.human||0,share:_.share||0,total:ka(_),days:0,danger:!1,orphan:!0}}).filter(w=>w.reads>0),x=b.length>0?f.jsxs("p",{className:"in-legend in-orphan-note",children:[tp(b.length,"file")," with reads ",b.length===1?"is":"are"," no longer in the project — see Hot path."]}):null;return f.jsxs("div",{className:"insights",children:[f.jsxs("h1",{className:"in-title",children:["Knowledge insights",u?f.jsxs("span",{className:"in-scope",children:[" · ",u]}):null]}),f.jsx("p",{className:"dl-sub",children:u?`Reads over the last 30 days × freshness, for ${u} and everything in it.`:"Reads over the last 30 days × how long since each file changed. Hot but stale knowledge — read a lot, maintained by nobody — is the danger zone."}),f.jsx("div",{className:"in-lens",children:FP.map(w=>f.jsx("button",{className:"in-lens-btn"+(w===n?" active":""),onClick:()=>r(w),children:VP[w]},w))}),f.jsx("h3",{className:"dl-h3",children:"Map — cell size = reads, color = freshness (scale below)"}),f.jsx(BP,{pts:v,onOpenFile:e.onOpenFile,onOpenFolder:e.onOpenFolder,isFolder:e.isFolder}),x,f.jsxs("h3",{className:"dl-h3 in-h3-row",children:["Reads × freshness",f.jsx("span",{className:"in-cap",children:"dot size = agent share of reads"})]}),f.jsx(GP,{pts:v,onOpenFile:e.onOpenFile}),x,f.jsx("h3",{className:"dl-h3",children:"Hot path — top files by reads"}),f.jsx(ZP,{pts:[...v,...b],lens:n,onOpenFile:e.onOpenFile,onOpenHistory:e.onOpenHistory}),p&&p.length>0&&f.jsxs(f.Fragment,{children:[f.jsx("h3",{className:"dl-h3",children:"Agent coverage — which agents read which areas"}),f.jsx(KP,{devices:p})]})]})}const HP="rgb(150,156,164)";function aE(e){const n=[[76,195,138],[232,196,84],[224,93,93]],r=Math.min(1,Math.max(0,e/300))*(n.length-1),i=Math.min(n.length-2,Math.floor(r)),o=r-i,l=n[i].map((u,d)=>Math.round(u+(n[i+1][d]-u)*o));return`rgb(${l[0]},${l[1]},${l[2]})`}function vw(e,n,r,i,o){const l=e.reduce((p,y)=>p+y.value,0);if(!l||i<=0||o<=0)return[];const u=e.slice().sort((p,y)=>y.value-p.value).map(p=>({it:p,a:p.value/l*i*o})),d=(p,y)=>{const b=p.reduce((w,_)=>w+_.a,0)/y;let x=0;for(const w of p){const _=w.a/b;x=Math.max(x,_/b,b/_)}return x},m=[];for(;u.length;){const p=i>=o,y=p?o:i,v=[u.shift()];for(;u.length&&d(v.concat(u[0]),y)<=d(v,y);)v.push(u.shift());const b=v.reduce((w,_)=>w+_.a,0)/y;let x=0;for(const w of v){const _=w.a/b;p?m.push({item:w.it,x:n,y:r+x,w:b,h:_}):m.push({item:w.it,x:n+x,y:r,w:_,h:b}),x+=_}p?(n+=b,i-=b):(r+=b,o-=b)}return m}const cm=15;function yw(e,n,r){const i=Math.floor((r-8)/6),o=`${e} · ${n}`;return o.length<=i?{label:o,fit:i}:{label:e.length>i?e.slice(0,Math.max(1,i-1))+"…":e,fit:i}}const tp=(e,n)=>`${e} ${n}${e===1?"":"s"}`;function BP({pts:e,onOpenFile:n,onOpenFolder:r,isFolder:i}){const u=oI(e.map(y=>y.days)),d=!!u&&lI(u.min,u.max),m=new Map;for(const y of e){const v=y.path.includes("/")?y.path.split("/")[0]:"/";let b=m.get(v);b||m.set(v,b={name:v,files:[],value:0,reads:0}),b.files.push(y),b.value+=y.reads+1,b.reads+=y.reads}const p=[];for(const y of vw([...m.values()],0,0,720,480)){const v=y.item,b=v.name==="/"?"":v.name,x=v.name==="/"?"(root)":v.name;if(p.push(f.jsx("rect",{x:y.x+1,y:y.y+1,width:Math.max(0,y.w-2),height:Math.max(0,y.h-2),rx:3,className:"in-tm-group","data-dir":b,children:f.jsx("title",{children:`${v.name==="/"?"(root)":v.name+"/"} — ${tp(v.reads,"read")}/30d · ${tp(v.files.length,"file")}`})},"g"+v.name)),y.w>46&&y.h>cm+10){const{label:_}=yw(x,v.reads,y.w);p.push(f.jsx("text",{x:y.x+5,y:y.y+12,className:"in-tm-glabel","data-dir":b,children:_},"gl"+v.name))}const w=vw(v.files.map(_=>({..._,name:_.path.split("/").pop(),value:_.reads+1})),y.x+2,y.y+cm,Math.max(0,y.w-4),Math.max(0,y.h-cm-2));for(const _ of w)if(p.push(f.jsx("rect",{x:_.x+.6,y:_.y+.6,width:Math.max(.4,_.w-1.2),height:Math.max(.4,_.h-1.2),rx:1.5,fill:d?HP:aE(_.item.days),className:"in-tm-cell","data-path":_.item.path,children:f.jsx("title",{children:`${_.item.path} — ${_.item.reads} read${_.item.reads===1?"":"s"}/30d · changed ${Math.round(_.item.days)}d ago`})},_.item.path)),_.w>54&&_.h>16){const{label:E,fit:R}=yw((_.item.danger?"⚠ ":"")+_.item.name,_.item.reads,_.w);R>=5&&p.push(f.jsx("text",{x:_.x+4.5,y:_.y+12.5,className:"in-tm-label","data-path":_.item.path,children:E},"l"+_.item.path))}}return f.jsxs(f.Fragment,{children:[f.jsx("svg",{viewBox:"0 0 720 480",className:"in-chart in-treemap",onClick:y=>{const v=y.target.closest("[data-path], [data-dir]");if(!v)return;const b=v.getAttribute("data-path");if(b)return n(b);const x=v.getAttribute("data-dir");x&&i(x)&&r(x)},children:p}),f.jsx(qP,{range:u,flat:d})]})}function qP({range:e,flat:n}){if(!e)return null;const r=cI(e.min,e.max);return f.jsxs("p",{className:"in-legend in-tm-legend",children:["freshness 0d",f.jsx("span",{className:"in-sw in-sw-age"+(n?" in-sw-flat":""),style:{background:`linear-gradient(to right, ${[0,60,150,300].map(aE).join(", ")})`}}),"300d+",f.jsx("span",{className:"in-tm-range",children:n?`all files here: ${r} old — colour off, not enough range to rank`:`observed: ${r} old`})]})}function GP({pts:e,onOpenFile:n}){const o={l:44,r:16,t:20,b:34},l=Math.max(Ns*2,...e.map(w=>w.days)),u=Math.max(Wo*2,...e.map(w=>w.reads)),d=w=>Math.log10(w+1)/Math.log10(l+1),m=w=>Math.log10(w+1)/Math.log10(u+1),p=w=>3+4*w,y=p(1),v=w=>o.l+y+d(w)*(720-o.l-o.r-2*y),b=w=>360-o.b-y-m(w)*(360-o.t-o.b-2*y),x=fI(e.filter(w=>w.danger).map(w=>({path:w.path,reads:w.reads,cx:v(w.days),cy:b(w.reads),r:p(w.total?(w.agent||0)/w.total:0)})),{right:720-o.r,top:o.t+8,bottom:360-o.b-4});return f.jsxs("svg",{viewBox:"0 0 720 360",className:"in-chart",children:[f.jsx("rect",{x:v(Ns),y:o.t,width:720-o.r-v(Ns),height:b(Wo)-o.t,className:"in-danger-zone"}),f.jsx("line",{x1:v(Ns),y1:o.t,x2:v(Ns),y2:360-o.b,className:"in-threshold"}),f.jsx("line",{x1:o.l,y1:b(Wo),x2:720-o.r,y2:b(Wo),className:"in-threshold"}),f.jsx("line",{x1:o.l,y1:360-o.b,x2:720-o.r,y2:360-o.b,className:"in-axis"}),f.jsx("line",{x1:o.l,y1:o.t,x2:o.l,y2:360-o.b,className:"in-axis"}),f.jsx("text",{x:(o.l+720-o.r)/2,y:352,className:"in-label",children:"days since last change →"}),f.jsx("text",{x:12,y:(o.t+360-o.b)/2,className:"in-label",transform:`rotate(-90 12 ${(o.t+360-o.b)/2})`,children:"reads / 30d →"}),f.jsx("text",{x:720-o.r-6,y:o.t+14,className:"in-quad in-quad-danger",textAnchor:"end",children:"hot + stale"}),f.jsx("text",{x:o.l+6,y:o.t+14,className:"in-quad",children:"hot + fresh"}),f.jsx("text",{x:720-o.r-6,y:360-o.b-8,className:"in-quad",textAnchor:"end",children:"cold + stale"}),f.jsx("text",{x:o.l+6,y:360-o.b-8,className:"in-quad",children:"cold + fresh"}),e.map(w=>{const _=w.total?(w.agent||0)/w.total:0;return f.jsx("circle",{cx:Number(v(w.days).toFixed(1)),cy:Number(b(w.reads).toFixed(1)),r:Number(p(_).toFixed(1)),className:"in-pt"+(w.danger?" danger":w.reads?"":" cold"),onClick:()=>n(w.path),children:f.jsx("title",{children:`${w.path} — ${w.reads} read${w.reads===1?"":"s"} / 30d · changed ${Math.round(w.days)}d ago`})},w.path)}),x.map(w=>f.jsx("text",{x:Number(w.x.toFixed(1)),y:Number(w.y.toFixed(1)),textAnchor:w.anchor,className:"in-pt-label",children:w.name},w.path))]})}function ZP({pts:e,lens:n,onOpenFile:r,onOpenHistory:i}){const o=e.filter(d=>d.reads>0).sort((d,m)=>m.reads-d.reads||m.days-d.days).slice(0,20);if(!o.length)return f.jsx("div",{className:"dl-empty",children:"No reads in the window yet."});const l=o[0].reads,u=o.some(d=>d.share>0);return f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"in-hotpath",children:o.map(d=>{const m=UP[n]??aI(d),p=d.reads/l*100,y=()=>d.orphan?i(d.path):r(d.path);return f.jsxs("div",{className:"in-hp-row",tabIndex:0,role:"button",title:d.orphan?`${d.reads} read${d.reads===1?"":"s"}/30d · no longer in the project — open its history`:d.danger?`${d.reads} read${d.reads===1?"":"s"}/30d · unchanged ${Math.round(d.days)}d — review this file`:d.path,onClick:y,onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),y())},children:[f.jsx("span",{className:"in-hp-name"+(d.danger?" danger":""),children:d.path+(d.danger?" ⚠":"")}),d.orphan&&f.jsx("span",{className:"in-hp-gone",children:"· no longer in the project"}),f.jsxs("span",{className:"in-hp-bar",children:[f.jsx("span",{className:"in-hp-agent",style:{width:(p*m.agent).toFixed(1)+"%"}}),f.jsx("span",{className:"in-hp-human",style:{width:(p*m.human).toFixed(1)+"%"}}),f.jsx("span",{className:"in-hp-share",style:{width:(p*m.share).toFixed(1)+"%"}})]}),f.jsx("span",{className:"in-hp-count",children:d.reads})]},d.path)})}),f.jsxs("p",{className:"in-legend",children:[f.jsx("span",{className:"in-sw agent"})," agent reads ",f.jsx("span",{className:"in-sw human"})," human reads",u&&f.jsxs(f.Fragment,{children:[" ",f.jsx("span",{className:"in-sw share"})," shared reads"]})]})]})}function KP({devices:e}){const n=new Map;for(const b of e)for(const[x,w]of Object.entries(b.folders||{}))n.set(x,(n.get(x)||0)+w);const r=[...n.entries()].sort((b,x)=>x[1]-b[1]).slice(0,12).map(b=>b[0]),i=e.slice(0,12),o=140,l=6,u=Math.min(76,Math.max(34,(720-o-8)/r.length)),d=26,m=720,p=l+i.length*d+58,y=Math.max(1,...i.flatMap(b=>r.map(x=>(b.folders||{})[x]||0))),v=b=>{const x=[23,25,31],w=[245,166,35],_=x.map((E,R)=>Math.round(E+(w[R]-E)*b));return`rgb(${_[0]},${_[1]},${_[2]})`};return f.jsxs("svg",{viewBox:`0 0 ${m} ${p}`,className:"in-chart in-matrix",children:[i.map((b,x)=>{let w=b.name||b.id||"";return w.length>20&&(w=w.slice(0,19)+"…"),f.jsxs("g",{children:[f.jsx("text",{x:o-8,y:l+x*d+17,textAnchor:"end",className:"in-label",children:w}),r.map((_,E)=>{const R=(b.folders||{})[_]||0;return f.jsx("rect",{x:o+E*u,y:l+x*d,width:u-4,height:d-4,rx:3,fill:v(Math.sqrt(R/y)),children:f.jsx("title",{children:`${b.name||b.id} × ${_||"(root)"}: ${R} read${R===1?"":"s"}/30d`})},_)})]},b.id||x)}),r.map((b,x)=>{const w=o+x*u+(u-4)/2,_=l+i.length*d+14;return f.jsx("text",{x:w,y:_,className:"in-label",textAnchor:"end",transform:`rotate(-28 ${w} ${_})`,children:b||"(root)"},b)})]})}function iE(e){return new Set(e.entries.map(n=>n.path)).size}function YP(e){const n=l=>(l.session?"s\0"+l.session:"n\0"+l.note)+"\0"+(l.device?.id??""),r=new Map;e.forEach((l,u)=>{if(!l.note&&!l.session)return;const d=r.get(n(l));if(d){d.entries.push(l),d.idx.push(u);return}r.set(n(l),{note:l.note??"",session:l.session,entries:[l],idx:[u]})});const i=[],o=new Set;return e.forEach((l,u)=>{const d=l.note||l.session?r.get(n(l)):void 0;if(!d||iE(d)<2){i.push({i:u});return}o.has(d)||(o.add(d),i.push({run:d,i:u}))}),i}function QP(e){const{filters:n,authors:r,onChange:i}=e,o=(y,v)=>i({...n,[y]:v||void 0}),[l,u]=S.useState(n?.q??""),d=S.useRef(!1);S.useEffect(()=>{d.current||u(n?.q??"")},[n?.q]),S.useEffect(()=>{if(!d.current)return;const y=setTimeout(()=>{d.current=!1,l!==(n?.q??"")&&o("q",l)},250);return()=>clearTimeout(y)},[l]);const m=n?.user&&!r.includes(n.user)?[n.user,...r]:r,p=Zp(n);return f.jsxs("div",{className:"hfilters",children:[f.jsxs("label",{className:"hf-search",children:[f.jsx(ut,{name:"search"}),f.jsx(du,{type:"search",value:l,placeholder:"path contains…","aria-label":"Filter by path",onChange:y=>{d.current=!0,u(y.target.value)}})]}),f.jsxs("select",{className:"hf-user",value:n?.user??"","aria-label":"Filter by author",onChange:y=>o("user",y.target.value),children:[f.jsx("option",{value:"",children:"Anyone"}),m.map(y=>f.jsx("option",{value:y,children:y},y))]}),f.jsxs("span",{className:"hf-dates",children:[f.jsx("span",{className:"hf-lbl",children:"UTC"}),f.jsx(du,{type:"date",className:"hf-date",value:n?.since??"","aria-label":"From date (UTC)",onChange:y=>o("since",y.target.value)}),f.jsx("span",{className:"hf-dash",children:"–"}),f.jsx(du,{type:"date",className:"hf-date",value:n?.until??"","aria-label":"To date (UTC)",onChange:y=>o("until",y.target.value)})]}),p&&f.jsx("button",{type:"button",className:"hf-clear",onClick:()=>i({}),children:"Clear"})]})}function XP(e){const n=new Set;for(const r of e)r.user&&n.add(r.user);return[...n].sort()}function JP(e){const{apiBase:n,target:r,isFolder:i,onMeta:o,onRendered:l,restore:u,remove:d,filters:m}=e,p=r?i(r)?{prefix:r+"/"}:{path:r}:{prefix:""},y=("path"in p&&p.path!==void 0?"path="+encodeURIComponent(p.path):"prefix="+encodeURIComponent(p.prefix??""))+N_(m).replace("?","&"),{data:v,error:b,fetchNextPage:x,hasNextPage:w,isFetchingNextPage:_}=mj({queryKey:["history",n,y],queryFn:({pageParam:$})=>Bt(n+"history?"+y+"&n=100"+($?"&cursor="+encodeURIComponent($):"")),initialPageParam:"",getNextPageParam:$=>$.next_cursor,staleTime:15e3}),E=S.useRef(new Set);S.useEffect(()=>{b&&o("History unavailable: "+b.message)},[b,o]),S.useEffect(()=>{v&&l?.()},[v,l]);const R=v?v.pages.flatMap($=>$.entries||[]):[];for(const $ of XP(R))E.current.add($);const T=e.onFilters&&f.jsx(QP,{filters:m,authors:[...E.current].sort(),onChange:e.onFilters});if(!v)return T?f.jsx("div",{className:"history",children:T}):null;const O=$=>{for(let F=$+1;F{const F=R[$].kind==="delete"?O($):R[$].blob;return F&&F===N.get(R[$].path)?void 0:F},U=$=>N.get(R[$].path)==="";return f.jsxs("div",{className:"history",children:[T,R.length===0&&(Zp(m)?f.jsxs("div",{className:"empty",children:["No changes match these filters.",f.jsx("br",{}),f.jsx("button",{type:"button",className:"btn hf-clear-empty",onClick:()=>e.onFilters?.({}),children:"Clear filters"})]}):f.jsx("div",{className:"empty",children:"No history yet."})),YP(R).map(($,F)=>$.run?f.jsx(WP,{run:$.run,onOpen:e.onOpen,apiBase:n,prevBlob:O,restoreSha:z,recreates:U,restore:u,remove:d},"g"+F):f.jsx(pg,{entry:R[$.i],apiBase:n,onOpen:e.onOpen,diff:{apiBase:n,prev:O($.i)},restore:u,restoreSha:z($.i),recreates:U($.i)},"r"+$.i)),w&&f.jsx("button",{type:"button",className:"btn hmore",onClick:()=>x(),disabled:_,children:_?"Loading…":"Load more"})]})}function WP({run:e,onOpen:n,apiBase:r,prevBlob:i,restoreSha:o,recreates:l,restore:u,remove:d}){const[m,p]=S.useState(!0),y=e.entries[0],v=dd(y),b=[y.device.name||y.device.id,y.device.os].filter(Boolean).join(" · "),x=y.session,w=y.device?.id,{data:_}=Pt({queryKey:["session-reads",r,x,w],queryFn:()=>Bt(r+"heat?session="+encodeURIComponent(x)+"&device="+encodeURIComponent(w)),enabled:!!x&&!!w,staleTime:3e4}),E=new Set(_?.paths??[]),R=new Set(e.entries.map(U=>U.path)),T=[...E].filter(U=>!R.has(U)).sort(),O=e.entries.map(U=>new Date(U.time).getTime()),N=eF(Math.min(...O),Math.max(...O)),z=iE(e);return f.jsxs("div",{className:"hrun"+(m?" open":""),children:[f.jsxs("div",{className:"hrun-head",children:[f.jsx("button",{type:"button",className:"hrun-toggle","aria-expanded":m,title:m?"Collapse this run":"Expand this run",onClick:()=>p(!m),children:f.jsx(ut,{name:m?"chevd":"chev"})}),f.jsx("span",{className:"hrun-note",children:f.jsx(KC,{text:e.note})}),f.jsxs("span",{className:"hrun-meta",children:[E.size>0?`read ${E.size} · changed ${z}`:`${z} file${z===1?"":"s"}`," ·"," ",v,b?" · "+b:""]}),f.jsx("span",{className:"hrun-time",children:N})]}),m&&f.jsxs("div",{className:"hrun-body",children:[e.entries.map((U,$)=>f.jsx(pg,{entry:U,apiBase:r,onOpen:n,diff:{apiBase:r,prev:i(e.idx[$])},restore:u,remove:d,restoreSha:o(e.idx[$]),recreates:l(e.idx[$]),inRun:!0,read:E.has(U.path)},$)),T.length>0&&f.jsxs("div",{className:"hrun-reads",children:[f.jsx("div",{className:"hrun-reads-head",children:"Read, not changed"}),T.map(U=>f.jsxs("button",{type:"button",className:"hrun-read",onClick:()=>n(U),children:[f.jsx("span",{className:"hkind",children:"read"}),f.jsx("span",{className:"hpath",children:U})]},U))]}),x&&f.jsx("div",{className:"hrun-foot",children:"Reads shown only for files the project still has."})]})]})}function eF(e,n){const r=new Date(e),i=new Date(n),o=u=>u.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(r.toDateString()!==i.toDateString())return r.toLocaleString()+" – "+i.toLocaleString();const l=i.toLocaleDateString();return e===n?l+" "+o(i):l+" "+o(r)+" – "+o(i)}function tF(e,n){return e?n(e)?e+"/ (folder)":e:"all changes"}function nF(e){const{apiBase:n,path:r,version:i}=e,o="path="+encodeURIComponent(r),{data:l}=Pt({queryKey:["history",n,o,200],queryFn:()=>Bt(n+"history?"+o+"&n=200"),staleTime:15e3}),u=l?.entries?.find(y=>y.blob===i),d=u?dd(u):"",m=u?.time?new Date(u.time).toLocaleString():"",p=n+"blob?sha="+i+"&name="+encodeURIComponent(r.split("/").pop()||r)+"&download=1";return f.jsxs("div",{className:"vbanner",role:"status",children:[f.jsx("span",{className:"vb-icon",children:f.jsx(ut,{name:"clock"})}),f.jsxs("div",{className:"vb-text",children:[f.jsx("b",{children:[m&&"Version from "+m,d&&"by "+d].filter(Boolean).join(" ")||"Earlier version"}),f.jsx("span",{children:"This is not the current file."})]}),f.jsxs("div",{className:"vb-actions",children:[f.jsx("button",{className:"ai-btn",onClick:e.onViewCurrent,children:"View current"}),f.jsx("a",{className:"ai-btn",download:!0,href:p,children:"Download this version"})]})]})}const rF={aws_access_key_id:"an AWS access key",openai_api_key:"an OpenAI API key",github_pat:"a GitHub token",slack_token:"a Slack token",private_key:"a private key",gitlab_pat:"a GitLab token"};function aF(e=[]){const n=e.map(i=>`${rF[i.rule]??i.rule} (line ${i.line})`);return`BearDrive found ${n.length>1?n.slice(0,-1).join(", ")+" and "+n[n.length-1]:n[0]||"something credential-shaped"} in this file. The check covers the file at the moment you share it — a link always serves the file's latest content, so later changes are never checked. Share anyway?`}function sE(e){const{config:n,apiBase:r,route:i,hub:o,project:l}=e,u=Yp(),d=Mi(),{tree:m,flatFiles:p,dirIndex:y,loaded:v}=hI(r,!o||!!l),b=mI(r,o&&!!l&&!!n.reads?.enabled),x=o&&!!l&&!i.path&&!i.view,w=i.view==="dashboard"||x,_=PP(r,w);S.useEffect(()=>{w&&d.invalidateQueries({queryKey:["heat",r]})},[w,r,d]);const E=i.path,R=i.view?void 0:i.version,T=E||(i.view==="dashboard"||i.view==="history")&&i.viewTarget||"",O=!!E&&y.has(E),N=!!E&&v&&!O&&p.some(Z=>Z.path===E),z=!!E&&v&&!O&&!N,U=O&&!i.view,{data:$}=Pt({queryKey:["resolve",r,E],queryFn:()=>Bt(r+"resolve?path="+encodeURIComponent(E)),enabled:z,retry:!1,staleTime:6e4}),[F,ve]=S.useState(null);S.useEffect(()=>{!z||!$?.to||(ve({from:E,to:$.to}),Kt(fl($.to,l?.id),{replace:!0}))},[z,$,E,l?.id]);const[ye,me]=S.useState(()=>new Set),de=S.useRef(!0);S.useEffect(()=>{if(!m||!de.current)return;de.current=!1;const Z=(m.children||[]).filter(J=>J.dir);Z.length===1&&me(J=>new Set(J).add(Z[0].path))},[m]),S.useEffect(()=>{!T||!v||me(Z=>{const J=new Set(Z);for(const fe of kI(T))J.add(fe);return y.has(T)&&J.add(T),J})},[T,v,y]);const le=S.useCallback(Z=>{me(J=>{const fe=new Set(J);return fe.has(Z)?fe.delete(Z):fe.add(Z),fe})},[]),te=S.useRef(null),ge=S.useRef(new Map),L=S.useRef({key:"",want:0,attempts:0});S.useEffect(()=>{L.current={key:u,want:z3()==="POP"?ge.current.get(u)??0:0,attempts:0}},[u]);const K=S.useCallback(()=>{const Z=te.current,J=L.current;!Z||J.key!==u||J.attempts>=3||(J.attempts++,Z.scrollTo({top:J.want,behavior:"instant"}))},[u]),re=S.useCallback(()=>{te.current&&ge.current.set(u,te.current.scrollTop)},[u]),W=S.useCallback((Z,J)=>{Kt(fl(Z,l?.id,J)),mr()},[l?.id]),ne=S.useCallback(Z=>Kt(Pn("history",l?.id,Z)),[l?.id]),[D,M]=S.useState(""),[B,X]=S.useState(null),[Y,ce]=S.useState(!1),[ae,be]=S.useState(!1);S.useEffect(()=>HD(()=>be(!0)),[]);const xe=S.useRef(null),Oe=e.panel??null,Ie=!Oe&&o&&!!l&&N&&Si(l.perm,"write"),{data:Ve}=j_(l?.id,o&&!!l),it=S.useCallback(()=>{d.invalidateQueries({queryKey:["shares",l?.id]})},[d,l?.id]),Qe=N?(Ve||[]).filter(Z=>Z.path===E):[],fn=!Oe&&o&&!!l,hn=!Oe&&N,Qt=!Oe&&(N||o&&!!l&&O),br=R?r+"blob?sha="+R+"&name="+encodeURIComponent(E)+"&download=1":r+"download?path="+encodeURIComponent(E),jt=S.useCallback(async()=>{const Z=J=>fetch(r+"shares",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J?{path:E,confirm:!0}:{path:E})});try{let J=await Z(!1);if(J.status===409){const{findings:_e}=await J.json();if(!await wi("This file may contain credentials",aF(_e),"Share anyway",!0))return;J=await Z(!0)}if(!J.ok)throw new Error(await J.text());const fe=await J.json();zw("share_created");const we=await qs(fe.url);X({url:fe.url,copied:we}),it()}catch(J){Ke("Share failed: "+J.message,!0)}},[r,E,it]),[rr,xr]=S.useState(""),Tt=o&&!!l&&Si(l?.perm,"write"),Vn=S.useCallback(async(Z,J,fe)=>{if(await wi("Restore this version of "+Z+"?","It syncs to every device as a new change. "+(fe?"The file comes back on every device. Removing it again isn't available from History yet.":"You can restore any other version afterwards."),"Restore")){xr(Z+J);try{await _i(r+"restore",{path:Z,sha:J}),d.invalidateQueries({queryKey:["history",r]}),d.invalidateQueries({queryKey:["tree",r]}),d.invalidateQueries({queryKey:["render",r,Z]}),d.invalidateQueries({queryKey:["text"]}),Ke("Restored "+Z+" — it syncs to every device like any other change.")}catch(we){Ke("Restore failed: "+we.message,!0)}finally{xr("")}}},[r,d]),[Dt,kr]=S.useState(""),ar=S.useCallback(async Z=>{if(await wi("Remove "+Z+"?","It disappears from every synced device. History keeps it — you can restore it from the DELETED row afterwards.","Remove file",!0)){kr(Z);try{await _i(r+"remove",{path:Z}),d.invalidateQueries({queryKey:["history",r]}),d.invalidateQueries({queryKey:["tree",r]}),d.invalidateQueries({queryKey:["render",r,Z]}),d.invalidateQueries({queryKey:["text"]}),Ke("Removed "+Z+" — it syncs to every device like any other change.")}catch(J){Ke("Remove failed: "+J.message,!0)}finally{kr("")}}},[r,d]),ir=S.useCallback(()=>{if(!E)return ne("");ne(O?E+"/":E)},[E,O,ne]);S.useEffect(()=>{const Z=J=>{(J.metaKey||J.ctrlKey)&&J.key.toLowerCase()==="k"&&(J.preventDefault(),be(fe=>!fe))};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[]);const wr=S.useCallback(()=>{const Z=[],J=(fe,we,_e,Xe)=>Z.push({icon:fe,label:we,kind:_e,run:Xe});if(o&&l){const fe=l.id,we=_e=>()=>{e.onClosePanel?.(),Kt(_e)};J("folder","Go to project root","action",we("/"+fe)),J("dashboard","Dashboard","action",we(Pn("dashboard",fe))),J("terminal","Installation","action",we(Pn("install",fe))),J("gear","Settings","action",we(Pn("settings",fe)))}if(o&&l&&E&&(N&&J("share","Share: "+E,"action",jt),J("hist","History: "+E,"action",ir),N&&J("download","Download: "+E,"action",()=>xe.current?.click())),o&&l&&J("hist","History: whole project","action",()=>ne("")),o)for(const fe of e.projects||[])(!l||fe.id!==l.id)&&J("folder","Switch to project: "+fe.name,"project",()=>Kt("/"+fe.id));n.auth?.enabled&&J("power","Sign out","action",()=>window.location.href="/auth/logout");for(const fe of y.keys())J("folder",fe,"folder",()=>W(fe));for(const fe of p)J("doc",fe.path,"file",()=>W(fe.path));return Z},[o,l,E,N,n.auth?.enabled,y,p,e.projects,e.onClosePanel,jt,ir,ne,W]);S.useEffect(()=>{if(!Y)return;const Z=()=>ce(!1);return document.addEventListener("click",Z),()=>document.removeEventListener("click",Z)},[Y]);const sr=S.useCallback(Z=>y.has(Z),[y]);let mn="app",A,P;Oe?P=Oe.body:i.view==="dashboard"?P=f.jsx(gw,{flatFiles:p,heatMap:b,devices:_,scope:i.viewTarget||"",loading:!v,installHref:l?Pn("install",l.id):void 0,onOpenFile:W,onOpenFolder:W,onOpenHistory:ne,isFolder:sr}):i.view==="history"?P=f.jsx(JP,{apiBase:r,target:i.viewTarget||"",isFolder:sr,onOpen:W,onMeta:M,onRendered:K,restore:Tt?{onRestore:Vn,busy:rr}:void 0,remove:Tt?{onRemove:ar,busy:Dt}:void 0,filters:i.filters,onFilters:Z=>Kt(Pn("history",l?.id,i.viewTarget||"",Z))}):E?v?z?P=f.jsxs("div",{className:"notfound",children:[f.jsx("h1",{children:"Couldn't find that"}),f.jsxs("p",{children:[f.jsx("code",{children:E})," isn't in this project right now."]}),f.jsx("p",{className:"nf-sub",children:"If it was just created, it may still be uploading or syncing from a teammate's device — this page checks again automatically every few seconds, so refresh or come back in a moment."}),f.jsx("button",{className:"pbtn",onClick:()=>d.invalidateQueries({queryKey:["tree",r]}),children:"Check again"})]}):O?P=f.jsx(ZI,{node:y.get(E),heatMap:b,hub:o&&!!l,apiBase:r,onOpen:W,onFullHistory:ne,onRendered:K}):(mn=OC.test(E)||AC.test(E)?"wide":"read",A="markdown",P=f.jsxs(f.Fragment,{children:[R&&f.jsx(nF,{apiBase:r,path:E,version:R,onViewCurrent:()=>W(E)}),f.jsx(QI,{apiBase:r,path:E,version:R,heatMap:b,flatFiles:p,onOpenFile:W,onMeta:M,onRendered:K})]})):P=f.jsx("div",{className:"empty",children:"Loading…"}):x?P=f.jsxs(f.Fragment,{children:[f.jsx(HC,{project:l,existing:i.connect==="existing"}),f.jsx("div",{className:"home-insights",children:f.jsx(gw,{flatFiles:p,heatMap:b,devices:_,loading:!v,onOpenFile:W,onOpenFolder:W,onOpenHistory:ne,isFolder:sr})})]}):P=f.jsx("div",{className:"empty",children:"Select a file to read it."}),F&&F.to===E&&(P=f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"vbanner",role:"status",children:[f.jsx("span",{className:"vb-icon",children:f.jsx(ut,{name:"link"})}),f.jsxs("div",{className:"vb-text",children:[f.jsxs("b",{children:["Moved from ",F.from]}),f.jsx("span",{children:"The URL has been updated."})]})]}),P]}));const V=Oe?Oe.crumb:E?f.jsx(LI,{path:E,onOpenFolder:W}):i.view==="dashboard"?"Dashboard — "+(i.viewTarget||l?.name||""):i.view==="history"?"History — "+tF(i.viewTarget||"",sr):x?l.name:null,ue=f.jsx(dl,{crumb:V,meta:D,actions:f.jsxs(f.Fragment,{children:[Ie&&f.jsx(vt,{id:"share-btn",variant:"toolbar",className:"icon-only",title:"Share","aria-label":"Share",onClick:jt,children:f.jsx(ut,{name:"share"})}),fn&&!E&&!i.view&&f.jsxs(vt,{id:"history-btn",variant:"toolbar",onClick:ir,children:[f.jsx(ut,{name:"hist"})," ",f.jsx("span",{className:"lbl",children:"History"})]}),hn&&f.jsx("a",{id:"download",hidden:!0,download:!0,href:br,ref:xe,children:"Download"}),Qt&&f.jsx(vt,{id:"more-btn",variant:"toolbar",className:"icon-only",title:"More actions","aria-label":"More actions",onClick:Z=>{Z.stopPropagation(),ce(!Y)},children:f.jsx(ut,{name:"dots"})}),Y&&f.jsxs("div",{id:"more-menu",role:"menu",children:[fn&&f.jsx("button",{className:"more-item",onClick:ir,children:"History"}),hn&&f.jsx("button",{className:"more-item",onClick:()=>xe.current?.click(),children:"Download"}),o&&!!l&&f.jsx("button",{className:"more-item",onClick:()=>{e.onClosePanel?.(),Kt(Pn("dashboard",l?.id,E))},children:"Dashboard"})]})]})});return f.jsxs(f.Fragment,{children:[f.jsx(ul,{vault:e.sidebar.vault,projectsNav:e.sidebar.projectsNav,orgBar:e.sidebar.orgBar,tree:f.jsx(zI,{root:m,expanded:ye,onToggle:le,currentPath:T,listingShowing:U,onOpen:W}),topbar:ue,contentRef:te,onContentScroll:re,children:f.jsxs(Su,{width:mn,className:A,children:[!Oe&&N&&f.jsx(oP,{shares:Qe,canRevoke:!!l&&Si(l.perm,"write"),onChanged:it}),P]})}),B&&f.jsx(sP,{url:B.url,copied:B.copied,onClose:()=>{X(null),it()}}),f.jsx(IP,{open:ae,onClose:()=>be(!1),candidates:wr})]})}function iF({config:e}){const n=Yp(),r=O_(),[i,o]=S.useState(null),[l,u]=S.useState(null);S.useEffect(()=>u(null),[n]);const d=S.useMemo(()=>{const ge=n.split("?")[0].match(/^\/join\/([0-9a-f]+)\/?$/);return ge?ge[1]:null},[n]),{data:m}=j3(!d),{data:p}=T3(!d),y=!!e.auth.admin,{data:v}=T_(y),b=S.useMemo(()=>D_(n,"hub"),[n]),[x,w]=S.useState(!1),_=e.upload.enabled,E=async(ge,L)=>{const K=L===BC;try{const re=await _i("/api/projects",{name:ge,template:K?"":L});w(!1),await r(),Kt("/"+re.project.id+(K?"?connect=existing":"")),Ke(`Created “${re.project.name}”.`)}catch(re){Ke("Could not create the project: "+re.message,!0)}},R=x?f.jsx(nI,{templates:e.templates??[],onCreate:E,onClose:()=>w(!1)}):null,T=S.useMemo(()=>m&&(m.find(ge=>ge.id===b.project)||i&&m.find(ge=>ge.org===i)||m.find(ge=>ge.id===E$())||m[0])||null,[m,b.project,i]);if(S.useEffect(()=>{document.title=T?T.name+" — BearDrive":e.brand||"BearDrive",T&&R$(T.id)},[T,e]),d)return f.jsx(sF,{token:d,onDone:async ge=>{o(ge),await r(),Kt("/",{replace:!0})}});const O=e.brand||"BearDrive",N=T&&p?.find(ge=>ge.id===T.org)||null,z=f.jsx(Xu,{name:O,onHome:()=>Kt("/"),search:!!T,beta:O==="BearDrive"}),U=e.me?f.jsx(Z$,{me:e.me,org:N,orgActive:!!b.org,billing:e.billing,admin:y?{pending:v?.length||0,onClick:()=>{u({kind:"hub"}),mr()}}:void 0}):void 0;if(!m||!p)return f.jsx(ul,{vault:z,topbar:f.jsx(dl,{}),children:f.jsx(Su,{children:f.jsx("div",{className:"empty",children:"Loading…"})})});if(!T)return f.jsxs(ul,{vault:z,projectsNav:f.jsx(aw,{projects:m,onNew:()=>w(!0)}),orgBar:U,topbar:f.jsx(dl,{}),children:[f.jsx(Su,{children:f.jsx(tI,{onNew:()=>w(!0),canCreate:_})}),R]});const $=l?.kind==="hub"?{crumb:"Signup & access",body:f.jsx($$,{})}:null,F=b.org?p.find(ge=>ge.id===b.org):null,ye=b.org&&!F?{crumb:"Organization",body:f.jsxs("div",{className:"empty",children:[f.jsx("h3",{children:"Organization not found"}),f.jsx("p",{children:"This organization doesn't exist, or you're no longer a member."}),f.jsx("p",{children:f.jsxs("a",{...Bs("/"+T.id),children:["Back to ",T.name]})})]})}:F?{crumb:"Organization",body:f.jsx(z$,{org:F,projects:m,myEmail:e.me?.email||""})}:null,me=!!b.project&&!m.some(ge=>ge.id===b.project),de=me?{crumb:"Project",body:f.jsxs("div",{className:"empty",children:[f.jsx("h3",{children:"Project not found"}),f.jsx("p",{children:"This project doesn't exist, or you're no longer a member."}),f.jsx("p",{children:f.jsxs("a",{...Bs("/"+T.id),children:["Back to ",T.name]})})]})}:null,le=b.billing?{crumb:"Billing",body:e.billing?f.jsx(K$,{url:e.billing.url}):f.jsxs("div",{className:"empty",children:[f.jsx("h3",{children:"No billing on this hub"}),f.jsx("p",{children:"This BearDrive hub doesn't have a billing surface."})]})}:null,te=b.view==="settings"?{crumb:"Project settings",body:f.jsx(X$,{project:T,org:N,onDeleted:async()=>{await r(),Kt("/")}})}:b.view==="install"?{crumb:"Installation",body:f.jsx(HC,{project:T,existing:b.connect==="existing"})}:null;if(!me){if(!b.org&&!b.billing&&b.project!==T.id)return f.jsx(Qo,{to:"/"+T.id});if(b.legacyView&&b.view)return f.jsx(Qo,{to:Pn(b.view,T.id,b.viewTarget,b.filters)});if(b.queryTarget&&b.view)return f.jsx(Qo,{to:Pn(b.view,T.id,b.viewTarget,b.filters)});if(b.trailingSlash&&b.path)return f.jsx(Qo,{to:fl(b.path,T.id,b.version)})}return f.jsxs(f.Fragment,{children:[f.jsx(sE,{config:e,apiBase:"/api/p/"+T.id+"/",route:b,hub:!0,project:T,projects:m,sidebar:{vault:z,projectsNav:f.jsx(aw,{projects:m,currentId:T.id,onNew:()=>w(!0),menu:{active:l?null:b.view==="dashboard"&&!b.viewTarget?"dashboard":b.view==="install"?"install":b.view==="history"&&!b.viewTarget?"history":b.view==="settings"?"settings":null,onDashboard:()=>{u(null),Kt(Pn("dashboard",T.id)),mr()},onInstall:()=>{u(null),Kt(Pn("install",T.id)),mr()},onHistory:()=>{u(null),Kt(Pn("history",T.id)),mr()},onSettings:()=>{u(null),Kt(Pn("settings",T.id)),mr()}}}),orgBar:U},panel:$||ye||de||le||te,onClosePanel:()=>u(null)},T.id),R]})}function sF({token:e,onDone:n}){return S.useEffect(()=>{let r=!1;return _i("/api/invites/"+e).then(i=>{r||(Ke(`Welcome — you joined the “${i.org.name}” team. Opening its projects…`),n(i.org.id))}).catch(i=>{r||String(i.message).includes("signing in")||(Ke("Could not accept the invite: "+i.message,!0),n(null))}),()=>{r=!0}},[e]),f.jsx(ul,{vault:f.jsx(Xu,{name:"BearDrive",beta:!0}),topbar:f.jsx(dl,{}),children:f.jsx(Su,{children:f.jsx("div",{className:"empty",children:"Joining…"})})})}function oF({config:e}){const n=Yp(),r=e.volume||"BearDrive";S.useEffect(()=>{document.title=e.brand||r},[e,r]);const i=S.useMemo(()=>D_(n,"volume"),[n]);return i.trailingSlash&&i.path?f.jsx(Qo,{to:fl(i.path)}):f.jsx(sE,{config:e,apiBase:"/api/",route:i,hub:!1,sidebar:{vault:f.jsx(Xu,{name:r,showSignout:e.auth.enabled,search:!0})}})}function lF(){const{data:e}=bj();return f.jsxs(PD,{delayDuration:150,children:[e?e.mode==="hub"?f.jsx(iF,{config:e}):f.jsx(oF,{config:e}):f.jsx(ul,{vault:f.jsx(Xu,{name:"…",showSignout:!1}),topbar:f.jsx(dl,{}),children:f.jsx("div",{className:"empty",children:"Loading…"})}),f.jsx(b3,{}),f.jsx(C3,{})]})}class cF extends S.Component{state={error:null};static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,r){console.error("BearDrive: unhandled render error",n,r.componentStack)}render(){return this.state.error?f.jsxs("div",{className:"mx-auto max-w-lg p-8 text-sm",children:[f.jsx("h1",{className:"mb-2 text-lg font-semibold",children:"This page didn’t load"}),f.jsx("p",{className:"mb-4 opacity-80",children:"Something went wrong rendering this view. The rest of BearDrive is fine."}),f.jsx("p",{className:"mb-4",children:f.jsx("a",{className:"underline",href:"/",children:"Go to the project list"})}),f.jsx("pre",{className:"overflow-x-auto rounded bg-black/5 p-3 text-xs dark:bg-white/10",children:String(this.state.error)})]}):this.props.children}}const uF=new nj({defaultOptions:{queries:{retry:1,refetchOnWindowFocus:!1}}});O2.createRoot(document.getElementById("root")).render(f.jsx(S.StrictMode,{children:f.jsx(cF,{children:f.jsx(rj,{client:uF,children:f.jsx(lF,{})})})}));
diff --git a/internal/webapp/static/index.html b/internal/webapp/static/index.html
index f5b3653..cd82f22 100644
--- a/internal/webapp/static/index.html
+++ b/internal/webapp/static/index.html
@@ -5,7 +5,7 @@
BearDrive
-
+