@shllg/emend 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffPane-CnM0c-g-.js","assets/rolldown-runtime-XKyaHtl9.js","assets/jsx-runtime-BwolrYx8.js","assets/diff-counts-aavca3cx.js","assets/diff-counts-CdprTo7g.css","assets/preload-helper-BLdHbfdN.js","assets/hastToHtml-ptNQFKyE.js","assets/unwrapDefault-ByDmBtHB.js","assets/lib-6HYXi0_j.js"])))=>i.map(i=>d[i]);
2
+ import{r as e,t}from"./rolldown-runtime-XKyaHtl9.js";import{n,r,t as i}from"./jsx-runtime-BwolrYx8.js";import{$ as a,$t as o,A as s,An as c,At as l,B as u,Bn as d,Bt as f,Cn as p,Ct as m,D as h,Dn as g,Dt as _,E as v,En as y,Et as b,F as x,Fn as S,Ft as C,G as w,Gn as T,Gt as E,H as D,Hn as O,Ht as k,I as ee,In as A,It as j,J as M,Jn as N,Jt as P,K as F,Kn as I,Kt as L,L as R,Ln as z,Lt as te,M as ne,Mn as B,Mt as re,N as ie,Nn as V,Nt as H,O as U,On as W,Ot as G,P as ae,Pn as K,Pt as oe,Q as se,Qn as ce,Qt as le,R as ue,Rn as de,Rt as fe,S as pe,Sn as me,St as he,T as ge,Tt as _e,U as q,Un as ve,Ut as ye,V as be,Vn as xe,W as Se,Wn as Ce,Wt as J,X as we,Xn as Te,Xt as Ee,Y as De,Yn as Oe,Yt as ke,Z as Ae,Zn as je,Zt as Me,_ as Ne,_n as Pe,_t as Y,a as Fe,an as Ie,at as Le,b as Re,bn as ze,bt as Be,c as Ve,cn as He,ct as Ue,d as We,dn as Ge,dt as Ke,en as qe,et as Je,f as Ye,fn as Xe,ft as Ze,gn as Qe,gt as $e,hn as et,ht as tt,i as nt,in as rt,it,j as at,jn as ot,k as st,kn as ct,kt as lt,l as ut,ln as dt,lt as ft,m as pt,mn as mt,mt as ht,nn as gt,nt as _t,o as vt,on as X,ot as yt,pn as bt,pt as xt,q as St,qn as Ct,qt as wt,r as Tt,rn as Et,rt as Dt,s as Ot,sn as Z,st as kt,t as At,tn as jt,tt as Mt,u as Nt,un as Pt,ut as Ft,v as It,vn as Lt,vt as Rt,w as zt,wn as Bt,wt as Vt,x as Ht,xn as Ut,y as Wt,yn as Gt,yt as Kt,zn as qt,zt as Jt}from"./diff-counts-aavca3cx.js";import{a as Yt,i as Xt,n as Zt,o as Qt,r as $t}from"./pairing-secret-YzFjEOKw.js";import{t as en}from"./preload-helper-BLdHbfdN.js";var tn=class extends A{#e;#t;#n;constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}build(e,t,n){let r=new ot({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=nn(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=nn(e);if(typeof t==`string`){let n=this.#t.get(t);if(n){if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=nn(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}return!0}runNext(e){let t=nn(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){K.batch(()=>{let e=this.getAll();this.#e.clear(),this.#t.clear(),e.forEach(e=>{this.notify({type:`removed`,mutation:e})})})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>d(t,e))}findAll(e={}){return this.getAll().filter(t=>d(e,t))}notify(e){K.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return K.batch(()=>Promise.all(e.map(e=>e.continue().catch(O))))}};function nn(e){return e.options.scope?.id}var rn=class extends A{#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){let r=t.queryKey,i=t.queryHash??qt(r,t),a=this.get(i);return a||(a=new B({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){this.#e.get(e.queryHash)===e&&(e.destroy(),this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){K.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>xe(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>xe(e,t)):t}notify(e){K.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){K.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){K.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},an=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new rn,this.#t=e.mutationCache||new tn,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=S.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=V.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(Ce(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=z(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return K.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;K.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return K.batch(()=>{let r=n.findAll(e),i=new Set(r);return r.forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,predicate:e=>i.has(e)},t)})}cancelQueries(e,t={}){let n={revert:!0,...t},r=K.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(O).catch(O)}invalidateQueries(e,t={}){return K.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=K.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(O)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(O)}async query(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t),r=n.isStaleByTime(Ce(t.staleTime,n))?await n.fetch(t):n.state.data,i=t.select;return i?i(r):r}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(Ce(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(O).catch(O)}infiniteQuery(e){return e._type=`infinite`,this.query(e)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(O).catch(O)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return V.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(de(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{ve(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(de(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{ve(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=qt(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===T&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}};function on(e){return e}var Q=e(r(),1),sn=Q.useLayoutEffect;function cn(e){return e[e.length-1]}function ln(e,t){return typeof e==`function`?e(t):e}var un=Object.prototype.hasOwnProperty;function dn(e){for(let t in e)if(un.call(e,t))return!0;return!1}var fn=()=>Object.create(null),pn=(e,t)=>mn(e,t,!0);function mn(e,t,n,r=0){if(e===t)return e;if(r++>500)return t;let i=Array.isArray(e)&&Array.isArray(t);if(!i&&!(hn(e)&&hn(t)))return t;let a=Object.keys(e),o=a.length,s=Object.keys(t),c=s.length;if(i?o!==e.length||c!==t.length||o&&cn(a)!==`${o-1}`||c&&cn(s)!==`${c-1}`:o!==Object.getOwnPropertyNames(e).length||c!==Object.getOwnPropertyNames(t).length||Object.getOwnPropertySymbols(t).length)return t;let l=0,u,d,f;if(i){for(;l<c&&(f=l,d=e[f],u=t[f],u=d===u?d:typeof d==`object`?mn(d,u,n,r):u,u===d);l++);if(l===c&&o===c)return e}else{let i=o===c,p=!0;for(;l<c;l++){f=s[l],d=e[f];let o=t[f];u=d===o?d:typeof d==`object`?mn(d,o,n,r):o,i&&=u===d&&(a[l]===f||un.call(e,f)),p&&=Object.is(u,o),a[l]=u}if(i)return Object.getOwnPropertySymbols(e).length?t:e;if(p)return t}let p=i?s.fill(0):n?fn():{};for(let o=0;o<c;o++)f=i?o:s[o],i?(d=e[f],o>l&&(u=t[f],u=d===u?d:typeof d==`object`?mn(d,u,n,r):u),p[f]=o<l?d:u):p[f]=a[o];return p}function hn(e){return!e||typeof e!=`object`?!1:(Object.getPrototypeOf(e)?.constructor??Object)===Object}function gn(e,t,n,r){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0,a=e.length;i<a;i++){let a=e[i],o=t[i];if(a!==o&&!gn(a,o,n,r))return!1}return!0}if(hn(e)&&hn(t)){if(n){for(let i in t)if((r||t[i]!==void 0)&&!gn(e[i],t[i],n,r))return!1;return!0}let i=0;if(r)i=Object.keys(e).length;else for(let t in e)e[t]!==void 0&&i++;for(let a in t)if((r||t[a]!==void 0)&&(i--===0||!gn(e[a],t[a],n,r)))return!1;return i===0}return!1}var _n=/[\x00-\x1f\x7f"<>`{}]/g;function vn(e){return e.replace(_n,e=>`%`+e.charCodeAt(0).toString(16).toUpperCase().padStart(2,`0`))}function yn(e){let t;try{t=decodeURI(e)}catch{t=e.replaceAll(/%[0-9A-F]{2}/gi,e=>{try{return decodeURI(e)}catch{return e}})}return vn(t)}var bn=[`http:`,`https:`,`mailto:`,`tel:`];function xn(e){if(e[0]!==`/`&&e.includes(`:`))return/^[\x00-\x20]*([a-z][a-z\d+.\t\n\r-]*:)/i.exec(e)?.[1]?.replace(/[\t\n\r]/g,``).toLowerCase()}var Sn=/^[\x00-\x20]*[\\/][\t\n\r]*[\\/]/;function Cn(e,t){if(!e)return!1;if(Sn.test(e))return!0;let n=xn(e);return n?!t.has(n):!1}function wn(e){if(!e)return e;let t=e;if(/[%\\\x00-\x1f\x7f]/.test(e)){let n=/%25|%5C/gi,r=0,i;for(t=``;(i=n.exec(e))!==null;)t+=yn(e.slice(r,i.index))+i[0],r=n.lastIndex;t+=yn(r?e.slice(r):e)}return t}function Tn(e){return/[\s\u0080-\uFFFF]/.test(e)?e.replace(/\s|[^\u0000-\u007F]/gu,encodeURIComponent):e}function En(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Dn(){throw Error(`Invariant failed`)}function On(e){return e.replace(/\/{2,}/g,`/`)}function kn(e){return e===`/`?e:e.replace(/^\/+/,``)}function An(e){let t=e.length;return t>1&&e[t-1]===`/`?e.replace(/\/+$/,``):e}function jn(e){return An(kn(e))}function Mn(e,t){return e?.endsWith(`/`)&&e!==`/`&&e!==`${t}/`?e.slice(0,-1):e}function Nn(e,t,n=`never`,r){if(t.includes(`//`)&&(t=On(t)),t.startsWith(`/`))return t.length===1||n===`preserve`?t:n===`always`?t.endsWith(`/`)?t:`${t}/`:t.endsWith(`/`)?t.slice(0,-1):t;let i=t===`.`,a;if(r){a=i?e:e+`\0`+t;let n=r.get(a);if(n)return n}let o;if(i)o=e.split(`/`);else{for(e.includes(`//`)&&(e=On(e)),o=e.split(`/`);o.length>1&&cn(o)===``;)o.pop();let n=t.split(`/`);for(let e=0,t=n.length;e<t;e++){let r=n[e];r===``?e?e===t-1&&o.push(r):o=[r]:r===`..`?o.length>1?o.pop():o=[``]:r===`.`||o.push(r)}}o.length>1&&(cn(o)===``?n===`never`&&o.pop():n===`always`&&o.push(``));let s=o.join(`/`),c=(i?On(s):s)||`/`;return a&&r&&r.set(a,c),c}function Pn(e){let t=new Map(e.map(e=>[encodeURIComponent(e),e])),n=new RegExp([...t.keys()].join(`|`).replace(/[.*()]/g,`\\$&`),`g`);return e=>e.replace(n,e=>t.get(e)??e)}function Fn(e){return e==null||e===``}function In(e,t,n){if(typeof t!=`string`)return``+(t??void 0);let r=e===`_splat`;if(r&&(!t||/^[a-zA-Z0-9\-._~!/]*$/.test(t)))return t;let i=encodeURIComponent(t);return r&&(i=i.replaceAll(`%2F`,`/`)),n?n(i):i}function Ln(e,t,n,r,i){let a=e.endsWith(`/`)?`/`:``,o=``;for(let e of t){if(typeof e==`string`){o+=e;continue}let[t,s,c,l]=e,u=t===2,d=u&&l!==void 0?l+a:l,f=n[s];if(t!==3||f!=null){if(i&&(i[s]=f,u&&(i[`*`]=f)),u&&Fn(f)){if(c===`/`&&!d)continue;f=``}o+=c+In(s,f,r)+(d||``)}}return o+a||`/`}function Rn(e){return e?.isNotFound===!0}function zn(){try{return sessionStorage}catch{return}}var Bn=`tsr-scroll-restoration-v1_3`,Vn=zn();function Hn(){try{return JSON.parse(Vn?.getItem(`tsr-scroll-restoration-v1_3`)||`{}`)}catch{return{}}}var Un=Hn(),Wn=`data-scroll-restoration-id`,Gn=e=>e.state.__TSR_key||e.href;function Kn(e){let t=e.getAttribute(Wn);if(t)return`[${Wn}="${t}"]`;let n=``,r=e,i;for(;i=r.parentNode;){let e=1,t=r;for(;t=t.previousElementSibling;)e++;let a=`${r.localName}:nth-child(${e})`;n=n?`${a} > ${n}`:a,r=i}return n}var qn=!1,Jn=`window`;function Yn(e){try{return typeof e==`function`?e():document.querySelector(e)}catch{}}function Xn(e){let t=new Set;for(let n of e){if(n===Jn)continue;let e=Yn(n);e&&t.add(e)}return t}function Zn(e,t){let n=t??e.options.scrollRestoration,r=e._scroll;n&&(r.e=!0);let i=e.options.getScrollRestorationKey||Gn,a=new Set,o=e=>{let t=Un[e]||={};for(let e of a)e===document?t[Jn]={scrollX,scrollY}:e.isConnected&&(t[Kn(e)]={scrollX:e.scrollLeft,scrollY:e.scrollTop})};n&&!r.s&&(r.s=!0,qn=!1,history.scrollRestoration=`manual`,document.addEventListener(`scroll`,e=>{qn||a.add(e.target)},!0),e.subscribe(`onBeforeLoad`,e=>{e.fromLocation&&o(i(e.fromLocation)),a.clear()}),addEventListener(`pagehide`,()=>{history.scrollRestoration=`auto`,o(i(e.stores.resolvedLocation.get()??e.stores.location.get()));try{Vn?.setItem(Bn,JSON.stringify(Un))}catch{}}),addEventListener(`pageshow`,e=>{e.persisted&&(history.scrollRestoration=`manual`)})),!r.r&&(r.r=!0,e.subscribe(`onRendered`,t=>{let n=e.options.scrollRestorationBehavior,o=e.options.scrollToTopSelectors,s=r.n,c=r.h,l;if(a.clear(),r.n=!0,r.h=!1,typeof e.options.scrollRestoration==`function`&&!e.options.scrollRestoration({location:e.latestLocation}))return;let u=i(t.toLocation),d=t.fromLocation&&i(t.fromLocation);if(r.e&&d&&d!==u){let e=Un[d];if(e){let t=Un[u];for(let n in e){if(n===Jn){if(s)continue}else{let e=Yn(n);if(!e||s&&o&&(l??=Xn(o),l.has(e)))continue}t||=Un[u]={},t[n]??=e[n]}}}qn=!0;try{let e=t.toLocation.hash,i=t.toLocation.state.__hashScrollIntoViewOptions??!0,a=!1;if(s){!e&&o&&(l??=Xn(o));let t=e&&i&&c,s=r.e?Un[u]:void 0;if(s)for(let e in s){let{scrollX:r,scrollY:i}=s[e];if(e===Jn){if(t)continue;scrollTo({top:i,left:r,behavior:n}),a=!0}else{let t=Yn(e);t&&(t.scrollLeft=r,t.scrollTop=i,l?.delete(t))}}if(!e){let e={top:0,left:0,behavior:n};if(a||scrollTo(e),l)for(let t of l)t.scrollTo(e)}}!a&&e&&i&&document.getElementById(e)?.scrollIntoView(i)}finally{qn=!1}}))}function Qn(e,t=String){let n;for(let r in e){let i=e[r];i!==void 0&&(n||=new URLSearchParams).set(r,t(i))}return n?n.toString():``}function $n(e){return e?e===`false`?!1:e===`true`?!0:e*0==0&&+e+``===e?+e:e:``}function er(e){let t=new URLSearchParams(e),n=Object.create(null);for(let[e,r]of t.entries()){let t=n[e];t==null?n[e]=$n(r):Array.isArray(t)?t.push($n(r)):n[e]=[t,$n(r)]}return n}var tr=/^(?:\s|["[{\d-]|fa|nu|tr)/,nr=ir(JSON.parse),rr=ar(JSON.stringify,JSON.parse);function ir(e){let t=e===JSON.parse;return n=>{n[0]===`?`&&(n=n.slice(1));let r=er(n);for(let n in r){let i=r[n];if(typeof i==`string`){if(t&&!tr.test(i))continue;try{r[n]=e(i)}catch{}}}return r}}function ar(e,t){let n=t===JSON.parse;function r(r){if(r&&typeof r==`object`)try{return e(r)}catch{}else if(t&&typeof r==`string`){if(n&&!tr.test(r))return r;try{return t(r),e(r)}catch{}}return r}return e=>{let t=Qn(e,r);return t?`?${t}`:``}}var or=`__root__`;function sr(e){e.statusCode=e.statusCode||e.code||307;let t=new Headers(e.headers);e.href&&t.get(`Location`)===null&&t.set(`Location`,e.href);let n=new Response(null,{status:e.statusCode,headers:t});if(n.options=e,e.throw)throw n;return n}function cr(e){return e instanceof Response&&!!e.options}function lr(e){let t=new Map,n,r;return{get(e){let n=t.get(e);if(n)return n.visited=!0,n.value},set(i,a){let o=t.get(i);if(o){o.value=a;return}if(t.size>=e){let e=n?.next().value;for(;!e||e.visited;)e?e.visited=!1:n=t.values(),e=n.next().value;e===r&&(n=void 0),t.delete(e.key)}let s={key:i,value:a,visited:!1};r=s,t.set(i,s)},clear(){t.clear(),n=void 0,r=void 0}}}var ur=4,dr=5;function fr(e){let t=e.names;if(t)return t;let n=[];for(let t of e)typeof t!=`string`&&n.push(t[1]);return e.names=n}function pr(e,t,n){let r=e.slice(t,n);if(r.charCodeAt(0)===36)return r.length===1?[2,`_splat`,``,void 0]:[1,r.slice(1),``,``];let i=r.indexOf(`{`);if(i>=0){let a=r.indexOf(`}`,i),o=r.charCodeAt(i+1)===45,s=i+(o?3:2);if(a>=0&&r.charCodeAt(s-1)===36&&(!o||s<a)){let c=r.slice(s,a);return[o?3:c?1:2,c||`_splat`,r.slice(0,i),e.slice(t+a+1,c?n:e.length)]}}return r}function mr(e,t,n,r,i,a){let o=n,s=t.fullPath??t.from,c=t.options,l=s.length,u=s.endsWith(`/`)?l-1:l,d=c?.caseSensitive??e,f=c?.params?.parse??c?.parseParams,p,m=a?n-1:0;if(!r||s.includes(`$`)){p=a?.slice()??[];let e=cn(p);e&&typeof e!=`string`&&e[0]===2&&(p[p.length-1]=[e[0],e[1],e[2],e[3]===void 0?void 0:e[3]+s.substring(n-(s[n-2]===`/`?2:1),u)],m=l)}for(;o<l;){let e=o,t=s.indexOf(`/`,e),n=t===-1?l:t,a=pr(s,e,n);o=n+1;let c;if(typeof a==`string`){if(!r)continue;let e=a,t;d?t=r.static??=new Map:(e=a.toLowerCase(),t=r.staticInsensitive??=new Map);let n=t.get(e);if(n)c=n;else{let n=gr(r);c=n,t.set(e,n)}}else{let t=a[0],h=a[2],g=a[3]??``;if(t===2&&(n=l,o=n+1),p&&m<n&&(m<e-1&&p.push(s.slice(m,e-1)),a[2]=`/`+h,t===2&&a[3]!==void 0&&u<l&&(a[3]=g.slice(0,-1)),p.push(a),m=n),!r)continue;let _=d&&!!(h||g);d||(h=h.toLowerCase(),g=g.toLowerCase());let v=t===1?r.dynamic??=[]:t===3?r.optional??=[]:r.wildcard??=[],y=t!==2&&!f&&v.find(e=>!e.parse&&e.caseSensitive===_&&e.prefix===h&&e.suffix===g);if(y)c=y;else{let e=gr(r,t,_,h,g);c=e,v.push(e),v.length===2&&i?.push(v)}}r=c}p&&m<u&&p.push(s.slice(m,u));let h=p?.slice();if(!r)return h;if(f&&t.children&&!t.isRoot&&t.id&&t.id.charCodeAt(t.id.lastIndexOf(`/`)+1)===95){let e=gr(r,dr);(r.pathless??=[]).push(e),r=e}let g=(t.path||!t.children)&&!t.isRoot;if(g&&u<l){let e=gr(r,ur);r.index=e,r=e}return r.parse=f??null,r.priority=c?.params?.priority??0,r.route||(r.data=h,g&&(r.route=t)),[r,o,h]}function hr(e,t){if(e.parse&&!t.parse)return-1;if(!e.parse&&t.parse)return 1;if(e.parse&&t.parse&&(e.priority||t.priority))return t.priority-e.priority;if(e.prefix&&t.prefix&&e.prefix!==t.prefix){if(e.prefix.startsWith(t.prefix))return-1;if(t.prefix.startsWith(e.prefix))return 1}if(e.suffix&&t.suffix&&e.suffix!==t.suffix){if(e.suffix.endsWith(t.suffix))return-1;if(t.suffix.endsWith(e.suffix))return 1}return e.prefix&&!t.prefix?-1:!e.prefix&&t.prefix?1:e.suffix&&!t.suffix?-1:!e.suffix&&t.suffix?1:e.caseSensitive&&!t.caseSensitive?-1:!e.caseSensitive&&t.caseSensitive?1:0}function gr(e,t=0,n,r,i){return{kind:t,depth:e?e.depth+1:0,pathless:null,index:null,static:null,staticInsensitive:null,dynamic:null,optional:null,wildcard:null,route:null,data:void 0,parent:e,parse:null,priority:0,caseSensitive:n,prefix:r,suffix:i}}function _r(e,t){let n=gr(),r=[];function i(e,t,n,a){let[o,s,c]=mr(!1,e,t,n,r,a);if(e.children)for(let t of e.children)i(t,s,o,c)}for(let t of e)i(t,1,n);for(let e of r)e.sort(hr);t.masksTree=n,t.flatCache=lr(1e3)}function vr(e,t){e||=`/`;let n=t.flatCache.get(e);if(n!==void 0)return n;let r=Sr(e,t.masksTree);return t.flatCache.set(e,r),r}function yr(e,t,n,r,i){e||=`/`,r||=`/`;let a=t?`case\0${e}`:e,o=i.singleCache.get(a);return o||(o=gr(),mr(t,{from:e},1,o),i.singleCache.set(a,o)),Sr(r,o,n)}function br(e,t,n=!1){let r=n?e:`nofuzz\0${e}`,i=t.matchCache.get(r);if(i!==void 0)return i;e||=`/`;let a;try{a=Sr(e,t.segmentTree,n)}catch(e){if(e instanceof URIError)a=null;else throw e}return a&&(a.branch=wr(a.route)),t.matchCache.set(r,a),a}function xr(e,t=!1){let n=gr(),r=[],i={},a={},o=0;function s(e,n,c,l){if(e.init(o),e.id in i&&Dn(),i[e.id]=e,o!==0&&e.path){let t=An(e.fullPath);(!a[t]||e.fullPath.endsWith(`/`))&&(a[t]=e)}o++;let[u,d,f]=mr(t,e,n,c,r,l);if(e._interpolation=f,e.children)for(let t of e.children)s(t,d,u,f)}s(e,1,n);for(let e of r)e.sort(hr);return{processedTree:{segmentTree:n,singleCache:lr(1e3),matchCache:lr(1e3),flatCache:null,masksTree:null},routesById:i,routesByPath:a}}function Sr(e,t,n=!1){let r=e.split(`/`),i=Er(e,r,t,n);if(!i)return null;let[a]=Cr(e,r,i);return{route:i.node.route,rawParams:a}}function Cr(e,t,n){let r=Tr(n.node),i=n.node.data&&fr(n.node.data),a=Object.create(null),o=n.extract?.part??0,s=n.extract?.node??0,c=n.extract?.path??0,l=n.extract?.param??0;for(;s<r.length;o++,s++,c++){let u=r[s];if(u.kind===ur)break;if(u.kind===dr){o--,c--;continue}let d=t[o],f=c;if(d&&(c+=d.length),u.kind===1||u.kind===3){let e=i[l++];if(u.kind===3&&n.skipped&1<<s){o--,c=f-1;continue}let t=u.suffix||u.prefix?d.substring(u.prefix.length,d.length-u.suffix.length):d;(t||u.kind===1)&&(a[e]=decodeURIComponent(t))}else if(u.kind===2){let t=u,n=e.substring(f+t.prefix.length,e.length-t.suffix.length),r=decodeURIComponent(n);a[`*`]=r,a._splat=r;break}}return n.rawParams&&Object.assign(a,n.rawParams),[a,{part:o,node:s,path:c,param:l}]}function wr(e){let t=[e];for(;e.parentRoute;)e=e.parentRoute,t.push(e);return t.reverse(),t}function Tr(e){let t=Array(e.depth+1);do t[e.depth]=e,e=e.parent;while(e);return t}function Er(e,t,n,r){if(e===`/`&&n.index)return{node:n.index,skipped:0};let i=!cn(t),a=i&&e!==`/`,o=t.length-+!!i,s=[{node:n,index:1,skipped:0,statics:0,dynamics:0,optionals:0}],c=null,l=null;for(;s.length;){let n=s.pop(),{node:i,index:u,skipped:d,statics:f,dynamics:p,optionals:m}=n,{extract:h,rawParams:g}=n;if(i.kind===2&&i.route&&!Ar(l,n))continue;if(i.parse){if(!kr(e,t,n))continue;g=n.rawParams,h=n.extract}r&&i.route&&i.kind!==ur&&Ar(c,n)&&(c=n);let _=u===o;if(_&&(i.route&&(!a||i.kind===ur||i.kind===2)&&Ar(l,n)&&(l=n),!i.optional&&!i.wildcard&&!i.index&&!i.pathless))continue;let v=_?void 0:t[u],y;if(_&&i.index){let n={node:i.index,index:u,skipped:d,statics:f,dynamics:p,optionals:m,extract:h,rawParams:g},r=!0;if(i.index.parse&&(kr(e,t,n)||(r=!1)),r){if(!p&&!m&&!d&&Or(f,o))return n;Ar(l,n)&&(l=n)}}if(i.wildcard)for(let e=i.wildcard.length-1;e>=0;e--){let n=i.wildcard[e],{prefix:r,suffix:a}=n;if(!r||!_&&(n.caseSensitive?v:y??=v.toLowerCase()).startsWith(r)){if(a){if(_)continue;let e=t.slice(u).join(`/`),i=e.slice(-a.length);if((n.caseSensitive?i:i.toLowerCase())!==a||e.length-a.length<r.length)continue}s.push({node:n,index:o,skipped:d,statics:f,dynamics:p,optionals:m,extract:h,rawParams:g})}}if(i.optional){let e=d|1<<i.depth+1;for(let t=i.optional.length-1;t>=0;t--){let n=i.optional[t];s.push({node:n,index:u,skipped:e,statics:f,dynamics:p,optionals:m,extract:h,rawParams:g})}if(!_)for(let e=i.optional.length-1;e>=0;e--){let t=i.optional[e],{prefix:n,suffix:r}=t;if(n||r){let e=t.caseSensitive?v:y??=v.toLowerCase();if(n&&!e.startsWith(n)||r&&e.indexOf(r,e.length-r.length)<n.length)continue}s.push({node:t,index:u+1,skipped:d,statics:f,dynamics:p,optionals:m+Dr(o,u),extract:h,rawParams:g})}}if(!_&&i.dynamic&&v)for(let e=i.dynamic.length-1;e>=0;e--){let t=i.dynamic[e],{prefix:n,suffix:r}=t;if(n||r){let e=t.caseSensitive?v:y??=v.toLowerCase();if(n&&!e.startsWith(n)||r&&e.indexOf(r,e.length-r.length)<n.length)continue}s.push({node:t,index:u+1,skipped:d,statics:f,dynamics:p+Dr(o,u),optionals:m,extract:h,rawParams:g})}if(!_&&i.staticInsensitive){let e=i.staticInsensitive.get(y??=v.toLowerCase());e&&s.push({node:e,index:u+1,skipped:d,statics:f+Dr(o,u),dynamics:p,optionals:m,extract:h,rawParams:g})}if(!_&&i.static){let e=i.static.get(v);e&&s.push({node:e,index:u+1,skipped:d,statics:f+Dr(o,u),dynamics:p,optionals:m,extract:h,rawParams:g})}if(i.pathless)for(let e=i.pathless.length-1;e>=0;e--){let t=i.pathless[e];s.push({node:t,index:u,skipped:d,statics:f,dynamics:p,optionals:m,extract:h,rawParams:g})}}if(l)return l;if(r&&c){let n=c.index;for(let e=0;e<c.index;e++)n+=t[e].length;let r=n===e.length?`/`:e.slice(n);return c.rawParams??=Object.create(null),c.rawParams[`**`]=decodeURIComponent(r),c}return null}function Dr(e,t){return 2**(e-t-1)}function Or(e,t){return e===2**(t-1)-1}function kr(e,t,n){let r,i;try{[r,i]=Cr(e,t,n)}catch{return null}if(n.rawParams=r,n.extract=i,!n.node.parse)return!0;try{if(n.node.parse(r)===!1)return null}catch{}return!0}function Ar(e,t){return!e||t.statics>e.statics||t.statics===e.statics&&(t.dynamics>e.dynamics||t.dynamics===e.dynamics&&(t.optionals>e.optionals||t.optionals===e.optionals&&((t.node.kind===ur)>(e.node.kind===ur)||t.node.kind===ur==(e.node.kind===ur)&&t.node.depth>e.node.depth)))}function jr(e,t,n){let r=jn(e),i=`/${r}`,a=t?i:i.toLowerCase(),o=`${a}/`,s={input:({url:e})=>{let n=t?e.pathname:e.pathname.toLowerCase();return n===a?e.pathname=`/`:n.startsWith(o)&&(e.pathname=e.pathname.slice(i.length)),e},output:({url:e})=>(e.pathname=On(`/${r}${e.pathname}`),e)};return n?{input:({url:e})=>Mr(n,s.input({url:e})),output:({url:e})=>s.output({url:Nr(n,e)})}:s}function Mr(e,t){let n=e?.input?.({url:t});if(n){if(typeof n==`string`)return new URL(n);if(n instanceof URL)return n}return t}function Nr(e,t){let n=e?.output?.({url:t});if(n){if(typeof n==`string`)return new URL(n);if(n instanceof URL)return n}return t}function Pr(e,t){let{createMutableStore:n,createReadonlyStore:r,batch:i}=t,a=new Map,o=n(`idle`),s=n(e),c=n(void 0),l=n([]),u=r(()=>l.get().map(e=>a.get(e).get())),d=r(()=>({status:o.get(),isLoading:o.get()===`pending`,matches:u.get(),location:s.get(),resolvedLocation:c.get()}));function f(e){let t=a.get(e);return t||(t=n(void 0),a.set(e,t)),t}let p={status:o,location:s,resolvedLocation:c,ids:l,matches:u,byRoute:a,__store:d,getMatchStore:f,setMatches:m};function m(e){let t=l.get(),n=e.map(e=>e.routeId);i(()=>{En(t,n)||l.set(n);for(let e of t)n.includes(e)||a.get(e).set(()=>void 0);for(let t of e){let e=f(t.routeId);e.get()!==t&&e.set(t)}})}return p}var Fr=`__TSR_index`,Ir=`popstate`,Lr=`beforeunload`,Rr=/^[\x00-\x20]*(?:[\\/][\t\n\r]*){2,}/;function zr(e){let t=Rr.exec(e);return t?`/`+e.slice(t[0].length):e}function Br(e){return/[\x00-\x1f\x7f]/.test(e)&&(e=e.replace(/[\x00-\x1f\x7f]/g,e=>`
3
+ \r`.includes(e)?``:encodeURIComponent(e))),zr(e)}function Vr(e){let t=e.getLocation(),n=new Set,r=r=>{t=e.getLocation(),n.forEach(e=>e({location:t,action:r}))},i=n=>{e.notifyOnIndexChange??!0?r(n):t=e.getLocation()},a=async n=>{let r=n.navigateOpts?.ignoreBlocker?void 0:e.getBlockers?.();if(typeof document<`u`&&r?.length&&(n.type===`PUSH`||n.type===`REPLACE`))for(let i of r){let r=Wr(n.path,n.state);if(await i.blockerFn({currentLocation:t,nextLocation:r,action:n.type})){e.onBlocked?.();return}}n.task()};return{get location(){return t},get length(){return e.getLength()},subscribers:n,subscribe:e=>(n.add(e),()=>{n.delete(e)}),push:(n,i,o)=>{let s=t.state[Fr];i=Hr(s+1,i),a({task:()=>{e.pushState(n,i),r({type:`PUSH`})},navigateOpts:o,type:`PUSH`,path:n,state:i})},replace:(n,i,o)=>{let s=t.state[Fr];i=Hr(s,i),a({task:()=>{e.replaceState(n,i),r({type:`REPLACE`})},navigateOpts:o,type:`REPLACE`,path:n,state:i})},go:(t,n)=>{a({task:()=>{e.go(t,n?.ignoreBlocker??!1),i({type:`GO`,index:t})},navigateOpts:n,type:`GO`})},back:t=>{a({task:()=>{e.back(t?.ignoreBlocker??!1),i({type:`BACK`})},navigateOpts:t,type:`BACK`})},forward:t=>{a({task:()=>{e.forward(t?.ignoreBlocker??!1),i({type:`FORWARD`})},navigateOpts:t,type:`FORWARD`})},canGoBack:()=>t.state[Fr]!==0,createHref:t=>e.createHref(t),block:t=>{if(!e.setBlockers)return()=>{};let n=e.getBlockers?.()??[];return e.setBlockers([...n,t]),()=>{let n=e.getBlockers?.()??[];e.setBlockers?.(n.filter(e=>e!==t))}},flush:()=>e.flush?.(),destroy:()=>e.destroy?.(),notify:r,_getBlockers:()=>e.getBlockers?.()??[]}}function Hr(e,t){let n=Gr();return{...t,key:n,__TSR_key:n,[Fr]:e}}function Ur(e){let t=e?.window??(typeof document<`u`?window:void 0),n=t.history.pushState,r=t.history.replaceState,i=[],a=()=>i,o=e=>i=e,s=t=>Br(e?.createHref?e.createHref(t):t),c=e?.parseLocation??(()=>Wr(`${t.location.pathname}${t.location.search}${t.location.hash}`,t.history.state));if(!t.history.state?.__TSR_key&&!t.history.state?.key){let e=Gr();t.history.replaceState({[Fr]:0,key:e,__TSR_key:e},``)}let l=c(),u,d=!1,f=!1,p=!1,m=!1,h=()=>l,g,_=()=>{g&&(S._ignoreSubscribers=!0,(g[2]?t.history.pushState:t.history.replaceState)(g[1],``,g[0]),S._ignoreSubscribers=!1,g=void 0,u=void 0)},v=(t,n,r)=>{let i=e?.createHref?s(n):void 0,a=!!g;a||(u=l),l=Wr(n,r),g=[i??l.href,r,g?.[2]||t],a||queueMicrotask(()=>_())},y=e=>{l=c(),S.notify({type:e})},b=async()=>{if(m=!1,f){f=!1;return}let e=c(),n=e.state[Fr]-l.state[Fr],r=n===1,i=n===-1,o=!r&&!i||d;d=!1;let s=o?`GO`:i?`BACK`:`FORWARD`,u=o?{type:`GO`,index:n}:{type:i?`BACK`:`FORWARD`};if(p)p=!1;else{let r=a();if(typeof document<`u`&&r.length){for(let i of r)if(await i.blockerFn({currentLocation:l,nextLocation:e,action:s})){f=!0,t.history.go(-n),S.notify(u);return}}}l=c(),S.notify(u)},x=e=>{if(m){m=!1;return}let t=!1,n=a();if(typeof document<`u`&&n.length)for(let e of n){let n=e.enableBeforeUnload??!0;if(n===!0||typeof n==`function`&&n()===!0){t=!0;break}}if(t)return e.preventDefault(),e.returnValue=``},S=Vr({getLocation:h,getLength:()=>t.history.length,pushState:(e,t)=>v(!0,e,t),replaceState:(e,t)=>v(!1,e,t),back:e=>(e&&(p=!0,m=!0),t.history.back()),forward:e=>{e&&(p=!0,m=!0),t.history.forward()},go:(e,n)=>{d=!0,n&&(p=!0,m=!0),t.history.go(e)},createHref:s,flush:_,destroy:()=>{t.history.pushState=n,t.history.replaceState=r,t.removeEventListener(Lr,x,{capture:!0}),t.removeEventListener(Ir,b)},onBlocked:()=>{u&&l!==u&&(l=u)},getBlockers:a,setBlockers:o,notifyOnIndexChange:!1});return S._ignoreNextBeforeUnload=e=>{m=!1;try{e=new URL(e,t.document.baseURI).href,m=/^https?:/.test(e)&&(!e.includes(`#`)||e.split(`#`)[0]!==t.location.href.split(`#`)[0])}catch{}},t.addEventListener(Lr,x,{capture:!0}),t.addEventListener(Ir,b),t.history.pushState=function(...e){let r=n.apply(t.history,e);return S._ignoreSubscribers||y(`PUSH`),r},t.history.replaceState=function(...e){let n=r.apply(t.history,e);return S._ignoreSubscribers||y(`REPLACE`),n},S}function Wr(e,t){let n=Br(e),r=n.indexOf(`#`),i=n.indexOf(`?`);if(!t){let e=Gr();t={[Fr]:0,key:e,__TSR_key:e}}return{href:n,pathname:n.slice(0,r>-1?i>-1?Math.min(r,i):r:i>-1?i:n.length),hash:r>-1?n.slice(r):``,search:i>-1?n.slice(i,r===-1?void 0:r):``,state:t}}function Gr(){return(Math.random()+1).toString(36).slice(7)}function Kr(e,t){return e.protocol!==`http:`&&e.protocol!==`https:`||e.origin!==t||!!e.username||!!e.password}function qr(e){return e.pathname+e.search+e.hash}function Jr(e){return e.options.loader||e.options.beforeLoad||e.lazyFn||e.options.component?.preload||e.options.pendingComponent?.preload}function Yr(e,t){return{fromLocation:t,toLocation:e,pathChanged:t?.pathname!==e.pathname,hrefChanged:t?.href!==e.href,hashChanged:t?.hash!==e.hash}}function Xr({key:e,__TSR_key:t,__TSR_index:n,__hashScrollIntoViewOptions:r,...i}){return i}function Zr(e){return e.findIndex(e=>e.status===`error`||e.status===`notFound`||e._notFound)+1}function Qr(e,t,n,r,i,a){r&&(t=t.slice(0,r)),i&&(n=n.slice(0,i));for(let r of t){if(a&&e._tx!==a)return;n.some(e=>e.routeId===r.routeId)||e.routesById[r.routeId].options.onLeave?.(r)}for(let r of n){if(a&&e._tx!==a)return;e.routesById[r.routeId].options[t.some(e=>e.routeId===r.routeId)?`onStay`:`onEnter`]?.(r)}}var $r=class{constructor(e,t){this.tempLocationKey=`${Math.round(Math.random()*1e7)}`,this._scroll={n:!0},this.subscribers=new Set,this._cache=new Map,this._committed=[],this.startTransition=async e=>(e(),!1),this.update=e=>{let t=this.options;this.options={...t,...e},this.isServer=this.options.isServer??!1??typeof document>`u`,this.staticLocations=new WeakMap,this.protocolAllowlist=new Set(this.options.protocolAllowlist),(!this.history||this.options.history&&this.options.history!==this.history)&&(this.history=this.options.history?this.options.history:Ur()),this.origin=this.options.origin,this.origin||=window?.origin&&window.origin!==`null`?window.origin:`http://localhost`;let n=this.options.basepath??`/`,r=this.options.rewrite,i=this.basepath!==n||t?.rewrite!==r||t?.caseSensitive!==this.options.caseSensitive;if(i&&(this.basepath=n,this.rewrite=n!==`/`&&jn(n)?jr(n,this.options.caseSensitive,r):r),this.history&&this.updateLatestLocation(),this.options.routeTree!==this.routeTree){this.routeTree=this.options.routeTree;let e;e=this.buildRouteTree(),this.setRoutes(e)}if(this.stores)i&&this.stores.location.set(this.latestLocation);else if(this.latestLocation){let e=this.getStoreConfig(this);this.batch=e.batch,this.stores=Pr(this.latestLocation,e),Zn(this)}},this.updateLatestLocation=()=>{this.latestLocation=this.parseLocation(this.history.location,this.latestLocation)},this.buildRouteTree=()=>{let e=xr(this.routeTree,this.options.caseSensitive);return this.options.routeMasks&&_r(this.options.routeMasks,e.processedTree),{...e,resolvePathCache:lr(1e3)}},this.subscribe=(e,t)=>{let n={eventType:e,fn:t};return this.subscribers.add(n),()=>{this.subscribers.delete(n)}},this.emit=e=>{for(let t of this.subscribers)if(t.eventType===e.type)try{t.fn(e)}catch(e){console.error(e)}},this.parseLocation=(e,t)=>{let n=({pathname:e,search:n,hash:r,href:i},a)=>{if(!this.rewrite&&!/[ \x00-\x1f\x7f\u0080-\uffff]/.test(e)){let i=this.options.parseSearch(n),o=this.options.stringifySearch(i);return{href:e+o+r,publicHref:e+o+r,pathname:wn(e),external:!1,searchStr:o,search:pn(t?.search,i),hash:wn(r.slice(1)),state:mn(t?.state,a)}}let o=Mr(this.rewrite,new URL(i,this.origin)),s=this.options.parseSearch(o.search),c=this.options.stringifySearch(s);return o.search=c,{href:o.href.replace(o.origin,``),publicHref:i,pathname:wn(zr(o.pathname)),external:!!this.rewrite&&Kr(o,this.origin),searchStr:c,search:pn(t?.search,s),hash:wn(o.hash.slice(1)),state:mn(t?.state,a)}},r=n(e,e.state),{__tempLocation:i,__tempKey:a}=r.state;if(i&&(!a||a===this.tempLocationKey)){let e=n(i,{...i.state,__tempLocation:void 0,key:r.state.key,__TSR_key:r.state.__TSR_key});return e.maskedLocation=r,e}return r},this.matchRoutes=(e,t,n)=>typeof e==`string`?this.matchRoutesInternal({pathname:e,search:t},n):this.matchRoutesInternal(e,t),this.getMatchedRoutes=e=>{let t=Object.create(null),n=br(An(e),this.processedTree,!0);return n&&Object.assign(t,n.rawParams),[n?.branch||[this.routesById.__root__],t,n?.route]},this.buildLocation=e=>{{let t=this.staticLocations.get(e);if(t)return t}let t=!1,n=(n={})=>{if(n.href){let e=Wr(n.href,{});n={...n,to:Mr(this.rewrite,new URL(e.pathname,this.origin)).pathname,search:this.options.parseSearch(e.search),hash:e.hash.slice(1)}}let r=e._fromLocation||this._pendingLocation||this.latestLocation,i,a=()=>(t=!0,r),o=()=>i??=this.matchRoutesLightweight(a()),s=n.to?`${n.to}`:`.`,c=Nn(s[0]===`/`?``:n.unsafeRelative===`path`?a().pathname:n.from??o()[1],s,this.options.trailingSlash,this.resolvePathCache),l=this.routesByPath[An(c)],u=c.includes(`$`),d;if(l)d=l._branch??=wr(l);else if(u)d=[];else{let[e,t,n]=this.getMatchedRoutes(c);d=e,this.options.notFoundRoute&&(!n||n.path!==`/`&&t[`**`])&&(d=[...d,this.options.notFoundRoute])}let f=u?l?._interpolation??mr(!1,{fullPath:c},0):void 0,p;for(let e of d){let t=e.options.params?.stringify??e.options.stringifyParams;if(t){let e=o()[3];if(p??=ii(n.params,e),!dn(p))break;p===e&&(p=Object.assign(fn(),p));try{Object.assign(p,t(p))}catch{}}}p??=ii(n.params,ai(n.params,f)?o()[3]:oi);let m=e.leaveParams?c:zr(wn(f?Ln(c,f,p,this.pathParamsDecoder):c)),h=si(d,e._includeValidateSearch),g=()=>{let t=o()[2];if(e._includeValidateSearch&&this.options.search?.strict){let e={};d.forEach(n=>{if(n.options.validateSearch)try{Object.assign(e,ri(n.options.validateSearch,{...e,...t}))}catch{}}),t=e}return t},_=h.length?ci(h,g(),n):n.search===!0?g():typeof n.search==`function`?n.search(g()):n.search||oi,v=this.options.stringifySearch(_),y=n.hash===!0?a().hash:typeof n.hash==`function`?n.hash(a().hash):n.hash||void 0,b=y?`#${y}`:``,x=n.state?n.state===!0?a().state:typeof n.state==`function`?n.state(a().state):n.state:oi,S=`${m}${v}${b}`,C,w,T=!1;if(this.rewrite){let e=new URL(S,this.origin),t=e.origin,n=Nr(this.rewrite,e);C=qr(e),Kr(n,t)?(w=n.href,T=!0):w=zr(qr(n))}else C=Tn(S),w=C;return{publicHref:w,href:C,pathname:m,search:_,searchStr:v,state:x,hash:y??``,external:T,unmaskOnReload:n.unmaskOnReload}},r=n(e);if(e.mask)r.maskedLocation=n({from:e.from,...e.mask});else if(this.options.routeMasks){let t=vr(r.pathname,this.processedTree);if(t){let i=Object.assign(fn(),t.rawParams),{from:a,params:o,...s}=t.route,c=ii(o,i);r.maskedLocation=n({from:e.from,...s,params:c})}}return!t&&e._fromLocation&&this.staticLocations.set(e,r),r},this.commitLocation=async({viewTransition:e,ignoreBlocker:t,...n})=>{let r=n.maskedLocation??n;if(r.external)return ei(this,r.publicHref,{replace:n.replace,ignoreBlocker:t});let i,a=An(this.latestLocation.href)===An(n.href)&&gn(Xr(n.state),Xr(this.latestLocation.state)),o=this._commitPromise,s,c=new Promise(e=>{s=e});if(c.resolve=()=>{s(),o?.resolve()},this._commitPromise=c,a)this.load();else{let{maskedLocation:r,hashScrollIntoView:a,...o}=n;r&&(o={...r,state:{...r.state,__tempKey:void 0,__tempLocation:{...o,search:o.searchStr,state:{...o.state,__tempKey:void 0,__tempLocation:void 0,__TSR_key:void 0,key:void 0}}}},(o.unmaskOnReload??this.options.unmaskOnReload??!1)&&(o.state.__tempKey=this.tempLocationKey)),o.state={...o.state,__hashScrollIntoViewOptions:a??this.options.defaultHashScrollIntoView??!0},this.shouldViewTransition=e,i=n.replace?`REPLACE`:`PUSH`,this.history[i===`REPLACE`?`replace`:`push`](o.publicHref,o.state,{ignoreBlocker:t}),this.history.subscribers.size||this.load({action:{type:i}})}return this._scroll.n=n.resetScroll??!0,this._commitPromise},this.buildAndCommitLocation=({replace:e,resetScroll:t,hashScrollIntoView:n,viewTransition:r,ignoreBlocker:i,...a}={})=>{let o=this.buildLocation({...a,_includeValidateSearch:!0});this._pendingLocation=o;let s=this.commitLocation({...o,viewTransition:r,replace:e,resetScroll:t,hashScrollIntoView:n,ignoreBlocker:i});return queueMicrotask(()=>{this._pendingLocation===o&&(this._pendingLocation=void 0)}),s},this.navigate=async({to:e,reloadDocument:t,href:n,publicHref:r,...i})=>{let a=n?xn(n):void 0;if(a||t){if(e!==void 0||!n){let t=this.buildLocation({to:e,...i}),a=t.maskedLocation??t;n??=a.publicHref,r??=a.publicHref}let t=!a&&r?r:n;return ei(this,t,i)}return this.buildAndCommitLocation({...i,href:n,to:e,_isNavigate:!0})},this.load=async e=>{this.updateLatestLocation(),e?.action&&(this._scroll.h=e.action.type===`PUSH`||e.action.type===`REPLACE`),await ta(this,e)},this.startViewTransition=e=>{let t=this.shouldViewTransition??this.options.defaultViewTransition;if(this.shouldViewTransition=void 0,t&&typeof document.startViewTransition==`function`){let n;if(typeof t==`object`&&window.CSS?.supports?.(`selector(:active-view-transition-type(a))`)){let r=this.latestLocation,i=this.stores.resolvedLocation.get(),a=typeof t.types==`function`?t.types(Yr(r,i)):t.types;if(a===!1)return e();n={update:e,types:a}}else n=e;return document.startViewTransition(n).updateCallbackDone}return e()},this.invalidate=e=>{let t=this._committed,n=e?.filter,r=this._preloads,i=new Set,a=e=>{(!n||n(e))&&i.add(e.id)};t.forEach(a),this._cache.forEach(a),r?.forEach(e=>e.forEach(a)),this._tx?.[3].forEach(a);let o=[];for(let[e,t]of r??[])t.some(e=>i.has(e.id))&&(r.delete(e),o.push(e));let s=t=>{if(i.has(t.id)){let n=this.routesById[t.routeId],r={...t,invalid:!0,...(e?.forcePending||t.status===`error`||t.status===`notFound`)&&Jr(n)?{status:`pending`,error:void 0}:void 0};return t._flight=void 0,r}return t};this._committed=t.map(s);for(let[t,n]of this._cache)i.has(t)&&(n.invalid=!0,e?.forcePending&&(n.status=`pending`));for(let e of i){let t=this._flights?.get(e);this._flights?.delete(e),t&&!t[2]&&o.push(t[1])}for(let e of o)e.abort();return this.shouldViewTransition=!1,this.load({sync:e?.sync})},this.resolveRedirect=e=>{let t=e.options,n=e.headers.get(`Location`)||t.href;if(!n){let e=this.buildLocation(t);n=(e.maskedLocation??e).publicHref||`/`}let r;if(Sn.test(n)||(r=xn(n))&&!this.protocolAllowlist.has(r))throw Error(`Redirect blocked: unsafe protocol`);if(r===`http:`||r===`https:`){let e=new URL(n);e.pathname.startsWith(`//`)?n=e.href:Kr(e,this.origin)||(n=qr(e),r=void 0)}return r&&(t.reloadDocument=!0),t.href=n,e.headers.set(`Location`,n),e},this.clearCache=e=>{let t=this._cache,n=this._preloads,r=e?.filter,i=[],a=[];for(let[e,n]of t)(!r||r(n))&&(a.push(e),i.push(n));let o=[];for(let[e,t]of n??[])(!r||t.some(r))&&(o.push(e),i.push(...t));for(let e of a)t.delete(e);for(let e of o)n.delete(e);for(let e of i){let t=e._flight;e._flight=void 0,t&&!--t[2]&&(this._flights?.get(e.id)===t&&this._flights.delete(e.id),o.push(t[1]))}for(let e of o)e.abort()},this.loadRouteChunk=pi,this.preloadRoute=e=>na(this,e),this.matchRoute=(e,t)=>{let n={...e,to:e.to?Nn(e.from||``,e.to,this.options.trailingSlash,this.resolvePathCache):void 0,params:e.params||{},leaveParams:!0},r=this.buildLocation(n),i=this.stores.status.get()===`pending`;if(t?.pending&&!i)return!1;let a=t?.pending??!i?this.latestLocation:this.stores.resolvedLocation.get()||this.stores.location.get(),o=yr(r.pathname,t?.caseSensitive??!1,t?.fuzzy??!1,a.pathname,this.processedTree);return!o||e.params&&!gn(o.rawParams,e.params,!0)?!1:t?.includeSearch??!0?gn(a.search,r.search,!0)?o.rawParams:!1:o.rawParams},this.getStoreConfig=t,e.pathParamsAllowedCharacters?.length&&(this.pathParamsDecoder=Pn(e.pathParamsAllowedCharacters)),this.update({defaultPreloadDelay:50,defaultPendingMs:1e3,defaultPendingMinMs:500,context:void 0,...e,caseSensitive:e.caseSensitive??!1,notFoundMode:e.notFoundMode??`fuzzy`,stringifySearch:e.stringifySearch??rr,parseSearch:e.parseSearch??nr,protocolAllowlist:e.protocolAllowlist??bn}),self.__TSR_ROUTER__=this}isShell(){return!!this.options.isShell}get state(){return this.stores.__store.get()}setRoutes(e){Object.assign(this,e),this.lightweightCache=new WeakMap,this.staticLocations=new WeakMap;let t=this.options.notFoundRoute;t&&(t.init(99999999999),this.routesById[t.id]!==t&&(t._interpolation=mr(!1,t,0)),this.routesById[t.id]=t)}matchRoutesInternal(e,t){let[n,r,i]=this.getMatchedRoutes(e.pathname),a=n,o=!1;(i?i.path!==`/`&&r[`**`]:An(e.pathname))&&(this.options.notFoundRoute?a=[...a,this.options.notFoundRoute]:o=!0);let s=o?li(this.options.notFoundMode,a):void 0,c=Array(a.length),l=this._committed,u=(e,t)=>{let n=l[t];return n?.routeId===e.id?n:e===this.options.notFoundRoute?l.find(t=>t.routeId===e.id):void 0},d;for(let n=0;n<a.length;n++){let i=a[n],o=c[n-1],l,f,p;{let n=o?.search??e.search,r=o?._strictSearch??void 0;try{let e=ri(i.options.validateSearch,{...n})??void 0;l={...n,...e},f={...r,...e}}catch(e){let r=e;if(e instanceof ti||(r=new ti(e.message,{cause:e})),t?.throwOnError)throw r;l=n,f={},p=r}}let m=``,h=``;try{m=i.options.loaderDeps?.({search:l})??``,h=m&&JSON.stringify(m)||``}catch(e){if(t?.throwOnError)throw e;p??=e}let g=fn(),_=i._interpolation?Ln(i.fullPath,i._interpolation,r,this.pathParamsDecoder,g):i.fullPath,v=i.id+_+h,y=u(i,n),b=this._cache.get(v)??(y?.id===v?y:void 0);d=b?._strictParams??Object.assign(g,d);let x;if(!b)try{ui(i,d)}catch(e){if(x=Rn(e)||cr(e)?e:new ni(e.message,{cause:e}),t?.throwOnError)throw x}let S=y?`stay`:`enter`,C;if(b)C={...b,cause:S,search:pn(y?y.search:b.search,l),_strictSearch:f,searchError:p};else{let e=Jr(i)?`pending`:`success`;C={id:v,ssr:i.options.ssr,index:n,routeId:i.id,params:y?.params??d,_strictParams:d,pathname:_,updatedAt:Date.now(),search:y?pn(y.search,l):l,_strictSearch:f,searchError:p,status:e,isFetching:!1,error:void 0,paramsError:x,context:{},abortController:t?._controller??new AbortController,cause:S,loaderDeps:y?mn(y.loaderDeps,m):m,invalid:!1,preload:!1,staticData:i.options.staticData||{},fullPath:i.fullPath}}let w=s===i.id;C._notFound&&!w&&(C.error=void 0),C._notFound=w,c[n]=C}for(let e=0;e<c.length;e++){let n=c[e];n.params=n.cause===`stay`?pn(n.params,d):d,t?._controller&&(n.context={})}return c}matchRoutesLightweight(e){let t=cn(this.stores.ids.get()),n=t?this.stores.byRoute.get(t).get():void 0,r=n?.id,i=this.lightweightCache.get(e);if(i&&i[0]===r)return i[1];let[a,o]=this.getMatchedRoutes(e.pathname),s=cn(a),c={...e.search};for(let e of a)try{Object.assign(c,ri(e.options.validateSearch,c))}catch{}let l=n&&n.routeId===s.id&&n.pathname===e.pathname,u;if(l)u=n.params;else{let e=o;for(let t of a)try{ui(t,e)}catch{}u=e}let d=[a,s.fullPath,c,u];return this.lightweightCache.set(e,[r,d]),d}};async function ei(e,t,{replace:n,ignoreBlocker:r}){if(!Cn(t,e.protocolAllowlist)){if(!r){let t=e.history._getBlockers();for(let r of t)if(r?.blockerFn&&await r.blockerFn({currentLocation:e.history.location,nextLocation:e.history.location,action:n?`REPLACE`:`PUSH`}))return}e.history._ignoreNextBeforeUnload?.(t),n?window.location.replace(t):window.location.href=t}}var ti=class extends Error{},ni=class extends Error{};function ri(e,t){if(e==null)return{};if(`~standard`in e){let n=e[`~standard`].validate(t);if(n instanceof Promise)throw new ti(`Async validation not supported`);if(n.issues)throw new ti(JSON.stringify(n.issues,void 0,2),{cause:n});return n.value}return`parse`in e?e.parse(t):typeof e==`function`?e(t):{}}function ii(e,t){if(e===void 0||e===!0)return t;let n=Object.create(null);return e===!1||e===null?n:typeof e==`function`?(Object.assign(n,t),Object.assign(n,e(n))):Object.assign(n,t,e)}function ai(e,t){return typeof e==`function`?!0:!t||e===!1||e===null?!1:e===void 0||e===!0||t.some(t=>typeof t!=`string`&&!un.call(e,t[1]))}var oi=Object.freeze({});function si(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r].options;`search`in i?i.search?.middlewares&&n.push(...i.search.middlewares):(i.preSearchFilters||i.postSearchFilters)&&n.push(({search:e,next:t})=>{let n=t(i.preSearchFilters?i.preSearchFilters.reduce((e,t)=>t(e),e):e);return i.postSearchFilters?i.postSearchFilters.reduce((e,t)=>t(e),n):n});let a=i.validateSearch;t&&a&&n.push(({search:e,next:t,meta:n})=>{let r=t(e);try{let e=ri(a,r);if(n&&e)for(let t in e)t in r||(n.defaulted||=new Map).set(t,e[t]);return{...r,...e}}catch{}return r})}return n}function ci(e,t,n){let r=(t,i,a)=>{if(t>=e.length){if(!n.search)return{};if(n.search===!0)return i;let e=ln(n.search,i);return a&&(a.explicit=e),e}return e[t]({search:i,next:(e,n)=>{if(n){let n=a||{};return{search:r(t+1,e,n),meta:n}}return r(t+1,e,a)},meta:a})};return r(0,t)}function li(e,t){if(e!==`root`){let e;for(let n=t.length-1;n>=0;n--){let r=t[n];if(r.options.notFoundComponent)return r.id;e||=r.children&&r.id}if(e)return e}return or}function ui(e,t){let n=e.options.params?.parse??e.options.parseParams;n&&Object.assign(t,n(t))}function di(e,t){return e.options[t]?.preload?.()}function fi(e,t){let n=di(e,`component`),r=di(e,`pendingComponent`);return t&&(r?r=r.then(t):t()),n&&r?Promise.all([n,r]).then(()=>{}):n??r}function pi(e,t,n){let r=()=>t===!1?void 0:t?di(e,t):fi(e,n),i=e._lazy;if(i)return i===!0?r():i.then(r);if(!e.lazyFn)return r();let a=e.lazyFn().then(t=>{{let{id:n,...r}=t.options;Object.assign(e.options,r),e._lazy=!0}},t=>{throw e._lazy=void 0,t});return e._lazy=a,a.then(r)}function mi(e){let t=e.findIndex(e=>e.status!==`success`||e._notFound)+1;return t&&t<e.length?e.slice(0,t):e}function hi(e,t,n){let r=e._tx;return t&&r?.[2]===n&&!r[3].some(e=>e.routeId===t)}var gi=0,_i=1,vi=2,yi=3,bi=[4];function xi(e){return typeof e[0]==`number`}function Si(e,t){return t.aborted?Promise.race([Promise.reject(t),e]):new Promise((n,r)=>{let i=()=>r(t);t.addEventListener(`abort`,i,{once:!0}),Promise.resolve(e).then(n,r).then(()=>t.removeEventListener(`abort`,i))})}function Ci(e,t){return e.routesById[t.routeId]}function wi(e,t,n){return cr(e)?[yi,e]:Rn(e)?(e.routeId||=n,[vi,e]):t?(typeof e?.then==`function`&&(e=Error(`A Promise was thrown`,{cause:e})),[_i,e]):[gi,e]}function Ti(e,t){let n=wi(t,!0,e.id);if(n[0]!==_i)return n;try{e.options.onError?.(n[1])}catch(t){n=wi(t,!0,e.id)}return n}function Ei(e,t,n,r,i){return i[0].signal.aborted?bi:Hi(e,t,n,Ti(n,r),i)}async function Di(e,t,n,r,i,a){let[o,s]=t,c=n[0].signal,l=!!n[3];for(let i=n[6]??0;i<r;i++){let r=s[i],u=Ci(e,r);r.abortController=n[0];let d=s[i-1]?.context??e.options.context??{},f={params:r.params,location:o,navigate:t=>e.navigate({...t,_fromLocation:o}),buildLocation:e.buildLocation,cause:l?`preload`:r.cause,abortController:n[0],preload:l,matches:s,routeId:u.id};try{let e=r._ctx||=u.options.context?u.options.context({...f,deps:r.loaderDeps,context:d})||{}:void 0;r.context={...d,...e}}catch(a){return ki(e,r),[i,Ei(e,t,u,a,n)]}if(c.aborted)return[i,bi];let p=r.paramsError??r.searchError;if(p!==void 0)return ki(e,r),[i,Ei(e,t,u,p,n)];let m=u.options.beforeLoad;if(!m)continue;let h=r.status;i>=a&&(r.status=`pending`,n[7]?.());try{Mi(e,r,`beforeLoad`,n[0]);let a=m({...f,search:r.search,context:r.context,...e.options.additionalContext}),o=await(typeof a?.then==`function`?Si(a,c):a);if(c.aborted)return[i,bi];let s=Hi(e,t,u,wi(o,!1,u.id),n);if(s[0]!==gi)return ki(e,r),[i,s];r.context={...r.context,...o}}catch(a){return ki(e,r),[i,Ei(e,t,u,a,n)]}finally{r.status=h,Mi(e,r,!1,n[0])}}i()}function Oi(e,t,n){if(!(!n||--n[2])){if(e._flights?.get(t.id)===n){let n=e._tx;if(n&&!n[0].signal.aborted&&!n[3].includes(t)&&n[3].some(e=>e.id===t.id)&&n[3].some(e=>e.isFetching===`beforeLoad`))return;e._flights.delete(t.id)}return n[1]}}function ki(e,t){let n=t._flight;t._flight=void 0,Oi(e,t,n)?.abort()}function Ai(e,t,n,r){let i=[];for(let a of t)if(!n?.includes(a)){let t=a._flight;if(a._flight=void 0,r&&t?.[2]===1&&e._flights?.get(a.id)===t&&n?.some(e=>e.id===a.id))t[2]=0;else{let n=Oi(e,a,t);n&&i.push(n)}}for(let e of i)e.abort()}function ji(e){for(let t of e){let e=t._flight;e&&e[2]++}}function Mi(e,t,n,r){if(t.isFetching=n,r&&e._tx?.[0]!==r)return;let i=e.stores.byRoute.get(t.routeId),a=i?.get();a?.id===t.id&&i.set({...a,isFetching:n})}function Ni(e,t,n,r,i,a,o){let s=t[0];return{params:n.params,location:s,navigate:t=>e.navigate({...t,_fromLocation:s}),cause:o?`preload`:n.cause,abortController:i,preload:o,deps:n.loaderDeps,parentMatchPromise:a,context:n.context,route:r,...e.options.additionalContext}}async function Pi(e,t,n,r,i,a,o){let s=o[0],c=s.signal;if(c.aborted)return bi;if(!i)return[gi,void 0];let l=n._flight;Mi(e,n,`loader`,s);try{if(!l){let s=new AbortController;l=[Promise.resolve().then(()=>i(Ni(e,t,n,r,s,a,!!o[3]))).then(e=>wi(e,!1,r.id),e=>wi(e,!0,r.id)).then(t=>(t[0]!==gi&&e._flights?.get(n.id)===l&&(e._flights.delete(n.id),l[2]||s.abort()),t[0]===_i&&l[2]?Ti(r,t[1]):t)),s,1],(e._flights??=new Map).set(n.id,l)}return n._flight=l,n.abortController=l[1],Hi(e,t,r,await Si(l[0],c),o)}catch(t){if(t!==c||!c.aborted)throw t;return ki(e,n),bi}finally{Mi(e,n,!1,s)}}function Fi(e,t,n){t[0]!==yi&&(e.status=`success`,e.error=void 0,t[0]===gi?(e.loaderData=t[1],e.invalid=!1,e.updatedAt=Date.now(),e.preload=n):e.invalid=!0)}function Ii(e,t,n){let r=e._cache.get(t.id);if(r!==n||e._committed.some(e=>e.id===t.id&&e._flight===t._flight))return;let i={...t,_notFound:void 0,context:{}};i._flight&&i._flight[2]++,e._cache.set(t.id,i),r&&ki(e,r)}function Li(e,t){return t[0]===_i||t[0]===vi?{...e,status:t[0]===_i?`error`:`notFound`,error:t[1],_flight:void 0}:e}function Ri(e,t,n,r,i,a,o){let s=t[1][n],c=Ci(e,s),l=!!a[3],u=e._cache.get(s.id),d,f=!1,p;try{if(s.status===`success`&&(d=c.options.shouldReload,typeof d==`function`&&(d=d(Ni(e,t,s,c,a[0],i,l))),a[0].signal.aborted&&(p=bi)),!p){if(s.status!==`success`)f=!0;else{let t=l||s.preload?c.options.preloadStaleTime??e.options.defaultPreloadStaleTime??3e4:c.options.staleTime??e.options.defaultStaleTime??0;f=!!(s.invalid||d||d===void 0&&Date.now()-s.updatedAt>=t&&(a[5]||s.cause===`enter`||a[2].some(e=>e.routeId===s.routeId&&e.id!==s.id)))}}}catch(n){s.invalid=!0,ki(e,s),p=Ei(e,t,c,n,a)}let m=c.options.loader,h=typeof m==`function`,g=h?m:m?.handler,_=!l||c.options.preload!==!1,v=_&&m?e._flights?.get(s.id):void 0;v===s._flight||p?v=void 0:v&&!f&&!l&&d===void 0?f=!0:f||(v=void 0);let y=!(!m||!f||s.status!==`success`||l||a[4]||((h?void 0:m.staleReloadMode)??e.options.defaultStaleReloadMode)===`blocking`),b=f&&_,x=b&&!y&&(s.status!==`success`||!!m),S=n>=o?a[7]:void 0,C=c.lazyFn&&c._lazy!==!0?S:void 0;if(b&&!m&&(s.invalid=!1,s.updatedAt=Date.now()),v&&v[2]++,x){let t=s._flight;s._flight=v,Oi(e,s,t)?.abort(),n>=o&&(s.status=`pending`),S?.()}b||(s.isFetching=!1);let w=!p&&x?Pi(e,t,s,c,g,i,a).then(t=>(Fi(s,t,l),t[0]===gi&&(m&&!a[0].signal.aborted&&Ii(e,s,u),n>=o&&(s.status=`pending`)),t)):Promise.resolve(p??[gi,s.loaderData]),T=(async()=>{try{let e=pi(c,void 0,C);e&&await Si(e,a[0].signal)}catch(r){if(!t[1].some((e,t)=>t<=n&&(e.status===`error`||e.status===`notFound`||e._notFound)))return[n,Ei(e,t,c,r,a)]}let r=await w;x&&r[0]===gi&&s.status===`pending`&&!a[0].signal.aborted&&(s.status=`success`,S?.())})();if(r.push([n,w,T]),!y)return w.then(e=>Li(s,e));let E={...s,status:`pending`,preload:!1,_flight:v};s.invalid=!1,s.isFetching=`loader`;let D=Pi(e,t,E,c,g,i,a).then(e=>(s.isFetching=!1,Fi(E,e,!1),e));return(t[2]??=[]).push([n,D,T,E]),D.then(e=>Li(E,e))}async function zi(e,t,n,r,i=0){let a=n?.[1][1],o=a?.routeId?t.findIndex(e=>e.routeId===a.routeId):n?.[0]??t.length-1;o<0&&(o=0);for(let n=o;n>=0;n--){let i=Ci(e,t[n]);try{let e=pi(i,!1);e&&await Si(e,r)}catch(e){if(e===r&&r.aborted)throw e}if(i.options.notFoundComponent)return n}return a?.routeId?o:i}function Bi(e,t){t[2]&&=(Ai(e,t[2].map(e=>e[3])),void 0)}async function Vi(e,t,n,r){let i;try{await Promise.all(e.map(e=>e[1].then(async t=>{let a=e[0];if(!(r&&a>=await r)){if(t[0]>=yi)throw[a,t];!i&&t[0]!==gi&&(i=[a,t],await Promise.all((n??[]).map(e=>{if(!(e[0]<=a))return e[1].then(t=>{if(t[0]===yi)throw[e[0],t]})})))}})))}catch(e){return e}return t??i}function Hi(e,t,n,r,i,a){for(;r[0]===yi;){let o=r[1],s=o.options;try{if((s.href||o.headers.has(`Location`))&&(e.resolveRedirect(o),s.reloadDocument)||(s.reloadDocument?i[3]:i[1]>=20))return r;let n=e.buildLocation({...s,_fromLocation:t[0],_includeValidateSearch:!0}),a=n.maskedLocation??n;if(a.external){let t=o.clone();return t.options={...s},t.headers.set(`Location`,a.publicHref),e.resolveRedirect(t),i[3]?[yi,t]:[yi,t,a]}return[yi,o,n]}catch(e){r=a?[_i,e]:Ti(n,e),a=!0}}return r}async function Ui(e,t,n,r,i,a){let o=t[1],s=await i,c=!1,l=o.findIndex(e=>e._notFound),u=t=>t[1][0]===vi?zi(e,o,t,r.signal):t[0],d=l<0?o.length:l;if((s?.[1][0]??0)>=yi)d=0;else if(s){d=s[2]??=await u(s);for(let e of n){if(e[0]>=d)break;let t=await e[1];if(t[0]!==gi&&t[0]<yi&&!(`loaderData`in o[e[0]])){s=[e[0],t],d=s[2]=await u(s);break}}}for(let e of n){if(e[0]>=d)break;let t=await e[2];if(t){s=t;break}}if((s?.[1][0]??0)>=yi){let n=s[1];if(n[0]!==yi||n[1].options.reloadDocument||n[2])return Bi(e,t),n;c=!0,s=[0,[_i,Error(`Too many redirects`)]]}let f=s?s[2]??await u(s):l;if(f>=0){let i=s?.[1],l=i?.[0],u=o[f],d=i?.[1],p=()=>{i&&(u._notFound=void 0,l===_i?u.status=`error`:(d.routeId=u.routeId,u.routeId===e.routeTree.id?(u.status=`success`,u._notFound=!0):u.status=`notFound`),u.error=d,u.isFetching=!1)};p(),i||a?.();let m=Ci(e,u);try{await Si(i?Promise.resolve().then(()=>pi(m,l===_i?`errorComponent`:`notFoundComponent`)):Promise.all([pi(m),pi(m,`notFoundComponent`)]),r.signal)}catch(n){if(n===r.signal&&r.signal.aborted)return Bi(e,t),bi}i?c&&(r.abort(),await Promise.all([...n.map(e=>e[1]),...n.map(e=>e[2]),...(t[2]??[]).map(e=>e[1])]),Bi(e,t),Ai(e,o),p()):u.status=`success`}return t}async function Wi(e,t,n,r=0,i=t[1].length){let a=t[1];for(let t=r;t<i;t++){let r=a[t],i=Ci(e,r).options;if(i.head||i.scripts)try{let t={ssr:e.options.ssr,matches:a,match:r,params:r.params,loaderData:r.loaderData},[o,s]=await Si(Promise.all([i.head?.(t),i.scripts?.(t)]),n);r.meta=o?.meta,r.links=o?.links,r.headScripts=o?.scripts,r.styles=o?.styles,r.scripts=s}catch(e){if(e===n&&n.aborted)break;console.error(e)}if(r.status!==`success`||r._notFound)break}return t}async function Gi(e,t,n,r){let i=[t,n],a=r[0].signal,o;try{let t=e.stores.matches.get(),s=n.findIndex(e=>e._notFound);if(e.options.notFoundMode!==`root`&&s>=0){let t=await zi(e,n,void 0,a,s);n[s]._notFound=void 0,n[t]._notFound=!0,s=t}let c=s<0?n.length:s+1,l=0;for(;l<c&&l!==s;){let e=n[l],i=r[2][l],a=t[l];if(i?.id!==e.id||i.status!==`success`||e.preload||a?.id!==e.id||a.status!==`success`||(l++,i._notFound||a._notFound))break}let u=[],d=r[6]??0,f=d?Promise.resolve(n[d-1]):void 0,p=()=>{for(let t=d;t<c&&!a.aborted;t++)f=Ri(e,i,t,u,f,r,l)},m=await Di(e,i,r,c,p,l);if(m){if(r[4]=!0,c=m[0],m[1][0]===vi){let t=await zi(e,n,m,a);m[2]=t,c=Math.min(c,t+1)}else m[1][0]>=yi&&(c=0);p()}if(!a.aborted&&!r[3]){let t=[];for(let[n,r]of e._flights??[])r[2]||(e._flights.delete(n),t.push(r[1]));for(let e of t)e.abort()}let h=Ui(e,i,u,r[0],Vi(u,m,i[2]),r[7]);i[2]?.length&&(i[3]=Vi(i[2],void 0,void 0,h.then(e=>xi(e)?0:mi(n).length,()=>0))),o=await h}catch(t){if(Bi(e,i),t===a&&a.aborted)return bi;throw t}return xi(o)?o:Wi(e,o,a,r[6]===n.length?r[6]:0)}function Ki(e,t){if(e._tx!==t)return;let n=t[3],r=e.stores.matches.get(),i=e._pending;for(let a=0;a<n.length;a++){let o=n[a],s=o.status===`success`&&!o._notFound,c=r[a]?.id===o.id&&r[a]?.status===`pending`;if(s&&!c)continue;let l=Ci(e,o),u=s||o.invalid?0:l.options.pendingMs??e.options.defaultPendingMs,d=l.options.pendingComponent??e.options.defaultPendingComponent;if(!d||typeof u!=`number`||u===1/0){i&&(i[0]=t,i[2]=0,i[4]=!0);return}let f=l.options.pendingMinMs??e.options.defaultPendingMinMs??0,p=!1;if(i?.[1]===o.id?(p=i[0]!==t,i[0]=t):(clearTimeout(i?.[3]),e._pending=i=void 0),i||(e._pending=i=[t,o.id,c?Date.now()+f:t[4]+u,void 0,c||void 0,d]),i[4]&&!p&&i[5]===d)return;if(i[5]=d,!i[4]){clearTimeout(i[3]);let n=i[2]-Date.now();if(n>0){i[3]=setTimeout(()=>Ki(e,t),n);return}i[2]=0}let m=n.map(e=>({...e,_flight:void 0}));m[a].status=`pending`;let h=i[4]=e.startTransition(()=>e.stores.setMatches(m),m).then(t=>(t&&e._pending===i&&i[4]===h&&!i[2]&&(i[2]=Date.now()+f),t));return}}function qi(e,t){let n=e._pending;e._tx!==t&&e._tx?.[3].some(e=>e.id===n?.[1])||(clearTimeout(n?.[3]),e._pending=void 0)}async function Ji(e,t){let n=e._pending;if(!n)return;clearTimeout(n[3]);let r=n[2]-Date.now();if(!n[4]||r<=0||!mi(t[3]).some(e=>e.id===n[1]))return;let i;try{await Si(new Promise(e=>{i=setTimeout(e,r)}),t[0].signal)}catch{}clearTimeout(i)}function Yi(e,t){e._committed=t,e.stores.setMatches(t)}function Xi(e,t,n,r){let i=e._committed,a=e._lifecycleEnd,o=e._cache;for(let e of n)e.preload=!1,r&&(e._assetEnd=void 0);let s=mi(n).length,c=new Map;{let t=Date.now(),r=new Set;for(let e=0;e<n.length;e++){let t=n[e];(e<s||t.status===`success`)&&r.add(t.id)}for(let n of[...i,...o.values()]){if(n.status!==`success`||r.has(n.id))continue;let i=Ci(e,n);!i.options.loader||t-n.updatedAt>=(n.preload?i.options.preloadGcTime??e.options.defaultPreloadGcTime??3e5:i.options.gcTime??e.options.defaultGcTime??3e5)||c.set(n.id,o.get(n.id)===n?n:{...n,_flight:void 0,isFetching:!1,context:{}})}}t[3]=[],e._cache=c;let l=e._lifecycleEnd=Zr(n);Yi(e,n),Ai(e,[...o.values(),...i].filter(e=>e._flight&&c.get(e.id)!==e),n),Qr(e,i,n,a,l,t)}async function Zi(e,t){let n=e._tx;for(;n&&n!==t;)t=n,await n[5],n=e._tx}function Qi(e,t,n){let r=n[1].options,i=n[2];if(!i)return e.navigate({...r,replace:!0,ignoreBlocker:!0});if(r.reloadDocument)return e.navigate({href:(i.maskedLocation??i).publicHref,reloadDocument:!0,replace:!0,ignoreBlocker:!0});i._redirects=t[1]+1,e._pendingLocation=i;let a=e.commitLocation({...i,viewTransition:r.viewTransition,replace:!0,resetScroll:r.resetScroll,hashScrollIntoView:r.hashScrollIntoView,ignoreBlocker:!0});return queueMicrotask(()=>{e._pendingLocation===i&&(e._pendingLocation=void 0)}),a}async function $i(e,t,n,r,i){let a=n.map(e=>({...e}));ji(a);for(let t of r)ki(e,a[t[0]]),a[t[0]]=t[3];let o=[t[2],a],s;try{s=await Ui(e,o,r,t[0],i)}catch(t){throw Ai(e,a),t}if(xi(s))Ai(e,a),s[0]===yi&&e._tx===t&&e._committed===n&&await Qi(e,t,s);else if(await Wi(e,s,t[0].signal),e._tx!==t||e._committed!==n)Ai(e,a);else{for(let t of a){let n=e._cache.get(t.id);n?._flight&&n._flight===t._flight&&(e._cache.delete(t.id),ki(e,n))}Yi(e,a),Ai(e,n,a)}}async function ea(e,t,n,r,i,a){let o=await Gi(e,t[2],t[3],[t[0],t[1],e._committed,void 0,i,n,a,r]);if(xi(o)){let n=o[0]===yi&&e._tx===t;if((!n||o[1].options.reloadDocument)&&qi(e,t),Ai(e,t[3]),t[3]=[],!n)return;if(e._tx!==t){qi(e,t);return}await Qi(e,t,o);return}let s=o[1];if(e._tx===t&&await Ji(e,t),e._tx!==t){qi(e,t),Ai(e,s),Bi(e,o);return}let c=t[2],l=Yr(c,e.stores.resolvedLocation.get()),u=o[2];await e.startViewTransition(async()=>{if(e._tx===t&&await Ji(e,t),e._tx!==t){qi(e,t),Ai(e,s),Bi(e,o);return}let n=await e.startTransition(()=>{qi(e,t),Xi(e,t,s,a),e._tx===t&&(e.emit({type:`onLoad`,...l}),e._tx===t&&e.emit({type:`onBeforeRouteMount`,...l}))},s);e._tx===t?(u?.length&&$i(e,t,s,u,o[3]).catch(console.error),e.batch(()=>{e.stores.resolvedLocation.set(c),e.stores.status.set(`idle`),e._tx===t&&e.emit({type:`onResolved`,...l}),n&&e._tx===t&&e.emit({type:`onRendered`,...l})}),e._tx===t&&(e._commitPromise?.resolve(),e._commitPromise=void 0)):Bi(e,o)})}async function ta(e,t){let n=e._tx,r=e.stores.resolvedLocation.get(),i=r??e.stores.location.get(),a=e.latestLocation,o=e._pendingLocation,s=o?.href===a.href?o._redirects??0:0,c=e._handoff,l=c?.[0](),u=new AbortController,d=e._preflight;if(e._preflight=u,l||c?.[1](),d?.abort(),!u.signal.aborted){let t=Yr(a,r);e.emit({type:`onBeforeNavigate`,...t}),u.signal.aborted||e.emit({type:`onBeforeLoad`,...t})}if(u.signal.aborted){await Zi(e,n);return}let f=i.href===a.href,p=u,m=e.matchRoutes(a,{_controller:u});ji(m);let h=l?c[1](m):void 0;if(h?p=l:l?.abort(),u.signal.aborted){Ai(e,m),await Zi(e,n);return}e._preflight=void 0;let g,_=()=>ea(e,y,f,()=>Ki(e,y),t?.sync,h),v=t?.sync?new Promise(e=>g=e):Promise.resolve().then(_),y=[p,s,a,m,Date.now(),v.then(()=>Zi(e,y))];if(e._tx=y,n){for(let t of e.stores.matches.get()){if(e._tx!==y)break;t.isFetching&&Mi(e,t,!1)}n[0].abort(),Ai(e,n[3],y[3],!0)}e._tx===y?(e.batch(()=>{e.stores.status.set(`pending`),e.stores.location.set(a)}),(h||!e._committed.length&&m[0]?.status!==`success`&&!m.some(e=>e._notFound))&&Ki(e,y),g?.(_()),await y[5]):(Ai(e,y[3]),y[3]=[],g?.(),await Zi(e,y))}async function na(e,t){let n=e.buildLocation(t);for(let t=0;;t++){let r=e._committed,i=new AbortController,a,o,s;try{try{a=e.matchRoutes(n,{_controller:i}),ji(a),o=(e._preloads??=new Map).set(i,a),s=await Gi(e,n,a,[i,t,r,!0])}finally{o&&(o=o.delete(i),Ai(e,a)),i.abort()}if(!xi(s))return s[1];if(!o||s.length<3)return;n=s[2]}catch(e){Rn(e)||console.error(e);return}}}var ra=`Error preloading route! ☝️`,ia=class{get to(){return this._to}get id(){return this._id}get path(){return this._path}get fullPath(){return this._fullPath}constructor(e){if(this.init=e=>{this.originalIndex=e,this._branch=void 0;let t=this.options,n=!t?.path&&!t?.id;this.parentRoute=this.options.getParentRoute?.(),n?this._path=or:this.parentRoute||Dn();let r=n?or:t?.path;r&&r!==`/`&&(r=kn(r));let i=t?.id||r,a=n?or:On((this.parentRoute.id===`__root__`?``:this.parentRoute.id)+`/`+(i??``));r===`__root__`&&(r=`/`);let o=a===`__root__`?`/`:r===void 0?this.parentRoute.fullPath:On(this.parentRoute.fullPath+`/`+r);this._path=r,this._id=a,this._fullPath=o,this._to=An(o)},this.addChildren=e=>this._addFileChildren(e),this._addFileChildren=e=>(Array.isArray(e)&&(this.children=e),typeof e==`object`&&e&&(this.children=Object.values(e)),this),this._addFileTypes=()=>this,this.updateLoader=e=>(Object.assign(this.options,e),this),this.update=e=>(Object.assign(this.options,e),this),this.lazy=e=>(this.lazyFn=e,this),this.redirect=e=>sr({from:this.fullPath,...e}),this.options=e||{},this.isRoot=!e?.getParentRoute,e?.id&&e?.path)throw Error(`Route cannot have both an 'id' and a 'path' option.`)}},aa=class extends ia{constructor(e){super(e)}},$=i(),oa=class extends Q.Component{constructor(...e){super(...e),this.state={error:0},this.reset=()=>{this.setState({error:0})}}static getDerivedStateFromProps(e,t){let n=e.getResetKey();return t.error&&t.resetKey!==n?{resetKey:n,error:0}:{resetKey:n}}static getDerivedStateFromError(e){return{error:[e]}}componentDidCatch(e,t){this.props.onCatch?.(e,t)}render(){let e=this.state.error;return e?Q.createElement(this.props.errorComponent??sa,{error:e[0],reset:this.reset}):this.props.children}};function sa({error:e}){let[t,n]=Q.useState(!1);return(0,$.jsxs)(`div`,{style:{padding:`.5rem`,maxWidth:`100%`},children:[(0,$.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`.5rem`},children:[(0,$.jsx)(`strong`,{style:{fontSize:`1rem`},children:`Something went wrong!`}),(0,$.jsx)(`button`,{style:{appearance:`none`,fontSize:`.6em`,border:`1px solid currentColor`,padding:`.1rem .2rem`,fontWeight:`bold`,borderRadius:`.25rem`},onClick:()=>n(e=>!e),children:t?`Hide Error`:`Show Error`})]}),(0,$.jsx)(`div`,{style:{height:`.25rem`}}),t?(0,$.jsx)(`div`,{children:(0,$.jsx)(`pre`,{style:{fontSize:`.7em`,border:`1px solid red`,borderRadius:`.25rem`,padding:`.3rem`,color:`red`,overflow:`auto`},children:e?.message?(0,$.jsx)(`code`,{children:e.message}):null})}):null]})}var ca=()=>!0,la=()=>!1;function ua({children:e,fallback:t=null}){return(0,$.jsx)(Q.Fragment,{children:da()?e:t})}function da(e=!0){return Q.useSyncExternalStore(fa,ca,e?la:ca)}function fa(){return()=>{}}function pa(e,t){let n=e.stores.location,r=new Set,i,a,o=n=>{hi(e,t,n)||(i=n,r.forEach(e=>e()))};return[()=>i??n.get(),e=>(r.size||(i=n.get(),a=n.subscribe(o).unsubscribe),r.add(e),()=>{r.delete(e),r.size||(a(),i=void 0)})]}var ma=Q.createContext(void 0),ha=Q.createContext(void 0);function ga({update:e,notify:t,unwatched:n}){return{link:r,unlink:i,propagate:a,checkDirty:o,shallowPropagate:s};function r(e,t,n){let r=t.depsTail;if(r!==void 0&&r.dep===e)return;let i=r===void 0?t.deps:r.nextDep;if(i!==void 0&&i.dep===e){i.version=n,t.depsTail=i;return}let a=e.subsTail;if(a!==void 0&&a.version===n&&a.sub===t)return;let o=t.depsTail=e.subsTail={version:n,dep:e,sub:t,prevDep:r,nextDep:i,prevSub:a,nextSub:void 0};i!==void 0&&(i.prevDep=o),r===void 0?t.deps=o:r.nextDep=o,a===void 0?e.subs=o:a.nextSub=o}function i(e,t=e.sub){let r=e.dep,i=e.prevDep,a=e.nextDep,o=e.nextSub,s=e.prevSub;return a===void 0?t.depsTail=i:a.prevDep=i,i===void 0?t.deps=a:i.nextDep=a,o===void 0?r.subsTail=s:o.prevSub=s,s===void 0?(r.subs=o)===void 0&&n(r):s.nextSub=o,a}function a(e){let n=e.nextSub,r;top:do{let i=e.sub,a=i.flags;if(a&60?a&12?a&4?!(a&48)&&c(e,i)?(i.flags=a|40,a&=1):a=0:i.flags=a&-9|32:a=0:i.flags=a|32,a&2&&t(i),a&1){let t=i.subs;if(t!==void 0){let i=(e=t).nextSub;i!==void 0&&(r={value:n,prev:r},n=i);continue}}if((e=n)!==void 0)n=e.nextSub;else{for(;r!==void 0;)if(e=r.value,r=r.prev,e!==void 0){n=e.nextSub;continue top}break}}while(1)}function o(t,n){let r,i=0,a=!1;top:do{let o=t.dep,c=o.flags;if(n.flags&16)a=!0;else if((c&17)==17){if(e(o)){let e=o.subs;e.nextSub!==void 0&&s(e),a=!0}}else if((c&33)==33){(t.nextSub!==void 0||t.prevSub!==void 0)&&(r={value:t,prev:r}),t=o.deps,n=o,++i;continue}if(!a){let e=t.nextDep;if(e!==void 0){t=e;continue}}for(;i--;){let i=n.subs,o=i.nextSub!==void 0;if(o?(t=r.value,r=r.prev):t=i,a){if(e(n)){o&&s(i),n=t.sub;continue}a=!1}else n.flags&=-33;n=t.sub;let c=t.nextDep;if(c!==void 0){t=c;continue top}}return a}while(1)}function s(e){do{let n=e.sub,r=n.flags;(r&48)==32&&(n.flags=r|16,(r&6)==2&&t(n))}while((e=e.nextSub)!==void 0)}function c(e,t){let n=t.depsTail;for(;n!==void 0;){if(n===e)return!0;n=n.prevDep}return!1}}function _a(e,t,n){let r=typeof e==`object`,i=r?e:void 0;return{next:(r?e.next:e)?.bind(i),error:(r?e.error:t)?.bind(i),complete:(r?e.complete:n)?.bind(i)}}var va=[],ya=0,{link:ba,unlink:xa,propagate:Sa,checkDirty:Ca,shallowPropagate:wa}=ga({update(e){return e._update()},notify(e){va[Ea++]=e,e.flags&=-3},unwatched(e){e.depsTail!==void 0&&(e.depsTail=void 0,e.flags=17,Aa(e))}}),Ta=0,Ea=0,Da,Oa=0;function ka(e){try{++Oa,e()}finally{--Oa||ja()}}function Aa(e){let t=e.depsTail,n=t===void 0?e.deps:t.nextDep;for(;n!==void 0;)n=xa(n,e)}function ja(){if(!(Oa>0)){for(;Ta<Ea;){let e=va[Ta];va[Ta++]=void 0,e.notify()}Ta=0,Ea=0}}function Ma(e,t){let n=typeof e==`function`,r=e,i={_snapshot:n?void 0:e,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:+!n,get(){return Da!==void 0&&ba(i,Da,ya),i._snapshot},subscribe(e){let t=_a(e),n={current:!1},r=Na(()=>{i.get(),n.current?(Da=void 0,t.next?.(i._snapshot)):n.current=!0});return{unsubscribe:()=>{r.stop()}}},_update(e){let a=Da,o=t?.compare??Object.is;if(n)Da=i,++ya,i.depsTail=void 0;else if(e===void 0)return!1;n&&(i.flags=5);try{let t=i._snapshot,a=typeof e==`function`?e(t):e===void 0&&n?r(t):e;return t===void 0||!o(t,a)?(i._snapshot=a,!0):!1}finally{Da=a,n&&(i.flags&=-5),Aa(i)}}};return n?(i.flags=17,i.get=function(){let e=i.flags;if(e&16||e&32&&Ca(i.deps,i)){if(i._update()){let e=i.subs;e!==void 0&&wa(e)}}else e&32&&(i.flags=e&-33);return Da!==void 0&&ba(i,Da,ya),i._snapshot}):i.set=function(e){if(i._update(e)){let e=i.subs;e!==void 0&&(Sa(e),wa(e),ja())}},i}function Na(e){let t=()=>{let t=Da;Da=n,++ya,n.depsTail=void 0,n.flags=6;try{return e()}finally{Da=t,n.flags&=-5,Aa(n)}},n={deps:void 0,depsTail:void 0,subs:void 0,subsTail:void 0,flags:6,notify(){let e=this.flags;e&16||e&32&&Ca(this.deps,this)?t():this.flags=2},stop(){this.flags=0,this.depsTail=void 0,Aa(this)}};return t(),n}var Pa=t((e=>{var t=r();function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:n,a=t.useState,o=t.useEffect,s=t.useLayoutEffect,c=t.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!i(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),Fa=t(((e,t)=>{t.exports=Pa()})),Ia=t((e=>{var t=r(),n=Fa();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=n.useSyncExternalStore,s=t.useRef,c=t.useEffect,l=t.useMemo,u=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),La=t(((e,t)=>{t.exports=Ia()}))();function Ra(e,t){return e===t}function za(e,t=e=>e,n){let r=n?.compare??Ra,i=(0,Q.useCallback)(t=>{let{unsubscribe:n}=e.subscribe(t);return n},[e]),a=(0,Q.useCallback)(()=>e.get(),[e]);return(0,La.useSyncExternalStoreWithSelector)(i,a,a,t,r)}var Ba={};function Va(e,t){let n=Q.useRef();return r=>{let i=e?.select?e.select(r):r;return e?.structuralSharing??t.options.defaultStructuralSharing?n.current=mn(n.current,i):i}}function Ha(e){let t=g(),n=Q.useContext(e.from?ha:ma),r=e.from??n,i=t.stores.getMatchStore(r),a=Va(e,t),o=za(i,e=>e?a(e):Ba);if(o!==Ba)return o;(e.shouldThrow??!0)&&Dn()}function Ua(e){return Ha({from:e.from,strict:e.strict,structuralSharing:e.structuralSharing,select:t=>e.select?e.select(t.loaderData):t.loaderData})}function Wa(e){let{select:t,...n}=e;return Ha({...n,select:e=>t?t(e.loaderDeps):e.loaderDeps})}function Ga(e){return Ha({from:e.from,shouldThrow:e.shouldThrow,structuralSharing:e.structuralSharing,strict:e.strict,select:t=>{let n=e.strict===!1?t.params:t._strictParams;return e.select?e.select(n):n}})}function Ka(e){return Ha({from:e.from,strict:e.strict,shouldThrow:e.shouldThrow,structuralSharing:e.structuralSharing,select:t=>e.select?e.select(t.search):t.search})}function qa(e){let t=g();return Q.useCallback(n=>t.navigate({...n,from:n.from??e?.from}),[e?.from,t])}function Ja(e){return Ha({...e,select:t=>e.select?e.select(t.context):t.context})}function Ya(...e){let t=Q.useRef(e),n=t.current;return e.forEach((e,t)=>{gn(n[t],e,!1,!0)||(n[t]=e)}),t.current}function Xa(e,t){e.preloadRoute(t).catch(e=>{console.warn(e),console.warn(ra)})}function Za(e,t){let n=typeof e==`string`&&xn(e);if(n)return t.has(n)?e:null}function Qa(e,t,n,r){let i=Mn(e.pathname,r),a=Mn(t.pathname,r);return(n?.exact?i!==a:!i.startsWith(a)||i.length!==a.length&&i[a.length]!==`/`)||(n?.includeSearch??!0)&&!gn(e.search,t.search,!n?.exact,n?.explicitUndefined)?!1:!n?.includeHash||e.hash===t.hash}function $a(e,t,n){let r=g(),i=Q.useRef(null),a=Q.useCallback(e=>{if(i.current=e,typeof t==`function`)return t(e);t&&(t.current=e)},[t]),{activeOptions:o,to:s,preload:c,preloadDelay:l,disabled:u,target:d,onClick:f,onBlur:p,onFocus:m,onMouseEnter:h,onMouseLeave:_,onTouchStart:v}=e,[y,b,x]=Ya(e.search,e.params,o),S=Q.useContext(ma),C=(r.stores._linkScopes??={})[S]??=pa(r,S),[w,T,E]=Q.useMemo(()=>{let t=Za(s,r.protocolAllowlist);if(t!==void 0){let n=[t??void 0];return[e,()=>n]}let n={...e},i,a,o,c=()=>{let e=C[0]();if(e!==i){n._fromLocation=e;let t=r.buildLocation(n),o=so(t,r,u),s=u||o&&!xn(o)?Qa(e,t,x,r.basepath):void 0;a&&a[0]===o&&a[1]===s||(a=[o,s]),i=e}return a};return[n,c,x?.includeHash&&(()=>{let e=c();return e[1]?o??=[e[0],!1]:e})]},[r,C,e.from,e.hash,e.href,s,y,b,e.state,e.mask,e.unsafeRelative,x,u]),[D,O]=Q.useSyncExternalStore(C[1],T,E||T),k=O===void 0&&D,ee=u||D===void 0,A=Q.useRef(!1),j=e.reloadDocument||k||ee?!1:c??r.options.defaultPreload,M=l??r.options.defaultPreloadDelay??0,N=Q.useCallback(e=>{let t=e?.isIntersecting;t??j===`intent`?M?i.t??=setTimeout(()=>{i.t=void 0,Xa(r,w)},M):Xa(r,w):t===!1&&ao(i)},[r,w,i,j,M]);Q.useEffect(()=>{if(!j)return;j===`render`&&!A.current&&(A.current=!0,Xa(r,w));let e=!0,t;return j===`viewport`&&i.current&&typeof IntersectionObserver==`function`&&(t=new IntersectionObserver(t=>{e&&N(t.pop())},{rootMargin:`100px`}),t.observe(i.current)),()=>{e=!1,t?.disconnect(),ao(i)}},[r,w,j,N,i]);let P=ro(e,n);if(P.ref=t?a:i,k)return P.href=k,P;let F=t=>{let n=d??t.currentTarget.getAttribute(`target`);ee||t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||n&&n!==`_self`||t.button!==0||(t.preventDefault(),ao(i),r.navigate({...e,_fromLocation:w._fromLocation}))},I=()=>{j===`intent`&&Xa(r,w)},L=()=>{j===`intent`&&ao(i)};return P.onClick=oo(f,F),P.onBlur=oo(p,L),P.onFocus=oo(m,N),P.onMouseEnter=oo(h,N),P.onMouseLeave=oo(_,L),P.onTouchStart=oo(v,I),io(P,e,O,D,ee,n)}var eo={},to={className:`active`},no=new Set([`to`,`params`,`search`,`hash`,`state`,`mask`,`from`,`unsafeRelative`,`reloadDocument`,`preload`,`preloadDelay`,`preloadIntentProximity`,`hashScrollIntoView`,`replace`,`startTransition`,`resetScroll`,`viewTransition`,`ignoreBlocker`,`activeProps`,`inactiveProps`,`activeOptions`,`_asChild`]);function ro(e,t){let n={};for(let r in e)no.has(r)||r===`type`&&t!==void 0||r===`disabled`&&t===`a`||(n[r]=e[r]);return n}function io(e,t,n,r,i,a){let{activeProps:o,inactiveProps:s,className:c,style:l,target:u}=t,d=ln(n?o:s,{})??(n?to:eo);Object.assign(e,d),e.href=r,a!==`a`&&(e.disabled=i),e.target=u;let f=d.style;(l||f)&&(e.style=l&&f?{...l,...f}:l||f);let p=d.className;return(c||p)&&(e.className=c?p?`${c} ${p}`:c:p),i&&(e.role=`link`,e[`aria-disabled`]=!0),n&&(e[`data-status`]=`active`,e[`aria-current`]=`page`),e}var ao=e=>{clearTimeout(e.t),e.t=void 0},oo=(e,t)=>e?n=>n.defaultPrevented||(e(n),n.defaultPrevented||t(n)):t;function so(e,t,n){if(n)return;let r=e.maskedLocation??e,i=r.external?r.publicHref:t.history.createHref(r.publicHref)||`/`;if(!r.external&&i===r.publicHref||!Cn(i,t.protocolAllowlist))return i}var co=Q.memo(Q.forwardRef((e,t)=>{let n=e._asChild||`a`,r=$a(e,t,n),i=typeof e.children==`function`?e.children({isActive:r[`data-status`]===`active`}):e.children;return Q.createElement(n,r,i)}),lo);function lo(e,t){let n=0;for(let r in t)if(n++,e[r]!==t[r]&&(!no.has(r)||!gn(e[r],t[r],!1,!0)))return!1;for(let t in e)n--;return n===0}var uo=class extends ia{constructor(e){super(e),this.useMatch=e=>Ha({...e,from:this.id}),this.useRouteContext=e=>Ja({...e,from:this.id}),this.useSearch=e=>Ka({...e,from:this.id}),this.useParams=e=>Ga({...e,from:this.id}),this.useLoaderDeps=e=>Wa({...e,from:this.id}),this.useLoaderData=e=>Ua({...e,from:this.id}),this.useNavigate=()=>qa({from:this.fullPath}),this.Link=Q.forwardRef((e,t)=>(0,$.jsx)(co,{ref:t,from:this.fullPath,...e}))}};function fo(e){return new uo(e)}var po=class extends aa{constructor(e){super(e),this.useMatch=e=>Ha({...e,from:this.id}),this.useRouteContext=e=>Ja({...e,from:this.id}),this.useSearch=e=>Ka({...e,from:this.id}),this.useParams=e=>Ga({...e,from:this.id}),this.useLoaderDeps=e=>Wa({...e,from:this.id}),this.useLoaderData=e=>Ua({...e,from:this.id}),this.useNavigate=()=>qa({from:this.fullPath}),this.Link=Q.forwardRef((e,t)=>(0,$.jsx)(co,{ref:t,from:this.fullPath,...e}))}};function mo(e){return new po(e)}function ho(e){let t=g(),n=`not-found-${za(t.stores.location,e=>e.pathname)}-${za(t.stores.status)}`;return(0,$.jsx)(oa,{getResetKey:()=>n,onCatch:(t,n)=>{if(Rn(t))e.onCatch?.(t,n);else throw t},errorComponent:({error:t})=>{if(Rn(t))return e.fallback?.(t);throw t},children:e.children})}function go(){return(0,$.jsx)(`p`,{children:`Not Found`})}function _o(e,t,n){return t.options.notFoundComponent?(0,$.jsx)(t.options.notFoundComponent,{...n}):e.options.defaultNotFoundComponent?(0,$.jsx)(e.options.defaultNotFoundComponent,{...n}):(0,$.jsx)(go,{})}function vo(e,t){let n=t?.options.pendingComponent??e.options.defaultPendingComponent;return n?(0,$.jsx)(n,{}):null}var yo=(e,t)=>e[0]===t[0]&&e[1]===t[1],bo=(e,t,n)=>!t.isRoot||t.options.shellComponent||t.options.wrapInSuspense||n===!1||n===`data-only`||!e.ssr,xo=Q.memo(function({routeId:e}){let t=g();return So(t,za(t.stores.getMatchStore(e)))});function So(e,t){let n=e.routesById[t.routeId],r=vo(e,n),i=n.options.errorComponent??e.options.defaultErrorComponent,a=n.options.onCatch??e.options.defaultOnCatch,o=n.isRoot?n.options.notFoundComponent??e.options.notFoundRoute?.options.component:n.options.notFoundComponent,s=t.ssr===!1||t.ssr===`data-only`,c=bo(e,n,t.ssr)&&(n.options.wrapInSuspense??r??(n.options.errorComponent?.preload||s)),l=(0,$.jsx)(Co,{match:t});s&&(l=(0,$.jsx)(ua,{fallback:r,children:l})),o&&(l=(0,$.jsx)(ho,{fallback:e=>{if(e.routeId??=t.routeId,e.routeId!==t.routeId)throw e;return Q.createElement(o,e)},children:l})),i&&(l=(0,$.jsx)(oa,{getResetKey:()=>t,errorComponent:i,onCatch:(e,n)=>{if(Rn(e))throw e.routeId??=t.routeId,e;a?.(e,n)},children:l})),c&&(l=(0,$.jsx)(Q.Suspense,{fallback:r,children:l}));let u=n.isRoot&&n.options.shellComponent;return u?(0,$.jsx)(ma.Provider,{value:t.routeId,children:(0,$.jsxs)(u,{children:[l,null]})}):(0,$.jsxs)(ma.Provider,{value:t.routeId,children:[l,null]})}var Co=Q.memo(function({match:e}){let t=g(),n=e.routeId,r=t.routesById[n],i=Q.useMemo(()=>{let i=(r.options.remountDeps??t.options.defaultRemountDeps)?.({routeId:n,loaderDeps:e.loaderDeps,params:e._strictParams,search:e._strictSearch});return i?JSON.stringify(i):void 0},[n,e.loaderDeps,e._strictParams,e._strictSearch,r.options.remountDeps,t.options.defaultRemountDeps]),a=Q.useMemo(()=>{let e=r.options.component??t.options.defaultComponent;return e?(0,$.jsx)(e,{},i):(0,$.jsx)(wo,{})},[i,r.options.component,t.options.defaultComponent]);if(e.status===`pending`){if(t.ssr&&!bo(t,r,e.ssr))return a;if(t._tx)throw t._tx[5];return vo(t,r)}if(e.status===`notFound`)return _o(t,r,e.error);if(e.status===`error`)throw e.error;return a}),wo=Q.memo(function(){let e=g(),t=Q.useContext(ma),n,r,i;{let a=e.stores.getMatchStore(t);[n,r]=za(a,e=>[!!e._notFound,e.error],{compare:yo}),i=za(e.stores.ids,e=>e[e.indexOf(t)+1])}if(n)return _o(e,e.routesById[t],r);if(!i)return null;let a=(0,$.jsx)(xo,{routeId:i});return t===`__root__`?(0,$.jsx)(Q.Suspense,{fallback:vo(e),children:a}):a});function To(e,t){let n=e[1];e.length=0,n?.(t)}function Eo({t:e}){let t=g(),n=t._rendered??=[];return t.startTransition=(r,i)=>new Promise(a=>{To(n,!1),n.push(i,a),e(t),Q.startTransition(r)}),sn(()=>{let e=t.history.subscribe(t.load);t.updateLatestLocation();let r=t.latestLocation,i=t.buildLocation({to:r.pathname,search:!0,params:!0,hash:!0,state:!0,_includeValidateSearch:!0});if(An(r.publicHref)!==An(i.publicHref))return t.commitLocation({...i,replace:!0,ignoreBlocker:!0}),e;let a=t.stores.resolvedLocation.get();return a?.href===r.href&&a.state.__TSR_key===r.state.__TSR_key?n.push(t.stores.matches.get(),e=>{e&&t.emit({type:`onRendered`,...Yr(a,a)})}):t._tx||t.load({sync:!0}).catch(console.error),e},[t,t.history]),null}function Do(){let e=g(),t=e.routesById[or],n=vo(e,t),r=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Eo,{t:Q.useState()[1]}),e.ssr?(0,$.jsx)(Oo,{}):(0,$.jsx)(Q.Suspense,{fallback:n,children:(0,$.jsx)(Oo,{})})]});return e.options.InnerWrap?(0,$.jsx)(e.options.InnerWrap,{children:r}):r}function Oo(){let e=g(),t=e._rendered,n=za(e.stores.matches,e=>t[0]??e),r=n[0],i=r?.routeId;sn(()=>{t[0]===n&&To(t,!0)},[t,n]);let a=i?(0,$.jsx)(xo,{routeId:i}):null;return e.options.disableGlobalCatchBoundary?a:(0,$.jsx)(oa,{getResetKey:()=>r,onCatch:void 0,children:a})}var ko=e=>({createMutableStore:Ma,createReadonlyStore:Ma,batch:ka}),Ao=e=>new jo(e),jo=class extends $r{constructor(e){super(e,ko)}};function Mo({router:e,children:t,...n}){dn(n)&&e.update({...e.options,...n,context:{...e.options.context,...n.context}});let r=(0,$.jsx)(W.Provider,{value:e,children:t});return e.options.Wrap?(0,$.jsx)(e.options.Wrap,{children:r}):r}function No({router:e,...t}){return(0,$.jsx)(Mo,{router:e,...t,children:(0,$.jsx)(Do,{})})}function Po(e){let t=g({warn:e?.router===void 0}),n=e?.router||t;return za(n.stores.__store,Va(e,n))}function Fo(e){let t=g();return za(t.stores.location,Va(e,t))}var Io={name:`alarm-clock`,size:24,node:[[`circle`,{cx:`12`,cy:`13`,r:`8`,key:`3y4lt7`}],[`path`,{d:`M12 9v4l2 2`,key:`1c63tq`}],[`path`,{d:`M5 3 2 6`,key:`18tl5t`}],[`path`,{d:`m22 6-3-3`,key:`1opdir`}],[`path`,{d:`M6.38 18.7 4 21`,key:`17xu3x`}],[`path`,{d:`M17.64 18.67 20 21`,key:`kv2oe2`}]]};Io.node;var Lo=y(Io),Ro={name:`archive`,size:24,node:[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]};Ro.node;var zo=y(Ro),Bo={name:`arrow-left`,size:24,node:[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]};Bo.node;var Vo=y(Bo),Ho={name:`bell-off`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]};Ho.node;var Uo=y(Ho),Wo={name:`check-check`,size:24,node:[[`path`,{d:`M18 6 7 17l-5-5`,key:`116fxf`}],[`path`,{d:`m22 10-7.5 7.5L13 16`,key:`ke71qq`}]]};Wo.node;var Go=y(Wo),Ko={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};Ko.node;var qo=y(Ko),Jo={name:`circle-alert`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]],aliases:[`alert-circle`]};Jo.node;var Yo=y(Jo),Xo={name:`circle-check`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 9-5.5 5.5L8 12`,key:`xofnsj`}]],aliases:[`check-circle-2`]};Xo.node;var Zo=y(Xo),Qo={name:`circle-dot`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};Qo.node;var $o=y(Qo),es={name:`clock`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]};es.node;var ts=y(es),ns={name:`copy`,size:24,node:[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]};ns.node;var rs=y(ns),is={name:`download`,size:24,node:[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]};is.node;var as=y(is),os={name:`external-link`,size:24,node:[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]};os.node;var ss=y(os),cs={name:`file-diff`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M9 10h6`,key:`9gxzsh`}],[`path`,{d:`M12 13V7`,key:`h0r20n`}],[`path`,{d:`M9 17h6`,key:`r8uit2`}]]};cs.node;var ls=y(cs),us={name:`file-terminal`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`m8 16 2-2-2-2`,key:`10vzyd`}],[`path`,{d:`M12 18h4`,key:`1wd2n7`}]]};us.node;var ds=y(us),fs={name:`files`,size:24,node:[[`path`,{d:`M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8`,key:`14sh0y`}],[`path`,{d:`M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z`,key:`1970lx`}],[`path`,{d:`M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1`,key:`l4dndm`}]]};fs.node;var ps=y(fs),ms={name:`git-branch`,size:24,node:[[`path`,{d:`M15 6a9 9 0 0 0-9 9V3`,key:`1cii5b`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}]]};ms.node;var hs=y(ms),gs={name:`git-commit-horizontal`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}],[`line`,{x1:`3`,x2:`9`,y1:`12`,y2:`12`,key:`1dyftd`}],[`line`,{x1:`15`,x2:`21`,y1:`12`,y2:`12`,key:`oup4p8`}]],aliases:[`git-commit`]};gs.node;var _s=y(gs),vs={name:`git-pull-request`,size:24,node:[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M13 6h3a2 2 0 0 1 2 2v7`,key:`1yeb86`}],[`line`,{x1:`6`,x2:`6`,y1:`9`,y2:`21`,key:`rroup`}]]};vs.node;var ys=y(vs),bs={name:`inbox`,size:24,node:[[`polyline`,{points:`22 12 16 12 14 15 10 15 8 12 2 12`,key:`o97t9d`}],[`path`,{d:`M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`oot6mr`}]]};bs.node;var xs=y(bs),Ss={name:`layout-list`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}],[`path`,{d:`M14 4h7`,key:`3xa0d5`}],[`path`,{d:`M14 9h7`,key:`1icrd9`}],[`path`,{d:`M14 15h7`,key:`1mj8o2`}],[`path`,{d:`M14 20h7`,key:`11slyb`}]]};Ss.node;var Cs=y(Ss),ws={name:`link`,size:24,node:[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]};ws.node;var Ts=y(ws),Es={name:`list-checks`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]};Es.node;var Ds=y(Es),Os={name:`log-out`,size:24,node:[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]};Os.node;var ks=y(Os),As={name:`monitor-smartphone`,size:24,node:[[`path`,{d:`M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8`,key:`10dyio`}],[`path`,{d:`M10 19v-3.96 3.15`,key:`1irgej`}],[`path`,{d:`M7 19h5`,key:`qswx4l`}],[`rect`,{width:`6`,height:`10`,x:`16`,y:`12`,rx:`2`,key:`1egngj`}]]};As.node;var js=y(As),Ms={name:`panel-left-close`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]],aliases:[`sidebar-close`]};Ms.node;var Ns=y(Ms),Ps={name:`panel-left-open`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]],aliases:[`sidebar-open`]};Ps.node;var Fs=y(Ps),Is={name:`qr-code`,size:24,node:[[`rect`,{width:`5`,height:`5`,x:`3`,y:`3`,rx:`1`,key:`1tu5fj`}],[`rect`,{width:`5`,height:`5`,x:`16`,y:`3`,rx:`1`,key:`1v8r4q`}],[`rect`,{width:`5`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`1x03jg`}],[`path`,{d:`M21 16h-3a2 2 0 0 0-2 2v3`,key:`177gqh`}],[`path`,{d:`M21 21v.01`,key:`ents32`}],[`path`,{d:`M12 7v3a2 2 0 0 1-2 2H7`,key:`8crl2c`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M12 3h.01`,key:`n36tog`}],[`path`,{d:`M12 16v.01`,key:`133mhm`}],[`path`,{d:`M16 12h1`,key:`1slzba`}],[`path`,{d:`M21 12v.01`,key:`1lwtk9`}],[`path`,{d:`M12 21v-1`,key:`1880an`}]]};Is.node;var Ls=y(Is),Rs={name:`refresh-cw`,size:24,node:[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]};Rs.node;var zs=y(Rs),Bs={name:`rotate-cw`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]};Bs.node;var Vs=y(Bs),Hs={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};Hs.node;var Us=y(Hs),Ws={name:`send`,size:24,node:[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]};Ws.node;var Gs=y(Ws),Ks={name:`server`,size:24,node:[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]};Ks.node;var qs=y(Ks),Js={name:`shield-check`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]};Js.node;var Ys=y(Js),Xs={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};Xs.node;var Zs=y(Xs),Qs={name:`triangle-alert`,size:24,node:[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`alert-triangle`]};Qs.node;var $s=y(Qs),ec={name:`type`,size:24,node:[[`path`,{d:`M12 4v16`,key:`1654pz`}],[`path`,{d:`M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2`,key:`e0r10z`}],[`path`,{d:`M9 20h6`,key:`s66wpe`}]]};ec.node;var tc=y(ec),nc={name:`undo-2`,size:24,node:[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]};nc.node;var rc=y(nc),ic=e(n(),1),ac={neutral:Bt,success:Zo,info:Pe,danger:Yo},oc={neutral:`text-(--ochre-400)`,success:`text-(--green-400)`,info:`text-(--blue-400)`,danger:`text-(--red-400)`};function sc({title:e,description:t,tone:n=`neutral`,onClose:r}){return(0,$.jsxs)(`div`,{className:`flex min-w-[min(260px,100%)] max-w-[380px] animate-[em-sheet-up_var(--dur-3)_var(--ease-out)] items-start gap-2.5 rounded-lg bg-inverse py-2.5 pr-2 pl-3 font-sans text-13 font-medium leading-(--lh-snug) text-fg-inverse shadow-3`,children:[(0,$.jsx)(X,{icon:ac[n],className:Z(`mt-px`,oc[n])}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5 pt-px wrap-break-word`,children:[(0,$.jsx)(`span`,{children:e}),t&&(0,$.jsx)(`span`,{className:`font-sans text-12 font-normal leading-(--lh-snug) opacity-75`,children:t})]}),(0,$.jsx)(Et,{label:`Dismiss`,icon:Pt,size:`sm`,onClick:r,className:`size-6 text-inherit opacity-70 [@media(pointer:coarse)]:size-10`})]})}var cc=(0,Q.createContext)(null);function lc({children:e}){let[t,n]=(0,Q.useState)(null),r=(0,Q.useCallback)(e=>n({...e}),[]),i=(0,Q.useCallback)(()=>n(null),[]),a=(0,Q.useMemo)(()=>({show:r}),[r]);return(0,Q.useEffect)(()=>{if(!t)return;let e=window.setTimeout(i,3200);return()=>window.clearTimeout(e)},[t,i]),(0,$.jsxs)(cc.Provider,{value:a,children:[e,(0,ic.createPortal)((0,$.jsx)(`div`,{"data-emend-toast":!0,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`pointer-events-auto fixed inset-x-4 bottom-[calc(var(--sendbar-h)+var(--tabbar-h)+var(--space-4)+env(safe-area-inset-bottom))] z-(--z-toast) flex justify-center md:bottom-[calc(var(--sendbar-h)+var(--space-4)+env(safe-area-inset-bottom))]`,children:t&&(0,$.jsx)(sc,{...t,onClose:i})}),document.body)]})}function uc(){let e=(0,Q.useContext)(cc);if(!e)throw Error(`useToast requires a ToastProvider`);return e}function dc(e){if(!e||typeof e!=`object`||!(`kind`in e))return null;if((e.kind===`open`||e.kind===`ping`)&&Object.keys(e).length===1)return e.kind;if(e.kind!==`event`||!(`type`in e)||!(`data`in e)||typeof e.data!=`string`)return null;try{return L.parse({...JSON.parse(e.data),type:e.type})}catch{return null}}var fc=5e3,pc=1e3,mc=1e4,hc=3e4;function gc(e){let t,n=!1,r=1e3,i,a,o,s=!1,c=0,l,u=()=>{n||i!==void 0||(i=setTimeout(()=>{i=void 0,p()},r),r=Math.min(r*2,6e4))},d=()=>{clearTimeout(a),a=setTimeout(()=>m(!0),ke)},f=async e=>{if(n||t!==e||o||i!==void 0)return;let r=new AbortController;o=r;try{await re(`/api/v1/events`,r.signal)}catch(t){!r.signal.aborted&&t instanceof G&&(t.status===401||t.status===403)&&(n=!0,e.close())}finally{o===r&&(o=void 0),!n&&t===e&&!r.signal.aborted&&(s?(s=!1,p()):u())}},p=()=>{if(n)return;clearTimeout(a),t?.close(),c=Date.now();let o;try{o=new EventSource(`/api/v1/events`)}catch{t=void 0,u();return}t=o,o.addEventListener(`error`,()=>{o.readyState===EventSource.CLOSED&&(clearTimeout(a),f(o))}),o.addEventListener(`open`,()=>{n||t!==o||(clearTimeout(i),i=void 0,r=1e3,d(),e({kind:`open`}))}),o.addEventListener(P,()=>{n||t!==o||(d(),e({kind:`ping`}))});for(let r of wt.options)o.addEventListener(r,i=>{n||t!==o||(d(),e({kind:`event`,type:r,data:i.data}))})},m=(e=!1)=>{if(!n&&!(!e&&Date.now()-c<pc)){if(o){if(!e){s=!0;return}o.abort(),o=void 0,s=!1}clearTimeout(i),i=void 0,p()}},h=()=>{n||t&&t.readyState!==EventSource.CLOSED||(o?s=!0:(clearTimeout(i),i=void 0,p()))},g=()=>{t&&t.readyState!==EventSource.CLOSED?m():h()},_=()=>{if(document.visibilityState!==`visible`){l??=Date.now();return}let e=l===void 0?0:Date.now()-l;l=void 0,e>fc?g():h()};return window.addEventListener(`online`,g),window.addEventListener(`pageshow`,g),document.addEventListener(`visibilitychange`,_),p(),{reconnect:()=>!n&&(r=1e3,m(!0),!0),stop:()=>{n=!0,clearTimeout(i),clearTimeout(a),o?.abort(),t?.close(),window.removeEventListener(`online`,g),window.removeEventListener(`pageshow`,g),document.removeEventListener(`visibilitychange`,_)}}}var _c,vc=new Set;function yc(e=3e3){let t=_c;return t?new Promise(n=>{let r=e=>{clearTimeout(a),vc.delete(i),n(e)},i=()=>r(!0),a=setTimeout(()=>r(!1),e);vc.add(i),t()||r(!1)}):Promise.resolve(!1)}function bc(e,t){let n=!1,r=Date.now(),i=r=>{if(n)return;let i=dc(r);if(i===`open`){t();for(let e of[...vc])e()}else i&&i!==`ping`&&e(i)};if(!navigator.locks?.request||typeof BroadcastChannel>`u`){let e=gc(i);return _c=e.reconnect,()=>{_c===e.reconnect&&(_c=void 0),e.stop()}}let a=new BroadcastChannel(`emend-events`);a.addEventListener(`message`,e=>{dc(e.data)&&(r=Date.now()),i(e.data)});let o=new Map,s,c,l=!1,u=e=>{if(n)return;if(e){if(l||s)return;l=!0}else c?.abort();let t=new AbortController,d=!1,f,p=()=>{},m=new Promise(e=>{p=e});o.set(t,p),e||(c=t);let h=e?{steal:!0}:{signal:t.signal};navigator.locks.request(`emend-events`,h,async()=>{n||t.signal.aborted||(d=!0,e&&(l=!1,c?.abort()),(c===t||e)&&(c=void 0),r=Date.now(),f=gc(e=>{r=Date.now(),i(e),a.postMessage(e)}),s=f,await m)}).catch(()=>{e&&(l=!1),!(n||t.signal.aborted)&&(d?(f?.stop(),s===f&&(s=void 0),r=Date.now(),u(!1)):e||(f=gc(i),s=f))}).finally(()=>{o.delete(t),p()})};u(!1);let d=()=>n?!1:s?s.reconnect():l?!0:Date.now()-r<=hc?!1:(u(!0),!0);_c=d;let f=setInterval(()=>{s||n||document.visibilityState!==`visible`||Date.now()-r<=4e4||(r=Date.now(),u(!0))},mc),p=()=>{document.visibilityState===`visible`&&(r=Date.now())};return document.addEventListener(`visibilitychange`,p),()=>{n=!0,clearInterval(f),document.removeEventListener(`visibilitychange`,p),_c===d&&(_c=void 0),s?.stop(),a.close();for(let[e,t]of o)e.abort(),t()}}function xc(){let e=null,t=new Set,n=new Set,r=new Set,i=e=>{t=e;for(let e of n)e()},a=e=>{let n=new Set(e.map(({id:e})=>e));[...t].some(e=>n.has(e))&&i(new Set([...t].filter(e=>!n.has(e))))};return{subscribe(e){return n.add(e),()=>{n.delete(e)}},snapshot:()=>t,baseline(t){e??=new Set(t.map(({id:e})=>e))},show(n){if(!e)return;let o=n.filter(({id:t})=>!e?.has(t));if(!o.length)return;for(let{id:t}of o)e.add(t);i(new Set([...t,...o.map(({id:e})=>e)]));let s=setTimeout(()=>{r.delete(s),a(o)},1e3);r.add(s)},hide:a,reset(){for(let e of r)clearTimeout(e);r.clear(),e=null,i(new Set)}}}var Sc=(0,Q.createContext)(null);function Cc({children:e,enabled:t}){let n=Ct(),[r]=(0,Q.useState)(xc);return(0,Q.useEffect)(()=>{if(!t)return;let e=n.getQueryCache().subscribe(e=>{if(e.type!==`updated`||e.action.type!==`success`||e.action.manual||e.query.queryKey.length!==1||e.query.queryKey[0]!==`inbox`)return;let t=n.getQueryData([`inbox`]);t&&r.baseline(t.items)});return()=>{e(),r.reset()}},[n,t,r]),(0,$.jsx)(Sc.Provider,{value:r,children:e})}function wc(e){let t=(0,Q.useContext)(Sc);if(!t)throw Error(`Missing inbox arrivals provider`);let n=(0,Q.useRef)(e),r=(0,Q.useSyncExternalStore)(t.subscribe,t.snapshot);return(0,Q.useEffect)(()=>{n.current=e,t.show(e)},[t,e]),(0,Q.useEffect)(()=>()=>t.hide(n.current),[t]),r}var Tc=(0,Q.createContext)(new Map);function Ec({children:e,enabled:t=!0}){let n=Ct(),[r,i]=(0,Q.useState)(()=>new Map);return(0,Q.useEffect)(()=>{if(!t){i(new Map);return}let e=bc(e=>{let{reviewId:t}=e;e.type===`publish`&&i(n=>e.revision>(n.get(t)??0)?new Map(n).set(t,e.revision):n);let r=e.type===`viewed`?[]:[[`inbox`],[`review`,t]];[`thread`,`send`,`claimed`,`confirmed`,`viewed`].includes(e.type)&&r.push([`revision`,t]),_(n,r)},()=>{_(n,[],{opened:!0})});return()=>{e()}},[n,t]),(0,$.jsx)(Tc.Provider,{value:r,children:(0,$.jsx)(Cc,{enabled:t,children:e})})}function Dc(e){return(0,Q.useContext)(Tc).get(e)??0}var Oc;function kc(e,t){e.defaultPrevented||e.button!==0||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||e.currentTarget.target&&e.currentTarget.target!==`_self`||(Oc={devicesIndex:/^\/devices\/?$/.test(t.pathname)?t.state.__TSR_index:void 0})}function Ac(){let e=Oc;return Oc=void 0,e}var jc=e=>new Promise(t=>setTimeout(t,e));function Mc(){let e=Ct(),[t,n]=(0,Q.useState)(!1),r=(0,Q.useRef)(!1);return{refresh:(0,Q.useCallback)(async()=>{if(!r.current){r.current=!0,n(!0);try{let t=e=>!b(e);if(await yc()){await jc(300);for(let n=0;e.isFetching({predicate:t})>0&&n<1e4;n+=100)await jc(100)}else await e.refetchQueries({type:`active`,predicate:t})}catch{}finally{r.current=!1,n(!1)}}},[e]),busy:t}}function Nc(e){return[{heading:`Writeup and docs`},{radioGroup:{label:`Writeup and docs`,segmented:!0,value:String(e.proseSize),onValueChange:e=>{let t=Number(e);(t===15||t===16||t===17||t===18)&&m.update({proseSize:t})},items:[15,16,17,18].map(e=>({value:String(e),label:`${e} px`}))}},{heading:`Code in diffs`},{radioGroup:{label:`Code in diffs`,segmented:!0,value:String(e.codeSize),onValueChange:e=>{let t=Number(e);(t===11||t===12||t===13||t===14)&&m.update({codeSize:t})},items:[11,12,13,14].map(e=>({value:String(e),label:`${e} px`}))}}]}function Pc(){let e=Kt(),t=Vt();return e===`phone`?null:(0,$.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(tt,{label:`Panes`,size:`sm`,value:t.pane[e],options:[{value:`split`,label:`Split`,icon:Ut},{value:`tabs`,label:`Tabs`,icon:ps}],onChange:n=>{(n===`split`||n===`tabs`)&&m.update({pane:{...t.pane,[e]:n}})}}),(0,$.jsx)($e,{label:`Text size`,trigger:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,icon:tc,children:`Text`}),items:Nc(t)})]})}var Fc=(0,Q.createContext)(null);function Ic(){let e=(0,Q.useContext)(Fc);if(!e)throw Error(`useRequestUpdate needs an AppFrame`);return e}function Lc(e){e===`update`?Xt.installUpdate():Xt.reloadNow()}function Rc(e){return e.length<2?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`}function zc(e){return e.saving||e.sending||e.unstored}function Bc(e){return`Reloading now could lose ${Rc([e.saving?`a comment that is still saving`:``,e.sending?`a Send in progress`:``,e.unstored?`text that could not be stored on this device`:``].filter(Boolean))}.`}function Vc(e){let[t,n]=(0,Q.useState)(null);function r(e){let t=ht();zc(t)?n({action:e,work:t}):Lc(e)}function i(e){let t=ht();zc(t)&&JSON.stringify(t)!==JSON.stringify(e.work)?n({action:e.action,work:t}):(n(null),Lc(e.action))}let a=t?.action===`reload`;return{request:r,dialog:t&&(0,$.jsx)(St,{open:!0,returnFocus:e,onOpenChange:e=>{e||n(null)},title:a?`Reload now?`:`Update now?`,description:Bc(t.work),actions:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{"data-autofocus":!0,variant:`ghost`,onClick:()=>n(null),children:`Cancel`}),(0,$.jsx)(Y,{variant:`danger`,onClick:()=>i(t),children:a?`Reload anyway`:`Update anyway`})]})})}}function Hc({isReview:e=!1,children:t,onCommentReview:n}){let r=Kt(),i=Vt(),a=g(),o=uc(),{refresh:s,busy:c}=Mc(),l=Qt(),u=(0,Q.useRef)(null),d=Vc(u),f=l.state===`available`?[{label:`Update available`,icon:as,opensDialog:!0,onSelect:()=>d.request(`update`)}]:l.state===`reload-needed`?[{label:`Reload to finish the update`,icon:Vs,opensDialog:!0,onSelect:()=>d.request(`reload`)}]:[],p={label:`Refresh`,icon:zs,disabled:c,onSelect:()=>void s()};async function h(){try{await navigator.clipboard.writeText(location.origin+location.pathname+location.search),o.show({title:`Link copied`})}catch{o.show({title:`Could not copy the link. Copy it from the address bar.`,tone:`danger`})}}let _={label:`Devices`,icon:Zs,asChild:!0,children:(0,$.jsx)(co,{to:`/devices`,children:`Devices`})},v=e?[...f,p,{label:`Copy link`,icon:Ts,onSelect:()=>void h()},...n?[{label:`Comment on review`,icon:et,onSelect:n}]:[],{separator:!0},...Nc(i),{heading:`Long lines`},{radioGroup:{label:`Long lines`,segmented:!0,value:i.wrap?`wrap`:`scroll`,onValueChange:e=>{(e===`scroll`||e===`wrap`)&&m.update({wrap:e===`wrap`})},items:[{value:`scroll`,label:`Scroll`},{value:`wrap`,label:`Wrap`}]}},{separator:!0},{label:`Inbox`,icon:xs,asChild:!0,children:(0,$.jsx)(co,{to:`/`,children:`Inbox`})},_]:[...f,p,_,{label:`Pair a device`,icon:Ls,asChild:!0,children:(0,$.jsx)(co,{to:`/devices/pair`,onClick:e=>kc(e,a.history.location),children:`Pair a device`})}];return(0,$.jsxs)(`div`,{className:`em-app flex h-dvh min-h-0 flex-col bg-app`,style:{"--reader-prose-size":`${i.proseSize}px`,"--reader-code-size":`${i.codeSize}px`},children:[(0,$.jsxs)(`header`,{className:Z(`flex shrink-0 items-center justify-between border-b border-line-1 bg-app pr-2 pl-4`,r===`phone`?`h-[calc(var(--topbar-h)+env(safe-area-inset-top))] pt-[env(safe-area-inset-top)]`:`h-(--topbar-h)`),children:[r===`phone`&&e?(0,$.jsxs)(co,{to:`/`,className:`inline-flex min-h-11 items-center gap-1 text-13 font-medium text-fg-2 no-underline hover:text-fg-1`,children:[(0,$.jsx)(X,{icon:qo,size:20}),`Inbox`]}):(0,$.jsx)(co,{to:`/`,className:`font-mono text-14 font-medium leading-none font-stretch-mono text-fg-3 no-underline hover:text-fg-1`,children:`emend`}),r===`phone`?(0,$.jsx)($e,{label:`More`,size:`lg`,triggerRef:u,trigger:(0,$.jsx)(Et,{label:`More`,icon:ze,size:`lg`,tooltip:!1}),items:v}):(0,$.jsxs)(`div`,{className:`flex items-center`,children:[(0,$.jsx)(Et,{label:`Refresh`,icon:zs,"aria-busy":c,className:c?`[&>svg]:animate-spin`:void 0,onClick:()=>void s()}),(0,$.jsx)(Et,{label:`Devices`,icon:Zs,asChild:!0,children:(0,$.jsx)(co,{to:`/devices`})})]})]}),(0,$.jsx)(`div`,{role:`status`,children:l.state===`reload-needed`&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3 gap-y-1 border-b border-line-1 bg-sunken py-1.5 pr-2 pl-4 text-13 text-fg-2`,children:[(0,$.jsx)(`p`,{children:`emend was updated in another window. Reload to keep working.`}),(0,$.jsx)(Y,{size:`sm`,icon:Vs,onClick:()=>d.request(`reload`),children:`Reload`})]})}),(0,$.jsx)(Fc.Provider,{value:d.request,children:t}),d.dialog]})}function Uc(e,t){let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=(t-n.getTime())/1e3;return r<60?`now`:r<3600?`${Math.floor(r/60)}m`:r<86400?`${Math.floor(r/3600)}h`:r<604800?new Intl.DateTimeFormat(void 0,{weekday:`short`}).format(n):new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`}).format(n)}function Wc(e){let t=new Date(e);return Number.isNaN(t.getTime())?``:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`}).format(t)}var Gc=864e5;function Kc(e,t){let n=new Date(e).getTime();return!Number.isNaN(n)&&n<=t}function qc(e,t){let n=typeof e==`string`?new Date(e):e;if(Number.isNaN(n.getTime()))return``;let r={hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`},i=new Date(t);return n.getTime()-t>=6*Gc||n.toDateString()!==i.toDateString()&&n.getDay()===i.getDay()?new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,...r}).format(n):new Intl.DateTimeFormat(void 0,{weekday:`short`,...r}).format(n)}function Jc(e){let t=t=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t,9,0,0,0);return[{id:`revision`,label:`Until it changes`},{id:`later`,label:`Later today`,until:new Date(e.getTime()+108e5)},{id:`tomorrow`,label:`Tomorrow morning`,until:t(e.getHours()<5?0:1)},{id:`week`,label:`Next week`,until:t((8-e.getDay())%7||7)}]}function Yc(e,t){let n=new Date(e).getTime();if(Number.isNaN(n))return``;let r=(t-n)/1e3;return r<60?`Checked just now.`:r<3600?`Checked ${Math.floor(r/60)}m ago.`:r<86400?`Checked ${Math.floor(r/3600)}h ago.`:`Checked on ${Uc(e,t)}.`}function Xc(e){switch(e.state){case`unsupported`:return`Updates need the installed app over a secure connection.`;case`checking`:return`Checking for updates…`;case`current`:return`This is the newest version.`;case`available`:return`An update is ready.`;case`updating`:return`Updating…`;case`reload-needed`:return`Another window installed an update. Reload to use it.`;case`error`:return`Could not check for updates: ${e.reason??`the check failed`}.`;default:return``}}function Zc({now:e}){let t=Qt(),n=Ic(),r=Yt(),i=t.state===`checking`||t.state===`updating`,a=t.checkedAt===null?``:Yc(new Date(t.checkedAt).toISOString(),e);return(0,$.jsxs)(`section`,{"aria-labelledby":`app-heading`,className:`mt-10`,children:[(0,$.jsx)(`h2`,{id:`app-heading`,className:`text-18 font-semibold leading-(--lh-snug)`,children:`App`}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3 rounded-lg border border-line-1 bg-surface px-3.5 py-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-60`,children:[(0,$.jsx)(`p`,{className:`text-14 font-semibold`,children:`emend 0.4.0${r?` (${r})`:``}`}),(0,$.jsx)(`p`,{"aria-live":`polite`,className:`mt-0.5 text-12 text-fg-3`,children:Xc(t)}),a&&t.state!==`unsupported`&&(0,$.jsx)(`p`,{className:`text-12 text-fg-3`,children:a})]}),t.state===`available`&&(0,$.jsx)(Y,{size:`sm`,variant:`primary`,icon:as,onClick:()=>n(`update`),children:`Update now`}),t.state===`reload-needed`&&(0,$.jsx)(Y,{size:`sm`,variant:`primary`,icon:Vs,onClick:()=>n(`reload`),children:`Reload`}),t.state!==`unsupported`&&(0,$.jsx)(Y,{size:`sm`,icon:zs,"aria-disabled":i,onClick:()=>{i||Xt.checkForUpdate()},children:`Check for update`})]})]})}function Qc(){let e=g(),t=Ct(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(Date.now),o=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=window.setInterval(()=>a(Date.now()),6e4);return()=>window.clearInterval(e)},[]);let s=c({queryKey:[`devices`],queryFn:({signal:e})=>l(`/api/v1/devices`,le,e)});async function u(){r(null),await t.invalidateQueries({queryKey:[`devices`]})}let d=ct({mutationFn:e=>lt(`/api/v1/devices/${e.id}`,`DELETE`),onSuccess:async(e,n)=>{n.current?(t.clear(),window.location.assign(`/pair`)):await u()},onError:async e=>{e instanceof G&&e.status===404&&await u()},onSettled:()=>{o.current=!1}});return(0,$.jsxs)(Hc,{children:[(0,$.jsx)(`main`,{className:`relative min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-[760px] px-5 pt-8 pb-20`,children:[(0,$.jsxs)(`div`,{className:`mb-5 flex flex-wrap items-start justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-80`,children:[(0,$.jsx)(`h1`,{className:`text-24 font-semibold leading-(--lh-tight) tracking-(--tracking-tight)`,children:`Devices`}),(0,$.jsx)(`p`,{className:`mt-1 text-14 text-fg-3`,children:`Browsers and machines that can use this hub. Sign-ins last 30 days and renew while in use.`})]}),(0,$.jsx)(Y,{asChild:!0,variant:`primary`,icon:Ls,children:(0,$.jsx)(co,{to:`/devices/pair`,onClick:t=>kc(t,e.history.location),children:`Pair a device`})})]}),s.isPending&&(0,$.jsx)(`p`,{role:`status`,children:`Loading devices…`}),s.isError&&(0,$.jsx)(`p`,{role:`alert`,children:`Could not load devices. Try again.`}),s.data?.items.length===0&&(0,$.jsx)(`p`,{className:`text-14 text-fg-3`,children:`No paired devices.`}),!!s.data?.items.length&&(0,$.jsx)(`ul`,{className:`divide-y divide-line-1 rounded-lg border border-line-1 bg-surface`,children:s.data.items.map(e=>(0,$.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3.5 py-3`,children:[(0,$.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-lg bg-sunken text-fg-2`,children:(0,$.jsx)(X,{icon:e.kind===`browser`?js:qs,size:18})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-36`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,$.jsx)(`p`,{className:`min-w-0 text-14 font-semibold wrap-anywhere`,children:e.name}),e.current&&(0,$.jsx)(`span`,{className:`rounded-sm border border-line-1 bg-sunken px-1.5 py-0.5 text-11 font-medium text-fg-2`,children:`This device`})]}),(0,$.jsxs)(`p`,{className:`mt-0.5 text-12 text-fg-3`,children:[e.kind===`browser`?`Browser · paired `:`Machine · attached `,(0,$.jsx)(`time`,{dateTime:e.createdAt,children:new Date(e.createdAt).toLocaleDateString()})]})]}),(0,$.jsxs)(`p`,{className:`text-12 text-fg-3`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:`Last seen: `}),e.lastSeenAt?(0,$.jsx)(`time`,{dateTime:e.lastSeenAt,children:Uc(e.lastSeenAt,i)}):`never`]}),(0,$.jsx)(Y,{size:`sm`,variant:e.current?`ghost`:`danger`,icon:e.current?ks:void 0,disabled:d.isPending,onClick:()=>{d.reset(),r(e)},children:e.current?`Sign out`:`Revoke`})]},e.id))}),(0,$.jsx)(Zc,{now:i})]})}),n&&(0,$.jsx)(St,{open:!0,onOpenChange:e=>{!e&&!o.current&&r(null)},title:n.current?`Sign out of this browser?`:`Revoke ${n.name}?`,description:n.current?`You will need a new code to sign in again.`:n.kind===`browser`?`It signs out now and needs a new code to pair again.`:`It loses access to this hub now and needs a new code to attach again.`,actions:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{"data-autofocus":!0,variant:`ghost`,disabled:d.isPending,onClick:()=>r(null),children:`Cancel`}),(0,$.jsx)(Y,{variant:`danger`,disabled:d.isPending,onClick:()=>{o.current||(o.current=!0,d.mutate(n))},children:n.current?`Sign out`:`Revoke`})]}),children:d.isError&&(0,$.jsx)(`p`,{role:`alert`,className:`mt-4 text-13 text-danger-fg`,children:`Could not revoke the device. Try again.`})}),(0,$.jsx)(wo,{})]})}var $c=()=>on({queryKey:[`inbox`],queryFn:({signal:e})=>l(`/api/v1/reviews`,j,e)}),el=e=>on({queryKey:[`review`,e],queryFn:({signal:t})=>l(`/api/v1/reviews/${encodeURIComponent(e)}`,te,t)}),tl=(e,t)=>on({queryKey:[`revision`,e,t],queryFn:({signal:n,client:r})=>F(r).fetch(e,t,n,()=>l(`/api/v1/reviews/${encodeURIComponent(e)}/revisions/${t}`,fe,n)),staleTime:1/0});function nl(e){return e.state===`approved`?`approved`:e.agentWaiting?`waiting`:e.pendingSend?`pending`:e.pickedUpAt?`pickedUp`:null}var rl={approved:`Approved`,waiting:`Agent waiting`,pending:`Not picked up yet`,pickedUp:`Picked up`},il={waiting:`bg-agent-waiting text-agent-waiting animate-[em-pulse_var(--dur-pulse)_var(--ease-out)_infinite]`,pending:`border-[1.5px] border-agent-none`,pickedUp:`bg-agent-none`};function al(e,t,n){let r=rl[e],i=e===`pickedUp`&&t?Uc(t,n):``;return i?`${r} ${i}`:r}function ol({status:e,pickedUpAt:t=null,now:n=Date.now(),pill:r=!1,className:i}){if(!e)return null;let a=e===`pickedUp`&&t?Uc(t,n):``;return(0,$.jsxs)(`span`,{className:Z(`inline-flex items-center gap-1.5 whitespace-nowrap text-12 font-medium leading-[1.2]`,e===`approved`?`text-success-fg`:e===`waiting`?`text-fg-1`:`text-fg-2`,r&&`h-6 rounded-full border border-line-1 bg-surface pr-[9px] pl-2`,i),children:[e===`approved`?(0,$.jsx)(X,{icon:Bt,size:13,strokeWidth:2.25}):(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Z(`size-2 shrink-0 rounded-full`,il[e])}),(0,$.jsx)(`span`,{children:rl[e]}),a&&(0,$.jsx)(`time`,{dateTime:t??void 0,children:a})]})}var sl=[[`bg-origin-1-bg text-origin-1-fg`,`bg-origin-1-fg`],[`bg-origin-2-bg text-origin-2-fg`,`bg-origin-2-fg`],[`bg-origin-3-bg text-origin-3-fg`,`bg-origin-3-fg`],[`bg-origin-4-bg text-origin-4-fg`,`bg-origin-4-fg`],[`bg-origin-5-bg text-origin-5-fg`,`bg-origin-5-fg`],[`bg-origin-6-bg text-origin-6-fg`,`bg-origin-6-fg`],[`bg-origin-7-bg text-origin-7-fg`,`bg-origin-7-fg`],[`bg-origin-8-bg text-origin-8-fg`,`bg-origin-8-fg`]];function cl({origin:e,size:t=`md`,dot:n=!1,className:r}){let i=0;for(let t of e.id)i=Math.imul(i,31)+t.charCodeAt(0)>>>0;let a=sl[i%sl.length];return n?(0,$.jsx)(`span`,{role:`img`,"aria-label":`From ${e.name}`,className:Z(`inline-block size-2 shrink-0 rounded-[2px]`,a?.[1],r)}):(0,$.jsx)(`span`,{title:`From ${e.name}`,className:Z(`inline-flex shrink-0 items-center whitespace-nowrap rounded-sm pr-1.5 pl-[5px] font-mono font-medium leading-none font-stretch-mono`,t===`sm`?`h-[18px] text-[10px]`:`h-5 text-[10.5px]`,a?.[0],r),children:e.name})}var ll={open:{icon:$o,label:`Open`,pill:`bg-state-open-bg text-state-open-fg`,inline:`text-state-open-fg`},approved:{icon:Zo,label:`Approved`,pill:`bg-state-approved-bg text-state-approved-fg`,inline:`text-success-fg`},settled:{icon:Go,label:`Retired`,pill:`bg-state-settled-bg text-state-settled-fg inset-ring-1 inset-ring-line-1`,inline:`text-fg-3`}};function ul({state:e,revision:t,variant:n=`pill`}){let r=ll[e];return(0,$.jsxs)(`span`,{className:Z(`inline-flex shrink-0 items-center gap-1 whitespace-nowrap text-11 leading-none`,n===`pill`?[`h-5 rounded-full pr-[7px] pl-[5px] font-semibold tracking-[.01em]`,r.pill]:[`font-medium`,r.inline]),children:[(0,$.jsx)(X,{icon:r.icon,size:n===`pill`?12:11,strokeWidth:2}),r.label,e===`approved`&&t!=null?` · rev ${t}`:``]})}function dl(e){return e.state===`open`&&!e.snoozed&&!e.movedTo&&(e.agentWaiting||e.unsentCount>0)}function fl({review:e,now:t,onOpen:n,highlight:r=!1}){let i=dl(e),a=nl(e),o=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`col-start-1 row-start-1 flex min-w-0 items-center gap-1.5 text-11 leading-[1.2] text-fg-3`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`inline-flex [&>span]:size-[7px] [&>span]:opacity-85`,children:(0,$.jsx)(cl,{origin:e.origin,dot:!0})}),(0,$.jsx)(`span`,{className:`truncate`,children:e.origin.name})]}),(0,$.jsx)(`span`,{className:`col-start-2 row-start-1 inline-flex items-center whitespace-nowrap text-12 font-normal text-fg-3 tabular-nums`,children:e.snoozed?e.snoozedUntil?Kc(e.snoozedUntil,t)?(0,$.jsx)(`span`,{children:`waking up`}):(0,$.jsxs)(`time`,{dateTime:e.snoozedUntil,title:new Date(e.snoozedUntil).toLocaleString(),children:[`until `,qc(e.snoozedUntil,t)]}):(0,$.jsx)(`span`,{children:`until it changes`}):e.state===`open`?(0,$.jsx)(`time`,{dateTime:e.updatedAt,title:new Date(e.updatedAt).toLocaleString(),children:Uc(e.updatedAt,t)}):(0,$.jsx)(ul,{state:e.state,variant:`inline`})}),(0,$.jsxs)(`span`,{className:Z(`relative col-span-2 row-start-2 min-w-0 text-13 leading-[1.35] font-[450] group-aria-[current=page]:font-medium group-aria-[current=page]:text-fg-1`,i&&`font-medium text-fg-1`),children:[i&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`absolute top-1/2 -left-2.5 size-[5px] -translate-y-1/2 rounded-full bg-accent`}),(0,$.jsxs)(`span`,{className:`block truncate`,children:[i&&(0,$.jsx)(`span`,{className:`sr-only`,children:`Needs you. `}),e.title]})]}),(0,$.jsx)(`span`,{className:`col-start-1 row-start-3 truncate font-mono text-11 leading-[1.3] font-stretch-mono text-fg-3`,children:e.movedTo?`Moved to ${new URL(e.movedTo).host}`:e.branch}),!e.movedTo&&(0,$.jsxs)(`span`,{className:`col-start-2 row-start-3 flex items-center justify-end gap-2 text-11 font-medium leading-none text-fg-3 tabular-nums`,children:[e.openThreads>0&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-[3px]`,children:[(0,$.jsx)(X,{icon:mt,size:11}),e.openThreads,(0,$.jsx)(`span`,{className:`sr-only`,children:w(e.openThreads,` open thread`)})]}),e.unsentCount>0&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-[3px] text-accent-text`,children:[(0,$.jsx)(X,{icon:bt,size:11}),e.unsentCount,(0,$.jsx)(`span`,{className:`sr-only`,children:` unsent`})]}),a&&a!==`approved`&&(0,$.jsx)(`span`,{role:`img`,"aria-label":al(a,e.pickedUpAt,t),className:Z(`size-[7px] shrink-0 rounded-full`,il[a])})]})]}),s=Z(`group relative grid w-full grid-cols-[minmax(0,1fr)_auto] grid-rows-[auto_auto_auto] gap-x-2 gap-y-[3px] rounded-sm px-2.5 pt-2 pb-[9px] text-left text-fg-2 no-underline`,r&&`em-inbox-new`);return(0,$.jsx)(`li`,{children:e.movedTo?(0,$.jsx)(`div`,{className:Z(s,`opacity-50`),"aria-disabled":`true`,children:o}):(0,$.jsx)(co,{to:`/r/$reviewId`,params:{reviewId:e.id},search:{rev:e.newestRevision},activeOptions:{includeSearch:!1},activeProps:{"aria-current":`page`},onClick:e=>{e.defaultPrevented||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||n?.()},className:Z(s,`hover:bg-hover hover:text-fg-2 aria-[current=page]:bg-active`,e.list===`done`&&`opacity-60 hover:opacity-100 focus-within:opacity-100 aria-[current=page]:opacity-100`),children:o})})}var pl=`flex min-w-0 flex-col gap-1.5`,ml=`font-sans text-13 font-medium leading-(--lh-snug) text-fg-1`,hl=`box-border w-full rounded-md border border-line-2 bg-surface px-2.5 font-sans text-14 font-normal leading-(--lh-body) text-fg-1 shadow-inset transition-[border-color,box-shadow] duration-(--dur-1) ease-(--ease-out) placeholder:text-fg-3 enabled:hover:border-line-strong focus:border-line-focus focus:outline-none focus:shadow-[0_0_0_3px_var(--accent-tint-2)] disabled:cursor-not-allowed disabled:bg-sunken disabled:text-fg-disabled aria-invalid:border-danger-solid aria-invalid:focus:shadow-[0_0_0_3px_var(--danger-bg)]`,gl={sm:`h-7 rounded-sm text-13`,md:`h-8`,lg:`h-10 text-15`};function _l(e,t,n,r){let i=(0,Q.useId)(),a=e??i,o=`${a}-description`;return{id:a,messageId:o,describedBy:[r,(t||n)&&o].filter(Boolean).join(` `)||void 0}}function vl({id:e,hint:t,error:n}){return n?(0,$.jsxs)(`span`,{id:e,role:`alert`,className:`flex items-center gap-[5px] font-sans text-12 font-normal leading-(--lh-snug) text-danger-fg`,children:[(0,$.jsx)(X,{icon:Yo,size:13}),n]}):t?(0,$.jsx)(`span`,{id:e,className:`font-sans text-12 font-normal leading-(--lh-snug) text-fg-3`,children:t}):null}function yl({label:e,hint:t,options:n,size:r=`md`,id:i,className:a,...o}){let s=_l(i,t,void 0,o[`aria-describedby`]);return(0,$.jsxs)(`div`,{className:Z(pl,a),children:[e&&(0,$.jsx)(`label`,{htmlFor:s.id,className:`font-sans text-13 font-medium leading-(--lh-snug) text-fg-1`,children:e}),(0,$.jsxs)(`div`,{className:`relative flex items-center`,children:[(0,$.jsx)(`select`,{...o,id:s.id,"aria-describedby":s.describedBy,className:Z(hl,`appearance-none pr-[30px] font-sans text-13 font-medium font-[450]`,gl[r],`leading-(--lh-snug)`),children:n.map(e=>typeof e==`string`?(0,$.jsx)(`option`,{value:e,children:e},e):(0,$.jsx)(`option`,{value:e.value,disabled:e.disabled,children:e.label},e.value))}),(0,$.jsx)(X,{icon:p,size:14,className:`pointer-events-none absolute right-2 text-fg-3`})]}),(0,$.jsx)(vl,{id:s.messageId,hint:t})]})}function bl({label:e,hint:t,error:n,icon:r,size:i=`md`,mono:a=!1,id:o,className:s,...c}){let l=_l(o,t,n,c[`aria-describedby`]);return(0,$.jsxs)(`div`,{className:Z(pl,s),children:[e&&(0,$.jsx)(`label`,{htmlFor:l.id,className:`font-sans text-13 font-medium leading-(--lh-snug) text-fg-1`,children:e}),(0,$.jsxs)(`div`,{className:`relative flex items-center`,children:[r&&(0,$.jsx)(X,{icon:r,size:14,className:`pointer-events-none absolute left-[9px] text-fg-3`}),(0,$.jsx)(`input`,{...c,id:l.id,"aria-invalid":n?!0:c[`aria-invalid`],"aria-describedby":l.describedBy,className:Z(hl,a&&`font-mono text-12 font-normal font-stretch-mono`,gl[i],a?`leading-[1.6]`:`leading-(--lh-body)`,r&&`pl-[30px]`)})]}),(0,$.jsx)(vl,{id:l.messageId,hint:t,error:n})]})}var xl=2**31-1,Sl=500;function Cl(e,t){let n=(0,Q.useRef)(t);n.current=t;let[r,i]=(0,Q.useState)(0),a=e.join(`|`);(0,Q.useEffect)(()=>{let t=Date.now(),r=e.map(e=>e?new Date(e).getTime():NaN).filter(e=>e>t-Sl);if(r.length===0)return;let a=Math.min(...r),o=setTimeout(()=>{let t=Date.now(),r=e.filter(e=>!!e&&new Date(e).getTime()<=t);r.length>0&&n.current(r),i(e=>e+1)},Math.min(Math.max(a-t,0)+Sl,xl));return()=>clearTimeout(o)},[a,r])}var wl=[{list:`active`,title:`Active`},{list:`snoozed`,title:`Snoozed`},{list:`done`,title:`Done`}],Tl=`emend:inbox-kind`;function El(){try{let e=localStorage.getItem(Tl);return e===`review`||e===`publish`?e:``}catch{return``}}function Dl({compact:e=!1,currentReviewId:t,hideHead:n=!1,onCollapse:r,onOpen:i}){let a=c($c()),[o,s]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(El),m=e=>{f(e);try{e?localStorage.setItem(Tl,e):localStorage.removeItem(Tl)}catch{}},[h,g]=(0,Q.useState)(Date.now),[_,v]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=window.setInterval(()=>g(Date.now()),6e4);return()=>window.clearInterval(e)},[]);let y=a.data?.items??[],b=Ct();Cl(y.map(e=>e.snoozedUntil),e=>{g(Date.now()),b.invalidateQueries({queryKey:[`inbox`]});for(let t of y)t.snoozedUntil&&e.includes(t.snoozedUntil)&&b.invalidateQueries({queryKey:[`review`,t.id]})});let x=[...new Map(y.map(({origin:e})=>[e.id,e])).values()].sort((e,t)=>e.name.localeCompare(t.name)),S=!e&&x.length>1&&x.some(e=>e.id===l)?l:``,C=o.toLocaleLowerCase(),T=y.filter(n=>(!S||n.origin.id===S)&&(!d||n.kind===d||d===`review`&&n.agentWaiting||e&&n.id===t)&&[n.title,n.branch,n.origin.name].some(e=>e?.toLocaleLowerCase().includes(C))),E=wc(y),D=e?`h3`:`h2`,O=y.filter(dl).length;return(0,$.jsxs)(`div`,{className:e?`flex min-h-0 flex-1 flex-col`:`mx-auto w-full max-w-[760px] px-5 pt-8 pb-20`,children:[!n&&(e?(0,$.jsxs)(`div`,{className:`flex items-center justify-between pt-2.5 pr-2 pb-1.5 pl-4`,children:[(0,$.jsx)(`h2`,{className:`text-13 font-medium leading-[1.2] text-fg-2`,children:`Inbox`}),(0,$.jsx)(Et,{label:`Collapse inbox`,icon:Ns,size:`sm`,onClick:r})]}):(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-baseline gap-x-3`,children:[(0,$.jsx)(`h1`,{className:`text-24 font-semibold leading-(--lh-tight) tracking-(--tracking-tight)`,children:`Inbox`}),a.data&&(0,$.jsxs)(`p`,{className:`mt-1 text-14 text-fg-3`,children:[O?`${O} ${w(O,`needs`,`need`)} you`:`Nothing needs you`,` ·`,` `,x.length,` `,w(x.length,`machine`)]})]})),(0,$.jsxs)(`div`,{className:e?`flex flex-col gap-2 px-2.5 pb-2`:`mb-3 flex flex-wrap items-center gap-2.5`,children:[(0,$.jsx)(bl,{"aria-label":`Filter reviews`,placeholder:`Filter by title, branch, machine`,icon:Us,size:`sm`,value:o,onChange:e=>s(e.target.value),className:e?`min-w-0`:`min-w-0 flex-[1_1_16rem]`}),y.length>0&&(0,$.jsx)(tt,{label:`Kind`,size:`sm`,className:e?`w-full [&>button]:flex-1 [&>button]:justify-center`:`max-w-full shrink-0`,value:d,onChange:e=>{(e===``||e===`review`||e===`publish`)&&m(e)},options:[{value:``,label:`All`},{value:`review`,label:`Reviews`},{value:`publish`,label:`Pubs`}]}),!e&&x.length>1&&(0,$.jsx)(yl,{"aria-label":`Machine`,size:`sm`,className:`min-w-0 max-w-full`,value:S,onChange:e=>u(e.target.value),options:[{value:``,label:`All machines`},...x.map(e=>({value:e.id,label:e.name}))]})]}),(0,$.jsxs)(`div`,{className:e?`relative min-h-0 flex-1 overflow-y-auto px-1.5 pt-1 pb-3`:`py-1`,children:[a.isPending&&(0,$.jsx)(`p`,{role:`status`,className:`p-4`,children:`Loading reviews…`}),a.isError&&(0,$.jsxs)(`div`,{className:`p-4`,children:[(0,$.jsx)(`p`,{role:`alert`,children:`Could not load reviews.`}),(0,$.jsx)(Y,{onClick:()=>void a.refetch(),children:`Retry`})]}),a.data&&y.length===0&&(0,$.jsx)(`p`,{className:`p-4 text-fg-3`,children:`No reviews yet.`}),y.length>0&&T.length===0&&(0,$.jsxs)(`div`,{className:`p-4`,children:[(0,$.jsx)(`p`,{className:`text-fg-3`,children:`No reviews match this filter.`}),(0,$.jsx)(Y,{variant:`ghost`,onClick:()=>{s(``),u(``),m(``)},children:`Clear filter`})]}),a.data&&y.length>0&&T.length>0&&wl.map(({list:e,title:t})=>{let n=T.filter(t=>t.list===e),r=e===`active`&&!y.some(e=>e.list===`active`);if(n.length===0&&!r)return null;let a=e!==`done`||_||C!==``,o=(0,$.jsxs)($.Fragment,{children:[t,(0,$.jsx)(`span`,{className:`ml-1.5 font-normal tabular-nums text-fg-3`,children:n.length})]});return(0,$.jsxs)(`section`,{"aria-label":t,children:[(0,$.jsx)(D,{className:`m-0 px-2.5 pt-3 pb-1 font-mono text-11 font-medium leading-(--lh-snug) font-stretch-mono tracking-(--tracking-label) text-fg-3 uppercase`,children:e===`done`&&C===``?(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":a,className:`inline-flex cursor-pointer items-center gap-1 border-0 bg-transparent p-0 font-[inherit] text-[inherit] uppercase`,onClick:()=>v(!_),children:[(0,$.jsx)(X,{icon:a?p:me,size:12}),o]}):o}),r&&(0,$.jsx)(`p`,{className:`px-2.5 py-2 text-13 text-fg-3`,children:`No active reviews.`}),a&&n.length>0&&(0,$.jsx)(`ul`,{children:n.map(e=>(0,$.jsx)(fl,{review:e,now:h,onOpen:i,highlight:E.has(e.id)},e.id))})]},e)})]})]})}function Ol(){return(0,$.jsx)(Hc,{children:(0,$.jsx)(`main`,{className:`relative min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsx)(Dl,{})})})}function kl(e){let t=e.toUpperCase().replace(/O/g,`0`).replace(/[IL]/g,`1`).replace(/[^0-9A-HJKMNP-TV-Z]/g,``).slice(0,8);return t.length>4?`${t.slice(0,4)}-${t.slice(4)}`:t}function Al({value:e,defaultValue:t=``,onChange:n,error:r,label:i=`Pairing code`,id:a,className:o,onPaste:s,...c}){let[l,u]=(0,Q.useState)(()=>kl(t)),d=e===void 0?l:kl(e),f=(0,Q.useRef)(null);(0,Q.useLayoutEffect)(()=>{let e=f.current;f.current=null,e?.value===d&&e.input.setSelectionRange(e.caret,e.caret)});let p=_l(a,void 0,r,c[`aria-describedby`]);function m(t,r,i){if(t.value=d,c.readOnly||c.disabled)return;let a=kl(r),o=kl(r.slice(0,i)).length,s={input:t,value:a,caret:o};f.current=s,a===d&&t.setSelectionRange(o,o),e===void 0&&u(a),n?.(a),queueMicrotask(()=>{f.current===s&&(f.current=null)})}return(0,$.jsxs)(`div`,{className:Z(pl,o),children:[(0,$.jsx)(`label`,{htmlFor:p.id,className:ml,children:i}),(0,$.jsx)(`input`,{...c,id:p.id,"data-own-size":!0,type:`text`,value:d,maxLength:9,pattern:`[0-9A-HJKMNP-TV-Z]{4}-[0-9A-HJKMNP-TV-Z]{4}`,autoComplete:`one-time-code`,inputMode:`text`,autoCapitalize:`characters`,spellCheck:!1,placeholder:c.placeholder??`XXXX-XXXX`,"aria-invalid":r?!0:c[`aria-invalid`],"aria-describedby":p.describedBy,onChange:e=>m(e.currentTarget,e.currentTarget.value,e.currentTarget.selectionStart??e.currentTarget.value.length),onPaste:e=>{if(c.readOnly||c.disabled){e.preventDefault();return}if(s?.(e),e.defaultPrevented)return;e.preventDefault();let t=e.currentTarget,n=t.selectionStart??t.value.length,r=t.selectionEnd??n,i=e.clipboardData.getData(`text`);m(t,t.value.slice(0,n)+i+t.value.slice(r),n+i.length)},className:`box-border h-[60px] w-full rounded-lg border border-line-2 bg-surface px-3 text-center font-mono text-[26px] leading-none font-semibold font-stretch-mono tracking-[0.16em] text-fg-1 uppercase shadow-inset placeholder:text-fg-disabled focus:border-line-focus focus:outline-none focus:shadow-[0_0_0_3px_var(--accent-tint-2)] disabled:cursor-not-allowed disabled:bg-sunken disabled:text-fg-disabled aria-invalid:border-danger-solid aria-invalid:focus:shadow-[0_0_0_3px_var(--danger-bg)]`}),(0,$.jsx)(vl,{id:p.messageId,error:r})]})}function jl(){let e=[`127.0.0.1`,`localhost`,`[::1]`,`::1`].includes(window.location.hostname),t=qa(),n=Ct(),[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),l=(0,Q.useRef)(null),u=(0,Q.useRef)(new Set);(0,Q.useEffect)(()=>{s&&!a&&l.current?.focus()},[s,a]);let d=(0,Q.useCallback)(async e=>{o(!0),c(``);try{await H(e),n.clear(),await t({to:`/`,replace:!0})}catch(e){c(e instanceof G&&e.status===429?`Too many wrong codes. Wait 10 minutes, then try again.`:e instanceof G&&(e.status===401||e.status===400)?`That code did not work. Check it on the hub and try again.`:`Could not pair. Check your connection and try again.`)}finally{o(!1)}},[n,t]);return(0,Q.useEffect)(()=>{let e=()=>{let e=$t();e&&!u.current.has(e)&&(u.current.add(e),d({secret:e}))},t=Zt(e);return e(),t},[d]),(0,$.jsxs)(`main`,{className:`mx-auto flex min-h-dvh w-full max-w-md flex-col gap-5 px-6 pt-14 pb-6`,children:[(0,$.jsx)(`p`,{className:`mb-3 font-mono text-30 font-medium leading-none font-stretch-mono text-fg-1`,children:`emend`}),(0,$.jsx)(`h1`,{className:`text-24 font-semibold leading-(--lh-tight) tracking-(--tracking-tight)`,children:e?`Sign in`:`Pair this device`}),e?(0,$.jsxs)($.Fragment,{children:[a?(0,$.jsx)(`p`,{role:`status`,children:`Pairing…`}):(0,$.jsxs)(`p`,{className:`text-15 text-fg-2`,children:[`Run `,(0,$.jsx)(`code`,{children:`emend`}),` in a terminal on the machine that runs emend. It opens this page signed in, or prints a one-time link you can open here.`]}),s&&(0,$.jsx)(`p`,{role:`alert`,className:`text-13 text-danger-fg`,children:s})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`text-15 text-fg-2`,children:`On a browser that is already signed in, open Devices, choose Pair a device, and type the code it shows here.`}),(0,$.jsx)(`p`,{className:`text-12 text-fg-3`,children:`The app on your home screen pairs once more with a code, even after Safari has paired.`}),(0,$.jsxs)(`form`,{className:`space-y-5`,onSubmit:e=>{e.preventDefault(),!a&&r.replace(/-/g,``).length===8&&d({code:r})},children:[(0,$.jsx)(Al,{ref:l,id:`pairing-code`,label:`Pairing code`,value:r,onChange:e=>{i(e),c(``)},error:s,required:!0,disabled:a}),(0,$.jsx)(Y,{type:`submit`,disabled:a||r.replace(/-/g,``).length!==8,variant:`primary`,size:`lg`,fullWidth:!0,children:`Pair`}),a&&(0,$.jsx)(`p`,{role:`status`,children:`Pairing…`})]})]})]})}var Ml=(e=>(e[e.Border=-1]=`Border`,e[e.Data=0]=`Data`,e[e.Function=1]=`Function`,e[e.Position=2]=`Position`,e[e.Timing=3]=`Timing`,e[e.Alignment=4]=`Alignment`,e))(Ml||{}),Nl=[0,1],Pl=[1,0],Fl=[2,3],Il=[3,2],Ll={L:Nl,M:Pl,Q:Fl,H:Il},Rl=/^\d*$/,zl=/^[A-Z0-9 $%*+./:-]*$/,Bl=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,Vl=1,Hl=40,Ul=3,Wl=3,Gl=40,Kl=10,ql=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],Jl=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],Yl=class{constructor(e,t,n,r){if(this.version=e,this.ecc=t,e<Vl||e>Hl)throw RangeError(`Version value out of range`);if(r<-1||r>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let i=Array.from({length:this.size}).fill(!1);for(let e=0;e<this.size;e++)this.modules.push(i.slice()),this.types.push(i.map(()=>0));this.drawFunctionPatterns();let a=this.addEccAndInterleave(n);if(this.drawCodewords(a),r===-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(r=t,e=n),this.applyMask(t)}}this.mask=r,this.applyMask(r),this.drawFormatBits(r)}size;mask;modules=[];types=[];getModule(e,t){return e>=0&&e<this.size&&t>=0&&t<this.size&&this.modules[t][e]}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0,Ml.Timing),this.setFunctionModule(e,6,e%2==0,Ml.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n===0&&r===0||n===0&&r===t-1||n===t-1&&r===0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.ecc[1]<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let r=(t<<10|n)^21522;for(let e=0;e<=5;e++)this.setFunctionModule(8,e,Zl(r,e));this.setFunctionModule(8,7,Zl(r,6)),this.setFunctionModule(8,8,Zl(r,7)),this.setFunctionModule(7,8,Zl(r,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,Zl(r,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,Zl(r,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,Zl(r,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;for(let e=0;e<18;e++){let n=Zl(t,e),r=this.size-11+e%3,i=Math.floor(e/3);this.setFunctionModule(r,i,n),this.setFunctionModule(i,r,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;a>=0&&a<this.size&&o>=0&&o<this.size&&this.setFunctionModule(a,o,i!==2&&i!==4,Ml.Position)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!==1,Ml.Alignment)}setFunctionModule(e,t,n,r=Ml.Function){this.modules[t][e]=n,this.types[t][e]=r}addEccAndInterleave(e){let t=this.version,n=this.ecc;if(e.length!==fu(t,n))throw RangeError(`Invalid argument`);let r=Jl[n[0]][t],i=ql[n[0]][t],a=Math.floor(du(t)/8),o=r-a%r,s=Math.floor(a/r),c=[],l=pu(i);for(let t=0,n=0;t<r;t++){let r=e.slice(n,n+s-i+(t<o?0:1));n+=r.length;let a=mu(r,l);t<o&&r.push(0),c.push(r.concat(a))}let u=[];for(let e=0;e<c[0].length;e++)c.forEach((t,n)=>{(e!==s-i||n>=o)&&u.push(t[e])});return u}drawCodewords(e){if(e.length!==Math.floor(du(this.version)/8))throw RangeError(`Invalid argument`);let t=0;for(let n=this.size-1;n>=1;n-=2){n===6&&(n=5);for(let r=0;r<this.size;r++)for(let i=0;i<2;i++){let a=n-i,o=n+1&2?r:this.size-1-r;!this.types[o][a]&&t<e.length*8&&(this.modules[o][a]=Zl(e[t>>>3],7-(t&7)),t++)}}}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.types[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[t][a]===n?(r++,r===5?e+=Ul:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*Gl),n=this.modules[t][a],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*Gl}for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[a][t]===n?(r++,r===5?e+=Ul:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*Gl),n=this.modules[a][t],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*Gl}for(let t=0;t<this.size-1;t++)for(let n=0;n<this.size-1;n++){let r=this.modules[t][n];r===this.modules[t][n+1]&&r===this.modules[t+1][n]&&r===this.modules[t+1][n+1]&&(e+=Wl)}let t=0;for(let e of this.modules)t=e.reduce((e,t)=>e+ +!!t,t);let n=this.size*this.size,r=Math.ceil(Math.abs(t*20-n*10)/n)-1;return e+=r*Kl,e}getAlignmentPatternPositions(){if(this.version===1)return[];{let e=Math.floor(this.version/7)+2,t=this.version===32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}finderPenaltyCountPatterns(e){let t=e[1],n=t>0&&e[2]===t&&e[3]===t*3&&e[4]===t&&e[5]===t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]===0&&(e+=this.size),t.pop(),t.unshift(e)}};function Xl(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function Zl(e,t){return!!(e>>>t&1)}var Ql=class{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}getData(){return this.bitData.slice()}},$l=[1,10,12,14],eu=[2,9,11,13],tu=[4,8,16,16];function nu(e,t){return e[Math.floor((t+7)/17)+1]}function ru(e){let t=[];for(let n of e)Xl(n,8,t);return new Ql(tu,e.length,t)}function iu(e){if(!su(e))throw RangeError(`String contains non-numeric characters`);let t=[];for(let n=0;n<e.length;){let r=Math.min(e.length-n,3);Xl(Number.parseInt(e.substring(n,n+r),10),r*3+1,t),n+=r}return new Ql($l,e.length,t)}function au(e){if(!cu(e))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let t=[],n=0;for(;n+2<=e.length;n+=2){let r=Bl.indexOf(e.charAt(n))*45;r+=Bl.indexOf(e.charAt(n+1)),Xl(r,11,t)}return n<e.length&&Xl(Bl.indexOf(e.charAt(n)),6,t),new Ql(eu,e.length,t)}function ou(e){return e===``?[]:su(e)?[iu(e)]:cu(e)?[au(e)]:[ru(uu(e))]}function su(e){return Rl.test(e)}function cu(e){return zl.test(e)}function lu(e,t){let n=0;for(let r of e){let e=nu(r.mode,t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}function uu(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)===`%`?(t.push(Number.parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}function du(e){if(e<Vl||e>Hl)throw RangeError(`Version number out of range`);let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}function fu(e,t){return Math.floor(du(e)/8)-ql[t[0]][e]*Jl[t[0]][e]}function pu(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let t=[];for(let n=0;n<e-1;n++)t.push(0);t.push(1);let n=1;for(let r=0;r<e;r++){for(let e=0;e<t.length;e++)t[e]=hu(t[e],n),e+1<t.length&&(t[e]^=t[e+1]);n=hu(n,2)}return t}function mu(e,t){let n=t.map(e=>0);for(let r of e){let e=r^n.shift();n.push(0),t.forEach((t,r)=>n[r]^=hu(t,e))}return n}function hu(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return n}function gu(e,t,n=1,r=40,i=-1,a=!0){if(!(Vl<=n&&n<=r&&r<=Hl)||i<-1||i>7)throw RangeError(`Invalid value`);let o,s;for(o=n;;o++){let n=fu(o,t)*8,i=lu(e,o);if(i<=n){s=i;break}if(o>=r)throw RangeError(`Data too long`)}for(let e of[Pl,Fl,Il])a&&s<=fu(o,e)*8&&(t=e);let c=[];for(let t of e){Xl(t.mode[0],4,c),Xl(t.numChars,nu(t.mode,o),c);for(let e of t.getData())c.push(e)}let l=fu(o,t)*8;Xl(0,Math.min(4,l-c.length),c),Xl(0,(8-c.length%8)%8,c);for(let e=236;c.length<l;e^=253)Xl(e,8,c);let u=Array.from({length:Math.ceil(c.length/8)},()=>0);return c.forEach((e,t)=>u[t>>>3]|=e<<7-(t&7)),new Yl(o,t,u,i)}function _u(e,t){let{ecc:n=`L`,boostEcc:r=!1,minVersion:i=1,maxVersion:a=40,maskPattern:o=-1,border:s=1}=t||{},c=typeof e==`string`?ou(e):Array.isArray(e)?[ru(e)]:void 0;if(!c)throw Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);let l=gu(c,Ll[n],i,a,o,r),u=vu({version:l.version,maskPattern:l.mask,size:l.size,data:l.modules,types:l.types},s);return t?.invert&&(u.data=u.data.map(e=>e.map(e=>!e))),t?.onEncoded?.(u),u}function vu(e,t=1){if(!t)return e;let{size:n}=e,r=n+t*2;e.size=r,e.data.forEach(e=>{for(let n=0;n<t;n++)e.unshift(!1),e.push(!1)});for(let n=0;n<t;n++)e.data.unshift(Array.from({length:r},e=>!1)),e.data.push(Array.from({length:r},e=>!1));let i=Ml.Border;e.types.forEach(e=>{for(let n=0;n<t;n++)e.unshift(i),e.push(i)});for(let n=0;n<t;n++)e.types.unshift(Array.from({length:r},e=>i)),e.types.push(Array.from({length:r},e=>i));return e}var yu={info:zs,warning:$s,danger:Yo,neutral:Pe},bu={info:`bg-info-bg text-info-fg border-[color-mix(in_oklch,var(--info-solid)_22%,transparent)]`,warning:`bg-warning-bg text-warning-fg border-[color-mix(in_oklch,var(--warning-solid)_30%,transparent)]`,danger:`bg-danger-bg text-danger-fg border-[color-mix(in_oklch,var(--danger-solid)_25%,transparent)]`,neutral:`bg-sunken text-fg-2 border-line-1`};function xu({tone:e=`info`,inline:t=!1,actionLabel:n,onAction:r,onDismiss:i,icon:a,children:o}){return(0,$.jsxs)(`div`,{role:e===`danger`?`alert`:`status`,className:Z(`flex min-h-10 items-center gap-2.5 border-b py-1.5 pr-2 pl-3.5 font-sans text-13 font-medium leading-(--lh-snug) font-[450]`,t&&`rounded-md border`,bu[e]),children:[(0,$.jsx)(X,{icon:a??yu[e]}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1 text-pretty`,children:o}),n&&(0,$.jsx)(Y,{size:`sm`,onClick:r,className:`shrink-0 shadow-none`,children:n}),i&&(0,$.jsx)(Et,{label:`Dismiss`,icon:Pt,size:`sm`,onClick:i})]})}async function Su(){let e=await oe(`/api/v1/pairings`,{purpose:`device`},o),t=Date.now(),n=t+Math.max(0,Math.min(6e5,Date.parse(e.expiresAt)-t)),r=new URL(e.url),i=_u(e.url,{border:4});return{code:e.code,deadline:n,origin:r.origin,loopback:[`127.0.0.1`,`localhost`,`[::1]`].includes(r.hostname),qr:{size:i.size,cells:i.data.flatMap((e,t)=>e.flatMap((e,n)=>e?[{x:n,y:t}]:[]))}}}function Cu(e){return Math.max(0,Math.min(600,Math.ceil((e-Date.now())/1e3)))}function wu(){let e=qa(),t=g(),n=(0,Q.useRef)(void 0),r=Ct(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(!1),o=(0,Q.useRef)(0),[s,c]=(0,Q.useState)(),[l,u]=(0,Q.useState)(0),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{let e=Ac();e&&(n.current=e,m(1))},[]),(0,Q.useEffect)(()=>{let e=++o.current;return()=>{queueMicrotask(()=>{o.current===e&&r.invalidateQueries({queryKey:[`devices`],refetchType:`all`})})}},[r]),(0,Q.useEffect)(()=>{if(p===0)return;let e=!0;return i.current?.attempt!==p&&(i.current={attempt:p,promise:Su()}),i.current.promise.then(t=>{if(!e)return;let n=Cu(t.deadline);u(n),n===0?(i.current=null,c({expired:!0,origin:t.origin,loopback:t.loopback})):c({...t,expired:!1})},()=>{e&&f(!0)}),()=>{e=!1}},[p]),(0,Q.useEffect)(()=>{if(!s||s.expired)return;let e=window.setInterval(()=>{let e=Cu(s.deadline);u(e),e===0&&(i.current=null,c({expired:!0,origin:s.origin,loopback:s.loopback}))},1e3);return()=>window.clearInterval(e)},[s]);function h(){c(void 0),f(!1),m(e=>e+1)}async function _(){if(a.current)return;a.current=!0;let r=n.current?.devicesIndex,i=r!==void 0&&t.history.location.state.__TSR_index===r+1;await e({to:`/devices`,replace:!0}),i&&t.history.back()}return(0,$.jsx)(St,{open:!0,onOpenChange:e=>{e||_()},title:`Pair a device`,description:p===0?`Create a code for another browser or phone.`:(0,$.jsxs)($.Fragment,{children:[`Scan the QR code to pair with this hub, or open`,` `,s?(0,$.jsx)(`span`,{className:`font-mono text-12 wrap-anywhere`,children:s.origin}):`this hub`,` on your device and type the code.`]}),actions:(0,$.jsx)(Y,{"data-autofocus":!0,variant:`ghost`,onClick:()=>void _(),children:`Done`}),children:(0,$.jsxs)(`div`,{className:`mt-4`,children:[p===0?(0,$.jsx)(Y,{variant:`primary`,onClick:h,children:`Create code`}):d?(0,$.jsx)(xu,{tone:`danger`,inline:!0,actionLabel:`Try again`,onAction:h,children:`Could not create a pairing. Try again.`}):!s&&(0,$.jsx)(`p`,{role:`status`,children:`Creating pairing…`}),s&&(0,$.jsxs)($.Fragment,{children:[s.loopback&&(0,$.jsx)(xu,{tone:`warning`,inline:!0,children:`This hub accepts connections from this computer only. To pair a phone, start emend with --tailscale.`}),s.expired?(0,$.jsxs)(`div`,{className:`mt-4 flex flex-col items-start gap-2`,children:[(0,$.jsx)(`p`,{role:`status`,className:`text-12 text-fg-3`,children:`This code expired.`}),(0,$.jsx)(Y,{onClick:h,children:`New code`})]}):(0,$.jsxs)(`div`,{className:`mt-4 grid grid-cols-[minmax(0,1fr)] items-center justify-items-center gap-5`,children:[(0,$.jsxs)(`svg`,{role:`img`,"aria-label":`Pairing QR code`,viewBox:`0 0 ${s.qr.size} ${s.qr.size}`,width:`256`,height:`256`,className:`h-auto min-w-0 w-full max-w-[256px]`,shapeRendering:`crispEdges`,children:[(0,$.jsx)(`title`,{children:`Pairing QR code`}),(0,$.jsx)(`rect`,{width:s.qr.size,height:s.qr.size,fill:`white`}),s.qr.cells.map(({x:e,y:t})=>(0,$.jsx)(`rect`,{x:e,y:t,width:`1`,height:`1`,fill:`black`},`${e}:${t}`))]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-2`,children:[(0,$.jsx)(`span`,{className:`font-mono text-11 font-medium font-stretch-mono tracking-(--tracking-label) text-fg-3 uppercase`,children:`Code`}),(0,$.jsx)(`p`,{className:`font-mono text-24 leading-none font-semibold font-stretch-mono tracking-[0.12em]`,children:s.code}),(0,$.jsxs)(`p`,{className:`inline-flex items-center gap-1 text-12 text-fg-3`,children:[(0,$.jsx)(X,{icon:ts,size:12}),`Expires in `,Math.floor(l/60),`:`,String(l%60).padStart(2,`0`)]})]})]})]})]})})}var Tu=()=>en(()=>import(`./DiffPane-CnM0c-g-.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8])),Eu=class extends Q.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?(0,$.jsxs)(`div`,{className:`space-y-3 p-5`,children:[(0,$.jsx)(`p`,{role:`alert`,children:`Could not load the diff.`}),(0,$.jsx)(Y,{onClick:this.props.retry,children:`Retry`}),this.props.retried&&(0,$.jsx)(Y,{onClick:()=>window.location.reload(),children:`Reload the page`})]}):this.props.children}};function Du({load:e=Tu,...t}){let[n,r]=(0,Q.useState)(()=>({Pane:(0,Q.lazy)(e),number:0})),i=n.Pane;return(0,$.jsx)(Eu,{retried:n.number>0,retry:()=>r({Pane:(0,Q.lazy)(e),number:n.number+1}),children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`p`,{role:`status`,className:`p-5`,children:`Loading diff…`}),children:(0,$.jsx)(i,{...t})})},n.number)}function Ou({revision:e,counts:t,onViewed:n,onNavigate:r}){let i=at(e),a=new Map(x([...i.values()].map(({topic:e})=>e)).map(({topic:e,rank:t})=>[e.slug,t])),o=e.files.filter(e=>e.role===`diff`),c=o.filter(e=>e.viewed===`viewed`).length,l=new Map;for(let t of e.threads){if(t.placement.status!==`placed`)continue;let e=ie(o,t.placement.location);e&&l.set(e.id,(l.get(e.id)??0)+1)}return(0,$.jsxs)(`div`,{className:`em-files-view`,children:[[...i.values()].map(({topic:e,files:i})=>{let o=i.filter(e=>e.viewed===`viewed`).length,c=i.length>0&&o===i.length,u=a.get(e.slug),d=e.slug===jt.slug?`Other files`:e.title;return(0,$.jsxs)(`section`,{className:`em-files-group`,"aria-label":d,children:[(0,$.jsxs)(`div`,{className:`em-files-group__head`,children:[u?(0,$.jsx)(U,{rank:u}):(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`··`}),(0,$.jsx)(`h3`,{className:`em-files-group__title`,children:d}),(0,$.jsxs)(`span`,{className:`em-files-group__count`,children:[o,`/`,i.length]}),(0,$.jsx)(h,{state:c?`viewed`:void 0,label:`topic ${d}`,disabled:!i.length,onToggle:()=>n(i.map(e=>e.path),!c)})]}),i.map(e=>{let i=e.path.lastIndexOf(`/`),a=t.get(e.id);return(0,$.jsxs)(`div`,{className:`em-files-row`,"data-viewed":e.viewed,children:[(0,$.jsxs)(`button`,{type:`button`,className:`em-files-row__main`,"aria-label":[`Open diff for ${e.path}`,e.status?.replaceAll(`-`,` `),a&&`${a.additions} added, ${a.deletions} removed`,(l.get(e.id)??0)>0&&`${l.get(e.id)} ${l.get(e.id)===1?`thread`:`threads`}`].filter(Boolean).join(`, `),onClick:()=>r(e),children:[(0,$.jsx)(s,{status:e.status}),(0,$.jsx)(`span`,{className:`em-files-row__path`,title:e.path,children:(0,$.jsxs)(`bdi`,{children:[(0,$.jsx)(`span`,{className:`em-files-row__dir`,children:e.path.slice(0,i+1)}),e.path.slice(i+1)]})}),(0,$.jsx)(`span`,{className:`em-files-row__counts`,children:a?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`text-diff-add-fg`,children:[`+`,a.additions]}),(0,$.jsxs)(`span`,{className:`text-diff-del-fg`,children:[`−`,a.deletions]})]}):null}),(0,$.jsx)(st,{count:l.get(e.id)??0})]}),(0,$.jsx)(h,{state:e.viewed,viewedOn:e.viewedOn,label:e.path,onToggle:()=>n([e.path],e.viewed!==`viewed`)})]},e.id)})]},e.slug)}),(0,$.jsxs)(`div`,{className:`em-files-progress`,children:[(0,$.jsx)(`progress`,{className:`em-files-progress__bar`,value:c,max:o.length||1,"aria-label":`Files viewed`}),(0,$.jsxs)(`span`,{children:[c,` of `,o.length,` viewed`]})]})]})}function ku(e,t,n){return Math.min(n,Math.max(t,e))}function Au({label:e,value:t,min:n,max:r,onPreview:i,onCommit:a,onReset:o}){let s=(0,Q.useRef)(null),[c,l]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>()=>{s.current&&i(void 0)},[i]),(0,Q.useEffect)(()=>{if(c)return document.body.classList.add(`em-resizing`),()=>document.body.classList.remove(`em-resizing`)},[c]);let u=(e,t)=>{let o=s.current;o&&o.id===e.pointerId&&(s.current=null,t&&o.value!==o.width&&a(ku(o.value,n,r)),i(void 0),l(!1),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))};return(0,$.jsx)(`div`,{role:`separator`,tabIndex:0,"aria-orientation":`vertical`,"aria-label":e,"aria-valuemin":Math.round(n),"aria-valuemax":Math.round(r),"aria-valuenow":Math.round(t),className:`em-resize-handle ${He}`,style:{"--resize-handle-width":`8px`},"data-active":c||void 0,title:`Drag to resize · double-click or Enter to reset`,onDoubleClick:o,onKeyDown:e=>{let i=e.shiftKey?64:16,s={ArrowLeft:t-i,ArrowRight:t+i,Home:n,End:r}[e.key];(s!==void 0||e.key===`Enter`)&&(e.preventDefault(),e.key===`Enter`?o():s!==void 0&&a(ku(s,n,r)))},onPointerDown:e=>{e.button!==0||s.current||(e.preventDefault(),e.currentTarget.focus(),e.currentTarget.setPointerCapture(e.pointerId),s.current={id:e.pointerId,x:e.clientX,width:t,value:t},l(!0))},onPointerMove:e=>{let t=s.current;t&&t.id===e.pointerId&&(t.value=ku(t.width+e.clientX-t.x,n,r),i(t.value))},onPointerUp:e=>u(e,!0),onPointerCancel:e=>u(e,!1),onLostPointerCapture:e=>u(e,!1)})}function ju({inbox:e,header:t,reading:n,diff:r,phoneTabs:i,sendBar:a,tab:o,hasDiff:s,tabs:c,readingLayout:l}){let u=Kt(),d=Vt(),f=u!==`phone`&&d.pane[u]===`split`,p=f&&s,[h,g]=(0,Q.useState)(),[_,v]=(0,Q.useState)(),y=(0,Q.useRef)(null),b=(0,Q.useRef)(null),[x,S]=(0,Q.useState)(0),[C,w]=(0,Q.useState)(0);(0,Q.useLayoutEffect)(()=>{let e=b.current,t=y.current;if(!e||!t)return;let n=()=>{S(e.getBoundingClientRect().width),w(t.getBoundingClientRect().width)};if(n(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,n),()=>window.removeEventListener(`resize`,n);let r=new ResizeObserver(n);return r.observe(e),r.observe(t),()=>r.disconnect()},[]);let T=Math.max(360,x-8-440),E=d.readingShare===he.readingShare?ku(x*he.readingShare,420,760):x*d.readingShare,D=ku(_??E,360,T),O=ku(C-8*(p?2:1)-360-440,220,520),k=u===`desktop`?ku(h??d.inboxWidth,220,O):he.inboxWidth;return(0,$.jsxs)(`div`,{ref:y,className:`em-panes flex min-h-0 flex-1`,style:{"--inbox-w":`${k}px`},children:[u!==`phone`&&e,u===`desktop`&&e&&!d.inboxCollapsed&&(0,$.jsx)(Au,{label:`Resize inbox`,value:k,min:220,max:O,onPreview:g,onCommit:e=>m.update({inboxWidth:e}),onReset:()=>m.update({inboxWidth:he.inboxWidth})}),(0,$.jsxs)(`main`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[t,u!==`phone`&&!f&&c,(0,$.jsxs)(`div`,{ref:b,className:`flex min-h-0 flex-1`,children:[(u!==`phone`||o!==`diff`||!s)&&(0,$.jsxs)(`section`,{"aria-label":`Reading`,"data-testid":`reading-pane`,"data-reading-scroll":!0,"data-reading-layout":l,hidden:!f&&s&&o===`diff`,tabIndex:-1,className:`relative min-w-0 flex-1 ${l===`original`?`overflow-hidden`:`overflow-y-auto`}`,style:p?{flex:`0 0 ${D}px`}:void 0,children:[f&&c,n]},`reading`),p&&(0,$.jsx)(Au,{label:`Resize reading pane`,value:D,min:360,max:T,onPreview:v,onCommit:e=>{x>0&&m.update({readingShare:e/x})},onReset:()=>m.update({readingShare:he.readingShare})},`reading-handle`),s&&(u!==`phone`||o===`diff`)&&(0,$.jsx)(`section`,{"aria-label":`Diff`,"data-testid":`diff-pane`,"data-diff-scroll":!0,hidden:!f&&o!==`diff`,className:`relative min-w-0 flex-1 overflow-y-auto`,children:r},`diff`)]}),a,u===`phone`&&i]})]})}var Mu=[{id:`writeup`,label:`Writeup`,icon:Lt},{id:`files`,label:`Files`,icon:Ds},{id:`docs`,label:`Docs`,icon:ps},{id:`comments`,label:`Comments`,icon:mt},{id:`diff`,label:`Diff`,icon:ls}];function Nu({id:e,search:t,hasDocs:n,hasWriteup:r,hasDiff:i,unsentCount:a,filesCount:o=0,viewedCount:s=0}){return(0,$.jsx)(`nav`,{"aria-label":`Review tabs`,className:`grid shrink-0 auto-cols-fr grid-flow-col border-t border-line-1 bg-surface pb-[env(safe-area-inset-bottom)]`,children:Mu.filter(e=>({writeup:r,files:o>0,diff:i,docs:n,comments:!0})[e.id]).map(n=>(0,$.jsx)(co,{to:`/r/$reviewId`,params:{reviewId:e},search:{...t,tab:n.id,thread:void 0},hash:``,"aria-current":n.id===t.tab?`page`:void 0,className:Z(`relative flex h-(--tab-touch) items-center justify-center text-11 font-medium leading-none no-underline hover:text-fg-1`,n.id===t.tab?`text-fg-1 before:absolute before:-top-px before:right-[28%] before:left-[28%] before:h-0.5 before:rounded-b-[2px] before:bg-accent before:content-['']`:`text-fg-3`),children:(0,$.jsxs)(`span`,{className:`relative flex flex-col items-center gap-[3px]`,children:[(0,$.jsx)(X,{icon:n.icon,size:18}),(0,$.jsx)(`span`,{children:n.id===`files`?`Files ${s}/${o}`:n.label}),n.id===`comments`&&a>0&&(0,$.jsxs)(`span`,{className:`absolute -top-1.5 left-[calc(50%+3px)] inline-grid h-[15px] min-w-[15px] place-items-center rounded-full bg-accent px-1 text-[9.5px] font-semibold leading-none text-accent-fg tabular-nums`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:` `}),a,(0,$.jsx)(`span`,{className:`sr-only`,children:` unsent`})]})]})},n.id))})}function Pu({onShow:e}){let t=c($c());return(0,$.jsxs)(`aside`,{"aria-label":`Inbox`,className:`flex w-(--inbox-w-collapsed) shrink-0 flex-col items-center gap-2 border-r border-line-1 bg-app py-2`,children:[(0,$.jsx)(Et,{label:`Show inbox`,icon:Fs,onClick:e}),(0,$.jsx)(`div`,{className:`relative min-h-0 w-full flex-1 overflow-y-auto`,children:(0,$.jsx)(`ul`,{className:`flex flex-col items-center gap-0.5`,children:t.data?.items.filter(e=>!e.movedTo).map(e=>(0,$.jsx)(`li`,{children:(0,$.jsx)(rt,{content:e.title,children:(0,$.jsxs)(co,{to:`/r/$reviewId`,params:{reviewId:e.id},search:{rev:e.newestRevision},"aria-label":`${dl(e)?`Needs you: `:``}${e.title}`,activeOptions:{includeSearch:!1},activeProps:{"aria-current":`page`},className:Z(`relative grid h-8 w-9 place-items-center rounded-[6px] no-underline hover:bg-hover aria-[current=page]:bg-selected [&>span[role=img]]:size-2.5`,e.list===`done`&&`opacity-60 hover:opacity-100 focus-within:opacity-100 aria-[current=page]:opacity-100`),children:[(0,$.jsx)(cl,{origin:e.origin,dot:!0}),dl(e)&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`absolute top-1.5 right-[7px] size-1.5 rounded-full bg-accent`})]})})},e.id))})})]})}function Fu({currentReviewId:e,collapsed:t,onCollapsedChange:n}){let r=Kt(),[i,a]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{r!==`tablet`&&a(!1)},[r]),r===`desktop`&&!t?(0,$.jsx)(`aside`,{"aria-label":`Inbox`,"data-testid":`inbox-pane`,className:`flex min-h-0 w-(--inbox-w) shrink-0 flex-col bg-app`,children:(0,$.jsx)(Dl,{compact:!0,currentReviewId:e,onCollapse:()=>n(!0)})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Pu,{onShow:()=>r===`tablet`?a(!0):n(!1)}),r===`tablet`&&(0,$.jsx)(v,{side:`left`,title:`Inbox`,open:i,onOpenChange:a,children:(0,$.jsx)(Dl,{compact:!0,hideHead:!0,currentReviewId:e,onOpen:()=>a(!1)})})]})}function Iu({items:e,value:t,onChange:n,label:r,className:i,idBase:a}){let o=(0,Q.useId)(),s=a??o,c=(0,Q.useRef)(new Map),l=e.filter(e=>!e.hidden),u=l.some(e=>e.id===t)?t:l[0]?.id;return(0,$.jsx)(`div`,{role:`tablist`,"aria-label":r,className:Z(`flex items-stretch gap-0.5 overflow-x-auto border-b border-line-1 px-2 [scrollbar-width:none]`,i),children:l.map((e,r)=>(0,$.jsxs)(`button`,{ref:t=>{t?c.current.set(e.id,t):c.current.delete(e.id)},type:`button`,role:`tab`,id:`${s}-tab-${e.id}`,"aria-selected":e.id===t,"aria-controls":e[`aria-controls`],tabIndex:e.id===u?0:-1,onClick:()=>n?.(e.id),onKeyDown:e=>{let t=dt(e.key,r,l.length);if(t===void 0)return;e.preventDefault();let i=l[t];i&&(c.current.get(i.id)?.focus(),n?.(i.id))},className:`relative inline-flex h-10 shrink-0 items-center gap-1.5 whitespace-nowrap border-0 bg-transparent px-2.5 font-sans text-13 font-medium leading-(--lh-snug) text-fg-3 [-webkit-tap-highlight-color:transparent] hover:text-fg-1 focus-visible:outline-none focus-visible:shadow-[inset_0_0_0_2px_var(--ochre-500)] aria-selected:text-fg-1 aria-selected:after:absolute aria-selected:after:right-2 aria-selected:after:-bottom-px aria-selected:after:left-2 aria-selected:after:h-0.5 aria-selected:after:rounded-t-[2px] aria-selected:after:bg-(--ochre-500) aria-selected:after:content-['']`,children:[e.label,e.count!=null&&e.count!==0&&(0,$.jsx)(`span`,{className:Z(`inline-grid h-[18px] min-w-[18px] place-items-center rounded-[9px] bg-active px-[5px] font-sans text-[10.5px] leading-none font-semibold text-fg-2 tabular-nums`,e.accent&&`bg-accent text-accent-fg`),children:e.count})]},e.id))})}function Lu({id:e,search:t,hasDocs:n,hasWriteup:r,hasDiff:i,unsentCount:a,filesCount:o=0,viewedCount:s=0,docsCount:c,idBase:l}){let u=qa(),d=Kt()===`phone`,{reading:f}=Vt(),p=Be()===`tabs`&&i,h=(t.tab===`diff`&&!p||t.tab===`files`&&!o?r?`writeup`:n?`docs`:`comments`:t.tab)??(r?`writeup`:n?`docs`:`comments`);return(0,$.jsxs)(`div`,{className:`em-review-tabs sticky top-0 z-(--z-sticky) flex shrink-0 items-center border-b border-line-1 bg-surface`,children:[(0,$.jsx)(Iu,{idBase:l,label:`Reading tabs`,className:`min-w-0 flex-1 border-b-0`,value:h,items:[{id:`writeup`,label:`Writeup`,hidden:!r},{id:`files`,label:`Files ${s}/${o}`,hidden:!o},{id:`docs`,label:`Docs`,hidden:!n,count:c},{id:`comments`,label:`Comments`,count:a,accent:!0},{id:`diff`,label:`Diff`,hidden:!p}].map(e=>({...e,"aria-controls":`${l}-${e.id===`diff`?`diff`:`reading`}-panel`})),onChange:n=>{(n===`writeup`||n===`files`||n===`docs`||n===`comments`||n===`diff`)&&u({to:`/r/$reviewId`,params:{reviewId:e},search:{...t,tab:n,thread:void 0},hash:``})}}),!d&&r&&h===`writeup`&&(0,$.jsx)(tt,{label:`Reading mode`,size:`sm`,className:`mx-2 shrink-0`,options:[{value:`standard`,label:`Standard`},{value:`focus`,label:`Focus`}],value:f,onChange:e=>{(e===`standard`||e===`focus`)&&m.update({reading:e})}})]})}var Ru=e=>/^(?:block-|thread-|diff-|topic-|doc-|html-doc-).+/.test(e),zu=e=>e.title||e.path.split(`/`).at(-1)||e.path;function Bu(e,t){let n=e.path.split(`/`).at(-1),r=t.filter(t=>t.path!==e.path&&(zu(t)===zu(e)||t.path.split(`/`).at(-1)===n)),i=e.path.split(`/`);for(let e=1;e<i.length;e++){let t=i.slice(-e).join(`/`);if(r.every(n=>n.path.split(`/`).slice(-e).join(`/`)!==t))return t}return e.path}function Vu(e,t){let n=(e instanceof HTMLElement?e.closest(`[data-reading-scroll]`):null)??e.querySelector(`[data-reading-scroll]`);return Array.from(n?.querySelectorAll(`[data-reading-doc]`)??[]).find(e=>e.dataset.readingDoc===t)}function Hu(e,t){let n=new Set(t.blocks?.filter(e=>e.kind===`heading`).map(e=>e.id));return Array.from(Vu(e,t.path)?.querySelectorAll(`h2, h3`)??[]).filter(e=>{let t=e.parentElement;return t?.tagName===`DIV`&&t.dataset.blockKind===`heading`&&n.has(t.dataset.blockId??``)&&t.id===`block-${t.dataset.blockId}`&&!t.closest(`.em-comment-html, [id^="thread-"], form`)})}function Uu(e,t,n){let r=t.headings?.find(e=>e.id===n);if(r)return Hu(e,t).find(e=>e.id===n&&e.tagName.toLowerCase()===`h${r.level}`)}function Wu(e,t){let n=new Map(t.headings?.flatMap(e=>e.id?[[e.id,e.level]]:[])),r=new Map;for(let i of Hu(e,t))!r.has(i.id)&&i.tagName.toLowerCase()===`h${n.get(i.id)}`&&r.set(i.id,i);return r}var Gu=e=>`${e.kind}:${e.path}`;function Ku(e,t){let n=e.placement.status===`placed`?e.placement.location:e.target;if(!(`path`in n)||n.path!==t.path)return!1;switch(n.kind){case`source-lines`:return t.kind===`source`;case`doc-span`:return t.kind===`markdown`;case`html-span`:return t.kind===`html`;default:return!1}}var qu=(e,t)=>e?.kind===`source`?`source`:t===`source`?void 0:t;function Ju(e,t,n){return e.find(e=>e.path===t&&(n===`source`?e.kind===`source`:e.kind!==`source`))??(n===`source`?void 0:e.find(e=>e.path===t))}var Yu=null;function Xu(e){if(!e)return;let t=Yu;Yu=e;try{e.focus({preventScroll:!0})}finally{Yu=t}}function Zu(e){return e!==null&&e===Yu}var Qu=`emend.reading.v1`,$u=Oe({id:je().min(1).max(600).regex(/^(?:block-|thread-|h-|html-doc-).+/),fraction:N().min(0).max(1),at:N().finite()}),ed=Te(je(),ce());function td(e,t,n=``,r,i=`reading`){return[e,t,n,...t===`docs`&&r!==void 0?[r,i]:[]].join(`
4
+ `)}function nd(){try{let e=ed.safeParse(JSON.parse(localStorage.getItem(`emend.reading.v1`)??`{}`));if(!e.success)return new Map;let t=new Map;for(let[n,r]of Object.entries(e.data)){let e=$u.safeParse(r);e.success&&t.set(n,e.data)}return t}catch{return new Map}}function rd(e){let t=nd().get(e);return t?{id:t.id,fraction:t.fraction}:void 0}function id(e,t,n=Date.now()){try{let r=nd();if(t){let i=$u.safeParse({id:t.id,fraction:Math.min(1,Math.max(0,t.fraction)),at:n});if(!i.success)return;r.set(e,i.data)}else r.delete(e);let i=[...r].sort((e,t)=>t[1].at-e[1].at).slice(0,200);localStorage.setItem(Qu,JSON.stringify(Object.fromEntries(i)))}catch{}}var ad=e=>e.width===0&&e.height===0,od=e=>Math.max(e.getBoundingClientRect().top,e.querySelector(`.em-doc-bar`)?.getBoundingClientRect().bottom??0,e.querySelector(`.em-review-tabs`)?.getBoundingClientRect().bottom??0);function sd(e,t){if(e.scrollTop<=0)return null;let n=od(e),r=Array.from(e.querySelectorAll(t)),i=e=>r[e],a,o=0,s=r.length;for(;o<s;){let e=o+s>>1,t=e,r=i(t).getBoundingClientRect();for(;ad(r)&&++t<s;)r=i(t).getBoundingClientRect();t>=s?s=e:r.bottom>n?(a={element:i(t),rect:r},s=e):o=t+1}if(a){let e=a.rect.height>0?(n-a.rect.top)/a.rect.height:0;return{id:a.element.id,fraction:Math.min(1,Math.max(0,e))}}for(let e=r.length-1;e>=0;e--)if(!ad(i(e).getBoundingClientRect()))return{id:i(e).id,fraction:1};return null}function cd(e,t,n){let r=t.id.startsWith(`h-`)?n&&Uu(e,n,t.id.slice(2)):Ru(t.id)?document.getElementById(t.id):void 0;if(!r||!e.contains(r))return;let i=r.getBoundingClientRect(),a=i.top+t.fraction*i.height-od(e);return Math.abs(a)>=1&&(e.scrollTop+=a),e.scrollTop}var ld;function ud(e){if(e.dataset.blockKind===`diagram`||e.dataset.blockText===void 0)return;let t=[],n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=``;for(let e=n.nextNode();e;e=n.nextNode()){let n=r.length;r+=e.textContent??``,r.length>n&&t.push({node:e,start:n,end:r.length})}ld??=new Intl.Segmenter(void 0,{granularity:`grapheme`});let i=``,a=[],o=[];for(let{segment:e,index:t}of ld.segment(r)){let n=e.normalize(`NFC`),r=n!==e;i+=n;for(let i=0;i<n.length;i++)a.push(r?t:t+i),o.push(r?t+e.length:t+i+1)}let s=``,c=[],l=[];for(let e of i.matchAll(/\p{White_Space}+|[^\p{White_Space}]/gu)){let t=/^\p{White_Space}/u.test(e[0])?` `:e[0];s+=t;for(let n=0;n<t.length;n++)c.push(a[e.index+n]),l.push(o[e.index+(t===` `?e[0].length-1:n)])}let u=s.length-s.trimStart().length,d=s.trim();if(d===Se(e.dataset.blockText))return(n,r)=>{if(!Number.isInteger(n)||!Number.isInteger(r)||n<0||r<=n||r>d.length)return;let i=c[u+n],a=l[u+r-1];if(i===void 0||a===void 0)return;let o=t.find(e=>e.start<=i&&i<e.end),s=t.find(e=>e.start<a&&a<=e.end);if(!o||!s)return;let f=e.ownerDocument.createRange();return f.setStart(o.node,i-o.start),f.setEnd(s.node,a-s.start),f}}function dd(e,t,n,r){(0,Q.useLayoutEffect)(()=>{let i=e.current;if(!i||!r)return;let a=new Map,o=new Map;for(let e of n){if(e.role!==`diff`||!e.topic)continue;let t=o.get(e.topic)??new Map;for(let n of e.notes??[])n.ref&&t.set(n.ref,{id:n.id,path:e.path});o.set(e.topic,t)}for(let e of t){let t=e.topic&&o.get(e.topic.slug);if(t&&!e.path)for(let n of[...e.blocks,...e.subsections?.flatMap(e=>e.blocks)??[]]){let e=document.getElementById(`block-${n.id}`);if(e&&i.contains(e))for(let n of e.querySelectorAll(`span.user-content-ref`)){let e=n.textContent??``,r=e.length===5?/^ref ([A-Z])$/.exec(e)?.[1]:void 0,i=r&&t.get(r);i&&(n.setAttribute(`role`,`button`),n.setAttribute(`tabindex`,`0`),n.setAttribute(`aria-label`,`Go to agent note ${r} in ${i.path}`),n.setAttribute(`data-agent-note-ref`,i.id),a.set(n,i.id))}}}let s=e=>{if(e instanceof KeyboardEvent&&e.key!==`Enter`&&e.key!==` `)return;let t=e.target instanceof HTMLElement?e.target:null;for(;t&&t!==i;){let n=a.get(t);if(n){e.preventDefault(),r(n);return}t=t.parentElement}};return i.addEventListener(`click`,s),i.addEventListener(`keydown`,s),()=>{i.removeEventListener(`click`,s),i.removeEventListener(`keydown`,s);for(let e of a.keys())for(let t of[`role`,`tabindex`,`aria-label`,`data-agent-note-ref`])e.removeAttribute(t)}},[e,t,n,r])}function fd({block:e,drift:t,changedIn:n,continuesChange:r,commenting:i,onComment:a,children:o}){return(0,$.jsxs)(`div`,{className:`em-reading-block relative rounded-sm`,"data-drift":t?``:void 0,"data-commenting":i?``:void 0,"data-change-continuation":n!==void 0&&r?``:void 0,children:[n!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`em-reading-block__change absolute w-0.5 bg-changed-line`}),!r&&(0,$.jsx)(`div`,{className:`em-reading-block__marker mb-1.5 flex`,children:(0,$.jsx)(Nt,{revision:n})})]}),(0,$.jsx)(Ye,{block:e}),e.kind!==`heading`&&Ne(e).quote!==``&&(0,$.jsx)(`span`,{className:`em-reading-block__comment`,children:(0,$.jsx)(Et,{icon:et,label:e.kind===`diagram`?`Comment on diagram`:`Comment on block`,size:`sm`,variant:`ghost`,className:`size-6 [&:not(:disabled):not([aria-disabled=true])]:hover:bg-accent-tint [&:not(:disabled):not([aria-disabled=true])]:hover:text-accent-text`,onMouseUpCapture:e=>e.stopPropagation(),onKeyUpCapture:e=>e.stopPropagation(),onClick:a})}),o]})}var pd=(0,Q.createContext)(null);function md({group:e,headingId:t,changedIn:n,children:r}){let i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useContext)(pd),s=JSON.stringify([o?.reviewId,o?.revision,e.key]),c=n!==void 0||e.presentation!==`glossary`&&e.topic?.attention!==`skim`,[l,u]=(0,Q.useState)({open:c}),d=o?o.choices.get(s)??c:l.open,f=(0,Q.useCallback)(e=>{o?.choices.set(s,e),u({open:e})},[o,s]),m=`${t}-body`;(0,Q.useLayoutEffect)(()=>{d||a.current?.setAttribute(`hidden`,`until-found`)},[d]),(0,Q.useEffect)(()=>{let t=i.current,n=()=>{if(a.current&&(a.current.hidden=!1),e.presentation===`glossary`){let e=t?.querySelector(`details.em-writeup-glossary`);e&&(e.open=!0)}f(!0)};return t?.addEventListener(`emend:reveal-reading`,n),t?.addEventListener(`beforematch`,n),()=>{t?.removeEventListener(`emend:reveal-reading`,n),t?.removeEventListener(`beforematch`,n)}},[e.presentation,f]);let h=e.heading!=null&&(0,$.jsxs)(`div`,{className:e.topic?`em-topic-header`:`mb-3 flex items-center gap-2.5`,children:[e.topic&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,className:`em-topic-fold`,"aria-labelledby":t,"aria-expanded":d,"aria-controls":m,onClick:()=>f(!d),children:d?(0,$.jsx)(p,{size:16,"aria-hidden":`true`}):(0,$.jsx)(me,{size:16,"aria-hidden":`true`})}),(0,$.jsx)(vt,{topic:e.topic}),e.rank!==void 0&&(0,$.jsx)(U,{rank:e.rank})]}),(0,$.jsx)(`h2`,{id:t,className:e.topic?`em-topic-title`:e.presentation===`tldr`||e.presentation===`decisions`?`em-writeup-kicker`:`min-w-0 flex-1 wrap-anywhere text-fg-1 [font:var(--type-h2)]`,children:e.heading}),!d&&!!e.commentCount&&(0,$.jsxs)(`span`,{className:`em-topic-comments`,children:[e.commentCount,` `,w(e.commentCount,`comment`)]}),e.topic&&!d&&n!==void 0&&(0,$.jsx)(Nt,{revision:n}),e.action]}),g=e.blocks.filter(e=>e.kind===`item`).length||e.blocks.length;return(0,$.jsx)(`section`,{ref:i,id:e.id,"data-reading-section":e.key,"aria-labelledby":e.labelledBy??t,className:`em-reading-group${e.topic?` em-topic-section`:``}${e.presentation===`tldr`?` em-writeup-card`:e.presentation===`decisions`?` em-writeup-callout em-writeup-decisions`:``}`,children:e.presentation===`glossary`?(0,$.jsxs)(`details`,{className:`em-writeup-glossary`,open:d,onToggle:e=>{e.target===e.currentTarget&&f(e.currentTarget.open)},children:[(0,$.jsxs)(`summary`,{id:t,children:[`Glossary · `,g,` `,w(g,`term`)]}),r]}):(0,$.jsxs)($.Fragment,{children:[h,e.meta,e.topic?(0,$.jsx)(`div`,{ref:a,id:m,hidden:!d,children:r}):r]})})}function hd({focus:e,reviewId:t,threads:n,composing:r,jump:i,children:a}){let o=(0,Q.useId)(),[s,c]=(0,Q.useState)(0),l=(0,Q.useCallback)(()=>(c(e=>e+1),()=>c(e=>e-1)),[]),u=(0,Q.useMemo)(()=>({replies:n.map(e=>_t(t,e.target,e.id)),edits:n.flatMap(e=>e.comments.filter(e=>e.author===`user`&&!e.sent).map(e=>Dt(t,e.id)))}),[t,n]),d=(0,Q.useSyncExternalStore)(xt,()=>u.replies.some(yt)||u.edits.some(e=>Le(e)&&Ht(e))),f=r||s>0||d||n.some(e=>e.comments.some(e=>e.author===`user`&&!e.sent)),p=(0,Q.useContext)(pd),[m,h]=(0,Q.useState)({open:f}),g=p&&n.length?n.some(e=>p.choices.get(`thread-${e.id}`)):m.open,_=e=>{for(let t of n)p?.choices.set(`thread-${t.id}`,e);h({open:e})},[v,y]=(0,Q.useState)();i&&v!==i.token&&n.some(e=>e.id===i.threadId)&&(y(i.token),_(!0)),f&&!g&&_(!0);let b=!e||g||f,x=n.every(e=>e.state===`resolved`)?` · resolved`:n.some(e=>e.state===`answered`)?` · answered`:``;return(0,$.jsx)(We,{value:l,children:(0,$.jsxs)(`div`,{className:`em-focus-threads`,children:[b&&(0,$.jsx)(`div`,{id:o,className:`em-focus-threads__cards`,children:a}),e&&n.length>0&&!f&&(0,$.jsx)(`button`,{type:`button`,className:`em-focus-pill`,"aria-expanded":b,"aria-controls":b?o:void 0,onClick:e=>{_(!b),b&&e.currentTarget.focus()},children:b?`Hide`:`${n.length} ${w(n.length,`comment`)}${x}`})]})})}var gd=[];function _d(e){return[...e.blocks,...e.subsections?.flatMap(e=>e.blocks)??[]]}function vd({reviewId:e,revision:t,changedBlocks:n,threads:r,topics:i,groups:a,resumedBlockId:o,activeThreadId:s,threadJump:c,focus:l=!1,files:u=gd,onNote:d}){let f=(0,Q.useId)(),p=(0,Q.useRef)(null);dd(p,a,u,d);let m=(0,Q.useRef)(null),h=(0,Q.useRef)(void 0),g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),v=(0,Q.useRef)(0),y=(0,Q.useRef)(!1),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(``),E=t=>{g.current=document.activeElement instanceof HTMLElement&&p.current?.contains(document.activeElement)?document.activeElement:null,Re(_t(e,t),`reading`),x(t),C(!0),T(``)},D=()=>{_.current=null,C(!1),x(null)};(0,Q.useEffect)(()=>{b||(_.current=null)},[b]);let O=new Map(n.map(e=>[e.blockId,e.revision])),k=(0,Q.useMemo)(()=>new Map(a.flatMap(e=>_d(e).map(t=>[t.id,e.path]))),[a]),ee=(0,Q.useMemo)(()=>{let e=new Map;for(let t of r){if(t.placement.status!==`placed`)continue;let n=t.placement.location;if(!(`blockId`in n)||!k.has(n.blockId))continue;let r=k.get(n.blockId);if(r===void 0?n.kind!==`writeup-span`:n.kind!==`doc-span`||n.path!==r)continue;let i=e.get(n.blockId)??[];i.push(t),e.set(n.blockId,i)}return e},[r,k]);(0,Q.useLayoutEffect)(()=>{if(!p.current||!ge())return;let e=[];for(let t of p.current.querySelectorAll(`[data-block-id]`))try{let n=ee.get(t.dataset.blockId??``);if(!n)continue;let r=ud(t);if(!r)continue;let i=new Map;for(let e of n){if(e.state===`resolved`||e.placement.status!==`placed`)continue;let t=e.placement.location;if(t.kind!==`writeup-span`&&t.kind!==`doc-span`)continue;let n=r(t.start,t.end);n&&i.set(e.id,n)}e.push(i)}catch{}let t=zt(e);return h.current=t,()=>{t?.unregister(),h.current=void 0}},[ee,t,e]),(0,Q.useLayoutEffect)(()=>h.current?.setActiveThread(s)),(0,Q.useEffect)(()=>{let e=e=>{if(!p.current||S||e?.target instanceof Node&&m.current?.contains(e.target))return;let t=window.getSelection();if(!e){if(y.current||Date.now()<v.current)return;if(t&&!t.isCollapsed&&!(p.current.contains(t.anchorNode)&&p.current.contains(t.focusNode))){x(null),T(``);return}}if(!t||t.isCollapsed){x(null),T(``);return}let n=It(t,p.current);if(`error`in n){x(null),T(n.error===`cross-block`?`Select text within one paragraph`:n.error===`too-long`?`Select at most 2000 characters.`:``);return}let r=k.get(n.blockId);x(r===void 0?{kind:`writeup-span`,...n}:{kind:`doc-span`,path:r,...n}),T(``)},t=p.current;t?.addEventListener(`mouseup`,e),t?.addEventListener(`keyup`,e);let n=0,r=()=>{y.current||Date.now()<v.current||(window.clearTimeout(n),n=window.setTimeout(()=>e(),200))},i=e=>{e.pointerType===`mouse`&&(y.current=!0)},a=()=>{y.current=!1,v.current===1/0&&(v.current=Date.now()+600)};return document.addEventListener(`selectionchange`,r),document.addEventListener(`pointerdown`,i,!0),document.addEventListener(`pointerup`,a,!0),document.addEventListener(`pointercancel`,a,!0),()=>{window.clearTimeout(n),document.removeEventListener(`selectionchange`,r),document.removeEventListener(`pointerdown`,i,!0),document.removeEventListener(`pointerup`,a,!0),document.removeEventListener(`pointercancel`,a,!0),t?.removeEventListener(`mouseup`,e),t?.removeEventListener(`keyup`,e)}},[S,k]);let A=(r,a,s=!1)=>r.map((u,d)=>(0,$.jsxs)(fd,{block:u,drift:s&&/^drift:/i.test(u.text.trimStart()),changedIn:O.get(u.id),continuesChange:d>0&&O.get(r[d-1]?.id??``)===O.get(u.id),commenting:o===u.id||S&&!!b&&`blockId`in b&&b.blockId===u.id,onComment:()=>{let e=Ne(u);e.quote&&E(a===void 0?{kind:`writeup-span`,...e}:{kind:`doc-span`,path:a,...e})},children:[(0,$.jsx)(hd,{focus:l,reviewId:e,threads:ee.get(u.id)??[],composing:o===u.id||S&&!!b&&`blockId`in b&&b.blockId===u.id,jump:c,children:ee.get(u.id)?.map(r=>(0,$.jsx)(`div`,{className:`mt-2.5 mb-1.5`,children:(0,$.jsx)(Ot,{reviewId:e,revision:t,thread:r,changedBlocks:n,topics:i})},r.id))}),S&&b&&`blockId`in b&&b.blockId===u.id&&(0,$.jsx)(pt,{reviewId:e,revision:t,target:b,topics:i,onSaved:D,onCancel:D,returnFocus:()=>g.current?.isConnected?g.current:p.current?.closest(`[data-reading-scroll]`)??p.current,wrap:e=>(0,$.jsx)(`div`,{className:`mt-3`,children:e})})]},u.id));return(0,$.jsxs)(`div`,{ref:p,tabIndex:-1,className:l?`em-reading-column em-focus-prose`:`em-reading-column pt-4 pb-8 md:pt-7 md:pb-[72px]`,children:[a.map((n,r)=>(0,$.jsxs)(md,{group:n,headingId:`${f}-${r}`,changedIn:_d(n).reduce((e,t)=>Math.max(e,O.get(t.id)??0),0)||void 0,children:[n.content,A(n.blocks,n.path,n.presentation===`decisions`),n.subsections?.map(e=>(0,$.jsxs)(`div`,{className:e.kind===`body`?`em-writeup-details`:`em-writeup-callout em-writeup-${e.kind}`,children:[(0,$.jsx)(`h3`,{className:e.kind===`body`?`sr-only`:`em-writeup-kicker`,children:e.heading}),A(e.blocks,n.path)]},e.key))]},`${e}:${t}:${n.key}`)),!S&&(w||b)&&(0,$.jsxs)(`div`,{ref:m,className:`sticky bottom-0 space-y-3 rounded-lg border border-line-2 bg-raised p-3 shadow-2`,style:{userSelect:`none`,WebkitUserSelect:`none`,WebkitTouchCallout:`none`,touchAction:`manipulation`},children:[w&&(0,$.jsx)(`p`,{role:`status`,children:w}),b&&(0,$.jsx)(Y,{variant:`primary`,size:`sm`,icon:Xe,onPointerDown:e=>{e.preventDefault(),_.current=b,v.current=1/0},onClick:()=>{let e=Date.now()<v.current?_.current:null;_.current=null,E(e??b)},children:`Comment on selection`})]})]})}function yd(e,t){let[n,r]=(0,Q.useState)();return(0,Q.useEffect)(()=>{let n=e.current,i=n?.closest(`[data-reading-scroll]`);if(!n||!i||!t)return;let a=Wu(n,t),o=t.headings?.flatMap(e=>{let t=e.id?a.get(e.id):void 0;return t?[t]:[]})??[],s,c=()=>{s=void 0;let e=n.querySelector(`.em-doc-bar`)?.getBoundingClientRect(),t=Math.max(i.getBoundingClientRect().top,e?.bottom??0)+8;r((o.findLast(e=>e.getBoundingClientRect().top<=t)??o[0])?.id)},l=()=>{s===void 0&&(s=requestAnimationFrame(c))};c(),i.addEventListener(`scroll`,l,{passive:!0});let u=new ResizeObserver(l);return u.observe(n),()=>{i.removeEventListener(`scroll`,l),u.disconnect(),s!==void 0&&cancelAnimationFrame(s)}},[e,t]),n}function bd({headings:e,current:t,onPick:n}){return(0,$.jsx)(`nav`,{"aria-label":`Document contents`,children:(0,$.jsx)(`ul`,{className:`em-doc-contents`,children:e.map(e=>e.id&&(0,$.jsx)(`li`,{"data-level":e.level,children:(0,$.jsx)(`button`,{type:`button`,dir:`auto`,"aria-current":t===e.id?`location`:void 0,onClick:()=>e.id&&n(e.id),children:e.text})},e.id))})})}var xd=Me,Sd=f.pick({quote:!0,prefix:!0,suffix:!0}).strict(),Cd=f.pick({}).strict(),wd=e=>f.shape.quote.refine(t=>t===e).transform(()=>e),Td=Jt.shape.id,Ed=Sd.extend({type:wd(`emend:anchor`)}).or(Cd.extend({type:wd(`emend:ready`)})).or(xd.safeExtend({type:wd(`emend:position`)})).or(Cd.extend({type:wd(`emend:navigate`),path:qe,fragment:C.shape.mediaType.max(1024).refine(e=>e.isWellFormed())}));Cd.extend({type:wd(`emend:highlight`),anchors:Sd.extend({threadId:Td}).array()}).or(Cd.extend({type:wd(`emend:scroll`),threadId:Td})).or(Cd.extend({type:wd(`emend:goto`),heading:xd.shape.heading.unwrap(),label:Ee.shape.text,fraction:xd.shape.fraction.optional()})).or(Cd.extend({type:wd(`emend:docs`),paths:qe.array()}));function Dd({path:e,contentUrl:t,reviewId:n,revision:r,threads:i,topics:a,changedBlocks:o,navigation:s,docNavigation:c,onNavigate:l,composerOpen:u=!1,headings:d=[],docPaths:f=[],reading:p,onPosition:m,commentsOpen:h=!1,onCommentsOpenChange:g=()=>{},returnFocus:_}){let y=Kt()===`phone`,b=JSON.parse((0,Q.useSyncExternalStore)(xt,()=>JSON.stringify(Ft(n).filter(t=>!t.threadId&&t.target?.kind===`html-span`&&t.target.path===e)))),x=(0,Q.useRef)(null),S=(0,Q.useRef)(null),C=(0,Q.useRef)(0),w=(0,Q.useRef)(!1),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(0),[k,ee]=(0,Q.useState)(t),A=(0,Q.useRef)(!1),[j,M]=(0,Q.useState)(0),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(!1),[L,R]=(0,Q.useState)(),z=(0,Q.useRef)(void 0),te=(0,Q.useCallback)(e=>{x.current=e,e&&(C.current=0,w.current=!1,A.current=!1)},[]);(0,Q.useEffect)(()=>{c&&(ee(`${t}#${encodeURIComponent(c.fragment)}`),M(0),E(!1),R(void 0),O(e=>e+1))},[t,c]);let ne=i.filter(t=>t.placement.status===`placed`&&t.placement.location.kind===`html-span`&&t.placement.location.path===e).sort((e,t)=>{let n=e=>e.placement.status===`placed`&&e.placement.location.kind===`html-span`?e.placement.location.start:0;return n(e)-n(t)}),B=[...ne,...i.filter(t=>t.placement.status!==`placed`&&t.target.kind===`html-span`&&t.target.path===e)],re=JSON.stringify(ne.flatMap(e=>e.target.kind===`html-span`?[{threadId:e.id,quote:e.target.quote,prefix:e.target.prefix,suffix:e.target.suffix}]:[])),ie=pe(ne.map(e=>_t(n,e.target,e.id)),`reading`);(0,Q.useEffect)(()=>{ie&&g(!0)},[ie,g]);let V=(0,Q.useCallback)(e=>{A.current&&!w.current&&x.current?.contentWindow?.postMessage(e,`*`)},[]),H=(0,Q.useCallback)(()=>{w.current=!0,A.current=!1,E(!0),M(0),F||P(null)},[F]);(0,Q.useEffect)(()=>{let t=t=>{if(w.current||!x.current?.contentWindow||t.source!==x.current.contentWindow)return;let n=Ed.safeParse(t.data);if(n.success){if(n.data.type===`emend:ready`){if(A.current){H();return}A.current=!0,M(e=>e+1)}else if(n.data.type===`emend:position`){if(!A.current||n.data.heading!==null&&!d[n.data.heading])return;let e={heading:n.data.heading,fraction:n.data.fraction};if(m?.(e),p){let t=e.heading===null?null:{id:`h-${e.heading}`,fraction:e.fraction};p.entry.positions.set(p.key,t),id(p.key,t)}}else if(n.data.type===`emend:navigate`)l?.(n.data);else if(!F&&!u){let{quote:t,prefix:r,suffix:i}=n.data;P({kind:`html-span`,path:e,quote:t,prefix:r,suffix:i})}}};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)},[e,F,u,l,d,p,m,H]),(0,Q.useEffect)(()=>{j&&!w.current&&x.current?.contentWindow?.postMessage({type:`emend:highlight`,anchors:JSON.parse(re)},`*`)},[j,re]);let U=JSON.stringify(f),W=(0,Q.useRef)(void 0);return(0,Q.useEffect)(()=>{j&&!w.current&&V({type:`emend:docs`,paths:JSON.parse(U)})},[j,U,V]),(0,Q.useEffect)(()=>{if(!j||w.current||!p)return;let e=x.current?.contentWindow??null,n=W.current;if(n?.reading===p&&n.window===e)return;W.current={reading:p,window:e};let r=p.entry.positions.get(p.key),i=p.returning&&p.entry.positions.has(p.key),a=p.target!==void 0&&/^(0|[1-9]\d*)$/.test(p.target)?Number(p.target):void 0,o=i?r:p.target===void 0?s||c?null:rd(p.key):a===void 0?null:{id:`h-${a}`,fraction:0};if(o&&/^h-(0|[1-9]\d*)$/.test(o.id)){let e=Number(o.id.slice(2)),t=d[e];if(t){let n=!i&&p.target!==void 0;n&&(p.entry.positions.delete(p.key),p.entry.focus={id:`h-${e}`,children:[]}),V({type:`emend:goto`,heading:e,label:t.text,...n?{}:{fraction:o.fraction}}),(p.target!==void 0||i&&p.entry.focus)&&Xu(x.current);return}}n&&n.reading!==p&&(i&&!r||p.target!==void 0)&&(ee(t),M(0),O(e=>e+1)),!s&&!c&&p.entry.positions.set(p.key,null)},[j,p,d,s,c,V,t]),(0,Q.useEffect)(()=>{R(s)},[s]),(0,Q.useEffect)(()=>{!j||w.current||p?.target!==void 0||p?.returning&&p.entry.positions.has(p.key)||!L||z.current===L||!ne.some(e=>e.id===L.threadId)||(x.current?.contentWindow?.postMessage({type:`emend:scroll`,threadId:L.threadId},`*`),z.current=L)},[j,L,ne,p]),(0,$.jsxs)(`div`,{ref:S,tabIndex:-1,className:`em-html-doc`,id:`html-doc-${e}`,children:[(0,$.jsx)(`div`,{className:`em-html-frame`,children:(0,$.jsx)(`iframe`,{ref:te,sandbox:`allow-scripts`,src:k,title:e,referrerPolicy:`no-referrer`,className:`h-full min-h-0 w-full border-0 bg-[#fff]`,onLoad:()=>{++C.current<=1||H()}},D)}),T&&(0,$.jsxs)(`div`,{role:`status`,className:`space-y-2`,children:[(0,$.jsx)(`p`,{children:`This doc navigated away.`}),(0,$.jsxs)(Y,{onClick:()=>{ee(t),E(!1),M(0),z.current=void 0,O(e=>e+1)},children:[`Reload `,e]})]}),(0,$.jsxs)(v,{side:y?`bottom`:`right`,title:`Comments`,open:h,onOpenChange:g,returnFocus:_,children:[B.map(e=>(0,$.jsxs)(`div`,{className:`space-y-2`,children:[e.placement.status===`placed`&&(0,$.jsx)(Y,{onClick:()=>{y&&g(!1),j?V({type:`emend:scroll`,threadId:e.id}):w.current||R({threadId:e.id,intent:{}})},children:`Show in doc`}),(0,$.jsx)(Ot,{reviewId:n,revision:r,changedBlocks:o,thread:e,topics:a})]},e.id)),!B.length&&(0,$.jsx)(`p`,{children:`No comments on this doc yet.`}),!F&&b.map(e=>(0,$.jsx)(Y,{onClick:()=>{e.target?.kind===`html-span`&&(P(e.target),Re(e.key,`reading`),I(!0))},children:`Resume selection comment`},e.key)),N&&F&&!u&&(0,$.jsx)(pt,{reviewId:n,revision:r,target:N,topics:a,onSaved:()=>{I(!1),P(null)},onCancel:()=>I(!1),returnFocus:()=>_?.()??S.current})]}),N&&!F&&!u&&(0,$.jsx)(`div`,{className:`em-html-selection`,children:(0,$.jsx)(Y,{variant:`primary`,size:`sm`,icon:Xe,onClick:()=>{Re(_t(n,N),`reading`),g(!0),I(!0)},children:`Comment on selection`})})]})}function Od({label:e,icon:t,children:n}){let r=Kt()===`phone`,[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)(null),s=(0,Q.useRef)(null),c=e=>{o.current=e,a(!1)},l=()=>{let e=o.current;o.current=null,e?.()},u=(0,$.jsxs)(Y,{ref:s,variant:`ghost`,"aria-label":e,"aria-haspopup":`dialog`,"aria-expanded":i,onClick:r?()=>a(!0):void 0,className:`em-doc-control`,children:[(0,$.jsx)(X,{icon:t}),(0,$.jsx)(`span`,{className:`em-doc-control-label`,children:e})]});return r?(0,$.jsxs)($.Fragment,{children:[u,(0,$.jsx)(v,{side:`bottom`,title:e,open:i,onOpenChange:a,returnFocus:()=>s.current,onClosed:l,children:n(c)})]}):(0,$.jsxs)(M,{modal:!1,open:i,onOpenChange:a,children:[(0,$.jsx)(se,{asChild:!0,children:u}),(0,$.jsxs)(we,{"aria-describedby":void 0,className:`em-reading-popover`,onCloseAutoFocus:e=>{o.current&&e.preventDefault(),l()},children:[(0,$.jsxs)(`header`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(Ae,{children:e}),(0,$.jsx)(De,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,"aria-label":`Close`,children:(0,$.jsx)(X,{icon:Pt})})})]}),n(c)]})]})}var kd=(0,Q.memo)(function({tokens:e,number:t,selected:n,commented:r,active:i}){return(0,$.jsxs)(`div`,{className:`em-source-line`,"data-source-line":t,"data-selected":n?``:void 0,"data-commented":r?``:void 0,"data-active":i?``:void 0,children:[(0,$.jsx)(`button`,{type:`button`,className:`em-source-number`,"aria-label":`Comment on line ${t}`,"aria-pressed":n,"data-source-number":t,children:t}),(0,$.jsx)(`code`,{className:`em-source-code`,children:e.map((e,t)=>(0,$.jsx)(`span`,{style:e.light||e.dark?{"--shiki-light":e.light,"--shiki-dark":e.dark}:void 0,children:e.text},t))})]})}),Ad=(0,Q.memo)(function({lines:e,start:t,selectionStart:n,selectionEnd:r,required:i,target:a,byEnd:o,marked:s,active:c,onClose:l,returnFocus:u,reviewId:d,revision:f,changedBlocks:p,topics:m,threadJump:h}){let g=(0,Q.useRef)(null),_=(0,Q.useRef)(void 0),[v,y]=(0,Q.useState)(t<=400),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(0),[w]=(0,Q.useState)(()=>new Map),T=(0,Q.useCallback)(()=>(C(e=>e+1),()=>C(e=>e-1)),[]),E=v||i||b||S>0,[D,O]=(0,Q.useState)(t<=400),k=e.some((e,n)=>o.has(t+n));return(0,Q.useLayoutEffect)(()=>{if(D!==E){if(!E&&k&&g.current?.getClientRects().length){let e=g.current.getBoundingClientRect();Number.isFinite(e.height)&&e.height>0&&Number.isFinite(e.width)&&e.width>0&&(_.current=e.height)}O(E)}},[D,E,k]),(0,Q.useEffect)(()=>{if(!g.current||typeof IntersectionObserver>`u`)return;let e=new IntersectionObserver(e=>{for(let t of e)t.target===g.current&&y(t.isIntersecting)},{rootMargin:`1200px 0px`});return e.observe(g.current),()=>e.disconnect()},[]),!D&&!E?(0,$.jsx)(`div`,{ref:g,"data-source-chunk":t,style:{height:k&&_.current!==void 0?_.current:`calc(${e.length} * var(--source-line-height))`},children:typeof IntersectionObserver>`u`&&(0,$.jsxs)(`button`,{type:`button`,className:`em-source-show`,onClick:()=>x(!0),children:[`Show lines `,t,`–`,t+e.length-1]})}):(0,$.jsx)(`div`,{ref:g,"data-source-chunk":t,children:e.flatMap((e,i)=>{let g=t+i,_=o.get(g),v=a?.end===g,y=(0,$.jsx)(kd,{tokens:e,number:g,selected:n!==void 0&&g>=n&&g<=(r??n),commented:s.has(g),active:c.has(g)},g);return!_&&!v?[y]:[y,(0,$.jsxs)(`div`,{className:`em-source-discussion`,"data-source-end":g,children:[_&&(0,$.jsx)(hd,{focus:!1,reviewId:d,threads:_,composing:v,jump:h,children:(0,$.jsx)(We,{value:T,children:(0,$.jsx)(Wt,{value:w,children:_.map(e=>(0,$.jsx)(Ot,{reviewId:d,revision:f,thread:e,changedBlocks:p,topics:m},e.id))})})}),v&&a&&(0,$.jsx)(pt,{surface:`reading`,reviewId:d,revision:f,target:a,topics:m,onSaved:l,onCancel:l,returnFocus:u})]},`discussion-${g}`)]})})});function jd(e,t,n,r){let i=nt(t,n,r);return`error`in i?i:k.parse({kind:`source-lines`,path:e,...i})}var Md=(0,Q.memo)(function({doc:e,reviewId:t,revision:n,threads:r,changedBlocks:i,topics:a,activeThreadId:o,threadJump:s}){let c=(0,Q.useRef)(null),l=(0,Q.useRef)(void 0),u=(0,Q.useRef)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(``),h=(0,Q.useMemo)(()=>e.lines.map(e=>e.map(e=>e.text).join(``)),[e.lines]),g=(0,Q.useMemo)(()=>{let t=[];for(let n=0;n<e.lines.length;n+=200)t.push({start:n+1,lines:e.lines.slice(n,n+200)});return t},[e.lines]),{byEnd:_,marked:v,active:y,requiredChunks:b}=(0,Q.useMemo)(()=>{let t=new Map,n=new Set,i=new Set,a=new Set;for(let c of r){if(c.placement.status!==`placed`)continue;let r=c.placement.location;if(r.kind!==`source-lines`||r.path!==e.path||r.end>h.length)continue;let l=t.get(r.end)??[];l.push(c),t.set(r.end,l);for(let e=r.start;e<=r.end;e++)n.add(e),(c.id===o||c.id===s?.threadId)&&a.add(Math.floor((e-1)/200)*200+1),c.id===o&&i.add(e)}return{byEnd:t,marked:n,active:i,requiredChunks:a}},[r,e.path,h.length,o,s?.threadId]),x=(0,Q.useCallback)((n,r,i)=>{r&&l.current!==void 0||(l.current=n),u.current=i;let a=jd(e.path,h,Math.min(l.current,n),Math.max(l.current,n));`error`in a?(f(null),m(Fe(a.error))):(Re(_t(t,a),`reading`),f(a),m(``))},[e.path,h,t]),S=(0,Q.useCallback)(()=>{f(null),l.current=void 0},[]),C=(0,Q.useCallback)(()=>u.current?.isConnected?u.current:c.current,[]);return(0,$.jsxs)(`div`,{ref:c,className:`em-source`,tabIndex:-1,children:[p&&(0,$.jsx)(`p`,{role:`alert`,className:`p-3`,children:p}),!e.lines.length&&(0,$.jsx)(`p`,{className:`p-3`,children:e.unrendered?`This file could not be shown.`:`This file is empty.`}),(0,$.jsx)(`div`,{className:`em-source-scroll`,onClickCapture:e=>{let t=e.target instanceof Element?e.target.closest(`button[data-source-number]`):null;t&&x(Number(t.dataset.sourceNumber),e.shiftKey,t)},children:g.map(({start:e,lines:r})=>{let o=e+r.length-1,c=d&&d.start<=o&&d.end>=e;return(0,$.jsx)(Ad,{lines:r,start:e,required:!!c||b.has(e),selectionStart:c?Math.max(e,d.start):void 0,selectionEnd:c?Math.min(o,d.end):void 0,target:d&&d.end>=e&&d.end<=o?d:null,byEnd:_,marked:v,active:y,onClose:S,returnFocus:C,reviewId:t,revision:n,changedBlocks:i,topics:a,threadJump:s},e)})})]})});function Nd({docs:e,openDoc:t,search:n,targeted:r,onOpenDoc:i,navigation:a,composingPath:o,onHeading:s=()=>{},back:c,entry:l,returning:u=!1,headingTarget:d,visit:f,...p}){let m=(0,Q.useRef)(null),h=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=h.current;if(!e||!t?.path)return;let n=new ResizeObserver(()=>{let t=e.getBoundingClientRect().height;t&&m.current?.style.setProperty(`--doc-bar-height`,`${t}px`)});return n.observe(e),()=>n.disconnect()},[t?.path]);let[g,_]=(0,Q.useState)(``),v=yd(m,t),[y,b]=(0,Q.useState)(),[x,S]=(0,Q.useState)(!1),C=(0,Q.useRef)(null),w=(0,Q.useCallback)(e=>{t&&b({path:t.path,heading:e.heading})},[t]),T=t?.kind===`html`?y?.path===t.path&&y.heading!==null?String(y.heading):void 0:v,E=(0,Q.useMemo)(()=>t?.kind===`source`?[]:t?.kind===`html`?(t.headings??[]).map((e,t)=>({...e,id:String(t)})):t?.headings?.filter(e=>e.id)??[],[t]),D=(0,Q.useMemo)(()=>l&&t?.kind===`html`?{key:td(p.reviewId,`docs`,t.path,p.revision,qu(t,n.view)??`original`),entry:l,returning:u,target:d,visit:f}:void 0,[l,t,p.reviewId,p.revision,n.view,u,d,f]),O=p.threads.filter(e=>e.state!==`resolved`&&t&&Ku(e,t)).length,k=E.length>=3,ee=(0,Q.useId)(),A=(0,Q.useRef)(null),j=(0,Q.useRef)(new Map),M=(0,Q.useRef)(null),[N,P]=(0,Q.useState)(),F=t?.path,I=t?Gu(t):void 0,L=`${n.view??`rendered`}:${n.doc??``}`;(0,Q.useEffect)(()=>{let e=M.current;if(M.current={path:I,doc:L},e&&e.path!==I&&S(!1),e&&I===e.path)return;let n=e&&e.doc!==L&&!r;if(P(e=>e?.path===F?e:void 0),F){if(e&&t?.kind===`source`&&!r){let e=m.current?.closest(`[data-reading-scroll]`);e&&(e.scrollTop=0)}n&&Xu(A.current)}else if(e?.path&&n){let t=j.current.get(e.path);Xu(t),t?.scrollIntoView?.({block:`nearest`})}},[F,I,L,r,t?.kind]);let R=t=>{let n=e.find(e=>e.path===t.path&&e.kind!==`source`);n&&Gu(n)!==I&&(P(n.kind===`html`&&t.fragment?t:void 0),i(n))},z=t?.kind===`html`?(0,$.jsx)(Dd,{...p,path:t.path,contentUrl:t.contentUrl,navigation:a,docNavigation:N?.path===t.path?N:void 0,onNavigate:R,composerOpen:o===t.path,headings:t.headings,docPaths:e.filter(e=>e.kind!==`source`).map(e=>e.path),reading:D,onPosition:w,commentsOpen:x,onCommentsOpenChange:S,returnFocus:()=>C.current},t.contentUrl):void 0,te=(0,Q.useMemo)(()=>t?[{key:t.path,id:`doc-${t.path}`,labelledBy:ee,path:t.path,blocks:t.kind===`markdown`?t.blocks:[],content:z}]:[],[t,ee,z]);return t?(0,$.jsxs)(`div`,{ref:m,className:`em-doc-view`,"data-layout":t.kind===`html`?`original`:void 0,"data-contents":k?``:void 0,children:[(0,$.jsxs)(`div`,{ref:h,className:`em-doc-bar sticky z-(--z-sticky) border-b border-line-1 bg-surface`,children:[(0,$.jsxs)(`div`,{className:`em-doc-title`,children:[(0,$.jsx)(`h2`,{ref:A,id:ee,title:t.path,tabIndex:-1,dir:`auto`,children:zu(t)}),(0,$.jsx)(`div`,{className:`em-doc-path`,dir:`auto`,children:Bu(t,e)})]}),(0,$.jsxs)(`div`,{className:`em-doc-controls`,children:[c&&(0,$.jsxs)(Y,{variant:`ghost`,className:`em-doc-control`,"aria-label":`Back to ${c.title}`,onClick:c.go,children:[(0,$.jsx)(X,{icon:Vo}),(0,$.jsxs)(`span`,{className:`em-doc-control-label`,dir:`auto`,children:[`Back to `,c.title]})]}),e.length>1&&(0,$.jsx)(Od,{label:`Docs`,icon:ps,children:t=>(0,$.jsxs)($.Fragment,{children:[e.length>8&&(0,$.jsx)(`input`,{className:`em-doc-filter`,"aria-label":`Filter docs`,value:g,onChange:e=>_(e.target.value)}),(0,$.jsx)(`ul`,{className:`em-doc-options`,children:e.filter(e=>`${zu(e)} ${e.path}`.toLowerCase().includes(g.toLowerCase())).map(n=>{let r=p.threads.filter(e=>e.state!==`resolved`&&Ku(e,n)).length;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,"aria-current":Gu(n)===I?`page`:void 0,onClick:()=>t(()=>{_(``),i(n),Gu(n)===I&&Xu(A.current)}),children:[(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{dir:`auto`,children:zu(n)}),(0,$.jsx)(`small`,{dir:`auto`,children:Bu(n,e)}),n.kind===`source`&&(0,$.jsx)(`small`,{children:`Source`})]}),(0,$.jsxs)(`span`,{children:[r,` open `,r===1?`comment`:`comments`]})]})},Gu(n))})})]})}),t.kind===`html`&&(0,$.jsxs)(Y,{ref:C,variant:`ghost`,className:`em-doc-control`,"aria-label":`Comments (${O})`,"aria-haspopup":`dialog`,"aria-expanded":x,onClick:()=>S(!0),children:[(0,$.jsx)(X,{icon:mt}),(0,$.jsxs)(`span`,{className:`em-doc-control-label`,children:[`Comments (`,O,`)`]})]}),k&&(0,$.jsx)(`span`,{className:`em-doc-contents-control`,children:(0,$.jsx)(Od,{label:`Contents`,icon:Qe,children:e=>(0,$.jsx)(bd,{headings:E,current:T,onPick:t=>e(()=>s(t))})})}),e.length>1&&(0,$.jsx)(Y,{asChild:!0,variant:`ghost`,className:`em-doc-control`,children:(0,$.jsxs)(co,{to:`/r/$reviewId`,"aria-label":`All docs`,params:{reviewId:p.reviewId},search:{...n,tab:`docs`,doc:void 0,view:qu(void 0,n.view),thread:void 0},hash:``,children:[(0,$.jsx)(X,{icon:Cs}),(0,$.jsx)(`span`,{className:`em-doc-control-label`,children:`All docs`})]})})]}),t.kind===`html`&&(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-fg-3 [font:var(--type-meta)]`,children:[(0,$.jsx)(X,{icon:Ys,size:13}),`Sandboxed, scripts off`]})]}),(0,$.jsxs)(`div`,{className:`em-doc-body`,"data-reading-doc":t.path,children:[t.kind===`source`?(0,$.jsx)(Md,{...p,doc:t},Gu(t)):t.kind===`html`?z:(0,$.jsx)(vd,{...p,groups:te},Gu(t)),k&&(0,$.jsx)(`aside`,{className:`em-doc-contents-rail`,children:(0,$.jsx)(bd,{headings:E,current:T,onPick:s})})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h2`,{className:`sr-only`,children:`Docs`}),(0,$.jsx)(`ul`,{className:`flex flex-col gap-2 p-4`,children:e.map(e=>{let t=zu(e);return(0,$.jsx)(`li`,{children:(0,$.jsxs)(co,{ref:t=>{t?j.current.set(Gu(e),t):j.current.delete(Gu(e))},to:`/r/$reviewId`,params:{reviewId:p.reviewId},search:{...n,tab:`docs`,doc:e.path,view:qu(e,n.view),thread:void 0},hash:``,className:`em-doc-row grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-lg border border-line-1 bg-surface px-3.5 py-3 text-fg-2 no-underline hover:border-line-2 hover:bg-sunken`,children:[(0,$.jsx)(X,{icon:e.kind===`source`?ds:e.kind===`html`?Gt:Lt,size:18}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-[3px]`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`truncate font-sans text-14 leading-[1.3] font-semibold text-fg-1`,children:t}),(0,$.jsx)(`span`,{dir:`auto`,className:`em-doc-path truncate font-stretch-mono text-fg-3`,children:e.path}),e.kind===`source`&&(0,$.jsx)(`span`,{className:`text-fg-3 [font:var(--type-meta)]`,children:`Source`})]}),(0,$.jsx)(X,{icon:me,size:16})]})},Gu(e))})})]})}function Pd(e){for(let t=e;t;t=t.parentElement)t instanceof HTMLDetailsElement&&(t.open=!0);e.dispatchEvent(new Event(`emend:reveal-reading`,{bubbles:!0}))}function Fd({root:e,groups:t,threads:n,visible:r,onCurrentTopic:i}){let a=(0,Q.useRef)(null),o=(0,Q.useMemo)(()=>t.filter(e=>e.key!==`topics-map`),[t]),[s,c]=(0,Q.useState)(o[0]?.key),l=(0,Q.useMemo)(()=>{let e=new Map(o.flatMap(e=>[...e.blocks,...e.subsections?.flatMap(e=>e.blocks)??[]].map(t=>[t.id,e.key]))),t=new Map(o.flatMap(e=>e.topic?[[e.topic.slug,e.key]]:[])),r=new Map;for(let i of n){if(i.placement.status!==`placed`)continue;let n=i.placement.location,a=n.kind===`writeup-span`?e.get(n.blockId):n.kind===`topic`?t.get(n.slug):void 0;a&&r.set(a,(r.get(a)??0)+1)}return r},[o,n]);return(0,Q.useEffect)(()=>{let t=e.current,n=t?.closest(`[data-reading-scroll]`);if(!r||!t||!n)return;let s=!1,l,u,d=null,f=0,p=!1,m=o.flatMap(e=>{let n=[...t.querySelectorAll(`[data-reading-section]`)].find(t=>t.dataset.readingSection===e.key)?.querySelector(`h2, summary`);return n?[{group:e,heading:n}]:[]}),h=()=>!s&&!n.closest(`[hidden]`),g=()=>{if(!h())return;let e=n.getBoundingClientRect().top,t=e+f+96,r=m.map(e=>({...e,rect:e.heading.getBoundingClientRect()})),a=(p?r.findLast(({rect:t})=>t.bottom>e+f&&t.top<e+n.clientHeight):void 0)??r.findLast(({rect:e})=>e.top<=t)??r[0];c(a?.group.key),i?.(a?.group.topic?.slug)},_=()=>{if(l=void 0,!h()||!a.current)return;let e=n.scrollHeight-n.clientHeight,t=n.scrollTop,r=e>0?Math.min(1,Math.max(0,t/e)):1;a.current.style.transform=`scaleX(${r})`;let i=e>0&&t>=e-1;i!==p&&(p=i,g())},v=()=>{h()&&l===void 0&&(l=requestAnimationFrame(_))},y=()=>{if(!h())return;u?.disconnect();let e=n.querySelector(`.em-review-tabs`);d!==e&&(d&&b.unobserve(d),d=e,d&&b.observe(d)),f=d?.getBoundingClientRect().height??0,t.style.setProperty(`--reading-sticky-top`,`${f}px`);let r=f+96;u=new IntersectionObserver(g,{root:n,rootMargin:`-${r}px 0px ${n.scrollHeight}px 0px`,threshold:1});for(let{heading:e}of m)u.observe(e);g(),v()},b=new ResizeObserver(y);return y(),b.observe(n),b.observe(t),n.addEventListener(`scroll`,v,{passive:!0}),()=>{s=!0,u?.disconnect(),b.disconnect(),n.removeEventListener(`scroll`,v),l!==void 0&&cancelAnimationFrame(l),t.style.removeProperty(`--reading-sticky-top`)}},[e,o,r,i]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{ref:a,className:`em-focus-progress`,style:{transform:`scaleX(0)`},"aria-hidden":`true`}),(0,$.jsxs)(`nav`,{className:`em-focus-outline`,"aria-label":`Writeup outline`,children:[(0,$.jsx)(`div`,{className:`em-focus-outline__label`,children:`WRITEUP`}),o.map(t=>{let n=l.get(t.key)??0;return(0,$.jsxs)(`button`,{type:`button`,className:`em-focus-outline__item`,"aria-current":s===t.key?`location`:void 0,onClick:()=>{let n=[...e.current?.querySelectorAll(`[data-reading-section]`)??[]].find(e=>e.dataset.readingSection===t.key);n&&(c(t.key),i?.(t.topic?.slug),Pd(n),n.scrollIntoView({block:`start`}))},children:[t.rank!==void 0&&(0,$.jsx)(U,{rank:t.rank}),(0,$.jsx)(`span`,{className:`em-focus-outline__text`,children:t.topic?.title??t.heading}),n>0&&(0,$.jsxs)(`span`,{className:`em-focus-outline__count`,title:`${n} ${w(n,`comment`)}`,children:[n,(0,$.jsxs)(`span`,{className:`sr-only`,children:[` `,w(n,`comment`)]})]})]},t.key)})]})]})}function Id({topics:e,fileCount:t,href:n}){return(0,$.jsx)(`ol`,{className:`-mx-2.5 mb-2 flex list-none flex-col gap-0.5`,children:e.map(({topic:e,rank:r})=>{let i=n(e.slug),a=t(e.slug);return(0,$.jsxs)(`li`,{className:`relative grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-2.5 gap-y-0.5 rounded-md px-2.5 py-2 hover:bg-hover`,children:[(0,$.jsx)(`span`,{className:`mt-px`,children:(0,$.jsx)(U,{rank:r})}),(0,$.jsx)(`span`,{className:`wrap-anywhere text-[15px] font-medium leading-[1.35] text-fg-1`,children:i?(0,$.jsx)(`a`,{href:i,className:`after:absolute after:inset-0 after:rounded-md after:content-['']`,children:e.title}):e.title}),(0,$.jsx)(`p`,{className:`col-start-2 text-pretty wrap-anywhere text-14 leading-[1.45] text-fg-2`,children:e.summary}),(e.attention||e.door||e.blastRadius||a>0)&&(0,$.jsxs)(`div`,{className:`col-start-2 mt-0.5 flex flex-wrap gap-x-3 gap-y-1 text-fg-3 [font:var(--type-meta)]`,children:[(0,$.jsx)(Tt,{topic:e}),a>0&&(0,$.jsxs)(`span`,{children:[a,` `,w(a,`file`)]})]})]},e.slug)})})}function Ld(e,t,n,r=!0){(0,Q.useEffect)(()=>{let i=e.current,a=i?.closest(`[data-reading-scroll]`);if(!i||!a||!t||!r)return;let o=!1,s=new Set(n.map(e=>e.topic).filter(Boolean)),c=[...i.querySelectorAll(`section[id^="topic-"]`)].filter(e=>s.has(e.id.slice(6))),l=()=>{if(o||a.closest(`[hidden]`))return;let e=a.querySelector(`[role="tablist"]`)?.getBoundingClientRect().height??0,n=a.getBoundingClientRect().top+e+1;t(c.findLast(e=>e.getBoundingClientRect().top<=n)?.id.slice(6))},u,d=()=>{if(o||a.closest(`[hidden]`))return;u?.disconnect();let e=a.querySelector(`[role="tablist"]`)?.getBoundingClientRect().height??0;u=new IntersectionObserver(l,{root:a,rootMargin:`-${e}px 0px -${Math.max(0,a.clientHeight-e-1)}px 0px`,threshold:0});for(let e of c)u.observe(e)};d();let f=new ResizeObserver(d);return f.observe(a),()=>{o=!0,u?.disconnect(),f.disconnect()}},[e,t,n,r])}var Rd=[],zd=[];function Bd({writeup:e,topics:t=Rd,files:n=zd,search:r={},phone:i=!1,visible:a=!0,onCurrentTopic:o,onNote:s,...c}){let l=(0,Q.useRef)(null),{reading:u}=Vt(),d=!i&&u===`focus`;Ld(l,o,e.sections,a&&!d),(0,Q.useEffect)(()=>()=>o?.(void 0),[o]);let f=(0,Q.useMemo)(()=>{let a=x(t),o=new Map(a.map(e=>[e.topic.slug,e])),s=new Map;for(let e of n)e.role===`diff`&&e.topic&&s.set(e.topic,(s.get(e.topic)??0)+1);let l=e=>s.get(e)??0,u=(e,t=!1)=>{let n={tab:t&&i?`diff`:r.tab,rev:r.rev},a=new URLSearchParams;for(let[e,t]of Object.entries(n))t!==void 0&&a.set(e,String(t));return`/r/${encodeURIComponent(c.reviewId)}${a.size?`?${a}`:``}#${e}`},d=new Map(e.sections.flatMap(e=>e.blocks.map(t=>[t.id,e.topic]))),f=new Map;for(let e of c.threads){if(e.state===`resolved`||e.placement.status!==`placed`)continue;let t=e.placement.location,n=t.kind===`topic`?t.slug:t.kind===`writeup-span`?d.get(t.blockId):void 0;n&&f.set(n,(f.get(n)??0)+1)}let p=[];for(let t of e.sections){let e=t.topic?o.get(t.topic):void 0;if(!e){p.push({key:t.key,heading:t.key===`decisions`?`Decisions & drift`:t.label,blocks:t.blocks,presentation:t.key===`tldr`||t.key===`decisions`||t.key===`glossary`?t.key:void 0});continue}let{topic:n,rank:r}=e,i=p.at(-1);i?.id!==`topic-${n.slug}`&&(i={key:t.key,id:`topic-${n.slug}`,topic:n,rank:r,commentCount:f.get(n.slug)??0,heading:(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`span`,{children:[(0,$.jsxs)(`span`,{className:`sr-only`,children:[`Topic `,r,`: `]}),n.title]})}),blocks:[],subsections:[],action:l(n.slug)>0&&(0,$.jsxs)(`a`,{href:u(`diff-topic-${n.slug}`,!0),"aria-label":`Files in diff: ${n.title}`,className:`em-topic-files`,children:[l(n.slug),` `,w(l(n.slug),`file`),` · Files in diff`,` `,(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`→`})]}),meta:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`em-topic-summary`,children:n.summary}),n.blastRadius&&(0,$.jsxs)(`p`,{className:`em-topic-blast`,children:[`Blast radius: `,(0,$.jsx)(`strong`,{children:n.blastRadius.scope}),` — `,n.blastRadius.note]})]})},p.push(i));let a=t.key.slice(t.key.lastIndexOf(`-`)+1),s=a===`why`||a===`example`?a:`body`,c=s===`why`?`Why`:s===`example`?`Example`:`Details`;i.subsections?.push({key:t.key,heading:c,kind:s,blocks:t.blocks})}if(a.length){let e=new Set(p.flatMap(e=>e.id?[e.id]:[])),t=p.findLastIndex(e=>[`overview`,`tldr`,`decisions`,`glossary`].includes(e.key))+1;p.splice(t,0,{key:`topics-map`,heading:`Topics`,blocks:[],content:(0,$.jsx)(Id,{topics:a,fileCount:l,href:t=>e.has(`topic-${t}`)?u(`topic-${t}`):l(t)>0?u(`diff-topic-${t}`,!0):void 0})})}return p},[e.sections,t,n,r.tab,r.rev,i,c.reviewId,c.threads]);return(0,$.jsx)(`div`,{className:d?`em-focus-container`:`contents`,children:(0,$.jsxs)(`div`,{ref:l,className:d?`em-focus`:`contents`,children:[d&&(0,$.jsx)(Fd,{root:l,groups:f,threads:c.threads,visible:a,onCurrentTopic:o}),(0,$.jsx)(vd,{...c,topics:t,groups:f,focus:d,files:n,onNote:s})]})})}function Vd({review:e,seq:t,onChange:n}){let r=e.newestRevision,i=t<r,a=Date.now();return(0,$.jsx)($e,{label:i?`Revision ${t}, ${r} is newer`:`Revision ${t} of ${r}`,align:`left`,trigger:(0,$.jsxs)(Y,{size:`sm`,iconRight:p,className:`gap-1.5 pr-1.5 leading-none shadow-none`,children:[`Revision `,(0,$.jsx)(`span`,{className:`font-mono text-11 font-semibold font-stretch-mono`,children:t}),i?(0,$.jsxs)(`span`,{className:`font-semibold text-warning-fg`,children:[`· `,r,` is newer`]}):(0,$.jsxs)(`span`,{className:`text-fg-3`,children:[`of `,r]})]}),items:[{radioGroup:{value:String(t),onValueChange:e=>n(Number(e)),items:[...e.revisions].sort((e,t)=>t.seq-e.seq).map(e=>({value:String(e.seq),label:(0,$.jsxs)($.Fragment,{children:[`Revision `,e.seq,e.seq===r&&(0,$.jsx)(`span`,{className:`inline-flex h-4 shrink-0 items-center rounded-xs bg-accent px-[5px] text-[9.5px] font-semibold leading-none tracking-[.04em] text-accent-fg uppercase`,children:`Latest`})]}),hint:Uc(e.createdAt,a)}))}}]})}var Hd={pr:ys,issue:$o,other:ss};function Ud(e){return(e??[]).flatMap(e=>{try{let t=new URL(e.url);return t.protocol===`https:`&&t.username===``&&t.password===``?[{...e,host:t.host,href:t.href}]:[]}catch{return[]}})}function Wd({review:e,revision:t,seq:n,ready:r,phone:i,titleRef:a,onRevisionChange:o,onCommentReview:s}){let c=nl(e),[l,u]=(0,Q.useState)(Date.now);(0,Q.useEffect)(()=>{let e=window.setInterval(()=>u(Date.now()),6e4);return()=>window.clearInterval(e)},[]);let d=t&&[t.base?.slice(0,7),t.head===`worktree`?`working tree`:t.head?.slice(0,7)].filter(Boolean).join(` → `),f=Ud(t?.links),p=`inline-flex min-w-0 items-center gap-[5px] wrap-anywhere`;return(0,$.jsxs)(`div`,{className:Z(`flex shrink-0 flex-col gap-1 border-b border-line-1 bg-surface`,i?`px-4 py-3`:`px-5 pt-3 pb-2.5`),children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,$.jsx)(`h1`,{ref:a,tabIndex:-1,className:`m-0 min-w-0 flex-[1_1_240px] text-pretty wrap-anywhere text-[17px] font-semibold leading-[1.3] tracking-[-0.01em] text-fg-1`,children:e.title}),!i&&(0,$.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,icon:et,disabled:!t,onClick:s,children:`Comment on review`}),(0,$.jsx)(Pc,{})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-fg-3 [font:var(--type-meta)]`,children:[(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5 wrap-anywhere`,children:[(0,$.jsx)(cl,{origin:e.origin,dot:!0,className:`size-[7px] opacity-85`}),e.origin.name]}),e.state!==`open`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-line-strong`,children:`·`}),(0,$.jsx)(ul,{state:e.state})]}),e.snoozed&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-line-strong`,children:`·`}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap font-medium`,children:[(0,$.jsx)(X,{icon:Uo,size:12}),e.snoozedUntil?Kc(e.snoozedUntil,Date.now())?`Waking up`:`Snoozed until ${qc(e.snoozedUntil,Date.now())}`:`Snoozed until it changes`]})]}),c&&c!==`approved`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-line-strong`,children:`·`}),(0,$.jsx)(ol,{status:c,pickedUpAt:e.pickedUpAt,now:l,className:`font-normal text-fg-3`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3.5 gap-y-1.5 font-mono text-12 leading-[1.2] font-stretch-mono text-fg-3`,children:[e.branch&&(0,$.jsxs)(`span`,{className:p,children:[(0,$.jsx)(X,{icon:hs,size:13}),e.branch]}),!i&&d&&(0,$.jsxs)(`span`,{className:p,children:[(0,$.jsx)(X,{icon:_s,size:13}),d]}),t?.files.length===0&&(0,$.jsxs)(`span`,{className:p,children:[(0,$.jsx)(X,{icon:Lt,size:13}),t.docs.length,` `,w(t.docs.length,`doc`),` · no code changes`]}),(0,$.jsx)(Vd,{review:e,seq:n,onChange:o})]}),f.length>0&&(0,$.jsx)(`ul`,{"aria-label":`Links`,className:`m-0 flex min-w-0 list-none flex-wrap items-center gap-1.5 p-0 text-12 leading-[1.2]`,children:f.map((e,t)=>(0,$.jsx)(`li`,{className:`min-w-0 max-w-full`,children:(0,$.jsxs)(`a`,{href:e.href,title:e.href,target:`_blank`,rel:`noopener noreferrer nofollow`,className:`inline-flex max-w-full items-center gap-1 rounded-sm border border-line-1 px-1.5 py-[3px] text-fg-2 no-underline hover:bg-hover hover:text-fg-1`,children:[(0,$.jsx)(X,{icon:Hd[e.kind??`other`],size:12}),(0,$.jsx)(`span`,{className:`min-w-0 shrink-[0.2] truncate`,children:e.label}),(0,$.jsx)(`span`,{className:`min-w-0 shrink-[3] truncate text-11 text-fg-3`,children:e.host})]})},`${t}:${e.url}`))}),e.importedAt&&(0,$.jsxs)(`p`,{className:`m-0 wrap-anywhere text-fg-3 [font:var(--type-meta)]`,children:[`Copied from `,e.origin.name,` on `,new Date(e.importedAt).toLocaleDateString(),`. Comments, Sends and approvals before then were made there.`]}),r>n&&(0,$.jsxs)(xu,{tone:`info`,actionLabel:`Show`,onAction:()=>o(r),children:[`Revision `,r,` is ready.`]})]})}function Gd({label:e,hint:t,error:n,maxLength:r,value:i,defaultValue:a,onChange:o,rows:s=3,id:c,className:l,ref:u,...d}){let[f,p]=(0,Q.useState)(String(a??``).length),m=(0,Q.useRef)(null),h=(0,Q.useCallback)(e=>{if(m.current=e,typeof u==`function`)return u(e);u&&(u.current=e)},[u]);(0,Q.useEffect)(()=>{let e=m.current,t=e?.form;if(i!=null||!e||!t)return;let n,r=()=>{window.clearTimeout(n),n=window.setTimeout(()=>p(e.value.length),0)};return t.addEventListener(`reset`,r),()=>{t.removeEventListener(`reset`,r),window.clearTimeout(n)}},[i,d.form]);let g=i==null?f:String(i).length,_=r!=null&&g>r,v=r!=null&&g>=r*.9,y=_l(c,t,n,d[`aria-describedby`]),b=`${y.id}-count`;return(0,$.jsxs)(`div`,{className:Z(pl,l),children:[(e||r!=null)&&(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[e&&(0,$.jsx)(`label`,{htmlFor:y.id,className:`font-sans text-13 font-medium leading-(--lh-snug) text-fg-1`,children:e}),r!=null&&(0,$.jsxs)(`span`,{id:b,"aria-live":v?`polite`:`off`,"aria-atomic":`true`,className:Z(`font-mono text-11 font-medium leading-(--lh-snug) font-stretch-mono text-fg-3`,_&&`text-danger-fg`),children:[g,` / `,r]})]}),(0,$.jsx)(`textarea`,{...d,ref:h,id:y.id,rows:s,value:i,defaultValue:a,onChange:e=>{p(e.target.value.length),o?.(e)},"aria-invalid":n||_?!0:d[`aria-invalid`],"aria-describedby":[y.describedBy,r!=null&&b].filter(Boolean).join(` `)||void 0,className:Z(hl,`h-auto min-h-[76px] resize-y py-2 font-sans leading-[1.5]`)}),(0,$.jsx)(vl,{id:y.messageId,hint:t,error:n})]})}var Kd=2e3,qd=`\xA0`;function Jd({reviewId:e,compact:t=!1}){let n=`/emend:emend-feedback ${e}`,r=(0,Q.useRef)(null),i=(0,Q.useRef)(void 0),[a,o]=(0,Q.useState)(`idle`),[s,c]=(0,Q.useState)(0),l=(0,Q.useRef)(!0);return(0,Q.useEffect)(()=>(l.current=!0,()=>{l.current=!1,window.clearTimeout(i.current)}),[]),(0,$.jsxs)(`div`,{className:Z(`flex min-w-0 flex-col gap-1.5`,t&&`gap-1`),children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsx)(`code`,{ref:r,className:`min-w-0 break-all rounded-sm border border-line-1 bg-sunken px-2 py-1 font-mono text-12 text-fg-1 select-all`,children:n}),(0,$.jsx)(Y,{size:`sm`,icon:rs,onClick:()=>{window.clearTimeout(i.current);let e=()=>{l.current&&(o(`copied`),i.current=window.setTimeout(()=>o(`idle`),Kd))},t=()=>{if(!l.current)return;let t=r.current,n=window.getSelection();if(t&&n){let e=document.createRange();e.selectNodeContents(t),n.removeAllRanges(),n.addRange(e)}let i=!1;try{i=typeof document.execCommand==`function`&&document.execCommand(`copy`)}catch{i=!1}i?e():(o(`failed`),c(e=>e+1))};try{navigator.clipboard.writeText(n).then(e,t)}catch{t()}},children:a===`copied`?`Copied`:`Copy`}),(0,$.jsx)(`span`,{role:`status`,className:Z(`text-fg-3 [font:var(--type-meta)]`,a!==`failed`&&`sr-only`),children:a===`failed`?`Select and copy the command${s%2==0?qd:``}`:a===`copied`?`Command copied`:``})]}),(0,$.jsxs)(`p`,{className:`m-0 text-fg-3 [font:var(--type-meta)]`,children:[`Run `,(0,$.jsxs)(`code`,{className:`font-mono`,children:[`emend feedback `,e]}),` and handle the result with the emend-feedback skill.`]})]})}var Yd=15e3,Xd=Error(`The review refetch did not finish in time.`),Zd=3e3,Qd=3e3;function $d(e,t){if(e.agentWaiting)return`An agent is waiting. It gets this now.`;let n=e.releasedAt?Wc(e.releasedAt):``;return n?t?.state===`settled`?`The agent stopped waiting when you retired this on ${n}.`:t?.snoozed?`The agent stopped waiting when you snoozed this on ${n}.`:`The agent stopped waiting on ${n}.`:`No agent is waiting. emend keeps this until an agent picks it up.`}function ef({reviewId:e,agent:t,lifecycle:n,className:r}){return(0,$.jsxs)(`div`,{className:r,children:[(0,$.jsx)(`p`,{className:`m-0 text-fg-3 [font:var(--type-meta)]`,children:$d(t,n)}),!t.agentWaiting&&(0,$.jsx)(Jd,{reviewId:e,compact:!0})]})}function tf({reviewId:e,baseline:t,agent:n,phone:r,onClose:i,returnFocus:a,returnFocusPhone:o}){let s=Ct(),{waited:c}=t,l=n.pickedUpAt!==null&&n.pickedUpAt!==t.pickedUpAt||n.newestRevision>t.newestRevision&&!n.pendingSend,[u,d]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{l&&d(!0)},[l]);let f=u||l,[p,m]=(0,Q.useState)(!c),[h,g]=(0,Q.useState)(!1),_=(0,Q.useRef)(null),[y,b]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(y)return s.getQueryCache().subscribe(t=>{let[n,r]=t.query.queryKey;n===`review`&&r===e&&t.type===`updated`&&t.action.type===`success`&&!t.action.manual&&b(!1)})},[y,s,e]),(0,Q.useEffect)(()=>{if(f)return;let t=!0,n,r=async()=>{let r=!1;try{r=await yc()}catch{r=!1}if(r||!t)return;let i={cancelRefetch:!1};s.invalidateQueries({queryKey:[`inbox`]},i).catch(()=>void 0);try{await Promise.race([s.invalidateQueries({queryKey:[`review`,e]},{...i,throwOnError:!0}),new Promise((e,t)=>{n=window.setTimeout(()=>t(Xd),Zd)})])}catch(e){t&&(e===Xd||e instanceof TypeError)&&b(!0)}window.clearTimeout(n)};if(!c)return r(),()=>{t=!1,window.clearTimeout(n)};let i=window.setTimeout(()=>{m(!0),r()},Yd);return()=>{t=!1,window.clearTimeout(i),window.clearTimeout(n)}},[f,c,s,e]),(0,Q.useEffect)(()=>{if(!f||h)return;let e=window.setTimeout(i,Qd);return()=>window.clearTimeout(e)},[f,h,i]),(0,Q.useEffect)(()=>{let e=()=>{let e=window.getSelection(),t=_.current?.closest(`[role="alertdialog"], [role="dialog"]`);e&&e.toString()!==``&&e.anchorNode&&t?.contains(e.anchorNode)&&g(!0)};return document.addEventListener(`selectionchange`,e),()=>document.removeEventListener(`selectionchange`,e)},[]);let x=(0,$.jsx)(`span`,{role:`status`,ref:_,children:f?`The agent picked up your feedback.`:p?y?`emend cannot reach its server right now, so a pick-up may not show here. If no agent has it yet, hand it over with the command below.`:`No agent has picked this up yet. emend keeps it until one does.`:`Waiting for the agent to pick this up…`}),S=!f&&p&&(0,$.jsx)(Jd,{reviewId:e}),C=e=>{e||i()},w=()=>g(!0);return(0,$.jsx)(`div`,{className:`contents`,onPointerDownCapture:w,onKeyDownCapture:w,children:r?(0,$.jsx)(v,{side:`bottom`,title:`Sent`,description:x,open:!0,onOpenChange:C,returnFocus:o,children:S}):(0,$.jsx)(St,{title:`Sent`,description:x,open:!0,onOpenChange:C,returnFocus:a,preferReturnFocus:!0,actions:(0,$.jsx)(Y,{"data-autofocus":!0,onClick:i,children:`Close`}),children:S?(0,$.jsx)(`div`,{className:`mt-3`,children:S}):null})})}function nf({label:e,options:t,value:n,onChange:r,name:i,variant:a=`cards`,className:o}){let s=(0,Q.useId)();return(0,$.jsxs)(`fieldset`,{className:Z(`m-0 flex min-w-0 flex-col gap-1.5 border-0 p-0`,o),children:[(0,$.jsx)(`legend`,{className:Z(ml,`mb-2 p-0`),children:e}),t.map((e,t)=>(0,$.jsxs)(`label`,{className:Z(`relative flex cursor-pointer items-start gap-2.5 rounded-md border border-line-1 bg-surface px-3 py-2.5 transition-[border-color,background] duration-(--dur-1) hover:border-line-2 has-checked:border-(--ochre-500) has-checked:bg-accent-tint has-focus-visible:shadow-(--focus-ring)`,a===`plain`&&`border-transparent bg-transparent px-1 py-1.5 hover:border-transparent has-checked:border-transparent has-checked:bg-transparent`),children:[(0,$.jsx)(`input`,{type:`radio`,className:`peer sr-only`,name:i??s,value:e.value,checked:n===e.value,onChange:()=>r?.(e.value),"aria-describedby":e.description?`${s}-${t}-description`:void 0}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid size-4 shrink-0 place-items-center rounded-full border-[1.5px] border-line-strong bg-surface peer-checked:border-fg-1 peer-checked:after:size-2 peer-checked:after:rounded-full peer-checked:after:bg-fg-1 peer-checked:after:content-['']`}),(0,$.jsxs)(`span`,{className:`flex flex-col gap-0.5 font-sans text-13 font-medium leading-(--lh-snug) text-fg-1`,children:[e.label,e.description&&(0,$.jsx)(`span`,{id:`${s}-${t}-description`,className:`font-sans text-12 font-normal leading-(--lh-snug) text-fg-3`,children:e.description})]})]},e.value))]})}var rf=J.options.map(e=>({value:e,label:E[e]}));function af({value:e,onChange:t,disabled:n,cards:r=!1}){return r?(0,$.jsx)(`fieldset`,{disabled:n,className:`m-0 min-w-0 border-0 p-0`,children:(0,$.jsx)(nf,{label:`Mode`,variant:`cards`,value:e,onChange:e=>t(J.parse(e)),options:rf})}):(0,$.jsx)(yl,{"aria-label":`Mode`,size:`sm`,options:rf,disabled:n,value:e,onChange:e=>t(J.parse(e.target.value))})}var of=1e3;function sf({reviewId:e,lifecycle:t,unsentCount:n,phone:r}){let{title:i,state:a,snoozed:o,onDeleted:s}=t,[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(Date.now),[f,p]=(0,Q.useState)(0),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(!1),v=R(e),y=uc(),b=(0,Q.useRef)(null),x=(0,Q.useRef)(!0),S=(0,Q.useRef)(!1),C=(0,Q.useRef)(!1),T=v.isPending;(0,Q.useEffect)(()=>(x.current=!0,()=>{x.current=!1}),[]);let E=e=>{C.current||(d(Date.now()),h(!1),p(n),l(e))},D=()=>{S.current||l(null)},O=async e=>{if(S.current||C.current)return!1;S.current=!0;try{return await v.mutateAsync(e),e.action===`delete`&&(C.current=!0,x.current&&l(null)),!0}catch(t){return t instanceof G&&t.code===`unsent_comments`&&e.action===`retire`?x.current&&h(!0):y.show({tone:`danger`,title:ee(t)}),!1}finally{S.current=!1}},k=async e=>{let t=e.id===`revision`?void 0:e.until;await O({action:`snooze`,body:t?{until:t.toISOString()}:{untilRevision:!0}})&&(x.current&&l(null),y.show({tone:`success`,title:t?`Snoozed until ${qc(t,Date.now())}`:`Snoozed until it changes`}))},A=async()=>{await O({action:`unsnooze`})&&y.show({tone:`success`,title:`Review unsnoozed`})},j=async()=>{await O({action:`reopen`})&&y.show({tone:`success`,title:`Review reopened`})},M=n>0,N=n-f,P=N>0?`${N} new unsent ${w(N,`comment`)} arrived.`:m?`New unsent comments arrived.`:N<0?`Some unsent comments were sent or deleted.`:null,F=M?`Discard ${n} unsent ${w(n,`comment`)} and retire`:`Retire`,I=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(c!==`retire`){I.current=null,_(!1);return}let e=I.current!==null&&I.current!==F;if(I.current=F,!e)return;_(!0);let t=setTimeout(()=>_(!1),of);return()=>clearTimeout(t)},[c,F]);let L=async()=>{g||await O({action:`retire`,body:M?{discardUnsent:!0}:{}})&&(x.current&&l(null),y.show({tone:`success`,title:`Review retired`}))},z=async()=>{await O({action:`delete`})&&(s(),y.show({tone:`success`,title:`Deleted “${i}”`}))},te=[];a===`open`&&(te.push({label:o?`Snooze again`:`Snooze`,icon:Lo,opensDialog:!0,onSelect:()=>E(`snooze`)}),o&&te.push({label:`Unsnooze`,icon:Uo,onSelect:()=>void A()}),te.push({label:`Retire`,icon:zo,opensDialog:!0,onSelect:()=>E(`retire`)})),a===`settled`&&te.push({label:`Reopen`,icon:rc,onSelect:()=>void j()}),te.length>0&&te.push({separator:!0}),te.push({label:`Delete`,icon:Ge,danger:!0,opensDialog:!0,onSelect:()=>E(`delete`)});let ne=(0,$.jsx)(Y,{"data-autofocus":!0,disabled:T,onClick:D,children:`Cancel`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)($e,{label:`More review actions`,size:r?`lg`:`md`,triggerRef:b,trigger:(0,$.jsx)(Et,{label:`More review actions`,icon:ze,size:r?`lg`:`md`,tooltip:!1,"aria-disabled":T,"aria-busy":T,onPointerDown:e=>T&&e.preventDefault(),onKeyDown:e=>{T&&[` `,`Enter`,`ArrowDown`,`ArrowUp`].includes(e.key)&&e.preventDefault()}}),items:te}),(0,$.jsx)(St,{open:c===`snooze`,returnFocus:b,onOpenChange:e=>!e&&D(),title:`Snooze this review`,description:`It leaves your active list until then. A new revision wakes it early.`,actions:ne,children:(0,$.jsx)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:Jc(new Date(u)).map(e=>(0,$.jsxs)(Y,{fullWidth:!0,disabled:T,className:`justify-start`,onClick:()=>void k(e),children:[(0,$.jsx)(`span`,{children:e.label}),e.id!==`revision`&&(0,$.jsxs)(`span`,{className:`font-normal text-fg-3`,children:[` · `,qc(e.until,u)]})]},e.id))})}),(0,$.jsx)(St,{open:c===`retire`,returnFocus:b,onOpenChange:e=>!e&&D(),title:`Retire this review?`,description:M?`It moves to Done without an approval, and an agent waiting on it stops. Its ${n} unsent ${w(n,`comment`)} will be deleted.`:`It moves to Done without an approval, and an agent waiting on it stops.`,actions:(0,$.jsxs)($.Fragment,{children:[ne,(0,$.jsx)(Y,{variant:M?`danger`:`primary`,loading:T,"aria-disabled":g||void 0,onClick:()=>void L(),children:F})]}),children:P&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-13 text-danger-fg`,children:P})}),(0,$.jsx)(St,{open:c===`delete`,returnFocus:b,onOpenChange:e=>!e&&D(),title:`Delete “${i}”?`,description:`This removes the review, its revisions, comments and Sends for good. An agent waiting on it stops. This cannot be undone.`,actions:(0,$.jsxs)($.Fragment,{children:[ne,(0,$.jsx)(Y,{variant:`danger`,loading:T,onClick:()=>void z(),children:`Delete review`})]})})]})}function cf({reviewId:e,revision:t,newestRevision:n,revisionError:r=!1,unsentCount:i,approved:o=!1,lifecycle:s,agent:c,phone:l=!1}){let[u,d]=(0,Q.useState)(ye),f=kt(e),p=(0,Q.useSyncExternalStore)(xt,()=>Ke(f)),m=(0,Q.useSyncExternalStore)(xt,()=>Ft(e).length),h=(0,Q.useSyncExternalStore)(xt,()=>Ue(e)),g=(0,Q.useSyncExternalStore)(xt,()=>ft(e)),_=/Mac|iPhone|iPad|iPod/.test(navigator.platform)?`⌘↵`:`Ctrl ↵`,[y,b]=(0,Q.useState)(!1),x=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>(x.current=!0,()=>{x.current=!1}),[]);let S=(0,Q.useRef)(!1),C=(0,Q.useRef)(null),[T,E]=(0,Q.useState)(!1),D=(0,Q.useRef)(c);(0,Q.useLayoutEffect)(()=>{D.current=c});let O=(0,Q.useRef)(!1),k=(0,Q.useRef)(null),[A,j]=(0,Q.useState)(null),M=(0,Q.useRef)(null),N=(0,Q.useCallback)(()=>j(null),[]),P=(0,Q.useCallback)(()=>{let e=M.current;M.current=null,e&&j(e)},[]),F=(0,Q.useRef)(null);(0,Q.useLayoutEffect)(()=>{let e=F.current;if(!e||l||(e.style.height=``,!p||CSS.supports?.(`field-sizing`,`content`)))return;e.style.height=`auto`;let t=getComputedStyle(e),n=(Number.parseFloat(t.borderTopWidth)||0)+(Number.parseFloat(t.borderBottomWidth)||0);e.style.height=`${e.scrollHeight+n}px`},[p,l]);let I=(0,Q.useRef)(!1),L=(0,Q.useCallback)(e=>{if(!e)return;let t=e.closest(`[role="dialog"]`);return()=>{I.current=t?.contains(document.activeElement)??!1}},[]),R=ue(e),z=R.isPending||g;O.current=y,(0,Q.useEffect)(()=>{l||P()},[l,P]),(0,Q.useEffect)(()=>{if(l){I.current=!1;return}y&&b(!1);let e=F.current;I.current&&e&&!z&&(I.current=!1,document.activeElement===document.body&&e.focus())},[l,y,z]);let te=uc(),ne=(0,Q.useId)(),B=(0,Q.useId)(),re=(0,Q.useId)(),ie=(0,Q.useId)(),V=(0,Q.useId)(),H=s?.state===`settled`,U=!o&&(!H||!!c?.releasedAt),W=t===void 0?r?`Could not load this revision.`:`Loading revision…`:void 0,G=t!==void 0&&t<n?`Revision ${n} is newer. Switch to it to send or approve.`:void 0,ae=z||h||m>0||t===void 0||!!G||H,K=i>0&&!o&&!H,oe=h||m>0||t===void 0||!!G||H||i>0||o;(0,Q.useEffect)(()=>{T&&oe&&!z&&(o&&le(!0),E(!1))},[T,oe,z,o]);let se=(0,Q.useRef)(null),[ce,le]=(0,Q.useState)(!1),de=m?m===1?`1 unsaved comment: save or discard it first.`:`${m} unsaved comments: save or discard them first.`:void 0,fe=H?`This review is retired. Reopen it to send or approve.`:void 0,pe=fe??de??(p.length>gt.instructionChars?`Shorten the instructions to ${gt.instructionChars} characters.`:i===0&&!p.trim()?`Write a comment or an instruction first.`:void 0),me=`${i} ${w(i,`comment`)}`,he=e=>{S.current||R.reset(),e?Ze(f,e):Je(f)},ge=e=>{S.current||R.reset(),d(e)},_e=async n=>{if(S.current||ae||Ft(e).length>0||Ue(e)||ft(e)||(n===`go`?pe:i>0||o)||!a(e))return;S.current=!0;let r={waited:D.current?.agentWaiting??!1,pickedUpAt:D.current?.pickedUpAt??null,newestRevision:D.current?.newestRevision??0};try{if(await R.mutateAsync({path:`/api/v1/reviews/${encodeURIComponent(e)}/sends`,body:n===`approve`?{revision:t,kind:n}:{revision:t,kind:n,mode:u,instruction:p},refresh:`background`,accepted:n===`approve`?`approve`:`send`}),n===`go`&&Mt(f,p),!x.current)return;n===`go`?(l&&O.current?M.current=r:j(r),b(!1)):(le(!0),E(!1),te.show({tone:`success`,title:`Approved revision ${t}`}))}catch{}finally{S.current=!1,it(e)}},q=R.error&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 text-13 text-danger-fg`,children:ee(R.error)}),ve=pe&&(0,$.jsx)(`span`,{id:re,className:`text-fg-3 [font:var(--type-meta)]`,children:pe}),be=G&&(0,$.jsx)(`span`,{id:V,children:G}),xe=[W&&ie,pe&&re,G&&V].filter(Boolean).join(` `)||void 0,Se=(0,$.jsx)(`span`,{id:B,children:`Send or delete before approving`}),Ce=(0,$.jsx)(Y,{ref:C,variant:`approve`,size:l?`lg`:`md`,icon:Bt,disabled:ae||i>0||o,"aria-describedby":[K&&B,(de||fe)&&re,W&&ie,G&&V].filter(Boolean).join(` `)||void 0,onClick:()=>{S.current||(R.reset(),le(!1),E(!0))},children:o?`Approved`:l||t===void 0?`Approve`:`Approve revision ${t}`}),J=s&&(0,$.jsx)(sf,{reviewId:e,lifecycle:s,unsentCount:i,phone:l}),we=(0,$.jsxs)(`div`,{ref:se,tabIndex:-1,className:Z(`flex min-w-0 flex-col gap-0.5 outline-none`,l&&`flex-1 overflow-hidden`),children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 whitespace-nowrap text-13 font-semibold leading-[1.2] text-fg-1`,children:[i>0&&(0,$.jsx)(`span`,{"aria-hidden":!l||void 0,className:`inline-flex h-[18px] min-w-[18px] items-center justify-center rounded-full bg-accent px-[5px] text-[10.5px] font-semibold tabular-nums text-accent-fg`,children:i}),i>0&&` `,l?i>0?`unsent`:`Nothing to send`:i>0?`${i} unsent ${w(i,`comment`)}`:`No unsent comments`]}),(0,$.jsxs)(`span`,{className:`text-fg-3 [font:var(--type-meta)]`,children:[t!==void 0&&`Revision ${t}`,!l&&K&&(0,$.jsxs)($.Fragment,{children:[` · `,Se]}),!l&&pe&&(0,$.jsxs)($.Fragment,{children:[` · `,ve]}),!l&&G&&(0,$.jsxs)($.Fragment,{children:[` · `,be]})]})]});return(0,$.jsxs)(`section`,{"aria-label":`Send and approve`,className:`shrink-0 border-t border-line-1 bg-surface`,children:[l?(0,$.jsxs)(`div`,{className:`flex min-h-[52px] flex-nowrap items-center gap-2.5 py-1.5 pr-2.5 pl-3.5`,children:[we,(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-nowrap items-center gap-1.5 [&>*]:shrink-0`,children:[J,Ce,(0,$.jsx)(v,{side:`bottom`,title:`Send feedback`,open:y,onClosed:P,onOpenChange:e=>{e&&!S.current&&R.reset(),b(e)},trigger:(0,$.jsx)(Y,{ref:k,variant:`primary`,size:`lg`,icon:Gs,disabled:ae,loading:z,"aria-describedby":[W&&ie,(de||fe)&&re,G&&V].filter(Boolean).join(` `)||void 0,children:`Send`}),footer:(0,$.jsxs)(`div`,{className:`flex w-full flex-col gap-2`,children:[ve,G&&(0,$.jsx)(`p`,{className:`m-0 text-fg-3 [font:var(--type-meta)]`,children:be}),W&&(0,$.jsx)(`p`,{id:ie,role:r?`alert`:`status`,className:`m-0 text-fg-3 [font:var(--type-meta)]`,children:W}),q,(0,$.jsx)(Y,{type:`submit`,form:ne,variant:`primary`,size:`lg`,fullWidth:!0,icon:Gs,disabled:ae||!!pe,loading:z,"aria-describedby":xe,children:i>0?`Send ${me} on revision ${t??`…`}`:`Send instructions on revision ${t??`…`}`})]}),children:(0,$.jsxs)(`form`,{ref:L,id:ne,className:`space-y-4`,onKeyDown:e=>{e.key===`Enter`&&e.target instanceof HTMLInputElement&&e.target.type===`radio`&&e.preventDefault()},onSubmit:e=>{e.preventDefault(),_e(`go`)},children:[(0,$.jsx)(af,{cards:!0,value:u,onChange:ge,disabled:z}),(0,$.jsx)(Gd,{label:`Instructions`,placeholder:`Optional. Applies to every comment in this Send.`,rows:2,maxLength:gt.instructionChars,disabled:z,value:p,onChange:e=>he(e.target.value)}),U&&c&&(0,$.jsx)(ef,{reviewId:e,agent:c,lifecycle:s})]})})]})]}):(0,$.jsxs)(`form`,{className:`flex min-h-(--sendbar-h) items-center gap-2.5 py-2 pr-3 pl-4`,onSubmit:e=>{e.preventDefault(),_e(`go`)},children:[we,(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 justify-end gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex min-w-0 max-w-[520px] flex-1 items-center`,children:[(0,$.jsx)(X,{icon:bt,size:14,className:`pointer-events-none absolute left-[9px] text-fg-3`}),(0,$.jsx)(`textarea`,{ref:F,"aria-label":`Instructions`,rows:1,enterKeyHint:`enter`,placeholder:`Instructions for the agent (optional)`,className:Z(hl,gl.sm,`min-h-7 max-h-32 resize-none overflow-y-auto py-[3px] pl-[30px] leading-5`,p&&`h-auto [field-sizing:content]`),maxLength:gt.instructionChars,disabled:z,value:p,onChange:e=>he(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&!e.nativeEvent.isComposing&&e.keyCode!==229&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())}}),(0,$.jsx)(`kbd`,{className:`ml-1.5 shrink-0 text-fg-3 [font:var(--type-meta)]`,children:_})]}),(0,$.jsx)(af,{value:u,onChange:ge,disabled:z})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[J,Ce,(0,$.jsx)(Y,{type:`submit`,variant:`primary`,icon:Gs,disabled:ae||!!pe,loading:z,"aria-describedby":xe,children:i>0?`Send ${i}`:`Send`})]})]}),!l&&U&&c&&(0,$.jsx)(ef,{reviewId:e,agent:c,lifecycle:s,className:`px-4 pb-2`}),(0,$.jsx)(St,{open:T,returnFocus:ce?se:C,preferReturnFocus:ce,onOpenChange:e=>{!e&&!z&&E(!1)},title:t===void 0?`Approve this revision?`:`Approve revision ${t}?`,description:`The agent receives the approval, now if one is waiting and otherwise when it next picks up. The review moves to Done.`,actions:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{"data-autofocus":!0,disabled:z,onClick:()=>E(!1),children:`Cancel`}),(0,$.jsx)(Y,{variant:`approve`,loading:z,onClick:()=>void _e(`approve`),children:`Approve`})]}),children:q&&(0,$.jsx)(`div`,{className:`mt-2`,children:q})}),A&&(0,$.jsx)(tf,{reviewId:e,baseline:A,agent:c??{agentWaiting:!1,pendingSend:!0,pickedUpAt:null,releasedAt:null,newestRevision:0},phone:l,onClose:N,returnFocus:F,returnFocusPhone:()=>k.current}),(!l||!y)&&(W||l&&(K||G||de||fe)||R.error&&!T)&&(0,$.jsxs)(`div`,{className:`space-y-1 px-4 pb-2`,children:[W&&(0,$.jsx)(`p`,{id:ie,role:r?`alert`:`status`,className:`m-0 text-fg-3 [font:var(--type-meta)]`,children:W}),l&&K&&(0,$.jsx)(`p`,{className:`m-0 text-fg-3 [font:var(--type-meta)]`,children:Se}),l&&(de||fe)&&ve,l&&G&&(0,$.jsx)(`p`,{className:`m-0 text-fg-3 [font:var(--type-meta)]`,children:be}),!T&&q]})]})}function lf({reviewId:e,topics:t,onResume:n}){let[r,i]=(0,Q.useState)(()=>Ft(e));return(0,Q.useEffect)(()=>{let t=()=>i(Ft(e));return t(),xt(t)},[e]),r.length?(0,$.jsxs)(`section`,{"aria-label":`Unsaved comments`,className:`space-y-3`,children:[(0,$.jsxs)(`h2`,{className:`em-comment-group`,children:[`Unsaved comments`,(0,$.jsx)(`span`,{children:r.length})]}),r.map(e=>{let{label:r,icon:i}=e.commentId?{label:`Unsaved edit`,icon:bt}:e.target?ae(e.target,t):{label:`Unreadable target`,icon:mt};return(0,$.jsxs)(`article`,{className:`rounded-lg border border-line-1 bg-surface px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`em-card__target`,title:r,children:[(0,$.jsx)(X,{icon:i,size:13}),(0,$.jsx)(`span`,{children:r})]}),(0,$.jsx)(`p`,{className:`my-2 line-clamp-2 whitespace-pre-wrap wrap-anywhere text-fg-2 [font:var(--type-body)]`,children:Ke(e.key)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(e.target||e.commentId)&&(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>n(e),children:`Resume`}),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,icon:Ge,onClick:()=>Je(e.key),children:`Discard`})]})]},e.key)})]}):null}function uf({reviewId:e,revision:t,threads:n,changedBlocks:r,topics:i,search:a={},phone:o=!1,onResume:s}){let c=(0,Q.useSyncExternalStore)(xt,()=>Ft(e).length>0),l={reviewId:e,revision:t,changedBlocks:r,topics:i,surface:`comments`};return(0,$.jsxs)(`div`,{className:`space-y-6 px-4 pt-4 pb-8 md:mx-auto md:max-w-[calc(1000px+88px)] md:pt-7 md:pr-8 md:pb-[72px] md:pl-14`,children:[(0,$.jsx)(lf,{reviewId:e,topics:i,onResume:s}),!c&&n.length===0&&(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`p`,{children:`No comments yet.`}),(0,$.jsx)(`p`,{className:`text-fg-3 [font:var(--type-meta)]`,children:`Select text in the writeup or a doc, or click a line in the diff.`})]}),[`unsent`,`sent`,`answered`,`open`,`unplaced`,`resolved`].map(t=>{let r=n.filter(e=>(e.placement.status===`unplaced`?`unplaced`:ut(e))===t);if(!r.length)return null;let i=t[0]?.toUpperCase()+t.slice(1);return(0,$.jsxs)(`section`,{"aria-label":i,className:`space-y-3`,children:[(0,$.jsxs)(`h2`,{className:`em-comment-group`,children:[i,(0,$.jsx)(`span`,{children:r.length})]}),r.map(t=>(0,$.jsx)(Ot,{...l,thread:t,showInPlace:Ve(e,t,a,o)},t.id))]},t)})]})}function df(e){if(e.main===`writeup`)return{tab:`writeup`};let t=e.docs.find(t=>t.path===e.main);if(t)return{tab:`docs`,doc:t.path};if(!e.writeupEmpty)return{tab:`writeup`};let n=e.docs[0];return n?{tab:`docs`,doc:n.path}:e.files.some(e=>e.role===`diff`)?{tab:`diff`}:{tab:`writeup`}}var ff=[0,100,300,800,1500],pf=250,mf=`emend:capture-reading-position`;function hf(){document.querySelector(`[data-reading-scroll]`)?.dispatchEvent(new Event(mf))}var gf=new WeakMap,_f=new Set([`PageUp`,`PageDown`,`Home`,`End`,`ArrowUp`,`ArrowDown`,` `]),vf=`input, textarea, select, [contenteditable]:not([contenteditable="false"])`;function yf({storageKey:e,selector:t,active:n,intentState:r,entry:i,doc:a,preserve:o=!1}){let s=(0,Q.useRef)(a);s.current=a;let c=(0,Q.useRef)(r);c.current=r,(0,Q.useLayoutEffect)(()=>{if(!n)return;let r=document.querySelector(`[data-reading-scroll]`);if(!r)return;let a=new Set,l=c.current().epoch,u=gf.get(r),d=u!==void 0&&u.key!==e,f=u!==void 0&&u.entry!==i,p=o&&f&&u?.key===e;gf.set(r,{key:e,entry:i});let m=!1,h=!1,g=!1,_=null,v,y=()=>{m=!1;for(let e of a)clearTimeout(e);a.clear()},b=()=>{g&&(g=!1,id(e,_))},x=()=>{_=sd(r,t),i?.positions.set(e,_),g=!0},S=()=>{y(),x(),b()},C=()=>{h&&(x(),v===void 0&&(b(),v=setTimeout(()=>{v=void 0,b()},pf)))},w=()=>{h=!0,y()},T=()=>{document.visibilityState===`hidden`&&b()};r.addEventListener(`scroll`,C,{passive:!0}),r.addEventListener(mf,S);let E=e=>{if(e.defaultPrevented||!_f.has(e.key))return;let t=e.target;t instanceof Node&&(t===document.body||r.contains(t))&&(t instanceof HTMLElement&&t.closest(vf)||w())};r.addEventListener(`wheel`,w,{passive:!0}),r.addEventListener(`touchstart`,w,{passive:!0}),r.addEventListener(`touchmove`,w,{passive:!0}),r.addEventListener(`pointerdown`,w,{passive:!0}),window.addEventListener(`keydown`,E),window.addEventListener(`pagehide`,b),document.addEventListener(`visibilitychange`,T);let D=p?void 0:i?.positions.has(e)?i.positions.get(e):rd(e);p&&S(),m=!p;let O=n=>{if(!m)return;let a=c.current();if(a.current||a.epoch!==l){y();return}let o=D?cd(r,D,s.current):void 0;if(n&&o===void 0&&(d||f&&D!==void 0)&&(r.scrollTop=0),i?.positions.set(e,sd(r,t)),n&&i?.focus){let e=i.focus,t=e.id.startsWith(`h-`)&&s.current?Uu(r,s.current,e.id.slice(2)):void 0;t&&(t.tabIndex=-1);let n=t??(Ru(e.id)?document.getElementById(e.id):void 0);for(let t of e.children)n=n?.children[t];n&&r.contains(n)&&Xu(n)}};p||O(!0),m&&ff.slice(1).forEach((e,t)=>{let n=setTimeout(()=>{a.delete(n),D&&O(!1),t===ff.length-2&&y()},e);a.add(n)});let k=()=>{if(Zu(document.activeElement)||!(document.activeElement instanceof HTMLElement)||!r.contains(document.activeElement)||(w(),C(),!i))return;let e=document.activeElement,t=e.closest(`[id^="block-"], [id^="thread-"], [id^="topic-"]`),n=s.current&&Uu(r,s.current,e.id)===e?e:void 0,a=n??(t&&Ru(t.id)&&r.contains(t)?t:void 0);if(!a){i.focus=void 0;return}let o=[];for(let t=e;t!==a&&t.parentElement;t=t.parentElement)o.unshift(Array.from(t.parentElement.children).indexOf(t));i.focus={id:n?`h-${n.id}`:a.id,children:o}};return r.addEventListener(`focusin`,k),()=>{b(),r.removeEventListener(`focusin`,k),y(),clearTimeout(v),r.removeEventListener(`scroll`,C),r.removeEventListener(mf,S),r.removeEventListener(`wheel`,w),r.removeEventListener(`touchstart`,w),r.removeEventListener(`touchmove`,w),r.removeEventListener(`pointerdown`,w),window.removeEventListener(`keydown`,E),window.removeEventListener(`pagehide`,b),document.removeEventListener(`visibilitychange`,T)}},[n,e,t,i,o])}function bf(e,t){let n=g(),r=Fo(),i=r.state.__TSR_index,a=(0,Q.useRef)(new Map),o=a.current.get(i),s=!!o&&o.revision===t,c=(0,Q.useRef)({key:r.state.__TSR_key,index:i,returning:!1});if(c.current.key!==r.state.__TSR_key&&(c.current={key:r.state.__TSR_key,index:i,returning:s&&i!==c.current.index}),!o||o.revision!==t){let n=a.current.get(i-1);o={title:e,revision:t,folds:new Map(n?.revision===t?n.folds:[]),positions:new Map},a.current.set(i,o)}o.title=e;let l=a.current.get(i-1);return(0,Q.useEffect)(()=>n.history.subscribe(({action:e,location:t})=>{if(e.type===`PUSH`)for(let e of a.current.keys())e>=t.state.__TSR_index&&a.current.delete(e)}),[n]),{entry:o,returning:c.current.returning,back:l?{title:l.title,go:()=>n.history.back()}:void 0}}function xf({reviewId:e,revision:t,tab:n,onResume:r,htmlNavigation:i,composingPath:a,resumedBlockId:o,activeThreadId:s,threadJump:c,search:l,phone:u,openDoc:d,targeted:f,onOpenDoc:p,onCurrentTopic:m,onNote:h,visible:g,intentState:_,entry:v,back:y,onHeading:b,preservePosition:x,returning:S,headingTarget:C,visit:w}){yf({storageKey:td(e,n,n===`docs`?d?.path??``:``,t.seq,qu(d,l.view)??(d?.kind===`html`?`original`:`reading`)),selector:n===`comments`?`[id^="thread-"]`:`[id^="block-"], [id^="html-doc-"]`,active:g&&(n!==`docs`||d?.kind!==`html`&&d?.kind!==`source`),preserve:x,entry:v,doc:n===`docs`?d:void 0,intentState:_});let T={reviewId:e,revision:t.seq,threads:t.threads,changedBlocks:t.changedBlocks,topics:t.topics,activeThreadId:s,threadJump:c};return n===`comments`?(0,$.jsx)(uf,{...T,search:l,phone:u,onResume:r}):n===`docs`?(0,$.jsx)(Nd,{...T,entry:v,returning:S,headingTarget:C,visit:w,docs:t.docs,openDoc:d,search:l,targeted:f,onHeading:b,back:y,onOpenDoc:p,navigation:i,composingPath:a,resumedBlockId:o}):(0,$.jsx)(Bd,{...T,writeup:t.writeup,files:t.files,search:l,phone:u,visible:g,resumedBlockId:o,onCurrentTopic:m,onNote:h})}function Sf(e,t){if(e.threadId)return t.threads.find(t=>t.id===e.threadId)?.placement;let n=e.target;if(n?.kind===`writeup-span`)return q(t.writeup.sections.flatMap(e=>e.blocks),n);if(n?.kind===`doc-span`){let e=t.docs.find(e=>e.kind===`markdown`&&e.path===n.path);return q(e?.kind===`markdown`?e.blocks:[],n)}}function Cf(e,t,n){let r;if(t.startsWith(`h-`))try{r=decodeURIComponent(t.slice(2))}catch{r=``}let i=r===void 0&&e.tab===`comments`&&!!e.thread;return{navigation:JSON.stringify([n,e.tab,e.doc,e.thread,e.view,t]),elementId:i?`thread-${e.thread}`:Ru(t)?t:``,headingId:r,reply:i,threadId:r===void 0?e.thread??(t.startsWith(`thread-`)?t.slice(7):void 0):void 0,routeThread:!0,block:`center`}}function wf(e,t,n,r,i){let a=Ju(e.docs,t.doc,t.view);if(a)return a;if(t.doc!==void 0)return;let o=e.threads.find(e=>e.id===n.threadId),s=o?.placement.status===`placed`?o.placement.location:void 0;return e.docs.find(e=>e.kind!==`source`&&n.elementId===`doc-${e.path}`||e.kind===`html`&&n.elementId===`html-doc-${e.path}`||e.kind===`markdown`&&e.blocks.some(e=>n.elementId===`block-${e.id}`)||(s?.kind===`doc-span`||s?.kind===`html-span`||s?.kind===`source-lines`)&&s.path===e.path&&e.kind===(s.kind===`source-lines`?`source`:s.kind===`html-span`?`html`:`markdown`))??Ju(e.docs,r)??(i&&e.docs.length===1?e.docs[0]:void 0)}function Tf({review:e,published:t,titleRef:n,collapsed:r,setCollapsed:i}){let a=Fo(),o=(0,Q.useMemo)(()=>Df(a.search),[a.search]),s=a.hash,[l]=(0,Q.useState)(e.newestRevision),d=o.rev??l,f=c(tl(e.id,d)),p=be(e.id),m=u(e.id),h=(e,t)=>p.mutate({revision:d,paths:e,viewed:t}),{counts:g}=At(),_=qa({from:`/r/$reviewId`}),v=Ct();Cl([e.snoozedUntil],()=>{v.invalidateQueries({queryKey:[`review`,e.id]}),v.invalidateQueries({queryKey:[`inbox`]})});let y=Kt(),b=Be(),x=(0,Q.useId)(),[,S]=(0,Q.useState)(0),C=(0,Q.useCallback)(()=>S(e=>e+1),[]),w=(0,Q.useRef)(null),T=(0,Q.useCallback)(e=>{w.current=e},[]),[E,O]=(0,Q.useState)(),k=D(e.id,f.data),A=k?.files.filter(e=>e.role===`diff`)??[],[j,M]=(0,Q.useState)(null),N=j&&k?Sf(j,k):void 0,P=N?.status===`placed`&&`blockId`in N.location?N.location.blockId:void 0,F=()=>M(e=>e===j?null:e);(0,Q.useEffect)(()=>{if(!j)return;let e=()=>{Le(j.key)||M(e=>e===j?null:e)};return e(),xt(e)},[j]);let I=(k?.docs.length??0)>0||j?.tab===`docs`,L=(k?.files.some(e=>e.role===`diff`)??!1)||j?.tab===`diff`,R=!!k&&(!k.writeupEmpty||k.main===`writeup`)||j?.tab===`writeup`,z=k?df(k):{tab:`writeup`},te=!o.tab||!{writeup:R,files:A.length>0,diff:L,docs:I,comments:!0}[o.tab],B=te?z.tab:o.tab??z.tab,[re,ie]=(0,Q.useState)();B!==`diff`&&re!==B&&ie(B);let V=B===`diff`?y!==`phone`&&b===`tabs`&&re||(R?`writeup`:I?`docs`:`comments`):B,H=V===`docs`&&(b===`split`||B!==`diff`),U=Cf(o,s,d),W=k?wf(k,o,U,te?z.doc:void 0,H):void 0,G=bf(B===`diff`?`Diff`:V===`docs`?W?zu(W):`All docs`:V===`writeup`?`Writeup`:V===`comments`?`Comments`:`Files`,d),ae=(0,Q.useMemo)(()=>({reviewId:e.id,revision:d,choices:G.entry.folds}),[e.id,d,G.entry]),K=H&&o.doc!==void 0&&!W,oe=td(e.id,V,V===`docs`?W?.path??``:``,d,qu(W,o.view)??(W?.kind===`html`?`original`:`reading`)),se=(V!==`docs`||W?.kind!==`source`)&&G.returning&&G.entry.positions.has(oe),[ce,le]=(0,Q.useState)(),ue=!se&&H&&!!W&&U.headingId!==void 0&&(ce===U.navigation||!(W.kind===`html`?/^(0|[1-9]\d*)$/.test(U.headingId)&&W.headings?.[Number(U.headingId)]:W.kind===`markdown`&&W.headings?.some(e=>e.id===U.headingId))),de=e=>{_({search:{...o,tab:B,rev:e}})},[fe,pe]=(0,Q.useState)(null),[me,he]=(0,Q.useState)(),[ge,_e]=(0,Q.useState)(),q=(0,Q.useRef)(null),ve=(0,Q.useRef)(null),ye=(0,Q.useRef)(0),xe=(0,Q.useRef)(-1),Se=(0,Q.useRef)(0),Ce=(0,Q.useCallback)(()=>{let e=fe&&fe!==ve.current?.requested,t=U.navigation!==ve.current?.navigation||G.entry!==ve.current?.entry,n=e?fe:t?U:void 0,r=n&&(e||!se)&&(n.headingId!==void 0||(e||n.elementId!==ve.current?.elementId||n.threadId!==ve.current?.threadId)&&!!(n.elementId||n.threadId));return{current:n?!!r:xe.current===ye.current,epoch:Se.current}},[U,fe,se,G.entry]),J=(0,Q.useCallback)((e,t=``,n=!1)=>{pe({...Cf(e,t,e.rev??l),token:{},jumpThread:!0}),_({search:e,hash:t,replace:n})},[l,_]),we=(0,Q.useCallback)(e=>J({...o,tab:b===`tabs`||y===`phone`?`diff`:`writeup`,thread:void 0},`diff-note-${e}`),[J,o,b,y]),Te=t=>{if(t.defaultPrevented||t.altKey||t.button!==0&&t.button!==1||t.type===`auxclick`&&t.button!==1)return;let n=t.target instanceof Element?t.target.closest(`a[href]`):null;if(!(n instanceof HTMLAnchorElement)||n.hasAttribute(`download`)||n.target&&n.target!==`_self`)return;let r=new URL(n.href);if(r.origin!==window.location.origin||r.pathname!==`/r/${encodeURIComponent(e.id)}`)return;let i=Df(Object.fromEntries(r.searchParams)),a=t.button===1||t.metaKey||t.ctrlKey||t.shiftKey;if(a&&i.tab!==`docs`)return;t.preventDefault();let s={...i,view:qu(Ju(k?.docs??[],i.doc,i.view),i.view??o.view),rev:i.tab===`docs`?d:i.rev??o.rev};if(a){let e=new URLSearchParams;for(let[t,n]of Object.entries(s))n!==void 0&&e.set(t,String(n));window.open(`${r.pathname}?${e}${r.hash}`,`_blank`,`noopener`)}else J(s,r.hash.slice(1),H&&i.tab===`docs`&&i.doc===W?.path&&s.view===o.view)},Ee=e=>{W&&(W.kind===`html`?/^(0|[1-9]\d*)$/.test(e)&&W.headings?.[Number(e)]:W.kind===`markdown`&&W.headings?.some(t=>t.id===e))&&J({...o,rev:d,tab:`docs`,doc:W.path,thread:void 0},`h-${encodeURIComponent(e)}`,!0)},De=e=>{if(e.commentId&&k){k.threads.find(t=>t.comments.some(t=>t.id===e.commentId))&&(M(null),Re(e.key,`comments`),J({...o,tab:`comments`,thread:void 0}));return}if(!e.target||!k)return;let t=e.threadId?k.threads.find(t=>t.id===e.threadId):void 0;if(t){let n=t.placement.status===`placed`?t.placement.location:void 0;M(null),J({...o,tab:`comments`,doc:n?.kind===`doc-span`||n?.kind===`html-span`?n.path:o.doc,view:n?.kind===`doc-span`||n?.kind===`html-span`?qu(void 0,o.view):o.view,thread:e.threadId});return}if(ne(e.target)){Re(e.key,`diff`),M({...e,tab:`diff`}),J({...o,tab:`diff`,thread:void 0});return}if(Re(e.key,`resumed`),e.target.kind===`source-lines`){M({...e,tab:`docs`}),J({...o,tab:`docs`,doc:e.target.path,view:`source`,thread:void 0},``);return}if(e.target.kind===`html-span`){M({...e,tab:`docs`}),J({...o,tab:`docs`,doc:e.target.path,view:qu(void 0,o.view),thread:void 0},`html-doc-${e.target.path}`);return}let n=Sf(e,k);if(n?.status===`placed`&&`blockId`in n.location){let t=n.location.kind===`doc-span`?`docs`:`writeup`;M({...e,tab:t}),J({...o,tab:t,doc:e.target.kind===`doc-span`?e.target.path:o.doc,view:e.target.kind===`doc-span`?qu(void 0,o.view):o.view,thread:void 0},`block-${n.location.blockId}`)}else{let t=e.target.kind===`doc-span`?`docs`:V;M({...e,tab:t}),J({...o,tab:t,doc:e.target.kind===`doc-span`?e.target.path:o.doc,view:e.target.kind===`doc-span`?qu(void 0,o.view):o.view,thread:void 0})}},Oe=()=>{let t={kind:`review`},n=_t(e.id,t);Le(n)||Ze(n,``),De({key:n,target:t})};(0,Q.useEffect)(()=>{let t=U,n=!1;fe&&fe!==ve.current?.requested?(q.current={...fe},n=!0):(t.navigation!==ve.current?.navigation||G.entry!==ve.current?.entry)&&q.current?.navigation!==t.navigation&&(q.current={...t,token:{},restoreEntry:se,jumpThread:t.elementId!==ve.current?.elementId||t.threadId!==ve.current?.threadId},n=!0),n&&(ye.current+=1,q.current&&!q.current.restoreEntry&&(q.current.headingId!==void 0||q.current.jumpThread&&(q.current.elementId||q.current.threadId))&&(xe.current=ye.current,Se.current+=1)),ve.current={navigation:t.navigation,elementId:t.elementId,threadId:t.threadId,requested:fe,entry:G.entry};let r=q.current;if(!r||r.navigation!==t.navigation)return;let i=(e=!1)=>{xe.current===ye.current&&(xe.current=-1,Se.current+=1),q.current=null,he(void 0),e&&hf()};if(r.restoreEntry&&!r.elementId.startsWith(`diff-`)){i();return}if(r.jumpThread&&!r.reply&&r.threadId&&r.elementId===`thread-${r.threadId}`&&r.threadId){if(me?.token!==r.token||me.navigation!==t.navigation){he({threadId:r.threadId,token:r.token,navigation:t.navigation});return}}else if(me){he(void 0);return}if(!k)return;if(H&&!K&&(o.doc!==W?.path||o.view!==qu(W,o.view))){let e={...o,doc:W?.path,view:qu(W,o.view)};r.navigation=Cf(e,s,d).navigation,_({search:e,hash:s,replace:!0});return}let a=k.threads.find(e=>e.id===r.threadId);if(r.routeThread){if(r.threadId&&!a)return;if(r.routeThread=!1,_e(void 0),a?.target.kind===`source-lines`&&(o.tab!==`comments`||o.thread)){let e=a.placement.status===`placed`?a.placement.location:void 0,t=e?.kind===`source-lines`&&k.docs.find(t=>t.kind===`source`&&t.path===e.path&&!t.unrendered),n={...o,tab:t?`docs`:`comments`,doc:t?t.path:o.doc,view:t?`source`:o.view},i=`thread-${a.id}`;if(r.elementId=i,o.tab!==n.tab||o.doc!==n.doc||o.view!==n.view||s!==i){r.navigation=Cf(n,i,d).navigation,_({search:n,hash:i,replace:!0});return}}if(a?.target.kind===`html-span`&&(o.tab!==`comments`||o.thread)){let e=a.placement.status===`placed`?a.placement.location:void 0,t=e?.kind===`html-span`&&k.docs.some(t=>t.kind===`html`&&t.path===e.path),n={...o,tab:t?`docs`:`comments`,doc:t?W?.path??e.path:o.doc,view:t?qu(void 0,o.view):o.view},i=`thread-${a.id}`;if(r.elementId=t?`html-doc-${e.path}`:i,t&&(r.block=`start`),r.reply||=!t,t&&_e({threadId:a.id,intent:r}),o.tab!==n.tab||o.doc!==n.doc||o.view!==n.view||s!==i){r.navigation=Cf(n,i,d).navigation,_({search:n,hash:i,replace:!0});return}}}if(r.headingId!==void 0&&H&&W?.kind===`html`){let e=/^(0|[1-9]\d*)$/.test(r.headingId)&&W.headings?.[Number(r.headingId)];le(e?void 0:t.navigation),i();return}if(r.headingId!==void 0||K){let e=document.querySelector(`[data-reading-scroll]`);if(!e||H&&!K&&!W)return;let n=H&&W&&e&&r.headingId!==void 0?Uu(e,W,r.headingId):void 0;le(n?void 0:t.navigation),n&&W?(Pd(n),n.scrollIntoView?.({block:`start`}),n.tabIndex=-1,G.entry.focus={id:`h-${n.id}`,children:[]},Xu(n)):H&&e&&(e.scrollTop=0),i(!0);return}if(!r.elementId){i();return}if(r.reply){if(!a)return;i(),Re(_t(e.id,a.target,a.id),o.tab===`docs`?`reading`:`comments`);return}if(r.elementId.startsWith(`diff-`)){if(b===`tabs`&&L&&B!==`diff`){let e={...o,tab:`diff`};r.navigation=Cf(e,s,d).navigation,_({search:e,hash:s,replace:!0});return}w.current?.({elementId:r.elementId})&&i(r.jumpThread);return}let c=Ru(r.elementId)?document.getElementById(r.elementId):null;c&&(Pd(c),c.scrollIntoView?.({block:r.block}),i(r.jumpThread),c.hasAttribute(`data-thread-card`)&&c.closest(`.em-source`)&&(c.tabIndex=-1,c.focus({preventScroll:!0})))});let ke={id:e.id,search:{...o,tab:B},hasDocs:I,hasDiff:L,hasWriteup:R,unsentCount:e.unsentCount,filesCount:A.length,viewedCount:A.filter(e=>e.viewed===`viewed`).length},Ae=Math.max(t,e.newestRevision);return(0,$.jsx)(Hc,{isReview:!0,onCommentReview:k?Oe:void 0,children:(0,$.jsx)(`div`,{className:`contents`,onClickCapture:Te,onAuxClickCapture:Te,children:(0,$.jsx)(ju,{inbox:(0,$.jsx)(Fu,{currentReviewId:e.id,collapsed:r,onCollapsedChange:i}),tab:B,hasDiff:L,readingLayout:H&&W?.kind===`html`?`original`:void 0,phoneTabs:(0,$.jsx)(Nu,{...ke}),tabs:(0,$.jsx)(Lu,{...ke,docsCount:k?.docs.length??0,idBase:x}),sendBar:(0,$.jsx)(cf,{reviewId:e.id,revision:k?.seq,newestRevision:Ae,revisionError:f.isError,unsentCount:e.unsentCount,approved:e.state===`approved`,agent:{agentWaiting:e.agentWaiting,pendingSend:e.pendingSend,pickedUpAt:e.pickedUpAt,releasedAt:e.releasedAt,newestRevision:e.newestRevision},lifecycle:{title:e.title,state:e.state,snoozed:e.snoozed,snoozedUntil:e.snoozedUntil,onDeleted:()=>{_({to:`/`}).then(()=>{v.removeQueries({queryKey:[`review`,e.id]}),v.removeQueries({queryKey:[`revision`,e.id]})})}},phone:y===`phone`},e.id),header:(0,$.jsxs)($.Fragment,{children:[m.errors.map(e=>(0,$.jsxs)(`div`,{role:`alert`,className:`px-4 py-2 text-danger-fg`,children:[(0,$.jsxs)(`p`,{children:[e.error&&ee(e.error),` `,(0,$.jsx)(`bdi`,{children:e.failedPaths?.[0]}),(e.failedPaths?.length??0)>1&&` and ${(e.failedPaths?.length??1)-1} other files`]}),(0,$.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>m.dismiss(e.id),children:`Dismiss`})]},e.id)),(y!==`phone`||B!==`diff`)&&(0,$.jsx)(Wd,{review:e,revision:k,seq:d,ready:Ae,phone:y===`phone`,titleRef:n,onRevisionChange:de,onCommentReview:Oe})]}),reading:(0,$.jsx)(`div`,{className:`contents`,children:(0,$.jsxs)(`div`,{className:H&&W?.kind===`html`?`em-original-panel`:void 0,...y===`phone`?{}:{role:`tabpanel`,id:`${x}-reading-panel`,"aria-labelledby":`${x}-tab-${V}`},children:[f.isPending&&(0,$.jsx)(`p`,{role:`status`,className:`p-5`,children:`Loading revision…`}),f.isError&&(0,$.jsxs)(`div`,{className:`p-5`,children:[(0,$.jsx)(`p`,{role:`alert`,children:`Could not load this revision.`}),(0,$.jsx)(Y,{onClick:()=>void f.refetch(),children:`Retry`})]}),(K||ue)&&(0,$.jsx)(`p`,{role:`status`,className:`px-4 py-2`,children:K?`Document not found. Showing all docs.`:`Heading not found. Showing the top of the document.`}),k&&(0,$.jsx)(pd,{value:ae,children:V===`files`?(0,$.jsx)(Ou,{revision:k,counts:g,onViewed:h,onNavigate:e=>J({...o,tab:b===`tabs`?`diff`:`files`,thread:void 0},`diff-file-${e.id}`)}):(0,$.jsx)(xf,{reviewId:e.id,revision:k,tab:V,visible:b===`split`||B!==`diff`||!L,intentState:Ce,entry:G.entry,returning:G.returning,headingTarget:U.headingId,visit:fe?.token??U.navigation,preservePosition:!G.returning&&U.elementId.startsWith(`diff-`),back:G.back,onHeading:Ee,search:o,openDoc:W,targeted:!!s||!!o.thread||G.returning&&!!G.entry.focus,activeThreadId:U.threadId,threadJump:me?.navigation===U.navigation?me:void 0,onOpenDoc:e=>J({...o,rev:d,tab:`docs`,doc:e.path,view:qu(e,o.view),thread:void 0},``,H&&!!W&&Gu(e)===Gu(W)),phone:y===`phone`,onResume:De,htmlNavigation:ge,composingPath:j?.target?.kind===`html-span`?j.target.path:void 0,resumedBlockId:P,onCurrentTopic:y!==`phone`&&L?O:void 0,onNote:we},`${d}:${V}`)}),j?.target&&!ne(j.target)&&(0,$.jsx)(pt,{surface:`resumed`,placeholder:!1,reviewId:e.id,revision:d,target:j.target,topics:k?.topics,threadId:j.threadId,storageKey:j.key,onSaved:F,onCancel:F,wrap:e=>(0,$.jsx)(`section`,{"aria-label":`Resumed comment`,className:`sticky bottom-0 px-4 pt-4 pb-8 md:pr-8 md:pl-14`,children:e})})]})}),diff:(0,$.jsx)(`div`,{...y!==`phone`&&b===`tabs`?{role:`tabpanel`,id:`${x}-diff-panel`,"aria-labelledby":`${x}-tab-diff`}:{},children:k?(0,$.jsx)(Du,{reviewId:e.id,revision:k,resume:j?.target&&ne(j.target)?j:void 0,onResumeEnd:F,onRendered:C,onNavigator:T,currentTopic:E,writeupVisible:V===`writeup`&&b===`split`,search:o,onViewed:h},d):(0,$.jsx)(`p`,{role:f.isError?`alert`:`status`,className:`p-5`,children:f.isError?`Could not load this revision.`:`Loading revision…`})})})})})}function Ef(){let{reviewId:e}=Ga({from:`/r/$reviewId`}),t=c(el(e)),n=Dc(e),[r,i]=Rt(),a=(0,Q.useRef)(e),o=(0,Q.useRef)(!1),s=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{a.current!==e&&(a.current=e,o.current=!0),t.isError&&!t.data&&(o.current=!1),o.current&&t.data?.id===e&&(o.current=!1,s.current?.focus())},[e,t.data,t.isError]),t.error instanceof G&&t.error.status===404&&t.error.code===`unknown_review`?(0,$.jsx)(Hc,{isReview:!0,children:(0,$.jsxs)(`main`,{className:`p-5`,children:[(0,$.jsx)(`p`,{role:`status`,children:`This review was deleted or never existed.`}),(0,$.jsx)(co,{to:`/`,children:`Back to the inbox`})]})}):t.data?(0,$.jsx)(Tf,{review:t.data,published:n,titleRef:s,collapsed:r,setCollapsed:i},e):(0,$.jsx)(Hc,{isReview:!0,children:(0,$.jsx)(`main`,{className:`p-5`,children:t.isError?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{role:`alert`,children:`Could not load this review.`}),(0,$.jsx)(Y,{onClick:()=>void t.refetch(),children:`Retry`})]}):(0,$.jsx)(`p`,{role:`status`,children:`Loading review…`})})})}function Df(e){let t=typeof e.rev==`string`||typeof e.rev==`number`?Number(e.rev):NaN;return{tab:e.tab===`writeup`||e.tab===`files`||e.tab===`diff`||e.tab===`docs`||e.tab===`comments`?e.tab:void 0,view:e.view===`reading`||e.view===`original`||e.view===`source`?e.view:void 0,rev:Number.isSafeInteger(t)&&t>0?t:void 0,doc:qe.safeParse(e.doc).data,thread:typeof e.thread==`string`&&/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(e.thread)?e.thread:void 0}}var Of=mo({component:wo,notFoundComponent:()=>(0,$.jsxs)(`main`,{className:`p-6`,children:[(0,$.jsx)(`h1`,{children:`Page not found`}),(0,$.jsx)(co,{to:`/`,children:`Inbox`})]})}),kf=fo({getParentRoute:()=>Of,path:`/`,component:Ol}),Af=fo({getParentRoute:()=>Of,path:`/r/$reviewId`,validateSearch:Df,component:Ef}),jf=fo({getParentRoute:()=>Of,path:`/pair`,component:jl}),Mf=fo({getParentRoute:()=>Of,path:`/devices`,component:Qc}),Nf=fo({getParentRoute:()=>Mf,path:`pair`,component:wu}),Pf=e=>{let t=Ao({routeTree:Of.addChildren([kf,Af,jf,Mf.addChildren([Nf])]),history:e,search:{strict:!0}});return t.subscribe(`onBeforeNavigate`,_e),t.update({scrollRestoration:({location:e})=>!/^\/r\/[^/]+\/?$/.test(e.pathname)}),t};function Ff({children:e}){let t=Po({select:e=>/^\/pair\/?$/i.test(e.location.pathname)});return(0,$.jsx)(Ec,{enabled:!t,children:e})}function If({queryClient:e,history:t}={}){let[n]=(0,Q.useState)(()=>e??new an({defaultOptions:{queries:{retry:!1}}})),[r]=(0,Q.useState)(()=>Pf(t));return(0,$.jsx)(I,{client:n,children:(0,$.jsx)(Ie,{children:(0,$.jsx)(lc,{children:(0,$.jsx)(No,{router:r,InnerWrap:Ff})})})})}export{If as App};