cctally 1.56.1 → 1.56.2
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.
- package/CHANGELOG.md +6 -0
- package/bin/_lib_conversation_query.py +44 -8
- package/dashboard/static/assets/{index-C2i65CfJ.js → index-CtgGA2MX.js} +1 -1
- package/dashboard/static/assets/{index-DV7rZVrP.css → index-DBy0SKfB.css} +1 -1
- package/dashboard/static/dashboard.html +2 -2
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@ Error generating stack: `+e.message+`
|
|
|
15
15
|
`]},t):e.type===`exit`?(0,B.jsxs)(`span`,{className:`update-stream-exit`,children:[`(exited rc=${e.rc??`?`})`,`
|
|
16
16
|
`]},t):(0,B.jsxs)(`span`,{className:`update-stream-line`,children:[e.data??``,`
|
|
17
17
|
`]},t))]})}var Ys=3e3,Xs=1e3;function Zs(e){if(e==null)return`0s`;let t=Math.max(0,Math.round((Date.now()-e)/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Qs(){let e=(0,_.useSyncExternalStore)(R,()=>L().update),t=e.runId,n=e.startedAt,r=e.state?.update_command??``,i=e.state?.latest_version??``,[,a]=(0,_.useState)(0);(0,_.useEffect)(()=>{let e=window.setInterval(()=>a(e=>e+1),1e3);return()=>window.clearInterval(e)},[]);let o=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{if(!t)return;let e=null,n=null,r=null,i=!1;o.current=!0;function a(){r!=null&&(window.clearTimeout(r),r=null),o.current=!1}function s(t,n){a();let r={};try{t instanceof MessageEvent&&typeof t.data==`string`&&(r=JSON.parse(t.data))}catch{}if(z({type:`APPEND_UPDATE_STREAM`,event:{type:n,data:typeof r.data==`string`?r.data:void 0,name:typeof r.name==`string`?r.name:void 0,rc:typeof r.rc==`number`?r.rc:void 0,step:typeof r.step==`string`?r.step:void 0,message:typeof r.message==`string`?r.message:void 0,ts:typeof r.ts==`number`?r.ts:void 0}}),n===`exit`){let e=typeof r.rc==`number`?r.rc:-1;e!==0&&z({type:`SET_UPDATE_STATUS`,status:`failed`,errorMessage:`subprocess exited with rc=${e}`})}else n===`execvp`?z({type:`SET_UPDATE_STATUS`,status:`success`}):n===`error_event`?z({type:`SET_UPDATE_STATUS`,status:`failed`,errorMessage:typeof r.message==`string`?r.message:`update worker error`}):n===`done`&&(e&&=(e.close(),null))}function c(){n??=window.setInterval(async()=>{if(!i)try{let e=await fetch(`/api/update/status`);if(!e.ok)return;let t=await e.json(),r=t?.current_run_id??null,i=t?.state??{};if(r===null){let e=i?.current_version,t=i?.latest_version,r=L().update;typeof e==`string`&&typeof t==`string`&&e===t?z({type:`SET_UPDATE_STATUS`,status:`success`}):r.status===`running`&&z({type:`SET_UPDATE_STATUS`,status:`failed`,errorMessage:`update worker exited (stream unavailable)`}),r.stream.length===0&&z({type:`APPEND_UPDATE_STREAM`,event:{type:`stdout`,data:`(SSE stream unavailable; install completed in background — see ~/.local/share/cctally/update.log for full output)`}}),n!=null&&(window.clearInterval(n),n=null)}}catch{}},Xs)}r=window.setTimeout(()=>{i||o.current&&(o.current=!1,e&&=(e.close(),null),c())},Ys);try{e=new EventSource(`/api/update/stream/${encodeURIComponent(t)}`),e.addEventListener(`message`,e=>s(e,`stdout`)),[`stdout`,`stderr`,`step`,`exit`,`execvp`,`error_event`,`done`,`heartbeat`].forEach(t=>{e.addEventListener(t,e=>s(e,t))}),e.onerror=()=>{o.current&&(a(),e&&=(e.close(),null),c())}}catch{a(),c()}return()=>{i=!0,r!=null&&(window.clearTimeout(r),r=null),n!=null&&(window.clearInterval(n),n=null),e&&=(e.close(),null),o.current=!1,Pt()}},[t]),(0,B.jsxs)(`div`,{className:`update-modal-body`,children:[(0,B.jsxs)(`div`,{className:`update-running-row`,children:[(0,B.jsx)(`span`,{className:`update-spinner`,"aria-hidden":`true`,children:`⟳`}),(0,B.jsx)(`code`,{className:`update-cmd update-cmd-inline`,children:r||`updating cctally`}),(0,B.jsxs)(`span`,{className:`update-elapsed`,children:[Zs(n),` elapsed`]})]}),(0,B.jsx)(Js,{events:e.stream}),(0,B.jsxs)(`p`,{className:`update-stream-cap`,children:[`Output streams over SSE · press Esc to hide (install continues to `,i||`latest`,`)`]})]})}var $s=1500,ec=20;function tc(e){if(e==null)return`—`;let t=Math.max(0,Math.round((Date.now()-e)/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function nc(){let e=(0,_.useSyncExternalStore)(R,()=>L().update),t=e.startedAt,n=e.state?.update_command??``,r=e.state?.latest_version??``,i=(0,_.useRef)(0),[a,o]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{let e=window.setInterval(()=>{if(i.current>=ec){window.clearInterval(e),o(!0);return}i.current+=1,Pt()},$s);return()=>window.clearInterval(e)},[]),(0,B.jsxs)(`div`,{className:`update-modal-body`,children:[(0,B.jsxs)(`div`,{className:`update-running-row update-running-row-success`,children:[(0,B.jsx)(`span`,{className:`update-check`,"aria-hidden":`true`,children:`✓`}),(0,B.jsx)(`code`,{className:`update-cmd update-cmd-inline`,children:n||`cctally`}),(0,B.jsxs)(`span`,{className:`update-elapsed`,children:[`finished in `,tc(t)]})]}),(0,B.jsxs)(`div`,{className:`update-row-label`,children:[`Restarting dashboard on the new code`,r?` (${r})`:``,`…`]}),a?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`update-running-row`,children:(0,B.jsx)(`span`,{className:`update-success-reconnect`,children:`Still reconnecting — check update.log`})}),(0,B.jsx)(`button`,{type:`button`,className:`update-btn`,onClick:()=>{z({type:`CLOSE_UPDATE_MODAL`}),z({type:`RESET_UPDATE_RUN`})},children:`Close`})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`update-running-row`,children:[(0,B.jsx)(`span`,{className:`update-spinner`,"aria-hidden":`true`,children:`⟳`}),(0,B.jsx)(`span`,{className:`update-success-reconnect`,children:`reconnecting (this page will refresh in a moment)`})]}),(0,B.jsx)(`p`,{className:`modal-hint`,children:`Press Esc to close`})]})]})}function rc(e,t){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.type===`exit`&&typeof n.rc==`number`)return`exited rc=${n.rc}`;if(n.type===`error_event`)return n.message??`worker error`}return t??`unknown failure`}function ic(){let e=(0,_.useSyncExternalStore)(R,()=>L().update),[t,n]=(0,_.useState)(`idle`),r=e.state?.update_command??``,i=e.stream.filter(e=>e.type===`stderr`&&e.data).map(e=>e.data).slice(-12),a=rc(e.stream,e.errorMessage);function o(){z({type:`RESET_UPDATE_RUN`}),Ft()}async function s(){if(r)try{await navigator.clipboard.writeText(r),n(`ok`),window.setTimeout(()=>n(`idle`),1500)}catch{n(`err`),window.setTimeout(()=>n(`idle`),1500)}}return(0,B.jsxs)(`div`,{className:`update-modal-body`,children:[(0,B.jsxs)(`div`,{className:`update-running-row update-running-row-failed`,children:[(0,B.jsx)(`span`,{className:`update-x`,"aria-hidden":`true`,children:`✗`}),(0,B.jsx)(`code`,{className:`update-cmd update-cmd-inline`,children:r||`cctally update`}),(0,B.jsx)(`span`,{className:`update-elapsed`,children:a})]}),i.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`update-row-label`,children:[`stderr (last `,i.length,` line`,i.length===1?``:`s`,`)`]}),(0,B.jsx)(`pre`,{className:`update-stream update-stream-fail`,children:i.map((e,t)=>(0,B.jsxs)(`span`,{className:`update-stream-line err`,children:[e,`
|
|
18
|
-
`]},t))})]}):(0,B.jsx)(`p`,{className:`update-manual-note`,children:e.errorMessage??`See ~/.local/share/cctally/update.log for the full failure log.`}),(0,B.jsxs)(`p`,{className:`update-stream-cap`,children:[`Full log: `,(0,B.jsx)(`code`,{children:`~/.local/share/cctally/update.log`})]}),(0,B.jsxs)(`div`,{className:`update-actions`,children:[(0,B.jsx)(`button`,{type:`button`,className:`update-btn update-btn-primary`,onClick:o,children:`Retry`}),(0,B.jsx)(`button`,{type:`button`,className:`update-btn`,onClick:s,disabled:!r,children:t===`ok`?`Copied!`:t===`err`?`Copy failed`:`Copy command`}),(0,B.jsx)(`button`,{type:`button`,className:`update-btn`,onClick:()=>Rt.close(),children:`Close`})]})]})}var ac={idle:`Update available`,running:`Updating cctally`,success:`Update complete`,failed:`Update failed`},oc={idle:`accent-amber`,running:`accent-amber`,success:`accent-green`,failed:`accent-red`};function sc(){let e=(0,_.useSyncExternalStore)(R,()=>L().update),t=()=>z({type:`CLOSE_UPDATE_MODAL`});if(On((0,_.useMemo)(()=>[{key:`Escape`,scope:`modal`,action:t,when:()=>L().update.modalOpen}],[])),In(e.modalOpen&&e.state!=null),!e.modalOpen||!e.state)return null;let n=e.status,r=oc[n]??`accent-amber`,i=ac[n]??`Update`;n===`running`&&e.state.latest_version?i=`Updating cctally → ${e.state.latest_version}`:n===`success`&&e.state.latest_version&&(i=`Update complete → ${e.state.latest_version}`);let a;switch(n){case`running`:a=(0,B.jsx)(Qs,{});break;case`success`:a=(0,B.jsx)(nc,{});break;case`failed`:a=(0,B.jsx)(ic,{});break;default:a=(0,B.jsx)(qs,{});break}return(0,B.jsxs)(`div`,{id:`update-modal-root`,className:`update-modal-root`,children:[(0,B.jsx)(`div`,{className:`modal-backdrop`,onClick:t}),(0,B.jsxs)(`div`,{className:`modal-card update-modal-card ${r}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`update-modal-title`,children:[(0,B.jsx)(`div`,{className:`modal-handle`,"aria-hidden":`true`}),(0,B.jsx)(Gr,{title:i,titleId:`update-modal-title`,onClose:t}),(0,B.jsx)(`div`,{className:`modal-body`,children:a})]})]})}function cc({title:e,accentClass:t,children:n,headerExtras:r}){let i=()=>z({type:`CLOSE_MODAL`});On((0,_.useMemo)(()=>[{key:`Escape`,scope:`modal`,action:i}],[]));let a=(0,_.useRef)(null);return Mn(a,{active:!0,trapEnabled:(0,_.useSyncExternalStore)(R,()=>pt(L())===`panel`)}),In(!0),(0,B.jsxs)(`div`,{id:`modal-root`,children:[(0,B.jsx)(`div`,{className:`modal-backdrop`,onClick:i}),(0,B.jsxs)(`div`,{ref:a,className:`modal-card ${t}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`modal-title`,children:[(0,B.jsx)(`div`,{className:`modal-handle`,"aria-hidden":`true`}),(0,B.jsx)(Gr,{title:e,titleId:`modal-title`,headerExtras:r,onClose:i}),(0,B.jsx)(`div`,{id:`modal-body`,className:`modal-body`,children:n})]})]})}function lc(e){return e==null||!isFinite(e)?0:Math.max(0,Math.min(100,e))}function uc(e,t,n){let r=F.dateShort(t,n);return e&&r?`${e} → ${r}`:e||(r?`→ ${r}`:`—`)}function dc(e){if(e==null||!isFinite(e))return[`—`,``];let t=(+e).toFixed(1),n=t.indexOf(`.`);return n===-1?[t,`.0%`]:[t.slice(0,n),t.slice(n)+`%`]}function fc(e){let t=[],n=[...e].sort((e,t)=>(e.percent??0)-(t.percent??0));for(let e of n)e.percent!=null&&(t.length&&e.percent-(t[t.length-1].percent??0)<3||t.push(e));return t}function pc(e){if(!Array.isArray(e)||e.length<2)return null;let t=e.map(e=>e.marginal_usd).filter(e=>e!=null&&isFinite(e)),n=t.length?t.reduce((e,t)=>e+t,0)/t.length:null,r=e[e.length-1].percent,i=[];return n!=null&&i.push(`avg marginal $`+n.toFixed(2)),r!=null&&i.push(`latest at `+r+`%`),i.length?i.join(` · `):null}function mc(e,t){let n=[];for(let t of e)n.push({kind:`milestone`,ts:t.captured_at_utc,data:t});for(let e of t)n.push({kind:`credit`,ts:e.effective_reset_at_utc,data:e});return n.sort((e,t)=>e.ts.localeCompare(t.ts)),n}function hc(){let e=V(),t=Rn(),n={tz:t.resolvedTz,offsetLabel:t.offsetLabel},r=e?.current_week??null,i=e?.header??null,a=Array.isArray(r?.milestones)?r.milestones:[],o=Array.isArray(r?.five_hour_milestones)?r.five_hour_milestones:[],s=mc(o,Array.isArray(r?.five_hour_block?.credits)?r.five_hour_block.credits:[]),c=lc(r?.used_pct),[l,u]=dc(r?.used_pct),d=r?uc(i?.week_label,r.reset_at_utc,n):`—`,f=fc(a),p=pc(a);return(0,B.jsx)(cc,{title:`Current Week — per-percent milestones`,accentClass:`accent-green`,headerExtras:(0,B.jsx)(Vn,{panel:`current-week`,panelLabel:`Current week`,triggerId:`current-week-modal`,onClick:()=>z(He(`current-week`,`current-week-modal`))}),children:(0,B.jsxs)(`section`,{className:`modal-current-week`,children:[(0,B.jsx)(`div`,{className:`m-chipstrip`,id:`mcw-badges`,children:(0,B.jsx)(`span`,{className:`m-pill accent-green`,id:`mcw-week-pill`,children:d})}),(0,B.jsxs)(`div`,{className:`mcw-herobar`,children:[(0,B.jsxs)(`div`,{className:`mcw-bignum`,id:`mcw-bignum`,children:[(0,B.jsx)(`span`,{className:`int`,children:l}),(0,B.jsx)(`span`,{className:`unit`,children:u})]}),(0,B.jsxs)(`div`,{className:`mcw-pbar-wrap`,children:[(0,B.jsxs)(`div`,{className:`mcw-pbar`,children:[(0,B.jsx)(`div`,{className:`fill`,id:`mcw-fill`,style:{width:c+`%`}}),(0,B.jsx)(`div`,{className:`ticks`,id:`mcw-ticks`,children:f.map(e=>(0,B.jsx)(`div`,{className:`tick`,"data-p":String(e.percent),style:{left:lc(e.percent)+`%`}},e.percent))}),(0,B.jsx)(`div`,{className:`marker`,id:`mcw-marker`,style:{left:c+`%`}})]}),(0,B.jsxs)(`div`,{className:`mcw-pscale`,children:[(0,B.jsx)(`span`,{children:`0%`}),(0,B.jsx)(`span`,{children:`25%`}),(0,B.jsx)(`span`,{children:`50%`}),(0,B.jsx)(`span`,{children:`75%`}),(0,B.jsx)(`span`,{children:`100%`})]})]}),(0,B.jsxs)(`div`,{className:`mcw-mini`,id:`mcw-mini`,children:[(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`spent`}),(0,B.jsx)(`span`,{className:`v v-magenta`,id:`mcw-spent`,children:F.usd2(r?.spent_usd)})]}),(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`$ / 1%`}),(0,B.jsx)(`span`,{className:`v v-cyan`,id:`mcw-dpp`,children:F.usd3(r?.dollar_per_pct)})]}),(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`reset`}),(0,B.jsx)(`span`,{className:`v`,id:`mcw-reset`,children:F.datetimeShortZ(r?.reset_at_utc,n)})]})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-ms`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),`Milestones`]}),(0,B.jsxs)(`div`,{className:`mcw-mshead`,children:[(0,B.jsxs)(`span`,{className:`m-pill accent-purple`,id:`mcw-ms-count`,children:[a.length,` crossed`]}),(0,B.jsx)(`span`,{className:`mcw-ms-sub`,id:`mcw-ms-sub`,hidden:!p,children:p??``})]}),a.length===0?(0,B.jsx)(`p`,{className:`empty-state`,id:`mcw-empty`,children:`No milestones yet — earliest crosses at 1\xA0%.`}):(0,B.jsxs)(`table`,{className:`m-histable`,id:`mcw-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`%`}),(0,B.jsxs)(`th`,{children:[`Crossed (`,t.offsetLabel,`)`]}),(0,B.jsx)(`th`,{className:`num`,children:`Cumulative $`}),(0,B.jsx)(`th`,{className:`num`,children:`Marginal $`}),(0,B.jsx)(`th`,{className:`num`,children:`5h %`})]})}),(0,B.jsx)(`tbody`,{id:`mcw-rows`,children:a.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`span`,{className:`m-pill accent-purple pct-cell`,children:e.percent??`—`})}),(0,B.jsx)(`td`,{className:`d`,children:F.startedShort(e.crossed_at_utc,n,{noSuffix:!0})}),(0,B.jsx)(`td`,{className:`num`,children:e.cumulative_usd==null?`—`:`$`+e.cumulative_usd.toFixed(2)}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(`span`,{className:`m-marginal`,children:e.marginal_usd==null?`—`:`$`+e.marginal_usd.toFixed(2)})}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(`span`,{className:`m-fh`,children:e.five_hour_pct_at_cross==null?`—`:Math.round(e.five_hour_pct_at_cross)+`%`})})]},e.percent))})]}),s.length>0&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-ms sec-5h`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#activity`})}),`5h milestones`]}),(0,B.jsx)(`div`,{className:`mcw-mshead`,children:(0,B.jsxs)(`span`,{className:`m-pill accent-purple`,id:`mcw-5h-count`,children:[o.length,` crossed`]})}),(0,B.jsxs)(`table`,{className:`m-histable mcw-5h-table`,id:`mcw-5h-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`%`}),(0,B.jsxs)(`th`,{children:[`When (`,t.offsetLabel,`)`]}),(0,B.jsx)(`th`,{className:`num`,children:`Block $`}),(0,B.jsx)(`th`,{className:`num`,children:`Marginal $`}),(0,B.jsx)(`th`,{className:`num`,children:`7d %`})]})}),(0,B.jsx)(`tbody`,{children:s.map((e,t)=>{if(e.kind===`credit`)return(0,B.jsx)(`tr`,{className:`mcw-5h-credit-row`,children:(0,B.jsxs)(`td`,{colSpan:5,className:`mcw-5h-credit-cell`,children:[`⚡ CREDIT\xA0`,` `,e.data.delta_pp>0?`+`:``,e.data.delta_pp.toFixed(0),`pp\xA0@`,` `,F.startedShort(e.ts,n,{noSuffix:!0})]})},`credit-${t}-${e.ts}`);let r=e.data;return(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`span`,{className:`m-pill accent-purple pct-cell`,children:r.percent_threshold})}),(0,B.jsx)(`td`,{className:`d`,children:F.startedShort(r.captured_at_utc,n,{noSuffix:!0})}),(0,B.jsx)(`td`,{className:`num`,children:`$`+r.block_cost_usd.toFixed(2)}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(`span`,{className:`m-marginal`,children:r.marginal_cost_usd==null?`—`:`$`+r.marginal_cost_usd.toFixed(2)})}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(`span`,{className:`m-fh`,children:r.seven_day_pct_at_crossing==null?`—`:Math.round(r.seven_day_pct_at_crossing)+`%`})})]},`fhms-${r.percent_threshold}-${r.reset_event_id}`)})})]})]})]})})}function gc(e){if(!e)return`—`;let t=e.elapsed_hours,n=e.remaining_hours;if(t==null||n==null)return`—`;let r=t+n;if(r<=0)return`—`;let i=t/r*100;return Math.min(100,i).toFixed(1)+`%`}function _c(e){return e==null||!isFinite(e)?null:e<0?0:e>110?110:e}function vc(e){return e==null||!isFinite(e)?`—`:e<0?`~`+(+e).toFixed(1)+`%`:(+e).toFixed(1)+`%`}function yc(e,t){for(let t of e)t.trueXPct=t.pos/110*100;if(e.length<2||t<=0){for(let t of e)t.resolvedXPct=t.trueXPct;return}let n=e.slice().sort((e,t)=>e.trueXPct-t.trueXPct),r=n[0],i=n[1],a=r.pillWidthPx/2/t*100,o=i.pillWidthPx/2/t*100,s=8/t*100,c=a+o+s,l=2*c;if(i.trueXPct-r.trueXPct<c){let e=(r.trueXPct+i.trueXPct)/2;r.resolvedXPct=e-l/2,i.resolvedXPct=e+l/2;let t=a,n=100-o;r.resolvedXPct<t&&(r.resolvedXPct=t,i.resolvedXPct-r.resolvedXPct<l&&(i.resolvedXPct=Math.min(n,r.resolvedXPct+l))),i.resolvedXPct>n&&(i.resolvedXPct=n,i.resolvedXPct-r.resolvedXPct<l&&(r.resolvedXPct=Math.max(t,i.resolvedXPct-l)))}else r.resolvedXPct=r.trueXPct,i.resolvedXPct=i.trueXPct}function bc(e,t,n){(0,_.useEffect)(()=>{let r=e.current,i=t.current;if(!r||!i||!n)return;let a=r.querySelector(`.mfc-pills`),o=r.querySelector(`.mfc-leaders`),s=i.querySelector(`.mfc-rangeband`);if(!a||!o)return;let c=n.week_avg_projection_pct,l=n.recent_24h_projection_pct,u=_c(c),d=_c(l),f=[];u!=null&&c!=null&&f.push({kind:`wa`,pos:u,raw:c}),d!=null&&l!=null&&f.push({kind:`r24`,pos:d,raw:l});let p=new Set(f.map(e=>e.kind));i.querySelectorAll(`.mfc-chev`).forEach(e=>{let t=e.dataset.kind;(!t||!p.has(t))&&e.remove()}),a.querySelectorAll(`.mfc-pill`).forEach(e=>{let t=e.dataset.kind;(!t||!p.has(t))&&e.remove()});let m=f.map(e=>({...e,trueXPct:0,resolvedXPct:0,pillWidthPx:0}));for(let e of m){let t=e.pos/110*100,n=i.querySelector(`.mfc-chev[data-kind="${e.kind}"]`);n||(n=document.createElement(`div`),n.className=`mfc-chev `+e.kind,n.dataset.kind=e.kind,i.appendChild(n)),n.style.left=t+`%`;let r=a.querySelector(`.mfc-pill[data-kind="${e.kind}"]`),o=vc(e.raw);r?r.textContent!==o&&(r.textContent=o):(r=document.createElement(`div`),r.className=`mfc-pill `+e.kind,r.dataset.kind=e.kind,r.textContent=o,a.appendChild(r)),e.pillEl=r}if(s){let e=!1;if(m.length===2){let t=m[0].pos/110*100,n=m[1].pos/110*100,r=Math.min(t,n),i=Math.max(t,n)-r;i>=.5&&(s.style.left=r+`%`,s.style.width=i+`%`,e=!0)}s.hidden=!e}let h=()=>{for(let e of m)if(!e.pillEl||!e.pillEl.isConnected)return;let e=r.clientWidth;if(e<=0){requestAnimationFrame(h);return}for(let e of m)e.pillWidthPx=e.pillEl.getBoundingClientRect().width;yc(m,e);for(let e of m)e.pillEl.style.left=e.resolvedXPct+`%`;for(;o.firstChild;)o.removeChild(o.firstChild);for(let e of m){let t=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);t.setAttribute(`class`,e.kind),t.setAttribute(`vector-effect`,`non-scaling-stroke`),t.setAttribute(`d`,`M ${e.resolvedXPct} 0 C ${e.resolvedXPct} 10, ${e.trueXPct} 8, ${e.trueXPct} 18`),o.appendChild(t)}};h()},[e,t,n])}function U(){let e=V()?.forecast??null,t=e?.explain??null,n=(0,_.useRef)(null),r=(0,_.useRef)(null);bc(n,r,e);let i=(0,B.jsx)(Vn,{panel:`forecast`,panelLabel:`Forecast`,triggerId:`forecast-modal`,onClick:()=>z(He(`forecast`,`forecast-modal`))});if(!e)return(0,B.jsx)(cc,{title:`Forecast — explain`,accentClass:`accent-purple`,headerExtras:i,children:(0,B.jsx)(`section`,{className:`modal-forecast`,children:(0,B.jsx)(`p`,{className:`empty-state`,id:`mfc-empty`,children:`No forecast data yet.`})})});let a=cn(e.verdict),o=a?`m-pill ${a.accent}`:`m-pill`,s=a?`${a.glyph} ${a.label}`:`—`,c=`m-pill`,l=`—`,u=!0;e.confidence===`high`?(c=`m-pill accent-blue`,l=`high confidence`,u=!1):e.confidence===`low`&&(c=`m-pill accent-red`,l=`low confidence`,u=!1);let d=t?.rates,f=t?.week;return(0,B.jsx)(cc,{title:`Forecast — explain`,accentClass:`accent-purple`,headerExtras:i,children:(0,B.jsxs)(`section`,{className:`modal-forecast`,children:[(0,B.jsxs)(`div`,{className:`m-chipstrip`,id:`mfc-chips`,children:[(0,B.jsx)(`span`,{className:o,id:`mfc-verdict`,children:s}),(0,B.jsx)(`span`,{className:c,id:`mfc-confidence`,hidden:u,children:l})]}),(0,B.jsxs)(`div`,{className:`m-hero cols-2`,children:[(0,B.jsxs)(`div`,{className:`m-kv kv-wa`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#gauge`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mfc-wa-pct`,children:F.pct1(e.week_avg_projection_pct)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Week-avg projection`}),(0,B.jsx)(`div`,{className:`sub`,id:`mfc-wa-sub`,children:F.ratePctPerHour(d?.week_average_pct_per_hour)})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-r24`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#zap`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mfc-r24-pct`,children:F.pct1(e.recent_24h_projection_pct)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Recent-24h projection`}),(0,B.jsx)(`div`,{className:`sub`,id:`mfc-r24-sub`,children:F.ratePctPerHour(d?.recent_24h_pct_per_hour)})]})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-range`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#bar-chart`})}),`Range vs. caps`]}),(0,B.jsxs)(`div`,{className:`mfc-rangewrap`,id:`mfc-rangewrap`,ref:n,children:[(0,B.jsx)(`div`,{className:`mfc-pills`,id:`mfc-pills`}),(0,B.jsx)(`svg`,{className:`mfc-leaders`,id:`mfc-leaders`,viewBox:`0 0 100 18`,preserveAspectRatio:`none`,"aria-hidden":`true`}),(0,B.jsxs)(`div`,{className:`mfc-rangetrack`,id:`mfc-rangetrack`,ref:r,children:[(0,B.jsx)(`div`,{className:`mfc-zone safe`}),(0,B.jsx)(`div`,{className:`mfc-zone warn`}),(0,B.jsx)(`div`,{className:`mfc-zone over`}),(0,B.jsx)(`div`,{className:`mfc-rangeband`,id:`mfc-rangeband`,hidden:!0}),(0,B.jsx)(`div`,{className:`mfc-bound b90`,children:(0,B.jsx)(`div`,{className:`lbl`,children:`90%`})}),(0,B.jsx)(`div`,{className:`mfc-bound b100`,children:(0,B.jsx)(`div`,{className:`lbl`,children:`100%`})})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-rates`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#activity`})}),`Rates`]}),(0,B.jsxs)(`div`,{className:`mfc-kvgrid`,children:[(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`$ / 1%`}),(0,B.jsx)(`span`,{className:`v v-cyan`,id:`mfc-dpp`,children:F.usd3(d?.dollars_per_percent)})]}),(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`week done`}),(0,B.jsx)(`span`,{className:`v v-green`,id:`mfc-wkdone`,children:gc(f)})]}),(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`elapsed`}),(0,B.jsx)(`span`,{className:`v v-green`,id:`mfc-elapsed`,children:F.hours1(f?.elapsed_hours)})]}),(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`remaining`}),(0,B.jsx)(`span`,{className:`v`,id:`mfc-remain`,children:F.hours1(f?.remaining_hours)})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-bud`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#dollar`})}),`Daily budgets to stay under`]}),(0,B.jsxs)(`div`,{className:`mfc-kvgrid mfc-kvgrid-single`,children:[(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`@ 100% cap`}),(0,B.jsx)(`span`,{className:`v v-magenta`,id:`mfc-bud100`,children:F.usd2PerDay(e.budget_100_per_day_usd)})]}),(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`@ 90% cap`}),(0,B.jsx)(`span`,{className:`v v-amber`,id:`mfc-bud90`,children:F.usd2PerDay(e.budget_90_per_day_usd)})]})]})]})})}function xc(e){let t=Math.max(1,Math.round(e/4));return`${e} week${e===1?``:`s`} · ${t} month${t===1?``:`s`}`}function Sc(e){let t=e.findIndex(e=>e&&e.is_current);return t>=0?t:e.length-1}function Cc(e,t){let n=e.filter((e,n)=>n!==t).map(e=>e.dollar_per_pct).filter(e=>e!=null&&isFinite(e));if(n.length<4)return null;let r=n.slice(-4).sort((e,t)=>e-t);return(r[1]+r[2])/2}function wc(e){if(!e.length)return null;let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2?t[n]:(t[n-1]+t[n])/2}function Tc(e,t){let n=[];if(!e.length)return n;let r={left:44,right:14,top:12,bottom:22},i=600-r.left-r.right,a=140-r.top-r.bottom,o=e.length,s=e=>r.left+(o===1?i:e/(o-1)*i),c=e.map(e=>e.dollar_per_pct).filter(e=>e!=null&&isFinite(e)),l=c.length?Math.min(...c)*.96:0,u=c.length?Math.max(...c)*1.04:1;u-l<1e-6&&(l-=.01,u+=.01);let d=e=>r.top+a*(1-(e-l)/(u-l)),f=e.map(e=>e.used_pct).filter(e=>e!=null&&isFinite(e)),p=f.length?Math.min(...f)*.96:0,m=f.length?Math.max(...f)*1.04:100;m-p<1e-6&&(--p,m+=1);let h=e=>r.top+a*(1-(e-p)/(m-p));if(n.push({el:`line`,attrs:{class:`mtr-axis`,x1:r.left,y1:r.top+a,x2:600-r.right,y2:r.top+a},key:`axis`}),c.length){let e=wc(c);e!=null&&(n.push({el:`line`,attrs:{class:`mtr-hl`,x1:r.left,y1:d(e),x2:600-r.right,y2:d(e)},key:`med-line`}),n.push({el:`text`,attrs:{class:`mtr-medlabel`,x:r.left+2,y:d(e)-3},text:`median $`+e.toFixed(2),key:`med-label`}))}{let t=[];e.forEach((e,n)=>{e.used_pct!=null&&isFinite(e.used_pct)&&t.push(`${s(n)},${h(e.used_pct)}`)}),t.length>=2&&n.push({el:`polyline`,attrs:{class:`mtr-trendline-dim`,points:t.join(` `)},key:`poly-used`})}{let t=[];e.forEach((e,n)=>{e.dollar_per_pct!=null&&isFinite(e.dollar_per_pct)&&t.push(`${s(n)},${d(e.dollar_per_pct)}`)}),t.length>=2&&n.push({el:`polyline`,attrs:{class:`mtr-trendline`,points:t.join(` `)},key:`poly-dpp`})}e.forEach((e,r)=>{if(e.dollar_per_pct==null||!isFinite(e.dollar_per_pct))return;let i=r===t;n.push({el:`circle`,attrs:{class:`mtr-trenddot`+(i?` cur`:``),cx:s(r),cy:d(e.dollar_per_pct),r:i?5:3},key:`dot-${r}`})}),c.length&&(n.push({el:`text`,attrs:{class:`mtr-ylabel`,x:3,y:r.top+8},text:`$`+(u/1.04).toFixed(2),key:`ymax`}),n.push({el:`text`,attrs:{class:`mtr-ylabel`,x:3,y:r.top+a},text:`$`+(l/.96).toFixed(2),key:`ymin`}));let g=e[t];return g&&g.dollar_per_pct!=null&&isFinite(g.dollar_per_pct)&&n.push({el:`text`,attrs:{class:`mtr-curlabel`,x:Math.max(r.left+4,s(t)-22),y:Math.min(138,d(g.dollar_per_pct)+16)},text:`$`+g.dollar_per_pct.toFixed(2),key:`curlabel`}),n}function Ec(e,t){return t===0?`Now`+(e.label?` · `+e.label:``):`W−`+t+(e.label?` · `+e.label:``)}function Dc(e){return e==null||!isFinite(e)?{cls:`flat`,text:`—`}:e>5e-4?{cls:`up`,text:`+`+e.toFixed(2)}:e<-5e-4?{cls:`down`,text:e.toFixed(2)}:{cls:`flat`,text:`0.00`}}function Oc(e){return e==null||!isFinite(e)?{cls:`delta-flat`,iconHref:`/static/icons.svg#minus`,text:`—`}:e<-5e-4?{cls:`delta-down`,iconHref:`/static/icons.svg#trending-down`,text:`−$`+Math.abs(e).toFixed(3)}:e>5e-4?{cls:`delta-up`,iconHref:`/static/icons.svg#trending-up`,text:`+$`+e.toFixed(3)}:{cls:`delta-flat`,iconHref:`/static/icons.svg#minus`,text:`$0.000`}}function kc(){let e=V(),t=Ae(e),n=(0,B.jsx)(Vn,{panel:`trend`,panelLabel:`Trend`,triggerId:`trend-modal`,onClick:()=>z(He(`trend`,`trend-modal`))});if(!t.length)return(0,B.jsx)(cc,{title:`Trend — 12-week history`,accentClass:`accent-amber`,headerExtras:n,children:(0,B.jsx)(`section`,{className:`modal-trend`,children:(0,B.jsx)(`p`,{className:`empty-state`,id:`mtr-empty`,children:`No history data yet.`})})});let r=Sc(t),i=t[r],a=e?.trend?.history_median_dpp,o=a!=null&&isFinite(a)?a:Cc(t,r),s=Oc(i&&i.dollar_per_pct!=null&&o!=null?i.dollar_per_pct-o:null),c=Tc(t,r),l=t.some(e=>e.used_pct!=null&&isFinite(e.used_pct)),u=t.length;return(0,B.jsx)(cc,{title:`Trend — 12-week history`,accentClass:`accent-amber`,headerExtras:n,children:(0,B.jsxs)(`section`,{className:`modal-trend`,children:[(0,B.jsx)(`div`,{className:`m-chipstrip`,children:(0,B.jsx)(`span`,{className:`m-pill accent-amber`,id:`mtr-weeks-pill`,children:xc(u)})}),(0,B.jsxs)(`div`,{className:`m-hero cols-3`,children:[(0,B.jsxs)(`div`,{className:`m-kv kv-cur`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#dollar`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mtr-cur`,children:i&&i.dollar_per_pct!=null?`$`+i.dollar_per_pct.toFixed(3):`—`}),(0,B.jsx)(`div`,{className:`lbl`,children:`Current $ / 1%`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-med`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#minus`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mtr-med`,children:o==null?`—`:`$`+o.toFixed(3)}),(0,B.jsx)(`div`,{className:`lbl`,children:`4-week median`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-delta ${s.cls}`,id:`mtr-delta-kv`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:s.iconHref})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mtr-delta`,children:s.text}),(0,B.jsx)(`div`,{className:`lbl`,children:`vs median`})]})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-spark`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#trending-down`})}),`12-week history · $/1%`,(0,B.jsxs)(`span`,{className:`mtr-legend`+(l?``:` legend-no-used`),"aria-hidden":`true`,children:[(0,B.jsx)(`span`,{className:`sw sw-dpp`}),(0,B.jsx)(`span`,{className:`sw-lbl`,children:`$/1%`}),(0,B.jsx)(`span`,{className:`sw sw-used`}),(0,B.jsx)(`span`,{className:`sw-lbl`,children:`used %`})]})]}),(0,B.jsxs)(`div`,{className:`mtr-sparkhero`,children:[(0,B.jsx)(`svg`,{id:`mtr-svg`,viewBox:`0 0 600 140`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:c.map(e=>{let{el:t,attrs:n,text:r,key:i}=e,a={};for(let e in n)a[e===`class`?`className`:e]=n[e];return t===`line`?(0,B.jsx)(`line`,{...a},i):t===`polyline`?(0,B.jsx)(`polyline`,{...a},i):t===`circle`?(0,B.jsx)(`circle`,{...a},i):(0,B.jsx)(`text`,{...a,children:r},i)})}),(0,B.jsx)(`div`,{className:`mtr-sparkaxis`,id:`mtr-sparkaxis`,children:u>0?(0,B.jsxs)(_.Fragment,{children:[(0,B.jsxs)(`span`,{children:[`W−`,u-1]}),(0,B.jsxs)(`span`,{children:[`W−`,Math.floor((u-1)/2)]}),(0,B.jsx)(`span`,{children:`Now`})]}):null})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-tbl`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),`Weekly detail`]}),(0,B.jsxs)(`div`,{className:`mtr-tbl-head`,children:[(0,B.jsxs)(`span`,{className:`m-pill accent-purple`,id:`mtr-tbl-count`,children:[u,` weeks`]}),(0,B.jsx)(`span`,{className:`mtr-tbl-sub`,children:`current row highlighted · negative Δ = $/1% down vs prior week`})]}),(0,B.jsxs)(`table`,{className:`m-histable`,id:`mtr-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Week`}),(0,B.jsx)(`th`,{className:`num`,children:`Used %`}),(0,B.jsx)(`th`,{className:`num`,children:`$ / 1%`}),(0,B.jsx)(`th`,{className:`num`,children:`Δ $/1%`})]})}),(0,B.jsx)(`tbody`,{id:`mtr-rows`,children:t.map((e,t)=>{let n=Ec(e,u-1-t),r=e.used_pct==null?`—`:Math.round(e.used_pct)+`%`,i=e.dollar_per_pct==null?`—`:`$`+e.dollar_per_pct.toFixed(2),a=Dc(e.delta);return(0,B.jsxs)(`tr`,{className:e.is_current?`cur`:void 0,children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`span`,{className:`wlab`,children:n})}),(0,B.jsx)(`td`,{className:`num usedpct`,children:r}),(0,B.jsx)(`td`,{className:`num dpp`,children:i}),(0,B.jsx)(`td`,{className:`num delta ${a.cls}`,children:a.text})]},e.label+`|`+t)})})]})]})})}var Ac=class extends Error{status;constructor(e){super(`HTTP ${e}`),this.status=e,this.name=`HttpError`}};function jc(e){return e?.name===`AbortError`}async function Mc(e,t){let n=await fetch(e,t?{signal:t}:void 0);if(!n.ok)throw new Ac(n.status);return await n.json()}function Nc(e,t){let n=t?.revalidateOnTick??!0,[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(null),l=(0,_.useRef)(e),u=(0,_.useRef)(null),d=(0,_.useRef)(!1),f=(0,_.useRef)(!1),p=(0,_.useCallback)(async()=>{if(d.current){f.current=!0;return}let e=l.current;if(e){d.current=!0;try{let t=await Mc(`/api/conversation/${encodeURIComponent(e)}/outline`);if(l.current!==e)return;u.current=t,i(t),c(null),o(!1)}catch{if(l.current!==e)return;c(`Couldn't load the outline.`),o(!1)}finally{d.current=!1,f.current&&(f.current=!1,p())}}},[]);return(0,_.useEffect)(()=>{if(l.current=e,u.current=null,d.current=!1,f.current=!1,i(null),c(null),!e){o(!1);return}o(!0),p()},[e,p]),(0,_.useEffect)(()=>{n&&u.current&&p()},[V()?.generated_at??``,n]),{outline:r,loading:a,error:s}}var Pc=3;function Fc({sessionId:e}){let t=(0,_.useSyncExternalStore)(R,()=>dt(L())),{outline:n}=Nc(t?e:null),r=V(),i=(0,_.useMemo)(()=>we(r),[r?.display?.resolved_tz,r?.display?.offset_label]),[a,o]=(0,_.useState)(!1);if(!t||!n||!n.stats||!e)return null;let s=n.stats,c=s.cache_failures,l=c?.count??0,u=s.cache_saved_usd??0,d=c?.rebuilds??[],f=a?d:d.slice(0,Pc),p=e;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-rebuild`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#refresh`})}),`Cache rebuilds`]}),l===0?(0,B.jsx)(`div`,{className:`msess-rebuild-none`,id:`msess-rebuild-none`,children:`No cache rebuilds ✓`}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`msess-tok-grid msess-rebuild-tiles`,id:`msess-rebuild-tiles`,children:[(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Rebuilds`}),(0,B.jsx)(`div`,{className:`n`,children:l})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile rebuild-wasted`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Wasted`}),(0,B.jsx)(`div`,{className:`n`,children:F.usd2(c.est_wasted_usd)})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Re-created`}),(0,B.jsx)(`div`,{className:`n`,children:c.tokens_recreated.toLocaleString(`en-US`)})]})]}),(0,B.jsx)(`ul`,{className:`msess-rebuild-list`,id:`msess-rebuild-list`,children:f.map(e=>(0,B.jsx)(`li`,{className:`rebuild-row`,children:(0,B.jsxs)(`button`,{type:`button`,className:`rebuild-jump`,onClick:()=>z({type:`OPEN_CONVERSATION`,sessionId:p,jump:{session_id:p,uuid:e.uuid}}),children:[(0,B.jsx)(`span`,{className:`rb-cost`,children:F.usd2(e.est_wasted_usd)}),(0,B.jsxs)(`span`,{className:`rb-tok`,children:[e.tokens_recreated.toLocaleString(`en-US`),` tok`]}),(0,B.jsx)(`span`,{className:`rb-time`,children:e.ts?F.timeHHmm(e.ts,i,{noSuffix:!0}):``}),e.subagent_key?(0,B.jsx)(`span`,{className:`rb-sub`,children:`subagent`}):null,(0,B.jsx)(`span`,{className:`rb-go`,children:`→ Jump`})]})},e.uuid))}),d.length>Pc&&!a?(0,B.jsxs)(`button`,{type:`button`,className:`msess-rebuild-more`,onClick:()=>o(!0),children:[`+`,d.length-Pc,` more`]}):null]}),u>0?(0,B.jsxs)(`div`,{className:`msess-rebuild-saved`,id:`msess-rebuild-saved`,children:[`Cache saved this session `,F.usd2(u),` ✓`]}):null]})}var Ic=/(^|\/)(subagents\/|agent-)/;function Lc(){return(0,_.useSyncExternalStore)(R,()=>L().snapshot?.generated_at??``)}function Rc(){let e=(0,_.useSyncExternalStore)(R,()=>L().openSessionId),t=Lc(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(null),c=(0,_.useRef)(null),l=(0,_.useRef)(!1),u=(0,_.useRef)(null);return(0,_.useEffect)(()=>{u.current=e??L().snapshot?.sessions?.rows?.[0]?.session_id??null,l.current=!1},[e]),(0,_.useEffect)(()=>{let e=u.current;if(!e){a(!1),s(`No session available.`),r(null),c.current=null;return}let t=c.current!==e||n==null;c.current=e,t&&(a(!0),s(null),r(null));let i=new AbortController;return fetch(`/api/session/${encodeURIComponent(e)}`,{signal:i.signal}).then(async e=>{if(e.status===404){(t||l.current)&&(a(!1),s(`Session not found (the cache may have rolled forward).`),r(null)),l.current=!0;return}if(!e.ok)throw Error(`HTTP `+e.status);let n=await e.json();l.current=!1,r(n),s(null),a(!1)}).catch(e=>{e.name!==`AbortError`&&(l.current=!1,t&&(s(`Failed to load: `+e.message),a(!1)))}),()=>i.abort()},[e,t]),(0,B.jsx)(cc,{title:`Session detail`,accentClass:`accent-orange`,headerExtras:(0,B.jsx)(Vn,{panel:`sessions`,panelLabel:`Session`,triggerId:`session-modal`,onClick:()=>z(He(`sessions`,`session-modal`))}),children:(0,B.jsxs)(`section`,{className:`modal-sessions`,children:[i?(0,B.jsx)(`div`,{className:`modal-loading`,id:`msess-loading`,children:`Loading session detail…`}):null,o?(0,B.jsx)(`div`,{className:`modal-error`,id:`msess-error`,children:o}):null,!i&&!o&&n?(0,B.jsx)(zc,{detail:n}):null]})})}function zc({detail:e}){let t=Array.isArray(e.source_paths)?e.source_paths:[],n=[],r=[];t.forEach(e=>{Ic.test(e)?r.push(e):n.push(e)});let i=e.cost_total_usd??0,a=[[`Input`,e.input_tokens,null],[`Output`,e.output_tokens,null],[`Cache creation`,e.cache_creation_tokens,null],[`Cache read`,e.cache_read_tokens,null],[`Cache hit %`,e.cache_hit_pct,`cache-hit`]].filter(e=>e[1]!=null),o=!e.models||e.models.length===0,s=!e.cost_per_model||e.cost_per_model.length===0;return(0,B.jsxs)(`div`,{className:`modal-content`,id:`msess-content`,children:[(0,B.jsx)(`div`,{className:`m-chipstrip`,children:(0,B.jsx)(`span`,{className:`msess-badge`,id:`msess-id`,"aria-label":`Session ID`,children:e.session_id??`—`})}),(0,B.jsxs)(`div`,{className:`m-hero cols-3`,children:[(0,B.jsxs)(`div`,{className:`m-kv kv-cost`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#dollar`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`msess-cost`,children:e.cost_total_usd==null?`—`:`$`+e.cost_total_usd.toFixed(2)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Total cost`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-dur`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#clock`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`msess-dur`,children:e.duration_min==null?`—`:e.duration_min+` min`}),(0,B.jsx)(`div`,{className:`lbl`,children:`Duration`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-proj`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#folder`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`msess-project`,title:e.project_path??``,"aria-label":`Project`,children:e.project_label??e.project_path??`—`}),(0,B.jsx)(`div`,{className:`lbl`,children:`Project`})]})]})]}),(0,B.jsxs)(`div`,{className:`msess-ts`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#calendar`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`started`}),(0,B.jsx)(`span`,{className:`v`,id:`msess-started`,children:e.started_utc??`—`})]}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`last activity`}),(0,B.jsx)(`span`,{className:`v`,id:`msess-last`,children:e.last_activity_utc??`—`})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-tok`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),`Tokens`]}),(0,B.jsx)(`div`,{className:`msess-tok-grid`,id:`msess-tokens`,children:a.map(([e,t,n])=>(0,B.jsxs)(`div`,{className:`msess-tok-tile`+(n?` `+n:``),children:[(0,B.jsx)(`div`,{className:`lbl`,children:e}),(0,B.jsx)(`div`,{className:`n`,children:n===`cache-hit`?t.toFixed(1)+`%`:t.toLocaleString(`en-US`)}),n===`cache-hit`?(0,B.jsx)(`div`,{className:`bar`,children:(0,B.jsx)(`div`,{className:`fill`,style:{width:Math.max(0,Math.min(t,100))+`%`}})}):null]},e))}),(0,B.jsx)(Fc,{sessionId:e.session_id??null},e.session_id??`no-session`),o?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-mod`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#sparkles`})}),`Models`]}),(0,B.jsx)(`div`,{className:`m-chipstrip`,id:`msess-models`,children:(e.models||[]).map(e=>(0,B.jsx)(`span`,{className:`chip `+or(e.name),children:e.name},e.name))})]}),s?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-costm`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#pie-chart`})}),`Cost by model`]}),(0,B.jsxs)(`div`,{className:`msess-costm`,children:[(0,B.jsx)(`div`,{className:`bar`,id:`msess-cost-bar`,children:(e.cost_per_model||[]).map(e=>{let t=i>0&&e.cost_usd!=null?e.cost_usd/i*100:0;return(0,B.jsx)(`div`,{className:`seg `+or(e.model),style:{width:t+`%`}},e.model)})}),(0,B.jsx)(`div`,{className:`legend`,id:`msess-cost-legend`,children:(e.cost_per_model||[]).map(e=>{let t=i>0&&e.cost_usd!=null?e.cost_usd/i*100:0;return(0,B.jsxs)(`div`,{className:`lg`,children:[(0,B.jsx)(`span`,{className:`sw `+or(e.model)}),(0,B.jsx)(`span`,{className:`name`,children:e.model}),(0,B.jsx)(`span`,{className:`v`,children:e.cost_usd==null?`—`:`$`+e.cost_usd.toFixed(3)}),(0,B.jsxs)(`span`,{className:`pct`,children:[Math.round(t),`%`]})]},e.model)})})]})]}),t.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-src`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#file-text`})}),`Source files`]}),(0,B.jsxs)(`div`,{className:`msess-src`,id:`msess-src`,children:[(0,B.jsxs)(`div`,{className:`src-head`,children:[(0,B.jsxs)(`span`,{className:`count-pill`,children:[t.length,` file`,t.length===1?``:`s`]}),(0,B.jsxs)(`span`,{className:`sub`,children:[n.length,` primary`,r.length>0?(0,B.jsxs)(B.Fragment,{children:[` `,(0,B.jsx)(`span`,{className:`dot`,children:`·`}),` `,(0,B.jsxs)(`span`,{className:`subcount`,children:[r.length,` subagent`,r.length===1?``:`s`]})]}):null]})]}),n.length>0?n.map(e=>(0,B.jsx)(`div`,{className:`primary-path`,children:e},e)):r.length>0?(0,B.jsxs)(`div`,{className:`src-empty-primary`,children:[`No primary path resolved · `,r.length,` subagent path`,r.length===1?``:`s`,` below`]}):null,r.length>0?(0,B.jsxs)(`details`,{className:`subagents`,open:n.length===0,children:[(0,B.jsxs)(`summary`,{children:[`Show `,r.length,` subagent path`,r.length===1?``:`s`]}),(0,B.jsx)(`ul`,{className:`paths`,children:r.map(e=>(0,B.jsx)(`li`,{children:e},e))})]}):null]})]}):null]})}function Bc({row:e,variant:t,accentClass:n}){let r=Rn(),i={tz:r.resolvedTz,offsetLabel:r.offsetLabel},a=(e,t)=>`${F.datetimeShort(e,i)} → ${F.datetimeShort(t,i)}`,o=e.delta_cost_pct==null?`flat`:e.delta_cost_pct>0?`up`:e.delta_cost_pct<0?`down`:`flat`,s=t===`weekly`?`week`:t===`monthly`?`month`:`day`,c=t===`daily`?`Today`:`Now`;return(0,B.jsxs)(`div`,{className:`detail-card ${n}`,children:[(0,B.jsxs)(`div`,{className:`head`,children:[(0,B.jsxs)(`div`,{className:`big`,children:[e.label,e.is_current&&(0,B.jsx)(`span`,{className:`pill-current`,children:c})]}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`span`,{className:`cost`,style:{color:`var(--text)`,fontWeight:700},children:F.usd2(e.cost_usd)}),` `,e.delta_cost_pct==null?(0,B.jsx)(`span`,{className:`delta flat`,children:`—`}):(0,B.jsxs)(`span`,{className:`delta ${o}`,children:[F.deltaPct(e.delta_cost_pct),` vs prior `,s]})]})]}),t===`weekly`&&e.week_start_at&&e.week_end_at&&(0,B.jsxs)(`div`,{className:`window`,children:[`Subscription window: `,a(e.week_start_at,e.week_end_at)]}),(0,B.jsx)(`div`,{className:`model-stack`,role:`presentation`,children:e.models.map(e=>(0,B.jsx)(`span`,{className:e.chip,style:{width:`${e.cost_pct}%`}},e.model))}),(0,B.jsx)(`div`,{className:`chips`,children:e.models.map(e=>(0,B.jsxs)(`span`,{className:`chip ${e.chip}`,children:[e.display,` `,Math.round(e.cost_pct),`% · `,F.usd2(e.cost_usd)]},e.model))}),(0,B.jsxs)(`div`,{className:`tokens-row`,children:[(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Input`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.input_tokens)})]}),(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Output`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.output_tokens)})]}),(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Cache+`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.cache_creation_tokens)})]}),(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Cache-read`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.cache_read_tokens)})]}),(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Total`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.total_tokens)})]}),e.cache_hit_pct!=null&&(0,B.jsxs)(`div`,{className:`t cache`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Cache hit`}),(0,B.jsxs)(`span`,{className:`v`,children:[e.cache_hit_pct.toFixed(1),`%`]}),(0,B.jsx)(`div`,{className:`bar`,children:(0,B.jsx)(`div`,{className:`fill`,style:{width:`${Math.min(100,Math.max(0,e.cache_hit_pct))}%`}})})]})]}),t===`weekly`&&(0,B.jsxs)(`div`,{className:`stats2`,children:[(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Used %`}),(0,B.jsx)(`span`,{className:`v`,children:F.pct0(e.used_pct)})]}),(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`$/1%`}),(0,B.jsx)(`span`,{className:`v`,children:F.usd2(e.dollar_per_pct)})]})]})]})}function Vc(e){return e==null||e===0?`num`:e>0?`num delta-up`:`num delta-down`}function Hc(e){let t=new Set,n=[];for(let r of e.models)t.has(r.chip)||(t.add(r.chip),n.push(r.chip));return n}function Uc({row:e}){let t=Hc(e),n=t.slice(0,3),r=t.length>3?t.length-3:0;return(0,B.jsxs)(`span`,{className:`models-chips`,children:[n.map(e=>(0,B.jsx)(`span`,{className:`chip ${e}`,children:e},e)),r>0&&(0,B.jsxs)(`span`,{className:`models-chips-more`,children:[`…+`,r]})]})}function Wc({rows:e,variant:t,accentClass:n,selectedIndex:r,onSelect:i}){return(0,B.jsxs)(`table`,{className:`history-table history-table--${t} ${n}`,role:`grid`,"aria-rowcount":e.length,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:t===`weekly`?`Week`:`Month`}),(0,B.jsx)(`th`,{children:`Models`}),(0,B.jsx)(`th`,{className:`num`,children:`Cost (USD)`}),t===`weekly`&&(0,B.jsx)(`th`,{className:`num`,children:`Used %`}),t===`weekly`&&(0,B.jsx)(`th`,{className:`num`,children:`$/1%`}),(0,B.jsx)(`th`,{className:`num`,children:`Δ`})]})}),(0,B.jsx)(`tbody`,{children:e.map((e,n)=>(0,B.jsxs)(`tr`,{className:n===r?`selected`:void 0,"aria-rowindex":n+1,"aria-selected":n===r,onClick:()=>i(n),children:[(0,B.jsxs)(`td`,{children:[e.label,n===r?` ▶`:``]}),(0,B.jsx)(`td`,{children:(0,B.jsx)(Uc,{row:e})}),(0,B.jsx)(`td`,{className:`num`,children:F.usd2(e.cost_usd)}),t===`weekly`&&(0,B.jsx)(`td`,{className:`num`,children:F.pct0(e.used_pct)}),t===`weekly`&&(0,B.jsx)(`td`,{className:`num`,children:F.usd2(e.dollar_per_pct)}),(0,B.jsx)(`td`,{className:Vc(e.delta_cost_pct),children:F.deltaPct(e.delta_cost_pct)})]},e.label))})]})}function Gc(){let e=V()?.weekly?.rows??[],[t,n]=(0,_.useState)(0),r=e.length;(0,_.useEffect)(()=>En([{key:`ArrowDown`,scope:`modal`,when:()=>L().openModal===`weekly`,action:()=>n(e=>Math.min(e+1,Math.max(0,r-1)))},{key:`ArrowUp`,scope:`modal`,when:()=>L().openModal===`weekly`,action:()=>n(e=>Math.max(e-1,0))}]),[r]);let i=(0,B.jsx)(Vn,{panel:`weekly`,panelLabel:`Weekly`,triggerId:`weekly-modal`,onClick:()=>z(He(`weekly`,`weekly-modal`))});if(r===0)return(0,B.jsx)(cc,{title:`Weekly history · last 12`,accentClass:`accent-cyan`,headerExtras:i,children:(0,B.jsx)(`div`,{className:`panel-empty`,children:`No usage history yet.`})});let a=e[Math.min(t,r-1)];return(0,B.jsxs)(cc,{title:`Weekly history · last 12`,accentClass:`accent-cyan`,headerExtras:i,children:[(0,B.jsx)(Bc,{row:a,variant:`weekly`,accentClass:`accent-cyan`}),(0,B.jsx)(Wc,{rows:e,variant:`weekly`,accentClass:`accent-cyan`,selectedIndex:t,onSelect:n})]})}function Kc(){let e=V()?.monthly?.rows??[],[t,n]=(0,_.useState)(0),r=e.length;(0,_.useEffect)(()=>En([{key:`ArrowDown`,scope:`modal`,when:()=>L().openModal===`monthly`,action:()=>n(e=>Math.min(e+1,Math.max(0,r-1)))},{key:`ArrowUp`,scope:`modal`,when:()=>L().openModal===`monthly`,action:()=>n(e=>Math.max(e-1,0))}]),[r]);let i=(0,B.jsx)(Vn,{panel:`monthly`,panelLabel:`Monthly`,triggerId:`monthly-modal`,onClick:()=>z(He(`monthly`,`monthly-modal`))});if(r===0)return(0,B.jsx)(cc,{title:`Monthly history · last 12`,accentClass:`accent-pink`,headerExtras:i,children:(0,B.jsx)(`div`,{className:`panel-empty`,children:`No usage history yet.`})});let a=e[Math.min(t,r-1)];return(0,B.jsxs)(cc,{title:`Monthly history · last 12`,accentClass:`accent-pink`,headerExtras:i,children:[(0,B.jsx)(Bc,{row:a,variant:`monthly`,accentClass:`accent-pink`}),(0,B.jsx)(Wc,{rows:e,variant:`monthly`,accentClass:`accent-pink`,selectedIndex:t,onSelect:n})]})}var qc=720,Jc=180,Yc={left:46,right:20,top:18,bottom:20};function Xc(e){return e===0?`$0`:e<10?`$`+e.toFixed(2):`$`+Math.round(e).toString()}function Zc(){return(0,_.useSyncExternalStore)(R,()=>L().snapshot?.generated_at??``)}function Qc({detail:e}){let t=Zc(),n=Rn(),r={tz:n.resolvedTz,offsetLabel:n.offsetLabel},i=Date.parse(e.start_at),a=Date.parse(e.end_at)-i||1,o=e=>Yc.left+(Date.parse(e)-i)/a*(qc-Yc.left-Yc.right),s=Math.max(e.cost_usd,e.projection?.total_cost_usd??0),c=e=>{let t=Yc.top,n=Jc-Yc.bottom;return s<=0?n:n-e/s*(n-t)},l=[];for(let e=0;e<=5;e++)l.push(new Date(i+e*36e5).toISOString());let u=e.samples.length>0?e.samples[e.samples.length-1].cum:0,d=e.is_active?t||new Date().toISOString():null,f=[];if(e.samples.length>0){f.push([o(e.start_at),c(0)]);for(let t of e.samples)f.push([o(t.t),c(t.cum)]);d&&f.push([o(d),c(u)])}let p=f.map(([e,t])=>`${e.toFixed(1)},${t.toFixed(1)}`).join(` `),m=f.length>0?`M ${p.replace(/ /g,` L `)} L ${f[f.length-1][0].toFixed(1)},${c(0).toFixed(1)} Z`:``,h=s<=0?[0]:[0,s/2,s];return(0,B.jsx)(`div`,{className:`mblock-timeline`,children:(0,B.jsxs)(`svg`,{viewBox:`0 0 ${qc} ${Jc}`,style:{width:`100%`,height:`auto`},role:`img`,"aria-label":`Cumulative cost over the 5-hour block window`,children:[h.map(e=>(0,B.jsx)(`text`,{x:8,y:c(e)+4,fill:`var(--text-dim)`,fontSize:10,children:Xc(e)},e)),(0,B.jsx)(`line`,{x1:Yc.left,y1:Yc.top,x2:Yc.left,y2:Jc-Yc.bottom,stroke:`var(--border-soft)`,strokeWidth:.8}),(0,B.jsx)(`line`,{x1:Yc.left,y1:Jc-Yc.bottom,x2:qc-Yc.right,y2:Jc-Yc.bottom,stroke:`var(--border-soft)`,strokeWidth:.8}),l.slice(1,-1).map(e=>(0,B.jsx)(`line`,{x1:o(e),y1:Yc.top,x2:o(e),y2:Jc-Yc.bottom,stroke:`var(--border-soft)`,strokeDasharray:`2 3`,strokeWidth:.5},e)),l.map(e=>(0,B.jsx)(`text`,{x:o(e)-14,y:Jc-5,fill:`var(--text-dim)`,fontSize:9,children:F.timeHHmm(e,r,{noSuffix:!0})},e)),f.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`path`,{d:m,fill:`var(--accent-green)`,opacity:.12}),(0,B.jsx)(`polyline`,{points:p,fill:`none`,stroke:`var(--accent-green)`,strokeWidth:2}),(0,B.jsx)(`circle`,{cx:f[f.length-1][0],cy:f[f.length-1][1],r:3,fill:`var(--accent-green)`})]}):(0,B.jsx)(`text`,{x:qc/2,y:Jc/2,fill:`var(--text-faint)`,fontSize:11,textAnchor:`middle`,children:`No spend recorded yet in this block.`}),e.is_active&&e.projection&&d&&f.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`polyline`,{points:`${o(d).toFixed(1)},${c(u).toFixed(1)} ${o(e.end_at).toFixed(1)},${c(e.projection.total_cost_usd).toFixed(1)}`,fill:`none`,stroke:`var(--accent-amber)`,strokeWidth:1.5,strokeDasharray:`5 4`,opacity:.85}),(0,B.jsx)(`circle`,{cx:o(e.end_at),cy:c(e.projection.total_cost_usd),r:3,fill:`var(--accent-amber)`,opacity:.85}),(0,B.jsxs)(`text`,{x:o(e.end_at)-50,y:c(e.projection.total_cost_usd)-6,fill:`var(--accent-amber)`,fontSize:9,children:[`proj $`,e.projection.total_cost_usd.toFixed(2)]}),(0,B.jsx)(`line`,{x1:o(d),y1:Yc.top,x2:o(d),y2:Jc-Yc.bottom,stroke:`var(--accent-amber)`,strokeWidth:1.2}),(0,B.jsx)(`text`,{x:o(d)+4,y:Yc.top+10,fill:`var(--accent-amber)`,fontSize:9,children:`now`})]}):null]})})}function $c(){return(0,_.useSyncExternalStore)(R,()=>L().snapshot?.generated_at??``)}function el(e,t){let n=Date.parse(e.start_at),r=e.is_active?Date.parse(t)||Date.now():e.actual_end_at?Date.parse(e.actual_end_at):Date.parse(e.end_at),i=Math.max(0,Math.floor((r-n)/6e4)),a=Math.floor(i/60),o=i%60;return`${a}h ${String(o).padStart(2,`0`)}m`}function tl(e,t,n){return`${F.timeHHmm(e,n)} → ${F.timeHHmm(t,n)}`}function nl(){let e=(0,_.useSyncExternalStore)(R,()=>L().openBlockStartAt),t=$c(),n=Rn(),r={tz:n.resolvedTz,offsetLabel:n.offsetLabel},[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!0),[c,l]=(0,_.useState)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(!1),f=(0,_.useRef)(null);return(0,_.useEffect)(()=>{f.current=e??null,d.current=!1},[e]),(0,_.useEffect)(()=>{let e=f.current;if(!e){s(!1),l(`No block bound.`),a(null),u.current=null;return}let t=u.current!==e||i==null;u.current=e,t&&(s(!0),l(null),a(null));let n=new AbortController;return fetch(`/api/block/${encodeURIComponent(e)}`,{signal:n.signal}).then(async e=>{if(e.status===404){(t||d.current)&&(s(!1),l(`Block not found (the cache may have rolled forward).`),a(null)),d.current=!0;return}if(!e.ok)throw Error(`HTTP `+e.status);let n=await e.json();d.current=!1,a(n),l(null),s(!1)}).catch(e=>{e.name!==`AbortError`&&(d.current=!1,t&&(l(`Failed to load: `+e.message),s(!1)))}),()=>n.abort()},[e,t]),(0,B.jsx)(cc,{title:i?`${i.anchor===`heuristic`?`~ `:``}Block · ${i.label}`:`Block`,accentClass:`accent-blue`,headerExtras:(0,B.jsx)(Vn,{panel:`blocks`,panelLabel:`5-hour block`,triggerId:`block-modal`,onClick:()=>z(He(`blocks`,`block-modal`))}),children:(0,B.jsxs)(`section`,{className:`modal-block`,children:[o?(0,B.jsx)(`div`,{className:`modal-loading`,children:`Loading block detail…`}):null,c?(0,B.jsx)(`div`,{className:`modal-error`,children:c}):null,!o&&!c&&i?(0,B.jsx)(rl,{detail:i,generatedAt:t,ctx:r}):null]})})}function rl({detail:e,generatedAt:t,ctx:n}){let r=e.cost_usd??0;return(0,B.jsxs)(`div`,{className:`modal-content`,children:[(0,B.jsxs)(`div`,{className:`m-chipstrip`,children:[e.is_active?(0,B.jsx)(`span`,{className:`m-pill accent-green`,children:`● Active`}):null,e.anchor===`heuristic`?(0,B.jsx)(`span`,{className:`m-pill accent-amber`,children:`~ heuristic anchor`}):null,(0,B.jsx)(`span`,{className:`m-pill accent-blue`,children:tl(e.start_at,e.end_at,n)}),(0,B.jsxs)(`span`,{className:`m-pill`,children:[e.entries_count.toLocaleString(`en-US`),` `,e.entries_count===1?`entry`:`entries`]})]}),(0,B.jsxs)(`div`,{className:`m-hero `+(e.is_active?`cols-4`:`cols-3`),children:[(0,B.jsxs)(`div`,{className:`m-kv kv-cost`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#dollar`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,children:F.usd2(e.cost_usd)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Total cost`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-dur`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#clock`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,children:el(e,t)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Elapsed`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,children:e.total_tokens.toLocaleString(`en-US`)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Total tokens`})]})]}),e.is_active?(0,B.jsxs)(`div`,{className:`m-kv kv-proj`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#crystal-ball`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,children:e.projection?F.usd2(e.projection.total_cost_usd):`—`}),(0,B.jsxs)(`div`,{className:`lbl`,children:[`Projected`,e.projection?` · ${e.projection.remaining_minutes}m left`:``]})]})]}):null]}),(0,B.jsx)(Qc,{detail:e}),(0,B.jsxs)(`h3`,{className:`m-sec sec-tok`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),`Tokens`]}),(0,B.jsxs)(`div`,{className:`msess-tok-grid mblock-tok-grid`,children:[(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Input`}),(0,B.jsx)(`div`,{className:`n`,children:e.input_tokens.toLocaleString(`en-US`)})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Output`}),(0,B.jsx)(`div`,{className:`n`,children:e.output_tokens.toLocaleString(`en-US`)})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Cache create`}),(0,B.jsx)(`div`,{className:`n`,children:e.cache_creation_tokens.toLocaleString(`en-US`)})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Cache read`}),(0,B.jsx)(`div`,{className:`n`,children:e.cache_read_tokens.toLocaleString(`en-US`)})]}),e.cache_hit_pct==null?null:(0,B.jsxs)(`div`,{className:`msess-tok-tile cache-hit`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Cache hit %`}),(0,B.jsxs)(`div`,{className:`n`,children:[e.cache_hit_pct.toFixed(1),`%`]}),(0,B.jsx)(`div`,{className:`bar`,children:(0,B.jsx)(`div`,{className:`fill`,style:{width:Math.min(100,Math.max(0,e.cache_hit_pct))+`%`}})})]})]}),e.models.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-costm`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#pie-chart`})}),`Cost by model`]}),(0,B.jsxs)(`div`,{className:`msess-costm`,children:[(0,B.jsx)(`div`,{className:`bar`,children:e.models.map(e=>{let t=r>0?e.cost_usd/r*100:0;return(0,B.jsx)(`div`,{className:`seg `+or(e.model),style:{width:t+`%`}},e.model)})}),(0,B.jsx)(`div`,{className:`legend`,children:e.models.map(e=>{let t=r>0?e.cost_usd/r*100:0;return(0,B.jsxs)(`div`,{className:`lg`,children:[(0,B.jsx)(`span`,{className:`sw `+or(e.model)}),(0,B.jsx)(`span`,{className:`name`,children:e.display}),(0,B.jsxs)(`span`,{className:`v`,children:[`$`,e.cost_usd.toFixed(2)]}),(0,B.jsxs)(`span`,{className:`pct`,children:[Math.round(t),`%`]})]},e.model)})})]})]}):null,e.is_active&&e.burn_rate&&e.projection?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-burn`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#crystal-ball`})}),`Burn rate & projection`]}),(0,B.jsxs)(`div`,{className:`mblock-burn`,children:[(0,B.jsxs)(`div`,{className:`row`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Burn rate`}),(0,B.jsx)(`span`,{className:`v amber`,children:F.usd2(e.burn_rate.cost_per_hour)}),(0,B.jsx)(`span`,{className:`dim`,children:`/ hr`}),(0,B.jsx)(`span`,{className:`sep`,children:`·`}),(0,B.jsx)(`span`,{className:`v cyan`,children:Math.round(e.burn_rate.tokens_per_minute).toLocaleString(`en-US`)}),(0,B.jsx)(`span`,{className:`dim`,children:`tok / min`})]}),(0,B.jsxs)(`div`,{className:`row`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Projection`}),(0,B.jsx)(`span`,{className:`v amber`,children:F.usd2(e.projection.total_cost_usd)}),(0,B.jsx)(`span`,{className:`dim`,children:`total`}),(0,B.jsx)(`span`,{className:`sep`,children:`·`}),(0,B.jsx)(`span`,{className:`v cyan`,children:e.projection.total_tokens.toLocaleString(`en-US`)}),(0,B.jsx)(`span`,{className:`dim`,children:`tok`}),(0,B.jsx)(`span`,{className:`sep`,children:`·`}),(0,B.jsxs)(`span`,{className:`v`,children:[e.projection.remaining_minutes,` min`]}),(0,B.jsx)(`span`,{className:`dim`,children:`remaining`})]})]})]}):null]})}function il(e,t,n){if(!t)return null;let r=e.findIndex(e=>e.date===t);return r<0?null:n===`older`?r>=e.length-1?null:e[r+1].date:r<=0?null:e[r-1].date}function al({rows:e,selectedDate:t,onSelect:n}){let r=[...e].reverse(),i=r.reduce((e,t)=>Math.max(e,t.cost_usd),0),a=r.length>0?ol(r[0].date):``,o=r.length>0?ol(r[r.length-1].date):``,s=r.find(e=>e.is_today),c=s?`${ol(s.date)} · today`:``;return(0,B.jsxs)(`section`,{className:`daily-modal-bars`,"aria-label":`30-day cost`,children:[(0,B.jsxs)(`div`,{className:`daily-modal-bars-head`,children:[(0,B.jsxs)(`span`,{className:`daily-bars-nav`,children:[(0,B.jsx)(`button`,{type:`button`,className:`daily-step-btn`,"aria-label":`Step to older day`,disabled:il(e,t,`older`)===null,onClick:()=>{let r=il(e,t,`older`);r&&n(r)},children:`‹`}),(0,B.jsxs)(`span`,{children:[`30-day cost · selected: `,t?ol(t):`—`]}),(0,B.jsx)(`button`,{type:`button`,className:`daily-step-btn`,"aria-label":`Step to newer day`,disabled:il(e,t,`newer`)===null,onClick:()=>{let r=il(e,t,`newer`);r&&n(r)},children:`›`})]}),(0,B.jsx)(`span`,{className:`hint hint-desktop`,children:`↑↓ navigate · click any bar`}),(0,B.jsx)(`span`,{className:`hint hint-mobile`,children:`‹ › to step · tap a bar`})]}),(0,B.jsx)(`div`,{className:`daily-modal-bars-grid`,role:`img`,"aria-label":`30-day cost histogram`,children:r.map(e=>{let r=e.cost_usd<=0,a=e.date===t,o=r?4:i>0?e.cost_usd/i*100:0,s=[`bar`,r?`zero`:``,a?`sel`:``,e.is_today?`today`:``].filter(Boolean).join(` `);return(0,B.jsx)(`button`,{"data-date":e.date,className:s,style:{height:`${o}%`},disabled:r,"aria-pressed":a,"aria-label":`${e.label} cost ${e.cost_usd>0?F.usd2(e.cost_usd):`no usage`}`,title:e.cost_usd>0?`${e.label} · ${F.usd2(e.cost_usd)}`:`${e.label} · —`,onClick:()=>{r||n(e.date)}},e.date)})}),r.length>0&&(0,B.jsxs)(`div`,{className:`daily-modal-bars-axis`,children:[(0,B.jsx)(`span`,{children:a}),c&&(0,B.jsx)(`span`,{children:c}),(0,B.jsx)(`span`,{children:o})]})]})}function ol(e){let t=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],n=e.split(`-`).map(Number);return`${t[n[1]-1]} ${n[2]}`}function sl(){let e=V()?.daily?.rows??[],t=(0,_.useSyncExternalStore)(R,()=>L().openDailyDate),[n,r]=(0,_.useState)(null);(0,_.useEffect)(()=>{t&&r(t)},[]);let i=new Set(e.map(e=>e.date)),a=e[0]?.date??null,o=n&&i.has(n)?n:a;(0,_.useEffect)(()=>En([{key:`ArrowDown`,scope:`modal`,when:()=>L().openModal===`daily`,action:()=>{let t=il(e,o,`older`);t&&r(t)}},{key:`ArrowUp`,scope:`modal`,when:()=>L().openModal===`daily`,action:()=>{let t=il(e,o,`newer`);t&&r(t)}}]),[e,o]);let s=(0,B.jsx)(Vn,{panel:`daily`,panelLabel:`Daily`,triggerId:`daily-modal`,onClick:()=>z(He(`daily`,`daily-modal`))});if(e.length===0)return(0,B.jsx)(cc,{title:`Daily history · last 30`,accentClass:`accent-indigo`,headerExtras:s,children:(0,B.jsx)(`div`,{className:`panel-empty`,children:`No usage history yet.`})});let c=e.findIndex(e=>e.date===o),l=c>=0?c:0,u=e[l],d=e[l+1],f=cl(u,d);return(0,B.jsxs)(cc,{title:`Daily history · last 30`,accentClass:`accent-indigo`,headerExtras:s,children:[(0,B.jsx)(al,{rows:e,selectedDate:o,onSelect:r}),(0,B.jsx)(Bc,{row:f,variant:`daily`,accentClass:`accent-indigo`})]})}function cl(e,t){let n=t&&t.cost_usd>0?(e.cost_usd-t.cost_usd)/t.cost_usd:null;return{label:e.label,cost_usd:e.cost_usd,total_tokens:e.total_tokens,input_tokens:e.input_tokens,output_tokens:e.output_tokens,cache_creation_tokens:e.cache_creation_tokens,cache_read_tokens:e.cache_read_tokens,used_pct:null,dollar_per_pct:null,delta_cost_pct:n,is_current:e.is_today,models:e.models,cache_hit_pct:e.cache_hit_pct}}var ll=[`#d946ef`,`#c084fc`,`#60a5fa`,`#fbbf24`,`#22d3ee`],ul=`#64748b`,dl=5,fl=400,pl=150;function ml({trend:e,yMode:t,windowWeeks:n,onProjectSelect:r}){let i=(0,_.useMemo)(()=>{let t=Math.max(0,Math.min(n,e.window_weeks)),r=e.weeks.slice(-t),i=e.projects.map(e=>{let n=e.weekly_cost.slice(-t),r=n.reduce((e,t)=>e+t,0);return{key:e.key,weekly:n,cost:r,color:``}}).sort((e,t)=>t.cost-e.cost),a=i.slice(0,dl).map((e,t)=>({...e,color:ll[t]??ul})),o=i.slice(dl),s=r.map((e,t)=>o.reduce((e,n)=>e+(n.weekly[t]??0),0)),c=s.reduce((e,t)=>e+t,0),l=[...a];return o.length>0&&c>0&&l.push({key:`(other)`,weekly:s,cost:c,color:ul}),{weeks:r,series:l}},[e,n]),a=rr();if(i.weeks.length===0||i.series.length===0)return(0,B.jsxs)(`div`,{className:`panel-empty`,children:[`No project activity in the last `,n,` week`,n===1?``:`s`,`.`]});let o=i.weeks.length,s=i.weeks.map((e,t)=>i.series.reduce((e,n)=>e+(n.weekly[t]??0),0)),c=t===`share`?100:Math.max(...s,.01),l=(e,t=`left`)=>o<=1?t===`left`?fl*.1:fl*.9:e/(o-1)*fl,u=Array(o).fill(0),d=i.series.map(e=>{let n=[];for(let e=0;e<o;e++){let t=pl-u[e]/c*pl;n.push(`${l(e,`left`).toFixed(2)},${t.toFixed(2)}`),o===1&&n.push(`${l(e,`right`).toFixed(2)},${t.toFixed(2)}`)}for(let r=o-1;r>=0;r--){let i=s[r]??0,a=t===`share`?i>0?(e.weekly[r]??0)/i*100:0:e.weekly[r]??0;u[r]+=a;let d=pl-u[r]/c*pl;o===1&&n.push(`${l(r,`right`).toFixed(2)},${d.toFixed(2)}`),n.push(`${l(r,`left`).toFixed(2)},${d.toFixed(2)}`)}return{color:e.color,key:e.key,points:n.join(` `)}}),f=i.weeks.map(e=>(0,B.jsx)(`span`,{children:e.week_label},e.week_start_date));return(0,B.jsxs)(`div`,{className:`projects-trend`,children:[(0,B.jsx)(`svg`,{viewBox:`0 0 ${fl} ${pl}`,preserveAspectRatio:`none`,role:`img`,"aria-label":`Stacked area: project ${t===`share`?`share %`:`cost`} over ${o} weeks`,children:d.map(e=>{let t=e.key===`(other)`;return(0,B.jsx)(`polygon`,{fill:e.color,opacity:t?.5:.65,points:e.points,"data-series-key":e.key,onClick:()=>{t||r?.(e.key)},style:{cursor:t?`default`:`pointer`}},e.key)})}),(0,B.jsx)(`div`,{className:`projects-trend-xaxis`,children:f}),(0,B.jsx)(`div`,{className:`projects-trend-legend`,children:i.series.map(e=>{let t=e.key===`(other)`,n=(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`sw`,style:{background:e.color}}),e.key]});return a&&!t?(0,B.jsx)(`button`,{type:`button`,className:`projects-trend-legend-item`,"data-series-key":e.key,onClick:()=>r?.(e.key),children:n},e.key):(0,B.jsx)(`span`,{className:`projects-trend-legend-item`,"data-series-key":e.key,children:n},e.key)})})]})}function hl(e,t){let[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),c=V()?.generated_at??``,l=(0,_.useRef)(0),u=(0,_.useRef)(null),d=(0,_.useRef)(null),f=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{if(!e){r(null),a(!1),s(null),l.current=0,u.current=null,d.current=null,f.current=!1;return}let i=u.current!==e||d.current!==t,o=i||n==null;if(o&&f.current&&!i)return;o&&(a(!0),s(null)),i&&(l.current=0),u.current=e,d.current=t,f.current=!0;let c=new AbortController,p=`/api/project/${encodeURIComponent(e)}?weeks=${t}`;return fetch(p,{signal:c.signal}).then(async e=>{if(e.status===404){l.current+=1,l.current>=2?(r(null),s(`Project no longer in cache — close this drill.`),a(!1)):o&&(s(`Couldn't load project detail — will retry on next tick.`),a(!1));return}if(!e.ok){o&&(s(`Couldn't load project detail — will retry on next tick.`),a(!1));return}l.current=0,r(await e.json()),s(null),a(!1)}).catch(e=>{e?.name!==`AbortError`&&o&&(s(`Couldn't load project detail — will retry on next tick.`),a(!1))}).finally(()=>{f.current=!1}),()=>c.abort()},[e,t,c]),{data:n,loading:i,error:o}}function gl({projectKey:e,windowWeeks:t}){let{data:n,loading:r,error:i}=hl(e,t),a=Rn(),o={tz:a.resolvedTz,offsetLabel:a.offsetLabel},s=n!=null&&(n.key!==e||n.window_weeks!==t);if(r&&!n||s)return(0,B.jsx)(`div`,{className:`panel-empty`,children:`Loading…`});if(i&&!n)return(0,B.jsx)(`div`,{className:`panel-empty`,children:i});if(!n)return null;let c=n.models[0]?.cost_usd??0,l=c>0?c:1,u=Math.max(0,n.sessions_total-n.sessions.length);return(0,B.jsxs)(`div`,{className:`projects-drill`,"data-testid":`projects-drill`,"aria-live":`polite`,children:[(0,B.jsx)(`div`,{className:`projects-drill-head`,children:(0,B.jsxs)(`span`,{className:`title`,children:[`▾ `,n.key,` · `,n.sessions_total,` session`,n.sessions_total===1?``:`s`,` · `,F.usd2(n.window_cost_usd),` (`,t,`w)`]})}),(0,B.jsxs)(`div`,{className:`projects-drill-grid`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`section-label`,children:`Models (this project)`}),n.models.length===0?(0,B.jsx)(`div`,{className:`muted`,children:`No model data for this window.`}):n.models.map(e=>{let t={"--w":`${e.cost_usd/l*100}%`};return(0,B.jsxs)(`div`,{className:`drill-bar-row`,children:[(0,B.jsx)(`span`,{className:`chip ${or(e.model)}`,children:e.model}),(0,B.jsx)(`div`,{className:`drill-bar`,style:t}),(0,B.jsx)(`span`,{className:`cost ${cr(e.cost_usd)}`,children:F.usd2(e.cost_usd)})]},e.model)})]}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`section-label`,children:`Recent sessions →`}),n.sessions.length===0?(0,B.jsx)(`div`,{className:`muted`,children:`No sessions for this window.`}):n.sessions.map((e,t)=>(0,B.jsxs)(`button`,{"data-testid":`drill-session-${t}`,className:`drill-session-row`,onClick:()=>z({type:`OPEN_MODAL`,kind:`session`,sessionId:e.session_id}),children:[(0,B.jsx)(`span`,{className:`started`,children:F.datetimeShort(e.last_activity_at,o)}),(0,B.jsx)(`span`,{className:`chip ${or(e.primary_model)}`,children:e.primary_model}),(0,B.jsx)(`span`,{className:`cost ${cr(e.cost_usd)}`,children:F.usd2(e.cost_usd)})]},e.session_id)),(0,B.jsxs)(`div`,{className:`drill-session-footer`,children:[u>0&&(0,B.jsxs)(`span`,{className:`muted`,children:[`+`,u,` more`]}),(0,B.jsx)(`button`,{type:`button`,"data-testid":`drill-show-in-sessions`,className:`drill-show-in-sessions`,onClick:()=>{z({type:`SET_FILTER`,text:n.key}),z({type:`CLOSE_MODAL`})},children:`Show in Sessions →`})]})]})]})]})}var _l=(e,t)=>e<t?-1:+(e>t),vl=[{id:`project`,label:`Project`,defaultDirection:`asc`,compare:(e,t)=>_l(e.key,t.key),className:`project`},{id:`sessions`,label:`Sessions`,defaultDirection:`desc`,numeric:!0,compare:(e,t)=>e.sessionsCount-t.sessionsCount},{id:`first_seen`,label:`First seen`,defaultDirection:`asc`,nullKey:e=>e.firstSeenAt,compare:(e,t)=>_l(e.firstSeenAt,t.firstSeenAt),className:`started`},{id:`last_seen`,label:`Last seen`,defaultDirection:`desc`,nullKey:e=>e.lastSeenAt,compare:(e,t)=>_l(e.lastSeenAt,t.lastSeenAt),className:`started`},{id:`cost`,label:`Cost`,defaultDirection:`desc`,numeric:!0,compare:(e,t)=>e.windowCost-t.windowCost},{id:`used_pct`,label:`Used %`,defaultDirection:`desc`,numeric:!0,nullKey:e=>e.windowPct,compare:(e,t)=>e.windowPct-t.windowPct},{id:`share_of_window`,label:`% of week`,defaultDirection:`desc`,numeric:!0,nullKey:e=>e.shareOfWindow,compare:(e,t)=>e.shareOfWindow-t.shareOfWindow}],yl=[{column:`cost`,direction:`desc`,label:`cost`,arrow:`↓`},{column:`sessions`,direction:`desc`,label:`sessions`,arrow:`↓`},{column:`used_pct`,direction:`desc`,label:`used`,arrow:`↓`},{column:`share_of_window`,direction:`desc`,label:`share`,arrow:`↓`},{column:`first_seen`,direction:`asc`,label:`first`,arrow:`↑`},{column:`last_seen`,direction:`desc`,label:`last`,arrow:`↓`},{column:`project`,direction:`asc`,label:`project`,arrow:`↑`}],bl=[1,4,8,12];function xl(){let e=V(),t=Rn(),n={tz:t.resolvedTz,offsetLabel:t.offsetLabel},r=(0,_.useSyncExternalStore)(R,()=>L().openProjectKey),i=(0,_.useSyncExternalStore)(R,()=>L().prefs.projectsWindowWeeks),a=(0,_.useSyncExternalStore)(R,()=>L().prefs.projectsTrendYMode),o=(0,_.useSyncExternalStore)(R,()=>L().prefs.projectsSortOverride),[s,c]=(0,_.useState)(r??null),[l,u]=(0,_.useState)(!1);(0,_.useEffect)(()=>{if(r){c(r);return}s||c(e?.projects?.current_week?.rows?.[0]?.key??null)},[r,e?.projects?.current_week?.rows]),(0,_.useEffect)(()=>{r||s&&((e?.projects?.trend?.projects??[]).some(e=>e.key===s)||c(e?.projects?.current_week?.rows?.[0]?.key??null))},[r,s,e?.projects?.trend?.projects,e?.projects?.current_week?.rows]);let d=e?.projects?.trend??null,f=i,p=d?.window_weeks??0,m=(e,t)=>{z({type:`SAVE_PREFS`,patch:{[e]:t}})},h=e=>{c(t=>t===e?null:e)},g=(d?.projects??[]).map(e=>{let t=e.weekly_cost.slice(-i),n=e.weekly_pct.slice(-i),r=e.sessions_per_week.slice(-i),a=e.first_seen_per_week.slice(-i),o=e.last_seen_per_week.slice(-i),s=t.reduce((e,t)=>e+t,0),c=n.reduce((e,t)=>t==null?e:(e??0)+t,null),l=r.reduce((e,t)=>e+t,0),u=a.reduce((e,t)=>t==null?e:e==null||t<e?t:e,null),d=o.reduce((e,t)=>t==null?e:e==null||t>e?t:e,null);return{key:e.key,sessionsCount:l,firstSeenAt:u,lastSeenAt:d,windowCost:s,windowPct:c,shareOfWindow:null}}),v=g.reduce((e,t)=>e+t.windowCost,0);for(let e of g)e.shareOfWindow=v>0?e.windowCost/v*100:null;let y=o?Ie(g,vl,o):Ie(g,vl,{column:`cost`,direction:`desc`}),b=y.filter(e=>e.windowCost>0).slice(0,10),x=y.length-b.length,S=l?y:b,C=x>0,w=rr(),T=(()=>{if(!o)return 0;let e=yl.findIndex(e=>e.column===o.column&&e.direction===o.direction);return e===-1?0:e})(),E=()=>{let e=yl[(T+1)%yl.length];z({type:`SET_TABLE_SORT`,table:`projects`,override:{column:e.column,direction:e.direction}})},D=yl[T],O=()=>L().shareModal===null&&L().composerModal===null;return On([{key:`1`,scope:`modal`,when:O,action:()=>m(`projectsWindowWeeks`,1)},{key:`4`,scope:`modal`,when:O,action:()=>m(`projectsWindowWeeks`,4)},{key:`8`,scope:`modal`,when:O,action:()=>m(`projectsWindowWeeks`,8)},{key:`0`,scope:`modal`,when:O,action:()=>m(`projectsWindowWeeks`,12)},{key:`s`,scope:`modal`,when:O,action:()=>m(`projectsTrendYMode`,a===`share`?`absolute`:`share`)},{key:`ArrowUp`,scope:`modal`,when:O,action:()=>{if(S.length===0)return;let e=S.findIndex(e=>e.key===s);c(S[e<=0?S.length-1:e-1].key)}},{key:`ArrowDown`,scope:`modal`,when:O,action:()=>{if(S.length===0)return;let e=S.findIndex(e=>e.key===s);c(S[e===-1||e===S.length-1?0:e+1].key)}},{key:`Enter`,scope:`modal`,when:O,action:()=>{s?c(null):S.length>0&&c(S[0].key)}}]),(0,B.jsx)(cc,{title:`Projects · last ${i}w`,accentClass:`accent-magenta`,headerExtras:(0,B.jsx)(Vn,{panel:`projects`,panelLabel:`Projects`,triggerId:`projects-modal`,dataTestId:`share-icon-projects-modal`,onClick:()=>z(He(`projects`,`projects-modal`,{windowWeeks:i}))}),children:(0,B.jsxs)(`div`,{className:`projects-modal-body`,children:[(0,B.jsxs)(`div`,{className:`projects-controls`,role:`radiogroup`,"aria-label":`Window`,children:[bl.map(e=>(0,B.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":i===e,className:`pill ${i===e?`on`:``}`,onClick:()=>m(`projectsWindowWeeks`,e),children:[e,`w`]},`window-${e}`)),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`|`}),(0,B.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":a===`share`,className:`pill ${a===`share`?`on`:``}`,onClick:()=>m(`projectsTrendYMode`,`share`),children:`share %`}),(0,B.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":a===`absolute`,className:`pill ${a===`absolute`?`on`:``}`,onClick:()=>m(`projectsTrendYMode`,`absolute`),children:`$ absolute`})]}),p>0&&p<f&&(0,B.jsxs)(`div`,{className:`projects-notice`,children:[`Showing `,p,` week`,p===1?``:`s`,` (need more history for the full window).`]}),d?(0,B.jsx)(ml,{trend:d,yMode:a,windowWeeks:i,onProjectSelect:e=>c(e)}):(0,B.jsx)(`div`,{className:`panel-empty`,children:`Projects trend unavailable.`}),w&&(0,B.jsxs)(`button`,{type:`button`,className:`projects-mobile-sort`,"data-testid":`projects-mobile-sort`,onClick:E,"aria-label":`Cycle sort column`,children:[`Sort: `,D.label,` `,D.arrow]}),(0,B.jsxs)(`table`,{className:`projects-table`,children:[(0,B.jsx)(Zn,{columns:vl,override:o,onChange:e=>z({type:`SET_TABLE_SORT`,table:`projects`,override:e}),accentVar:`--accent-magenta`}),(0,B.jsx)(`tbody`,{children:S.map(e=>(0,B.jsxs)(_.Fragment,{children:[(0,B.jsxs)(`tr`,{"data-testid":`projects-table-row`,"data-cost":e.windowCost,"data-sessions":e.sessionsCount,"aria-expanded":s===e.key,className:s===e.key?`selected`:``,onClick:()=>h(e.key),children:[(0,B.jsx)(`td`,{className:`project`,children:e.key}),(0,B.jsx)(`td`,{children:e.sessionsCount}),(0,B.jsx)(`td`,{className:`started first-seen`,children:F.dateShort(e.firstSeenAt,n)??`—`}),(0,B.jsx)(`td`,{className:`started last-seen`,children:F.dateShort(e.lastSeenAt,n)??`—`}),(0,B.jsx)(`td`,{className:cr(e.windowCost),children:F.usd2(e.windowCost)}),(0,B.jsx)(`td`,{children:e.windowPct==null?`—`:F.pct0(e.windowPct)}),(0,B.jsx)(`td`,{children:e.shareOfWindow==null?`—`:F.pct0(e.shareOfWindow)})]}),w&&s===e.key&&(0,B.jsx)(`tr`,{className:`projects-drill-row`,"aria-hidden":`false`,children:(0,B.jsx)(`td`,{colSpan:7,children:(0,B.jsx)(gl,{projectKey:e.key,windowWeeks:i})})})]},e.key))})]}),C&&(0,B.jsx)(`button`,{type:`button`,className:`projects-table-toggle`,"data-testid":`projects-table-toggle`,"aria-expanded":l,onClick:()=>u(e=>!e),children:l?`Show top 10 active`:`Show all ${y.length} projects (+${x})`}),!w&&s&&(0,B.jsx)(gl,{projectKey:s,windowWeeks:i}),(0,B.jsxs)(`div`,{className:`projects-modal-footer-hint`,"data-testid":`projects-modal-footer-hint`,"aria-live":`off`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`1`}),`/`,(0,B.jsx)(`kbd`,{children:`4`}),`/`,(0,B.jsx)(`kbd`,{children:`8`}),`/`,(0,B.jsx)(`kbd`,{children:`0`}),` window`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`↑↓`}),` row`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`Enter`}),` drill`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`s`}),` share/$`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`Esc`}),` close`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsx)(nn,{})]})]})})}function Sl({cr:e}){let t=e.today.baseline_daily_row_count<5,n=e.today.anomaly_triggered&&!t,r;r=t?{text:`~ Building baseline · ${e.today.baseline_daily_row_count}/5 days`,cls:`thin`}:n?{text:`⚠ Anomaly`,cls:``}:{text:`✓ Healthy`,cls:`ok`};let i=e.today.baseline_median_percent,a=e.today.delta_pp,o;if(a===null)o=`—`;else{let e=F.pctFloor(Math.abs(a));o=`${a<0?`−`:`+`}${e}pp`}return(0,B.jsxs)(`div`,{className:`crm-section`,children:[(0,B.jsxs)(`div`,{className:`crm-section-head crm-sh-spotlight`,children:[`Today's spotlight`,(0,B.jsxs)(`span`,{className:`meta`,children:[e.today.date,` · `,e.days.length,` days observed`]})]}),(0,B.jsxs)(`div`,{className:`crm-spotlight${n?` anom`:``}`,children:[(0,B.jsxs)(`div`,{className:`crm-spotlight-row`,children:[(0,B.jsx)(`span`,{className:`pill${r.cls?` `+r.cls:``}`,children:r.text}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`Cache hit`}),` `,(0,B.jsxs)(`strong`,{children:[F.pctFloor(e.today.cache_hit_percent),`%`]})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`14d median`}),` `,(0,B.jsx)(`strong`,{children:i===null?`—`:`${F.pctFloor(i)}%`})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`Δ`}),` `,(0,B.jsx)(`strong`,{children:o})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`Net`}),` `,(0,B.jsx)(`strong`,{children:F.usdSigned(e.today.net_usd)})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`Saved / Wasted`}),` `,(0,B.jsxs)(`strong`,{children:[`$`,e.today.saved_usd.toFixed(2),` / $`,e.today.wasted_usd.toFixed(2)]})]})]}),n&&e.today.anomaly_reasons.length>0&&(0,B.jsxs)(`div`,{className:`reasons`,children:[`Reasons:`,` `,e.today.anomaly_reasons.map((e,t)=>(0,B.jsxs)(`span`,{children:[t>0&&` · `,(0,B.jsx)(`code`,{children:e})]},e)),` | `,`thresholds: `,e.anomaly_threshold_pp,`pp drop, net < 0`]})]})]})}function Cl(e,t=28){if(e.length<=t)return e;let n=e.split(`/`).filter(Boolean);if(n.length<=2)return e;let r=`/`+n[0],i=`${r}/…/${n.slice(-2).join(`/`)}`;return i.length<=t||(i=`${r}/…/${n[n.length-1]}`,i.length<=t)?i:`…/${n[n.length-1]}`}function wl({kind:e,rows:t}){let n=e===`projects`?`bd-projects`:`bd-models`,r=e===`projects`?`By project`:`By model`,i=e===`projects`?`No project activity in this window`:`No model activity in this window`,a=e===`projects`;return(0,B.jsxs)(`div`,{className:`crm-bd-card ${n}`,"data-bd-kind":e,children:[(0,B.jsx)(`div`,{className:`crm-bd-head`,children:r}),t.length===0?(0,B.jsx)(`div`,{className:`empty`,children:i}):(0,B.jsx)(`table`,{children:(0,B.jsx)(`tbody`,{children:t.map(e=>{let t=a?Cl(e.key):e.key,n=t!==e.key;return(0,B.jsxs)(`tr`,{"data-testid":`crm-bd-row`,"data-bd-key":e.key,children:[(0,B.jsx)(`td`,{className:`bd-key`,title:n?e.key:void 0,children:t}),(0,B.jsxs)(`td`,{children:[F.pctFloor(e.cache_hit_percent),`%`]}),(0,B.jsx)(`td`,{className:e.net_usd>=0?`net-pos`:`net-neg`,children:F.usdSigned(e.net_usd)})]},e.key)})})})]})}function Tl({current_threshold_pp:e,onClose:t}){let[n,r]=(0,_.useState)(String(e)),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1),u=(0,_.useRef)(null);(0,_.useEffect)(()=>{function e(e){let n=e.target;n&&n.closest(`[data-cr-settings-toggle]`)||u.current&&!u.current.contains(e.target)&&t()}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[t]),(0,_.useEffect)(()=>{function e(e){e.key===`Escape`&&(e.stopPropagation(),t())}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[t]);async function d(){l(!1);let e=n.trim(),t=/^-?\d+$/.test(e)?parseInt(e,10):NaN;if(!Number.isInteger(t)||t<1||t>100){a(`Must be an integer between 1 and 100`);return}s(!0),a(null);try{let e=await fetch(`/api/settings`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cache_report:{anomaly_threshold_pp:t}})});if(e.ok)l(!0),setTimeout(()=>l(!1),1500);else{let t=await e.json().catch(()=>({}));a(typeof t.error==`string`?t.error:`HTTP ${e.status}`)}}catch(e){a(String(e))}finally{s(!1)}}return(0,B.jsxs)(`div`,{ref:u,className:`crm-settings-popover`,role:`dialog`,"aria-label":`Cache Report settings`,children:[(0,B.jsx)(`h4`,{children:`Cache Report settings`}),(0,B.jsx)(`label`,{htmlFor:`cr-threshold`,children:`Anomaly threshold (pp)`}),(0,B.jsx)(`input`,{id:`cr-threshold`,type:`number`,inputMode:`numeric`,min:1,max:100,value:n,onChange:e=>{r(e.target.value),a(null),l(!1)},className:i?`invalid`:``}),i&&(0,B.jsx)(`div`,{className:`err`,children:i}),c&&(0,B.jsx)(`div`,{className:`saved`,children:`Saved · next sync will re-evaluate`}),(0,B.jsxs)(`div`,{className:`actions`,children:[(0,B.jsx)(`button`,{onClick:t,type:`button`,children:`Close`}),(0,B.jsx)(`button`,{className:`primary`,onClick:d,disabled:o,type:`button`,children:o?`Saving…`:`Save`})]})]})}function El(){let e=V()?.cache_report,[t,n]=(0,_.useState)(!1);if(!e)return(0,B.jsx)(cc,{title:`Cache Report`,accentClass:`accent-teal`,children:(0,B.jsx)(`div`,{style:{color:`var(--text-dim)`,padding:`20px 0`},children:`Loading…`})});if(e.is_empty)return(0,B.jsx)(cc,{title:`Cache Report`,accentClass:`accent-teal`,children:(0,B.jsxs)(`div`,{style:{color:`var(--text-dim)`,padding:`20px 0`},children:[`No Claude activity in the last `,e.window_days,` days.`]})});let r=(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`span`,{className:`sub`,style:{marginRight:12,color:`var(--text-dim)`},children:[`Last `,e.window_days,` days · `,e.anomaly_window_days,`d baseline · Claude only`]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Cache Report settings`,"data-cr-settings-toggle":!0,onClick:e=>{e.stopPropagation(),n(e=>!e)},style:{background:`transparent`,border:0,color:`var(--text-dim)`,cursor:`pointer`,fontSize:18,padding:`0 8px`},children:`⚙`})]}),i=e.today.baseline_daily_row_count<5,a=e.today.anomaly_triggered&&!i,o=a?`var(--accent-amber)`:`var(--accent-green)`,s=a?`accent-amber`:`accent-teal`,c=Math.round(e.fourteen_day_efficiency_ratio*100);return(0,B.jsxs)(cc,{title:`Cache Report`,accentClass:s,headerExtras:r,children:[t&&(0,B.jsx)(Tl,{current_threshold_pp:e.anomaly_threshold_pp,onClose:()=>n(!1)}),(0,B.jsx)(Sl,{cr:e}),(0,B.jsxs)(`div`,{className:`crm-section`,children:[(0,B.jsxs)(`div`,{className:`crm-section-head crm-sh-timeline`,children:[`Cache hit % — `,e.window_days,`-day timeline`,(0,B.jsxs)(`span`,{className:`meta`,children:[`band = `,e.anomaly_window_days,`d median ±`,5,`pp`]})]}),(0,B.jsx)(`div`,{className:`crm-chart-frame timeline`,children:(0,B.jsx)(Ir,{days:e.days,baseline_median_percent:e.today.baseline_median_percent,today_marker_color:o,size:`large`})})]}),(0,B.jsx)(Rr,{days:e.days,size:`large`}),(0,B.jsxs)(`div`,{className:`crm-counterfactual`,children:[`Without caching, you'd have paid`,` `,(0,B.jsxs)(`strong`,{children:[`+$`,e.fourteen_day_counterfactual_usd.toFixed(2),` more`]}),` `,`over the last `,e.window_days,` days · cache efficiency`,` `,(0,B.jsxs)(`span`,{title:`saved / (saved + |wasted|) = ${c}%`,children:[c,`%`]})]}),(0,B.jsxs)(`div`,{className:`crm-section`,children:[(0,B.jsxs)(`div`,{className:`crm-section-head crm-sh-table`,children:[`Daily rows · `,e.window_days,` days`,(0,B.jsxs)(`span`,{className:`meta`,children:[e.days.length,` days observed`]})]}),(0,B.jsxs)(`table`,{className:`ch-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{className:`c-date`,children:`Date`}),(0,B.jsx)(`th`,{className:`c-hit num`,children:`Cache %`}),(0,B.jsx)(`th`,{className:`c-tokens num`,children:`Tok In`}),(0,B.jsx)(`th`,{className:`c-tokens num`,children:`Tok Out`}),(0,B.jsx)(`th`,{className:`c-saved num`,children:`Saved`}),(0,B.jsx)(`th`,{className:`c-wasted num`,children:`Wasted`}),(0,B.jsx)(`th`,{className:`c-net num`,children:`Net`}),(0,B.jsx)(`th`,{className:`c-flag num`,children:`Flag`})]})}),(0,B.jsx)(`tbody`,{children:e.days.map(t=>{let n=t.date===e.today.date,r=e.today.baseline_median_percent!==null,i=r&&e.today.baseline_median_percent!==null&&t.cache_hit_percent<e.today.baseline_median_percent-5,a=t.net_usd<0;return(0,B.jsxs)(`tr`,{className:n?`cur`:``,"data-testid":`crm-daily-row`,"data-date":t.date,children:[(0,B.jsx)(`td`,{children:t.date}),(0,B.jsxs)(`td`,{className:`num ${r?i?`hit-bad`:`hit-good`:``}`.trim(),children:[F.pctFloor(t.cache_hit_percent),`%`]}),(0,B.jsx)(`td`,{className:`num`,children:F.compact(t.input_tokens,{upper:!0})}),(0,B.jsx)(`td`,{className:`num`,children:F.compact(t.output_tokens,{upper:!0})}),(0,B.jsx)(`td`,{className:`num`,children:F.usd2(t.saved_usd)}),(0,B.jsx)(`td`,{className:`num`,children:F.usd2(t.wasted_usd)}),(0,B.jsx)(`td`,{className:`num ${a?`net-neg`:`net-pos`}`,children:F.usdSigned(t.net_usd)}),(0,B.jsx)(`td`,{className:`num ${t.anomaly_triggered?`flag-warn`:`flag-ok`}`,children:t.anomaly_triggered?`⚠`:`✓`})]},t.date)})})]})]}),(0,B.jsx)(`div`,{className:`crm-section`,children:(0,B.jsxs)(`div`,{className:`crm-breakdowns`,children:[(0,B.jsx)(wl,{kind:`projects`,rows:e.by_project}),(0,B.jsx)(wl,{kind:`models`,rows:e.by_model})]})})]})}var Dl=100;function Ol({alert:e,ctx:t}){if(e.axis===`weekly`){let n=e.context.week_start_date?F.weekStart(e.context.week_start_date,t):null,r=e.context.dollars_per_percent;return(0,B.jsxs)(`span`,{className:`alert-context alert-context--weekly`,children:[n?`Week of ${n}`:`Week —`,r!=null&&(0,B.jsxs)(B.Fragment,{children:[` · `,(0,B.jsxs)(`span`,{className:`num`,children:[`$`,r.toFixed(2),`/1%`]})]})]})}if(e.axis===`budget`){let n=Ar(e.context.period),r=e.context.period_start_at??e.context.week_start_at,i=r?F.weekStart(r.slice(0,10),t):null,a=e.context.consumption_pct;return(0,B.jsxs)(`span`,{className:`alert-context alert-context--budget`,children:[i?`${n} of ${i}`:`${n} —`,a!=null&&(0,B.jsxs)(B.Fragment,{children:[` · `,(0,B.jsxs)(`span`,{className:`num`,children:[Math.round(a),`% of budget`]})]})]})}if(e.axis===`codex_budget`){let n=Ar(e.context.period),r=e.context.period_start_at,i=r?F.weekStart(r.slice(0,10),t):null,a=e.context.consumption_pct;return(0,B.jsxs)(`span`,{className:`alert-context alert-context--codex_budget`,children:[i?`${n} of ${i}`:`${n} —`,a!=null&&(0,B.jsxs)(B.Fragment,{children:[` · `,(0,B.jsxs)(`span`,{className:`num`,children:[Math.round(a),`% of budget`]})]})]})}if(e.axis===`project_budget`){let t=e.context.project??`(project)`,n=e.context.consumption_pct;return(0,B.jsxs)(`span`,{className:`alert-context alert-context--project_budget`,children:[t,n!=null&&(0,B.jsxs)(B.Fragment,{children:[` · `,(0,B.jsxs)(`span`,{className:`num`,children:[Math.round(n),`% of budget`]})]})]})}return e.axis===`projected`?(0,B.jsx)(`span`,{className:`alert-context alert-context--projected`,children:Mr(e)??`Projected —`}):(0,B.jsxs)(`span`,{className:`alert-context alert-context--five-hour`,children:[`Block `,e.context.block_start_at?F.timeOnly(e.context.block_start_at,t):`—`]})}function kl({alert:e}){if(e.axis===`projected`)return(0,B.jsx)(`span`,{className:`num`,children:`—`});let t;return t=e.axis===`weekly`?e.context.cumulative_cost_usd:e.axis===`budget`||e.axis===`project_budget`||e.axis===`codex_budget`?e.context.spent_usd:e.context.block_cost_usd,(0,B.jsx)(`span`,{className:`num`,children:F.usd2(t??null)})}function Al(){let e=(0,_.useSyncExternalStore)(R,()=>L().alerts),t=Rn(),n={tz:t.resolvedTz,offsetLabel:t.offsetLabel},r=e.slice(0,Dl);return r.length===0?(0,B.jsx)(cc,{title:`Recent alerts`,accentClass:`accent-amber`,children:(0,B.jsx)(`div`,{className:`panel-empty`,children:`No alerts yet. Alerts appear when usage crosses 90% or 95%.`})}):(0,B.jsx)(cc,{title:`Recent alerts`,accentClass:`accent-amber`,children:(0,B.jsxs)(`div`,{className:`alerts-modal-body`,children:[(0,B.jsxs)(`table`,{className:`alerts-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{scope:`col`,children:`%`}),(0,B.jsx)(`th`,{scope:`col`,children:`Axis`}),(0,B.jsx)(`th`,{scope:`col`,children:`Cost`}),(0,B.jsx)(`th`,{scope:`col`,children:`Context`}),(0,B.jsx)(`th`,{scope:`col`,children:`Alerted`})]})}),(0,B.jsx)(`tbody`,{children:r.map(e=>{let t=jr(e);return(0,B.jsxs)(`tr`,{className:`alert-modal-row`,children:[(0,B.jsxs)(`td`,{className:`alert-threshold severity-${t} ${t} num`,children:[e.threshold,`%`]}),(0,B.jsx)(`td`,{children:(0,B.jsx)(`span`,{className:`chip chip--${e.axis}`,children:Or[e.axis]})}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(kl,{alert:e})}),(0,B.jsx)(`td`,{children:(0,B.jsx)(Ol,{alert:e,ctx:n})}),(0,B.jsx)(`td`,{className:`alert-when`,children:F.relativeOrAbsolute(e.alerted_at,n)})]},e.id)})})]}),e.length>Dl&&(0,B.jsxs)(`div`,{className:`alerts-modal-foot`,children:[`Showing `,Dl,` of `,e.length,` most recent`]})]})})}function jl(){let e=(0,_.useSyncExternalStore)(R,()=>L().openModal);if(!e)return null;switch(e){case`current-week`:return(0,B.jsx)(hc,{});case`forecast`:return(0,B.jsx)(U,{});case`trend`:return(0,B.jsx)(kc,{});case`session`:return(0,B.jsx)(Rc,{});case`weekly`:return(0,B.jsx)(Gc,{});case`monthly`:return(0,B.jsx)(Kc,{});case`block`:return(0,B.jsx)(nl,{});case`daily`:return(0,B.jsx)(sl,{});case`projects`:return(0,B.jsx)(xl,{});case`alerts`:return(0,B.jsx)(Al,{});case`cache-report`:return(0,B.jsx)(El,{})}}var Ml=class extends Error{status;field;code;constructor(e,t,n,r){super(n),this.status=e,this.field=t,this.code=r}};async function Nl(e){if(!e.ok){let t={};try{t=await e.json()}catch{}throw new Ml(e.status,t.field,t.error??`HTTP ${e.status}`,t.code)}return e.json()}async function Pl(e,t){return Nl(await fetch(`/api/share/templates?panel=${encodeURIComponent(e)}`,{signal:t?.signal}))}async function Fl(e,t){return Nl(await fetch(`/api/share/render`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t?.signal}))}var Il=[{id:`recap`,label:`Recap`,placeholderDescription:`Text + tiny chart`},{id:`visual`,label:`Visual`,placeholderDescription:`Coming soon`},{id:`detail`,label:`Detail`,placeholderDescription:`Coming soon`}];function Ll(e){return e.endsWith(`-recap`)?`recap`:e.endsWith(`-visual`)?`visual`:e.endsWith(`-detail`)?`detail`:null}function Rl({panel:e,templates:t,error:n,selectedTemplateId:r,onSelect:i}){if(n)return(0,B.jsx)(`div`,{className:`share-gallery-error`,role:`alert`,children:n});let a={};for(let e of t??[]){let t=Ll(e.id);t&&(a[t]=e)}return(0,B.jsx)(`div`,{className:`share-gallery`,role:`radiogroup`,"aria-label":`Report template`,children:Il.map(e=>{let n=a[e.id];if(t==null)return(0,B.jsxs)(`div`,{className:`share-tile share-tile-skeleton`,"aria-hidden":`true`,children:[(0,B.jsx)(`div`,{className:`share-tile-skeleton-bar`}),(0,B.jsx)(`div`,{className:`share-tile-skeleton-bar short`})]},e.id);if(!n)return(0,B.jsxs)(`button`,{type:`button`,className:`share-tile share-tile-disabled`,disabled:!0,"aria-disabled":`true`,role:`radio`,"aria-checked":`false`,title:`${e.label} — ${e.placeholderDescription}`,children:[(0,B.jsx)(`div`,{className:`share-tile-label`,children:e.label}),(0,B.jsx)(`div`,{className:`share-tile-desc`,children:e.placeholderDescription})]},e.id);let o=n.id===r;return(0,B.jsxs)(`button`,{type:`button`,className:`share-tile`+(o?` share-tile-selected`:``),role:`radio`,"aria-checked":o,"data-template-id":n.id,onClick:()=>i(n.id),children:[(0,B.jsx)(`div`,{className:`share-tile-label`,children:n.label}),(0,B.jsx)(`div`,{className:`share-tile-desc`,children:n.description})]},e.id)})})}function zl({options:e,onChange:t}){let n=n=>t({...e,...n}),r=n=>t({...e,period:{...e.period,...n}}),i=e=>{if(e===``){n({top_n:null});return}let t=Number.parseInt(e,10);Number.isNaN(t)||n({top_n:Math.max(1,t)})};return(0,B.jsxs)(`div`,{className:`share-knobs`,children:[(0,B.jsxs)(`div`,{className:`share-knob`,children:[(0,B.jsx)(`label`,{htmlFor:`share-knob-period`,children:`Period`}),(0,B.jsxs)(`select`,{id:`share-knob-period`,value:e.period.kind,onChange:e=>r({kind:e.target.value}),children:[(0,B.jsx)(`option`,{value:`current`,children:`This week`}),(0,B.jsx)(`option`,{value:`previous`,children:`Previous week`}),(0,B.jsx)(`option`,{value:`custom`,children:`Custom`})]}),e.period.kind===`custom`?(0,B.jsxs)(`div`,{className:`share-knob-period-custom`,children:[(0,B.jsxs)(`label`,{className:`share-knob-sublabel`,children:[(0,B.jsx)(`span`,{children:`Start`}),(0,B.jsx)(`input`,{type:`date`,value:e.period.start?.slice(0,10)??``,onChange:e=>r({start:e.target.value}),"aria-label":`Custom period start date`})]}),(0,B.jsxs)(`label`,{className:`share-knob-sublabel`,children:[(0,B.jsx)(`span`,{children:`End`}),(0,B.jsx)(`input`,{type:`date`,value:e.period.end?.slice(0,10)??``,onChange:e=>r({end:e.target.value}),"aria-label":`Custom period end date`})]})]}):null]}),(0,B.jsxs)(`div`,{className:`share-knob`,children:[(0,B.jsx)(`span`,{className:`share-knob-label`,children:`Theme`}),(0,B.jsxs)(`div`,{className:`share-knob-radiogroup`,role:`radiogroup`,"aria-label":`Theme`,children:[(0,B.jsxs)(`label`,{className:`share-knob-radio`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`share-theme`,value:`light`,checked:e.theme===`light`,onChange:()=>n({theme:`light`})}),(0,B.jsx)(`span`,{children:`Light`})]}),(0,B.jsxs)(`label`,{className:`share-knob-radio`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`share-theme`,value:`dark`,checked:e.theme===`dark`,onChange:()=>n({theme:`dark`})}),(0,B.jsx)(`span`,{children:`Dark`})]})]})]}),(0,B.jsxs)(`div`,{className:`share-knob`,children:[(0,B.jsx)(`label`,{htmlFor:`share-knob-topn`,children:`Top-N`}),(0,B.jsx)(`input`,{id:`share-knob-topn`,type:`number`,min:1,step:1,inputMode:`numeric`,value:e.top_n??``,onChange:e=>i(e.target.value),"aria-label":`Top-N`})]}),(0,B.jsxs)(`div`,{className:`share-knob`,children:[(0,B.jsx)(`span`,{className:`share-knob-label`,children:`Projects`}),(0,B.jsx)(`button`,{type:`button`,className:`share-knob-allowlist-stub`,disabled:!0,"aria-disabled":`true`,title:`Exports include all projects`,children:`All projects`})]}),(0,B.jsx)(`div`,{className:`share-knob`,children:(0,B.jsxs)(`label`,{className:`share-knob-checkbox`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:e.show_chart,onChange:e=>n({show_chart:e.target.checked}),"aria-label":`Include chart in export`}),(0,B.jsx)(`span`,{children:`Show chart`})]})}),(0,B.jsx)(`div`,{className:`share-knob`,children:(0,B.jsxs)(`label`,{className:`share-knob-checkbox`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:e.show_table,onChange:e=>n({show_table:e.target.checked}),"aria-label":`Include table in export`}),(0,B.jsx)(`span`,{children:`Show table`})]})}),(0,B.jsx)(`div`,{className:`share-knob`,children:(0,B.jsxs)(`label`,{className:`share-knob-checkbox`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:!e.reveal_projects,onChange:e=>n({reveal_projects:!e.target.checked}),"aria-label":`Anonymize project names on export`}),(0,B.jsx)(`span`,{children:`Anon on export`})]})})]})}var Bl=200,Vl={status:`idle`,body:``,contentType:``,errorMessage:null,errorField:null};function Hl({panel:e,templateId:t,options:n}){let[r,i]=(0,_.useState)(Vl),a=(0,_.useRef)(null),o=(0,_.useRef)(0);return(0,_.useEffect)(()=>{if(!t){i(Vl);return}i(e=>({...e,status:`loading`}));let r=++o.current,s=setTimeout(()=>{a.current?.abort();let s=new AbortController;a.current=s,Fl({panel:e,template_id:t,options:{...n,reveal_projects:!0}},{signal:s.signal}).then(e=>{r===o.current&&i({status:`ready`,body:e.body,contentType:e.content_type,errorMessage:null,errorField:null})}).catch(e=>{if(r===o.current&&!(e&&typeof e==`object`&&e.name===`AbortError`)){if(e instanceof Ml){i({status:`error`,body:``,contentType:``,errorMessage:e.message??`HTTP ${e.status}`,errorField:e.field??null});return}i({status:`error`,body:``,contentType:``,errorMessage:e.message??`Unknown error`,errorField:null})}})},Bl);return()=>{clearTimeout(s)}},[e,t,n]),(0,_.useEffect)(()=>()=>{a.current?.abort()},[]),t?r.status===`error`?(0,B.jsxs)(`div`,{className:`share-preview share-preview-error`,role:`alert`,children:[(0,B.jsx)(`div`,{className:`share-preview-error-title`,children:`Preview failed`}),(0,B.jsxs)(`div`,{className:`share-preview-error-message`,children:[r.errorMessage,r.errorField?(0,B.jsxs)(`span`,{className:`share-preview-error-field`,children:[` `,`(field: `,r.errorField,`)`]}):null]})]}):r.status===`loading`||r.status===`idle`?(0,B.jsx)(`div`,{className:`share-preview share-preview-loading`,"aria-busy":`true`,children:`Rendering preview…`}):n.format===`md`?(0,B.jsx)(`pre`,{className:`share-preview share-preview-md`,"aria-label":`Markdown preview`,children:r.body}):(0,B.jsx)(`iframe`,{className:`share-preview share-preview-iframe`,title:`Report preview (decorative)`,tabIndex:-1,sandbox:`allow-same-origin`,srcDoc:r.body}):(0,B.jsx)(`div`,{className:`share-preview share-preview-empty`,children:`Select a template to preview.`})}var Ul={"current-week":`Current week`,trend:`Trend`,weekly:`Weekly`,daily:`Daily`,monthly:`Monthly`,blocks:`5-hour blocks`,forecast:`Forecast`,sessions:`Sessions`,projects:`Projects`};function Wl(e){return Ul[e]}function Gl(e){switch(e){case`md`:return`md`;case`html`:return`html`;case`svg`:return`svg`}}async function Kl(e){if(!e.ok){let t={};try{t=await e.json()}catch{}throw new Ml(e.status,t.field,t.error??`HTTP ${e.status}`)}return e.json()}async function ql(e){return Kl(await fetch(`/api/share/presets`,{signal:e?.signal}))}async function Jl(e,t){return Kl(await fetch(`/api/share/presets`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t?.signal}))}async function Yl(e,t,n){let r=await fetch(`/api/share/presets/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`,signal:n?.signal});if(!r.ok){let e={};try{e=await r.json()}catch{}throw new Ml(r.status,void 0,e.error??`HTTP ${r.status}`)}}async function Xl(e){return Kl(await fetch(`/api/share/history`,{signal:e?.signal}))}async function Zl(e,t){return Kl(await fetch(`/api/share/history`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t?.signal}))}function Ql({panel:e,templateId:t,options:n,onSaved:r,onCancel:i}){let[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(null);async function d(){let i=a.trim();if(!i){u(`Name is required`);return}if(i.length>64){u(`Name must be 64 characters or fewer`);return}if(i.includes(`/`)){u(`Name cannot contain '/'`);return}c(!0),u(null);try{await Jl({panel:e,name:i,template_id:t,options:n}),z({type:`SHOW_STATUS_TOAST`,text:`Saved preset "${i}"`}),r()}catch(e){u((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Save failed`)}finally{c(!1)}}return(0,B.jsxs)(`div`,{className:`share-save-popover`,role:`dialog`,"aria-label":`Save preset`,children:[(0,B.jsxs)(`label`,{className:`share-save-label`,children:[`Preset name`,(0,B.jsx)(`input`,{type:`text`,className:`share-save-input`,autoFocus:!0,value:a,maxLength:64,disabled:s,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),e.stopPropagation(),d()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),i())}})]}),l?(0,B.jsx)(`div`,{className:`share-save-error`,role:`alert`,children:l}):null,(0,B.jsxs)(`div`,{className:`share-save-actions`,children:[(0,B.jsx)(`button`,{type:`button`,onClick:i,disabled:s,children:`Cancel`}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>void d(),disabled:s,children:s?`Saving…`:`Save`})]})]})}async function $l(e,t,n){let r=new Blob([e],{type:`image/svg+xml`}),i=URL.createObjectURL(r);try{let e=new Image;e.src=i,await e.decode();let r=document.createElement(`canvas`);r.width=e.naturalWidth*t,r.height=e.naturalHeight*t;let a=r.getContext(`2d`);if(!a)throw Error(`Could not acquire 2D canvas context`);a.fillStyle=n,a.fillRect(0,0,r.width,r.height),a.scale(t,t),a.drawImage(e,0,0);let o=await new Promise(e=>{r.toBlob(t=>e(t),`image/png`)});if(o)return o;let s=r.toDataURL(`image/png`);return(await fetch(s)).blob()}finally{URL.revokeObjectURL(i)}}function eu(e){let t=document.createElement(`iframe`);t.setAttribute(`aria-hidden`,`true`),t.style.cssText=`position:fixed;right:0;bottom:0;width:0;height:0;border:0`,document.body.appendChild(t);let n=t.contentDocument;if(!n)throw Error(`iframe contentDocument unavailable`);n.open(),n.write(e),n.close();try{t.contentWindow?.focus(),t.contentWindow?.print()}catch{let t=window.open(``,`_blank`,`noopener,noreferrer`);t&&(t.document.open(),t.document.write(e),t.document.close())}setTimeout(()=>t.remove(),1e3)}function tu(e){Zl({panel:e.panel,template_id:e.template_id,options:e.options,format:e.options.format,destination:e.destination}).catch(()=>{})}function nu(e){return e===`light`?`#ffffff`:`#0f172a`}function ru(e,t){return`cctally-${e}-${new Date().toISOString().slice(0,10).replaceAll(`-`,``)}.${Gl(t)}`}function iu(e){switch(e){case`md`:return`text/markdown;charset=utf-8`;case`html`:return`text/html;charset=utf-8`;case`svg`:return`image/svg+xml;charset=utf-8`}}function au(e,t){let n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=e,r.style.display=`none`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>URL.revokeObjectURL(n),0)}function ou({panel:e,templateId:t,options:n,onOptionsChange:r}){let[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),u=(0,_.useRef)(null);(0,_.useEffect)(()=>()=>{u.current!=null&&clearTimeout(u.current)},[]);let[d,f]=(0,_.useState)(!1),p=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!d)return;function e(e){let t=p.current;t&&(t.contains(e.target)||f(!1))}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[d]),On((0,_.useMemo)(()=>[{key:`Escape`,scope:`overlay`,layer:205,when:()=>d,action:()=>f(!1)}],[d])),(0,_.useEffect)(()=>{s(null)},[n.format,t]);let m=t==null||i!=null,h=e=>z({type:`SHOW_STATUS_TOAST`,text:e}),g=async()=>{if(!t)throw Error(`no template selected`);return{body:(await Fl({panel:e,template_id:t,options:n})).body,format:n.format}},v=async()=>{if(!(m||!t)){a(`copy`),s(null);try{let{body:r}=await g();if(!navigator.clipboard||typeof navigator.clipboard.writeText!=`function`)throw Error(`Clipboard API unavailable in this browser`);await navigator.clipboard.writeText(r),h(`Copied`),tu({panel:e,template_id:t,options:n,destination:`copy`})}catch(e){s(`Copy failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},y=async()=>{if(!(m||!t)){a(`download`),s(null);try{let{body:r,format:i}=await g(),a=new Blob([r],{type:iu(i)});au(ru(e,i),a),h(`Downloaded`),tu({panel:e,template_id:t,options:n,destination:`download`})}catch(e){s(`Download failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},b=async()=>{if(!(m||!t)){a(`basket`),s(null);try{let r=await Fl({panel:e,template_id:t,options:n}),i=Je({panel:e,template_id:t,options:n,added_at:new Date().toISOString(),data_digest_at_add:r.snapshot.data_digest,kernel_version:r.snapshot.kernel_version,label_hint:Wl(e)});z({type:`BASKET_ADD`,item:i});let a=L().basket;if(a.rejectedReason===`capacity`)return;l(!0),u.current!=null&&clearTimeout(u.current),u.current=setTimeout(()=>l(!1),800),z({type:`SHOW_STATUS_TOAST`,text:`Added ${i.label_hint} to basket (${a.items.length})`})}catch(e){s(`Add to basket failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},x=async()=>{if(!(m||!t)){a(`open`),s(null);try{let{body:r,format:i}=await g(),a=new Blob([r],{type:iu(i)}),o=URL.createObjectURL(a);window.open(o,`_blank`,`noopener,noreferrer`),tu({panel:e,template_id:t,options:n,destination:`open`})}catch(e){s(`Open failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},S=async()=>{if(!(!t||n.format!==`svg`||m)){a(`png`),s(null);try{let{body:r}=await g(),i=await $l(r,2,nu(n.theme));au(ru(e,`svg`).replace(/\.svg$/,`.png`),i),h(`PNG downloaded`),tu({panel:e,template_id:t,options:n,destination:`png`})}catch(e){s(`PNG export failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},C=async()=>{if(!(!t||n.format!==`html`||m)){a(`print`),s(null);try{let{body:r}=await g();eu(r),tu({panel:e,template_id:t,options:n,destination:`print`})}catch(e){s(`Print failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},w=n.format===`md`&&!m,T=(n.format===`html`||n.format===`svg`)&&!m,E=n.format===`svg`&&!m,D=n.format===`html`&&!m;return(0,B.jsxs)(`div`,{className:`share-actions`,children:[(0,B.jsxs)(`div`,{className:`share-format-row`,role:`radiogroup`,"aria-label":`Export format`,children:[(0,B.jsx)(`span`,{className:`share-format-label`,children:`Format:`}),[`md`,`html`,`svg`].map(e=>(0,B.jsxs)(`label`,{className:`share-format-radio`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`share-format`,value:e,checked:n.format===e,onChange:()=>r({...n,format:e})}),(0,B.jsx)(`span`,{children:e})]},e))]}),(0,B.jsxs)(`div`,{className:`share-action-row`,children:[(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-copy`,onClick:v,disabled:!w,title:n.format===`md`?i===`copy`?`Copying…`:`Copy to clipboard`:`Copy is available for Markdown only`,children:i===`copy`?`Copying…`:`Copy`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-download`,onClick:y,disabled:m,title:i===`download`?`Downloading…`:`Download file`,children:i===`download`?`Downloading…`:`Download`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-open`,onClick:x,disabled:!T,title:n.format===`html`||n.format===`svg`?i===`open`?`Opening…`:`Open in new tab`:`Open is available for HTML/SVG`,children:i===`open`?`Opening…`:`Open`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-png`,onClick:S,disabled:!E,title:n.format===`svg`?i===`png`?`Rasterizing…`:`Download PNG (rasterized from SVG)`:`PNG export — available for SVG format only`,children:i===`png`?`Rasterizing…`:`PNG`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-print`,onClick:C,disabled:!D,title:n.format===`html`?i===`print`?`Opening print dialog…`:`Open the browser print dialog (save as PDF)`:`Print → PDF — available for HTML format only`,children:i===`print`?`Printing…`:`Print → PDF`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-basket${c?` share-action-basket-added`:``}`,onClick:b,disabled:m,title:m&&t==null?`Pick a template first`:i===`basket`?`Adding to basket…`:`Add this section to the report basket`,children:c?`✓ Added`:i===`basket`?`Adding…`:`+ Basket`})]}),(0,B.jsxs)(`div`,{className:`share-save-preset-row`,ref:p,children:[(0,B.jsx)(`button`,{type:`button`,className:`share-save-preset`,disabled:t==null||i!=null,onClick:()=>f(e=>!e),"aria-haspopup":`dialog`,"aria-expanded":d,title:t==null?`Pick a template first`:`Save the current recipe as a named preset`,children:`Save preset…`}),d&&t?(0,B.jsx)(Ql,{panel:e,templateId:t,options:n,onSaved:()=>f(!1),onCancel:()=>f(!1)}):null]}),o?(0,B.jsx)(`div`,{className:`share-action-error`,role:`alert`,children:o}):null]})}function su(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function cu({panel:e,onPick:t,onManage:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)({}),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(null),d=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!r)return;let t=new AbortController;return u(null),Promise.all([ql({signal:t.signal}),Xl({signal:t.signal})]).then(([t,n])=>{o(t.presets[e]??{}),c(n.history.filter(t=>t.panel===e).slice().reverse())}).catch(e=>{e?.name!==`AbortError`&&u((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Failed to load presets`)}),()=>t.abort()},[r,e]),(0,_.useEffect)(()=>{if(!r)return;function e(e){let t=d.current;t&&(t.contains(e.target)||i(!1))}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]),On((0,_.useMemo)(()=>[{key:`Escape`,scope:`overlay`,layer:205,when:()=>r,action:()=>i(!1)}],[r]));let f=Object.keys(a).sort();return(0,B.jsxs)(`div`,{className:`share-presets-dropdown`,ref:d,children:[(0,B.jsx)(`button`,{type:`button`,className:`share-presets-trigger`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>i(e=>!e),children:`presets ▾`}),r?(0,B.jsxs)(`div`,{className:`share-presets-menu`,role:`menu`,children:[l?(0,B.jsx)(`div`,{className:`share-presets-error`,role:`alert`,children:l}):null,f.length===0&&!l?(0,B.jsx)(`div`,{className:`share-presets-empty`,children:`No saved presets yet.`}):null,f.length>0?(0,B.jsx)(`ul`,{className:`share-presets-list`,children:f.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,className:`share-presets-item`,onClick:()=>{t(a[e].template_id,a[e].options),i(!1)},children:e})},e))}):null,s.length>0?(0,B.jsxs)(`div`,{className:`share-presets-history`,children:[(0,B.jsx)(`div`,{className:`share-presets-history-heading`,role:`presentation`,children:`Recent shares`}),(0,B.jsx)(`ul`,{className:`share-presets-history-list`,children:s.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`share-presets-history-item`,onClick:()=>{t(e.template_id,e.options),i(!1)},title:`${e.template_id} · ${e.format??`unknown`} · ${e.exported_at}`,children:[(0,B.jsx)(`span`,{className:`share-presets-history-template`,children:e.template_id}),(0,B.jsxs)(`span`,{className:`share-presets-history-meta`,children:[` · `,e.format??`unknown`,` · `,su(e.exported_at)]})]})},e.recipe_id))})]}):null,(0,B.jsx)(`div`,{className:`share-presets-footer`,children:(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,className:`share-presets-manage`,onClick:()=>{n(),i(!1)},children:`Manage presets…`})})]}):null]})}var lu=`share-manage-presets-title`;function uu({open:e,onClose:t}){let[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null);On((0,_.useMemo)(()=>e?[{key:`Escape`,scope:`modal`,action:t}]:[],[e,t]));let c=(0,_.useRef)(null),l=(0,_.useRef)(!1);(0,_.useEffect)(()=>{if(e)l.current||(l.current=!0,c.current=document.activeElement);else if(l.current){l.current=!1;let e=c.current;if(c.current=null,e&&typeof e.focus==`function`&&document.contains(e))e.focus();else{let e=document.activeElement;e&&typeof e.blur==`function`&&e.blur(),document.body.focus()}}},[e]),(0,_.useEffect)(()=>{if(!e)return;let t=!1;return s(null),(async()=>{try{let e=await ql();if(t)return;let n=[];for(let[t,r]of Object.entries(e.presets))for(let[e,i]of Object.entries(r))n.push({panel:t,name:e,record:i});n.sort((e,t)=>e.panel===t.panel?e.name.localeCompare(t.name):e.panel.localeCompare(t.panel)),r(n)}catch(e){if(t)return;s((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Failed to load presets`)}})(),()=>{t=!0}},[e]);async function u(e){a(!0),s(null);try{await Yl(e.panel,e.name),r(t=>t.filter(t=>!(t.panel===e.panel&&t.name===e.name))),z({type:`SHOW_STATUS_TOAST`,text:`Deleted preset "${e.name}"`})}catch(e){s((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Delete failed`)}finally{a(!1)}}async function d(e,t){a(!0),s(null);try{await Jl({panel:e.panel,name:t,template_id:e.record.template_id,options:e.record.options}),await Yl(e.panel,e.name),r(n=>n.map(n=>n.panel===e.panel&&n.name===e.name?{...n,name:t}:n)),z({type:`SHOW_STATUS_TOAST`,text:`Renamed to "${t}"`})}catch(e){s((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Rename failed`)}finally{a(!1)}}return e?(0,B.jsxs)(`div`,{className:`share-manage-modal`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":lu,onClick:e=>e.stopPropagation(),children:[(0,B.jsx)(Gr,{title:`Manage presets`,titleId:lu,className:`share-manage-header`,onClose:t,closeClassName:`share-manage-close`}),o?(0,B.jsx)(`div`,{className:`share-manage-error`,role:`alert`,children:o}):null,n.length===0&&!o?(0,B.jsx)(`p`,{className:`share-manage-empty`,children:`No saved presets yet.`}):null,n.length>0?(0,B.jsxs)(`table`,{className:`share-manage-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Panel`}),(0,B.jsx)(`th`,{children:`Name`}),(0,B.jsx)(`th`,{children:`Saved at`}),(0,B.jsx)(`th`,{})]})}),(0,B.jsx)(`tbody`,{children:n.map(e=>(0,B.jsx)(du,{row:e,busy:i,onDelete:()=>void u(e),onRename:t=>void d(e,t)},`${e.panel}/${e.name}`))})]}):null]}):null}function du({row:e,busy:t,onDelete:n,onRename:r}){let[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(e.name),c=()=>{let t=o.trim();if(!t||t===e.name){s(e.name),a(!1);return}r(t),a(!1)};return(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:Wl(e.panel)}),(0,B.jsx)(`td`,{children:i?(0,B.jsx)(`input`,{className:`share-manage-name-input`,autoFocus:!0,value:o,disabled:t,maxLength:64,onChange:e=>s(e.target.value),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),c()):t.key===`Escape`&&(t.preventDefault(),t.stopPropagation(),s(e.name),a(!1))}}):(0,B.jsx)(`span`,{children:e.name})}),(0,B.jsx)(`td`,{children:e.record.saved_at}),(0,B.jsxs)(`td`,{className:`share-manage-actions`,children:[(0,B.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>{i?(s(e.name),a(!1)):a(!0)},children:i?`Cancel`:`Rename`}),(0,B.jsx)(`button`,{type:`button`,disabled:t,onClick:n,children:`Delete`})]})]})}function fu(){return{format:`md`,theme:`light`,reveal_projects:!1,no_branding:!1,top_n:5,period:{kind:`current`},project_allowlist:null,show_chart:!0,show_table:!0}}function pu(e,t){if(!t)return e;let n={...e,...t};return t.period&&(n.period={...e.period,...t.period}),n}function mu({panel:e,onClose:t,initialParams:n}){let r=Wl(e),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(()=>{let e=fu();return n?.windowWeeks==null?e:{...e,windowWeeks:n.windowWeeks}}),f=(0,_.useRef)(!1),[p,m]=(0,_.useState)(!1),h=`share-modal-title`;In(!0),On((0,_.useMemo)(()=>[{key:`Escape`,scope:`overlay`,layer:200,when:()=>!p&&L().composerModal===null,action:t}],[t,p])),(0,_.useEffect)(()=>{let t=!1;return a(null),s(null),Pl(e).then(e=>{if(t)return;a(e.templates);let n=e.templates[0];n&&(l(n.id),f.current||d(e=>pu(e,n.default_options)))}).catch(e=>{t||s(e instanceof Ml?`Couldn't load templates: ${e.message??`HTTP ${e.status}`}`:`Couldn't load templates: ${e.message}`)}),()=>{t=!0}},[e]),(0,_.useEffect)(()=>{if(!i||!c||f.current)return;let e=i.find(e=>e.id===c);e&&d(t=>pu(t,e.default_options))},[c,i]);let g=e=>{f.current=!0,d(e)};return(0,B.jsxs)(`div`,{className:`share-modal`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":h,onClick:e=>e.stopPropagation(),children:[(0,B.jsx)(Gr,{title:`Share ${r} report`,titleId:h,className:`share-modal-header`}),(0,B.jsxs)(`div`,{className:`share-modal-body`,children:[(0,B.jsxs)(`section`,{className:`share-section share-gallery-section`,"aria-label":`Template gallery`,children:[(0,B.jsx)(`div`,{className:`share-gallery-header`,children:(0,B.jsx)(cu,{panel:e,onPick:(e,t)=>{l(e),f.current=!0,d(e=>({...e,...t}))},onManage:()=>m(!0)})}),(0,B.jsx)(Rl,{panel:e,templates:i,error:o,selectedTemplateId:c,onSelect:e=>l(e)})]}),(0,B.jsxs)(`section`,{className:`share-section share-main-section`,children:[(0,B.jsx)(`div`,{className:`share-knobs-col`,"aria-label":`Render options`,children:(0,B.jsx)(zl,{options:u,onChange:g})}),(0,B.jsx)(`div`,{className:`share-preview-col`,"aria-label":`Live preview`,children:(0,B.jsx)(Hl,{panel:e,templateId:c,options:u})})]})]}),(0,B.jsx)(`footer`,{className:`share-modal-footer`,children:(0,B.jsx)(ou,{panel:e,templateId:c,options:u,onOptionsChange:g})}),(0,B.jsx)(Wr,{className:`share-modal-close`,label:`Close share modal`,onClose:t}),(0,B.jsx)(uu,{open:p,onClose:()=>m(!1)})]})}function hu(e,t){return{title:t.title,theme:t.theme,format:t.format,no_branding:t.no_branding,reveal_projects:t.reveal_projects,sections:e.map(e=>({snapshot:{panel:e.panel,template_id:e.template_id,options:e.options,data_digest_at_add:e.data_digest_at_add,kernel_version:e.kernel_version}}))}}async function gu(e,t){let n=await fetch(`/api/share/compose`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t?.signal});if(!n.ok){let e={};try{e=await n.json()}catch{}throw new Ml(n.status,e.field,e.error??`HTTP ${n.status}`,e.code)}return n.json()}function _u({items:e,results:t,kernelVersion:n,onRefresh:r,onRemove:i,onPreviewOnly:a}){let o=Xi(Yi(Qa,{activationConstraint:{distance:4}}),Yi(qa,{coordinateGetter:Ts}));function s(t){if(!t.over||t.active.id===t.over.id)return;let n=e.findIndex(e=>e.id===t.active.id),r=e.findIndex(e=>e.id===t.over.id);n<0||r<0||z({type:`BASKET_REORDER`,fromIdx:n,toIdx:r})}return(0,B.jsx)(Xo,{sensors:o,collisionDetection:ia,onDragEnd:s,children:(0,B.jsx)(ps,{items:e.map(e=>e.id),strategy:us,children:(0,B.jsx)(`ul`,{className:`composer-section-list`,children:e.map((e,o)=>(0,B.jsx)(vu,{item:e,result:t[o],kernelVersion:n,onRefresh:r,onRemove:i,onPreviewOnly:a},e.id))})})})}function vu({item:e,result:t,kernelVersion:n,onRefresh:r,onRemove:i,onPreviewOnly:a}){let{attributes:o,listeners:s,setNodeRef:c,transform:l,transition:u,isDragging:d}=xs({id:e.id}),f=Ms(),p={transform:Fi.Transform.toString(l),transition:f?void 0:u,opacity:d?.4:1},[m,h]=(0,_.useState)(!1),g=t?.drift_detected,v=e.kernel_version!==n,y=!!(g||v);return(0,B.jsxs)(`li`,{ref:c,style:p,className:`composer-section-row`,children:[(0,B.jsx)(`button`,{className:`composer-drag-handle`,"aria-label":`Reorder ${e.label_hint}`,type:`button`,...o,...s,children:`≡`}),(0,B.jsx)(`span`,{className:`composer-section-label`,children:e.label_hint}),y?(0,B.jsx)(`span`,{className:`composer-outdated-badge`,title:g&&v?`Data and kernel both shifted since add-time. Refresh to update.`:g?`Data has changed since this section was added. Refresh to update.`:`Kernel updated since this section was added. Refresh to re-render at the new version.`,children:`Outdated`}):null,(0,B.jsxs)(`div`,{className:`composer-section-actions`,children:[(0,B.jsx)(`button`,{type:`button`,"aria-haspopup":`menu`,"aria-expanded":m,onClick:()=>h(e=>!e),"aria-label":`Actions for ${e.label_hint}`,children:`⋯`}),m?(0,B.jsxs)(`ul`,{role:`menu`,className:`composer-section-menu`,children:[(0,B.jsx)(`li`,{children:(0,B.jsx)(`button`,{type:`button`,onClick:()=>{a(e.id),h(!1)},children:`Preview only this`})}),(0,B.jsx)(`li`,{children:(0,B.jsx)(`button`,{type:`button`,onClick:()=>{r(e.id),h(!1)},children:`Refresh from current data`})}),(0,B.jsx)(`li`,{children:(0,B.jsx)(`button`,{type:`button`,onClick:()=>{i(e.id),h(!1)},"aria-label":`Remove ${e.label_hint}`,children:`Remove`})})]}):null]})]})}function yu(e,t){return t&&e>0}function bu(e){return`cctally-report-${new Date().toISOString().slice(0,10).replaceAll(`-`,``)}.${e===`md`?`md`:e}`}function xu(e){switch(e){case`md`:return`text/markdown;charset=utf-8`;case`html`:return`text/html;charset=utf-8`;case`svg`:return`image/svg+xml;charset=utf-8`}}function Su(e){return e===`light`?`#ffffff`:`#0f172a`}function Cu(e,t){let n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=e,r.style.display=`none`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>URL.revokeObjectURL(n),0)}var wu=200;function Tu(){return L().composerModal}function Eu(){return L().basket}var Du=`composer-modal-title`;function Ou(){let e=(0,_.useSyncExternalStore)(R,Tu),t=(0,_.useSyncExternalStore)(R,Eu),n=rr();In(e?.open??!1);let r=(0,_.useRef)(null),i=(0,_.useRef)(!1),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`light`),[l,u]=(0,_.useState)(`html`),[d,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(!1),S=(0,_.useRef)(null),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(null);(0,_.useEffect)(()=>{E(null)},[l,s,d,p]),On((0,_.useMemo)(()=>[{key:`Escape`,scope:`overlay`,layer:210,when:()=>L().composerModal!==null,action:()=>z(Ge())}],[])),(0,_.useEffect)(()=>{e?.open&&a===``&&o(`cctally report — ${new Date().toISOString().slice(0,10)}`)},[e?.open,a]),(0,_.useEffect)(()=>{if(e?.open)i.current||(i.current=!0,r.current=document.activeElement);else if(i.current){i.current=!1;let e=r.current;if(r.current=null,e&&typeof e.focus==`function`&&document.contains(e))e.focus();else{let e=document.activeElement;e&&typeof e.blur==`function`&&e.blur(),document.body.focus()}}},[e?.open]),(0,_.useEffect)(()=>{if(!e?.open||t.items.length===0||a===``)return;let n=setTimeout(()=>{S.current?.abort();let e=new AbortController;S.current=e,x(!0),y(null),gu(hu(t.items,{title:a,theme:s,format:l,no_branding:p,reveal_projects:!d}),{signal:e.signal}).then(t=>{e.signal.aborted||g(t)}).catch(t=>{t?.name!==`AbortError`&&(e.signal.aborted||y(t instanceof Ml?t.message??`HTTP ${t.status}`:t.message))}).finally(()=>{e.signal.aborted||x(!1)})},wu);return()=>clearTimeout(n)},[e?.open,t.items,a,s,l,d,p]);async function D(e){let n=t.items.findIndex(t=>t.id===e);if(n<0)return;let r=t.items[n];try{let t=await Fl({panel:r.panel,template_id:r.template_id,options:{...r.options,reveal_projects:!d}}),i=Je({panel:r.panel,template_id:r.template_id,options:r.options,added_at:new Date().toISOString(),data_digest_at_add:t.snapshot.data_digest,kernel_version:t.snapshot.kernel_version,label_hint:r.label_hint,id:r.id});z({type:`BASKET_REMOVE`,id:e}),z({type:`BASKET_ADD`,item:i});let a=L().basket.items.length-1;a!==n&&z({type:`BASKET_REORDER`,fromIdx:a,toIdx:n})}catch(e){y(`Refresh failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}}let O=async e=>{let n=await gu(hu(t.items,{title:a,theme:s,format:e,no_branding:p,reveal_projects:!d}));return{body:n.body,content_type:n.content_type}},k=e=>z({type:`SHOW_STATUS_TOAST`,text:e}),A=async(e,t,n)=>{if(C==null){w(e),E(null);try{await t()}catch(e){E(`${n} failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{w(null)}}},ee=()=>A(`copy`,async()=>{let{body:e}=await O(`md`);if(!navigator.clipboard||typeof navigator.clipboard.writeText!=`function`)throw Error(`Clipboard API unavailable in this browser`);await navigator.clipboard.writeText(e),k(`Copied`)},`Copy`),te=()=>A(`download`,async()=>{let{body:e}=await O(l),t=new Blob([e],{type:xu(l)});Cu(bu(l),t),k(`Downloaded`)},`Download`),j=()=>A(`open`,async()=>{let{body:e}=await O(l),t=new Blob([e],{type:xu(l)}),n=URL.createObjectURL(t);window.open(n,`_blank`,`noopener,noreferrer`)},`Open`),M=()=>A(`png`,async()=>{let{body:e}=await O(`svg`),t=await $l(e,2,Su(s));Cu(bu(`svg`).replace(/\.svg$/,`.png`),t),k(`PNG downloaded`)},`PNG export`),N=()=>A(`print`,async()=>{let{body:e}=await O(`html`);eu(e)},`Print`),ne=C==null&&l===`md`&&t.items.length>0,re=C==null&&t.items.length>0,ie=C==null&&(l===`html`||l===`svg`)&&t.items.length>0,P=C==null&&l===`svg`&&t.items.length>0,ae=C==null&&l===`html`&&t.items.length>0,oe=!d,se=yu(t.items.length,oe),ce=oe?t.items.length:0;if(!e?.open)return null;let le=(0,B.jsx)(Gr,{title:`Compose report`,titleId:Du,className:`composer-modal-header`,onClose:()=>z(Ge()),closeClassName:`composer-modal-close`});return t.items.length===0?(0,B.jsxs)(`div`,{className:`composer-modal composer-modal-empty${n?` composer-modal-mobile`:``}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":Du,children:[le,(0,B.jsx)(`p`,{className:`composer-empty-message`,children:`Basket is empty. Open any panel's share menu and pick + Basket to add a section.`})]}):(0,B.jsxs)(`div`,{className:`composer-modal${n?` composer-modal-mobile`:``}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":Du,children:[le,(0,B.jsxs)(`div`,{className:`composer-knobs`,children:[(0,B.jsxs)(`label`,{children:[`Title`,(0,B.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value)})]}),(0,B.jsxs)(`label`,{children:[`Theme`,(0,B.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),children:[(0,B.jsx)(`option`,{value:`light`,children:`light`}),(0,B.jsx)(`option`,{value:`dark`,children:`dark`})]})]}),(0,B.jsxs)(`label`,{children:[`Format`,(0,B.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),children:[(0,B.jsx)(`option`,{value:`html`,children:`html`}),(0,B.jsx)(`option`,{value:`md`,children:`md`}),(0,B.jsx)(`option`,{value:`svg`,children:`svg`})]})]}),(0,B.jsxs)(`label`,{children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),`Anon on export`]}),(0,B.jsxs)(`label`,{children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked)}),`No branding`]})]}),se?(0,B.jsxs)(`div`,{className:`composer-anon-banner`,role:`status`,"aria-live":`polite`,children:[(0,B.jsxs)(`span`,{children:[ce,` section`,ce===1?``:`s`,` contain real project names. They will appear in the export.`]}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>f(!0),children:`Anonymize all`})]}):null,(0,B.jsxs)(`div`,{className:`composer-body`,children:[(0,B.jsx)(_u,{items:t.items,results:h?.snapshot.section_results??[],kernelVersion:h?.snapshot.kernel_version??1,onRefresh:e=>{D(e)},onRemove:e=>z({type:`BASKET_REMOVE`,id:e}),onPreviewOnly:e=>{}}),(0,B.jsxs)(`figure`,{className:`composer-preview-frame`,children:[(0,B.jsxs)(`figcaption`,{className:`composer-preview-label`,children:[`Preview · `,s]}),(0,B.jsx)(`iframe`,{className:`composer-preview`,title:`Combined preview`,tabIndex:-1,sandbox:`allow-same-origin`,srcDoc:h?.body??`<p>Composing…</p>`})]})]}),b?(0,B.jsx)(`div`,{className:`composer-busy`,children:`Composing…`}):null,v?(0,B.jsx)(`div`,{className:`composer-error`,role:`alert`,children:v}):null,T?(0,B.jsx)(`div`,{className:`composer-error`,role:`alert`,children:T}):null,(0,B.jsxs)(`footer`,{className:`composer-actions`,children:[(0,B.jsxs)(`div`,{className:`composer-export-row`,children:[(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-copy`,onClick:ee,disabled:!ne,title:l===`md`?C===`copy`?`Copying…`:`Copy composed report to clipboard`:`Copy is available for Markdown only`,children:C===`copy`?`Copying…`:`Copy`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-download`,onClick:te,disabled:!re,title:C===`download`?`Downloading…`:`Download composed report`,children:C===`download`?`Downloading…`:`Download`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-open`,onClick:j,disabled:!ie,title:l===`html`||l===`svg`?C===`open`?`Opening…`:`Open composed report in new tab`:`Open is available for HTML/SVG`,children:C===`open`?`Opening…`:`Open`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-png`,onClick:M,disabled:!P,title:l===`svg`?C===`png`?`Rasterizing…`:`Download composed report as PNG`:`PNG export — available for SVG format only`,children:C===`png`?`Rasterizing…`:`PNG`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-print`,onClick:N,disabled:!ae,title:l===`html`?C===`print`?`Opening print dialog…`:`Open the browser print dialog (save as PDF)`:`Print → PDF — available for HTML format only`,children:C===`print`?`Printing…`:`Print → PDF`})]}),(0,B.jsx)(`button`,{type:`button`,className:`composer-clear-all`,onClick:()=>z({type:`BASKET_CLEAR`}),children:`Clear all`})]})]})}function ku(){let e=(0,_.useSyncExternalStore)(R,()=>L().shareModal),t=(0,_.useRef)(null),n=(0,_.useRef)(!1);(0,_.useEffect)(()=>{if(e)n.current||(n.current=!0,t.current=(e.triggerId?document.getElementById(e.triggerId):null)??document.activeElement);else if(n.current){n.current=!1;let e=t.current;if(t.current=null,e&&typeof e.focus==`function`&&document.contains(e))e.focus();else{let e=document.activeElement;e&&typeof e.blur==`function`&&e.blur(),document.body.focus()}}},[e]);let r=()=>z(Ue());return(0,B.jsxs)(B.Fragment,{children:[e?(0,B.jsx)(`div`,{id:`share-modal-root`,className:`share-overlay`,onClick:e=>{e.stopPropagation(),e.target===e.currentTarget&&r()},children:(0,B.jsx)(mu,{panel:e.panel,initialParams:e.params,onClose:r})}):null,(0,B.jsx)(Ou,{})]})}function Au(){let[e,t]=(0,_.useState)(()=>typeof window>`u`||!window.matchMedia?!0:window.matchMedia(nr).matches);return(0,_.useEffect)(()=>{if(typeof window>`u`||!window.matchMedia)return;let e=window.matchMedia(nr),n=e=>{t(e.matches)};return e.addEventListener(`change`,n),t(e.matches),()=>{e.removeEventListener(`change`,n)}},[]),e}function ju(e){if(L().snapshot==null)return;let t=L().prefs.panelOrder,n=e-1;if(n<0||n>=t.length)return;let r=Ur[t[n]];r&&r.openAction()}var Mu=`Click a panel first, then press S to share it.`;function Nu(){return typeof window>`u`||!window.matchMedia?!1:window.matchMedia(tr).matches}function Pu(){if(typeof document>`u`)return null;let e=document.activeElement;if(!e||!(e instanceof Element))return null;let t=e.closest(`[data-panel-kind]`);return t?t.getAttribute(`data-panel-kind`):null}function Fu(){return{key:`S`,scope:`global`,when:()=>{let e=L();return!(Nu()||e.shareModal!==null||e.composerModal!==null||e.openModal!==null||e.update.modalOpen||e.inputMode!==null||e.chromeOverlayOpen!==0)},action:()=>{let e=Pu();if(e===null){z({type:`SHOW_STATUS_TOAST`,text:Mu});return}if(!Me.has(e))return;let t=e;z(He(t,`${t}-panel`))}}}function Iu(){return typeof window>`u`||!window.matchMedia?!1:window.matchMedia(tr).matches}function Lu(){return{key:`B`,scope:`global`,when:()=>{let e=L();return!(Iu()||e.shareModal!==null||e.composerModal!==null||e.openModal!==null||e.update.modalOpen||e.inputMode!==null||e.chromeOverlayOpen!==0)},action:()=>z(We())}}function Ru(){return[Lu()]}function zu(){let e=L();return!e.openModal&&!e.update.modalOpen&&!e.doctorModalOpen&&e.inputMode===null&&e.chromeOverlayOpen===0}function Bu(){let e=L();return!(e.openModal!==null||e.update.modalOpen||e.inputMode!==null||e.chromeOverlayOpen!==0)}function Vu(){return[{key:`1`,scope:`global`,when:zu,action:()=>ju(1)},{key:`2`,scope:`global`,when:zu,action:()=>ju(2)},{key:`3`,scope:`global`,when:zu,action:()=>ju(3)},{key:`4`,scope:`global`,when:zu,action:()=>ju(4)},{key:`5`,scope:`global`,when:zu,action:()=>ju(5)},{key:`6`,scope:`global`,when:zu,action:()=>ju(6)},{key:`7`,scope:`global`,when:zu,action:()=>ju(7)},{key:`8`,scope:`global`,when:zu,action:()=>ju(8)},{key:`9`,scope:`global`,when:zu,action:()=>ju(9)},{key:`0`,scope:`global`,when:zu,action:()=>ju(10)},{key:`r`,scope:`global`,when:zu,action:()=>fn()},{key:`q`,scope:`global`,when:zu,action:yn},{key:`n`,scope:`global`,when:zu,action:()=>_n(1)},{key:`N`,scope:`global`,when:zu,action:()=>_n(-1)},{key:`d`,scope:`global`,view:`any`,when:Bu,action:()=>z({type:`OPEN_DOCTOR_MODAL`})},Fu(),...Ru(),{key:`c`,scope:`sessions`,when:()=>!L().openModal&&L().chromeOverlayOpen===0,action:()=>{let e=L().prefs.sessionsCollapsed;z({type:`SAVE_PREFS`,patch:{sessionsCollapsed:!e}})}}]}function Hu(){(0,_.useEffect)(()=>{let e=e=>{if(!(e.metaKey||e.ctrlKey)||e.shiftKey||e.altKey||e.key.toLowerCase()!==`f`)return;let t=L();if(t.view===`conversations`&&zu())if(e.preventDefault(),t.selectedConversationId)z({type:`OPEN_CONV_FIND`}),requestAnimationFrame(()=>{document.querySelector(`.conv-findbar-input`)?.focus()});else{let e=document.querySelector(`.conv-rail-search input`);e?.focus(),e?.select()}};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[])}function Uu(e){let t=new URLSearchParams;e.dateFrom&&t.set(`date_from`,e.dateFrom),e.dateTo&&t.set(`date_to`,e.dateTo);for(let n of e.projects)t.append(`projects`,n);e.costMin!=null&&t.set(`cost_min`,String(e.costMin)),e.costMax!=null&&t.set(`cost_max`,String(e.costMax)),e.rebuildMin!=null&&t.set(`rebuild_min`,String(e.rebuildMin));let n=t.toString();return n?`&${n}`:``}var Wu=50;function Gu(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!0),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(0),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(!1),f=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),p=(0,_.useRef)(f);p.current=f;let m=(0,_.useSyncExternalStore)(R,()=>L().conversationRailSort),h=(0,_.useRef)(m);h.current=m;let g=V()?.generated_at??``,v=(0,_.useRef)(!1),[y,b]=(0,_.useState)(!1),x=(0,_.useRef)(0);(0,_.useEffect)(()=>{x.current=e.length},[e.length]);let S=(0,_.useRef)(null),C=(0,_.useRef)(0),w=(0,_.useCallback)(()=>{if(v.current||x.current>Wu)return;S.current?.abort();let e=new AbortController;S.current=e,Mc(`/api/conversations?sort=${h.current}&limit=${Wu}&offset=0${Uu(p.current)}`,e.signal).then(e=>{t(e.conversations),s(e.page.next_offset),l(e.page.filter_degraded===!0),d(e.page.sort_degraded===!0),a(null),r(!1)}).catch(e=>{jc(e)||(a(`Couldn't load conversations.`),r(!1))})},[]),T=(0,_.useCallback)(()=>{a(null),r(!0),w()},[w]),E=JSON.stringify({filters:f,sort:m}),D=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(D.current===null){D.current=E;return}D.current!==E&&(D.current=E,C.current+=1,v.current=!1,b(!1),t([]),s(0),x.current=0,w())},[E]),(0,_.useEffect)(()=>{if(!(typeof document<`u`&&document.hidden))return w(),()=>S.current?.abort()},[g,w]),(0,_.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{document.hidden||w()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[w]);let O=(0,_.useCallback)(async()=>{if(o==null||v.current)return;v.current=!0,b(!0);let e=C.current;try{let n=await Mc(`/api/conversations?sort=${h.current}&limit=${Wu}&offset=${o}${Uu(p.current)}`);if(C.current!==e)return;t(e=>[...e,...n.conversations]),s(n.page.next_offset),l(n.page.filter_degraded===!0),d(n.page.sort_degraded===!0)}catch{}finally{v.current=!1,b(!1)}},[o]);return(0,_.useEffect)(()=>{e.length!==0&&z({type:`CACHE_CONVERSATION_TITLES`,titles:e.map(e=>[e.session_id,e.title])})},[e]),{rows:e,loading:n,error:i,hasMore:o!=null,loadMore:O,loadingMore:y,filterDegraded:c,sortDegraded:u,retry:T}}function Ku(e,t,n=e){let[r,i]=(0,_.useState)(n);return(0,_.useEffect)(()=>{let n=setTimeout(()=>i(e),t);return()=>clearTimeout(n)},[e,t]),r}var qu=200;function Ju(e,t=`all`){let[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(0),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=e.trim(),b=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),x=JSON.stringify(b),S=(0,_.useRef)(b);S.current=b;let C=Ku(y,qu,``),w=(0,_.useRef)(null),T=(0,_.useRef)(0);T.current=n.length;let E=(0,_.useRef)(0);E.current=o;let D=(0,_.useRef)(!1);D.current=m;let O=(0,_.useCallback)(e=>`/api/conversation/search?q=${encodeURIComponent(C)}&limit=50&offset=${e}&kind=${t}${Uu(S.current)}`,[C,t,x]);(0,_.useEffect)(()=>(y||(r([]),a(null),s(0),l(null),d(!1),v(null)),()=>{w.current?.abort()}),[y,t,x]),(0,_.useEffect)(()=>{if(!C){p(!1),h(!1);return}let e=new AbortController;return w.current=e,p(!0),h(!1),Mc(O(0),e.signal).then(e=>{r(e.hits),a(e.mode),s(e.total),l(e.search_depth??`full`),d(e.filter_degraded===!0),v(null),p(!1)}).catch(e=>{jc(e)||(v(`Search failed.`),p(!1))}),()=>e.abort()},[C,t,O]);let k=(0,_.useCallback)(()=>{if(D.current||T.current>=E.current)return;let e=T.current,t=new AbortController;w.current=t,h(!0),Mc(O(e),t.signal).then(e=>{r(t=>[...t,...e.hits]),s(e.total),a(e.mode),l(e.search_depth??`full`),d(e.filter_degraded===!0),h(!1)}).catch(e=>{jc(e)||(v(`Search failed.`),h(!1))})},[O]);return{hits:n,mode:i,total:o,loading:y!==``&&(y!==C||f),loadingMore:m,searchDepth:c,filterDegraded:u,error:g,loadMore:k}}function Yu(e){let t=[],n=0,r=0;for(;n<e.length;){let i=e.indexOf(`[`,n);if(i===-1){t.push((0,B.jsx)(_.Fragment,{children:e.slice(n)},r++));break}let a=e.indexOf(`]`,i+1);if(a===-1){t.push((0,B.jsx)(_.Fragment,{children:e.slice(n)},r++));break}i>n&&t.push((0,B.jsx)(_.Fragment,{children:e.slice(n,i)},r++)),t.push((0,B.jsx)(`mark`,{children:e.slice(i+1,a)},r++)),n=a+1}return(0,B.jsx)(B.Fragment,{children:t})}var Xu=864e5;function Zu(e,t){let[n,r,i]=new Intl.DateTimeFormat(`en-CA`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`}).format(new Date(e)).split(`-`).map(Number);return{y:n,m:r,d:i}}function Qu(e,t,n){let r=Date.parse(e),i=Zu(r,t),a=Zu(n,t),o=Date.UTC(i.y,i.m-1,i.d),s=Date.UTC(a.y,a.m-1,a.d),c=Math.round((s-o)/Xu);return c<=0?`Today`:c===1?`Yesterday`:c<7?`This Week`:i.y===a.y&&i.m===a.m?`This Month`:new Intl.DateTimeFormat(`en-US`,{timeZone:t,month:`long`,year:`numeric`}).format(new Date(r))}function $u(e,t,n,r){return e===`recent`||e===`oldest`?Qu(t.last_activity_utc,n,r):e===`project`?t.project_label||`—`:null}function ed(){let[e,t]=(0,_.useState)({projects:[]});return(0,_.useEffect)(()=>{let e=new AbortController;return Mc(`/api/conversations/facets`,e.signal).then(t).catch(e=>{jc(e)||t({projects:[]})}),()=>e.abort()},[]),e}function td(e){return`${e.getUTCFullYear()}-${String(e.getUTCMonth()+1).padStart(2,`0`)}-${String(e.getUTCDate()).padStart(2,`0`)}`}function nd(e){let[t,n,r]=new Intl.DateTimeFormat(`en-CA`,{timeZone:e,year:`numeric`,month:`2-digit`,day:`2-digit`}).format(new Date).split(`-`).map(Number);return{y:t,m:n,d:r}}var rd=[{key:`this-month`,label:`This month`,bounds:e=>{let{y:t,m:n}=nd(e);return{from:td(new Date(Date.UTC(t,n-1,1))),to:td(new Date(Date.UTC(t,n,0)))}}},{key:`last-month`,label:`Last month`,bounds:e=>{let{y:t,m:n}=nd(e);return{from:td(new Date(Date.UTC(t,n-2,1))),to:td(new Date(Date.UTC(t,n-1,0)))}}},{key:`last-7d`,label:`Last 7d`,bounds:e=>{let{y:t,m:n,d:r}=nd(e),i=new Date(Date.UTC(t,n-1,r));return{from:td(new Date(i.getTime()-6*864e5)),to:td(i)}}}],id=[1,5,10],ad=[1,3,5];function od(e){z({type:`SET_CONVERSATION_FILTERS`,patch:e})}function sd(){let e=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),t=ed(),{resolvedTz:n}=Rn(),[r,i]=(0,_.useState)(e.costMin?.toString()??``),[a,o]=(0,_.useState)(e.costMax?.toString()??``),[s,c]=(0,_.useState)(e.rebuildMin?.toString()??``);(0,_.useEffect)(()=>{i(e.costMin?.toString()??``)},[e.costMin]),(0,_.useEffect)(()=>{o(e.costMax?.toString()??``)},[e.costMax]),(0,_.useEffect)(()=>{c(e.rebuildMin?.toString()??``)},[e.rebuildMin]);let l=(0,_.useRef)({});(0,_.useEffect)(()=>{let e=l.current;return()=>{for(let t in e)clearTimeout(e[t])}},[]);let u=(e,t)=>{let n=l.current[e];n&&clearTimeout(n),l.current[e]=setTimeout(t,300)},d=e=>{if(e.trim()===``)return null;let t=Number(e);return Number.isFinite(t)?t:void 0},f=()=>z({type:`SET_INPUT_MODE`,mode:`filter`}),p=()=>z({type:`SET_INPUT_MODE`,mode:null});(0,_.useEffect)(()=>()=>{z({type:`SET_INPUT_MODE`,mode:null})},[]);let m=t=>{od({projects:e.projects.includes(t)?e.projects.filter(e=>e!==t):[...e.projects,t]})};return(0,B.jsxs)(`div`,{className:`conv-rail-filters`,role:`dialog`,"aria-label":`Conversation filters`,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),z({type:`SET_CONV_FILTERS_OPEN`,open:!1}))},children:[(0,B.jsxs)(`section`,{className:`conv-rail-filters-sec`,children:[(0,B.jsx)(`div`,{className:`conv-rail-filters-label`,children:`Date (last activity)`}),(0,B.jsx)(`div`,{className:`conv-rail-filters-chips`,children:rd.map(t=>(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-chip${e.datePreset===t.key?` is-on`:``}`,onClick:()=>{let e=t.bounds(n);od({dateFrom:e.from,dateTo:e.to,datePreset:t.key})},children:t.label},t.key))}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-range`,children:[(0,B.jsxs)(`label`,{className:`conv-rail-filters-field`,children:[(0,B.jsx)(`span`,{children:`From`}),(0,B.jsx)(`input`,{type:`date`,value:e.dateFrom??``,"aria-label":`Date from`,onFocus:f,onBlur:p,onChange:e=>od({dateFrom:e.target.value||null,datePreset:null})})]}),(0,B.jsxs)(`label`,{className:`conv-rail-filters-field`,children:[(0,B.jsx)(`span`,{children:`To`}),(0,B.jsx)(`input`,{type:`date`,value:e.dateTo??``,"aria-label":`Date to`,onFocus:f,onBlur:p,onChange:e=>od({dateTo:e.target.value||null,datePreset:null})})]})]})]}),(0,B.jsxs)(`section`,{className:`conv-rail-filters-sec`,children:[(0,B.jsx)(`div`,{className:`conv-rail-filters-label`,children:`Project`}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-projects`,children:[t.projects.length===0&&(0,B.jsx)(`div`,{className:`conv-rail-filters-empty`,children:`No projects.`}),t.projects.map(t=>(0,B.jsxs)(`label`,{className:`conv-rail-filters-proj`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:e.projects.includes(t.project_label),"aria-label":t.project_label,onChange:()=>m(t.project_label)}),(0,B.jsx)(`span`,{className:`conv-rail-filters-proj-name`,children:t.project_label}),(0,B.jsx)(`span`,{className:`conv-rail-filters-proj-count`,children:t.count})]},t.project_label))]})]}),(0,B.jsxs)(`section`,{className:`conv-rail-filters-sec`,children:[(0,B.jsx)(`div`,{className:`conv-rail-filters-label`,children:`Cost (USD)`}),(0,B.jsx)(`div`,{className:`conv-rail-filters-chips`,children:id.map(t=>(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-filters-chip${e.costMin===t?` is-on`:``}`,onClick:()=>od({costMin:t}),children:[`≥$`,t]},t))}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-range`,children:[(0,B.jsxs)(`label`,{className:`conv-rail-filters-field`,children:[(0,B.jsx)(`span`,{children:`Min`}),(0,B.jsx)(`input`,{type:`number`,inputMode:`decimal`,min:`0`,step:`0.01`,value:r,"aria-label":`Min cost`,placeholder:`0`,onFocus:f,onBlur:p,onChange:e=>{i(e.target.value);let t=d(e.target.value);t!==void 0&&u(`costMin`,()=>od({costMin:t}))}})]}),(0,B.jsxs)(`label`,{className:`conv-rail-filters-field`,children:[(0,B.jsx)(`span`,{children:`Max`}),(0,B.jsx)(`input`,{type:`number`,inputMode:`decimal`,min:`0`,step:`0.01`,value:a,"aria-label":`Max cost`,placeholder:`∞`,onFocus:f,onBlur:p,onChange:e=>{o(e.target.value);let t=d(e.target.value);t!==void 0&&u(`costMax`,()=>od({costMax:t}))}})]})]})]}),(0,B.jsxs)(`section`,{className:`conv-rail-filters-sec`,children:[(0,B.jsx)(`div`,{className:`conv-rail-filters-label`,children:`Cache rebuilds`}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-chips`,children:[ad.map(t=>(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-filters-chip${e.rebuildMin===t?` is-on`:``}`,onClick:()=>od({rebuildMin:t}),children:[`≥`,t]},t)),(0,B.jsxs)(`label`,{className:`conv-rail-filters-field conv-rail-filters-field--inline`,children:[(0,B.jsx)(`span`,{children:`≥`}),(0,B.jsx)(`input`,{type:`number`,inputMode:`numeric`,min:`0`,step:`1`,value:s,"aria-label":`Min cache rebuilds`,placeholder:`N`,onFocus:f,onBlur:p,onChange:e=>{c(e.target.value);let t=d(e.target.value);if(t!==void 0){let e=t===null?null:Math.floor(t);u(`rebuildMin`,()=>od({rebuildMin:e}))}}})]})]})]}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-footer`,children:[(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-clear`,onClick:()=>z({type:`CLEAR_CONVERSATION_FILTERS`}),children:`Clear all`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-done`,onClick:()=>z({type:`SET_CONV_FILTERS_OPEN`,open:!1}),children:`Done`})]})]})}var cd=48;function ld(e,t){let n=t[e]?.trim();return n?{kind:`title`,text:n.length>cd?`${n.slice(0,cd-1)}…`:n}:{kind:`hash`,text:e.slice(0,8)}}function ud(e){let t=new Set;for(let n of e)if(t.add(n.project_label),t.size>1)return!1;return!0}var dd={tools:`tool`,thinking:`thinking`,title:`title`,files:`file`};function fd(e,t){let n=dd[t];return n?e.filter(e=>e!==n):e}var pd=[{key:`recent`,label:`Recent`},{key:`oldest`,label:`Oldest`},{key:`cost`,label:`Cost`},{key:`messages`,label:`Messages`},{key:`project`,label:`Project`}],md=[{kind:`all`,label:`All`,needsSplit:!1,group:`content`},{kind:`prompts`,label:`Prompts`,needsSplit:!1,group:`content`},{kind:`assistant`,label:`Assistant`,needsSplit:!1,group:`content`},{kind:`tools`,label:`Tools`,needsSplit:!0,group:`content`},{kind:`thinking`,label:`Thinking`,needsSplit:!0,group:`content`},{kind:`title`,label:`Title`,needsSplit:!1,group:`structural`},{kind:`files`,label:`Files`,needsSplit:!1,group:`structural`}],hd={tool:`tool`,thinking:`thinking`,title:`title`,file:`file`},gd={"this-month":`This month`,"last-month":`Last month`,"last-7d":`Last 7d`};function _d(e){return e.dateFrom!=null||e.dateTo!=null||e.projects.length>0||e.costMin!=null||e.costMax!=null||e.rebuildMin!=null}function vd(e){let t=[];if(e.dateFrom||e.dateTo){let n=e.datePreset?gd[e.datePreset]??e.datePreset:e.dateFrom&&e.dateTo?`${e.dateFrom} → ${e.dateTo}`:e.dateFrom?`from ${e.dateFrom}`:`to ${e.dateTo}`;t.push({key:`date`,label:n,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{dateFrom:null,dateTo:null,datePreset:null}})})}for(let n of e.projects)t.push({key:`proj:${n}`,label:n,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{projects:e.projects.filter(e=>e!==n)}})});return e.costMin!=null&&t.push({key:`costMin`,label:`≥$${e.costMin}`,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{costMin:null}})}),e.costMax!=null&&t.push({key:`costMax`,label:`≤$${e.costMax}`,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{costMax:null}})}),e.rebuildMin!=null&&t.push({key:`rebuildMin`,label:`≥${e.rebuildMin} ♻`,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{rebuildMin:null}})}),t}function yd(){let e=(0,_.useSyncExternalStore)(R,()=>L().conversationSearch),t=(0,_.useSyncExternalStore)(R,()=>L().conversationSearchKind),n=(0,_.useSyncExternalStore)(R,()=>L().selectedConversationId),r=(0,_.useSyncExternalStore)(R,()=>L().convFiltersOpen),i=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),a=(0,_.useSyncExternalStore)(R,()=>L().conversationRailSort),o=(0,_.useSyncExternalStore)(R,()=>L().comparePick),s=(0,_.useSyncExternalStore)(R,()=>L().conversationTitles),c=Rn(),l={tz:c.resolvedTz,offsetLabel:c.offsetLabel},u=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!o)return;let e=e=>{e.key===`Escape`&&(e.stopPropagation(),z({type:`CANCEL_COMPARE_PICK`}))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o]);let d=e.trim()!==``,f=vd(i),p=o?ld(o.anchor,s):null;return(0,B.jsxs)(`aside`,{className:`conv-rail${o?` conv-rail--picking`:``}`,children:[o&&(0,B.jsxs)(`div`,{className:`conv-rail-pickbanner`,role:`status`,"aria-live":`polite`,children:[(0,B.jsxs)(`span`,{className:`conv-rail-pickbanner-text`,children:[`Comparing with`,` `,p?.kind===`title`?(0,B.jsxs)(`strong`,{className:`conv-rail-pickbanner-title`,children:[`“`,p.text,`”`]}):(0,B.jsx)(`code`,{children:p?.text}),` `,`— pick a session`]}),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-pickcancel`,"aria-label":`Cancel comparison pick`,onClick:()=>z({type:`CANCEL_COMPARE_PICK`}),children:`Cancel`})]}),(0,B.jsxs)(`div`,{className:`conv-rail-search`,children:[(0,B.jsxs)(`div`,{className:`conv-rail-search-bar`,children:[(0,B.jsxs)(`div`,{className:`conv-rail-search-inputwrap`,children:[(0,B.jsx)(`span`,{className:`conv-rail-search-mag`,"aria-hidden":`true`,children:`⌕`}),(0,B.jsx)(`input`,{ref:u,type:`search`,className:`conv-rail-search-input`,placeholder:`search all conversations…`,value:e,onChange:e=>z({type:`SET_CONVERSATION_SEARCH`,text:e.target.value}),onFocus:()=>z({type:`SET_INPUT_MODE`,mode:`search`}),onBlur:()=>z({type:`SET_INPUT_MODE`,mode:null}),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),z({type:`SET_CONVERSATION_SEARCH`,text:``}),u.current?.blur())}})]}),(0,B.jsxs)(`div`,{className:`conv-rail-search-controls`,children:[(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-btn${r?` is-on`:``}`,"aria-expanded":r,title:`Filter conversations`,onClick:()=>z({type:`TOGGLE_CONV_FILTERS`}),onKeyDown:e=>{r&&e.key===`Escape`&&(e.stopPropagation(),z({type:`TOGGLE_CONV_FILTERS`}))},children:`Filters ▾`}),(0,B.jsxs)(`label`,{className:`conv-rail-sort`,children:[(0,B.jsx)(`span`,{className:`conv-rail-sort-label`,children:`Sort`}),(0,B.jsx)(`select`,{className:`conv-rail-sort-select`,"aria-label":`Sort conversations`,value:a,onChange:e=>z({type:`SET_CONVERSATION_RAIL_SORT`,sort:e.target.value}),children:pd.map(e=>(0,B.jsx)(`option`,{value:e.key,children:e.label},e.key))})]})]})]}),r&&(0,B.jsx)(sd,{}),f.length>0&&(0,B.jsxs)(`div`,{className:`conv-rail-filters-active`,children:[f.map(e=>(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-filters-activechip`,title:`Remove ${e.label}`,"aria-label":`Remove ${e.label}`,onClick:e.remove,children:[e.label,(0,B.jsx)(`span`,{className:`conv-rail-filters-x`,"aria-hidden":`true`,children:`✕`})]},e.key)),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-clearall`,onClick:()=>z({type:`CLEAR_CONVERSATION_FILTERS`}),children:`Clear all`})]})]}),d?(0,B.jsx)(wd,{needle:e,kind:t,ctx:l,selectedId:n,pickAnchor:o?.anchor??null}):(0,B.jsx)(xd,{selectedId:n,ctx:l,pickAnchor:o?.anchor??null})]})}function bd(e,t,n){return e&&e!==t?()=>z({type:`OPEN_COMPARE`,a:e,b:t}):n}function xd({selectedId:e,ctx:t,pickAnchor:n}){let{rows:r,loading:i,error:a,hasMore:o,loadMore:s,loadingMore:c,filterDegraded:l,sortDegraded:u,retry:d}=Gu(),f=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),p=(0,_.useSyncExternalStore)(R,()=>L().conversationRailSort),m=(0,B.jsxs)(B.Fragment,{children:[l&&(0,B.jsx)(`div`,{className:`conv-rail-filters-degraded`,children:`Project/cost/rebuild filters apply once indexing finishes.`}),u&&(0,B.jsx)(`div`,{className:`conv-rail-sort-degraded`,children:`Cost/Project sort unavailable while indexing — showing recent order.`})]});if(a)return(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,(0,B.jsxs)(`div`,{className:`conv-rail-empty`,children:[a,(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-retry`,onClick:()=>d(),children:`Retry`})]})]});if(i&&r.length===0)return(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,(0,B.jsx)(`div`,{className:`conv-rail-empty`,children:`Loading…`})]});if(r.length===0)return _d(f)?(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,(0,B.jsxs)(`div`,{className:`conv-rail-empty conv-rail-empty--filtered`,children:[(0,B.jsx)(`div`,{children:`No conversations match these filters.`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-empty-clear`,onClick:()=>z({type:`CLEAR_CONVERSATION_FILTERS`}),children:`Clear filters`})]})]}):(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,(0,B.jsx)(`div`,{className:`conv-rail-empty`,children:`No conversations.`})]});let h=u?`recent`:p,g=h===`project`,v=null,y=Date.now(),b=ud(r)||g;return(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,r.map(r=>{let i=$u(h,r,t.tz,y),a=i===null?null:i.toLowerCase(),o=i!==null&&a!==v;return a!==null&&(v=a),(0,B.jsxs)(_.Fragment,{children:[o&&(0,B.jsx)(`div`,{className:`conv-rail-sec${g?` conv-rail-sec--project`:``}`,title:g?i??void 0:void 0,children:i}),(0,B.jsx)(Sd,{row:r,ctx:t,active:r.session_id===e,pickAnchor:n,hideProject:b})]},r.session_id)}),o&&(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-more`,disabled:c,onClick:()=>void s(),children:c?`Loading…`:`Load more`})]})}function Sd({row:e,ctx:t,active:n,pickAnchor:r,hideProject:i}){let a=r===e.session_id,o=sr(e.models);return(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-row${n?` is-active`:``}${r?` conv-rail-row--pick`:``}${a?` conv-rail-row--anchor`:``}`,disabled:a,"aria-disabled":a||void 0,title:a?`This is the anchor session`:void 0,onClick:bd(r,e.session_id,()=>z({type:`SELECT_CONVERSATION`,sessionId:e.session_id})),children:[(0,B.jsx)(`div`,{className:`conv-rail-row-title`,children:e.title}),(0,B.jsxs)(`div`,{className:`conv-rail-row-meta`,children:[(0,B.jsxs)(`span`,{className:`conv-rail-row-metaleft`,children:[!i&&(0,B.jsx)(`span`,{className:`conv-rail-row-project`,children:e.project_label||`—`}),(0,B.jsx)(`span`,{className:`conv-rail-row-branch`,children:e.git_branch??`—`})]}),(0,B.jsx)(`span`,{className:`conv-rail-row-when`,children:F.startedShort(e.last_activity_utc,t,{noSuffix:!0})}),o.classes.length>0&&(0,B.jsxs)(`span`,{className:`conv-rail-row-model`,children:[o.classes.map(e=>(0,B.jsx)(`span`,{className:`chip ${e}`,children:e},e)),o.extra>0&&(0,B.jsxs)(`span`,{className:`conv-rail-row-model-more`,children:[`+`,o.extra]})]}),(0,B.jsxs)(`span`,{className:`conv-rail-row-cluster`,children:[(0,B.jsx)(`span`,{className:`conv-rail-row-cost`,children:F.usd2(e.cost_usd)}),(0,B.jsx)(`span`,{className:`conv-rail-row-msgs`,children:e.msg_count})]})]})]})}function Cd({kind:e,proseOnly:t}){let n=null;return(0,B.jsx)(`div`,{className:`conv-rail-chips`,role:`radiogroup`,"aria-label":`Search kind`,children:md.map(r=>{let i=r.needsSplit&&t,a=e===r.kind,o=n!==null&&r.group!==n;return n=r.group,(0,B.jsxs)(_.Fragment,{children:[o&&(0,B.jsx)(`span`,{className:`conv-rail-chips-break`,"aria-hidden":`true`}),(0,B.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":a,disabled:i,title:i?`indexing…`:void 0,className:`conv-rail-chip${a?` is-on`:``}`,onClick:()=>z({type:`SET_CONVERSATION_SEARCH_KIND`,kind:r.kind}),children:r.label})]},r.kind)})})}function wd({needle:e,kind:t,ctx:n,selectedId:r,pickAnchor:i}){let{hits:a,mode:o,total:s,loading:c,loadingMore:l,searchDepth:u,filterDegraded:d,error:f,loadMore:p}=Ju(e,t),m=u===`prose-only`,h=s-a.length,g=m&&(t===`tools`||t===`thinking`),_=(s===0?`No results`:`${s} results${o===`like`?` · basic search`:``}`)+(g?` · indexing…`:``),v=s===0&&!c&&!f;return(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[(0,B.jsx)(Cd,{kind:t,proseOnly:m}),d&&(0,B.jsx)(`div`,{className:`conv-rail-search-filters-degraded`,children:`Some filters unavailable while indexing.`}),f?(0,B.jsx)(`div`,{className:`conv-rail-empty`,role:`alert`,children:f}):c&&a.length===0?(0,B.jsx)(`div`,{className:`conv-rail-empty`,role:`status`,children:`Searching…`}):v?(0,B.jsxs)(`div`,{className:`conv-rail-noresults`,role:`status`,children:[(0,B.jsxs)(`div`,{className:`conv-rail-noresults-q`,children:[`No results for “`,e.length>40?e.slice(0,40)+`…`:e,`”`,g?` · indexing…`:``]}),t!==`all`&&(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-noresults-action`,onClick:()=>z({type:`SET_CONVERSATION_SEARCH_KIND`,kind:`all`}),children:`Search all conversations`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-noresults-action`,onClick:()=>z({type:`SET_CONVERSATION_SEARCH`,text:``}),children:`Clear search`})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`conv-rail-count`,"aria-live":`polite`,children:_}),a.map((e,a)=>(0,B.jsx)(Td,{hit:e,ctx:n,kind:t,selectedId:r,pickAnchor:i},`${e.session_id}-${e.uuid}-${a}`)),a.length<s&&(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-more`,disabled:l,onClick:()=>p(),children:[`Load `,Math.min(50,h),` more (`,h,` remaining)`]})]})]})}function Td({hit:e,ctx:t,kind:n,selectedId:r,pickAnchor:i}){let a=e.match_kinds??[],o=a.includes(`file`),s=fd(a,n),c=i===e.session_id;return(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-row conv-rail-row--hit${e.session_id===r?` is-active`:``}${o?` conv-rail-row--filehit`:``}${i?` conv-rail-row--pick`:``}${c?` conv-rail-row--anchor`:``}`,disabled:c,"aria-disabled":c||void 0,title:c?`This is the anchor session`:void 0,onClick:bd(i,e.session_id,()=>z({type:`OPEN_CONVERSATION`,sessionId:e.session_id,jump:{session_id:e.session_id,uuid:e.uuid}})),children:[o?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`conv-rail-row-title conv-rail-row-title--hit`,children:[(0,B.jsx)(`span`,{className:`conv-rail-row-filepath conv-rail-row-title-text`,children:e.snippet}),s.length>0&&(0,B.jsx)(Ed,{badges:s})]}),(0,B.jsx)(`div`,{className:`conv-rail-row-filetitle`,children:e.title})]}):(0,B.jsxs)(`div`,{className:`conv-rail-row-title conv-rail-row-title--hit`,children:[(0,B.jsx)(`span`,{className:`conv-rail-row-title-text`,children:e.title}),s.length>0&&(0,B.jsx)(Ed,{badges:s})]}),(0,B.jsxs)(`div`,{className:`conv-rail-row-meta`,children:[(0,B.jsx)(`span`,{className:`conv-rail-row-metaleft`,children:(0,B.jsx)(`span`,{className:`conv-rail-row-project`,children:e.project_label||`—`})}),(0,B.jsx)(`span`,{className:`conv-rail-row-when`,children:F.startedShort(e.ts,t,{noSuffix:!0})})]}),!o&&(0,B.jsx)(`div`,{className:`conv-rail-row-snippet`,children:Yu(e.snippet)})]})}function Ed({badges:e}){return(0,B.jsx)(`span`,{className:`conv-rail-kindbs`,children:e.map(e=>(0,B.jsx)(`span`,{className:`conv-rail-kindb`,children:hd[e]??e},e))})}var Dd=0,Od=1,kd=2,Ad=4;function jd(e){return()=>e}function Md(e){e()}function Nd(e,t){return n=>e(t(n))}function Pd(e,t){return()=>e(t)}function Fd(e,t){return n=>e(t,n)}function Id(e){return e!==void 0}function Ld(...e){return()=>{e.map(Md)}}function Rd(){}function zd(e,t){return t(e),e}function Bd(e,t){return t(e)}function Vd(...e){return e}function Hd(e,t){return e(Od,t)}function Ud(e,t){e(Dd,t)}function Wd(e){e(kd)}function Gd(e){return e(Ad)}function W(e,t){return Hd(e,Fd(t,Dd))}function Kd(e,t){let n=e(Od,e=>{n(),t(e)});return n}function qd(e){let t,n;return r=>i=>{t=i,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Jd(e,t){return e===t}function Yd(e=Jd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function G(e){return t=>n=>{e(n)&&t(n)}}function K(e){return t=>Nd(t,e)}function Xd(e){return t=>()=>{t(e)}}function q(e,...t){let n=tf(...t);return((t,r)=>{switch(t){case kd:Wd(e);return;case Od:return Hd(e,n(r))}})}function Zd(e,t){return n=>r=>{n(t=e(t,r))}}function Qd(e){return t=>n=>{e>0?e--:t(n)}}function $d(e){let t=null,n;return r=>i=>{t=i,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function ef(...e){let t=Array(e.length),n=0,r=null,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;Hd(e,e=>{let s=n;n|=o,t[a]=e,s!==i&&n===i&&r&&(r(),r=null)})}),e=>a=>{let o=()=>{e([a].concat(t))};n===i?o():r=o}}function tf(...e){return t=>e.reduceRight(Bd,t)}function nf(e){let t,n,r=()=>t?.();return function(i,a){switch(i){case Od:return a?n===a?void 0:(r(),n=a,t=Hd(e,a),t):(r(),Rd);case kd:r(),n=null;return}}}function J(e){let t=e,n=af();return((e,r)=>{switch(e){case Dd:t=r;break;case Od:r(t);break;case Ad:return t}return n(e,r)})}function rf(e,t){return zd(J(t),t=>W(e,t))}function af(){let e=[];return((t,n)=>{switch(t){case Dd:e.slice().forEach(e=>{e(n)});return;case kd:e.splice(0,e.length);return;case Od:return e.push(n),()=>{let t=e.indexOf(n);t>-1&&e.splice(t,1)}}})}function of(e){return zd(af(),t=>W(e,t))}function sf(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:cf(),singleton:n}}var cf=()=>Symbol();function lf(e){let t=new Map,n=({constructor:e,dependencies:r,id:i,singleton:a})=>{if(a&&t.has(i))return t.get(i);let o=e(r.map(e=>n(e)));return a&&t.set(i,o),o};return n(e)}function uf(...e){let t=af(),n=Array(e.length),r=0,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;Hd(e,e=>{n[a]=e,r|=o,r===i&&Ud(t,n)})}),function(e,a){switch(e){case kd:Wd(t);return;case Od:return r===i&&a(n),Hd(t,a)}}}function Y(e,t=Jd){return q(e,Yd(t))}function df(...e){return function(t,n){switch(t){case kd:return;case Od:return Ld(...e.map(e=>Hd(e,n)))}}}var ff={DEBUG:0,INFO:1,WARN:2,ERROR:3},pf={[ff.DEBUG]:`debug`,[ff.ERROR]:`error`,[ff.INFO]:`log`,[ff.WARN]:`warn`},mf=()=>typeof globalThis>`u`?window:globalThis,hf=sf(()=>{let e=J(ff.ERROR);return{log:J((t,n,r=ff.INFO)=>{r>=(mf().VIRTUOSO_LOG_LEVEL??Gd(e))&&console[pf[r]](`%creact-virtuoso: %c%s %o`,`color: #0253b3; font-weight: bold`,`color: initial`,t,n)}),logLevel:e}},[],{singleton:!0}),gf=new WeakMap;function _f(e){return`self`in e?e.document.documentElement:e}function vf(e){let t=_f(e),n=gf.get(t);if(n!==void 0)return n;let r=t.ownerDocument.defaultView.getComputedStyle(t).direction===`rtl`;return gf.set(t,r),r}function yf(e){gf.delete(_f(e))}function bf(e,t){return vf(e)?-t:t}var xf=bf;function Sf(e,t){return bf(e,t)}function Cf(e,t,n){return wf(e,t,n).callbackRef}function wf(e,t,n){let r=_.useRef(null),i=e=>{},a=_.useMemo(()=>typeof ResizeObserver<`u`?new ResizeObserver(t=>{let r=()=>{let n=t[0].target;n.offsetParent!==null&&e(n)};n?r():requestAnimationFrame(r)}):null,[e,n]);return i=e=>{e&&t?(a?.observe(e),r.current=e):(r.current&&a?.unobserve(r.current),r.current=null)},{callbackRef:i,ref:r}}function Tf(e,t,n,r,i,a,o,s,c){return wf(_.useCallback(n=>{let c=Ef(n.children,t,s?`offsetWidth`:`offsetHeight`,i),l=n.parentElement;for(;l.dataset.virtuosoScroller===void 0;)l=l.parentElement;let u=l.lastElementChild.dataset.viewportType===`window`,d;u&&(d=l.ownerDocument.defaultView);let f=o?s?o.scrollWidth:o.scrollHeight:u?s?d.document.documentElement.scrollWidth:d.document.documentElement.scrollHeight:s?l.scrollWidth:l.scrollHeight,p=o?s?o.offsetWidth:o.offsetHeight:u?s?d.innerWidth:d.innerHeight:s?l.offsetWidth:l.offsetHeight,m=o?s?xf(o,o.scrollLeft):o.scrollTop:u?s?xf(d,d.scrollX||d.document.documentElement.scrollLeft):d.scrollY||d.document.documentElement.scrollTop:s?xf(l,l.scrollLeft):l.scrollTop;r({scrollHeight:f,scrollTop:Math.max(m,0),viewportHeight:p}),a?.(s?Df(`column-gap`,getComputedStyle(n).columnGap,i):Df(`row-gap`,getComputedStyle(n).rowGap,i)),c!==null&&e(c)},[e,t,i,a,o,r,s]),n,c)}function Ef(e,t,n,r){let i=e.length;if(i===0)return null;let a=[];for(let o=0;o<i;o++){let i=e.item(o);if(i.dataset.index===void 0)continue;let s=parseInt(i.dataset.index),c=parseFloat(i.dataset.knownSize),l=t(i,n);if(l===0&&r(`Zero-sized element, this should not happen`,{child:i},ff.ERROR),l===c)continue;let u=a[a.length-1];a.length===0||u.size!==l||u.endIndex!==s-1?a.push({endIndex:s,size:l,startIndex:s}):a[a.length-1].endIndex++}return a}function Df(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,ff.WARN),t===`normal`?0:parseInt(t??`0`,10)}function Of(e,t,n){let r=_.useRef(null),i=_.useCallback(n=>{if(!n?.offsetParent)return;let i=n.getBoundingClientRect(),a=i.width,s,c;if(t){let e=t.getBoundingClientRect(),n=i.top-e.top;c=e.height-Math.max(0,n),s=n+t.scrollTop}else{let e=o.current.ownerDocument.defaultView;c=e.innerHeight-Math.max(0,i.top),s=i.top+e.scrollY}r.current={listHeight:i.height,offsetTop:s,visibleHeight:c,visibleWidth:a},e(r.current)},[e,t]),{callbackRef:a,ref:o}=wf(i,!0,n),s=_.useCallback(()=>{i(o.current)},[i,o]);return _.useEffect(()=>{if(t){t.addEventListener(`scroll`,s);let e=new ResizeObserver(()=>{requestAnimationFrame(s)});return e.observe(t),()=>{t.removeEventListener(`scroll`,s),e.unobserve(t)}}let e=o.current?.ownerDocument.defaultView;return e?.addEventListener(`scroll`,s),e?.addEventListener(`resize`,s),()=>{e?.removeEventListener(`scroll`,s),e?.removeEventListener(`resize`,s)}},[s,t,o]),a}var kf=sf(()=>{let e=af(),t=af(),n=J(0),r=af(),i=J(0),a=af(),o=af(),s=J(0),c=J(0),l=J(0),u=J(0),d=af(),f=af(),p=J(!1),m=J(!1),h=J(!1);return W(q(e,K(({scrollTop:e})=>e)),t),W(q(e,K(({scrollHeight:e})=>e)),o),W(t,i),{deviation:n,fixedFooterHeight:l,fixedHeaderHeight:c,footerHeight:u,headerHeight:s,horizontalDirection:m,scrollBy:f,scrollContainerState:e,scrollHeight:o,scrollingInProgress:p,scrollTo:d,scrollTop:t,skipAnimationFrameInResizeObserver:h,smoothScrollTargetReached:r,statefulScrollTop:i,viewportHeight:a}},[],{singleton:!0}),Af={lvl:0};function jf(e,t){let n=e.length;if(n===0)return[];let{index:r,value:i}=t(e[0]),a=[];for(let o=1;o<n;o++){let{index:n,value:s}=t(e[o]);a.push({end:n-1,start:r,value:i}),r=n,i=s}return a.push({end:1/0,start:r,value:i}),a}function Mf(e){return e===Af}function Nf(e,t){if(!Mf(e))return t===e.k?e.v:t<e.k?Nf(e.l,t):Nf(e.r,t)}function Pf(e,t,n=`k`){if(Mf(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){let r=Pf(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Pf(e.l,t,n)}function Ff(e,t,n){return Mf(e)?Kf(t,n,1):t===e.k?Hf(e,{k:t,v:n}):t<e.k?qf(Hf(e,{l:Ff(e.l,t,n)})):qf(Hf(e,{r:Ff(e.r,t,n)}))}function If(){return Af}function Lf(e,t,n){if(Mf(e))return[];let r=Pf(e,t)[0];return Xf(Bf(e,r,n))}function Rf(e,t){if(Mf(e))return Af;let{k:n,l:r,r:i}=e;if(t===n){if(Mf(r))return i;if(Mf(i))return r;let[t,n]=Gf(r);return Vf(Hf(e,{k:t,l:Uf(r),v:n}))}return Vf(t<n?Hf(e,{l:Rf(r,t)}):Hf(e,{r:Rf(i,t)}))}function zf(e){return Mf(e)?[]:[...zf(e.l),{k:e.k,v:e.v},...zf(e.r)]}function Bf(e,t,n){if(Mf(e))return[];let{k:r,l:i,r:a,v:o}=e,s=[];return r>t&&(s=s.concat(Bf(i,t,n))),r>=t&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(Bf(a,t,n))),s}function Vf(e){let{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(Wf(t))return Jf(Hf(e,{lvl:n-1}));if(!Mf(t)&&!Mf(t.r))return Hf(t.r,{l:Hf(t,{r:t.r.l}),lvl:n,r:Hf(e,{l:t.r.r,lvl:n-1})});throw Error(`Unexpected empty nodes`)}if(Wf(e))return Yf(Hf(e,{lvl:n-1}));if(!Mf(r)&&!Mf(r.l)){let t=r.l,i=Wf(t)?r.lvl-1:r.lvl;return Hf(t,{l:Hf(e,{lvl:n-1,r:t.l}),lvl:t.lvl+1,r:Yf(Hf(r,{l:t.r,lvl:i}))})}throw Error(`Unexpected empty nodes`)}function Hf(e,t){return Kf(t.k===void 0?e.k:t.k,t.v===void 0?e.v:t.v,t.lvl===void 0?e.lvl:t.lvl,t.l===void 0?e.l:t.l,t.r===void 0?e.r:t.r)}function Uf(e){return Mf(e.r)?e.l:Vf(Hf(e,{r:Uf(e.r)}))}function Wf(e){return Mf(e)||e.lvl>e.r.lvl}function Gf(e){return Mf(e.r)?[e.k,e.v]:Gf(e.r)}function Kf(e,t,n,r=Af,i=Af){return{k:e,l:r,lvl:n,r:i,v:t}}function qf(e){return Yf(Jf(e))}function Jf(e){let{l:t}=e;return!Mf(t)&&t.lvl===e.lvl?Hf(t,{r:Hf(e,{l:t.r})}):e}function Yf(e){let{lvl:t,r:n}=e;return!Mf(n)&&!Mf(n.r)&&n.lvl===t&&n.r.lvl===t?Hf(n,{l:Hf(e,{r:n.l}),lvl:t+1}):e}function Xf(e){return jf(e,({k:e,v:t})=>({index:e,value:t}))}function Zf(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Qf(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}var $f=sf(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function ep(e,t,n){return e[tp(e,t,n)]}function tp(e,t,n,r=0){let i=e.length-1;for(;r<=i;){let a=Math.floor((r+i)/2),o=e[a],s=n(o,t);if(s===0)return a;if(s===-1){if(i-r<2)return a-1;i=a-1}else{if(i===r)return a;r=a+1}}throw Error(`Failed binary finding record in array - ${e.join(`,`)}, searched for ${t}`)}function np(e,t,n,r){let i=tp(e,t,r),a=tp(e,n,r,i);return e.slice(i,a+1)}function rp(e,t){return Math.round(e.getBoundingClientRect()[t])}function ip(e){return!Mf(e.groupOffsetTree)}function ap({index:e},t){return t===e?0:t<e?-1:1}function op(){return{groupIndices:[],groupOffsetTree:If(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:If()}}function sp(e,t){let n=Mf(e)?0:1/0;for(let r of t){let{endIndex:t,size:i,startIndex:a}=r;if(n=Math.min(n,a),Mf(e)){e=Ff(e,0,i);continue}let o=Lf(e,a-1,t+1);if(o.some(yp(r)))continue;let s=!1,c=!1;for(let{end:n,start:r,value:a}of o)s?(t>=r||i===a)&&(e=Rf(e,r)):(c=a!==i,s=!0),n>t&&t>=r&&a!==i&&(e=Ff(e,t+1,a));c&&(e=Ff(e,a,i))}return[e,n]}function cp(e){return typeof e.groupIndex<`u`}function lp({offset:e},t){return t===e?0:t<e?-1:1}function up(e,t,n){if(t.length===0)return 0;let{index:r,offset:i,size:a}=ep(t,e,ap),o=e-r,s=a*o+(o-1)*n+i;return s>0?s+n:s}function dp(e,t){if(!ip(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function fp(e,t,n){if(cp(e))return t.groupIndices[e.groupIndex]+1;let r=dp(e.index===`LAST`?n:e.index,t);return r=Math.max(0,r,Math.min(n,r)),r}function pp(e,t,n,r=0){return r>0&&(t=Math.max(t,ep(e,r,ap).offset)),jf(np(e,t,n,lp),vp)}function mp(e,[t,n,r,i]){t.length>0&&r(`received item sizes`,t,ff.DEBUG);let a=e.sizeTree,o=a,s=0;if(n.length>0&&Mf(a)&&t.length===2){let e=t[0].size,r=t[1].size;o=n.reduce((t,n)=>Ff(Ff(t,n,e),n+1,r),o)}else [o,s]=sp(o,t);if(o===a)return e;let{lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d}=_p(e.offsetTree,s,o,i);return{groupIndices:n,groupOffsetTree:n.reduce((e,t)=>Ff(e,t,up(t,d,i)),If()),lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d,sizeTree:o}}function hp(e){return zf(e).map(({k:e,v:t},n,r)=>{let i=r[n+1];return{endIndex:i===void 0?1/0:i.k-1,size:t,startIndex:e}})}function gp(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function _p(e,t,n,r){let i=e,a=0,o=0,s=0,c=0;if(t!==0){c=tp(i,t-1,ap),s=i[c].offset;let e=Pf(n,t-1);a=e[0],o=e[1],i.length&&i[c].size===Pf(n,t)[1]&&--c,i=i.slice(0,c+1)}else i=[];for(let{start:e,value:c}of Lf(n,t,1/0)){let t=e-a,n=t*o+s+t*r;i.push({index:e,offset:n,size:c}),a=e,s=n,o=c}return{lastIndex:a,lastOffset:s,lastSize:o,offsetTree:i}}function vp(e){return{index:e.index,value:e}}function yp(e){let{endIndex:t,size:n,startIndex:r}=e;return e=>e.start===r&&(e.end===t||e.end===1/0)&&e.value===n}var bp={offsetHeight:`height`,offsetWidth:`width`},xp=sf(([{log:e},{recalcInProgress:t}])=>{let n=af(),r=af(),i=rf(r,0),a=af(),o=af(),s=J(0),c=J([]),l=J(void 0),u=J(void 0),d=J(void 0),f=J(void 0),p=J((e,t)=>rp(e,bp[t])),m=J(void 0),h=J(0),g=op(),_=rf(q(n,ef(c,e,h),Zd(mp,g),Yd()),g),v=rf(q(c,Yd(),Zd((e,t)=>({current:t,prev:e.current}),{current:[],prev:[]}),K(({prev:e})=>e)),[]);W(q(c,G(e=>e.length>0),ef(_,h),K(([e,t,n])=>{let r=e.reduce((e,r,i)=>Ff(e,r,up(r,t.offsetTree,n)||i),If());return{...t,groupIndices:e,groupOffsetTree:r}})),_),W(q(r,ef(_),G(([e,{lastIndex:t}])=>e<t),K(([e,{lastIndex:t,lastSize:n}])=>[{endIndex:t,size:n,startIndex:e}])),n),W(l,u);let y=rf(q(l,K(e=>e===void 0)),!0);W(q(u,G(e=>e!==void 0&&Mf(Gd(_).sizeTree)),K(e=>{let t=Gd(d),n=Gd(c).length>0;return t!==void 0&&t!==0?n?[{endIndex:0,size:t,startIndex:0},{endIndex:1,size:e,startIndex:1}]:[]:[{endIndex:0,size:e,startIndex:0}]})),n),W(q(f,G(e=>e!==void 0&&e.length>0&&Mf(Gd(_).sizeTree)),K(e=>{let t=[],n=e[0],r=0;for(let i=1;i<e.length;i++){let a=e[i];a!==n&&(t.push({endIndex:i-1,size:n,startIndex:r}),n=a,r=i)}return t.push({endIndex:e.length-1,size:n,startIndex:r}),t})),n),W(q(c,ef(d,u),G(([,e,t])=>e!==void 0&&t!==void 0),K(([e,t,n])=>{let r=[];for(let i=0;i<e.length;i++){let a=e[i],o=e[i+1];r.push({startIndex:a,endIndex:a,size:t}),o!==void 0&&r.push({startIndex:a+1,endIndex:o-1,size:n})}return r})),n);let b=of(q(n,ef(_),Zd(({sizes:e},[t,n])=>({changed:n!==e,sizes:n}),{changed:!1,sizes:g}),K(e=>e.changed)));Hd(q(s,Zd((e,t)=>({diff:e.prev-t,prev:t}),{diff:0,prev:0}),K(e=>e.diff)),e=>{let{groupIndices:n}=Gd(_);if(e>0)Ud(t,!0),Ud(a,e+gp(e,n));else if(e<0){let t=Gd(v);t.length>0&&(e-=gp(-e,t)),Ud(o,e)}}),Hd(q(s,ef(e)),([e,t])=>{e<0&&t("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:s},ff.ERROR)});let x=of(a);W(q(a,ef(_),K(([e,t])=>{let n=t.groupIndices.length>0,r=[],i=t.lastSize;if(n){let n=Nf(t.sizeTree,0),a=0,o=0;for(;a<e;){let e=t.groupIndices[o],s=t.groupIndices.length===o+1?1/0:t.groupIndices[o+1]-e-1;r.push({endIndex:e,size:n,startIndex:e}),r.push({endIndex:e+1+s-1,size:i,startIndex:e+1}),o++,a+=s+1}let s=zf(t.sizeTree);return a!==e&&s.shift(),s.reduce((t,{k:n,v:r})=>{let i=t.ranges;return t.prevSize!==0&&(i=[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]),{prevIndex:n+e,prevSize:r,ranges:i}},{prevIndex:e,prevSize:0,ranges:r}).ranges}return zf(t.sizeTree).reduce((t,{k:n,v:r})=>({prevIndex:n+e,prevSize:r,ranges:[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]}),{prevIndex:0,prevSize:i,ranges:[]}).ranges})),n);let S=of(q(o,ef(_,h),K(([e,{offsetTree:t},n])=>up(-e,t,n))));return W(q(o,ef(_,h),K(([e,t,n])=>{if(t.groupIndices.length>0){if(Mf(t.sizeTree))return t;let r=If(),i=Gd(v),a=0,o=0,s=0;for(;a<-e;){s=i[o];let e=i[o+1]-s-1;o++,a+=e+1}if(r=zf(t.sizeTree).reduce((t,{k:n,v:r})=>Ff(t,Math.max(0,n+e),r),r),a!==-e){let n=Nf(t.sizeTree,s);r=Ff(r,0,n);let i=Pf(t.sizeTree,-e+1)[1];r=Ff(r,1,i)}return{...t,sizeTree:r,..._p(t.offsetTree,0,r,n)}}let r=zf(t.sizeTree).reduce((t,{k:n,v:r})=>Ff(t,Math.max(0,n+e),r),If());return{...t,sizeTree:r,..._p(t.offsetTree,0,r,n)}})),_),{beforeUnshiftWith:x,data:m,defaultItemSize:u,firstItemIndex:s,fixedItemSize:l,fixedGroupSize:d,gap:h,groupIndices:c,heightEstimates:f,itemSize:p,listRefresh:b,shiftWith:o,shiftWithOffset:S,sizeRanges:n,sizes:_,statefulTotalCount:i,totalCount:r,trackItemSizes:y,unshiftWith:a}},Vd(hf,$f),{singleton:!0});function Sp(e){return e.reduce((e,t)=>(e.groupIndices.push(e.totalCount),e.totalCount+=t+1,e),{groupIndices:[],totalCount:0})}var Cp=sf(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:i}])=>{let a=af(),o=af(),s=of(q(a,K(Sp)));return W(q(s,K(e=>e.totalCount)),n),W(q(s,K(e=>e.groupIndices)),e),W(q(uf(i,t,r),G(([e,t])=>ip(t)),K(([e,t,n])=>Pf(t.groupOffsetTree,Math.max(e-n,0),`v`)[0]),Yd(),K(e=>[e])),o),{groupCounts:a,topItemsIndexes:o}},Vd(xp,kf)),wp=sf(([{log:e}])=>{let t=J(!1),n=of(q(t,G(e=>e),Yd()));return Hd(t,t=>{t&&Gd(e)(`props updated`,{},ff.DEBUG)}),{didMount:n,propsReady:t}},Vd(hf),{singleton:!0}),Tp=typeof document<`u`&&`scrollBehavior`in document.documentElement.style;function Ep(e){let t=typeof e==`number`?{index:e}:e;return t.align||=`start`,(!t.behavior||!Tp)&&(t.behavior=`auto`),t.offset===void 0&&(t.offset=0),t}var Dp=sf(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:i,fixedHeaderHeight:a,footerHeight:o,headerHeight:s,scrollingInProgress:c,scrollTo:l,smoothScrollTargetReached:u,viewportHeight:d},{log:f}])=>{let p=af(),m=af(),h=J(0),g=null,_=null,v=null;function y(){g!==null&&(g(),g=null),v!==null&&(v(),v=null),_&&=(clearTimeout(_),null),Ud(c,!1)}return W(q(p,ef(n,d,r,h,s,o,f),ef(e,a,i),K(([[e,n,r,i,a,o,s,l],d,f,h])=>{let b=Ep(e),{align:x,behavior:S,offset:C}=b,w=i-1,T=fp(b,n,w),E=up(T,n.offsetTree,d)+o;x===`end`?(E+=f+Pf(n.sizeTree,T)[1]-r+h,T===w&&(E+=s)):x===`center`?E+=(f+Pf(n.sizeTree,T)[1]-r+h)/2:E-=a,C!==void 0&&C!==0&&(E+=C);let D=t=>{y(),t?(l(`retrying to scroll to`,{location:e},ff.DEBUG),Ud(p,e)):(Ud(m,!0),l(`list did not change, scroll successful`,{},ff.DEBUG))};if(y(),S===`smooth`){let e=!1;v=Hd(t,t=>{e||=t}),g=Kd(u,()=>{D(e)})}else g=Kd(q(t,Op(150)),D);return _=setTimeout(()=>{y()},1200),Ud(c,!0),l(`scrolling from index to`,{behavior:S,index:T,top:E},ff.DEBUG),{behavior:S,top:E}})),l),{scrollTargetReached:m,scrollToIndex:p,topListHeight:h}},Vd(xp,kf,hf),{singleton:!0});function Op(e){return t=>{let n=setTimeout(()=>{t(!1)},e);return e=>{e&&(t(!0),clearTimeout(n))}}}function kp(e,t){e===0?t():requestAnimationFrame(()=>{kp(e-1,t)})}function Ap(e,t){let n=t-1;return typeof e==`number`?e:e.index===`LAST`?n:e.index}var jp=sf(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:i,scrollToIndex:a},{didMount:o}])=>{let s=J(!0),c=J(0),l=J(!0);return W(q(o,ef(c),G(([e,t])=>t!==0),Xd(!1)),s),W(q(o,ef(c),G(([e,t])=>t!==0),Xd(!1)),l),Hd(q(uf(t,o),ef(s,n,e,l),G(([[,e],t,{sizeTree:n},r,i])=>e&&(!Mf(n)||Id(r))&&!t&&!i),ef(c)),([,e])=>{Kd(i,()=>{Ud(l,!0)}),kp(4,()=>{Kd(r,()=>{Ud(s,!0)}),Ud(a,e)})}),{initialItemFinalLocationReached:l,initialTopMostItemIndex:c,scrolledToInitialItem:s}},Vd(xp,kf,Dp,wp),{singleton:!0});function Mp(e,t){return Math.abs(e-t)<1.01}var Np=`up`,Pp=`down`,Fp=`none`,Ip={atBottom:!1,notAtBottomBecause:`NOT_SHOWING_LAST_ITEM`,state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Lp=0,Rp=sf(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:i,viewportHeight:a}])=>{let o=J(!1),s=J(!0),c=af(),l=af(),u=J(4),d=J(Lp),f=rf(q(df(q(Y(i),Qd(1),Xd(!0)),q(Y(i),Qd(1),Xd(!1),qd(100))),Yd()),!1),p=rf(q(df(q(n,Xd(!0)),q(n,Xd(!1),qd(200))),Yd()),!1);W(q(uf(Y(i),Y(d)),K(([e,t])=>e<=t),Yd()),s),W(q(s,$d(50)),l);let m=of(q(uf(r,Y(a),Y(t),Y(e),Y(u)),Zd((e,[{scrollHeight:t,scrollTop:n},r,i,a,o])=>{let s=n+r-t>-o,c={scrollHeight:t,scrollTop:n,viewportHeight:r};if(s){let t,r;return n>e.state.scrollTop?(t=`SCROLLED_DOWN`,r=e.state.scrollTop-n):(t=`SIZE_DECREASED`,r=e.state.scrollTop-n||e.scrollTopDelta),{atBottom:!0,atBottomBecause:t,scrollTopDelta:r,state:c}}let l;return l=c.scrollHeight>e.state.scrollHeight?`SIZE_INCREASED`:r<e.state.viewportHeight?`VIEWPORT_HEIGHT_DECREASING`:n<e.state.scrollTop?`SCROLLING_UPWARDS`:`NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM`,{atBottom:!1,notAtBottomBecause:l,state:c}},Ip),Yd((e,t)=>e!==void 0&&e.atBottom===t.atBottom))),h=rf(q(r,Zd((e,{scrollHeight:t,scrollTop:n,viewportHeight:r})=>{if(!Mp(e.scrollHeight,t)){let i=t-(n+r)<1;return e.scrollTop!==n&&i?{changed:!0,jump:e.scrollTop-n,scrollHeight:t,scrollTop:n}:{changed:!0,jump:0,scrollHeight:t,scrollTop:n}}return{changed:!1,jump:0,scrollHeight:t,scrollTop:n}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),G(e=>e.changed),K(e=>e.jump)),0);W(q(m,K(e=>e.atBottom)),o),W(q(o,$d(50)),c);let g=J(Pp);W(q(r,K(({scrollTop:e})=>e),Yd(),Zd((e,t)=>Gd(p)?{direction:e.direction,prevScrollTop:t}:{direction:t<e.prevScrollTop?Np:Pp,prevScrollTop:t},{direction:Pp,prevScrollTop:0}),K(e=>e.direction)),g),W(q(r,$d(50),Xd(Fp)),g);let _=J(0);return W(q(f,G(e=>!e),Xd(0)),_),W(q(i,$d(100),ef(f),G(([e,t])=>t),Zd(([e,t],[n])=>[t,n],[0,0]),K(([e,t])=>t-e)),_),{atBottomState:m,atBottomStateChange:c,atBottomThreshold:u,atTopStateChange:l,atTopThreshold:d,isAtBottom:o,isAtTop:s,isScrolling:f,lastJumpDueToItemResize:h,scrollDirection:g,scrollVelocity:_}},Vd(kf)),zp=`top`,Bp=`bottom`,Vp=`none`;function Hp(e,t,n){return typeof e==`number`?n===Np&&t===zp||n===Pp&&t===Bp?e:0:n===Np?t===zp?e.main:e.reverse:t===Bp?e.main:e.reverse}function Up(e,t){return typeof e==`number`?e:e[t]??0}var Wp=sf(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:i}])=>{let a=af(),o=J(0),s=J(0),c=J(0);return{increaseViewportBy:s,listBoundary:a,overscan:c,topListHeight:o,visibleRange:rf(q(uf(Y(r),Y(i),Y(n),Y(a,Qf),Y(c),Y(o),Y(t),Y(e),Y(s)),K(([e,t,n,[r,i],a,o,s,c,l])=>{let u=e-c,d=o+s,f=Math.max(n-u,0),p=Vp,m=Up(l,zp),h=Up(l,Bp);return r-=c,r+=n+s,i+=n+s,i-=c,r>e+d-m&&(p=Np),i<e-f+t+h&&(p=Pp),p===Vp?null:[Math.max(u-n-Hp(a,zp,p)-m,0),u-f-s+t+Hp(a,Bp,p)+h]}),G(e=>e!==null),Yd(Qf)),[0,0])}},Vd(kf),{singleton:!0});function Gp(e,t,n){if(ip(t)){let r=dp(e,t);return[{index:Pf(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n?.[0],index:r,offset:0,size:0}]}return[{data:n?.[0],index:e,offset:0,size:0}]}var Kp={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function qp(e,t,n,r,i,a){let{lastIndex:o,lastOffset:s,lastSize:c}=i,l=0,u=0;if(e.length>0){l=e[0].offset;let t=e[e.length-1];u=t.offset+t.size}let d=n-o,f=s+d*c+(d-1)*r,p=l,m=f-u;return{bottom:u,firstItemIndex:a,items:Yp(e,i,a),offsetBottom:m,offsetTop:l,top:p,topItems:Yp(t,i,a),topListHeight:t.reduce((e,t)=>t.size+e,0),totalCount:n}}function Jp(e,t,n,r,i,a){let o=0;if(n.groupIndices.length>0)for(let t of n.groupIndices){if(t-o>=e)break;o++}let s=e+o,c=Ap(t,s);return qp(Array.from({length:s}).map((e,t)=>({data:a[t+c],index:t+c,offset:0,size:0})),[],s,i,n,r)}function Yp(e,t,n){if(e.length===0)return[];if(!ip(t))return e.map(e=>({...e,index:e.index+n,originalIndex:e.index}));let r=e[0].index,i=e[e.length-1].index,a=[],o=Lf(t.groupOffsetTree,r,i),s,c=0;for(let r of e){(!s||s.end<r.index)&&(s=o.shift(),c=t.groupIndices.indexOf(s.start));let e;e=r.index===s.start?{index:c,type:`group`}:{groupIndex:c,index:r.index-(c+1)+n},a.push({...e,data:r.data,offset:r.offset,originalIndex:r.index,size:r.size})}return a}function Xp(e,t){return e===void 0?0:typeof e==`number`?e:e[t]??0}var Zp=sf(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:i},a,{listBoundary:o,topListHeight:s,visibleRange:c},{initialTopMostItemIndex:l,scrolledToInitialItem:u},{topListHeight:d},f,{didMount:p},{recalcInProgress:m}])=>{let h=J([]),g=J(0),_=af(),v=J(0);W(a.topItemsIndexes,h);let y=rf(q(uf(p,m,Y(c,Qf),Y(i),Y(r),Y(l),u,Y(h),Y(t),Y(n),Y(v),e),G(([e,t,,n,,,,,,,,r])=>{let i=r!==void 0&&r.length!==n;return e&&!t&&!i}),K(([,,[e,t],n,r,i,a,o,s,c,l,u])=>{let d=r,{offsetTree:f,sizeTree:p}=d,m=Gd(g);if(n===0)return{...Kp,totalCount:n};if(e===0&&t===0)return m===0?{...Kp,totalCount:n}:Jp(m,i,r,s,c,u||[]);if(Mf(p))return m>0?null:qp(Gp(Ap(i,n),d,u),[],n,c,d,s);let h=[];if(o.length>0){let e=o[0],t=o[o.length-1],n=0;for(let r of Lf(p,e,t)){let i=r.value,a=Math.max(r.start,e),o=Math.min(r.end,t);for(let e=a;e<=o;e++)h.push({data:u?.[e],index:e,offset:n,size:i}),n+=i}}if(!a)return qp([],h,n,c,d,s);let _=o.length>0?o[o.length-1]+1:0,v=pp(f,e,t,_);if(v.length===0)return null;let y=n-1,b=zd([],n=>{for(let r of v){let i=r.value,a=i.offset,o=r.start,s=i.size;if(i.offset<e){o+=Math.floor((e-i.offset+c)/(s+c));let t=o-r.start;a+=t*s+t*c}o<_&&(a+=(_-o)*s,o=_);let l=Math.min(r.end,y);for(let e=o;e<=l&&!(a>=t);e++)n.push({data:u?.[e],index:e,offset:a,size:s}),a+=s+c}}),x=Xp(l,zp),S=Xp(l,Bp);if(b.length>0&&(x>0||S>0)){let e=b[0],t=b[b.length-1];if(x>0&&e.index>_){let t=Math.min(x,e.index-_),n=[],r=e.offset;for(let i=e.index-1;i>=e.index-t;i--){let t=Lf(p,i,i)[0]?.value??e.size;r-=t+c,n.unshift({data:u?.[i],index:i,offset:r,size:t})}b.unshift(...n)}if(S>0&&t.index<y){let e=Math.min(S,y-t.index),n=t.offset+t.size+c;for(let r=t.index+1;r<=t.index+e;r++){let e=Lf(p,r,r)[0]?.value??t.size;b.push({data:u?.[r],index:r,offset:n,size:e}),n+=e+c}}}return qp(b,h,n,c,d,s)}),G(e=>e!==null),Yd()),Kp);W(q(e,G(Id),K(e=>e?.length)),i),W(q(y,K(e=>e.topListHeight)),d),W(d,s),W(q(y,K(e=>[e.top,e.bottom])),o),W(q(y,K(e=>e.items)),_);let b=of(q(y,G(({items:e})=>e.length>0),ef(i,e),G(([{items:e},t])=>e[e.length-1].originalIndex===t-1),K(([,e,t])=>[e-1,t]),Yd(Qf),K(([e])=>e))),x=of(q(y,$d(200),G(({items:e,topItems:t})=>e.length>0&&e[0].originalIndex===t.length),K(({items:e})=>e[0].index),Yd()));return{endReached:b,initialItemCount:g,itemsRendered:_,listState:y,minOverscanItemCount:v,rangeChanged:of(q(y,G(({items:e})=>e.length>0),K(({items:e})=>{let t=0,n=e.length-1;for(;e[t].type===`group`&&t<n;)t++;for(;e[n].type===`group`&&n>t;)n--;return{endIndex:e[n].index,startIndex:e[t].index}}),Yd(Zf))),startReached:x,topItemsIndexes:h,...f}},Vd(xp,Cp,Wp,jp,Dp,Rp,wp,$f),{singleton:!0}),Qp=sf(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:i}])=>{let a=af(),o=rf(q(uf(n,e,r,t,i),K(([e,t,n,r,i])=>e+t+n+r+i.offsetBottom+i.bottom)),0);return W(Y(o),a),{totalListHeight:o,totalListHeightChanged:a}},Vd(kf,Zp),{singleton:!0}),$p=sf(([{viewportHeight:e},{totalListHeight:t}])=>{let n=J(!1);return{alignToBottom:n,paddingTopAddition:rf(q(uf(n,e,t),G(([e])=>e),K(([,e,t])=>Math.max(0,e-t)),$d(0),Yd()),0)}},Vd(kf,Qp),{singleton:!0}),em=sf(()=>({context:J(null)})),tm=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...i},viewportBottom:a,viewportTop:o})=>t<o?{...i,align:n??`start`,...r===void 0?{}:{behavior:r}}:e>a?{...i,align:n??`end`,...r===void 0?{}:{behavior:r}}:null,nm=sf(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:i,headerHeight:a,scrollingInProgress:o,scrollTop:s,viewportHeight:c},{scrollToIndex:l}])=>{let u=af();return W(q(u,ef(t,c,n,a,i,r,s),ef(e),K(([[e,t,n,r,i,a,s,c],l])=>{let{calculateViewLocation:u=tm,done:d,...f}=e,p=fp(e,t,r-1),m=up(p,t.offsetTree,l)+i+a,h=m+Pf(t.sizeTree,p)[1],g=c+a,_=u({itemBottom:h,itemTop:m,locationParams:f,viewportBottom:c+n-s,viewportTop:g});return _===null?d?.():d&&Kd(q(o,G(e=>!e),Qd(Gd(o)?1:2)),d),_}),G(e=>e!==null)),l),{scrollIntoView:u}},Vd(xp,kf,Dp,Zp,hf),{singleton:!0});function rm(e){return e===!1?!1:e===`smooth`?`smooth`:`auto`}var im=(e,t)=>typeof e==`function`?rm(e(t)):t&&rm(e),am=sf(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:i,isAtBottom:a},{scrollToIndex:o},{scrolledToInitialItem:s},{didMount:c,propsReady:l},{log:u},{scrollingInProgress:d},{context:f},{scrollIntoView:p}])=>{let m=J(!1),h=af(),g=null;function _(e){Ud(o,{align:`end`,behavior:e,index:`LAST`})}Hd(q(uf(q(Y(t),Qd(1)),c),ef(Y(m),a,s,d),K(([[e,t],n,r,i,a])=>{let o=t&&i,s=`auto`;return o&&(s=im(n,r||a),o&&=s!==!1),{followOutputBehavior:s,shouldFollow:o,totalCount:e}}),G(({shouldFollow:e})=>e)),({followOutputBehavior:t,totalCount:r})=>{g!==null&&(g(),g=null),Gd(n)===void 0?g=Kd(e,()=>{Gd(u)(`following output to `,{totalCount:r},ff.DEBUG),_(t),g=null}):requestAnimationFrame(()=>{Gd(u)(`following output to `,{totalCount:r},ff.DEBUG),_(t)})});function v(e){let t=Kd(i,t=>{e&&!t.atBottom&&t.notAtBottomBecause===`SIZE_INCREASED`&&g===null&&(Gd(u)(`scrolling to bottom due to increased size`,{},ff.DEBUG),_(`auto`))});setTimeout(t,100)}Hd(q(uf(Y(m),t,l),G(([e,,t])=>e!==!1&&t),Zd(({value:e},[,t])=>({refreshed:e===t,value:t}),{refreshed:!1,value:0}),G(({refreshed:e})=>e),ef(m,t)),([,e])=>{Gd(s)&&v(e!==!1)}),Hd(h,()=>{v(Gd(m)!==!1)}),Hd(uf(Y(m),i),([e,t])=>{e!==!1&&!t.atBottom&&t.notAtBottomBecause===`VIEWPORT_HEIGHT_DECREASING`&&_(`auto`)});let y=J(null),b=af();return W(df(q(Y(r),K(e=>e?.length??0)),q(Y(t))),b),Hd(q(uf(q(b,Qd(1)),c),ef(Y(y),s,d,f),K(([[e,t],n,r,i,a])=>t&&r&&n?.({context:a,totalCount:e,scrollingInProgress:i})),G(e=>!!e),$d(0)),t=>{g!==null&&(g(),g=null),Gd(n)===void 0?g=Kd(e,()=>{Gd(u)(`scrolling into view`,{}),Ud(p,t),g=null}):requestAnimationFrame(()=>{Gd(u)(`scrolling into view`,{}),Ud(p,t)})}),{autoscrollToBottom:h,followOutput:m,scrollIntoViewOnChange:y}},Vd(xp,Rp,Dp,jp,wp,hf,kf,em,nm)),om=sf(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:i},{initialItemCount:a,listState:o},{didMount:s}])=>(W(q(s,ef(a),G(([,e])=>e!==0),ef(i,r,t,n,e),K(([[,e],t,n,r,i,a=[]])=>Jp(e,t,n,r,i,a))),o),{}),Vd(xp,jp,Zp,wp),{singleton:!0}),sm=sf(([{didMount:e},{scrollTo:t},{listState:n}])=>{let r=J(0);return Hd(q(e,ef(r),G(([,e])=>e!==0),K(([,e])=>({top:e}))),e=>{Kd(q(n,Qd(1),G(e=>e.items.length>1)),()=>{requestAnimationFrame(()=>{Ud(t,e)})})}),{initialScrollTop:r}},Vd(wp,kf,Zp),{singleton:!0}),cm=sf(([{scrollVelocity:e}])=>{let t=J(!1),n=af(),r=J(!1);return W(q(e,ef(r,t,n),G(([e,t])=>t!==!1&&t!==void 0),K(([e,t,n,r])=>{let{enter:i,exit:a}=t;if(n){if(a(e,r))return!1}else if(i(e,r))return!0;return n}),Yd()),t),Hd(q(uf(t,e,n),ef(r)),([[e,t,n],r])=>{e&&r!==!1&&r!==void 0&&r.change&&r.change(t,n)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Vd(Rp),{singleton:!0}),lm=sf(([{scrollContainerState:e,scrollTo:t}])=>{let n=af(),r=af(),i=af(),a=J(!1),o=J(void 0);return W(q(uf(n,r),K(([{scrollTop:e,viewportHeight:t},{offsetTop:n,listHeight:r}])=>({scrollHeight:r,scrollTop:Math.max(0,e-n),viewportHeight:t}))),e),W(q(t,ef(r),K(([e,{offsetTop:t}])=>({...e,top:e.top+t}))),i),{customScrollParent:o,useWindowScroll:a,windowScrollContainerState:n,windowScrollTo:i,windowViewportRect:r}},Vd(kf)),um=sf(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:i},{didMount:a},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:c}])=>{let l=af(),u=J(void 0),d=J(null),f=J(null);return W(s,d),W(c,f),Hd(q(l,ef(t,r,o,d,f,n)),([e,t,n,r,i,a,o])=>{let s=hp(t.sizeTree);r&&i!==null&&a!==null&&(n=i.scrollTop-a.offsetTop),n-=o,e({ranges:s,scrollTop:n})}),W(q(u,G(Id),K(dm)),i),W(q(a,ef(u),G(([,e])=>e!==void 0),Yd(),K(([,e])=>e.ranges)),e),{getState:l,restoreStateFrom:u}},Vd(xp,kf,jp,wp,lm));function dm(e){return{align:`start`,index:0,offset:e.scrollTop}}var fm=sf(([{topItemsIndexes:e}])=>{let t=J(0);return W(q(t,G(e=>e>=0),K(e=>Array.from({length:e}).map((e,t)=>t))),e),{topItemCount:t}},Vd(Zp));function pm(e){let t=!1,n;return(()=>(t||(t=!0,n=e()),n))}var mm=pm(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),hm=sf(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,fixedGroupSize:i,gap:a,groupIndices:o,heightEstimates:s,itemSize:c,sizeRanges:l,sizes:u,statefulTotalCount:d,totalCount:f,trackItemSizes:p},{initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g},_,v,y,b,{scrollToIndex:x},S,{topItemCount:C},{groupCounts:w},T])=>{let{listState:E,minOverscanItemCount:D,topItemsIndexes:O,rangeChanged:k,...A}=b;return W(k,T.scrollSeekRangeChanged),W(q(T.windowViewportRect,K(e=>e.visibleHeight)),_.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,fixedGroupHeight:i,gap:a,groupCounts:w,heightEstimates:s,initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g,sizeRanges:l,topItemCount:C,topItemsIndexes:O,totalCount:f,...y,groupIndices:o,itemSize:c,listState:E,minOverscanItemCount:D,scrollToIndex:x,statefulTotalCount:d,trackItemSizes:p,rangeChanged:k,...A,...T,..._,sizes:u,...v}},Vd(xp,jp,kf,um,am,Zp,Dp,sf(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:i,isScrolling:a,lastJumpDueToItemResize:o,scrollDirection:s},{listState:c},{beforeUnshiftWith:l,gap:u,shiftWithOffset:d,sizes:f},{log:p},{recalcInProgress:m}])=>{let h=of(q(c,ef(o),Zd(([,e,t,n],[{bottom:r,items:i,offsetBottom:a,totalCount:o},s])=>{let c=r+a,l=0;return t===o&&e.length>0&&i.length>0&&(i[0].originalIndex===0&&e[0].originalIndex===0||(l=c-n,l!==0&&(l+=s))),[l,i,o,c]},[0,[],0,0]),G(([e])=>e!==0),ef(r,s,n,i,p,m),G(([,e,t,n,,,r])=>!r&&!n&&e!==0&&t===Np),K(([[e],,,,,t])=>(t(`Upward scrolling compensation`,{amount:e},ff.DEBUG),e))));function g(n){n>0?(Ud(t,{behavior:`auto`,top:-n}),Ud(e,0)):(Ud(e,0),Ud(t,{behavior:`auto`,top:-n}))}return Hd(q(h,ef(e,a)),([t,n,r])=>{r&&mm()?Ud(e,n-t):g(-t)}),Hd(q(uf(rf(a,!1),e,m),G(([e,t,n])=>!e&&!n&&t!==0),K(([e,t])=>t),$d(1)),g),W(q(d,K(e=>({top:-e}))),t),Hd(q(l,ef(f,u),K(([e,{groupIndices:t,lastSize:n,sizeTree:r},i])=>{function a(e){return e*(n+i)}if(t.length===0)return a(e);let o=0,s=Nf(r,0),c=0,l=0;for(;c<e;){c++,o+=s;let n=t.length===l+1?1/0:t[l+1]-t[l]-1;c+n>e&&(o-=s,n=e-c+1),c+=n,o+=a(n),l++}return o})),n=>{Ud(e,n),requestAnimationFrame(()=>{Ud(t,{top:n}),requestAnimationFrame(()=>{Ud(e,0),Ud(m,!1)})})}),{deviation:e}},Vd(kf,Rp,Zp,xp,hf,$f)),fm,Cp,sf(([e,t,n,r,i,a,o,s,c,l,u])=>({...e,...t,...n,...r,...i,...a,...o,...s,...c,...l,...u}),Vd(Wp,om,wp,cm,Qp,sm,$p,lm,nm,hf,em))));function gm(e,t){let n={},r={},i=0,a=e.length;for(;i<a;)r[e[i]]=1,i+=1;for(let e in t)Object.hasOwn(r,e)||(n[e]=t[e]);return n}var _m=typeof document<`u`?_.useLayoutEffect:_.useEffect;function vm(e,t,n){let r=Object.keys(t.required||{}),i=Object.keys(t.optional||{}),a=Object.keys(t.methods||{}),o=Object.keys(t.events||{}),s=_.createContext({});function c(e,n){e.propsReady!==void 0&&Ud(e.propsReady,!1);for(let i of r){let r=e[t.required[i]];Ud(r,n[i])}for(let r of i)if(r in n){let i=e[t.optional[r]];Ud(i,n[r])}e.propsReady!==void 0&&Ud(e.propsReady,!0)}function l(e){return a.reduce((n,r)=>(n[r]=n=>{let i=e[t.methods[r]];Ud(i,n)},n),{})}function u(e){return o.reduce((n,r)=>(n[r]=nf(e[t.events[r]]),n),{})}return{Component:_.forwardRef(function(t,a){let{children:d,...f}=t,[p]=_.useState(()=>zd(lf(e),e=>{c(e,f)})),[m]=_.useState(Pd(u,p));_m(()=>{for(let e of o)e in f&&Hd(m[e],f[e]);return()=>{Object.values(m).map(Wd)}},[f,m,p]),_m(()=>{c(p,f)}),_.useImperativeHandle(a,jd(l(p)));let h=n;return(0,B.jsx)(s.Provider,{value:p,children:n===void 0?d:(0,B.jsx)(h,{...gm([...r,...i,...o],f),children:d})})}),useEmitter:(e,t)=>{let n=_.useContext(s)[e];_m(()=>Hd(n,t),[t,n])},useEmitterValue:e=>{let t=_.useContext(s)[e],n=_.useCallback(e=>Hd(t,e),[t]);return _.useSyncExternalStore(n,()=>Gd(t),()=>Gd(t))},usePublisher:e=>{let t=_.useContext(s);return _.useCallback(n=>{Ud(t[e],n)},[t,e])}}}var ym=_.createContext(void 0),bm=_.createContext(void 0),xm=`-webkit-sticky`,Sm=`sticky`,Cm=pm(()=>{if(typeof document>`u`)return Sm;let e=document.createElement(`div`);return e.style.position=xm,e.style.position===xm?xm:Sm}),wm=typeof document<`u`?_.useLayoutEffect:_.useEffect;function Tm(e){return`self`in e}function Em(e){return`body`in e}function Dm(e,t,n,r=Rd,i,a){let o=_.useRef(null),s=_.useRef(null),c=_.useRef(null),l=_.useCallback(n=>{let r,i,o,l=n.target;if(Em(l)||Tm(l)){let e=Tm(l)?l:l.defaultView;o=a===!0?xf(e,e.scrollX):e.scrollY,r=a===!0?e.document.documentElement.scrollWidth:e.document.documentElement.scrollHeight,i=a===!0?e.innerWidth:e.innerHeight}else o=a===!0?xf(l,l.scrollLeft):l.scrollTop,r=a===!0?l.scrollWidth:l.scrollHeight,i=a===!0?l.offsetWidth:l.offsetHeight;let u=()=>{e({scrollHeight:r,scrollTop:Math.max(o,0),viewportHeight:i})};n.suppressFlushSync===!0?u():li.flushSync(u),s.current!==null&&(o===s.current||o<=0||o===r-i)&&(s.current=null,t(!0),c.current&&=(clearTimeout(c.current),null))},[e,t,a]);_.useEffect(()=>{let e=i||o.current;return yf(e),r(i||o.current),l({suppressFlushSync:!0,target:e}),e.addEventListener(`scroll`,l,{passive:!0}),()=>{yf(e),r(null),e.removeEventListener(`scroll`,l)}},[o,l,n,r,i]);function u(n){let r=o.current;if(!r||(a===!0?`offsetWidth`in r&&r.offsetWidth===0:`offsetHeight`in r&&r.offsetHeight===0))return;let i=n.behavior===`smooth`,l,u,d;Tm(r)?(u=Math.max(rp(r.document.documentElement,a===!0?`width`:`height`),a===!0?r.document.documentElement.scrollWidth:r.document.documentElement.scrollHeight),l=a===!0?r.innerWidth:r.innerHeight,d=a===!0?xf(r,r.scrollX):r.scrollY):(u=r[a===!0?`scrollWidth`:`scrollHeight`],l=rp(r,a===!0?`width`:`height`),d=a===!0?xf(r,r.scrollLeft):r.scrollTop);let f=u-l;if(n.top===void 0){r.scrollTo(n);return}let p=Math.ceil(Math.max(Math.min(f,n.top),0));if(n.top=p,Mp(l,u)||p===d){e({scrollHeight:u,scrollTop:d,viewportHeight:l}),i&&t(!0);return}i?(s.current=p,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,s.current=null,t(!0)},1e3)):s.current=null,a===!0&&(n={...n.behavior===void 0?{}:{behavior:n.behavior},left:Sf(r,p)}),r.scrollTo(n)}function d(e){a===!0&&(e={...e.behavior===void 0?{}:{behavior:e.behavior},...e.top===void 0?{}:{left:Sf(o.current,e.top)}}),o.current.scrollBy(e)}return{scrollByCallback:d,scrollerRef:o,scrollToCallback:u}}function Om(e){return e}var km=sf(([e,t])=>({...e,...t}),Vd(hm,sf(()=>{let e=J(e=>`Item ${e}`),t=J(e=>`Group ${e}`),n=J({}),r=J(Om),i=J(`div`),a=J(Rd),o=(e,t=null)=>rf(q(n,K(t=>t[e]),Yd()),t);return{components:n,computeItemKey:r,EmptyPlaceholder:o(`EmptyPlaceholder`),FooterComponent:o(`Footer`),GroupComponent:o(`Group`,`div`),groupContent:t,HeaderComponent:o(`Header`),HeaderFooterTag:i,ItemComponent:o(`Item`,`div`),itemContent:e,ListComponent:o(`List`,`div`),ScrollerComponent:o(`Scroller`,`div`),scrollerRef:a,ScrollSeekPlaceholder:o(`ScrollSeekPlaceholder`),TopItemListComponent:o(`TopItemList`)}}))),Am=({height:e})=>(0,B.jsx)(`div`,{style:{height:e}}),jm={overflowAnchor:`none`,position:Cm(),zIndex:1},Mm={overflowAnchor:`none`},Nm={...Mm,display:`inline-block`,height:`100%`},Pm=_.memo(function({showTopList:e=!1}){let t=X(`listState`),n=Zm(`sizeRanges`),r=X(`useWindowScroll`),i=X(`customScrollParent`),a=Zm(`windowScrollContainerState`),o=Zm(`scrollContainerState`),s=i||r?a:o,c=X(`itemContent`),l=X(`context`),u=X(`groupContent`),d=X(`trackItemSizes`),f=X(`itemSize`),p=X(`log`),m=Zm(`gap`),h=X(`horizontalDirection`),{callbackRef:g}=Tf(n,f,d,e?Rd:s,p,m,i,h,X(`skipAnimationFrameInResizeObserver`)),[v,y]=_.useState(0);Xm(`deviation`,e=>{v!==e&&y(e)});let b=X(`EmptyPlaceholder`),x=X(`ScrollSeekPlaceholder`)??Am,S=X(`ListComponent`),C=X(`ItemComponent`),w=X(`GroupComponent`),T=X(`computeItemKey`),E=X(`isSeeking`),D=X(`groupIndices`).length>0,O=X(`alignToBottom`),k=X(`initialItemFinalLocationReached`),A=e?{}:{boxSizing:`border-box`,...h?{display:`inline-block`,height:`100%`,marginInlineStart:v===0?O?`auto`:0:v,paddingInlineEnd:t.offsetBottom,paddingInlineStart:t.offsetTop,whiteSpace:`nowrap`}:{marginTop:v===0?O?`auto`:0:v,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...k?{}:{visibility:`hidden`}};return!e&&t.totalCount===0&&b!=null?(0,B.jsx)(b,{...Bm(b,l)}):(0,B.jsx)(S,{...Bm(S,l),"data-testid":e?`virtuoso-top-item-list`:`virtuoso-item-list`,ref:g,style:A,children:(e?t.topItems:t.items).map(e=>{let n=e.originalIndex,r=T(n+t.firstItemIndex,e.data,l);return E?(0,_.createElement)(x,{...Bm(x,l),height:e.size,index:e.index,key:r,type:e.type||`item`,...e.type===`group`?{}:{groupIndex:e.groupIndex}}):e.type===`group`?(0,_.createElement)(w,{...Bm(w,l),"data-index":n,"data-item-index":e.index,"data-known-size":e.size,key:r,style:jm},u(e.index,l)):(0,_.createElement)(C,{...Bm(C,l),...Vm(C,e.data),"data-index":n,"data-item-group-index":e.groupIndex,"data-item-index":e.index,"data-known-size":e.size,key:r,style:h?Nm:Mm},D?c(e.index,e.groupIndex,e.data,l):c(e.index,e.data,l))})})}),Fm={height:`100%`,outline:`none`,overflowY:`auto`,position:`relative`,WebkitOverflowScrolling:`touch`},Im={outline:`none`,overflowX:`auto`,position:`relative`},Lm=e=>({height:`100%`,position:`absolute`,top:0,width:`100%`,...e?{display:`flex`,flexDirection:`column`}:void 0}),Rm=(e,t,n=0)=>({...Lm(e),position:t?`relative`:`absolute`,top:t?-n:0}),zm={position:Cm(),top:0,width:`100%`,zIndex:1};function Bm(e,t){if(typeof e!=`string`)return{context:t}}function Vm(e,t){return{item:typeof e==`string`?void 0:t}}var Hm=_.memo(function(){let e=X(`HeaderComponent`),t=Zm(`headerHeight`),n=X(`HeaderFooterTag`),r=Cf(_.useMemo(()=>e=>{t(rp(e,`height`))},[t]),!0,X(`skipAnimationFrameInResizeObserver`)),i=X(`context`);return e==null?null:(0,B.jsx)(n,{ref:r,children:(0,B.jsx)(e,{...Bm(e,i)})})}),Um=_.memo(function(){let e=X(`FooterComponent`),t=Zm(`footerHeight`),n=X(`HeaderFooterTag`),r=Cf(_.useMemo(()=>e=>{t(rp(e,`height`))},[t]),!0,X(`skipAnimationFrameInResizeObserver`)),i=X(`context`);return e==null?null:(0,B.jsx)(n,{ref:r,children:(0,B.jsx)(e,{...Bm(e,i)})})});function Wm({useEmitter:e,useEmitterValue:t,usePublisher:n}){return _.memo(function({children:r,style:i,context:a,...o}){let s=n(`scrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`scrollerRef`),d=t(`horizontalDirection`)||!1,{scrollByCallback:f,scrollerRef:p,scrollToCallback:m}=Dm(s,l,c,u,void 0,d);return e(`scrollTo`,m),e(`scrollBy`,f),(0,B.jsx)(c,{"data-testid":`virtuoso-scroller`,"data-virtuoso-scroller":!0,ref:p,style:{...d?Im:Fm,...i},tabIndex:0,...o,...Bm(c,a),children:r})})}function Gm({useEmitter:e,useEmitterValue:t,usePublisher:n}){return _.memo(function({children:r,style:i,context:a,...o}){let s=n(`windowScrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`totalListHeight`),d=t(`deviation`),f=t(`customScrollParent`),p=_.useRef(null),{scrollByCallback:m,scrollerRef:h,scrollToCallback:g}=Dm(s,l,c,t(`scrollerRef`),f);return wm(()=>(h.current=f||p.current?.ownerDocument.defaultView,()=>{h.current=null}),[h,f]),e(`windowScrollTo`,g),e(`scrollBy`,m),(0,B.jsx)(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:`relative`,...i,...u===0?void 0:{height:u+d}},...o,...Bm(c,a),children:r})})}var Km=({children:e})=>{let t=_.useContext(ym),n=Zm(`viewportHeight`),r=Zm(`fixedItemHeight`),i=X(`alignToBottom`),a=X(`horizontalDirection`),o=Cf(_.useMemo(()=>Nd(n,e=>rp(e,a?`width`:`height`)),[n,a]),!0,X(`skipAnimationFrameInResizeObserver`));return _.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,B.jsx)(`div`,{"data-viewport-type":`element`,ref:o,style:Lm(i),children:e})},qm=({children:e})=>{let t=_.useContext(ym),n=Zm(`windowViewportRect`),r=Zm(`fixedItemHeight`),i=X(`customScrollParent`),a=X(`useWindowScroll`),o=X(`topListHeight`),s=Of(n,i,X(`skipAnimationFrameInResizeObserver`)),c=X(`alignToBottom`);return _.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,B.jsx)(`div`,{"data-viewport-type":`window`,ref:s,style:Rm(c,a,o),children:e})},Jm=({children:e})=>{let t=X(`TopItemListComponent`)??`div`,n=X(`headerHeight`);return(0,B.jsx)(t,{style:{...zm,marginTop:`${n}px`},...Bm(t,X(`context`)),children:e})},{Component:Ym,useEmitter:Xm,useEmitterValue:X,usePublisher:Zm}=vm(km,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,scrollIntoViewOnChange:`scrollIntoViewOnChange`,itemContent:`itemContent`,groupContent:`groupContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,groupCounts:`groupCounts`,topItemCount:`topItemCount`,firstItemIndex:`firstItemIndex`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,heightEstimates:`heightEstimates`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`HeaderFooterTag`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,horizontalDirection:`horizontalDirection`,skipAnimationFrameInResizeObserver:`skipAnimationFrameInResizeObserver`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,autoscrollToBottom:`autoscrollToBottom`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},_.memo(function(e){let t=X(`useWindowScroll`),n=X(`topItemsIndexes`).length>0,r=X(`customScrollParent`),i=X(`context`);return(0,B.jsxs)(r||t?$m:Qm,{...e,context:i,children:[n&&(0,B.jsx)(Jm,{children:(0,B.jsx)(Pm,{showTopList:!0})}),(0,B.jsxs)(r||t?qm:Km,{children:[(0,B.jsx)(Hm,{}),(0,B.jsx)(Pm,{}),(0,B.jsx)(Um,{})]})]})})),Qm=Wm({useEmitter:Xm,useEmitterValue:X,usePublisher:Zm}),$m=Gm({useEmitter:Xm,useEmitterValue:X,usePublisher:Zm}),eh=Ym,th=sf(([e,t])=>({...e,...t}),Vd(hm,sf(()=>{let e=J(e=>(0,B.jsxs)(`td`,{children:[`Item $`,e]})),t=J(null),n=J(e=>(0,B.jsxs)(`td`,{colSpan:1e3,children:[`Group `,e]})),r=J(null),i=J(null),a=J({}),o=J(Om),s=J(Rd),c=(e,t=null)=>rf(q(a,K(t=>t[e]),Yd()),t);return{components:a,computeItemKey:o,context:t,EmptyPlaceholder:c(`EmptyPlaceholder`),FillerRow:c(`FillerRow`),fixedFooterContent:i,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`),TableBodyComponent:c(`TableBody`,`tbody`),TableComponent:c(`Table`,`table`),TableFooterComponent:c(`TableFoot`,`tfoot`),TableHeadComponent:c(`TableHead`,`thead`),TableRowComponent:c(`TableRow`,`tr`),GroupComponent:c(`Group`,`tr`)}}))),nh=({height:e})=>(0,B.jsx)(`tr`,{children:(0,B.jsx)(`td`,{style:{height:e}})}),rh=({height:e})=>(0,B.jsx)(`tr`,{children:(0,B.jsx)(`td`,{style:{border:0,height:e,padding:0}})}),ih={overflowAnchor:`none`},ah={position:Cm(),zIndex:2,overflowAnchor:`none`},oh=_.memo(function({showTopList:e=!1}){let t=fh(`listState`),n=fh(`computeItemKey`),r=fh(`firstItemIndex`),i=fh(`context`),a=fh(`isSeeking`),o=fh(`fixedHeaderHeight`),s=fh(`groupIndices`).length>0,c=fh(`itemContent`),l=fh(`groupContent`),u=fh(`ScrollSeekPlaceholder`)??nh,d=fh(`GroupComponent`),f=fh(`TableRowComponent`),p=(e?t.topItems:[]).reduce((e,t,n)=>(n===0?e.push(t.size):e.push(e[n-1]+t.size),e),[]);return(e?t.topItems:t.items).map(t=>{let m=t.originalIndex,h=n(m+r,t.data,i),g=e?m===0?0:p[m-1]:0;return a?(0,_.createElement)(u,{...Bm(u,i),height:t.size,index:t.index,key:h,type:t.type||`item`}):t.type===`group`?(0,_.createElement)(d,{...Bm(d,i),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,key:h,style:{...ah,top:o}},l(t.index,i)):(0,_.createElement)(f,{...Bm(f,i),...Vm(f,t.data),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,"data-item-group-index":t.groupIndex,key:h,style:e?{...ah,top:o+g}:ih},s?c(t.index,t.groupIndex,t.data,i):c(t.index,t.data,i))})}),sh=_.memo(function(){let e=fh(`listState`),t=fh(`topItemsIndexes`).length>0,n=ph(`sizeRanges`),r=fh(`useWindowScroll`),i=fh(`customScrollParent`),a=ph(`windowScrollContainerState`),o=ph(`scrollContainerState`),s=i||r?a:o,c=fh(`trackItemSizes`),{callbackRef:l,ref:u}=Tf(n,fh(`itemSize`),c,s,fh(`log`),void 0,i,!1,fh(`skipAnimationFrameInResizeObserver`)),[d,f]=_.useState(0);dh(`deviation`,e=>{d!==e&&(u.current.style.marginTop=`${e}px`,f(e))});let p=fh(`EmptyPlaceholder`),m=fh(`FillerRow`)??rh,h=fh(`TableBodyComponent`),g=fh(`paddingTopAddition`),v=fh(`statefulTotalCount`),y=fh(`context`);if(v===0&&p!=null)return(0,B.jsx)(p,{...Bm(p,y)});let b=(t?e.topItems:[]).reduce((e,t)=>e+t.size,0),x=e.offsetTop+g+d-b,S=e.offsetBottom,C=x>0?(0,B.jsx)(m,{context:y,height:x},`padding-top`):null,w=S>0?(0,B.jsx)(m,{context:y,height:S},`padding-bottom`):null;return(0,B.jsxs)(h,{"data-testid":`virtuoso-item-list`,ref:l,...Bm(h,y),children:[C,t&&(0,B.jsx)(oh,{showTopList:!0}),(0,B.jsx)(oh,{}),w]})}),ch=({children:e})=>{let t=_.useContext(ym),n=ph(`viewportHeight`),r=ph(`fixedItemHeight`),i=Cf(_.useMemo(()=>Nd(n,e=>rp(e,`height`)),[n]),!0,fh(`skipAnimationFrameInResizeObserver`));return _.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,B.jsx)(`div`,{"data-viewport-type":`element`,ref:i,style:Lm(!1),children:e})},lh=({children:e})=>{let t=_.useContext(ym),n=ph(`windowViewportRect`),r=ph(`fixedItemHeight`),i=fh(`customScrollParent`),a=fh(`useWindowScroll`),o=Of(n,i,fh(`skipAnimationFrameInResizeObserver`));return _.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,B.jsx)(`div`,{"data-viewport-type":`window`,ref:o,style:Rm(!1,a),children:e})},{Component:uh,useEmitter:dh,useEmitterValue:fh,usePublisher:ph}=vm(th,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,firstItemIndex:`firstItemIndex`,itemContent:`itemContent`,groupContent:`groupContent`,fixedHeaderContent:`fixedHeaderContent`,fixedFooterContent:`fixedFooterContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,topItemCount:`topItemCount`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,groupCounts:`groupCounts`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},_.memo(function(e){let t=fh(`useWindowScroll`),n=fh(`customScrollParent`),r=ph(`fixedHeaderHeight`),i=ph(`fixedFooterHeight`),a=fh(`fixedHeaderContent`),o=fh(`fixedFooterContent`),s=fh(`context`),c=Cf(_.useMemo(()=>Nd(r,e=>rp(e,`height`)),[r]),!0,fh(`skipAnimationFrameInResizeObserver`)),l=Cf(_.useMemo(()=>Nd(i,e=>rp(e,`height`)),[i]),!0,fh(`skipAnimationFrameInResizeObserver`)),u=n||t?hh:mh,d=n||t?lh:ch,f=fh(`TableComponent`),p=fh(`TableHeadComponent`),m=fh(`TableFooterComponent`),h=a?(0,B.jsx)(p,{ref:c,style:{position:`sticky`,top:0,zIndex:2},...Bm(p,s),children:a()},`TableHead`):null,g=o?(0,B.jsx)(m,{ref:l,style:{bottom:0,position:`sticky`,zIndex:1},...Bm(m,s),children:o()},`TableFoot`):null;return(0,B.jsx)(u,{...e,...Bm(u,s),children:(0,B.jsx)(d,{children:(0,B.jsxs)(f,{style:{borderSpacing:0,overflowAnchor:`none`},...Bm(f,s),children:[h,(0,B.jsx)(sh,{},`TableBody`),g]})})})})),mh=Wm({useEmitter:dh,useEmitterValue:fh,usePublisher:ph}),hh=Gm({useEmitter:dh,useEmitterValue:fh,usePublisher:ph}),gh={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},_h={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:vh,floor:yh,max:bh,min:xh,round:Sh}=Math;function Ch(e,t,n){return Array.from({length:t-e+1}).map((t,r)=>({data:n===null?null:n[r+e],index:r+e}))}function wh(e){return{..._h,items:e}}function Th(e,t){return e!==void 0&&e.width===t.width&&e.height===t.height}function Eh(e,t){return e!==void 0&&e.column===t.column&&e.row===t.row}var Dh=sf(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:i,headerHeight:a,scrollBy:o,scrollContainerState:s,scrollTo:c,scrollTop:l,smoothScrollTargetReached:u,viewportHeight:d},f,p,{didMount:m,propsReady:h},{customScrollParent:g,useWindowScroll:_,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b},x])=>{let S=J(0),C=J(0),w=J(gh),T=J({height:0,width:0}),E=J({height:0,width:0}),D=af(),O=af(),k=J(0),A=J(null),ee=J({column:0,row:0}),te=af(),j=af(),M=J(!1),N=J(0),ne=J(!0),re=J(!1),ie=J(!1);Hd(q(m,ef(N),G(([e,t])=>t!==0)),()=>{Ud(ne,!1)}),Hd(q(uf(m,ne,E,T,N,re),G(([e,t,n,r,,i])=>e&&!t&&n.height!==0&&r.height!==0&&!i)),([,,,,e])=>{Ud(re,!0),kp(1,()=>{Ud(D,e)}),Kd(q(l),()=>{Ud(t,[0,0]),Ud(ne,!0)})}),W(q(j,G(e=>e!=null&&e.scrollTop>0),Xd(0)),C),Hd(q(m,ef(j),G(([,e])=>e!=null)),([,e])=>{e&&(Ud(T,e.viewport),Ud(E,e.item),Ud(ee,e.gap),e.scrollTop>0&&(Ud(M,!0),Kd(q(l,Qd(1)),e=>{Ud(M,!1)}),Ud(c,{top:e.scrollTop})))}),W(q(T,K(({height:e})=>e)),d),W(q(uf(Y(T,Th),Y(E,Th),Y(ee,(e,t)=>e!==void 0&&e.column===t.column&&e.row===t.row),Y(l)),K(([e,t,n,r])=>({gap:n,item:t,scrollTop:r,viewport:e}))),te),W(q(uf(Y(S),r,Y(ee,Eh),Y(E,Th),Y(T,Th),Y(A),Y(C),Y(M),Y(ne),Y(N)),G(([,,,,,,,e])=>!e),K(([e,[t,n],r,i,a,o,s,,c,l])=>{let{column:u,row:d}=r,{height:f,width:p}=i,{width:m}=a;if(s===0&&(e===0||m===0))return gh;if(p===0){let t=Ap(l,e);return wh(Ch(t,t+Math.max(s-1,0),o))}let h=Oh(m,p,u),g,_;c?t===0&&n===0&&s>0?(g=0,_=s-1):(g=h*yh((t+d)/(f+d)),_=h*vh((n+d)/(f+d))-1,_=xh(e-1,bh(_,h-1)),g=xh(_,bh(0,g))):(g=0,_=-1);let v=Ch(g,_,o),{bottom:y,top:b}=kh(a,r,i,v),x=vh(e/h);return{bottom:y,itemHeight:f,items:v,itemWidth:p,offsetBottom:x*f+(x-1)*d-y,offsetTop:b,top:b}})),w),W(q(A,G(e=>e!==null),K(e=>e.length)),S),W(q(uf(T,E,w,ee),G(([e,t,{items:n}])=>n.length>0&&t.height!==0&&e.height!==0),K(([e,t,{items:n},r])=>{let{bottom:i,top:a}=kh(e,r,t,n);return[a,i]}),Yd(Qf)),t);let P=J(!1);W(q(l,ef(P),K(([e,t])=>t||e!==0)),P);let ae=of(q(uf(w,S),G(([{items:e}])=>e.length>0),ef(P),G(([[e,t],n])=>{let r=e.items[e.items.length-1].index===t-1;return(n||e.bottom>0&&e.itemHeight>0&&e.offsetBottom===0&&e.items.length===t)&&r}),K(([[,e]])=>e-1),Yd())),oe=of(q(Y(w),G(({items:e})=>e.length>0&&e[0].index===0),Xd(0),Yd())),se=of(q(Y(w),ef(M),G(([{items:e},t])=>e.length>0&&!t),K(([{items:e}])=>({endIndex:e[e.length-1].index,startIndex:e[0].index})),Yd(Zf),$d(0)));W(se,p.scrollSeekRangeChanged),W(q(D,ef(T,E,S,ee),K(([e,t,n,r,i])=>{let a=Ep(e),{align:o,behavior:s,offset:c}=a,l=a.index;l===`LAST`&&(l=r-1),l=bh(0,l,xh(r-1,l));let u=Ah(t,i,n,l);return o===`end`?u=Sh(u-t.height+n.height):o===`center`&&(u=Sh(u-t.height/2+n.height/2)),c!==void 0&&c!==0&&(u+=c),{behavior:s,top:u}})),c);let ce=rf(q(w,K(e=>e.offsetBottom+e.bottom)),0);return W(q(b,K(e=>({height:e.visibleHeight,width:e.visibleWidth}))),T),{customScrollParent:g,data:A,deviation:k,footerHeight:i,gap:ee,headerHeight:a,increaseViewportBy:e,initialItemCount:C,itemDimensions:E,overscan:n,restoreStateFrom:j,scrollBy:o,scrollContainerState:s,scrollHeight:O,scrollTo:c,scrollToIndex:D,scrollTop:l,smoothScrollTargetReached:u,totalCount:S,useWindowScroll:_,viewportDimensions:T,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b,...p,gridState:w,horizontalDirection:ie,initialTopMostItemIndex:N,totalListHeight:ce,...f,endReached:ae,propsReady:h,rangeChanged:se,startReached:oe,stateChanged:te,stateRestoreInProgress:M,...x}},Vd(Wp,kf,Rp,cm,wp,lm,hf));function Oh(e,t,n){return bh(1,yh((e+n)/(yh(t)+n)))}function kh(e,t,n,r){let{height:i}=n;if(i===void 0||r.length===0)return{bottom:0,top:0};let a=Ah(e,t,n,r[0].index);return{bottom:Ah(e,t,n,r[r.length-1].index)+i,top:a}}function Ah(e,t,n,r){let i=yh(r/Oh(e.width,n.width,t.column)),a=i*n.height+bh(0,i-1)*t.row;return a>0?a+t.row:a}var jh=sf(([e,t])=>({...e,...t}),Vd(Dh,sf(()=>{let e=J(e=>`Item ${e}`),t=J({}),n=J(null),r=J(`virtuoso-grid-item`),i=J(`virtuoso-grid-list`),a=J(Om),o=J(`div`),s=J(Rd),c=(e,n=null)=>rf(q(t,K(t=>t[e]),Yd()),n),l=J(!1),u=J(!1);return W(Y(u),l),{components:t,computeItemKey:a,context:n,FooterComponent:c(`Footer`),HeaderComponent:c(`Header`),headerFooterTag:o,itemClassName:r,ItemComponent:c(`Item`,`div`),itemContent:e,listClassName:i,ListComponent:c(`List`,`div`),readyStateChanged:l,reportReadyState:u,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`,`div`)}}))),Mh=_.memo(function(){let e=zh(`gridState`),t=zh(`listClassName`),n=zh(`itemClassName`),r=zh(`itemContent`),i=zh(`computeItemKey`),a=zh(`isSeeking`),o=Bh(`scrollHeight`),s=zh(`ItemComponent`),c=zh(`ListComponent`),l=zh(`ScrollSeekPlaceholder`),u=zh(`context`),d=Bh(`itemDimensions`),f=Bh(`gap`),p=zh(`log`),m=zh(`stateRestoreInProgress`),h=Bh(`reportReadyState`),g=Cf(_.useMemo(()=>e=>{let t=e.parentElement.parentElement.scrollHeight;o(t);let n=e.firstChild;if(n!==null){let{height:e,width:t}=n.getBoundingClientRect();d({height:e,width:t})}f({column:Uh(`column-gap`,getComputedStyle(e).columnGap,p),row:Uh(`row-gap`,getComputedStyle(e).rowGap,p)})},[o,d,f,p]),!0,!1);return wm(()=>{e.itemHeight>0&&e.itemWidth>0&&h(!0)},[e]),m?null:(0,B.jsx)(c,{className:t,ref:g,...Bm(c,u),"data-testid":`virtuoso-item-list`,style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(t=>{let o=i(t.index,t.data,u);return a?(0,B.jsx)(l,{...Bm(l,u),height:e.itemHeight,index:t.index,width:e.itemWidth},o):(0,_.createElement)(s,{...Bm(s,u),className:n,"data-index":t.index,key:o},r(t.index,t.data,u))})})}),Nh=_.memo(function(){let e=zh(`HeaderComponent`),t=Bh(`headerHeight`),n=zh(`headerFooterTag`),r=Cf(_.useMemo(()=>e=>{t(rp(e,`height`))},[t]),!0,!1),i=zh(`context`);return e==null?null:(0,B.jsx)(n,{ref:r,children:(0,B.jsx)(e,{...Bm(e,i)})})}),Ph=_.memo(function(){let e=zh(`FooterComponent`),t=Bh(`footerHeight`),n=zh(`headerFooterTag`),r=Cf(_.useMemo(()=>e=>{t(rp(e,`height`))},[t]),!0,!1),i=zh(`context`);return e==null?null:(0,B.jsx)(n,{ref:r,children:(0,B.jsx)(e,{...Bm(e,i)})})}),Fh=({children:e})=>{let t=_.useContext(bm),n=Bh(`itemDimensions`),r=Bh(`viewportDimensions`),i=Cf(_.useMemo(()=>e=>{r(e.getBoundingClientRect())},[r]),!0,!1);return _.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),(0,B.jsx)(`div`,{ref:i,style:Lm(!1),children:e})},Ih=({children:e})=>{let t=_.useContext(bm),n=Bh(`windowViewportRect`),r=Bh(`itemDimensions`),i=zh(`customScrollParent`),a=zh(`useWindowScroll`),o=Of(n,i,!1);return _.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),(0,B.jsx)(`div`,{ref:o,style:Rm(!1,a),children:e})},{Component:Lh,useEmitter:Rh,useEmitterValue:zh,usePublisher:Bh}=vm(jh,{optional:{context:`context`,totalCount:`totalCount`,overscan:`overscan`,itemContent:`itemContent`,components:`components`,computeItemKey:`computeItemKey`,data:`data`,initialItemCount:`initialItemCount`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`headerFooterTag`,listClassName:`listClassName`,itemClassName:`itemClassName`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,restoreStateFrom:`restoreStateFrom`,initialTopMostItemIndex:`initialTopMostItemIndex`,increaseViewportBy:`increaseViewportBy`},methods:{scrollTo:`scrollTo`,scrollBy:`scrollBy`,scrollToIndex:`scrollToIndex`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,stateChanged:`stateChanged`,readyStateChanged:`readyStateChanged`}},_.memo(function({...e}){let t=zh(`useWindowScroll`),n=zh(`customScrollParent`),r=n||t?Hh:Vh,i=n||t?Ih:Fh,a=zh(`context`);return(0,B.jsx)(r,{...e,...Bm(r,a),children:(0,B.jsxs)(i,{children:[(0,B.jsx)(Nh,{}),(0,B.jsx)(Mh,{}),(0,B.jsx)(Ph,{})]})})})),Vh=Wm({useEmitter:Rh,useEmitterValue:zh,usePublisher:Bh}),Hh=Gm({useEmitter:Rh,useEmitterValue:zh,usePublisher:Bh});function Uh(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,ff.WARN),t===`normal`?0:parseInt(t??`0`,10)}var Wh=new Set([`edit`,`multiedit`,`write`]);function Gh(e,t){if(t===`all`)return!0;if(t.startsWith(`subagent:`))return e.subagent_key===t.slice(9);let n=t=>(e.tools??[]).some(e=>!!e.name&&t.has(e.name.toLowerCase()));if(t===`edits`)return n(Wh);if(t===`bash`)return n(new Set([`bash`]));let r=(e.tools??[]).some(e=>e.is_error);return e.is_sidechain?t===`errors`&&r:t===`prompts`?e.kind===`human`:t===`errors`?r:e.kind===`human`?!0:e.kind===`assistant`?e.label.trim()!==``||(e.thinking?.length??0)>0:!1}var Kh=new Set([`ExitPlanMode`,`AskUserQuestion`]);function qh(e,t){let n=[],r=[],i=[],a=[],o=[],s=[],c=[],l=new Map,u=new Map,d=new Set;return e.forEach((e,f)=>{l.set(e.uuid,f);for(let t of e.member_uuids?.length?e.member_uuids:[e.uuid])u.has(t)||u.set(t,f);e.tools?.some(e=>e.is_error)&&n.push(f),e.kind===`human`&&r.push(f),e.subagent_key!=null&&!d.has(e.subagent_key)&&(d.add(e.subagent_key),i.push(f)),e.tools?.some(e=>e.name!=null&&Kh.has(e.name))&&a.push(f),e.cache_failure&&o.push(f),e.kind===`meta`&&e.meta_kind===`compaction`&&s.push(f),t&&e.uuid in t&&c.push(f)}),{error:n,prompt:r,subagent:i,plan:a,cache:o,compaction:s,bookmark:c,indexByUuid:l,memberIndex:u}}function Jh(e,t){let n=e.indexByUuid.get(t);return n===void 0?e.memberIndex.get(t):n}function Yh(e,t,n){if(n===1){for(let n of e)if(n>t)return n;return null}for(let n=e.length-1;n>=0;n--)if(e[n]<t)return e[n];return null}function Xh(e,t){if(t.size===0)return!1;if(t.has(e.anchor.uuid))return!0;for(let n of e.member_uuids)if(t.has(n))return!0;return!1}var Zh=e=>({keep:e,droppedTop:0,droppedBottom:0,resetTopCursorTo:null,resetBottomCursorTo:null});function Qh(e){let{items:t,op:n,cap:r,protectedUuids:i,fetchInFlight:a}=e;if(a||n===`reset`||t.length<=r)return Zh(t);if(n===`prepend`){let e=r;for(let n=t.length-1;n>=e;n--)if(Xh(t[n],i)){e=n+1;break}if(e>=t.length)return Zh(t);let n=t.slice(0,e);return{keep:n,droppedTop:0,droppedBottom:t.length-e,resetTopCursorTo:null,resetBottomCursorTo:n[n.length-1].anchor.id}}let o=t.length-r,s=o;for(let e=0;e<o;e++)if(Xh(t[e],i)){s=e;break}if(s<=0)return Zh(t);let c=t.slice(s);return{keep:c,droppedTop:s,droppedBottom:0,resetTopCursorTo:c[0].anchor.id,resetBottomCursorTo:null}}var $h=1e6;function eg(e,t){let n=e-t.addedTop+t.droppedTop;return n<0?0:n}var tg=500,ng=10,rg=2*tg;function ig(e,t={}){let{outlineTurns:n,openIntent:r,protectedUuids:i}=t,a=(0,_.useRef)(i);a.current=i;let[o,s]=(0,_.useState)({detail:null,firstItemIndex:$h}),c=o.detail,[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),v=(0,_.useRef)(0),y=(0,_.useCallback)(e=>{let t={rev:++v.current,...e};return g(t),t},[]),[b,x]=(0,_.useState)(0),[S,C]=(0,_.useState)(null),w=(0,_.useRef)(null),T=(0,_.useRef)(null),[E,D]=(0,_.useState)(!1),O=(0,_.useRef)(!1);O.current=E;let k=(0,_.useRef)(!1),A=(0,_.useRef)(!1),ee=(0,_.useRef)(null),te=(0,_.useRef)(()=>Promise.resolve()),j=(0,_.useRef)(null),M=(0,_.useRef)(!1),N=(0,_.useRef)(!1),ne=(0,_.useRef)(!1),re=(0,_.useRef)(null),ie=(0,_.useRef)(n);ie.current=n;let P=(0,_.useCallback)(e=>{s(t=>{let n=typeof e==`function`?e(t.detail):e;return re.current=n,{detail:n,firstItemIndex:t.firstItemIndex}})},[]),ae=(0,_.useCallback)(e=>{s(()=>(re.current=e,{detail:e,firstItemIndex:$h})),w.current=e.page.next_after,T.current=e.page.prev_before??null,D(e.page.has_prev??!1),y({op:`reset`,addedTop:0,addedBottom:0,droppedTop:0,droppedBottom:0})},[y]);(0,_.useEffect)(()=>{if(j.current=e,!e){P(null),C(null),u(!1),f(null),w.current=null,T.current=null,D(!1),m(null);return}u(!0),f(null),P(null),w.current=null,T.current=null,D(!1),m(null);let t=new AbortController,n=r?.kind;return Mc(n==null?`/api/conversation/${encodeURIComponent(e)}?limit=${tg}`:`/api/conversation/${encodeURIComponent(e)}?tail=1&limit=${tg}`,t.signal).then(t=>{j.current===e&&(ae(t),C(e),u(!1),n===`tail`?m(t.page.has_prev?`bottom`:`top`):n??m(null))}).catch(e=>{if(!jc(e)){if(e instanceof Ac&&e.status===404){f(`Conversation not found.`),u(!1);return}f(`Couldn't load the conversation.`),u(!1)}}),()=>t.abort()},[e,r?.kind,r&&`uuid`in r?r.uuid:null,P,ae]);let oe=(0,_.useCallback)(async()=>{let e=w.current,t=j.current;if(e==null||t==null||k.current)return null;k.current=!0;try{let n;try{n=await Mc(`/api/conversation/${encodeURIComponent(t)}?limit=${tg}&after=${e}`)}catch{return null}return j.current===t?(P(e=>e?{...e,items:[...e.items,...n.items],page:{...e.page,next_after:n.page.next_after,has_more:n.page.has_more},subagent_meta:n.subagent_meta??e.subagent_meta}:n),w.current=n.page.next_after,y({op:`append`,addedTop:0,addedBottom:n.items.length,droppedTop:0,droppedBottom:0})):null}finally{k.current=!1}},[P,y]),se=(0,_.useCallback)(async()=>oe(),[oe]),ce=(0,_.useCallback)(async()=>{let e=T.current,t=j.current;if(e==null||t==null||A.current)return null;A.current=!0;try{let n;try{n=await Mc(`/api/conversation/${encodeURIComponent(t)}?limit=${tg}&before=${e}`)}catch{return null}return j.current===t?(s(e=>{let t=e.detail,r=t?{...t,items:[...n.items,...t.items],page:{...t.page,prev_before:n.page.prev_before??null,has_prev:n.page.has_prev??!1},subagent_meta:n.subagent_meta??t.subagent_meta}:n;return re.current=r,{detail:r,firstItemIndex:eg(e.firstItemIndex,{addedTop:n.items.length,droppedTop:0})}}),T.current=n.page.prev_before??null,D(n.page.has_prev??!1),y({op:`prepend`,addedTop:n.items.length,addedBottom:0,droppedTop:0,droppedBottom:0})):null}finally{A.current=!1}},[P,y]),le=(0,_.useCallback)(async()=>{let e=await ce();return e&&e.addedTop>0?e:null},[ce]),ue=(0,_.useCallback)(async e=>{let t=j.current;if(t==null)return;let n=ee.current;if(n){await n;return}let r=()=>{};ee.current=new Promise(e=>{r=e});try{await de(e,t)}finally{ee.current=null,r()}},[]),de=(0,_.useCallback)((e,t)=>te.current(e,t),[]);te.current=(0,_.useCallback)(async(e,t)=>{let n=()=>{let t=re.current;return!!t&&t.items.some(t=>t.member_uuids.includes(e))};if(n())return;let r=e=>{s(t=>{let n=t.detail;if(!n||n.items.length<=rg)return t;let r=Qh({items:n.items,op:e,cap:rg,protectedUuids:a.current??new Set,fetchInFlight:!1});if(r.keep===n.items)return t;if(r.droppedBottom>0){w.current=r.resetBottomCursorTo;let e={...n,items:r.keep,page:{...n.page,next_after:r.resetBottomCursorTo,has_more:!0}};return re.current=e,{detail:e,firstItemIndex:t.firstItemIndex}}T.current=r.resetTopCursorTo,queueMicrotask(()=>D(!0));let i={...n,items:r.keep,page:{...n.page,prev_before:r.resetTopCursorTo,has_prev:!0}};return re.current=i,{detail:i,firstItemIndex:eg(t.firstItemIndex,{addedTop:0,droppedTop:r.droppedTop})}})},i=()=>new Promise(e=>{setTimeout(e,0)}),o=ie.current??[];if(o.length===0){let e=t;for(;;){if(n())return;if(await oe()&&w.current!=null){if(r(`append`),await i(),j.current!==e)return;continue}if(w.current==null||j.current!==e)return;for(;k.current&&j.current===e;)await i();if(j.current!==e)return}}let c=qh(o),l=Jh(c,e);if(l===void 0)return;let u=re.current?.items??[],d=e=>{for(let t of e.member_uuids){let e=Jh(c,t);if(e!==void 0)return e}},f,p;for(let e of u){let t=d(e);t!==void 0&&((f===void 0||t<f)&&(f=t),(p===void 0||t>p)&&(p=t))}if(f!==void 0&&l<f)for(;;){if(n())return;if(await ce()&&T.current!=null){if(r(`prepend`),await i(),j.current!==t)return;continue}if(T.current==null||j.current!==t)return;for(;A.current&&j.current===t;)await i();if(j.current!==t)return}else for(;;){if(n())return;if(await oe()&&w.current!=null){if(r(`append`),await i(),j.current!==t)return;continue}if(w.current==null||j.current!==t)return;for(;k.current&&j.current===t;)await i();if(j.current!==t)return}},[oe,ce]);let fe=(0,_.useCallback)(async()=>{let e=j.current;if(e==null)return;let t;try{t=await Mc(`/api/conversation/${encodeURIComponent(e)}?tail=1&limit=${tg}`)}catch{return}j.current===e&&ae(t)},[ae]),pe=c!=null&&S===e,me=pe?c:null,he=e!=null&&!pe&&d==null?!0:l,ge=me?.page?.next_after!=null;M.current=ge;let _e=me?.page?.prev_before??null,ve=(0,_.useCallback)(async()=>{if(N.current){ne.current=!0;return}let e=j.current;if(!(!e||M.current||k.current)){N.current=!0;try{for(let t=0;t<50;t++){let t=re.current?.items??[];if(!t.length)break;let n=Math.max(0,t.length-ng),r=n>0?t[n-1].anchor.id:null,i;try{i=await Mc(`/api/conversation/${encodeURIComponent(e)}?limit=${tg}`+(r==null?``:`&after=${r}`))}catch{break}if(j.current!==e)return;let a=i.items,o,s=0,c=!1;if(a.length===0)o=t;else{c=!0;let e=new Map(a.map(e=>[e.anchor.id,e])),r=new Set(t.map(e=>e.anchor.id)),i=t.slice(0,n),l=t.slice(n);o=[...i];for(let t of l){let n=e.get(t.anchor.id);n!==void 0&&o.push(n)}for(let e of a)r.has(e.anchor.id)||(o.push(e),s+=1)}if(P(e=>e&&{...e,items:o,cost_usd:i.cost_usd,models:i.models,title:i.title??e.title,git_branch:i.git_branch,project_label:i.project_label,last_anchor:i.last_anchor??e.last_anchor,last_activity_utc:i.last_activity_utc??e.last_activity_utc,subagent_meta:i.subagent_meta??e.subagent_meta,page:e.page}),c&&x(e=>e+1),c&&y({op:`append`,addedTop:0,addedBottom:s,droppedTop:0,droppedBottom:0}),s===0||i.page.next_after==null)break}}finally{N.current=!1,ne.current&&(ne.current=!1,ve())}}},[P,y]),ye=V();(0,_.useEffect)(()=>{re.current&&!M.current&&ve()},[ye?.generated_at??``]);let be=ye?.transcriptsEnabled??!1,xe=(0,_.useSyncExternalStore)(R,()=>ft(L()));return(0,_.useEffect)(()=>{if(!e||!be||!xe||typeof EventSource>`u`)return;let t=new EventSource(`/api/conversation/${encodeURIComponent(e)}/events`);return t.addEventListener(`tail`,()=>{ve()}),t.addEventListener(`open`,()=>{ve()}),()=>t.close()},[e,be,xe]),(0,_.useEffect)(()=>{let e=h;if(!e||e.trim||e.op!==`append`&&e.op!==`prepend`)return;let t=k.current||A.current||N.current,n=re.current?.items;if(!n)return;let r=Qh({items:n,op:e.op,cap:rg,protectedUuids:a.current??new Set,fetchInFlight:t});if(r.keep!==n){if(r.droppedBottom>0)w.current=r.resetBottomCursorTo,P(e=>e&&{...e,items:r.keep,page:{...e.page,next_after:r.resetBottomCursorTo,has_more:!0}});else if(r.droppedTop>0)T.current=r.resetTopCursorTo,D(!0),s(e=>{let t=e.detail;if(!t)return e;let n={...t,items:r.keep,page:{...t.page,prev_before:r.resetTopCursorTo,has_prev:!0}};return re.current=n,{detail:n,firstItemIndex:eg(e.firstItemIndex,{addedTop:0,droppedTop:r.droppedTop})}});else return;y({op:`append`,addedTop:0,addedBottom:0,droppedTop:r.droppedTop,droppedBottom:r.droppedBottom,trim:!0})}},[h?.rev]),{detail:me,loading:he,error:d,hasMore:ge,hasPrev:E,prevBefore:_e,openScrollIntent:p,lastOp:h,loadMore:se,loadPrev:le,loadToTarget:ue,jumpToLatest:fe,tailRevision:b,virtualFirstItemIndex:o.firstItemIndex}}function ag(e){let t=[],n=[],r=()=>{n.length>=2?t.push({kind:`tool_result_run`,items:n}):n.length===1&&t.push({kind:`item`,item:n[0]}),n=[]};for(let i of e){if(i.kind===`item`&&i.item.kind===`tool_result`){n.push(i.item);continue}r(),t.push(i)}return r(),t}function og(e,t){let n=new Map,r=new Map;for(let t of e){let e=t.subagent_key;if(e!=null){let r=n.get(e);r?r.push(t):n.set(e,[t])}else for(let e of t.member_uuids)r.set(e,t)}let i=new Map;for(let e of n.keys()){let a=t?.[e];if(a&&a.parent_subagent_key!==void 0){let t=a.parent_subagent_key??null,o=a.spawn_uuid??null;t!=null&&n.has(t)?i.set(e,{where:`subagent`,parentKey:t,anchorUuid:o}):t==null&&o!=null&&r.has(o)?i.set(e,{where:`main`,anchorUuid:o}):i.set(e,{where:`top`});continue}let o=n.get(e),s=o.find(e=>e.kind!==`meta`)??o[0],c=s.parent_uuid==null?void 0:r.get(s.parent_uuid);i.set(e,c?{where:`main`,anchorUuid:c.anchor.uuid}:{where:`top`})}let a=new Map,o=new Map;for(let[e,t]of i)if(t.where===`subagent`){let n=o.get(t.parentKey);n?n.push(e):o.set(t.parentKey,[e])}let s=(e,t,r)=>{let c=a.get(e);if(c)return c;let l=i.get(e),u={kind:`subagent`,subagentKey:e,items:n.get(e),nested:l.where!==`top`,depth:t,spawnAnchorUuid:l.where===`top`?null:l.anchorUuid??null,children:[]};return a.set(e,u),r.add(e),u.children=(o.get(e)??[]).filter(e=>!r.has(e)).map(e=>s(e,t+1,r)),r.delete(e),u},c=new Map;for(let[e,t]of i)if(t.where===`main`){let n=c.get(t.anchorUuid);n?n.push(e):c.set(t.anchorUuid,[e])}let l=[],u=new Set,d=e=>{if(!u.has(e)){u.add(e);for(let t of o.get(e)??[])d(t)}},f=e=>{l.push(s(e,0,new Set)),d(e)};for(let t of e)if(t.subagent_key==null){l.push({kind:`item`,item:t});for(let e of c.get(t.anchor.uuid)??[])u.has(e)||f(e)}else{let e=t.subagent_key;if(u.has(e))continue;i.get(e).where===`top`&&f(e)}for(let e of n.keys())u.has(e)||f(e);return ag(l)}function sg(e,t){for(let n of e)n.kind===`subagent`&&(t(n),n.children.length&&sg(n.children,t))}function cg(e){let t=[];return sg(e,e=>t.push(e)),t}var lg=RegExp(`^\\s*(?:<(${[`command-name`,`command-message`,`command-args`,`local-command-caveat`,`local-command-stdout`,`local-command-stderr`].join(`|`)})>(?:(?!</\\1>)[\\s\\S])*</\\1>\\s*)+$`);function ug(e){return e?lg.test(e):!1}var dg=200;function fg(e,t,n={}){let{regex:r=!1,case:i=!1,tailRevision:a=0}=n,[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(0),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=t.trim(),b=Ku(y,dg,``),x=Ku(a,dg,0),S=(0,_.useRef)(null);return(0,_.useEffect)(()=>(y||(s([]),l(0),d(!1),p(null),v(null)),()=>{S.current?.abort()}),[y]),(0,_.useEffect)(()=>{if(!b){h(!1);return}let t=new AbortController;S.current=t,h(!0);let n=`/api/conversation/${encodeURIComponent(e)}/find?q=${encodeURIComponent(b)}`;return r&&(n+=`®ex=1`),i&&(n+=`&case=1`),Mc(n,t.signal).then(e=>{s(e.anchors),l(e.total),d(e.anchors_truncated),p(e.mode),v(null),h(!1)}).catch(e=>{jc(e)||(s([]),l(0),d(!1),p(null),v(e instanceof Ac&&e.status===400?`invalid regex`:`find failed`),h(!1))}),()=>t.abort()},[e,b,r,i,x]),{anchors:o,total:c,truncated:u,mode:f,loading:y!==``&&(y!==b||m),error:g}}var pg=`cctally.conv.find.regex`,mg=`cctally.conv.find.case`;function hg(e){try{return localStorage.getItem(e)===`1`}catch{return!1}}function gg(e,t){try{localStorage.setItem(e,t?`1`:`0`)}catch{}}function _g(){return hg(pg)}function vg(e){gg(pg,e)}function yg(){return hg(mg)}function bg(e){gg(mg,e)}function xg({sessionId:e,onClose:t,onTermsChange:n,stepRef:r,tailRevision:i=0}){let[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(0),[l,u]=(0,_.useState)(_g),[d,f]=(0,_.useState)(yg),{anchors:p,total:m,truncated:h,mode:g,loading:v,error:y}=fg(e,a,{regex:l,case:d,tailRevision:i}),b=(0,_.useRef)(null),x=(0,_.useRef)(null);(0,_.useEffect)(()=>{b.current?.focus()},[]);let S=Ku(a.trim(),200,``);(0,_.useEffect)(()=>{n(S,d,l)},[S,l,d,n]);let C=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=C.current,t=e?p.findIndex(t=>t.uuid===e):-1,n=t>=0?t:0;c(n),C.current=p.length?p[n]?.uuid??null:null},[p]);let w=t=>{if(p.length===0)return;let n=((s+t)%p.length+p.length)%p.length;c(n);let r=p[n];C.current=r.uuid,z({type:`OPEN_CONVERSATION`,sessionId:e,jump:{session_id:e,uuid:r.uuid,expand_details:r.match_kinds.length>0}})};r&&(r.current=w),(0,_.useEffect)(()=>()=>{r&&(r.current=null)},[r]);let T=()=>{z({type:`CLOSE_CONV_FIND`}),t()},E=()=>u(e=>{let t=!e;return vg(t),t}),D=()=>f(e=>{let t=!e;return bg(t),t}),O=e=>{e.key===`Enter`&&(e.preventDefault(),e.stopPropagation(),w(e.shiftKey?-1:1))},k=e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),T();return}if(e.key!==`Tab`)return;let t=x.current;if(!t)return;let n=Array.from(t.querySelectorAll(`input, button`)).filter(e=>!e.disabled);if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;e.shiftKey&&a===r?(e.preventDefault(),i.focus()):!e.shiftKey&&a===i&&(e.preventDefault(),r.focus())},A=p.length>0,ee=A?p[s]:null,te=`${A?s+1:0} / ${m}`,j=[l&&`regex`,d&&`case`].filter(Boolean).join(` · `);return(0,B.jsxs)(`div`,{className:`conv-findbar`,role:`search`,"aria-label":`Find within this conversation`,ref:x,onKeyDown:k,children:[(0,B.jsx)(`input`,{ref:b,className:`conv-findbar-input`,type:`text`,"aria-label":`Find in conversation`,placeholder:`Find…`,value:a,onChange:e=>o(e.target.value),onKeyDown:O}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-toggle`,"aria-pressed":l,"aria-label":`Regular expression`,title:`Regular expression (.*)`,onClick:E,children:`.*`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-toggle`,"aria-pressed":d,"aria-label":`Case-sensitive`,title:`Case-sensitive (Aa)`,onClick:D,children:`Aa`}),j&&(0,B.jsx)(`span`,{className:`conv-findbar-mode`,"aria-label":`search mode: ${j}`,children:j}),(0,B.jsxs)(`span`,{className:`conv-findbar-count`,"aria-live":`polite`,children:[te,h&&(0,B.jsx)(`span`,{className:`conv-findbar-note`,children:` · first 500`})]}),ee&&ee.match_kinds.length>0&&(0,B.jsx)(`span`,{className:`conv-findbar-kind`,children:ee.match_kinds.join(` `)}),g===`like`&&!y&&(0,B.jsx)(`span`,{className:`conv-findbar-hint`,children:`basic search`}),y&&(0,B.jsx)(`span`,{className:`conv-findbar-hint`,role:`alert`,children:y}),v&&(0,B.jsx)(`span`,{className:`conv-findbar-spin`,"aria-hidden":`true`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-nav`,"aria-label":`Previous match`,title:`Previous match (Shift+Enter)`,disabled:!A,onClick:()=>w(-1),children:`‹`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-nav`,"aria-label":`Next match`,title:`Next match (Enter)`,disabled:!A,onClick:()=>w(1),children:`›`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-close`,"aria-label":`Close find`,title:`Close (Esc)`,onClick:T,children:`✕`})]})}function Sg(){let[e,t]=(0,_.useState)(!1),n=(0,_.useRef)(null),r=(0,_.useRef)(!0);return(0,_.useEffect)(()=>()=>{r.current=!1,n.current!=null&&window.clearTimeout(n.current)},[]),{copied:e,copy:(0,_.useCallback)(e=>{let i=()=>{r.current&&(t(!0),n.current!=null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t(!1),n.current=null},1100))};if(navigator.clipboard?.writeText){navigator.clipboard.writeText(e).then(i).catch(()=>{});return}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),i()}catch{}},[])}}function Cg(e,t,n){if(n<=0)return null;switch(e){case`ArrowDown`:return(t+1)%n;case`ArrowUp`:return(t-1+n)%n;case`Home`:return 0;case`End`:return n-1;default:return null}}function wg(e,t,n){let r=(0,_.useRef)(n);r.current=n,(0,_.useEffect)(()=>{if(!t||typeof document>`u`)return;let n=t=>{let n=e.current;n&&!n.contains(t.target)&&r.current()};return document.addEventListener(`pointerdown`,n,!0),()=>document.removeEventListener(`pointerdown`,n,!0)},[t,e])}var Tg=[{scope:`all`,label:`Whole transcript`},{scope:`prompts`,label:`Prompts only`},{scope:`chat`,label:`Chat only`},{scope:`recipe`,label:`Replay recipe`}];function Eg(e,t){return(e??``).normalize(`NFKD`).replace(/[^\x20-\x7E]/g,``).replace(/[^a-zA-Z0-9._-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,60)||t.slice(0,12)}function Dg(e,t){return`/api/conversation/${encodeURIComponent(e)}/export?scope=${t}`}async function Og(e,t){let n=await fetch(Dg(e,t));if(!n.ok)throw Error(`export failed: ${n.status}`);return n.text()}function kg(e,t){let n=new Blob([t],{type:`text/markdown;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,i.style.display=`none`,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(r),0)}function Ag({sessionId:e,title:t}){let[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null),o=(0,_.useRef)(null),s=(0,_.useRef)(null),c=(0,_.useRef)(null);wg(c,n,(0,_.useCallback)(()=>r(!1),[]));let l=Tg.length*2,u=(0,_.useRef)([]),[d,f]=(0,_.useState)(0),p=(0,_.useRef)(0),m=(0,_.useCallback)(e=>{p.current=e,f(e)},[]),h=(0,_.useRef)(!0);(0,_.useEffect)(()=>()=>{h.current=!1},[]);let{copy:g}=Sg();(0,_.useEffect)(()=>{r(!1)},[e]);let v=(0,_.useCallback)(()=>{r(!1);let e=s.current;e instanceof HTMLElement&&e.focus()},[]),y=(0,_.useCallback)(e=>{s.current=document.activeElement,m(e),r(!0)},[m]),b=(0,_.useCallback)(()=>{n?r(!1):y(0)},[n,y]);(0,_.useEffect)(()=>{n&&u.current[p.current]?.focus()},[n]);let x=(0,_.useCallback)(e=>{if(e.key===`Escape`){e.stopPropagation(),v();return}let t=Cg(e.key,p.current,l);t!==null&&(e.preventDefault(),m(t),u.current[t]?.focus())},[v,l,m]),S=(0,_.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),y(0)):e.key===`ArrowUp`&&(e.preventDefault(),y(l-1))},[y,l]),C=(0,_.useCallback)(async t=>{let n=`${t}:copy`;a(n);try{g(await Og(e,t))}catch{}finally{h.current&&a(e=>e===n?null:e)}},[e,g]),w=(0,_.useCallback)(async n=>{let r=`${n}:download`;a(r);try{let r=await Og(e,n);kg(`${Eg(t,e)}-${n}.md`,r)}catch{}finally{h.current&&a(e=>e===r?null:e)}},[e,t]);return(0,B.jsxs)(`div`,{ref:c,className:`conv-export`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||r(!1)},children:[(0,B.jsx)(`button`,{ref:o,type:`button`,className:`conv-export-toggle`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-label":`Export transcript`,onClick:b,onKeyDown:S,children:`Export ▾`}),n&&(0,B.jsx)(`div`,{className:`conv-export-menu`,role:`menu`,"aria-label":`Export transcript`,tabIndex:-1,onKeyDown:x,children:Tg.map(({scope:e,label:t},n)=>{let r=n*2,a=r+1;return(0,B.jsxs)(`div`,{className:`conv-export-row`,role:`none`,children:[(0,B.jsx)(`span`,{className:`conv-export-row-label`,children:t}),(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:r===d?0:-1,ref:e=>{u.current[r]=e},className:`conv-export-action`,"aria-label":`${t} — Copy`,disabled:i===`${e}:copy`,onClick:()=>void C(e),children:i===`${e}:copy`?`…`:`Copy`}),(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:a===d?0:-1,ref:e=>{u.current[a]=e},className:`conv-export-action`,"aria-label":`${t} — Download`,disabled:i===`${e}:download`,onClick:()=>void w(e),children:i===`${e}:download`?`…`:`Download`})]},e)})})]})}function jg(e,t){if(e===`edits`)return`Edits`;if(e===`bash`)return`Bash`;if(e.startsWith(`subagent:`)){let n=e.slice(9),r=t.find(e=>e.key===n);return r?Mg(r):n.slice(0,8)}return``}function Mg(e){return e.label.trim()||e.key.slice(0,8)}function Ng({focusMode:e,subagents:t,onSelect:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1),s=(0,_.useRef)(null),c=(0,_.useRef)(null);wg(c,r,(0,_.useCallback)(()=>{i(!1),o(!1)},[]));let l=t.length>0,u=2+ +!!l,d=(0,_.useRef)([]),f=(0,_.useRef)([]),[p,m]=(0,_.useState)(0),h=(0,_.useRef)(0),g=(0,_.useCallback)(e=>{h.current=e,m(e)},[]),[v,y]=(0,_.useState)(0),b=(0,_.useRef)(0),x=(0,_.useCallback)(e=>{b.current=e,y(e)},[]),[S,C]=(0,_.useState)(!1),w=(0,_.useRef)(!1),T=(0,_.useCallback)(e=>{w.current=e,C(e)},[]),E=(0,_.useCallback)(()=>{i(!1),o(!1),T(!1);let e=s.current;e instanceof HTMLElement&&e.focus()},[T]),D=(0,_.useCallback)(e=>{s.current=document.activeElement,g(e),T(!1),o(!1),i(!0)},[g,T]),O=(0,_.useCallback)(()=>{r?(i(!1),o(!1),T(!1)):D(0)},[r,D,T]),k=(0,_.useCallback)(()=>{x(0),T(!0),o(!0)},[x,T]),A=(0,_.useCallback)(()=>{o(!1),T(!1),d.current[2]?.focus()},[T]),ee=(0,_.useCallback)(e=>{n(e),E()},[n,E]);(0,_.useEffect)(()=>{r&&d.current[h.current]?.focus()},[r]),(0,_.useEffect)(()=>{a&&w.current&&f.current[b.current]?.focus()},[a]);let te=(0,_.useCallback)(e=>{if(e.key===`Escape`){e.stopPropagation(),E();return}if(!w.current){if(e.key===`ArrowRight`&&l&&h.current===2){e.preventDefault(),k();return}let t=Cg(e.key,h.current,u);t!==null&&(e.preventDefault(),g(t),d.current[t]?.focus());return}if(e.key===`ArrowLeft`){e.preventDefault(),A();return}let n=Cg(e.key,b.current,t.length);n!==null&&(e.preventDefault(),x(n),f.current[n]?.focus())},[E,l,u,k,A,g,x,t.length]),j=(0,_.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),D(0)):e.key===`ArrowUp`&&(e.preventDefault(),D(u-1))},[D,u]),M=jg(e,t),N=M!==``;return(0,B.jsxs)(`div`,{ref:c,className:`conv-focus-more`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(i(!1),o(!1))},children:[(0,B.jsx)(`button`,{type:`button`,className:[`conv-focus-more-toggle`,N?`conv-focus-more-toggle--on`:``].filter(Boolean).join(` `),"aria-haspopup":`menu`,"aria-expanded":r,"aria-label":`More focus filters`,onClick:O,onKeyDown:j,children:N?`${M} ▾`:`More ▾`}),r&&(0,B.jsxs)(`div`,{className:`conv-focus-more-menu`,role:`menu`,"aria-label":`More focus filters`,tabIndex:-1,onKeyDown:te,children:[(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:!S&&p===0?0:-1,ref:e=>{d.current[0]=e},className:[`conv-focus-more-item`,e===`edits`?`conv-focus-more-item--on`:``].filter(Boolean).join(` `),onClick:()=>ee(`edits`),children:`Edits`}),(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:!S&&p===1?0:-1,ref:e=>{d.current[1]=e},className:[`conv-focus-more-item`,e===`bash`?`conv-focus-more-item--on`:``].filter(Boolean).join(` `),onClick:()=>ee(`bash`),children:`Bash`}),l&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,tabIndex:!S&&p===2?0:-1,ref:e=>{d.current[2]=e},className:`conv-focus-more-item conv-focus-more-sub`,"aria-haspopup":`menu`,"aria-expanded":a,onClick:()=>a?A():k(),children:[`Subagent `,a?`▾`:`▸`]}),a&&(0,B.jsx)(`div`,{className:`conv-focus-more-submenu`,role:`menu`,"aria-label":`Focus a subagent`,children:t.map((t,n)=>{let r=`subagent:${t.key}`;return(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:S&&v===n?0:-1,ref:e=>{f.current[n]=e},className:[`conv-focus-more-item`,e===r?`conv-focus-more-item--on`:``].filter(Boolean).join(` `),onClick:()=>ee(r),children:Mg(t)},t.key)})})]})]})]})}var Pg=[{mode:`all`,label:`All`},{mode:`chat`,label:`Chat`},{mode:`prompts`,label:`Prompts`},{mode:`errors`,label:`Errors`}],Fg=[{mode:`edits`,label:`Edits`},{mode:`bash`,label:`Bash`}];function Ig(e,t){let n=Pg.find(t=>t.mode===e);if(n)return n.label;if(e===`edits`)return`Edits`;if(e===`bash`)return`Bash`;if(e.startsWith(`subagent:`)){let n=e.slice(9),r=t.find(e=>e.key===n);return r?Mg(r):n.slice(0,8)}return`All`}function Lg({focusMode:e,subagents:t,onSelect:n,errorCount:r=0}){let[i,a]=(0,_.useState)(!1),o=(0,_.useRef)(null),s=(0,_.useRef)(null);wg(s,i,(0,_.useCallback)(()=>a(!1),[]));let c=[...Pg.map(e=>e.mode===`errors`&&r>0?{...e,badge:r}:e),...Fg,...t.map(e=>({mode:`subagent:${e.key}`,label:Mg(e)}))],l=c.length,u=(0,_.useRef)([]),[d,f]=(0,_.useState)(0),p=(0,_.useRef)(0),m=(0,_.useCallback)(e=>{p.current=e,f(e)},[]),h=(0,_.useCallback)(()=>{a(!1);let e=o.current;e instanceof HTMLElement&&e.focus()},[]),g=(0,_.useCallback)(e=>{o.current=document.activeElement,m(e),a(!0)},[m]),v=(0,_.useCallback)(()=>{if(i)a(!1);else{let t=c.findIndex(t=>t.mode===e);g(t>=0?t:0)}},[i,g,c,e]);(0,_.useEffect)(()=>{i&&u.current[p.current]?.focus()},[i]);let y=(0,_.useCallback)(e=>{if(e.key===`Escape`){e.stopPropagation(),h();return}let t=Cg(e.key,p.current,l);t!==null&&(e.preventDefault(),m(t),u.current[t]?.focus())},[h,l,m]),b=(0,_.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),g(0)):e.key===`ArrowUp`&&(e.preventDefault(),g(l-1))},[g,l]),x=(0,_.useCallback)(e=>{n(e),h()},[n,h]),S=Ig(e,t);return(0,B.jsxs)(`div`,{ref:s,className:`conv-focus-compact`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||a(!1)},children:[(0,B.jsxs)(`button`,{type:`button`,className:`conv-focus-compact-toggle`,"aria-haspopup":`menu`,"aria-expanded":i,"aria-label":`Focus: ${S}`,onClick:v,onKeyDown:b,children:[`Focus: `,S,` ▾`]}),i&&(0,B.jsx)(`div`,{className:`conv-focus-compact-menu`,role:`menu`,"aria-label":`Focus mode`,tabIndex:-1,onKeyDown:y,children:c.map((t,n)=>(0,B.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t.mode,tabIndex:n===d?0:-1,ref:e=>{u.current[n]=e},className:[`conv-focus-compact-item`,e===t.mode?`conv-focus-compact-item--on`:``].filter(Boolean).join(` `),onClick:()=>x(t.mode),children:[t.label,t.badge!=null&&(0,B.jsx)(`span`,{className:`conv-focus-compact-badge`,children:t.badge})]},t.mode))})]})}function Rg({sessionId:e,exportTitle:t,onCompare:n,onLatest:r,latestBusy:i=!1,onExpandAll:a,onCollapseAll:o,completionTotal:s=null,costCumulative:c=0,costTotal:l=0,costApprox:u=!1}){let[d,f]=(0,_.useState)(!1),p=(0,_.useRef)(null),m=(0,_.useRef)(null);wg(m,d,(0,_.useCallback)(()=>f(!1),[]));let h=[{key:`compare`,label:`⟷ Compare with…`,run:n},r?{key:`latest`,label:`${i?`… `:``}Latest ↓`,run:r,busy:i}:null,{key:`expand`,label:`⤢ Expand all`,run:a},{key:`collapse`,label:`⤡ Collapse all`,run:o}].filter(Boolean),g=h.length,v=(0,_.useRef)([]),[y,b]=(0,_.useState)(0),x=(0,_.useRef)(0),S=(0,_.useCallback)(e=>{x.current=e,b(e)},[]);(0,_.useEffect)(()=>{f(!1)},[e]);let C=(0,_.useCallback)(()=>{f(!1);let e=p.current;e instanceof HTMLElement&&e.focus()},[]),w=(0,_.useCallback)(e=>{p.current=document.activeElement,S(e),f(!0)},[S]),T=(0,_.useCallback)(()=>{d?f(!1):w(0)},[d,w]);(0,_.useEffect)(()=>{d&&v.current[x.current]?.focus()},[d]);let E=(0,_.useCallback)(e=>{if(e.key===`Escape`){e.stopPropagation(),C();return}let t=Cg(e.key,x.current,g);t!==null&&(e.preventDefault(),S(t),v.current[t]?.focus())},[C,g,S]),D=(0,_.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),w(0)):e.key===`ArrowUp`&&(e.preventDefault(),w(g-1))},[w,g]),O=(0,_.useCallback)(e=>{e(),C()},[C]),k=l>0,A=s!=null;return(0,B.jsxs)(`div`,{ref:m,className:`conv-overflow`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||f(!1)},children:[(0,B.jsx)(`button`,{type:`button`,className:`conv-overflow-toggle`,"aria-haspopup":`menu`,"aria-expanded":d,"aria-label":`More actions`,title:`More actions`,onClick:T,onKeyDown:D,children:`⋯`}),d&&(0,B.jsxs)(`div`,{className:`conv-overflow-menu`,role:`menu`,"aria-label":`More actions`,tabIndex:-1,onKeyDown:E,children:[(A||k)&&(0,B.jsxs)(`div`,{className:`conv-overflow-summary`,role:`none`,children:[A&&(0,B.jsxs)(`div`,{className:`conv-overflow-summary-row`,role:`none`,children:[(0,B.jsx)(`span`,{className:`conv-overflow-summary-label`,children:`Completion`}),(0,B.jsxs)(`span`,{className:`conv-overflow-summary-value`,children:[`✓ `,s]})]}),k&&(0,B.jsxs)(`div`,{className:`conv-overflow-summary-row`,role:`none`,children:[(0,B.jsx)(`span`,{className:`conv-overflow-summary-label`,children:`Cost`}),(0,B.jsxs)(`span`,{className:`conv-overflow-summary-value`,children:[u?`~`:``,F.usd2(c),` / `,F.usd2(l)]})]})]}),(0,B.jsx)(`div`,{className:`conv-overflow-export`,role:`none`,children:(0,B.jsx)(Ag,{sessionId:e,title:t})}),h.map((e,t)=>(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:t===y?0:-1,ref:e=>{v.current[t]=e},className:`conv-overflow-item`,disabled:e.busy,onClick:()=>O(e.run),children:e.label},e.key))]})]})}var zg=(0,_.createContext)(null);function Bg(e){let t=[],n=String(e||``),r=n.indexOf(`,`),i=0,a=!1;for(;!a;){r===-1&&(r=n.length,a=!0);let e=n.slice(i,r).trim();(e||!a)&&t.push(e),i=r+1,r=n.indexOf(`,`,i)}return t}function Vg(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var Hg=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Ug=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Wg={};function Gg(e,t){return((t||Wg).jsx?Ug:Hg).test(e)}var Kg=/[ \t\n\f\r]/g;function qg(e){return typeof e==`object`?e.type===`text`?Jg(e.value):!1:Jg(e)}function Jg(e){return e.replace(Kg,``)===``}var Yg=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};Yg.prototype.normal={},Yg.prototype.property={},Yg.prototype.space=void 0;function Xg(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new Yg(n,r,t)}function Zg(e){return e.toLowerCase()}var Qg=class{constructor(e,t){this.attribute=t,this.property=e}};Qg.prototype.attribute=``,Qg.prototype.booleanish=!1,Qg.prototype.boolean=!1,Qg.prototype.commaOrSpaceSeparated=!1,Qg.prototype.commaSeparated=!1,Qg.prototype.defined=!1,Qg.prototype.mustUseProperty=!1,Qg.prototype.number=!1,Qg.prototype.overloadedBoolean=!1,Qg.prototype.property=``,Qg.prototype.spaceSeparated=!1,Qg.prototype.space=void 0;var $g=s({boolean:()=>Z,booleanish:()=>t_,commaOrSpaceSeparated:()=>a_,commaSeparated:()=>i_,number:()=>Q,overloadedBoolean:()=>n_,spaceSeparated:()=>r_}),e_=0,Z=o_(),t_=o_(),n_=o_(),Q=o_(),r_=o_(),i_=o_(),a_=o_();function o_(){return 2**++e_}var s_=Object.keys($g),c_=class extends Qg{constructor(e,t,n,r){let i=-1;if(super(e,t),l_(this,`space`,r),typeof n==`number`)for(;++i<s_.length;){let e=s_[i];l_(this,s_[i],(n&$g[e])===$g[e])}}};c_.prototype.defined=!0;function l_(e,t,n){n&&(e[t]=n)}function u_(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new c_(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[Zg(r)]=r,n[Zg(a.attribute)]=r}return new Yg(t,n,e.space)}var d_=u_({properties:{ariaActiveDescendant:null,ariaAtomic:t_,ariaAutoComplete:null,ariaBusy:t_,ariaChecked:t_,ariaColCount:Q,ariaColIndex:Q,ariaColSpan:Q,ariaControls:r_,ariaCurrent:null,ariaDescribedBy:r_,ariaDetails:null,ariaDisabled:t_,ariaDropEffect:r_,ariaErrorMessage:null,ariaExpanded:t_,ariaFlowTo:r_,ariaGrabbed:t_,ariaHasPopup:null,ariaHidden:t_,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:r_,ariaLevel:Q,ariaLive:null,ariaModal:t_,ariaMultiLine:t_,ariaMultiSelectable:t_,ariaOrientation:null,ariaOwns:r_,ariaPlaceholder:null,ariaPosInSet:Q,ariaPressed:t_,ariaReadOnly:t_,ariaRelevant:null,ariaRequired:t_,ariaRoleDescription:r_,ariaRowCount:Q,ariaRowIndex:Q,ariaRowSpan:Q,ariaSelected:t_,ariaSetSize:Q,ariaSort:null,ariaValueMax:Q,ariaValueMin:Q,ariaValueNow:Q,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function f_(e,t){return t in e?e[t]:t}function p_(e,t){return f_(e,t.toLowerCase())}var m_=u_({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:i_,acceptCharset:r_,accessKey:r_,action:null,allow:null,allowFullScreen:Z,allowPaymentRequest:Z,allowUserMedia:Z,alpha:Z,alt:null,as:null,async:Z,autoCapitalize:null,autoComplete:r_,autoFocus:Z,autoPlay:Z,blocking:r_,capture:null,charSet:null,checked:Z,cite:null,className:r_,closedBy:null,colorSpace:null,cols:Q,colSpan:Q,command:null,commandFor:null,content:null,contentEditable:t_,controls:Z,controlsList:r_,coords:Q|i_,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Z,defer:Z,dir:null,dirName:null,disabled:Z,download:n_,draggable:t_,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Z,formTarget:null,headers:r_,height:Q,hidden:n_,high:Q,href:null,hrefLang:null,htmlFor:r_,httpEquiv:r_,id:null,imageSizes:null,imageSrcSet:null,inert:Z,inputMode:null,integrity:null,is:null,isMap:Z,itemId:null,itemProp:r_,itemRef:r_,itemScope:Z,itemType:r_,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Z,low:Q,manifest:null,max:null,maxLength:Q,media:null,method:null,min:null,minLength:Q,multiple:Z,muted:Z,name:null,nonce:null,noModule:Z,noValidate:Z,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Z,optimum:Q,pattern:null,ping:r_,placeholder:null,playsInline:Z,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Z,referrerPolicy:null,rel:r_,required:Z,reversed:Z,rows:Q,rowSpan:Q,sandbox:r_,scope:null,scoped:Z,seamless:Z,selected:Z,shadowRootClonable:Z,shadowRootCustomElementRegistry:Z,shadowRootDelegatesFocus:Z,shadowRootMode:null,shadowRootSerializable:Z,shape:null,size:Q,sizes:null,slot:null,span:Q,spellCheck:t_,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Q,step:null,style:null,tabIndex:Q,target:null,title:null,translate:null,type:null,typeMustMatch:Z,useMap:null,value:t_,width:Q,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:r_,axis:null,background:null,bgColor:null,border:Q,borderColor:null,bottomMargin:Q,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Z,declare:Z,event:null,face:null,frame:null,frameBorder:null,hSpace:Q,leftMargin:Q,link:null,longDesc:null,lowSrc:null,marginHeight:Q,marginWidth:Q,noResize:Z,noHref:Z,noShade:Z,noWrap:Z,object:null,profile:null,prompt:null,rev:null,rightMargin:Q,rules:null,scheme:null,scrolling:t_,standby:null,summary:null,text:null,topMargin:Q,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Q,allowTransparency:null,autoCorrect:null,autoSave:null,credentialless:Z,disablePictureInPicture:Z,disableRemotePlayback:Z,exportParts:i_,part:r_,prefix:null,property:null,results:Q,security:null,unselectable:null},space:`html`,transform:p_}),h_=u_({attributes:{accentHeight:`accent-height`,alignmentBaseline:`alignment-baseline`,arabicForm:`arabic-form`,baselineShift:`baseline-shift`,capHeight:`cap-height`,className:`class`,clipPath:`clip-path`,clipRule:`clip-rule`,colorInterpolation:`color-interpolation`,colorInterpolationFilters:`color-interpolation-filters`,colorProfile:`color-profile`,colorRendering:`color-rendering`,crossOrigin:`crossorigin`,dataType:`datatype`,dominantBaseline:`dominant-baseline`,enableBackground:`enable-background`,fillOpacity:`fill-opacity`,fillRule:`fill-rule`,floodColor:`flood-color`,floodOpacity:`flood-opacity`,fontFamily:`font-family`,fontSize:`font-size`,fontSizeAdjust:`font-size-adjust`,fontStretch:`font-stretch`,fontStyle:`font-style`,fontVariant:`font-variant`,fontWeight:`font-weight`,glyphName:`glyph-name`,glyphOrientationHorizontal:`glyph-orientation-horizontal`,glyphOrientationVertical:`glyph-orientation-vertical`,hrefLang:`hreflang`,horizAdvX:`horiz-adv-x`,horizOriginX:`horiz-origin-x`,horizOriginY:`horiz-origin-y`,imageRendering:`image-rendering`,letterSpacing:`letter-spacing`,lightingColor:`lighting-color`,markerEnd:`marker-end`,markerMid:`marker-mid`,markerStart:`marker-start`,maskType:`mask-type`,navDown:`nav-down`,navDownLeft:`nav-down-left`,navDownRight:`nav-down-right`,navLeft:`nav-left`,navNext:`nav-next`,navPrev:`nav-prev`,navRight:`nav-right`,navUp:`nav-up`,navUpLeft:`nav-up-left`,navUpRight:`nav-up-right`,onAbort:`onabort`,onActivate:`onactivate`,onAfterPrint:`onafterprint`,onBeforePrint:`onbeforeprint`,onBegin:`onbegin`,onCancel:`oncancel`,onCanPlay:`oncanplay`,onCanPlayThrough:`oncanplaythrough`,onChange:`onchange`,onClick:`onclick`,onClose:`onclose`,onCopy:`oncopy`,onCueChange:`oncuechange`,onCut:`oncut`,onDblClick:`ondblclick`,onDrag:`ondrag`,onDragEnd:`ondragend`,onDragEnter:`ondragenter`,onDragExit:`ondragexit`,onDragLeave:`ondragleave`,onDragOver:`ondragover`,onDragStart:`ondragstart`,onDrop:`ondrop`,onDurationChange:`ondurationchange`,onEmptied:`onemptied`,onEnd:`onend`,onEnded:`onended`,onError:`onerror`,onFocus:`onfocus`,onFocusIn:`onfocusin`,onFocusOut:`onfocusout`,onHashChange:`onhashchange`,onInput:`oninput`,onInvalid:`oninvalid`,onKeyDown:`onkeydown`,onKeyPress:`onkeypress`,onKeyUp:`onkeyup`,onLoad:`onload`,onLoadedData:`onloadeddata`,onLoadedMetadata:`onloadedmetadata`,onLoadStart:`onloadstart`,onMessage:`onmessage`,onMouseDown:`onmousedown`,onMouseEnter:`onmouseenter`,onMouseLeave:`onmouseleave`,onMouseMove:`onmousemove`,onMouseOut:`onmouseout`,onMouseOver:`onmouseover`,onMouseUp:`onmouseup`,onMouseWheel:`onmousewheel`,onOffline:`onoffline`,onOnline:`ononline`,onPageHide:`onpagehide`,onPageShow:`onpageshow`,onPaste:`onpaste`,onPause:`onpause`,onPlay:`onplay`,onPlaying:`onplaying`,onPopState:`onpopstate`,onProgress:`onprogress`,onRateChange:`onratechange`,onRepeat:`onrepeat`,onReset:`onreset`,onResize:`onresize`,onScroll:`onscroll`,onSeeked:`onseeked`,onSeeking:`onseeking`,onSelect:`onselect`,onShow:`onshow`,onStalled:`onstalled`,onStorage:`onstorage`,onSubmit:`onsubmit`,onSuspend:`onsuspend`,onTimeUpdate:`ontimeupdate`,onToggle:`ontoggle`,onUnload:`onunload`,onVolumeChange:`onvolumechange`,onWaiting:`onwaiting`,onZoom:`onzoom`,overlinePosition:`overline-position`,overlineThickness:`overline-thickness`,paintOrder:`paint-order`,panose1:`panose-1`,pointerEvents:`pointer-events`,referrerPolicy:`referrerpolicy`,renderingIntent:`rendering-intent`,shapeRendering:`shape-rendering`,stopColor:`stop-color`,stopOpacity:`stop-opacity`,strikethroughPosition:`strikethrough-position`,strikethroughThickness:`strikethrough-thickness`,strokeDashArray:`stroke-dasharray`,strokeDashOffset:`stroke-dashoffset`,strokeLineCap:`stroke-linecap`,strokeLineJoin:`stroke-linejoin`,strokeMiterLimit:`stroke-miterlimit`,strokeOpacity:`stroke-opacity`,strokeWidth:`stroke-width`,tabIndex:`tabindex`,textAnchor:`text-anchor`,textDecoration:`text-decoration`,textRendering:`text-rendering`,transformOrigin:`transform-origin`,typeOf:`typeof`,underlinePosition:`underline-position`,underlineThickness:`underline-thickness`,unicodeBidi:`unicode-bidi`,unicodeRange:`unicode-range`,unitsPerEm:`units-per-em`,vAlphabetic:`v-alphabetic`,vHanging:`v-hanging`,vIdeographic:`v-ideographic`,vMathematical:`v-mathematical`,vectorEffect:`vector-effect`,vertAdvY:`vert-adv-y`,vertOriginX:`vert-origin-x`,vertOriginY:`vert-origin-y`,wordSpacing:`word-spacing`,writingMode:`writing-mode`,xHeight:`x-height`,playbackOrder:`playbackorder`,timelineBegin:`timelinebegin`},properties:{about:a_,accentHeight:Q,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Q,amplitude:Q,arabicForm:null,ascent:Q,attributeName:null,attributeType:null,azimuth:Q,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Q,by:null,calcMode:null,capHeight:Q,className:r_,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Q,diffuseConstant:Q,direction:null,display:null,dur:null,divisor:Q,dominantBaseline:null,download:Z,dx:null,dy:null,edgeMode:null,editable:null,elevation:Q,enableBackground:null,end:null,event:null,exponent:Q,externalResourcesRequired:null,fill:null,fillOpacity:Q,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:i_,g2:i_,glyphName:i_,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Q,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Q,horizOriginX:Q,horizOriginY:Q,id:null,ideographic:Q,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Q,k:Q,k1:Q,k2:Q,k3:Q,k4:Q,kernelMatrix:a_,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Q,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskType:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Q,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Q,overlineThickness:Q,paintOrder:null,panose1:null,path:null,pathLength:Q,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:r_,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Q,pointsAtY:Q,pointsAtZ:Q,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:a_,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:a_,rev:a_,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:a_,requiredFeatures:a_,requiredFonts:a_,requiredFormats:a_,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Q,specularExponent:Q,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Q,strikethroughThickness:Q,string:null,stroke:null,strokeDashArray:a_,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Q,strokeOpacity:Q,strokeWidth:null,style:null,surfaceScale:Q,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:a_,tabIndex:Q,tableValues:null,target:null,targetX:Q,targetY:Q,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:a_,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Q,underlineThickness:Q,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Q,values:null,vAlphabetic:Q,vMathematical:Q,vectorEffect:null,vHanging:Q,vIdeographic:Q,version:null,vertAdvY:Q,vertOriginX:Q,vertOriginY:Q,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Q,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:`svg`,transform:f_}),g_=u_({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:`xlink`,transform(e,t){return`xlink:`+t.slice(5).toLowerCase()}}),__=u_({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:p_}),v_=u_({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),y_={classId:`classID`,dataType:`datatype`,itemId:`itemID`,strokeDashArray:`strokeDasharray`,strokeDashOffset:`strokeDashoffset`,strokeLineCap:`strokeLinecap`,strokeLineJoin:`strokeLinejoin`,strokeMiterLimit:`strokeMiterlimit`,typeOf:`typeof`,xLinkActuate:`xlinkActuate`,xLinkArcRole:`xlinkArcrole`,xLinkHref:`xlinkHref`,xLinkRole:`xlinkRole`,xLinkShow:`xlinkShow`,xLinkTitle:`xlinkTitle`,xLinkType:`xlinkType`,xmlnsXLink:`xmlnsXlink`},b_=/[A-Z]/g,x_=/-[a-z]/g,S_=/^data[-\w.:]+$/i;function C_(e,t){let n=Zg(t),r=t,i=Qg;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&S_.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(x_,T_);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!x_.test(e)){let n=e.replace(b_,w_);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=c_}return new i(r,t)}function w_(e){return`-`+e.toLowerCase()}function T_(e){return e.charAt(1).toUpperCase()}var E_=Xg([d_,m_,g_,__,v_],`html`),D_=Xg([d_,h_,g_,__,v_],`svg`);function O_(e){let t=String(e||``).trim();return t?t.split(/[ \t\n\r\f]+/g):[]}function k_(e){return e.join(` `).trim()}var A_=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=`
|
|
18
|
+
`]},t))})]}):(0,B.jsx)(`p`,{className:`update-manual-note`,children:e.errorMessage??`See ~/.local/share/cctally/update.log for the full failure log.`}),(0,B.jsxs)(`p`,{className:`update-stream-cap`,children:[`Full log: `,(0,B.jsx)(`code`,{children:`~/.local/share/cctally/update.log`})]}),(0,B.jsxs)(`div`,{className:`update-actions`,children:[(0,B.jsx)(`button`,{type:`button`,className:`update-btn update-btn-primary`,onClick:o,children:`Retry`}),(0,B.jsx)(`button`,{type:`button`,className:`update-btn`,onClick:s,disabled:!r,children:t===`ok`?`Copied!`:t===`err`?`Copy failed`:`Copy command`}),(0,B.jsx)(`button`,{type:`button`,className:`update-btn`,onClick:()=>Rt.close(),children:`Close`})]})]})}var ac={idle:`Update available`,running:`Updating cctally`,success:`Update complete`,failed:`Update failed`},oc={idle:`accent-amber`,running:`accent-amber`,success:`accent-green`,failed:`accent-red`};function sc(){let e=(0,_.useSyncExternalStore)(R,()=>L().update),t=()=>z({type:`CLOSE_UPDATE_MODAL`});if(On((0,_.useMemo)(()=>[{key:`Escape`,scope:`modal`,action:t,when:()=>L().update.modalOpen}],[])),In(e.modalOpen&&e.state!=null),!e.modalOpen||!e.state)return null;let n=e.status,r=oc[n]??`accent-amber`,i=ac[n]??`Update`;n===`running`&&e.state.latest_version?i=`Updating cctally → ${e.state.latest_version}`:n===`success`&&e.state.latest_version&&(i=`Update complete → ${e.state.latest_version}`);let a;switch(n){case`running`:a=(0,B.jsx)(Qs,{});break;case`success`:a=(0,B.jsx)(nc,{});break;case`failed`:a=(0,B.jsx)(ic,{});break;default:a=(0,B.jsx)(qs,{});break}return(0,B.jsxs)(`div`,{id:`update-modal-root`,className:`update-modal-root`,children:[(0,B.jsx)(`div`,{className:`modal-backdrop`,onClick:t}),(0,B.jsxs)(`div`,{className:`modal-card update-modal-card ${r}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`update-modal-title`,children:[(0,B.jsx)(`div`,{className:`modal-handle`,"aria-hidden":`true`}),(0,B.jsx)(Gr,{title:i,titleId:`update-modal-title`,onClose:t}),(0,B.jsx)(`div`,{className:`modal-body`,children:a})]})]})}function cc({title:e,accentClass:t,children:n,headerExtras:r}){let i=()=>z({type:`CLOSE_MODAL`});On((0,_.useMemo)(()=>[{key:`Escape`,scope:`modal`,action:i}],[]));let a=(0,_.useRef)(null);return Mn(a,{active:!0,trapEnabled:(0,_.useSyncExternalStore)(R,()=>pt(L())===`panel`)}),In(!0),(0,B.jsxs)(`div`,{id:`modal-root`,children:[(0,B.jsx)(`div`,{className:`modal-backdrop`,onClick:i}),(0,B.jsxs)(`div`,{ref:a,className:`modal-card ${t}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`modal-title`,children:[(0,B.jsx)(`div`,{className:`modal-handle`,"aria-hidden":`true`}),(0,B.jsx)(Gr,{title:e,titleId:`modal-title`,headerExtras:r,onClose:i}),(0,B.jsx)(`div`,{id:`modal-body`,className:`modal-body`,children:n})]})]})}function lc(e){return e==null||!isFinite(e)?0:Math.max(0,Math.min(100,e))}function uc(e,t,n){let r=F.dateShort(t,n);return e&&r?`${e} → ${r}`:e||(r?`→ ${r}`:`—`)}function dc(e){if(e==null||!isFinite(e))return[`—`,``];let t=(+e).toFixed(1),n=t.indexOf(`.`);return n===-1?[t,`.0%`]:[t.slice(0,n),t.slice(n)+`%`]}function fc(e){let t=[],n=[...e].sort((e,t)=>(e.percent??0)-(t.percent??0));for(let e of n)e.percent!=null&&(t.length&&e.percent-(t[t.length-1].percent??0)<3||t.push(e));return t}function pc(e){if(!Array.isArray(e)||e.length<2)return null;let t=e.map(e=>e.marginal_usd).filter(e=>e!=null&&isFinite(e)),n=t.length?t.reduce((e,t)=>e+t,0)/t.length:null,r=e[e.length-1].percent,i=[];return n!=null&&i.push(`avg marginal $`+n.toFixed(2)),r!=null&&i.push(`latest at `+r+`%`),i.length?i.join(` · `):null}function mc(e,t){let n=[];for(let t of e)n.push({kind:`milestone`,ts:t.captured_at_utc,data:t});for(let e of t)n.push({kind:`credit`,ts:e.effective_reset_at_utc,data:e});return n.sort((e,t)=>e.ts.localeCompare(t.ts)),n}function hc(){let e=V(),t=Rn(),n={tz:t.resolvedTz,offsetLabel:t.offsetLabel},r=e?.current_week??null,i=e?.header??null,a=Array.isArray(r?.milestones)?r.milestones:[],o=Array.isArray(r?.five_hour_milestones)?r.five_hour_milestones:[],s=mc(o,Array.isArray(r?.five_hour_block?.credits)?r.five_hour_block.credits:[]),c=lc(r?.used_pct),[l,u]=dc(r?.used_pct),d=r?uc(i?.week_label,r.reset_at_utc,n):`—`,f=fc(a),p=pc(a);return(0,B.jsx)(cc,{title:`Current Week — per-percent milestones`,accentClass:`accent-green`,headerExtras:(0,B.jsx)(Vn,{panel:`current-week`,panelLabel:`Current week`,triggerId:`current-week-modal`,onClick:()=>z(He(`current-week`,`current-week-modal`))}),children:(0,B.jsxs)(`section`,{className:`modal-current-week`,children:[(0,B.jsx)(`div`,{className:`m-chipstrip`,id:`mcw-badges`,children:(0,B.jsx)(`span`,{className:`m-pill accent-green`,id:`mcw-week-pill`,children:d})}),(0,B.jsxs)(`div`,{className:`mcw-herobar`,children:[(0,B.jsxs)(`div`,{className:`mcw-bignum`,id:`mcw-bignum`,children:[(0,B.jsx)(`span`,{className:`int`,children:l}),(0,B.jsx)(`span`,{className:`unit`,children:u})]}),(0,B.jsxs)(`div`,{className:`mcw-pbar-wrap`,children:[(0,B.jsxs)(`div`,{className:`mcw-pbar`,children:[(0,B.jsx)(`div`,{className:`fill`,id:`mcw-fill`,style:{width:c+`%`}}),(0,B.jsx)(`div`,{className:`ticks`,id:`mcw-ticks`,children:f.map(e=>(0,B.jsx)(`div`,{className:`tick`,"data-p":String(e.percent),style:{left:lc(e.percent)+`%`}},e.percent))}),(0,B.jsx)(`div`,{className:`marker`,id:`mcw-marker`,style:{left:c+`%`}})]}),(0,B.jsxs)(`div`,{className:`mcw-pscale`,children:[(0,B.jsx)(`span`,{children:`0%`}),(0,B.jsx)(`span`,{children:`25%`}),(0,B.jsx)(`span`,{children:`50%`}),(0,B.jsx)(`span`,{children:`75%`}),(0,B.jsx)(`span`,{children:`100%`})]})]}),(0,B.jsxs)(`div`,{className:`mcw-mini`,id:`mcw-mini`,children:[(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`spent`}),(0,B.jsx)(`span`,{className:`v v-magenta`,id:`mcw-spent`,children:F.usd2(r?.spent_usd)})]}),(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`$ / 1%`}),(0,B.jsx)(`span`,{className:`v v-cyan`,id:`mcw-dpp`,children:F.usd3(r?.dollar_per_pct)})]}),(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`reset`}),(0,B.jsx)(`span`,{className:`v`,id:`mcw-reset`,children:F.datetimeShortZ(r?.reset_at_utc,n)})]})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-ms`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),`Milestones`]}),(0,B.jsxs)(`div`,{className:`mcw-mshead`,children:[(0,B.jsxs)(`span`,{className:`m-pill accent-purple`,id:`mcw-ms-count`,children:[a.length,` crossed`]}),(0,B.jsx)(`span`,{className:`mcw-ms-sub`,id:`mcw-ms-sub`,hidden:!p,children:p??``})]}),a.length===0?(0,B.jsx)(`p`,{className:`empty-state`,id:`mcw-empty`,children:`No milestones yet — earliest crosses at 1\xA0%.`}):(0,B.jsxs)(`table`,{className:`m-histable`,id:`mcw-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`%`}),(0,B.jsxs)(`th`,{children:[`Crossed (`,t.offsetLabel,`)`]}),(0,B.jsx)(`th`,{className:`num`,children:`Cumulative $`}),(0,B.jsx)(`th`,{className:`num`,children:`Marginal $`}),(0,B.jsx)(`th`,{className:`num`,children:`5h %`})]})}),(0,B.jsx)(`tbody`,{id:`mcw-rows`,children:a.map(e=>(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`span`,{className:`m-pill accent-purple pct-cell`,children:e.percent??`—`})}),(0,B.jsx)(`td`,{className:`d`,children:F.startedShort(e.crossed_at_utc,n,{noSuffix:!0})}),(0,B.jsx)(`td`,{className:`num`,children:e.cumulative_usd==null?`—`:`$`+e.cumulative_usd.toFixed(2)}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(`span`,{className:`m-marginal`,children:e.marginal_usd==null?`—`:`$`+e.marginal_usd.toFixed(2)})}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(`span`,{className:`m-fh`,children:e.five_hour_pct_at_cross==null?`—`:Math.round(e.five_hour_pct_at_cross)+`%`})})]},e.percent))})]}),s.length>0&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-ms sec-5h`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#activity`})}),`5h milestones`]}),(0,B.jsx)(`div`,{className:`mcw-mshead`,children:(0,B.jsxs)(`span`,{className:`m-pill accent-purple`,id:`mcw-5h-count`,children:[o.length,` crossed`]})}),(0,B.jsxs)(`table`,{className:`m-histable mcw-5h-table`,id:`mcw-5h-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`%`}),(0,B.jsxs)(`th`,{children:[`When (`,t.offsetLabel,`)`]}),(0,B.jsx)(`th`,{className:`num`,children:`Block $`}),(0,B.jsx)(`th`,{className:`num`,children:`Marginal $`}),(0,B.jsx)(`th`,{className:`num`,children:`7d %`})]})}),(0,B.jsx)(`tbody`,{children:s.map((e,t)=>{if(e.kind===`credit`)return(0,B.jsx)(`tr`,{className:`mcw-5h-credit-row`,children:(0,B.jsxs)(`td`,{colSpan:5,className:`mcw-5h-credit-cell`,children:[`⚡ CREDIT\xA0`,` `,e.data.delta_pp>0?`+`:``,e.data.delta_pp.toFixed(0),`pp\xA0@`,` `,F.startedShort(e.ts,n,{noSuffix:!0})]})},`credit-${t}-${e.ts}`);let r=e.data;return(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`span`,{className:`m-pill accent-purple pct-cell`,children:r.percent_threshold})}),(0,B.jsx)(`td`,{className:`d`,children:F.startedShort(r.captured_at_utc,n,{noSuffix:!0})}),(0,B.jsx)(`td`,{className:`num`,children:`$`+r.block_cost_usd.toFixed(2)}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(`span`,{className:`m-marginal`,children:r.marginal_cost_usd==null?`—`:`$`+r.marginal_cost_usd.toFixed(2)})}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(`span`,{className:`m-fh`,children:r.seven_day_pct_at_crossing==null?`—`:Math.round(r.seven_day_pct_at_crossing)+`%`})})]},`fhms-${r.percent_threshold}-${r.reset_event_id}`)})})]})]})]})})}function gc(e){if(!e)return`—`;let t=e.elapsed_hours,n=e.remaining_hours;if(t==null||n==null)return`—`;let r=t+n;if(r<=0)return`—`;let i=t/r*100;return Math.min(100,i).toFixed(1)+`%`}function _c(e){return e==null||!isFinite(e)?null:e<0?0:e>110?110:e}function vc(e){return e==null||!isFinite(e)?`—`:e<0?`~`+(+e).toFixed(1)+`%`:(+e).toFixed(1)+`%`}function yc(e,t){for(let t of e)t.trueXPct=t.pos/110*100;if(e.length<2||t<=0){for(let t of e)t.resolvedXPct=t.trueXPct;return}let n=e.slice().sort((e,t)=>e.trueXPct-t.trueXPct),r=n[0],i=n[1],a=r.pillWidthPx/2/t*100,o=i.pillWidthPx/2/t*100,s=8/t*100,c=a+o+s,l=2*c;if(i.trueXPct-r.trueXPct<c){let e=(r.trueXPct+i.trueXPct)/2;r.resolvedXPct=e-l/2,i.resolvedXPct=e+l/2;let t=a,n=100-o;r.resolvedXPct<t&&(r.resolvedXPct=t,i.resolvedXPct-r.resolvedXPct<l&&(i.resolvedXPct=Math.min(n,r.resolvedXPct+l))),i.resolvedXPct>n&&(i.resolvedXPct=n,i.resolvedXPct-r.resolvedXPct<l&&(r.resolvedXPct=Math.max(t,i.resolvedXPct-l)))}else r.resolvedXPct=r.trueXPct,i.resolvedXPct=i.trueXPct}function bc(e,t,n){(0,_.useEffect)(()=>{let r=e.current,i=t.current;if(!r||!i||!n)return;let a=r.querySelector(`.mfc-pills`),o=r.querySelector(`.mfc-leaders`),s=i.querySelector(`.mfc-rangeband`);if(!a||!o)return;let c=n.week_avg_projection_pct,l=n.recent_24h_projection_pct,u=_c(c),d=_c(l),f=[];u!=null&&c!=null&&f.push({kind:`wa`,pos:u,raw:c}),d!=null&&l!=null&&f.push({kind:`r24`,pos:d,raw:l});let p=new Set(f.map(e=>e.kind));i.querySelectorAll(`.mfc-chev`).forEach(e=>{let t=e.dataset.kind;(!t||!p.has(t))&&e.remove()}),a.querySelectorAll(`.mfc-pill`).forEach(e=>{let t=e.dataset.kind;(!t||!p.has(t))&&e.remove()});let m=f.map(e=>({...e,trueXPct:0,resolvedXPct:0,pillWidthPx:0}));for(let e of m){let t=e.pos/110*100,n=i.querySelector(`.mfc-chev[data-kind="${e.kind}"]`);n||(n=document.createElement(`div`),n.className=`mfc-chev `+e.kind,n.dataset.kind=e.kind,i.appendChild(n)),n.style.left=t+`%`;let r=a.querySelector(`.mfc-pill[data-kind="${e.kind}"]`),o=vc(e.raw);r?r.textContent!==o&&(r.textContent=o):(r=document.createElement(`div`),r.className=`mfc-pill `+e.kind,r.dataset.kind=e.kind,r.textContent=o,a.appendChild(r)),e.pillEl=r}if(s){let e=!1;if(m.length===2){let t=m[0].pos/110*100,n=m[1].pos/110*100,r=Math.min(t,n),i=Math.max(t,n)-r;i>=.5&&(s.style.left=r+`%`,s.style.width=i+`%`,e=!0)}s.hidden=!e}let h=()=>{for(let e of m)if(!e.pillEl||!e.pillEl.isConnected)return;let e=r.clientWidth;if(e<=0){requestAnimationFrame(h);return}for(let e of m)e.pillWidthPx=e.pillEl.getBoundingClientRect().width;yc(m,e);for(let e of m)e.pillEl.style.left=e.resolvedXPct+`%`;for(;o.firstChild;)o.removeChild(o.firstChild);for(let e of m){let t=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);t.setAttribute(`class`,e.kind),t.setAttribute(`vector-effect`,`non-scaling-stroke`),t.setAttribute(`d`,`M ${e.resolvedXPct} 0 C ${e.resolvedXPct} 10, ${e.trueXPct} 8, ${e.trueXPct} 18`),o.appendChild(t)}};h()},[e,t,n])}function U(){let e=V()?.forecast??null,t=e?.explain??null,n=(0,_.useRef)(null),r=(0,_.useRef)(null);bc(n,r,e);let i=(0,B.jsx)(Vn,{panel:`forecast`,panelLabel:`Forecast`,triggerId:`forecast-modal`,onClick:()=>z(He(`forecast`,`forecast-modal`))});if(!e)return(0,B.jsx)(cc,{title:`Forecast — explain`,accentClass:`accent-purple`,headerExtras:i,children:(0,B.jsx)(`section`,{className:`modal-forecast`,children:(0,B.jsx)(`p`,{className:`empty-state`,id:`mfc-empty`,children:`No forecast data yet.`})})});let a=cn(e.verdict),o=a?`m-pill ${a.accent}`:`m-pill`,s=a?`${a.glyph} ${a.label}`:`—`,c=`m-pill`,l=`—`,u=!0;e.confidence===`high`?(c=`m-pill accent-blue`,l=`high confidence`,u=!1):e.confidence===`low`&&(c=`m-pill accent-red`,l=`low confidence`,u=!1);let d=t?.rates,f=t?.week;return(0,B.jsx)(cc,{title:`Forecast — explain`,accentClass:`accent-purple`,headerExtras:i,children:(0,B.jsxs)(`section`,{className:`modal-forecast`,children:[(0,B.jsxs)(`div`,{className:`m-chipstrip`,id:`mfc-chips`,children:[(0,B.jsx)(`span`,{className:o,id:`mfc-verdict`,children:s}),(0,B.jsx)(`span`,{className:c,id:`mfc-confidence`,hidden:u,children:l})]}),(0,B.jsxs)(`div`,{className:`m-hero cols-2`,children:[(0,B.jsxs)(`div`,{className:`m-kv kv-wa`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#gauge`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mfc-wa-pct`,children:F.pct1(e.week_avg_projection_pct)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Week-avg projection`}),(0,B.jsx)(`div`,{className:`sub`,id:`mfc-wa-sub`,children:F.ratePctPerHour(d?.week_average_pct_per_hour)})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-r24`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#zap`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mfc-r24-pct`,children:F.pct1(e.recent_24h_projection_pct)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Recent-24h projection`}),(0,B.jsx)(`div`,{className:`sub`,id:`mfc-r24-sub`,children:F.ratePctPerHour(d?.recent_24h_pct_per_hour)})]})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-range`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#bar-chart`})}),`Range vs. caps`]}),(0,B.jsxs)(`div`,{className:`mfc-rangewrap`,id:`mfc-rangewrap`,ref:n,children:[(0,B.jsx)(`div`,{className:`mfc-pills`,id:`mfc-pills`}),(0,B.jsx)(`svg`,{className:`mfc-leaders`,id:`mfc-leaders`,viewBox:`0 0 100 18`,preserveAspectRatio:`none`,"aria-hidden":`true`}),(0,B.jsxs)(`div`,{className:`mfc-rangetrack`,id:`mfc-rangetrack`,ref:r,children:[(0,B.jsx)(`div`,{className:`mfc-zone safe`}),(0,B.jsx)(`div`,{className:`mfc-zone warn`}),(0,B.jsx)(`div`,{className:`mfc-zone over`}),(0,B.jsx)(`div`,{className:`mfc-rangeband`,id:`mfc-rangeband`,hidden:!0}),(0,B.jsx)(`div`,{className:`mfc-bound b90`,children:(0,B.jsx)(`div`,{className:`lbl`,children:`90%`})}),(0,B.jsx)(`div`,{className:`mfc-bound b100`,children:(0,B.jsx)(`div`,{className:`lbl`,children:`100%`})})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-rates`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#activity`})}),`Rates`]}),(0,B.jsxs)(`div`,{className:`mfc-kvgrid`,children:[(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`$ / 1%`}),(0,B.jsx)(`span`,{className:`v v-cyan`,id:`mfc-dpp`,children:F.usd3(d?.dollars_per_percent)})]}),(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`week done`}),(0,B.jsx)(`span`,{className:`v v-green`,id:`mfc-wkdone`,children:gc(f)})]}),(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`elapsed`}),(0,B.jsx)(`span`,{className:`v v-green`,id:`mfc-elapsed`,children:F.hours1(f?.elapsed_hours)})]}),(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`remaining`}),(0,B.jsx)(`span`,{className:`v`,id:`mfc-remain`,children:F.hours1(f?.remaining_hours)})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-bud`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#dollar`})}),`Daily budgets to stay under`]}),(0,B.jsxs)(`div`,{className:`mfc-kvgrid mfc-kvgrid-single`,children:[(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`@ 100% cap`}),(0,B.jsx)(`span`,{className:`v v-magenta`,id:`mfc-bud100`,children:F.usd2PerDay(e.budget_100_per_day_usd)})]}),(0,B.jsxs)(`div`,{className:`mfc-krow`,children:[(0,B.jsx)(`span`,{className:`l`,children:`@ 90% cap`}),(0,B.jsx)(`span`,{className:`v v-amber`,id:`mfc-bud90`,children:F.usd2PerDay(e.budget_90_per_day_usd)})]})]})]})})}function xc(e){let t=Math.max(1,Math.round(e/4));return`${e} week${e===1?``:`s`} · ${t} month${t===1?``:`s`}`}function Sc(e){let t=e.findIndex(e=>e&&e.is_current);return t>=0?t:e.length-1}function Cc(e,t){let n=e.filter((e,n)=>n!==t).map(e=>e.dollar_per_pct).filter(e=>e!=null&&isFinite(e));if(n.length<4)return null;let r=n.slice(-4).sort((e,t)=>e-t);return(r[1]+r[2])/2}function wc(e){if(!e.length)return null;let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2?t[n]:(t[n-1]+t[n])/2}function Tc(e,t){let n=[];if(!e.length)return n;let r={left:44,right:14,top:12,bottom:22},i=600-r.left-r.right,a=140-r.top-r.bottom,o=e.length,s=e=>r.left+(o===1?i:e/(o-1)*i),c=e.map(e=>e.dollar_per_pct).filter(e=>e!=null&&isFinite(e)),l=c.length?Math.min(...c)*.96:0,u=c.length?Math.max(...c)*1.04:1;u-l<1e-6&&(l-=.01,u+=.01);let d=e=>r.top+a*(1-(e-l)/(u-l)),f=e.map(e=>e.used_pct).filter(e=>e!=null&&isFinite(e)),p=f.length?Math.min(...f)*.96:0,m=f.length?Math.max(...f)*1.04:100;m-p<1e-6&&(--p,m+=1);let h=e=>r.top+a*(1-(e-p)/(m-p));if(n.push({el:`line`,attrs:{class:`mtr-axis`,x1:r.left,y1:r.top+a,x2:600-r.right,y2:r.top+a},key:`axis`}),c.length){let e=wc(c);e!=null&&(n.push({el:`line`,attrs:{class:`mtr-hl`,x1:r.left,y1:d(e),x2:600-r.right,y2:d(e)},key:`med-line`}),n.push({el:`text`,attrs:{class:`mtr-medlabel`,x:r.left+2,y:d(e)-3},text:`median $`+e.toFixed(2),key:`med-label`}))}{let t=[];e.forEach((e,n)=>{e.used_pct!=null&&isFinite(e.used_pct)&&t.push(`${s(n)},${h(e.used_pct)}`)}),t.length>=2&&n.push({el:`polyline`,attrs:{class:`mtr-trendline-dim`,points:t.join(` `)},key:`poly-used`})}{let t=[];e.forEach((e,n)=>{e.dollar_per_pct!=null&&isFinite(e.dollar_per_pct)&&t.push(`${s(n)},${d(e.dollar_per_pct)}`)}),t.length>=2&&n.push({el:`polyline`,attrs:{class:`mtr-trendline`,points:t.join(` `)},key:`poly-dpp`})}e.forEach((e,r)=>{if(e.dollar_per_pct==null||!isFinite(e.dollar_per_pct))return;let i=r===t;n.push({el:`circle`,attrs:{class:`mtr-trenddot`+(i?` cur`:``),cx:s(r),cy:d(e.dollar_per_pct),r:i?5:3},key:`dot-${r}`})}),c.length&&(n.push({el:`text`,attrs:{class:`mtr-ylabel`,x:3,y:r.top+8},text:`$`+(u/1.04).toFixed(2),key:`ymax`}),n.push({el:`text`,attrs:{class:`mtr-ylabel`,x:3,y:r.top+a},text:`$`+(l/.96).toFixed(2),key:`ymin`}));let g=e[t];return g&&g.dollar_per_pct!=null&&isFinite(g.dollar_per_pct)&&n.push({el:`text`,attrs:{class:`mtr-curlabel`,x:Math.max(r.left+4,s(t)-22),y:Math.min(138,d(g.dollar_per_pct)+16)},text:`$`+g.dollar_per_pct.toFixed(2),key:`curlabel`}),n}function Ec(e,t){return t===0?`Now`+(e.label?` · `+e.label:``):`W−`+t+(e.label?` · `+e.label:``)}function Dc(e){return e==null||!isFinite(e)?{cls:`flat`,text:`—`}:e>5e-4?{cls:`up`,text:`+`+e.toFixed(2)}:e<-5e-4?{cls:`down`,text:e.toFixed(2)}:{cls:`flat`,text:`0.00`}}function Oc(e){return e==null||!isFinite(e)?{cls:`delta-flat`,iconHref:`/static/icons.svg#minus`,text:`—`}:e<-5e-4?{cls:`delta-down`,iconHref:`/static/icons.svg#trending-down`,text:`−$`+Math.abs(e).toFixed(3)}:e>5e-4?{cls:`delta-up`,iconHref:`/static/icons.svg#trending-up`,text:`+$`+e.toFixed(3)}:{cls:`delta-flat`,iconHref:`/static/icons.svg#minus`,text:`$0.000`}}function kc(){let e=V(),t=Ae(e),n=(0,B.jsx)(Vn,{panel:`trend`,panelLabel:`Trend`,triggerId:`trend-modal`,onClick:()=>z(He(`trend`,`trend-modal`))});if(!t.length)return(0,B.jsx)(cc,{title:`Trend — 12-week history`,accentClass:`accent-amber`,headerExtras:n,children:(0,B.jsx)(`section`,{className:`modal-trend`,children:(0,B.jsx)(`p`,{className:`empty-state`,id:`mtr-empty`,children:`No history data yet.`})})});let r=Sc(t),i=t[r],a=e?.trend?.history_median_dpp,o=a!=null&&isFinite(a)?a:Cc(t,r),s=Oc(i&&i.dollar_per_pct!=null&&o!=null?i.dollar_per_pct-o:null),c=Tc(t,r),l=t.some(e=>e.used_pct!=null&&isFinite(e.used_pct)),u=t.length;return(0,B.jsx)(cc,{title:`Trend — 12-week history`,accentClass:`accent-amber`,headerExtras:n,children:(0,B.jsxs)(`section`,{className:`modal-trend`,children:[(0,B.jsx)(`div`,{className:`m-chipstrip`,children:(0,B.jsx)(`span`,{className:`m-pill accent-amber`,id:`mtr-weeks-pill`,children:xc(u)})}),(0,B.jsxs)(`div`,{className:`m-hero cols-3`,children:[(0,B.jsxs)(`div`,{className:`m-kv kv-cur`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#dollar`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mtr-cur`,children:i&&i.dollar_per_pct!=null?`$`+i.dollar_per_pct.toFixed(3):`—`}),(0,B.jsx)(`div`,{className:`lbl`,children:`Current $ / 1%`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-med`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#minus`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mtr-med`,children:o==null?`—`:`$`+o.toFixed(3)}),(0,B.jsx)(`div`,{className:`lbl`,children:`4-week median`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-delta ${s.cls}`,id:`mtr-delta-kv`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:s.iconHref})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`mtr-delta`,children:s.text}),(0,B.jsx)(`div`,{className:`lbl`,children:`vs median`})]})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-spark`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#trending-down`})}),`12-week history · $/1%`,(0,B.jsxs)(`span`,{className:`mtr-legend`+(l?``:` legend-no-used`),"aria-hidden":`true`,children:[(0,B.jsx)(`span`,{className:`sw sw-dpp`}),(0,B.jsx)(`span`,{className:`sw-lbl`,children:`$/1%`}),(0,B.jsx)(`span`,{className:`sw sw-used`}),(0,B.jsx)(`span`,{className:`sw-lbl`,children:`used %`})]})]}),(0,B.jsxs)(`div`,{className:`mtr-sparkhero`,children:[(0,B.jsx)(`svg`,{id:`mtr-svg`,viewBox:`0 0 600 140`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:c.map(e=>{let{el:t,attrs:n,text:r,key:i}=e,a={};for(let e in n)a[e===`class`?`className`:e]=n[e];return t===`line`?(0,B.jsx)(`line`,{...a},i):t===`polyline`?(0,B.jsx)(`polyline`,{...a},i):t===`circle`?(0,B.jsx)(`circle`,{...a},i):(0,B.jsx)(`text`,{...a,children:r},i)})}),(0,B.jsx)(`div`,{className:`mtr-sparkaxis`,id:`mtr-sparkaxis`,children:u>0?(0,B.jsxs)(_.Fragment,{children:[(0,B.jsxs)(`span`,{children:[`W−`,u-1]}),(0,B.jsxs)(`span`,{children:[`W−`,Math.floor((u-1)/2)]}),(0,B.jsx)(`span`,{children:`Now`})]}):null})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-tbl`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),`Weekly detail`]}),(0,B.jsxs)(`div`,{className:`mtr-tbl-head`,children:[(0,B.jsxs)(`span`,{className:`m-pill accent-purple`,id:`mtr-tbl-count`,children:[u,` weeks`]}),(0,B.jsx)(`span`,{className:`mtr-tbl-sub`,children:`current row highlighted · negative Δ = $/1% down vs prior week`})]}),(0,B.jsxs)(`table`,{className:`m-histable`,id:`mtr-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Week`}),(0,B.jsx)(`th`,{className:`num`,children:`Used %`}),(0,B.jsx)(`th`,{className:`num`,children:`$ / 1%`}),(0,B.jsx)(`th`,{className:`num`,children:`Δ $/1%`})]})}),(0,B.jsx)(`tbody`,{id:`mtr-rows`,children:t.map((e,t)=>{let n=Ec(e,u-1-t),r=e.used_pct==null?`—`:Math.round(e.used_pct)+`%`,i=e.dollar_per_pct==null?`—`:`$`+e.dollar_per_pct.toFixed(2),a=Dc(e.delta);return(0,B.jsxs)(`tr`,{className:e.is_current?`cur`:void 0,children:[(0,B.jsx)(`td`,{children:(0,B.jsx)(`span`,{className:`wlab`,children:n})}),(0,B.jsx)(`td`,{className:`num usedpct`,children:r}),(0,B.jsx)(`td`,{className:`num dpp`,children:i}),(0,B.jsx)(`td`,{className:`num delta ${a.cls}`,children:a.text})]},e.label+`|`+t)})})]})]})})}var Ac=class extends Error{status;constructor(e){super(`HTTP ${e}`),this.status=e,this.name=`HttpError`}};function jc(e){return e?.name===`AbortError`}async function Mc(e,t){let n=await fetch(e,t?{signal:t}:void 0);if(!n.ok)throw new Ac(n.status);return await n.json()}function Nc(e,t){let n=t?.revalidateOnTick??!0,[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(null),l=(0,_.useRef)(e),u=(0,_.useRef)(null),d=(0,_.useRef)(!1),f=(0,_.useRef)(!1),p=(0,_.useCallback)(async()=>{if(d.current){f.current=!0;return}let e=l.current;if(e){d.current=!0;try{let t=await Mc(`/api/conversation/${encodeURIComponent(e)}/outline`);if(l.current!==e)return;u.current=t,i(t),c(null),o(!1)}catch{if(l.current!==e)return;c(`Couldn't load the outline.`),o(!1)}finally{d.current=!1,f.current&&(f.current=!1,p())}}},[]);return(0,_.useEffect)(()=>{if(l.current=e,u.current=null,d.current=!1,f.current=!1,i(null),c(null),!e){o(!1);return}o(!0),p()},[e,p]),(0,_.useEffect)(()=>{n&&u.current&&p()},[V()?.generated_at??``,n]),{outline:r,loading:a,error:s}}var Pc=3;function Fc({sessionId:e}){let t=(0,_.useSyncExternalStore)(R,()=>dt(L())),{outline:n}=Nc(t?e:null),r=V(),i=(0,_.useMemo)(()=>we(r),[r?.display?.resolved_tz,r?.display?.offset_label]),[a,o]=(0,_.useState)(!1);if(!t||!n||!n.stats||!e)return null;let s=n.stats,c=s.cache_failures,l=c?.count??0,u=s.cache_saved_usd??0,d=c?.rebuilds??[],f=a?d:d.slice(0,Pc),p=e;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-rebuild`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#refresh`})}),`Cache rebuilds`]}),l===0?(0,B.jsx)(`div`,{className:`msess-rebuild-none`,id:`msess-rebuild-none`,children:`No cache rebuilds ✓`}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`msess-tok-grid msess-rebuild-tiles`,id:`msess-rebuild-tiles`,children:[(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Rebuilds`}),(0,B.jsx)(`div`,{className:`n`,children:l})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile rebuild-wasted`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Wasted`}),(0,B.jsx)(`div`,{className:`n`,children:F.usd2(c.est_wasted_usd)})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Re-created`}),(0,B.jsx)(`div`,{className:`n`,children:c.tokens_recreated.toLocaleString(`en-US`)})]})]}),(0,B.jsx)(`ul`,{className:`msess-rebuild-list`,id:`msess-rebuild-list`,children:f.map(e=>(0,B.jsx)(`li`,{className:`rebuild-row`,children:(0,B.jsxs)(`button`,{type:`button`,className:`rebuild-jump`,onClick:()=>z({type:`OPEN_CONVERSATION`,sessionId:p,jump:{session_id:p,uuid:e.uuid}}),children:[(0,B.jsx)(`span`,{className:`rb-cost`,children:F.usd2(e.est_wasted_usd)}),(0,B.jsxs)(`span`,{className:`rb-tok`,children:[e.tokens_recreated.toLocaleString(`en-US`),` tok`]}),(0,B.jsx)(`span`,{className:`rb-time`,children:e.ts?F.timeHHmm(e.ts,i,{noSuffix:!0}):``}),e.subagent_key?(0,B.jsx)(`span`,{className:`rb-sub`,children:`subagent`}):null,(0,B.jsx)(`span`,{className:`rb-go`,children:`→ Jump`})]})},e.uuid))}),d.length>Pc&&!a?(0,B.jsxs)(`button`,{type:`button`,className:`msess-rebuild-more`,onClick:()=>o(!0),children:[`+`,d.length-Pc,` more`]}):null]}),u>0?(0,B.jsxs)(`div`,{className:`msess-rebuild-saved`,id:`msess-rebuild-saved`,children:[`Cache saved this session `,F.usd2(u),` ✓`]}):null]})}var Ic=/(^|\/)(subagents\/|agent-)/;function Lc(){return(0,_.useSyncExternalStore)(R,()=>L().snapshot?.generated_at??``)}function Rc(){let e=(0,_.useSyncExternalStore)(R,()=>L().openSessionId),t=Lc(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(null),c=(0,_.useRef)(null),l=(0,_.useRef)(!1),u=(0,_.useRef)(null);return(0,_.useEffect)(()=>{u.current=e??L().snapshot?.sessions?.rows?.[0]?.session_id??null,l.current=!1},[e]),(0,_.useEffect)(()=>{let e=u.current;if(!e){a(!1),s(`No session available.`),r(null),c.current=null;return}let t=c.current!==e||n==null;c.current=e,t&&(a(!0),s(null),r(null));let i=new AbortController;return fetch(`/api/session/${encodeURIComponent(e)}`,{signal:i.signal}).then(async e=>{if(e.status===404){(t||l.current)&&(a(!1),s(`Session not found (the cache may have rolled forward).`),r(null)),l.current=!0;return}if(!e.ok)throw Error(`HTTP `+e.status);let n=await e.json();l.current=!1,r(n),s(null),a(!1)}).catch(e=>{e.name!==`AbortError`&&(l.current=!1,t&&(s(`Failed to load: `+e.message),a(!1)))}),()=>i.abort()},[e,t]),(0,B.jsx)(cc,{title:`Session detail`,accentClass:`accent-orange`,headerExtras:(0,B.jsx)(Vn,{panel:`sessions`,panelLabel:`Session`,triggerId:`session-modal`,onClick:()=>z(He(`sessions`,`session-modal`))}),children:(0,B.jsxs)(`section`,{className:`modal-sessions`,children:[i?(0,B.jsx)(`div`,{className:`modal-loading`,id:`msess-loading`,children:`Loading session detail…`}):null,o?(0,B.jsx)(`div`,{className:`modal-error`,id:`msess-error`,children:o}):null,!i&&!o&&n?(0,B.jsx)(zc,{detail:n}):null]})})}function zc({detail:e}){let t=Array.isArray(e.source_paths)?e.source_paths:[],n=[],r=[];t.forEach(e=>{Ic.test(e)?r.push(e):n.push(e)});let i=e.cost_total_usd??0,a=[[`Input`,e.input_tokens,null],[`Output`,e.output_tokens,null],[`Cache creation`,e.cache_creation_tokens,null],[`Cache read`,e.cache_read_tokens,null],[`Cache hit %`,e.cache_hit_pct,`cache-hit`]].filter(e=>e[1]!=null),o=!e.models||e.models.length===0,s=!e.cost_per_model||e.cost_per_model.length===0;return(0,B.jsxs)(`div`,{className:`modal-content`,id:`msess-content`,children:[(0,B.jsx)(`div`,{className:`m-chipstrip`,children:(0,B.jsx)(`span`,{className:`msess-badge`,id:`msess-id`,"aria-label":`Session ID`,children:e.session_id??`—`})}),(0,B.jsxs)(`div`,{className:`m-hero cols-3`,children:[(0,B.jsxs)(`div`,{className:`m-kv kv-cost`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#dollar`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`msess-cost`,children:e.cost_total_usd==null?`—`:`$`+e.cost_total_usd.toFixed(2)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Total cost`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-dur`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#clock`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`msess-dur`,children:e.duration_min==null?`—`:e.duration_min+` min`}),(0,B.jsx)(`div`,{className:`lbl`,children:`Duration`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-proj`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#folder`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,id:`msess-project`,title:e.project_path??``,"aria-label":`Project`,children:e.project_label??e.project_path??`—`}),(0,B.jsx)(`div`,{className:`lbl`,children:`Project`})]})]})]}),(0,B.jsxs)(`div`,{className:`msess-ts`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#calendar`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`started`}),(0,B.jsx)(`span`,{className:`v`,id:`msess-started`,children:e.started_utc??`—`})]}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`last activity`}),(0,B.jsx)(`span`,{className:`v`,id:`msess-last`,children:e.last_activity_utc??`—`})]})]}),(0,B.jsxs)(`h3`,{className:`m-sec sec-tok`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),`Tokens`]}),(0,B.jsx)(`div`,{className:`msess-tok-grid`,id:`msess-tokens`,children:a.map(([e,t,n])=>(0,B.jsxs)(`div`,{className:`msess-tok-tile`+(n?` `+n:``),children:[(0,B.jsx)(`div`,{className:`lbl`,children:e}),(0,B.jsx)(`div`,{className:`n`,children:n===`cache-hit`?t.toFixed(1)+`%`:t.toLocaleString(`en-US`)}),n===`cache-hit`?(0,B.jsx)(`div`,{className:`bar`,children:(0,B.jsx)(`div`,{className:`fill`,style:{width:Math.max(0,Math.min(t,100))+`%`}})}):null]},e))}),(0,B.jsx)(Fc,{sessionId:e.session_id??null},e.session_id??`no-session`),o?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-mod`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#sparkles`})}),`Models`]}),(0,B.jsx)(`div`,{className:`m-chipstrip`,id:`msess-models`,children:(e.models||[]).map(e=>(0,B.jsx)(`span`,{className:`chip `+or(e.name),children:e.name},e.name))})]}),s?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-costm`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#pie-chart`})}),`Cost by model`]}),(0,B.jsxs)(`div`,{className:`msess-costm`,children:[(0,B.jsx)(`div`,{className:`bar`,id:`msess-cost-bar`,children:(e.cost_per_model||[]).map(e=>{let t=i>0&&e.cost_usd!=null?e.cost_usd/i*100:0;return(0,B.jsx)(`div`,{className:`seg `+or(e.model),style:{width:t+`%`}},e.model)})}),(0,B.jsx)(`div`,{className:`legend`,id:`msess-cost-legend`,children:(e.cost_per_model||[]).map(e=>{let t=i>0&&e.cost_usd!=null?e.cost_usd/i*100:0;return(0,B.jsxs)(`div`,{className:`lg`,children:[(0,B.jsx)(`span`,{className:`sw `+or(e.model)}),(0,B.jsx)(`span`,{className:`name`,children:e.model}),(0,B.jsx)(`span`,{className:`v`,children:e.cost_usd==null?`—`:`$`+e.cost_usd.toFixed(3)}),(0,B.jsxs)(`span`,{className:`pct`,children:[Math.round(t),`%`]})]},e.model)})})]})]}),t.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-src`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#file-text`})}),`Source files`]}),(0,B.jsxs)(`div`,{className:`msess-src`,id:`msess-src`,children:[(0,B.jsxs)(`div`,{className:`src-head`,children:[(0,B.jsxs)(`span`,{className:`count-pill`,children:[t.length,` file`,t.length===1?``:`s`]}),(0,B.jsxs)(`span`,{className:`sub`,children:[n.length,` primary`,r.length>0?(0,B.jsxs)(B.Fragment,{children:[` `,(0,B.jsx)(`span`,{className:`dot`,children:`·`}),` `,(0,B.jsxs)(`span`,{className:`subcount`,children:[r.length,` subagent`,r.length===1?``:`s`]})]}):null]})]}),n.length>0?n.map(e=>(0,B.jsx)(`div`,{className:`primary-path`,children:e},e)):r.length>0?(0,B.jsxs)(`div`,{className:`src-empty-primary`,children:[`No primary path resolved · `,r.length,` subagent path`,r.length===1?``:`s`,` below`]}):null,r.length>0?(0,B.jsxs)(`details`,{className:`subagents`,open:n.length===0,children:[(0,B.jsxs)(`summary`,{children:[`Show `,r.length,` subagent path`,r.length===1?``:`s`]}),(0,B.jsx)(`ul`,{className:`paths`,children:r.map(e=>(0,B.jsx)(`li`,{children:e},e))})]}):null]})]}):null]})}function Bc({row:e,variant:t,accentClass:n}){let r=Rn(),i={tz:r.resolvedTz,offsetLabel:r.offsetLabel},a=(e,t)=>`${F.datetimeShort(e,i)} → ${F.datetimeShort(t,i)}`,o=e.delta_cost_pct==null?`flat`:e.delta_cost_pct>0?`up`:e.delta_cost_pct<0?`down`:`flat`,s=t===`weekly`?`week`:t===`monthly`?`month`:`day`,c=t===`daily`?`Today`:`Now`;return(0,B.jsxs)(`div`,{className:`detail-card ${n}`,children:[(0,B.jsxs)(`div`,{className:`head`,children:[(0,B.jsxs)(`div`,{className:`big`,children:[e.label,e.is_current&&(0,B.jsx)(`span`,{className:`pill-current`,children:c})]}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`span`,{className:`cost`,style:{color:`var(--text)`,fontWeight:700},children:F.usd2(e.cost_usd)}),` `,e.delta_cost_pct==null?(0,B.jsx)(`span`,{className:`delta flat`,children:`—`}):(0,B.jsxs)(`span`,{className:`delta ${o}`,children:[F.deltaPct(e.delta_cost_pct),` vs prior `,s]})]})]}),t===`weekly`&&e.week_start_at&&e.week_end_at&&(0,B.jsxs)(`div`,{className:`window`,children:[`Subscription window: `,a(e.week_start_at,e.week_end_at)]}),(0,B.jsx)(`div`,{className:`model-stack`,role:`presentation`,children:e.models.map(e=>(0,B.jsx)(`span`,{className:e.chip,style:{width:`${e.cost_pct}%`}},e.model))}),(0,B.jsx)(`div`,{className:`chips`,children:e.models.map(e=>(0,B.jsxs)(`span`,{className:`chip ${e.chip}`,children:[e.display,` `,Math.round(e.cost_pct),`% · `,F.usd2(e.cost_usd)]},e.model))}),(0,B.jsxs)(`div`,{className:`tokens-row`,children:[(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Input`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.input_tokens)})]}),(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Output`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.output_tokens)})]}),(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Cache+`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.cache_creation_tokens)})]}),(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Cache-read`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.cache_read_tokens)})]}),(0,B.jsxs)(`div`,{className:`t`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Total`}),(0,B.jsx)(`span`,{className:`v`,children:F.compact(e.total_tokens)})]}),e.cache_hit_pct!=null&&(0,B.jsxs)(`div`,{className:`t cache`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Cache hit`}),(0,B.jsxs)(`span`,{className:`v`,children:[e.cache_hit_pct.toFixed(1),`%`]}),(0,B.jsx)(`div`,{className:`bar`,children:(0,B.jsx)(`div`,{className:`fill`,style:{width:`${Math.min(100,Math.max(0,e.cache_hit_pct))}%`}})})]})]}),t===`weekly`&&(0,B.jsxs)(`div`,{className:`stats2`,children:[(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Used %`}),(0,B.jsx)(`span`,{className:`v`,children:F.pct0(e.used_pct)})]}),(0,B.jsxs)(`div`,{className:`s`,children:[(0,B.jsx)(`span`,{className:`k`,children:`$/1%`}),(0,B.jsx)(`span`,{className:`v`,children:F.usd2(e.dollar_per_pct)})]})]})]})}function Vc(e){return e==null||e===0?`num`:e>0?`num delta-up`:`num delta-down`}function Hc(e){let t=new Set,n=[];for(let r of e.models)t.has(r.chip)||(t.add(r.chip),n.push(r.chip));return n}function Uc({row:e}){let t=Hc(e),n=t.slice(0,3),r=t.length>3?t.length-3:0;return(0,B.jsxs)(`span`,{className:`models-chips`,children:[n.map(e=>(0,B.jsx)(`span`,{className:`chip ${e}`,children:e},e)),r>0&&(0,B.jsxs)(`span`,{className:`models-chips-more`,children:[`…+`,r]})]})}function Wc({rows:e,variant:t,accentClass:n,selectedIndex:r,onSelect:i}){return(0,B.jsxs)(`table`,{className:`history-table history-table--${t} ${n}`,role:`grid`,"aria-rowcount":e.length,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:t===`weekly`?`Week`:`Month`}),(0,B.jsx)(`th`,{children:`Models`}),(0,B.jsx)(`th`,{className:`num`,children:`Cost (USD)`}),t===`weekly`&&(0,B.jsx)(`th`,{className:`num`,children:`Used %`}),t===`weekly`&&(0,B.jsx)(`th`,{className:`num`,children:`$/1%`}),(0,B.jsx)(`th`,{className:`num`,children:`Δ`})]})}),(0,B.jsx)(`tbody`,{children:e.map((e,n)=>(0,B.jsxs)(`tr`,{className:n===r?`selected`:void 0,"aria-rowindex":n+1,"aria-selected":n===r,onClick:()=>i(n),children:[(0,B.jsxs)(`td`,{children:[e.label,n===r?` ▶`:``]}),(0,B.jsx)(`td`,{children:(0,B.jsx)(Uc,{row:e})}),(0,B.jsx)(`td`,{className:`num`,children:F.usd2(e.cost_usd)}),t===`weekly`&&(0,B.jsx)(`td`,{className:`num`,children:F.pct0(e.used_pct)}),t===`weekly`&&(0,B.jsx)(`td`,{className:`num`,children:F.usd2(e.dollar_per_pct)}),(0,B.jsx)(`td`,{className:Vc(e.delta_cost_pct),children:F.deltaPct(e.delta_cost_pct)})]},e.label))})]})}function Gc(){let e=V()?.weekly?.rows??[],[t,n]=(0,_.useState)(0),r=e.length;(0,_.useEffect)(()=>En([{key:`ArrowDown`,scope:`modal`,when:()=>L().openModal===`weekly`,action:()=>n(e=>Math.min(e+1,Math.max(0,r-1)))},{key:`ArrowUp`,scope:`modal`,when:()=>L().openModal===`weekly`,action:()=>n(e=>Math.max(e-1,0))}]),[r]);let i=(0,B.jsx)(Vn,{panel:`weekly`,panelLabel:`Weekly`,triggerId:`weekly-modal`,onClick:()=>z(He(`weekly`,`weekly-modal`))});if(r===0)return(0,B.jsx)(cc,{title:`Weekly history · last 12`,accentClass:`accent-cyan`,headerExtras:i,children:(0,B.jsx)(`div`,{className:`panel-empty`,children:`No usage history yet.`})});let a=e[Math.min(t,r-1)];return(0,B.jsxs)(cc,{title:`Weekly history · last 12`,accentClass:`accent-cyan`,headerExtras:i,children:[(0,B.jsx)(Bc,{row:a,variant:`weekly`,accentClass:`accent-cyan`}),(0,B.jsx)(Wc,{rows:e,variant:`weekly`,accentClass:`accent-cyan`,selectedIndex:t,onSelect:n})]})}function Kc(){let e=V()?.monthly?.rows??[],[t,n]=(0,_.useState)(0),r=e.length;(0,_.useEffect)(()=>En([{key:`ArrowDown`,scope:`modal`,when:()=>L().openModal===`monthly`,action:()=>n(e=>Math.min(e+1,Math.max(0,r-1)))},{key:`ArrowUp`,scope:`modal`,when:()=>L().openModal===`monthly`,action:()=>n(e=>Math.max(e-1,0))}]),[r]);let i=(0,B.jsx)(Vn,{panel:`monthly`,panelLabel:`Monthly`,triggerId:`monthly-modal`,onClick:()=>z(He(`monthly`,`monthly-modal`))});if(r===0)return(0,B.jsx)(cc,{title:`Monthly history · last 12`,accentClass:`accent-pink`,headerExtras:i,children:(0,B.jsx)(`div`,{className:`panel-empty`,children:`No usage history yet.`})});let a=e[Math.min(t,r-1)];return(0,B.jsxs)(cc,{title:`Monthly history · last 12`,accentClass:`accent-pink`,headerExtras:i,children:[(0,B.jsx)(Bc,{row:a,variant:`monthly`,accentClass:`accent-pink`}),(0,B.jsx)(Wc,{rows:e,variant:`monthly`,accentClass:`accent-pink`,selectedIndex:t,onSelect:n})]})}var qc=720,Jc=180,Yc={left:46,right:20,top:18,bottom:20};function Xc(e){return e===0?`$0`:e<10?`$`+e.toFixed(2):`$`+Math.round(e).toString()}function Zc(){return(0,_.useSyncExternalStore)(R,()=>L().snapshot?.generated_at??``)}function Qc({detail:e}){let t=Zc(),n=Rn(),r={tz:n.resolvedTz,offsetLabel:n.offsetLabel},i=Date.parse(e.start_at),a=Date.parse(e.end_at)-i||1,o=e=>Yc.left+(Date.parse(e)-i)/a*(qc-Yc.left-Yc.right),s=Math.max(e.cost_usd,e.projection?.total_cost_usd??0),c=e=>{let t=Yc.top,n=Jc-Yc.bottom;return s<=0?n:n-e/s*(n-t)},l=[];for(let e=0;e<=5;e++)l.push(new Date(i+e*36e5).toISOString());let u=e.samples.length>0?e.samples[e.samples.length-1].cum:0,d=e.is_active?t||new Date().toISOString():null,f=[];if(e.samples.length>0){f.push([o(e.start_at),c(0)]);for(let t of e.samples)f.push([o(t.t),c(t.cum)]);d&&f.push([o(d),c(u)])}let p=f.map(([e,t])=>`${e.toFixed(1)},${t.toFixed(1)}`).join(` `),m=f.length>0?`M ${p.replace(/ /g,` L `)} L ${f[f.length-1][0].toFixed(1)},${c(0).toFixed(1)} Z`:``,h=s<=0?[0]:[0,s/2,s];return(0,B.jsx)(`div`,{className:`mblock-timeline`,children:(0,B.jsxs)(`svg`,{viewBox:`0 0 ${qc} ${Jc}`,style:{width:`100%`,height:`auto`},role:`img`,"aria-label":`Cumulative cost over the 5-hour block window`,children:[h.map(e=>(0,B.jsx)(`text`,{x:8,y:c(e)+4,fill:`var(--text-dim)`,fontSize:10,children:Xc(e)},e)),(0,B.jsx)(`line`,{x1:Yc.left,y1:Yc.top,x2:Yc.left,y2:Jc-Yc.bottom,stroke:`var(--border-soft)`,strokeWidth:.8}),(0,B.jsx)(`line`,{x1:Yc.left,y1:Jc-Yc.bottom,x2:qc-Yc.right,y2:Jc-Yc.bottom,stroke:`var(--border-soft)`,strokeWidth:.8}),l.slice(1,-1).map(e=>(0,B.jsx)(`line`,{x1:o(e),y1:Yc.top,x2:o(e),y2:Jc-Yc.bottom,stroke:`var(--border-soft)`,strokeDasharray:`2 3`,strokeWidth:.5},e)),l.map(e=>(0,B.jsx)(`text`,{x:o(e)-14,y:Jc-5,fill:`var(--text-dim)`,fontSize:9,children:F.timeHHmm(e,r,{noSuffix:!0})},e)),f.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`path`,{d:m,fill:`var(--accent-green)`,opacity:.12}),(0,B.jsx)(`polyline`,{points:p,fill:`none`,stroke:`var(--accent-green)`,strokeWidth:2}),(0,B.jsx)(`circle`,{cx:f[f.length-1][0],cy:f[f.length-1][1],r:3,fill:`var(--accent-green)`})]}):(0,B.jsx)(`text`,{x:qc/2,y:Jc/2,fill:`var(--text-faint)`,fontSize:11,textAnchor:`middle`,children:`No spend recorded yet in this block.`}),e.is_active&&e.projection&&d&&f.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`polyline`,{points:`${o(d).toFixed(1)},${c(u).toFixed(1)} ${o(e.end_at).toFixed(1)},${c(e.projection.total_cost_usd).toFixed(1)}`,fill:`none`,stroke:`var(--accent-amber)`,strokeWidth:1.5,strokeDasharray:`5 4`,opacity:.85}),(0,B.jsx)(`circle`,{cx:o(e.end_at),cy:c(e.projection.total_cost_usd),r:3,fill:`var(--accent-amber)`,opacity:.85}),(0,B.jsxs)(`text`,{x:o(e.end_at)-50,y:c(e.projection.total_cost_usd)-6,fill:`var(--accent-amber)`,fontSize:9,children:[`proj $`,e.projection.total_cost_usd.toFixed(2)]}),(0,B.jsx)(`line`,{x1:o(d),y1:Yc.top,x2:o(d),y2:Jc-Yc.bottom,stroke:`var(--accent-amber)`,strokeWidth:1.2}),(0,B.jsx)(`text`,{x:o(d)+4,y:Yc.top+10,fill:`var(--accent-amber)`,fontSize:9,children:`now`})]}):null]})})}function $c(){return(0,_.useSyncExternalStore)(R,()=>L().snapshot?.generated_at??``)}function el(e,t){let n=Date.parse(e.start_at),r=e.is_active?Date.parse(t)||Date.now():e.actual_end_at?Date.parse(e.actual_end_at):Date.parse(e.end_at),i=Math.max(0,Math.floor((r-n)/6e4)),a=Math.floor(i/60),o=i%60;return`${a}h ${String(o).padStart(2,`0`)}m`}function tl(e,t,n){return`${F.timeHHmm(e,n)} → ${F.timeHHmm(t,n)}`}function nl(){let e=(0,_.useSyncExternalStore)(R,()=>L().openBlockStartAt),t=$c(),n=Rn(),r={tz:n.resolvedTz,offsetLabel:n.offsetLabel},[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!0),[c,l]=(0,_.useState)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(!1),f=(0,_.useRef)(null);return(0,_.useEffect)(()=>{f.current=e??null,d.current=!1},[e]),(0,_.useEffect)(()=>{let e=f.current;if(!e){s(!1),l(`No block bound.`),a(null),u.current=null;return}let t=u.current!==e||i==null;u.current=e,t&&(s(!0),l(null),a(null));let n=new AbortController;return fetch(`/api/block/${encodeURIComponent(e)}`,{signal:n.signal}).then(async e=>{if(e.status===404){(t||d.current)&&(s(!1),l(`Block not found (the cache may have rolled forward).`),a(null)),d.current=!0;return}if(!e.ok)throw Error(`HTTP `+e.status);let n=await e.json();d.current=!1,a(n),l(null),s(!1)}).catch(e=>{e.name!==`AbortError`&&(d.current=!1,t&&(l(`Failed to load: `+e.message),s(!1)))}),()=>n.abort()},[e,t]),(0,B.jsx)(cc,{title:i?`${i.anchor===`heuristic`?`~ `:``}Block · ${i.label}`:`Block`,accentClass:`accent-blue`,headerExtras:(0,B.jsx)(Vn,{panel:`blocks`,panelLabel:`5-hour block`,triggerId:`block-modal`,onClick:()=>z(He(`blocks`,`block-modal`))}),children:(0,B.jsxs)(`section`,{className:`modal-block`,children:[o?(0,B.jsx)(`div`,{className:`modal-loading`,children:`Loading block detail…`}):null,c?(0,B.jsx)(`div`,{className:`modal-error`,children:c}):null,!o&&!c&&i?(0,B.jsx)(rl,{detail:i,generatedAt:t,ctx:r}):null]})})}function rl({detail:e,generatedAt:t,ctx:n}){let r=e.cost_usd??0;return(0,B.jsxs)(`div`,{className:`modal-content`,children:[(0,B.jsxs)(`div`,{className:`m-chipstrip`,children:[e.is_active?(0,B.jsx)(`span`,{className:`m-pill accent-green`,children:`● Active`}):null,e.anchor===`heuristic`?(0,B.jsx)(`span`,{className:`m-pill accent-amber`,children:`~ heuristic anchor`}):null,(0,B.jsx)(`span`,{className:`m-pill accent-blue`,children:tl(e.start_at,e.end_at,n)}),(0,B.jsxs)(`span`,{className:`m-pill`,children:[e.entries_count.toLocaleString(`en-US`),` `,e.entries_count===1?`entry`:`entries`]})]}),(0,B.jsxs)(`div`,{className:`m-hero `+(e.is_active?`cols-4`:`cols-3`),children:[(0,B.jsxs)(`div`,{className:`m-kv kv-cost`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#dollar`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,children:F.usd2(e.cost_usd)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Total cost`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv kv-dur`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#clock`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,children:el(e,t)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Elapsed`})]})]}),(0,B.jsxs)(`div`,{className:`m-kv`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,children:e.total_tokens.toLocaleString(`en-US`)}),(0,B.jsx)(`div`,{className:`lbl`,children:`Total tokens`})]})]}),e.is_active?(0,B.jsxs)(`div`,{className:`m-kv kv-proj`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#crystal-ball`})}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`v`,children:e.projection?F.usd2(e.projection.total_cost_usd):`—`}),(0,B.jsxs)(`div`,{className:`lbl`,children:[`Projected`,e.projection?` · ${e.projection.remaining_minutes}m left`:``]})]})]}):null]}),(0,B.jsx)(Qc,{detail:e}),(0,B.jsxs)(`h3`,{className:`m-sec sec-tok`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#hash`})}),`Tokens`]}),(0,B.jsxs)(`div`,{className:`msess-tok-grid mblock-tok-grid`,children:[(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Input`}),(0,B.jsx)(`div`,{className:`n`,children:e.input_tokens.toLocaleString(`en-US`)})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Output`}),(0,B.jsx)(`div`,{className:`n`,children:e.output_tokens.toLocaleString(`en-US`)})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Cache create`}),(0,B.jsx)(`div`,{className:`n`,children:e.cache_creation_tokens.toLocaleString(`en-US`)})]}),(0,B.jsxs)(`div`,{className:`msess-tok-tile`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Cache read`}),(0,B.jsx)(`div`,{className:`n`,children:e.cache_read_tokens.toLocaleString(`en-US`)})]}),e.cache_hit_pct==null?null:(0,B.jsxs)(`div`,{className:`msess-tok-tile cache-hit`,children:[(0,B.jsx)(`div`,{className:`lbl`,children:`Cache hit %`}),(0,B.jsxs)(`div`,{className:`n`,children:[e.cache_hit_pct.toFixed(1),`%`]}),(0,B.jsx)(`div`,{className:`bar`,children:(0,B.jsx)(`div`,{className:`fill`,style:{width:Math.min(100,Math.max(0,e.cache_hit_pct))+`%`}})})]})]}),e.models.length>0?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-costm`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#pie-chart`})}),`Cost by model`]}),(0,B.jsxs)(`div`,{className:`msess-costm`,children:[(0,B.jsx)(`div`,{className:`bar`,children:e.models.map(e=>{let t=r>0?e.cost_usd/r*100:0;return(0,B.jsx)(`div`,{className:`seg `+or(e.model),style:{width:t+`%`}},e.model)})}),(0,B.jsx)(`div`,{className:`legend`,children:e.models.map(e=>{let t=r>0?e.cost_usd/r*100:0;return(0,B.jsxs)(`div`,{className:`lg`,children:[(0,B.jsx)(`span`,{className:`sw `+or(e.model)}),(0,B.jsx)(`span`,{className:`name`,children:e.display}),(0,B.jsxs)(`span`,{className:`v`,children:[`$`,e.cost_usd.toFixed(2)]}),(0,B.jsxs)(`span`,{className:`pct`,children:[Math.round(t),`%`]})]},e.model)})})]})]}):null,e.is_active&&e.burn_rate&&e.projection?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`h3`,{className:`m-sec sec-burn`,children:[(0,B.jsx)(`svg`,{className:`icon`,"aria-hidden":`true`,children:(0,B.jsx)(`use`,{href:`/static/icons.svg#crystal-ball`})}),`Burn rate & projection`]}),(0,B.jsxs)(`div`,{className:`mblock-burn`,children:[(0,B.jsxs)(`div`,{className:`row`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Burn rate`}),(0,B.jsx)(`span`,{className:`v amber`,children:F.usd2(e.burn_rate.cost_per_hour)}),(0,B.jsx)(`span`,{className:`dim`,children:`/ hr`}),(0,B.jsx)(`span`,{className:`sep`,children:`·`}),(0,B.jsx)(`span`,{className:`v cyan`,children:Math.round(e.burn_rate.tokens_per_minute).toLocaleString(`en-US`)}),(0,B.jsx)(`span`,{className:`dim`,children:`tok / min`})]}),(0,B.jsxs)(`div`,{className:`row`,children:[(0,B.jsx)(`span`,{className:`k`,children:`Projection`}),(0,B.jsx)(`span`,{className:`v amber`,children:F.usd2(e.projection.total_cost_usd)}),(0,B.jsx)(`span`,{className:`dim`,children:`total`}),(0,B.jsx)(`span`,{className:`sep`,children:`·`}),(0,B.jsx)(`span`,{className:`v cyan`,children:e.projection.total_tokens.toLocaleString(`en-US`)}),(0,B.jsx)(`span`,{className:`dim`,children:`tok`}),(0,B.jsx)(`span`,{className:`sep`,children:`·`}),(0,B.jsxs)(`span`,{className:`v`,children:[e.projection.remaining_minutes,` min`]}),(0,B.jsx)(`span`,{className:`dim`,children:`remaining`})]})]})]}):null]})}function il(e,t,n){if(!t)return null;let r=e.findIndex(e=>e.date===t);return r<0?null:n===`older`?r>=e.length-1?null:e[r+1].date:r<=0?null:e[r-1].date}function al({rows:e,selectedDate:t,onSelect:n}){let r=[...e].reverse(),i=r.reduce((e,t)=>Math.max(e,t.cost_usd),0),a=r.length>0?ol(r[0].date):``,o=r.length>0?ol(r[r.length-1].date):``,s=r.find(e=>e.is_today),c=s?`${ol(s.date)} · today`:``;return(0,B.jsxs)(`section`,{className:`daily-modal-bars`,"aria-label":`30-day cost`,children:[(0,B.jsxs)(`div`,{className:`daily-modal-bars-head`,children:[(0,B.jsxs)(`span`,{className:`daily-bars-nav`,children:[(0,B.jsx)(`button`,{type:`button`,className:`daily-step-btn`,"aria-label":`Step to older day`,disabled:il(e,t,`older`)===null,onClick:()=>{let r=il(e,t,`older`);r&&n(r)},children:`‹`}),(0,B.jsxs)(`span`,{children:[`30-day cost · selected: `,t?ol(t):`—`]}),(0,B.jsx)(`button`,{type:`button`,className:`daily-step-btn`,"aria-label":`Step to newer day`,disabled:il(e,t,`newer`)===null,onClick:()=>{let r=il(e,t,`newer`);r&&n(r)},children:`›`})]}),(0,B.jsx)(`span`,{className:`hint hint-desktop`,children:`↑↓ navigate · click any bar`}),(0,B.jsx)(`span`,{className:`hint hint-mobile`,children:`‹ › to step · tap a bar`})]}),(0,B.jsx)(`div`,{className:`daily-modal-bars-grid`,role:`img`,"aria-label":`30-day cost histogram`,children:r.map(e=>{let r=e.cost_usd<=0,a=e.date===t,o=r?4:i>0?e.cost_usd/i*100:0,s=[`bar`,r?`zero`:``,a?`sel`:``,e.is_today?`today`:``].filter(Boolean).join(` `);return(0,B.jsx)(`button`,{"data-date":e.date,className:s,style:{height:`${o}%`},disabled:r,"aria-pressed":a,"aria-label":`${e.label} cost ${e.cost_usd>0?F.usd2(e.cost_usd):`no usage`}`,title:e.cost_usd>0?`${e.label} · ${F.usd2(e.cost_usd)}`:`${e.label} · —`,onClick:()=>{r||n(e.date)}},e.date)})}),r.length>0&&(0,B.jsxs)(`div`,{className:`daily-modal-bars-axis`,children:[(0,B.jsx)(`span`,{children:a}),c&&(0,B.jsx)(`span`,{children:c}),(0,B.jsx)(`span`,{children:o})]})]})}function ol(e){let t=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],n=e.split(`-`).map(Number);return`${t[n[1]-1]} ${n[2]}`}function sl(){let e=V()?.daily?.rows??[],t=(0,_.useSyncExternalStore)(R,()=>L().openDailyDate),[n,r]=(0,_.useState)(null);(0,_.useEffect)(()=>{t&&r(t)},[]);let i=new Set(e.map(e=>e.date)),a=e[0]?.date??null,o=n&&i.has(n)?n:a;(0,_.useEffect)(()=>En([{key:`ArrowDown`,scope:`modal`,when:()=>L().openModal===`daily`,action:()=>{let t=il(e,o,`older`);t&&r(t)}},{key:`ArrowUp`,scope:`modal`,when:()=>L().openModal===`daily`,action:()=>{let t=il(e,o,`newer`);t&&r(t)}}]),[e,o]);let s=(0,B.jsx)(Vn,{panel:`daily`,panelLabel:`Daily`,triggerId:`daily-modal`,onClick:()=>z(He(`daily`,`daily-modal`))});if(e.length===0)return(0,B.jsx)(cc,{title:`Daily history · last 30`,accentClass:`accent-indigo`,headerExtras:s,children:(0,B.jsx)(`div`,{className:`panel-empty`,children:`No usage history yet.`})});let c=e.findIndex(e=>e.date===o),l=c>=0?c:0,u=e[l],d=e[l+1],f=cl(u,d);return(0,B.jsxs)(cc,{title:`Daily history · last 30`,accentClass:`accent-indigo`,headerExtras:s,children:[(0,B.jsx)(al,{rows:e,selectedDate:o,onSelect:r}),(0,B.jsx)(Bc,{row:f,variant:`daily`,accentClass:`accent-indigo`})]})}function cl(e,t){let n=t&&t.cost_usd>0?(e.cost_usd-t.cost_usd)/t.cost_usd:null;return{label:e.label,cost_usd:e.cost_usd,total_tokens:e.total_tokens,input_tokens:e.input_tokens,output_tokens:e.output_tokens,cache_creation_tokens:e.cache_creation_tokens,cache_read_tokens:e.cache_read_tokens,used_pct:null,dollar_per_pct:null,delta_cost_pct:n,is_current:e.is_today,models:e.models,cache_hit_pct:e.cache_hit_pct}}var ll=[`#d946ef`,`#c084fc`,`#60a5fa`,`#fbbf24`,`#22d3ee`],ul=`#64748b`,dl=5,fl=400,pl=150;function ml({trend:e,yMode:t,windowWeeks:n,onProjectSelect:r}){let i=(0,_.useMemo)(()=>{let t=Math.max(0,Math.min(n,e.window_weeks)),r=e.weeks.slice(-t),i=e.projects.map(e=>{let n=e.weekly_cost.slice(-t),r=n.reduce((e,t)=>e+t,0);return{key:e.key,weekly:n,cost:r,color:``}}).sort((e,t)=>t.cost-e.cost),a=i.slice(0,dl).map((e,t)=>({...e,color:ll[t]??ul})),o=i.slice(dl),s=r.map((e,t)=>o.reduce((e,n)=>e+(n.weekly[t]??0),0)),c=s.reduce((e,t)=>e+t,0),l=[...a];return o.length>0&&c>0&&l.push({key:`(other)`,weekly:s,cost:c,color:ul}),{weeks:r,series:l}},[e,n]),a=rr();if(i.weeks.length===0||i.series.length===0)return(0,B.jsxs)(`div`,{className:`panel-empty`,children:[`No project activity in the last `,n,` week`,n===1?``:`s`,`.`]});let o=i.weeks.length,s=i.weeks.map((e,t)=>i.series.reduce((e,n)=>e+(n.weekly[t]??0),0)),c=t===`share`?100:Math.max(...s,.01),l=(e,t=`left`)=>o<=1?t===`left`?fl*.1:fl*.9:e/(o-1)*fl,u=Array(o).fill(0),d=i.series.map(e=>{let n=[];for(let e=0;e<o;e++){let t=pl-u[e]/c*pl;n.push(`${l(e,`left`).toFixed(2)},${t.toFixed(2)}`),o===1&&n.push(`${l(e,`right`).toFixed(2)},${t.toFixed(2)}`)}for(let r=o-1;r>=0;r--){let i=s[r]??0,a=t===`share`?i>0?(e.weekly[r]??0)/i*100:0:e.weekly[r]??0;u[r]+=a;let d=pl-u[r]/c*pl;o===1&&n.push(`${l(r,`right`).toFixed(2)},${d.toFixed(2)}`),n.push(`${l(r,`left`).toFixed(2)},${d.toFixed(2)}`)}return{color:e.color,key:e.key,points:n.join(` `)}}),f=i.weeks.map(e=>(0,B.jsx)(`span`,{children:e.week_label},e.week_start_date));return(0,B.jsxs)(`div`,{className:`projects-trend`,children:[(0,B.jsx)(`svg`,{viewBox:`0 0 ${fl} ${pl}`,preserveAspectRatio:`none`,role:`img`,"aria-label":`Stacked area: project ${t===`share`?`share %`:`cost`} over ${o} weeks`,children:d.map(e=>{let t=e.key===`(other)`;return(0,B.jsx)(`polygon`,{fill:e.color,opacity:t?.5:.65,points:e.points,"data-series-key":e.key,onClick:()=>{t||r?.(e.key)},style:{cursor:t?`default`:`pointer`}},e.key)})}),(0,B.jsx)(`div`,{className:`projects-trend-xaxis`,children:f}),(0,B.jsx)(`div`,{className:`projects-trend-legend`,children:i.series.map(e=>{let t=e.key===`(other)`,n=(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`sw`,style:{background:e.color}}),e.key]});return a&&!t?(0,B.jsx)(`button`,{type:`button`,className:`projects-trend-legend-item`,"data-series-key":e.key,onClick:()=>r?.(e.key),children:n},e.key):(0,B.jsx)(`span`,{className:`projects-trend-legend-item`,"data-series-key":e.key,children:n},e.key)})})]})}function hl(e,t){let[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),c=V()?.generated_at??``,l=(0,_.useRef)(0),u=(0,_.useRef)(null),d=(0,_.useRef)(null),f=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{if(!e){r(null),a(!1),s(null),l.current=0,u.current=null,d.current=null,f.current=!1;return}let i=u.current!==e||d.current!==t,o=i||n==null;if(o&&f.current&&!i)return;o&&(a(!0),s(null)),i&&(l.current=0),u.current=e,d.current=t,f.current=!0;let c=new AbortController,p=`/api/project/${encodeURIComponent(e)}?weeks=${t}`;return fetch(p,{signal:c.signal}).then(async e=>{if(e.status===404){l.current+=1,l.current>=2?(r(null),s(`Project no longer in cache — close this drill.`),a(!1)):o&&(s(`Couldn't load project detail — will retry on next tick.`),a(!1));return}if(!e.ok){o&&(s(`Couldn't load project detail — will retry on next tick.`),a(!1));return}l.current=0,r(await e.json()),s(null),a(!1)}).catch(e=>{e?.name!==`AbortError`&&o&&(s(`Couldn't load project detail — will retry on next tick.`),a(!1))}).finally(()=>{f.current=!1}),()=>c.abort()},[e,t,c]),{data:n,loading:i,error:o}}function gl({projectKey:e,windowWeeks:t}){let{data:n,loading:r,error:i}=hl(e,t),a=Rn(),o={tz:a.resolvedTz,offsetLabel:a.offsetLabel},s=n!=null&&(n.key!==e||n.window_weeks!==t);if(r&&!n||s)return(0,B.jsx)(`div`,{className:`panel-empty`,children:`Loading…`});if(i&&!n)return(0,B.jsx)(`div`,{className:`panel-empty`,children:i});if(!n)return null;let c=n.models[0]?.cost_usd??0,l=c>0?c:1,u=Math.max(0,n.sessions_total-n.sessions.length);return(0,B.jsxs)(`div`,{className:`projects-drill`,"data-testid":`projects-drill`,"aria-live":`polite`,children:[(0,B.jsx)(`div`,{className:`projects-drill-head`,children:(0,B.jsxs)(`span`,{className:`title`,children:[`▾ `,n.key,` · `,n.sessions_total,` session`,n.sessions_total===1?``:`s`,` · `,F.usd2(n.window_cost_usd),` (`,t,`w)`]})}),(0,B.jsxs)(`div`,{className:`projects-drill-grid`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`section-label`,children:`Models (this project)`}),n.models.length===0?(0,B.jsx)(`div`,{className:`muted`,children:`No model data for this window.`}):n.models.map(e=>{let t={"--w":`${e.cost_usd/l*100}%`};return(0,B.jsxs)(`div`,{className:`drill-bar-row`,children:[(0,B.jsx)(`span`,{className:`chip ${or(e.model)}`,children:e.model}),(0,B.jsx)(`div`,{className:`drill-bar`,style:t}),(0,B.jsx)(`span`,{className:`cost ${cr(e.cost_usd)}`,children:F.usd2(e.cost_usd)})]},e.model)})]}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`section-label`,children:`Recent sessions →`}),n.sessions.length===0?(0,B.jsx)(`div`,{className:`muted`,children:`No sessions for this window.`}):n.sessions.map((e,t)=>(0,B.jsxs)(`button`,{"data-testid":`drill-session-${t}`,className:`drill-session-row`,onClick:()=>z({type:`OPEN_MODAL`,kind:`session`,sessionId:e.session_id}),children:[(0,B.jsx)(`span`,{className:`started`,children:F.datetimeShort(e.last_activity_at,o)}),(0,B.jsx)(`span`,{className:`chip ${or(e.primary_model)}`,children:e.primary_model}),(0,B.jsx)(`span`,{className:`cost ${cr(e.cost_usd)}`,children:F.usd2(e.cost_usd)})]},e.session_id)),(0,B.jsxs)(`div`,{className:`drill-session-footer`,children:[u>0&&(0,B.jsxs)(`span`,{className:`muted`,children:[`+`,u,` more`]}),(0,B.jsx)(`button`,{type:`button`,"data-testid":`drill-show-in-sessions`,className:`drill-show-in-sessions`,onClick:()=>{z({type:`SET_FILTER`,text:n.key}),z({type:`CLOSE_MODAL`})},children:`Show in Sessions →`})]})]})]})]})}var _l=(e,t)=>e<t?-1:+(e>t),vl=[{id:`project`,label:`Project`,defaultDirection:`asc`,compare:(e,t)=>_l(e.key,t.key),className:`project`},{id:`sessions`,label:`Sessions`,defaultDirection:`desc`,numeric:!0,compare:(e,t)=>e.sessionsCount-t.sessionsCount},{id:`first_seen`,label:`First seen`,defaultDirection:`asc`,nullKey:e=>e.firstSeenAt,compare:(e,t)=>_l(e.firstSeenAt,t.firstSeenAt),className:`started`},{id:`last_seen`,label:`Last seen`,defaultDirection:`desc`,nullKey:e=>e.lastSeenAt,compare:(e,t)=>_l(e.lastSeenAt,t.lastSeenAt),className:`started`},{id:`cost`,label:`Cost`,defaultDirection:`desc`,numeric:!0,compare:(e,t)=>e.windowCost-t.windowCost},{id:`used_pct`,label:`Used %`,defaultDirection:`desc`,numeric:!0,nullKey:e=>e.windowPct,compare:(e,t)=>e.windowPct-t.windowPct},{id:`share_of_window`,label:`% of week`,defaultDirection:`desc`,numeric:!0,nullKey:e=>e.shareOfWindow,compare:(e,t)=>e.shareOfWindow-t.shareOfWindow}],yl=[{column:`cost`,direction:`desc`,label:`cost`,arrow:`↓`},{column:`sessions`,direction:`desc`,label:`sessions`,arrow:`↓`},{column:`used_pct`,direction:`desc`,label:`used`,arrow:`↓`},{column:`share_of_window`,direction:`desc`,label:`share`,arrow:`↓`},{column:`first_seen`,direction:`asc`,label:`first`,arrow:`↑`},{column:`last_seen`,direction:`desc`,label:`last`,arrow:`↓`},{column:`project`,direction:`asc`,label:`project`,arrow:`↑`}],bl=[1,4,8,12];function xl(){let e=V(),t=Rn(),n={tz:t.resolvedTz,offsetLabel:t.offsetLabel},r=(0,_.useSyncExternalStore)(R,()=>L().openProjectKey),i=(0,_.useSyncExternalStore)(R,()=>L().prefs.projectsWindowWeeks),a=(0,_.useSyncExternalStore)(R,()=>L().prefs.projectsTrendYMode),o=(0,_.useSyncExternalStore)(R,()=>L().prefs.projectsSortOverride),[s,c]=(0,_.useState)(r??null),[l,u]=(0,_.useState)(!1);(0,_.useEffect)(()=>{if(r){c(r);return}s||c(e?.projects?.current_week?.rows?.[0]?.key??null)},[r,e?.projects?.current_week?.rows]),(0,_.useEffect)(()=>{r||s&&((e?.projects?.trend?.projects??[]).some(e=>e.key===s)||c(e?.projects?.current_week?.rows?.[0]?.key??null))},[r,s,e?.projects?.trend?.projects,e?.projects?.current_week?.rows]);let d=e?.projects?.trend??null,f=i,p=d?.window_weeks??0,m=(e,t)=>{z({type:`SAVE_PREFS`,patch:{[e]:t}})},h=e=>{c(t=>t===e?null:e)},g=(d?.projects??[]).map(e=>{let t=e.weekly_cost.slice(-i),n=e.weekly_pct.slice(-i),r=e.sessions_per_week.slice(-i),a=e.first_seen_per_week.slice(-i),o=e.last_seen_per_week.slice(-i),s=t.reduce((e,t)=>e+t,0),c=n.reduce((e,t)=>t==null?e:(e??0)+t,null),l=r.reduce((e,t)=>e+t,0),u=a.reduce((e,t)=>t==null?e:e==null||t<e?t:e,null),d=o.reduce((e,t)=>t==null?e:e==null||t>e?t:e,null);return{key:e.key,sessionsCount:l,firstSeenAt:u,lastSeenAt:d,windowCost:s,windowPct:c,shareOfWindow:null}}),v=g.reduce((e,t)=>e+t.windowCost,0);for(let e of g)e.shareOfWindow=v>0?e.windowCost/v*100:null;let y=o?Ie(g,vl,o):Ie(g,vl,{column:`cost`,direction:`desc`}),b=y.filter(e=>e.windowCost>0).slice(0,10),x=y.length-b.length,S=l?y:b,C=x>0,w=rr(),T=(()=>{if(!o)return 0;let e=yl.findIndex(e=>e.column===o.column&&e.direction===o.direction);return e===-1?0:e})(),E=()=>{let e=yl[(T+1)%yl.length];z({type:`SET_TABLE_SORT`,table:`projects`,override:{column:e.column,direction:e.direction}})},D=yl[T],O=()=>L().shareModal===null&&L().composerModal===null;return On([{key:`1`,scope:`modal`,when:O,action:()=>m(`projectsWindowWeeks`,1)},{key:`4`,scope:`modal`,when:O,action:()=>m(`projectsWindowWeeks`,4)},{key:`8`,scope:`modal`,when:O,action:()=>m(`projectsWindowWeeks`,8)},{key:`0`,scope:`modal`,when:O,action:()=>m(`projectsWindowWeeks`,12)},{key:`s`,scope:`modal`,when:O,action:()=>m(`projectsTrendYMode`,a===`share`?`absolute`:`share`)},{key:`ArrowUp`,scope:`modal`,when:O,action:()=>{if(S.length===0)return;let e=S.findIndex(e=>e.key===s);c(S[e<=0?S.length-1:e-1].key)}},{key:`ArrowDown`,scope:`modal`,when:O,action:()=>{if(S.length===0)return;let e=S.findIndex(e=>e.key===s);c(S[e===-1||e===S.length-1?0:e+1].key)}},{key:`Enter`,scope:`modal`,when:O,action:()=>{s?c(null):S.length>0&&c(S[0].key)}}]),(0,B.jsx)(cc,{title:`Projects · last ${i}w`,accentClass:`accent-magenta`,headerExtras:(0,B.jsx)(Vn,{panel:`projects`,panelLabel:`Projects`,triggerId:`projects-modal`,dataTestId:`share-icon-projects-modal`,onClick:()=>z(He(`projects`,`projects-modal`,{windowWeeks:i}))}),children:(0,B.jsxs)(`div`,{className:`projects-modal-body`,children:[(0,B.jsxs)(`div`,{className:`projects-controls`,role:`radiogroup`,"aria-label":`Window`,children:[bl.map(e=>(0,B.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":i===e,className:`pill ${i===e?`on`:``}`,onClick:()=>m(`projectsWindowWeeks`,e),children:[e,`w`]},`window-${e}`)),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`|`}),(0,B.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":a===`share`,className:`pill ${a===`share`?`on`:``}`,onClick:()=>m(`projectsTrendYMode`,`share`),children:`share %`}),(0,B.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":a===`absolute`,className:`pill ${a===`absolute`?`on`:``}`,onClick:()=>m(`projectsTrendYMode`,`absolute`),children:`$ absolute`})]}),p>0&&p<f&&(0,B.jsxs)(`div`,{className:`projects-notice`,children:[`Showing `,p,` week`,p===1?``:`s`,` (need more history for the full window).`]}),d?(0,B.jsx)(ml,{trend:d,yMode:a,windowWeeks:i,onProjectSelect:e=>c(e)}):(0,B.jsx)(`div`,{className:`panel-empty`,children:`Projects trend unavailable.`}),w&&(0,B.jsxs)(`button`,{type:`button`,className:`projects-mobile-sort`,"data-testid":`projects-mobile-sort`,onClick:E,"aria-label":`Cycle sort column`,children:[`Sort: `,D.label,` `,D.arrow]}),(0,B.jsxs)(`table`,{className:`projects-table`,children:[(0,B.jsx)(Zn,{columns:vl,override:o,onChange:e=>z({type:`SET_TABLE_SORT`,table:`projects`,override:e}),accentVar:`--accent-magenta`}),(0,B.jsx)(`tbody`,{children:S.map(e=>(0,B.jsxs)(_.Fragment,{children:[(0,B.jsxs)(`tr`,{"data-testid":`projects-table-row`,"data-cost":e.windowCost,"data-sessions":e.sessionsCount,"aria-expanded":s===e.key,className:s===e.key?`selected`:``,onClick:()=>h(e.key),children:[(0,B.jsx)(`td`,{className:`project`,children:e.key}),(0,B.jsx)(`td`,{children:e.sessionsCount}),(0,B.jsx)(`td`,{className:`started first-seen`,children:F.dateShort(e.firstSeenAt,n)??`—`}),(0,B.jsx)(`td`,{className:`started last-seen`,children:F.dateShort(e.lastSeenAt,n)??`—`}),(0,B.jsx)(`td`,{className:cr(e.windowCost),children:F.usd2(e.windowCost)}),(0,B.jsx)(`td`,{children:e.windowPct==null?`—`:F.pct0(e.windowPct)}),(0,B.jsx)(`td`,{children:e.shareOfWindow==null?`—`:F.pct0(e.shareOfWindow)})]}),w&&s===e.key&&(0,B.jsx)(`tr`,{className:`projects-drill-row`,"aria-hidden":`false`,children:(0,B.jsx)(`td`,{colSpan:7,children:(0,B.jsx)(gl,{projectKey:e.key,windowWeeks:i})})})]},e.key))})]}),C&&(0,B.jsx)(`button`,{type:`button`,className:`projects-table-toggle`,"data-testid":`projects-table-toggle`,"aria-expanded":l,onClick:()=>u(e=>!e),children:l?`Show top 10 active`:`Show all ${y.length} projects (+${x})`}),!w&&s&&(0,B.jsx)(gl,{projectKey:s,windowWeeks:i}),(0,B.jsxs)(`div`,{className:`projects-modal-footer-hint`,"data-testid":`projects-modal-footer-hint`,"aria-live":`off`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`1`}),`/`,(0,B.jsx)(`kbd`,{children:`4`}),`/`,(0,B.jsx)(`kbd`,{children:`8`}),`/`,(0,B.jsx)(`kbd`,{children:`0`}),` window`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`↑↓`}),` row`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`Enter`}),` drill`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`s`}),` share/$`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`kbd`,{children:`Esc`}),` close`]}),(0,B.jsx)(`span`,{className:`sep`,"aria-hidden":`true`,children:`·`}),(0,B.jsx)(nn,{})]})]})})}function Sl({cr:e}){let t=e.today.baseline_daily_row_count<5,n=e.today.anomaly_triggered&&!t,r;r=t?{text:`~ Building baseline · ${e.today.baseline_daily_row_count}/5 days`,cls:`thin`}:n?{text:`⚠ Anomaly`,cls:``}:{text:`✓ Healthy`,cls:`ok`};let i=e.today.baseline_median_percent,a=e.today.delta_pp,o;if(a===null)o=`—`;else{let e=F.pctFloor(Math.abs(a));o=`${a<0?`−`:`+`}${e}pp`}return(0,B.jsxs)(`div`,{className:`crm-section`,children:[(0,B.jsxs)(`div`,{className:`crm-section-head crm-sh-spotlight`,children:[`Today's spotlight`,(0,B.jsxs)(`span`,{className:`meta`,children:[e.today.date,` · `,e.days.length,` days observed`]})]}),(0,B.jsxs)(`div`,{className:`crm-spotlight${n?` anom`:``}`,children:[(0,B.jsxs)(`div`,{className:`crm-spotlight-row`,children:[(0,B.jsx)(`span`,{className:`pill${r.cls?` `+r.cls:``}`,children:r.text}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`Cache hit`}),` `,(0,B.jsxs)(`strong`,{children:[F.pctFloor(e.today.cache_hit_percent),`%`]})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`14d median`}),` `,(0,B.jsx)(`strong`,{children:i===null?`—`:`${F.pctFloor(i)}%`})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`Δ`}),` `,(0,B.jsx)(`strong`,{children:o})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`Net`}),` `,(0,B.jsx)(`strong`,{children:F.usdSigned(e.today.net_usd)})]}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`k`,children:`Saved / Wasted`}),` `,(0,B.jsxs)(`strong`,{children:[`$`,e.today.saved_usd.toFixed(2),` / $`,e.today.wasted_usd.toFixed(2)]})]})]}),n&&e.today.anomaly_reasons.length>0&&(0,B.jsxs)(`div`,{className:`reasons`,children:[`Reasons:`,` `,e.today.anomaly_reasons.map((e,t)=>(0,B.jsxs)(`span`,{children:[t>0&&` · `,(0,B.jsx)(`code`,{children:e})]},e)),` | `,`thresholds: `,e.anomaly_threshold_pp,`pp drop, net < 0`]})]})]})}function Cl(e,t=28){if(e.length<=t)return e;let n=e.split(`/`).filter(Boolean);if(n.length<=2)return e;let r=`/`+n[0],i=`${r}/…/${n.slice(-2).join(`/`)}`;return i.length<=t||(i=`${r}/…/${n[n.length-1]}`,i.length<=t)?i:`…/${n[n.length-1]}`}function wl({kind:e,rows:t}){let n=e===`projects`?`bd-projects`:`bd-models`,r=e===`projects`?`By project`:`By model`,i=e===`projects`?`No project activity in this window`:`No model activity in this window`,a=e===`projects`;return(0,B.jsxs)(`div`,{className:`crm-bd-card ${n}`,"data-bd-kind":e,children:[(0,B.jsx)(`div`,{className:`crm-bd-head`,children:r}),t.length===0?(0,B.jsx)(`div`,{className:`empty`,children:i}):(0,B.jsx)(`table`,{children:(0,B.jsx)(`tbody`,{children:t.map(e=>{let t=a?Cl(e.key):e.key,n=t!==e.key;return(0,B.jsxs)(`tr`,{"data-testid":`crm-bd-row`,"data-bd-key":e.key,children:[(0,B.jsx)(`td`,{className:`bd-key`,title:n?e.key:void 0,children:t}),(0,B.jsxs)(`td`,{children:[F.pctFloor(e.cache_hit_percent),`%`]}),(0,B.jsx)(`td`,{className:e.net_usd>=0?`net-pos`:`net-neg`,children:F.usdSigned(e.net_usd)})]},e.key)})})})]})}function Tl({current_threshold_pp:e,onClose:t}){let[n,r]=(0,_.useState)(String(e)),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1),u=(0,_.useRef)(null);(0,_.useEffect)(()=>{function e(e){let n=e.target;n&&n.closest(`[data-cr-settings-toggle]`)||u.current&&!u.current.contains(e.target)&&t()}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[t]),(0,_.useEffect)(()=>{function e(e){e.key===`Escape`&&(e.stopPropagation(),t())}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[t]);async function d(){l(!1);let e=n.trim(),t=/^-?\d+$/.test(e)?parseInt(e,10):NaN;if(!Number.isInteger(t)||t<1||t>100){a(`Must be an integer between 1 and 100`);return}s(!0),a(null);try{let e=await fetch(`/api/settings`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cache_report:{anomaly_threshold_pp:t}})});if(e.ok)l(!0),setTimeout(()=>l(!1),1500);else{let t=await e.json().catch(()=>({}));a(typeof t.error==`string`?t.error:`HTTP ${e.status}`)}}catch(e){a(String(e))}finally{s(!1)}}return(0,B.jsxs)(`div`,{ref:u,className:`crm-settings-popover`,role:`dialog`,"aria-label":`Cache Report settings`,children:[(0,B.jsx)(`h4`,{children:`Cache Report settings`}),(0,B.jsx)(`label`,{htmlFor:`cr-threshold`,children:`Anomaly threshold (pp)`}),(0,B.jsx)(`input`,{id:`cr-threshold`,type:`number`,inputMode:`numeric`,min:1,max:100,value:n,onChange:e=>{r(e.target.value),a(null),l(!1)},className:i?`invalid`:``}),i&&(0,B.jsx)(`div`,{className:`err`,children:i}),c&&(0,B.jsx)(`div`,{className:`saved`,children:`Saved · next sync will re-evaluate`}),(0,B.jsxs)(`div`,{className:`actions`,children:[(0,B.jsx)(`button`,{onClick:t,type:`button`,children:`Close`}),(0,B.jsx)(`button`,{className:`primary`,onClick:d,disabled:o,type:`button`,children:o?`Saving…`:`Save`})]})]})}function El(){let e=V()?.cache_report,[t,n]=(0,_.useState)(!1);if(!e)return(0,B.jsx)(cc,{title:`Cache Report`,accentClass:`accent-teal`,children:(0,B.jsx)(`div`,{style:{color:`var(--text-dim)`,padding:`20px 0`},children:`Loading…`})});if(e.is_empty)return(0,B.jsx)(cc,{title:`Cache Report`,accentClass:`accent-teal`,children:(0,B.jsxs)(`div`,{style:{color:`var(--text-dim)`,padding:`20px 0`},children:[`No Claude activity in the last `,e.window_days,` days.`]})});let r=(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`span`,{className:`sub`,style:{marginRight:12,color:`var(--text-dim)`},children:[`Last `,e.window_days,` days · `,e.anomaly_window_days,`d baseline · Claude only`]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Cache Report settings`,"data-cr-settings-toggle":!0,onClick:e=>{e.stopPropagation(),n(e=>!e)},style:{background:`transparent`,border:0,color:`var(--text-dim)`,cursor:`pointer`,fontSize:18,padding:`0 8px`},children:`⚙`})]}),i=e.today.baseline_daily_row_count<5,a=e.today.anomaly_triggered&&!i,o=a?`var(--accent-amber)`:`var(--accent-green)`,s=a?`accent-amber`:`accent-teal`,c=Math.round(e.fourteen_day_efficiency_ratio*100);return(0,B.jsxs)(cc,{title:`Cache Report`,accentClass:s,headerExtras:r,children:[t&&(0,B.jsx)(Tl,{current_threshold_pp:e.anomaly_threshold_pp,onClose:()=>n(!1)}),(0,B.jsx)(Sl,{cr:e}),(0,B.jsxs)(`div`,{className:`crm-section`,children:[(0,B.jsxs)(`div`,{className:`crm-section-head crm-sh-timeline`,children:[`Cache hit % — `,e.window_days,`-day timeline`,(0,B.jsxs)(`span`,{className:`meta`,children:[`band = `,e.anomaly_window_days,`d median ±`,5,`pp`]})]}),(0,B.jsx)(`div`,{className:`crm-chart-frame timeline`,children:(0,B.jsx)(Ir,{days:e.days,baseline_median_percent:e.today.baseline_median_percent,today_marker_color:o,size:`large`})})]}),(0,B.jsx)(Rr,{days:e.days,size:`large`}),(0,B.jsxs)(`div`,{className:`crm-counterfactual`,children:[`Without caching, you'd have paid`,` `,(0,B.jsxs)(`strong`,{children:[`+$`,e.fourteen_day_counterfactual_usd.toFixed(2),` more`]}),` `,`over the last `,e.window_days,` days · cache efficiency`,` `,(0,B.jsxs)(`span`,{title:`saved / (saved + |wasted|) = ${c}%`,children:[c,`%`]})]}),(0,B.jsxs)(`div`,{className:`crm-section`,children:[(0,B.jsxs)(`div`,{className:`crm-section-head crm-sh-table`,children:[`Daily rows · `,e.window_days,` days`,(0,B.jsxs)(`span`,{className:`meta`,children:[e.days.length,` days observed`]})]}),(0,B.jsxs)(`table`,{className:`ch-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{className:`c-date`,children:`Date`}),(0,B.jsx)(`th`,{className:`c-hit num`,children:`Cache %`}),(0,B.jsx)(`th`,{className:`c-tokens num`,children:`Tok In`}),(0,B.jsx)(`th`,{className:`c-tokens num`,children:`Tok Out`}),(0,B.jsx)(`th`,{className:`c-saved num`,children:`Saved`}),(0,B.jsx)(`th`,{className:`c-wasted num`,children:`Wasted`}),(0,B.jsx)(`th`,{className:`c-net num`,children:`Net`}),(0,B.jsx)(`th`,{className:`c-flag num`,children:`Flag`})]})}),(0,B.jsx)(`tbody`,{children:e.days.map(t=>{let n=t.date===e.today.date,r=e.today.baseline_median_percent!==null,i=r&&e.today.baseline_median_percent!==null&&t.cache_hit_percent<e.today.baseline_median_percent-5,a=t.net_usd<0;return(0,B.jsxs)(`tr`,{className:n?`cur`:``,"data-testid":`crm-daily-row`,"data-date":t.date,children:[(0,B.jsx)(`td`,{children:t.date}),(0,B.jsxs)(`td`,{className:`num ${r?i?`hit-bad`:`hit-good`:``}`.trim(),children:[F.pctFloor(t.cache_hit_percent),`%`]}),(0,B.jsx)(`td`,{className:`num`,children:F.compact(t.input_tokens,{upper:!0})}),(0,B.jsx)(`td`,{className:`num`,children:F.compact(t.output_tokens,{upper:!0})}),(0,B.jsx)(`td`,{className:`num`,children:F.usd2(t.saved_usd)}),(0,B.jsx)(`td`,{className:`num`,children:F.usd2(t.wasted_usd)}),(0,B.jsx)(`td`,{className:`num ${a?`net-neg`:`net-pos`}`,children:F.usdSigned(t.net_usd)}),(0,B.jsx)(`td`,{className:`num ${t.anomaly_triggered?`flag-warn`:`flag-ok`}`,children:t.anomaly_triggered?`⚠`:`✓`})]},t.date)})})]})]}),(0,B.jsx)(`div`,{className:`crm-section`,children:(0,B.jsxs)(`div`,{className:`crm-breakdowns`,children:[(0,B.jsx)(wl,{kind:`projects`,rows:e.by_project}),(0,B.jsx)(wl,{kind:`models`,rows:e.by_model})]})})]})}var Dl=100;function Ol({alert:e,ctx:t}){if(e.axis===`weekly`){let n=e.context.week_start_date?F.weekStart(e.context.week_start_date,t):null,r=e.context.dollars_per_percent;return(0,B.jsxs)(`span`,{className:`alert-context alert-context--weekly`,children:[n?`Week of ${n}`:`Week —`,r!=null&&(0,B.jsxs)(B.Fragment,{children:[` · `,(0,B.jsxs)(`span`,{className:`num`,children:[`$`,r.toFixed(2),`/1%`]})]})]})}if(e.axis===`budget`){let n=Ar(e.context.period),r=e.context.period_start_at??e.context.week_start_at,i=r?F.weekStart(r.slice(0,10),t):null,a=e.context.consumption_pct;return(0,B.jsxs)(`span`,{className:`alert-context alert-context--budget`,children:[i?`${n} of ${i}`:`${n} —`,a!=null&&(0,B.jsxs)(B.Fragment,{children:[` · `,(0,B.jsxs)(`span`,{className:`num`,children:[Math.round(a),`% of budget`]})]})]})}if(e.axis===`codex_budget`){let n=Ar(e.context.period),r=e.context.period_start_at,i=r?F.weekStart(r.slice(0,10),t):null,a=e.context.consumption_pct;return(0,B.jsxs)(`span`,{className:`alert-context alert-context--codex_budget`,children:[i?`${n} of ${i}`:`${n} —`,a!=null&&(0,B.jsxs)(B.Fragment,{children:[` · `,(0,B.jsxs)(`span`,{className:`num`,children:[Math.round(a),`% of budget`]})]})]})}if(e.axis===`project_budget`){let t=e.context.project??`(project)`,n=e.context.consumption_pct;return(0,B.jsxs)(`span`,{className:`alert-context alert-context--project_budget`,children:[t,n!=null&&(0,B.jsxs)(B.Fragment,{children:[` · `,(0,B.jsxs)(`span`,{className:`num`,children:[Math.round(n),`% of budget`]})]})]})}return e.axis===`projected`?(0,B.jsx)(`span`,{className:`alert-context alert-context--projected`,children:Mr(e)??`Projected —`}):(0,B.jsxs)(`span`,{className:`alert-context alert-context--five-hour`,children:[`Block `,e.context.block_start_at?F.timeOnly(e.context.block_start_at,t):`—`]})}function kl({alert:e}){if(e.axis===`projected`)return(0,B.jsx)(`span`,{className:`num`,children:`—`});let t;return t=e.axis===`weekly`?e.context.cumulative_cost_usd:e.axis===`budget`||e.axis===`project_budget`||e.axis===`codex_budget`?e.context.spent_usd:e.context.block_cost_usd,(0,B.jsx)(`span`,{className:`num`,children:F.usd2(t??null)})}function Al(){let e=(0,_.useSyncExternalStore)(R,()=>L().alerts),t=Rn(),n={tz:t.resolvedTz,offsetLabel:t.offsetLabel},r=e.slice(0,Dl);return r.length===0?(0,B.jsx)(cc,{title:`Recent alerts`,accentClass:`accent-amber`,children:(0,B.jsx)(`div`,{className:`panel-empty`,children:`No alerts yet. Alerts appear when usage crosses 90% or 95%.`})}):(0,B.jsx)(cc,{title:`Recent alerts`,accentClass:`accent-amber`,children:(0,B.jsxs)(`div`,{className:`alerts-modal-body`,children:[(0,B.jsxs)(`table`,{className:`alerts-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{scope:`col`,children:`%`}),(0,B.jsx)(`th`,{scope:`col`,children:`Axis`}),(0,B.jsx)(`th`,{scope:`col`,children:`Cost`}),(0,B.jsx)(`th`,{scope:`col`,children:`Context`}),(0,B.jsx)(`th`,{scope:`col`,children:`Alerted`})]})}),(0,B.jsx)(`tbody`,{children:r.map(e=>{let t=jr(e);return(0,B.jsxs)(`tr`,{className:`alert-modal-row`,children:[(0,B.jsxs)(`td`,{className:`alert-threshold severity-${t} ${t} num`,children:[e.threshold,`%`]}),(0,B.jsx)(`td`,{children:(0,B.jsx)(`span`,{className:`chip chip--${e.axis}`,children:Or[e.axis]})}),(0,B.jsx)(`td`,{className:`num`,children:(0,B.jsx)(kl,{alert:e})}),(0,B.jsx)(`td`,{children:(0,B.jsx)(Ol,{alert:e,ctx:n})}),(0,B.jsx)(`td`,{className:`alert-when`,children:F.relativeOrAbsolute(e.alerted_at,n)})]},e.id)})})]}),e.length>Dl&&(0,B.jsxs)(`div`,{className:`alerts-modal-foot`,children:[`Showing `,Dl,` of `,e.length,` most recent`]})]})})}function jl(){let e=(0,_.useSyncExternalStore)(R,()=>L().openModal);if(!e)return null;switch(e){case`current-week`:return(0,B.jsx)(hc,{});case`forecast`:return(0,B.jsx)(U,{});case`trend`:return(0,B.jsx)(kc,{});case`session`:return(0,B.jsx)(Rc,{});case`weekly`:return(0,B.jsx)(Gc,{});case`monthly`:return(0,B.jsx)(Kc,{});case`block`:return(0,B.jsx)(nl,{});case`daily`:return(0,B.jsx)(sl,{});case`projects`:return(0,B.jsx)(xl,{});case`alerts`:return(0,B.jsx)(Al,{});case`cache-report`:return(0,B.jsx)(El,{})}}var Ml=class extends Error{status;field;code;constructor(e,t,n,r){super(n),this.status=e,this.field=t,this.code=r}};async function Nl(e){if(!e.ok){let t={};try{t=await e.json()}catch{}throw new Ml(e.status,t.field,t.error??`HTTP ${e.status}`,t.code)}return e.json()}async function Pl(e,t){return Nl(await fetch(`/api/share/templates?panel=${encodeURIComponent(e)}`,{signal:t?.signal}))}async function Fl(e,t){return Nl(await fetch(`/api/share/render`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t?.signal}))}var Il=[{id:`recap`,label:`Recap`,placeholderDescription:`Text + tiny chart`},{id:`visual`,label:`Visual`,placeholderDescription:`Coming soon`},{id:`detail`,label:`Detail`,placeholderDescription:`Coming soon`}];function Ll(e){return e.endsWith(`-recap`)?`recap`:e.endsWith(`-visual`)?`visual`:e.endsWith(`-detail`)?`detail`:null}function Rl({panel:e,templates:t,error:n,selectedTemplateId:r,onSelect:i}){if(n)return(0,B.jsx)(`div`,{className:`share-gallery-error`,role:`alert`,children:n});let a={};for(let e of t??[]){let t=Ll(e.id);t&&(a[t]=e)}return(0,B.jsx)(`div`,{className:`share-gallery`,role:`radiogroup`,"aria-label":`Report template`,children:Il.map(e=>{let n=a[e.id];if(t==null)return(0,B.jsxs)(`div`,{className:`share-tile share-tile-skeleton`,"aria-hidden":`true`,children:[(0,B.jsx)(`div`,{className:`share-tile-skeleton-bar`}),(0,B.jsx)(`div`,{className:`share-tile-skeleton-bar short`})]},e.id);if(!n)return(0,B.jsxs)(`button`,{type:`button`,className:`share-tile share-tile-disabled`,disabled:!0,"aria-disabled":`true`,role:`radio`,"aria-checked":`false`,title:`${e.label} — ${e.placeholderDescription}`,children:[(0,B.jsx)(`div`,{className:`share-tile-label`,children:e.label}),(0,B.jsx)(`div`,{className:`share-tile-desc`,children:e.placeholderDescription})]},e.id);let o=n.id===r;return(0,B.jsxs)(`button`,{type:`button`,className:`share-tile`+(o?` share-tile-selected`:``),role:`radio`,"aria-checked":o,"data-template-id":n.id,onClick:()=>i(n.id),children:[(0,B.jsx)(`div`,{className:`share-tile-label`,children:n.label}),(0,B.jsx)(`div`,{className:`share-tile-desc`,children:n.description})]},e.id)})})}function zl({options:e,onChange:t}){let n=n=>t({...e,...n}),r=n=>t({...e,period:{...e.period,...n}}),i=e=>{if(e===``){n({top_n:null});return}let t=Number.parseInt(e,10);Number.isNaN(t)||n({top_n:Math.max(1,t)})};return(0,B.jsxs)(`div`,{className:`share-knobs`,children:[(0,B.jsxs)(`div`,{className:`share-knob`,children:[(0,B.jsx)(`label`,{htmlFor:`share-knob-period`,children:`Period`}),(0,B.jsxs)(`select`,{id:`share-knob-period`,value:e.period.kind,onChange:e=>r({kind:e.target.value}),children:[(0,B.jsx)(`option`,{value:`current`,children:`This week`}),(0,B.jsx)(`option`,{value:`previous`,children:`Previous week`}),(0,B.jsx)(`option`,{value:`custom`,children:`Custom`})]}),e.period.kind===`custom`?(0,B.jsxs)(`div`,{className:`share-knob-period-custom`,children:[(0,B.jsxs)(`label`,{className:`share-knob-sublabel`,children:[(0,B.jsx)(`span`,{children:`Start`}),(0,B.jsx)(`input`,{type:`date`,value:e.period.start?.slice(0,10)??``,onChange:e=>r({start:e.target.value}),"aria-label":`Custom period start date`})]}),(0,B.jsxs)(`label`,{className:`share-knob-sublabel`,children:[(0,B.jsx)(`span`,{children:`End`}),(0,B.jsx)(`input`,{type:`date`,value:e.period.end?.slice(0,10)??``,onChange:e=>r({end:e.target.value}),"aria-label":`Custom period end date`})]})]}):null]}),(0,B.jsxs)(`div`,{className:`share-knob`,children:[(0,B.jsx)(`span`,{className:`share-knob-label`,children:`Theme`}),(0,B.jsxs)(`div`,{className:`share-knob-radiogroup`,role:`radiogroup`,"aria-label":`Theme`,children:[(0,B.jsxs)(`label`,{className:`share-knob-radio`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`share-theme`,value:`light`,checked:e.theme===`light`,onChange:()=>n({theme:`light`})}),(0,B.jsx)(`span`,{children:`Light`})]}),(0,B.jsxs)(`label`,{className:`share-knob-radio`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`share-theme`,value:`dark`,checked:e.theme===`dark`,onChange:()=>n({theme:`dark`})}),(0,B.jsx)(`span`,{children:`Dark`})]})]})]}),(0,B.jsxs)(`div`,{className:`share-knob`,children:[(0,B.jsx)(`label`,{htmlFor:`share-knob-topn`,children:`Top-N`}),(0,B.jsx)(`input`,{id:`share-knob-topn`,type:`number`,min:1,step:1,inputMode:`numeric`,value:e.top_n??``,onChange:e=>i(e.target.value),"aria-label":`Top-N`})]}),(0,B.jsxs)(`div`,{className:`share-knob`,children:[(0,B.jsx)(`span`,{className:`share-knob-label`,children:`Projects`}),(0,B.jsx)(`button`,{type:`button`,className:`share-knob-allowlist-stub`,disabled:!0,"aria-disabled":`true`,title:`Exports include all projects`,children:`All projects`})]}),(0,B.jsx)(`div`,{className:`share-knob`,children:(0,B.jsxs)(`label`,{className:`share-knob-checkbox`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:e.show_chart,onChange:e=>n({show_chart:e.target.checked}),"aria-label":`Include chart in export`}),(0,B.jsx)(`span`,{children:`Show chart`})]})}),(0,B.jsx)(`div`,{className:`share-knob`,children:(0,B.jsxs)(`label`,{className:`share-knob-checkbox`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:e.show_table,onChange:e=>n({show_table:e.target.checked}),"aria-label":`Include table in export`}),(0,B.jsx)(`span`,{children:`Show table`})]})}),(0,B.jsx)(`div`,{className:`share-knob`,children:(0,B.jsxs)(`label`,{className:`share-knob-checkbox`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:!e.reveal_projects,onChange:e=>n({reveal_projects:!e.target.checked}),"aria-label":`Anonymize project names on export`}),(0,B.jsx)(`span`,{children:`Anon on export`})]})})]})}var Bl=200,Vl={status:`idle`,body:``,contentType:``,errorMessage:null,errorField:null};function Hl({panel:e,templateId:t,options:n}){let[r,i]=(0,_.useState)(Vl),a=(0,_.useRef)(null),o=(0,_.useRef)(0);return(0,_.useEffect)(()=>{if(!t){i(Vl);return}i(e=>({...e,status:`loading`}));let r=++o.current,s=setTimeout(()=>{a.current?.abort();let s=new AbortController;a.current=s,Fl({panel:e,template_id:t,options:{...n,reveal_projects:!0}},{signal:s.signal}).then(e=>{r===o.current&&i({status:`ready`,body:e.body,contentType:e.content_type,errorMessage:null,errorField:null})}).catch(e=>{if(r===o.current&&!(e&&typeof e==`object`&&e.name===`AbortError`)){if(e instanceof Ml){i({status:`error`,body:``,contentType:``,errorMessage:e.message??`HTTP ${e.status}`,errorField:e.field??null});return}i({status:`error`,body:``,contentType:``,errorMessage:e.message??`Unknown error`,errorField:null})}})},Bl);return()=>{clearTimeout(s)}},[e,t,n]),(0,_.useEffect)(()=>()=>{a.current?.abort()},[]),t?r.status===`error`?(0,B.jsxs)(`div`,{className:`share-preview share-preview-error`,role:`alert`,children:[(0,B.jsx)(`div`,{className:`share-preview-error-title`,children:`Preview failed`}),(0,B.jsxs)(`div`,{className:`share-preview-error-message`,children:[r.errorMessage,r.errorField?(0,B.jsxs)(`span`,{className:`share-preview-error-field`,children:[` `,`(field: `,r.errorField,`)`]}):null]})]}):r.status===`loading`||r.status===`idle`?(0,B.jsx)(`div`,{className:`share-preview share-preview-loading`,"aria-busy":`true`,children:`Rendering preview…`}):n.format===`md`?(0,B.jsx)(`pre`,{className:`share-preview share-preview-md`,"aria-label":`Markdown preview`,children:r.body}):(0,B.jsx)(`iframe`,{className:`share-preview share-preview-iframe`,title:`Report preview (decorative)`,tabIndex:-1,sandbox:`allow-same-origin`,srcDoc:r.body}):(0,B.jsx)(`div`,{className:`share-preview share-preview-empty`,children:`Select a template to preview.`})}var Ul={"current-week":`Current week`,trend:`Trend`,weekly:`Weekly`,daily:`Daily`,monthly:`Monthly`,blocks:`5-hour blocks`,forecast:`Forecast`,sessions:`Sessions`,projects:`Projects`};function Wl(e){return Ul[e]}function Gl(e){switch(e){case`md`:return`md`;case`html`:return`html`;case`svg`:return`svg`}}async function Kl(e){if(!e.ok){let t={};try{t=await e.json()}catch{}throw new Ml(e.status,t.field,t.error??`HTTP ${e.status}`)}return e.json()}async function ql(e){return Kl(await fetch(`/api/share/presets`,{signal:e?.signal}))}async function Jl(e,t){return Kl(await fetch(`/api/share/presets`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t?.signal}))}async function Yl(e,t,n){let r=await fetch(`/api/share/presets/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`,signal:n?.signal});if(!r.ok){let e={};try{e=await r.json()}catch{}throw new Ml(r.status,void 0,e.error??`HTTP ${r.status}`)}}async function Xl(e){return Kl(await fetch(`/api/share/history`,{signal:e?.signal}))}async function Zl(e,t){return Kl(await fetch(`/api/share/history`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t?.signal}))}function Ql({panel:e,templateId:t,options:n,onSaved:r,onCancel:i}){let[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(null);async function d(){let i=a.trim();if(!i){u(`Name is required`);return}if(i.length>64){u(`Name must be 64 characters or fewer`);return}if(i.includes(`/`)){u(`Name cannot contain '/'`);return}c(!0),u(null);try{await Jl({panel:e,name:i,template_id:t,options:n}),z({type:`SHOW_STATUS_TOAST`,text:`Saved preset "${i}"`}),r()}catch(e){u((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Save failed`)}finally{c(!1)}}return(0,B.jsxs)(`div`,{className:`share-save-popover`,role:`dialog`,"aria-label":`Save preset`,children:[(0,B.jsxs)(`label`,{className:`share-save-label`,children:[`Preset name`,(0,B.jsx)(`input`,{type:`text`,className:`share-save-input`,autoFocus:!0,value:a,maxLength:64,disabled:s,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),e.stopPropagation(),d()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),i())}})]}),l?(0,B.jsx)(`div`,{className:`share-save-error`,role:`alert`,children:l}):null,(0,B.jsxs)(`div`,{className:`share-save-actions`,children:[(0,B.jsx)(`button`,{type:`button`,onClick:i,disabled:s,children:`Cancel`}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>void d(),disabled:s,children:s?`Saving…`:`Save`})]})]})}async function $l(e,t,n){let r=new Blob([e],{type:`image/svg+xml`}),i=URL.createObjectURL(r);try{let e=new Image;e.src=i,await e.decode();let r=document.createElement(`canvas`);r.width=e.naturalWidth*t,r.height=e.naturalHeight*t;let a=r.getContext(`2d`);if(!a)throw Error(`Could not acquire 2D canvas context`);a.fillStyle=n,a.fillRect(0,0,r.width,r.height),a.scale(t,t),a.drawImage(e,0,0);let o=await new Promise(e=>{r.toBlob(t=>e(t),`image/png`)});if(o)return o;let s=r.toDataURL(`image/png`);return(await fetch(s)).blob()}finally{URL.revokeObjectURL(i)}}function eu(e){let t=document.createElement(`iframe`);t.setAttribute(`aria-hidden`,`true`),t.style.cssText=`position:fixed;right:0;bottom:0;width:0;height:0;border:0`,document.body.appendChild(t);let n=t.contentDocument;if(!n)throw Error(`iframe contentDocument unavailable`);n.open(),n.write(e),n.close();try{t.contentWindow?.focus(),t.contentWindow?.print()}catch{let t=window.open(``,`_blank`,`noopener,noreferrer`);t&&(t.document.open(),t.document.write(e),t.document.close())}setTimeout(()=>t.remove(),1e3)}function tu(e){Zl({panel:e.panel,template_id:e.template_id,options:e.options,format:e.options.format,destination:e.destination}).catch(()=>{})}function nu(e){return e===`light`?`#ffffff`:`#0f172a`}function ru(e,t){return`cctally-${e}-${new Date().toISOString().slice(0,10).replaceAll(`-`,``)}.${Gl(t)}`}function iu(e){switch(e){case`md`:return`text/markdown;charset=utf-8`;case`html`:return`text/html;charset=utf-8`;case`svg`:return`image/svg+xml;charset=utf-8`}}function au(e,t){let n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=e,r.style.display=`none`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>URL.revokeObjectURL(n),0)}function ou({panel:e,templateId:t,options:n,onOptionsChange:r}){let[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),u=(0,_.useRef)(null);(0,_.useEffect)(()=>()=>{u.current!=null&&clearTimeout(u.current)},[]);let[d,f]=(0,_.useState)(!1),p=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!d)return;function e(e){let t=p.current;t&&(t.contains(e.target)||f(!1))}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[d]),On((0,_.useMemo)(()=>[{key:`Escape`,scope:`overlay`,layer:205,when:()=>d,action:()=>f(!1)}],[d])),(0,_.useEffect)(()=>{s(null)},[n.format,t]);let m=t==null||i!=null,h=e=>z({type:`SHOW_STATUS_TOAST`,text:e}),g=async()=>{if(!t)throw Error(`no template selected`);return{body:(await Fl({panel:e,template_id:t,options:n})).body,format:n.format}},v=async()=>{if(!(m||!t)){a(`copy`),s(null);try{let{body:r}=await g();if(!navigator.clipboard||typeof navigator.clipboard.writeText!=`function`)throw Error(`Clipboard API unavailable in this browser`);await navigator.clipboard.writeText(r),h(`Copied`),tu({panel:e,template_id:t,options:n,destination:`copy`})}catch(e){s(`Copy failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},y=async()=>{if(!(m||!t)){a(`download`),s(null);try{let{body:r,format:i}=await g(),a=new Blob([r],{type:iu(i)});au(ru(e,i),a),h(`Downloaded`),tu({panel:e,template_id:t,options:n,destination:`download`})}catch(e){s(`Download failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},b=async()=>{if(!(m||!t)){a(`basket`),s(null);try{let r=await Fl({panel:e,template_id:t,options:n}),i=Je({panel:e,template_id:t,options:n,added_at:new Date().toISOString(),data_digest_at_add:r.snapshot.data_digest,kernel_version:r.snapshot.kernel_version,label_hint:Wl(e)});z({type:`BASKET_ADD`,item:i});let a=L().basket;if(a.rejectedReason===`capacity`)return;l(!0),u.current!=null&&clearTimeout(u.current),u.current=setTimeout(()=>l(!1),800),z({type:`SHOW_STATUS_TOAST`,text:`Added ${i.label_hint} to basket (${a.items.length})`})}catch(e){s(`Add to basket failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},x=async()=>{if(!(m||!t)){a(`open`),s(null);try{let{body:r,format:i}=await g(),a=new Blob([r],{type:iu(i)}),o=URL.createObjectURL(a);window.open(o,`_blank`,`noopener,noreferrer`),tu({panel:e,template_id:t,options:n,destination:`open`})}catch(e){s(`Open failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},S=async()=>{if(!(!t||n.format!==`svg`||m)){a(`png`),s(null);try{let{body:r}=await g(),i=await $l(r,2,nu(n.theme));au(ru(e,`svg`).replace(/\.svg$/,`.png`),i),h(`PNG downloaded`),tu({panel:e,template_id:t,options:n,destination:`png`})}catch(e){s(`PNG export failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},C=async()=>{if(!(!t||n.format!==`html`||m)){a(`print`),s(null);try{let{body:r}=await g();eu(r),tu({panel:e,template_id:t,options:n,destination:`print`})}catch(e){s(`Print failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{a(null)}}},w=n.format===`md`&&!m,T=(n.format===`html`||n.format===`svg`)&&!m,E=n.format===`svg`&&!m,D=n.format===`html`&&!m;return(0,B.jsxs)(`div`,{className:`share-actions`,children:[(0,B.jsxs)(`div`,{className:`share-format-row`,role:`radiogroup`,"aria-label":`Export format`,children:[(0,B.jsx)(`span`,{className:`share-format-label`,children:`Format:`}),[`md`,`html`,`svg`].map(e=>(0,B.jsxs)(`label`,{className:`share-format-radio`,children:[(0,B.jsx)(`input`,{type:`radio`,name:`share-format`,value:e,checked:n.format===e,onChange:()=>r({...n,format:e})}),(0,B.jsx)(`span`,{children:e})]},e))]}),(0,B.jsxs)(`div`,{className:`share-action-row`,children:[(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-copy`,onClick:v,disabled:!w,title:n.format===`md`?i===`copy`?`Copying…`:`Copy to clipboard`:`Copy is available for Markdown only`,children:i===`copy`?`Copying…`:`Copy`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-download`,onClick:y,disabled:m,title:i===`download`?`Downloading…`:`Download file`,children:i===`download`?`Downloading…`:`Download`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-open`,onClick:x,disabled:!T,title:n.format===`html`||n.format===`svg`?i===`open`?`Opening…`:`Open in new tab`:`Open is available for HTML/SVG`,children:i===`open`?`Opening…`:`Open`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-png`,onClick:S,disabled:!E,title:n.format===`svg`?i===`png`?`Rasterizing…`:`Download PNG (rasterized from SVG)`:`PNG export — available for SVG format only`,children:i===`png`?`Rasterizing…`:`PNG`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-print`,onClick:C,disabled:!D,title:n.format===`html`?i===`print`?`Opening print dialog…`:`Open the browser print dialog (save as PDF)`:`Print → PDF — available for HTML format only`,children:i===`print`?`Printing…`:`Print → PDF`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-basket${c?` share-action-basket-added`:``}`,onClick:b,disabled:m,title:m&&t==null?`Pick a template first`:i===`basket`?`Adding to basket…`:`Add this section to the report basket`,children:c?`✓ Added`:i===`basket`?`Adding…`:`+ Basket`})]}),(0,B.jsxs)(`div`,{className:`share-save-preset-row`,ref:p,children:[(0,B.jsx)(`button`,{type:`button`,className:`share-save-preset`,disabled:t==null||i!=null,onClick:()=>f(e=>!e),"aria-haspopup":`dialog`,"aria-expanded":d,title:t==null?`Pick a template first`:`Save the current recipe as a named preset`,children:`Save preset…`}),d&&t?(0,B.jsx)(Ql,{panel:e,templateId:t,options:n,onSaved:()=>f(!1),onCancel:()=>f(!1)}):null]}),o?(0,B.jsx)(`div`,{className:`share-action-error`,role:`alert`,children:o}):null]})}function su(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function cu({panel:e,onPick:t,onManage:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)({}),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(null),d=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!r)return;let t=new AbortController;return u(null),Promise.all([ql({signal:t.signal}),Xl({signal:t.signal})]).then(([t,n])=>{o(t.presets[e]??{}),c(n.history.filter(t=>t.panel===e).slice().reverse())}).catch(e=>{e?.name!==`AbortError`&&u((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Failed to load presets`)}),()=>t.abort()},[r,e]),(0,_.useEffect)(()=>{if(!r)return;function e(e){let t=d.current;t&&(t.contains(e.target)||i(!1))}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]),On((0,_.useMemo)(()=>[{key:`Escape`,scope:`overlay`,layer:205,when:()=>r,action:()=>i(!1)}],[r]));let f=Object.keys(a).sort();return(0,B.jsxs)(`div`,{className:`share-presets-dropdown`,ref:d,children:[(0,B.jsx)(`button`,{type:`button`,className:`share-presets-trigger`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>i(e=>!e),children:`presets ▾`}),r?(0,B.jsxs)(`div`,{className:`share-presets-menu`,role:`menu`,children:[l?(0,B.jsx)(`div`,{className:`share-presets-error`,role:`alert`,children:l}):null,f.length===0&&!l?(0,B.jsx)(`div`,{className:`share-presets-empty`,children:`No saved presets yet.`}):null,f.length>0?(0,B.jsx)(`ul`,{className:`share-presets-list`,children:f.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,className:`share-presets-item`,onClick:()=>{t(a[e].template_id,a[e].options),i(!1)},children:e})},e))}):null,s.length>0?(0,B.jsxs)(`div`,{className:`share-presets-history`,children:[(0,B.jsx)(`div`,{className:`share-presets-history-heading`,role:`presentation`,children:`Recent shares`}),(0,B.jsx)(`ul`,{className:`share-presets-history-list`,children:s.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`share-presets-history-item`,onClick:()=>{t(e.template_id,e.options),i(!1)},title:`${e.template_id} · ${e.format??`unknown`} · ${e.exported_at}`,children:[(0,B.jsx)(`span`,{className:`share-presets-history-template`,children:e.template_id}),(0,B.jsxs)(`span`,{className:`share-presets-history-meta`,children:[` · `,e.format??`unknown`,` · `,su(e.exported_at)]})]})},e.recipe_id))})]}):null,(0,B.jsx)(`div`,{className:`share-presets-footer`,children:(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,className:`share-presets-manage`,onClick:()=>{n(),i(!1)},children:`Manage presets…`})})]}):null]})}var lu=`share-manage-presets-title`;function uu({open:e,onClose:t}){let[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null);On((0,_.useMemo)(()=>e?[{key:`Escape`,scope:`modal`,action:t}]:[],[e,t]));let c=(0,_.useRef)(null),l=(0,_.useRef)(!1);(0,_.useEffect)(()=>{if(e)l.current||(l.current=!0,c.current=document.activeElement);else if(l.current){l.current=!1;let e=c.current;if(c.current=null,e&&typeof e.focus==`function`&&document.contains(e))e.focus();else{let e=document.activeElement;e&&typeof e.blur==`function`&&e.blur(),document.body.focus()}}},[e]),(0,_.useEffect)(()=>{if(!e)return;let t=!1;return s(null),(async()=>{try{let e=await ql();if(t)return;let n=[];for(let[t,r]of Object.entries(e.presets))for(let[e,i]of Object.entries(r))n.push({panel:t,name:e,record:i});n.sort((e,t)=>e.panel===t.panel?e.name.localeCompare(t.name):e.panel.localeCompare(t.panel)),r(n)}catch(e){if(t)return;s((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Failed to load presets`)}})(),()=>{t=!0}},[e]);async function u(e){a(!0),s(null);try{await Yl(e.panel,e.name),r(t=>t.filter(t=>!(t.panel===e.panel&&t.name===e.name))),z({type:`SHOW_STATUS_TOAST`,text:`Deleted preset "${e.name}"`})}catch(e){s((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Delete failed`)}finally{a(!1)}}async function d(e,t){a(!0),s(null);try{await Jl({panel:e.panel,name:t,template_id:e.record.template_id,options:e.record.options}),await Yl(e.panel,e.name),r(n=>n.map(n=>n.panel===e.panel&&n.name===e.name?{...n,name:t}:n)),z({type:`SHOW_STATUS_TOAST`,text:`Renamed to "${t}"`})}catch(e){s((e instanceof Ml?e.message??`HTTP ${e.status}`:e.message)??`Rename failed`)}finally{a(!1)}}return e?(0,B.jsxs)(`div`,{className:`share-manage-modal`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":lu,onClick:e=>e.stopPropagation(),children:[(0,B.jsx)(Gr,{title:`Manage presets`,titleId:lu,className:`share-manage-header`,onClose:t,closeClassName:`share-manage-close`}),o?(0,B.jsx)(`div`,{className:`share-manage-error`,role:`alert`,children:o}):null,n.length===0&&!o?(0,B.jsx)(`p`,{className:`share-manage-empty`,children:`No saved presets yet.`}):null,n.length>0?(0,B.jsxs)(`table`,{className:`share-manage-table`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{children:`Panel`}),(0,B.jsx)(`th`,{children:`Name`}),(0,B.jsx)(`th`,{children:`Saved at`}),(0,B.jsx)(`th`,{})]})}),(0,B.jsx)(`tbody`,{children:n.map(e=>(0,B.jsx)(du,{row:e,busy:i,onDelete:()=>void u(e),onRename:t=>void d(e,t)},`${e.panel}/${e.name}`))})]}):null]}):null}function du({row:e,busy:t,onDelete:n,onRename:r}){let[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(e.name),c=()=>{let t=o.trim();if(!t||t===e.name){s(e.name),a(!1);return}r(t),a(!1)};return(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`td`,{children:Wl(e.panel)}),(0,B.jsx)(`td`,{children:i?(0,B.jsx)(`input`,{className:`share-manage-name-input`,autoFocus:!0,value:o,disabled:t,maxLength:64,onChange:e=>s(e.target.value),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),c()):t.key===`Escape`&&(t.preventDefault(),t.stopPropagation(),s(e.name),a(!1))}}):(0,B.jsx)(`span`,{children:e.name})}),(0,B.jsx)(`td`,{children:e.record.saved_at}),(0,B.jsxs)(`td`,{className:`share-manage-actions`,children:[(0,B.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>{i?(s(e.name),a(!1)):a(!0)},children:i?`Cancel`:`Rename`}),(0,B.jsx)(`button`,{type:`button`,disabled:t,onClick:n,children:`Delete`})]})]})}function fu(){return{format:`md`,theme:`light`,reveal_projects:!1,no_branding:!1,top_n:5,period:{kind:`current`},project_allowlist:null,show_chart:!0,show_table:!0}}function pu(e,t){if(!t)return e;let n={...e,...t};return t.period&&(n.period={...e.period,...t.period}),n}function mu({panel:e,onClose:t,initialParams:n}){let r=Wl(e),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(()=>{let e=fu();return n?.windowWeeks==null?e:{...e,windowWeeks:n.windowWeeks}}),f=(0,_.useRef)(!1),[p,m]=(0,_.useState)(!1),h=`share-modal-title`;In(!0),On((0,_.useMemo)(()=>[{key:`Escape`,scope:`overlay`,layer:200,when:()=>!p&&L().composerModal===null,action:t}],[t,p])),(0,_.useEffect)(()=>{let t=!1;return a(null),s(null),Pl(e).then(e=>{if(t)return;a(e.templates);let n=e.templates[0];n&&(l(n.id),f.current||d(e=>pu(e,n.default_options)))}).catch(e=>{t||s(e instanceof Ml?`Couldn't load templates: ${e.message??`HTTP ${e.status}`}`:`Couldn't load templates: ${e.message}`)}),()=>{t=!0}},[e]),(0,_.useEffect)(()=>{if(!i||!c||f.current)return;let e=i.find(e=>e.id===c);e&&d(t=>pu(t,e.default_options))},[c,i]);let g=e=>{f.current=!0,d(e)};return(0,B.jsxs)(`div`,{className:`share-modal`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":h,onClick:e=>e.stopPropagation(),children:[(0,B.jsx)(Gr,{title:`Share ${r} report`,titleId:h,className:`share-modal-header`}),(0,B.jsxs)(`div`,{className:`share-modal-body`,children:[(0,B.jsxs)(`section`,{className:`share-section share-gallery-section`,"aria-label":`Template gallery`,children:[(0,B.jsx)(`div`,{className:`share-gallery-header`,children:(0,B.jsx)(cu,{panel:e,onPick:(e,t)=>{l(e),f.current=!0,d(e=>({...e,...t}))},onManage:()=>m(!0)})}),(0,B.jsx)(Rl,{panel:e,templates:i,error:o,selectedTemplateId:c,onSelect:e=>l(e)})]}),(0,B.jsxs)(`section`,{className:`share-section share-main-section`,children:[(0,B.jsx)(`div`,{className:`share-knobs-col`,"aria-label":`Render options`,children:(0,B.jsx)(zl,{options:u,onChange:g})}),(0,B.jsx)(`div`,{className:`share-preview-col`,"aria-label":`Live preview`,children:(0,B.jsx)(Hl,{panel:e,templateId:c,options:u})})]})]}),(0,B.jsx)(`footer`,{className:`share-modal-footer`,children:(0,B.jsx)(ou,{panel:e,templateId:c,options:u,onOptionsChange:g})}),(0,B.jsx)(Wr,{className:`share-modal-close`,label:`Close share modal`,onClose:t}),(0,B.jsx)(uu,{open:p,onClose:()=>m(!1)})]})}function hu(e,t){return{title:t.title,theme:t.theme,format:t.format,no_branding:t.no_branding,reveal_projects:t.reveal_projects,sections:e.map(e=>({snapshot:{panel:e.panel,template_id:e.template_id,options:e.options,data_digest_at_add:e.data_digest_at_add,kernel_version:e.kernel_version}}))}}async function gu(e,t){let n=await fetch(`/api/share/compose`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t?.signal});if(!n.ok){let e={};try{e=await n.json()}catch{}throw new Ml(n.status,e.field,e.error??`HTTP ${n.status}`,e.code)}return n.json()}function _u({items:e,results:t,kernelVersion:n,onRefresh:r,onRemove:i,onPreviewOnly:a}){let o=Xi(Yi(Qa,{activationConstraint:{distance:4}}),Yi(qa,{coordinateGetter:Ts}));function s(t){if(!t.over||t.active.id===t.over.id)return;let n=e.findIndex(e=>e.id===t.active.id),r=e.findIndex(e=>e.id===t.over.id);n<0||r<0||z({type:`BASKET_REORDER`,fromIdx:n,toIdx:r})}return(0,B.jsx)(Xo,{sensors:o,collisionDetection:ia,onDragEnd:s,children:(0,B.jsx)(ps,{items:e.map(e=>e.id),strategy:us,children:(0,B.jsx)(`ul`,{className:`composer-section-list`,children:e.map((e,o)=>(0,B.jsx)(vu,{item:e,result:t[o],kernelVersion:n,onRefresh:r,onRemove:i,onPreviewOnly:a},e.id))})})})}function vu({item:e,result:t,kernelVersion:n,onRefresh:r,onRemove:i,onPreviewOnly:a}){let{attributes:o,listeners:s,setNodeRef:c,transform:l,transition:u,isDragging:d}=xs({id:e.id}),f=Ms(),p={transform:Fi.Transform.toString(l),transition:f?void 0:u,opacity:d?.4:1},[m,h]=(0,_.useState)(!1),g=t?.drift_detected,v=e.kernel_version!==n,y=!!(g||v);return(0,B.jsxs)(`li`,{ref:c,style:p,className:`composer-section-row`,children:[(0,B.jsx)(`button`,{className:`composer-drag-handle`,"aria-label":`Reorder ${e.label_hint}`,type:`button`,...o,...s,children:`≡`}),(0,B.jsx)(`span`,{className:`composer-section-label`,children:e.label_hint}),y?(0,B.jsx)(`span`,{className:`composer-outdated-badge`,title:g&&v?`Data and kernel both shifted since add-time. Refresh to update.`:g?`Data has changed since this section was added. Refresh to update.`:`Kernel updated since this section was added. Refresh to re-render at the new version.`,children:`Outdated`}):null,(0,B.jsxs)(`div`,{className:`composer-section-actions`,children:[(0,B.jsx)(`button`,{type:`button`,"aria-haspopup":`menu`,"aria-expanded":m,onClick:()=>h(e=>!e),"aria-label":`Actions for ${e.label_hint}`,children:`⋯`}),m?(0,B.jsxs)(`ul`,{role:`menu`,className:`composer-section-menu`,children:[(0,B.jsx)(`li`,{children:(0,B.jsx)(`button`,{type:`button`,onClick:()=>{a(e.id),h(!1)},children:`Preview only this`})}),(0,B.jsx)(`li`,{children:(0,B.jsx)(`button`,{type:`button`,onClick:()=>{r(e.id),h(!1)},children:`Refresh from current data`})}),(0,B.jsx)(`li`,{children:(0,B.jsx)(`button`,{type:`button`,onClick:()=>{i(e.id),h(!1)},"aria-label":`Remove ${e.label_hint}`,children:`Remove`})})]}):null]})]})}function yu(e,t){return t&&e>0}function bu(e){return`cctally-report-${new Date().toISOString().slice(0,10).replaceAll(`-`,``)}.${e===`md`?`md`:e}`}function xu(e){switch(e){case`md`:return`text/markdown;charset=utf-8`;case`html`:return`text/html;charset=utf-8`;case`svg`:return`image/svg+xml;charset=utf-8`}}function Su(e){return e===`light`?`#ffffff`:`#0f172a`}function Cu(e,t){let n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=e,r.style.display=`none`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>URL.revokeObjectURL(n),0)}var wu=200;function Tu(){return L().composerModal}function Eu(){return L().basket}var Du=`composer-modal-title`;function Ou(){let e=(0,_.useSyncExternalStore)(R,Tu),t=(0,_.useSyncExternalStore)(R,Eu),n=rr();In(e?.open??!1);let r=(0,_.useRef)(null),i=(0,_.useRef)(!1),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`light`),[l,u]=(0,_.useState)(`html`),[d,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(!1),S=(0,_.useRef)(null),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(null);(0,_.useEffect)(()=>{E(null)},[l,s,d,p]),On((0,_.useMemo)(()=>[{key:`Escape`,scope:`overlay`,layer:210,when:()=>L().composerModal!==null,action:()=>z(Ge())}],[])),(0,_.useEffect)(()=>{e?.open&&a===``&&o(`cctally report — ${new Date().toISOString().slice(0,10)}`)},[e?.open,a]),(0,_.useEffect)(()=>{if(e?.open)i.current||(i.current=!0,r.current=document.activeElement);else if(i.current){i.current=!1;let e=r.current;if(r.current=null,e&&typeof e.focus==`function`&&document.contains(e))e.focus();else{let e=document.activeElement;e&&typeof e.blur==`function`&&e.blur(),document.body.focus()}}},[e?.open]),(0,_.useEffect)(()=>{if(!e?.open||t.items.length===0||a===``)return;let n=setTimeout(()=>{S.current?.abort();let e=new AbortController;S.current=e,x(!0),y(null),gu(hu(t.items,{title:a,theme:s,format:l,no_branding:p,reveal_projects:!d}),{signal:e.signal}).then(t=>{e.signal.aborted||g(t)}).catch(t=>{t?.name!==`AbortError`&&(e.signal.aborted||y(t instanceof Ml?t.message??`HTTP ${t.status}`:t.message))}).finally(()=>{e.signal.aborted||x(!1)})},wu);return()=>clearTimeout(n)},[e?.open,t.items,a,s,l,d,p]);async function D(e){let n=t.items.findIndex(t=>t.id===e);if(n<0)return;let r=t.items[n];try{let t=await Fl({panel:r.panel,template_id:r.template_id,options:{...r.options,reveal_projects:!d}}),i=Je({panel:r.panel,template_id:r.template_id,options:r.options,added_at:new Date().toISOString(),data_digest_at_add:t.snapshot.data_digest,kernel_version:t.snapshot.kernel_version,label_hint:r.label_hint,id:r.id});z({type:`BASKET_REMOVE`,id:e}),z({type:`BASKET_ADD`,item:i});let a=L().basket.items.length-1;a!==n&&z({type:`BASKET_REORDER`,fromIdx:a,toIdx:n})}catch(e){y(`Refresh failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}}let O=async e=>{let n=await gu(hu(t.items,{title:a,theme:s,format:e,no_branding:p,reveal_projects:!d}));return{body:n.body,content_type:n.content_type}},k=e=>z({type:`SHOW_STATUS_TOAST`,text:e}),A=async(e,t,n)=>{if(C==null){w(e),E(null);try{await t()}catch(e){E(`${n} failed: ${e instanceof Ml?e.message??`HTTP ${e.status}`:e.message}`)}finally{w(null)}}},ee=()=>A(`copy`,async()=>{let{body:e}=await O(`md`);if(!navigator.clipboard||typeof navigator.clipboard.writeText!=`function`)throw Error(`Clipboard API unavailable in this browser`);await navigator.clipboard.writeText(e),k(`Copied`)},`Copy`),te=()=>A(`download`,async()=>{let{body:e}=await O(l),t=new Blob([e],{type:xu(l)});Cu(bu(l),t),k(`Downloaded`)},`Download`),j=()=>A(`open`,async()=>{let{body:e}=await O(l),t=new Blob([e],{type:xu(l)}),n=URL.createObjectURL(t);window.open(n,`_blank`,`noopener,noreferrer`)},`Open`),M=()=>A(`png`,async()=>{let{body:e}=await O(`svg`),t=await $l(e,2,Su(s));Cu(bu(`svg`).replace(/\.svg$/,`.png`),t),k(`PNG downloaded`)},`PNG export`),N=()=>A(`print`,async()=>{let{body:e}=await O(`html`);eu(e)},`Print`),ne=C==null&&l===`md`&&t.items.length>0,re=C==null&&t.items.length>0,ie=C==null&&(l===`html`||l===`svg`)&&t.items.length>0,P=C==null&&l===`svg`&&t.items.length>0,ae=C==null&&l===`html`&&t.items.length>0,oe=!d,se=yu(t.items.length,oe),ce=oe?t.items.length:0;if(!e?.open)return null;let le=(0,B.jsx)(Gr,{title:`Compose report`,titleId:Du,className:`composer-modal-header`,onClose:()=>z(Ge()),closeClassName:`composer-modal-close`});return t.items.length===0?(0,B.jsxs)(`div`,{className:`composer-modal composer-modal-empty${n?` composer-modal-mobile`:``}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":Du,children:[le,(0,B.jsx)(`p`,{className:`composer-empty-message`,children:`Basket is empty. Open any panel's share menu and pick + Basket to add a section.`})]}):(0,B.jsxs)(`div`,{className:`composer-modal${n?` composer-modal-mobile`:``}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":Du,children:[le,(0,B.jsxs)(`div`,{className:`composer-knobs`,children:[(0,B.jsxs)(`label`,{children:[`Title`,(0,B.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value)})]}),(0,B.jsxs)(`label`,{children:[`Theme`,(0,B.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),children:[(0,B.jsx)(`option`,{value:`light`,children:`light`}),(0,B.jsx)(`option`,{value:`dark`,children:`dark`})]})]}),(0,B.jsxs)(`label`,{children:[`Format`,(0,B.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),children:[(0,B.jsx)(`option`,{value:`html`,children:`html`}),(0,B.jsx)(`option`,{value:`md`,children:`md`}),(0,B.jsx)(`option`,{value:`svg`,children:`svg`})]})]}),(0,B.jsxs)(`label`,{children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),`Anon on export`]}),(0,B.jsxs)(`label`,{children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked)}),`No branding`]})]}),se?(0,B.jsxs)(`div`,{className:`composer-anon-banner`,role:`status`,"aria-live":`polite`,children:[(0,B.jsxs)(`span`,{children:[ce,` section`,ce===1?``:`s`,` contain real project names. They will appear in the export.`]}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>f(!0),children:`Anonymize all`})]}):null,(0,B.jsxs)(`div`,{className:`composer-body`,children:[(0,B.jsx)(_u,{items:t.items,results:h?.snapshot.section_results??[],kernelVersion:h?.snapshot.kernel_version??1,onRefresh:e=>{D(e)},onRemove:e=>z({type:`BASKET_REMOVE`,id:e}),onPreviewOnly:e=>{}}),(0,B.jsxs)(`figure`,{className:`composer-preview-frame`,children:[(0,B.jsxs)(`figcaption`,{className:`composer-preview-label`,children:[`Preview · `,s]}),(0,B.jsx)(`iframe`,{className:`composer-preview`,title:`Combined preview`,tabIndex:-1,sandbox:`allow-same-origin`,srcDoc:h?.body??`<p>Composing…</p>`})]})]}),b?(0,B.jsx)(`div`,{className:`composer-busy`,children:`Composing…`}):null,v?(0,B.jsx)(`div`,{className:`composer-error`,role:`alert`,children:v}):null,T?(0,B.jsx)(`div`,{className:`composer-error`,role:`alert`,children:T}):null,(0,B.jsxs)(`footer`,{className:`composer-actions`,children:[(0,B.jsxs)(`div`,{className:`composer-export-row`,children:[(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-copy`,onClick:ee,disabled:!ne,title:l===`md`?C===`copy`?`Copying…`:`Copy composed report to clipboard`:`Copy is available for Markdown only`,children:C===`copy`?`Copying…`:`Copy`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-download`,onClick:te,disabled:!re,title:C===`download`?`Downloading…`:`Download composed report`,children:C===`download`?`Downloading…`:`Download`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-open`,onClick:j,disabled:!ie,title:l===`html`||l===`svg`?C===`open`?`Opening…`:`Open composed report in new tab`:`Open is available for HTML/SVG`,children:C===`open`?`Opening…`:`Open`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-png`,onClick:M,disabled:!P,title:l===`svg`?C===`png`?`Rasterizing…`:`Download composed report as PNG`:`PNG export — available for SVG format only`,children:C===`png`?`Rasterizing…`:`PNG`}),(0,B.jsx)(`button`,{type:`button`,className:`share-action share-action-print`,onClick:N,disabled:!ae,title:l===`html`?C===`print`?`Opening print dialog…`:`Open the browser print dialog (save as PDF)`:`Print → PDF — available for HTML format only`,children:C===`print`?`Printing…`:`Print → PDF`})]}),(0,B.jsx)(`button`,{type:`button`,className:`composer-clear-all`,onClick:()=>z({type:`BASKET_CLEAR`}),children:`Clear all`})]})]})}function ku(){let e=(0,_.useSyncExternalStore)(R,()=>L().shareModal),t=(0,_.useRef)(null),n=(0,_.useRef)(!1);(0,_.useEffect)(()=>{if(e)n.current||(n.current=!0,t.current=(e.triggerId?document.getElementById(e.triggerId):null)??document.activeElement);else if(n.current){n.current=!1;let e=t.current;if(t.current=null,e&&typeof e.focus==`function`&&document.contains(e))e.focus();else{let e=document.activeElement;e&&typeof e.blur==`function`&&e.blur(),document.body.focus()}}},[e]);let r=()=>z(Ue());return(0,B.jsxs)(B.Fragment,{children:[e?(0,B.jsx)(`div`,{id:`share-modal-root`,className:`share-overlay`,onClick:e=>{e.stopPropagation(),e.target===e.currentTarget&&r()},children:(0,B.jsx)(mu,{panel:e.panel,initialParams:e.params,onClose:r})}):null,(0,B.jsx)(Ou,{})]})}function Au(){let[e,t]=(0,_.useState)(()=>typeof window>`u`||!window.matchMedia?!0:window.matchMedia(nr).matches);return(0,_.useEffect)(()=>{if(typeof window>`u`||!window.matchMedia)return;let e=window.matchMedia(nr),n=e=>{t(e.matches)};return e.addEventListener(`change`,n),t(e.matches),()=>{e.removeEventListener(`change`,n)}},[]),e}function ju(e){if(L().snapshot==null)return;let t=L().prefs.panelOrder,n=e-1;if(n<0||n>=t.length)return;let r=Ur[t[n]];r&&r.openAction()}var Mu=`Click a panel first, then press S to share it.`;function Nu(){return typeof window>`u`||!window.matchMedia?!1:window.matchMedia(tr).matches}function Pu(){if(typeof document>`u`)return null;let e=document.activeElement;if(!e||!(e instanceof Element))return null;let t=e.closest(`[data-panel-kind]`);return t?t.getAttribute(`data-panel-kind`):null}function Fu(){return{key:`S`,scope:`global`,when:()=>{let e=L();return!(Nu()||e.shareModal!==null||e.composerModal!==null||e.openModal!==null||e.update.modalOpen||e.inputMode!==null||e.chromeOverlayOpen!==0)},action:()=>{let e=Pu();if(e===null){z({type:`SHOW_STATUS_TOAST`,text:Mu});return}if(!Me.has(e))return;let t=e;z(He(t,`${t}-panel`))}}}function Iu(){return typeof window>`u`||!window.matchMedia?!1:window.matchMedia(tr).matches}function Lu(){return{key:`B`,scope:`global`,when:()=>{let e=L();return!(Iu()||e.shareModal!==null||e.composerModal!==null||e.openModal!==null||e.update.modalOpen||e.inputMode!==null||e.chromeOverlayOpen!==0)},action:()=>z(We())}}function Ru(){return[Lu()]}function zu(){let e=L();return!e.openModal&&!e.update.modalOpen&&!e.doctorModalOpen&&e.inputMode===null&&e.chromeOverlayOpen===0}function Bu(){let e=L();return!(e.openModal!==null||e.update.modalOpen||e.inputMode!==null||e.chromeOverlayOpen!==0)}function Vu(){return[{key:`1`,scope:`global`,when:zu,action:()=>ju(1)},{key:`2`,scope:`global`,when:zu,action:()=>ju(2)},{key:`3`,scope:`global`,when:zu,action:()=>ju(3)},{key:`4`,scope:`global`,when:zu,action:()=>ju(4)},{key:`5`,scope:`global`,when:zu,action:()=>ju(5)},{key:`6`,scope:`global`,when:zu,action:()=>ju(6)},{key:`7`,scope:`global`,when:zu,action:()=>ju(7)},{key:`8`,scope:`global`,when:zu,action:()=>ju(8)},{key:`9`,scope:`global`,when:zu,action:()=>ju(9)},{key:`0`,scope:`global`,when:zu,action:()=>ju(10)},{key:`r`,scope:`global`,when:zu,action:()=>fn()},{key:`q`,scope:`global`,when:zu,action:yn},{key:`n`,scope:`global`,when:zu,action:()=>_n(1)},{key:`N`,scope:`global`,when:zu,action:()=>_n(-1)},{key:`d`,scope:`global`,view:`any`,when:Bu,action:()=>z({type:`OPEN_DOCTOR_MODAL`})},Fu(),...Ru(),{key:`c`,scope:`sessions`,when:()=>!L().openModal&&L().chromeOverlayOpen===0,action:()=>{let e=L().prefs.sessionsCollapsed;z({type:`SAVE_PREFS`,patch:{sessionsCollapsed:!e}})}}]}function Hu(){(0,_.useEffect)(()=>{let e=e=>{if(!(e.metaKey||e.ctrlKey)||e.shiftKey||e.altKey||e.key.toLowerCase()!==`f`)return;let t=L();if(t.view===`conversations`&&zu())if(e.preventDefault(),t.selectedConversationId)z({type:`OPEN_CONV_FIND`}),requestAnimationFrame(()=>{document.querySelector(`.conv-findbar-input`)?.focus()});else{let e=document.querySelector(`.conv-rail-search input`);e?.focus(),e?.select()}};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[])}function Uu(e){let t=new URLSearchParams;e.dateFrom&&t.set(`date_from`,e.dateFrom),e.dateTo&&t.set(`date_to`,e.dateTo);for(let n of e.projects)t.append(`projects`,n);e.costMin!=null&&t.set(`cost_min`,String(e.costMin)),e.costMax!=null&&t.set(`cost_max`,String(e.costMax)),e.rebuildMin!=null&&t.set(`rebuild_min`,String(e.rebuildMin));let n=t.toString();return n?`&${n}`:``}var Wu=50;function Gu(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!0),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(0),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(!1),f=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),p=(0,_.useRef)(f);p.current=f;let m=(0,_.useSyncExternalStore)(R,()=>L().conversationRailSort),h=(0,_.useRef)(m);h.current=m;let g=V()?.generated_at??``,v=(0,_.useRef)(!1),[y,b]=(0,_.useState)(!1),x=(0,_.useRef)(0);(0,_.useEffect)(()=>{x.current=e.length},[e.length]);let S=(0,_.useRef)(null),C=(0,_.useRef)(0),w=(0,_.useCallback)(()=>{if(v.current||x.current>Wu)return;S.current?.abort();let e=new AbortController;S.current=e,Mc(`/api/conversations?sort=${h.current}&limit=${Wu}&offset=0${Uu(p.current)}`,e.signal).then(e=>{t(e.conversations),s(e.page.next_offset),l(e.page.filter_degraded===!0),d(e.page.sort_degraded===!0),a(null),r(!1)}).catch(e=>{jc(e)||(a(`Couldn't load conversations.`),r(!1))})},[]),T=(0,_.useCallback)(()=>{a(null),r(!0),w()},[w]),E=JSON.stringify({filters:f,sort:m}),D=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(D.current===null){D.current=E;return}D.current!==E&&(D.current=E,C.current+=1,v.current=!1,b(!1),t([]),s(0),x.current=0,w())},[E]),(0,_.useEffect)(()=>{if(!(typeof document<`u`&&document.hidden))return w(),()=>S.current?.abort()},[g,w]),(0,_.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{document.hidden||w()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[w]);let O=(0,_.useCallback)(async()=>{if(o==null||v.current)return;v.current=!0,b(!0);let e=C.current;try{let n=await Mc(`/api/conversations?sort=${h.current}&limit=${Wu}&offset=${o}${Uu(p.current)}`);if(C.current!==e)return;t(e=>[...e,...n.conversations]),s(n.page.next_offset),l(n.page.filter_degraded===!0),d(n.page.sort_degraded===!0)}catch{}finally{v.current=!1,b(!1)}},[o]);return(0,_.useEffect)(()=>{e.length!==0&&z({type:`CACHE_CONVERSATION_TITLES`,titles:e.map(e=>[e.session_id,e.title])})},[e]),{rows:e,loading:n,error:i,hasMore:o!=null,loadMore:O,loadingMore:y,filterDegraded:c,sortDegraded:u,retry:T}}function Ku(e,t,n=e){let[r,i]=(0,_.useState)(n);return(0,_.useEffect)(()=>{let n=setTimeout(()=>i(e),t);return()=>clearTimeout(n)},[e,t]),r}var qu=200;function Ju(e,t=`all`){let[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(0),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=e.trim(),b=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),x=JSON.stringify(b),S=(0,_.useRef)(b);S.current=b;let C=Ku(y,qu,``),w=(0,_.useRef)(null),T=(0,_.useRef)(0);T.current=n.length;let E=(0,_.useRef)(0);E.current=o;let D=(0,_.useRef)(!1);D.current=m;let O=(0,_.useCallback)(e=>`/api/conversation/search?q=${encodeURIComponent(C)}&limit=50&offset=${e}&kind=${t}${Uu(S.current)}`,[C,t,x]);(0,_.useEffect)(()=>(y||(r([]),a(null),s(0),l(null),d(!1),v(null)),()=>{w.current?.abort()}),[y,t,x]),(0,_.useEffect)(()=>{if(!C){p(!1),h(!1);return}let e=new AbortController;return w.current=e,p(!0),h(!1),Mc(O(0),e.signal).then(e=>{r(e.hits),a(e.mode),s(e.total),l(e.search_depth??`full`),d(e.filter_degraded===!0),v(null),p(!1)}).catch(e=>{jc(e)||(v(`Search failed.`),p(!1))}),()=>e.abort()},[C,t,O]);let k=(0,_.useCallback)(()=>{if(D.current||T.current>=E.current)return;let e=T.current,t=new AbortController;w.current=t,h(!0),Mc(O(e),t.signal).then(e=>{r(t=>[...t,...e.hits]),s(e.total),a(e.mode),l(e.search_depth??`full`),d(e.filter_degraded===!0),h(!1)}).catch(e=>{jc(e)||(v(`Search failed.`),h(!1))})},[O]);return{hits:n,mode:i,total:o,loading:y!==``&&(y!==C||f),loadingMore:m,searchDepth:c,filterDegraded:u,error:g,loadMore:k}}function Yu(e){let t=[],n=0,r=0;for(;n<e.length;){let i=e.indexOf(`[`,n);if(i===-1){t.push((0,B.jsx)(_.Fragment,{children:e.slice(n)},r++));break}let a=e.indexOf(`]`,i+1);if(a===-1){t.push((0,B.jsx)(_.Fragment,{children:e.slice(n)},r++));break}i>n&&t.push((0,B.jsx)(_.Fragment,{children:e.slice(n,i)},r++)),t.push((0,B.jsx)(`mark`,{children:e.slice(i+1,a)},r++)),n=a+1}return(0,B.jsx)(B.Fragment,{children:t})}var Xu=864e5;function Zu(e,t){let[n,r,i]=new Intl.DateTimeFormat(`en-CA`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`}).format(new Date(e)).split(`-`).map(Number);return{y:n,m:r,d:i}}function Qu(e,t,n){let r=Date.parse(e),i=Zu(r,t),a=Zu(n,t),o=Date.UTC(i.y,i.m-1,i.d),s=Date.UTC(a.y,a.m-1,a.d),c=Math.round((s-o)/Xu);return c<=0?`Today`:c===1?`Yesterday`:c<7?`This Week`:i.y===a.y&&i.m===a.m?`This Month`:new Intl.DateTimeFormat(`en-US`,{timeZone:t,month:`long`,year:`numeric`}).format(new Date(r))}function $u(e,t,n,r){return e===`recent`||e===`oldest`?Qu(t.last_activity_utc,n,r):e===`project`?t.project_label||`—`:null}function ed(){let[e,t]=(0,_.useState)({projects:[]});return(0,_.useEffect)(()=>{let e=new AbortController;return Mc(`/api/conversations/facets`,e.signal).then(t).catch(e=>{jc(e)||t({projects:[]})}),()=>e.abort()},[]),e}function td(e){return`${e.getUTCFullYear()}-${String(e.getUTCMonth()+1).padStart(2,`0`)}-${String(e.getUTCDate()).padStart(2,`0`)}`}function nd(e){let[t,n,r]=new Intl.DateTimeFormat(`en-CA`,{timeZone:e,year:`numeric`,month:`2-digit`,day:`2-digit`}).format(new Date).split(`-`).map(Number);return{y:t,m:n,d:r}}var rd=[{key:`this-month`,label:`This month`,bounds:e=>{let{y:t,m:n}=nd(e);return{from:td(new Date(Date.UTC(t,n-1,1))),to:td(new Date(Date.UTC(t,n,0)))}}},{key:`last-month`,label:`Last month`,bounds:e=>{let{y:t,m:n}=nd(e);return{from:td(new Date(Date.UTC(t,n-2,1))),to:td(new Date(Date.UTC(t,n-1,0)))}}},{key:`last-7d`,label:`Last 7d`,bounds:e=>{let{y:t,m:n,d:r}=nd(e),i=new Date(Date.UTC(t,n-1,r));return{from:td(new Date(i.getTime()-6*864e5)),to:td(i)}}}],id=[1,5,10],ad=[1,3,5];function od(e){z({type:`SET_CONVERSATION_FILTERS`,patch:e})}function sd(){let e=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),t=ed(),{resolvedTz:n}=Rn(),[r,i]=(0,_.useState)(e.costMin?.toString()??``),[a,o]=(0,_.useState)(e.costMax?.toString()??``),[s,c]=(0,_.useState)(e.rebuildMin?.toString()??``);(0,_.useEffect)(()=>{i(e.costMin?.toString()??``)},[e.costMin]),(0,_.useEffect)(()=>{o(e.costMax?.toString()??``)},[e.costMax]),(0,_.useEffect)(()=>{c(e.rebuildMin?.toString()??``)},[e.rebuildMin]);let l=(0,_.useRef)({});(0,_.useEffect)(()=>{let e=l.current;return()=>{for(let t in e)clearTimeout(e[t])}},[]);let u=(e,t)=>{let n=l.current[e];n&&clearTimeout(n),l.current[e]=setTimeout(t,300)},d=e=>{if(e.trim()===``)return null;let t=Number(e);return Number.isFinite(t)?t:void 0},f=()=>z({type:`SET_INPUT_MODE`,mode:`filter`}),p=()=>z({type:`SET_INPUT_MODE`,mode:null});(0,_.useEffect)(()=>()=>{z({type:`SET_INPUT_MODE`,mode:null})},[]);let m=t=>{od({projects:e.projects.includes(t)?e.projects.filter(e=>e!==t):[...e.projects,t]})};return(0,B.jsxs)(`div`,{className:`conv-rail-filters`,role:`dialog`,"aria-label":`Conversation filters`,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),z({type:`SET_CONV_FILTERS_OPEN`,open:!1}))},children:[(0,B.jsxs)(`section`,{className:`conv-rail-filters-sec`,children:[(0,B.jsx)(`div`,{className:`conv-rail-filters-label`,children:`Date (last activity)`}),(0,B.jsx)(`div`,{className:`conv-rail-filters-chips`,children:rd.map(t=>(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-chip${e.datePreset===t.key?` is-on`:``}`,onClick:()=>{let e=t.bounds(n);od({dateFrom:e.from,dateTo:e.to,datePreset:t.key})},children:t.label},t.key))}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-range`,children:[(0,B.jsxs)(`label`,{className:`conv-rail-filters-field`,children:[(0,B.jsx)(`span`,{children:`From`}),(0,B.jsx)(`input`,{type:`date`,value:e.dateFrom??``,"aria-label":`Date from`,onFocus:f,onBlur:p,onChange:e=>od({dateFrom:e.target.value||null,datePreset:null})})]}),(0,B.jsxs)(`label`,{className:`conv-rail-filters-field`,children:[(0,B.jsx)(`span`,{children:`To`}),(0,B.jsx)(`input`,{type:`date`,value:e.dateTo??``,"aria-label":`Date to`,onFocus:f,onBlur:p,onChange:e=>od({dateTo:e.target.value||null,datePreset:null})})]})]})]}),(0,B.jsxs)(`section`,{className:`conv-rail-filters-sec`,children:[(0,B.jsx)(`div`,{className:`conv-rail-filters-label`,children:`Project`}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-projects`,children:[t.projects.length===0&&(0,B.jsx)(`div`,{className:`conv-rail-filters-empty`,children:`No projects.`}),t.projects.map(t=>(0,B.jsxs)(`label`,{className:`conv-rail-filters-proj`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:e.projects.includes(t.project_label),"aria-label":t.project_label,onChange:()=>m(t.project_label)}),(0,B.jsx)(`span`,{className:`conv-rail-filters-proj-name`,children:t.project_label}),(0,B.jsx)(`span`,{className:`conv-rail-filters-proj-count`,children:t.count})]},t.project_label))]})]}),(0,B.jsxs)(`section`,{className:`conv-rail-filters-sec`,children:[(0,B.jsx)(`div`,{className:`conv-rail-filters-label`,children:`Cost (USD)`}),(0,B.jsx)(`div`,{className:`conv-rail-filters-chips`,children:id.map(t=>(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-filters-chip${e.costMin===t?` is-on`:``}`,onClick:()=>od({costMin:t}),children:[`≥$`,t]},t))}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-range`,children:[(0,B.jsxs)(`label`,{className:`conv-rail-filters-field`,children:[(0,B.jsx)(`span`,{children:`Min`}),(0,B.jsx)(`input`,{type:`number`,inputMode:`decimal`,min:`0`,step:`0.01`,value:r,"aria-label":`Min cost`,placeholder:`0`,onFocus:f,onBlur:p,onChange:e=>{i(e.target.value);let t=d(e.target.value);t!==void 0&&u(`costMin`,()=>od({costMin:t}))}})]}),(0,B.jsxs)(`label`,{className:`conv-rail-filters-field`,children:[(0,B.jsx)(`span`,{children:`Max`}),(0,B.jsx)(`input`,{type:`number`,inputMode:`decimal`,min:`0`,step:`0.01`,value:a,"aria-label":`Max cost`,placeholder:`∞`,onFocus:f,onBlur:p,onChange:e=>{o(e.target.value);let t=d(e.target.value);t!==void 0&&u(`costMax`,()=>od({costMax:t}))}})]})]})]}),(0,B.jsxs)(`section`,{className:`conv-rail-filters-sec`,children:[(0,B.jsx)(`div`,{className:`conv-rail-filters-label`,children:`Cache rebuilds`}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-chips`,children:[ad.map(t=>(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-filters-chip${e.rebuildMin===t?` is-on`:``}`,onClick:()=>od({rebuildMin:t}),children:[`≥`,t]},t)),(0,B.jsxs)(`label`,{className:`conv-rail-filters-field conv-rail-filters-field--inline`,children:[(0,B.jsx)(`span`,{children:`≥`}),(0,B.jsx)(`input`,{type:`number`,inputMode:`numeric`,min:`0`,step:`1`,value:s,"aria-label":`Min cache rebuilds`,placeholder:`N`,onFocus:f,onBlur:p,onChange:e=>{c(e.target.value);let t=d(e.target.value);if(t!==void 0){let e=t===null?null:Math.floor(t);u(`rebuildMin`,()=>od({rebuildMin:e}))}}})]})]})]}),(0,B.jsxs)(`div`,{className:`conv-rail-filters-footer`,children:[(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-clear`,onClick:()=>z({type:`CLEAR_CONVERSATION_FILTERS`}),children:`Clear all`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-done`,onClick:()=>z({type:`SET_CONV_FILTERS_OPEN`,open:!1}),children:`Done`})]})]})}var cd=48;function ld(e,t){let n=t[e]?.trim();return n?{kind:`title`,text:n.length>cd?`${n.slice(0,cd-1)}…`:n}:{kind:`hash`,text:e.slice(0,8)}}function ud(e){let t=new Set;for(let n of e)if(t.add(n.project_label),t.size>1)return!1;return!0}var dd={tools:`tool`,thinking:`thinking`,title:`title`,files:`file`};function fd(e,t){let n=dd[t];return n?e.filter(e=>e!==n):e}var pd=[{key:`recent`,label:`Recent`},{key:`oldest`,label:`Oldest`},{key:`cost`,label:`Cost`},{key:`messages`,label:`Messages`},{key:`project`,label:`Project`}],md=[{kind:`all`,label:`All`,needsSplit:!1,group:`content`},{kind:`prompts`,label:`Prompts`,needsSplit:!1,group:`content`},{kind:`assistant`,label:`Assistant`,needsSplit:!1,group:`content`},{kind:`tools`,label:`Tools`,needsSplit:!0,group:`content`},{kind:`thinking`,label:`Thinking`,needsSplit:!0,group:`content`},{kind:`title`,label:`Title`,needsSplit:!1,group:`structural`},{kind:`files`,label:`Files`,needsSplit:!1,group:`structural`}],hd={tool:`tool`,thinking:`thinking`,title:`title`,file:`file`},gd={"this-month":`This month`,"last-month":`Last month`,"last-7d":`Last 7d`};function _d(e){return e.dateFrom!=null||e.dateTo!=null||e.projects.length>0||e.costMin!=null||e.costMax!=null||e.rebuildMin!=null}function vd(e){let t=[];if(e.dateFrom||e.dateTo){let n=e.datePreset?gd[e.datePreset]??e.datePreset:e.dateFrom&&e.dateTo?`${e.dateFrom} → ${e.dateTo}`:e.dateFrom?`from ${e.dateFrom}`:`to ${e.dateTo}`;t.push({key:`date`,label:n,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{dateFrom:null,dateTo:null,datePreset:null}})})}for(let n of e.projects)t.push({key:`proj:${n}`,label:n,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{projects:e.projects.filter(e=>e!==n)}})});return e.costMin!=null&&t.push({key:`costMin`,label:`≥$${e.costMin}`,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{costMin:null}})}),e.costMax!=null&&t.push({key:`costMax`,label:`≤$${e.costMax}`,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{costMax:null}})}),e.rebuildMin!=null&&t.push({key:`rebuildMin`,label:`≥${e.rebuildMin} ♻`,remove:()=>z({type:`SET_CONVERSATION_FILTERS`,patch:{rebuildMin:null}})}),t}function yd(){let e=(0,_.useSyncExternalStore)(R,()=>L().conversationSearch),t=(0,_.useSyncExternalStore)(R,()=>L().conversationSearchKind),n=(0,_.useSyncExternalStore)(R,()=>L().selectedConversationId),r=(0,_.useSyncExternalStore)(R,()=>L().convFiltersOpen),i=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),a=(0,_.useSyncExternalStore)(R,()=>L().conversationRailSort),o=(0,_.useSyncExternalStore)(R,()=>L().comparePick),s=(0,_.useSyncExternalStore)(R,()=>L().conversationTitles),c=Rn(),l={tz:c.resolvedTz,offsetLabel:c.offsetLabel},u=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!o)return;let e=e=>{e.key===`Escape`&&(e.stopPropagation(),z({type:`CANCEL_COMPARE_PICK`}))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o]);let d=e.trim()!==``,f=vd(i),p=o?ld(o.anchor,s):null;return(0,B.jsxs)(`aside`,{className:`conv-rail${o?` conv-rail--picking`:``}`,children:[o&&(0,B.jsxs)(`div`,{className:`conv-rail-pickbanner`,role:`status`,"aria-live":`polite`,children:[(0,B.jsxs)(`span`,{className:`conv-rail-pickbanner-text`,children:[`Comparing with`,` `,p?.kind===`title`?(0,B.jsxs)(`strong`,{className:`conv-rail-pickbanner-title`,children:[`“`,p.text,`”`]}):(0,B.jsx)(`code`,{children:p?.text}),` `,`— pick a session`]}),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-pickcancel`,"aria-label":`Cancel comparison pick`,onClick:()=>z({type:`CANCEL_COMPARE_PICK`}),children:`Cancel`})]}),(0,B.jsxs)(`div`,{className:`conv-rail-search`,children:[(0,B.jsxs)(`div`,{className:`conv-rail-search-bar`,children:[(0,B.jsxs)(`div`,{className:`conv-rail-search-inputwrap`,children:[(0,B.jsx)(`span`,{className:`conv-rail-search-mag`,"aria-hidden":`true`,children:`⌕`}),(0,B.jsx)(`input`,{ref:u,type:`search`,className:`conv-rail-search-input`,placeholder:`search all conversations…`,value:e,onChange:e=>z({type:`SET_CONVERSATION_SEARCH`,text:e.target.value}),onFocus:()=>z({type:`SET_INPUT_MODE`,mode:`search`}),onBlur:()=>z({type:`SET_INPUT_MODE`,mode:null}),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),z({type:`SET_CONVERSATION_SEARCH`,text:``}),u.current?.blur())}})]}),(0,B.jsxs)(`div`,{className:`conv-rail-search-controls`,children:[(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-btn${r?` is-on`:``}`,"aria-expanded":r,title:`Filter conversations`,onClick:()=>z({type:`TOGGLE_CONV_FILTERS`}),onKeyDown:e=>{r&&e.key===`Escape`&&(e.stopPropagation(),z({type:`TOGGLE_CONV_FILTERS`}))},children:`Filters ▾`}),(0,B.jsxs)(`label`,{className:`conv-rail-sort`,children:[(0,B.jsx)(`span`,{className:`conv-rail-sort-label`,children:`Sort`}),(0,B.jsx)(`select`,{className:`conv-rail-sort-select`,"aria-label":`Sort conversations`,value:a,onChange:e=>z({type:`SET_CONVERSATION_RAIL_SORT`,sort:e.target.value}),children:pd.map(e=>(0,B.jsx)(`option`,{value:e.key,children:e.label},e.key))})]})]})]}),r&&(0,B.jsx)(sd,{}),f.length>0&&(0,B.jsxs)(`div`,{className:`conv-rail-filters-active`,children:[f.map(e=>(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-filters-activechip`,title:`Remove ${e.label}`,"aria-label":`Remove ${e.label}`,onClick:e.remove,children:[e.label,(0,B.jsx)(`span`,{className:`conv-rail-filters-x`,"aria-hidden":`true`,children:`✕`})]},e.key)),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-filters-clearall`,onClick:()=>z({type:`CLEAR_CONVERSATION_FILTERS`}),children:`Clear all`})]})]}),d?(0,B.jsx)(wd,{needle:e,kind:t,ctx:l,selectedId:n,pickAnchor:o?.anchor??null}):(0,B.jsx)(xd,{selectedId:n,ctx:l,pickAnchor:o?.anchor??null})]})}function bd(e,t,n){return e&&e!==t?()=>z({type:`OPEN_COMPARE`,a:e,b:t}):n}function xd({selectedId:e,ctx:t,pickAnchor:n}){let{rows:r,loading:i,error:a,hasMore:o,loadMore:s,loadingMore:c,filterDegraded:l,sortDegraded:u,retry:d}=Gu(),f=(0,_.useSyncExternalStore)(R,()=>L().conversationFilters),p=(0,_.useSyncExternalStore)(R,()=>L().conversationRailSort),m=(0,B.jsxs)(B.Fragment,{children:[l&&(0,B.jsx)(`div`,{className:`conv-rail-filters-degraded`,children:`Project/cost/rebuild filters apply once indexing finishes.`}),u&&(0,B.jsx)(`div`,{className:`conv-rail-sort-degraded`,children:`Cost/Project sort unavailable while indexing — showing recent order.`})]});if(a)return(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,(0,B.jsxs)(`div`,{className:`conv-rail-empty`,children:[a,(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-retry`,onClick:()=>d(),children:`Retry`})]})]});if(i&&r.length===0)return(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,(0,B.jsx)(`div`,{className:`conv-rail-empty`,children:`Loading…`})]});if(r.length===0)return _d(f)?(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,(0,B.jsxs)(`div`,{className:`conv-rail-empty conv-rail-empty--filtered`,children:[(0,B.jsx)(`div`,{children:`No conversations match these filters.`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-empty-clear`,onClick:()=>z({type:`CLEAR_CONVERSATION_FILTERS`}),children:`Clear filters`})]})]}):(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,(0,B.jsx)(`div`,{className:`conv-rail-empty`,children:`No conversations.`})]});let h=u?`recent`:p,g=h===`project`,v=null,y=Date.now(),b=ud(r)||g;return(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[m,r.map(r=>{let i=$u(h,r,t.tz,y),a=i===null?null:i.toLowerCase(),o=i!==null&&a!==v;return a!==null&&(v=a),(0,B.jsxs)(_.Fragment,{children:[o&&(0,B.jsx)(`div`,{className:`conv-rail-sec${g?` conv-rail-sec--project`:``}`,title:g?i??void 0:void 0,children:i}),(0,B.jsx)(Sd,{row:r,ctx:t,active:r.session_id===e,pickAnchor:n,hideProject:b})]},r.session_id)}),o&&(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-more`,disabled:c,onClick:()=>void s(),children:c?`Loading…`:`Load more`})]})}function Sd({row:e,ctx:t,active:n,pickAnchor:r,hideProject:i}){let a=r===e.session_id,o=sr(e.models,1);return(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-row${n?` is-active`:``}${r?` conv-rail-row--pick`:``}${a?` conv-rail-row--anchor`:``}`,disabled:a,"aria-disabled":a||void 0,title:a?`This is the anchor session`:void 0,onClick:bd(r,e.session_id,()=>z({type:`SELECT_CONVERSATION`,sessionId:e.session_id})),children:[(0,B.jsx)(`div`,{className:`conv-rail-row-title`,children:e.title}),(0,B.jsxs)(`div`,{className:`conv-rail-row-meta`,children:[(0,B.jsxs)(`span`,{className:`conv-rail-row-metaleft`,children:[!i&&(0,B.jsx)(`span`,{className:`conv-rail-row-project`,children:e.project_label||`—`}),(0,B.jsx)(`span`,{className:`conv-rail-row-branch`,children:e.git_branch??`—`})]}),(0,B.jsx)(`span`,{className:`conv-rail-row-when`,children:F.startedShort(e.last_activity_utc,t,{noSuffix:!0})}),o.classes.length>0&&(0,B.jsxs)(`span`,{className:`conv-rail-row-model`,children:[o.classes.map(e=>(0,B.jsx)(`span`,{className:`chip ${e}`,children:e},e)),o.extra>0&&(0,B.jsxs)(`span`,{className:`conv-rail-row-model-more`,children:[`+`,o.extra]})]}),(0,B.jsxs)(`span`,{className:`conv-rail-row-cluster`,children:[(0,B.jsx)(`span`,{className:`conv-rail-row-cost`,children:F.usd2(e.cost_usd)}),(0,B.jsx)(`span`,{className:`conv-rail-row-msgs`,children:e.msg_count})]})]})]})}function Cd({kind:e,proseOnly:t}){let n=null;return(0,B.jsx)(`div`,{className:`conv-rail-chips`,role:`radiogroup`,"aria-label":`Search kind`,children:md.map(r=>{let i=r.needsSplit&&t,a=e===r.kind,o=n!==null&&r.group!==n;return n=r.group,(0,B.jsxs)(_.Fragment,{children:[o&&(0,B.jsx)(`span`,{className:`conv-rail-chips-break`,"aria-hidden":`true`}),(0,B.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":a,disabled:i,title:i?`indexing…`:void 0,className:`conv-rail-chip${a?` is-on`:``}`,onClick:()=>z({type:`SET_CONVERSATION_SEARCH_KIND`,kind:r.kind}),children:r.label})]},r.kind)})})}function wd({needle:e,kind:t,ctx:n,selectedId:r,pickAnchor:i}){let{hits:a,mode:o,total:s,loading:c,loadingMore:l,searchDepth:u,filterDegraded:d,error:f,loadMore:p}=Ju(e,t),m=u===`prose-only`,h=s-a.length,g=m&&(t===`tools`||t===`thinking`),_=(s===0?`No results`:`${s} results${o===`like`?` · basic search`:``}`)+(g?` · indexing…`:``),v=s===0&&!c&&!f;return(0,B.jsxs)(`div`,{className:`conv-rail-list`,children:[(0,B.jsx)(Cd,{kind:t,proseOnly:m}),d&&(0,B.jsx)(`div`,{className:`conv-rail-search-filters-degraded`,children:`Some filters unavailable while indexing.`}),f?(0,B.jsx)(`div`,{className:`conv-rail-empty`,role:`alert`,children:f}):c&&a.length===0?(0,B.jsx)(`div`,{className:`conv-rail-empty`,role:`status`,children:`Searching…`}):v?(0,B.jsxs)(`div`,{className:`conv-rail-noresults`,role:`status`,children:[(0,B.jsxs)(`div`,{className:`conv-rail-noresults-q`,children:[`No results for “`,e.length>40?e.slice(0,40)+`…`:e,`”`,g?` · indexing…`:``]}),t!==`all`&&(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-noresults-action`,onClick:()=>z({type:`SET_CONVERSATION_SEARCH_KIND`,kind:`all`}),children:`Search all conversations`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-rail-noresults-action`,onClick:()=>z({type:`SET_CONVERSATION_SEARCH`,text:``}),children:`Clear search`})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`conv-rail-count`,"aria-live":`polite`,children:_}),a.map((e,a)=>(0,B.jsx)(Td,{hit:e,ctx:n,kind:t,selectedId:r,pickAnchor:i},`${e.session_id}-${e.uuid}-${a}`)),a.length<s&&(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-more`,disabled:l,onClick:()=>p(),children:[`Load `,Math.min(50,h),` more (`,h,` remaining)`]})]})]})}function Td({hit:e,ctx:t,kind:n,selectedId:r,pickAnchor:i}){let a=e.match_kinds??[],o=a.includes(`file`),s=fd(a,n),c=i===e.session_id;return(0,B.jsxs)(`button`,{type:`button`,className:`conv-rail-row conv-rail-row--hit${e.session_id===r?` is-active`:``}${o?` conv-rail-row--filehit`:``}${i?` conv-rail-row--pick`:``}${c?` conv-rail-row--anchor`:``}`,disabled:c,"aria-disabled":c||void 0,title:c?`This is the anchor session`:void 0,onClick:bd(i,e.session_id,()=>z({type:`OPEN_CONVERSATION`,sessionId:e.session_id,jump:{session_id:e.session_id,uuid:e.uuid}})),children:[o?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`conv-rail-row-title conv-rail-row-title--hit`,children:[(0,B.jsx)(`span`,{className:`conv-rail-row-filepath conv-rail-row-title-text`,children:e.snippet}),s.length>0&&(0,B.jsx)(Ed,{badges:s})]}),(0,B.jsx)(`div`,{className:`conv-rail-row-filetitle`,children:e.title})]}):(0,B.jsxs)(`div`,{className:`conv-rail-row-title conv-rail-row-title--hit`,children:[(0,B.jsx)(`span`,{className:`conv-rail-row-title-text`,children:e.title}),s.length>0&&(0,B.jsx)(Ed,{badges:s})]}),(0,B.jsxs)(`div`,{className:`conv-rail-row-meta`,children:[(0,B.jsx)(`span`,{className:`conv-rail-row-metaleft`,children:(0,B.jsx)(`span`,{className:`conv-rail-row-project`,children:e.project_label||`—`})}),(0,B.jsx)(`span`,{className:`conv-rail-row-when`,children:F.startedShort(e.ts,t,{noSuffix:!0})})]}),!o&&(0,B.jsx)(`div`,{className:`conv-rail-row-snippet`,children:Yu(e.snippet)})]})}function Ed({badges:e}){return(0,B.jsx)(`span`,{className:`conv-rail-kindbs`,children:e.map(e=>(0,B.jsx)(`span`,{className:`conv-rail-kindb`,children:hd[e]??e},e))})}var Dd=0,Od=1,kd=2,Ad=4;function jd(e){return()=>e}function Md(e){e()}function Nd(e,t){return n=>e(t(n))}function Pd(e,t){return()=>e(t)}function Fd(e,t){return n=>e(t,n)}function Id(e){return e!==void 0}function Ld(...e){return()=>{e.map(Md)}}function Rd(){}function zd(e,t){return t(e),e}function Bd(e,t){return t(e)}function Vd(...e){return e}function Hd(e,t){return e(Od,t)}function Ud(e,t){e(Dd,t)}function Wd(e){e(kd)}function Gd(e){return e(Ad)}function W(e,t){return Hd(e,Fd(t,Dd))}function Kd(e,t){let n=e(Od,e=>{n(),t(e)});return n}function qd(e){let t,n;return r=>i=>{t=i,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Jd(e,t){return e===t}function Yd(e=Jd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function G(e){return t=>n=>{e(n)&&t(n)}}function K(e){return t=>Nd(t,e)}function Xd(e){return t=>()=>{t(e)}}function q(e,...t){let n=tf(...t);return((t,r)=>{switch(t){case kd:Wd(e);return;case Od:return Hd(e,n(r))}})}function Zd(e,t){return n=>r=>{n(t=e(t,r))}}function Qd(e){return t=>n=>{e>0?e--:t(n)}}function $d(e){let t=null,n;return r=>i=>{t=i,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function ef(...e){let t=Array(e.length),n=0,r=null,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;Hd(e,e=>{let s=n;n|=o,t[a]=e,s!==i&&n===i&&r&&(r(),r=null)})}),e=>a=>{let o=()=>{e([a].concat(t))};n===i?o():r=o}}function tf(...e){return t=>e.reduceRight(Bd,t)}function nf(e){let t,n,r=()=>t?.();return function(i,a){switch(i){case Od:return a?n===a?void 0:(r(),n=a,t=Hd(e,a),t):(r(),Rd);case kd:r(),n=null;return}}}function J(e){let t=e,n=af();return((e,r)=>{switch(e){case Dd:t=r;break;case Od:r(t);break;case Ad:return t}return n(e,r)})}function rf(e,t){return zd(J(t),t=>W(e,t))}function af(){let e=[];return((t,n)=>{switch(t){case Dd:e.slice().forEach(e=>{e(n)});return;case kd:e.splice(0,e.length);return;case Od:return e.push(n),()=>{let t=e.indexOf(n);t>-1&&e.splice(t,1)}}})}function of(e){return zd(af(),t=>W(e,t))}function sf(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:cf(),singleton:n}}var cf=()=>Symbol();function lf(e){let t=new Map,n=({constructor:e,dependencies:r,id:i,singleton:a})=>{if(a&&t.has(i))return t.get(i);let o=e(r.map(e=>n(e)));return a&&t.set(i,o),o};return n(e)}function uf(...e){let t=af(),n=Array(e.length),r=0,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;Hd(e,e=>{n[a]=e,r|=o,r===i&&Ud(t,n)})}),function(e,a){switch(e){case kd:Wd(t);return;case Od:return r===i&&a(n),Hd(t,a)}}}function Y(e,t=Jd){return q(e,Yd(t))}function df(...e){return function(t,n){switch(t){case kd:return;case Od:return Ld(...e.map(e=>Hd(e,n)))}}}var ff={DEBUG:0,INFO:1,WARN:2,ERROR:3},pf={[ff.DEBUG]:`debug`,[ff.ERROR]:`error`,[ff.INFO]:`log`,[ff.WARN]:`warn`},mf=()=>typeof globalThis>`u`?window:globalThis,hf=sf(()=>{let e=J(ff.ERROR);return{log:J((t,n,r=ff.INFO)=>{r>=(mf().VIRTUOSO_LOG_LEVEL??Gd(e))&&console[pf[r]](`%creact-virtuoso: %c%s %o`,`color: #0253b3; font-weight: bold`,`color: initial`,t,n)}),logLevel:e}},[],{singleton:!0}),gf=new WeakMap;function _f(e){return`self`in e?e.document.documentElement:e}function vf(e){let t=_f(e),n=gf.get(t);if(n!==void 0)return n;let r=t.ownerDocument.defaultView.getComputedStyle(t).direction===`rtl`;return gf.set(t,r),r}function yf(e){gf.delete(_f(e))}function bf(e,t){return vf(e)?-t:t}var xf=bf;function Sf(e,t){return bf(e,t)}function Cf(e,t,n){return wf(e,t,n).callbackRef}function wf(e,t,n){let r=_.useRef(null),i=e=>{},a=_.useMemo(()=>typeof ResizeObserver<`u`?new ResizeObserver(t=>{let r=()=>{let n=t[0].target;n.offsetParent!==null&&e(n)};n?r():requestAnimationFrame(r)}):null,[e,n]);return i=e=>{e&&t?(a?.observe(e),r.current=e):(r.current&&a?.unobserve(r.current),r.current=null)},{callbackRef:i,ref:r}}function Tf(e,t,n,r,i,a,o,s,c){return wf(_.useCallback(n=>{let c=Ef(n.children,t,s?`offsetWidth`:`offsetHeight`,i),l=n.parentElement;for(;l.dataset.virtuosoScroller===void 0;)l=l.parentElement;let u=l.lastElementChild.dataset.viewportType===`window`,d;u&&(d=l.ownerDocument.defaultView);let f=o?s?o.scrollWidth:o.scrollHeight:u?s?d.document.documentElement.scrollWidth:d.document.documentElement.scrollHeight:s?l.scrollWidth:l.scrollHeight,p=o?s?o.offsetWidth:o.offsetHeight:u?s?d.innerWidth:d.innerHeight:s?l.offsetWidth:l.offsetHeight,m=o?s?xf(o,o.scrollLeft):o.scrollTop:u?s?xf(d,d.scrollX||d.document.documentElement.scrollLeft):d.scrollY||d.document.documentElement.scrollTop:s?xf(l,l.scrollLeft):l.scrollTop;r({scrollHeight:f,scrollTop:Math.max(m,0),viewportHeight:p}),a?.(s?Df(`column-gap`,getComputedStyle(n).columnGap,i):Df(`row-gap`,getComputedStyle(n).rowGap,i)),c!==null&&e(c)},[e,t,i,a,o,r,s]),n,c)}function Ef(e,t,n,r){let i=e.length;if(i===0)return null;let a=[];for(let o=0;o<i;o++){let i=e.item(o);if(i.dataset.index===void 0)continue;let s=parseInt(i.dataset.index),c=parseFloat(i.dataset.knownSize),l=t(i,n);if(l===0&&r(`Zero-sized element, this should not happen`,{child:i},ff.ERROR),l===c)continue;let u=a[a.length-1];a.length===0||u.size!==l||u.endIndex!==s-1?a.push({endIndex:s,size:l,startIndex:s}):a[a.length-1].endIndex++}return a}function Df(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,ff.WARN),t===`normal`?0:parseInt(t??`0`,10)}function Of(e,t,n){let r=_.useRef(null),i=_.useCallback(n=>{if(!n?.offsetParent)return;let i=n.getBoundingClientRect(),a=i.width,s,c;if(t){let e=t.getBoundingClientRect(),n=i.top-e.top;c=e.height-Math.max(0,n),s=n+t.scrollTop}else{let e=o.current.ownerDocument.defaultView;c=e.innerHeight-Math.max(0,i.top),s=i.top+e.scrollY}r.current={listHeight:i.height,offsetTop:s,visibleHeight:c,visibleWidth:a},e(r.current)},[e,t]),{callbackRef:a,ref:o}=wf(i,!0,n),s=_.useCallback(()=>{i(o.current)},[i,o]);return _.useEffect(()=>{if(t){t.addEventListener(`scroll`,s);let e=new ResizeObserver(()=>{requestAnimationFrame(s)});return e.observe(t),()=>{t.removeEventListener(`scroll`,s),e.unobserve(t)}}let e=o.current?.ownerDocument.defaultView;return e?.addEventListener(`scroll`,s),e?.addEventListener(`resize`,s),()=>{e?.removeEventListener(`scroll`,s),e?.removeEventListener(`resize`,s)}},[s,t,o]),a}var kf=sf(()=>{let e=af(),t=af(),n=J(0),r=af(),i=J(0),a=af(),o=af(),s=J(0),c=J(0),l=J(0),u=J(0),d=af(),f=af(),p=J(!1),m=J(!1),h=J(!1);return W(q(e,K(({scrollTop:e})=>e)),t),W(q(e,K(({scrollHeight:e})=>e)),o),W(t,i),{deviation:n,fixedFooterHeight:l,fixedHeaderHeight:c,footerHeight:u,headerHeight:s,horizontalDirection:m,scrollBy:f,scrollContainerState:e,scrollHeight:o,scrollingInProgress:p,scrollTo:d,scrollTop:t,skipAnimationFrameInResizeObserver:h,smoothScrollTargetReached:r,statefulScrollTop:i,viewportHeight:a}},[],{singleton:!0}),Af={lvl:0};function jf(e,t){let n=e.length;if(n===0)return[];let{index:r,value:i}=t(e[0]),a=[];for(let o=1;o<n;o++){let{index:n,value:s}=t(e[o]);a.push({end:n-1,start:r,value:i}),r=n,i=s}return a.push({end:1/0,start:r,value:i}),a}function Mf(e){return e===Af}function Nf(e,t){if(!Mf(e))return t===e.k?e.v:t<e.k?Nf(e.l,t):Nf(e.r,t)}function Pf(e,t,n=`k`){if(Mf(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){let r=Pf(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Pf(e.l,t,n)}function Ff(e,t,n){return Mf(e)?Kf(t,n,1):t===e.k?Hf(e,{k:t,v:n}):t<e.k?qf(Hf(e,{l:Ff(e.l,t,n)})):qf(Hf(e,{r:Ff(e.r,t,n)}))}function If(){return Af}function Lf(e,t,n){if(Mf(e))return[];let r=Pf(e,t)[0];return Xf(Bf(e,r,n))}function Rf(e,t){if(Mf(e))return Af;let{k:n,l:r,r:i}=e;if(t===n){if(Mf(r))return i;if(Mf(i))return r;let[t,n]=Gf(r);return Vf(Hf(e,{k:t,l:Uf(r),v:n}))}return Vf(t<n?Hf(e,{l:Rf(r,t)}):Hf(e,{r:Rf(i,t)}))}function zf(e){return Mf(e)?[]:[...zf(e.l),{k:e.k,v:e.v},...zf(e.r)]}function Bf(e,t,n){if(Mf(e))return[];let{k:r,l:i,r:a,v:o}=e,s=[];return r>t&&(s=s.concat(Bf(i,t,n))),r>=t&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(Bf(a,t,n))),s}function Vf(e){let{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(Wf(t))return Jf(Hf(e,{lvl:n-1}));if(!Mf(t)&&!Mf(t.r))return Hf(t.r,{l:Hf(t,{r:t.r.l}),lvl:n,r:Hf(e,{l:t.r.r,lvl:n-1})});throw Error(`Unexpected empty nodes`)}if(Wf(e))return Yf(Hf(e,{lvl:n-1}));if(!Mf(r)&&!Mf(r.l)){let t=r.l,i=Wf(t)?r.lvl-1:r.lvl;return Hf(t,{l:Hf(e,{lvl:n-1,r:t.l}),lvl:t.lvl+1,r:Yf(Hf(r,{l:t.r,lvl:i}))})}throw Error(`Unexpected empty nodes`)}function Hf(e,t){return Kf(t.k===void 0?e.k:t.k,t.v===void 0?e.v:t.v,t.lvl===void 0?e.lvl:t.lvl,t.l===void 0?e.l:t.l,t.r===void 0?e.r:t.r)}function Uf(e){return Mf(e.r)?e.l:Vf(Hf(e,{r:Uf(e.r)}))}function Wf(e){return Mf(e)||e.lvl>e.r.lvl}function Gf(e){return Mf(e.r)?[e.k,e.v]:Gf(e.r)}function Kf(e,t,n,r=Af,i=Af){return{k:e,l:r,lvl:n,r:i,v:t}}function qf(e){return Yf(Jf(e))}function Jf(e){let{l:t}=e;return!Mf(t)&&t.lvl===e.lvl?Hf(t,{r:Hf(e,{l:t.r})}):e}function Yf(e){let{lvl:t,r:n}=e;return!Mf(n)&&!Mf(n.r)&&n.lvl===t&&n.r.lvl===t?Hf(n,{l:Hf(e,{r:n.l}),lvl:t+1}):e}function Xf(e){return jf(e,({k:e,v:t})=>({index:e,value:t}))}function Zf(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Qf(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}var $f=sf(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function ep(e,t,n){return e[tp(e,t,n)]}function tp(e,t,n,r=0){let i=e.length-1;for(;r<=i;){let a=Math.floor((r+i)/2),o=e[a],s=n(o,t);if(s===0)return a;if(s===-1){if(i-r<2)return a-1;i=a-1}else{if(i===r)return a;r=a+1}}throw Error(`Failed binary finding record in array - ${e.join(`,`)}, searched for ${t}`)}function np(e,t,n,r){let i=tp(e,t,r),a=tp(e,n,r,i);return e.slice(i,a+1)}function rp(e,t){return Math.round(e.getBoundingClientRect()[t])}function ip(e){return!Mf(e.groupOffsetTree)}function ap({index:e},t){return t===e?0:t<e?-1:1}function op(){return{groupIndices:[],groupOffsetTree:If(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:If()}}function sp(e,t){let n=Mf(e)?0:1/0;for(let r of t){let{endIndex:t,size:i,startIndex:a}=r;if(n=Math.min(n,a),Mf(e)){e=Ff(e,0,i);continue}let o=Lf(e,a-1,t+1);if(o.some(yp(r)))continue;let s=!1,c=!1;for(let{end:n,start:r,value:a}of o)s?(t>=r||i===a)&&(e=Rf(e,r)):(c=a!==i,s=!0),n>t&&t>=r&&a!==i&&(e=Ff(e,t+1,a));c&&(e=Ff(e,a,i))}return[e,n]}function cp(e){return typeof e.groupIndex<`u`}function lp({offset:e},t){return t===e?0:t<e?-1:1}function up(e,t,n){if(t.length===0)return 0;let{index:r,offset:i,size:a}=ep(t,e,ap),o=e-r,s=a*o+(o-1)*n+i;return s>0?s+n:s}function dp(e,t){if(!ip(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function fp(e,t,n){if(cp(e))return t.groupIndices[e.groupIndex]+1;let r=dp(e.index===`LAST`?n:e.index,t);return r=Math.max(0,r,Math.min(n,r)),r}function pp(e,t,n,r=0){return r>0&&(t=Math.max(t,ep(e,r,ap).offset)),jf(np(e,t,n,lp),vp)}function mp(e,[t,n,r,i]){t.length>0&&r(`received item sizes`,t,ff.DEBUG);let a=e.sizeTree,o=a,s=0;if(n.length>0&&Mf(a)&&t.length===2){let e=t[0].size,r=t[1].size;o=n.reduce((t,n)=>Ff(Ff(t,n,e),n+1,r),o)}else [o,s]=sp(o,t);if(o===a)return e;let{lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d}=_p(e.offsetTree,s,o,i);return{groupIndices:n,groupOffsetTree:n.reduce((e,t)=>Ff(e,t,up(t,d,i)),If()),lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d,sizeTree:o}}function hp(e){return zf(e).map(({k:e,v:t},n,r)=>{let i=r[n+1];return{endIndex:i===void 0?1/0:i.k-1,size:t,startIndex:e}})}function gp(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function _p(e,t,n,r){let i=e,a=0,o=0,s=0,c=0;if(t!==0){c=tp(i,t-1,ap),s=i[c].offset;let e=Pf(n,t-1);a=e[0],o=e[1],i.length&&i[c].size===Pf(n,t)[1]&&--c,i=i.slice(0,c+1)}else i=[];for(let{start:e,value:c}of Lf(n,t,1/0)){let t=e-a,n=t*o+s+t*r;i.push({index:e,offset:n,size:c}),a=e,s=n,o=c}return{lastIndex:a,lastOffset:s,lastSize:o,offsetTree:i}}function vp(e){return{index:e.index,value:e}}function yp(e){let{endIndex:t,size:n,startIndex:r}=e;return e=>e.start===r&&(e.end===t||e.end===1/0)&&e.value===n}var bp={offsetHeight:`height`,offsetWidth:`width`},xp=sf(([{log:e},{recalcInProgress:t}])=>{let n=af(),r=af(),i=rf(r,0),a=af(),o=af(),s=J(0),c=J([]),l=J(void 0),u=J(void 0),d=J(void 0),f=J(void 0),p=J((e,t)=>rp(e,bp[t])),m=J(void 0),h=J(0),g=op(),_=rf(q(n,ef(c,e,h),Zd(mp,g),Yd()),g),v=rf(q(c,Yd(),Zd((e,t)=>({current:t,prev:e.current}),{current:[],prev:[]}),K(({prev:e})=>e)),[]);W(q(c,G(e=>e.length>0),ef(_,h),K(([e,t,n])=>{let r=e.reduce((e,r,i)=>Ff(e,r,up(r,t.offsetTree,n)||i),If());return{...t,groupIndices:e,groupOffsetTree:r}})),_),W(q(r,ef(_),G(([e,{lastIndex:t}])=>e<t),K(([e,{lastIndex:t,lastSize:n}])=>[{endIndex:t,size:n,startIndex:e}])),n),W(l,u);let y=rf(q(l,K(e=>e===void 0)),!0);W(q(u,G(e=>e!==void 0&&Mf(Gd(_).sizeTree)),K(e=>{let t=Gd(d),n=Gd(c).length>0;return t!==void 0&&t!==0?n?[{endIndex:0,size:t,startIndex:0},{endIndex:1,size:e,startIndex:1}]:[]:[{endIndex:0,size:e,startIndex:0}]})),n),W(q(f,G(e=>e!==void 0&&e.length>0&&Mf(Gd(_).sizeTree)),K(e=>{let t=[],n=e[0],r=0;for(let i=1;i<e.length;i++){let a=e[i];a!==n&&(t.push({endIndex:i-1,size:n,startIndex:r}),n=a,r=i)}return t.push({endIndex:e.length-1,size:n,startIndex:r}),t})),n),W(q(c,ef(d,u),G(([,e,t])=>e!==void 0&&t!==void 0),K(([e,t,n])=>{let r=[];for(let i=0;i<e.length;i++){let a=e[i],o=e[i+1];r.push({startIndex:a,endIndex:a,size:t}),o!==void 0&&r.push({startIndex:a+1,endIndex:o-1,size:n})}return r})),n);let b=of(q(n,ef(_),Zd(({sizes:e},[t,n])=>({changed:n!==e,sizes:n}),{changed:!1,sizes:g}),K(e=>e.changed)));Hd(q(s,Zd((e,t)=>({diff:e.prev-t,prev:t}),{diff:0,prev:0}),K(e=>e.diff)),e=>{let{groupIndices:n}=Gd(_);if(e>0)Ud(t,!0),Ud(a,e+gp(e,n));else if(e<0){let t=Gd(v);t.length>0&&(e-=gp(-e,t)),Ud(o,e)}}),Hd(q(s,ef(e)),([e,t])=>{e<0&&t("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:s},ff.ERROR)});let x=of(a);W(q(a,ef(_),K(([e,t])=>{let n=t.groupIndices.length>0,r=[],i=t.lastSize;if(n){let n=Nf(t.sizeTree,0),a=0,o=0;for(;a<e;){let e=t.groupIndices[o],s=t.groupIndices.length===o+1?1/0:t.groupIndices[o+1]-e-1;r.push({endIndex:e,size:n,startIndex:e}),r.push({endIndex:e+1+s-1,size:i,startIndex:e+1}),o++,a+=s+1}let s=zf(t.sizeTree);return a!==e&&s.shift(),s.reduce((t,{k:n,v:r})=>{let i=t.ranges;return t.prevSize!==0&&(i=[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]),{prevIndex:n+e,prevSize:r,ranges:i}},{prevIndex:e,prevSize:0,ranges:r}).ranges}return zf(t.sizeTree).reduce((t,{k:n,v:r})=>({prevIndex:n+e,prevSize:r,ranges:[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]}),{prevIndex:0,prevSize:i,ranges:[]}).ranges})),n);let S=of(q(o,ef(_,h),K(([e,{offsetTree:t},n])=>up(-e,t,n))));return W(q(o,ef(_,h),K(([e,t,n])=>{if(t.groupIndices.length>0){if(Mf(t.sizeTree))return t;let r=If(),i=Gd(v),a=0,o=0,s=0;for(;a<-e;){s=i[o];let e=i[o+1]-s-1;o++,a+=e+1}if(r=zf(t.sizeTree).reduce((t,{k:n,v:r})=>Ff(t,Math.max(0,n+e),r),r),a!==-e){let n=Nf(t.sizeTree,s);r=Ff(r,0,n);let i=Pf(t.sizeTree,-e+1)[1];r=Ff(r,1,i)}return{...t,sizeTree:r,..._p(t.offsetTree,0,r,n)}}let r=zf(t.sizeTree).reduce((t,{k:n,v:r})=>Ff(t,Math.max(0,n+e),r),If());return{...t,sizeTree:r,..._p(t.offsetTree,0,r,n)}})),_),{beforeUnshiftWith:x,data:m,defaultItemSize:u,firstItemIndex:s,fixedItemSize:l,fixedGroupSize:d,gap:h,groupIndices:c,heightEstimates:f,itemSize:p,listRefresh:b,shiftWith:o,shiftWithOffset:S,sizeRanges:n,sizes:_,statefulTotalCount:i,totalCount:r,trackItemSizes:y,unshiftWith:a}},Vd(hf,$f),{singleton:!0});function Sp(e){return e.reduce((e,t)=>(e.groupIndices.push(e.totalCount),e.totalCount+=t+1,e),{groupIndices:[],totalCount:0})}var Cp=sf(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:i}])=>{let a=af(),o=af(),s=of(q(a,K(Sp)));return W(q(s,K(e=>e.totalCount)),n),W(q(s,K(e=>e.groupIndices)),e),W(q(uf(i,t,r),G(([e,t])=>ip(t)),K(([e,t,n])=>Pf(t.groupOffsetTree,Math.max(e-n,0),`v`)[0]),Yd(),K(e=>[e])),o),{groupCounts:a,topItemsIndexes:o}},Vd(xp,kf)),wp=sf(([{log:e}])=>{let t=J(!1),n=of(q(t,G(e=>e),Yd()));return Hd(t,t=>{t&&Gd(e)(`props updated`,{},ff.DEBUG)}),{didMount:n,propsReady:t}},Vd(hf),{singleton:!0}),Tp=typeof document<`u`&&`scrollBehavior`in document.documentElement.style;function Ep(e){let t=typeof e==`number`?{index:e}:e;return t.align||=`start`,(!t.behavior||!Tp)&&(t.behavior=`auto`),t.offset===void 0&&(t.offset=0),t}var Dp=sf(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:i,fixedHeaderHeight:a,footerHeight:o,headerHeight:s,scrollingInProgress:c,scrollTo:l,smoothScrollTargetReached:u,viewportHeight:d},{log:f}])=>{let p=af(),m=af(),h=J(0),g=null,_=null,v=null;function y(){g!==null&&(g(),g=null),v!==null&&(v(),v=null),_&&=(clearTimeout(_),null),Ud(c,!1)}return W(q(p,ef(n,d,r,h,s,o,f),ef(e,a,i),K(([[e,n,r,i,a,o,s,l],d,f,h])=>{let b=Ep(e),{align:x,behavior:S,offset:C}=b,w=i-1,T=fp(b,n,w),E=up(T,n.offsetTree,d)+o;x===`end`?(E+=f+Pf(n.sizeTree,T)[1]-r+h,T===w&&(E+=s)):x===`center`?E+=(f+Pf(n.sizeTree,T)[1]-r+h)/2:E-=a,C!==void 0&&C!==0&&(E+=C);let D=t=>{y(),t?(l(`retrying to scroll to`,{location:e},ff.DEBUG),Ud(p,e)):(Ud(m,!0),l(`list did not change, scroll successful`,{},ff.DEBUG))};if(y(),S===`smooth`){let e=!1;v=Hd(t,t=>{e||=t}),g=Kd(u,()=>{D(e)})}else g=Kd(q(t,Op(150)),D);return _=setTimeout(()=>{y()},1200),Ud(c,!0),l(`scrolling from index to`,{behavior:S,index:T,top:E},ff.DEBUG),{behavior:S,top:E}})),l),{scrollTargetReached:m,scrollToIndex:p,topListHeight:h}},Vd(xp,kf,hf),{singleton:!0});function Op(e){return t=>{let n=setTimeout(()=>{t(!1)},e);return e=>{e&&(t(!0),clearTimeout(n))}}}function kp(e,t){e===0?t():requestAnimationFrame(()=>{kp(e-1,t)})}function Ap(e,t){let n=t-1;return typeof e==`number`?e:e.index===`LAST`?n:e.index}var jp=sf(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:i,scrollToIndex:a},{didMount:o}])=>{let s=J(!0),c=J(0),l=J(!0);return W(q(o,ef(c),G(([e,t])=>t!==0),Xd(!1)),s),W(q(o,ef(c),G(([e,t])=>t!==0),Xd(!1)),l),Hd(q(uf(t,o),ef(s,n,e,l),G(([[,e],t,{sizeTree:n},r,i])=>e&&(!Mf(n)||Id(r))&&!t&&!i),ef(c)),([,e])=>{Kd(i,()=>{Ud(l,!0)}),kp(4,()=>{Kd(r,()=>{Ud(s,!0)}),Ud(a,e)})}),{initialItemFinalLocationReached:l,initialTopMostItemIndex:c,scrolledToInitialItem:s}},Vd(xp,kf,Dp,wp),{singleton:!0});function Mp(e,t){return Math.abs(e-t)<1.01}var Np=`up`,Pp=`down`,Fp=`none`,Ip={atBottom:!1,notAtBottomBecause:`NOT_SHOWING_LAST_ITEM`,state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Lp=0,Rp=sf(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:i,viewportHeight:a}])=>{let o=J(!1),s=J(!0),c=af(),l=af(),u=J(4),d=J(Lp),f=rf(q(df(q(Y(i),Qd(1),Xd(!0)),q(Y(i),Qd(1),Xd(!1),qd(100))),Yd()),!1),p=rf(q(df(q(n,Xd(!0)),q(n,Xd(!1),qd(200))),Yd()),!1);W(q(uf(Y(i),Y(d)),K(([e,t])=>e<=t),Yd()),s),W(q(s,$d(50)),l);let m=of(q(uf(r,Y(a),Y(t),Y(e),Y(u)),Zd((e,[{scrollHeight:t,scrollTop:n},r,i,a,o])=>{let s=n+r-t>-o,c={scrollHeight:t,scrollTop:n,viewportHeight:r};if(s){let t,r;return n>e.state.scrollTop?(t=`SCROLLED_DOWN`,r=e.state.scrollTop-n):(t=`SIZE_DECREASED`,r=e.state.scrollTop-n||e.scrollTopDelta),{atBottom:!0,atBottomBecause:t,scrollTopDelta:r,state:c}}let l;return l=c.scrollHeight>e.state.scrollHeight?`SIZE_INCREASED`:r<e.state.viewportHeight?`VIEWPORT_HEIGHT_DECREASING`:n<e.state.scrollTop?`SCROLLING_UPWARDS`:`NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM`,{atBottom:!1,notAtBottomBecause:l,state:c}},Ip),Yd((e,t)=>e!==void 0&&e.atBottom===t.atBottom))),h=rf(q(r,Zd((e,{scrollHeight:t,scrollTop:n,viewportHeight:r})=>{if(!Mp(e.scrollHeight,t)){let i=t-(n+r)<1;return e.scrollTop!==n&&i?{changed:!0,jump:e.scrollTop-n,scrollHeight:t,scrollTop:n}:{changed:!0,jump:0,scrollHeight:t,scrollTop:n}}return{changed:!1,jump:0,scrollHeight:t,scrollTop:n}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),G(e=>e.changed),K(e=>e.jump)),0);W(q(m,K(e=>e.atBottom)),o),W(q(o,$d(50)),c);let g=J(Pp);W(q(r,K(({scrollTop:e})=>e),Yd(),Zd((e,t)=>Gd(p)?{direction:e.direction,prevScrollTop:t}:{direction:t<e.prevScrollTop?Np:Pp,prevScrollTop:t},{direction:Pp,prevScrollTop:0}),K(e=>e.direction)),g),W(q(r,$d(50),Xd(Fp)),g);let _=J(0);return W(q(f,G(e=>!e),Xd(0)),_),W(q(i,$d(100),ef(f),G(([e,t])=>t),Zd(([e,t],[n])=>[t,n],[0,0]),K(([e,t])=>t-e)),_),{atBottomState:m,atBottomStateChange:c,atBottomThreshold:u,atTopStateChange:l,atTopThreshold:d,isAtBottom:o,isAtTop:s,isScrolling:f,lastJumpDueToItemResize:h,scrollDirection:g,scrollVelocity:_}},Vd(kf)),zp=`top`,Bp=`bottom`,Vp=`none`;function Hp(e,t,n){return typeof e==`number`?n===Np&&t===zp||n===Pp&&t===Bp?e:0:n===Np?t===zp?e.main:e.reverse:t===Bp?e.main:e.reverse}function Up(e,t){return typeof e==`number`?e:e[t]??0}var Wp=sf(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:i}])=>{let a=af(),o=J(0),s=J(0),c=J(0);return{increaseViewportBy:s,listBoundary:a,overscan:c,topListHeight:o,visibleRange:rf(q(uf(Y(r),Y(i),Y(n),Y(a,Qf),Y(c),Y(o),Y(t),Y(e),Y(s)),K(([e,t,n,[r,i],a,o,s,c,l])=>{let u=e-c,d=o+s,f=Math.max(n-u,0),p=Vp,m=Up(l,zp),h=Up(l,Bp);return r-=c,r+=n+s,i+=n+s,i-=c,r>e+d-m&&(p=Np),i<e-f+t+h&&(p=Pp),p===Vp?null:[Math.max(u-n-Hp(a,zp,p)-m,0),u-f-s+t+Hp(a,Bp,p)+h]}),G(e=>e!==null),Yd(Qf)),[0,0])}},Vd(kf),{singleton:!0});function Gp(e,t,n){if(ip(t)){let r=dp(e,t);return[{index:Pf(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n?.[0],index:r,offset:0,size:0}]}return[{data:n?.[0],index:e,offset:0,size:0}]}var Kp={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function qp(e,t,n,r,i,a){let{lastIndex:o,lastOffset:s,lastSize:c}=i,l=0,u=0;if(e.length>0){l=e[0].offset;let t=e[e.length-1];u=t.offset+t.size}let d=n-o,f=s+d*c+(d-1)*r,p=l,m=f-u;return{bottom:u,firstItemIndex:a,items:Yp(e,i,a),offsetBottom:m,offsetTop:l,top:p,topItems:Yp(t,i,a),topListHeight:t.reduce((e,t)=>t.size+e,0),totalCount:n}}function Jp(e,t,n,r,i,a){let o=0;if(n.groupIndices.length>0)for(let t of n.groupIndices){if(t-o>=e)break;o++}let s=e+o,c=Ap(t,s);return qp(Array.from({length:s}).map((e,t)=>({data:a[t+c],index:t+c,offset:0,size:0})),[],s,i,n,r)}function Yp(e,t,n){if(e.length===0)return[];if(!ip(t))return e.map(e=>({...e,index:e.index+n,originalIndex:e.index}));let r=e[0].index,i=e[e.length-1].index,a=[],o=Lf(t.groupOffsetTree,r,i),s,c=0;for(let r of e){(!s||s.end<r.index)&&(s=o.shift(),c=t.groupIndices.indexOf(s.start));let e;e=r.index===s.start?{index:c,type:`group`}:{groupIndex:c,index:r.index-(c+1)+n},a.push({...e,data:r.data,offset:r.offset,originalIndex:r.index,size:r.size})}return a}function Xp(e,t){return e===void 0?0:typeof e==`number`?e:e[t]??0}var Zp=sf(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:i},a,{listBoundary:o,topListHeight:s,visibleRange:c},{initialTopMostItemIndex:l,scrolledToInitialItem:u},{topListHeight:d},f,{didMount:p},{recalcInProgress:m}])=>{let h=J([]),g=J(0),_=af(),v=J(0);W(a.topItemsIndexes,h);let y=rf(q(uf(p,m,Y(c,Qf),Y(i),Y(r),Y(l),u,Y(h),Y(t),Y(n),Y(v),e),G(([e,t,,n,,,,,,,,r])=>{let i=r!==void 0&&r.length!==n;return e&&!t&&!i}),K(([,,[e,t],n,r,i,a,o,s,c,l,u])=>{let d=r,{offsetTree:f,sizeTree:p}=d,m=Gd(g);if(n===0)return{...Kp,totalCount:n};if(e===0&&t===0)return m===0?{...Kp,totalCount:n}:Jp(m,i,r,s,c,u||[]);if(Mf(p))return m>0?null:qp(Gp(Ap(i,n),d,u),[],n,c,d,s);let h=[];if(o.length>0){let e=o[0],t=o[o.length-1],n=0;for(let r of Lf(p,e,t)){let i=r.value,a=Math.max(r.start,e),o=Math.min(r.end,t);for(let e=a;e<=o;e++)h.push({data:u?.[e],index:e,offset:n,size:i}),n+=i}}if(!a)return qp([],h,n,c,d,s);let _=o.length>0?o[o.length-1]+1:0,v=pp(f,e,t,_);if(v.length===0)return null;let y=n-1,b=zd([],n=>{for(let r of v){let i=r.value,a=i.offset,o=r.start,s=i.size;if(i.offset<e){o+=Math.floor((e-i.offset+c)/(s+c));let t=o-r.start;a+=t*s+t*c}o<_&&(a+=(_-o)*s,o=_);let l=Math.min(r.end,y);for(let e=o;e<=l&&!(a>=t);e++)n.push({data:u?.[e],index:e,offset:a,size:s}),a+=s+c}}),x=Xp(l,zp),S=Xp(l,Bp);if(b.length>0&&(x>0||S>0)){let e=b[0],t=b[b.length-1];if(x>0&&e.index>_){let t=Math.min(x,e.index-_),n=[],r=e.offset;for(let i=e.index-1;i>=e.index-t;i--){let t=Lf(p,i,i)[0]?.value??e.size;r-=t+c,n.unshift({data:u?.[i],index:i,offset:r,size:t})}b.unshift(...n)}if(S>0&&t.index<y){let e=Math.min(S,y-t.index),n=t.offset+t.size+c;for(let r=t.index+1;r<=t.index+e;r++){let e=Lf(p,r,r)[0]?.value??t.size;b.push({data:u?.[r],index:r,offset:n,size:e}),n+=e+c}}}return qp(b,h,n,c,d,s)}),G(e=>e!==null),Yd()),Kp);W(q(e,G(Id),K(e=>e?.length)),i),W(q(y,K(e=>e.topListHeight)),d),W(d,s),W(q(y,K(e=>[e.top,e.bottom])),o),W(q(y,K(e=>e.items)),_);let b=of(q(y,G(({items:e})=>e.length>0),ef(i,e),G(([{items:e},t])=>e[e.length-1].originalIndex===t-1),K(([,e,t])=>[e-1,t]),Yd(Qf),K(([e])=>e))),x=of(q(y,$d(200),G(({items:e,topItems:t})=>e.length>0&&e[0].originalIndex===t.length),K(({items:e})=>e[0].index),Yd()));return{endReached:b,initialItemCount:g,itemsRendered:_,listState:y,minOverscanItemCount:v,rangeChanged:of(q(y,G(({items:e})=>e.length>0),K(({items:e})=>{let t=0,n=e.length-1;for(;e[t].type===`group`&&t<n;)t++;for(;e[n].type===`group`&&n>t;)n--;return{endIndex:e[n].index,startIndex:e[t].index}}),Yd(Zf))),startReached:x,topItemsIndexes:h,...f}},Vd(xp,Cp,Wp,jp,Dp,Rp,wp,$f),{singleton:!0}),Qp=sf(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:i}])=>{let a=af(),o=rf(q(uf(n,e,r,t,i),K(([e,t,n,r,i])=>e+t+n+r+i.offsetBottom+i.bottom)),0);return W(Y(o),a),{totalListHeight:o,totalListHeightChanged:a}},Vd(kf,Zp),{singleton:!0}),$p=sf(([{viewportHeight:e},{totalListHeight:t}])=>{let n=J(!1);return{alignToBottom:n,paddingTopAddition:rf(q(uf(n,e,t),G(([e])=>e),K(([,e,t])=>Math.max(0,e-t)),$d(0),Yd()),0)}},Vd(kf,Qp),{singleton:!0}),em=sf(()=>({context:J(null)})),tm=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...i},viewportBottom:a,viewportTop:o})=>t<o?{...i,align:n??`start`,...r===void 0?{}:{behavior:r}}:e>a?{...i,align:n??`end`,...r===void 0?{}:{behavior:r}}:null,nm=sf(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:i,headerHeight:a,scrollingInProgress:o,scrollTop:s,viewportHeight:c},{scrollToIndex:l}])=>{let u=af();return W(q(u,ef(t,c,n,a,i,r,s),ef(e),K(([[e,t,n,r,i,a,s,c],l])=>{let{calculateViewLocation:u=tm,done:d,...f}=e,p=fp(e,t,r-1),m=up(p,t.offsetTree,l)+i+a,h=m+Pf(t.sizeTree,p)[1],g=c+a,_=u({itemBottom:h,itemTop:m,locationParams:f,viewportBottom:c+n-s,viewportTop:g});return _===null?d?.():d&&Kd(q(o,G(e=>!e),Qd(Gd(o)?1:2)),d),_}),G(e=>e!==null)),l),{scrollIntoView:u}},Vd(xp,kf,Dp,Zp,hf),{singleton:!0});function rm(e){return e===!1?!1:e===`smooth`?`smooth`:`auto`}var im=(e,t)=>typeof e==`function`?rm(e(t)):t&&rm(e),am=sf(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:i,isAtBottom:a},{scrollToIndex:o},{scrolledToInitialItem:s},{didMount:c,propsReady:l},{log:u},{scrollingInProgress:d},{context:f},{scrollIntoView:p}])=>{let m=J(!1),h=af(),g=null;function _(e){Ud(o,{align:`end`,behavior:e,index:`LAST`})}Hd(q(uf(q(Y(t),Qd(1)),c),ef(Y(m),a,s,d),K(([[e,t],n,r,i,a])=>{let o=t&&i,s=`auto`;return o&&(s=im(n,r||a),o&&=s!==!1),{followOutputBehavior:s,shouldFollow:o,totalCount:e}}),G(({shouldFollow:e})=>e)),({followOutputBehavior:t,totalCount:r})=>{g!==null&&(g(),g=null),Gd(n)===void 0?g=Kd(e,()=>{Gd(u)(`following output to `,{totalCount:r},ff.DEBUG),_(t),g=null}):requestAnimationFrame(()=>{Gd(u)(`following output to `,{totalCount:r},ff.DEBUG),_(t)})});function v(e){let t=Kd(i,t=>{e&&!t.atBottom&&t.notAtBottomBecause===`SIZE_INCREASED`&&g===null&&(Gd(u)(`scrolling to bottom due to increased size`,{},ff.DEBUG),_(`auto`))});setTimeout(t,100)}Hd(q(uf(Y(m),t,l),G(([e,,t])=>e!==!1&&t),Zd(({value:e},[,t])=>({refreshed:e===t,value:t}),{refreshed:!1,value:0}),G(({refreshed:e})=>e),ef(m,t)),([,e])=>{Gd(s)&&v(e!==!1)}),Hd(h,()=>{v(Gd(m)!==!1)}),Hd(uf(Y(m),i),([e,t])=>{e!==!1&&!t.atBottom&&t.notAtBottomBecause===`VIEWPORT_HEIGHT_DECREASING`&&_(`auto`)});let y=J(null),b=af();return W(df(q(Y(r),K(e=>e?.length??0)),q(Y(t))),b),Hd(q(uf(q(b,Qd(1)),c),ef(Y(y),s,d,f),K(([[e,t],n,r,i,a])=>t&&r&&n?.({context:a,totalCount:e,scrollingInProgress:i})),G(e=>!!e),$d(0)),t=>{g!==null&&(g(),g=null),Gd(n)===void 0?g=Kd(e,()=>{Gd(u)(`scrolling into view`,{}),Ud(p,t),g=null}):requestAnimationFrame(()=>{Gd(u)(`scrolling into view`,{}),Ud(p,t)})}),{autoscrollToBottom:h,followOutput:m,scrollIntoViewOnChange:y}},Vd(xp,Rp,Dp,jp,wp,hf,kf,em,nm)),om=sf(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:i},{initialItemCount:a,listState:o},{didMount:s}])=>(W(q(s,ef(a),G(([,e])=>e!==0),ef(i,r,t,n,e),K(([[,e],t,n,r,i,a=[]])=>Jp(e,t,n,r,i,a))),o),{}),Vd(xp,jp,Zp,wp),{singleton:!0}),sm=sf(([{didMount:e},{scrollTo:t},{listState:n}])=>{let r=J(0);return Hd(q(e,ef(r),G(([,e])=>e!==0),K(([,e])=>({top:e}))),e=>{Kd(q(n,Qd(1),G(e=>e.items.length>1)),()=>{requestAnimationFrame(()=>{Ud(t,e)})})}),{initialScrollTop:r}},Vd(wp,kf,Zp),{singleton:!0}),cm=sf(([{scrollVelocity:e}])=>{let t=J(!1),n=af(),r=J(!1);return W(q(e,ef(r,t,n),G(([e,t])=>t!==!1&&t!==void 0),K(([e,t,n,r])=>{let{enter:i,exit:a}=t;if(n){if(a(e,r))return!1}else if(i(e,r))return!0;return n}),Yd()),t),Hd(q(uf(t,e,n),ef(r)),([[e,t,n],r])=>{e&&r!==!1&&r!==void 0&&r.change&&r.change(t,n)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Vd(Rp),{singleton:!0}),lm=sf(([{scrollContainerState:e,scrollTo:t}])=>{let n=af(),r=af(),i=af(),a=J(!1),o=J(void 0);return W(q(uf(n,r),K(([{scrollTop:e,viewportHeight:t},{offsetTop:n,listHeight:r}])=>({scrollHeight:r,scrollTop:Math.max(0,e-n),viewportHeight:t}))),e),W(q(t,ef(r),K(([e,{offsetTop:t}])=>({...e,top:e.top+t}))),i),{customScrollParent:o,useWindowScroll:a,windowScrollContainerState:n,windowScrollTo:i,windowViewportRect:r}},Vd(kf)),um=sf(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:i},{didMount:a},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:c}])=>{let l=af(),u=J(void 0),d=J(null),f=J(null);return W(s,d),W(c,f),Hd(q(l,ef(t,r,o,d,f,n)),([e,t,n,r,i,a,o])=>{let s=hp(t.sizeTree);r&&i!==null&&a!==null&&(n=i.scrollTop-a.offsetTop),n-=o,e({ranges:s,scrollTop:n})}),W(q(u,G(Id),K(dm)),i),W(q(a,ef(u),G(([,e])=>e!==void 0),Yd(),K(([,e])=>e.ranges)),e),{getState:l,restoreStateFrom:u}},Vd(xp,kf,jp,wp,lm));function dm(e){return{align:`start`,index:0,offset:e.scrollTop}}var fm=sf(([{topItemsIndexes:e}])=>{let t=J(0);return W(q(t,G(e=>e>=0),K(e=>Array.from({length:e}).map((e,t)=>t))),e),{topItemCount:t}},Vd(Zp));function pm(e){let t=!1,n;return(()=>(t||(t=!0,n=e()),n))}var mm=pm(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),hm=sf(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,fixedGroupSize:i,gap:a,groupIndices:o,heightEstimates:s,itemSize:c,sizeRanges:l,sizes:u,statefulTotalCount:d,totalCount:f,trackItemSizes:p},{initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g},_,v,y,b,{scrollToIndex:x},S,{topItemCount:C},{groupCounts:w},T])=>{let{listState:E,minOverscanItemCount:D,topItemsIndexes:O,rangeChanged:k,...A}=b;return W(k,T.scrollSeekRangeChanged),W(q(T.windowViewportRect,K(e=>e.visibleHeight)),_.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,fixedGroupHeight:i,gap:a,groupCounts:w,heightEstimates:s,initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g,sizeRanges:l,topItemCount:C,topItemsIndexes:O,totalCount:f,...y,groupIndices:o,itemSize:c,listState:E,minOverscanItemCount:D,scrollToIndex:x,statefulTotalCount:d,trackItemSizes:p,rangeChanged:k,...A,...T,..._,sizes:u,...v}},Vd(xp,jp,kf,um,am,Zp,Dp,sf(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:i,isScrolling:a,lastJumpDueToItemResize:o,scrollDirection:s},{listState:c},{beforeUnshiftWith:l,gap:u,shiftWithOffset:d,sizes:f},{log:p},{recalcInProgress:m}])=>{let h=of(q(c,ef(o),Zd(([,e,t,n],[{bottom:r,items:i,offsetBottom:a,totalCount:o},s])=>{let c=r+a,l=0;return t===o&&e.length>0&&i.length>0&&(i[0].originalIndex===0&&e[0].originalIndex===0||(l=c-n,l!==0&&(l+=s))),[l,i,o,c]},[0,[],0,0]),G(([e])=>e!==0),ef(r,s,n,i,p,m),G(([,e,t,n,,,r])=>!r&&!n&&e!==0&&t===Np),K(([[e],,,,,t])=>(t(`Upward scrolling compensation`,{amount:e},ff.DEBUG),e))));function g(n){n>0?(Ud(t,{behavior:`auto`,top:-n}),Ud(e,0)):(Ud(e,0),Ud(t,{behavior:`auto`,top:-n}))}return Hd(q(h,ef(e,a)),([t,n,r])=>{r&&mm()?Ud(e,n-t):g(-t)}),Hd(q(uf(rf(a,!1),e,m),G(([e,t,n])=>!e&&!n&&t!==0),K(([e,t])=>t),$d(1)),g),W(q(d,K(e=>({top:-e}))),t),Hd(q(l,ef(f,u),K(([e,{groupIndices:t,lastSize:n,sizeTree:r},i])=>{function a(e){return e*(n+i)}if(t.length===0)return a(e);let o=0,s=Nf(r,0),c=0,l=0;for(;c<e;){c++,o+=s;let n=t.length===l+1?1/0:t[l+1]-t[l]-1;c+n>e&&(o-=s,n=e-c+1),c+=n,o+=a(n),l++}return o})),n=>{Ud(e,n),requestAnimationFrame(()=>{Ud(t,{top:n}),requestAnimationFrame(()=>{Ud(e,0),Ud(m,!1)})})}),{deviation:e}},Vd(kf,Rp,Zp,xp,hf,$f)),fm,Cp,sf(([e,t,n,r,i,a,o,s,c,l,u])=>({...e,...t,...n,...r,...i,...a,...o,...s,...c,...l,...u}),Vd(Wp,om,wp,cm,Qp,sm,$p,lm,nm,hf,em))));function gm(e,t){let n={},r={},i=0,a=e.length;for(;i<a;)r[e[i]]=1,i+=1;for(let e in t)Object.hasOwn(r,e)||(n[e]=t[e]);return n}var _m=typeof document<`u`?_.useLayoutEffect:_.useEffect;function vm(e,t,n){let r=Object.keys(t.required||{}),i=Object.keys(t.optional||{}),a=Object.keys(t.methods||{}),o=Object.keys(t.events||{}),s=_.createContext({});function c(e,n){e.propsReady!==void 0&&Ud(e.propsReady,!1);for(let i of r){let r=e[t.required[i]];Ud(r,n[i])}for(let r of i)if(r in n){let i=e[t.optional[r]];Ud(i,n[r])}e.propsReady!==void 0&&Ud(e.propsReady,!0)}function l(e){return a.reduce((n,r)=>(n[r]=n=>{let i=e[t.methods[r]];Ud(i,n)},n),{})}function u(e){return o.reduce((n,r)=>(n[r]=nf(e[t.events[r]]),n),{})}return{Component:_.forwardRef(function(t,a){let{children:d,...f}=t,[p]=_.useState(()=>zd(lf(e),e=>{c(e,f)})),[m]=_.useState(Pd(u,p));_m(()=>{for(let e of o)e in f&&Hd(m[e],f[e]);return()=>{Object.values(m).map(Wd)}},[f,m,p]),_m(()=>{c(p,f)}),_.useImperativeHandle(a,jd(l(p)));let h=n;return(0,B.jsx)(s.Provider,{value:p,children:n===void 0?d:(0,B.jsx)(h,{...gm([...r,...i,...o],f),children:d})})}),useEmitter:(e,t)=>{let n=_.useContext(s)[e];_m(()=>Hd(n,t),[t,n])},useEmitterValue:e=>{let t=_.useContext(s)[e],n=_.useCallback(e=>Hd(t,e),[t]);return _.useSyncExternalStore(n,()=>Gd(t),()=>Gd(t))},usePublisher:e=>{let t=_.useContext(s);return _.useCallback(n=>{Ud(t[e],n)},[t,e])}}}var ym=_.createContext(void 0),bm=_.createContext(void 0),xm=`-webkit-sticky`,Sm=`sticky`,Cm=pm(()=>{if(typeof document>`u`)return Sm;let e=document.createElement(`div`);return e.style.position=xm,e.style.position===xm?xm:Sm}),wm=typeof document<`u`?_.useLayoutEffect:_.useEffect;function Tm(e){return`self`in e}function Em(e){return`body`in e}function Dm(e,t,n,r=Rd,i,a){let o=_.useRef(null),s=_.useRef(null),c=_.useRef(null),l=_.useCallback(n=>{let r,i,o,l=n.target;if(Em(l)||Tm(l)){let e=Tm(l)?l:l.defaultView;o=a===!0?xf(e,e.scrollX):e.scrollY,r=a===!0?e.document.documentElement.scrollWidth:e.document.documentElement.scrollHeight,i=a===!0?e.innerWidth:e.innerHeight}else o=a===!0?xf(l,l.scrollLeft):l.scrollTop,r=a===!0?l.scrollWidth:l.scrollHeight,i=a===!0?l.offsetWidth:l.offsetHeight;let u=()=>{e({scrollHeight:r,scrollTop:Math.max(o,0),viewportHeight:i})};n.suppressFlushSync===!0?u():li.flushSync(u),s.current!==null&&(o===s.current||o<=0||o===r-i)&&(s.current=null,t(!0),c.current&&=(clearTimeout(c.current),null))},[e,t,a]);_.useEffect(()=>{let e=i||o.current;return yf(e),r(i||o.current),l({suppressFlushSync:!0,target:e}),e.addEventListener(`scroll`,l,{passive:!0}),()=>{yf(e),r(null),e.removeEventListener(`scroll`,l)}},[o,l,n,r,i]);function u(n){let r=o.current;if(!r||(a===!0?`offsetWidth`in r&&r.offsetWidth===0:`offsetHeight`in r&&r.offsetHeight===0))return;let i=n.behavior===`smooth`,l,u,d;Tm(r)?(u=Math.max(rp(r.document.documentElement,a===!0?`width`:`height`),a===!0?r.document.documentElement.scrollWidth:r.document.documentElement.scrollHeight),l=a===!0?r.innerWidth:r.innerHeight,d=a===!0?xf(r,r.scrollX):r.scrollY):(u=r[a===!0?`scrollWidth`:`scrollHeight`],l=rp(r,a===!0?`width`:`height`),d=a===!0?xf(r,r.scrollLeft):r.scrollTop);let f=u-l;if(n.top===void 0){r.scrollTo(n);return}let p=Math.ceil(Math.max(Math.min(f,n.top),0));if(n.top=p,Mp(l,u)||p===d){e({scrollHeight:u,scrollTop:d,viewportHeight:l}),i&&t(!0);return}i?(s.current=p,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,s.current=null,t(!0)},1e3)):s.current=null,a===!0&&(n={...n.behavior===void 0?{}:{behavior:n.behavior},left:Sf(r,p)}),r.scrollTo(n)}function d(e){a===!0&&(e={...e.behavior===void 0?{}:{behavior:e.behavior},...e.top===void 0?{}:{left:Sf(o.current,e.top)}}),o.current.scrollBy(e)}return{scrollByCallback:d,scrollerRef:o,scrollToCallback:u}}function Om(e){return e}var km=sf(([e,t])=>({...e,...t}),Vd(hm,sf(()=>{let e=J(e=>`Item ${e}`),t=J(e=>`Group ${e}`),n=J({}),r=J(Om),i=J(`div`),a=J(Rd),o=(e,t=null)=>rf(q(n,K(t=>t[e]),Yd()),t);return{components:n,computeItemKey:r,EmptyPlaceholder:o(`EmptyPlaceholder`),FooterComponent:o(`Footer`),GroupComponent:o(`Group`,`div`),groupContent:t,HeaderComponent:o(`Header`),HeaderFooterTag:i,ItemComponent:o(`Item`,`div`),itemContent:e,ListComponent:o(`List`,`div`),ScrollerComponent:o(`Scroller`,`div`),scrollerRef:a,ScrollSeekPlaceholder:o(`ScrollSeekPlaceholder`),TopItemListComponent:o(`TopItemList`)}}))),Am=({height:e})=>(0,B.jsx)(`div`,{style:{height:e}}),jm={overflowAnchor:`none`,position:Cm(),zIndex:1},Mm={overflowAnchor:`none`},Nm={...Mm,display:`inline-block`,height:`100%`},Pm=_.memo(function({showTopList:e=!1}){let t=X(`listState`),n=Zm(`sizeRanges`),r=X(`useWindowScroll`),i=X(`customScrollParent`),a=Zm(`windowScrollContainerState`),o=Zm(`scrollContainerState`),s=i||r?a:o,c=X(`itemContent`),l=X(`context`),u=X(`groupContent`),d=X(`trackItemSizes`),f=X(`itemSize`),p=X(`log`),m=Zm(`gap`),h=X(`horizontalDirection`),{callbackRef:g}=Tf(n,f,d,e?Rd:s,p,m,i,h,X(`skipAnimationFrameInResizeObserver`)),[v,y]=_.useState(0);Xm(`deviation`,e=>{v!==e&&y(e)});let b=X(`EmptyPlaceholder`),x=X(`ScrollSeekPlaceholder`)??Am,S=X(`ListComponent`),C=X(`ItemComponent`),w=X(`GroupComponent`),T=X(`computeItemKey`),E=X(`isSeeking`),D=X(`groupIndices`).length>0,O=X(`alignToBottom`),k=X(`initialItemFinalLocationReached`),A=e?{}:{boxSizing:`border-box`,...h?{display:`inline-block`,height:`100%`,marginInlineStart:v===0?O?`auto`:0:v,paddingInlineEnd:t.offsetBottom,paddingInlineStart:t.offsetTop,whiteSpace:`nowrap`}:{marginTop:v===0?O?`auto`:0:v,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...k?{}:{visibility:`hidden`}};return!e&&t.totalCount===0&&b!=null?(0,B.jsx)(b,{...Bm(b,l)}):(0,B.jsx)(S,{...Bm(S,l),"data-testid":e?`virtuoso-top-item-list`:`virtuoso-item-list`,ref:g,style:A,children:(e?t.topItems:t.items).map(e=>{let n=e.originalIndex,r=T(n+t.firstItemIndex,e.data,l);return E?(0,_.createElement)(x,{...Bm(x,l),height:e.size,index:e.index,key:r,type:e.type||`item`,...e.type===`group`?{}:{groupIndex:e.groupIndex}}):e.type===`group`?(0,_.createElement)(w,{...Bm(w,l),"data-index":n,"data-item-index":e.index,"data-known-size":e.size,key:r,style:jm},u(e.index,l)):(0,_.createElement)(C,{...Bm(C,l),...Vm(C,e.data),"data-index":n,"data-item-group-index":e.groupIndex,"data-item-index":e.index,"data-known-size":e.size,key:r,style:h?Nm:Mm},D?c(e.index,e.groupIndex,e.data,l):c(e.index,e.data,l))})})}),Fm={height:`100%`,outline:`none`,overflowY:`auto`,position:`relative`,WebkitOverflowScrolling:`touch`},Im={outline:`none`,overflowX:`auto`,position:`relative`},Lm=e=>({height:`100%`,position:`absolute`,top:0,width:`100%`,...e?{display:`flex`,flexDirection:`column`}:void 0}),Rm=(e,t,n=0)=>({...Lm(e),position:t?`relative`:`absolute`,top:t?-n:0}),zm={position:Cm(),top:0,width:`100%`,zIndex:1};function Bm(e,t){if(typeof e!=`string`)return{context:t}}function Vm(e,t){return{item:typeof e==`string`?void 0:t}}var Hm=_.memo(function(){let e=X(`HeaderComponent`),t=Zm(`headerHeight`),n=X(`HeaderFooterTag`),r=Cf(_.useMemo(()=>e=>{t(rp(e,`height`))},[t]),!0,X(`skipAnimationFrameInResizeObserver`)),i=X(`context`);return e==null?null:(0,B.jsx)(n,{ref:r,children:(0,B.jsx)(e,{...Bm(e,i)})})}),Um=_.memo(function(){let e=X(`FooterComponent`),t=Zm(`footerHeight`),n=X(`HeaderFooterTag`),r=Cf(_.useMemo(()=>e=>{t(rp(e,`height`))},[t]),!0,X(`skipAnimationFrameInResizeObserver`)),i=X(`context`);return e==null?null:(0,B.jsx)(n,{ref:r,children:(0,B.jsx)(e,{...Bm(e,i)})})});function Wm({useEmitter:e,useEmitterValue:t,usePublisher:n}){return _.memo(function({children:r,style:i,context:a,...o}){let s=n(`scrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`scrollerRef`),d=t(`horizontalDirection`)||!1,{scrollByCallback:f,scrollerRef:p,scrollToCallback:m}=Dm(s,l,c,u,void 0,d);return e(`scrollTo`,m),e(`scrollBy`,f),(0,B.jsx)(c,{"data-testid":`virtuoso-scroller`,"data-virtuoso-scroller":!0,ref:p,style:{...d?Im:Fm,...i},tabIndex:0,...o,...Bm(c,a),children:r})})}function Gm({useEmitter:e,useEmitterValue:t,usePublisher:n}){return _.memo(function({children:r,style:i,context:a,...o}){let s=n(`windowScrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`totalListHeight`),d=t(`deviation`),f=t(`customScrollParent`),p=_.useRef(null),{scrollByCallback:m,scrollerRef:h,scrollToCallback:g}=Dm(s,l,c,t(`scrollerRef`),f);return wm(()=>(h.current=f||p.current?.ownerDocument.defaultView,()=>{h.current=null}),[h,f]),e(`windowScrollTo`,g),e(`scrollBy`,m),(0,B.jsx)(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:`relative`,...i,...u===0?void 0:{height:u+d}},...o,...Bm(c,a),children:r})})}var Km=({children:e})=>{let t=_.useContext(ym),n=Zm(`viewportHeight`),r=Zm(`fixedItemHeight`),i=X(`alignToBottom`),a=X(`horizontalDirection`),o=Cf(_.useMemo(()=>Nd(n,e=>rp(e,a?`width`:`height`)),[n,a]),!0,X(`skipAnimationFrameInResizeObserver`));return _.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,B.jsx)(`div`,{"data-viewport-type":`element`,ref:o,style:Lm(i),children:e})},qm=({children:e})=>{let t=_.useContext(ym),n=Zm(`windowViewportRect`),r=Zm(`fixedItemHeight`),i=X(`customScrollParent`),a=X(`useWindowScroll`),o=X(`topListHeight`),s=Of(n,i,X(`skipAnimationFrameInResizeObserver`)),c=X(`alignToBottom`);return _.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,B.jsx)(`div`,{"data-viewport-type":`window`,ref:s,style:Rm(c,a,o),children:e})},Jm=({children:e})=>{let t=X(`TopItemListComponent`)??`div`,n=X(`headerHeight`);return(0,B.jsx)(t,{style:{...zm,marginTop:`${n}px`},...Bm(t,X(`context`)),children:e})},{Component:Ym,useEmitter:Xm,useEmitterValue:X,usePublisher:Zm}=vm(km,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,scrollIntoViewOnChange:`scrollIntoViewOnChange`,itemContent:`itemContent`,groupContent:`groupContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,groupCounts:`groupCounts`,topItemCount:`topItemCount`,firstItemIndex:`firstItemIndex`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,heightEstimates:`heightEstimates`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`HeaderFooterTag`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,horizontalDirection:`horizontalDirection`,skipAnimationFrameInResizeObserver:`skipAnimationFrameInResizeObserver`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,autoscrollToBottom:`autoscrollToBottom`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},_.memo(function(e){let t=X(`useWindowScroll`),n=X(`topItemsIndexes`).length>0,r=X(`customScrollParent`),i=X(`context`);return(0,B.jsxs)(r||t?$m:Qm,{...e,context:i,children:[n&&(0,B.jsx)(Jm,{children:(0,B.jsx)(Pm,{showTopList:!0})}),(0,B.jsxs)(r||t?qm:Km,{children:[(0,B.jsx)(Hm,{}),(0,B.jsx)(Pm,{}),(0,B.jsx)(Um,{})]})]})})),Qm=Wm({useEmitter:Xm,useEmitterValue:X,usePublisher:Zm}),$m=Gm({useEmitter:Xm,useEmitterValue:X,usePublisher:Zm}),eh=Ym,th=sf(([e,t])=>({...e,...t}),Vd(hm,sf(()=>{let e=J(e=>(0,B.jsxs)(`td`,{children:[`Item $`,e]})),t=J(null),n=J(e=>(0,B.jsxs)(`td`,{colSpan:1e3,children:[`Group `,e]})),r=J(null),i=J(null),a=J({}),o=J(Om),s=J(Rd),c=(e,t=null)=>rf(q(a,K(t=>t[e]),Yd()),t);return{components:a,computeItemKey:o,context:t,EmptyPlaceholder:c(`EmptyPlaceholder`),FillerRow:c(`FillerRow`),fixedFooterContent:i,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`),TableBodyComponent:c(`TableBody`,`tbody`),TableComponent:c(`Table`,`table`),TableFooterComponent:c(`TableFoot`,`tfoot`),TableHeadComponent:c(`TableHead`,`thead`),TableRowComponent:c(`TableRow`,`tr`),GroupComponent:c(`Group`,`tr`)}}))),nh=({height:e})=>(0,B.jsx)(`tr`,{children:(0,B.jsx)(`td`,{style:{height:e}})}),rh=({height:e})=>(0,B.jsx)(`tr`,{children:(0,B.jsx)(`td`,{style:{border:0,height:e,padding:0}})}),ih={overflowAnchor:`none`},ah={position:Cm(),zIndex:2,overflowAnchor:`none`},oh=_.memo(function({showTopList:e=!1}){let t=fh(`listState`),n=fh(`computeItemKey`),r=fh(`firstItemIndex`),i=fh(`context`),a=fh(`isSeeking`),o=fh(`fixedHeaderHeight`),s=fh(`groupIndices`).length>0,c=fh(`itemContent`),l=fh(`groupContent`),u=fh(`ScrollSeekPlaceholder`)??nh,d=fh(`GroupComponent`),f=fh(`TableRowComponent`),p=(e?t.topItems:[]).reduce((e,t,n)=>(n===0?e.push(t.size):e.push(e[n-1]+t.size),e),[]);return(e?t.topItems:t.items).map(t=>{let m=t.originalIndex,h=n(m+r,t.data,i),g=e?m===0?0:p[m-1]:0;return a?(0,_.createElement)(u,{...Bm(u,i),height:t.size,index:t.index,key:h,type:t.type||`item`}):t.type===`group`?(0,_.createElement)(d,{...Bm(d,i),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,key:h,style:{...ah,top:o}},l(t.index,i)):(0,_.createElement)(f,{...Bm(f,i),...Vm(f,t.data),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,"data-item-group-index":t.groupIndex,key:h,style:e?{...ah,top:o+g}:ih},s?c(t.index,t.groupIndex,t.data,i):c(t.index,t.data,i))})}),sh=_.memo(function(){let e=fh(`listState`),t=fh(`topItemsIndexes`).length>0,n=ph(`sizeRanges`),r=fh(`useWindowScroll`),i=fh(`customScrollParent`),a=ph(`windowScrollContainerState`),o=ph(`scrollContainerState`),s=i||r?a:o,c=fh(`trackItemSizes`),{callbackRef:l,ref:u}=Tf(n,fh(`itemSize`),c,s,fh(`log`),void 0,i,!1,fh(`skipAnimationFrameInResizeObserver`)),[d,f]=_.useState(0);dh(`deviation`,e=>{d!==e&&(u.current.style.marginTop=`${e}px`,f(e))});let p=fh(`EmptyPlaceholder`),m=fh(`FillerRow`)??rh,h=fh(`TableBodyComponent`),g=fh(`paddingTopAddition`),v=fh(`statefulTotalCount`),y=fh(`context`);if(v===0&&p!=null)return(0,B.jsx)(p,{...Bm(p,y)});let b=(t?e.topItems:[]).reduce((e,t)=>e+t.size,0),x=e.offsetTop+g+d-b,S=e.offsetBottom,C=x>0?(0,B.jsx)(m,{context:y,height:x},`padding-top`):null,w=S>0?(0,B.jsx)(m,{context:y,height:S},`padding-bottom`):null;return(0,B.jsxs)(h,{"data-testid":`virtuoso-item-list`,ref:l,...Bm(h,y),children:[C,t&&(0,B.jsx)(oh,{showTopList:!0}),(0,B.jsx)(oh,{}),w]})}),ch=({children:e})=>{let t=_.useContext(ym),n=ph(`viewportHeight`),r=ph(`fixedItemHeight`),i=Cf(_.useMemo(()=>Nd(n,e=>rp(e,`height`)),[n]),!0,fh(`skipAnimationFrameInResizeObserver`));return _.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,B.jsx)(`div`,{"data-viewport-type":`element`,ref:i,style:Lm(!1),children:e})},lh=({children:e})=>{let t=_.useContext(ym),n=ph(`windowViewportRect`),r=ph(`fixedItemHeight`),i=fh(`customScrollParent`),a=fh(`useWindowScroll`),o=Of(n,i,fh(`skipAnimationFrameInResizeObserver`));return _.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,B.jsx)(`div`,{"data-viewport-type":`window`,ref:o,style:Rm(!1,a),children:e})},{Component:uh,useEmitter:dh,useEmitterValue:fh,usePublisher:ph}=vm(th,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,firstItemIndex:`firstItemIndex`,itemContent:`itemContent`,groupContent:`groupContent`,fixedHeaderContent:`fixedHeaderContent`,fixedFooterContent:`fixedFooterContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,topItemCount:`topItemCount`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,groupCounts:`groupCounts`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},_.memo(function(e){let t=fh(`useWindowScroll`),n=fh(`customScrollParent`),r=ph(`fixedHeaderHeight`),i=ph(`fixedFooterHeight`),a=fh(`fixedHeaderContent`),o=fh(`fixedFooterContent`),s=fh(`context`),c=Cf(_.useMemo(()=>Nd(r,e=>rp(e,`height`)),[r]),!0,fh(`skipAnimationFrameInResizeObserver`)),l=Cf(_.useMemo(()=>Nd(i,e=>rp(e,`height`)),[i]),!0,fh(`skipAnimationFrameInResizeObserver`)),u=n||t?hh:mh,d=n||t?lh:ch,f=fh(`TableComponent`),p=fh(`TableHeadComponent`),m=fh(`TableFooterComponent`),h=a?(0,B.jsx)(p,{ref:c,style:{position:`sticky`,top:0,zIndex:2},...Bm(p,s),children:a()},`TableHead`):null,g=o?(0,B.jsx)(m,{ref:l,style:{bottom:0,position:`sticky`,zIndex:1},...Bm(m,s),children:o()},`TableFoot`):null;return(0,B.jsx)(u,{...e,...Bm(u,s),children:(0,B.jsx)(d,{children:(0,B.jsxs)(f,{style:{borderSpacing:0,overflowAnchor:`none`},...Bm(f,s),children:[h,(0,B.jsx)(sh,{},`TableBody`),g]})})})})),mh=Wm({useEmitter:dh,useEmitterValue:fh,usePublisher:ph}),hh=Gm({useEmitter:dh,useEmitterValue:fh,usePublisher:ph}),gh={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},_h={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:vh,floor:yh,max:bh,min:xh,round:Sh}=Math;function Ch(e,t,n){return Array.from({length:t-e+1}).map((t,r)=>({data:n===null?null:n[r+e],index:r+e}))}function wh(e){return{..._h,items:e}}function Th(e,t){return e!==void 0&&e.width===t.width&&e.height===t.height}function Eh(e,t){return e!==void 0&&e.column===t.column&&e.row===t.row}var Dh=sf(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:i,headerHeight:a,scrollBy:o,scrollContainerState:s,scrollTo:c,scrollTop:l,smoothScrollTargetReached:u,viewportHeight:d},f,p,{didMount:m,propsReady:h},{customScrollParent:g,useWindowScroll:_,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b},x])=>{let S=J(0),C=J(0),w=J(gh),T=J({height:0,width:0}),E=J({height:0,width:0}),D=af(),O=af(),k=J(0),A=J(null),ee=J({column:0,row:0}),te=af(),j=af(),M=J(!1),N=J(0),ne=J(!0),re=J(!1),ie=J(!1);Hd(q(m,ef(N),G(([e,t])=>t!==0)),()=>{Ud(ne,!1)}),Hd(q(uf(m,ne,E,T,N,re),G(([e,t,n,r,,i])=>e&&!t&&n.height!==0&&r.height!==0&&!i)),([,,,,e])=>{Ud(re,!0),kp(1,()=>{Ud(D,e)}),Kd(q(l),()=>{Ud(t,[0,0]),Ud(ne,!0)})}),W(q(j,G(e=>e!=null&&e.scrollTop>0),Xd(0)),C),Hd(q(m,ef(j),G(([,e])=>e!=null)),([,e])=>{e&&(Ud(T,e.viewport),Ud(E,e.item),Ud(ee,e.gap),e.scrollTop>0&&(Ud(M,!0),Kd(q(l,Qd(1)),e=>{Ud(M,!1)}),Ud(c,{top:e.scrollTop})))}),W(q(T,K(({height:e})=>e)),d),W(q(uf(Y(T,Th),Y(E,Th),Y(ee,(e,t)=>e!==void 0&&e.column===t.column&&e.row===t.row),Y(l)),K(([e,t,n,r])=>({gap:n,item:t,scrollTop:r,viewport:e}))),te),W(q(uf(Y(S),r,Y(ee,Eh),Y(E,Th),Y(T,Th),Y(A),Y(C),Y(M),Y(ne),Y(N)),G(([,,,,,,,e])=>!e),K(([e,[t,n],r,i,a,o,s,,c,l])=>{let{column:u,row:d}=r,{height:f,width:p}=i,{width:m}=a;if(s===0&&(e===0||m===0))return gh;if(p===0){let t=Ap(l,e);return wh(Ch(t,t+Math.max(s-1,0),o))}let h=Oh(m,p,u),g,_;c?t===0&&n===0&&s>0?(g=0,_=s-1):(g=h*yh((t+d)/(f+d)),_=h*vh((n+d)/(f+d))-1,_=xh(e-1,bh(_,h-1)),g=xh(_,bh(0,g))):(g=0,_=-1);let v=Ch(g,_,o),{bottom:y,top:b}=kh(a,r,i,v),x=vh(e/h);return{bottom:y,itemHeight:f,items:v,itemWidth:p,offsetBottom:x*f+(x-1)*d-y,offsetTop:b,top:b}})),w),W(q(A,G(e=>e!==null),K(e=>e.length)),S),W(q(uf(T,E,w,ee),G(([e,t,{items:n}])=>n.length>0&&t.height!==0&&e.height!==0),K(([e,t,{items:n},r])=>{let{bottom:i,top:a}=kh(e,r,t,n);return[a,i]}),Yd(Qf)),t);let P=J(!1);W(q(l,ef(P),K(([e,t])=>t||e!==0)),P);let ae=of(q(uf(w,S),G(([{items:e}])=>e.length>0),ef(P),G(([[e,t],n])=>{let r=e.items[e.items.length-1].index===t-1;return(n||e.bottom>0&&e.itemHeight>0&&e.offsetBottom===0&&e.items.length===t)&&r}),K(([[,e]])=>e-1),Yd())),oe=of(q(Y(w),G(({items:e})=>e.length>0&&e[0].index===0),Xd(0),Yd())),se=of(q(Y(w),ef(M),G(([{items:e},t])=>e.length>0&&!t),K(([{items:e}])=>({endIndex:e[e.length-1].index,startIndex:e[0].index})),Yd(Zf),$d(0)));W(se,p.scrollSeekRangeChanged),W(q(D,ef(T,E,S,ee),K(([e,t,n,r,i])=>{let a=Ep(e),{align:o,behavior:s,offset:c}=a,l=a.index;l===`LAST`&&(l=r-1),l=bh(0,l,xh(r-1,l));let u=Ah(t,i,n,l);return o===`end`?u=Sh(u-t.height+n.height):o===`center`&&(u=Sh(u-t.height/2+n.height/2)),c!==void 0&&c!==0&&(u+=c),{behavior:s,top:u}})),c);let ce=rf(q(w,K(e=>e.offsetBottom+e.bottom)),0);return W(q(b,K(e=>({height:e.visibleHeight,width:e.visibleWidth}))),T),{customScrollParent:g,data:A,deviation:k,footerHeight:i,gap:ee,headerHeight:a,increaseViewportBy:e,initialItemCount:C,itemDimensions:E,overscan:n,restoreStateFrom:j,scrollBy:o,scrollContainerState:s,scrollHeight:O,scrollTo:c,scrollToIndex:D,scrollTop:l,smoothScrollTargetReached:u,totalCount:S,useWindowScroll:_,viewportDimensions:T,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b,...p,gridState:w,horizontalDirection:ie,initialTopMostItemIndex:N,totalListHeight:ce,...f,endReached:ae,propsReady:h,rangeChanged:se,startReached:oe,stateChanged:te,stateRestoreInProgress:M,...x}},Vd(Wp,kf,Rp,cm,wp,lm,hf));function Oh(e,t,n){return bh(1,yh((e+n)/(yh(t)+n)))}function kh(e,t,n,r){let{height:i}=n;if(i===void 0||r.length===0)return{bottom:0,top:0};let a=Ah(e,t,n,r[0].index);return{bottom:Ah(e,t,n,r[r.length-1].index)+i,top:a}}function Ah(e,t,n,r){let i=yh(r/Oh(e.width,n.width,t.column)),a=i*n.height+bh(0,i-1)*t.row;return a>0?a+t.row:a}var jh=sf(([e,t])=>({...e,...t}),Vd(Dh,sf(()=>{let e=J(e=>`Item ${e}`),t=J({}),n=J(null),r=J(`virtuoso-grid-item`),i=J(`virtuoso-grid-list`),a=J(Om),o=J(`div`),s=J(Rd),c=(e,n=null)=>rf(q(t,K(t=>t[e]),Yd()),n),l=J(!1),u=J(!1);return W(Y(u),l),{components:t,computeItemKey:a,context:n,FooterComponent:c(`Footer`),HeaderComponent:c(`Header`),headerFooterTag:o,itemClassName:r,ItemComponent:c(`Item`,`div`),itemContent:e,listClassName:i,ListComponent:c(`List`,`div`),readyStateChanged:l,reportReadyState:u,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`,`div`)}}))),Mh=_.memo(function(){let e=zh(`gridState`),t=zh(`listClassName`),n=zh(`itemClassName`),r=zh(`itemContent`),i=zh(`computeItemKey`),a=zh(`isSeeking`),o=Bh(`scrollHeight`),s=zh(`ItemComponent`),c=zh(`ListComponent`),l=zh(`ScrollSeekPlaceholder`),u=zh(`context`),d=Bh(`itemDimensions`),f=Bh(`gap`),p=zh(`log`),m=zh(`stateRestoreInProgress`),h=Bh(`reportReadyState`),g=Cf(_.useMemo(()=>e=>{let t=e.parentElement.parentElement.scrollHeight;o(t);let n=e.firstChild;if(n!==null){let{height:e,width:t}=n.getBoundingClientRect();d({height:e,width:t})}f({column:Uh(`column-gap`,getComputedStyle(e).columnGap,p),row:Uh(`row-gap`,getComputedStyle(e).rowGap,p)})},[o,d,f,p]),!0,!1);return wm(()=>{e.itemHeight>0&&e.itemWidth>0&&h(!0)},[e]),m?null:(0,B.jsx)(c,{className:t,ref:g,...Bm(c,u),"data-testid":`virtuoso-item-list`,style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(t=>{let o=i(t.index,t.data,u);return a?(0,B.jsx)(l,{...Bm(l,u),height:e.itemHeight,index:t.index,width:e.itemWidth},o):(0,_.createElement)(s,{...Bm(s,u),className:n,"data-index":t.index,key:o},r(t.index,t.data,u))})})}),Nh=_.memo(function(){let e=zh(`HeaderComponent`),t=Bh(`headerHeight`),n=zh(`headerFooterTag`),r=Cf(_.useMemo(()=>e=>{t(rp(e,`height`))},[t]),!0,!1),i=zh(`context`);return e==null?null:(0,B.jsx)(n,{ref:r,children:(0,B.jsx)(e,{...Bm(e,i)})})}),Ph=_.memo(function(){let e=zh(`FooterComponent`),t=Bh(`footerHeight`),n=zh(`headerFooterTag`),r=Cf(_.useMemo(()=>e=>{t(rp(e,`height`))},[t]),!0,!1),i=zh(`context`);return e==null?null:(0,B.jsx)(n,{ref:r,children:(0,B.jsx)(e,{...Bm(e,i)})})}),Fh=({children:e})=>{let t=_.useContext(bm),n=Bh(`itemDimensions`),r=Bh(`viewportDimensions`),i=Cf(_.useMemo(()=>e=>{r(e.getBoundingClientRect())},[r]),!0,!1);return _.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),(0,B.jsx)(`div`,{ref:i,style:Lm(!1),children:e})},Ih=({children:e})=>{let t=_.useContext(bm),n=Bh(`windowViewportRect`),r=Bh(`itemDimensions`),i=zh(`customScrollParent`),a=zh(`useWindowScroll`),o=Of(n,i,!1);return _.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),(0,B.jsx)(`div`,{ref:o,style:Rm(!1,a),children:e})},{Component:Lh,useEmitter:Rh,useEmitterValue:zh,usePublisher:Bh}=vm(jh,{optional:{context:`context`,totalCount:`totalCount`,overscan:`overscan`,itemContent:`itemContent`,components:`components`,computeItemKey:`computeItemKey`,data:`data`,initialItemCount:`initialItemCount`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`headerFooterTag`,listClassName:`listClassName`,itemClassName:`itemClassName`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,restoreStateFrom:`restoreStateFrom`,initialTopMostItemIndex:`initialTopMostItemIndex`,increaseViewportBy:`increaseViewportBy`},methods:{scrollTo:`scrollTo`,scrollBy:`scrollBy`,scrollToIndex:`scrollToIndex`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,stateChanged:`stateChanged`,readyStateChanged:`readyStateChanged`}},_.memo(function({...e}){let t=zh(`useWindowScroll`),n=zh(`customScrollParent`),r=n||t?Hh:Vh,i=n||t?Ih:Fh,a=zh(`context`);return(0,B.jsx)(r,{...e,...Bm(r,a),children:(0,B.jsxs)(i,{children:[(0,B.jsx)(Nh,{}),(0,B.jsx)(Mh,{}),(0,B.jsx)(Ph,{})]})})})),Vh=Wm({useEmitter:Rh,useEmitterValue:zh,usePublisher:Bh}),Hh=Gm({useEmitter:Rh,useEmitterValue:zh,usePublisher:Bh});function Uh(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,ff.WARN),t===`normal`?0:parseInt(t??`0`,10)}var Wh=new Set([`edit`,`multiedit`,`write`]);function Gh(e,t){if(t===`all`)return!0;if(t.startsWith(`subagent:`))return e.subagent_key===t.slice(9);let n=t=>(e.tools??[]).some(e=>!!e.name&&t.has(e.name.toLowerCase()));if(t===`edits`)return n(Wh);if(t===`bash`)return n(new Set([`bash`]));let r=(e.tools??[]).some(e=>e.is_error);return e.is_sidechain?t===`errors`&&r:t===`prompts`?e.kind===`human`:t===`errors`?r:e.kind===`human`?!0:e.kind===`assistant`?e.label.trim()!==``||(e.thinking?.length??0)>0:!1}var Kh=new Set([`ExitPlanMode`,`AskUserQuestion`]);function qh(e,t){let n=[],r=[],i=[],a=[],o=[],s=[],c=[],l=new Map,u=new Map,d=new Set;return e.forEach((e,f)=>{l.set(e.uuid,f);for(let t of e.member_uuids?.length?e.member_uuids:[e.uuid])u.has(t)||u.set(t,f);e.tools?.some(e=>e.is_error)&&n.push(f),e.kind===`human`&&r.push(f),e.subagent_key!=null&&!d.has(e.subagent_key)&&(d.add(e.subagent_key),i.push(f)),e.tools?.some(e=>e.name!=null&&Kh.has(e.name))&&a.push(f),e.cache_failure&&o.push(f),e.kind===`meta`&&e.meta_kind===`compaction`&&s.push(f),t&&e.uuid in t&&c.push(f)}),{error:n,prompt:r,subagent:i,plan:a,cache:o,compaction:s,bookmark:c,indexByUuid:l,memberIndex:u}}function Jh(e,t){let n=e.indexByUuid.get(t);return n===void 0?e.memberIndex.get(t):n}function Yh(e,t,n){if(n===1){for(let n of e)if(n>t)return n;return null}for(let n=e.length-1;n>=0;n--)if(e[n]<t)return e[n];return null}function Xh(e,t){if(t.size===0)return!1;if(t.has(e.anchor.uuid))return!0;for(let n of e.member_uuids)if(t.has(n))return!0;return!1}var Zh=e=>({keep:e,droppedTop:0,droppedBottom:0,resetTopCursorTo:null,resetBottomCursorTo:null});function Qh(e){let{items:t,op:n,cap:r,protectedUuids:i,fetchInFlight:a}=e;if(a||n===`reset`||t.length<=r)return Zh(t);if(n===`prepend`){let e=r;for(let n=t.length-1;n>=e;n--)if(Xh(t[n],i)){e=n+1;break}if(e>=t.length)return Zh(t);let n=t.slice(0,e);return{keep:n,droppedTop:0,droppedBottom:t.length-e,resetTopCursorTo:null,resetBottomCursorTo:n[n.length-1].anchor.id}}let o=t.length-r,s=o;for(let e=0;e<o;e++)if(Xh(t[e],i)){s=e;break}if(s<=0)return Zh(t);let c=t.slice(s);return{keep:c,droppedTop:s,droppedBottom:0,resetTopCursorTo:c[0].anchor.id,resetBottomCursorTo:null}}var $h=1e6;function eg(e,t){let n=e-t.addedTop+t.droppedTop;return n<0?0:n}var tg=500,ng=10,rg=2*tg;function ig(e,t={}){let{outlineTurns:n,openIntent:r,protectedUuids:i}=t,a=(0,_.useRef)(i);a.current=i;let[o,s]=(0,_.useState)({detail:null,firstItemIndex:$h}),c=o.detail,[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),v=(0,_.useRef)(0),y=(0,_.useCallback)(e=>{let t={rev:++v.current,...e};return g(t),t},[]),[b,x]=(0,_.useState)(0),[S,C]=(0,_.useState)(null),w=(0,_.useRef)(null),T=(0,_.useRef)(null),[E,D]=(0,_.useState)(!1),O=(0,_.useRef)(!1);O.current=E;let k=(0,_.useRef)(!1),A=(0,_.useRef)(!1),ee=(0,_.useRef)(null),te=(0,_.useRef)(()=>Promise.resolve()),j=(0,_.useRef)(null),M=(0,_.useRef)(!1),N=(0,_.useRef)(!1),ne=(0,_.useRef)(!1),re=(0,_.useRef)(null),ie=(0,_.useRef)(n);ie.current=n;let P=(0,_.useCallback)(e=>{s(t=>{let n=typeof e==`function`?e(t.detail):e;return re.current=n,{detail:n,firstItemIndex:t.firstItemIndex}})},[]),ae=(0,_.useCallback)(e=>{s(()=>(re.current=e,{detail:e,firstItemIndex:$h})),w.current=e.page.next_after,T.current=e.page.prev_before??null,D(e.page.has_prev??!1),y({op:`reset`,addedTop:0,addedBottom:0,droppedTop:0,droppedBottom:0})},[y]);(0,_.useEffect)(()=>{if(j.current=e,!e){P(null),C(null),u(!1),f(null),w.current=null,T.current=null,D(!1),m(null);return}u(!0),f(null),P(null),w.current=null,T.current=null,D(!1),m(null);let t=new AbortController,n=r?.kind;return Mc(n==null?`/api/conversation/${encodeURIComponent(e)}?limit=${tg}`:`/api/conversation/${encodeURIComponent(e)}?tail=1&limit=${tg}`,t.signal).then(t=>{j.current===e&&(ae(t),C(e),u(!1),n===`tail`?m(t.page.has_prev?`bottom`:`top`):n??m(null))}).catch(e=>{if(!jc(e)){if(e instanceof Ac&&e.status===404){f(`Conversation not found.`),u(!1);return}f(`Couldn't load the conversation.`),u(!1)}}),()=>t.abort()},[e,r?.kind,r&&`uuid`in r?r.uuid:null,P,ae]);let oe=(0,_.useCallback)(async()=>{let e=w.current,t=j.current;if(e==null||t==null||k.current)return null;k.current=!0;try{let n;try{n=await Mc(`/api/conversation/${encodeURIComponent(t)}?limit=${tg}&after=${e}`)}catch{return null}return j.current===t?(P(e=>e?{...e,items:[...e.items,...n.items],page:{...e.page,next_after:n.page.next_after,has_more:n.page.has_more},subagent_meta:n.subagent_meta??e.subagent_meta}:n),w.current=n.page.next_after,y({op:`append`,addedTop:0,addedBottom:n.items.length,droppedTop:0,droppedBottom:0})):null}finally{k.current=!1}},[P,y]),se=(0,_.useCallback)(async()=>oe(),[oe]),ce=(0,_.useCallback)(async()=>{let e=T.current,t=j.current;if(e==null||t==null||A.current)return null;A.current=!0;try{let n;try{n=await Mc(`/api/conversation/${encodeURIComponent(t)}?limit=${tg}&before=${e}`)}catch{return null}return j.current===t?(s(e=>{let t=e.detail,r=t?{...t,items:[...n.items,...t.items],page:{...t.page,prev_before:n.page.prev_before??null,has_prev:n.page.has_prev??!1},subagent_meta:n.subagent_meta??t.subagent_meta}:n;return re.current=r,{detail:r,firstItemIndex:eg(e.firstItemIndex,{addedTop:n.items.length,droppedTop:0})}}),T.current=n.page.prev_before??null,D(n.page.has_prev??!1),y({op:`prepend`,addedTop:n.items.length,addedBottom:0,droppedTop:0,droppedBottom:0})):null}finally{A.current=!1}},[P,y]),le=(0,_.useCallback)(async()=>{let e=await ce();return e&&e.addedTop>0?e:null},[ce]),ue=(0,_.useCallback)(async e=>{let t=j.current;if(t==null)return;let n=ee.current;if(n){await n;return}let r=()=>{};ee.current=new Promise(e=>{r=e});try{await de(e,t)}finally{ee.current=null,r()}},[]),de=(0,_.useCallback)((e,t)=>te.current(e,t),[]);te.current=(0,_.useCallback)(async(e,t)=>{let n=()=>{let t=re.current;return!!t&&t.items.some(t=>t.member_uuids.includes(e))};if(n())return;let r=e=>{s(t=>{let n=t.detail;if(!n||n.items.length<=rg)return t;let r=Qh({items:n.items,op:e,cap:rg,protectedUuids:a.current??new Set,fetchInFlight:!1});if(r.keep===n.items)return t;if(r.droppedBottom>0){w.current=r.resetBottomCursorTo;let e={...n,items:r.keep,page:{...n.page,next_after:r.resetBottomCursorTo,has_more:!0}};return re.current=e,{detail:e,firstItemIndex:t.firstItemIndex}}T.current=r.resetTopCursorTo,queueMicrotask(()=>D(!0));let i={...n,items:r.keep,page:{...n.page,prev_before:r.resetTopCursorTo,has_prev:!0}};return re.current=i,{detail:i,firstItemIndex:eg(t.firstItemIndex,{addedTop:0,droppedTop:r.droppedTop})}})},i=()=>new Promise(e=>{setTimeout(e,0)}),o=ie.current??[];if(o.length===0){let e=t;for(;;){if(n())return;if(await oe()&&w.current!=null){if(r(`append`),await i(),j.current!==e)return;continue}if(w.current==null||j.current!==e)return;for(;k.current&&j.current===e;)await i();if(j.current!==e)return}}let c=qh(o),l=Jh(c,e);if(l===void 0)return;let u=re.current?.items??[],d=e=>{for(let t of e.member_uuids){let e=Jh(c,t);if(e!==void 0)return e}},f,p;for(let e of u){let t=d(e);t!==void 0&&((f===void 0||t<f)&&(f=t),(p===void 0||t>p)&&(p=t))}if(f!==void 0&&l<f)for(;;){if(n())return;if(await ce()&&T.current!=null){if(r(`prepend`),await i(),j.current!==t)return;continue}if(T.current==null||j.current!==t)return;for(;A.current&&j.current===t;)await i();if(j.current!==t)return}else for(;;){if(n())return;if(await oe()&&w.current!=null){if(r(`append`),await i(),j.current!==t)return;continue}if(w.current==null||j.current!==t)return;for(;k.current&&j.current===t;)await i();if(j.current!==t)return}},[oe,ce]);let fe=(0,_.useCallback)(async()=>{let e=j.current;if(e==null)return;let t;try{t=await Mc(`/api/conversation/${encodeURIComponent(e)}?tail=1&limit=${tg}`)}catch{return}j.current===e&&ae(t)},[ae]),pe=c!=null&&S===e,me=pe?c:null,he=e!=null&&!pe&&d==null?!0:l,ge=me?.page?.next_after!=null;M.current=ge;let _e=me?.page?.prev_before??null,ve=(0,_.useCallback)(async()=>{if(N.current){ne.current=!0;return}let e=j.current;if(!(!e||M.current||k.current)){N.current=!0;try{for(let t=0;t<50;t++){let t=re.current?.items??[];if(!t.length)break;let n=Math.max(0,t.length-ng),r=n>0?t[n-1].anchor.id:null,i;try{i=await Mc(`/api/conversation/${encodeURIComponent(e)}?limit=${tg}`+(r==null?``:`&after=${r}`))}catch{break}if(j.current!==e)return;let a=i.items,o,s=0,c=!1;if(a.length===0)o=t;else{c=!0;let e=new Map(a.map(e=>[e.anchor.id,e])),r=new Set(t.map(e=>e.anchor.id)),i=t.slice(0,n),l=t.slice(n);o=[...i];for(let t of l){let n=e.get(t.anchor.id);n!==void 0&&o.push(n)}for(let e of a)r.has(e.anchor.id)||(o.push(e),s+=1)}if(P(e=>e&&{...e,items:o,cost_usd:i.cost_usd,models:i.models,title:i.title??e.title,git_branch:i.git_branch,project_label:i.project_label,last_anchor:i.last_anchor??e.last_anchor,last_activity_utc:i.last_activity_utc??e.last_activity_utc,subagent_meta:i.subagent_meta??e.subagent_meta,page:e.page}),c&&x(e=>e+1),c&&y({op:`append`,addedTop:0,addedBottom:s,droppedTop:0,droppedBottom:0}),s===0||i.page.next_after==null)break}}finally{N.current=!1,ne.current&&(ne.current=!1,ve())}}},[P,y]),ye=V();(0,_.useEffect)(()=>{re.current&&!M.current&&ve()},[ye?.generated_at??``]);let be=ye?.transcriptsEnabled??!1,xe=(0,_.useSyncExternalStore)(R,()=>ft(L()));return(0,_.useEffect)(()=>{if(!e||!be||!xe||typeof EventSource>`u`)return;let t=new EventSource(`/api/conversation/${encodeURIComponent(e)}/events`);return t.addEventListener(`tail`,()=>{ve()}),t.addEventListener(`open`,()=>{ve()}),()=>t.close()},[e,be,xe]),(0,_.useEffect)(()=>{let e=h;if(!e||e.trim||e.op!==`append`&&e.op!==`prepend`)return;let t=k.current||A.current||N.current,n=re.current?.items;if(!n)return;let r=Qh({items:n,op:e.op,cap:rg,protectedUuids:a.current??new Set,fetchInFlight:t});if(r.keep!==n){if(r.droppedBottom>0)w.current=r.resetBottomCursorTo,P(e=>e&&{...e,items:r.keep,page:{...e.page,next_after:r.resetBottomCursorTo,has_more:!0}});else if(r.droppedTop>0)T.current=r.resetTopCursorTo,D(!0),s(e=>{let t=e.detail;if(!t)return e;let n={...t,items:r.keep,page:{...t.page,prev_before:r.resetTopCursorTo,has_prev:!0}};return re.current=n,{detail:n,firstItemIndex:eg(e.firstItemIndex,{addedTop:0,droppedTop:r.droppedTop})}});else return;y({op:`append`,addedTop:0,addedBottom:0,droppedTop:r.droppedTop,droppedBottom:r.droppedBottom,trim:!0})}},[h?.rev]),{detail:me,loading:he,error:d,hasMore:ge,hasPrev:E,prevBefore:_e,openScrollIntent:p,lastOp:h,loadMore:se,loadPrev:le,loadToTarget:ue,jumpToLatest:fe,tailRevision:b,virtualFirstItemIndex:o.firstItemIndex}}function ag(e){let t=[],n=[],r=()=>{n.length>=2?t.push({kind:`tool_result_run`,items:n}):n.length===1&&t.push({kind:`item`,item:n[0]}),n=[]};for(let i of e){if(i.kind===`item`&&i.item.kind===`tool_result`){n.push(i.item);continue}r(),t.push(i)}return r(),t}function og(e,t){let n=new Map,r=new Map;for(let t of e){let e=t.subagent_key;if(e!=null){let r=n.get(e);r?r.push(t):n.set(e,[t])}else for(let e of t.member_uuids)r.set(e,t)}let i=new Map;for(let e of n.keys()){let a=t?.[e];if(a&&a.parent_subagent_key!==void 0){let t=a.parent_subagent_key??null,o=a.spawn_uuid??null;t!=null&&n.has(t)?i.set(e,{where:`subagent`,parentKey:t,anchorUuid:o}):t==null&&o!=null&&r.has(o)?i.set(e,{where:`main`,anchorUuid:o}):i.set(e,{where:`top`});continue}let o=n.get(e),s=o.find(e=>e.kind!==`meta`)??o[0],c=s.parent_uuid==null?void 0:r.get(s.parent_uuid);i.set(e,c?{where:`main`,anchorUuid:c.anchor.uuid}:{where:`top`})}let a=new Map,o=new Map;for(let[e,t]of i)if(t.where===`subagent`){let n=o.get(t.parentKey);n?n.push(e):o.set(t.parentKey,[e])}let s=(e,t,r)=>{let c=a.get(e);if(c)return c;let l=i.get(e),u={kind:`subagent`,subagentKey:e,items:n.get(e),nested:l.where!==`top`,depth:t,spawnAnchorUuid:l.where===`top`?null:l.anchorUuid??null,children:[]};return a.set(e,u),r.add(e),u.children=(o.get(e)??[]).filter(e=>!r.has(e)).map(e=>s(e,t+1,r)),r.delete(e),u},c=new Map;for(let[e,t]of i)if(t.where===`main`){let n=c.get(t.anchorUuid);n?n.push(e):c.set(t.anchorUuid,[e])}let l=[],u=new Set,d=e=>{if(!u.has(e)){u.add(e);for(let t of o.get(e)??[])d(t)}},f=e=>{l.push(s(e,0,new Set)),d(e)};for(let t of e)if(t.subagent_key==null){l.push({kind:`item`,item:t});for(let e of c.get(t.anchor.uuid)??[])u.has(e)||f(e)}else{let e=t.subagent_key;if(u.has(e))continue;i.get(e).where===`top`&&f(e)}for(let e of n.keys())u.has(e)||f(e);return ag(l)}function sg(e,t){for(let n of e)n.kind===`subagent`&&(t(n),n.children.length&&sg(n.children,t))}function cg(e){let t=[];return sg(e,e=>t.push(e)),t}var lg=RegExp(`^\\s*(?:<(${[`command-name`,`command-message`,`command-args`,`local-command-caveat`,`local-command-stdout`,`local-command-stderr`].join(`|`)})>(?:(?!</\\1>)[\\s\\S])*</\\1>\\s*)+$`);function ug(e){return e?lg.test(e):!1}var dg=200;function fg(e,t,n={}){let{regex:r=!1,case:i=!1,tailRevision:a=0}=n,[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(0),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=t.trim(),b=Ku(y,dg,``),x=Ku(a,dg,0),S=(0,_.useRef)(null);return(0,_.useEffect)(()=>(y||(s([]),l(0),d(!1),p(null),v(null)),()=>{S.current?.abort()}),[y]),(0,_.useEffect)(()=>{if(!b){h(!1);return}let t=new AbortController;S.current=t,h(!0);let n=`/api/conversation/${encodeURIComponent(e)}/find?q=${encodeURIComponent(b)}`;return r&&(n+=`®ex=1`),i&&(n+=`&case=1`),Mc(n,t.signal).then(e=>{s(e.anchors),l(e.total),d(e.anchors_truncated),p(e.mode),v(null),h(!1)}).catch(e=>{jc(e)||(s([]),l(0),d(!1),p(null),v(e instanceof Ac&&e.status===400?`invalid regex`:`find failed`),h(!1))}),()=>t.abort()},[e,b,r,i,x]),{anchors:o,total:c,truncated:u,mode:f,loading:y!==``&&(y!==b||m),error:g}}var pg=`cctally.conv.find.regex`,mg=`cctally.conv.find.case`;function hg(e){try{return localStorage.getItem(e)===`1`}catch{return!1}}function gg(e,t){try{localStorage.setItem(e,t?`1`:`0`)}catch{}}function _g(){return hg(pg)}function vg(e){gg(pg,e)}function yg(){return hg(mg)}function bg(e){gg(mg,e)}function xg({sessionId:e,onClose:t,onTermsChange:n,stepRef:r,tailRevision:i=0}){let[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(0),[l,u]=(0,_.useState)(_g),[d,f]=(0,_.useState)(yg),{anchors:p,total:m,truncated:h,mode:g,loading:v,error:y}=fg(e,a,{regex:l,case:d,tailRevision:i}),b=(0,_.useRef)(null),x=(0,_.useRef)(null);(0,_.useEffect)(()=>{b.current?.focus()},[]);let S=Ku(a.trim(),200,``);(0,_.useEffect)(()=>{n(S,d,l)},[S,l,d,n]);let C=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=C.current,t=e?p.findIndex(t=>t.uuid===e):-1,n=t>=0?t:0;c(n),C.current=p.length?p[n]?.uuid??null:null},[p]);let w=t=>{if(p.length===0)return;let n=((s+t)%p.length+p.length)%p.length;c(n);let r=p[n];C.current=r.uuid,z({type:`OPEN_CONVERSATION`,sessionId:e,jump:{session_id:e,uuid:r.uuid,expand_details:r.match_kinds.length>0}})};r&&(r.current=w),(0,_.useEffect)(()=>()=>{r&&(r.current=null)},[r]);let T=()=>{z({type:`CLOSE_CONV_FIND`}),t()},E=()=>u(e=>{let t=!e;return vg(t),t}),D=()=>f(e=>{let t=!e;return bg(t),t}),O=e=>{e.key===`Enter`&&(e.preventDefault(),e.stopPropagation(),w(e.shiftKey?-1:1))},k=e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),T();return}if(e.key!==`Tab`)return;let t=x.current;if(!t)return;let n=Array.from(t.querySelectorAll(`input, button`)).filter(e=>!e.disabled);if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;e.shiftKey&&a===r?(e.preventDefault(),i.focus()):!e.shiftKey&&a===i&&(e.preventDefault(),r.focus())},A=p.length>0,ee=A?p[s]:null,te=`${A?s+1:0} / ${m}`,j=[l&&`regex`,d&&`case`].filter(Boolean).join(` · `);return(0,B.jsxs)(`div`,{className:`conv-findbar`,role:`search`,"aria-label":`Find within this conversation`,ref:x,onKeyDown:k,children:[(0,B.jsx)(`input`,{ref:b,className:`conv-findbar-input`,type:`text`,"aria-label":`Find in conversation`,placeholder:`Find…`,value:a,onChange:e=>o(e.target.value),onKeyDown:O}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-toggle`,"aria-pressed":l,"aria-label":`Regular expression`,title:`Regular expression (.*)`,onClick:E,children:`.*`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-toggle`,"aria-pressed":d,"aria-label":`Case-sensitive`,title:`Case-sensitive (Aa)`,onClick:D,children:`Aa`}),j&&(0,B.jsx)(`span`,{className:`conv-findbar-mode`,"aria-label":`search mode: ${j}`,children:j}),(0,B.jsxs)(`span`,{className:`conv-findbar-count`,"aria-live":`polite`,children:[te,h&&(0,B.jsx)(`span`,{className:`conv-findbar-note`,children:` · first 500`})]}),ee&&ee.match_kinds.length>0&&(0,B.jsx)(`span`,{className:`conv-findbar-kind`,children:ee.match_kinds.join(` `)}),g===`like`&&!y&&(0,B.jsx)(`span`,{className:`conv-findbar-hint`,children:`basic search`}),y&&(0,B.jsx)(`span`,{className:`conv-findbar-hint`,role:`alert`,children:y}),v&&(0,B.jsx)(`span`,{className:`conv-findbar-spin`,"aria-hidden":`true`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-nav`,"aria-label":`Previous match`,title:`Previous match (Shift+Enter)`,disabled:!A,onClick:()=>w(-1),children:`‹`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-nav`,"aria-label":`Next match`,title:`Next match (Enter)`,disabled:!A,onClick:()=>w(1),children:`›`}),(0,B.jsx)(`button`,{type:`button`,className:`conv-findbar-close`,"aria-label":`Close find`,title:`Close (Esc)`,onClick:T,children:`✕`})]})}function Sg(){let[e,t]=(0,_.useState)(!1),n=(0,_.useRef)(null),r=(0,_.useRef)(!0);return(0,_.useEffect)(()=>()=>{r.current=!1,n.current!=null&&window.clearTimeout(n.current)},[]),{copied:e,copy:(0,_.useCallback)(e=>{let i=()=>{r.current&&(t(!0),n.current!=null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t(!1),n.current=null},1100))};if(navigator.clipboard?.writeText){navigator.clipboard.writeText(e).then(i).catch(()=>{});return}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),i()}catch{}},[])}}function Cg(e,t,n){if(n<=0)return null;switch(e){case`ArrowDown`:return(t+1)%n;case`ArrowUp`:return(t-1+n)%n;case`Home`:return 0;case`End`:return n-1;default:return null}}function wg(e,t,n){let r=(0,_.useRef)(n);r.current=n,(0,_.useEffect)(()=>{if(!t||typeof document>`u`)return;let n=t=>{let n=e.current;n&&!n.contains(t.target)&&r.current()};return document.addEventListener(`pointerdown`,n,!0),()=>document.removeEventListener(`pointerdown`,n,!0)},[t,e])}var Tg=[{scope:`all`,label:`Whole transcript`},{scope:`prompts`,label:`Prompts only`},{scope:`chat`,label:`Chat only`},{scope:`recipe`,label:`Replay recipe`}];function Eg(e,t){return(e??``).normalize(`NFKD`).replace(/[^\x20-\x7E]/g,``).replace(/[^a-zA-Z0-9._-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,60)||t.slice(0,12)}function Dg(e,t){return`/api/conversation/${encodeURIComponent(e)}/export?scope=${t}`}async function Og(e,t){let n=await fetch(Dg(e,t));if(!n.ok)throw Error(`export failed: ${n.status}`);return n.text()}function kg(e,t){let n=new Blob([t],{type:`text/markdown;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,i.style.display=`none`,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(r),0)}function Ag({sessionId:e,title:t}){let[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null),o=(0,_.useRef)(null),s=(0,_.useRef)(null),c=(0,_.useRef)(null);wg(c,n,(0,_.useCallback)(()=>r(!1),[]));let l=Tg.length*2,u=(0,_.useRef)([]),[d,f]=(0,_.useState)(0),p=(0,_.useRef)(0),m=(0,_.useCallback)(e=>{p.current=e,f(e)},[]),h=(0,_.useRef)(!0);(0,_.useEffect)(()=>()=>{h.current=!1},[]);let{copy:g}=Sg();(0,_.useEffect)(()=>{r(!1)},[e]);let v=(0,_.useCallback)(()=>{r(!1);let e=s.current;e instanceof HTMLElement&&e.focus()},[]),y=(0,_.useCallback)(e=>{s.current=document.activeElement,m(e),r(!0)},[m]),b=(0,_.useCallback)(()=>{n?r(!1):y(0)},[n,y]);(0,_.useEffect)(()=>{n&&u.current[p.current]?.focus()},[n]);let x=(0,_.useCallback)(e=>{if(e.key===`Escape`){e.stopPropagation(),v();return}let t=Cg(e.key,p.current,l);t!==null&&(e.preventDefault(),m(t),u.current[t]?.focus())},[v,l,m]),S=(0,_.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),y(0)):e.key===`ArrowUp`&&(e.preventDefault(),y(l-1))},[y,l]),C=(0,_.useCallback)(async t=>{let n=`${t}:copy`;a(n);try{g(await Og(e,t))}catch{}finally{h.current&&a(e=>e===n?null:e)}},[e,g]),w=(0,_.useCallback)(async n=>{let r=`${n}:download`;a(r);try{let r=await Og(e,n);kg(`${Eg(t,e)}-${n}.md`,r)}catch{}finally{h.current&&a(e=>e===r?null:e)}},[e,t]);return(0,B.jsxs)(`div`,{ref:c,className:`conv-export`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||r(!1)},children:[(0,B.jsx)(`button`,{ref:o,type:`button`,className:`conv-export-toggle`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-label":`Export transcript`,onClick:b,onKeyDown:S,children:`Export ▾`}),n&&(0,B.jsx)(`div`,{className:`conv-export-menu`,role:`menu`,"aria-label":`Export transcript`,tabIndex:-1,onKeyDown:x,children:Tg.map(({scope:e,label:t},n)=>{let r=n*2,a=r+1;return(0,B.jsxs)(`div`,{className:`conv-export-row`,role:`none`,children:[(0,B.jsx)(`span`,{className:`conv-export-row-label`,children:t}),(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:r===d?0:-1,ref:e=>{u.current[r]=e},className:`conv-export-action`,"aria-label":`${t} — Copy`,disabled:i===`${e}:copy`,onClick:()=>void C(e),children:i===`${e}:copy`?`…`:`Copy`}),(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:a===d?0:-1,ref:e=>{u.current[a]=e},className:`conv-export-action`,"aria-label":`${t} — Download`,disabled:i===`${e}:download`,onClick:()=>void w(e),children:i===`${e}:download`?`…`:`Download`})]},e)})})]})}function jg(e,t){if(e===`edits`)return`Edits`;if(e===`bash`)return`Bash`;if(e.startsWith(`subagent:`)){let n=e.slice(9),r=t.find(e=>e.key===n);return r?Mg(r):n.slice(0,8)}return``}function Mg(e){return e.label.trim()||e.key.slice(0,8)}function Ng({focusMode:e,subagents:t,onSelect:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1),s=(0,_.useRef)(null),c=(0,_.useRef)(null);wg(c,r,(0,_.useCallback)(()=>{i(!1),o(!1)},[]));let l=t.length>0,u=2+ +!!l,d=(0,_.useRef)([]),f=(0,_.useRef)([]),[p,m]=(0,_.useState)(0),h=(0,_.useRef)(0),g=(0,_.useCallback)(e=>{h.current=e,m(e)},[]),[v,y]=(0,_.useState)(0),b=(0,_.useRef)(0),x=(0,_.useCallback)(e=>{b.current=e,y(e)},[]),[S,C]=(0,_.useState)(!1),w=(0,_.useRef)(!1),T=(0,_.useCallback)(e=>{w.current=e,C(e)},[]),E=(0,_.useCallback)(()=>{i(!1),o(!1),T(!1);let e=s.current;e instanceof HTMLElement&&e.focus()},[T]),D=(0,_.useCallback)(e=>{s.current=document.activeElement,g(e),T(!1),o(!1),i(!0)},[g,T]),O=(0,_.useCallback)(()=>{r?(i(!1),o(!1),T(!1)):D(0)},[r,D,T]),k=(0,_.useCallback)(()=>{x(0),T(!0),o(!0)},[x,T]),A=(0,_.useCallback)(()=>{o(!1),T(!1),d.current[2]?.focus()},[T]),ee=(0,_.useCallback)(e=>{n(e),E()},[n,E]);(0,_.useEffect)(()=>{r&&d.current[h.current]?.focus()},[r]),(0,_.useEffect)(()=>{a&&w.current&&f.current[b.current]?.focus()},[a]);let te=(0,_.useCallback)(e=>{if(e.key===`Escape`){e.stopPropagation(),E();return}if(!w.current){if(e.key===`ArrowRight`&&l&&h.current===2){e.preventDefault(),k();return}let t=Cg(e.key,h.current,u);t!==null&&(e.preventDefault(),g(t),d.current[t]?.focus());return}if(e.key===`ArrowLeft`){e.preventDefault(),A();return}let n=Cg(e.key,b.current,t.length);n!==null&&(e.preventDefault(),x(n),f.current[n]?.focus())},[E,l,u,k,A,g,x,t.length]),j=(0,_.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),D(0)):e.key===`ArrowUp`&&(e.preventDefault(),D(u-1))},[D,u]),M=jg(e,t),N=M!==``;return(0,B.jsxs)(`div`,{ref:c,className:`conv-focus-more`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(i(!1),o(!1))},children:[(0,B.jsx)(`button`,{type:`button`,className:[`conv-focus-more-toggle`,N?`conv-focus-more-toggle--on`:``].filter(Boolean).join(` `),"aria-haspopup":`menu`,"aria-expanded":r,"aria-label":`More focus filters`,onClick:O,onKeyDown:j,children:N?`${M} ▾`:`More ▾`}),r&&(0,B.jsxs)(`div`,{className:`conv-focus-more-menu`,role:`menu`,"aria-label":`More focus filters`,tabIndex:-1,onKeyDown:te,children:[(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:!S&&p===0?0:-1,ref:e=>{d.current[0]=e},className:[`conv-focus-more-item`,e===`edits`?`conv-focus-more-item--on`:``].filter(Boolean).join(` `),onClick:()=>ee(`edits`),children:`Edits`}),(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:!S&&p===1?0:-1,ref:e=>{d.current[1]=e},className:[`conv-focus-more-item`,e===`bash`?`conv-focus-more-item--on`:``].filter(Boolean).join(` `),onClick:()=>ee(`bash`),children:`Bash`}),l&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,tabIndex:!S&&p===2?0:-1,ref:e=>{d.current[2]=e},className:`conv-focus-more-item conv-focus-more-sub`,"aria-haspopup":`menu`,"aria-expanded":a,onClick:()=>a?A():k(),children:[`Subagent `,a?`▾`:`▸`]}),a&&(0,B.jsx)(`div`,{className:`conv-focus-more-submenu`,role:`menu`,"aria-label":`Focus a subagent`,children:t.map((t,n)=>{let r=`subagent:${t.key}`;return(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:S&&v===n?0:-1,ref:e=>{f.current[n]=e},className:[`conv-focus-more-item`,e===r?`conv-focus-more-item--on`:``].filter(Boolean).join(` `),onClick:()=>ee(r),children:Mg(t)},t.key)})})]})]})]})}var Pg=[{mode:`all`,label:`All`},{mode:`chat`,label:`Chat`},{mode:`prompts`,label:`Prompts`},{mode:`errors`,label:`Errors`}],Fg=[{mode:`edits`,label:`Edits`},{mode:`bash`,label:`Bash`}];function Ig(e,t){let n=Pg.find(t=>t.mode===e);if(n)return n.label;if(e===`edits`)return`Edits`;if(e===`bash`)return`Bash`;if(e.startsWith(`subagent:`)){let n=e.slice(9),r=t.find(e=>e.key===n);return r?Mg(r):n.slice(0,8)}return`All`}function Lg({focusMode:e,subagents:t,onSelect:n,errorCount:r=0}){let[i,a]=(0,_.useState)(!1),o=(0,_.useRef)(null),s=(0,_.useRef)(null);wg(s,i,(0,_.useCallback)(()=>a(!1),[]));let c=[...Pg.map(e=>e.mode===`errors`&&r>0?{...e,badge:r}:e),...Fg,...t.map(e=>({mode:`subagent:${e.key}`,label:Mg(e)}))],l=c.length,u=(0,_.useRef)([]),[d,f]=(0,_.useState)(0),p=(0,_.useRef)(0),m=(0,_.useCallback)(e=>{p.current=e,f(e)},[]),h=(0,_.useCallback)(()=>{a(!1);let e=o.current;e instanceof HTMLElement&&e.focus()},[]),g=(0,_.useCallback)(e=>{o.current=document.activeElement,m(e),a(!0)},[m]),v=(0,_.useCallback)(()=>{if(i)a(!1);else{let t=c.findIndex(t=>t.mode===e);g(t>=0?t:0)}},[i,g,c,e]);(0,_.useEffect)(()=>{i&&u.current[p.current]?.focus()},[i]);let y=(0,_.useCallback)(e=>{if(e.key===`Escape`){e.stopPropagation(),h();return}let t=Cg(e.key,p.current,l);t!==null&&(e.preventDefault(),m(t),u.current[t]?.focus())},[h,l,m]),b=(0,_.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),g(0)):e.key===`ArrowUp`&&(e.preventDefault(),g(l-1))},[g,l]),x=(0,_.useCallback)(e=>{n(e),h()},[n,h]),S=Ig(e,t);return(0,B.jsxs)(`div`,{ref:s,className:`conv-focus-compact`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||a(!1)},children:[(0,B.jsxs)(`button`,{type:`button`,className:`conv-focus-compact-toggle`,"aria-haspopup":`menu`,"aria-expanded":i,"aria-label":`Focus: ${S}`,onClick:v,onKeyDown:b,children:[`Focus: `,S,` ▾`]}),i&&(0,B.jsx)(`div`,{className:`conv-focus-compact-menu`,role:`menu`,"aria-label":`Focus mode`,tabIndex:-1,onKeyDown:y,children:c.map((t,n)=>(0,B.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t.mode,tabIndex:n===d?0:-1,ref:e=>{u.current[n]=e},className:[`conv-focus-compact-item`,e===t.mode?`conv-focus-compact-item--on`:``].filter(Boolean).join(` `),onClick:()=>x(t.mode),children:[t.label,t.badge!=null&&(0,B.jsx)(`span`,{className:`conv-focus-compact-badge`,children:t.badge})]},t.mode))})]})}function Rg({sessionId:e,exportTitle:t,onCompare:n,onLatest:r,latestBusy:i=!1,onExpandAll:a,onCollapseAll:o,completionTotal:s=null,costCumulative:c=0,costTotal:l=0,costApprox:u=!1}){let[d,f]=(0,_.useState)(!1),p=(0,_.useRef)(null),m=(0,_.useRef)(null);wg(m,d,(0,_.useCallback)(()=>f(!1),[]));let h=[{key:`compare`,label:`⟷ Compare with…`,run:n},r?{key:`latest`,label:`${i?`… `:``}Latest ↓`,run:r,busy:i}:null,{key:`expand`,label:`⤢ Expand all`,run:a},{key:`collapse`,label:`⤡ Collapse all`,run:o}].filter(Boolean),g=h.length,v=(0,_.useRef)([]),[y,b]=(0,_.useState)(0),x=(0,_.useRef)(0),S=(0,_.useCallback)(e=>{x.current=e,b(e)},[]);(0,_.useEffect)(()=>{f(!1)},[e]);let C=(0,_.useCallback)(()=>{f(!1);let e=p.current;e instanceof HTMLElement&&e.focus()},[]),w=(0,_.useCallback)(e=>{p.current=document.activeElement,S(e),f(!0)},[S]),T=(0,_.useCallback)(()=>{d?f(!1):w(0)},[d,w]);(0,_.useEffect)(()=>{d&&v.current[x.current]?.focus()},[d]);let E=(0,_.useCallback)(e=>{if(e.key===`Escape`){e.stopPropagation(),C();return}let t=Cg(e.key,x.current,g);t!==null&&(e.preventDefault(),S(t),v.current[t]?.focus())},[C,g,S]),D=(0,_.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),w(0)):e.key===`ArrowUp`&&(e.preventDefault(),w(g-1))},[w,g]),O=(0,_.useCallback)(e=>{e(),C()},[C]),k=l>0,A=s!=null;return(0,B.jsxs)(`div`,{ref:m,className:`conv-overflow`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||f(!1)},children:[(0,B.jsx)(`button`,{type:`button`,className:`conv-overflow-toggle`,"aria-haspopup":`menu`,"aria-expanded":d,"aria-label":`More actions`,title:`More actions`,onClick:T,onKeyDown:D,children:`⋯`}),d&&(0,B.jsxs)(`div`,{className:`conv-overflow-menu`,role:`menu`,"aria-label":`More actions`,tabIndex:-1,onKeyDown:E,children:[(A||k)&&(0,B.jsxs)(`div`,{className:`conv-overflow-summary`,role:`none`,children:[A&&(0,B.jsxs)(`div`,{className:`conv-overflow-summary-row`,role:`none`,children:[(0,B.jsx)(`span`,{className:`conv-overflow-summary-label`,children:`Completion`}),(0,B.jsxs)(`span`,{className:`conv-overflow-summary-value`,children:[`✓ `,s]})]}),k&&(0,B.jsxs)(`div`,{className:`conv-overflow-summary-row`,role:`none`,children:[(0,B.jsx)(`span`,{className:`conv-overflow-summary-label`,children:`Cost`}),(0,B.jsxs)(`span`,{className:`conv-overflow-summary-value`,children:[u?`~`:``,F.usd2(c),` / `,F.usd2(l)]})]})]}),(0,B.jsx)(`div`,{className:`conv-overflow-export`,role:`none`,children:(0,B.jsx)(Ag,{sessionId:e,title:t})}),h.map((e,t)=>(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,tabIndex:t===y?0:-1,ref:e=>{v.current[t]=e},className:`conv-overflow-item`,disabled:e.busy,onClick:()=>O(e.run),children:e.label},e.key))]})]})}var zg=(0,_.createContext)(null);function Bg(e){let t=[],n=String(e||``),r=n.indexOf(`,`),i=0,a=!1;for(;!a;){r===-1&&(r=n.length,a=!0);let e=n.slice(i,r).trim();(e||!a)&&t.push(e),i=r+1,r=n.indexOf(`,`,i)}return t}function Vg(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var Hg=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Ug=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Wg={};function Gg(e,t){return((t||Wg).jsx?Ug:Hg).test(e)}var Kg=/[ \t\n\f\r]/g;function qg(e){return typeof e==`object`?e.type===`text`?Jg(e.value):!1:Jg(e)}function Jg(e){return e.replace(Kg,``)===``}var Yg=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};Yg.prototype.normal={},Yg.prototype.property={},Yg.prototype.space=void 0;function Xg(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new Yg(n,r,t)}function Zg(e){return e.toLowerCase()}var Qg=class{constructor(e,t){this.attribute=t,this.property=e}};Qg.prototype.attribute=``,Qg.prototype.booleanish=!1,Qg.prototype.boolean=!1,Qg.prototype.commaOrSpaceSeparated=!1,Qg.prototype.commaSeparated=!1,Qg.prototype.defined=!1,Qg.prototype.mustUseProperty=!1,Qg.prototype.number=!1,Qg.prototype.overloadedBoolean=!1,Qg.prototype.property=``,Qg.prototype.spaceSeparated=!1,Qg.prototype.space=void 0;var $g=s({boolean:()=>Z,booleanish:()=>t_,commaOrSpaceSeparated:()=>a_,commaSeparated:()=>i_,number:()=>Q,overloadedBoolean:()=>n_,spaceSeparated:()=>r_}),e_=0,Z=o_(),t_=o_(),n_=o_(),Q=o_(),r_=o_(),i_=o_(),a_=o_();function o_(){return 2**++e_}var s_=Object.keys($g),c_=class extends Qg{constructor(e,t,n,r){let i=-1;if(super(e,t),l_(this,`space`,r),typeof n==`number`)for(;++i<s_.length;){let e=s_[i];l_(this,s_[i],(n&$g[e])===$g[e])}}};c_.prototype.defined=!0;function l_(e,t,n){n&&(e[t]=n)}function u_(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new c_(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[Zg(r)]=r,n[Zg(a.attribute)]=r}return new Yg(t,n,e.space)}var d_=u_({properties:{ariaActiveDescendant:null,ariaAtomic:t_,ariaAutoComplete:null,ariaBusy:t_,ariaChecked:t_,ariaColCount:Q,ariaColIndex:Q,ariaColSpan:Q,ariaControls:r_,ariaCurrent:null,ariaDescribedBy:r_,ariaDetails:null,ariaDisabled:t_,ariaDropEffect:r_,ariaErrorMessage:null,ariaExpanded:t_,ariaFlowTo:r_,ariaGrabbed:t_,ariaHasPopup:null,ariaHidden:t_,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:r_,ariaLevel:Q,ariaLive:null,ariaModal:t_,ariaMultiLine:t_,ariaMultiSelectable:t_,ariaOrientation:null,ariaOwns:r_,ariaPlaceholder:null,ariaPosInSet:Q,ariaPressed:t_,ariaReadOnly:t_,ariaRelevant:null,ariaRequired:t_,ariaRoleDescription:r_,ariaRowCount:Q,ariaRowIndex:Q,ariaRowSpan:Q,ariaSelected:t_,ariaSetSize:Q,ariaSort:null,ariaValueMax:Q,ariaValueMin:Q,ariaValueNow:Q,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function f_(e,t){return t in e?e[t]:t}function p_(e,t){return f_(e,t.toLowerCase())}var m_=u_({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:i_,acceptCharset:r_,accessKey:r_,action:null,allow:null,allowFullScreen:Z,allowPaymentRequest:Z,allowUserMedia:Z,alpha:Z,alt:null,as:null,async:Z,autoCapitalize:null,autoComplete:r_,autoFocus:Z,autoPlay:Z,blocking:r_,capture:null,charSet:null,checked:Z,cite:null,className:r_,closedBy:null,colorSpace:null,cols:Q,colSpan:Q,command:null,commandFor:null,content:null,contentEditable:t_,controls:Z,controlsList:r_,coords:Q|i_,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Z,defer:Z,dir:null,dirName:null,disabled:Z,download:n_,draggable:t_,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Z,formTarget:null,headers:r_,height:Q,hidden:n_,high:Q,href:null,hrefLang:null,htmlFor:r_,httpEquiv:r_,id:null,imageSizes:null,imageSrcSet:null,inert:Z,inputMode:null,integrity:null,is:null,isMap:Z,itemId:null,itemProp:r_,itemRef:r_,itemScope:Z,itemType:r_,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Z,low:Q,manifest:null,max:null,maxLength:Q,media:null,method:null,min:null,minLength:Q,multiple:Z,muted:Z,name:null,nonce:null,noModule:Z,noValidate:Z,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Z,optimum:Q,pattern:null,ping:r_,placeholder:null,playsInline:Z,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Z,referrerPolicy:null,rel:r_,required:Z,reversed:Z,rows:Q,rowSpan:Q,sandbox:r_,scope:null,scoped:Z,seamless:Z,selected:Z,shadowRootClonable:Z,shadowRootCustomElementRegistry:Z,shadowRootDelegatesFocus:Z,shadowRootMode:null,shadowRootSerializable:Z,shape:null,size:Q,sizes:null,slot:null,span:Q,spellCheck:t_,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Q,step:null,style:null,tabIndex:Q,target:null,title:null,translate:null,type:null,typeMustMatch:Z,useMap:null,value:t_,width:Q,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:r_,axis:null,background:null,bgColor:null,border:Q,borderColor:null,bottomMargin:Q,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Z,declare:Z,event:null,face:null,frame:null,frameBorder:null,hSpace:Q,leftMargin:Q,link:null,longDesc:null,lowSrc:null,marginHeight:Q,marginWidth:Q,noResize:Z,noHref:Z,noShade:Z,noWrap:Z,object:null,profile:null,prompt:null,rev:null,rightMargin:Q,rules:null,scheme:null,scrolling:t_,standby:null,summary:null,text:null,topMargin:Q,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Q,allowTransparency:null,autoCorrect:null,autoSave:null,credentialless:Z,disablePictureInPicture:Z,disableRemotePlayback:Z,exportParts:i_,part:r_,prefix:null,property:null,results:Q,security:null,unselectable:null},space:`html`,transform:p_}),h_=u_({attributes:{accentHeight:`accent-height`,alignmentBaseline:`alignment-baseline`,arabicForm:`arabic-form`,baselineShift:`baseline-shift`,capHeight:`cap-height`,className:`class`,clipPath:`clip-path`,clipRule:`clip-rule`,colorInterpolation:`color-interpolation`,colorInterpolationFilters:`color-interpolation-filters`,colorProfile:`color-profile`,colorRendering:`color-rendering`,crossOrigin:`crossorigin`,dataType:`datatype`,dominantBaseline:`dominant-baseline`,enableBackground:`enable-background`,fillOpacity:`fill-opacity`,fillRule:`fill-rule`,floodColor:`flood-color`,floodOpacity:`flood-opacity`,fontFamily:`font-family`,fontSize:`font-size`,fontSizeAdjust:`font-size-adjust`,fontStretch:`font-stretch`,fontStyle:`font-style`,fontVariant:`font-variant`,fontWeight:`font-weight`,glyphName:`glyph-name`,glyphOrientationHorizontal:`glyph-orientation-horizontal`,glyphOrientationVertical:`glyph-orientation-vertical`,hrefLang:`hreflang`,horizAdvX:`horiz-adv-x`,horizOriginX:`horiz-origin-x`,horizOriginY:`horiz-origin-y`,imageRendering:`image-rendering`,letterSpacing:`letter-spacing`,lightingColor:`lighting-color`,markerEnd:`marker-end`,markerMid:`marker-mid`,markerStart:`marker-start`,maskType:`mask-type`,navDown:`nav-down`,navDownLeft:`nav-down-left`,navDownRight:`nav-down-right`,navLeft:`nav-left`,navNext:`nav-next`,navPrev:`nav-prev`,navRight:`nav-right`,navUp:`nav-up`,navUpLeft:`nav-up-left`,navUpRight:`nav-up-right`,onAbort:`onabort`,onActivate:`onactivate`,onAfterPrint:`onafterprint`,onBeforePrint:`onbeforeprint`,onBegin:`onbegin`,onCancel:`oncancel`,onCanPlay:`oncanplay`,onCanPlayThrough:`oncanplaythrough`,onChange:`onchange`,onClick:`onclick`,onClose:`onclose`,onCopy:`oncopy`,onCueChange:`oncuechange`,onCut:`oncut`,onDblClick:`ondblclick`,onDrag:`ondrag`,onDragEnd:`ondragend`,onDragEnter:`ondragenter`,onDragExit:`ondragexit`,onDragLeave:`ondragleave`,onDragOver:`ondragover`,onDragStart:`ondragstart`,onDrop:`ondrop`,onDurationChange:`ondurationchange`,onEmptied:`onemptied`,onEnd:`onend`,onEnded:`onended`,onError:`onerror`,onFocus:`onfocus`,onFocusIn:`onfocusin`,onFocusOut:`onfocusout`,onHashChange:`onhashchange`,onInput:`oninput`,onInvalid:`oninvalid`,onKeyDown:`onkeydown`,onKeyPress:`onkeypress`,onKeyUp:`onkeyup`,onLoad:`onload`,onLoadedData:`onloadeddata`,onLoadedMetadata:`onloadedmetadata`,onLoadStart:`onloadstart`,onMessage:`onmessage`,onMouseDown:`onmousedown`,onMouseEnter:`onmouseenter`,onMouseLeave:`onmouseleave`,onMouseMove:`onmousemove`,onMouseOut:`onmouseout`,onMouseOver:`onmouseover`,onMouseUp:`onmouseup`,onMouseWheel:`onmousewheel`,onOffline:`onoffline`,onOnline:`ononline`,onPageHide:`onpagehide`,onPageShow:`onpageshow`,onPaste:`onpaste`,onPause:`onpause`,onPlay:`onplay`,onPlaying:`onplaying`,onPopState:`onpopstate`,onProgress:`onprogress`,onRateChange:`onratechange`,onRepeat:`onrepeat`,onReset:`onreset`,onResize:`onresize`,onScroll:`onscroll`,onSeeked:`onseeked`,onSeeking:`onseeking`,onSelect:`onselect`,onShow:`onshow`,onStalled:`onstalled`,onStorage:`onstorage`,onSubmit:`onsubmit`,onSuspend:`onsuspend`,onTimeUpdate:`ontimeupdate`,onToggle:`ontoggle`,onUnload:`onunload`,onVolumeChange:`onvolumechange`,onWaiting:`onwaiting`,onZoom:`onzoom`,overlinePosition:`overline-position`,overlineThickness:`overline-thickness`,paintOrder:`paint-order`,panose1:`panose-1`,pointerEvents:`pointer-events`,referrerPolicy:`referrerpolicy`,renderingIntent:`rendering-intent`,shapeRendering:`shape-rendering`,stopColor:`stop-color`,stopOpacity:`stop-opacity`,strikethroughPosition:`strikethrough-position`,strikethroughThickness:`strikethrough-thickness`,strokeDashArray:`stroke-dasharray`,strokeDashOffset:`stroke-dashoffset`,strokeLineCap:`stroke-linecap`,strokeLineJoin:`stroke-linejoin`,strokeMiterLimit:`stroke-miterlimit`,strokeOpacity:`stroke-opacity`,strokeWidth:`stroke-width`,tabIndex:`tabindex`,textAnchor:`text-anchor`,textDecoration:`text-decoration`,textRendering:`text-rendering`,transformOrigin:`transform-origin`,typeOf:`typeof`,underlinePosition:`underline-position`,underlineThickness:`underline-thickness`,unicodeBidi:`unicode-bidi`,unicodeRange:`unicode-range`,unitsPerEm:`units-per-em`,vAlphabetic:`v-alphabetic`,vHanging:`v-hanging`,vIdeographic:`v-ideographic`,vMathematical:`v-mathematical`,vectorEffect:`vector-effect`,vertAdvY:`vert-adv-y`,vertOriginX:`vert-origin-x`,vertOriginY:`vert-origin-y`,wordSpacing:`word-spacing`,writingMode:`writing-mode`,xHeight:`x-height`,playbackOrder:`playbackorder`,timelineBegin:`timelinebegin`},properties:{about:a_,accentHeight:Q,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Q,amplitude:Q,arabicForm:null,ascent:Q,attributeName:null,attributeType:null,azimuth:Q,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Q,by:null,calcMode:null,capHeight:Q,className:r_,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Q,diffuseConstant:Q,direction:null,display:null,dur:null,divisor:Q,dominantBaseline:null,download:Z,dx:null,dy:null,edgeMode:null,editable:null,elevation:Q,enableBackground:null,end:null,event:null,exponent:Q,externalResourcesRequired:null,fill:null,fillOpacity:Q,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:i_,g2:i_,glyphName:i_,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Q,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Q,horizOriginX:Q,horizOriginY:Q,id:null,ideographic:Q,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Q,k:Q,k1:Q,k2:Q,k3:Q,k4:Q,kernelMatrix:a_,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Q,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskType:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Q,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Q,overlineThickness:Q,paintOrder:null,panose1:null,path:null,pathLength:Q,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:r_,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Q,pointsAtY:Q,pointsAtZ:Q,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:a_,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:a_,rev:a_,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:a_,requiredFeatures:a_,requiredFonts:a_,requiredFormats:a_,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Q,specularExponent:Q,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Q,strikethroughThickness:Q,string:null,stroke:null,strokeDashArray:a_,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Q,strokeOpacity:Q,strokeWidth:null,style:null,surfaceScale:Q,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:a_,tabIndex:Q,tableValues:null,target:null,targetX:Q,targetY:Q,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:a_,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Q,underlineThickness:Q,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Q,values:null,vAlphabetic:Q,vMathematical:Q,vectorEffect:null,vHanging:Q,vIdeographic:Q,version:null,vertAdvY:Q,vertOriginX:Q,vertOriginY:Q,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Q,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:`svg`,transform:f_}),g_=u_({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:`xlink`,transform(e,t){return`xlink:`+t.slice(5).toLowerCase()}}),__=u_({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:p_}),v_=u_({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),y_={classId:`classID`,dataType:`datatype`,itemId:`itemID`,strokeDashArray:`strokeDasharray`,strokeDashOffset:`strokeDashoffset`,strokeLineCap:`strokeLinecap`,strokeLineJoin:`strokeLinejoin`,strokeMiterLimit:`strokeMiterlimit`,typeOf:`typeof`,xLinkActuate:`xlinkActuate`,xLinkArcRole:`xlinkArcrole`,xLinkHref:`xlinkHref`,xLinkRole:`xlinkRole`,xLinkShow:`xlinkShow`,xLinkTitle:`xlinkTitle`,xLinkType:`xlinkType`,xmlnsXLink:`xmlnsXlink`},b_=/[A-Z]/g,x_=/-[a-z]/g,S_=/^data[-\w.:]+$/i;function C_(e,t){let n=Zg(t),r=t,i=Qg;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&S_.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(x_,T_);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!x_.test(e)){let n=e.replace(b_,w_);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=c_}return new i(r,t)}function w_(e){return`-`+e.toLowerCase()}function T_(e){return e.charAt(1).toUpperCase()}var E_=Xg([d_,m_,g_,__,v_],`html`),D_=Xg([d_,h_,g_,__,v_],`svg`);function O_(e){let t=String(e||``).trim();return t?t.split(/[ \t\n\r\f]+/g):[]}function k_(e){return e.join(` `).trim()}var A_=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=`
|
|
19
19
|
`,d=`/`,f=`*`,p=``,m=`comment`,h=`declaration`;function g(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var l=1,g=1;function v(e){var t=e.match(r);t&&(l+=t.length);var n=e.lastIndexOf(u);g=~n?e.length-n:g+e.length}function y(){var e={line:l,column:g};return function(t){return t.position=new b(e),C(),t}}function b(e){this.start=e,this.end={line:l,column:g},this.source=t.source}b.prototype.content=e;function x(n){var r=Error(t.source+`:`+l+`:`+g+`: `+n);if(r.reason=n,r.filename=t.source,r.line=l,r.column=g,r.source=e,!t.silent)throw r}function S(t){var n=t.exec(e);if(n){var r=n[0];return v(r),e=e.slice(r.length),n}}function C(){S(i)}function w(e){var t;for(e||=[];t=T();)t!==!1&&e.push(t);return e}function T(){var t=y();if(!(d!=e.charAt(0)||f!=e.charAt(1))){for(var n=2;p!=e.charAt(n)&&(f!=e.charAt(n)||d!=e.charAt(n+1));)++n;if(n+=2,p===e.charAt(n-1))return x(`End of comment missing`);var r=e.slice(2,n-2);return g+=2,v(r),e=e.slice(n),g+=2,t({type:m,comment:r})}}function E(){var e=y(),t=S(a);if(t){if(T(),!S(o))return x(`property missing ':'`);var r=S(s),i=e({type:h,property:_(t[0].replace(n,p)),value:r?_(r[0].replace(n,p)):p});return S(c),i}}function D(){var e=[];w(e);for(var t;t=E();)t!==!1&&(e.push(t),w(e));return e}return C(),D()}function _(e){return e?e.replace(l,p):p}t.exports=g})),j_=o((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var n=t(A_());function r(e,t){let r=null;if(!e||typeof e!=`string`)return r;let i=(0,n.default)(e),a=typeof t==`function`;return i.forEach(e=>{if(e.type!==`declaration`)return;let{property:n,value:i}=e;a?t(n,i,e):i&&(r||={},r[n]=i)}),r}})),M_=o((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.camelCase=void 0;var t=/^--[a-zA-Z0-9_-]+$/,n=/-([a-z])/g,r=/^[^-]+$/,i=/^-(webkit|moz|ms|o|khtml)-/,a=/^-(ms)-/,o=function(e){return!e||r.test(e)||t.test(e)},s=function(e,t){return t.toUpperCase()},c=function(e,t){return`${t}-`};e.camelCase=function(e,t){return t===void 0&&(t={}),o(e)?e:(e=e.toLowerCase(),e=t.reactCompat?e.replace(a,c):e.replace(i,c),e.replace(n,s))}})),N_=o(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(j_()),r=M_();function i(e,t){var i={};return!e||typeof e!=`string`||(0,n.default)(e,function(e,n){e&&n&&(i[(0,r.camelCase)(e,t)]=n)}),i}i.default=i,t.exports=i})),P_=I_(`end`),F_=I_(`start`);function I_(e){return t;function t(t){let n=t&&t.position&&t.position[e]||{};if(typeof n.line==`number`&&n.line>0&&typeof n.column==`number`&&n.column>0)return{line:n.line,column:n.column,offset:typeof n.offset==`number`&&n.offset>-1?n.offset:void 0}}}function L_(e){let t=F_(e),n=P_(e);if(t&&n)return{start:t,end:n}}function R_(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?B_(e.position):`start`in e||`end`in e?B_(e):`line`in e||`column`in e?z_(e):``}function z_(e){return V_(e&&e.line)+`:`+V_(e&&e.column)}function B_(e){return z_(e&&e.start)+`-`+z_(e&&e.end)}function V_(e){return e&&typeof e==`number`?e:1}var H_=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=R_(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};H_.prototype.file=``,H_.prototype.name=``,H_.prototype.reason=``,H_.prototype.message=``,H_.prototype.stack=``,H_.prototype.column=void 0,H_.prototype.line=void 0,H_.prototype.ancestors=void 0,H_.prototype.cause=void 0,H_.prototype.fatal=void 0,H_.prototype.place=void 0,H_.prototype.ruleId=void 0,H_.prototype.source=void 0;var U_=l(N_(),1),W_={}.hasOwnProperty,G_=new Map,K_=/[A-Z]/g,q_=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),J_=new Set([`td`,`th`]);function Y_(e,t){if(!t||t.Fragment===void 0)throw TypeError("Expected `Fragment` in options");let n=t.filePath||void 0,r;if(t.development){if(typeof t.jsxDEV!=`function`)throw TypeError("Expected `jsxDEV` in options when `development: true`");r=ov(n,t.jsxDEV)}else{if(typeof t.jsx!=`function`)throw TypeError("Expected `jsx` in production options");if(typeof t.jsxs!=`function`)throw TypeError("Expected `jsxs` in production options");r=av(n,t.jsx,t.jsxs)}let i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||`react`,evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space===`svg`?D_:E_,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=X_(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function X_(e,t,n){if(t.type===`element`)return Z_(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return Q_(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return ev(e,t,n);if(t.type===`mdxjsEsm`)return $_(e,t);if(t.type===`root`)return tv(e,t,n);if(t.type===`text`)return nv(e,t)}function Z_(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=D_,e.schema=i),e.ancestors.push(t);let a=fv(e,t.tagName,!1),o=sv(e,t),s=lv(e,t);return q_.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!qg(e):!0})),rv(e,o,a,t),iv(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function Q_(e,t){if(t.data&&t.data.estree&&e.evaluater){let n=t.data.estree.body[0];return n.type,e.evaluater.evaluateExpression(n.expression)}pv(e,t.position)}function $_(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);pv(e,t.position)}function ev(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=D_,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:fv(e,t.name,!0),o=cv(e,t),s=lv(e,t);return rv(e,o,a,t),iv(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function tv(e,t,n){let r={};return iv(r,lv(e,t)),e.create(t,e.Fragment,r,n)}function nv(e,t){return t.value}function rv(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function iv(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function av(e,t,n){return r;function r(e,r,i,a){let o=Array.isArray(i.children)?n:t;return a?o(r,i,a):o(r,i)}}function ov(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=F_(n);return t(r,i,a,o,{columnNumber:s?s.column-1:void 0,fileName:e,lineNumber:s?s.line:void 0},void 0)}}function sv(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&W_.call(t.properties,i)){let a=uv(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&J_.has(t.tagName)?r=o:n[i]=o}}if(r){let t=n.style||={};t[e.stylePropertyNameCase===`css`?`text-align`:`textAlign`]=r}return n}function cv(e,t){let n={};for(let r of t.attributes)if(r.type===`mdxJsxExpressionAttribute`)if(r.data&&r.data.estree&&e.evaluater){let t=r.data.estree.body[0];t.type;let i=t.expression;i.type;let a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else pv(e,t.position);else{let i=r.name,a;if(r.value&&typeof r.value==`object`)if(r.value.data&&r.value.data.estree&&e.evaluater){let t=r.value.data.estree.body[0];t.type,a=e.evaluater.evaluateExpression(t.expression)}else pv(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function lv(e,t){let n=[],r=-1,i=e.passKeys?new Map:G_;for(;++r<t.children.length;){let a=t.children[r],o;if(e.passKeys){let e=a.type===`element`?a.tagName:a.type===`mdxJsxFlowElement`||a.type===`mdxJsxTextElement`?a.name:void 0;if(e){let t=i.get(e)||0;o=e+`-`+t,i.set(e,t+1)}}let s=X_(e,a,o);s!==void 0&&n.push(s)}return n}function uv(e,t,n){let r=C_(e.schema,t);if(!(n==null||typeof n==`number`&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?Vg(n):k_(n)),r.property===`style`){let t=typeof n==`object`?n:dv(e,String(n));return e.stylePropertyNameCase===`css`&&(t=mv(t)),[`style`,t]}return[e.elementAttributeNameCase===`react`&&r.space?y_[r.property]||r.property:r.attribute,n]}}function dv(e,t){try{return(0,U_.default)(t,{reactCompat:!0})}catch(t){if(e.ignoreInvalidStyle)return{};let n=t,r=new H_("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:n,ruleId:`style`,source:`hast-util-to-jsx-runtime`});throw r.file=e.filePath||void 0,r.url=`https://github.com/syntax-tree/hast-util-to-jsx-runtime#cannot-parse-style-attribute`,r}}function fv(e,t,n){let r;if(!n)r={type:`Literal`,value:t};else if(t.includes(`.`)){let e=t.split(`.`),n=-1,i;for(;++n<e.length;){let t=Gg(e[n])?{type:`Identifier`,name:e[n]}:{type:`Literal`,value:e[n]};i=i?{type:`MemberExpression`,object:i,property:t,computed:!!(n&&t.type===`Literal`),optional:!1}:t}r=i}else r=Gg(t)&&!/^[a-z]/.test(t)?{type:`Identifier`,name:t}:{type:`Literal`,value:t};if(r.type===`Literal`){let t=r.value;return W_.call(e.components,t)?e.components[t]:t}if(e.evaluater)return e.evaluater.evaluateExpression(r);pv(e)}function pv(e,t){let n=new H_("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:`mdx-estree`,source:`hast-util-to-jsx-runtime`});throw n.file=e.filePath||void 0,n.url=`https://github.com/syntax-tree/hast-util-to-jsx-runtime#cannot-handle-mdx-estrees-without-createevaluater`,n}function mv(e){let t={},n;for(n in e)W_.call(e,n)&&(t[hv(n)]=e[n]);return t}function hv(e){let t=e.replace(K_,gv);return t.slice(0,3)===`ms-`&&(t=`-`+t),t}function gv(e){return`-`+e.toLowerCase()}var _v={action:[`form`],cite:[`blockquote`,`del`,`ins`,`q`],data:[`object`],formAction:[`button`,`input`],href:[`a`,`area`,`base`,`link`],icon:[`menuitem`],itemId:null,manifest:[`html`],ping:[`a`,`area`],poster:[`video`],src:[`audio`,`embed`,`iframe`,`img`,`input`,`script`,`source`,`track`,`video`]},vv={};function yv(e,t){let n=t||vv;return bv(e,typeof n.includeImageAlt==`boolean`?n.includeImageAlt:!0,typeof n.includeHtml==`boolean`?n.includeHtml:!0)}function bv(e,t,n){if(Sv(e)){if(`value`in e)return e.type===`html`&&!n?``:e.value;if(t&&`alt`in e&&e.alt)return e.alt;if(`children`in e)return xv(e.children,t,n)}return Array.isArray(e)?xv(e,t,n):``}function xv(e,t,n){let r=[],i=-1;for(;++i<e.length;)r[i]=bv(e[i],t,n);return r.join(``)}function Sv(e){return!!(e&&typeof e==`object`)}var Cv=document.createElement(`i`);function wv(e){let t=`&`+e+`;`;Cv.innerHTML=t;let n=Cv.textContent;return n.charCodeAt(n.length-1)===59&&e!==`semi`||n===t?!1:n}function Tv(e,t,n,r){let i=e.length,a=0,o;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a<r.length;)o=r.slice(a,a+1e4),o.unshift(t,0),e.splice(...o),a+=1e4,t+=1e4}function Ev(e,t){return e.length>0?(Tv(e,e.length,0,t),e):t}var Dv={}.hasOwnProperty;function Ov(e){let t={},n=-1;for(;++n<e.length;)kv(t,e[n]);return t}function kv(e,t){let n;for(n in t){let r=(Dv.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n],a;if(i)for(a in i){Dv.call(r,a)||(r[a]=[]);let e=i[a];Av(r[a],Array.isArray(e)?e:e?[e]:[])}}}function Av(e,t){let n=-1,r=[];for(;++n<t.length;)(t[n].add===`after`?e:r).push(t[n]);Tv(e,0,0,r)}function jv(e,t){let n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function Mv(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var Nv=Wv(/[A-Za-z]/),Pv=Wv(/[\dA-Za-z]/),Fv=Wv(/[#-'*+\--9=?A-Z^-~]/);function Iv(e){return e!==null&&(e<32||e===127)}var Lv=Wv(/\d/),Rv=Wv(/[\dA-Fa-f]/),zv=Wv(/[!-/:-@[-`{-~]/);function $(e){return e!==null&&e<-2}function Bv(e){return e!==null&&(e<0||e===32)}function Vv(e){return e===-2||e===-1||e===32}var Hv=Wv(/\p{P}|\p{S}/u),Uv=Wv(/\s/);function Wv(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function Gv(e){let t=[],n=-1,r=0,i=0;for(;++n<e.length;){let a=e.charCodeAt(n),o=``;if(a===37&&Pv(e.charCodeAt(n+1))&&Pv(e.charCodeAt(n+2)))i=2;else if(a<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(a))||(o=String.fromCharCode(a));else if(a>55295&&a<57344){let t=e.charCodeAt(n+1);a<56320&&t>56319&&t<57344?(o=String.fromCharCode(a,t),i=1):o=`�`}else o=String.fromCharCode(a);o&&=(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,``),i&&=(n+=i,0)}return t.join(``)+e.slice(r)}function Kv(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return Vv(r)?(e.enter(n),s(r)):t(r)}function s(r){return Vv(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}var qv={tokenize:Jv};function Jv(e){let t=e.attempt(this.parser.constructs.contentInitial,r,i),n;return t;function r(n){if(n===null){e.consume(n);return}return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),Kv(e,t,`linePrefix`)}function i(t){return e.enter(`paragraph`),a(t)}function a(t){let r=e.enter(`chunkText`,{contentType:`text`,previous:n});return n&&(n.next=r),n=r,o(t)}function o(t){if(t===null){e.exit(`chunkText`),e.exit(`paragraph`),e.consume(t);return}return $(t)?(e.consume(t),e.exit(`chunkText`),a):(e.consume(t),o)}}var Yv={tokenize:Zv},Xv={tokenize:Qv};function Zv(e){let t=this,n=[],r=0,i,a,o;return s;function s(i){if(r<n.length){let a=n[r];return t.containerState=a[1],e.attempt(a[0].continuation,c,l)(i)}return l(i)}function c(e){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&v();let n=t.events.length,a=n,o;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){o=t.events[a][1].end;break}_(r);let s=n;for(;s<t.events.length;)t.events[s][1].end={...o},s++;return Tv(t.events,a+1,0,t.events.slice(n)),t.events.length=s,l(e)}return s(e)}function l(a){if(r===n.length){if(!i)return f(a);if(i.currentConstruct&&i.currentConstruct.concrete)return m(a);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(Xv,u,d)(a)}function u(e){return i&&v(),_(r),f(e)}function d(e){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(e)}function f(n){return t.containerState={},e.attempt(Xv,p,m)(n)}function p(e){return r++,n.push([t.currentConstruct,t.containerState]),f(e)}function m(n){if(n===null){i&&v(),_(0),e.consume(n);return}return i||=t.parser.flow(t.now()),e.enter(`chunkFlow`,{_tokenizer:i,contentType:`flow`,previous:a}),h(n)}function h(n){if(n===null){g(e.exit(`chunkFlow`),!0),_(0),e.consume(n);return}return $(n)?(e.consume(n),g(e.exit(`chunkFlow`)),r=0,t.interrupt=void 0,s):(e.consume(n),h)}function g(e,n){let s=t.sliceStream(e);if(n&&s.push(null),e.previous=a,a&&(a.next=e),a=e,i.defineSkip(e.start),i.write(s),t.parser.lazy[e.start.line]){let e=i.events.length;for(;e--;)if(i.events[e][1].start.offset<o&&(!i.events[e][1].end||i.events[e][1].end.offset>o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;e<t.events.length;)t.events[e][1].end={...c},e++;Tv(t.events,a+1,0,t.events.slice(n)),t.events.length=e}}function _(r){let i=n.length;for(;i-- >r;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Qv(e,t,n){return Kv(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function $v(e){if(e===null||Bv(e)||Uv(e))return 1;if(Hv(e))return 2}function ey(e,t,n){let r=[],i=-1;for(;++i<e.length;){let a=e[i].resolveAll;a&&!r.includes(a)&&(t=a(t,n),r.push(a))}return t}var ty={name:`attention`,resolveAll:ny,tokenize:ry};function ny(e,t){let n=-1,r,i,a,o,s,c,l,u;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`attentionSequence`&&e[n][1]._close){for(r=n;r--;)if(e[r][0]===`exit`&&e[r][1].type===`attentionSequence`&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;c=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;let d={...e[r][1].end},f={...e[n][1].start};iy(d,-c),iy(f,c),o={type:c>1?`strongSequence`:`emphasisSequence`,start:d,end:{...e[r][1].end}},s={type:c>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:f},a={type:c>1?`strongText`:`emphasisText`,start:{...e[r][1].end},end:{...e[n][1].start}},i={type:c>1?`strong`:`emphasis`,start:{...o.start},end:{...s.end}},e[r][1].end={...o.start},e[n][1].start={...s.end},l=[],e[r][1].end.offset-e[r][1].start.offset&&(l=Ev(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=Ev(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=Ev(l,ey(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=Ev(l,[[`exit`,a,t],[`enter`,s,t],[`exit`,s,t],[`exit`,i,t]]),e[n][1].end.offset-e[n][1].start.offset?(u=2,l=Ev(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,Tv(e,r-1,n-r+3,l),n=r+l.length-u-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`attentionSequence`&&(e[n][1].type=`data`);return e}function ry(e,t){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=$v(r),a;return o;function o(t){return a=t,e.enter(`attentionSequence`),s(t)}function s(o){if(o===a)return e.consume(o),s;let c=e.exit(`attentionSequence`),l=$v(o),u=!l||l===2&&i||n.includes(o),d=!i||i===2&&l||n.includes(r);return c._open=!!(a===42?u:u&&(i||!d)),c._close=!!(a===42?d:d&&(l||!u)),t(o)}}function iy(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}var ay={name:`autolink`,tokenize:oy};function oy(e,t,n){let r=0;return i;function i(t){return e.enter(`autolink`),e.enter(`autolinkMarker`),e.consume(t),e.exit(`autolinkMarker`),e.enter(`autolinkProtocol`),a}function a(t){return Nv(t)?(e.consume(t),o):t===64?n(t):l(t)}function o(e){return e===43||e===45||e===46||Pv(e)?(r=1,s(e)):l(e)}function s(t){return t===58?(e.consume(t),r=0,c):(t===43||t===45||t===46||Pv(t))&&r++<32?(e.consume(t),s):(r=0,l(t))}function c(r){return r===62?(e.exit(`autolinkProtocol`),e.enter(`autolinkMarker`),e.consume(r),e.exit(`autolinkMarker`),e.exit(`autolink`),t):r===null||r===32||r===60||Iv(r)?n(r):(e.consume(r),c)}function l(t){return t===64?(e.consume(t),u):Fv(t)?(e.consume(t),l):n(t)}function u(e){return Pv(e)?d(e):n(e)}function d(n){return n===46?(e.consume(n),r=0,u):n===62?(e.exit(`autolinkProtocol`).type=`autolinkEmail`,e.enter(`autolinkMarker`),e.consume(n),e.exit(`autolinkMarker`),e.exit(`autolink`),t):f(n)}function f(t){if((t===45||Pv(t))&&r++<63){let n=t===45?f:d;return e.consume(t),n}return n(t)}}var sy={partial:!0,tokenize:cy};function cy(e,t,n){return r;function r(t){return Vv(t)?Kv(e,i,`linePrefix`)(t):i(t)}function i(e){return e===null||$(e)?t(e):n(e)}}var ly={continuation:{tokenize:dy},exit:fy,name:`blockQuote`,tokenize:uy};function uy(e,t,n){let r=this;return i;function i(t){if(t===62){let n=r.containerState;return n.open||=(e.enter(`blockQuote`,{_container:!0}),!0),e.enter(`blockQuotePrefix`),e.enter(`blockQuoteMarker`),e.consume(t),e.exit(`blockQuoteMarker`),a}return n(t)}function a(n){return Vv(n)?(e.enter(`blockQuotePrefixWhitespace`),e.consume(n),e.exit(`blockQuotePrefixWhitespace`),e.exit(`blockQuotePrefix`),t):(e.exit(`blockQuotePrefix`),t(n))}}function dy(e,t,n){let r=this;return i;function i(t){return Vv(t)?Kv(e,a,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):a(t)}function a(r){return e.attempt(ly,t,n)(r)}}function fy(e){e.exit(`blockQuote`)}var py={name:`characterEscape`,tokenize:my};function my(e,t,n){return r;function r(t){return e.enter(`characterEscape`),e.enter(`escapeMarker`),e.consume(t),e.exit(`escapeMarker`),i}function i(r){return zv(r)?(e.enter(`characterEscapeValue`),e.consume(r),e.exit(`characterEscapeValue`),e.exit(`characterEscape`),t):n(r)}}var hy={name:`characterReference`,tokenize:gy};function gy(e,t,n){let r=this,i=0,a,o;return s;function s(t){return e.enter(`characterReference`),e.enter(`characterReferenceMarker`),e.consume(t),e.exit(`characterReferenceMarker`),c}function c(t){return t===35?(e.enter(`characterReferenceMarkerNumeric`),e.consume(t),e.exit(`characterReferenceMarkerNumeric`),l):(e.enter(`characterReferenceValue`),a=31,o=Pv,u(t))}function l(t){return t===88||t===120?(e.enter(`characterReferenceMarkerHexadecimal`),e.consume(t),e.exit(`characterReferenceMarkerHexadecimal`),e.enter(`characterReferenceValue`),a=6,o=Rv,u):(e.enter(`characterReferenceValue`),a=7,o=Lv,u(t))}function u(s){if(s===59&&i){let i=e.exit(`characterReferenceValue`);return o===Pv&&!wv(r.sliceSerialize(i))?n(s):(e.enter(`characterReferenceMarker`),e.consume(s),e.exit(`characterReferenceMarker`),e.exit(`characterReference`),t)}return o(s)&&i++<a?(e.consume(s),u):n(s)}}var _y={partial:!0,tokenize:by},vy={concrete:!0,name:`codeFenced`,tokenize:yy};function yy(e,t,n){let r=this,i={partial:!0,tokenize:x},a=0,o=0,s;return c;function c(e){return l(e)}function l(t){let n=r.events[r.events.length-1];return a=n&&n[1].type===`linePrefix`?n[2].sliceSerialize(n[1],!0).length:0,s=t,e.enter(`codeFenced`),e.enter(`codeFencedFence`),e.enter(`codeFencedFenceSequence`),u(t)}function u(t){return t===s?(o++,e.consume(t),u):o<3?n(t):(e.exit(`codeFencedFenceSequence`),Vv(t)?Kv(e,d,`whitespace`)(t):d(t))}function d(n){return n===null||$(n)?(e.exit(`codeFencedFence`),r.interrupt?t(n):e.check(_y,h,b)(n)):(e.enter(`codeFencedFenceInfo`),e.enter(`chunkString`,{contentType:`string`}),f(n))}function f(t){return t===null||$(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),d(t)):Vv(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),Kv(e,p,`whitespace`)(t)):t===96&&t===s?n(t):(e.consume(t),f)}function p(t){return t===null||$(t)?d(t):(e.enter(`codeFencedFenceMeta`),e.enter(`chunkString`,{contentType:`string`}),m(t))}function m(t){return t===null||$(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceMeta`),d(t)):t===96&&t===s?n(t):(e.consume(t),m)}function h(t){return e.attempt(i,b,g)(t)}function g(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),_}function _(t){return a>0&&Vv(t)?Kv(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||$(t)?e.check(_y,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||$(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),Vv(t)?Kv(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),Vv(t)?Kv(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||$(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function by(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var xy={name:`codeIndented`,tokenize:Cy},Sy={partial:!0,tokenize:wy};function Cy(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),Kv(e,a,`linePrefix`,5)(t)}function a(e){let t=r.events[r.events.length-1];return t&&t[1].type===`linePrefix`&&t[2].sliceSerialize(t[1],!0).length>=4?o(e):n(e)}function o(t){return t===null?c(t):$(t)?e.attempt(Sy,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||$(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function wy(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):$(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):Kv(e,a,`linePrefix`,5)(t)}function a(e){let a=r.events[r.events.length-1];return a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(e):$(e)?i(e):n(e)}}var Ty={name:`codeText`,previous:Dy,resolve:Ey,tokenize:Oy};function Ey(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r<t;)if(e[r][1].type===`codeTextData`){e[n][1].type=`codeTextPadding`,e[t][1].type=`codeTextPadding`,n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!==`lineEnding`&&(i=r):(r===t||e[r][1].type===`lineEnding`)&&(e[i][1].type=`codeTextData`,r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function Dy(e){return e!==96||this.events[this.events.length-1][1].type===`characterEscape`}function Oy(e,t,n){let r=0,i,a;return o;function o(t){return e.enter(`codeText`),e.enter(`codeTextSequence`),s(t)}function s(t){return t===96?(e.consume(t),r++,s):(e.exit(`codeTextSequence`),c(t))}function c(t){return t===null?n(t):t===32?(e.enter(`space`),e.consume(t),e.exit(`space`),c):t===96?(a=e.enter(`codeTextSequence`),i=0,u(t)):$(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c):(e.enter(`codeTextData`),l(t))}function l(t){return t===null||t===32||t===96||$(t)?(e.exit(`codeTextData`),c(t)):(e.consume(t),l)}function u(n){return n===96?(e.consume(n),i++,u):i===r?(e.exit(`codeTextSequence`),e.exit(`codeText`),t(n)):(a.type=`codeTextData`,l(n))}}var ky=class{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,t){let n=t??1/0;return n<this.left.length?this.left.slice(e,n):e>this.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&Ay(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),Ay(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),Ay(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e<this.left.length){let t=this.left.splice(e,1/0);Ay(this.right,t.reverse())}else{let t=this.right.splice(this.left.length+this.right.length-e,1/0);Ay(this.left,t.reverse())}}};function Ay(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function jy(e){let t={},n=-1,r,i,a,o,s,c,l,u=new ky(e);for(;++n<u.length;){for(;n in t;)n=t[n];if(r=u.get(n),n&&r[1].type===`chunkFlow`&&u.get(n-1)[1].type===`listItemPrefix`&&(c=r[1]._tokenizer.events,a=0,a<c.length&&c[a][1].type===`lineEndingBlank`&&(a+=2),a<c.length&&c[a][1].type===`content`))for(;++a<c.length&&c[a][1].type!==`content`;)c[a][1].type===`chunkText`&&(c[a][1]._isInFirstContentOfListItem=!0,a++);if(r[0]===`enter`)r[1].contentType&&(Object.assign(t,My(u,n)),n=t[n],l=!0);else if(r[1]._container){for(a=n,i=void 0;a--;)if(o=u.get(a),o[1].type===`lineEnding`||o[1].type===`lineEndingBlank`)o[0]===`enter`&&(i&&(u.get(i)[1].type=`lineEndingBlank`),o[1].type=`lineEnding`,i=a);else if(!(o[1].type===`linePrefix`||o[1].type===`listItemIndent`))break;i&&(r[1].end={...u.get(i)[1].start},s=u.slice(i,n),s.unshift(r),u.splice(i,n-i+1,s))}}return Tv(e,0,1/0,u.slice(0)),!l}function My(e,t){let n=e.get(t)[1],r=e.get(t)[2],i=t-1,a=[],o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));let s=o.events,c=[],l={},u,d,f=-1,p=n,m=0,h=0,g=[h];for(;p;){for(;e.get(++i)[1]!==p;);a.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),d&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(u),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=p,p=p.next}for(p=n;++f<s.length;)s[f][0]===`exit`&&s[f-1][0]===`enter`&&s[f][1].type===s[f-1][1].type&&s[f][1].start.line!==s[f][1].end.line&&(h=f+1,g.push(h),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):g.pop(),f=g.length;f--;){let t=s.slice(g[f],g[f+1]),n=a.pop();c.push([n,n+t.length-1]),e.splice(n,2,t)}for(c.reverse(),f=-1;++f<c.length;)l[m+c[f][0]]=m+c[f][1],m+=c[f][1]-c[f][0]-1;return l}var Ny={resolve:Fy,tokenize:Iy},Py={partial:!0,tokenize:Ly};function Fy(e){return jy(e),e}function Iy(e,t){let n;return r;function r(t){return e.enter(`content`),n=e.enter(`chunkContent`,{contentType:`content`}),i(t)}function i(t){return t===null?a(t):$(t)?e.check(Py,o,a)(t):(e.consume(t),i)}function a(n){return e.exit(`chunkContent`),e.exit(`content`),t(n)}function o(t){return e.consume(t),e.exit(`chunkContent`),n.next=e.enter(`chunkContent`,{contentType:`content`,previous:n}),n=n.next,i}}function Ly(e,t,n){let r=this;return i;function i(t){return e.exit(`chunkContent`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),Kv(e,a,`linePrefix`)}function a(i){if(i===null||$(i))return n(i);let a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes(`codeIndented`)&&a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function Ry(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||Iv(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||$(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||Bv(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u<l&&i===40?(e.consume(i),u++,h):i===41?(e.consume(i),u--,h):i===null||i===32||i===40||Iv(i)?n(i):(e.consume(i),i===92?g:h)}function g(t){return t===40||t===41||t===92?(e.consume(t),h):h(t)}}function zy(e,t,n,r,i,a){let o=this,s=0,c;return l;function l(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),e.enter(a),u}function u(l){return s>999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):$(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||$(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!Vv(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function By(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):$(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),Kv(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||$(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function Vy(e,t){let n;return r;function r(i){return $(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):Vv(i)?Kv(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var Hy={name:`definition`,tokenize:Wy},Uy={partial:!0,tokenize:Gy};function Wy(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return zy.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=Mv(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return Bv(t)?Vy(e,l)(t):l(t)}function l(t){return Ry(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(Uy,d,d)(t)}function d(t){return Vv(t)?Kv(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||$(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function Gy(e,t,n){return r;function r(t){return Bv(t)?Vy(e,i)(t):n(t)}function i(t){return By(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return Vv(t)?Kv(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||$(e)?t(e):n(e)}}var Ky={name:`hardBreakEscape`,tokenize:qy};function qy(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return $(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var Jy={name:`headingAtx`,resolve:Yy,tokenize:Xy};function Yy(e,t){let n=e.length-2,r=3,i,a;return e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r&&(i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`},Tv(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function Xy(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||Bv(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||$(n)?(e.exit(`atxHeading`),t(n)):Vv(n)?Kv(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||Bv(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var Zy=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),Qy=[`pre`,`script`,`style`,`textarea`],$y={concrete:!0,name:`htmlFlow`,resolveTo:nb,tokenize:rb},eb={partial:!0,tokenize:ab},tb={partial:!0,tokenize:ib};function nb(e){let t=e.length;for(;t--&&!(e[t][0]===`enter`&&e[t][1].type===`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function rb(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:ne):Nv(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):Nv(a)?(e.consume(a),i=4,r.interrupt?t:ne):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:ne):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return Nv(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||Bv(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&Qy.includes(l)?(i=1,r.interrupt?t(s):O(s)):Zy.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||Pv(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return Vv(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||Nv(t)?(e.consume(t),b):Vv(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||Pv(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):Vv(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):Vv(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||$(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||Bv(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||Vv(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||$(t)?O(t):Vv(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),te):t===60&&i===1?(e.consume(t),j):t===62&&i===4?(e.consume(t),re):t===63&&i===3?(e.consume(t),ne):t===93&&i===5?(e.consume(t),N):$(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(eb,ie,k)(t)):t===null||$(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(tb,A,ie)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),ee}function ee(t){return t===null||$(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function te(t){return t===45?(e.consume(t),ne):O(t)}function j(t){return t===47?(e.consume(t),o=``,M):O(t)}function M(t){if(t===62){let n=o.toLowerCase();return Qy.includes(n)?(e.consume(t),re):O(t)}return Nv(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),M):O(t)}function N(t){return t===93?(e.consume(t),ne):O(t)}function ne(t){return t===62?(e.consume(t),re):t===45&&i===2?(e.consume(t),ne):O(t)}function re(t){return t===null||$(t)?(e.exit(`htmlFlowData`),ie(t)):(e.consume(t),re)}function ie(n){return e.exit(`htmlFlow`),t(n)}}function ib(e,t,n){let r=this;return i;function i(t){return $(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a):n(t)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}function ab(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(sy,t,n)}}var ob={name:`htmlText`,tokenize:sb};function sb(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):Nv(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):Nv(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):$(t)?(o=d,j(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?te(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):$(t)?(o=h,j(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?te(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?te(t):$(t)?(o=v,j(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):$(t)?(o=y,j(t)):(e.consume(t),y)}function b(e){return e===62?te(e):y(e)}function x(t){return Nv(t)?(e.consume(t),S):n(t)}function S(t){return t===45||Pv(t)?(e.consume(t),S):C(t)}function C(t){return $(t)?(o=C,j(t)):Vv(t)?(e.consume(t),C):te(t)}function w(t){return t===45||Pv(t)?(e.consume(t),w):t===47||t===62||Bv(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),te):t===58||t===95||Nv(t)?(e.consume(t),E):$(t)?(o=T,j(t)):Vv(t)?(e.consume(t),T):te(t)}function E(t){return t===45||t===46||t===58||t===95||Pv(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):$(t)?(o=D,j(t)):Vv(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):$(t)?(o=O,j(t)):Vv(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,ee):t===null?n(t):$(t)?(o=k,j(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||Bv(t)?T(t):(e.consume(t),A)}function ee(e){return e===47||e===62||Bv(e)?T(e):n(e)}function te(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function j(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),M}function M(t){return Vv(t)?Kv(e,N,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):N(t)}function N(t){return e.enter(`htmlTextData`),o(t)}}var cb={name:`labelEnd`,resolveAll:fb,resolveTo:pb,tokenize:mb},lb={tokenize:hb},ub={tokenize:gb},db={tokenize:_b};function fb(e){let t=-1,n=[];for(;++t<e.length;){let r=e[t][1];if(n.push(e[t]),r.type===`labelImage`||r.type===`labelLink`||r.type===`labelEnd`){let e=r.type===`labelImage`?4:2;r.type=`data`,t+=e}}return e.length!==n.length&&Tv(e,0,e.length,n),e}function pb(e,t){let n=e.length,r=0,i,a,o,s;for(;n--;)if(i=e[n][1],a){if(i.type===`link`||i.type===`labelLink`&&i._inactive)break;e[n][0]===`enter`&&i.type===`labelLink`&&(i._inactive=!0)}else if(o){if(e[n][0]===`enter`&&(i.type===`labelImage`||i.type===`labelLink`)&&!i._balanced&&(a=n,i.type!==`labelLink`)){r=2;break}}else i.type===`labelEnd`&&(o=n);let c={type:e[a][1].type===`labelLink`?`link`:`image`,start:{...e[a][1].start},end:{...e[e.length-1][1].end}},l={type:`label`,start:{...e[a][1].start},end:{...e[o][1].end}},u={type:`labelText`,start:{...e[a+r+2][1].end},end:{...e[o-2][1].start}};return s=[[`enter`,c,t],[`enter`,l,t]],s=Ev(s,e.slice(a+1,a+r+3)),s=Ev(s,[[`enter`,u,t]]),s=Ev(s,ey(t.parser.constructs.insideSpan.null,e.slice(a+r+4,o-3),t)),s=Ev(s,[[`exit`,u,t],e[o-2],e[o-1],[`exit`,l,t]]),s=Ev(s,e.slice(o+1)),s=Ev(s,[[`exit`,c,t]]),Tv(e,a,e.length,s),e}function mb(e,t,n){let r=this,i=r.events.length,a,o;for(;i--;)if((r.events[i][1].type===`labelImage`||r.events[i][1].type===`labelLink`)&&!r.events[i][1]._balanced){a=r.events[i][1];break}return s;function s(t){return a?a._inactive?d(t):(o=r.parser.defined.includes(Mv(r.sliceSerialize({start:a.end,end:r.now()}))),e.enter(`labelEnd`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelEnd`),c):n(t)}function c(t){return t===40?e.attempt(lb,u,o?u:d)(t):t===91?e.attempt(ub,u,o?l:d)(t):o?u(t):d(t)}function l(t){return e.attempt(db,u,d)(t)}function u(e){return t(e)}function d(e){return a._balanced=!0,n(e)}}function hb(e,t,n){return r;function r(t){return e.enter(`resource`),e.enter(`resourceMarker`),e.consume(t),e.exit(`resourceMarker`),i}function i(t){return Bv(t)?Vy(e,a)(t):a(t)}function a(t){return t===41?u(t):Ry(e,o,s,`resourceDestination`,`resourceDestinationLiteral`,`resourceDestinationLiteralMarker`,`resourceDestinationRaw`,`resourceDestinationString`,32)(t)}function o(t){return Bv(t)?Vy(e,c)(t):u(t)}function s(e){return n(e)}function c(t){return t===34||t===39||t===40?By(e,l,n,`resourceTitle`,`resourceTitleMarker`,`resourceTitleString`)(t):u(t)}function l(t){return Bv(t)?Vy(e,u)(t):u(t)}function u(r){return r===41?(e.enter(`resourceMarker`),e.consume(r),e.exit(`resourceMarker`),e.exit(`resource`),t):n(r)}}function gb(e,t,n){let r=this;return i;function i(t){return zy.call(r,e,a,o,`reference`,`referenceMarker`,`referenceString`)(t)}function a(e){return r.parser.defined.includes(Mv(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(e):n(e)}function o(e){return n(e)}}function _b(e,t,n){return r;function r(t){return e.enter(`reference`),e.enter(`referenceMarker`),e.consume(t),e.exit(`referenceMarker`),i}function i(r){return r===93?(e.enter(`referenceMarker`),e.consume(r),e.exit(`referenceMarker`),e.exit(`reference`),t):n(r)}}var vb={name:`labelStartImage`,resolveAll:cb.resolveAll,tokenize:yb};function yb(e,t,n){let r=this;return i;function i(t){return e.enter(`labelImage`),e.enter(`labelImageMarker`),e.consume(t),e.exit(`labelImageMarker`),a}function a(t){return t===91?(e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelImage`),o):n(t)}function o(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):t(e)}}var bb={name:`labelStartLink`,resolveAll:cb.resolveAll,tokenize:xb};function xb(e,t,n){let r=this;return i;function i(t){return e.enter(`labelLink`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelLink`),a}function a(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):t(e)}}var Sb={name:`lineEnding`,tokenize:Cb};function Cb(e,t){return n;function n(n){return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),Kv(e,t,`linePrefix`)}}var wb={name:`thematicBreak`,tokenize:Tb};function Tb(e,t,n){let r=0,i;return a;function a(t){return e.enter(`thematicBreak`),o(t)}function o(e){return i=e,s(e)}function s(a){return a===i?(e.enter(`thematicBreakSequence`),c(a)):r>=3&&(a===null||$(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),Vv(t)?Kv(e,s,`whitespace`)(t):s(t))}}var Eb={continuation:{tokenize:Ab},exit:Mb,name:`list`,tokenize:kb},Db={partial:!0,tokenize:Nb},Ob={partial:!0,tokenize:jb};function kb(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:Lv(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(wb,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return Lv(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(sy,r.interrupt?n:u,e.attempt(Db,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return Vv(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function Ab(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(sy,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,Kv(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!Vv(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(Ob,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,Kv(e,e.attempt(Eb,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function jb(e,t,n){let r=this;return Kv(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function Mb(e){e.exit(this.containerState.type)}function Nb(e,t,n){let r=this;return Kv(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!Vv(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var Pb={name:`setextUnderline`,resolveTo:Fb,tokenize:Ib};function Fb(e,t){let n=e.length,r,i,a;for(;n--;)if(e[n][0]===`enter`){if(e[n][1].type===`content`){r=n;break}e[n][1].type===`paragraph`&&(i=n)}else e[n][1].type===`content`&&e.splice(n,1),!a&&e[n][1].type===`definition`&&(a=n);let o={type:`setextHeading`,start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type=`setextHeadingText`,a?(e.splice(i,0,[`enter`,o,t]),e.splice(a+1,0,[`exit`,e[r][1],t]),e[r][1].end={...e[a][1].end}):e[r][1]=o,e.push([`exit`,o,t]),e}function Ib(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),Vv(t)?Kv(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||$(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var Lb={tokenize:Rb};function Rb(e){let t=this,n=e.attempt(sy,r,e.attempt(this.parser.constructs.flowInitial,i,Kv(e,e.attempt(this.parser.constructs.flow,i,e.attempt(Ny,i)),`linePrefix`)));return n;function r(r){if(r===null){e.consume(r);return}return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null){e.consume(r);return}return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var zb={resolveAll:Ub()},Bb=Hb(`string`),Vb=Hb(`text`);function Hb(e){return{resolveAll:Ub(e===`text`?Wb:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null){t.consume(e);return}return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++i<t.length;){let e=t[i];if(!e.previous||e.previous.call(n,n.previous))return!0}return!1}}}function Ub(e){return t;function t(t,n){let r=-1,i;for(;++r<=t.length;)i===void 0?t[r]&&t[r][1].type===`data`&&(i=r,r++):(!t[r]||t[r][1].type!==`data`)&&(r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),r=i+2),i=void 0);return e?e(t,n):t}}function Wb(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type===`lineEnding`)&&e[n-1][1].type===`data`){let r=e[n-1][1],i=t.sliceStream(r),a=i.length,o=-1,s=0,c;for(;a--;){let e=i[a];if(typeof e==`string`){for(o=e.length;e.charCodeAt(o-1)===32;)s++,o--;if(o)break;o=-1}else if(e===-2)c=!0,s++;else if(e!==-1){a++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(s=0),s){let i={type:n===e.length||c||s<2?`lineSuffix`:`hardBreakTrailing`,start:{_bufferIndex:a?o:r.start._bufferIndex+o,_index:r.start._index+a,line:r.end.line,column:r.end.column-s,offset:r.end.offset-s},end:{...r.end}};r.end={...i.start},r.start.offset===r.end.offset?Object.assign(r,i):(e.splice(n,0,[`enter`,i,t],[`exit`,i,t]),n+=2)}n++}return e}var Gb=s({attentionMarkers:()=>$b,contentInitial:()=>qb,disable:()=>ex,document:()=>Kb,flow:()=>Yb,flowInitial:()=>Jb,insideSpan:()=>Qb,string:()=>Xb,text:()=>Zb}),Kb={42:Eb,43:Eb,45:Eb,48:Eb,49:Eb,50:Eb,51:Eb,52:Eb,53:Eb,54:Eb,55:Eb,56:Eb,57:Eb,62:ly},qb={91:Hy},Jb={[-2]:xy,[-1]:xy,32:xy},Yb={35:Jy,42:wb,45:[Pb,wb],60:$y,61:Pb,95:wb,96:vy,126:vy},Xb={38:hy,92:py},Zb={[-5]:Sb,[-4]:Sb,[-3]:Sb,33:vb,38:hy,42:ty,60:[ay,ob],91:bb,92:[Ky,py],93:cb,95:ty,96:Ty},Qb={null:[ty,zb]},$b={null:[42,95]},ex={null:[]};function tx(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=Ev(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=ey(a,l.events,l),l.events):[]}function f(e,t){return rx(p(e),t)}function p(e){return nx(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){let e;for(;r._index<o.length;){let t=o[r._index];if(typeof t==`string`)for(e=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===e&&r._bufferIndex<t.length;)_(t.charCodeAt(r._bufferIndex));else _(t)}}function _(e){u=u(e)}function v(e){$(e)?(r.line++,r.column=1,r.offset+=e===-3?2:1,E()):e!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),l.previous=e}function y(e,t){let n=t||{};return n.type=e,n.start=m(),l.events.push([`enter`,n,l]),s.push(n),n}function b(e){let t=s.pop();return t.end=m(),l.events.push([`exit`,t,l]),t}function x(e,t){w(e,t.from)}function S(e,t){t.restore()}function C(e,t){return n;function n(n,r,i){let a,o,s,u;return Array.isArray(n)?f(n):`tokenize`in n?f([n]):d(n);function d(e){return t;function t(t){let n=t!==null&&e[t],r=t!==null&&e.null;return f([...Array.isArray(n)?n:n?[n]:[],...Array.isArray(r)?r:r?[r]:[]])(t)}}function f(e){return a=e,o=0,e.length===0?i:p(e[o])}function p(e){return n;function n(n){return u=T(),s=e,e.partial||(l.currentConstruct=e),e.name&&l.parser.constructs.disable.null.includes(e.name)?h(n):e.tokenize.call(t?Object.assign(Object.create(l),t):l,c,m,h)(n)}}function m(t){return e(s,u),r}function h(e){return u.restore(),++o<a.length?p(a[o]):i}}}function w(e,t){e.resolveAll&&!a.includes(e)&&a.push(e),e.resolve&&Tv(l.events,t,l.events.length-t,e.resolve(l.events.slice(t),l)),e.resolveTo&&(l.events=e.resolveTo(l.events,l))}function T(){let e=m(),t=l.previous,n=l.currentConstruct,i=l.events.length,a=Array.from(s);return{from:i,restore:o};function o(){r=e,l.previous=t,l.currentConstruct=n,l.events.length=i,s=a,E()}}function E(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function nx(e,t){let n=t.start._index,r=t.start._bufferIndex,i=t.end._index,a=t.end._bufferIndex,o;if(n===i)o=[e[n].slice(r,a)];else{if(o=e.slice(n,i),r>-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function rx(e,t){let n=-1,r=[],i;for(;++n<e.length;){let a=e[n],o;if(typeof a==`string`)o=a;else switch(a){case-5:o=`\r`;break;case-4:o=`
|
|
20
20
|
`;break;case-3:o=`\r
|
|
21
21
|
`;break;case-2:o=t?` `:` `;break;case-1:if(!t&&i)continue;o=` `;break;default:o=String.fromCharCode(a)}i=a===-2,r.push(o)}return r.join(``)}function ix(e){let t={constructs:Ov([Gb,...(e||{}).extensions||[]]),content:n(qv),defined:[],document:n(Yv),flow:n(Lb),lazy:{},string:n(Bb),text:n(Vb)};return t;function n(e){return n;function n(n){return tx(t,e,n)}}}function ax(e){for(;!jy(e););return e}var ox=/[\0\t\n\r]/g;function sx(){let e=1,t=``,n=!0,r;return i;function i(i,a,o){let s=[],c,l,u,d,f;for(i=t+(typeof i==`string`?i.toString():new TextDecoder(a||void 0).decode(i)),u=0,t=``,n&&=(i.charCodeAt(0)===65279&&u++,void 0);u<i.length;){if(ox.lastIndex=u,c=ox.exec(i),d=c&&c.index!==void 0?c.index:i.length,f=i.charCodeAt(d),!c){t=i.slice(u);break}if(f===10&&u===d&&r)s.push(-3),r=void 0;else switch(r&&=(s.push(-5),void 0),u<d&&(s.push(i.slice(u,d)),e+=d-u),f){case 0:s.push(65533),e++;break;case 9:for(l=Math.ceil(e/4)*4,s.push(-2);e++<l;)s.push(-1);break;case 10:s.push(-4),e=1;break;default:r=!0,e=1}u=d+1}return o&&(r&&s.push(-5),t&&s.push(t),s.push(null)),s}}var cx=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function lx(e){return e.replace(cx,ux)}function ux(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){let e=n.charCodeAt(1),t=e===120||e===88;return jv(n.slice(t?2:1),t?16:10)}return wv(n)||e}var dx={}.hasOwnProperty;function fx(e,t,n){return t&&typeof t==`object`&&(n=t,t=void 0),px(n)(ax(ix(n).document().write(sx()(e,t,!0))))}function px(e){let t={transforms:[],canContainEols:[`emphasis`,`fragment`,`heading`,`paragraph`,`strong`],enter:{autolink:a(be),autolinkProtocol:T,autolinkEmail:T,atxHeading:a(ge),blockQuote:a(de),characterEscape:T,characterReference:T,codeFenced:a(fe),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:a(fe,o),codeText:a(pe,o),codeTextData:T,data:T,codeFlowValue:T,definition:a(me),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:a(he),hardBreakEscape:a(_e),hardBreakTrailing:a(_e),htmlFlow:a(ve,o),htmlFlowData:T,htmlText:a(ve,o),htmlTextData:T,image:a(ye),label:o,link:a(be),listItem:a(Se),listItemValue:f,listOrdered:a(xe,d),listUnordered:a(xe),paragraph:a(F),reference:P,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:a(ge),strong:a(Ce),thematicBreak:a(Te)},exit:{atxHeading:c(),atxHeadingSequence:x,autolink:c(),autolinkEmail:ue,autolinkProtocol:le,blockQuote:c(),characterEscapeValue:E,characterReferenceMarkerHexadecimal:oe,characterReferenceMarkerNumeric:oe,characterReferenceValue:se,characterReference:ce,codeFenced:c(g),codeFencedFence:h,codeFencedFenceInfo:p,codeFencedFenceMeta:m,codeFlowValue:E,codeIndented:c(_),codeText:c(ee),codeTextData:E,data:E,definition:c(),definitionDestinationString:b,definitionLabelString:v,definitionTitleString:y,emphasis:c(),hardBreakEscape:c(O),hardBreakTrailing:c(O),htmlFlow:c(k),htmlFlowData:E,htmlText:c(A),htmlTextData:E,image:c(j),label:N,labelText:M,lineEnding:D,link:c(te),listItem:c(),listOrdered:c(),listUnordered:c(),paragraph:c(),referenceString:ae,resourceDestinationString:ne,resourceTitleString:re,resource:ie,setextHeading:c(w),setextHeadingLineSequence:C,setextHeadingText:S,strong:c(),thematicBreak:c()}};hx(t,(e||{}).mdastExtensions||[]);let n={};return r;function r(e){let r={type:`root`,children:[]},a={stack:[r],tokenStack:[],config:t,enter:s,exit:l,buffer:o,resume:u,data:n},c=[],d=-1;for(;++d<e.length;)(e[d][1].type===`listOrdered`||e[d][1].type===`listUnordered`)&&(e[d][0]===`enter`?c.push(d):d=i(e,c.pop(),d));for(d=-1;++d<e.length;){let n=t[e[d][0]];dx.call(n,e[d][1].type)&&n[e[d][1].type].call(Object.assign({sliceSerialize:e[d][2].sliceSerialize},a),e[d][1])}if(a.tokenStack.length>0){let e=a.tokenStack[a.tokenStack.length-1];(e[1]||_x).call(a,void 0,e[0])}for(r.position={start:mx(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:mx(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},d=-1;++d<t.transforms.length;)r=t.transforms[d](r)||r;return r}function i(e,t,n){let r=t-1,i=-1,a=!1,o,s,c,l;for(;++r<=n;){let t=e[r];switch(t[1].type){case`listUnordered`:case`listOrdered`:case`blockQuote`:t[0]===`enter`?i++:i--,l=void 0;break;case`lineEndingBlank`:t[0]===`enter`&&(o&&!l&&!i&&!c&&(c=r),l=void 0);break;case`linePrefix`:case`listItemValue`:case`listItemMarker`:case`listItemPrefix`:case`listItemPrefixWhitespace`:break;default:l=void 0}if(!i&&t[0]===`enter`&&t[1].type===`listItemPrefix`||i===-1&&t[0]===`exit`&&(t[1].type===`listUnordered`||t[1].type===`listOrdered`)){if(o){let i=r;for(s=void 0;i--;){let t=e[i];if(t[1].type===`lineEnding`||t[1].type===`lineEndingBlank`){if(t[0]===`exit`)continue;s&&(e[s][1].type=`lineEndingBlank`,a=!0),t[1].type=`lineEnding`,s=i}else if(!(t[1].type===`linePrefix`||t[1].type===`blockQuotePrefix`||t[1].type===`blockQuotePrefixWhitespace`||t[1].type===`blockQuoteMarker`||t[1].type===`listItemIndent`))break}c&&(!s||c<s)&&(o._spread=!0),o.end=Object.assign({},s?e[s][1].start:t[1].end),e.splice(s||r,0,[`exit`,o,t[2]]),r++,n++}if(t[1].type===`listItemPrefix`){let i={type:`listItem`,_spread:!1,start:Object.assign({},t[1].start),end:void 0};o=i,e.splice(r,0,[`enter`,i,t[2]]),r++,n++,c=void 0,l=!0}}}return e[t][1]._spread=a,n}function a(e,t){return n;function n(n){s.call(this,e(n),n),t&&t.call(this,n)}}function o(){this.stack.push({type:`fragment`,children:[]})}function s(e,t,n){this.stack[this.stack.length-1].children.push(e),this.stack.push(e),this.tokenStack.push([t,n||void 0]),e.position={start:mx(t.start),end:void 0}}function c(e){return t;function t(t){e&&e.call(this,t),l.call(this,t)}}function l(e,t){let n=this.stack.pop(),r=this.tokenStack.pop();if(r)r[0].type!==e.type&&(t?t.call(this,e,r[0]):(r[1]||_x).call(this,e,r[0]));else throw Error("Cannot close `"+e.type+"` ("+R_({start:e.start,end:e.end})+`): it’s not open`);n.position.end=mx(e.end)}function u(){return yv(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function f(e){if(this.data.expectingFirstListItemValue){let t=this.stack[this.stack.length-2];t.start=Number.parseInt(this.sliceSerialize(e),10),this.data.expectingFirstListItemValue=void 0}}function p(){let e=this.resume(),t=this.stack[this.stack.length-1];t.lang=e}function m(){let e=this.resume(),t=this.stack[this.stack.length-1];t.meta=e}function h(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function g(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``),this.data.flowCodeInside=void 0}function _(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/(\r?\n|\r)$/g,``)}function v(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=Mv(this.sliceSerialize(e)).toLowerCase()}function y(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function b(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function x(e){let t=this.stack[this.stack.length-1];t.depth||=this.sliceSerialize(e).length}function S(){this.data.setextHeadingSlurpLineEnding=!0}function C(e){let t=this.stack[this.stack.length-1];t.depth=this.sliceSerialize(e).codePointAt(0)===61?1:2}function w(){this.data.setextHeadingSlurpLineEnding=void 0}function T(e){let t=this.stack[this.stack.length-1].children,n=t[t.length-1];(!n||n.type!==`text`)&&(n=we(),n.position={start:mx(e.start),end:void 0},t.push(n)),this.stack.push(n)}function E(e){let t=this.stack.pop();t.value+=this.sliceSerialize(e),t.position.end=mx(e.end)}function D(e){let n=this.stack[this.stack.length-1];if(this.data.atHardBreak){let t=n.children[n.children.length-1];t.position.end=mx(e.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(n.type)&&(T.call(this,e),E.call(this,e))}function O(){this.data.atHardBreak=!0}function k(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function A(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function ee(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function te(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function j(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function M(e){let t=this.sliceSerialize(e),n=this.stack[this.stack.length-2];n.label=lx(t),n.identifier=Mv(t).toLowerCase()}function N(){let e=this.stack[this.stack.length-1],t=this.resume(),n=this.stack[this.stack.length-1];this.data.inReference=!0,n.type===`link`?n.children=e.children:n.alt=t}function ne(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function re(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function ie(){this.data.inReference=void 0}function P(){this.data.referenceType=`collapsed`}function ae(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=Mv(this.sliceSerialize(e)).toLowerCase(),this.data.referenceType=`full`}function oe(e){this.data.characterReferenceType=e.type}function se(e){let t=this.sliceSerialize(e),n=this.data.characterReferenceType,r;n?(r=jv(t,n===`characterReferenceMarkerNumeric`?10:16),this.data.characterReferenceType=void 0):r=wv(t);let i=this.stack[this.stack.length-1];i.value+=r}function ce(e){let t=this.stack.pop();t.position.end=mx(e.end)}function le(e){E.call(this,e);let t=this.stack[this.stack.length-1];t.url=this.sliceSerialize(e)}function ue(e){E.call(this,e);let t=this.stack[this.stack.length-1];t.url=`mailto:`+this.sliceSerialize(e)}function de(){return{type:`blockquote`,children:[]}}function fe(){return{type:`code`,lang:null,meta:null,value:``}}function pe(){return{type:`inlineCode`,value:``}}function me(){return{type:`definition`,identifier:``,label:null,title:null,url:``}}function he(){return{type:`emphasis`,children:[]}}function ge(){return{type:`heading`,depth:0,children:[]}}function _e(){return{type:`break`}}function ve(){return{type:`html`,value:``}}function ye(){return{type:`image`,title:null,url:``,alt:null}}function be(){return{type:`link`,title:null,url:``,children:[]}}function xe(e){return{type:`list`,ordered:e.type===`listOrdered`,start:null,spread:e._spread,children:[]}}function Se(e){return{type:`listItem`,spread:e._spread,checked:null,children:[]}}function F(){return{type:`paragraph`,children:[]}}function Ce(){return{type:`strong`,children:[]}}function we(){return{type:`text`,value:``}}function Te(){return{type:`thematicBreak`}}}function mx(e){return{line:e.line,column:e.column,offset:e.offset}}function hx(e,t){let n=-1;for(;++n<t.length;){let r=t[n];Array.isArray(r)?hx(e,r):gx(e,r)}}function gx(e,t){let n;for(n in t)if(dx.call(t,n))switch(n){case`canContainEols`:{let r=t[n];r&&e[n].push(...r);break}case`transforms`:{let r=t[n];r&&e[n].push(...r);break}case`enter`:case`exit`:{let r=t[n];r&&Object.assign(e[n],r);break}}}function _x(e,t){throw Error(e?"Cannot close `"+e.type+"` ("+R_({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+R_({start:t.start,end:t.end})+`) is open`:"Cannot close document, a token (`"+t.type+"`, "+R_({start:t.start,end:t.end})+`) is still open`)}function vx(e){let t=this;t.parser=n;function n(n){return fx(n,{...t.data(`settings`),...e,extensions:t.data(`micromarkExtensions`)||[],mdastExtensions:t.data(`fromMarkdownExtensions`)||[]})}}function yx(e,t){let n={type:`element`,tagName:`blockquote`,properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function bx(e,t){let n={type:`element`,tagName:`br`,properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:`text`,value:`
|