@openchamber/web 1.17.0 → 1.17.1

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.
Files changed (63) hide show
  1. package/README.md +3 -0
  2. package/dist/assets/{DiagramView-CRjw8BGO.js → DiagramView-CI2JhNxs.js} +1 -1
  3. package/dist/assets/{MarkdownRendererImpl-BjjFniUt.js → MarkdownRendererImpl-Bq-wtyiF.js} +3 -3
  4. package/dist/assets/{OnboardingScreen-JuiKjRTI.js → OnboardingScreen-B6BqjJ0l.js} +1 -1
  5. package/dist/assets/{SessionSwitcherDropdown-S2EvRz-E.js → SessionSwitcherDropdown-DepVWyeA.js} +1 -1
  6. package/dist/assets/{SettingsWindow-PzqMjCEx.js → SettingsWindow-Xj4Uy_Fr.js} +1 -1
  7. package/dist/assets/{document-attachments-DZf4VoiD.js → document-attachments-C5tUWELq.js} +1 -1
  8. package/dist/assets/{es-CErIcckI.js → es-DSTFcl6A.js} +1 -1
  9. package/dist/assets/{fr-z5ORYrou.js → fr-CEeK5ifb.js} +1 -1
  10. package/dist/assets/index-DUBtXIPQ.css +1 -0
  11. package/dist/assets/{index-DMCrPMIW.js → index-Dld5wFqI.js} +3 -3
  12. package/dist/assets/{ja-ecPbYMn0.js → ja-pu3u7ZOY.js} +1 -1
  13. package/dist/assets/{ko-CASkpaQH.js → ko-CStr_CJ-.js} +1 -1
  14. package/dist/assets/{main-BTLr2DyB.js → main-DBG0rE6P.js} +36 -36
  15. package/dist/assets/{main-DQ-uX_zf.js → main-Xc2GeALp.js} +2 -2
  16. package/dist/assets/{markdownCore-C4XTgyYU.js → markdownCore-Bn8Ywh-t.js} +2 -2
  17. package/dist/assets/miniChat-D5FFElbH.js +2 -0
  18. package/dist/assets/mobile-B4K4IpE7.js +2 -0
  19. package/dist/assets/{pl-BYtGQyDI.js → pl-nD08d1Bo.js} +1 -1
  20. package/dist/assets/{pt-BR-D8dONk68.js → pt-BR-DqcoQ-nE.js} +1 -1
  21. package/dist/assets/{renderElectronMiniChatApp-Cbdusroc.js → renderElectronMiniChatApp-B-rksap7.js} +2 -2
  22. package/dist/assets/renderMobileApp-U-jxDI_G.js +16 -0
  23. package/dist/assets/runtimeEndpointReset-fpfBYOyW.js +174 -0
  24. package/dist/assets/{uk-C8z1P8tg.js → uk-DkX7DsWk.js} +1 -1
  25. package/dist/assets/{useAppFontEffects-DrLhDSC3.js → useAppFontEffects-CZdEKvZ8.js} +129 -127
  26. package/dist/assets/{vendor-.bun-DvcSrJLa.js → vendor-.bun-BzW0Lgld.js} +1 -1
  27. package/dist/assets/{zh-CN-BwJPtjKq.js → zh-CN-DlqHNM1o.js} +1 -1
  28. package/dist/assets/{zh-TW-C7FpgD-Y.js → zh-TW-DeKAHBhV.js} +1 -1
  29. package/dist/index.html +4 -4
  30. package/dist/mini-chat.html +4 -4
  31. package/dist/mobile.html +4 -4
  32. package/package.json +2 -2
  33. package/server/index.js +31 -2
  34. package/server/lib/openchamber-sessions/routes.js +30 -30
  35. package/server/lib/openchamber-sessions/routes.test.js +38 -0
  36. package/server/lib/opencode/DOCUMENTATION.md +7 -2
  37. package/server/lib/opencode/env-runtime.js +18 -0
  38. package/server/lib/opencode/env-runtime.test.js +12 -0
  39. package/server/lib/opencode/feature-routes-runtime.js +2 -0
  40. package/server/lib/opencode/lifecycle.js +18 -6
  41. package/server/lib/opencode/lifecycle.test.js +67 -1
  42. package/server/lib/opencode/proxy.js +32 -2
  43. package/server/lib/opencode/routes-upgrade.test.js +113 -0
  44. package/server/lib/opencode/routes.js +69 -36
  45. package/server/lib/opencode/server-utils-runtime.js +2 -0
  46. package/server/lib/opencode/settings-helpers.js +3 -0
  47. package/server/lib/opencode/settings-helpers.test.js +8 -0
  48. package/server/lib/opencode/upgrade-capability.js +36 -0
  49. package/server/lib/opencode/upgrade-capability.test.js +57 -0
  50. package/server/lib/quota/providers/codex.js +18 -0
  51. package/server/lib/quota/providers/codex.test.js +28 -0
  52. package/server/lib/scheduled-tasks/runtime.js +44 -18
  53. package/server/lib/scheduled-tasks/runtime.test.js +12 -1
  54. package/server/lib/session-goal/DOCUMENTATION.md +12 -3
  55. package/server/lib/system-prompt/DOCUMENTATION.md +36 -0
  56. package/server/lib/system-prompt/runtime.js +68 -0
  57. package/server/lib/system-prompt/runtime.test.js +76 -0
  58. package/server/opencode-proxy.test.js +49 -0
  59. package/dist/assets/index-Csh1A7Eh.css +0 -1
  60. package/dist/assets/miniChat-ComIlrTa.js +0 -2
  61. package/dist/assets/mobile-DUYXEkKA.js +0 -2
  62. package/dist/assets/renderMobileApp-m9MPmIZT.js +0 -16
  63. package/dist/assets/runtimeEndpointReset-B0yQKPe0.js +0 -174
@@ -0,0 +1,16 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-CZdEKvZ8.js","assets/vendor-.bun-BzW0Lgld.js","assets/index-Dld5wFqI.js","assets/index-DUBtXIPQ.css"])))=>i.map(i=>d[i]);
2
+ import{b as ce,r as as,j as t,R as l,P as Et,K as gs,e as Cr,f as Pn,B as Er,Q as Pr,g as Ir,i as Tr,F as Rr,U as Ar,Z as Dr,a as bs,p as In,k as Mr,u as Tn,l as Ot,s as Rn,m as An,n as Dn,o as ls,D as Mn,q as _n,S as Ln,v as zn,t as On,w as Bn,C as Fn,M as $n,x as cs,J as Un,y as _r,z as Os,A as xs,E as Bs,V as Lr,G as zr,H as Or,_ as Oe,I as Br}from"./vendor-.bun-BzW0Lgld.js";import{u as ut,a as Vt,b as Fs,r as Gt,d as $s,e as it,f as Je,s as wt,i as kt,h as Fr,j as Wn,p as $r,k as Us,l as Ws,m as Ur,o as Vs,n as Wr,q as Vr}from"./index-Dld5wFqI.js";import{u as Ht,a as Gr,b as Ae,c as ys,d as vs,r as Vn,e as Gn,f as de,g as Hn,t as oe,o as Hr,I as re,h as Kt,i as ws,j as js,k as Kn,l as Kr,m as De,s as qr,n as Jr,p as Yr,q as Xr,v as Qr,w as qn,B as ge,x as jt,S as Qe,y as Z,z as ks,A as Zr,C as Gs,D as Ss,F as eo,E as Hs,G as to,J as so,H as Jn,K as be,L as no,M as ro,N as Yn,P as Xn,O as Qn,Q as Zn,R as oo,T as io,U as ao,V as lo,W as co,X as Ks,Y as er,Z as ke,_ as uo,$ as fo,a0 as Re,a1 as mo,a2 as ho,a3 as po,a4 as go,a5 as bo,a6 as xt,a7 as xo,a8 as ze,a9 as yo,aa as vo,ab as wo,ac as jo,ad as ko,ae as So,af as tr,ag as No,ah as Co,ai as Eo,aj as Po,ak as Io,al as To,am as Ro,an as Ao,ao as qs,ap as Js,aq as Do,ar as Mo,as as _o,at as Lo,au as zo,av as Oo,aw as Bo,ax as Fo,ay as $o,az as Uo,aA as Wo,aB as Vo,aC as Go,aD as Ho,aE as Ko,aF as qo}from"./useAppFontEffects-CZdEKvZ8.js";import{u as rt,S as Jo,C as Yo,a as Xo,P as Qo,b as Zo,D as ei,N as ti,r as si,c as ni,d as ri,e as oi,O as ii,f as ai,g as Mt,h as li,M as ci,i as di,T as ui,j as fi,k as mi,A as hi,l as qe,m as pi,Q as gi,n as bi,o as xi}from"./runtimeEndpointReset-fpfBYOyW.js";import"./mobileLayoutPreference-Dio-WWkI.js";let sr=null,Ys=!1;const yi=new Promise(s=>{sr=s});function vi(){Ys||(Ys=!0,sr?.())}const wi=6,ji=s=>s.parentID??null,Xs=s=>{const e=s.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},ki=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),Si=(s,e)=>{if(!s)return"";let n=null,r=-1;for(const i of e){const o=ki(i.path);(s===o||s.startsWith(`${o}/`))&&o.length>r&&(n=i,r=o.length)}return n?n.label?.trim()||Xs(n.path):Xs(s)},Ni=()=>{const s=Ht.getState().activeSessions,e=Gr.getState().index.session.unseenCount,n=ut.getState().notifyOnSubtasks,r=Ae.getState().projects,i=ys.getState().ids,o=vs.getState().rankById;let a=0;const c=[];for(const u of s){const f=ji(u)!==null,p=(e[u.id]??0)>0&&(!f||n);p&&(a+=1),f||c.push({session:u,unread:p,project:Si(Vn(u),r)})}c.sort((u,f)=>Gn(u.session,f.session,i,o));const d=c.slice(0,wi).map(({session:u,unread:f,project:m})=>({id:u.id,title:u.title??"",unread:f,project:m}));return{runtimeKey:Vt(),attentionCount:a,recentSessions:d}},Ci="__OPENCHAMBER_WIDGET_SNAPSHOT__",Ei=()=>{typeof window>"u"||(window[Ci]=()=>{try{return JSON.stringify(Ni())}catch{return null}})},es="mobile-app-update-available",Qs="mobile-app-update-toast-dismissed-version",Pi=()=>{const s=ce.c(8),{t:e}=de(),n=rt(Ii),r=rt(Ti),i=rt(Ri),o=rt(Ai);let a;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,s[0]=a):a=s[0];const c=as.useRef(a);let d,u;return s[1]!==n||s[2]!==o||s[3]!==r||s[4]!==e||s[5]!==i?(d=()=>{if(Hn()!=="android"||r!=="mobile"||!n||!i||!o){oe.dismiss(es);return}Fs().getItem(Qs)!==i&&(c.current.has(i)||(c.current.add(i),oe.info(e("mobileUpdate.toast.available.title"),{id:es,description:e("mobileUpdate.toast.available.description",{version:i}),duration:1/0,icon:t.jsx(re,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{Hr(o)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{Fs().setItem(Qs,i),oe.dismiss(es)}}})))},u=[n,o,r,e,i],s[1]=n,s[2]=o,s[3]=r,s[4]=e,s[5]=i,s[6]=d,s[7]=u):(d=s[6],u=s[7]),as.useEffect(d,u),null};function Ii(s){return s.available}function Ti(s){return s.runtimeType}function Ri(s){return s.info?.version}function Ai(s){return s.info?.downloadUrl}const Di=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),Mi=s=>{const e=s.index?.trim();return!!(e&&e!=="?")},_i=s=>{const e=s.working_dir?.trim(),n=s.index?.trim();return!!(e||n==="?")},Zs=(s,e)=>e?`${s}\0staged`:s,en=({onClose:s,initialDiffPath:e,initialDiffStaged:n=!1})=>{const{t:r}=de(),{git:i}=Kt(),o=Di(ws()??null),a=js(o||null),c=Kn(o||null),d=Kr(o||null),u=De(L=>L.setActiveDirectory),f=De(L=>L.ensureAll),m=De(L=>L.fetchStatus),p=De(L=>L.fetchBranches),g=De(L=>L.prefetchDiffs),v=De(L=>L.getDiff),S=De(L=>L.setDiff),[y,C]=l.useState(()=>e?{type:"diff",path:e,staged:n}:{type:"list"});l.useEffect(()=>{e&&C(L=>L.type==="diff"&&L.path===e&&L.staged===n?L:{type:"diff",path:e,staged:n})},[e,n]);const[P,A]=l.useState(null),[T,D]=l.useState(null),[w,k]=l.useState(""),[R,E]=l.useState(new Set),[x,N]=l.useState(!1),[j,_]=l.useState(!1),[F,B]=l.useState([]),[M,Y]=l.useState([]),[I,U]=l.useState([]),[G,J]=l.useState(null),[q,z]=l.useState(null),[V,ee]=l.useState(0),X=l.useMemo(()=>{const L=a?.files??[],O=new Map;for(const se of L)O.set(se.path,se);return Array.from(O.values()).sort((se,me)=>se.path.localeCompare(me.path))},[a?.files]),b=l.useMemo(()=>X.filter(Mi),[X]),K=l.useMemo(()=>X.filter(_i),[X]),te=l.useMemo(()=>{if(I.length>0)return I;const L=a?.tracking?.includes("/")?a.tracking.split("/")[0]:null;return L||G?[{name:L||"origin",fetchUrl:G??"",pushUrl:G??""}]:[]},[G,I,a?.tracking]),ne=De(l.useCallback(L=>!o||y.type!=="diff"?null:L.directories.get(o)?.diffCache.get(Zs(y.path,y.staged))??null,[o,y])),ue=l.useMemo(()=>y.type!=="diff"?null:X.find(L=>L.path===y.path)??null,[X,y]),le=l.useCallback(async(L=!0)=>{if(o)try{await Promise.all([m(o,i),p(o,i)])}catch(O){L&&oe.error(O instanceof Error?O.message:r("gitView.toast.refreshRepositoryFailed"))}},[o,p,m,i,r]),Te=l.useCallback(async()=>{if(!o){U([]),J(null);return}try{const[L,O]=await Promise.all([i.getRemotes(o).catch(()=>[]),i.getRemoteUrl?i.getRemoteUrl(o).catch(()=>null):Promise.resolve(null)]);U(L),J(O)}catch{U([]),J(null)}},[o,i]);l.useEffect(()=>{o&&(u(o),f(o,i))},[o,f,i,u]),l.useEffect(()=>{Te()},[Te]),l.useEffect(()=>{if(!o||X.length===0)return;const L=Array.from(new Set([...b.map(se=>se.path),...M,...X.slice(0,20).map(se=>se.path)])).filter(Boolean);if(L.length===0)return;const O=window.setTimeout(()=>{g(o,i,L,{maxFiles:40})},120);return()=>window.clearTimeout(O)},[X,o,i,g,b,M]),l.useEffect(()=>{if(y.type!=="diff"){z(null);return}const L=Zs(y.path,y.staged);if(!o||v(o,L)){z(null);return}let O=!1;const se=Vt();return z(null),i.getGitFileDiff(o,{path:y.path,staged:y.staged||void 0}).then(me=>{O||S(o,L,{original:me.original??"",modified:me.modified??"",isBinary:me.isBinary},se)}).catch(me=>{O||z(me instanceof Error?me.message:String(me))}),()=>{O=!0}},[o,V,v,i,y,S]);const Ee=async(L,O)=>{if(o){A(L);try{const se=me=>{const _e=`${me.name}/`,$e=a?.tracking?.startsWith(_e)?a.tracking.slice(_e.length):void 0;return{remote:me.name,branch:$e,rebase:!0}};if(L==="fetch"){if(!O)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:O.name}),oe.success(r("gitView.toast.fetchedFromRemote",{name:O.name}))}else if(L==="sync"){if(!O)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:O.name});const me=await i.getGitStatus(o);if((me.behind??0)>0){if((me.files?.length??0)>0){oe.error(r("gitView.toast.commitOrStashBeforeSync"));return}await i.gitPull(o,se(O))}((await i.getGitStatus(o)).ahead??0)>0&&await i.gitPush(o),oe.success(r("gitView.toast.alreadyUpToDate"))}await le(!1),await Te()}catch(se){oe.error(se instanceof Error?se.message:r("gitView.toast.syncActionFailed",{action:r("gitView.sync.syncChanges")}))}finally{A(null)}}},ie=l.useCallback(async(L,O)=>{if(!(!o||L.length===0))try{O==="stage"?L.length>1?await qr(o,L):await Jr(o,L[0]):L.length>1?await Yr(o,L):await Xr(o,L[0]),await le(!1)}catch(se){oe.error(se instanceof Error?se.message:r(O==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[o,le,r]),xe=l.useCallback((L,O=!1)=>{C({type:"diff",path:L,staged:O})},[]),fe=l.useCallback(async L=>{if(o){E(O=>new Set(O).add(L));try{await i.revertGitFile(o,L),oe.success(r("gitView.toast.revertedFile",{path:L})),await le(!1)}catch(O){oe.error(O instanceof Error?O.message:r("gitView.toast.revertFailed"))}finally{E(O=>{const se=new Set(O);return se.delete(L),se})}}},[o,i,le,r]),ye=l.useCallback(async L=>{if(!o||L.length===0||x)return;const O=Array.from(new Set(L));N(!0),E(new Set(O));try{await Promise.all(O.map(se=>i.revertGitFile(o,se))),await le(!1),oe.success(O.length===1?r("gitView.toast.revertedFilesSingle",{count:O.length}):r("gitView.toast.revertedFilesPlural",{count:O.length}))}catch(se){oe.error(se instanceof Error?se.message:r("gitView.toast.revertFailed"))}finally{E(new Set),N(!1)}},[o,i,x,le,r]),Se=l.useCallback(L=>{const O=L.map(se=>se.trim()).filter(Boolean);if(O.length===0){B([]);return}k(se=>`${se.trim()}${se.trim()?`
3
+
4
+ `:""}${O.join(`
5
+ `)}`.trim()),B([])},[]),mt=l.useCallback(async()=>{if(!o)return;const L=b.map(O=>O.path).sort();if(L.length===0){oe.error(r("gitView.toast.selectFileToDescribe"));return}_(!0);try{const{message:O}=await Qr(o,L);k(O.subject?.trim()??""),B(Array.isArray(O.highlights)?O.highlights:[])}catch(O){oe.error(O instanceof Error?O.message:r("gitView.toast.generateCommitMessageFailed"))}finally{_(!1)}},[o,b,r]),Be=async(L={})=>{if(!o)return;if(!w.trim()){oe.error(r("gitView.toast.enterCommitMessage"));return}const O=b.map(se=>se.path).sort();if(O.length===0){oe.error(r("gitView.toast.selectFileToCommit"));return}D(L.pushAfter?"commitAndPush":"commit");try{if(await i.createGitCommit(o,w.trim(),{files:O}),oe.success(r("gitView.toast.commitCreated")),k(""),B([]),L.pushAfter){const se=a?.tracking?.split("/")[0],me=te.find(pt=>pt.name===se)??te[0];if(!me)throw new Error(r("mobile.changes.noRemote"));A("sync");const _e=`${me.name}/`,$e=a?.tracking?.startsWith(_e)?a.tracking.slice(_e.length):void 0;await i.gitFetch(o,{remote:me.name}),((await i.getGitStatus(o)).behind??0)>0&&await i.gitPull(o,{remote:me.name,branch:$e,rebase:!0}),((await i.getGitStatus(o)).ahead??0)>0&&await i.gitPush(o),await le(!1),await Te()}else await le(!1)}catch(se){oe.error(se instanceof Error?se.message:r("gitView.toast.createCommitFailed"))}finally{D(null),L.pushAfter&&A(null)}},ht=l.useMemo(()=>{const L=[];return b.length>0&&L.push({id:"staged",title:r("gitView.changes.stagedTitle"),entries:b,actionSymbol:"-",actionAllLabel:r("gitView.changes.unstageAllAria"),getActionLabel:O=>r("gitView.changes.unstageFileAria",{path:O}),onActionFile:O=>{ie([O],"unstage")},onActionAll:O=>{ie(O,"unstage")},onViewDiff:O=>xe(O,!0),onRevertFile:fe,showRevertActions:!1,accent:!0}),K.length>0&&L.push({id:"unstaged",title:r("gitView.changes.title"),entries:K,actionSymbol:"+",actionAllLabel:r("gitView.changes.stageAllAria"),getActionLabel:O=>r("gitView.changes.stageFileAria",{path:O}),onActionFile:O=>{ie([O],"stage")},onActionAll:O=>{ie(O,"stage")},onViewDiff:O=>xe(O,!1),onRevertFile:fe}),L},[fe,xe,ie,b,r,K]),Fe=L=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:r("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:a?.current||o||""})]})]}),t.jsx("div",{className:"min-h-0 flex-1",children:L})]});return o?d&&c===null?Fe(t.jsx(Ge,{loading:!0,message:r("gitView.loading.checkingRepository")})):c===!1?Fe(t.jsx(Ge,{icon:!0,message:r("gitView.empty.notGitRepository"),description:r("gitView.empty.notGitRepositoryDescription")})):y.type==="diff"?t.jsx(Li,{path:y.path,diff:ne,fileExists:!!ue,error:q,onBack:()=>C({type:"list"}),onRetry:()=>ee(L=>L+1)}):t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:r("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:a?.current||o})]}),t.jsx(Jo,{syncAction:P,remotes:te,onFetch:L=>{Ee("fetch",L)},onSync:L=>{Ee("sync",L)},disabled:T!==null||d,aheadCount:a?.ahead??0,behindCount:a?.behind??0,trackingRemoteName:a?.tracking?.split("/")[0],hasUncommittedChanges:X.length>0})]}),X.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-4 pt-4",children:t.jsx(Yo,{groups:ht,diffStats:a?.diffStats,revertingPaths:R,onRevertAll:ye,isRevertingAll:x,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:Y})}),t.jsx("div",{className:"shrink-0 border-t border-border/50 px-4 pb-4 pt-3",children:t.jsx(Xo,{stagedCount:b.length,commitMessage:w,onCommitMessageChange:k,generatedHighlights:F,onInsertHighlights:Se,onGenerateMessage:mt,isGeneratingMessage:j,onCommit:()=>{Be({pushAfter:!1})},onCommitAndPush:()=>{Be({pushAfter:!0})},commitAction:T,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Ge,{icon:!0,message:r("gitView.empty.cleanTitle"),description:r("mobile.changes.cleanDescription")})})]}):Fe(t.jsx(Ge,{message:r("gitView.empty.selectSessionOrDirectory")}))},Ge=s=>{const e=ce.c(13),{message:n,description:r,loading:i,icon:o}=s,a=i===void 0?!1:i,c=o===void 0?!1:o;let d;e[0]!==a?(d=a?t.jsx(re,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=a,e[1]=d):d=e[1];let u;e[2]!==c?(u=c?t.jsx(re,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=c,e[3]=u):u=e[3];let f;e[4]!==n?(f=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:n}),e[4]=n,e[5]=f):f=e[5];let m;e[6]!==r?(m=r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r}):null,e[6]=r,e[7]=m):m=e[7];let p;return e[8]!==d||e[9]!==u||e[10]!==f||e[11]!==m?(p=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[d,u,f,m]})}),e[8]=d,e[9]=u,e[10]=f,e[11]=m,e[12]=p):p=e[12],p},Li=s=>{const e=ce.c(24),{path:n,diff:r,fileExists:i,error:o,onBack:a,onRetry:c}=s,{t:d}=de();let u;e[0]!==n?(u=qn(n)||"text",e[0]=n,e[1]=u):u=e[1];const f=u;let m;e[2]!==d?(m=d("header.actions.backAria"),e[2]=d,e[3]=m):m=e[3];let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(re,{name:"arrow-left",className:"size-5"}),e[4]=p):p=e[4];let g;e[5]!==a||e[6]!==m?(g=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":m,onClick:a,children:p}),e[5]=a,e[6]=m,e[7]=g):g=e[7];let v;e[8]!==n?(v=t.jsx("div",{className:"min-w-0 flex-1 px-2",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:n})}),e[8]=n,e[9]=v):v=e[9];let S;e[10]!==g||e[11]!==v?(S=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/50 px-3 text-foreground",children:[g,v]}),e[10]=g,e[11]=v,e[12]=S):S=e[12];let y;e[13]!==r||e[14]!==o||e[15]!==i||e[16]!==f||e[17]!==c||e[18]!==n||e[19]!==d?(y=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:i?o?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:d("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}),t.jsx(ge,{type:"button",size:"sm",variant:"outline",onClick:c,children:d("diffView.actions.retry")})]})}):r?r.isBinary?t.jsx(Ge,{icon:!0,message:d("diffView.binary.unavailable")}):jt(n)?t.jsx(Ge,{icon:!0,message:d("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(Qe,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(Qo,{original:r.original,modified:r.modified,language:f,fileName:n,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(Ge,{loading:!0,message:d("diffView.state.loadingDiff")}):t.jsx(Ge,{icon:!0,message:d("mobile.changes.diffDetail.missingTitle"),description:d("mobile.changes.diffDetail.missingDescription")})}),e[13]=r,e[14]=o,e[15]=i,e[16]=f,e[17]=c,e[18]=n,e[19]=d,e[20]=y):y=e[20];let C;return e[21]!==S||e[22]!==y?(C=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[S,y]}),e[21]=S,e[22]=y,e[23]=C):C=e[23],C},tn=25e4,at=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),He=s=>{const e=at(s);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},zi=s=>{const e=at(s);if(!e||e==="/")return null;const n=e.lastIndexOf("/");return n<=0?e.startsWith("/")?"/":null:e.slice(0,n)},Oi=(s,e)=>{const n=at(s),r=at(e);return!r||n===r?He(n):n.startsWith(`${r}/`)?n.slice(r.length+1):n},Bi=s=>{if(typeof s!="number"||!Number.isFinite(s)||s<0)return"";if(s<1024)return`${s} B`;const e=["KB","MB","GB"];let n=s/1024;for(const r of e){if(n<1024||r===e[e.length-1])return`${n.toFixed(n>=10?0:1)} ${r}`;n/=1024}return""},Fi=s=>/\.(md|mdx|markdown)$/i.test(s),$i=s=>/\.(json|jsonc)$/i.test(s),sn=({onClose:s})=>{const{t:e}=de(),{files:n}=Kt(),r=at(ws()??null),[i,o]=l.useState(()=>({type:"browser",directory:r})),[a,c]=l.useState([]),[d,u]=l.useState(!1),[f,m]=l.useState(null),[p,g]=l.useState(""),[v,S]=l.useState([]),[y,C]=l.useState(!1),[P,A]=l.useState(""),[T,D]=l.useState(""),[w,k]=l.useState(null),[R,E]=l.useState(!1),x=l.useRef(0);l.useEffect(()=>{r&&o(z=>z.type==="browser"&&z.directory?z:{type:"browser",directory:r})},[r]);const N=i.type==="browser"?i.directory:i.returnDirectory,j=l.useCallback(async z=>{if(!z)return;const V=x.current+1;x.current=V,u(!0),m(null);try{const ee=await n.listDirectory(z);if(x.current!==V)return;c(ee.entries.slice().sort((X,b)=>X.isDirectory!==b.isDirectory?X.isDirectory?-1:1:X.name.localeCompare(b.name)))}catch(ee){if(x.current!==V)return;c([]),m(ee instanceof Error?ee.message:e("mobile.files.error.listFailed"))}finally{x.current===V&&u(!1)}},[n,e]);l.useEffect(()=>{i.type==="browser"&&j(i.directory)},[j,i]),l.useEffect(()=>{if(i.type!=="browser")return;const z=p.trim();if(!z){S([]),C(!1);return}let V=!1;const ee=window.setTimeout(()=>{C(!0),n.search({directory:i.directory,query:z,maxResults:40}).then(X=>{V||S(X)}).catch(()=>{V||S([])}).finally(()=>{V||C(!1)})},250);return()=>{V=!0,window.clearTimeout(ee)}},[n,p,i]),l.useEffect(()=>{if(i.type!=="file")return;if(A(""),D(""),k(null),jt(i.path)&&!i.path.toLowerCase().endsWith(".svg")){let V=!1,ee="";return E(!0),Gt("/api/fs/raw",{query:{path:i.path,directory:r||void 0}}).then(async X=>{if(!X.ok)throw new Error(e("filesView.error.readFileFailed"));if(ee=URL.createObjectURL(await X.blob()),V){URL.revokeObjectURL(ee),ee="";return}D(ee)}).catch(X=>{V||k(X instanceof Error?X.message:e("filesView.error.readFileFailed"))}).finally(()=>{V||E(!1)}),()=>{V=!0,ee&&URL.revokeObjectURL(ee)}}if(!n.readFile){k(e("mobile.files.error.readUnavailable")),E(!1);return}let z=!1;return E(!0),n.readFile(i.path).then(V=>{z||A(V.content.length>tn?`${V.content.slice(0,tn)}
6
+
7
+ ${e("mobile.files.file.truncated")}`:V.content)}).catch(V=>{z||k(V instanceof Error?V.message:e("filesView.error.readFileFailed"))}).finally(()=>{z||E(!1)}),()=>{z=!0}},[n,r,i,e]);const _=z=>{g(""),o({type:"browser",directory:z})},F=z=>{o({type:"file",path:z,returnDirectory:N||r})},B=async z=>{(await Gs(z)).ok?oe.success(e("mobile.files.toast.pathCopied")):oe.error(e("mobile.files.toast.copyFailed"))},M=async()=>{(await Gs(P)).ok?oe.success(e("mobile.files.toast.contentCopied")):oe.error(e("mobile.files.toast.copyFailed"))};if(!r)return t.jsx(lt,{message:e("mobile.files.empty.noDirectory")});if(i.type==="file")return t.jsx(Wi,{path:i.path,content:P,imageSrc:T,error:w,isLoading:R,onBack:()=>o({type:"browser",directory:i.returnDirectory}),onCopyPath:()=>{B(i.path)},onCopyContent:()=>{M()}});const Y=i.directory===r?e("mobile.files.rootDirectory"):He(i.directory),I=p.trim()?v:[],U=zi(i.directory),G=i.directory!==r&&U!==null&&(U===r||U.startsWith(`${r}/`)),J=G&&!p.trim(),q=G?U:null;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(Et,{className:"size-5"})}):null,J&&q?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.files.backToParentAria",{name:He(q)}),onClick:()=>_(q),style:{touchAction:"manipulation"},children:t.jsx(gs,{className:"size-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:Y})}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.files.refreshAria"),onClick:()=>{j(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(Cr,{className:Z("size-5",d&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-4 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(Pn,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ks,{value:p,onChange:z=>g(z.target.value),placeholder:e("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(Qe,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:f?t.jsx(lt,{message:f}):p.trim()?t.jsx(Ui,{results:I,isSearching:y,onOpenFile:F}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",children:[a.length===0&&!d?t.jsx("div",{className:"px-4 py-8 text-center typography-body text-muted-foreground",children:e("mobile.files.empty.directory")}):null,a.map(z=>t.jsx(nr,{name:z.name,path:z.path,directory:z.isDirectory,meta:z.isDirectory?void 0:Bi(z.size),onClick:()=>z.isDirectory?_(z.path):F(z.path)},z.path))]})})]})},nr=s=>{const e=ce.c(16),{name:n,path:r,directory:i,meta:o,onClick:a}=s;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={touchAction:"manipulation"},e[0]=c):c=e[0];let d;e[1]!==i||e[2]!==r?(d=i?t.jsx(Pr,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(eo,{filePath:r,className:"size-5 shrink-0"}),e[1]=i,e[2]=r,e[3]=d):d=e[3];let u;e[4]!==n?(u=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:n}),e[4]=n,e[5]=u):u=e[5];let f;e[6]!==o?(f=o?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:o}):null,e[6]=o,e[7]=f):f=e[7];let m;e[8]!==i?(m=i?t.jsx(Ir,{className:"size-4 shrink-0 text-muted-foreground/60"}):null,e[8]=i,e[9]=m):m=e[9];let p;return e[10]!==a||e[11]!==d||e[12]!==u||e[13]!==f||e[14]!==m?(p=t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/30 px-3 py-2.5 text-left transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:a,style:c,children:[d,u,f,m]}),e[10]=a,e[11]=d,e[12]=u,e[13]=f,e[14]=m,e[15]=p):p=e[15],p},Ui=s=>{const e=ce.c(10),{results:n,isSearching:r,onOpenFile:i}=s,{t:o}=de(),a=at(ws()??null);if(r){let f;e[0]!==o?(f=o("common.loading"),e[0]=o,e[1]=f):f=e[1];let m;return e[2]!==f?(m=t.jsx(lt,{loading:!0,message:f}),e[2]=f,e[3]=m):m=e[3],m}if(n.length===0){let f;e[4]!==o?(f=o("mobile.files.search.empty"),e[4]=o,e[5]=f):f=e[5];let m;return e[6]!==f?(m=t.jsx(lt,{message:f}),e[6]=f,e[7]=m):m=e[7],m}const c="overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",d=n.map(f=>t.jsx(nr,{name:He(f.path),path:f.path,directory:!1,meta:Oi(f.path,a),onClick:()=>i(f.path)},f.path));let u;return e[8]!==d?(u=t.jsx("div",{className:c,children:d}),e[8]=d,e[9]=u):u=e[9],u},Wi=s=>{const e=ce.c(35),{path:n,content:r,imageSrc:i,error:o,isLoading:a,onBack:c,onCopyPath:d,onCopyContent:u}=s,{t:f}=de();let m;e[0]!==f?(m=f("header.actions.backAria"),e[0]=f,e[1]=m):m=e[1];let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(gs,{className:"size-5"}),e[2]=p):p=e[2];let g;e[3]!==c||e[4]!==m?(g=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":m,onClick:c,children:p}),e[3]=c,e[4]=m,e[5]=g):g=e[5];let v;e[6]!==n?(v=He(n),e[6]=n,e[7]=v):v=e[7];let S;e[8]!==v?(S=t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:v})}),e[8]=v,e[9]=S):S=e[9];let y;e[10]!==u||e[11]!==n||e[12]!==f?(y=jt(n)?null:t.jsx(ge,{type:"button",variant:"ghost",size:"icon",onClick:u,"aria-label":f("mobile.files.copyContentAria"),children:t.jsx(Er,{className:"size-4"})}),e[10]=u,e[11]=n,e[12]=f,e[13]=y):y=e[13];let C;e[14]!==f?(C=f("mobile.files.copyPathAria"),e[14]=f,e[15]=C):C=e[15];let P;e[16]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(Tr,{className:"size-4"}),e[16]=P):P=e[16];let A;e[17]!==d||e[18]!==C?(A=t.jsx(ge,{type:"button",variant:"ghost",size:"icon",onClick:d,"aria-label":C,children:P}),e[17]=d,e[18]=C,e[19]=A):A=e[19];let T;e[20]!==g||e[21]!==S||e[22]!==y||e[23]!==A?(T=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/50 px-3 text-foreground",children:[g,S,y,A]}),e[20]=g,e[21]=S,e[22]=y,e[23]=A,e[24]=T):T=e[24];let D;e[25]!==r||e[26]!==o||e[27]!==i||e[28]!==a||e[29]!==n||e[30]!==f?(D=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:a?t.jsx(lt,{loading:!0,message:f("filesView.state.loading")}):o?t.jsx(lt,{message:o}):jt(n)&&i?t.jsx(Qe,{className:"h-full overflow-auto p-4",children:t.jsx("img",{src:i,alt:He(n),className:"mx-auto max-h-full max-w-full rounded-lg object-contain"})}):jt(n)?t.jsx(Qe,{className:"h-full overflow-auto p-4",children:t.jsx("img",{src:`data:${Zr(n)};utf8,${encodeURIComponent(r)}`,alt:He(n),className:"mx-auto max-h-full max-w-full rounded-lg object-contain"})}):t.jsx(Vi,{path:n,content:r})}),e[25]=r,e[26]=o,e[27]=i,e[28]=a,e[29]=n,e[30]=f,e[31]=D):D=e[31];let w;return e[32]!==T||e[33]!==D?(w=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[T,D]}),e[32]=T,e[33]=D,e[34]=w):w=e[34],w},Vi=s=>{const e=ce.c(32),{path:n,content:r}=s,{currentTheme:i,availableThemes:o,lightThemeId:a,darkThemeId:c}=Ss();let d;e[0]!==o||e[1]!==a?(d=o.find(k=>k.metadata.id===a)??$s(!1),e[0]=o,e[1]=a,e[2]=d):d=e[2];const u=d;let f;e[3]!==o||e[4]!==c?(f=o.find(k=>k.metadata.id===c)??$s(!0),e[3]=o,e[4]=c,e[5]=f):f=e[5];const m=f;let p,g;e[6]!==m||e[7]!==u?(p=()=>{Hs(u),Hs(m)},g=[m,u],e[6]=m,e[7]=u,e[8]=p,e[9]=g):(p=e[8],g=e[9]),l.useEffect(p,g);let v;e[10]!==m.metadata.id||e[11]!==u.metadata.id?(v={light:u.metadata.id,dark:m.metadata.id},e[10]=m.metadata.id,e[11]=u.metadata.id,e[12]=v):v=e[12];const S=v;if(Fi(n)){let k;return e[13]!==r?(k=t.jsx(Qe,{className:"h-full overflow-y-auto px-4 py-4",children:t.jsx(to,{content:r,enableFileReferences:!1})}),e[13]=r,e[14]=k):k=e[14],k}if($i(n)){let k;return e[15]!==r?(k=t.jsx(so,{jsonString:r,className:"h-full overflow-auto"}),e[15]=r,e[16]=k):k=e[16],k}let y;e[17]!==n?(y=He(n),e[17]=n,e[18]=y):y=e[18];let C;e[19]!==n?(C=qn(n)||void 0,e[19]=n,e[20]=C):C=e[20];let P;e[21]!==r||e[22]!==y||e[23]!==C?(P={name:y,contents:r,lang:C},e[21]=r,e[22]=y,e[23]=C,e[24]=P):P=e[24];const A=i.metadata.variant==="dark"?"dark":"light";let T;e[25]!==S||e[26]!==A?(T={disableFileHeader:!0,overflow:"wrap",theme:S,themeType:A,unsafeCSS:Zo},e[25]=S,e[26]=A,e[27]=T):T=e[27];let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D={minHeight:"100%"},e[28]=D):D=e[28];let w;return e[29]!==T||e[30]!==P?(w=t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx(Qe,{className:"min-h-0 flex-1 overflow-auto bg-[var(--syntax-base-background)]",children:t.jsx(Rr,{file:P,options:T,className:"block min-h-full w-full",style:D})})}),e[29]=T,e[30]=P,e[31]=w):w=e[31],w},lt=s=>{const e=ce.c(7),{message:n,loading:r}=s,i=r===void 0?!1:r;let o;e[0]!==i?(o=i?t.jsx(Ar,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(Dr,{className:"size-6 text-muted-foreground"}),e[0]=i,e[1]=o):o=e[1];let a;e[2]!==n?(a=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:n}),e[2]=n,e[3]=a):a=e[3];let c;return e[4]!==o||e[5]!==a?(c=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[o,a]})}),e[4]=o,e[5]=a,e[6]=c):c=e[6],c},nn=bs(s=>({expandedParents:{},toggleParent:e=>s(n=>{const r={...n.expandedParents};return r[e]?delete r[e]:r[e]=!0,{expandedParents:r}})})),_t=bs()(In(s=>({projectExpanded:{},worktreeExpanded:{},setProjectExpanded:(e,n)=>s(r=>({projectExpanded:{...r.projectExpanded,[e]:n}})),setWorktreeExpanded:(e,n)=>s(r=>({worktreeExpanded:{...r.worktreeExpanded,[e]:n}}))}),{name:"mobile-session-tree"})),rr=bs()(In(s=>({orderByProject:{},setWorktreeOrder:(e,n)=>s(r=>({orderByProject:{...r.orderByProject,[e]:n}}))}),{name:"mobile-worktree-order"})),rn=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),Gi=(s,e)=>{if(!s||s.length===0)return e;const n=new Map(s.map((i,o)=>[rn(i),o])),r=i=>n.get(rn(i.path))??Number.MAX_SAFE_INTEGER;return e.map((i,o)=>({worktree:i,index:o})).sort((i,o)=>{const a=r(i.worktree)-r(o.worktree);return a!==0?a:i.index-o.index}).map(i=>i.worktree)},yt=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/,""),Hi=s=>{const e=s;return yt(e.directory??e.project?.worktree??null)},Ki=({open:s,project:e,worktree:n,onClose:r,onDeleted:i})=>{const{t:o}=de(),a=Jn(),c=Ht(E=>E.activeSessions),d=be(E=>E.archiveSessions),u=it(E=>E.currentDirectory),[f,m]=l.useState(!1),[p,g]=l.useState(!1),[v,S]=l.useState(!1),[y,C]=l.useState(!1),P=yt(n?.path),A=typeof n?.branch=="string"&&n.branch.trim().length>0,T=l.useMemo(()=>{if(!P)return[];const E=new Map;for(const x of[...c,...a])Hi(x)===P&&E.set(x.id,x);return Array.from(E.values())},[c,a,P]);l.useEffect(()=>{if(!s){m(!1),g(!1),S(!1),C(!1);return}if(!n?.path)return;let E=!1;return no(n.path).then(x=>{E||S(!!x?.isDirty)}).catch(()=>{E||S(!!n.status?.isDirty)}),()=>{E=!0}},[s,n?.path,n?.status?.isDirty]);const D=l.useCallback(E=>{(async()=>{try{await ro(e,E,{deleteRemoteBranch:A&&p,deleteLocalBranch:A&&f}),yt(u)===P&&yt(e.path)&&it.getState().setDirectory(yt(e.path),{showOverlay:!1}),oe.success(o("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:o(A&&p?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),i?.()}catch(x){oe.error(o("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:x instanceof Error?x.message:o("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[u,f,p,A,i,e,o,P]),w=async()=>{if(!(!n||y)){C(!0);try{if(T.length>0){const{archivedIds:E,failedIds:x}=await d(T.map(N=>N.id));if(x.length>0){E.length>0&&oe.success(E.length===1?o("sessions.sidebar.bulkActions.archivedSingle",{count:E.length}):o("sessions.sidebar.bulkActions.archivedPlural",{count:E.length})),oe.error(x.length===1?o("sessions.sidebar.bulkActions.failedArchiveSingle",{count:x.length}):o("sessions.sidebar.bulkActions.failedArchivePlural",{count:x.length}),{description:o("sessions.sidebar.dialogs.deleteResult.tryAgain")}),C(!1);return}}D(n),r()}catch(E){oe.error(o("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:E instanceof Error?E.message:o("sessions.sidebar.dialogs.deleteResult.tryAgain")}),C(!1)}finally{s||C(!1)}}};if(!n)return null;const k=n.branch||n.label||n.path,R=(E,x,N,j)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":E,disabled:j,onClick:()=>x(!E),className:Z("flex w-full items-center justify-between gap-3 rounded-xl border border-border/50 px-3.5 py-3 text-left transition-colors","hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",j&&"pointer-events-none opacity-40"),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:N}),t.jsx("span",{className:Z("relative h-6 w-10 shrink-0 rounded-full transition-colors",E?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:Z("absolute top-0.5 size-5 rounded-full bg-white transition-transform",E?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx(Yn,{open:s,onClose:r,title:o("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ge,{variant:"ghost",className:"flex-1",onClick:r,disabled:y,children:o("projectEditDialog.actions.cancel")}),t.jsx(ge,{variant:"destructive",className:"flex-1",onClick:()=>{w()},disabled:y,children:o("mobile.projectEdit.deleteWorktreeConfirmButton")})]}),children:t.jsxs("div",{className:"flex flex-col gap-4 px-1 py-1",children:[t.jsx("p",{className:"typography-ui-body text-foreground",children:o("mobile.projectEdit.deleteWorktreeConfirm",{name:k})}),v?t.jsx("p",{className:"rounded-xl border border-[var(--warning)]/40 bg-[color-mix(in_srgb,var(--warning)_10%,transparent)] px-3.5 py-3 typography-meta text-foreground",children:o("mobile.projectEdit.deleteWorktreeDirty")}):null,T.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o("mobile.projectEdit.deleteWorktreeArchiveNote",{count:T.length})}):null,A?t.jsxs("div",{className:"flex flex-col gap-2",children:[R(f,m,o("mobile.projectEdit.deleteLocalBranch"),y),R(p,g,o("mobile.projectEdit.deleteRemoteBranch"),y)]}):null]})})},on="mobile-surface-root",qi=90,ts=16,an=100,Ji=48,Yi=8,Xi=()=>{if(typeof document>"u")return null;let s=document.getElementById(on);return s||(s=document.createElement("div"),s.id=on,document.body.appendChild(s)),s},Ve=({open:s,onClose:e,title:n,subtitle:r,trailing:i,onBack:o,disableSwipeDismiss:a=!1,disableEscapeDismiss:c=!1,headerless:d=!1,ariaLabel:u,children:f})=>{const{t:m}=de(),p=l.useRef(null),[g,v]=l.useState(!1),[S,y]=l.useState(!1),[C,P]=l.useState(!1),[A,T]=l.useState(0),D=l.useRef(null),w=l.useRef(!1),k=l.useRef(null),R=l.useRef(null),E=l.useRef(e);l.useEffect(()=>{E.current=e},[e]),typeof document<"u"&&!p.current&&(p.current=Xi()),l.useEffect(()=>{if(s){v(!0);const M=window.setTimeout(()=>y(!0),ts);return()=>window.clearTimeout(M)}y(!1);const B=window.setTimeout(()=>v(!1),300);return()=>window.clearTimeout(B)},[s]),l.useEffect(()=>{if(!s){P(!1);return}const B=window.setTimeout(()=>P(!0),ts+an+80);return()=>window.clearTimeout(B)},[s]),l.useEffect(()=>{if(!s)return;const B=document.body.style.overflow;R.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const M=()=>{const U=k.current;if(!U)return;(U.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??U).focus({preventScroll:!0})},Y=window.setTimeout(M,ts),I=U=>{if(U.key==="Escape"&&!c){E.current();return}if(U.key!=="Tab")return;const G=k.current;if(!G)return;const J=Array.from(G.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(ee=>!ee.hasAttribute("disabled")&&ee.getAttribute("aria-hidden")!=="true");if(J.length===0){U.preventDefault(),G.focus({preventScroll:!0});return}const q=J[0],z=J[J.length-1],V=document.activeElement;U.shiftKey&&V===q?(U.preventDefault(),z.focus({preventScroll:!0})):!U.shiftKey&&V===z&&(U.preventDefault(),q.focus({preventScroll:!0}))};return document.addEventListener("keydown",I),()=>{window.clearTimeout(Y),document.body.style.overflow=B,document.removeEventListener("keydown",I),R.current?.focus?.({preventScroll:!0}),R.current=null}},[c,s]);const x=B=>{a||(D.current=B.touches[0]?.clientY??null,w.current=!0)},N=B=>{if(!w.current||D.current==null)return;const Y=(B.touches[0]?.clientY??D.current)-D.current;T(Y>0?Y:0)},j=()=>{w.current&&(w.current=!1,D.current=null,A>=qi?(T(0),e()):T(0))};if(!g||!p.current)return null;const _=o?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":m("header.actions.backAria"),onClick:o,style:{touchAction:"manipulation"},children:t.jsx(gs,{className:"size-5"})}):t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":m("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(Et,{className:"size-5"})}),F=S?A>0?`translateY(${A}px)`:"none":`translateY(${Ji}px)`;return Mr.createPortal(t.jsxs("div",{className:Z("oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-[rgb(0_0_0_/_0.45)]","transition-opacity duration-200 ease-out",S?"opacity-100":"opacity-0"),role:"dialog","aria-modal":"true","aria-label":u,onClick:e,children:[t.jsxs("section",{ref:k,className:"mt-auto flex min-h-0 w-full flex-col overflow-hidden rounded-t-[20px] border-t border-border/40 bg-background text-foreground",tabIndex:-1,onClick:B=>B.stopPropagation(),onTransitionEnd:B=>{S&&B.target===B.currentTarget&&B.propertyName==="transform"&&P(!0)},style:{height:`calc(100% - var(--oc-safe-area-top, 0px) - ${Yi}px)`,transform:F,transition:w.current?"none":`transform ${an}ms cubic-bezier(0.32, 0.72, 0, 1)`},children:[t.jsxs("div",{className:"shrink-0 select-none",onTouchStart:x,onTouchMove:N,onTouchEnd:j,onTouchCancel:j,children:[a?t.jsx("div",{className:"h-3"}):t.jsx("div",{className:"flex items-center justify-center pt-2 pb-1",children:t.jsx("span",{className:"h-1 w-10 rounded-full bg-[var(--surface-muted)]","aria-hidden":!0})}),d?null:t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] items-center gap-2 px-3",children:[_,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[n?typeof n=="string"?t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:n}):n:null,r?typeof r=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:r}):r:null]}),i?t.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:i}):null]})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:C?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:f}):null})]}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]}),p.current)},Qi=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/,""),Zi=s=>{const e=ce.c(36),{worktree:n,onDelete:r}=s,{t:i}=de();let o;e[0]!==n.path?(o={id:n.path},e[0]=n.path,e[1]=o):o=e[1];const{attributes:a,listeners:c,setNodeRef:d,transform:u,transition:f,isDragging:m}=Bn(o);let p;e[2]!==u?(p=Fn.Transform.toString(u),e[2]=u,e[3]=p):p=e[3];const g=m?10:1;let v;e[4]!==p||e[5]!==g||e[6]!==f?(v={transform:p,transition:f,zIndex:g},e[4]=p,e[5]=g,e[6]=f,e[7]=v):v=e[7];const S=v,y=n.branch||n.label||n.path,C=m&&"shadow-lg shadow-black/20";let P;e[8]!==C?(P=Z("flex items-center gap-1 rounded-2xl border border-border/40 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",C),e[8]=C,e[9]=P):P=e[9];let A;e[10]!==y||e[11]!==i?(A=i("mobile.projectEdit.dragWorktreeAria",{label:y}),e[10]=y,e[11]=i,e[12]=A):A=e[12];let T;e[13]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx($n,{className:"size-4"}),e[13]=T):T=e[13];let D;e[14]!==a||e[15]!==c||e[16]!==A?(D=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":A,...a,...c,children:T}),e[14]=a,e[15]=c,e[16]=A,e[17]=D):D=e[17];let w;e[18]===Symbol.for("react.memo_cache_sentinel")?(w=t.jsx(re,{name:"node-tree",className:"size-4 shrink-0 text-muted-foreground"}),e[18]=w):w=e[18];let k;e[19]!==y?(k=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:y}),e[19]=y,e[20]=k):k=e[20];let R;e[21]!==y||e[22]!==i?(R=i("mobile.projectEdit.deleteWorktreeAria",{label:y}),e[21]=y,e[22]=i,e[23]=R):R=e[23];let E,x;e[24]===Symbol.for("react.memo_cache_sentinel")?(E={touchAction:"manipulation"},x=t.jsx(cs,{className:"size-4"}),e[24]=E,e[25]=x):(E=e[24],x=e[25]);let N;e[26]!==r||e[27]!==R?(N=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":R,onClick:r,style:E,children:x}),e[26]=r,e[27]=R,e[28]=N):N=e[28];let j;return e[29]!==d||e[30]!==S||e[31]!==k||e[32]!==N||e[33]!==P||e[34]!==D?(j=t.jsxs("div",{ref:d,style:S,className:P,children:[D,w,k,N]}),e[29]=d,e[30]=S,e[31]=k,e[32]=N,e[33]=P,e[34]=D,e[35]=j):j=e[35],j},ea=({open:s,project:e,onClose:n,onWorktreesChanged:r})=>{const{t:i}=de(),{currentTheme:o}=Ss(),a=Ae(M=>M.updateProjectMeta),c=Ae(M=>M.discoverProjectIcon),d=Ae(M=>M.removeProjectIcon),u=rr(M=>M.setWorktreeOrder),f=Ae(M=>e?M.projects.find(Y=>Y.id===e.id)?.iconImage??null:null),[m,p]=l.useState(""),[g,v]=l.useState(null),[S,y]=l.useState(null),[C,P]=l.useState(!1),[A,T]=l.useState([]),[D,w]=l.useState(null),k=e?.id??null;l.useEffect(()=>{!s||!e||(p(e.label),v(e.icon??null),y(e.color??null),T(e.worktrees))},[s,k]),l.useEffect(()=>{!s||!e||T(M=>{const Y=e.worktrees.map(G=>G.path),I=M.map(G=>G.path);return Y.length===I.length&&Y.every(G=>I.includes(G))?M:e.worktrees})},[e?.worktrees]);const R=Tn(Ot(Dn,{activationConstraint:{distance:8}}),Ot(An,{coordinateGetter:Rn})),E=()=>{if(!e)return;const M=m.trim();a(e.id,{label:M||e.label,icon:g,color:S}),n()},x=()=>{!e||C||(P(!0),c(e.id).then(M=>{if(!M.ok){oe.error(M.error||i("projectEditDialog.toast.failedToDiscoverIcon"));return}if(M.skipped){oe.success(i("projectEditDialog.toast.customIconAlreadySet"));return}oe.success(i("projectEditDialog.toast.iconDiscovered"))}).finally(()=>P(!1)))},N=()=>{e&&d(e.id).then(M=>{if(!M.ok){oe.error(M.error||i("projectEditDialog.toast.failedToRemoveIcon"));return}oe.success(i("projectEditDialog.toast.iconRemoved"))})},j=M=>{const{active:Y,over:I}=M;if(!I||Y.id===I.id||!e)return;const U=A.findIndex(z=>z.path===Y.id),G=A.findIndex(z=>z.path===I.id);if(U<0||G<0)return;const J=[...A],[q]=J.splice(U,1);J.splice(G,0,q),T(J),u(e.id,J.map(z=>Qi(z.path)))},_=S?Xn[S]??null:null,F=g?Qn[g]:null,B=!!f;return t.jsxs(t.Fragment,{children:[t.jsx(Ve,{open:s,onClose:n,onBack:n,title:i("projectEditDialog.title"),ariaLabel:i("projectEditDialog.title"),trailing:t.jsxs(ge,{type:"button",variant:"default",size:"sm","aria-label":i("projectEditDialog.actions.save"),onClick:E,disabled:!m.trim(),style:{touchAction:"manipulation"},children:[t.jsx(On,{className:"size-4"}),i("projectEditDialog.actions.save")]}),children:e?t.jsxs("div",{className:"h-full space-y-6 overflow-y-auto px-4 pb-8 pt-2",children:[t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx("span",{className:"flex size-16 items-center justify-center overflow-hidden rounded-2xl bg-[var(--surface-muted)] text-muted-foreground",style:e.iconBackground?{backgroundColor:e.iconBackground}:void 0,children:B?t.jsx(Zn,{project:{id:e.id,iconImage:f},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(ls,{className:"size-7"})}):F?t.jsx(re,{name:F,className:"size-7",style:_?{color:_}:void 0}):t.jsx(ls,{className:"size-7",style:_?{color:_}:void 0})})}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:i("projectEditDialog.field.name")}),t.jsx(ks,{value:m,onChange:M=>p(M.target.value),placeholder:i("projectEditDialog.field.namePlaceholder"),className:"h-11"}),t.jsx("p",{className:"truncate typography-meta text-muted-foreground",title:e.path,children:e.path})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:i("projectEditDialog.field.color")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>y(null),"aria-label":i("projectEditDialog.option.none"),className:Z("flex size-9 items-center justify-center rounded-xl border-2 transition-all",S===null?"border-foreground":"border-border hover:border-border/80"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),oo.map(M=>t.jsx("button",{type:"button",onClick:()=>y(M.key),"aria-label":M.label,title:M.label,className:Z("size-9 rounded-xl border-2 transition-all",S===M.key?"border-foreground":"border-transparent hover:border-border"),style:{backgroundColor:M.cssVar,touchAction:"manipulation"}},M.key))]})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:i("projectEditDialog.field.icon")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>v(null),"aria-label":i("projectEditDialog.option.none"),className:Z("flex size-9 items-center justify-center rounded-xl border-2 transition-all",g===null?"border-foreground bg-[var(--surface-elevated)]":"border-border hover:border-border/80"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),io.map(M=>t.jsx("button",{type:"button",onClick:()=>v(M.key),"aria-label":M.label,title:M.label,className:Z("flex size-9 items-center justify-center rounded-xl border-2 transition-all",g===M.key?"border-foreground bg-[var(--surface-elevated)]":"border-border hover:border-border/80"),style:{touchAction:"manipulation"},children:t.jsx(re,{name:M.Icon,className:"size-4",style:_?{color:_}:void 0})},M.key))]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[t.jsx(ge,{size:"sm",variant:"outline",onClick:x,disabled:C,children:i(C?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),B?t.jsx(ge,{size:"sm",variant:"outline",onClick:N,children:i("projectEditDialog.actions.removeProjectIcon")}):null]})]}),e.isGitRepo?t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:i("mobile.projectEdit.worktreesTitle")}),A.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("mobile.projectEdit.worktreesEmpty")}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("mobile.projectEdit.reorderHint")}),t.jsx(Mn,{sensors:R,collisionDetection:_n,onDragEnd:j,children:t.jsx(Ln,{items:A.map(M=>M.path),strategy:zn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:A.map(M=>t.jsx(Zi,{worktree:M,onDelete:()=>w(M)},M.path))})})})]})]}):null]}):null}),e?t.jsx(Ki,{open:!!D,project:{id:e.id,path:e.path},worktree:D,onClose:()=>w(null),onDeleted:()=>{T(M=>M.filter(Y=>Y.path!==D?.path)),r?.()}}):null]})},ta=new Set,ss=7,sa=36,na=52,ra=18,Lt=s=>s.parentID??null,Ie=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),nt=s=>{const e=s;return Ie(e.directory??e.project?.worktree??null)},ns=s=>{const e=Ie(s);if(!e)return"";const n=e.split("/").filter(Boolean);return n[n.length-1]?.replace(/[-_]/g," ")||e},oa=s=>{const e=s.time?.updated??s.time?.created,n=typeof e=="number"?e:Number(e);return Number.isFinite(n)&&n>0?n:0},ia=s=>{if(s<=0)return"";const e=Date.now()-s;if(e<6e4)return"now";const n=Math.floor(e/6e4);if(n<60)return`${n}m`;const r=Math.floor(n/60);if(r<24)return`${r}h`;const i=Math.floor(r/24);return i<7?`${i}d`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(s))},aa=(s,e)=>{const n=Ie(s),r=Ie(e);return!!(n&&r&&(n===r||n.startsWith(`${r}/`)))},ds=(s,e)=>s.worktrees.find(n=>Ie(n.path)===e)??null,us=(s,e)=>e===s.path||!!ds(s,e),rs=(s,e)=>{const n=Ie(e);return n?s.find(r=>us(r,n))??null:null},os=(s,e,n)=>n?`${s.title??""} ${s.id} ${nt(s)} ${e}`.toLowerCase().includes(n):!0,fs=s=>{const e=ce.c(17),{project:n,size:r}=s,i=r===void 0?"md":r,{currentTheme:o}=Ss(),a=n.icon?Qn[n.icon]:null,c=n.color?Xn[n.color]??null:null,d=i==="sm"?"size-6 rounded-md":"size-8 rounded-lg",u=i==="sm"?"size-3.5":"size-4";let f;e[0]!==a||e[1]!==c||e[2]!==u?(f=a?t.jsx(re,{name:a,className:u,style:c?{color:c}:void 0}):t.jsx(ls,{className:u,style:c?{color:c}:void 0}),e[0]=a,e[1]=c,e[2]=u,e[3]=f):f=e[3];const m=f;let p;e[4]!==d?(p=Z("flex shrink-0 items-center justify-center overflow-hidden bg-[var(--surface-muted)] text-muted-foreground",d),e[4]=d,e[5]=p):p=e[5];let g;e[6]!==n.iconBackground?(g=n.iconBackground?{backgroundColor:n.iconBackground}:void 0,e[6]=n.iconBackground,e[7]=g):g=e[7];let v;e[8]!==o||e[9]!==m||e[10]!==n.iconImage||e[11]!==n.id?(v=n.iconImage?t.jsx(Zn,{project:{id:n.id,iconImage:n.iconImage??null},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"size-full object-contain",fallback:m}):m,e[8]=o,e[9]=m,e[10]=n.iconImage,e[11]=n.id,e[12]=v):v=e[12];let S;return e[13]!==p||e[14]!==g||e[15]!==v?(S=t.jsx("span",{className:p,style:g,children:v}),e[13]=p,e[14]=g,e[15]=v,e[16]=S):S=e[16],S},la=s=>{const e=ce.c(5),{expanded:n}=s,r=n?"rotate-0":"-rotate-90";let i;e[0]!==r?(i=Z("flex size-5 shrink-0 items-center justify-center text-muted-foreground/70 transition-transform duration-150",r),e[0]=r,e[1]=i):i=e[1];let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx(xs,{className:"size-4"}),e[2]=o):o=e[2];let a;return e[3]!==i?(a=t.jsx("span",{"aria-hidden":!0,className:i,children:o}),e[3]=i,e[4]=a):a=e[4],a},ln=s=>{const e=ce.c(2),{ariaLabel:n}=s;let r;return e[0]!==n?(r=t.jsx("span",{className:"inline-block size-1.5 shrink-0 rounded-full bg-primary","aria-label":n}),e[0]=n,e[1]=r):r=e[1],r},cn=s=>{const e=ce.c(12),{onClick:n,className:r}=s,{t:i}=de();let o;e[0]!==i?(o=i("sessions.sidebar.project.actions.newWorktree"),e[0]=i,e[1]=o):o=e[1];const a=o;let c;e[2]!==r?(c=Z("flex size-9 shrink-0 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",r),e[2]=r,e[3]=c):c=e[3];let d;e[4]!==n?(d=p=>{p.stopPropagation(),n()},e[4]=n,e[5]=d):d=e[5];let u,f;e[6]===Symbol.for("react.memo_cache_sentinel")?(u={touchAction:"manipulation"},f=t.jsx(re,{name:"node-tree",className:"size-4"}),e[6]=u,e[7]=f):(u=e[6],f=e[7]);let m;return e[8]!==a||e[9]!==c||e[10]!==d?(m=t.jsx("button",{type:"button",className:c,"aria-label":a,title:a,onClick:d,style:u,children:f}),e[8]=a,e[9]=c,e[10]=d,e[11]=m):m=e[11],m},dn=s=>{const e=ce.c(55),{session:n,active:r,indent:i,contextLabel:o,confirmingArchive:a,hasChildren:c,expanded:d,onToggleChildren:u,onSelect:f,onRequestArchive:m,onConfirmArchive:p}=s,g=a===void 0?!1:a,v=c===void 0?!1:c,S=d===void 0?!1:d,{t:y}=de();let C;e[0]!==n?(C=ia(oa(n)),e[0]=n,e[1]=C):C=e[1];const P=C;let A;e[2]!==n.title||e[3]!==y?(A=n.title?.trim()||y("mobile.sessions.untitled"),e[2]=n.title,e[3]=y,e[4]=A):A=e[4];const T=A,D=r&&!g&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]",w=g&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]";let k;e[5]!==D||e[6]!==w?(k=Z("relative flex items-center gap-1 transition-colors",D,w),e[5]=D,e[6]=w,e[7]=k):k=e[7];let R;e[8]!==S||e[9]!==v||e[10]!==i||e[11]!==u||e[12]!==y?(R=v&&u?t.jsx("button",{type:"button",className:"absolute z-10 flex w-6 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",style:{left:Math.max(i-32,2),top:0,bottom:0,touchAction:"manipulation"},"aria-label":y(S?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),onClick:ee=>{ee.stopPropagation(),u()},children:t.jsx(xs,{className:Z("size-[18px] transition-transform duration-150",S?"rotate-0":"-rotate-90")})}):null,e[8]=S,e[9]=v,e[10]=i,e[11]=u,e[12]=y,e[13]=R):R=e[13];const E=g&&"opacity-50";let x;e[14]!==E?(x=Z("flex min-h-12 min-w-0 flex-1 items-center gap-2.5 py-2 pr-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",E),e[14]=E,e[15]=x):x=e[15];let N;e[16]!==i?(N={paddingLeft:i,touchAction:"manipulation"},e[16]=i,e[17]=N):N=e[17];const j=r?"bg-primary":"bg-muted-foreground/30";let _;e[18]!==j?(_=Z("size-1.5 shrink-0 rounded-full",j),e[18]=j,e[19]=_):_=e[19];let F;e[20]!==_?(F=t.jsx("span",{className:_,"aria-hidden":!0}),e[20]=_,e[21]=F):F=e[21];const B=r?"text-primary":"text-foreground";let M;e[22]!==B?(M=Z("block min-w-0 flex-1 truncate typography-ui-label",B),e[22]=B,e[23]=M):M=e[23];let Y;e[24]!==M||e[25]!==T?(Y=t.jsx("span",{className:M,children:T}),e[24]=M,e[25]=T,e[26]=Y):Y=e[26];let I;e[27]!==P?(I=P?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:P}):null,e[27]=P,e[28]=I):I=e[28];let U;e[29]!==F||e[30]!==Y||e[31]!==I?(U=t.jsxs("span",{className:"flex items-center gap-2.5",children:[F,Y,I]}),e[29]=F,e[30]=Y,e[31]=I,e[32]=U):U=e[32];let G;e[33]!==o?(G=o?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground pl-4",children:o}):null,e[33]=o,e[34]=G):G=e[34];let J;e[35]!==U||e[36]!==G?(J=t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[U,G]}),e[35]=U,e[36]=G,e[37]=J):J=e[37];let q;e[38]!==g||e[39]!==f||e[40]!==x||e[41]!==N||e[42]!==J?(q=t.jsx("button",{type:"button",className:x,style:N,onClick:f,disabled:g,children:J}),e[38]=g,e[39]=f,e[40]=x,e[41]=N,e[42]=J,e[43]=q):q=e[43];let z;e[44]!==g||e[45]!==p||e[46]!==m||e[47]!==y||e[48]!==T?(z=m?t.jsxs(t.Fragment,{children:[g?t.jsxs("button",{type:"button",className:"flex h-9 shrink-0 items-center gap-1.5 rounded-xl bg-destructive px-3 text-destructive-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":y("mobile.sessions.archiveSessionAria",{title:T}),onClick:p,style:{touchAction:"manipulation"},children:[t.jsx(Bs,{className:"size-4"}),t.jsx("span",{className:"typography-ui-label",children:y("sessions.sidebar.bulkActions.archive")})]}):null,t.jsx("button",{type:"button",className:"mr-1.5 flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":g?y("mobile.sessions.cancelArchiveAria",{title:T}):y("mobile.sessions.archiveSessionAria",{title:T}),onClick:m,style:{touchAction:"manipulation"},children:g?t.jsx(Et,{className:"size-4"}):t.jsx(Bs,{className:"size-4"})})]}):null,e[44]=g,e[45]=p,e[46]=m,e[47]=y,e[48]=T,e[49]=z):z=e[49];let V;return e[50]!==q||e[51]!==z||e[52]!==k||e[53]!==R?(V=t.jsxs("div",{className:k,children:[R,q,z]}),e[50]=q,e[51]=z,e[52]=k,e[53]=R,e[54]=V):V=e[54],V},ca=s=>{const e=ce.c(11),{indent:n,onClick:r}=s,{t:i}=de();let o;e[0]!==n?(o={paddingLeft:n,touchAction:"manipulation"},e[0]=n,e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(xs,{className:"size-4"}),e[2]=a):a=e[2];let c;e[3]!==i?(c=i("sessions.sidebar.group.showMore"),e[3]=i,e[4]=c):c=e[4];let d;e[5]!==c?(d=t.jsx("span",{className:"typography-micro",children:c}),e[5]=c,e[6]=d):d=e[6];let u;return e[7]!==r||e[8]!==o||e[9]!==d?(u=t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 py-1.5 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",style:o,onClick:r,children:[a,d]}),e[7]=r,e[8]=o,e[9]=d,e[10]=u):u=e[10],u},da=s=>{const e=ce.c(11),{indent:n,onClick:r}=s,{t:i}=de();let o;e[0]!==n?(o={paddingLeft:n,touchAction:"manipulation"},e[0]=n,e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(Lr,{className:"size-4"}),e[2]=a):a=e[2];let c;e[3]!==i?(c=i("sessions.sidebar.group.showFewer"),e[3]=i,e[4]=c):c=e[4];let d;e[5]!==c?(d=t.jsx("span",{className:"typography-micro",children:c}),e[5]=c,e[6]=d):d=e[6];let u;return e[7]!==r||e[8]!==o||e[9]!==d?(u=t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 py-1.5 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",style:o,onClick:r,children:[a,d]}),e[7]=r,e[8]=o,e[9]=d,e[10]=u):u=e[10],u},ua=s=>{const e=ce.c(53),{project:n,totalSessions:r,confirmingDelete:i,onEdit:o,onRequestRemove:a,onConfirmRemove:c}=s,{t:d}=de();let u;e[0]!==n.id?(u={id:n.id},e[0]=n.id,e[1]=u):u=e[1];const{attributes:f,listeners:m,setNodeRef:p,transform:g,transition:v,isDragging:S}=Bn(u);let y;e[2]!==g?(y=Fn.Transform.toString(g),e[2]=g,e[3]=y):y=e[3];const C=S?10:1;let P;e[4]!==y||e[5]!==C||e[6]!==v?(P={transform:y,transition:v,zIndex:C},e[4]=y,e[5]=C,e[6]=v,e[7]=P):P=e[7];const A=P,T=S&&"shadow-lg shadow-black/20",D=i&&"border-destructive/50 bg-[color-mix(in_srgb,var(--destructive)_8%,var(--surface-elevated))]";let w;e[8]!==T||e[9]!==D?(w=Z("flex items-center gap-1 rounded-2xl border border-border/40 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",T,D),e[8]=T,e[9]=D,e[10]=w):w=e[10];let k;e[11]!==n.label||e[12]!==d?(k=d("mobile.sessions.dragHandleAria",{label:n.label}),e[11]=n.label,e[12]=d,e[13]=k):k=e[13];let R;e[14]===Symbol.for("react.memo_cache_sentinel")?(R=t.jsx($n,{className:"size-4"}),e[14]=R):R=e[14];let E;e[15]!==f||e[16]!==m||e[17]!==k?(E=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":k,...f,...m,children:R}),e[15]=f,e[16]=m,e[17]=k,e[18]=E):E=e[18];let x;e[19]!==n?(x=t.jsx(fs,{project:n}),e[19]=n,e[20]=x):x=e[20];let N;e[21]!==n.label?(N=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:n.label}),e[21]=n.label,e[22]=N):N=e[22];let j;e[23]!==i||e[24]!==c||e[25]!==o||e[26]!==n.label||e[27]!==d||e[28]!==r?(j=i?t.jsxs("button",{type:"button",className:"flex h-9 shrink-0 items-center gap-1.5 rounded-xl bg-destructive px-3 text-destructive-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":d("mobile.sessions.confirmRemoveProjectAria",{label:n.label}),onClick:c,style:{touchAction:"manipulation"},children:[t.jsx(cs,{className:"size-4"}),t.jsx("span",{className:"typography-ui-label",children:d("mobile.sessions.confirmRemoveProject")})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:r}),t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":d("mobile.sessions.editProjectAria",{label:n.label}),onClick:o,style:{touchAction:"manipulation"},children:t.jsx(Un,{className:"size-4"})})]}),e[23]=i,e[24]=c,e[25]=o,e[26]=n.label,e[27]=d,e[28]=r,e[29]=j):j=e[29];const _=i?"text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:ring-primary":"text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:ring-destructive";let F;e[30]!==_?(F=Z("flex size-9 shrink-0 items-center justify-center rounded-xl transition-colors focus-visible:outline-none focus-visible:ring-2",_),e[30]=_,e[31]=F):F=e[31];let B;e[32]!==i||e[33]!==n.label||e[34]!==d?(B=i?d("mobile.sessions.cancelRemoveProjectAria",{label:n.label}):d("mobile.sessions.removeProjectAria",{label:n.label}),e[32]=i,e[33]=n.label,e[34]=d,e[35]=B):B=e[35];let M;e[36]===Symbol.for("react.memo_cache_sentinel")?(M={touchAction:"manipulation"},e[36]=M):M=e[36];let Y;e[37]!==i?(Y=i?t.jsx(Et,{className:"size-4"}):t.jsx(cs,{className:"size-4"}),e[37]=i,e[38]=Y):Y=e[38];let I;e[39]!==a||e[40]!==F||e[41]!==B||e[42]!==Y?(I=t.jsx("button",{type:"button",className:F,"aria-label":B,onClick:a,style:M,children:Y}),e[39]=a,e[40]=F,e[41]=B,e[42]=Y,e[43]=I):I=e[43];let U;return e[44]!==p||e[45]!==A||e[46]!==E||e[47]!==x||e[48]!==N||e[49]!==j||e[50]!==I||e[51]!==w?(U=t.jsxs("div",{ref:p,style:A,className:w,children:[E,x,N,j,I]}),e[44]=p,e[45]=A,e[46]=E,e[47]=x,e[48]=N,e[49]=j,e[50]=I,e[51]=w,e[52]=U):U=e[52],U},un=({open:s,onOpenChange:e,variant:n="sheet"})=>{const{t:r}=de(),{git:i}=Kt(),o=Jn(),a=Ht(h=>h.activeSessions),c=ys(l.useCallback(h=>s||n==="sidebar"?h.ids:ta,[s,n])),d=vs(l.useCallback(h=>s||n==="sidebar"?h.rankById:ao,[s,n])),u=Ae(h=>h.projects),f=Ae(h=>h.activeProjectId),m=it(h=>h.currentDirectory),p=be(h=>h.currentSessionId),g=be(h=>h.setCurrentSession),v=be(h=>h.archiveSession),S=be(h=>h.openNewSessionDraft),y=Ae(h=>h.setActiveProject),C=Ae(h=>h.setActiveProjectIdOnly),P=Ae(h=>h.reorderProjects),A=Ae(h=>h.removeProject),T=_t(h=>h.projectExpanded),D=_t(h=>h.worktreeExpanded),w=_t(h=>h.setProjectExpanded),k=_t(h=>h.setWorktreeExpanded),R=rr(h=>h.orderByProject),E=nn(h=>h.expandedParents),x=nn(h=>h.toggleParent),[N,j]=l.useState(""),[_,F]=l.useState(null),[B,M]=l.useState(null),[Y,I]=l.useState(0),[U,G]=l.useState(!1),[J,q]=l.useState(!1),[z,V]=l.useState(null),[ee,X]=l.useState(new Map),[b,K]=l.useState(new Set),[te,ne]=l.useState(!1),[ue,le]=l.useState(null),[Te,Ee]=l.useState(new Map);l.useEffect(()=>{if(!s){j(""),ne(!1),le(null),Ee(new Map),F(null),M(null);return}lo(o)},[s]),l.useEffect(()=>{te||le(null)},[te]),l.useEffect(()=>{if(!s||u.length===0)return;let h=!1;return(async()=>{const H=await Promise.all(u.map(async ae=>{const ve=Ie(ae.path);if(!ve)return null;const he=await i.checkIsGitRepository(ve).catch(()=>!1),Pe=he?await er({id:ae.id,path:ve}).catch(()=>[]):[];return[ve,Pe,he]}));if(h)return;const Q=new Map,pe=new Set;for(const ae of H)ae&&(Q.set(ae[0],ae[1]),ae[2]&&pe.add(ae[0]));X(Q),K(pe)})(),()=>{h=!0}},[i,s,u,Y]);const ie=l.useMemo(()=>u.map(h=>({id:h.id,label:h.label?.trim()||ns(h.path),path:Ie(h.path),icon:h.icon,color:h.color,iconImage:h.iconImage,iconBackground:h.iconBackground,isGitRepo:b.has(Ie(h.path)),worktrees:Gi(R[h.id],ee.get(Ie(h.path))??[])})),[b,u,R,ee]),xe=l.useMemo(()=>{const h=new Map(o.map(Q=>[Q.id,Q])),W=a.map(Q=>{const pe=h.get(Q.id);return pe?co(pe,Q):Q}),H=new Set(W.map(Q=>Q.id));for(const Q of o)H.has(Q.id)||W.push(Q);return W},[a,o]),fe=N.trim().toLowerCase(),ye=l.useMemo(()=>{const h=ie.map(H=>({project:H,buckets:[],totalSessions:0,isActive:H.id===f})),W=(H,Q,pe)=>{const ae=Ie(Q)||H.project.path,ve=ae||"__root__";let he=H.buckets.find(Pe=>Pe.key===ve);return he||(he={key:ve,label:pe?.branch||ns(ae),path:ae,worktree:pe,sessions:[]},H.buckets.push(he)),he};for(const H of h){W(H,H.project.path,null);for(const Q of H.project.worktrees)W(H,Q.path,Q)}for(const H of xe){const Q=nt(H);if(!Q)continue;const pe=Ie(Q),ae=h.find(Pe=>us(Pe.project,pe));if(!ae)continue;const ve=ds(ae.project,pe);(ve?W(ae,ve.path,ve):W(ae,ae.project.path,null)).sessions.push(H)}for(const H of h)for(const Q of H.buckets){Q.sessions=Ks(Q.sessions,c,d);for(const pe of Q.sessions)Lt(pe)||(H.totalSessions+=1)}return h},[f,c,ie,d,xe]),Se=Ie(m),mt=h=>h.isActive?Se===h.project.path?h.project.path:h.project.worktrees.find(H=>aa(Se,H.path))?.path??h.project.path:null,Be=h=>T[h.project.id]??!0,ht=(h,W)=>D[`${h.project.id}::${W.key}`]??!1,Fe=h=>{Ee(W=>{if(!W.has(h))return W;const H=new Map(W);return H.delete(h),H})},L=h=>{Ee(W=>{let H=!1;const Q=new Map(W),pe=`${h}::`;for(const ae of Q.keys())ae.startsWith(pe)&&(Q.delete(ae),H=!0);return H?Q:W})},O=(h,W)=>{Ee(H=>{const Q=new Map(H);return Q.set(h,W+ss),Q})},se=(h,W,H)=>{const Q=`${h.project.id}::${W.key}`,pe=new Set(W.sessions.map(we=>we.id)),ae=new Map;for(const we of W.sessions){const Le=Lt(we);if(Le&&pe.has(Le)){const gt=ae.get(Le)??[];gt.push(we),ae.set(Le,gt)}}const ve=W.sessions.filter(we=>{const Le=Lt(we);return!Le||!pe.has(Le)}),he=Te.get(Q)??ss,Pe=ve.slice(0,he),st=ve.length-Pe.length,Sr=ve.length>ss&&st===0,Ls=(we,Le)=>{const gt=ae.get(we.id)??[],Zt=gt.length>0,zs=!!E[we.id];return t.jsxs(l.Fragment,{children:[t.jsx(dn,{session:we,active:p===we.id,indent:Le,hasChildren:Zt,expanded:zs,onToggleChildren:Zt?()=>x(we.id):void 0,confirmingArchive:B===we.id,onSelect:()=>$e(we),onRequestArchive:()=>It(we.id),onConfirmArchive:()=>{Tt(we)}}),Zt&&zs?gt.map(Nr=>Ls(Nr,Le+ra)):null]},we.id)};return t.jsxs("div",{children:[Pe.map(we=>Ls(we,H)),st>0?t.jsx(ca,{indent:H,onClick:()=>O(Q,Pe.length)}):null,Sr?t.jsx(da,{indent:H,onClick:()=>Fe(Q)}):null]})},me=(h,W)=>{w(h,!W),L(h)},_e=(h,W,H)=>{k(`${h}::${W}`,!H),Fe(`${h}::${W}`)},$e=h=>{const W=nt(h)||null,H=rs(ie,W??"");H&&C(H.id),g(h.id,W),e(!1)},It=h=>{M(W=>W===h?null:h)},Tt=async h=>{M(null),await v(h.id)?oe.success(r("sessions.sidebar.session.archive.success")):oe.error(r("sessions.sidebar.session.archive.error"))},pt=()=>{S(),e(!1)},$=h=>{V(h),C(h),q(!0)},Ne=Tn(Ot(Dn,{activationConstraint:{distance:8}}),Ot(An,{coordinateGetter:Rn})),We=h=>{const{active:W,over:H}=h;if(le(null),!H||W.id===H.id)return;const Q=ie.findIndex(ae=>ae.id===W.id),pe=ie.findIndex(ae=>ae.id===H.id);Q<0||pe<0||P(Q,pe)},Rt=h=>{le(W=>W===h?null:h)},Xt=h=>{A(h.id),le(null),oe.success(r("mobile.sessions.toast.projectRemoved",{label:h.label}))},vr=l.useCallback(h=>{const W=nt(h),H=rs(ie,W);if(!H)return ns(W)||W;const Q=ds(H,Ie(W));return Q?.branch?`${H.label} · ${Q.branch}`:H.label},[ie]),wr=h=>{y(h.id),e(!1)},jr=l.useMemo(()=>fe?ye.filter(h=>`${h.project.label} ${h.project.path}`.toLowerCase().includes(fe)?!0:h.buckets.some(W=>W.sessions.some(H=>os(H,h.project.label,fe)))):ye,[fe,ye]),At=l.useMemo(()=>fe?Ks(xe.filter(h=>{const W=nt(h),H=rs(ie,W);return os(h,H?.label??"",fe)}),c,d):[],[fe,c,ie,d,xe]),Dt=l.useMemo(()=>fe?ie.filter(h=>`${h.label} ${h.path}`.toLowerCase().includes(fe)).map(h=>({...h,sessionCount:xe.filter(W=>{if(Lt(W))return!1;const H=Ie(nt(W));return us(h,H)}).length})):[],[fe,ie,xe]),kr=fe&&At.length===0&&Dt.length===0,As=!fe&&ie.length>1?t.jsx(ge,{type:"button",variant:"chip",size:"sm","aria-label":r(te?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":te,onClick:()=>ne(h=>!h),style:{touchAction:"manipulation"},children:te?t.jsx(On,{className:"size-4"}):t.jsx(Un,{className:"size-4"})}):null,Ds=!te&&ie.length>0?t.jsxs(ge,{type:"button",variant:"default",size:"sm","aria-label":r("mobile.sessions.newChat"),onClick:pt,style:{touchAction:"manipulation"},children:[t.jsx(_r,{className:"size-4"}),r("mobile.sessions.newChat")]}):null,Ms=te?null:t.jsx(ge,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.addProject"),title:r("sessions.sidebar.header.actions.addProject"),onClick:()=>G(!0),style:{touchAction:"manipulation"},children:t.jsx(Os,{className:"size-4"})}),Qt=Ds||Ms||As?t.jsxs(t.Fragment,{children:[Ds,Ms,As]}):null,_s=t.jsxs("div",{className:"flex h-full flex-col",children:[t.jsx("div",{className:Z("shrink-0 px-4 pb-2 pt-1",te&&"hidden"),children:t.jsxs("div",{className:"relative",children:[t.jsx(Pn,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ks,{value:N,onChange:h=>j(h.target.value),placeholder:r("mobile.sessions.search.placeholder"),className:Z("h-11 pl-9",N&&"pr-10")}),N?t.jsx("button",{type:"button",className:"absolute right-1.5 top-1/2 flex size-8 -translate-y-1/2 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.sessions.clearSearchAria"),onClick:()=>j(""),style:{touchAction:"manipulation"},children:t.jsx(Et,{className:"size-4"})}):null]})}),t.jsx(Qe,{className:"min-h-0 flex-1 overflow-y-auto pb-4",children:ie.length===0?t.jsx(fn,{title:r("mobile.sessions.empty.noProjectsTitle"),description:r("mobile.sessions.empty.noProjectsDescription"),action:t.jsxs("button",{type:"button",className:"flex items-center justify-center gap-2 rounded-2xl bg-primary px-5 py-3 typography-ui-label text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>G(!0),children:[t.jsx(Os,{className:"size-4"}),r("sessions.sidebar.header.actions.addProject")]})}):kr?t.jsx(fn,{title:r("mobile.sessions.empty.searchTitle"),description:r("mobile.sessions.empty.searchDescription")}):fe&&!te?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[At.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.sessions")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:At.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",children:At.map((h,W)=>t.jsx("div",{className:Z(W>0&&"border-t border-border/30"),children:t.jsx(dn,{session:h,active:p===h.id,indent:12,contextLabel:vr(h),onSelect:()=>$e(h)})},h.id))})]}):null,Dt.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.projects")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:Dt.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",children:Dt.map((h,W)=>t.jsxs("div",{className:Z("flex items-center",W>0&&"border-t border-border/30"),children:[t.jsxs("button",{type:"button",className:"flex min-h-14 min-w-0 flex-1 items-center gap-3 px-3 py-2 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>wr(h),style:{touchAction:"manipulation"},children:[t.jsx(fs,{project:h}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:h.label}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:h.sessionCount})]}),h.isGitRepo?t.jsx(cn,{className:"mr-2",onClick:()=>$(h.id)}):null]},h.id))})]}):null]}):te?t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2",children:[t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:r("mobile.sessions.editOrderHint")}),t.jsx(Mn,{sensors:Ne,collisionDetection:_n,onDragEnd:We,children:t.jsx(Ln,{items:ie.map(h=>h.id),strategy:zn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:ie.map(h=>{const W=ye.find(H=>H.project.id===h.id);return t.jsx(ua,{project:h,totalSessions:W?.totalSessions??0,confirmingDelete:ue===h.id,onEdit:()=>F(h.id),onRequestRemove:()=>Rt(h.id),onConfirmRemove:()=>Xt(h)},h.id)})})})})]}):t.jsx("div",{className:"flex flex-col",children:jr.map((h,W)=>{const H=Be(h),Q=fe?h.buckets.filter(ae=>ae.sessions.some(ve=>os(ve,h.project.label,fe))):h.buckets,pe=mt(h);return t.jsxs("section",{className:Z(W>0&&"border-t border-border/30"),children:[t.jsxs("div",{className:"flex min-h-14 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-14 min-w-0 flex-1 items-center gap-2 px-3 py-2 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>me(h.project.id,H),"aria-expanded":H,"aria-label":H?r("sessions.sidebar.group.collapseAria",{label:h.project.label}):r("sessions.sidebar.group.expandAria",{label:h.project.label}),style:{touchAction:"manipulation"},children:[t.jsx(fs,{project:h.project}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:h.project.label}),h.isActive?t.jsx(ln,{ariaLabel:r("mobile.sessions.activeProjectAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:h.totalSessions})]}),h.project.isGitRepo?t.jsx(cn,{className:"mr-2",onClick:()=>$(h.project.id)}):null]}),H?t.jsx("div",{className:"pb-2",children:(()=>{const ae=Q.find(he=>he.worktree===null),ve=Q.filter(he=>he.worktree!==null);return t.jsxs(t.Fragment,{children:[ae&&ae.sessions.length>0?se(h,ae,sa):null,ve.map(he=>{const Pe=ht(h,he),st=pe===he.path;return t.jsxs("div",{children:[t.jsxs("button",{type:"button",className:"flex min-h-11 w-full items-center gap-2 py-1.5 pl-4 pr-3 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>_e(h.project.id,he.key,Pe),"aria-expanded":Pe,"aria-label":Pe?r("sessions.sidebar.group.collapseAria",{label:he.label}):r("sessions.sidebar.group.expandAria",{label:he.label}),style:{touchAction:"manipulation"},children:[t.jsx(la,{expanded:Pe}),t.jsx(re,{name:"node-tree",className:Z("size-4 shrink-0",st?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Z("block min-w-0 flex-1 truncate typography-ui-label font-semibold",st?"text-foreground":"text-foreground/90"),children:he.label}),st?t.jsx(ln,{ariaLabel:r("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:he.sessions.length})]}),Pe?se(h,he,na):null]},he.key)})]})})()}):null]},h.project.id)})})}),t.jsx(ei,{open:U,onOpenChange:G}),t.jsx(ti,{open:J,onOpenChange:h=>{q(h),h||V(null)},onWorktreeCreated:(h,W)=>{W?.sessionId?g(W.sessionId,h):S({selectedProjectId:z,directoryOverride:h,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(ea,{open:_!==null,project:ie.find(h=>h.id===_)??null,onClose:()=>F(null),onWorktreesChanged:()=>I(h=>h+1)})]});return n==="sidebar"?s?t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center justify-between gap-2 border-b border-border/30 px-4",children:[t.jsx("h2",{className:"truncate typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Qt?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Qt}):null]}),_s]}):null:t.jsx(Ve,{open:s,onClose:()=>e(!1),ariaLabel:r("mobile.sessions.sheet.title"),title:r("mobile.sessions.sheet.title"),trailing:Qt,children:_s})},fn=s=>{const e=ce.c(10),{title:n,description:r,action:i}=s;let o;e[0]!==n?(o=t.jsx("p",{className:"typography-ui-label text-foreground",children:n}),e[0]=n,e[1]=o):o=e[1];let a;e[2]!==r?(a=r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r}):null,e[2]=r,e[3]=a):a=e[3];let c;e[4]!==i?(c=i?t.jsx("div",{className:"pt-2",children:i}):null,e[4]=i,e[5]=c):c=e[5];let d;return e[6]!==o||e[7]!==a||e[8]!==c?(d=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[o,a,c]}),e[6]=o,e[7]=a,e[8]=c,e[9]=d):d=e[9],d},Bt="openchamber.mobile.connections.v1",fa="openchamber.mobile.",mn="openchamber.mobile.deviceId",ma=()=>{try{const s=window.localStorage.getItem(mn);if(s&&s.trim())return s.trim();const e=crypto.randomUUID();return window.localStorage.setItem(mn,e),e}catch{return crypto.randomUUID()}},hn=()=>`mobile:${ma()}`,pn=()=>{try{const s=Or.getPlatform();return s==="ios"||s==="android"?s:void 0}catch{return}},or=12,ha=8e3,pa=2500,ga=3e3,Ft=2500,ft=s=>{const e=s.trim();if(!e)return"";const n=/^https?:\/\//i.test(e)?e:`http://${e}`,r=new URL(n);return r.hash="",r.search="",r.pathname=r.pathname.replace(/\/+$/,""),r.toString().replace(/\/+$/,"")},zt=s=>{try{return new URL(s).host}catch{return s}},ct=s=>{try{return ft(s)}catch{return s.trim().replace(/\/+$/g,"")}},ir=(s,e)=>ct(s)===ct(e),ar=s=>`relay:${s.serverId}@${s.relayUrl.trim()}`,ba=s=>`relay://${s.serverId}`,qt=s=>s.candidates.filter(e=>e.kind==="direct"),Ze=s=>{const e=s.candidates.find(n=>n.kind==="relay");return e&&e.kind==="relay"?e.relay:null},Ue=s=>{const e=qt(s)[0];if(e)return e.url;const n=Ze(s);return n?ba(n):""},je=s=>{const e=Ze(s);if(e)return ar(e);const n=qt(s)[0];return n?ct(n.url):""},$t=(s,e)=>{const n=s.find(o=>o.kind==="relay"),r=n&&n.kind==="relay"?n.relay.serverId:null,i=new Set(s.filter(o=>o.kind==="direct").map(o=>ct(o.url)));return e.some(o=>o.kind==="relay"?r!==null&&o.relay.serverId===r:i.has(ct(o.url)))},Ns=s=>{const e=(()=>{try{return ft(s)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},gn=s=>{if(s.candidates&&s.candidates.length>0)return s.candidates;const e=[];return typeof s.url=="string"&&s.url.trim()&&!/^relay:\/\//i.test(s.url.trim())&&e.push(...Ns(s.url)),s.relay&&e.push({kind:"relay",relay:s.relay}),e},Cs=s=>{if(!s||typeof s!="object"||Array.isArray(s))return null;const e=s;if(typeof e.relayUrl!="string"||!e.relayUrl.trim()||typeof e.serverId!="string"||!e.serverId.trim())return null;const n=e.hostEncPubJwk;if(!n||typeof n!="object"||Array.isArray(n))return null;const r=n;return r.kty!=="EC"||r.crv!=="P-256"||typeof r.x!="string"||!r.x||typeof r.y!="string"||!r.y?null:{relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:r.x,y:r.y}}},Jt=s=>{try{return JSON.stringify(s)}catch{return String(s)}},Ce=(s,e={})=>{console.info("[mobile-connect]",s,Jt(e))},dt=(s,e={})=>{console.info("[mobile-storage]",s,Jt(e))},xa=s=>{if(typeof s!="string")return s;try{return JSON.parse(s)}catch{return s}},ya=s=>{if(typeof s!="string")return s??void 0;try{return JSON.parse(s)}catch{return s}},va=async(s,e)=>{if(!ke())return null;try{const{CapacitorHttp:n}=await Oe(async()=>{const{CapacitorHttp:o}=await import("./vendor-.bun-BzW0Lgld.js").then(a=>a.cw);return{CapacitorHttp:o}},[]),r=Object.fromEntries(new Headers(e?.headers).entries()),i=await n.request({url:s,method:e?.method||"GET",headers:r,data:ya(e?.body)});return{ok:i.status>=200&&i.status<300,status:i.status,source:"native-http",json:async()=>xa(i.data)}}catch(n){return console.warn("[mobile-connect]","native-http failed",Jt({url:s,error:n instanceof Error?n.message:String(n)})),null}},wa=async(s,e)=>{const n=await fetch(s,e).catch(r=>(console.warn("[mobile-connect]","browser-fetch failed",Jt({url:s,error:r instanceof Error?r.message:String(r)})),null));return n?{ok:n.ok,status:n.status,source:"browser-fetch",json:()=>n.json()}:null},Ke=async(s,e,n)=>{let r;const i=new Promise(o=>{r=window.setTimeout(()=>{n?.(),o(null)},s)});try{return await Promise.race([e,i])}catch{return null}finally{r!==void 0&&window.clearTimeout(r)}},et=async(s,e,n)=>{const r=n?.totalTimeoutMs??ha,i=Date.now(),o=await Ke(Math.min(pa,r),va(s,e));if(o)return o;const a=new AbortController,c=Math.max(500,r-(Date.now()-i));return Ke(c,wa(s,{...e,signal:a.signal}),()=>a.abort())},Yt=async s=>{if(!s)return null;const e=await s.json().catch(()=>null);if(!e||typeof e!="object")return null;const n=e;return{authenticated:typeof n.authenticated=="boolean"?n.authenticated:void 0,disabled:typeof n.disabled=="boolean"?n.disabled:void 0,scope:typeof n.scope=="string"?n.scope:void 0}},St=15e3,ja=async(s,e,n,r=St,i)=>{const o=Wn({relayUrl:s.relayUrl,serverId:s.serverId,hostEncPubJwk:s.hostEncPubJwk}),a=c=>c==="ok"&&i?.keepTunnel?{outcome:c,tunnel:o}:(o.close(),{outcome:c});try{const c=e?{Authorization:`Bearer ${e}`}:void 0,d=await Ke(r,o.fetch("/auth/session",{headers:c}).catch(()=>null));if(Ce("relay:session",{ok:d?.ok===!0,status:d?.status??null,hasToken:!!e}),!d)return a("unreachable");if(d.status===401)return a(e?"auth-failed":"needs-login");if(!d.ok&&d.status!==404)return a("auth-failed");const u=await Yt(d);return u&&u.disabled!==!0&&u.authenticated===!1?a(e?"auth-failed":"needs-login"):a("ok")}catch(c){throw o.close(),c}},ka=(s,e,n,r,i)=>{const o=typeof window<"u"?window.location.origin:"",a={relayUrl:s.relayUrl,serverId:s.serverId,hostEncPubJwk:s.hostEncPubJwk,...n?{grant:n}:{}};i&&Fr(a,i),wt({apiBaseUrl:o,clientToken:e,runtimeKey:r??ar(s),relay:a})},Sa=s=>{if(!s||typeof s!="object")return null;const e=s;if(e.kind==="direct")return typeof e.url=="string"&&e.url.trim()?{kind:"direct",url:e.url}:null;if(e.kind==="relay"){const n=Cs(e.relay);return n?{kind:"relay",relay:n}:null}return null},Na=s=>{if(s.mode==="relay"){const e=Cs(s.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof s.url=="string"?Ns(s.url):[]},tt=()=>{if(typeof window>"u")return[];let s;try{s=JSON.parse(window.localStorage.getItem(Bt)||"[]")}catch{return[]}if(!Array.isArray(s))return[];const e=ke();return s.flatMap(n=>{if(!n||typeof n!="object")return[];const r=n;if(typeof r.id!="string")return[];const i=Array.isArray(r.candidates)?r.candidates.map(Sa).filter(d=>!!d):Na(r);if(i.length===0)return[];const o=typeof r.clientToken=="string"&&r.clientToken.trim()?r.clientToken:void 0,a=typeof r.label=="string"&&r.label.trim()?r.label:zt(Ue({candidates:i})),c={id:r.id,label:a,candidates:i,lastUsedAt:typeof r.lastUsedAt=="number"?r.lastUsedAt:0};return e?[{...c,hasToken:!!r.hasToken||!!o}]:[{...c,clientToken:o,hasToken:!!o}]}).sort((n,r)=>r.lastUsedAt-n.lastUsedAt)},ms=s=>s.kind==="relay"?{kind:"relay",relay:{relayUrl:s.relay.relayUrl,serverId:s.relay.serverId,hostEncPubJwk:s.relay.hostEncPubJwk}}:{kind:"direct",url:s.url},Es=s=>{if(typeof window>"u")return;const e=ke(),n=s.slice(0,or).map(r=>{const i={id:r.id,label:r.label,candidates:r.candidates.map(ms),lastUsedAt:r.lastUsedAt};return e?{...i,hasToken:!!(r.hasToken||r.clientToken)}:{...i,clientToken:r.clientToken}});try{window.localStorage.setItem(Bt,JSON.stringify(n))}catch(r){console.warn("[mobile-storage] failed to persist connection metadata",r)}},lr=(s,e)=>{const n=s.find(o=>e.id&&o.id===e.id||$t(o.candidates,e.candidates)),r=ke(),i={id:e.id||n?.id||crypto.randomUUID(),label:e.label,candidates:e.candidates,lastUsedAt:Date.now(),...r?{hasToken:e.hasToken??(!!e.clientToken||n?.hasToken||!1)}:{clientToken:e.clientToken??n?.clientToken,hasToken:!!(e.clientToken??n?.clientToken)}};return[i,...s.filter(o=>o.id!==i.id&&!$t(o.candidates,e.candidates))].slice(0,or)},Ps=zr,Ca=0,Is=s=>`${fa}token.${encodeURIComponent(s)}`,Ea=async(s,e)=>{let n;const r=new Promise(i=>{n=window.setTimeout(()=>i(e),ga)});try{return await Promise.race([s.catch(()=>e),r])}finally{n!==void 0&&window.clearTimeout(n)}},Ts=async(s,e,n)=>ke()?Ea(e().catch(r=>(console.warn(`[mobile-storage] ${s} failed`,r),n)),n):n,Nt=async s=>{dt("secure:read-start",{key:s});const e=await Ts("secure:read",async()=>(await Ps.internalGetItem({prefixedKey:Is(s),sync:!1})).data,null),n=typeof e=="string"&&e.trim()?e:void 0;return dt("secure:read",{key:s,hasToken:!!n}),n},Ye=async(s,e)=>{dt("secure:write-start",{key:s});const n=await Ts("secure:write",async()=>(await Ps.internalSetItem({prefixedKey:Is(s),data:e,sync:!1,access:Ca}),!0),!1);return dt("secure:write",{key:s,ok:n}),n},Pa=async s=>{await Ts("secure:delete",async()=>(await Ps.internalRemoveItem({prefixedKey:Is(s),sync:!1}),!0),!1)},Ia=async(s,e)=>{let n=0,r=0;return{records:await Promise.all(s.map(async o=>{if(!o||typeof o!="object")return o;const a=o,c=typeof a.url=="string"?a.url:null,d=typeof a.clientToken=="string"?a.clientToken.trim():"";if(!c||!d)return o;if(!await e(c,d))return r+=1,o;n+=1;const{clientToken:u,...f}=a;return{...f,hasToken:!0}})),migrated:n,failed:r}},cr=async()=>{if(typeof window>"u"||!ke())return;let s;try{s=JSON.parse(window.localStorage.getItem(Bt)||"[]")}catch{return}if(!Array.isArray(s))return;const e=s.filter(r=>!!r&&typeof r=="object"&&typeof r.url=="string"&&typeof r.clientToken=="string"&&!!r.clientToken.trim());if(e.length===0)return;dt("secure:migrate-start",{count:e.length});const n=await Ia(s,async(r,i)=>{const o=ct(r);return await Ye(o,i)?await Nt(o)===i:!1});if(n.migrated>0)try{window.localStorage.setItem(Bt,JSON.stringify(n.records))}catch(r){console.warn("[mobile-storage] failed to finalize secure token migration",r);return}dt("secure:migrate-done",{migrated:n.migrated,failed:n.failed})},Ta=async()=>(await cr(),tt()),Ut=async s=>{const e=lr(tt(),s);return Es(e),ke()&&s.clientToken&&await Ye(je({candidates:s.candidates}),s.clientToken),e},Ra=async s=>{const e=tt(),n=e.find(i=>i.id===s)??null,r=e.filter(i=>i.id!==s);return Es(r),n&&ke()&&await Pa(je(n)),r},Aa=1500,Wt=async(s,e,n)=>{const r=n?.fast?{totalTimeoutMs:Ft}:void 0,i=Ze({candidates:s})?.serverId??null,o=s.find(u=>u.kind==="relay")??null,a=s.filter(u=>u.kind==="direct"),c=async()=>{for(const u of a){const f=ft(u.url)||u.url,m=e?{Authorization:`Bearer ${e}`}:void 0,p=await et(`${f}/health`,{method:"GET"},r);if(!p?.ok)continue;if(i){const y=await p.json().catch(()=>null),C=y&&typeof y=="object"?y.serverId:null;if(typeof C=="string"&&C&&C!==i){Ce("probe:server-id-mismatch",{url:f});continue}}const g=await et(`${f}/auth/session`,{method:"GET",credentials:"include",headers:m},r);if(g?.status===401)return{status:"needs-login"};if(!g||!g.ok&&g.status!==404)continue;const v=await Yt(g);if(v&&v.disabled!==!0&&v.authenticated===!1)return{status:"needs-login"};const S=v?.disabled===!0;return!e&&ke()&&!S&&v?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:f}}}return{status:"unreachable"}},d=async()=>{if(!o)return{status:"unreachable"};const{outcome:u,tunnel:f}=await ja(o.relay,e,void 0,n?.fast?Ft:void 0,{keepTunnel:!0});return u==="ok"?{status:"ok",transport:{kind:"relay",relay:o.relay,tunnel:f}}:u==="needs-login"||u==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return o?a.length===0?d():new Promise(u=>{let f=!1,m=!1,p,g=null,v=null;const S=P=>{P?.status==="ok"&&P.transport.kind==="relay"&&P.transport.tunnel?.close()},y=P=>{f||(f=!0,u(P))},C=()=>{m||f||(p!==void 0&&(window.clearTimeout(p),p=void 0),d().then(P=>{if(v=P,f||m){S(P);return}if(P.status==="ok"||P.status==="needs-login"){y(P);return}g&&y(g)}))};c().then(P=>{if(g=P,!f){if(P.status==="ok"||P.status==="needs-login"){m=!0,p!==void 0&&window.clearTimeout(p),S(v),y(P);return}if(v){y(v);return}C()}}),p=window.setTimeout(C,Aa)}):c()},Xe=(s,e,n)=>{s.kind==="relay"?ka(s.relay,e,n?.grant,n?.runtimeKey,s.tunnel):wt({apiBaseUrl:s.url,clientToken:e,runtimeKey:n?.runtimeKey}),ur()},Da=()=>{const s=tt()[0];return s?.label?.trim()?s.label:null},bn=async()=>{await cr();const s=tt()[0];if(!s)return!1;let e;if(ke()){if(!s.hasToken||(e=await Nt(je(s)),!e))return!1}else if(e=s.clientToken,!e)return!1;const n=await Wt(s.candidates,e);return n.status!=="ok"?!1:(await Ut({id:s.id,label:s.label,candidates:s.candidates}),Xe(n.transport,e,{runtimeKey:je(s)}),!0)},Ma=async(s,e)=>{let n="";try{n=ft(s.url)}catch{return!1}if(!n)return!1;const r=s.clientToken?.trim()||void 0,i=r?{Authorization:`Bearer ${r}`}:void 0,o={totalTimeoutMs:Ft};if(!(await et(`${n}/health`,{method:"GET",headers:i},o))?.ok)return!1;const c=await et(`${n}/auth/session`,{method:"GET",credentials:"include",headers:i},o);if(!c||!c.ok&&c.status!==404)return!1;const d=await Yt(c);return!(d&&d.disabled!==!0&&d.authenticated===!1)},_a=s=>[...s].sort((e,n)=>{const r=(e.priority??100)-(n.priority??100);if(r!==0)return r;const i=o=>o.type==="relay"?2:o.url.startsWith("https://")?0:1;return i(e)-i(n)}).flatMap(e=>{if(e.type==="relay"){const n=Cs({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return n?[{kind:"relay",relay:n}]:[]}return Ns(e.url)}),xn=async s=>{const e=Ze({candidates:s})?.serverId??null;for(const n of s){if(n.kind==="relay"){const o=Wn(n.relay),a=await Ke(St,o.fetch("/health").catch(()=>null));if(Ce("establish:relay:health",{ok:a?.ok===!0,status:a?.status??null}),a?.ok)return{kind:"relay",relay:n.relay,tunnel:o};o.close();continue}const r=ft(n.url)||n.url,i=await et(`${r}/health`,{method:"GET"});if(Ce("establish:direct:health",{ok:i?.ok===!0,status:i?.status??null}),!!i?.ok){if(e){const o=await i.json().catch(()=>null),a=o&&typeof o=="object"?o.serverId:null;if(typeof a=="string"&&a&&a!==e){Ce("establish:server-id-mismatch",{url:r});continue}}return{kind:"direct",url:r}}}return null},La=async(s,e)=>{if(!kt())return Ma(s);const n=await Ke(Ft,Gt("/auth/session").then(i=>i).catch(()=>null));if(!n)return!0;if(n.status===401)return!1;if(!n.ok&&n.status!==404)return!0;const r=await Yt(n);return!(r&&r.disabled!==!0&&r.authenticated===!1)},za=s=>s.kind==="relay"?kt():!kt()&&ir(s.url,Je()),dr=()=>{const s=Vt();return s?tt().find(e=>je(e)===s)??null:null},yn=s=>{const e=Vt();return!!e&&je(s)===e},hs=async()=>{const s=dr();if(!s)return"no-connection";let e;if(ke()?e=s.hasToken?await Nt(je(s)):void 0:e=s.clientToken,!e)return"unreachable";const n=s.candidates.findIndex(c=>za(c.kind==="relay"?{kind:"relay",relay:c.relay}:{kind:"direct",url:c.url})),r=n>=0?s.candidates.slice(0,n):s.candidates,i=await Wt(r,e,{fast:!0});if(i.status==="ok")return await Ut({id:s.id,label:s.label,candidates:s.candidates}),Xe(i.transport,e,{runtimeKey:je(s)}),"switched";if(i.status==="needs-login")return"unreachable";if(n>=0&&await La({url:Je(),clientToken:e}))return ur(),"unchanged";const o=n>=0?s.candidates.slice(n+1):[],a=await Wt(o,e,{fast:!0});return a.status==="ok"?(await Ut({id:s.id,label:s.label,candidates:s.candidates}),Xe(a.transport,e,{runtimeKey:je(s)}),"switched"):"unreachable"},Oa=5e3;let is=!1;const Ba=async()=>{if(is)return"skipped";const s=dr();if(!s)return Ce("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=Ze(s);if(!e)return Ce("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";is=!0;try{const n=await Ke(St,Gt("/api/client-auth/connection/candidates").then(u=>u).catch(()=>null));if(!n?.ok)return Ce("candidates:refresh-skip",{reason:"fetch-failed",status:n?.status??null}),"skipped";const r=await n.json().catch(()=>null);if(!r||r.serverId!==e.serverId)return Ce("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const i=Array.isArray(r.candidates)?r.candidates:[],o=[];for(const u of i){if(!u||typeof u!="object")continue;const f=u;if(!(f.type!=="lan"||typeof f.url!="string"))try{const m=ft(f.url);m&&!o.includes(m)&&o.push(m)}catch{}}if(o.length===0)return Ce("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const a=qt(s).filter(u=>u.url.startsWith("https://")),c=[...o.map(u=>({kind:"direct",url:u})),...a,{kind:"relay",relay:e}];return JSON.stringify(s.candidates.map(ms))===JSON.stringify(c.map(ms))?"unchanged":(Ce("candidates:refreshed",{lanCount:o.length}),await Ut({id:s.id,label:s.label,candidates:c}),"updated")}finally{is=!1}},ur=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const s=await Ba().catch(()=>"skipped");Ce("candidates:refresh-result",{result:s}),s==="updated"&&kt()&&await hs().catch(()=>null)})()},Oa)},fr=s=>{const{t:e}=de(),[n,r]=l.useState(()=>tt()),[i,o]=l.useState(null),[a,c]=l.useState(null),[d,u]=l.useState(null),f=l.useRef(n),m=l.useRef(null),p=l.useCallback(w=>{f.current=w,r(w)},[]),g=l.useCallback(w=>{m.current=w,o(w)},[]),v=l.useCallback(w=>{m.current===w&&(m.current=null,o(null))},[]);l.useEffect(()=>{let w=!1;return Ta().then(k=>{w||p(k)}),()=>{w=!0}},[p]);const S=l.useCallback(w=>{const k=lr(f.current,w);return p(k),Es(k),k},[p]),y=l.useCallback(async w=>{c(null),g("connect");try{const k=gn(w);if(k.length===0){c(e("mobile.connect.error.urlRequired"));return}const R=w.id?f.current.find(F=>F.id===w.id):f.current.find(F=>$t(F.candidates,k)),E=w.label?.trim()||R?.label||zt(Ue({candidates:k})),x=w.relayGrant;let N=w.clientToken?.trim()||void 0;const j=!!N;N||(ke()?R?.hasToken&&(N=await Nt(je({candidates:k}))):N=R?.clientToken),Ce("connect:start",{candidates:k.map(F=>F.kind),hasToken:!!N});const _=await Wt(k,N);if(Ce("connect:probe",{status:_.status}),_.status==="unreachable"){c(e("mobile.connect.error.unreachable"));return}if(_.status==="needs-login"){S({id:R?.id,label:E,candidates:k}),u({id:R?.id??crypto.randomUUID(),label:E,candidates:k,relay:Ze({candidates:k})??void 0,relayGrant:x});return}N&&j&&ke()&&await Ye(je({candidates:k}),N),S({id:R?.id,label:E,candidates:k,clientToken:N}),Xe(_.transport,N??null,{runtimeKey:je({candidates:k}),grant:x}),s()}catch(k){console.warn("[mobile-connect] connect threw",k),c(e("mobile.connect.error.invalidUrl"))}finally{v("connect")}},[g,v,s,S,e]),C=l.useCallback(async w=>{if(m.current==="pairing")return;c(null),g("pairing");const k=_a(w.candidates);let R=null,E=!1;try{if(R=await xn(k),!R){c(e("mobile.connect.error.unreachable"));return}const x=JSON.stringify({pairingId:w.pairingId,secret:w.secret,clientLabel:"OpenChamber Mobile",clientKind:"mobile",deviceName:"OpenChamber Mobile",devicePlatform:pn(),dedupeKey:hn()}),N={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:x},j=R.kind==="relay"?await Ke(St,R.tunnel.fetch("/api/client-auth/pairing/redeem",N).catch(()=>null)):await et(`${R.url}/api/client-auth/pairing/redeem`,N);if(!j?.ok){c(e("mobile.connect.error.authRequired"));return}const _=await j.json().catch(()=>null),F=typeof _?.clientToken=="string"?_.clientToken.trim():"";if(!F){c(e("mobile.connect.error.authRequired"));return}const B=typeof _?.server?.label=="string"?_.server.label:"",M=w.label||B||zt(Ue({candidates:k}));if(ke()&&!await Ye(je({candidates:k}),F)){c(e("mobile.connect.error.authRequired"));return}S({label:M,candidates:k,clientToken:F}),Xe(R.kind==="relay"?{kind:"relay",relay:R.relay,tunnel:R.tunnel}:{kind:"direct",url:R.url},F,{runtimeKey:je({candidates:k})}),E=R.kind==="relay",s()}catch(x){console.warn("[mobile-connect] pairing threw",x),c(e("mobile.connect.error.authRequired"))}finally{!E&&R?.kind==="relay"&&R.tunnel.close(),v("pairing")}},[g,v,s,S,e]),P=l.useCallback(async w=>{if(!d||!w.trim()||m.current==="password")return;c(null),g("password");const{id:k,label:R,candidates:E}=d;let x=null,N=!1;try{if(x=await xn(E),!x){c(e("mobile.connect.error.unreachable"));return}const j={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:w,trustDevice:!0,issueClientToken:!0,clientLabel:"OpenChamber Mobile",clientKind:"mobile",devicePlatform:pn(),dedupeKey:hn()})};Ce("password:start",{transport:x.kind});const _=x.kind==="relay"?await Ke(St,x.tunnel.fetch("/auth/session",j).catch(()=>null)):await et(`${x.url}/auth/session`,j);if(Ce("password:done",{ok:_?.ok===!0,status:_?.status??null}),!_?.ok){c(e("mobile.connect.error.passwordFailed"));return}const F=await _.json().catch(()=>null),B=typeof F?.clientToken=="string"?F.clientToken.trim():"";if(Ce("password:token",{issued:!!B}),!B){if(x.kind==="direct"&&!ke()){S({id:k,label:R,candidates:E}),u(null),Xe({kind:"direct",url:x.url},null,{runtimeKey:je({candidates:E})}),s();return}c(e("mobile.connect.error.authRequired"));return}ke()&&await Ye(je({candidates:E}),B),S({id:k,label:R,candidates:E,clientToken:B}),u(null),Xe(x.kind==="relay"?{kind:"relay",relay:x.relay,tunnel:x.tunnel}:{kind:"direct",url:x.url},B,{runtimeKey:je({candidates:E})}),N=x.kind==="relay",s()}catch(j){console.warn("[mobile-connect] password threw",j),c(e("mobile.connect.error.passwordFailed"))}finally{!N&&x?.kind==="relay"&&x.tunnel.close(),v("password")}},[g,v,s,d,S,e]),A=l.useCallback(()=>{u(null),c(null)},[]),T=l.useCallback(async w=>{c(null);let k=gn(w);const R=w.id?f.current.find(j=>j.id===w.id)??null:null;if(R){const j=k.filter(B=>B.kind==="direct"),_=qt(R).filter(B=>B.url.startsWith("https://")&&!j.some(M=>ir(M.url,B.url))),F=Ze(R);k=[...j,..._,...F?[{kind:"relay",relay:F}]:[]]}if(k.length===0)return c(e("mobile.connect.error.urlRequired")),null;const E=w.clientToken?.trim()||void 0,x=w.label?.trim()||zt(Ue({candidates:k}));if(ke()){const j=je({candidates:k});if(E)await Ye(j,E);else if(R?.hasToken){const _=je(R);if(_&&j&&_!==j){const F=await Nt(_);F&&await Ye(j,F)}}}return S({id:w.id,label:x,candidates:k,clientToken:E}).find(j=>$t(j.candidates,k))??null},[S,e]),D=l.useCallback(async w=>{const k=f.current.find(E=>E.id===w)??null,R=await Ra(w);return p(R),k},[p]);return{connections:n,isBusy:i!==null,isPasswordBusy:i==="password",error:a,pendingConnection:d,connect:y,redeemPairingConnection:C,submitPassword:P,cancelPassword:A,saveConnection:T,removeConnection:D,setError:c}},Fa=4,$a=3,Ua=5,Wa=9e4,Va=async s=>{window.Capacitor?.getPlatform?.()!=="android"||!s.isGoogleBarcodeScannerModuleAvailable||!s.installGoogleBarcodeScannerModule||(await s.isGoogleBarcodeScannerModuleAvailable().catch(()=>{}))?.available||await new Promise((r,i)=>{let o;const a=d=>{window.clearTimeout(c),o?.remove(),d()},c=window.setTimeout(()=>a(()=>i(new Error("module install timed out"))),Wa);Promise.resolve(s.addListener?.("googleBarcodeScannerModuleInstallProgress",d=>{d?.state===Fa?a(r):(d?.state===$a||d?.state===Ua)&&a(()=>i(new Error("module install failed")))})).then(d=>{o=d}).catch(()=>{}),Promise.resolve(s.installGoogleBarcodeScannerModule?.()).catch(d=>a(()=>i(d instanceof Error?d:new Error("module install failed"))))})},mr=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&typeof e.scan=="function"?e:null},hr=s=>{const e=s.trim();if(!e)return null;if(/^openchamber:\/\//i.test(e)){const n=$r(e);return n?{pairing:n}:null}return/^https?:\/\//i.test(e)?{url:e}:null},Ga=s=>{const e=typeof s=="object"&&s&&"message"in s?String(s.message??""):String(s??"");return/module/i.test(e)&&/not\s*available|unavailable/i.test(e)},ps=()=>mr()!==null,pr=async()=>{const s=mr();if(!s?.scan)return{status:"unsupported"};try{if(s.requestPermissions){const n=(await s.requestPermissions())?.camera;if(n&&n!=="granted"&&n!=="limited")return{status:"permission-denied"}}for(let e=0;e<3;e++)try{await Va(s);const r=(await s.scan({formats:["QR_CODE"]}))?.barcodes?.[0],i=(r?.rawValue??r?.displayValue??"").trim();if(!i)return{status:"cancelled"};const o=hr(i);return o?"pairing"in o?{status:"pairing",...o}:{status:"ok",...o}:{status:"invalid"}}catch(n){if(!Ga(n)||e===2)return{status:"failed"};await new Promise(r=>window.setTimeout(r,600))}return{status:"failed"}}catch{return{status:"failed"}}};function Ha(s){const e=ce.c(4),n=2500,{uiFont:r}=uo(),[i,o]=l.useState(!1);let a,c;return e[0]!==n||e[1]!==r?(a=()=>{let d=!1;const u=()=>{d||o(!0)},f=()=>{requestAnimationFrame(()=>requestAnimationFrame(u))},m=Promise.all([fo(r).catch(Xa),document.fonts?.ready?.then(Ya).catch(Ja)??Promise.resolve(),yi.catch(qa)]).then(Ka),p=new Promise(g=>{window.setTimeout(g,n)});return Promise.race([m,p]).then(f),()=>{d=!0}},c=[r,n],e[0]=n,e[1]=r,e[2]=a,e[3]=c):(a=e[2],c=e[3]),l.useEffect(a,c),i}function Ka(){}function qa(){}function Ja(){}function Ya(){}function Xa(){}const Qa="openchamber",Za=s=>s.replace(/^\/+|\/+$/g,""),el=s=>{const e=Za(s.pathname).split("/").filter(Boolean);return s.host?[s.host,...e]:e};function tl(s){if(typeof s!="string"||s.length===0)return null;let e;try{e=new URL(s)}catch{return null}if(e.protocol!==`${Qa}:`)return null;const n=el(e),r=(n[0]??"").toLowerCase(),i=n.slice(1),o=e.searchParams;switch(r){case"session":{const a=i[0]||o.get("id")||"";return a?{type:"session",sessionId:a,directory:o.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:o.get("dir")??void 0,projectId:o.get("project")??void 0,agent:o.get("agent")??void 0,model:o.get("model")??void 0};case"sessions":{const a=o.get("filter");return{type:"sessions",filter:a==="attention"||a==="recent"||a==="all"?a:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:i[0]||o.get("section")||void 0};case"changes":return{type:"changes",path:i.join("/")||o.get("path")||void 0,staged:o.get("staged")==="true"};case"view":{const a=(i[0]||"").toLowerCase();return a==="changes"?{type:"changes"}:a==="files"||a==="mcp"||a==="instances"||a==="update"?{type:"view",target:a}:null}default:return null}}let Me={},gr=!1,vt=null;const sl=s=>{switch(s.type){case"session":return be.getState().setCurrentSession(s.sessionId,s.directory??null),!0;case"new-session":{const e=be.getState();return e.openNewSessionDraft(),(s.directory||s.projectId)&&e.setNewSessionDraftTarget({directoryOverride:s.directory??null,projectId:s.projectId??null,selectedProjectId:s.projectId??null}),!0}case"sessions":return Me.openSessions?(Me.openSessions(s.filter),!0):!1;case"status":return ut.getState().setMobileSessionPanelOpen(!0),!0;case"view":return Me.openView?(Me.openView(s.target),!0):!1;case"changes":return Me.openChanges?(Me.openChanges({path:s.path,staged:s.staged}),!0):!1;case"settings":return Me.openSettings?(Me.openSettings(s.section),!0):!1}},Rs=()=>{if(!gr||!vt)return;const s=vt;vt=null,sl(s)||(vt=s)},br=s=>{vt=s,Rs()},vn=s=>{const e=tl(s);e&&br(e)},nl=s=>{gr=s,Rs()},rl=s=>{const e=ce.c(3);let n,r;e[0]!==s?(n=()=>(Me=s,Rs(),()=>{Me===s&&(Me={})}),r=[s],e[0]=s,e[1]=n,e[2]=r):(n=e[1],r=e[2]),l.useEffect(n,r)},ol=s=>{const{ready:e}=s;l.useEffect(()=>{nl(e)},[e]),l.useEffect(()=>{if(!ke())return;let n=!1;const r=[];return Oe(()=>import("./vendor-.bun-BzW0Lgld.js").then(i=>i.cy),[]).then(async({App:i})=>{if(n)return;const o=await i.addListener("appUrlOpen",a=>{vn(a?.url)});if(n){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),Oe(()=>import("./vendor-.bun-BzW0Lgld.js").then(i=>i.cz),[]).then(async({PushNotifications:i})=>{if(n)return;const o=await i.addListener("pushNotificationActionPerformed",a=>{const c=a?.notification?.data,d=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(d){vn(d);return}const u=typeof c?.sessionId=="string"?c.sessionId:void 0;u&&br({type:"session",sessionId:u})});if(n){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),()=>{n=!0,r.forEach(i=>i())}},[])},wn=32,il=64,al=.7,ll=s=>s.parentID??null,cl=()=>{const s=ys.getState().ids,e=vs.getState().rankById;return Ht.getState().activeSessions.filter(n=>ll(n)===null).slice().sort((n,r)=>Gn(n,r,s,e))},dl=s=>{const e=cl();if(e.length<2)return!1;const n=be.getState().currentSessionId,r=e.findIndex(a=>a.id===n);if(r<0)return!1;const i=r+s;if(i<0||i>=e.length)return!1;const o=e[i];return be.getState().setCurrentSession(o.id,Vn(o)),!0},ul=(s,e)=>{const n=l.useRef(e?.onSwitch);n.current=e?.onSwitch,l.useEffect(()=>{const r=s.current;if(!r)return;let i=!1,o=!1,a=0,c=0;const d=f=>{if(f.touches.length!==1){i=!1;return}const m=f.touches[0],p=r.clientWidth,g=m.clientX<=wn,v=m.clientX>=p-wn;i=g||v,o=g,a=m.clientX,c=m.clientY},u=f=>{if(!i)return;i=!1;const m=f.changedTouches[0];if(!m)return;const p=m.clientX-a,g=m.clientY-c;if(Math.abs(p)<il||Math.abs(g)>Math.abs(p)*al||o&&p<=0||!o&&p>=0)return;const v=o?-1:1;dl(v)&&n.current?.(v<0?"prev":"next")};return r.addEventListener("touchstart",d,{passive:!0}),r.addEventListener("touchend",u,{passive:!0}),()=>{r.removeEventListener("touchstart",d),r.removeEventListener("touchend",u)}},[s])},fl=()=>{if(typeof window>"u")return;const s=window.__OPENCHAMBER_APNS_ENV__;if(s==="development")return"sandbox";if(s==="production")return"production"},ml=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},hl=s=>{const{enabled:e}=s,n=ut(i=>i.nativeNotificationsEnabled),r=l.useRef(null);l.useEffect(()=>{if(!e||!n||!ml())return;let i=!1;const o=[];return Oe(()=>import("./vendor-.bun-BzW0Lgld.js").then(a=>a.cz),[]).then(async({PushNotifications:a})=>{if(i)return;let c=await a.checkPermissions().catch(()=>null);if(c?.receive!=="granted"&&(c=await a.requestPermissions().catch(()=>null)),c?.receive!=="granted")return;const d=await a.addListener("registration",f=>{r.current=f.value,Us()?.push?.registerApnsToken?.({token:f.value,platform:Hn(),environment:fl()})}),u=await a.addListener("registrationError",f=>{console.warn("[Push] APNs registration error:",f)});if(await a.register().catch(()=>{}),i){d.remove(),u.remove();return}o.push(()=>{d.remove()},()=>{u.remove()})}).catch(()=>{}),()=>{i=!0,o.forEach(a=>a())}},[e,n]),l.useEffect(()=>{if(n)return;const i=r.current;if(!i)return;r.current=null,Us()?.push?.unregisterApnsToken?.({token:i})},[n])},pl=["general","appearance","chat","notifications","sessions","git","magic-prompts","behavior","mcp","providers","usage","voice","about"],gl=320,bl=380,xr=280,yr=560,jn=380;function kn(s,e,n){const r=ce.c(18),i=l.useRef(null);let o;r[0]!==n||r[1]!==e?(o=()=>{if(typeof window>"u")return n;const x=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(x)?Math.min(yr,Math.max(xr,x)):n},r[0]=n,r[1]=e,r[2]=o):o=r[2];const[a,c]=l.useState(o),[d,u]=l.useState(!1),f=l.useRef(0),m=l.useRef(a),p=l.useRef(null),g=l.useRef(null),v=xl;let S;r[3]===Symbol.for("react.memo_cache_sentinel")?(S=x=>{const N=i.current;N&&(N.style.width=`${x}px`,N.style.minWidth=`${x}px`,N.style.maxWidth=`${x}px`,N.style.setProperty("--oc-ipad-sidebar-width",`${x}px`))},r[3]=S):S=r[3];const y=S;let C;r[4]!==a?(C=x=>{try{x.currentTarget.setPointerCapture(x.pointerId)}catch{}g.current=x.pointerId,f.current=x.clientX,m.current=a,p.current=a,u(!0),x.preventDefault()},r[4]=a,r[5]=C):C=r[5];const P=C;let A;r[6]!==s?(A=x=>{if(g.current!==x.pointerId)return;const N=x.clientX-f.current,j=v(m.current+(s==="left"?N:-N));p.current!==j&&(p.current=j,y(j))},r[6]=s,r[7]=A):A=r[7];const T=A;let D;r[8]!==e?(D=x=>{if(g.current!==x.pointerId)return;try{x.currentTarget.releasePointerCapture(x.pointerId)}catch{}const N=v(p.current??m.current);g.current=null,p.current=null,u(!1),c(N);try{window.localStorage.setItem(e,String(N))}catch{}},r[8]=e,r[9]=D):D=r[9];const w=D;let k;r[10]!==P||r[11]!==w||r[12]!==T?(k={onPointerDown:P,onPointerMove:T,onPointerUp:w,onPointerCancel:w},r[10]=P,r[11]=w,r[12]=T,r[13]=k):k=r[13];const R=k;let E;return r[14]!==R||r[15]!==d||r[16]!==a?(E={asideRef:i,width:a,isResizing:d,handleProps:R},r[14]=R,r[15]=d,r[16]=a,r[17]=E):E=r[17],E}function xl(s){return Math.min(yr,Math.max(xr,Math.round(s)))}const Sn=s=>{const e=ce.c(12),{side:n,isResizing:r,ariaLabel:i,handleProps:o}=s,a=n==="left"?"right-0":"left-0";let c;e[0]!==a?(c=Z("absolute inset-y-0 z-30 w-6 cursor-col-resize touch-none",a),e[0]=a,e[1]=c):c=e[1];const d=n==="left"?"right-0":"left-0",u=r&&"bg-[var(--interactive-border)]";let f;e[2]!==d||e[3]!==u?(f=Z("absolute inset-y-0 w-[3px] transition-colors",d,u),e[2]=d,e[3]=u,e[4]=f):f=e[4];let m;e[5]!==f?(m=t.jsx("div",{className:f}),e[5]=f,e[6]=m):m=e[6];let p;return e[7]!==i||e[8]!==o||e[9]!==c||e[10]!==m?(p=t.jsx("div",{className:c,role:"separator","aria-orientation":"vertical","aria-label":i,...o,children:m}),e[7]=i,e[8]=o,e[9]=c,e[10]=m,e[11]=p):p=e[11],p},Pt=()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0?!0:window.location.protocol==="capacitor:",yl=()=>{l.useEffect(()=>{if(!Pt())return;let s=!1;const e=[],n=document.documentElement;n.classList.add("oc-capacitor-app"),window.Capacitor?.getPlatform?.()==="android"&&n.classList.add("oc-platform-android");const i=o=>{n.style.setProperty("--oc-keyboard-inset",`${Math.max(0,Math.round(o))}px`)};return Oe(()=>import("./vendor-.bun-BzW0Lgld.js").then(o=>o.cA),[]).then(async({StatusBar:o,Style:a})=>{if(s)return;const c=window.Capacitor?.getPlatform?.(),d=async()=>{if(c==="android"){const p=document.documentElement.classList.contains("dark"),g=(p?localStorage.getItem("splashBgDark"):localStorage.getItem("splashBgLight"))||(p?"#171515":"#fffdf4");await o.setOverlaysWebView({overlay:!1}).catch(()=>{}),await o.setBackgroundColor({color:g}).catch(()=>{}),await o.setStyle({style:p?a.Dark:a.Light}).catch(()=>{}),await o.show().catch(()=>{});return}await o.setStyle({style:a.Default}).catch(()=>{}),await o.setOverlaysWebView({overlay:!0}).catch(()=>{}),await o.show().catch(()=>{})};await d();const u=window.setTimeout(()=>{d()},400);e.push(()=>window.clearTimeout(u));const{App:f}=await Oe(async()=>{const{App:p}=await import("./vendor-.bun-BzW0Lgld.js").then(g=>g.cy);return{App:p}},[]),m=await f.addListener("appStateChange",({isActive:p})=>{p&&d()});if(s){m.remove();return}e.push(()=>{m.remove()})}).catch(()=>{}),Oe(()=>import("./vendor-.bun-BzW0Lgld.js").then(o=>o.cx),[]).then(async({Keyboard:o})=>{if(s)return;if(window.Capacitor?.getPlatform?.()==="android"){const x=await o.addListener("keyboardWillShow",()=>{n.classList.add("oc-keyboard-open"),window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),N=await o.addListener("keyboardDidShow",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),j=await o.addListener("keyboardWillHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-intent",{detail:{open:!1}})),n.classList.remove("oc-keyboard-open")}),_=await o.addListener("keyboardDidHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!1}}))}),F=()=>{x.remove(),N.remove(),j.remove(),_.remove()};if(s){F();return}e.push(F);return}await o.setAccessoryBarVisible({isVisible:!1}).catch(()=>{});const c=250,d=200,u="cubic-bezier(0.38, 0.7, 0.125, 1)";let f=null,m=null,p=0,g=!1,v=0,S=!1;const y=(x,N)=>{n.style.setProperty(x,`${Math.max(0,Math.round(N))}px`)},C=()=>{f!==null&&(window.clearTimeout(f),f=null)},P=(x,N)=>{window.dispatchEvent(new CustomEvent(x,{detail:N}))},A=()=>{const x=[],N=document.querySelector(".oc-mobile-composer");N&&x.push({el:N,factor:1});const j=document.querySelector(".oc-draft-center");return j&&x.push({el:j,factor:.5}),x},T=()=>{for(const{el:x}of A())x.style.transition="",x.style.transform=""},D=await o.addListener("keyboardWillShow",x=>{if(C(),S=!0,p=x.keyboardHeight,!g){const j=document.querySelector(".oc-mobile-app-shell");v=j&&parseFloat(getComputedStyle(j).paddingBottom)||0}const N=Math.max(0,p-v);n.classList.remove("oc-kb-hide"),m!==null&&(window.clearTimeout(m),m=null),n.classList.add("oc-keyboard-open","oc-kb-animating","oc-kb-caret-hold"),i(p);for(const{el:j,factor:_}of A())j.style.transition=`transform ${c}ms ${u}`,j.style.transform=`translateY(${-N*_}px)`;y("--oc-kb-scroll-inset",N),P("oc:keyboard-settled",{open:!0}),P("oc:keyboard-anim",{phase:"show",slide:N,durationMs:c,easing:u}),f=window.setTimeout(()=>{f=null,n.classList.remove("oc-kb-animating"),y("--oc-kb-layout",p),g=!0,T(),P("oc:keyboard-settled",{open:!0}),m=window.setTimeout(()=>{m=null,n.classList.remove("oc-kb-caret-hold")},250)},c+20)}),w=()=>{if(!S)return;S=!1,C(),P("oc:keyboard-intent",{open:!1}),m!==null&&(window.clearTimeout(m),m=null),n.classList.remove("oc-kb-caret-hold");const x=Math.max(0,p-v);if(n.classList.remove("oc-keyboard-open"),i(0),y("--oc-kb-scroll-inset",0),g){n.classList.remove("oc-kb-animating"),y("--oc-kb-layout",0),g=!1;for(const{el:N,factor:j}of A())N.style.transition="none",N.style.transform=`translateY(${-x*j}px)`;document.querySelector(".oc-mobile-app-shell")?.offsetHeight}P("oc:keyboard-anim",{phase:"hide",slide:x,durationMs:d,easing:u}),n.classList.add("oc-kb-animating","oc-kb-hide");for(const{el:N}of A())N.style.transition=`transform ${d}ms ${u}`,N.style.transform="translateY(0px)";f=window.setTimeout(()=>{f=null,n.classList.remove("oc-kb-animating","oc-kb-hide"),T(),P("oc:keyboard-settled",{open:!1})},d+20)},k=await o.addListener("keyboardWillHide",w),R=x=>x instanceof HTMLElement&&(x.tagName==="TEXTAREA"||x.tagName==="INPUT"||x.isContentEditable),E=x=>{S&&R(x.target)&&(R(x.relatedTarget)||window.setTimeout(()=>{S&&(R(document.activeElement)||w())},0))};if(document.addEventListener("focusout",E,!0),s){C(),document.removeEventListener("focusout",E,!0),D.remove(),k.remove();return}e.push(C,()=>{m!==null&&(window.clearTimeout(m),m=null)},()=>document.removeEventListener("focusout",E,!0),()=>{D.remove()},()=>{k.remove()})}).catch(()=>{}),()=>{s=!0,e.forEach(o=>o()),n.classList.remove("oc-capacitor-app","oc-keyboard-open","oc-kb-animating","oc-kb-hide","oc-kb-caret-hold","oc-platform-android"),n.style.removeProperty("--oc-keyboard-inset"),n.style.removeProperty("--oc-kb-shift"),n.style.removeProperty("--oc-kb-layout"),n.style.removeProperty("--oc-kb-scroll-inset")}},[])},vl=s=>{const e=l.useRef(!1);l.useEffect(()=>{if(!Pt())return;let n=!1;const r=[],i=()=>{e.current&&(e.current=!1,s())},o=()=>{if(document.visibilityState==="hidden"){e.current=!0;return}i()};return document.addEventListener("visibilitychange",o),r.push(()=>document.removeEventListener("visibilitychange",o)),Oe(()=>import("./vendor-.bun-BzW0Lgld.js").then(a=>a.cy),[]).then(async({App:a})=>{if(n)return;const c=await a.addListener("appStateChange",({isActive:u})=>{if(document.documentElement.classList.toggle("oc-native-app-active",u),!u){e.current=!0;return}i()}),d=await a.addListener("resume",i);if(n){c.remove(),d.remove();return}r.push(()=>{c.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{n=!0,r.forEach(a=>a())}},[s])},wl=s=>{l.useEffect(()=>{if(!Pt())return;let e=!1,n=null;return Oe(()=>import("./vendor-.bun-BzW0Lgld.js").then(r=>r.cy),[]).then(async({App:r})=>{if(e)return;const i=await r.addListener("backButton",()=>{s()||r.minimizeApp().catch(()=>{})});if(e){i.remove();return}n=()=>{i.remove()}}).catch(()=>{}),()=>{e=!0,n?.()}},[s])},Ct=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),jl=(s,e)=>{if(!s||typeof s!="object")return;const n=s[e];return typeof n=="number"&&Number.isFinite(n)?n:void 0},bt=s=>typeof s=="number"&&Number.isFinite(s)?s:0,Nn=s=>s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:String(s),ot={autoComplete:"off",autoCorrect:"off",spellCheck:!1},kl=1e3,Cn=s=>{const e=Ct(s);if(!e)return"";const n=e.split("/").filter(Boolean);return n[n.length-1]?.replace(/[-_]/g," ")||e},Sl=(s,e)=>s?s.label?.trim()||Cn(s.path):Cn(e),Nl=({onConnected:s})=>{const{t:e}=de(),n=fr(s),{connections:r,isBusy:i,isPasswordBusy:o,error:a,pendingConnection:c}=n,[d,u]=l.useState(""),[f,m]=l.useState(""),[p,g]=l.useState(""),[v,S]=l.useState(!1),y=l.useMemo(()=>ps(),[]),[C,P]=l.useState(()=>!ps()),[A,T]=l.useState(null),[D,w]=l.useState(""),k=l.useCallback(j=>{j.preventDefault(),n.connect({url:d,clientToken:p,label:f})},[p,n,f,d]),R=l.useCallback(j=>{if(/^openchamber:\/\//i.test(j.trim())){const _=hr(j);if(_){if("pairing"in _){n.redeemPairingConnection(_.pairing);return}u(_.url),_.label&&m(_.label),_.clientToken&&g(_.clientToken);return}}u(j)},[n]),E=l.useCallback(async()=>{if(!(v||i)){n.setError(null),S(!0);try{const j=await pr();switch(j.status){case"ok":u(j.url),j.label&&m(j.label),j.clientToken&&g(j.clientToken),await n.connect({url:j.url,clientToken:j.clientToken,label:j.label});break;case"pairing":await n.redeemPairingConnection(j.pairing);break;case"permission-denied":n.setError(e("mobile.connect.scan.permissionDenied"));break;case"invalid":n.setError(e("mobile.connect.scan.invalid"));break;case"unsupported":n.setError(e("mobile.connect.scan.unsupported"));break;case"failed":n.setError(e("mobile.connect.scan.failed"));break;default:break}}finally{S(!1)}}},[n,i,v,e]),x=l.useCallback(j=>{j.preventDefault(),n.submitPassword(D)},[n,D]),N=l.useCallback(()=>{w(""),n.cancelPassword()},[n]);return t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+28px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx(xt,{width:72,height:72,className:"size-[72px]"}),t.jsx("h1",{className:"typography-h2 text-foreground",children:e("mobile.connect.welcome.title")})]}),c?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:x,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(re,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.candidates.some(j=>j.kind==="direct")?Ue(c):e("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...ot,value:D,onChange:j=>w(j.target.value),placeholder:e("mobile.connect.password.placeholder"),"aria-label":e("mobile.connect.password.label"),type:"password",autoFocus:!0,className:"h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20"}),a?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:a}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:o||!D.trim(),children:e(o?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:N,children:e("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[y?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(ge,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{E()},disabled:v||i,children:[t.jsx(re,{name:"scan-2",className:Z("size-[18px]",v&&"animate-pulse")}),e(i?"mobile.connect.connecting":"mobile.connect.scanQr")]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:e("mobile.connect.welcome.scanHint")})]}):null,a&&!C?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:a}):null,r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:e("mobile.connect.saved.title")}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(j=>{const _=A===j.id;return t.jsxs("button",{type:"button",disabled:i,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/60 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-70",onClick:()=>{T(j.id),n.connect({id:j.id,candidates:j.candidates,clientToken:j.clientToken,label:j.label}).finally(()=>T(null))},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(re,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:j.label}),t.jsx("span",{className:Z("block truncate typography-small",_?"text-foreground":"text-muted-foreground"),children:_?e("mobile.connect.connecting"):j.candidates.some(F=>F.kind==="direct")?Ue(j):e("mobile.connect.relay.badge")})]}),_?t.jsx(re,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(re,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},j.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[y?t.jsxs("button",{type:"button",onClick:()=>P(j=>!j),"aria-expanded":C,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:[t.jsx("span",{children:e("mobile.connect.manual.toggle")}),t.jsx(re,{name:"arrow-down-s",className:Z("size-4 transition-transform duration-200",C&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:C?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:k,children:[t.jsx("input",{...ot,value:d,onChange:j=>R(j.target.value),placeholder:e("mobile.connect.url.placeholder"),"aria-label":e("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:C?void 0:-1,className:"h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-center text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20"}),t.jsx("input",{value:f,onChange:j=>m(j.target.value),placeholder:e("mobile.instances.label.placeholder"),"aria-label":e("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:C?void 0:-1,className:"h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-center text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20"}),t.jsx("input",{...ot,value:p,onChange:j=>g(j.target.value),placeholder:e("mobile.connect.token.placeholder"),"aria-label":e("mobile.connect.token.label"),tabIndex:C?void 0:-1,autoCapitalize:"none",className:"h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-center text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20"}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:e("mobile.connect.token.hint")}),a?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:a}):null,t.jsx(ge,{type:"submit",variant:y?"outline":"default",size:"lg",className:"h-12 w-full",disabled:i||v||!d.trim(),children:e(i?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})},Cl=({onActiveConnectionDeleted:s,onConnect:e})=>{const{t:n}=de(),r=fr(e),{connections:i,isBusy:o,isPasswordBusy:a,error:c,pendingConnection:d,connect:u,submitPassword:f,cancelPassword:m,saveConnection:p,removeConnection:g,setError:v}=r,[S,y]=l.useState(null),C=S?i.find(b=>b.id===S)??null:null,[P,A]=l.useState(null),[T,D]=l.useState(""),[w,k]=l.useState(""),[R,E]=l.useState(""),[x,N]=l.useState(""),[j,_]=l.useState(!1),F=l.useMemo(()=>ps(),[]),[B,M]=l.useState(!1),[Y,I]=l.useState(null),U=l.useCallback(()=>{y(null),D(""),k(""),E(""),v(null),M(!1)},[v]),G=l.useCallback(b=>{b.preventDefault(),p({id:S??void 0,url:T,label:w,clientToken:R}).then(K=>{K&&U()})},[R,S,w,U,p,T]),J=l.useCallback(async()=>{if(!j){v(null),_(!0);try{const b=await pr();switch(b.status){case"ok":D(b.url),b.label&&k(b.label),b.clientToken&&E(b.clientToken),M(!0);break;case"pairing":await r.redeemPairingConnection(b.pairing);break;case"permission-denied":v(n("mobile.connect.scan.permissionDenied"));break;case"invalid":v(n("mobile.connect.scan.invalid"));break;case"unsupported":v(n("mobile.connect.scan.unsupported"));break;case"failed":v(n("mobile.connect.scan.failed"));break;default:break}}finally{_(!1)}}},[r,j,v,n]),q=l.useCallback(b=>{b.preventDefault(),f(x)},[x,f]),z=l.useCallback(()=>{N(""),m()},[m]),V=l.useCallback(b=>{A(K=>K===b?null:b)},[]),ee=l.useCallback(b=>{A(null),S===b&&U();const K=i.length===1;g(b).then(te=>{te&&(K||yn(te))&&s()})},[i.length,S,s,g,U]),X="h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20";return d?t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:q,children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(re,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:d.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:d.candidates.some(b=>b.kind==="direct")?Ue(d):n("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...ot,value:x,onChange:b=>N(b.target.value),placeholder:n("mobile.connect.password.placeholder"),"aria-label":n("mobile.connect.password.label"),type:"password",autoFocus:!0,className:X}),c?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!x.trim(),children:n(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:z,children:n("mobile.connect.cancelPassword")})]})})}):t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-6",children:[i.length>0?t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:i.map(b=>{const K=P===b.id,te=yn(b),ne=Y===b.id,ue=ne?n("mobile.connect.connecting"):te?kt()?n("mobile.instances.status.connectedRelay"):n("mobile.instances.status.connectedDirect"):b.candidates.some(le=>le.kind==="direct")?Ue(b):n("mobile.connect.relay.badge");return t.jsxs("div",{className:Z("flex items-center border-b border-border/60 transition-colors last:border-b-0",K&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-60",onClick:()=>{te||(I(b.id),u({id:b.id,candidates:b.candidates,clientToken:b.clientToken,label:b.label}).finally(()=>I(null)))},disabled:o&&!ne||K,children:[t.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[t.jsx(re,{name:"server",className:"size-[18px]"}),te?t.jsx("span",{className:"absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--status-success)]","aria-hidden":!0}):null]}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:b.label}),t.jsx("span",{className:Z("block truncate typography-small",te&&!ne?"text-[var(--status-success)]":"text-muted-foreground"),children:ue})]}),ne?t.jsx(re,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),t.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[K?t.jsxs("button",{type:"button","aria-label":n("mobile.instances.confirmDeleteAria",{label:b.label}),className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>ee(b.id),style:{touchAction:"manipulation"},children:[t.jsx(re,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:n("mobile.instances.delete")})]}):b.candidates.some(le=>le.kind==="direct")?t.jsx("button",{type:"button","aria-label":n("mobile.instances.edit"),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>{y(b.id),D(Ue(b)),k(b.label),E(b.clientToken||""),v(null)},style:{touchAction:"manipulation"},children:t.jsx(re,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":K?n("mobile.instances.cancelDeleteAria",{label:b.label}):n("mobile.instances.deleteAria",{label:b.label}),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>V(b.id),style:{touchAction:"manipulation"},children:t.jsx(re,{name:K?"close":"delete-bin",className:"size-[18px]"})})]})]},b.id)})}):t.jsx("p",{className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:n("mobile.connect.saved.empty")}),!B&&!C?t.jsxs("div",{className:"space-y-2",children:[F?t.jsxs(ge,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{J()},disabled:j,children:[t.jsx(re,{name:"scan-2",className:Z("size-[18px]",j&&"animate-pulse")}),n("mobile.connect.scanQr")]}):null,t.jsxs(ge,{type:"button",variant:F?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{v(null),M(!0)},children:[t.jsx(re,{name:"add",className:"size-[18px]"}),n("mobile.instances.addManual")]}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:G,children:[t.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:n(C?"mobile.instances.editTitle":"mobile.instances.addTitle")}),t.jsx(ge,{type:"button",variant:"ghost",size:"xs",onClick:U,children:n("mobile.instances.cancelEdit")})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:n("mobile.connect.url.label")}),t.jsx("input",{...ot,value:T,onChange:b=>D(b.target.value),placeholder:n("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:X})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:n("mobile.instances.label.label")}),t.jsx("input",{value:w,onChange:b=>k(b.target.value),placeholder:n("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:X})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:n("mobile.connect.token.label")}),t.jsx("input",{...ot,value:R,onChange:b=>E(b.target.value),placeholder:n("mobile.connect.token.placeholder"),autoCapitalize:"none",className:X}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:n("mobile.connect.token.hint")})]}),c?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:n(C?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})},El=s=>{const e=s.usedPercent;return typeof e!="number"||!Number.isFinite(e)?"text-foreground":e>=80?"text-[var(--status-error)]":e>=50?"text-[var(--status-warning)]":"text-foreground"},Pl=s=>{const e=ce.c(19),{percentage:n}=s;let r,i,o,a,c,d,u;if(e[0]!==n){o=Do(n)??0;const v=Mo(n);i=v==="critical"?"var(--status-error)":v==="warn"?"var(--status-warning)":"var(--status-success)",r=2*Math.PI*7.5,a="0 0 18 18",c="size-[18px] -rotate-90",d="progressbar",u=Math.round(o),e[0]=n,e[1]=r,e[2]=i,e[3]=o,e[4]=a,e[5]=c,e[6]=d,e[7]=u}else r=e[1],i=e[2],o=e[3],a=e[4],c=e[5],d=e[6],u=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=f):f=e[8];const m=r*(1-o/100);let p;e[9]!==r||e[10]!==i||e[11]!==m?(p=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:i,strokeWidth:3,strokeLinecap:"round",strokeDasharray:r,strokeDashoffset:m,className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=r,e[10]=i,e[11]=m,e[12]=p):p=e[12];let g;return e[13]!==a||e[14]!==c||e[15]!==d||e[16]!==u||e[17]!==p?(g=t.jsxs("svg",{viewBox:a,className:c,role:d,"aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100,children:[f,p]}),e[13]=a,e[14]=c,e[15]=d,e[16]=u,e[17]=p,e[18]=g):g=e[18],g},En=s=>{const e=ce.c(13),{icon:n,iconNode:r,label:i,children:o}=s;let a;e[0]!==n||e[1]!==r?(a=r??(n?t.jsx(re,{name:n,className:"size-[18px]"}):null),e[0]=n,e[1]=r,e[2]=a):a=e[2];let c;e[3]!==a?(c=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:a}),e[3]=a,e[4]=c):c=e[4];let d;e[5]!==i?(d=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:i}),e[5]=i,e[6]=d):d=e[6];let u;e[7]!==o?(u=t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:o}),e[7]=o,e[8]=u):u=e[8];let f;return e[9]!==c||e[10]!==d||e[11]!==u?(f=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[c,d,u]}),e[9]=c,e[10]=d,e[11]=u,e[12]=f):f=e[12],f},Il=s=>{const e=ce.c(55),{open:n,onClose:r,anchorRef:i,contextDisplay:o,branchLabel:a,usageGroups:c,usageDisplayMode:d,isUsageLoading:u,timeFormatPreference:f}=s,{t:m}=de(),p=l.useRef(null),[g,v]=l.useState(n),[S,y]=l.useState(!1);let C;e[0]===Symbol.for("react.memo_cache_sentinel")?(C=tr(),e[0]=C):C=e[0];const P=C,A=l.useRef(null),[T,D]=l.useState(null);let w,k;e[1]!==i||e[2]!==n||e[3]!==g?(w=()=>{if(!n||!P||!g)return;const ne=()=>{const Te=i.current?.getBoundingClientRect(),Ee=A.current?.getBoundingClientRect();if(!Te||!Ee){D(null);return}const ie=Te.left-Ee.left,xe=Math.min(Math.max(ie,8),Math.max(8,Ee.width-jn-8));D(xe)};ne();const ue=A.current;if(typeof ResizeObserver>"u"||!ue)return;const le=new ResizeObserver(ne);return le.observe(ue),()=>le.disconnect()},k=[i,P,n,g],e[1]=i,e[2]=n,e[3]=g,e[4]=w,e[5]=k):(w=e[4],k=e[5]),l.useLayoutEffect(w,k);const R=P&&T!==null;let E,x;e[6]!==n||e[7]!==g?(E=()=>{if(n){v(!0),y(!1);return}if(!g)return;y(!0);const ne=window.setTimeout(()=>{v(!1),y(!1)},140);return()=>window.clearTimeout(ne)},x=[n,g],e[6]=n,e[7]=g,e[8]=E,e[9]=x):(E=e[8],x=e[9]),l.useEffect(E,x);let N,j;e[10]!==r||e[11]!==n?(N=()=>{if(!n)return;const ne=ue=>{ue.key==="Escape"&&r()};return document.addEventListener("keydown",ne),()=>document.removeEventListener("keydown",ne)},j=[r,n],e[10]=r,e[11]=n,e[12]=N,e[13]=j):(N=e[12],j=e[13]),l.useEffect(N,j);let _,F;if(e[14]!==i||e[15]!==r||e[16]!==n?(_=()=>{if(!n)return;const ne=ue=>{const le=ue.target;if(!(le instanceof Node)){r();return}p.current?.contains(le)||i.current?.contains(le)||r()};return document.addEventListener("pointerdown",ne,!0),document.addEventListener("wheel",ne,!0),()=>{document.removeEventListener("pointerdown",ne,!0),document.removeEventListener("wheel",ne,!0)}},F=[i,r,n],e[14]=i,e[15]=r,e[16]=n,e[17]=_,e[18]=F):(_=e[17],F=e[18]),l.useEffect(_,F),!g)return null;let B;e[19]!==m?(B=m("mobile.header.openMetadataAria"),e[19]=m,e[20]=B):B=e[20];const M=R?"absolute origin-top-left":"mx-3 mt-2",Y=S?"pointer-events-none":"pointer-events-auto";let I;e[21]!==M||e[22]!==Y?(I=Z("overflow-y-auto overscroll-contain rounded-[20px] border border-border/40 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",M,Y),e[21]=M,e[22]=Y,e[23]=I):I=e[23];const U=`${S?"session-metadata-out":"session-metadata-in"} ${S?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let G;e[24]!==T||e[25]!==R?(G=R?{top:8,left:T??8,width:`min(${jn}px, calc(100% - 16px))`}:null,e[24]=T,e[25]=R,e[26]=G):G=e[26];let J;e[27]!==U||e[28]!==G?(J={animation:U,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...G},e[27]=U,e[28]=G,e[29]=J):J=e[29];let q;e[30]!==m?(q=m("mobile.header.metadata.branch"),e[30]=m,e[31]=q):q=e[31];let z;e[32]!==a||e[33]!==q?(z=t.jsx(En,{icon:"git-branch",label:q,children:a}),e[32]=a,e[33]=q,e[34]=z):z=e[34];let V;e[35]!==o||e[36]!==m?(V=o?t.jsx(En,{iconNode:t.jsx(Pl,{percentage:o.percentage}),label:m("mobile.header.metadata.context"),children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:Z("font-semibold",o.colorClass),children:[o.percentage.toFixed(1),"%"]}),t.jsx("span",{className:"text-muted-foreground",children:o.tokens})]})}):null,e[35]=o,e[36]=m,e[37]=V):V=e[37];let ee;e[38]!==u||e[39]!==f||e[40]!==d||e[41]!==c?(ee=t.jsx(Tl,{groups:c,displayMode:d,isLoading:u,timeFormatPreference:f}),e[38]=u,e[39]=f,e[40]=d,e[41]=c,e[42]=ee):ee=e[42];let X;e[43]!==z||e[44]!==V||e[45]!==ee?(X=t.jsxs("div",{className:"space-y-1",children:[z,V,ee]}),e[43]=z,e[44]=V,e[45]=ee,e[46]=X):X=e[46];let b;e[47]!==B||e[48]!==I||e[49]!==J||e[50]!==X?(b=t.jsx("div",{ref:p,role:"dialog","aria-label":B,className:I,style:J,children:X}),e[47]=B,e[48]=I,e[49]=J,e[50]=X,e[51]=b):b=e[51];let K;e[52]===Symbol.for("react.memo_cache_sentinel")?(K=t.jsx("style",{children:`
8
+ @keyframes session-metadata-in {
9
+ from { opacity: 0; transform: translateY(-8px) scale(0.985); }
10
+ to { opacity: 1; transform: translateY(0) scale(1); }
11
+ }
12
+ @keyframes session-metadata-out {
13
+ from { opacity: 1; transform: translateY(0) scale(1); }
14
+ to { opacity: 0; transform: translateY(-6px) scale(0.985); }
15
+ }
16
+ `}),e[52]=K):K=e[52];let te;return e[53]!==b?(te=t.jsxs("div",{ref:A,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[b,K]}),e[53]=b,e[54]=te):te=e[54],te},Tl=s=>{const e=ce.c(30),{groups:n,displayMode:r,isLoading:i,timeFormatPreference:o}=s,{t:a}=de();let c;e[0]!==r||e[1]!==a?(c=a(r==="remaining"?"header.services.remaining":"header.services.used"),e[0]=r,e[1]=a,e[2]=c):c=e[2];const d=c;if(n.length===0)return null;let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t.jsx(re,{name:"timer",className:"size-[18px]"})}),e[3]=u):u=e[3];let f;e[4]!==a?(f=a("mobile.header.metadata.usage"),e[4]=a,e[5]=f):f=e[5];let m;e[6]!==f?(m=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:f}),e[6]=f,e[7]=m):m=e[7];let p;e[8]!==i?(p=i?t.jsx(re,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[8]=i,e[9]=p):p=e[9];let g;e[10]!==d?(g=t.jsx("span",{className:"truncate",children:d}),e[10]=d,e[11]=g):g=e[11];let v;e[12]!==p||e[13]!==g?(v=t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-center justify-end gap-1.5 typography-ui-label text-muted-foreground",children:[p,g]}),e[12]=p,e[13]=g,e[14]=v):v=e[14];let S;e[15]!==m||e[16]!==v?(S=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[u,m,v]}),e[15]=m,e[16]=v,e[17]=S):S=e[17];let y;if(e[18]!==r||e[19]!==n||e[20]!==o){let A;e[22]!==r||e[23]!==o?(A=T=>t.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-2.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(_o,{providerId:T.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:T.providerName}),T.status&&T.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:T.status}):null]}),T.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:T.rows.map(D=>{const w=r==="remaining"?D.window.remainingPercent:D.window.usedPercent,k=Lo(D.window.valueLabel,w),R=zo(D.window.resetAt,D.window.resetAfterFormatted??D.window.resetAtFormatted,o);return t.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-3",children:[t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-baseline gap-1.5",children:[t.jsx("span",{className:"truncate typography-ui-label text-muted-foreground",children:D.subtitle?`${D.subtitle} · ${D.label}`:D.label}),R?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground/70",children:R}):null]}),t.jsx("span",{className:Z("shrink-0 typography-ui-label font-semibold tabular-nums",El(D.window)),children:k==="-"?"":k})]},D.key)})}):null,T.status&&T.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:T.status}):null]},T.providerId),e[22]=r,e[23]=o,e[24]=A):A=e[24],y=n.map(A),e[18]=r,e[19]=n,e[20]=o,e[21]=y}else y=e[21];let C;e[25]!==y?(C=t.jsx("div",{className:"space-y-1.5",children:y}),e[25]=y,e[26]=C):C=e[26];let P;return e[27]!==C||e[28]!==S?(P=t.jsxs("div",{className:"pt-2.5",children:[S,C]}),e[27]=C,e[28]=S,e[29]=P):P=e[29],P},Rl=s=>{const e=ce.c(26),{open:n,onClose:r,items:i,rightOffset:o}=s,a=o===void 0?0:o,{t:c}=de();let d,u;if(e[0]!==r||e[1]!==n?(d=()=>{if(!n)return;const A=T=>{T.key==="Escape"&&r()};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},u=[r,n],e[0]=r,e[1]=n,e[2]=d,e[3]=u):(d=e[2],u=e[3]),l.useEffect(d,u),!n)return null;let f;e[4]!==c?(f=c("mobile.menu.titleAria"),e[4]=c,e[5]=f):f=e[5];let m;e[6]!==c?(m=c("mobile.surface.closeAria"),e[6]=c,e[7]=m):m=e[7];let p;e[8]!==r||e[9]!==m?(p=t.jsx("button",{type:"button",className:"absolute inset-0 cursor-default","aria-label":m,onClick:r}),e[8]=r,e[9]=m,e[10]=p):p=e[10];const g=`${8+a}px`;let v;e[11]!==g?(v={right:g,animation:"mobile-menu-in 160ms cubic-bezier(0.32, 0.72, 0, 1)"},e[11]=g,e[12]=v):v=e[12];let S;if(e[13]!==i||e[14]!==r){let A;e[16]!==r?(A=(T,D)=>t.jsxs("button",{type:"button",role:"menuitem",className:Z("flex w-full items-center gap-3 px-4 py-3 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",D>0&&"border-t border-border/30"),style:{touchAction:"manipulation"},onClick:()=>{T.onSelect(),r()},children:[T.iconNode??(T.icon?t.jsx(re,{name:T.icon,className:"size-5 shrink-0 text-muted-foreground"}):null),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:T.label}),T.badge&&T.badge>0?t.jsx("span",{className:"inline-flex size-2 shrink-0 rounded-full bg-primary","aria-hidden":!0}):null]},T.key),e[16]=r,e[17]=A):A=e[17],S=i.map(A),e[13]=i,e[14]=r,e[15]=S}else S=e[15];let y;e[18]!==v||e[19]!==S?(y=t.jsx("div",{className:"absolute top-[calc(var(--oc-safe-area-top,0px)+56px+4px)] w-[min(220px,calc(100vw-1rem))] origin-top-right overflow-hidden rounded-2xl border border-border/40 bg-background shadow-[0_18px_60px_rgb(0_0_0_/_0.35)]",role:"menu",style:v,children:S}),e[18]=v,e[19]=S,e[20]=y):y=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=t.jsx("style",{children:"@keyframes mobile-menu-in { from { opacity: 0; transform: translateY(-6px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }"}),e[21]=C):C=e[21];let P;return e[22]!==y||e[23]!==f||e[24]!==p?(P=t.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":f,children:[p,y,C]}),e[22]=y,e[23]=f,e[24]=p,e[25]=P):P=e[25],P},Al=l.memo(function({open:e,onOpenChange:n,currentSessionId:r,effectiveDirectory:i,gitDirectory:o,isNewSessionDraftOpen:a,primaryLabel:c,secondaryLabel:d}){const{t:u}=de(),{git:f}=Kt(),m=l.useRef(null),p=To(r??"",i||void 0),g=Kn(o),v=js(o),S=De(b=>b.ensureStatus),y=De(b=>b.fetchStatus),C=Re(b=>b.providers),P=Re(b=>b.currentProviderId),A=Re(b=>b.currentModelId),T=Re(b=>b.getModelMetadata);Re(b=>b.modelsMetadata.size);const D=Ro(l.useCallback(b=>r?b.sessionModelSelections.get(r)??null:null,[r])),w=qe(b=>b.results),k=qe(b=>b.loadSettings),R=qe(b=>b.fetchAllQuotas),E=qe(b=>b.isLoading),x=qe(b=>b.displayMode),N=qe(b=>b.dropdownProviderIds),j=qe(b=>b.selectedModels),_=ut(b=>b.timeFormatPreference);pi(),l.useEffect(()=>{o&&S(o,f)},[S,f,o]),l.useEffect(()=>{if(o)return Ao.onGitRefreshHint(b=>{Ct(b.directory)===o&&y(o,f)})},[y,f,o]),l.useEffect(()=>{k()},[k]),l.useEffect(()=>{qs(N)},[N]),l.useEffect(()=>{!e||E||!N.some(K=>!w.some(te=>te.providerId===K))||R()},[N,R,E,e,w]);const B=l.useMemo(()=>{for(let b=p.length-1;b>=0;b-=1){const K=p[b];if(K.role!=="user")continue;const te=typeof K.model?.providerID=="string"&&K.model.providerID.trim().length>0?K.model.providerID:void 0,ne=typeof K.model?.modelID=="string"&&K.model.modelID.trim().length>0?K.model.modelID:void 0;if(te&&ne)return{providerID:te,modelID:ne}}return null},[p])??(D?{providerID:D.providerId,modelID:D.modelId}:null)??(P&&A?{providerID:P,modelID:A}:null),Y=(B?C.find(b=>b.id===B.providerID):void 0)?.models.find(b=>b.id===B?.modelID),I=B?T(B.providerID,B.modelID):void 0,U=jl(Y?.limit,"context")??I?.limit?.context??0,G=l.useMemo(()=>{for(let b=p.length-1;b>=0;b-=1){const K=p[b];if(K.role!=="assistant"||!K.tokens)continue;const te=bt(K.tokens.input)+bt(K.tokens.output)+bt(K.tokens.reasoning)+bt(K.tokens.cache?.read)+bt(K.tokens.cache?.write);if(te>0)return te}return 0},[p]),J=!a&&G>0&&U>0?Math.min(G/U*100,999):null,q=J!==null?`${Nn(G)}/${Nn(U)}`:null,z=J===null?"":J>=90?"text-[var(--status-error)]":J>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",V=J!==null&&q?{percentage:J,tokens:q,colorClass:z}:null,ee=g===!0?v?.current?.trim()||u("gitView.branch.detachedHead"):u("common.unavailable"),X=l.useMemo(()=>{const b=new Map(w.map(K=>[K.providerId,K]));return gi.filter(K=>N.includes(K.id)).filter(K=>b.get(K.id)?.configured===!0).map(K=>{const te=b.get(K.id),ne=[];for(const[ie,xe]of Object.entries(te?.usage?.windows??{}))ne.push({key:`window-${ie}`,label:Js(ie),window:xe});const ue=Object.entries(te?.usage?.models??{}),le=j[K.id]??[],Te=le.length>0?ue.filter(([ie])=>le.includes(ie)):ue;for(const[ie,xe]of Te){const fe=Object.entries(xe.windows??{});if(fe.length===0)continue;const[ye,Se]=fe[0];ne.push({key:`model-${ie}-${ye}`,label:Js(ye),subtitle:bi(ie),window:Se})}const Ee=!te.ok&&te.error?te.error:ne.length===0?u("header.services.noRateLimitsReported"):null;return{providerId:K.id,providerName:K.name,rows:ne,status:Ee}})},[N,w,j,u]);return l.useEffect(()=>{!e||X.length===0||qs(X.map(b=>b.providerId))},[e,X]),t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex min-w-0 flex-1 items-center px-2 py-1.5 text-left",children:t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col leading-tight",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:c}),d?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:d}):null]})}),t.jsx("button",{ref:m,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":u("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>n(b=>!b),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"apps-2-ai",className:"size-5"})}),t.jsx(Il,{open:e,onClose:()=>n(!1),anchorRef:m,contextDisplay:V,branchLabel:ee,usageGroups:X,usageDisplayMode:x,isUsageLoading:E,timeFormatPreference:_})]})}),Dl=({onOpenSessions:s,onOpenMenu:e,surfaceShortcuts:n})=>{const{t:r}=de(),[i,o]=l.useState(!1),a=it(w=>w.currentDirectory),c=be(w=>w.currentSessionId),u=be(l.useCallback(w=>c?w.getDirectoryForSession(c):null,[c]))||a,f=Ct(u)||null,m=Ae(w=>w.projects),p=be(w=>w.availableWorktreesByProject),g=be(l.useCallback(w=>c?w.worktreeMetadata.get(c)??null:null,[c])),v=Eo(c,u||void 0),S=be(w=>!!w.newSessionDraft?.open),y=l.useMemo(()=>{const w=Ct(u);if(!w)return r("mobile.header.noProject");const R=(g?.projectDirectory?Po(m,g.projectDirectory):null)??Io(m,p,w);return Sl(R,w)||r("mobile.header.noProject")},[p,g?.projectDirectory,u,m,r]),P=v?.title?.trim()||(c?r("mobile.sessions.untitled"):y),A=c?y:"";l.useEffect(()=>{o(!1)},[c,u]);const T=l.useCallback(()=>{o(!1),s()},[s]),D=l.useCallback(()=>{o(!1),e()},[e]);return t.jsx(t.Fragment,{children:t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 border-b border-border/30 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.sessions.openSheetAria"),onClick:T,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"folders",className:"size-5"})}),t.jsx(Al,{open:i,onOpenChange:o,currentSessionId:c,effectiveDirectory:u,gitDirectory:f,isNewSessionDraftOpen:S,primaryLabel:P,secondaryLabel:A}),n?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:Z("flex size-10 shrink-0 items-center justify-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",n.activePanel==="files"?"bg-[var(--interactive-selection)] text-[var(--interactive-selectionForeground)]":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),"aria-label":r("mobile.menu.files"),"aria-pressed":n.activePanel==="files",onClick:n.onToggleFiles,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"file-text",className:"size-5"})}),t.jsxs("button",{type:"button",className:Z("relative flex size-10 shrink-0 items-center justify-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",n.activePanel==="changes"?"bg-[var(--interactive-selection)] text-[var(--interactive-selectionForeground)]":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),"aria-label":r("mobile.menu.changes"),"aria-pressed":n.activePanel==="changes",onClick:n.onToggleChanges,style:{touchAction:"manipulation"},children:[t.jsx(re,{name:"git-branch",className:"size-5"}),n.changesDirty?t.jsx("span",{className:"absolute right-2 top-2 inline-flex size-2 rounded-full bg-primary","aria-hidden":!0}):null]})]}):null,t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.header.openMenuAria"),onClick:D,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"more-2",className:"size-5"})})]})})})},Ml=({onActiveConnectionDeleted:s})=>{const{t:e}=de(),[n,r]=l.useState(!1),[i,o]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState(!1),[f,m]=l.useState(!1),[p,g]=l.useState(!1),[v,S]=l.useState(!1),[y,C]=l.useState(!1),[P,A]=l.useState(!1),[T,D]=l.useState("nav"),[w,k]=l.useState(!1),[R,E]=l.useState(null),x=it($=>$.currentDirectory),N=ut($=>$.setSettingsPage),j=rt($=>$.available),_=rt($=>$.runtimeType),F=l.useMemo(()=>Pt(),[]),B=Mt($=>$.mcpServers),M=Mt($=>$.setMcpDraft),Y=Mt($=>$.setSelectedMcp),I=li($=>$.refresh),U=Mt($=>$.loadMcpConfigs),J=js(Ct(x)||null)?.files?.length??0,q=l.useMemo(()=>tr(),[]),V=No()==="portrait",[ee,X]=l.useState(q&&!V),[b,K]=l.useState(null),te=l.useCallback(()=>{const $=!ee;$&&V&&K(null),X($)},[ee,V]),ne=l.useCallback(()=>{if(q){E(null),K("files"),V&&X(!1);return}o(!0)},[q,V]),ue=l.useCallback(($=null)=>{if(E($),q){K("changes"),V&&X(!1);return}c(!0)},[q,V]),le=l.useCallback(()=>{K(null),E(null)},[]),Te=l.useCallback($=>{if(b===$){le();return}$==="files"?ne():ue()},[le,b,ue,ne]),Ee=l.useRef("changes");b&&(Ee.current=b);const[ie,xe]=l.useState(!1);l.useEffect(()=>{if(!q)return;if(b){xe(!0);return}const $=window.setTimeout(()=>xe(!1),240);return()=>window.clearTimeout($)},[b,q]);const fe=b??Ee.current,ye=kn("left","openchamber.ipad.leftSidebarWidth",gl),Se=kn("right","openchamber.ipad.rightSidebarWidth",bl),mt=l.useMemo(()=>({openChanges:({diffPath:$,staged:Ne}={})=>{ue($?{path:$,staged:Ne===!0}:null)},openFiles:()=>ne(),openSettings:()=>{D("nav"),C(!0)}}),[ue,ne]),Be=l.useCallback(()=>{c(!1),E(null)},[]),ht=l.useMemo(()=>({openSessions:()=>{q?X(!0):r(!0)},openView:$=>{$==="files"?ne():$==="mcp"?m(!0):$==="instances"?g(!0):$==="update"&&A(!0)},openChanges:({path:$,staged:Ne}={})=>{ue($?{path:$,staged:Ne===!0}:null)},openSettings:$=>{$&&N($),D($?"page-content":"nav"),C(!0)}}),[q,ue,ne,N]);rl(ht);const Fe=l.useRef(null),L=l.useRef(null),O=l.useRef(null),se=be($=>$.currentSessionId),me=l.useCallback($=>{O.current=$},[]);ul(Fe,{onSwitch:me}),l.useLayoutEffect(()=>{const $=O.current;if(O.current=null,!$)return;const Ne=L.current;if(!Ne||typeof Ne.animate!="function")return;Ne.getAnimations().forEach(Rt=>Rt.cancel());const We=$==="prev"?-70:70;Ne.animate([{opacity:.1,transform:`translateX(${We}px)`},{opacity:1,transform:"translateX(0)"}],{duration:300,easing:"cubic-bezier(0.22, 1, 0.36, 1)"})},[se]);const _e=l.useCallback(()=>w?(k(!1),!0):n?(r(!1),!0):i?(o(!1),!0):a?(Be(),!0):f?(m(!1),!0):p?(g(!1),!0):y?(C(!1),!0):P?(A(!1),!0):!1,[a,Be,i,p,f,w,n,y,P]);wl(_e);const $e=j&&(_==="desktop"||_==="web"),It=l.useCallback(()=>{const $="new-mcp-server";let Ne=$,We=1;for(;B.some(Xt=>Xt.name===Ne);)Ne=`${$}-${We}`,We+=1;M({name:Ne,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),Y(Ne),N("mcp"),m(!1),D("page-content"),C(!0)},[B,M,Y,N]),Tt=l.useCallback(()=>{if(v)return;S(!0);const $=x||null,Ne=new Promise(We=>window.setTimeout(We,500));Promise.all([I({directory:$,silent:!0}),U({force:!0}),Ne]).finally(()=>S(!1))},[x,v,U,I]),pt=l.useMemo(()=>{const $=[];return q||$.push({key:"files",icon:"file-text",label:e("mobile.menu.files"),onSelect:()=>ne()},{key:"changes",icon:"git-branch",label:e("mobile.menu.changes"),badge:J,onSelect:()=>ue()}),$.push({key:"terminal",icon:"terminal",label:e("mobile.menu.terminal"),onSelect:()=>u(!0)}),$.push({key:"mcp",iconNode:t.jsx(ci,{className:"size-5 shrink-0 text-muted-foreground"}),label:e("mobile.menu.mcp"),onSelect:()=>m(!0)}),F&&$.push({key:"instances",icon:"server",label:e("mobile.menu.instances"),onSelect:()=>g(!0)}),$e&&$.push({key:"update",icon:"download",label:e("mobile.menu.update"),onSelect:()=>A(!0)}),$.push({key:"settings",icon:"settings-3",label:e("mobile.menu.settings"),onSelect:()=>{D("nav"),C(!0)}}),$},[J,q,ue,ne,F,$e,e]);return t.jsx(Co,{actions:mt,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[q?t.jsxs("aside",{ref:ye.asideRef,className:Z("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/50 bg-sidebar will-change-[width] motion-reduce:transition-none",!ee&&"border-r-0"),style:{width:ee?ye.width:0,minWidth:ee?ye.width:0,maxWidth:ee?ye.width:0,"--oc-ipad-sidebar-width":`${ye.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:ye.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!ee,"data-page-scroll-lock":"true",children:[ee?t.jsx(Sn,{side:"left",isResizing:ye.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:ye.handleProps}):null,t.jsx("div",{className:Z("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",ye.isResizing&&"pointer-events-none",!ee&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(ze,{children:t.jsx(un,{open:!0,variant:"sidebar",onOpenChange:$=>{!$&&V&&X(!1)}})})})]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(Dl,{onOpenSessions:()=>q?te():r(!0),onOpenMenu:()=>k(!0),surfaceShortcuts:q?{activePanel:b,changesDirty:J>0,onToggleFiles:()=>Te("files"),onToggleChanges:()=>Te("changes")}:void 0}),t.jsx("main",{ref:Fe,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{ref:L,className:"h-full w-full",children:t.jsx(ze,{children:t.jsx(di,{})})})})]}),q?t.jsxs("aside",{ref:Se.asideRef,className:Z("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/50 bg-background will-change-[width] motion-reduce:transition-none",!b&&"border-l-0"),style:{width:b?Se.width:0,minWidth:b?Se.width:0,maxWidth:b?Se.width:0,"--oc-ipad-sidebar-width":`${Se.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:Se.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!b,"data-page-scroll-lock":"true",children:[b?t.jsx(Sn,{side:"right",isResizing:Se.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:Se.handleProps}):null,t.jsx("div",{className:Z("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",Se.isResizing&&"pointer-events-none",!b&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:ie?t.jsx(ze,{children:fe==="files"?t.jsx(sn,{onClose:le}):t.jsx(en,{onClose:le,initialDiffPath:R?.path??null,initialDiffStaged:R?.staged===!0})}):null})]}):null,t.jsx(Rl,{open:w,onClose:()=>k(!1),items:pt,rightOffset:q&&b?Se.width:0}),n?t.jsx(un,{open:n,onOpenChange:r}):null,i?t.jsx(Ve,{open:!0,onClose:()=>o(!1),ariaLabel:e("mobile.menu.files"),headerless:!0,children:t.jsx(ze,{children:t.jsx(sn,{onClose:()=>o(!1)})})}):null,a?t.jsx(Ve,{open:!0,onClose:Be,ariaLabel:e("mobile.menu.changes"),headerless:!0,children:t.jsx(ze,{children:t.jsx(en,{onClose:Be,initialDiffPath:R?.path??null,initialDiffStaged:R?.staged===!0})})}):null,d?t.jsx(Ve,{open:!0,onClose:()=>u(!1),ariaLabel:e("mobile.menu.terminal"),title:e("mobile.menu.terminal"),disableSwipeDismiss:!0,disableEscapeDismiss:!0,children:t.jsx(ze,{children:t.jsx(ui,{visible:!0})})}):null,f?t.jsx(Yn,{open:!0,onClose:()=>m(!1),title:e("mcpDropdown.title"),className:"h-[72vh]",contentMaxHeightClassName:"max-h-full",renderHeader:$=>t.jsxs("div",{className:"shrink-0",children:[t.jsx("div",{className:"flex justify-center pt-2.5 pb-1",children:t.jsx("div",{className:"h-1 w-9 rounded-full bg-[color-mix(in_srgb,var(--surface-mutedForeground)_40%,transparent)]"})}),t.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 pb-2",children:[t.jsx("h2",{className:"text-[16px] font-semibold text-[var(--surface-foreground)]",children:e("mcpDropdown.title")}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{type:"button",className:"flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]",onClick:It,"aria-label":e("settings.mcp.sidebar.actions.addServerTitle"),title:e("settings.mcp.sidebar.actions.addServerTitle"),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"add",className:"h-5 w-5"})}),t.jsx("button",{type:"button",className:"flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] disabled:opacity-60",onClick:Tt,disabled:v,"aria-label":e("mcpDropdown.actions.refreshAria"),title:e("mcpDropdown.actions.refreshAria"),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"refresh",className:Z("h-5 w-5",v&&"animate-spin")})}),$]})]})]}),children:t.jsx(ze,{children:t.jsx(fi,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})})}):null,p&&F?t.jsx(Ve,{open:!0,onClose:()=>g(!1),ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(Cl,{onConnect:()=>g(!1),onActiveConnectionDeleted:s})}):null,y?t.jsx(Ve,{open:!0,onClose:()=>C(!1),ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(ze,{children:t.jsx(mi,{forceMobile:!0,isWindowed:!0,initialMobileStage:T,visiblePageSlugs:[...pl],onClose:()=>C(!1)})})}):null,P?t.jsx(Ve,{open:!0,onClose:()=>A(!1),ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(ze,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(hi,{initialUpdateDialogOpen:!0})})})}):null]})})};function _l({apis:s}){const{t:e}=de(),n=Re(I=>I.initializeApp),r=Re(I=>I.isInitialized),i=Re(I=>I.isConnected),o=Re(I=>I.connectionPhase),a=Re(I=>I.providers.length),c=Re(I=>I.agents.length),d=Re(I=>I.loadProviders),u=Re(I=>I.loadAgents),f=it(I=>I.currentDirectory),m=be(I=>I.error),p=be(I=>I.clearError),g=ut(I=>I.setIsMobile),v=mo(I=>I.refreshStatus),S=ho(I=>I.setPlanModeEnabled),y=Ae(I=>I.projects),[C,P]=l.useState(0),[A,T]=l.useState(0),[D,w]=l.useState(!1),[k,R]=l.useState("pending"),E=l.useMemo(()=>Da(),[]),[,x]=l.useReducer(I=>I+1,0),N=l.useMemo(()=>Pt(),[]),j=l.useRef(0),_=l.useRef(0),F=l.useCallback(()=>{const I=Je(),U=_.current+1;if(_.current=U,!I){bn();return}const G=()=>{n(),v(s.github,{force:!0}),a===0&&d({source:"mobileApp:nativeResume"}),c===0&&u({source:"mobileApp:nativeResume"})},J=()=>{wt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(z=>z+1)};hs().then(z=>{if(_.current===U){if(z==="no-connection"){J();return}if(z==="unreachable"){window.setTimeout(()=>{_.current===U&&hs().then(V=>{if(_.current===U&&V!=="switched"){if(V==="unchanged"){G();return}J()}})},4e3);return}z!=="switched"&&G()}});const q=Date.now();q-j.current>=kl&&(j.current=q,window.dispatchEvent(new Event("openchamber:system-resume")))},[c,s.github,n,u,d,a,v]);yl(),vl(F),l.useEffect(()=>{if(!N)return;let I;const U=()=>{window.clearTimeout(I),I=window.setTimeout(()=>F(),1500)};return window.addEventListener("online",U),()=>{window.removeEventListener("online",U),window.clearTimeout(I)}},[N,F]),l.useEffect(()=>(Ws(s),()=>Ws(null)),[s]),l.useEffect(()=>Ur(I=>{if(!!I.runtimeKey&&I.runtimeKey===I.previousRuntimeKey){si(),x();return}ni(I),T(G=>G+1),P(G=>G+1)}),[]),l.useEffect(()=>{if(!N||i||Je()){R("done");return}let I=!1;return R("attempting"),bn().catch(()=>!1).then(()=>{I||R("done")}),()=>{I=!0}},[]),l.useEffect(()=>{g(!0)},[g]),l.useEffect(()=>{N&&!Je()||n()},[C,n,N]),l.useEffect(()=>{i&&(a===0&&d({source:"mobileApp:recovery"}),c===0&&u({source:"mobileApp:recovery"}))},[c,i,u,d,a]),l.useEffect(()=>{i&&Vs.setDirectory(f)},[f,i]),l.useEffect(()=>{i&&v(s.github,{force:!0})},[s.github,i,v]),l.useEffect(()=>{if(!i||y.length===0)return;let I=!1;return(async()=>{const G=new Map(be.getState().availableWorktreesByProject);if(await Promise.all(y.map(async z=>{const V=z.path.replace(/\\/g,"/").replace(/\/+$/,"");if(V)try{if(!(De.getState().directories.get(V)?.isGitRepo??await Oe(()=>import("./useAppFontEffects-CZdEKvZ8.js").then(K=>K.fC),__vite__mapDeps([0,1,2,3])).then(K=>K.checkIsGitRepository(V))))return;const b=await er({id:z.id,path:V});if(I)return;G.set(V,b)}catch{}})),I)return;const J=Array.from(G.values()).flat(),q=be.getState().availableWorktreesByProject;So(G,q)||be.setState({availableWorktrees:J,availableWorktreesByProject:G})})(),()=>{I=!0}},[i,y]),l.useEffect(()=>{let I=!1;return(async()=>{const G=await Gt("/health",{method:"GET"}).catch(()=>null);if(!G||!G.ok||I)return;const J=await G.json().catch(()=>null);if(!J||I)return;const q=J.planModeExperimentalEnabled;S(q===!0||q===1||q==="1"||q==="true")})(),()=>{I=!0}},[S]),l.useEffect(()=>{if(!m)return;const I=window.setTimeout(()=>p(),5e3);return()=>window.clearTimeout(I)},[p,m]),l.useEffect(()=>{if(!(!i&&(N?!!Je():!0))){w(!1);return}const U=window.setTimeout(()=>w(!0),8e3);return()=>window.clearTimeout(U)},[i,N,C,A]),po(),go({enabled:!0}),ri(),bo(),oi(),hl({enabled:N&&i}),ol({ready:N&&i&&r});const B=Ha(),M=!i&&o==="reconnecting";if(!B)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(xt,{width:120,height:120,isAnimated:!0})});const Y=!!Je();return N&&(!Y||!i&&!M)?Y?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(xt,{width:120,height:120,isAnimated:!D}),D?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]}),t.jsx(ge,{type:"button",variant:"outline",onClick:()=>{wt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(I=>I+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):k!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(xt,{width:120,height:120,isAnimated:!0}),E?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:e("mobile.connect.splash.connectingTo")}),t.jsxs("p",{className:"typography-small text-foreground",children:[E,t.jsx(xo,{})]})]}):null]}):t.jsx(Nl,{onConnected:()=>P(I=>I+1)}):!i&&!M?D?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(xt,{width:120,height:120,isAnimated:!0})}):t.jsx(ze,{children:t.jsx(yo,{sdk:Vs.getSdkClient(),directory:f||"",children:t.jsx(vo,{apis:s,children:t.jsx(wo,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[t.jsx(jo,{embeddedBackgroundWorkEnabled:r}),t.jsx(ii,{}),t.jsx(Pi,{}),t.jsx(Ml,{onActiveConnectionDeleted:()=>{wt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(I=>I+1)}}),t.jsx(ko,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),r?t.jsx(ai,{}):null]})})})},A)})}const Ll=()=>{Vo(),Wr().then(()=>{Promise.all([Vr(),Go()]).catch(s=>{console.error("[mobile-main] settings init failed:",s)}),Ho(),Ko(),qo()}).catch(s=>{console.error("[mobile-main] appearance init failed:",s)}).finally(()=>{vi()})};function Vl(s){Oo(),Ll(),Ei(),Bo();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const r=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",i=r?{...s,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:s,o=t.jsx(_l,{apis:i});Br.createRoot(e).render(t.jsx(as.StrictMode,{children:t.jsx(Fo,{children:t.jsx($o,{children:t.jsx(Uo,{children:t.jsx(xi,{children:r?o:t.jsx(Wo,{children:o})})})})})}))}export{Vl as renderMobileApp};