@openchamber/web 1.14.1 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/bin/cli.test.js +8 -0
  2. package/bin/lib/DOCUMENTATION.md +3 -0
  3. package/bin/lib/cli-args.js +10 -0
  4. package/bin/lib/commands-connect-url.js +169 -22
  5. package/dist/assets/{DiagramView-Cb58svCq.js → DiagramView-he_RFVx5.js} +1 -1
  6. package/dist/assets/MarkdownRendererImpl-CdBIHSPZ.js +11 -0
  7. package/dist/assets/{MultiRunWindow-BPSxV_B7.js → MultiRunWindow-B_C-tvVq.js} +1 -1
  8. package/dist/assets/OnboardingScreen-BBnTt-9w.js +1 -0
  9. package/dist/assets/SessionSwitcherDropdown-CWWrCFzr.js +1 -0
  10. package/dist/assets/SettingsWindow-CjqLdpTE.js +1 -0
  11. package/dist/assets/{TerminalView-fTYjnQkh.js → TerminalView-DQcdegHp.js} +1 -1
  12. package/dist/assets/es-r0_jT91q.js +15 -0
  13. package/dist/assets/fr-Bo8rtAJ1.js +13 -0
  14. package/dist/assets/index-8J6waVO6.js +2 -0
  15. package/dist/assets/index-DEMqM4Lz.css +1 -0
  16. package/dist/assets/ja-BPWtkG-c.js +15 -0
  17. package/dist/assets/ko-Bv0k-0E3.js +15 -0
  18. package/dist/assets/main-B-GA5Tg5.js +237 -0
  19. package/dist/assets/main-Dfm-VKZ9.js +2 -0
  20. package/dist/assets/miniChat-CfmCFFfu.js +2 -0
  21. package/dist/assets/mobile-CXJqeDlm.js +2 -0
  22. package/dist/assets/pl-CiTP50bz.js +15 -0
  23. package/dist/assets/pt-BR-DadIjX5L.js +15 -0
  24. package/dist/assets/renderElectronMiniChatApp-DS7Dy2ii.js +2 -0
  25. package/dist/assets/renderMobileApp-o7Fs9EBx.js +16 -0
  26. package/dist/assets/runtimeEndpointReset-MTaPPm4F.js +167 -0
  27. package/dist/assets/uk-2RpsWGoZ.js +15 -0
  28. package/dist/assets/{useAppFontEffects-BUUJYbAZ.js → useAppFontEffects-DkPuAMXD.js} +196 -133
  29. package/dist/assets/{vendor-.bun-C6iL44L9.js → vendor-.bun-BE757pvp.js} +1 -1
  30. package/dist/assets/zh-CN-BwKWaTuz.js +15 -0
  31. package/dist/assets/zh-TW--f_BqBpD.js +15 -0
  32. package/dist/index.html +4 -4
  33. package/dist/mini-chat.html +4 -4
  34. package/dist/mobile.html +4 -4
  35. package/package.json +2 -2
  36. package/server/index.js +236 -2
  37. package/server/lib/client-auth/pairing.js +308 -0
  38. package/server/lib/client-auth/pairing.test.js +142 -0
  39. package/server/lib/client-auth/remote-clients.js +65 -3
  40. package/server/lib/notifications/DOCUMENTATION.md +1 -1
  41. package/server/lib/notifications/apns-runtime.js +11 -16
  42. package/server/lib/notifications/runtime.js +135 -33
  43. package/server/lib/opencode/DOCUMENTATION.md +1 -0
  44. package/server/lib/opencode/agents.js +3 -0
  45. package/server/lib/opencode/bootstrap-runtime.js +15 -0
  46. package/server/lib/opencode/core-routes.js +321 -8
  47. package/server/lib/opencode/core-routes.test.js +329 -9
  48. package/server/lib/opencode/feature-routes-runtime.js +6 -0
  49. package/server/lib/opencode/network-runtime.js +14 -1
  50. package/server/lib/opencode/network-runtime.test.js +29 -9
  51. package/server/lib/opencode/proxy.js +47 -6
  52. package/server/lib/opencode/settings-helpers.js +24 -0
  53. package/server/lib/opencode/settings-helpers.test.js +25 -0
  54. package/server/lib/opencode/settings-normalization-runtime.js +21 -4
  55. package/server/lib/opencode/settings-normalization-runtime.test.js +21 -0
  56. package/server/lib/opencode/settings-runtime.js +25 -0
  57. package/server/lib/opencode/shutdown-runtime.js +2 -0
  58. package/server/lib/opencode/tunnel-auth.js +4 -9
  59. package/server/lib/package-manager.js +18 -5
  60. package/server/lib/permission-auto-accept/DOCUMENTATION.md +34 -0
  61. package/server/lib/permission-auto-accept/runtime.js +263 -0
  62. package/server/lib/permission-auto-accept/runtime.test.js +137 -0
  63. package/server/lib/projects/project-config.js +8 -0
  64. package/server/lib/quota/DOCUMENTATION.md +5 -2
  65. package/server/lib/quota/credentials/providers.js +43 -0
  66. package/server/lib/quota/credentials/store.js +48 -0
  67. package/server/lib/quota/credentials/store.test.js +26 -0
  68. package/server/lib/quota/opencode-go-credentials.js +11 -0
  69. package/server/lib/quota/opencode-go-credentials.test.js +32 -0
  70. package/server/lib/quota/providers/codex.js +7 -4
  71. package/server/lib/quota/providers/codex.test.js +48 -0
  72. package/server/lib/quota/providers/cursor.js +28 -39
  73. package/server/lib/quota/providers/index.js +7 -0
  74. package/server/lib/quota/providers/ollama-cloud.js +23 -42
  75. package/server/lib/quota/providers/ollama-cloud.test.js +12 -0
  76. package/server/lib/quota/providers/opencode-go.js +70 -0
  77. package/server/lib/quota/providers/opencode-go.test.js +17 -0
  78. package/server/lib/quota/routes.js +78 -7
  79. package/server/lib/quota/routes.test.js +40 -0
  80. package/server/lib/relay/DOCUMENTATION.md +98 -0
  81. package/server/lib/relay/cross-compat.test.js +135 -0
  82. package/server/lib/relay/e2ee.js +341 -0
  83. package/server/lib/relay/e2ee.test.js +124 -0
  84. package/server/lib/relay/host-client.js +389 -0
  85. package/server/lib/relay/host-client.test.js +280 -0
  86. package/server/lib/relay/host-lock.js +101 -0
  87. package/server/lib/relay/host-lock.test.js +129 -0
  88. package/server/lib/relay/identity.js +93 -0
  89. package/server/lib/relay/identity.test.js +78 -0
  90. package/server/lib/relay/service.js +334 -0
  91. package/server/lib/relay/signing-key.js +73 -0
  92. package/server/lib/relay/tunnel-codec.js +373 -0
  93. package/server/lib/relay/tunnel-codec.test.js +58 -0
  94. package/server/lib/relay/tunnel-host.js +462 -0
  95. package/server/lib/scheduled-tasks/runtime.js +104 -0
  96. package/server/lib/session-goal/DOCUMENTATION.md +176 -0
  97. package/server/lib/session-goal/objectives.js +61 -0
  98. package/server/lib/session-goal/routes.js +36 -0
  99. package/server/lib/session-goal/runtime.js +764 -0
  100. package/server/lib/ui-auth/DOCUMENTATION.md +6 -0
  101. package/server/lib/ui-auth/ui-auth.js +10 -0
  102. package/server/opencode-proxy.test.js +38 -0
  103. package/dist/assets/MarkdownRendererImpl-D2yCDL5A.js +0 -7
  104. package/dist/assets/OnboardingScreen-Sl-6JgaP.js +0 -1
  105. package/dist/assets/SessionSwitcherDropdown-4FWg9xMC.js +0 -1
  106. package/dist/assets/SettingsWindow-CY8q4msv.js +0 -1
  107. package/dist/assets/es-bWcuDy_2.js +0 -15
  108. package/dist/assets/fr-DzRs3OzV.js +0 -13
  109. package/dist/assets/index-KnWk9fmM.css +0 -1
  110. package/dist/assets/index-ZJTzZ0_U.js +0 -2
  111. package/dist/assets/ja-BqUX_UD3.js +0 -15
  112. package/dist/assets/ko-BQo10SNx.js +0 -15
  113. package/dist/assets/main-BDoqLlQB.js +0 -236
  114. package/dist/assets/main-DUGyTrDt.js +0 -2
  115. package/dist/assets/miniChat-DNDiX8GA.js +0 -2
  116. package/dist/assets/mobile-DnghtOCb.js +0 -2
  117. package/dist/assets/pl-Bgx_ATJT.js +0 -15
  118. package/dist/assets/pt-BR-B1yXRvoX.js +0 -15
  119. package/dist/assets/renderElectronMiniChatApp-BB4C1K7t.js +0 -2
  120. package/dist/assets/renderMobileApp-CZgaXKi5.js +0 -16
  121. package/dist/assets/runtimeEndpointReset-By39StyB.js +0 -167
  122. package/dist/assets/uk-C9k8SP8q.js +0 -15
  123. package/dist/assets/zh-CN-Bri-Vo5y.js +0 -15
  124. package/dist/assets/zh-TW-DAUGzmYG.js +0 -15
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-DkPuAMXD.js","assets/vendor-.bun-BE757pvp.js","assets/index-8J6waVO6.js","assets/index-DEMqM4Lz.css"])))=>i.map(i=>d[i]);
2
+ import{b as q,j as c,R as p,_ as jt,I as Dt,r as kt}from"./vendor-.bun-BE757pvp.js";import{e as le,ae as Pt,J as me,u as ut,D as Ct,o as ht,m as gt,p as Et,q as Mt}from"./index-8J6waVO6.js";import{eW as At,c as vt,dS as Rt,G as g,b as Ve,Y as _,cl as ft,ah as Nt,d as Lt,j as St,aU as Bt,aW as Ot,v as Tt,I as Fe,B as yt,a_ as V,ai as zt,aY as Wt,$ as $t,a0 as Ut,a1 as Gt,a7 as Ht,a9 as Ft,a6 as Vt,a4 as qt,a5 as Jt,eX as Kt,cU as Yt,U as Xt,aa as Qt,at as Zt,au as en,av as tn,aw as nn,ax as rn,ay as sn,az as on,aA as an,aB as cn}from"./useAppFontEffects-DkPuAMXD.js";import{C as ln,S as dn,W as un}from"./SessionSwitcherDropdown-CWWrCFzr.js";const fn=t=>{const e=q.c(3),{mode:r,children:s}=t;let n;return e[0]!==s||e[1]!==r?(n=c.jsx(At.Provider,{value:r,children:s}),e[0]=s,e[1]=r,e[2]=n):n=e[2],n},mn=t=>{const e=typeof t=="string"?t.trim():"";if(!e)return"";const r=typeof window<"u"?window.__OPENCHAMBER_HOME__:"";if(r&&e===r)return"~";if(r&&e.startsWith(`${r}/`))return`~/${e.slice(r.length+1)}`;const s=e.split("/").filter(Boolean);return s.length<=3?e:`.../${s.slice(-3).join("/")}`},U=t=>{const e=typeof t=="string"?t.trim():"";if(!e)return"";const r=e.replace(/\\/g,"/");return r==="/"?"/":r.replace(/\/+$/,"")},pn=t=>{const e=q.c(125),{mode:r}=t,{t:s}=vt(),n=g(yn),l=g(wn),a=g(gn),u=le(vn),f=Ve(Sn),d=Ve(xn),y=_(bn),j=_(_n),D=ft(),v=Nt(n??""),w=Lt(),x=St(In);let T;e[0]!==n?(T=o=>n?o.worktreeMetadata.get(n)?.path??"":"",e[0]=n,e[1]=T):T=e[1];const A=g(T);let R;e[2]!==n?(R=o=>n?o.worktreeMetadata.get(n)?.branch?.trim()??null:null,e[2]=n,e[3]=R):R=e[3];const B=g(R);let z;e[4]!==n?(z=o=>n?o.getAttachment(n):void 0,e[4]=n,e[5]=z):z=e[5];const i=Bt(z),N=g(jn),[m,I]=p.useState(!1),W=typeof window<"u"?window.__OPENCHAMBER_MACOS_MAJOR__??0:0,G=Number.isFinite(W)&&W>0,$=typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__&&window.__OPENCHAMBER_PLATFORM__==="win32",mt=G?W>=26?"h-12":W<=15?"h-14":"":"";let de;e[6]!==n||e[7]!==D?(de=n?D.find(o=>o.id===n)??null:null,e[6]=n,e[7]=D,e[8]=de):de=e[8];const E=de,L=E?.worktreeMetadata??null;let pe,he;e[9]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>{Pt()&&me("desktop_get_window_pinned").then(o=>{typeof o?.pinned=="boolean"&&I(o.pinned)})},he=[],e[9]=pe,e[10]=he):(pe=e[9],he=e[10]),p.useEffect(pe,he);let ye;e[11]!==l||e[12]!==r||e[13]!==E?.title||e[14]!==s?(ye=E?.title?.trim()||s(l||r==="draft"?"miniChat.header.newSession":"miniChat.header.session"),e[11]=l,e[12]=r,e[13]=E?.title,e[14]=s,e[15]=ye):ye=e[15];const qe=ye,Je=E?.directory??null;let we;e[16]!==Je?(we=U(Je),e[16]=Je,e[17]=we):we=e[17];const ge=we,Ke=A||L?.path||i?.cwd||i?.worktreeRoot||"";let ve;e[18]!==Ke?(ve=U(Ke),e[18]=Ke,e[19]=ve):ve=e[19];const Se=ve;let xe;e[20]!==u?(xe=U(u),e[20]=u,e[21]=xe):xe=e[21];const k=Se||ge||N||xe;let be;e[22]!==k?(be=mn(k),e[22]=k,e[23]=be):be=e[23];const xt=be;let _e;e[24]!==ge||e[25]!==Se?(_e=o=>{const h=U(Se||ge||"");if(!h)return null;for(const C of o.availableWorktreesByProject.values()){const b=C.find(O=>U(O.path)===h)?.branch?.trim();if(b)return b}return null},e[24]=ge,e[25]=Se,e[26]=_e):_e=e[26];const Ye=g(_e);let Ie,je;e[27]!==x||e[28]!==k||e[29]!==w.git?(Ie=()=>{k&&x(k,w.git).catch(Dn)},je=[x,k,w.git],e[27]=x,e[28]=k,e[29]=w.git,e[30]=Ie,e[31]=je):(Ie=e[30],je=e[31]),p.useEffect(Ie,je),L?.projectDirectory,i?.worktreeRoot;let Xe;e:{const o=L?.projectDirectory??i?.worktreeRoot??null;let h;e[32]!==o?(h=U(o),e[32]=o,e[33]=h):h=e[33];const S=h||k;if(!S){Xe=null;break e}let b;e[34]!==S||e[35]!==f?(b=f.map(kn).filter(O=>O.normalizedPath&&(O.normalizedPath===S||S.startsWith(`${O.normalizedPath}/`))).sort(Pn)[0]??null,e[34]=S,e[35]=f,e[36]=b):b=e[36],Xe=b}const bt=Xe;let De;e:{const o=bt??d;if(!o){De=xt||"OpenChamber";break e}let h;e[37]!==o.label?(h=o.label?.trim(),e[37]=o.label,e[38]=h):h=e[38];const C=h;if(C){De=C;break e}let S;e[39]!==o.path?(S=o.path.split(/[\\/]/).filter(Boolean).at(-1)??o.path,e[39]=o.path,e[40]=S):S=e[40],De=S}const Qe=De,Ze=Ot(k||null);let ke;e[41]!==Ye||e[42]!==Ze||e[43]!==L?.branch||e[44]!==i?.branch||e[45]!==B?(ke=Ze||B||L?.branch?.trim()||i?.branch?.trim()||Ye,e[41]=Ye,e[42]=Ze,e[43]=L?.branch,e[44]=i?.branch,e[45]=B,e[46]=ke):ke=e[46];const et=ke,Pe=et&&et!=="HEAD"?et:null;let Ce;e[47]!==y?(Ce=y(),e[47]=y,e[48]=Ce):Ce=e[48];const pt=Ce;let tt;e:{for(let o=v.length-1;o>=0;o=o-1,o){const h=v[o];if(h.role!=="assistant"||typeof h.providerID!="string"||typeof h.modelID!="string")continue;const S=j.find(b=>b.id===h.providerID)?.models.find(b=>b.id===h.modelID);if(S){tt=S;break e}}tt=void 0}const _t=tt,Ee=pt?.limit?pt:_t,J=Ee&&typeof Ee.limit=="object"&&Ee.limit!==null?Ee.limit:null,H=J&&typeof J.context=="number"?J.context:0,ue=J&&typeof J.output=="number"?J.output:0;let Me;e:{if(!n||v.length===0){Me=null;break e}let o,h;for(let fe=v.length-1;fe>=0;fe=fe-1,fe){const dt=v[fe];if(dt.role!=="assistant")continue;const F=dt.tokens;if(!F)continue;if(F.input+F.output+F.reasoning+(F.cache?.read??0)+(F.cache?.write??0)>0){o=F,h=dt.id;break}}if(!o){Me=null;break e}const C=o.input+o.output+o.reasoning+(o.cache?.read??0)+(o.cache?.write??0),S=H>0?H:2e5;let b;e[49]!==H||e[50]!==C?(b=H>0?Math.round(C/H*100):0,e[49]=H,e[50]=C,e[51]=b):b=e[51];const O=b;let Ge;e[52]!==o.output||e[53]!==ue?(Ge=ue>0?Math.round(o.output/ue*100):void 0,e[52]=o.output,e[53]=ue,e[54]=Ge):Ge=e[54];const at=Ge,ct=H||0,lt=ue||void 0;let He;e[55]!==h||e[56]!==at||e[57]!==O||e[58]!==ct||e[59]!==lt||e[60]!==S||e[61]!==C?(He={totalTokens:C,percentage:O,contextLimit:ct,outputLimit:lt,normalizedOutput:at,thresholdLimit:S,lastMessageId:h},e[55]=h,e[56]=at,e[57]=O,e[58]=ct,e[59]=lt,e[60]=S,e[61]=C,e[62]=He):He=e[62],Me=He}const P=Me,[M,nt]=p.useState(null);let Ae;e[63]===Symbol.for("react.memo_cache_sentinel")?(Ae={WebkitAppRegion:"drag"},e[63]=Ae):Ae=e[63];const It=Ae;let Re;e[64]===Symbol.for("react.memo_cache_sentinel")?(Re={WebkitAppRegion:"no-drag"},e[64]=Re):Re=e[64];const rt=Re;let Ne,Le;e[65]!==P||e[66]!==n?(Ne=()=>{if(!n){nt(Cn);return}if(P&&P.totalTokens>0){nt(o=>o&&o.totalTokens===P.totalTokens&&o.percentage===P.percentage&&o.contextLimit===P.contextLimit&&(o.outputLimit??0)===(P.outputLimit??0)&&(o.normalizedOutput??0)===(P.normalizedOutput??0)&&o.thresholdLimit===P.thresholdLimit&&o.lastMessageId===P.lastMessageId?o:P);return}nt(En)},Le=[P,n],e[65]=P,e[66]=n,e[67]=Ne,e[68]=Le):(Ne=e[67],Le=e[68]),p.useEffect(Ne,Le);const st=M&&M.contextLimit>0?Math.min(999,M.totalTokens/M.contextLimit*100):0;let Be;e[69]!==m?(Be=()=>{const o=!m;I(o),me("desktop_set_window_pinned",{pinned:o}).catch(()=>{I(!o)})},e[69]=m,e[70]=Be):Be=e[70];const ot=Be;let Oe;e[71]!==u||e[72]!==n||e[73]!==a||e[74]!==k||e[75]!==E?(Oe=()=>{const o=n?{sessionId:n,directory:E?.directory??u??""}:{mode:"draft",directory:k||u||"",projectId:a};me("desktop_focus_main_window",o).then(Mn)},e[71]=u,e[72]=n,e[73]=a,e[74]=k,e[75]=E,e[76]=Oe):Oe=e[76];const it=Oe;let Te;e[77]===Symbol.for("react.memo_cache_sentinel")?(Te=Tt("flex items-center gap-3 bg-background pr-3",G?"pl-[5.5rem]":"pl-3",$?"h-12":mt||"min-h-14"),e[77]=Te):Te=e[77];let K;e[78]!==s?(K=s("sessions.switcher.openAria"),e[78]=s,e[79]=K):K=e[79];let Y;e[80]!==qe?(Y=c.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:qe}),e[80]=qe,e[81]=Y):Y=e[81];let X;e[82]!==Qe?(X=c.jsx("span",{className:"truncate",children:Qe}),e[82]=Qe,e[83]=X):X=e[83];let Q;e[84]!==Pe?(Q=Pe?c.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[c.jsx(Fe,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),c.jsx("span",{className:"truncate",children:Pe})]}):null,e[84]=Pe,e[85]=Q):Q=e[85];let Z;e[86]!==X||e[87]!==Q?(Z=c.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[X,Q]}),e[86]=X,e[87]=Q,e[88]=Z):Z=e[88];let ee;e[89]!==K||e[90]!==Y||e[91]!==Z?(ee=c.jsx(dn,{children:c.jsxs("button",{type:"button","aria-label":K,style:rt,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[Y,Z]})}),e[89]=K,e[90]=Y,e[91]=Z,e[92]=ee):ee=e[92];let ze;e[93]===Symbol.for("react.memo_cache_sentinel")?(ze=c.jsx("div",{className:"min-w-0 flex-1"}),e[93]=ze):ze=e[93];let te;e[94]!==st||e[95]!==M?(te=M&&M.totalTokens>0?c.jsx(ln,{totalTokens:M.totalTokens,percentage:st,colorPercentage:M.percentage,contextLimit:M.contextLimit,outputLimit:M.outputLimit??0,className:"h-9 shrink-0 pl-1 pr-1 typography-ui-label",valueClassName:"font-semibold leading-none",hideIcon:!0,showPercentIcon:!0,percentIconClassName:"h-4.5 w-4.5"}):null,e[94]=st,e[95]=M,e[96]=te):te=e[96];let ne;e[97]!==m||e[98]!==s?(ne=s(m?"miniChat.actions.unpinAria":"miniChat.actions.pinAria"),e[97]=m,e[98]=s,e[99]=ne):ne=e[99];let re;e[100]!==m||e[101]!==s?(re=s(m?"miniChat.actions.unpin":"miniChat.actions.pin"),e[100]=m,e[101]=s,e[102]=re):re=e[102];let se;e[103]!==m?(se=m?c.jsx(Fe,{name:"pushpin-2-fill",className:"h-4 w-4"}):c.jsx(Fe,{name:"pushpin-2",className:"h-4 w-4"}),e[103]=m,e[104]=se):se=e[104];let oe;e[105]!==ot||e[106]!==ne||e[107]!==re||e[108]!==se?(oe=c.jsx(yt,{type:"button",variant:"ghost",size:"icon",onClick:ot,"aria-label":ne,title:re,style:rt,children:se}),e[105]=ot,e[106]=ne,e[107]=re,e[108]=se,e[109]=oe):oe=e[109];let ie;e[110]!==s?(ie=s("miniChat.actions.openMainAria"),e[110]=s,e[111]=ie):ie=e[111];let ae;e[112]!==s?(ae=s("miniChat.actions.openMain"),e[112]=s,e[113]=ae):ae=e[113];let We;e[114]===Symbol.for("react.memo_cache_sentinel")?(We=c.jsx(Fe,{name:"external-link",className:"h-4 w-4"}),e[114]=We):We=e[114];let ce;e[115]!==it||e[116]!==ie||e[117]!==ae?(ce=c.jsx(yt,{type:"button",variant:"ghost",size:"icon",onClick:it,"aria-label":ie,title:ae,style:rt,children:We}),e[115]=it,e[116]=ie,e[117]=ae,e[118]=ce):ce=e[118];let $e;e[119]===Symbol.for("react.memo_cache_sentinel")?($e=c.jsx(un,{visible:$}),e[119]=$e):$e=e[119];let Ue;return e[120]!==ee||e[121]!==te||e[122]!==oe||e[123]!==ce?(Ue=c.jsxs("header",{className:Te,style:It,children:[ee,ze,te,oe,ce,$e]}),e[120]=ee,e[121]=te,e[122]=oe,e[123]=ce,e[124]=Ue):Ue=e[124],Ue},hn=t=>{const e=q.c(9),{mode:r,autoOpenDraft:s,unavailable:n}=t,l=s===void 0?!1:s,a=n===void 0?!1:n,{t:u}=vt();let f;e[0]!==r?(f=c.jsx(pn,{mode:r}),e[0]=r,e[1]=f):f=e[1];let d;e[2]!==l||e[3]!==u||e[4]!==a?(d=c.jsx("main",{className:"min-h-0 flex-1",children:a?c.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center typography-ui-label text-muted-foreground",children:c.jsxs("div",{className:"max-w-sm rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-3",children:[c.jsx("div",{className:"font-medium text-foreground",children:u("miniChat.unavailable.title")}),c.jsx("div",{className:"mt-1 typography-small text-muted-foreground",children:u("miniChat.unavailable.description")})]})}):c.jsx(fn,{mode:"mini-chat",children:c.jsx(Rt,{autoOpenDraft:l})})}),e[2]=l,e[3]=u,e[4]=a,e[5]=d):d=e[5];let y;return e[6]!==f||e[7]!==d?(y=c.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[f,d]}),e[6]=f,e[7]=d,e[8]=y):y=e[8],y};function yn(t){return t.currentSessionId}function wn(t){return!!t.newSessionDraft?.open}function gn(t){return t.newSessionDraft?.selectedProjectId??null}function vn(t){return t.currentDirectory}function Sn(t){return t.projects}function xn(t){return t.getActiveProject()}function bn(t){return t.getCurrentModel}function _n(t){return t.providers}function In(t){return t.ensureStatus}function jn(t){return t.newSessionDraft?.open?U(t.newSessionDraft.bootstrapPendingDirectory??t.newSessionDraft.directoryOverride??""):""}function Dn(){}function kn(t){return{...t,normalizedPath:U(t.path)}}function Pn(t,e){return e.path.length-t.path.length}function Cn(t){return t===null?t:null}function En(t){return t===null?t:null}function Mn(t){return t?.focused===!0?me("desktop_close_current_window"):null}const wt=()=>{document.querySelector('textarea[data-chat-input="true"]')?.focus()},An=()=>{const t=ut(n=>n.shortcutOverrides),e=le(n=>n.currentDirectory),r=Ve(n=>n.getActiveProject()),s=g(n=>n.openNewSessionDraft);p.useEffect(()=>{const n=a=>Wt(a,t),l=a=>{if(V(a,n("focus_input"))){a.preventDefault(),wt();return}if(Ct()&&V(a,n("new_mini_chat"))){a.preventDefault(),me("desktop_open_draft_mini_chat_window",{directory:e||r?.path||"",projectId:r?.id??null})?.catch(d=>{console.warn("[mini-chat-shortcuts] failed to open draft mini chat window",d)});return}if(V(a,n("new_chat"))){a.preventDefault(),s({selectedProjectId:r?.id??null,directoryOverride:e||r?.path||null,preserveDirectoryOverride:!!(e||r?.path)}),wt();return}if(V(a,n("open_model_selector"))){a.preventDefault();const{isModelSelectorOpen:d,setModelSelectorOpen:y}=ut.getState();y(!d);return}if(V(a,n("cycle_thinking_variant"))){const d=_.getState();if(d.getCurrentModelVariants().length===0)return;a.preventDefault(),d.cycleCurrentVariant();const j=_.getState().currentVariant,D=g.getState().currentSessionId,v=_.getState().currentAgentName,w=_.getState().currentProviderId,x=_.getState().currentModelId;D&&v&&w&&x&&zt.getState().saveAgentModelVariantForSession(D,v,w,x,j);return}const u=V(a,n("cycle_favorite_model_forward")),f=V(a,n("cycle_favorite_model_backward"));if(u||f){const{favoriteModels:d,addRecentModel:y}=ut.getState();if(d.length===0)return;a.preventDefault();const{currentProviderId:j,currentModelId:D,setProvider:v,setModel:w}=_.getState(),x=d.findIndex(R=>R.providerID===j&&R.modelID===D),A=d[(x+(u?1:-1)+d.length)%d.length];v(A.providerID),w(A.modelID),y(A.providerID,A.modelID)}};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[r?.id,r?.path,e,s,t])},Rn="openchamber:mini-chat-presence",Nn=()=>{const t=typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,e=t.get("mode")==="session"?"session":"draft",r=t.get("sessionId")?.trim()||null,s=t.get("directory")?.trim()||null,n=t.get("projectId")?.trim()||null;return{mode:e,sessionId:r,directory:s,projectId:n}},Ln=({config:t})=>{const e=ft(),r=le(i=>i.currentDirectory),s=le(i=>i.setDirectory),n=Ve(i=>i.projects),l=g(i=>i.currentSessionId),a=g(i=>!!i.newSessionDraft?.open),u=g(i=>i.newSessionDraft?.open?i.newSessionDraft.bootstrapPendingDirectory??i.newSessionDraft.directoryOverride??"":""),f=g(i=>i.setCurrentSession),d=g(i=>i.openNewSessionDraft),y=_(i=>i.initializeApp),j=_(i=>i.isInitialized),D=_(i=>i.isConnected),v=_(i=>i.loadProviders),w=_(i=>i.loadAgents),x=_(i=>i.providers.length),T=_(i=>i.agents.length),A=Yt();p.useEffect(()=>{y()},[y]),p.useEffect(()=>{if(j)return;let i=!0,N=0;const m=window.setInterval(()=>{if(i){if(N+=1,N>10){window.clearInterval(m);return}_.getState().isInitialized||_.getState().initializeApp()}},1e3);return()=>{i=!1,window.clearInterval(m)}},[j]);const R=p.useRef(!1);p.useEffect(()=>{if(!R.current&&t.mode==="session"&&t.directory){if(r===t.directory){R.current=!0;return}s(t.directory,{showOverlay:!1}),R.current=!0}},[t.directory,t.mode,r,s]),p.useEffect(()=>{t.mode!=="draft"||!a||l||!u||r===u||s(u,{showOverlay:!1})},[t.mode,r,l,u,a,s]),p.useEffect(()=>{D&&(x===0&&v({source:"electronMiniChat:recovery"}),T===0&&w({source:"electronMiniChat:recovery"}))},[T,D,w,v,x]);const B=p.useRef(!1);p.useEffect(()=>{if(B.current||t.mode!=="session"||!t.sessionId)return;if(l===t.sessionId){B.current=!0;return}if(l){B.current=!0;return}const i=e.find(m=>m.id===t.sessionId);if(!i){A.ensureSessionRenderable(t.sessionId);return}const N=i.directory??t.directory;f(t.sessionId,N),B.current=!0},[t,l,e,f,A]),p.useEffect(()=>{const i=N=>{const m=N.detail,I=typeof m?.sessionId=="string"?m.sessionId.trim():"";if(!I||g.getState().currentSessionId===I)return;const W=typeof m?.directory=="string"&&m.directory.trim().length>0?m.directory.trim():e.find(G=>G.id===I)?.directory??null;A.ensureSessionRenderable(I),f(I,W),B.current=!0};return window.addEventListener("openchamber:open-session",i),()=>window.removeEventListener("openchamber:open-session",i)},[e,f,A]),p.useEffect(()=>{t.mode!=="draft"||a||l||d({selectedProjectId:t.projectId,directoryOverride:t.directory,preserveDirectoryOverride:!!t.directory})},[t,l,a,d]),p.useEffect(()=>{if(n.length===0)return;let i=!1;return(async()=>{const m=new Map,I=[];if(await Promise.all(n.map(async G=>{const $=G.path.replace(/\\/g,"/").replace(/\/+$/,"");if($)try{if(!(St.getState().directories.get($)?.isGitRepo??await jt(()=>import("./useAppFontEffects-DkPuAMXD.js").then(L=>L.fc),__vite__mapDeps([0,1,2,3])).then(L=>L.checkIsGitRepository($))))return;const E=await Xt({id:G.id,path:$});if(i||E.length===0)return;m.set($,E),I.push(...E)}catch{}})),i)return;const W=g.getState().availableWorktreesByProject;Qt(m,W)||g.setState({availableWorktrees:I,availableWorktreesByProject:m})})(),()=>{i=!0}},[n]);const z=p.useRef(!1);return p.useEffect(()=>{if(z.current||!j)return;const i=()=>{if(z.current)return;z.current=!0;const I=typeof document<"u"?document.getElementById("initial-loading"):null;I&&(I.classList.add("fade-out"),window.setTimeout(()=>I.remove(),300))},N=t.mode==="session"?l===t.sessionId:a,m=window.setTimeout(i,N?100:1500);return()=>window.clearTimeout(m)},[j,t.mode,t.sessionId,l,a]),null},Bn=()=>{const t=q.c(4),e=g(Un),r=le(Gn);let s,n;return t[0]!==r||t[1]!==e?(s=()=>{if(!e||!r||typeof BroadcastChannel>"u")return;const l=new BroadcastChannel(Rn),a=d=>{l.postMessage({type:"mini-chat-session-presence",sessionId:e,directory:r,viewed:d})};a(!0);const u=window.setInterval(()=>a(!0),5e3),f=()=>a(!1);return window.addEventListener("beforeunload",f),()=>{window.clearInterval(u),window.removeEventListener("beforeunload",f),a(!1),l.close()}},n=[r,e],t[0]=r,t[1]=e,t[2]=s,t[3]=n):(s=t[2],n=t[3]),p.useEffect(s,n),null},On=t=>{const e=q.c(6),r=ft(),s=g(Hn),[n,l]=p.useState(!1);let a,u;return e[0]!==t.mode||e[1]!==t.sessionId||e[2]!==s||e[3]!==r?(a=()=>{if(t.mode!=="session"||!t.sessionId||s===t.sessionId){l(!1);return}if(r.some(d=>d.id===t.sessionId)){l(!1);return}const f=window.setTimeout(()=>l(!0),5e3);return()=>window.clearTimeout(f)},u=[t.mode,t.sessionId,s,r],e[0]=t.mode,e[1]=t.sessionId,e[2]=s,e[3]=r,e[4]=a,e[5]=u):(a=e[4],u=e[5]),p.useEffect(a,u),n};function Tn(t){const e=q.c(15),{apis:r}=t;let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=Nn(),e[0]=s):s=e[0];const n=s,l=le(Wn);let a,u;e[1]!==l?(a=()=>{ht.setDirectory(l||n.directory||void 0)},u=[n.directory,l],e[1]=l,e[2]=a,e[3]=u):(a=e[2],u=e[3]),p.useEffect(a,u);let f,d;e[4]!==r?(f=()=>(gt(r),zn),d=[r],e[4]=r,e[5]=f,e[6]=d):(f=e[5],d=e[6]),p.useEffect(f,d),$t(),An();let y;e[7]===Symbol.for("react.memo_cache_sentinel")?(y={enabled:!0},e[7]=y):y=e[7],Ut(y),Gt();let j;e[8]===Symbol.for("react.memo_cache_sentinel")?(j=ht.getSdkClient(),e[8]=j):j=e[8];const D=l||n.directory||"";let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=c.jsx(Ht,{delayDuration:300,skipDelayDuration:150,children:c.jsxs("div",{className:"h-full text-foreground bg-background",children:[c.jsx($n,{config:n}),c.jsx(Ft,{})]})}),e[9]=v):v=e[9];let w;e[10]!==r?(w=c.jsx(Vt,{apis:r,children:v}),e[10]=r,e[11]=w):w=e[11];let x;return e[12]!==w||e[13]!==D?(x=c.jsx(qt,{children:c.jsx(Jt,{sdk:j,directory:D,children:w})}),e[12]=w,e[13]=D,e[14]=x):x=e[14],x}function zn(){return gt(null)}function Wn(t){return t.currentDirectory}const $n=t=>{const e=q.c(11),{config:r}=t,s=On(r);let n;e[0]!==r?(n=c.jsx(Ln,{config:r}),e[0]=r,e[1]=n):n=e[1];let l,a;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=c.jsx(Bn,{}),a=c.jsx(Kt,{embeddedBackgroundWorkEnabled:!0}),e[2]=l,e[3]=a):(l=e[2],a=e[3]);const u=r.mode==="draft";let f;e[4]!==r.mode||e[5]!==s||e[6]!==u?(f=c.jsx(hn,{mode:r.mode,autoOpenDraft:u,unavailable:s}),e[4]=r.mode,e[5]=s,e[6]=u,e[7]=f):f=e[7];let d;return e[8]!==n||e[9]!==f?(d=c.jsxs(c.Fragment,{children:[n,l,a,f]}),e[8]=n,e[9]=f,e[10]=d):d=e[10],d};function Un(t){return t.currentSessionId}function Gn(t){return t.currentDirectory}function Hn(t){return t.currentSessionId}const Fn=()=>{rn(),Et().then(()=>{Promise.all([Mt(),sn()]).catch(t=>{console.error("[mini-chat-main] settings init failed:",t)}),on(),an(),cn()}).catch(t=>{console.error("[mini-chat-main] appearance init failed:",t)})};function Qn(t){Fn();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");Dt.createRoot(e).render(c.jsx(kt.StrictMode,{children:c.jsx(Zt,{children:c.jsx(en,{children:c.jsx(tn,{children:c.jsx(nn,{children:c.jsx(Tn,{apis:t})})})})})}))}export{Qn as renderElectronMiniChatApp};
@@ -0,0 +1,16 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-DkPuAMXD.js","assets/vendor-.bun-BE757pvp.js","assets/index-8J6waVO6.js","assets/index-DEMqM4Lz.css"])))=>i.map(i=>d[i]);
2
+ import{b as de,r as rs,j as t,R as c,P as Ct,K as ms,e as jr,f as Sn,B as kr,Q as Sr,g as Nr,i as Cr,F as Er,U as Pr,Z as Ir,a as hs,p as Nn,k as Tr,u as Cn,l as zt,s as En,m as Pn,n as In,o as os,D as Tn,q as An,S as Rn,v as Dn,t as Mn,w as _n,C as zn,M as Ln,x as is,J as On,y as Ar,z as Ms,A as ps,E as _s,V as Rr,G as Dr,H as Mr,_ as ze,I as _r}from"./vendor-.bun-BE757pvp.js";import{u as mt,a as zs,b as zr,r as Lr,d as We,e as lt,s as jt,f as Bn,i as kt,h as gs,j as Or,k as Fn,l as Ls,m as Os,n as Br,o as Bs,p as Fr,q as $r}from"./index-8J6waVO6.js";import{u as Ut,a as Ur,b as Te,r as $n,c as ue,g as Un,t as ie,o as Wr,I as re,d as Wt,e as bs,f as xs,h as Wn,i as Vr,j as Ae,s as Gr,k as Hr,l as Kr,m as qr,n as Jr,p as Vn,B as pe,q as ot,S as Ze,v as X,w as ys,x as Yr,y as Fs,z as vs,A as $s,F as Xr,C as Us,D as Qr,J as Zr,E as Gn,G as be,H as eo,K as to,M as Hn,P as Kn,L as qn,N as Jn,O as so,Q as no,R as ro,T as oo,U as Yn,V as Ne,W as io,X as ao,Y as Ie,Z as lo,_ as co,$ as uo,a0 as fo,a1 as mo,a2 as xt,a3 as ho,a4 as Oe,a5 as po,a6 as go,a7 as bo,a8 as xo,a9 as yo,aa as vo,ab as Xn,ac as wo,ad as jo,ae as ko,af as So,ag as No,ah as Co,ai as Eo,aj as Po,ak as Ws,al as Vs,am as Io,an as To,ao as Ao,ap as Ro,aq as Do,ar as Mo,as as _o,at as zo,au as Lo,av as Oo,aw as Bo,ax as Fo,ay as $o,az as Uo,aA as Wo,aB as Vo}from"./useAppFontEffects-DkPuAMXD.js";import{u as it,S as Go,C as Ho,a as Ko,P as qo,b as Jo,D as Yo,N as Xo,p as Qo,r as Zo,c as ei,d as ti,e as si,O as ni,f as ri,g as Rt,h as oi,M as ii,i as ai,j as li,k as ci,A as di,l as Je,m as ui,Q as fi,n as mi,o as hi}from"./runtimeEndpointReset-MTaPPm4F.js";import"./mobileLayoutPreference-Dio-WWkI.js";let Qn=null,Gs=!1;const pi=new Promise(s=>{Qn=s});function gi(){Gs||(Gs=!0,Qn?.())}const bi=6,xi=s=>s.parentID??null,Hs=s=>{const e=s.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},yi=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),vi=(s,e)=>{if(!s)return"";let n=null,r=-1;for(const i of e){const o=yi(i.path);(s===o||s.startsWith(`${o}/`))&&o.length>r&&(n=i,r=o.length)}return n?n.label?.trim()||Hs(n.path):Hs(s)},wi=()=>{const s=Ut.getState().activeSessions,e=Ur.getState().index.session.unseenCount,n=mt.getState().notifyOnSubtasks,r=Te.getState().projects;let i=0;const o=[];for(const l of s){const d=xi(l)!==null,f=(e[l.id]??0)>0&&(!d||n);f&&(i+=1),d||o.push({id:l.id,title:l.title??"",updated:l.time?.updated??l.time?.created??0,unread:f,project:vi($n(l),r)})}o.sort((l,d)=>d.updated-l.updated);const a=o.slice(0,bi).map(({id:l,title:d,unread:u,project:f})=>({id:l,title:d,unread:u,project:f}));return{attentionCount:i,recentSessions:a}},ji="__OPENCHAMBER_WIDGET_SNAPSHOT__",ki=()=>{typeof window>"u"||(window[ji]=()=>{try{return JSON.stringify(wi())}catch{return null}})},Xt="mobile-app-update-available",Ks="mobile-app-update-toast-dismissed-version",Si=()=>{const s=de.c(8),{t:e}=ue(),n=it(Ni),r=it(Ci),i=it(Ei),o=it(Pi);let a;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,s[0]=a):a=s[0];const l=rs.useRef(a);let d,u;return s[1]!==n||s[2]!==o||s[3]!==r||s[4]!==e||s[5]!==i?(d=()=>{if(Un()!=="android"||r!=="mobile"||!n||!i||!o){ie.dismiss(Xt);return}zs().getItem(Ks)!==i&&(l.current.has(i)||(l.current.add(i),ie.info(e("mobileUpdate.toast.available.title"),{id:Xt,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:()=>{Wr(o)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{zs().setItem(Ks,i),ie.dismiss(Xt)}}})))},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]),rs.useEffect(d,u),null};function Ni(s){return s.available}function Ci(s){return s.runtimeType}function Ei(s){return s.info?.version}function Pi(s){return s.info?.downloadUrl}const Ii=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),Ti=s=>{const e=s.index?.trim();return!!(e&&e!=="?")},Ai=s=>{const e=s.working_dir?.trim(),n=s.index?.trim();return!!(e||n==="?")},qs=(s,e)=>e?`${s}\0staged`:s,Js=({onClose:s,initialDiffPath:e,initialDiffStaged:n=!1})=>{const{t:r}=ue(),{git:i}=Wt(),o=Ii(bs()??null),a=xs(o||null),l=Wn(o||null),d=Vr(o||null),u=Ae(z=>z.setActiveDirectory),f=Ae(z=>z.ensureAll),m=Ae(z=>z.fetchStatus),p=Ae(z=>z.fetchBranches),g=Ae(z=>z.prefetchDiffs),k=Ae(z=>z.getDiff),S=Ae(z=>z.setDiff),[y,P]=c.useState(()=>e?{type:"diff",path:e,staged:n}:{type:"list"});c.useEffect(()=>{e&&P(z=>z.type==="diff"&&z.path===e&&z.staged===n?z:{type:"diff",path:e,staged:n})},[e,n]);const[I,D]=c.useState(null),[A,R]=c.useState(null),[w,j]=c.useState(""),[T,E]=c.useState(new Set),[b,N]=c.useState(!1),[x,_]=c.useState(!1),[L,G]=c.useState([]),[M,J]=c.useState([]),[C,q]=c.useState([]),[B,O]=c.useState(null),[V,K]=c.useState(null),[Z,te]=c.useState(0),oe=c.useMemo(()=>{const z=a?.files??[],F=new Map;for(const Y of z)F.set(Y.path,Y);return Array.from(F.values()).sort((Y,Se)=>Y.path.localeCompare(Se.path))},[a?.files]),v=c.useMemo(()=>oe.filter(Ti),[oe]),W=c.useMemo(()=>oe.filter(Ai),[oe]),ee=c.useMemo(()=>{if(C.length>0)return C;const z=a?.tracking?.includes("/")?a.tracking.split("/")[0]:null;return z||B?[{name:z||"origin",fetchUrl:B??"",pushUrl:B??""}]:[]},[B,C,a?.tracking]),se=Ae(c.useCallback(z=>!o||y.type!=="diff"?null:z.directories.get(o)?.diffCache.get(qs(y.path,y.staged))??null,[o,y])),je=c.useMemo(()=>y.type!=="diff"?null:oe.find(z=>z.path===y.path)??null,[oe,y]),le=c.useCallback(async(z=!0)=>{if(o)try{await Promise.all([m(o,i),p(o,i)])}catch(F){z&&ie.error(F instanceof Error?F.message:r("gitView.toast.refreshRepositoryFailed"))}},[o,p,m,i,r]),ce=c.useCallback(async()=>{if(!o){q([]),O(null);return}try{const[z,F]=await Promise.all([i.getRemotes(o).catch(()=>[]),i.getRemoteUrl?i.getRemoteUrl(o).catch(()=>null):Promise.resolve(null)]);q(z),O(F)}catch{q([]),O(null)}},[o,i]);c.useEffect(()=>{o&&(u(o),f(o,i))},[o,f,i,u]),c.useEffect(()=>{ce()},[ce]),c.useEffect(()=>{if(!o||oe.length===0)return;const z=Array.from(new Set([...v.map(Y=>Y.path),...M,...oe.slice(0,20).map(Y=>Y.path)])).filter(Boolean);if(z.length===0)return;const F=window.setTimeout(()=>{g(o,i,z,{maxFiles:40})},120);return()=>window.clearTimeout(F)},[oe,o,i,g,v,M]),c.useEffect(()=>{if(y.type!=="diff"){K(null);return}const z=qs(y.path,y.staged);if(!o||k(o,z)){K(null);return}let F=!1;return K(null),i.getGitFileDiff(o,{path:y.path,staged:y.staged||void 0}).then(Y=>{F||S(o,z,{original:Y.original??"",modified:Y.modified??"",isBinary:Y.isBinary})}).catch(Y=>{F||K(Y instanceof Error?Y.message:String(Y))}),()=>{F=!0}},[o,Z,k,i,y,S]);const ke=async(z,F)=>{if(o){D(z);try{const Y=Se=>{const Me=`${Se.name}/`,qe=a?.tracking?.startsWith(Me)?a.tracking.slice(Me.length):void 0;return{remote:Se.name,branch:qe,rebase:!0}};if(z==="fetch"){if(!F)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:F.name}),ie.success(r("gitView.toast.fetchedFromRemote",{name:F.name}))}else if(z==="sync"){if(!F)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:F.name});const Se=await i.getGitStatus(o);if((Se.behind??0)>0){if((Se.files?.length??0)>0){ie.error(r("gitView.toast.commitOrStashBeforeSync"));return}await i.gitPull(o,Y(F))}((await i.getGitStatus(o)).ahead??0)>0&&await i.gitPush(o),ie.success(r("gitView.toast.alreadyUpToDate"))}await le(!1),await ce()}catch(Y){ie.error(Y instanceof Error?Y.message:r("gitView.toast.syncActionFailed",{action:r("gitView.sync.syncChanges")}))}finally{D(null)}}},ae=c.useCallback(async(z,F)=>{if(!(!o||z.length===0))try{F==="stage"?z.length>1?await Gr(o,z):await Hr(o,z[0]):z.length>1?await Kr(o,z):await qr(o,z[0]),await le(!1)}catch(Y){ie.error(Y instanceof Error?Y.message:r(F==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[o,le,r]),me=c.useCallback((z,F=!1)=>{P({type:"diff",path:z,staged:F})},[]),ge=c.useCallback(async z=>{if(o){E(F=>new Set(F).add(z));try{await i.revertGitFile(o,z),ie.success(r("gitView.toast.revertedFile",{path:z})),await le(!1)}catch(F){ie.error(F instanceof Error?F.message:r("gitView.toast.revertFailed"))}finally{E(F=>{const Y=new Set(F);return Y.delete(z),Y})}}},[o,i,le,r]),Fe=c.useCallback(async z=>{if(!o||z.length===0||b)return;const F=Array.from(new Set(z));N(!0),E(new Set(F));try{await Promise.all(F.map(Y=>i.revertGitFile(o,Y))),await le(!1),ie.success(F.length===1?r("gitView.toast.revertedFilesSingle",{count:F.length}):r("gitView.toast.revertedFilesPlural",{count:F.length}))}catch(Y){ie.error(Y instanceof Error?Y.message:r("gitView.toast.revertFailed"))}finally{E(new Set),N(!1)}},[o,i,b,le,r]),De=c.useCallback(z=>{const F=z.map(Y=>Y.trim()).filter(Boolean);if(F.length===0){G([]);return}j(Y=>`${Y.trim()}${Y.trim()?`
3
+
4
+ `:""}${F.join(`
5
+ `)}`.trim()),G([])},[]),pt=c.useCallback(async()=>{if(!o)return;const z=v.map(F=>F.path).sort();if(z.length===0){ie.error(r("gitView.toast.selectFileToDescribe"));return}_(!0);try{const{message:F}=await Jr(o,z);j(F.subject?.trim()??""),G(Array.isArray(F.highlights)?F.highlights:[])}catch(F){ie.error(F instanceof Error?F.message:r("gitView.toast.generateCommitMessageFailed"))}finally{_(!1)}},[o,v,r]),$e=async(z={})=>{if(!o)return;if(!w.trim()){ie.error(r("gitView.toast.enterCommitMessage"));return}const F=v.map(Y=>Y.path).sort();if(F.length===0){ie.error(r("gitView.toast.selectFileToCommit"));return}R(z.pushAfter?"commitAndPush":"commit");try{if(await i.createGitCommit(o,w.trim(),{files:F}),ie.success(r("gitView.toast.commitCreated")),j(""),G([]),z.pushAfter){const Y=a?.tracking?.split("/")[0],Se=ee.find(xe=>xe.name===Y)??ee[0];if(!Se)throw new Error(r("mobile.changes.noRemote"));D("sync");const Me=`${Se.name}/`,qe=a?.tracking?.startsWith(Me)?a.tracking.slice(Me.length):void 0;await i.gitFetch(o,{remote:Se.name}),((await i.getGitStatus(o)).behind??0)>0&&await i.gitPull(o,{remote:Se.name,branch:qe,rebase:!0}),((await i.getGitStatus(o)).ahead??0)>0&&await i.gitPush(o),await le(!1),await ce()}else await le(!1)}catch(Y){ie.error(Y instanceof Error?Y.message:r("gitView.toast.createCommitFailed"))}finally{R(null),z.pushAfter&&D(null)}},st=c.useMemo(()=>{const z=[];return v.length>0&&z.push({id:"staged",title:r("gitView.changes.stagedTitle"),entries:v,actionSymbol:"-",actionAllLabel:r("gitView.changes.unstageAllAria"),getActionLabel:F=>r("gitView.changes.unstageFileAria",{path:F}),onActionFile:F=>{ae([F],"unstage")},onActionAll:F=>{ae(F,"unstage")},onViewDiff:F=>me(F,!0),onRevertFile:ge,showRevertActions:!1,accent:!0}),W.length>0&&z.push({id:"unstaged",title:r("gitView.changes.title"),entries:W,actionSymbol:"+",actionAllLabel:r("gitView.changes.stageAllAria"),getActionLabel:F=>r("gitView.changes.stageFileAria",{path:F}),onActionFile:F=>{ae([F],"stage")},onActionAll:F=>{ae(F,"stage")},onViewDiff:F=>me(F,!1),onRevertFile:ge}),z},[ge,me,ae,v,r,W]),Le=z=>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:z})]});return o?d&&l===null?Le(t.jsx(Ve,{loading:!0,message:r("gitView.loading.checkingRepository")})):l===!1?Le(t.jsx(Ve,{icon:!0,message:r("gitView.empty.notGitRepository"),description:r("gitView.empty.notGitRepositoryDescription")})):y.type==="diff"?t.jsx(Ri,{path:y.path,diff:se,fileExists:!!je,error:V,onBack:()=>P({type:"list"}),onRetry:()=>te(z=>z+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(Go,{syncAction:I,remotes:ee,onFetch:z=>{ke("fetch",z)},onSync:z=>{ke("sync",z)},disabled:A!==null||d,aheadCount:a?.ahead??0,behindCount:a?.behind??0,trackingRemoteName:a?.tracking?.split("/")[0],hasUncommittedChanges:oe.length>0})]}),oe.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(Ho,{groups:st,diffStats:a?.diffStats,revertingPaths:T,onRevertAll:Fe,isRevertingAll:b,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:J})}),t.jsx("div",{className:"shrink-0 border-t border-border/50 px-4 pb-4 pt-3",children:t.jsx(Ko,{stagedCount:v.length,commitMessage:w,onCommitMessageChange:j,generatedHighlights:L,onInsertHighlights:De,onGenerateMessage:pt,isGeneratingMessage:x,onCommit:()=>{$e({pushAfter:!1})},onCommitAndPush:()=>{$e({pushAfter:!0})},commitAction:A,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Ve,{icon:!0,message:r("gitView.empty.cleanTitle"),description:r("mobile.changes.cleanDescription")})})]}):Le(t.jsx(Ve,{message:r("gitView.empty.selectSessionOrDirectory")}))},Ve=s=>{const e=de.c(13),{message:n,description:r,loading:i,icon:o}=s,a=i===void 0?!1:i,l=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]!==l?(u=l?t.jsx(re,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=l,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},Ri=s=>{const e=de.c(24),{path:n,diff:r,fileExists:i,error:o,onBack:a,onRetry:l}=s,{t:d}=ue();let u;e[0]!==n?(u=Vn(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 k;e[8]!==n?(k=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]=k):k=e[9];let S;e[10]!==g||e[11]!==k?(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,k]}),e[10]=g,e[11]=k,e[12]=S):S=e[12];let y;e[13]!==r||e[14]!==o||e[15]!==i||e[16]!==f||e[17]!==l||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(pe,{type:"button",size:"sm",variant:"outline",onClick:l,children:d("diffView.actions.retry")})]})}):r?r.isBinary?t.jsx(Ve,{icon:!0,message:d("diffView.binary.unavailable")}):ot(n)?t.jsx(Ve,{icon:!0,message:d("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(Ze,{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(Ve,{loading:!0,message:d("diffView.state.loadingDiff")}):t.jsx(Ve,{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]=l,e[18]=n,e[19]=d,e[20]=y):y=e[20];let P;return e[21]!==S||e[22]!==y?(P=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]=P):P=e[23],P},Ys=25e4,ct=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),Ge=s=>{const e=ct(s);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},Di=s=>{const e=ct(s);if(!e||e==="/")return null;const n=e.lastIndexOf("/");return n<=0?e.startsWith("/")?"/":null:e.slice(0,n)},Mi=(s,e)=>{const n=ct(s),r=ct(e);return!r||n===r?Ge(n):n.startsWith(`${r}/`)?n.slice(r.length+1):n},_i=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""},zi=s=>s.toLowerCase().endsWith(".svg")?"":zr().authenticatedAsset("/api/fs/raw",{path:s}),Li=s=>/\.(md|mdx|markdown)$/i.test(s),Oi=s=>/\.(json|jsonc)$/i.test(s),Xs=({onClose:s})=>{const{t:e}=ue(),{files:n}=Wt(),r=ct(bs()??null),[i,o]=c.useState(()=>({type:"browser",directory:r})),[a,l]=c.useState([]),[d,u]=c.useState(!1),[f,m]=c.useState(null),[p,g]=c.useState(""),[k,S]=c.useState([]),[y,P]=c.useState(!1),[I,D]=c.useState(""),[A,R]=c.useState(null),[w,j]=c.useState(!1),T=c.useRef(0);c.useEffect(()=>{r&&o(O=>O.type==="browser"&&O.directory?O:{type:"browser",directory:r})},[r]);const E=i.type==="browser"?i.directory:i.returnDirectory,b=c.useCallback(async O=>{if(!O)return;const V=T.current+1;T.current=V,u(!0),m(null);try{const K=await n.listDirectory(O);if(T.current!==V)return;l(K.entries.slice().sort((Z,te)=>Z.isDirectory!==te.isDirectory?Z.isDirectory?-1:1:Z.name.localeCompare(te.name)))}catch(K){if(T.current!==V)return;l([]),m(K instanceof Error?K.message:e("mobile.files.error.listFailed"))}finally{T.current===V&&u(!1)}},[n,e]);c.useEffect(()=>{i.type==="browser"&&b(i.directory)},[b,i]),c.useEffect(()=>{if(i.type!=="browser")return;const O=p.trim();if(!O){S([]),P(!1);return}let V=!1;const K=window.setTimeout(()=>{P(!0),n.search({directory:i.directory,query:O,maxResults:40}).then(Z=>{V||S(Z)}).catch(()=>{V||S([])}).finally(()=>{V||P(!1)})},250);return()=>{V=!0,window.clearTimeout(K)}},[n,p,i]),c.useEffect(()=>{if(i.type!=="file")return;if(D(""),R(null),ot(i.path)&&!i.path.toLowerCase().endsWith(".svg")){j(!1);return}if(!n.readFile){R(e("mobile.files.error.readUnavailable")),j(!1);return}let O=!1;return j(!0),n.readFile(i.path).then(V=>{O||D(V.content.length>Ys?`${V.content.slice(0,Ys)}
6
+
7
+ ${e("mobile.files.file.truncated")}`:V.content)}).catch(V=>{O||R(V instanceof Error?V.message:e("filesView.error.readFileFailed"))}).finally(()=>{O||j(!1)}),()=>{O=!0}},[n,i,e]);const N=O=>{g(""),o({type:"browser",directory:O})},x=O=>{o({type:"file",path:O,returnDirectory:E||r})},_=async O=>{(await Fs(O)).ok?ie.success(e("mobile.files.toast.pathCopied")):ie.error(e("mobile.files.toast.copyFailed"))},L=async()=>{(await Fs(I)).ok?ie.success(e("mobile.files.toast.contentCopied")):ie.error(e("mobile.files.toast.copyFailed"))};if(!r)return t.jsx(dt,{message:e("mobile.files.empty.noDirectory")});if(i.type==="file")return t.jsx(Fi,{path:i.path,content:I,error:A,isLoading:w,onBack:()=>o({type:"browser",directory:i.returnDirectory}),onCopyPath:()=>{_(i.path)},onCopyContent:()=>{L()}});const G=i.directory===r?e("mobile.files.rootDirectory"):Ge(i.directory),M=p.trim()?k:[],J=Di(i.directory),C=i.directory!==r&&J!==null&&(J===r||J.startsWith(`${r}/`)),q=C&&!p.trim(),B=C?J: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(Ct,{className:"size-5"})}):null,q&&B?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:Ge(B)}),onClick:()=>N(B),style:{touchAction:"manipulation"},children:t.jsx(ms,{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:G})}),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:()=>{b(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(jr,{className:X("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(Sn,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ys,{value:p,onChange:O=>g(O.target.value),placeholder:e("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(Ze,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:f?t.jsx(dt,{message:f}):p.trim()?t.jsx(Bi,{results:M,isSearching:y,onOpenFile:x}):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(O=>t.jsx(Zn,{name:O.name,path:O.path,directory:O.isDirectory,meta:O.isDirectory?void 0:_i(O.size),onClick:()=>O.isDirectory?N(O.path):x(O.path)},O.path))]})})]})},Zn=s=>{const e=de.c(16),{name:n,path:r,directory:i,meta:o,onClick:a}=s;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={touchAction:"manipulation"},e[0]=l):l=e[0];let d;e[1]!==i||e[2]!==r?(d=i?t.jsx(Sr,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(Xr,{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(Nr,{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:l,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},Bi=s=>{const e=de.c(10),{results:n,isSearching:r,onOpenFile:i}=s,{t:o}=ue(),a=ct(bs()??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(dt,{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(dt,{message:f}),e[6]=f,e[7]=m):m=e[7],m}const l="overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",d=n.map(f=>t.jsx(Zn,{name:Ge(f.path),path:f.path,directory:!1,meta:Mi(f.path,a),onClick:()=>i(f.path)},f.path));let u;return e[8]!==d?(u=t.jsx("div",{className:l,children:d}),e[8]=d,e[9]=u):u=e[9],u},Fi=s=>{const e=de.c(42),{path:n,content:r,error:i,isLoading:o,onBack:a,onCopyPath:l,onCopyContent:d}=s,{t:u}=ue(),f=ot(n)&&!n.toLowerCase().endsWith(".svg")?n:"",[m,p]=c.useState("");let g,k;e[0]!==f?(g=()=>{if(!f){p("");return}let L=!1;return p(""),Lr(We()).then(G=>{!L&&G&&p(f)}).catch(Ui),()=>{L=!0}},k=[f],e[0]=f,e[1]=g,e[2]=k):(g=e[1],k=e[2]),c.useEffect(g,k);const S=!!(f&&m!==f);let y;e[3]!==S||e[4]!==n?(y=S?"":zi(n),e[3]=S,e[4]=n,e[5]=y):y=e[5];const P=y;let I;e[6]!==u?(I=u("header.actions.backAria"),e[6]=u,e[7]=I):I=e[7];let D;e[8]===Symbol.for("react.memo_cache_sentinel")?(D=t.jsx(ms,{className:"size-5"}),e[8]=D):D=e[8];let A;e[9]!==a||e[10]!==I?(A=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":I,onClick:a,children:D}),e[9]=a,e[10]=I,e[11]=A):A=e[11];let R;e[12]!==n?(R=Ge(n),e[12]=n,e[13]=R):R=e[13];let w;e[14]!==R?(w=t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:R})}),e[14]=R,e[15]=w):w=e[15];let j;e[16]!==d||e[17]!==n||e[18]!==u?(j=ot(n)?null:t.jsx(pe,{type:"button",variant:"ghost",size:"icon",onClick:d,"aria-label":u("mobile.files.copyContentAria"),children:t.jsx(kr,{className:"size-4"})}),e[16]=d,e[17]=n,e[18]=u,e[19]=j):j=e[19];let T;e[20]!==u?(T=u("mobile.files.copyPathAria"),e[20]=u,e[21]=T):T=e[21];let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=t.jsx(Cr,{className:"size-4"}),e[22]=E):E=e[22];let b;e[23]!==l||e[24]!==T?(b=t.jsx(pe,{type:"button",variant:"ghost",size:"icon",onClick:l,"aria-label":T,children:E}),e[23]=l,e[24]=T,e[25]=b):b=e[25];let N;e[26]!==b||e[27]!==A||e[28]!==w||e[29]!==j?(N=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:[A,w,j,b]}),e[26]=b,e[27]=A,e[28]=w,e[29]=j,e[30]=N):N=e[30];let x;e[31]!==r||e[32]!==i||e[33]!==S||e[34]!==P||e[35]!==o||e[36]!==n||e[37]!==u?(x=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:o||S?t.jsx(dt,{loading:!0,message:u("filesView.state.loading")}):i?t.jsx(dt,{message:i}):ot(n)&&P?t.jsx(Ze,{className:"h-full overflow-auto p-4",children:t.jsx("img",{src:P,alt:Ge(n),className:"mx-auto max-h-full max-w-full rounded-lg object-contain"})}):ot(n)?t.jsx(Ze,{className:"h-full overflow-auto p-4",children:t.jsx("img",{src:`data:${Yr(n)};utf8,${encodeURIComponent(r)}`,alt:Ge(n),className:"mx-auto max-h-full max-w-full rounded-lg object-contain"})}):t.jsx($i,{path:n,content:r})}),e[31]=r,e[32]=i,e[33]=S,e[34]=P,e[35]=o,e[36]=n,e[37]=u,e[38]=x):x=e[38];let _;return e[39]!==N||e[40]!==x?(_=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[N,x]}),e[39]=N,e[40]=x,e[41]=_):_=e[41],_},$i=s=>{const e=de.c(32),{path:n,content:r}=s,{currentTheme:i,availableThemes:o,lightThemeId:a,darkThemeId:l}=vs();let d;e[0]!==o||e[1]!==a?(d=o.find(j=>j.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]!==l?(f=o.find(j=>j.metadata.id===l)??$s(!0),e[3]=o,e[4]=l,e[5]=f):f=e[5];const m=f;let p,g;e[6]!==m||e[7]!==u?(p=()=>{Us(u),Us(m)},g=[m,u],e[6]=m,e[7]=u,e[8]=p,e[9]=g):(p=e[8],g=e[9]),c.useEffect(p,g);let k;e[10]!==m.metadata.id||e[11]!==u.metadata.id?(k={light:u.metadata.id,dark:m.metadata.id},e[10]=m.metadata.id,e[11]=u.metadata.id,e[12]=k):k=e[12];const S=k;if(Li(n)){let j;return e[13]!==r?(j=t.jsx(Ze,{className:"h-full overflow-y-auto px-4 py-4",children:t.jsx(Qr,{content:r,enableFileReferences:!1})}),e[13]=r,e[14]=j):j=e[14],j}if(Oi(n)){let j;return e[15]!==r?(j=t.jsx(Zr,{jsonString:r,className:"h-full overflow-auto"}),e[15]=r,e[16]=j):j=e[16],j}let y;e[17]!==n?(y=Ge(n),e[17]=n,e[18]=y):y=e[18];let P;e[19]!==n?(P=Vn(n)||void 0,e[19]=n,e[20]=P):P=e[20];let I;e[21]!==r||e[22]!==y||e[23]!==P?(I={name:y,contents:r,lang:P},e[21]=r,e[22]=y,e[23]=P,e[24]=I):I=e[24];const D=i.metadata.variant==="dark"?"dark":"light";let A;e[25]!==S||e[26]!==D?(A={disableFileHeader:!0,overflow:"wrap",theme:S,themeType:D,unsafeCSS:Jo},e[25]=S,e[26]=D,e[27]=A):A=e[27];let R;e[28]===Symbol.for("react.memo_cache_sentinel")?(R={minHeight:"100%"},e[28]=R):R=e[28];let w;return e[29]!==A||e[30]!==I?(w=t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx(Ze,{className:"min-h-0 flex-1 overflow-auto bg-[var(--syntax-base-background)]",children:t.jsx(Er,{file:I,options:A,className:"block min-h-full w-full",style:R})})}),e[29]=A,e[30]=I,e[31]=w):w=e[31],w},dt=s=>{const e=de.c(7),{message:n,loading:r}=s,i=r===void 0?!1:r;let o;e[0]!==i?(o=i?t.jsx(Pr,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(Ir,{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 l;return e[4]!==o||e[5]!==a?(l=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]=l):l=e[6],l};function Ui(){}const Qs=hs(s=>({expandedParents:{},toggleParent:e=>s(n=>{const r={...n.expandedParents};return r[e]?delete r[e]:r[e]=!0,{expandedParents:r}})})),Dt=hs()(Nn(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"})),er=hs()(Nn(s=>({orderByProject:{},setWorktreeOrder:(e,n)=>s(r=>({orderByProject:{...r.orderByProject,[e]:n}}))}),{name:"mobile-worktree-order"})),Zs=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),Wi=(s,e)=>{if(!s||s.length===0)return e;const n=new Map(s.map((i,o)=>[Zs(i),o])),r=i=>n.get(Zs(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(/\/+$/,""),Vi=s=>{const e=s;return yt(e.directory??e.project?.worktree??null)},Gi=({open:s,project:e,worktree:n,onClose:r,onDeleted:i})=>{const{t:o}=ue(),a=Gn(),l=Ut(E=>E.activeSessions),d=be(E=>E.archiveSessions),u=lt(E=>E.currentDirectory),[f,m]=c.useState(!1),[p,g]=c.useState(!1),[k,S]=c.useState(!1),[y,P]=c.useState(!1),I=yt(n?.path),D=typeof n?.branch=="string"&&n.branch.trim().length>0,A=c.useMemo(()=>{if(!I)return[];const E=new Map;for(const b of[...l,...a])Vi(b)===I&&E.set(b.id,b);return Array.from(E.values())},[l,a,I]);c.useEffect(()=>{if(!s){m(!1),g(!1),S(!1),P(!1);return}if(!n?.path)return;let E=!1;return eo(n.path).then(b=>{E||S(!!b?.isDirty)}).catch(()=>{E||S(!!n.status?.isDirty)}),()=>{E=!0}},[s,n?.path,n?.status?.isDirty]);const R=c.useCallback(E=>{(async()=>{try{await to(e,E,{deleteRemoteBranch:D&&p,deleteLocalBranch:D&&f}),yt(u)===I&&yt(e.path)&&lt.getState().setDirectory(yt(e.path),{showOverlay:!1}),ie.success(o("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:o(D&&p?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),i?.()}catch(b){ie.error(o("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:b instanceof Error?b.message:o("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[u,f,p,D,i,e,o,I]),w=async()=>{if(!(!n||y)){P(!0);try{if(A.length>0){const{archivedIds:E,failedIds:b}=await d(A.map(N=>N.id));if(b.length>0){E.length>0&&ie.success(E.length===1?o("sessions.sidebar.bulkActions.archivedSingle",{count:E.length}):o("sessions.sidebar.bulkActions.archivedPlural",{count:E.length})),ie.error(b.length===1?o("sessions.sidebar.bulkActions.failedArchiveSingle",{count:b.length}):o("sessions.sidebar.bulkActions.failedArchivePlural",{count:b.length}),{description:o("sessions.sidebar.dialogs.deleteResult.tryAgain")}),P(!1);return}}R(n),r()}catch(E){ie.error(o("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:E instanceof Error?E.message:o("sessions.sidebar.dialogs.deleteResult.tryAgain")}),P(!1)}finally{s||P(!1)}}};if(!n)return null;const j=n.branch||n.label||n.path,T=(E,b,N,x)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":E,disabled:x,onClick:()=>b(!E),className:X("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",x&&"pointer-events-none opacity-40"),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:N}),t.jsx("span",{className:X("relative h-6 w-10 shrink-0 rounded-full transition-colors",E?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:X("absolute top-0.5 size-5 rounded-full bg-white transition-transform",E?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx(Hn,{open:s,onClose:r,title:o("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(pe,{variant:"ghost",className:"flex-1",onClick:r,disabled:y,children:o("projectEditDialog.actions.cancel")}),t.jsx(pe,{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:j})}),k?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,A.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o("mobile.projectEdit.deleteWorktreeArchiveNote",{count:A.length})}):null,D?t.jsxs("div",{className:"flex flex-col gap-2",children:[T(f,m,o("mobile.projectEdit.deleteLocalBranch"),y),T(p,g,o("mobile.projectEdit.deleteRemoteBranch"),y)]}):null]})})},en="mobile-surface-root",Hi=90,Qt=16,tn=100,Ki=48,qi=8,Ji=()=>{if(typeof document>"u")return null;let s=document.getElementById(en);return s||(s=document.createElement("div"),s.id=en,document.body.appendChild(s)),s},Ye=({open:s,onClose:e,title:n,subtitle:r,trailing:i,onBack:o,disableSwipeDismiss:a=!1,headerless:l=!1,ariaLabel:d,children:u})=>{const{t:f}=ue(),m=c.useRef(null),[p,g]=c.useState(!1),[k,S]=c.useState(!1),[y,P]=c.useState(!1),[I,D]=c.useState(0),A=c.useRef(null),R=c.useRef(!1),w=c.useRef(null),j=c.useRef(null),T=c.useRef(e);c.useEffect(()=>{T.current=e},[e]),typeof document<"u"&&!m.current&&(m.current=Ji()),c.useEffect(()=>{if(s){g(!0);const G=window.setTimeout(()=>S(!0),Qt);return()=>window.clearTimeout(G)}S(!1);const L=window.setTimeout(()=>g(!1),300);return()=>window.clearTimeout(L)},[s]),c.useEffect(()=>{if(!s){P(!1);return}const L=window.setTimeout(()=>P(!0),Qt+tn+80);return()=>window.clearTimeout(L)},[s]),c.useEffect(()=>{if(!s)return;const L=document.body.style.overflow;j.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const G=()=>{const C=w.current;if(!C)return;(C.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??C).focus({preventScroll:!0})},M=window.setTimeout(G,Qt),J=C=>{if(C.key==="Escape"){T.current();return}if(C.key!=="Tab")return;const q=w.current;if(!q)return;const B=Array.from(q.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(Z=>!Z.hasAttribute("disabled")&&Z.getAttribute("aria-hidden")!=="true");if(B.length===0){C.preventDefault(),q.focus({preventScroll:!0});return}const O=B[0],V=B[B.length-1],K=document.activeElement;C.shiftKey&&K===O?(C.preventDefault(),V.focus({preventScroll:!0})):!C.shiftKey&&K===V&&(C.preventDefault(),O.focus({preventScroll:!0}))};return document.addEventListener("keydown",J),()=>{window.clearTimeout(M),document.body.style.overflow=L,document.removeEventListener("keydown",J),j.current?.focus?.({preventScroll:!0}),j.current=null}},[s]);const E=L=>{a||(A.current=L.touches[0]?.clientY??null,R.current=!0)},b=L=>{if(!R.current||A.current==null)return;const M=(L.touches[0]?.clientY??A.current)-A.current;D(M>0?M:0)},N=()=>{R.current&&(R.current=!1,A.current=null,I>=Hi?(D(0),e()):D(0))};if(!p||!m.current)return null;const x=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":f("header.actions.backAria"),onClick:o,style:{touchAction:"manipulation"},children:t.jsx(ms,{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":f("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(Ct,{className:"size-5"})}),_=k?I>0?`translateY(${I}px)`:"none":`translateY(${Ki}px)`;return Tr.createPortal(t.jsxs("div",{className:X("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",k?"opacity-100":"opacity-0"),role:"dialog","aria-modal":"true","aria-label":d,onClick:e,children:[t.jsxs("section",{ref:w,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:L=>L.stopPropagation(),onTransitionEnd:L=>{k&&L.target===L.currentTarget&&L.propertyName==="transform"&&P(!0)},style:{height:`calc(100% - var(--oc-safe-area-top, 0px) - ${qi}px)`,transform:_,transition:R.current?"none":`transform ${tn}ms cubic-bezier(0.32, 0.72, 0, 1)`},children:[t.jsxs("div",{className:"shrink-0 select-none",onTouchStart:E,onTouchMove:b,onTouchEnd:N,onTouchCancel:N,children:[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})}),l?null:t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] items-center gap-2 px-3",children:[x,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:y?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:u}):null})]}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]}),m.current)},Yi=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/,""),Xi=s=>{const e=de.c(36),{worktree:n,onDelete:r}=s,{t:i}=ue();let o;e[0]!==n.path?(o={id:n.path},e[0]=n.path,e[1]=o):o=e[1];const{attributes:a,listeners:l,setNodeRef:d,transform:u,transition:f,isDragging:m}=_n(o);let p;e[2]!==u?(p=zn.Transform.toString(u),e[2]=u,e[3]=p):p=e[3];const g=m?10:1;let k;e[4]!==p||e[5]!==g||e[6]!==f?(k={transform:p,transition:f,zIndex:g},e[4]=p,e[5]=g,e[6]=f,e[7]=k):k=e[7];const S=k,y=n.branch||n.label||n.path,P=m&&"shadow-lg shadow-black/20";let I;e[8]!==P?(I=X("flex items-center gap-1 rounded-2xl border border-border/40 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",P),e[8]=P,e[9]=I):I=e[9];let D;e[10]!==y||e[11]!==i?(D=i("mobile.projectEdit.dragWorktreeAria",{label:y}),e[10]=y,e[11]=i,e[12]=D):D=e[12];let A;e[13]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx(Ln,{className:"size-4"}),e[13]=A):A=e[13];let R;e[14]!==a||e[15]!==l||e[16]!==D?(R=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":D,...a,...l,children:A}),e[14]=a,e[15]=l,e[16]=D,e[17]=R):R=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 j;e[19]!==y?(j=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:y}),e[19]=y,e[20]=j):j=e[20];let T;e[21]!==y||e[22]!==i?(T=i("mobile.projectEdit.deleteWorktreeAria",{label:y}),e[21]=y,e[22]=i,e[23]=T):T=e[23];let E,b;e[24]===Symbol.for("react.memo_cache_sentinel")?(E={touchAction:"manipulation"},b=t.jsx(is,{className:"size-4"}),e[24]=E,e[25]=b):(E=e[24],b=e[25]);let N;e[26]!==r||e[27]!==T?(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":T,onClick:r,style:E,children:b}),e[26]=r,e[27]=T,e[28]=N):N=e[28];let x;return e[29]!==d||e[30]!==S||e[31]!==j||e[32]!==N||e[33]!==I||e[34]!==R?(x=t.jsxs("div",{ref:d,style:S,className:I,children:[R,w,j,N]}),e[29]=d,e[30]=S,e[31]=j,e[32]=N,e[33]=I,e[34]=R,e[35]=x):x=e[35],x},Qi=({open:s,project:e,onClose:n,onWorktreesChanged:r})=>{const{t:i}=ue(),{currentTheme:o}=vs(),a=Te(M=>M.updateProjectMeta),l=Te(M=>M.discoverProjectIcon),d=Te(M=>M.removeProjectIcon),u=er(M=>M.setWorktreeOrder),f=Te(M=>e?M.projects.find(J=>J.id===e.id)?.iconImage??null:null),[m,p]=c.useState(""),[g,k]=c.useState(null),[S,y]=c.useState(null),[P,I]=c.useState(!1),[D,A]=c.useState([]),[R,w]=c.useState(null),j=e?.id??null;c.useEffect(()=>{!s||!e||(p(e.label),k(e.icon??null),y(e.color??null),A(e.worktrees))},[s,j]),c.useEffect(()=>{!s||!e||A(M=>{const J=e.worktrees.map(B=>B.path),C=M.map(B=>B.path);return J.length===C.length&&J.every(B=>C.includes(B))?M:e.worktrees})},[e?.worktrees]);const T=Cn(zt(In,{activationConstraint:{distance:8}}),zt(Pn,{coordinateGetter:En})),E=()=>{if(!e)return;const M=m.trim();a(e.id,{label:M||e.label,icon:g,color:S}),n()},b=()=>{!e||P||(I(!0),l(e.id).then(M=>{if(!M.ok){ie.error(M.error||i("projectEditDialog.toast.failedToDiscoverIcon"));return}if(M.skipped){ie.success(i("projectEditDialog.toast.customIconAlreadySet"));return}ie.success(i("projectEditDialog.toast.iconDiscovered"))}).finally(()=>I(!1)))},N=()=>{e&&d(e.id).then(M=>{if(!M.ok){ie.error(M.error||i("projectEditDialog.toast.failedToRemoveIcon"));return}ie.success(i("projectEditDialog.toast.iconRemoved"))})},x=M=>{const{active:J,over:C}=M;if(!C||J.id===C.id||!e)return;const q=D.findIndex(K=>K.path===J.id),B=D.findIndex(K=>K.path===C.id);if(q<0||B<0)return;const O=[...D],[V]=O.splice(q,1);O.splice(B,0,V),A(O),u(e.id,O.map(K=>Yi(K.path)))},_=S?Kn[S]??null:null,L=g?qn[g]:null,G=!!f;return t.jsxs(t.Fragment,{children:[t.jsx(Ye,{open:s,onClose:n,onBack:n,title:i("projectEditDialog.title"),ariaLabel:i("projectEditDialog.title"),trailing:t.jsxs(pe,{type:"button",variant:"default",size:"sm","aria-label":i("projectEditDialog.actions.save"),onClick:E,disabled:!m.trim(),style:{touchAction:"manipulation"},children:[t.jsx(Mn,{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:G?t.jsx(Jn,{project:{id:e.id,iconImage:f},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(os,{className:"size-7"})}):L?t.jsx(re,{name:L,className:"size-7",style:_?{color:_}:void 0}):t.jsx(os,{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(ys,{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:X("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"})}),so.map(M=>t.jsx("button",{type:"button",onClick:()=>y(M.key),"aria-label":M.label,title:M.label,className:X("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:()=>k(null),"aria-label":i("projectEditDialog.option.none"),className:X("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"})}),no.map(M=>t.jsx("button",{type:"button",onClick:()=>k(M.key),"aria-label":M.label,title:M.label,className:X("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(pe,{size:"sm",variant:"outline",onClick:b,disabled:P,children:i(P?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),G?t.jsx(pe,{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")}),D.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(Tn,{sensors:T,collisionDetection:An,onDragEnd:x,children:t.jsx(Rn,{items:D.map(M=>M.path),strategy:Dn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:D.map(M=>t.jsx(Xi,{worktree:M,onDelete:()=>w(M)},M.path))})})})]})]}):null]}):null}),e?t.jsx(Gi,{open:!!R,project:{id:e.id,path:e.path},worktree:R,onClose:()=>w(null),onDeleted:()=>{A(M=>M.filter(J=>J.path!==R?.path)),r?.()}}):null]})},Zt=7,Zi=36,ea=52,ta=18,Mt=s=>s.parentID??null,Pe=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),rt=s=>{const e=s;return Pe(e.directory??e.project?.worktree??null)},es=s=>{const e=Pe(s);if(!e)return"";const n=e.split("/").filter(Boolean);return n[n.length-1]?.replace(/[-_]/g," ")||e},vt=s=>{const e=s.time?.updated??s.time?.created,n=typeof e=="number"?e:Number(e);return Number.isFinite(n)&&n>0?n:0},sa=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))},na=(s,e)=>{const n=Pe(s),r=Pe(e);return!!(n&&r&&(n===r||n.startsWith(`${r}/`)))},as=(s,e)=>s.worktrees.find(n=>Pe(n.path)===e)??null,ls=(s,e)=>e===s.path||!!as(s,e),ts=(s,e)=>{const n=Pe(e);return n?s.find(r=>ls(r,n))??null:null},ss=(s,e,n)=>n?`${s.title??""} ${s.id} ${rt(s)} ${e}`.toLowerCase().includes(n):!0,cs=s=>{const e=de.c(17),{project:n,size:r}=s,i=r===void 0?"md":r,{currentTheme:o}=vs(),a=n.icon?qn[n.icon]:null,l=n.color?Kn[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]!==l||e[2]!==u?(f=a?t.jsx(re,{name:a,className:u,style:l?{color:l}:void 0}):t.jsx(os,{className:u,style:l?{color:l}:void 0}),e[0]=a,e[1]=l,e[2]=u,e[3]=f):f=e[3];const m=f;let p;e[4]!==d?(p=X("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 k;e[8]!==o||e[9]!==m||e[10]!==n.iconImage||e[11]!==n.id?(k=n.iconImage?t.jsx(Jn,{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]=k):k=e[12];let S;return e[13]!==p||e[14]!==g||e[15]!==k?(S=t.jsx("span",{className:p,style:g,children:k}),e[13]=p,e[14]=g,e[15]=k,e[16]=S):S=e[16],S},ra=s=>{const e=de.c(5),{expanded:n}=s,r=n?"rotate-0":"-rotate-90";let i;e[0]!==r?(i=X("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(ps,{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},sn=s=>{const e=de.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},nn=s=>{const e=de.c(12),{onClick:n,className:r}=s,{t:i}=ue();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 l;e[2]!==r?(l=X("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]=l):l=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]!==l||e[10]!==d?(m=t.jsx("button",{type:"button",className:l,"aria-label":a,title:a,onClick:d,style:u,children:f}),e[8]=a,e[9]=l,e[10]=d,e[11]=m):m=e[11],m},rn=s=>{const e=de.c(55),{session:n,active:r,indent:i,contextLabel:o,confirmingArchive:a,hasChildren:l,expanded:d,onToggleChildren:u,onSelect:f,onRequestArchive:m,onConfirmArchive:p}=s,g=a===void 0?!1:a,k=l===void 0?!1:l,S=d===void 0?!1:d,{t:y}=ue();let P;e[0]!==n?(P=sa(vt(n)),e[0]=n,e[1]=P):P=e[1];const I=P;let D;e[2]!==n.title||e[3]!==y?(D=n.title?.trim()||y("mobile.sessions.untitled"),e[2]=n.title,e[3]=y,e[4]=D):D=e[4];const A=D,R=r&&!g&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]",w=g&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]";let j;e[5]!==R||e[6]!==w?(j=X("relative flex items-center gap-1 transition-colors",R,w),e[5]=R,e[6]=w,e[7]=j):j=e[7];let T;e[8]!==S||e[9]!==k||e[10]!==i||e[11]!==u||e[12]!==y?(T=k&&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:te=>{te.stopPropagation(),u()},children:t.jsx(ps,{className:X("size-[18px] transition-transform duration-150",S?"rotate-0":"-rotate-90")})}):null,e[8]=S,e[9]=k,e[10]=i,e[11]=u,e[12]=y,e[13]=T):T=e[13];const E=g&&"opacity-50";let b;e[14]!==E?(b=X("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]=b):b=e[15];let N;e[16]!==i?(N={paddingLeft:i,touchAction:"manipulation"},e[16]=i,e[17]=N):N=e[17];const x=r?"bg-primary":"bg-muted-foreground/30";let _;e[18]!==x?(_=X("size-1.5 shrink-0 rounded-full",x),e[18]=x,e[19]=_):_=e[19];let L;e[20]!==_?(L=t.jsx("span",{className:_,"aria-hidden":!0}),e[20]=_,e[21]=L):L=e[21];const G=r?"text-primary":"text-foreground";let M;e[22]!==G?(M=X("block min-w-0 flex-1 truncate typography-ui-label",G),e[22]=G,e[23]=M):M=e[23];let J;e[24]!==M||e[25]!==A?(J=t.jsx("span",{className:M,children:A}),e[24]=M,e[25]=A,e[26]=J):J=e[26];let C;e[27]!==I?(C=I?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:I}):null,e[27]=I,e[28]=C):C=e[28];let q;e[29]!==L||e[30]!==J||e[31]!==C?(q=t.jsxs("span",{className:"flex items-center gap-2.5",children:[L,J,C]}),e[29]=L,e[30]=J,e[31]=C,e[32]=q):q=e[32];let B;e[33]!==o?(B=o?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground pl-4",children:o}):null,e[33]=o,e[34]=B):B=e[34];let O;e[35]!==q||e[36]!==B?(O=t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[q,B]}),e[35]=q,e[36]=B,e[37]=O):O=e[37];let V;e[38]!==g||e[39]!==f||e[40]!==b||e[41]!==N||e[42]!==O?(V=t.jsx("button",{type:"button",className:b,style:N,onClick:f,disabled:g,children:O}),e[38]=g,e[39]=f,e[40]=b,e[41]=N,e[42]=O,e[43]=V):V=e[43];let K;e[44]!==g||e[45]!==p||e[46]!==m||e[47]!==y||e[48]!==A?(K=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:A}),onClick:p,style:{touchAction:"manipulation"},children:[t.jsx(_s,{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:A}):y("mobile.sessions.archiveSessionAria",{title:A}),onClick:m,style:{touchAction:"manipulation"},children:g?t.jsx(Ct,{className:"size-4"}):t.jsx(_s,{className:"size-4"})})]}):null,e[44]=g,e[45]=p,e[46]=m,e[47]=y,e[48]=A,e[49]=K):K=e[49];let Z;return e[50]!==V||e[51]!==K||e[52]!==j||e[53]!==T?(Z=t.jsxs("div",{className:j,children:[T,V,K]}),e[50]=V,e[51]=K,e[52]=j,e[53]=T,e[54]=Z):Z=e[54],Z},oa=s=>{const e=de.c(11),{indent:n,onClick:r}=s,{t:i}=ue();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(ps,{className:"size-4"}),e[2]=a):a=e[2];let l;e[3]!==i?(l=i("sessions.sidebar.group.showMore"),e[3]=i,e[4]=l):l=e[4];let d;e[5]!==l?(d=t.jsx("span",{className:"typography-micro",children:l}),e[5]=l,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},ia=s=>{const e=de.c(11),{indent:n,onClick:r}=s,{t:i}=ue();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(Rr,{className:"size-4"}),e[2]=a):a=e[2];let l;e[3]!==i?(l=i("sessions.sidebar.group.showFewer"),e[3]=i,e[4]=l):l=e[4];let d;e[5]!==l?(d=t.jsx("span",{className:"typography-micro",children:l}),e[5]=l,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},aa=s=>{const e=de.c(53),{project:n,totalSessions:r,confirmingDelete:i,onEdit:o,onRequestRemove:a,onConfirmRemove:l}=s,{t:d}=ue();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:k,isDragging:S}=_n(u);let y;e[2]!==g?(y=zn.Transform.toString(g),e[2]=g,e[3]=y):y=e[3];const P=S?10:1;let I;e[4]!==y||e[5]!==P||e[6]!==k?(I={transform:y,transition:k,zIndex:P},e[4]=y,e[5]=P,e[6]=k,e[7]=I):I=e[7];const D=I,A=S&&"shadow-lg shadow-black/20",R=i&&"border-destructive/50 bg-[color-mix(in_srgb,var(--destructive)_8%,var(--surface-elevated))]";let w;e[8]!==A||e[9]!==R?(w=X("flex items-center gap-1 rounded-2xl border border-border/40 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",A,R),e[8]=A,e[9]=R,e[10]=w):w=e[10];let j;e[11]!==n.label||e[12]!==d?(j=d("mobile.sessions.dragHandleAria",{label:n.label}),e[11]=n.label,e[12]=d,e[13]=j):j=e[13];let T;e[14]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(Ln,{className:"size-4"}),e[14]=T):T=e[14];let E;e[15]!==f||e[16]!==m||e[17]!==j?(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":j,...f,...m,children:T}),e[15]=f,e[16]=m,e[17]=j,e[18]=E):E=e[18];let b;e[19]!==n?(b=t.jsx(cs,{project:n}),e[19]=n,e[20]=b):b=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 x;e[23]!==i||e[24]!==l||e[25]!==o||e[26]!==n.label||e[27]!==d||e[28]!==r?(x=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:l,style:{touchAction:"manipulation"},children:[t.jsx(is,{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(On,{className:"size-4"})})]}),e[23]=i,e[24]=l,e[25]=o,e[26]=n.label,e[27]=d,e[28]=r,e[29]=x):x=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 L;e[30]!==_?(L=X("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]=L):L=e[31];let G;e[32]!==i||e[33]!==n.label||e[34]!==d?(G=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]=G):G=e[35];let M;e[36]===Symbol.for("react.memo_cache_sentinel")?(M={touchAction:"manipulation"},e[36]=M):M=e[36];let J;e[37]!==i?(J=i?t.jsx(Ct,{className:"size-4"}):t.jsx(is,{className:"size-4"}),e[37]=i,e[38]=J):J=e[38];let C;e[39]!==a||e[40]!==L||e[41]!==G||e[42]!==J?(C=t.jsx("button",{type:"button",className:L,"aria-label":G,onClick:a,style:M,children:J}),e[39]=a,e[40]=L,e[41]=G,e[42]=J,e[43]=C):C=e[43];let q;return e[44]!==p||e[45]!==D||e[46]!==E||e[47]!==b||e[48]!==N||e[49]!==x||e[50]!==C||e[51]!==w?(q=t.jsxs("div",{ref:p,style:D,className:w,children:[E,b,N,x,C]}),e[44]=p,e[45]=D,e[46]=E,e[47]=b,e[48]=N,e[49]=x,e[50]=C,e[51]=w,e[52]=q):q=e[52],q},on=({open:s,onOpenChange:e,variant:n="sheet"})=>{const{t:r}=ue(),{git:i}=Wt(),o=Gn(),a=Ut(h=>h.activeSessions),l=Te(h=>h.projects),d=Te(h=>h.activeProjectId),u=lt(h=>h.currentDirectory),f=be(h=>h.currentSessionId),m=be(h=>h.setCurrentSession),p=be(h=>h.archiveSession),g=be(h=>h.openNewSessionDraft),k=Te(h=>h.setActiveProject),S=Te(h=>h.setActiveProjectIdOnly),y=Te(h=>h.reorderProjects),P=Te(h=>h.removeProject),I=Dt(h=>h.projectExpanded),D=Dt(h=>h.worktreeExpanded),A=Dt(h=>h.setProjectExpanded),R=Dt(h=>h.setWorktreeExpanded),w=er(h=>h.orderByProject),j=Qs(h=>h.expandedParents),T=Qs(h=>h.toggleParent),[E,b]=c.useState(""),[N,x]=c.useState(null),[_,L]=c.useState(null),[G,M]=c.useState(0),[J,C]=c.useState(!1),[q,B]=c.useState(!1),[O,V]=c.useState(null),[K,Z]=c.useState(new Map),[te,oe]=c.useState(new Set),[v,W]=c.useState(!1),[ee,se]=c.useState(null),[je,le]=c.useState(new Map);c.useEffect(()=>{if(!s){b(""),W(!1),se(null),le(new Map),x(null),L(null);return}ro(o)},[s]),c.useEffect(()=>{v||se(null)},[v]),c.useEffect(()=>{if(!s||l.length===0)return;let h=!1;return(async()=>{const H=await Promise.all(l.map(async ne=>{const ye=Pe(ne.path);if(!ye)return null;const he=await i.checkIsGitRepository(ye).catch(()=>!1),Ee=he?await Yn({id:ne.id,path:ye}).catch(()=>[]):[];return[ye,Ee,he]}));if(h)return;const Q=new Map,fe=new Set;for(const ne of H)ne&&(Q.set(ne[0],ne[1]),ne[2]&&fe.add(ne[0]));Z(Q),oe(fe)})(),()=>{h=!0}},[i,s,l,G]);const ce=c.useMemo(()=>l.map(h=>({id:h.id,label:h.label?.trim()||es(h.path),path:Pe(h.path),icon:h.icon,color:h.color,iconImage:h.iconImage,iconBackground:h.iconBackground,isGitRepo:te.has(Pe(h.path)),worktrees:Wi(w[h.id],K.get(Pe(h.path))??[])})),[te,l,w,K]),ke=c.useMemo(()=>{const h=new Map(o.map(Q=>[Q.id,Q])),U=a.map(Q=>{const fe=h.get(Q.id);return fe?oo(fe,Q):Q}),H=new Set(U.map(Q=>Q.id));for(const Q of o)H.has(Q.id)||U.push(Q);return U},[a,o]),ae=E.trim().toLowerCase(),me=c.useMemo(()=>{const h=ce.map(H=>({project:H,buckets:[],totalSessions:0,isActive:H.id===d})),U=(H,Q,fe)=>{const ne=Pe(Q)||H.project.path,ye=ne||"__root__";let he=H.buckets.find(Ee=>Ee.key===ye);return he||(he={key:ye,label:fe?.branch||es(ne),path:ne,worktree:fe,sessions:[]},H.buckets.push(he)),he};for(const H of h){U(H,H.project.path,null);for(const Q of H.project.worktrees)U(H,Q.path,Q)}for(const H of ke){const Q=rt(H);if(!Q)continue;const fe=Pe(Q),ne=h.find(Ee=>ls(Ee.project,fe));if(!ne)continue;const ye=as(ne.project,fe);(ye?U(ne,ye.path,ye):U(ne,ne.project.path,null)).sessions.push(H)}for(const H of h)for(const Q of H.buckets){Q.sessions.sort((fe,ne)=>vt(ne)-vt(fe));for(const fe of Q.sessions)Mt(fe)||(H.totalSessions+=1)}return h},[d,ce,ke]),ge=Pe(u),Fe=h=>h.isActive?ge===h.project.path?h.project.path:h.project.worktrees.find(H=>na(ge,H.path))?.path??h.project.path:null,De=h=>I[h.project.id]??!0,pt=(h,U)=>D[`${h.project.id}::${U.key}`]??!1,$e=h=>{le(U=>{if(!U.has(h))return U;const H=new Map(U);return H.delete(h),H})},st=h=>{le(U=>{let H=!1;const Q=new Map(U),fe=`${h}::`;for(const ne of Q.keys())ne.startsWith(fe)&&(Q.delete(ne),H=!0);return H?Q:U})},Le=(h,U)=>{le(H=>{const Q=new Map(H);return Q.set(h,U+Zt),Q})},z=(h,U,H)=>{const Q=`${h.project.id}::${U.key}`,fe=new Set(U.sessions.map(ve=>ve.id)),ne=new Map;for(const ve of U.sessions){const _e=Mt(ve);if(_e&&fe.has(_e)){const gt=ne.get(_e)??[];gt.push(ve),ne.set(_e,gt)}}const ye=U.sessions.filter(ve=>{const _e=Mt(ve);return!_e||!fe.has(_e)}),he=je.get(Q)??Zt,Ee=ye.slice(0,he),nt=ye.length-Ee.length,vr=ye.length>Zt&&nt===0,Rs=(ve,_e)=>{const gt=ne.get(ve.id)??[],Yt=gt.length>0,Ds=!!j[ve.id];return t.jsxs(c.Fragment,{children:[t.jsx(rn,{session:ve,active:f===ve.id,indent:_e,hasChildren:Yt,expanded:Ds,onToggleChildren:Yt?()=>T(ve.id):void 0,confirmingArchive:_===ve.id,onSelect:()=>Se(ve),onRequestArchive:()=>Me(ve.id),onConfirmArchive:()=>{qe(ve)}}),Yt&&Ds?gt.map(wr=>Rs(wr,_e+ta)):null]},ve.id)};return t.jsxs("div",{children:[Ee.map(ve=>Rs(ve,H)),nt>0?t.jsx(oa,{indent:H,onClick:()=>Le(Q,Ee.length)}):null,vr?t.jsx(ia,{indent:H,onClick:()=>$e(Q)}):null]})},F=(h,U)=>{A(h,!U),st(h)},Y=(h,U,H)=>{R(`${h}::${U}`,!H),$e(`${h}::${U}`)},Se=h=>{const U=rt(h)||null,H=ts(ce,U??"");H&&S(H.id),m(h.id,U),e(!1)},Me=h=>{L(U=>U===h?null:h)},qe=async h=>{L(null),await p(h.id)?ie.success(r("sessions.sidebar.session.archive.success")):ie.error(r("sessions.sidebar.session.archive.error"))},Pt=()=>{g(),e(!1)},$=h=>{V(h),S(h),B(!0)},xe=Cn(zt(In,{activationConstraint:{distance:8}}),zt(Pn,{coordinateGetter:En})),Ue=h=>{const{active:U,over:H}=h;if(se(null),!H||U.id===H.id)return;const Q=ce.findIndex(ne=>ne.id===U.id),fe=ce.findIndex(ne=>ne.id===H.id);Q<0||fe<0||y(Q,fe)},It=h=>{se(U=>U===h?null:h)},qt=h=>{P(h.id),se(null),ie.success(r("mobile.sessions.toast.projectRemoved",{label:h.label}))},gr=c.useCallback(h=>{const U=rt(h),H=ts(ce,U);if(!H)return es(U)||U;const Q=as(H,Pe(U));return Q?.branch?`${H.label} · ${Q.branch}`:H.label},[ce]),br=h=>{k(h.id),e(!1)},xr=c.useMemo(()=>ae?me.filter(h=>`${h.project.label} ${h.project.path}`.toLowerCase().includes(ae)?!0:h.buckets.some(U=>U.sessions.some(H=>ss(H,h.project.label,ae)))):me,[ae,me]),Tt=c.useMemo(()=>ae?ke.filter(h=>{const U=rt(h),H=ts(ce,U);return ss(h,H?.label??"",ae)}).sort((h,U)=>vt(U)-vt(h)):[],[ae,ce,ke]),At=c.useMemo(()=>ae?ce.filter(h=>`${h.label} ${h.path}`.toLowerCase().includes(ae)).map(h=>({...h,sessionCount:ke.filter(U=>{if(Mt(U))return!1;const H=Pe(rt(U));return ls(h,H)}).length})):[],[ae,ce,ke]),yr=ae&&Tt.length===0&&At.length===0,Ps=!ae&&ce.length>1?t.jsx(pe,{type:"button",variant:"chip",size:"sm","aria-label":r(v?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":v,onClick:()=>W(h=>!h),style:{touchAction:"manipulation"},children:v?t.jsx(Mn,{className:"size-4"}):t.jsx(On,{className:"size-4"})}):null,Is=!v&&ce.length>0?t.jsxs(pe,{type:"button",variant:"default",size:"sm","aria-label":r("mobile.sessions.newChat"),onClick:Pt,style:{touchAction:"manipulation"},children:[t.jsx(Ar,{className:"size-4"}),r("mobile.sessions.newChat")]}):null,Ts=v?null:t.jsx(pe,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.addProject"),title:r("sessions.sidebar.header.actions.addProject"),onClick:()=>C(!0),style:{touchAction:"manipulation"},children:t.jsx(Ms,{className:"size-4"})}),Jt=Is||Ts||Ps?t.jsxs(t.Fragment,{children:[Is,Ts,Ps]}):null,As=t.jsxs("div",{className:"flex h-full flex-col",children:[t.jsx("div",{className:X("shrink-0 px-4 pb-2 pt-1",v&&"hidden"),children:t.jsxs("div",{className:"relative",children:[t.jsx(Sn,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ys,{value:E,onChange:h=>b(h.target.value),placeholder:r("mobile.sessions.search.placeholder"),className:X("h-11 pl-9",E&&"pr-10")}),E?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:()=>b(""),style:{touchAction:"manipulation"},children:t.jsx(Ct,{className:"size-4"})}):null]})}),t.jsx(Ze,{className:"min-h-0 flex-1 overflow-y-auto pb-4",children:ce.length===0?t.jsx(an,{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:()=>C(!0),children:[t.jsx(Ms,{className:"size-4"}),r("sessions.sidebar.header.actions.addProject")]})}):yr?t.jsx(an,{title:r("mobile.sessions.empty.searchTitle"),description:r("mobile.sessions.empty.searchDescription")}):ae&&!v?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[Tt.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:Tt.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",children:Tt.map((h,U)=>t.jsx("div",{className:X(U>0&&"border-t border-border/30"),children:t.jsx(rn,{session:h,active:f===h.id,indent:12,contextLabel:gr(h),onSelect:()=>Se(h)})},h.id))})]}):null,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.projects")}),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,U)=>t.jsxs("div",{className:X("flex items-center",U>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:()=>br(h),style:{touchAction:"manipulation"},children:[t.jsx(cs,{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(nn,{className:"mr-2",onClick:()=>$(h.id)}):null]},h.id))})]}):null]}):v?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(Tn,{sensors:xe,collisionDetection:An,onDragEnd:Ue,children:t.jsx(Rn,{items:ce.map(h=>h.id),strategy:Dn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:ce.map(h=>{const U=me.find(H=>H.project.id===h.id);return t.jsx(aa,{project:h,totalSessions:U?.totalSessions??0,confirmingDelete:ee===h.id,onEdit:()=>x(h.id),onRequestRemove:()=>It(h.id),onConfirmRemove:()=>qt(h)},h.id)})})})})]}):t.jsx("div",{className:"flex flex-col",children:xr.map((h,U)=>{const H=De(h),Q=ae?h.buckets.filter(ne=>ne.sessions.some(ye=>ss(ye,h.project.label,ae))):h.buckets,fe=Fe(h);return t.jsxs("section",{className:X(U>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:()=>F(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(cs,{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(sn,{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(nn,{className:"mr-2",onClick:()=>$(h.project.id)}):null]}),H?t.jsx("div",{className:"pb-2",children:(()=>{const ne=Q.find(he=>he.worktree===null),ye=Q.filter(he=>he.worktree!==null);return t.jsxs(t.Fragment,{children:[ne&&ne.sessions.length>0?z(h,ne,Zi):null,ye.map(he=>{const Ee=pt(h,he),nt=fe===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:()=>Y(h.project.id,he.key,Ee),"aria-expanded":Ee,"aria-label":Ee?r("sessions.sidebar.group.collapseAria",{label:he.label}):r("sessions.sidebar.group.expandAria",{label:he.label}),style:{touchAction:"manipulation"},children:[t.jsx(ra,{expanded:Ee}),t.jsx(re,{name:"node-tree",className:X("size-4 shrink-0",nt?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:X("block min-w-0 flex-1 truncate typography-ui-label font-semibold",nt?"text-foreground":"text-foreground/90"),children:he.label}),nt?t.jsx(sn,{ariaLabel:r("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:he.sessions.length})]}),Ee?z(h,he,ea):null]},he.key)})]})})()}):null]},h.project.id)})})}),t.jsx(Yo,{open:J,onOpenChange:C}),t.jsx(Xo,{open:q,onOpenChange:h=>{B(h),h||V(null)},onWorktreeCreated:(h,U)=>{U?.sessionId?m(U.sessionId,h):g({selectedProjectId:O,directoryOverride:h,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(Qi,{open:N!==null,project:ce.find(h=>h.id===N)??null,onClose:()=>x(null),onWorktreesChanged:()=>M(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")}),Jt?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Jt}):null]}),As]}):null:t.jsx(Ye,{open:s,onClose:()=>e(!1),ariaLabel:r("mobile.sessions.sheet.title"),title:r("mobile.sessions.sheet.title"),trailing:Jt,children:As})},an=s=>{const e=de.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 l;e[4]!==i?(l=i?t.jsx("div",{className:"pt-2",children:i}):null,e[4]=i,e[5]=l):l=e[5];let d;return e[6]!==o||e[7]!==a||e[8]!==l?(d=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[o,a,l]}),e[6]=o,e[7]=a,e[8]=l,e[9]=d):d=e[9],d},ws="openchamber.mobile.connections.v1",la="openchamber.mobile.",ln="openchamber.mobile.deviceId",ca=()=>{try{const s=window.localStorage.getItem(ln);if(s&&s.trim())return s.trim();const e=crypto.randomUUID();return window.localStorage.setItem(ln,e),e}catch{return crypto.randomUUID()}},cn=()=>`mobile:${ca()}`,dn=()=>{try{const s=Mr.getPlatform();return s==="ios"||s==="android"?s:void 0}catch{return}},tr=12,da=8e3,ua=2500,fa=3e3,Lt=2500,ht=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(/\/+$/,"")},_t=s=>{try{return new URL(s).host}catch{return s}},ut=s=>{try{return ht(s)}catch{return s.trim().replace(/\/+$/g,"")}},sr=(s,e)=>ut(s)===ut(e),nr=s=>`relay:${s.serverId}@${s.relayUrl.trim()}`,ma=s=>`relay://${s.serverId}`,Vt=s=>s.candidates.filter(e=>e.kind==="direct"),et=s=>{const e=s.candidates.find(n=>n.kind==="relay");return e&&e.kind==="relay"?e.relay:null},Be=s=>{const e=Vt(s)[0];if(e)return e.url;const n=et(s);return n?ma(n):""},we=s=>{const e=et(s);if(e)return nr(e);const n=Vt(s)[0];return n?ut(n.url):""},Ot=(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=>ut(o.url)));return e.some(o=>o.kind==="relay"?r!==null&&o.relay.serverId===r:i.has(ut(o.url)))},js=s=>{const e=(()=>{try{return ht(s)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},un=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(...js(s.url)),s.relay&&e.push({kind:"relay",relay:s.relay}),e},ks=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}}},Gt=s=>{try{return JSON.stringify(s)}catch{return String(s)}},Ce=(s,e={})=>{console.info("[mobile-connect]",s,Gt(e))},ft=(s,e={})=>{console.info("[mobile-storage]",s,Gt(e))},ha=s=>{if(typeof s!="string")return s;try{return JSON.parse(s)}catch{return s}},pa=s=>{if(typeof s!="string")return s??void 0;try{return JSON.parse(s)}catch{return s}},ga=async(s,e)=>{if(!Ne())return null;try{const{CapacitorHttp:n}=await ze(async()=>{const{CapacitorHttp:o}=await import("./vendor-.bun-BE757pvp.js").then(a=>a.cr);return{CapacitorHttp:o}},[]),r=Object.fromEntries(new Headers(e?.headers).entries()),i=await n.request({url:s,method:e?.method||"GET",headers:r,data:pa(e?.body)});return{ok:i.status>=200&&i.status<300,status:i.status,source:"native-http",json:async()=>ha(i.data)}}catch(n){return console.warn("[mobile-connect]","native-http failed",Gt({url:s,error:n instanceof Error?n.message:String(n)})),null}},ba=async(s,e)=>{const n=await fetch(s,e).catch(r=>(console.warn("[mobile-connect]","browser-fetch failed",Gt({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},He=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)}},tt=async(s,e,n)=>{const r=n?.totalTimeoutMs??da,i=Date.now(),o=await He(Math.min(ua,r),ga(s,e));if(o)return o;const a=new AbortController,l=Math.max(500,r-(Date.now()-i));return He(l,ba(s,{...e,signal:a.signal}),()=>a.abort())},Ht=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,xa=async(s,e,n,r=St,i)=>{const o=Fn({relayUrl:s.relayUrl,serverId:s.serverId,hostEncPubJwk:s.hostEncPubJwk}),a=l=>l==="ok"&&i?.keepTunnel?{outcome:l,tunnel:o}:(o.close(),{outcome:l});try{const l=e?{Authorization:`Bearer ${e}`}:void 0,d=await He(r,o.fetch("/auth/session",{headers:l}).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 Ht(d);return u&&u.disabled!==!0&&u.authenticated===!1?a(e?"auth-failed":"needs-login"):a("ok")}catch(l){throw o.close(),l}},ya=(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&&Or(a,i),jt({apiBaseUrl:o,clientToken:e,runtimeKey:r??nr(s),relay:a})},va=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=ks(e.relay);return n?{kind:"relay",relay:n}:null}return null},wa=s=>{if(s.mode==="relay"){const e=ks(s.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof s.url=="string"?js(s.url):[]},Ke=()=>{if(typeof window>"u")return[];let s;try{s=JSON.parse(window.localStorage.getItem(ws)||"[]")}catch{return[]}if(!Array.isArray(s))return[];const e=Ne();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(va).filter(d=>!!d):wa(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:_t(Be({candidates:i})),l={id:r.id,label:a,candidates:i,lastUsedAt:typeof r.lastUsedAt=="number"?r.lastUsedAt:0};return e?[{...l,hasToken:!!r.hasToken||!!o}]:[{...l,clientToken:o,hasToken:!!o}]}).sort((n,r)=>r.lastUsedAt-n.lastUsedAt)},ds=s=>s.kind==="relay"?{kind:"relay",relay:{relayUrl:s.relay.relayUrl,serverId:s.relay.serverId,hostEncPubJwk:s.relay.hostEncPubJwk}}:{kind:"direct",url:s.url},Kt=s=>{if(typeof window>"u")return;const e=Ne(),n=s.slice(0,tr).map(r=>{const i={id:r.id,label:r.label,candidates:r.candidates.map(ds),lastUsedAt:r.lastUsedAt};return e?{...i,hasToken:!!(r.hasToken||r.clientToken)}:{...i,clientToken:r.clientToken}});try{window.localStorage.setItem(ws,JSON.stringify(n))}catch(r){console.warn("[mobile-storage] failed to persist connection metadata",r)}},rr=(s,e)=>{const n=s.find(o=>e.id&&o.id===e.id||Ot(o.candidates,e.candidates)),r=Ne(),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&&!Ot(o.candidates,e.candidates))].slice(0,tr)},Ss=Dr,ja=0,Ns=s=>`${la}token.${encodeURIComponent(s)}`,ka=async(s,e)=>{let n;const r=new Promise(i=>{n=window.setTimeout(()=>i(e),fa)});try{return await Promise.race([s.catch(()=>e),r])}finally{n!==void 0&&window.clearTimeout(n)}},Cs=async(s,e,n)=>Ne()?ka(e().catch(r=>(console.warn(`[mobile-storage] ${s} failed`,r),n)),n):n,Bt=async s=>{ft("secure:read-start",{key:s});const e=await Cs("secure:read",async()=>(await Ss.internalGetItem({prefixedKey:Ns(s),sync:!1})).data,null),n=typeof e=="string"&&e.trim()?e:void 0;return ft("secure:read",{key:s,hasToken:!!n}),n},Xe=async(s,e)=>{ft("secure:write-start",{key:s});const n=await Cs("secure:write",async()=>(await Ss.internalSetItem({prefixedKey:Ns(s),data:e,sync:!1,access:ja}),!0),!1);return ft("secure:write",{key:s,ok:n}),n},Sa=async s=>{await Cs("secure:delete",async()=>(await Ss.internalRemoveItem({prefixedKey:Ns(s),sync:!1}),!0),!1)},or=async()=>{if(typeof window>"u"||!Ne())return;let s;try{s=JSON.parse(window.localStorage.getItem(ws)||"[]")}catch{return}if(!Array.isArray(s))return;const e=s.filter(n=>!!n&&typeof n=="object"&&typeof n.url=="string"&&typeof n.clientToken=="string"&&!!n.clientToken.trim());if(e.length!==0){ft("secure:migrate-start",{count:e.length});for(const{url:n,clientToken:r}of e)await Xe(ut(n),r);Kt(Ke()),ft("secure:migrate-done",{count:e.length})}},Na=async()=>(await or(),Ke()),Ft=async s=>{const e=rr(Ke(),s);return Kt(e),Ne()&&s.clientToken&&await Xe(we({candidates:s.candidates}),s.clientToken),e},Ca=async s=>{const e=Ke(),n=e.find(i=>i.id===s)??null,r=e.filter(i=>i.id!==s);return Kt(r),n&&Ne()&&await Sa(we(n)),r},Ea=1500,$t=async(s,e,n)=>{const r=n?.fast?{totalTimeoutMs:Lt}:void 0,i=et({candidates:s})?.serverId??null,o=s.find(u=>u.kind==="relay")??null,a=s.filter(u=>u.kind==="direct"),l=async()=>{for(const u of a){const f=ht(u.url)||u.url,m=e?{Authorization:`Bearer ${e}`}:void 0,p=await tt(`${f}/health`,{method:"GET"},r);if(!p?.ok)continue;if(i){const y=await p.json().catch(()=>null),P=y&&typeof y=="object"?y.serverId:null;if(typeof P=="string"&&P&&P!==i){Ce("probe:server-id-mismatch",{url:f});continue}}const g=await tt(`${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 k=await Ht(g);if(k&&k.disabled!==!0&&k.authenticated===!1)return{status:"needs-login"};const S=k?.disabled===!0;return!e&&Ne()&&!S&&k?.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 xa(o.relay,e,void 0,n?.fast?Lt: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,k=null;const S=I=>{I?.status==="ok"&&I.transport.kind==="relay"&&I.transport.tunnel?.close()},y=I=>{f||(f=!0,u(I))},P=()=>{m||f||(p!==void 0&&(window.clearTimeout(p),p=void 0),d().then(I=>{if(k=I,f||m){S(I);return}if(I.status==="ok"||I.status==="needs-login"){y(I);return}g&&y(g)}))};l().then(I=>{if(g=I,!f){if(I.status==="ok"||I.status==="needs-login"){m=!0,p!==void 0&&window.clearTimeout(p),S(k),y(I);return}if(k){y(k);return}P()}}),p=window.setTimeout(P,Ea)}):l()},Qe=(s,e,n)=>{s.kind==="relay"?ya(s.relay,e,n?.grant,n?.runtimeKey,s.tunnel):jt({apiBaseUrl:s.url,clientToken:e,runtimeKey:n?.runtimeKey}),ar()},Pa=()=>{const s=Ke()[0];return s?.label?.trim()?s.label:null},fn=async()=>{await or();const s=Ke()[0];if(!s)return!1;let e;if(Ne()){if(!s.hasToken||(e=await Bt(we(s)),!e))return!1}else if(e=s.clientToken,!e)return!1;const n=await $t(s.candidates,e);return n.status!=="ok"?!1:(await Ft({id:s.id,label:s.label,candidates:s.candidates}),Qe(n.transport,e,{runtimeKey:we(s)}),!0)},Ia=async(s,e)=>{let n="";try{n=ht(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:Lt};if(!(await tt(`${n}/health`,{method:"GET",headers:i},o))?.ok)return!1;const l=await tt(`${n}/auth/session`,{method:"GET",credentials:"include",headers:i},o);if(!l||!l.ok&&l.status!==404)return!1;const d=await Ht(l);return!(d&&d.disabled!==!0&&d.authenticated===!1)},Ta=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=ks({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return n?[{kind:"relay",relay:n}]:[]}return js(e.url)}),mn=async s=>{const e=et({candidates:s})?.serverId??null;for(const n of s){if(n.kind==="relay"){const o=Fn(n.relay),a=await He(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=ht(n.url)||n.url,i=await tt(`${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},Aa=async(s,e)=>{if(!kt())return Ia(s);const n=await He(Lt,gs("/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 Ht(n);return!(r&&r.disabled!==!0&&r.authenticated===!1)},Ra=s=>s.kind==="relay"?kt():!kt()&&sr(s.url,We()),ir=()=>{const s=Bn();return s?Ke().find(e=>we(e)===s)??null:null},hn=s=>{const e=Bn();return!!e&&we(s)===e},us=async()=>{const s=ir();if(!s)return"no-connection";let e;if(Ne()?e=s.hasToken?await Bt(we(s)):void 0:e=s.clientToken,!e)return"unreachable";const n=s.candidates.findIndex(l=>Ra(l.kind==="relay"?{kind:"relay",relay:l.relay}:{kind:"direct",url:l.url})),r=n>=0?s.candidates.slice(0,n):s.candidates,i=await $t(r,e,{fast:!0});if(i.status==="ok")return await Ft({id:s.id,label:s.label,candidates:s.candidates}),Qe(i.transport,e,{runtimeKey:we(s)}),"switched";if(i.status==="needs-login")return"unreachable";if(n>=0&&await Aa({url:We(),clientToken:e}))return ar(),"unchanged";const o=n>=0?s.candidates.slice(n+1):[],a=await $t(o,e,{fast:!0});return a.status==="ok"?(await Ft({id:s.id,label:s.label,candidates:s.candidates}),Qe(a.transport,e,{runtimeKey:we(s)}),"switched"):"unreachable"},Da=5e3;let ns=!1;const Ma=async()=>{if(ns)return"skipped";const s=ir();if(!s)return Ce("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=et(s);if(!e)return Ce("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";ns=!0;try{const n=await He(St,gs("/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=ht(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=Vt(s).filter(u=>u.url.startsWith("https://")),l=[...o.map(u=>({kind:"direct",url:u})),...a,{kind:"relay",relay:e}];return JSON.stringify(s.candidates.map(ds))===JSON.stringify(l.map(ds))?"unchanged":(Ce("candidates:refreshed",{lanCount:o.length}),await Ft({id:s.id,label:s.label,candidates:l}),"updated")}finally{ns=!1}},ar=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const s=await Ma().catch(()=>"skipped");Ce("candidates:refresh-result",{result:s}),s==="updated"&&kt()&&await us().catch(()=>null)})()},Da)},lr=s=>{const{t:e}=ue(),[n,r]=c.useState(()=>Ke()),[i,o]=c.useState(null),[a,l]=c.useState(null),[d,u]=c.useState(null),f=c.useRef(n),m=c.useRef(null),p=c.useCallback(w=>{f.current=w,r(w)},[]),g=c.useCallback(w=>{m.current=w,o(w)},[]),k=c.useCallback(w=>{m.current===w&&(m.current=null,o(null))},[]);c.useEffect(()=>{let w=!1;return Na().then(j=>{w||p(j)}),()=>{w=!0}},[p]);const S=c.useCallback(w=>{const j=rr(f.current,w);return p(j),Kt(j),j},[p]),y=c.useCallback(async w=>{l(null),g("connect");try{const j=un(w);if(j.length===0){l(e("mobile.connect.error.urlRequired"));return}const T=w.id?f.current.find(L=>L.id===w.id):f.current.find(L=>Ot(L.candidates,j)),E=w.label?.trim()||T?.label||_t(Be({candidates:j})),b=w.relayGrant;let N=w.clientToken?.trim()||void 0;const x=!!N;N||(Ne()?T?.hasToken&&(N=await Bt(we({candidates:j}))):N=T?.clientToken),Ce("connect:start",{candidates:j.map(L=>L.kind),hasToken:!!N});const _=await $t(j,N);if(Ce("connect:probe",{status:_.status}),_.status==="unreachable"){l(e("mobile.connect.error.unreachable"));return}if(_.status==="needs-login"){S({id:T?.id,label:E,candidates:j}),u({id:T?.id??crypto.randomUUID(),label:E,candidates:j,relay:et({candidates:j})??void 0,relayGrant:b});return}N&&x&&Ne()&&await Xe(we({candidates:j}),N),S({id:T?.id,label:E,candidates:j,clientToken:N}),Qe(_.transport,N??null,{runtimeKey:we({candidates:j}),grant:b}),s()}catch(j){console.warn("[mobile-connect] connect threw",j),l(e("mobile.connect.error.invalidUrl"))}finally{k("connect")}},[g,k,s,S,e]),P=c.useCallback(async w=>{if(m.current==="pairing")return;l(null),g("pairing");const j=Ta(w.candidates);let T=null,E=!1;try{if(T=await mn(j),!T){l(e("mobile.connect.error.unreachable"));return}const b=JSON.stringify({pairingId:w.pairingId,secret:w.secret,clientLabel:"OpenChamber Mobile",clientKind:"mobile",deviceName:"OpenChamber Mobile",devicePlatform:dn(),dedupeKey:cn()}),N={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:b},x=T.kind==="relay"?await He(St,T.tunnel.fetch("/api/client-auth/pairing/redeem",N).catch(()=>null)):await tt(`${T.url}/api/client-auth/pairing/redeem`,N);if(!x?.ok){l(e("mobile.connect.error.authRequired"));return}const _=await x.json().catch(()=>null),L=typeof _?.clientToken=="string"?_.clientToken.trim():"";if(!L){l(e("mobile.connect.error.authRequired"));return}const G=typeof _?.server?.label=="string"?_.server.label:"",M=w.label||G||_t(Be({candidates:j}));if(Ne()&&!await Xe(we({candidates:j}),L)){l(e("mobile.connect.error.authRequired"));return}S({label:M,candidates:j,clientToken:L}),Qe(T.kind==="relay"?{kind:"relay",relay:T.relay,tunnel:T.tunnel}:{kind:"direct",url:T.url},L,{runtimeKey:we({candidates:j})}),E=T.kind==="relay",s()}catch(b){console.warn("[mobile-connect] pairing threw",b),l(e("mobile.connect.error.authRequired"))}finally{!E&&T?.kind==="relay"&&T.tunnel.close(),k("pairing")}},[g,k,s,S,e]),I=c.useCallback(async w=>{if(!d||!w.trim()||m.current==="password")return;l(null),g("password");const{id:j,label:T,candidates:E}=d;let b=null,N=!1;try{if(b=await mn(E),!b){l(e("mobile.connect.error.unreachable"));return}const x={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:dn(),dedupeKey:cn()})};Ce("password:start",{transport:b.kind});const _=b.kind==="relay"?await He(St,b.tunnel.fetch("/auth/session",x).catch(()=>null)):await tt(`${b.url}/auth/session`,x);if(Ce("password:done",{ok:_?.ok===!0,status:_?.status??null}),!_?.ok){l(e("mobile.connect.error.passwordFailed"));return}const L=await _.json().catch(()=>null),G=typeof L?.clientToken=="string"?L.clientToken.trim():"";if(Ce("password:token",{issued:!!G}),!G){if(b.kind==="direct"&&!Ne()){S({id:j,label:T,candidates:E}),u(null),Qe({kind:"direct",url:b.url},null,{runtimeKey:we({candidates:E})}),s();return}l(e("mobile.connect.error.authRequired"));return}Ne()&&await Xe(we({candidates:E}),G),S({id:j,label:T,candidates:E,clientToken:G}),u(null),Qe(b.kind==="relay"?{kind:"relay",relay:b.relay,tunnel:b.tunnel}:{kind:"direct",url:b.url},G,{runtimeKey:we({candidates:E})}),N=b.kind==="relay",s()}catch(x){console.warn("[mobile-connect] password threw",x),l(e("mobile.connect.error.passwordFailed"))}finally{!N&&b?.kind==="relay"&&b.tunnel.close(),k("password")}},[g,k,s,d,S,e]),D=c.useCallback(()=>{u(null),l(null)},[]),A=c.useCallback(async w=>{l(null);let j=un(w);const T=w.id?f.current.find(x=>x.id===w.id)??null:null;if(T){const x=j.filter(G=>G.kind==="direct"),_=Vt(T).filter(G=>G.url.startsWith("https://")&&!x.some(M=>sr(M.url,G.url))),L=et(T);j=[...x,..._,...L?[{kind:"relay",relay:L}]:[]]}if(j.length===0)return l(e("mobile.connect.error.urlRequired")),null;const E=w.clientToken?.trim()||void 0,b=w.label?.trim()||_t(Be({candidates:j}));if(Ne()){const x=we({candidates:j});if(E)await Xe(x,E);else if(T?.hasToken){const _=we(T);if(_&&x&&_!==x){const L=await Bt(_);L&&await Xe(x,L)}}}return S({id:w.id,label:b,candidates:j,clientToken:E}).find(x=>Ot(x.candidates,j))??null},[S,e]),R=c.useCallback(async w=>{const j=f.current.find(E=>E.id===w)??null,T=await Ca(w);return p(T),j},[p]);return{connections:n,isBusy:i!==null,isPasswordBusy:i==="password",error:a,pendingConnection:d,connect:y,redeemPairingConnection:P,submitPassword:I,cancelPassword:D,saveConnection:A,removeConnection:R,setError:l}},_a=4,za=3,La=5,Oa=9e4,Ba=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(l),o?.remove(),d()},l=window.setTimeout(()=>a(()=>i(new Error("module install timed out"))),Oa);Promise.resolve(s.addListener?.("googleBarcodeScannerModuleInstallProgress",d=>{d?.state===_a?a(r):(d?.state===za||d?.state===La)&&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"))))})},cr=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&typeof e.scan=="function"?e:null},dr=s=>{const e=s.trim();if(!e)return null;if(/^openchamber:\/\//i.test(e)){const n=Qo(e);return n?{pairing:n}:null}return/^https?:\/\//i.test(e)?{url:e}:null},Fa=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)},fs=()=>cr()!==null,ur=async()=>{const s=cr();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 Ba(s);const r=(await s.scan({formats:["QR_CODE"]}))?.barcodes?.[0],i=(r?.rawValue??r?.displayValue??"").trim();if(!i)return{status:"cancelled"};const o=dr(i);return o?"pairing"in o?{status:"pairing",...o}:{status:"ok",...o}:{status:"invalid"}}catch(n){if(!Fa(n)||e===2)return{status:"failed"};await new Promise(r=>window.setTimeout(r,600))}return{status:"failed"}}catch{return{status:"failed"}}};function $a(s){const e=de.c(4),n=2500,{uiFont:r}=io(),[i,o]=c.useState(!1);let a,l;return e[0]!==n||e[1]!==r?(a=()=>{let d=!1;const u=()=>{d||o(!0)},f=()=>{requestAnimationFrame(()=>requestAnimationFrame(u))},m=Promise.all([ao(r).catch(Ha),document.fonts?.ready?.then(Ga).catch(Va)??Promise.resolve(),pi.catch(Wa)]).then(Ua),p=new Promise(g=>{window.setTimeout(g,n)});return Promise.race([m,p]).then(f),()=>{d=!0}},l=[r,n],e[0]=n,e[1]=r,e[2]=a,e[3]=l):(a=e[2],l=e[3]),c.useEffect(a,l),i}function Ua(){}function Wa(){}function Va(){}function Ga(){}function Ha(){}const Ka="openchamber",qa=s=>s.replace(/^\/+|\/+$/g,""),Ja=s=>{const e=qa(s.pathname).split("/").filter(Boolean);return s.host?[s.host,...e]:e};function Ya(s){if(typeof s!="string"||s.length===0)return null;let e;try{e=new URL(s)}catch{return null}if(e.protocol!==`${Ka}:`)return null;const n=Ja(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 Re={},fr=!1,wt=null;const Xa=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 Re.openSessions?(Re.openSessions(s.filter),!0):!1;case"status":return mt.getState().setMobileSessionPanelOpen(!0),!0;case"view":return Re.openView?(Re.openView(s.target),!0):!1;case"changes":return Re.openChanges?(Re.openChanges({path:s.path,staged:s.staged}),!0):!1;case"settings":return Re.openSettings?(Re.openSettings(s.section),!0):!1}},Es=()=>{if(!fr||!wt)return;const s=wt;wt=null,Xa(s)||(wt=s)},mr=s=>{wt=s,Es()},pn=s=>{const e=Ya(s);e&&mr(e)},Qa=s=>{fr=s,Es()},Za=s=>{const e=de.c(3);let n,r;e[0]!==s?(n=()=>(Re=s,Es(),()=>{Re===s&&(Re={})}),r=[s],e[0]=s,e[1]=n,e[2]=r):(n=e[1],r=e[2]),c.useEffect(n,r)},el=s=>{const{ready:e}=s;c.useEffect(()=>{Qa(e)},[e]),c.useEffect(()=>{if(!Ne())return;let n=!1;const r=[];return ze(()=>import("./vendor-.bun-BE757pvp.js").then(i=>i.cs),[]).then(async({App:i})=>{if(n)return;const o=await i.addListener("appUrlOpen",a=>{pn(a?.url)});if(n){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),ze(()=>import("./vendor-.bun-BE757pvp.js").then(i=>i.ct),[]).then(async({PushNotifications:i})=>{if(n)return;const o=await i.addListener("pushNotificationActionPerformed",a=>{const l=a?.notification?.data,d=typeof l?.url=="string"?l.url:typeof l?.deeplink=="string"?l.deeplink:void 0;if(d){pn(d);return}const u=typeof l?.sessionId=="string"?l.sessionId:void 0;u&&mr({type:"session",sessionId:u})});if(n){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),()=>{n=!0,r.forEach(i=>i())}},[])},gn=32,tl=64,sl=.7,nl=s=>s.parentID??null,bn=s=>s.time?.updated??s.time?.created??0,rl=()=>Ut.getState().activeSessions.filter(s=>nl(s)===null).slice().sort((s,e)=>bn(e)-bn(s)),ol=s=>{const e=rl();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,$n(o)),!0},il=(s,e)=>{const n=c.useRef(e?.onSwitch);n.current=e?.onSwitch,c.useEffect(()=>{const r=s.current;if(!r)return;let i=!1,o=!1,a=0,l=0;const d=f=>{if(f.touches.length!==1){i=!1;return}const m=f.touches[0],p=r.clientWidth,g=m.clientX<=gn,k=m.clientX>=p-gn;i=g||k,o=g,a=m.clientX,l=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-l;if(Math.abs(p)<tl||Math.abs(g)>Math.abs(p)*sl||o&&p<=0||!o&&p>=0)return;const k=o?-1:1;ol(k)&&n.current?.(k<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])},al=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},ll=s=>{const{enabled:e}=s,n=mt(i=>i.nativeNotificationsEnabled),r=c.useRef(null);c.useEffect(()=>{if(!e||!n||!al())return;let i=!1;const o=[];return ze(()=>import("./vendor-.bun-BE757pvp.js").then(a=>a.ct),[]).then(async({PushNotifications:a})=>{if(i)return;let l=await a.checkPermissions().catch(()=>null);if(l?.receive!=="granted"&&(l=await a.requestPermissions().catch(()=>null)),l?.receive!=="granted")return;const d=await a.addListener("registration",f=>{r.current=f.value,Ls()?.push?.registerApnsToken?.({token:f.value,platform:Un()})}),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]),c.useEffect(()=>{if(n)return;const i=r.current;if(!i)return;r.current=null,Ls()?.push?.unregisterApnsToken?.({token:i})},[n])},cl=["appearance","chat","notifications","sessions","git","magic-prompts","behavior","mcp","providers","usage","voice","about"],dl=320,ul=380,hr=280,pr=560,xn=380;function yn(s,e,n){const r=de.c(18),i=c.useRef(null);let o;r[0]!==n||r[1]!==e?(o=()=>{if(typeof window>"u")return n;const b=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(b)?Math.min(pr,Math.max(hr,b)):n},r[0]=n,r[1]=e,r[2]=o):o=r[2];const[a,l]=c.useState(o),[d,u]=c.useState(!1),f=c.useRef(0),m=c.useRef(a),p=c.useRef(null),g=c.useRef(null),k=fl;let S;r[3]===Symbol.for("react.memo_cache_sentinel")?(S=b=>{const N=i.current;N&&(N.style.width=`${b}px`,N.style.minWidth=`${b}px`,N.style.maxWidth=`${b}px`,N.style.setProperty("--oc-ipad-sidebar-width",`${b}px`))},r[3]=S):S=r[3];const y=S;let P;r[4]!==a?(P=b=>{try{b.currentTarget.setPointerCapture(b.pointerId)}catch{}g.current=b.pointerId,f.current=b.clientX,m.current=a,p.current=a,u(!0),b.preventDefault()},r[4]=a,r[5]=P):P=r[5];const I=P;let D;r[6]!==s?(D=b=>{if(g.current!==b.pointerId)return;const N=b.clientX-f.current,x=k(m.current+(s==="left"?N:-N));p.current!==x&&(p.current=x,y(x))},r[6]=s,r[7]=D):D=r[7];const A=D;let R;r[8]!==e?(R=b=>{if(g.current!==b.pointerId)return;try{b.currentTarget.releasePointerCapture(b.pointerId)}catch{}const N=k(p.current??m.current);g.current=null,p.current=null,u(!1),l(N);try{window.localStorage.setItem(e,String(N))}catch{}},r[8]=e,r[9]=R):R=r[9];const w=R;let j;r[10]!==I||r[11]!==w||r[12]!==A?(j={onPointerDown:I,onPointerMove:A,onPointerUp:w,onPointerCancel:w},r[10]=I,r[11]=w,r[12]=A,r[13]=j):j=r[13];const T=j;let E;return r[14]!==T||r[15]!==d||r[16]!==a?(E={asideRef:i,width:a,isResizing:d,handleProps:T},r[14]=T,r[15]=d,r[16]=a,r[17]=E):E=r[17],E}function fl(s){return Math.min(pr,Math.max(hr,Math.round(s)))}const vn=s=>{const e=de.c(12),{side:n,isResizing:r,ariaLabel:i,handleProps:o}=s,a=n==="left"?"right-0":"left-0";let l;e[0]!==a?(l=X("absolute inset-y-0 z-30 w-6 cursor-col-resize touch-none",a),e[0]=a,e[1]=l):l=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=X("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]!==l||e[10]!==m?(p=t.jsx("div",{className:l,role:"separator","aria-orientation":"vertical","aria-label":i,...o,children:m}),e[7]=i,e[8]=o,e[9]=l,e[10]=m,e[11]=p):p=e[11],p},Et=()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0?!0:window.location.protocol==="capacitor:",ml=()=>{c.useEffect(()=>{if(!Et())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 ze(()=>import("./vendor-.bun-BE757pvp.js").then(o=>o.cu),[]).then(async({StatusBar:o,Style:a})=>{if(s)return;const l=window.Capacitor?.getPlatform?.(),d=async()=>{if(l==="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 ze(async()=>{const{App:p}=await import("./vendor-.bun-BE757pvp.js").then(g=>g.cs);return{App:p}},[]),m=await f.addListener("appStateChange",({isActive:p})=>{p&&d()});if(s){m.remove();return}e.push(()=>{m.remove()})}).catch(()=>{}),ze(()=>import("./vendor-.bun-BE757pvp.js").then(o=>o.cv),[]).then(async({Keyboard:o})=>{if(s)return;if(window.Capacitor?.getPlatform?.()==="android"){const b=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}}))}),x=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}}))}),L=()=>{b.remove(),N.remove(),x.remove(),_.remove()};if(s){L();return}e.push(L);return}await o.setAccessoryBarVisible({isVisible:!1}).catch(()=>{});const l=250,d=200,u="cubic-bezier(0.38, 0.7, 0.125, 1)";let f=null,m=null,p=0,g=!1,k=0,S=!1;const y=(b,N)=>{n.style.setProperty(b,`${Math.max(0,Math.round(N))}px`)},P=()=>{f!==null&&(window.clearTimeout(f),f=null)},I=(b,N)=>{window.dispatchEvent(new CustomEvent(b,{detail:N}))},D=()=>{const b=[],N=document.querySelector(".oc-mobile-composer");N&&b.push({el:N,factor:1});const x=document.querySelector(".oc-draft-center");return x&&b.push({el:x,factor:.5}),b},A=()=>{for(const{el:b}of D())b.style.transition="",b.style.transform=""},R=await o.addListener("keyboardWillShow",b=>{if(P(),S=!0,p=b.keyboardHeight,!g){const x=document.querySelector(".oc-mobile-app-shell");k=x&&parseFloat(getComputedStyle(x).paddingBottom)||0}const N=Math.max(0,p-k);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:x,factor:_}of D())x.style.transition=`transform ${l}ms ${u}`,x.style.transform=`translateY(${-N*_}px)`;y("--oc-kb-scroll-inset",N),I("oc:keyboard-settled",{open:!0}),I("oc:keyboard-anim",{phase:"show",slide:N,durationMs:l,easing:u}),f=window.setTimeout(()=>{f=null,n.classList.remove("oc-kb-animating"),y("--oc-kb-layout",p),g=!0,A(),I("oc:keyboard-settled",{open:!0}),m=window.setTimeout(()=>{m=null,n.classList.remove("oc-kb-caret-hold")},250)},l+20)}),w=()=>{if(!S)return;S=!1,P(),I("oc:keyboard-intent",{open:!1}),m!==null&&(window.clearTimeout(m),m=null),n.classList.remove("oc-kb-caret-hold");const b=Math.max(0,p-k);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:x}of D())N.style.transition="none",N.style.transform=`translateY(${-b*x}px)`;document.querySelector(".oc-mobile-app-shell")?.offsetHeight}I("oc:keyboard-anim",{phase:"hide",slide:b,durationMs:d,easing:u}),n.classList.add("oc-kb-animating","oc-kb-hide");for(const{el:N}of D())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"),A(),I("oc:keyboard-settled",{open:!1})},d+20)},j=await o.addListener("keyboardWillHide",w),T=b=>b instanceof HTMLElement&&(b.tagName==="TEXTAREA"||b.tagName==="INPUT"||b.isContentEditable),E=b=>{S&&T(b.target)&&(T(b.relatedTarget)||window.setTimeout(()=>{S&&(T(document.activeElement)||w())},0))};if(document.addEventListener("focusout",E,!0),s){P(),document.removeEventListener("focusout",E,!0),R.remove(),j.remove();return}e.push(P,()=>{m!==null&&(window.clearTimeout(m),m=null)},()=>document.removeEventListener("focusout",E,!0),()=>{R.remove()},()=>{j.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")}},[])},hl=s=>{const e=c.useRef(!1);c.useEffect(()=>{if(!Et())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)),ze(()=>import("./vendor-.bun-BE757pvp.js").then(a=>a.cs),[]).then(async({App:a})=>{if(n)return;const l=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){l.remove(),d.remove();return}r.push(()=>{l.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{n=!0,r.forEach(a=>a())}},[s])},pl=s=>{c.useEffect(()=>{if(!Et())return;let e=!1,n=null;return ze(()=>import("./vendor-.bun-BE757pvp.js").then(r=>r.cs),[]).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])},Nt=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),gl=(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,wn=s=>s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:String(s),at={autoComplete:"off",autoCorrect:"off",spellCheck:!1},bl=1e3,jn=s=>{const e=Nt(s);if(!e)return"";const n=e.split("/").filter(Boolean);return n[n.length-1]?.replace(/[-_]/g," ")||e},xl=(s,e)=>s?s.label?.trim()||jn(s.path):jn(e),yl=({onConnected:s})=>{const{t:e}=ue(),n=lr(s),{connections:r,isBusy:i,isPasswordBusy:o,error:a,pendingConnection:l}=n,[d,u]=c.useState(""),[f,m]=c.useState(""),[p,g]=c.useState(""),[k,S]=c.useState(!1),y=c.useMemo(()=>fs(),[]),[P,I]=c.useState(()=>!fs()),[D,A]=c.useState(null),[R,w]=c.useState(""),j=c.useCallback(x=>{x.preventDefault(),n.connect({url:d,clientToken:p,label:f})},[p,n,f,d]),T=c.useCallback(x=>{if(/^openchamber:\/\//i.test(x.trim())){const _=dr(x);if(_){if("pairing"in _){n.redeemPairingConnection(_.pairing);return}u(_.url),_.label&&m(_.label),_.clientToken&&g(_.clientToken);return}}u(x)},[n]),E=c.useCallback(async()=>{if(!(k||i)){n.setError(null),S(!0);try{const x=await ur();switch(x.status){case"ok":u(x.url),x.label&&m(x.label),x.clientToken&&g(x.clientToken),await n.connect({url:x.url,clientToken:x.clientToken,label:x.label});break;case"pairing":await n.redeemPairingConnection(x.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,k,e]),b=c.useCallback(x=>{x.preventDefault(),n.submitPassword(R)},[n,R]),N=c.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")})]}),l?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:b,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:l.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:l.candidates.some(x=>x.kind==="direct")?Be(l):e("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...at,value:R,onChange:x=>w(x.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(pe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:o||!R.trim(),children:e(o?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(pe,{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(pe,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{E()},disabled:k||i,children:[t.jsx(re,{name:"scan-2",className:X("size-[18px]",k&&"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&&!P?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(x=>{const _=D===x.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:()=>{A(x.id),n.connect({id:x.id,candidates:x.candidates,clientToken:x.clientToken,label:x.label}).finally(()=>A(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:x.label}),t.jsx("span",{className:X("block truncate typography-small",_?"text-foreground":"text-muted-foreground"),children:_?e("mobile.connect.connecting"):x.candidates.some(L=>L.kind==="direct")?Be(x):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"})]},x.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[y?t.jsxs("button",{type:"button",onClick:()=>I(x=>!x),"aria-expanded":P,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:X("size-4 transition-transform duration-200",P&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:P?"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:j,children:[t.jsx("input",{...at,value:d,onChange:x=>T(x.target.value),placeholder:e("mobile.connect.url.placeholder"),"aria-label":e("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:P?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:x=>m(x.target.value),placeholder:e("mobile.instances.label.placeholder"),"aria-label":e("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:P?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",{...at,value:p,onChange:x=>g(x.target.value),placeholder:e("mobile.connect.token.placeholder"),"aria-label":e("mobile.connect.token.label"),tabIndex:P?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(pe,{type:"submit",variant:y?"outline":"default",size:"lg",className:"h-12 w-full",disabled:i||k||!d.trim(),children:e(i?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})},vl=({onActiveConnectionDeleted:s,onConnect:e})=>{const{t:n}=ue(),r=lr(e),{connections:i,isBusy:o,isPasswordBusy:a,error:l,pendingConnection:d,connect:u,submitPassword:f,cancelPassword:m,saveConnection:p,removeConnection:g,setError:k}=r,[S,y]=c.useState(null),P=S?i.find(v=>v.id===S)??null:null,[I,D]=c.useState(null),[A,R]=c.useState(""),[w,j]=c.useState(""),[T,E]=c.useState(""),[b,N]=c.useState(""),[x,_]=c.useState(!1),L=c.useMemo(()=>fs(),[]),[G,M]=c.useState(!1),[J,C]=c.useState(null),q=c.useCallback(()=>{y(null),R(""),j(""),E(""),k(null),M(!1)},[k]),B=c.useCallback(v=>{v.preventDefault(),p({id:S??void 0,url:A,label:w,clientToken:T}).then(W=>{W&&q()})},[T,S,w,q,p,A]),O=c.useCallback(async()=>{if(!x){k(null),_(!0);try{const v=await ur();switch(v.status){case"ok":R(v.url),v.label&&j(v.label),v.clientToken&&E(v.clientToken),M(!0);break;case"pairing":await r.redeemPairingConnection(v.pairing);break;case"permission-denied":k(n("mobile.connect.scan.permissionDenied"));break;case"invalid":k(n("mobile.connect.scan.invalid"));break;case"unsupported":k(n("mobile.connect.scan.unsupported"));break;case"failed":k(n("mobile.connect.scan.failed"));break;default:break}}finally{_(!1)}}},[r,x,k,n]),V=c.useCallback(v=>{v.preventDefault(),f(b)},[b,f]),K=c.useCallback(()=>{N(""),m()},[m]),Z=c.useCallback(v=>{D(W=>W===v?null:v)},[]),te=c.useCallback(v=>{D(null),S===v&&q();const W=i.length===1;g(v).then(ee=>{ee&&(W||hn(ee))&&s()})},[i.length,S,s,g,q]),oe="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:V,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(v=>v.kind==="direct")?Be(d):n("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...at,value:b,onChange:v=>N(v.target.value),placeholder:n("mobile.connect.password.placeholder"),"aria-label":n("mobile.connect.password.label"),type:"password",autoFocus:!0,className:oe}),l?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:l}):null,t.jsx(pe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!b.trim(),children:n(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(pe,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:K,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(v=>{const W=I===v.id,ee=hn(v),se=J===v.id,je=se?n("mobile.connect.connecting"):ee?kt()?n("mobile.instances.status.connectedRelay"):n("mobile.instances.status.connectedDirect"):v.candidates.some(le=>le.kind==="direct")?Be(v):n("mobile.connect.relay.badge");return t.jsxs("div",{className:X("flex items-center border-b border-border/60 transition-colors last:border-b-0",W&&"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:()=>{ee||(C(v.id),u({id:v.id,candidates:v.candidates,clientToken:v.clientToken,label:v.label}).finally(()=>C(null)))},disabled:o&&!se||W,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]"}),ee?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:v.label}),t.jsx("span",{className:X("block truncate typography-small",ee&&!se?"text-[var(--status-success)]":"text-muted-foreground"),children:je})]}),se?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:[W?t.jsxs("button",{type:"button","aria-label":n("mobile.instances.confirmDeleteAria",{label:v.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:()=>te(v.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")})]}):v.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(v.id),R(Be(v)),j(v.label),E(v.clientToken||""),k(null)},style:{touchAction:"manipulation"},children:t.jsx(re,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":W?n("mobile.instances.cancelDeleteAria",{label:v.label}):n("mobile.instances.deleteAria",{label:v.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:()=>Z(v.id),style:{touchAction:"manipulation"},children:t.jsx(re,{name:W?"close":"delete-bin",className:"size-[18px]"})})]})]},v.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")}),!G&&!P?t.jsxs("div",{className:"space-y-2",children:[L?t.jsxs(pe,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{O()},disabled:x,children:[t.jsx(re,{name:"scan-2",className:X("size-[18px]",x&&"animate-pulse")}),n("mobile.connect.scanQr")]}):null,t.jsxs(pe,{type:"button",variant:L?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{k(null),M(!0)},children:[t.jsx(re,{name:"add",className:"size-[18px]"}),n("mobile.instances.addManual")]}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:B,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(P?"mobile.instances.editTitle":"mobile.instances.addTitle")}),t.jsx(pe,{type:"button",variant:"ghost",size:"xs",onClick:q,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",{...at,value:A,onChange:v=>R(v.target.value),placeholder:n("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:oe})]}),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:v=>j(v.target.value),placeholder:n("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:oe})]}),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",{...at,value:T,onChange:v=>E(v.target.value),placeholder:n("mobile.connect.token.placeholder"),autoCapitalize:"none",className:oe}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:n("mobile.connect.token.hint")})]}),l?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:l}):null,t.jsx(pe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:n(P?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})},wl=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"},jl=s=>{const e=de.c(19),{percentage:n}=s;let r,i,o,a,l,d,u;if(e[0]!==n){o=Io(n)??0;const k=To(n);i=k==="critical"?"var(--status-error)":k==="warn"?"var(--status-warning)":"var(--status-success)",r=2*Math.PI*7.5,a="0 0 18 18",l="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]=l,e[6]=d,e[7]=u}else r=e[1],i=e[2],o=e[3],a=e[4],l=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]!==l||e[15]!==d||e[16]!==u||e[17]!==p?(g=t.jsxs("svg",{viewBox:a,className:l,role:d,"aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100,children:[f,p]}),e[13]=a,e[14]=l,e[15]=d,e[16]=u,e[17]=p,e[18]=g):g=e[18],g},kn=s=>{const e=de.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 l;e[3]!==a?(l=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:a}),e[3]=a,e[4]=l):l=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]!==l||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:[l,d,u]}),e[9]=l,e[10]=d,e[11]=u,e[12]=f):f=e[12],f},kl=s=>{const e=de.c(55),{open:n,onClose:r,anchorRef:i,contextDisplay:o,branchLabel:a,usageGroups:l,usageDisplayMode:d,isUsageLoading:u,timeFormatPreference:f}=s,{t:m}=ue(),p=c.useRef(null),[g,k]=c.useState(n),[S,y]=c.useState(!1);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P=Xn(),e[0]=P):P=e[0];const I=P,D=c.useRef(null),[A,R]=c.useState(null);let w,j;e[1]!==i||e[2]!==n||e[3]!==g?(w=()=>{if(!n||!I||!g)return;const se=()=>{const ce=i.current?.getBoundingClientRect(),ke=D.current?.getBoundingClientRect();if(!ce||!ke){R(null);return}const ae=ce.left-ke.left,me=Math.min(Math.max(ae,8),Math.max(8,ke.width-xn-8));R(me)};se();const je=D.current;if(typeof ResizeObserver>"u"||!je)return;const le=new ResizeObserver(se);return le.observe(je),()=>le.disconnect()},j=[i,I,n,g],e[1]=i,e[2]=n,e[3]=g,e[4]=w,e[5]=j):(w=e[4],j=e[5]),c.useLayoutEffect(w,j);const T=I&&A!==null;let E,b;e[6]!==n||e[7]!==g?(E=()=>{if(n){k(!0),y(!1);return}if(!g)return;y(!0);const se=window.setTimeout(()=>{k(!1),y(!1)},140);return()=>window.clearTimeout(se)},b=[n,g],e[6]=n,e[7]=g,e[8]=E,e[9]=b):(E=e[8],b=e[9]),c.useEffect(E,b);let N,x;e[10]!==r||e[11]!==n?(N=()=>{if(!n)return;const se=je=>{je.key==="Escape"&&r()};return document.addEventListener("keydown",se),()=>document.removeEventListener("keydown",se)},x=[r,n],e[10]=r,e[11]=n,e[12]=N,e[13]=x):(N=e[12],x=e[13]),c.useEffect(N,x);let _,L;if(e[14]!==i||e[15]!==r||e[16]!==n?(_=()=>{if(!n)return;const se=je=>{const le=je.target;if(!(le instanceof Node)){r();return}p.current?.contains(le)||i.current?.contains(le)||r()};return document.addEventListener("pointerdown",se,!0),document.addEventListener("wheel",se,!0),()=>{document.removeEventListener("pointerdown",se,!0),document.removeEventListener("wheel",se,!0)}},L=[i,r,n],e[14]=i,e[15]=r,e[16]=n,e[17]=_,e[18]=L):(_=e[17],L=e[18]),c.useEffect(_,L),!g)return null;let G;e[19]!==m?(G=m("mobile.header.openMetadataAria"),e[19]=m,e[20]=G):G=e[20];const M=T?"absolute origin-top-left":"mx-3 mt-2",J=S?"pointer-events-none":"pointer-events-auto";let C;e[21]!==M||e[22]!==J?(C=X("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,J),e[21]=M,e[22]=J,e[23]=C):C=e[23];const q=`${S?"session-metadata-out":"session-metadata-in"} ${S?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let B;e[24]!==A||e[25]!==T?(B=T?{top:8,left:A??8,width:`min(${xn}px, calc(100% - 16px))`}:null,e[24]=A,e[25]=T,e[26]=B):B=e[26];let O;e[27]!==q||e[28]!==B?(O={animation:q,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...B},e[27]=q,e[28]=B,e[29]=O):O=e[29];let V;e[30]!==m?(V=m("mobile.header.metadata.branch"),e[30]=m,e[31]=V):V=e[31];let K;e[32]!==a||e[33]!==V?(K=t.jsx(kn,{icon:"git-branch",label:V,children:a}),e[32]=a,e[33]=V,e[34]=K):K=e[34];let Z;e[35]!==o||e[36]!==m?(Z=o?t.jsx(kn,{iconNode:t.jsx(jl,{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:X("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]=Z):Z=e[37];let te;e[38]!==u||e[39]!==f||e[40]!==d||e[41]!==l?(te=t.jsx(Sl,{groups:l,displayMode:d,isLoading:u,timeFormatPreference:f}),e[38]=u,e[39]=f,e[40]=d,e[41]=l,e[42]=te):te=e[42];let oe;e[43]!==K||e[44]!==Z||e[45]!==te?(oe=t.jsxs("div",{className:"space-y-1",children:[K,Z,te]}),e[43]=K,e[44]=Z,e[45]=te,e[46]=oe):oe=e[46];let v;e[47]!==G||e[48]!==C||e[49]!==O||e[50]!==oe?(v=t.jsx("div",{ref:p,role:"dialog","aria-label":G,className:C,style:O,children:oe}),e[47]=G,e[48]=C,e[49]=O,e[50]=oe,e[51]=v):v=e[51];let W;e[52]===Symbol.for("react.memo_cache_sentinel")?(W=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]=W):W=e[52];let ee;return e[53]!==v?(ee=t.jsxs("div",{ref:D,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:[v,W]}),e[53]=v,e[54]=ee):ee=e[54],ee},Sl=s=>{const e=de.c(30),{groups:n,displayMode:r,isLoading:i,timeFormatPreference:o}=s,{t:a}=ue();let l;e[0]!==r||e[1]!==a?(l=a(r==="remaining"?"header.services.remaining":"header.services.used"),e[0]=r,e[1]=a,e[2]=l):l=e[2];const d=l;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 k;e[12]!==p||e[13]!==g?(k=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]=k):k=e[14];let S;e[15]!==m||e[16]!==k?(S=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[u,m,k]}),e[15]=m,e[16]=k,e[17]=S):S=e[17];let y;if(e[18]!==r||e[19]!==n||e[20]!==o){let D;e[22]!==r||e[23]!==o?(D=A=>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(Ao,{providerId:A.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:A.providerName}),A.status&&A.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:A.status}):null]}),A.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:A.rows.map(R=>{const w=r==="remaining"?R.window.remainingPercent:R.window.usedPercent,j=Ro(R.window.valueLabel,w),T=Do(R.window.resetAt,R.window.resetAfterFormatted??R.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:R.subtitle?`${R.subtitle} · ${R.label}`:R.label}),T?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground/70",children:T}):null]}),t.jsx("span",{className:X("shrink-0 typography-ui-label font-semibold tabular-nums",wl(R.window)),children:j==="-"?"":j})]},R.key)})}):null,A.status&&A.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:A.status}):null]},A.providerId),e[22]=r,e[23]=o,e[24]=D):D=e[24],y=n.map(D),e[18]=r,e[19]=n,e[20]=o,e[21]=y}else y=e[21];let P;e[25]!==y?(P=t.jsx("div",{className:"space-y-1.5",children:y}),e[25]=y,e[26]=P):P=e[26];let I;return e[27]!==P||e[28]!==S?(I=t.jsxs("div",{className:"pt-2.5",children:[S,P]}),e[27]=P,e[28]=S,e[29]=I):I=e[29],I},Nl=s=>{const e=de.c(26),{open:n,onClose:r,items:i,rightOffset:o}=s,a=o===void 0?0:o,{t:l}=ue();let d,u;if(e[0]!==r||e[1]!==n?(d=()=>{if(!n)return;const D=A=>{A.key==="Escape"&&r()};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},u=[r,n],e[0]=r,e[1]=n,e[2]=d,e[3]=u):(d=e[2],u=e[3]),c.useEffect(d,u),!n)return null;let f;e[4]!==l?(f=l("mobile.menu.titleAria"),e[4]=l,e[5]=f):f=e[5];let m;e[6]!==l?(m=l("mobile.surface.closeAria"),e[6]=l,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 k;e[11]!==g?(k={right:g,animation:"mobile-menu-in 160ms cubic-bezier(0.32, 0.72, 0, 1)"},e[11]=g,e[12]=k):k=e[12];let S;if(e[13]!==i||e[14]!==r){let D;e[16]!==r?(D=(A,R)=>t.jsxs("button",{type:"button",role:"menuitem",className:X("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",R>0&&"border-t border-border/30"),style:{touchAction:"manipulation"},onClick:()=>{A.onSelect(),r()},children:[A.iconNode??(A.icon?t.jsx(re,{name:A.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:A.label}),A.badge&&A.badge>0?t.jsx("span",{className:"inline-flex size-2 shrink-0 rounded-full bg-primary","aria-hidden":!0}):null]},A.key),e[16]=r,e[17]=D):D=e[17],S=i.map(D),e[13]=i,e[14]=r,e[15]=S}else S=e[15];let y;e[18]!==k||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:k,children:S}),e[18]=k,e[19]=S,e[20]=y):y=e[20];let P;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=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]=P):P=e[21];let I;return e[22]!==y||e[23]!==f||e[24]!==p?(I=t.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":f,children:[p,y,P]}),e[22]=y,e[23]=f,e[24]=p,e[25]=I):I=e[25],I},Cl=c.memo(function({open:e,onOpenChange:n,currentSessionId:r,effectiveDirectory:i,gitDirectory:o,isNewSessionDraftOpen:a,primaryLabel:l,secondaryLabel:d}){const{t:u}=ue(),{git:f}=Wt(),m=c.useRef(null),p=Co(r??"",i||void 0),g=Wn(o),k=xs(o),S=Ae(v=>v.ensureStatus),y=Ae(v=>v.fetchStatus),P=Ie(v=>v.providers),I=Ie(v=>v.currentProviderId),D=Ie(v=>v.currentModelId),A=Ie(v=>v.getModelMetadata);Ie(v=>v.modelsMetadata.size);const R=Eo(c.useCallback(v=>r?v.sessionModelSelections.get(r)??null:null,[r])),w=Je(v=>v.results),j=Je(v=>v.loadSettings),T=Je(v=>v.fetchAllQuotas),E=Je(v=>v.isLoading),b=Je(v=>v.displayMode),N=Je(v=>v.dropdownProviderIds),x=Je(v=>v.selectedModels),_=mt(v=>v.timeFormatPreference);ui(),c.useEffect(()=>{o&&S(o,f)},[S,f,o]),c.useEffect(()=>{if(o)return Po.onGitRefreshHint(v=>{Nt(v.directory)===o&&y(o,f)})},[y,f,o]),c.useEffect(()=>{j()},[j]),c.useEffect(()=>{Ws(N)},[N]),c.useEffect(()=>{!e||E||!N.some(W=>!w.some(ee=>ee.providerId===W))||T()},[N,T,E,e,w]);const G=c.useMemo(()=>{for(let v=p.length-1;v>=0;v-=1){const W=p[v];if(W.role!=="user")continue;const ee=typeof W.model?.providerID=="string"&&W.model.providerID.trim().length>0?W.model.providerID:void 0,se=typeof W.model?.modelID=="string"&&W.model.modelID.trim().length>0?W.model.modelID:void 0;if(ee&&se)return{providerID:ee,modelID:se}}return null},[p])??(R?{providerID:R.providerId,modelID:R.modelId}:null)??(I&&D?{providerID:I,modelID:D}:null),J=(G?P.find(v=>v.id===G.providerID):void 0)?.models.find(v=>v.id===G?.modelID),C=G?A(G.providerID,G.modelID):void 0,q=gl(J?.limit,"context")??C?.limit?.context??0,B=c.useMemo(()=>{for(let v=p.length-1;v>=0;v-=1){const W=p[v];if(W.role!=="assistant"||!W.tokens)continue;const ee=bt(W.tokens.input)+bt(W.tokens.output)+bt(W.tokens.reasoning)+bt(W.tokens.cache?.read)+bt(W.tokens.cache?.write);if(ee>0)return ee}return 0},[p]),O=!a&&B>0&&q>0?Math.min(B/q*100,999):null,V=O!==null?`${wn(B)}/${wn(q)}`:null,K=O===null?"":O>=90?"text-[var(--status-error)]":O>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",Z=O!==null&&V?{percentage:O,tokens:V,colorClass:K}:null,te=g===!0?k?.current?.trim()||u("gitView.branch.detachedHead"):u("common.unavailable"),oe=c.useMemo(()=>{const v=new Map(w.map(W=>[W.providerId,W]));return fi.filter(W=>N.includes(W.id)).filter(W=>v.get(W.id)?.configured===!0).map(W=>{const ee=v.get(W.id),se=[];for(const[ae,me]of Object.entries(ee?.usage?.windows??{}))se.push({key:`window-${ae}`,label:Vs(ae),window:me});const je=Object.entries(ee?.usage?.models??{}),le=x[W.id]??[],ce=le.length>0?je.filter(([ae])=>le.includes(ae)):je;for(const[ae,me]of ce){const ge=Object.entries(me.windows??{});if(ge.length===0)continue;const[Fe,De]=ge[0];se.push({key:`model-${ae}-${Fe}`,label:Vs(Fe),subtitle:mi(ae),window:De})}const ke=!ee.ok&&ee.error?ee.error:se.length===0?u("header.services.noRateLimitsReported"):null;return{providerId:W.id,providerName:W.name,rows:se,status:ke}})},[N,w,x,u]);return c.useEffect(()=>{!e||oe.length===0||Ws(oe.map(v=>v.providerId))},[e,oe]),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:l}),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(v=>!v),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"apps-2-ai",className:"size-5"})}),t.jsx(kl,{open:e,onClose:()=>n(!1),anchorRef:m,contextDisplay:Z,branchLabel:te,usageGroups:oe,usageDisplayMode:b,isUsageLoading:E,timeFormatPreference:_})]})}),El=({onOpenSessions:s,onOpenMenu:e,surfaceShortcuts:n})=>{const{t:r}=ue(),[i,o]=c.useState(!1),a=lt(w=>w.currentDirectory),l=be(w=>w.currentSessionId),u=be(c.useCallback(w=>l?w.getDirectoryForSession(l):null,[l]))||a,f=Nt(u)||null,m=Te(w=>w.projects),p=be(w=>w.availableWorktreesByProject),g=be(c.useCallback(w=>l?w.worktreeMetadata.get(l)??null:null,[l])),k=ko(l,u||void 0),S=be(w=>!!w.newSessionDraft?.open),y=c.useMemo(()=>{const w=Nt(u);if(!w)return r("mobile.header.noProject");const T=(g?.projectDirectory?So(m,g.projectDirectory):null)??No(m,p,w);return xl(T,w)||r("mobile.header.noProject")},[p,g?.projectDirectory,u,m,r]),I=k?.title?.trim()||(l?r("mobile.sessions.untitled"):y),D=l?y:"";c.useEffect(()=>{o(!1)},[l,u]);const A=c.useCallback(()=>{o(!1),s()},[s]),R=c.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:A,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"folders",className:"size-5"})}),t.jsx(Cl,{open:i,onOpenChange:o,currentSessionId:l,effectiveDirectory:u,gitDirectory:f,isNewSessionDraftOpen:S,primaryLabel:I,secondaryLabel:D}),n?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:X("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:X("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:R,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"more-2",className:"size-5"})})]})})})},Pl=({onActiveConnectionDeleted:s})=>{const{t:e}=ue(),[n,r]=c.useState(!1),[i,o]=c.useState(!1),[a,l]=c.useState(!1),[d,u]=c.useState(!1),[f,m]=c.useState(!1),[p,g]=c.useState(!1),[k,S]=c.useState(!1),[y,P]=c.useState(!1),[I,D]=c.useState("nav"),[A,R]=c.useState(!1),[w,j]=c.useState(null),T=lt($=>$.currentDirectory),E=mt($=>$.setSettingsPage),b=it($=>$.available),N=it($=>$.runtimeType),x=c.useMemo(()=>Et(),[]),_=Rt($=>$.mcpServers),L=Rt($=>$.setMcpDraft),G=Rt($=>$.setSelectedMcp),M=oi($=>$.refresh),J=Rt($=>$.loadMcpConfigs),q=xs(Nt(T)||null)?.files?.length??0,B=c.useMemo(()=>Xn(),[]),V=wo()==="portrait",[K,Z]=c.useState(B&&!V),[te,oe]=c.useState(null),v=c.useCallback(()=>{const $=!K;$&&V&&oe(null),Z($)},[K,V]),W=c.useCallback(()=>{if(B){j(null),oe("files"),V&&Z(!1);return}o(!0)},[B,V]),ee=c.useCallback(($=null)=>{if(j($),B){oe("changes"),V&&Z(!1);return}l(!0)},[B,V]),se=c.useCallback(()=>{oe(null),j(null)},[]),je=c.useCallback($=>{if(te===$){se();return}$==="files"?W():ee()},[se,te,ee,W]),le=c.useRef("changes");te&&(le.current=te);const[ce,ke]=c.useState(!1);c.useEffect(()=>{if(!B)return;if(te){ke(!0);return}const $=window.setTimeout(()=>ke(!1),240);return()=>window.clearTimeout($)},[te,B]);const ae=te??le.current,me=yn("left","openchamber.ipad.leftSidebarWidth",dl),ge=yn("right","openchamber.ipad.rightSidebarWidth",ul),Fe=c.useMemo(()=>({openChanges:({diffPath:$,staged:xe}={})=>{ee($?{path:$,staged:xe===!0}:null)},openFiles:()=>W(),openSettings:()=>{D("nav"),S(!0)}}),[ee,W]),De=c.useCallback(()=>{l(!1),j(null)},[]),pt=c.useMemo(()=>({openSessions:()=>{B?Z(!0):r(!0)},openView:$=>{$==="files"?W():$==="mcp"?u(!0):$==="instances"?m(!0):$==="update"&&P(!0)},openChanges:({path:$,staged:xe}={})=>{ee($?{path:$,staged:xe===!0}:null)},openSettings:$=>{$&&E($),D($?"page-content":"nav"),S(!0)}}),[B,ee,W,E]);Za(pt);const $e=c.useRef(null),st=c.useRef(null),Le=c.useRef(null),z=be($=>$.currentSessionId),F=c.useCallback($=>{Le.current=$},[]);il($e,{onSwitch:F}),c.useLayoutEffect(()=>{const $=Le.current;if(Le.current=null,!$)return;const xe=st.current;if(!xe||typeof xe.animate!="function")return;xe.getAnimations().forEach(It=>It.cancel());const Ue=$==="prev"?-70:70;xe.animate([{opacity:.1,transform:`translateX(${Ue}px)`},{opacity:1,transform:"translateX(0)"}],{duration:300,easing:"cubic-bezier(0.22, 1, 0.36, 1)"})},[z]);const Y=c.useCallback(()=>A?(R(!1),!0):n?(r(!1),!0):i?(o(!1),!0):a?(De(),!0):d?(u(!1),!0):f?(m(!1),!0):k?(S(!1),!0):y?(P(!1),!0):!1,[a,De,i,f,d,A,n,k,y]);pl(Y);const Se=b&&(N==="desktop"||N==="web"),Me=c.useCallback(()=>{const $="new-mcp-server";let xe=$,Ue=1;for(;_.some(qt=>qt.name===xe);)xe=`${$}-${Ue}`,Ue+=1;L({name:xe,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),G(xe),E("mcp"),u(!1),D("page-content"),S(!0)},[_,L,G,E]),qe=c.useCallback(()=>{if(p)return;g(!0);const $=T||null,xe=new Promise(Ue=>window.setTimeout(Ue,500));Promise.all([M({directory:$,silent:!0}),J({force:!0}),xe]).finally(()=>g(!1))},[T,p,J,M]),Pt=c.useMemo(()=>{const $=[];return B||$.push({key:"files",icon:"file-text",label:e("mobile.menu.files"),onSelect:()=>W()},{key:"changes",icon:"git-branch",label:e("mobile.menu.changes"),badge:q,onSelect:()=>ee()}),$.push({key:"mcp",iconNode:t.jsx(ii,{className:"size-5 shrink-0 text-muted-foreground"}),label:e("mobile.menu.mcp"),onSelect:()=>u(!0)}),x&&$.push({key:"instances",icon:"server",label:e("mobile.menu.instances"),onSelect:()=>m(!0)}),Se&&$.push({key:"update",icon:"download",label:e("mobile.menu.update"),onSelect:()=>P(!0)}),$.push({key:"settings",icon:"settings-3",label:e("mobile.menu.settings"),onSelect:()=>{D("nav"),S(!0)}}),$},[q,B,ee,W,x,Se,e]);return t.jsx(jo,{actions:Fe,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:[B?t.jsxs("aside",{ref:me.asideRef,className:X("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/50 bg-sidebar will-change-[width] motion-reduce:transition-none",!K&&"border-r-0"),style:{width:K?me.width:0,minWidth:K?me.width:0,maxWidth:K?me.width:0,"--oc-ipad-sidebar-width":`${me.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:me.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!K,"data-page-scroll-lock":"true",children:[K?t.jsx(vn,{side:"left",isResizing:me.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:me.handleProps}):null,t.jsx("div",{className:X("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",me.isResizing&&"pointer-events-none",!K&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Oe,{children:t.jsx(on,{open:!0,variant:"sidebar",onOpenChange:$=>{!$&&V&&Z(!1)}})})})]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(El,{onOpenSessions:()=>B?v():r(!0),onOpenMenu:()=>R(!0),surfaceShortcuts:B?{activePanel:te,changesDirty:q>0,onToggleFiles:()=>je("files"),onToggleChanges:()=>je("changes")}:void 0}),t.jsx("main",{ref:$e,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{ref:st,className:"h-full w-full",children:t.jsx(Oe,{children:t.jsx(ai,{})})})})]}),B?t.jsxs("aside",{ref:ge.asideRef,className:X("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/50 bg-background will-change-[width] motion-reduce:transition-none",!te&&"border-l-0"),style:{width:te?ge.width:0,minWidth:te?ge.width:0,maxWidth:te?ge.width:0,"--oc-ipad-sidebar-width":`${ge.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:ge.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!te,"data-page-scroll-lock":"true",children:[te?t.jsx(vn,{side:"right",isResizing:ge.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:ge.handleProps}):null,t.jsx("div",{className:X("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",ge.isResizing&&"pointer-events-none",!te&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:ce?t.jsx(Oe,{children:ae==="files"?t.jsx(Xs,{onClose:se}):t.jsx(Js,{onClose:se,initialDiffPath:w?.path??null,initialDiffStaged:w?.staged===!0})}):null})]}):null,t.jsx(Nl,{open:A,onClose:()=>R(!1),items:Pt,rightOffset:B&&te?ge.width:0}),n?t.jsx(on,{open:n,onOpenChange:r}):null,i?t.jsx(Ye,{open:!0,onClose:()=>o(!1),ariaLabel:e("mobile.menu.files"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(Xs,{onClose:()=>o(!1)})})}):null,a?t.jsx(Ye,{open:!0,onClose:De,ariaLabel:e("mobile.menu.changes"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(Js,{onClose:De,initialDiffPath:w?.path??null,initialDiffStaged:w?.staged===!0})})}):null,d?t.jsx(Hn,{open:!0,onClose:()=>u(!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:Me,"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:qe,disabled:p,"aria-label":e("mcpDropdown.actions.refreshAria"),title:e("mcpDropdown.actions.refreshAria"),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"refresh",className:X("h-5 w-5",p&&"animate-spin")})}),$]})]})]}),children:t.jsx(Oe,{children:t.jsx(li,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})})}):null,f&&x?t.jsx(Ye,{open:!0,onClose:()=>m(!1),ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(vl,{onConnect:()=>m(!1),onActiveConnectionDeleted:s})}):null,k?t.jsx(Ye,{open:!0,onClose:()=>S(!1),ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(ci,{forceMobile:!0,isWindowed:!0,initialMobileStage:I,visiblePageSlugs:[...cl],onClose:()=>S(!1)})})}):null,y?t.jsx(Ye,{open:!0,onClose:()=>P(!1),ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Oe,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(di,{initialUpdateDialogOpen:!0})})})}):null]})})};function Il({apis:s}){const{t:e}=ue(),n=Ie(C=>C.initializeApp),r=Ie(C=>C.isInitialized),i=Ie(C=>C.isConnected),o=Ie(C=>C.connectionPhase),a=Ie(C=>C.providers.length),l=Ie(C=>C.agents.length),d=Ie(C=>C.loadProviders),u=Ie(C=>C.loadAgents),f=lt(C=>C.currentDirectory),m=be(C=>C.error),p=be(C=>C.clearError),g=mt(C=>C.setIsMobile),k=lo(C=>C.refreshStatus),S=co(C=>C.setPlanModeEnabled),y=Te(C=>C.projects),[P,I]=c.useState(0),[D,A]=c.useState(0),[R,w]=c.useState(!1),[j,T]=c.useState("pending"),E=c.useMemo(()=>Pa(),[]),[,b]=c.useReducer(C=>C+1,0),N=c.useMemo(()=>Et(),[]),x=c.useRef(0),_=c.useRef(0),L=c.useCallback(()=>{const C=We(),q=_.current+1;if(_.current=q,!C){fn();return}const B=()=>{n(),k(s.github,{force:!0}),a===0&&d({source:"mobileApp:nativeResume"}),l===0&&u({source:"mobileApp:nativeResume"})},O=()=>{jt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),I(K=>K+1)};us().then(K=>{if(_.current===q){if(K==="no-connection"){O();return}if(K==="unreachable"){window.setTimeout(()=>{_.current===q&&us().then(Z=>{if(_.current===q&&Z!=="switched"){if(Z==="unchanged"){B();return}O()}})},4e3);return}K!=="switched"&&B()}});const V=Date.now();V-x.current>=bl&&(x.current=V,window.dispatchEvent(new Event("openchamber:system-resume")))},[l,s.github,n,u,d,a,k]);ml(),hl(L),c.useEffect(()=>{if(!N)return;let C;const q=()=>{window.clearTimeout(C),C=window.setTimeout(()=>L(),1500)};return window.addEventListener("online",q),()=>{window.removeEventListener("online",q),window.clearTimeout(C)}},[N,L]),c.useEffect(()=>(Os(s),()=>Os(null)),[s]),c.useEffect(()=>Br(C=>{if(!!C.runtimeKey&&C.runtimeKey===C.previousRuntimeKey){Zo(),b();return}ei(C),A(B=>B+1),I(B=>B+1)}),[]),c.useEffect(()=>{if(!N||i||We()){T("done");return}let C=!1;return T("attempting"),fn().catch(()=>!1).then(()=>{C||T("done")}),()=>{C=!0}},[]),c.useEffect(()=>{g(!0)},[g]),c.useEffect(()=>{N&&!We()||n()},[P,n,N]),c.useEffect(()=>{i&&(a===0&&d({source:"mobileApp:recovery"}),l===0&&u({source:"mobileApp:recovery"}))},[l,i,u,d,a]),c.useEffect(()=>{i&&Bs.setDirectory(f)},[f,i]),c.useEffect(()=>{i&&k(s.github,{force:!0})},[s.github,i,k]),c.useEffect(()=>{if(!i||y.length===0)return;let C=!1;return(async()=>{const B=new Map(be.getState().availableWorktreesByProject);if(await Promise.all(y.map(async K=>{const Z=K.path.replace(/\\/g,"/").replace(/\/+$/,"");if(Z)try{if(!(Ae.getState().directories.get(Z)?.isGitRepo??await ze(()=>import("./useAppFontEffects-DkPuAMXD.js").then(W=>W.fc),__vite__mapDeps([0,1,2,3])).then(W=>W.checkIsGitRepository(Z))))return;const v=await Yn({id:K.id,path:Z});if(C)return;B.set(Z,v)}catch{}})),C)return;const O=Array.from(B.values()).flat(),V=be.getState().availableWorktreesByProject;vo(B,V)||be.setState({availableWorktrees:O,availableWorktreesByProject:B})})(),()=>{C=!0}},[i,y]),c.useEffect(()=>{let C=!1;return(async()=>{const B=await gs("/health",{method:"GET"}).catch(()=>null);if(!B||!B.ok||C)return;const O=await B.json().catch(()=>null);if(!O||C)return;const V=O.planModeExperimentalEnabled;S(V===!0||V===1||V==="1"||V==="true")})(),()=>{C=!0}},[S]),c.useEffect(()=>{if(!m)return;const C=window.setTimeout(()=>p(),5e3);return()=>window.clearTimeout(C)},[p,m]),c.useEffect(()=>{if(!(!i&&(N?!!We():!0))){w(!1);return}const q=window.setTimeout(()=>w(!0),8e3);return()=>window.clearTimeout(q)},[i,N,P,D]),uo(),fo({enabled:!0}),ti(),mo(),si(),ll({enabled:N&&i}),el({ready:N&&i&&r});const G=$a(),M=!i&&o==="reconnecting";if(!G)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 J=!!We();return N&&(!J||!i&&!M)?J?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:!R}),R?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(pe,{type:"button",variant:"outline",onClick:()=>{jt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),I(C=>C+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):j!=="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(ho,{})]})]}):null]}):t.jsx(yl,{onConnected:()=>I(C=>C+1)}):!i&&!M?R?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(Oe,{children:t.jsx(po,{sdk:Bs.getSdkClient(),directory:f||"",children:t.jsx(go,{apis:s,children:t.jsx(bo,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[t.jsx(xo,{embeddedBackgroundWorkEnabled:r}),t.jsx(ni,{}),t.jsx(Si,{}),t.jsx(Pl,{onActiveConnectionDeleted:()=>{jt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),I(C=>C+1)}}),t.jsx(yo,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),r?t.jsx(ri,{}):null]})})})},D)})}const Tl=()=>{Fo(),Fr().then(()=>{Promise.all([$r(),$o()]).catch(s=>{console.error("[mobile-main] settings init failed:",s)}),Uo(),Wo(),Vo()}).catch(s=>{console.error("[mobile-main] appearance init failed:",s)}).finally(()=>{gi()})};function Ol(s){Mo(),Tl(),ki(),_o();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(Il,{apis:i});_r.createRoot(e).render(t.jsx(rs.StrictMode,{children:t.jsx(zo,{children:t.jsx(Lo,{children:t.jsx(Oo,{children:t.jsx(hi,{children:r?o:t.jsx(Bo,{children:o})})})})})}))}export{Ol as renderMobileApp};