@pi-chamber/web 1.0.4-rc.1 → 1.0.4-rc.4

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 (168) hide show
  1. package/dist/assets/DiagramView--BGR3PRZ.js +1 -0
  2. package/dist/assets/{DiffView-BjWUdbL5.js → DiffView-hz90_htv.js} +5 -5
  3. package/dist/assets/FileSaveConflictDialog-CcrWHRvd.js +3 -0
  4. package/dist/assets/{FilesView-qP1ypN9J.js → FilesView-DaqkPMqx.js} +4 -4
  5. package/dist/assets/{GitHubDetailScaffold-zCKCy5OJ.js → GitHubDetailScaffold-BZhP67Va.js} +2 -2
  6. package/dist/assets/GitHubLinkPicker-CJZmDljp.js +1 -0
  7. package/dist/assets/{GitHubListPrimitives-Ck3zllel.js → GitHubListPrimitives-DhF42guB.js} +1 -1
  8. package/dist/assets/{GitView-y2k2i4gR.js → GitView-JK-QCK9R.js} +4 -4
  9. package/dist/assets/{IssuesSurface-HWgR87N3.js → IssuesSurface-CAqQzrsv.js} +3 -3
  10. package/dist/assets/{JsonTreeView-DSuC4naV.js → JsonTreeView-CKTqB1CD.js} +1 -1
  11. package/dist/assets/MarkdownRendererImpl-B5kJy9Nt.js +12 -0
  12. package/dist/assets/{PatchDiff-DArTeWeK.js → PatchDiff-BQnRFN30.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-DQKujzLb.js → PierreDiffViewer-BeGpdI0x.js} +2 -2
  14. package/dist/assets/PullRequestsSurface-D9beq2x9.js +2 -0
  15. package/dist/assets/SessionSwitcherContent-DElQ_cjm.js +1 -0
  16. package/dist/assets/SessionSwitcherDropdown-JaIDcDIj.js +2 -0
  17. package/dist/assets/SessionUnreadDot-Czfvjbdi.js +1 -0
  18. package/dist/assets/SettingsView-C_GC1Mx3.js +6 -0
  19. package/dist/assets/SettingsWindow-CAxKgYOu.js +1 -0
  20. package/dist/assets/ToolOutputDialog-lz5exVQ4.js +8 -0
  21. package/dist/assets/ToolPartDiffPreview-nIUiNLpP.js +1 -0
  22. package/dist/assets/{VirtualizedFileDiff-D6KbvKc6.js → VirtualizedFileDiff-IWqCJNXu.js} +1 -1
  23. package/dist/assets/{Virtualizer-wpC51ZBQ.js → Virtualizer-Cp_cJWbI.js} +1 -1
  24. package/dist/assets/{collapsible-DhV9d4dT.js → collapsible-C7oyikVm.js} +1 -1
  25. package/dist/assets/{computeVirtualFileMetrics-CeMpF2xC.js → computeVirtualFileMetrics-CyhUKEfv.js} +1 -1
  26. package/dist/assets/{contextFileOpenGuard-Ck5u_kAP.js → contextFileOpenGuard-DkjmJ-NU.js} +1 -1
  27. package/dist/assets/{gitStatusPredicates-DEBSqUNE.js → gitStatusPredicates-DBmUY3kA.js} +1 -1
  28. package/dist/assets/{githubLink-DT7i2NlH.js → githubLink-BdbPMMAK.js} +5 -5
  29. package/dist/assets/index-BnZVqcki.js +11 -0
  30. package/dist/assets/index-BnieExes.css +1 -0
  31. package/dist/assets/index-CKgYIOis.js +1 -0
  32. package/dist/assets/{main-BczEScAA.js → main-6YKi4QM2.js} +2 -2
  33. package/dist/assets/{main-CHLNMYeJ.js → main-CWdWdhdL.js} +8 -8
  34. package/dist/assets/{markdownCore-C4Gk5Zht.js → markdownCore-D7V46WY9.js} +1 -1
  35. package/dist/assets/miniChat-PanPmbEK.js +2 -0
  36. package/dist/assets/mobile-0LY-2fxw.js +2 -0
  37. package/dist/assets/nativeFileSave-BzhtrDoD.js +1 -0
  38. package/dist/assets/{pi-session-focus-preference-LDVCJ_YR.js → pi-session-focus-preference-BC-ze1oC.js} +4 -4
  39. package/dist/assets/{renderDiffWithHighlighter-CDsgOnkH.js → renderDiffWithHighlighter-ByZtK9za.js} +1 -1
  40. package/dist/assets/renderElectronMiniChatApp-DETQLjFi.js +2 -0
  41. package/dist/assets/{renderFileWithHighlighter-TpKRyfCY.js → renderFileWithHighlighter-CnN0Tv_8.js} +1 -1
  42. package/dist/assets/renderMobileApp-DS0FDQLg.js +11 -0
  43. package/dist/assets/runtimeEndpointReset-BqqXMwE9.js +62 -0
  44. package/dist/assets/{runtimeSurface-DW_Ia4q3.js → runtimeSurface-DBiUWYK2.js} +1 -1
  45. package/dist/assets/useAppFontEffects-BisjofNZ.js +212 -0
  46. package/dist/assets/{useFilesViewSearch-C_LzYIgD.js → useFilesViewSearch-BWABG6pS.js} +3 -3
  47. package/dist/assets/{useGitHubRemoteSearch-DsxWOzKZ.js → useGitHubRemoteSearch-Bsf2YeQP.js} +1 -1
  48. package/dist/assets/{useSwitcherItems-BmoCnS9W.js → useSwitcherItems-BSTSev5C.js} +1 -1
  49. package/dist/assets/vendor-aparajita-capacitor-secure-storage-BYohCVY0.js +1 -0
  50. package/dist/assets/{vendor-base-ui-DIkTOIJS.js → vendor-base-ui-BscvGUFt.js} +1 -1
  51. package/dist/assets/vendor-boot-Dgb9NVFe.js +69 -0
  52. package/dist/assets/vendor-capacitor-app-BjdQVib9.js +1 -0
  53. package/dist/assets/vendor-capacitor-keyboard-eTtI5go3.js +1 -0
  54. package/dist/assets/vendor-capacitor-push-notifications-CBKq2Arn.js +1 -0
  55. package/dist/assets/vendor-capacitor-status-bar-9rNIGxlO.js +1 -0
  56. package/dist/assets/{vendor-codemirror-autocomplete-DsFn4GLp.js → vendor-codemirror-autocomplete-DxS3jwvE.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-angular-B_NMmBbS.js → vendor-codemirror-lang-angular-DdjXl9e2.js} +1 -1
  58. package/dist/assets/vendor-codemirror-lang-cpp--aMr7NVt.js +1 -0
  59. package/dist/assets/vendor-codemirror-lang-css-CZ_qxZY9.js +1 -0
  60. package/dist/assets/{vendor-codemirror-lang-go-C2KHbcll.js → vendor-codemirror-lang-go-Ca-y2Alu.js} +2 -2
  61. package/dist/assets/vendor-codemirror-lang-html-COZ0L5wT.js +1 -0
  62. package/dist/assets/vendor-codemirror-lang-java-D3Rf3QNJ.js +1 -0
  63. package/dist/assets/{vendor-codemirror-lang-javascript-DpTUrvx8.js → vendor-codemirror-lang-javascript-DwJ-IvCs.js} +2 -2
  64. package/dist/assets/vendor-codemirror-lang-jinja-D_5lod6k.js +1 -0
  65. package/dist/assets/vendor-codemirror-lang-json-BG8C7OpC.js +1 -0
  66. package/dist/assets/vendor-codemirror-lang-less-CVEkoaTw.js +1 -0
  67. package/dist/assets/vendor-codemirror-lang-liquid-U9vj0m8w.js +1 -0
  68. package/dist/assets/vendor-codemirror-lang-markdown-DqlYH9gY.js +1 -0
  69. package/dist/assets/vendor-codemirror-lang-php-BFEiEVA1.js +1 -0
  70. package/dist/assets/vendor-codemirror-lang-python-Cz1dQXQd.js +3 -0
  71. package/dist/assets/vendor-codemirror-lang-rust-C_CoD9mj.js +1 -0
  72. package/dist/assets/vendor-codemirror-lang-sass-BuR0aKh5.js +1 -0
  73. package/dist/assets/{vendor-codemirror-lang-sql-C_RazIaB.js → vendor-codemirror-lang-sql-DggNUjdM.js} +2 -2
  74. package/dist/assets/{vendor-codemirror-lang-vue-BYL0r7KR.js → vendor-codemirror-lang-vue-DFZHi2J3.js} +1 -1
  75. package/dist/assets/vendor-codemirror-lang-wast-zuTN3SHT.js +1 -0
  76. package/dist/assets/vendor-codemirror-lang-xml-CrcvhI-k.js +1 -0
  77. package/dist/assets/vendor-codemirror-lang-yaml-DcVWsakb.js +1 -0
  78. package/dist/assets/{vendor-codemirror-language-data-DglcKYWT.js → vendor-codemirror-language-data-CCLITgCF.js} +2 -2
  79. package/dist/assets/{vendor-codemirror-search-DaE6R5gH.js → vendor-codemirror-search-H7NOEdbX.js} +2 -2
  80. package/dist/assets/{vendor-lezer-cpp-Dt99h3WT.js → vendor-lezer-cpp-C8aD2KAr.js} +1 -1
  81. package/dist/assets/{vendor-lezer-css-DNU_fzPI.js → vendor-lezer-css-2lbTJF-Y.js} +1 -1
  82. package/dist/assets/{vendor-lezer-go-BEFtcNyS.js → vendor-lezer-go-Bw6LFTrZ.js} +1 -1
  83. package/dist/assets/{vendor-lezer-html-DDGRhRUz.js → vendor-lezer-html-D7ym2z7S.js} +1 -1
  84. package/dist/assets/{vendor-lezer-java-DmfZtW09.js → vendor-lezer-java-CZhK7w21.js} +1 -1
  85. package/dist/assets/{vendor-lezer-javascript-oje4tdp_.js → vendor-lezer-javascript-rpKeTHZp.js} +1 -1
  86. package/dist/assets/{vendor-lezer-json-BRXb_bDX.js → vendor-lezer-json-C7jwsd2G.js} +1 -1
  87. package/dist/assets/{vendor-lezer-lr-BU2qmu_5.js → vendor-lezer-lr-DR-ylqNN.js} +1 -1
  88. package/dist/assets/{vendor-lezer-markdown-CicYv7V9.js → vendor-lezer-markdown-Bir0m5nB.js} +1 -1
  89. package/dist/assets/{vendor-lezer-php-COORrTpE.js → vendor-lezer-php-y0hIEfo1.js} +1 -1
  90. package/dist/assets/{vendor-lezer-python-Cuvm9X9Y.js → vendor-lezer-python-D64A9lNV.js} +1 -1
  91. package/dist/assets/{vendor-lezer-rust-C_zOfHbX.js → vendor-lezer-rust-E3ZA9T2L.js} +1 -1
  92. package/dist/assets/{vendor-lezer-sass-DWP4w7O1.js → vendor-lezer-sass-C5UFI9SP.js} +1 -1
  93. package/dist/assets/{vendor-lezer-xml-Br6nOYeG.js → vendor-lezer-xml-DOy7FzCR.js} +1 -1
  94. package/dist/assets/{vendor-lezer-yaml-CYQmm6Sb.js → vendor-lezer-yaml-kEjaSCvZ.js} +1 -1
  95. package/dist/assets/{vendor-replit-codemirror-vim-CZy3BUVv.js → vendor-replit-codemirror-vim-BLfh0LPy.js} +1 -1
  96. package/dist/assets/{web-components-CH3-XV-n.js → web-components-CdMfsnXE.js} +1 -1
  97. package/dist/index.html +4 -4
  98. package/dist/mini-chat.html +3 -3
  99. package/dist/mobile.html +3 -3
  100. package/package.json +2 -2
  101. package/server/lib/pi/routes.js +1 -0
  102. package/server/lib/pi/session-daemon/DOCUMENTATION.md +22 -9
  103. package/server/lib/pi/session-daemon/builtin-extensions.js +37 -0
  104. package/server/lib/pi/session-daemon/daemon-process.js +6 -0
  105. package/server/lib/pi/session-daemon/extension-theme.js +75 -0
  106. package/server/lib/pi/session-daemon/extension-theme.test.js +47 -0
  107. package/server/lib/pi/session-daemon/prompt-operations.test.js +3 -3
  108. package/server/lib/pi/session-daemon/prompt-preflight.test.js +12 -14
  109. package/server/lib/pi/session-daemon/sdk-upgrade.test.js +118 -2
  110. package/server/lib/pi/session-daemon/send-operation-dedup.test.js +1 -1
  111. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +1 -1
  112. package/server/lib/pi/session-daemon/session-daemon-mcp.e2e.test.js +638 -0
  113. package/server/lib/pi/session-daemon/session-daemon-turn.e2e.test.js +437 -0
  114. package/server/lib/pi/session-daemon/session-daemon.js +61 -42
  115. package/server/lib/pi/session-daemon/session-daemon.test.js +53 -5
  116. package/server/lib/pi/session-daemon/session-idle-residency.test.js +1 -1
  117. package/server/lib/pi/session-daemon/session-replay.test.js +1 -1
  118. package/server/lib/pi/session-daemon/supervisor.js +13 -1
  119. package/server/lib/pi/session-daemon/supervisor.test.js +92 -0
  120. package/server/lib/pi/session-persistence-gap.test.js +2 -3
  121. package/server/lib/pi/ui-settings-store.js +1 -0
  122. package/server/lib/pi/ui-settings-store.test.js +27 -0
  123. package/server/lib/relay/DOCUMENTATION.md +4 -0
  124. package/server/lib/terminal/DOCUMENTATION.md +1 -0
  125. package/dist/assets/DiagramView-DfZMQkXY.js +0 -1
  126. package/dist/assets/FileSaveConflictDialog-u5L4k_5k.js +0 -3
  127. package/dist/assets/GitHubLinkPicker-CwxKY3lN.js +0 -1
  128. package/dist/assets/MarkdownRendererImpl-CT5ln9em.js +0 -12
  129. package/dist/assets/PullRequestsSurface-Cfb1wSvC.js +0 -2
  130. package/dist/assets/SessionSwitcherContent-DEGJyZBl.js +0 -1
  131. package/dist/assets/SessionSwitcherDropdown-cC9wVBH7.js +0 -2
  132. package/dist/assets/SessionUnreadDot-CELKNVIM.js +0 -1
  133. package/dist/assets/SettingsView-CZvRRgJe.js +0 -6
  134. package/dist/assets/SettingsWindow-CZM1dmVb.js +0 -1
  135. package/dist/assets/ToolOutputDialog-DClOSbJc.js +0 -8
  136. package/dist/assets/ToolPartDiffPreview-BaFiGUDE.js +0 -1
  137. package/dist/assets/index-6IO1AcJI.js +0 -10
  138. package/dist/assets/index-BAmzAlNx.css +0 -1
  139. package/dist/assets/index-eDf4LKLY.js +0 -1
  140. package/dist/assets/miniChat-Do3hE87Z.js +0 -2
  141. package/dist/assets/mobile-CTnihwfa.js +0 -2
  142. package/dist/assets/renderElectronMiniChatApp-DSa3gYqR.js +0 -2
  143. package/dist/assets/renderMobileApp-CPE-3uMl.js +0 -11
  144. package/dist/assets/runtimeEndpointReset-CzJfovWI.js +0 -62
  145. package/dist/assets/useAppFontEffects-CG3_yteE.js +0 -212
  146. package/dist/assets/vendor-aparajita-capacitor-secure-storage-5IShChL0.js +0 -1
  147. package/dist/assets/vendor-boot-DyL2td56.js +0 -69
  148. package/dist/assets/vendor-capacitor-app-BrDJj9I_.js +0 -1
  149. package/dist/assets/vendor-capacitor-core-B4EWRrHz.js +0 -1
  150. package/dist/assets/vendor-capacitor-keyboard-CYccoJjr.js +0 -1
  151. package/dist/assets/vendor-capacitor-push-notifications-KNe1zSBF.js +0 -1
  152. package/dist/assets/vendor-capacitor-status-bar-B-N0EOVk.js +0 -1
  153. package/dist/assets/vendor-codemirror-lang-cpp-GOE7Gjd0.js +0 -1
  154. package/dist/assets/vendor-codemirror-lang-css-Dwf2XpnZ.js +0 -1
  155. package/dist/assets/vendor-codemirror-lang-html-DcKqyeGk.js +0 -1
  156. package/dist/assets/vendor-codemirror-lang-java-6eGbyB2k.js +0 -1
  157. package/dist/assets/vendor-codemirror-lang-jinja-xSUJjXhr.js +0 -1
  158. package/dist/assets/vendor-codemirror-lang-json-CLGxdOCz.js +0 -1
  159. package/dist/assets/vendor-codemirror-lang-less-6nXi1rS9.js +0 -1
  160. package/dist/assets/vendor-codemirror-lang-liquid-B9hmb9P8.js +0 -1
  161. package/dist/assets/vendor-codemirror-lang-markdown-DmFP9s6x.js +0 -1
  162. package/dist/assets/vendor-codemirror-lang-php-DC6To8iX.js +0 -1
  163. package/dist/assets/vendor-codemirror-lang-python-yuxIkjit.js +0 -3
  164. package/dist/assets/vendor-codemirror-lang-rust-di1Sjz-0.js +0 -1
  165. package/dist/assets/vendor-codemirror-lang-sass-BWpV9NPV.js +0 -1
  166. package/dist/assets/vendor-codemirror-lang-wast-BiVarhcz.js +0 -1
  167. package/dist/assets/vendor-codemirror-lang-xml-Cn1lY1ts.js +0 -1
  168. package/dist/assets/vendor-codemirror-lang-yaml-BZ6mZw9L.js +0 -1
@@ -0,0 +1,11 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-boot-Dgb9NVFe.js","assets/vendor-react-DASdDPIk.js","assets/vendor-clsx-B-dksMZM.js","assets/nativeFileSave-BzhtrDoD.js","assets/index-BnZVqcki.js","assets/vendor-zustand-CUi8eEds.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-BnieExes.css","assets/FilesView-DaqkPMqx.js","assets/useAppFontEffects-BisjofNZ.js","assets/runtimeSurface-DBiUWYK2.js","assets/vendor-codemirror-lang-javascript-DwJ-IvCs.js","assets/vendor-lezer-javascript-rpKeTHZp.js","assets/vendor-lezer-lr-DR-ylqNN.js","assets/vendor-codemirror-autocomplete-DxS3jwvE.js","assets/vendor-codemirror-lang-json-BG8C7OpC.js","assets/vendor-lezer-json-C7jwsd2G.js","assets/vendor-codemirror-lang-css-CZ_qxZY9.js","assets/vendor-lezer-css-2lbTJF-Y.js","assets/vendor-codemirror-lang-html-COZ0L5wT.js","assets/vendor-lezer-html-D7ym2z7S.js","assets/vendor-codemirror-lang-markdown-DqlYH9gY.js","assets/vendor-lezer-markdown-Bir0m5nB.js","assets/vendor-codemirror-language-data-CCLITgCF.js","assets/vendor-codemirror-lang-python-Cz1dQXQd.js","assets/vendor-lezer-python-D64A9lNV.js","assets/shell-CjFT_Tl9.js","assets/appThemeRegistry-gegrE2dq.js","assets/registerCustomTheme-DmolaWWZ.js","assets/themeResolver-yJ9XpNMI.js","assets/vendor-pierre-theming-Dgp7B_O4.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/FileSaveConflictDialog-CcrWHRvd.js","assets/vendor-react-drawio-Duu5LgQA.js","assets/runtimeEndpointReset-BqqXMwE9.js","assets/SessionUnreadDot-Czfvjbdi.js","assets/permissionStore-B9Hkrqny.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/vendor-xterm-xterm-css-DDGTF8rc.css","assets/useFilesViewSearch-BWABG6pS.js","assets/JsonTreeView-CKTqB1CD.js","assets/web-components-CdMfsnXE.js","assets/computeVirtualFileMetrics-CyhUKEfv.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/Virtualizer-Cp_cJWbI.js","assets/renderFileWithHighlighter-CnN0Tv_8.js","assets/vendor-codemirror-search-H7NOEdbX.js","assets/vendor-replit-codemirror-vim-BLfh0LPy.js","assets/GitView-JK-QCK9R.js","assets/gitStatusPredicates-DBmUY3kA.js","assets/GitHubDetailScaffold-BZhP67Va.js","assets/vendor-dompurify-r8glNMJW.js","assets/collapsible-C7oyikVm.js","assets/vendor-base-ui-BscvGUFt.js","assets/PierreDiffViewer-BeGpdI0x.js","assets/VirtualizedFileDiff-IWqCJNXu.js","assets/renderDiffWithHighlighter-ByZtK9za.js","assets/vendor-diff-C3JhlQdm.js","assets/PullRequestsSurface-D9beq2x9.js","assets/useGitHubRemoteSearch-Bsf2YeQP.js","assets/GitHubListPrimitives-DhF42guB.js","assets/IssuesSurface-CAqQzrsv.js","assets/githubLink-BdbPMMAK.js","assets/vendor-capacitor-app-BjdQVib9.js","assets/vendor-capacitor-push-notifications-CBKq2Arn.js"])))=>i.map(i=>d[i]);
2
+ import{k as n,C as ws,aL as He,aM as gt,aN as ks}from"./vendor-boot-Dgb9NVFe.js";import{a as Et,R as a}from"./vendor-react-DASdDPIk.js";/* empty css */import{a as pe,b as Nn,d as qt,e as lt,i as Y,f as Ze,h as se,s as Ie,r as me,j as Ss,k as et,l as Pn,m as In,p as Cs,n as js,o as W,u as An,q as Es,t as Ae,v as Rs,w as Rt,x as Ts,y as Ns,z as Jt,A as Ps,B as _n,C as Is,D as As}from"./index-BnZVqcki.js";import{f as _s,u as Ds,a as Ms,s as Ls}from"./pi-session-focus-preference-BC-ze1oC.js";import{u as Os,M as zs,a as Us,i as Bs,D as Yt,b as Qt,c as Zt,g as $s,d as en,e as Ws,s as Ks,S as Hs,f as Fs,T as Vs,h as tn,j as nn,k as Gs,r as Xs,l as qs,m as Js,n as Ys,H as Qs,A as Zs,C as er,o as tr,p as nr,q as sr,F as rr,t as ar,v as ir,W as or,w as lr,x as cr}from"./runtimeEndpointReset-BqqXMwE9.js";import{g as qe,l as ur,u as dr,a as Dn,b as fr,c as pr,r as Mn,d as hr,e as We,t as xt,o as mr,I as F,f as At,B as oe,P as Ee,h as ye,i as yr,j as br,k as gr,m as xr,E as fe,C as at,n as Ln,p as vr,q as wr,s as sn,v as kr,w as Sr,x as Cr,y as jr,z as Er,A as Rr,D as Tr,F as Nr,G as Pr,H as je,J as Ir,K as Pe,L as Ar,M as _r,N as Dr,O as Mr,Q as Lr,R as Or,S as zr,T as Ur,U as Br,W as $r,V as Wr,X as Kr,Y as Hr,Z as Fr,_ as Vr,$ as Gr,a0 as Xr,a1 as qr,a2 as Jr,a3 as Yr}from"./useAppFontEffects-BisjofNZ.js";import{p as Qr}from"./vendor-aparajita-capacitor-secure-storage-BYohCVY0.js";import{_ as Se}from"./vendor-vite-runtime-DD1OZmLC.js";import{S as Zr,A as ea}from"./SettingsView-C_GC1Mx3.js";import{f as ta,S as na,a as sa,g as On}from"./SessionUnreadDot-Czfvjbdi.js";import{u as ra}from"./useSwitcherItems-BSTSev5C.js";let zn=null,rn=!1;const aa=new Promise(e=>{zn=e});function ia(){rn||(rn=!0,zn?.())}const oa=6,la=e=>e.parentID??null,an=e=>{const t=e.replace(/\/+$/,"");return t.slice(t.lastIndexOf("/")+1)||t},ca=e=>e.replace(/\\/g,"/").replace(/\/+$/,""),ua=(e,t)=>{if(!e)return"";let s=null,r=-1;for(const l of t){const i=ca(l.path);(e===i||e.startsWith(`${i}/`))&&i.length>r&&(s=l,r=i.length)}return s?s.label?.trim()||an(s.path):an(e)},da=()=>{const e=qe().getState().catalog,t=[];for(const d of e.byId.values())d.archived||t.push(ur(d));const s=dr.getState().index.session.unseenCount,r=Dn.getState().projects,l=fr.getState().ids,i=pr.getState().rankById;let o=0;const c=[];for(const d of t){const h=la(d)!==null,S=(s[d.id]??0)>0;S&&(o+=1),h||c.push({session:d,unread:S,project:ua(Mn(d),r)})}c.sort(hr(l,i,d=>d.session));const u=c.slice(0,oa).map(({session:d,unread:h,project:m})=>({id:d.id,title:d.title??"",unread:h,project:m}));return{runtimeKey:pe(),attentionCount:o,recentSessions:u}},fa="__PICHAMBER_WIDGET_SNAPSHOT__",pa=()=>{typeof window>"u"||(window[fa]=()=>{try{return JSON.stringify(da())}catch{return null}})},vt="mobile-app-update-available",on="mobile-app-update-toast-dismissed-version",ha=()=>{const e=We(i=>i.available),t=We(i=>i.runtimeType),s=We(i=>i.info?.version),r=We(i=>i.info?.downloadUrl),l=Et.useRef(new Set);return Et.useEffect(()=>{if(Nn()!=="android"||t!=="mobile"||!e||!s||!r){xt.dismiss(vt);return}qt().getItem(on)!==s&&(l.current.has(s)||(l.current.add(s),xt.info("PiChamber update available",{id:vt,description:`Version ${s} is ready for Android.`,duration:1/0,icon:n.jsx(F,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:"Download",onClick:()=>{mr(r)}},cancel:{label:"Dismiss",onClick:()=>{qt().setItem(on,s),xt.dismiss(vt)}}})))},[e,r,t,s]),null},ma=e=>{const{persisted:t,persistedDirectory:s,stale:r,ready:l,catalog:i,runtimeKey:o,capturedRuntimeKey:c,storeIdentityMatches:u,generationMatches:d}=e;if(!t||!s)return{action:"wait"};if(r||o!==c||!u||!d)return{action:"wait"};if(!l||!i)return{action:"wait"};const h=i.byId.get(t.sessionId);return!h||h.archived?{action:"clear"}:{action:"select",sessionId:h.id,directory:h.directory??s}},ct="pichamber.mobile.connections.v1",ya="pichamber.mobile.",ln="pichamber.mobile.deviceId",Un=12,Bn=8e3,ba=2500,ga=5e3,$n=2500,Fe=15e3,Wn=8e3,xa=1500,va=5e3,wa=()=>{try{const e=window.localStorage.getItem(ln);if(e&&e.trim())return e.trim();const t=lt();return window.localStorage.setItem(ln,t),t}catch{return lt()}},cn=()=>`mobile:${wa()}`,un=()=>{try{const e=ws.getPlatform();return e==="ios"||e==="android"?e:void 0}catch{return}},Kn=()=>{let e=0;return{begin:()=>(e+=1,e),cancel:()=>{e+=1},isCurrent:t=>t===e}},Ue=e=>{const t=e.trim();if(!t)return"";const s=/^https?:\/\//i.test(t)?t:`http://${t}`,r=new URL(s);return r.hash="",r.search="",r.pathname=r.pathname.replace(/\/+$/,""),r.toString().replace(/\/+$/,"")},Qe=e=>{try{return new URL(e).host}catch{return e}},Ve=e=>{try{return Ue(e)}catch{return e.trim().replace(/\/+$/g,"")}},_t=(e,t)=>Ve(e)===Ve(t),Dt=e=>`relay:${e.serverId}@${e.relayUrl.trim()}`,ka=e=>`relay://${e.serverId}`,pt=e=>e.candidates.filter(t=>t.kind==="direct"),Oe=e=>{const t=e.candidates.find(s=>s.kind==="relay");return t&&t.kind==="relay"?t.relay:null},xe=e=>{const t=pt(e)[0];if(t)return t.url;const s=Oe(e);return s?ka(s):""},J=e=>{const t=Oe(e);if(t)return Dt(t);const s=pt(e)[0];return s?Ve(s.url):""},ut=(e,t)=>{const s=e.find(i=>i.kind==="relay"),r=s&&s.kind==="relay"?s.relay.serverId:null,l=new Set(e.filter(i=>i.kind==="direct").map(i=>Ve(i.url)));return t.some(i=>i.kind==="relay"?r!==null&&i.relay.serverId===r:l.has(Ve(i.url)))},Mt=e=>{const t=(()=>{try{return Ue(e)}catch{return""}})();return t?[{kind:"direct",url:t}]:[]},dn=e=>{if(e.candidates&&e.candidates.length>0)return e.candidates;const t=[];return typeof e.url=="string"&&e.url.trim()&&!/^relay:\/\//i.test(e.url.trim())&&t.push(...Mt(e.url)),e.relay&&t.push({kind:"relay",relay:e.relay}),t},Lt=e=>{if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e;if(typeof t.relayUrl!="string"||!t.relayUrl.trim()||typeof t.serverId!="string"||!t.serverId.trim())return null;const s=t.hostEncPubJwk;if(!s||typeof s!="object"||Array.isArray(s))return null;const r=s;return r.kty!=="EC"||r.crv!=="P-256"||typeof r.x!="string"||!r.x||typeof r.y!="string"||!r.y?null:{relayUrl:t.relayUrl,serverId:t.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:r.x,y:r.y}}},Sa=e=>{if(!e||typeof e!="object")return null;const t=e;if(t.kind==="direct")return typeof t.url=="string"&&t.url.trim()?{kind:"direct",url:t.url}:null;if(t.kind==="relay"){const s=Lt(t.relay);return s?{kind:"relay",relay:s}:null}return null},Ca=e=>{if(e.mode==="relay"){const t=Lt(e.relay);return t?[{kind:"relay",relay:t}]:[]}return typeof e.url=="string"?Mt(e.url):[]},tt=e=>e.kind==="relay"?{kind:"relay",relay:{relayUrl:e.relay.relayUrl,serverId:e.relay.serverId,hostEncPubJwk:e.relay.hostEncPubJwk}}:{kind:"direct",url:e.url},Be=()=>{if(typeof window>"u")return[];let e;try{e=JSON.parse(window.localStorage.getItem(ct)||"[]")}catch{return[]}if(!Array.isArray(e))return[];const t=Y();return e.flatMap(s=>{if(!s||typeof s!="object")return[];const r=s;if(typeof r.id!="string")return[];const l=Array.isArray(r.candidates)?r.candidates.map(Sa).filter(u=>!!u):Ca(r);if(l.length===0)return[];const i=typeof r.clientToken=="string"&&r.clientToken.trim()?r.clientToken:void 0,o=typeof r.label=="string"&&r.label.trim()?r.label:Qe(xe({candidates:l})),c={id:r.id,label:o,candidates:l,lastUsedAt:typeof r.lastUsedAt=="number"?r.lastUsedAt:0};return t?[{...c,hasToken:!!r.hasToken||!!i}]:[{...c,clientToken:i,hasToken:!!i}]}).sort((s,r)=>r.lastUsedAt-s.lastUsedAt)},Ot=e=>{if(typeof window>"u")return;const t=Y(),s=e.slice(0,Un).map(r=>{const l={id:r.id,label:r.label,candidates:r.candidates.map(tt),lastUsedAt:r.lastUsedAt};return t?{...l,hasToken:!!(r.hasToken||r.clientToken)}:{...l,clientToken:r.clientToken}});try{window.localStorage.setItem(ct,JSON.stringify(s))}catch(r){console.warn("[mobile-storage] failed to persist connection metadata",r)}},Hn=(e,t)=>{const s=e.find(i=>t.id&&i.id===t.id||ut(i.candidates,t.candidates)),r=Y(),l={id:t.id||s?.id||lt(),label:t.label,candidates:t.candidates,lastUsedAt:Date.now(),...r?{hasToken:t.hasToken??(!!t.clientToken||s?.hasToken||!1)}:{clientToken:t.clientToken??s?.clientToken,hasToken:!!(t.clientToken??s?.clientToken)}};return[l,...e.filter(i=>i.id!==l.id&&!ut(i.candidates,t.candidates))].slice(0,Un)},zt=Qr,ja=0,nt=new Map,Ut=e=>`${ya}token.${encodeURIComponent(e)}`,Fn=async(e,t)=>{let s;const r=new Promise(l=>{s=window.setTimeout(()=>l(t),ga)});try{return await Promise.race([e.catch(()=>t),r])}finally{s!==void 0&&window.clearTimeout(s)}},Vn=async(e,t,s)=>Y()?Fn(t().catch(r=>(console.warn(`[mobile-storage] ${e} failed`,r),s)),s):s,Ea=e=>{if(!e||typeof e!="object")return!1;const{code:t,message:s}=e;return t==="invalidData"?!0:typeof s=="string"&&/AEADBadTagException|BadPaddingException/.test(s)},st=async(e,t)=>{const s=t?.bypassCache?void 0:nt.get(e);if(typeof s=="string"&&s)return{status:"present",token:s};if(!Y())return{status:"absent"};const r=await Fn(zt.internalGetItem({prefixedKey:Ut(e),sync:!1}).then(i=>({kind:"ok",data:i?.data??null})).catch(i=>({kind:"error",error:i})),{kind:"timeout"});if(r.kind==="timeout")return console.warn("[mobile-storage] secure:read timed out"),{status:"failure"};if(r.kind==="error")return Ea(r.error)?(console.warn("[mobile-storage] secure:read undecryptable entry"),{status:"absent"}):(console.warn("[mobile-storage] secure:read failed",r.error),{status:"failure"});const l=r.data;return typeof l=="string"&&l.trim()?(nt.set(e,l),{status:"present",token:l}):{status:"absent"}},_e=async(e,t)=>{if(!Y())return!1;const s=await Vn("secure:write",async()=>(await zt.internalSetItem({prefixedKey:Ut(e),data:t,sync:!1,access:ja}),!0),!1);return s&&t.trim()?nt.set(e,t):nt.delete(e),s},Ra=async e=>{nt.delete(e),await Vn("secure:delete",async()=>(await zt.internalRemoveItem({prefixedKey:Ut(e),sync:!1}),!0),!1)},Gn=async(e,t)=>{let s=0,r=0;return{records:await Promise.all(e.map(async i=>{if(!i||typeof i!="object")return i;const o=i,c=typeof o.url=="string"?o.url:null,u=typeof o.clientToken=="string"?o.clientToken.trim():"";if(!c||!u)return i;if(!await t(c,u))return r+=1,i;s+=1;const{clientToken:d,...h}=o;return{...h,hasToken:!0}})),migrated:s,failed:r}},Xn=async()=>{if(typeof window>"u"||!Y())return;let e;try{e=JSON.parse(window.localStorage.getItem(ct)||"[]")}catch{return}if(!Array.isArray(e)||e.filter(r=>!!r&&typeof r=="object"&&typeof r.url=="string"&&typeof r.clientToken=="string"&&!!r.clientToken.trim()).length===0)return;const s=await Gn(e,async(r,l)=>{const i=Ve(r);if(!await _e(i,l))return!1;const o=await st(i,{bypassCache:!0});return o.status==="present"&&o.token===l});if(s.migrated>0)try{window.localStorage.setItem(ct,JSON.stringify(s.records))}catch(r){console.warn("[mobile-storage] failed to finalize secure token migration",r)}},qn=async()=>(await Xn(),Be()),rt=async e=>{const t=Hn(Be(),e);return Ot(t),Y()&&e.clientToken&&await _e(J({candidates:e.candidates}),e.clientToken),t},Jn=async e=>{const t=Be(),s=t.find(l=>l.id===e)??null,r=t.filter(l=>l.id!==e);return Ot(r),s&&Y()&&await Ra(J(s)),r},Bt=e=>{try{return JSON.stringify(e)}catch{return String(e)}},Z=(e,t={})=>{console.info("[mobile-connect]",e,Bt(t)),me("connect",{code:e,status:typeof t.status=="number"?t.status:void 0,detail:typeof t.reason=="string"?t.reason:typeof t.result=="string"?t.result:void 0})},Ta=e=>{if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}},Na=e=>{if(typeof e!="string")return e??void 0;try{return JSON.parse(e)}catch{return e}},Pa=async(e,t,s)=>{if(!Y())return null;const r=s?.timeoutMs??Bn;try{const{CapacitorHttp:l}=await Se(async()=>{const{CapacitorHttp:c}=await import("./vendor-boot-Dgb9NVFe.js").then(u=>u.cj);return{CapacitorHttp:c}},__vite__mapDeps([0,1,2])),i=Object.fromEntries(new Headers(t?.headers).entries()),o=await l.request({url:e,method:t?.method||"GET",headers:i,data:Na(t?.body),connectTimeout:r,readTimeout:r});return{ok:o.status>=200&&o.status<300,status:o.status,source:"native-http",json:async()=>Ta(o.data)}}catch(l){return console.warn("[mobile-connect]","native-http failed",Bt({url:e,error:l instanceof Error?l.message:String(l)})),null}},Ia=async(e,t)=>{const s=await fetch(e,t).catch(r=>(console.warn("[mobile-connect]","browser-fetch failed",Bt({url:e,error:r instanceof Error?r.message:String(r)})),null));return s?{ok:s.ok,status:s.status,source:"browser-fetch",json:()=>s.json()}:null},Re=async(e,t,s)=>{let r;const l=new Promise(i=>{r=window.setTimeout(()=>{s?.(),i(null)},e)});try{return await Promise.race([t,l])}catch{return null}finally{r!==void 0&&window.clearTimeout(r)}},ze=async(e,t,s)=>{const r=s?.totalTimeoutMs??Bn,l=Date.now(),i=Math.min(ba,r),o=await Re(i,Pa(e,t,{timeoutMs:i}));if(o)return o;const c=new AbortController,u=Math.max(500,r-(Date.now()-l));return Re(u,Ia(e,{...t,signal:c.signal}),()=>c.abort())},ht=async e=>{if(!e)return null;const t=await e.json().catch(()=>null);if(!t||typeof t!="object")return null;const s=t;return{authenticated:typeof s.authenticated=="boolean"?s.authenticated:void 0,disabled:typeof s.disabled=="boolean"?s.disabled:void 0,scope:typeof s.scope=="string"?s.scope:void 0}},Aa=async(e,t,s,r=Fe,l)=>{if(l?.shouldAbort?.())return{outcome:"unreachable"};const i=Pn({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk}),o=c=>c==="ok"&&l?.keepTunnel?{outcome:c,tunnel:i}:(i.close(),{outcome:c});try{const c=t?{Authorization:`Bearer ${t}`}:void 0,u=await Re(r,i.fetch("/auth/session",{headers:c}).catch(()=>null));if(Z("relay:session",{ok:u?.ok===!0,status:u?.status??null,hasToken:!!t}),!u)return o("unreachable");if(u.status===401)return o(t?"auth-failed":"needs-login");if(!u.ok&&u.status!==404)return o("auth-failed");const d=await ht(u);return d&&d.disabled!==!0&&d.authenticated===!1?o(t?"auth-failed":"needs-login"):o("ok")}catch(c){throw i.close(),c}},_a=(e,t,s,r,l)=>{const i=typeof window<"u"?window.location.origin:"",o={relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk,...s?{grant:s}:{}};l&&Ss(o,l),Ie({apiBaseUrl:i,clientToken:t,runtimeKey:r??Dt(e),relay:o})},dt=async(e,t,s)=>{const r=s?.shouldAbort,l=s?.fast?{totalTimeoutMs:$n}:void 0,i=Oe({candidates:e})?.serverId??null,o=e.find(h=>h.kind==="relay")??null,c=e.filter(h=>h.kind==="direct"),u=async()=>{for(const h of c){if(r?.())return{status:"unreachable"};const m=Ue(h.url)||h.url,S=t?{Authorization:`Bearer ${t}`}:void 0,k=await ze(`${m}/health`,{method:"GET"},l);if(r?.())return{status:"unreachable"};if(!k?.ok)continue;if(i){const I=await k.json().catch(()=>null),_=I&&typeof I=="object"?I.serverId:null;if(typeof _=="string"&&_&&_!==i){Z("probe:server-id-mismatch",{url:m});continue}}const w=await ze(`${m}/auth/session`,{method:"GET",credentials:t?"omit":"include",headers:S},l);if(r?.())return{status:"unreachable"};if(w?.status===401)return{status:"needs-login"};if(!w||!w.ok&&w.status!==404)continue;const T=await ht(w);if(T&&T.disabled!==!0&&T.authenticated===!1)return{status:"needs-login"};const A=T?.disabled===!0;return!t&&Y()&&!A&&T?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:m}}}return{status:"unreachable"}},d=async()=>{if(!o)return{status:"unreachable"};if(r?.())return{status:"unreachable"};const{outcome:h,tunnel:m}=await Aa(o.relay,t,void 0,s?.fast?Wn:void 0,{keepTunnel:!0,...r?{shouldAbort:r}:{}});return r?.()?(m?.close(),{status:"unreachable"}):h==="ok"?{status:"ok",transport:{kind:"relay",relay:o.relay,tunnel:m}}:h==="needs-login"||h==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return o?c.length===0?d():new Promise(h=>{let m=!1,S=!1,k,w=null,T=null;const A=p=>{p?.status==="ok"&&p.transport.kind==="relay"&&p.transport.tunnel?.close()},I=p=>{m||(m=!0,h(p))},_=()=>{S||m||r?.()||(k!==void 0&&(window.clearTimeout(k),k=void 0),d().then(p=>{if(T=p,m||S){A(p);return}if(p.status==="ok"||p.status==="needs-login"){I(p);return}w&&I(w)}))};u().then(p=>{if(w=p,!m){if(p.status==="ok"||p.status==="needs-login"){S=!0,k!==void 0&&window.clearTimeout(k),A(T),I(p);return}if(T){I(T);return}_()}}),k=window.setTimeout(_,xa)}):u()},Me=(e,t,s)=>{e.kind==="relay"?_a(e.relay,t,s?.grant,s?.runtimeKey,e.tunnel):Ie({apiBaseUrl:e.url,clientToken:t,runtimeKey:s?.runtimeKey}),ts()},De=()=>{const e=Be()[0];return e?.label?.trim()?e.label:null},ot=async()=>{const e=Ze(),t=`${pe()}|${se()}`,s=()=>Ze()!==e||`${pe()}|${se()}`!==t;if(await Xn(),s())return{status:"no-candidate"};const r=Be()[0];if(!r)return{status:"no-candidate"};let l;if(Y()){if(!r.hasToken)return{status:"no-candidate"};const o=await st(J(r));if(o.status==="failure")return{status:"unreachable",label:r.label};if(o.status==="absent"||!o.token)return{status:"needs-login",label:r.label};l=o.token}else if(l=r.clientToken,!l)return{status:"no-candidate"};const i=await dt(r.candidates,l,{fast:!0});return s()?(Nt(i),{status:"no-candidate"}):i.status==="needs-login"?{status:"needs-login",label:r.label}:i.status!=="ok"?{status:"unreachable",label:r.label}:(await rt({id:r.id,label:r.label,candidates:r.candidates}),s()?(ft(i.transport),{status:"no-candidate"}):(Me(i.transport,l,{runtimeKey:J(r)}),{status:"connected"}))},Yn=async(e,t)=>{let s="";try{s=Ue(e.url)}catch{return!1}if(!s)return!1;const r=e.clientToken?.trim()||void 0,l=r?{Authorization:`Bearer ${r}`}:void 0,i=t?.fast?{totalTimeoutMs:$n}:void 0;if(!(await ze(`${s}/health`,{method:"GET",headers:l},i))?.ok)return!1;const c=await ze(`${s}/auth/session`,{method:"GET",credentials:r?"omit":"include",headers:l},i);if(!c||!c.ok&&c.status!==404)return!1;const u=await ht(c);return!(u&&u.disabled!==!0&&u.authenticated===!1)},fn=async e=>{const t=Oe({candidates:e})?.serverId??null;for(const s of e){if(s.kind==="relay"){const i=Pn(s.relay),o=await Re(Fe,i.fetch("/health").catch(()=>null));if(Z("establish:relay:health",{ok:o?.ok===!0,status:o?.status??null}),o?.ok)return{kind:"relay",relay:s.relay,tunnel:i};i.close();continue}const r=Ue(s.url)||s.url,l=await ze(`${r}/health`,{method:"GET"});if(Z("establish:direct:health",{ok:l?.ok===!0,status:l?.status??null}),!!l?.ok){if(t){const i=await l.json().catch(()=>null),o=i&&typeof i=="object"?i.serverId:null;if(typeof o=="string"&&o&&o!==t){Z("establish:server-id-mismatch",{url:r});continue}}return{kind:"direct",url:r}}}return null},Da=e=>[...e].sort((t,s)=>{const r=(t.priority??100)-(s.priority??100);if(r!==0)return r;const l=i=>i.type==="relay"?2:i.url.startsWith("https://")?0:1;return l(t)-l(s)}).flatMap(t=>{if(t.type==="relay"){const s=Lt({relayUrl:t.relayUrl,serverId:t.serverId,hostEncPubJwk:t.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return Mt(t.url)}),Qn=async(e,t)=>{if(!et())return Yn(e,t);const s=await Re(t?.fast?Wn:Fe,In("/auth/session").then(l=>l).catch(()=>null));if(!s||!s.ok&&s.status!==404)return!1;const r=await ht(s);return!(r&&r.disabled!==!0&&r.authenticated===!1)},Ma=e=>e.kind==="relay"?et():!et()&&_t(e.url,se()),mt=()=>{const e=pe();return e?Be().find(t=>J(t)===e)??null:null},Tt=e=>{const t=pe();return!!t&&J(e)===t},$t=e=>({generation:Ze(),runtimeKey:pe(),apiBaseUrl:se(),connectionId:e.id,secureKey:J(e),candidatesJson:JSON.stringify(e.candidates.map(tt))}),Zn=e=>{if(Ze()!==e.generation||pe()!==e.runtimeKey||se()!==e.apiBaseUrl)return!0;const t=mt();if(!t||t.id!==e.connectionId||J(t)!==e.secureKey)return!0;try{if(JSON.stringify(t.candidates.map(tt))!==e.candidatesJson)return!0}catch{return!0}return!1},ft=e=>{try{e?.kind==="relay"&&e.tunnel?.close()}catch{}},Nt=e=>{e.status==="ok"&&ft(e.transport)},La=e=>e?`${e.generation}|${e.runtimeKey}|${e.apiBaseUrl}|${e.connectionId}|${e.secureKey}|${e.candidatesJson}`:`noselection|${Ze()}|${pe()}`;let Le=null,Pt="";const pn=(e,t)=>{const s=t.finally(()=>{Le===s&&(Le=null,Pt="")});return Le=s,Pt=e,s},wt=async()=>{const e=await Oa();return me("reprobe",{code:e}),e},Wt=()=>{const e=mt(),t=e?$t(e):null,s=La(t);if(Le&&Pt===s)return Le;if(Le){const l=Le.then(()=>wt(),()=>wt());return pn(s,l)}return pn(s,wt())},Oa=async()=>{const e=mt();if(!e)return"no-connection";const t=$t(e),s=()=>Zn(t);let r;if(Y()){if(e.hasToken){const d=await st(J(e));if(d.status==="present")r=d.token;else return s()?"no-connection":d.status==="absent"?"needs-login":"unreachable"}if(s())return"no-connection"}else r=e.clientToken;if(!r)return"unreachable";if(s())return"no-connection";const l=e.candidates.findIndex(d=>Ma(d.kind==="relay"?{kind:"relay",relay:d.relay}:{kind:"direct",url:d.url})),i=l>=0?e.candidates.slice(0,l):e.candidates,o=await dt(i,r,{fast:!0,shouldAbort:s});if(s())return Nt(o),"no-connection";if(o.status==="ok")return await rt({id:e.id,label:e.label,candidates:e.candidates}),s()?(ft(o.transport),"no-connection"):(Me(o.transport,r,{runtimeKey:J(e)}),"switched");if(o.status==="needs-login")return"needs-login";if(l>=0){if(s())return"no-connection";const d=await Qn({url:t.apiBaseUrl,clientToken:r},{fast:!0});if(s())return"no-connection";if(d)return ts(),"unchanged"}const c=l>=0?e.candidates.slice(l+1):[];if(c.length===0)return"unreachable";const u=await dt(c,r,{fast:!0,shouldAbort:s});return s()?(Nt(u),"no-connection"):u.status==="ok"?(await rt({id:e.id,label:e.label,candidates:e.candidates}),s()?(ft(u.transport),"no-connection"):(Me(u.transport,r,{runtimeKey:J(e)}),"switched")):u.status==="needs-login"?"needs-login":"unreachable"};let kt=!1;const es=async()=>{if(kt)return"skipped";const e=mt();if(!e)return Z("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const t=Oe(e);if(!t)return Z("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";const s=$t(e),r=()=>Zn(s);kt=!0;try{const l=await Re(Fe,In("/api/client-auth/connection/candidates").then(m=>m).catch(()=>null));if(!l?.ok)return Z("candidates:refresh-skip",{reason:"fetch-failed",status:l?.status??null}),"skipped";if(r())return Z("candidates:refresh-skip",{reason:"selection-changed"}),"skipped";const i=await l.json().catch(()=>null);if(!i||i.serverId!==t.serverId)return Z("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const o=Array.isArray(i.candidates)?i.candidates:[],c=[];for(const m of o){if(!m||typeof m!="object")continue;const S=m;if(!(S.type!=="lan"||typeof S.url!="string"))try{const k=Ue(S.url);k&&!c.includes(k)&&c.push(k)}catch{}}if(c.length===0)return Z("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const u=pt(e).filter(m=>m.url.startsWith("https://")),d=[...c.map(m=>({kind:"direct",url:m})),...u,{kind:"relay",relay:t}];return JSON.stringify(e.candidates.map(tt))===JSON.stringify(d.map(tt))?"unchanged":r()?(Z("candidates:refresh-skip",{reason:"selection-changed"}),"skipped"):(Z("candidates:refreshed",{lanCount:c.length}),await rt({id:e.id,label:e.label,candidates:d}),"updated")}finally{kt=!1}},ts=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const e=await es().catch(()=>"skipped");Z("candidates:refresh-result",{result:e}),e==="updated"&&et()&&await Wt().catch(()=>null)})()},va)},Kt=e=>{const[t,s]=a.useState(()=>Be()),[r,l]=a.useState(null),[i,o]=a.useState(null),[c,u]=a.useState(null),d=a.useRef(t),h=a.useRef(null),m=a.useRef(Kn()),S=a.useCallback(g=>{d.current=g,s(g)},[]),k=a.useCallback(g=>{h.current=g,l(g)},[]),w=a.useCallback(g=>{h.current===g&&(h.current=null,l(null))},[]);a.useEffect(()=>{let g=!1;return qn().then(E=>{g||S(E)}),()=>{g=!0}},[S]);const T=a.useCallback(g=>{const E=Hn(d.current,g);return S(E),Ot(E),E},[S]),A=a.useCallback(async g=>{o(null),k("connect");try{const E=dn(g);if(E.length===0){o("Enter a server URL.");return}const R=g.id?d.current.find(P=>P.id===g.id):d.current.find(P=>ut(P.candidates,E)),L=g.label?.trim()||R?.label||Qe(xe({candidates:E})),z=g.relayGrant;let D=g.clientToken?.trim()||void 0;const f=!!D;if(!D)if(Y()){if(R?.hasToken){const P=await st(J({candidates:E}));if(P.status==="present")D=P.token;else if(P.status==="failure"){o("Could not read saved credentials. Please try again.");return}}}else D=R?.clientToken;Z("connect:start",{candidates:E.map(P=>P.kind),hasToken:!!D});const M=await dt(E,D);if(Z("connect:probe",{status:M.status}),M.status==="unreachable"){o("Could not reach that PiChamber server.");return}if(M.status==="needs-login"){T({id:R?.id,label:L,candidates:E}),u({id:R?.id??lt(),label:L,candidates:E,relay:Oe({candidates:E})??void 0,relayGrant:z});return}D&&f&&Y()&&await _e(J({candidates:E}),D),T({id:R?.id,label:L,candidates:E,clientToken:D}),Me(M.transport,D??null,{runtimeKey:J({candidates:E}),grant:z}),e()}catch(E){console.warn("[mobile-connect] connect threw",E),o("That server URL is not valid.")}finally{w("connect")}},[k,w,e,T]),I=a.useCallback(async g=>{if(h.current==="pairing")return;o(null),k("pairing");const E=Da(g.candidates);let R=null,L=!1;try{if(R=await fn(E),!R){o("Could not reach that PiChamber server.");return}const z=JSON.stringify({pairingId:g.pairingId,secret:g.secret,clientLabel:"PiChamber Mobile",clientKind:"mobile",deviceName:"PiChamber Mobile",devicePlatform:un(),dedupeKey:cn()}),D={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:z},f=R.kind==="relay"?await Re(Fe,R.tunnel.fetch("/api/client-auth/pairing/redeem",D).catch(()=>null)):await ze(`${R.url}/api/client-auth/pairing/redeem`,D);if(!f?.ok){o("This server needs a password or client token.");return}const M=await f.json().catch(()=>null),P=typeof M?.clientToken=="string"?M.clientToken.trim():"";if(!P){o("This server needs a password or client token.");return}const B=typeof M?.server?.label=="string"?M.server.label:"",C=g.label||B||Qe(xe({candidates:E}));if(Y()&&!await _e(J({candidates:E}),P)){o("This server needs a password or client token.");return}T({label:C,candidates:E,clientToken:P}),Me(R.kind==="relay"?{kind:"relay",relay:R.relay,tunnel:R.tunnel}:{kind:"direct",url:R.url},P,{runtimeKey:J({candidates:E})}),L=R.kind==="relay",e()}catch(z){console.warn("[mobile-connect] pairing threw",z),o("This server needs a password or client token.")}finally{!L&&R?.kind==="relay"&&R.tunnel.close(),w("pairing")}},[k,w,e,T]),_=a.useCallback(async g=>{if(!c||!g.trim()||h.current==="password")return;o(null),k("password");const E=m.current.begin(),R=()=>m.current.isCurrent(E),{id:L,label:z,candidates:D}=c;let f=null,M=!1;try{if(f=await fn(D),!R())return;if(!f){o("Could not reach that PiChamber server.");return}const P={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:g,trustDevice:!0,issueClientToken:!0,clientLabel:"PiChamber Mobile",clientKind:"mobile",devicePlatform:un(),dedupeKey:cn()})};Z("password:start",{transport:f.kind});const B=f.kind==="relay"?await Re(Fe,f.tunnel.fetch("/auth/session",P).catch(()=>null)):await ze(`${f.url}/auth/session`,P);if(!R())return;if(Z("password:done",{ok:B?.ok===!0,status:B?.status??null}),!B?.ok){o("Could not unlock that server. Check the password.");return}const C=await B.json().catch(()=>null);if(!R())return;const O=typeof C?.clientToken=="string"?C.clientToken.trim():"";if(Z("password:token",{issued:!!O}),!O){if(f.kind==="direct"&&!Y()){T({id:L,label:z,candidates:D}),u(null),Me({kind:"direct",url:f.url},null,{runtimeKey:J({candidates:D})}),e();return}o("This server needs a password or client token.");return}if(Y()&&(!R()||(await _e(J({candidates:D}),O),!R()))||!R()||(T({id:L,label:z,candidates:D,clientToken:O}),u(null),Me(f.kind==="relay"?{kind:"relay",relay:f.relay,tunnel:f.tunnel}:{kind:"direct",url:f.url},O,{runtimeKey:J({candidates:D})}),M=f.kind==="relay",!R()))return;e()}catch(P){if(!R())return;console.warn("[mobile-connect] password threw",P),o("Could not unlock that server. Check the password.")}finally{!M&&f?.kind==="relay"&&f.tunnel.close(),R()&&w("password")}},[k,w,e,c,T]),p=a.useCallback(()=>{m.current.cancel(),w("password"),u(null),o(null)},[w]),y=a.useCallback(async g=>{o(null);let E=dn(g);const R=g.id?d.current.find(f=>f.id===g.id)??null:null;if(R){const f=E.filter(B=>B.kind==="direct"),M=pt(R).filter(B=>B.url.startsWith("https://")&&!f.some(C=>_t(C.url,B.url))),P=Oe(R);E=[...f,...M,...P?[{kind:"relay",relay:P}]:[]]}if(E.length===0)return o("Enter a server URL."),null;const L=g.clientToken?.trim()||void 0,z=g.label?.trim()||Qe(xe({candidates:E}));if(Y()){const f=J({candidates:E});if(L)await _e(f,L);else if(R?.hasToken){const M=J(R);if(M&&f&&M!==f){const P=await st(M);P.status==="present"&&await _e(f,P.token)}}}return T({id:g.id,label:z,candidates:E,clientToken:L}).find(f=>ut(f.candidates,E))??null},[T]),U=a.useCallback(async g=>{const E=d.current.find(L=>L.id===g)??null,R=await Jn(g);return S(R),E},[S]);return{connections:t,isBusy:r!==null,isPasswordBusy:r==="password",error:i,pendingConnection:c,connect:A,redeemPairingConnection:I,submitPassword:_,cancelPassword:p,saveConnection:y,removeConnection:U,setError:o}},zi=Object.freeze(Object.defineProperty({__proto__:null,autoConnectLastInstance:ot,connectionDisplayUrl:xe,createMobilePasswordOperationTracker:Kn,deleteMobileConnection:Jn,getAutoConnectTargetLabel:De,getConnectionLabel:Qe,isActiveRuntimeConnection:Tt,isSameConnectionUrl:_t,loadMobileConnections:qn,migrateLegacyInlineTokenRecords:Gn,normalizeConnectionUrl:Ue,refreshActiveConnectionCandidates:es,relayConnectionRuntimeKey:Dt,reprobeActiveConnection:Wt,upsertMobileConnection:rt,useMobileConnection:Kt,validateActiveRuntimeSession:Qn,validateMobileConnectionSession:Yn},Symbol.toStringTag,{value:"Module"})),ns=()=>{if(typeof window>"u")return null;const t=window.Capacitor?.Plugins?.BarcodeScanner;return t&&(typeof t.scan=="function"||typeof t.startScan=="function")?t:null},ss=()=>window.Capacitor?.getPlatform?.()==="android",rs=e=>{const t=e.trim();if(!t)return null;if(/^pichamber:\/\//i.test(t)){const s=Cs(t);return s?{pairing:s}:null}return/^https?:\/\//i.test(t)?{url:t}:null},as=(e,t)=>{const s=rs(e);if(!s&&t?.pairingStringFallback){const r=js(e);if(r)return{status:"pairing",pairing:r}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},za=async(e,t)=>{if(!e.startScan||!e.stopScan||!e.addListener)return{status:"unsupported"};if(t?.aborted)return{status:"cancelled"};let s,r,l=!1,i=()=>{};const o=new Promise(d=>{i=d}),c=d=>{l||(l=!0,i(d))},u=()=>c({status:"cancelled"});t?.addEventListener("abort",u,{once:!0});try{return(await Promise.allSettled([Promise.resolve(e.addListener("barcodesScanned",({barcodes:h})=>{const m=h?.[0],S=(m?.rawValue??m?.displayValue??"").trim();S&&c(as(S,{pairingStringFallback:!0}))})).then(h=>{s=h}),Promise.resolve(e.addListener("scanError",()=>c({status:"failed"}))).then(h=>{r=h})])).some(({status:h})=>h==="rejected")?c({status:"failed"}):l||e.startScan({formats:["QR_CODE"]}).catch(()=>c({status:"failed"})),await o}finally{t?.removeEventListener("abort",u),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(r?.remove()),e.stopScan()]),await is()}},hn=e=>{const t=e.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/);if(!t||t[4]!==void 0&&parseFloat(t[4])===0)return null;const s=parseInt(t[1],10).toString(16).padStart(2,"0"),r=parseInt(t[2],10).toString(16).padStart(2,"0"),l=parseInt(t[3],10).toString(16).padStart(2,"0");return`#${s}${r}${l}`},Ua=()=>typeof window>"u"||typeof window.getComputedStyle!="function"?null:hn(window.getComputedStyle(document.documentElement).backgroundColor)??(document.body?hn(window.getComputedStyle(document.body).backgroundColor):null),is=async()=>{if(!ss())return;const e=Ua();if(!e)return;const{setNativeWebViewBackground:t}=await Se(()=>import("./nativeFileSave-BzhtrDoD.js"),__vite__mapDeps([3,0,1,2,4,5,6,7,8,9])).catch(()=>({setNativeWebViewBackground:void 0}));await t?.(e)},It=()=>ns()!==null,os=async e=>{const t=ns();if(!t)return{status:"unsupported"};try{if(t.requestPermissions){const o=(await t.requestPermissions())?.camera;if(o&&o!=="granted"&&o!=="limited")return{status:"permission-denied"}}if(e?.signal?.aborted)return{status:"cancelled"};if(ss())return za(t,e?.signal);if(!t.scan)return{status:"unsupported"};const r=(await t.scan({formats:["QR_CODE"]}))?.barcodes?.[0],l=(r?.rawValue??r?.displayValue??"").trim();return l?as(l):{status:"cancelled"}}catch{return{status:"failed"}}},Ke={autoComplete:"off",autoCorrect:"off",spellCheck:!1},Je="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",ls=({onCancel:e})=>{const t=a.useRef(null);return At(a.useCallback(()=>(e(),!0),[e])),a.useLayoutEffect(()=>{const s={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},r={value:document.body.style.getPropertyValue("background-color"),priority:document.body.style.getPropertyPriority("background-color")};document.documentElement.style.setProperty("background-color","rgba(0, 0, 0, 0)","important"),document.body.style.setProperty("background-color","rgba(0, 0, 0, 0)","important");const l=new Map,i=c=>{!(c instanceof HTMLElement)||c===t.current||l.has(c)||(l.set(c,{opacity:c.style.opacity,pointerEvents:c.style.pointerEvents}),c.style.setProperty("opacity","0"),c.style.setProperty("pointer-events","none"))};Array.from(document.body.children).forEach(i);const o=new MutationObserver(c=>{c.forEach(u=>u.addedNodes.forEach(i))});return o.observe(document.body,{childList:!0}),()=>{o.disconnect(),l.forEach((c,u)=>{u.style.opacity=c.opacity,u.style.pointerEvents=c.pointerEvents}),s.value?document.documentElement.style.setProperty("background-color",s.value,s.priority):document.documentElement.style.removeProperty("background-color"),r.value?document.body.style.setProperty("background-color",r.value,r.priority):document.body.style.removeProperty("background-color"),is()}},[]),a.useEffect(()=>{const s=()=>{document.visibilityState==="hidden"&&e()};return document.addEventListener("visibilitychange",s),()=>document.removeEventListener("visibilitychange",s)},[e]),He.createPortal(n.jsxs("div",{ref:t,role:"dialog","aria-modal":"true","aria-label":"Scan QR code",className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[n.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),n.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:"On your computer, open «Add a device» to show a QR code, then scan it here."})]}),n.jsxs(oe,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:e,children:[n.jsx(F,{name:"close",className:"size-[18px]"}),"Cancel"]})]}),document.body)},cs=()=>He.createPortal(n.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[n.jsx(Ee,{width:96,height:96,isAnimated:!0}),n.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[n.jsx(F,{name:"loader-4",className:"size-[18px] animate-spin"}),n.jsx("span",{children:"Connecting..."})]})]}),document.body),Ba=({onConnected:e,notice:t=null})=>{const s=Kt(e),{connections:r,isBusy:l,isPasswordBusy:i,error:o,pendingConnection:c}=s,[u,d]=a.useState(""),[h,m]=a.useState(""),[S,k]=a.useState(""),[w,T]=a.useState(!1),[A,I]=a.useState(!1),_=a.useRef(null),p=a.useMemo(()=>It(),[]),[y,U]=a.useState(()=>!It()),[g,E]=a.useState(null),[R,L]=a.useState(""),z=a.useCallback(C=>{C.preventDefault(),s.connect({url:u,clientToken:S,label:h})},[S,s,h,u]),D=a.useCallback(C=>{if(/^pichamber:\/\//i.test(C.trim())){const O=rs(C);if(O){if("pairing"in O){s.redeemPairingConnection(O.pairing);return}d(O.url),O.label&&m(O.label),O.clientToken&&k(O.clientToken);return}}d(C)},[s]),f=a.useCallback(async()=>{if(_.current||l)return;s.setError(null),T(!0);const C=new AbortController;_.current=C;try{const O=await os({signal:C.signal});switch(_.current===C&&(_.current=null,T(!1)),O.status){case"ok":I(!0),d(O.url),O.label&&m(O.label),O.clientToken&&k(O.clientToken),await s.connect({url:O.url,clientToken:O.clientToken,label:O.label});break;case"pairing":I(!0),await s.redeemPairingConnection(O.pairing);break;case"permission-denied":s.setError("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":s.setError("That QR code is not an PiChamber connection code.");break;case"unsupported":s.setError("QR scanning is only available in the installed mobile app.");break;case"failed":s.setError("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{I(!1),_.current===C&&(_.current=null,T(!1))}},[s,l]);a.useEffect(()=>()=>_.current?.abort(),[]);const M=a.useCallback(C=>{C.preventDefault(),s.submitPassword(R)},[s,R]),P=a.useCallback(()=>{L(""),s.cancelPassword()},[s]),B=a.useCallback(()=>w?(_.current?.abort(),T(!1),!0):c?(P(),!0):y&&p?(U(!1),!0):!1,[P,w,y,c,p]);return At(B),n.jsxs(n.Fragment,{children:[w?n.jsx(ls,{onCancel:()=>_.current?.abort()}):null,A?n.jsx(cs,{}):null,n.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:n.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[n.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[n.jsx(Ee,{width:72,height:72,className:"size-[72px]"}),n.jsx("h1",{className:"typography-h2 text-foreground",children:"Connect to PiChamber"})]}),t?n.jsxs("div",{role:"status",className:"flex w-full items-center gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--status-warning)_35%,transparent)] bg-[color-mix(in_srgb,var(--status-warning)_10%,transparent)] px-3.5 py-3",children:[n.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-[color-mix(in_srgb,var(--status-warning)_16%,transparent)] text-[var(--status-warning)]",children:n.jsx(F,{name:t.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),n.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:t.kind==="auth-expired"?`Access to ${t.label} has expired or was revoked. Sign in again.`:`Couldn't reach ${t.label}. Check that the server is running.`})]}):null,c?n.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:M,children:[n.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[n.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:n.jsx(F,{name:"lock",className:"size-[18px]"})}),n.jsxs("div",{className:"min-w-0 text-left",children:[n.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),n.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.candidates.some(C=>C.kind==="direct")?xe(c):"via PiChamber Relay"})]})]}),n.jsx("input",{...Ke,value:R,onChange:C=>L(C.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:Je}),o?n.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null,n.jsx(oe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:i||!R.trim(),children:i?"Connecting...":"Unlock and connect"}),n.jsx(oe,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:P,children:"Use another server"})]}):n.jsxs("div",{className:"flex w-full flex-col gap-6",children:[p?n.jsxs("div",{className:"flex w-full flex-col gap-2",children:[n.jsxs(oe,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{f()},disabled:w||l,children:[n.jsx(F,{name:"scan-2",className:W("size-[18px]",w&&"animate-pulse")}),l?"Connecting...":"Scan QR code"]}),n.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:"On your computer, open «Add a device» to show a QR code, then scan it here."})]}):null,o&&!y?n.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null,r.length>0?n.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[n.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:"Saved connections"}),n.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(C=>{const O=g===C.id;return n.jsxs("button",{type:"button",disabled:l,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 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:()=>{E(C.id),s.connect({id:C.id,candidates:C.candidates,clientToken:C.clientToken,label:C.label}).finally(()=>E(null))},children:[n.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:n.jsx(F,{name:"server",className:"size-[18px]"})}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:C.label}),n.jsx("span",{className:W("block truncate typography-small",O?"text-foreground":"text-muted-foreground"),children:O?"Connecting...":C.candidates.some(G=>G.kind==="direct")?xe(C):"via PiChamber Relay"})]}),O?n.jsx(F,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):n.jsx(F,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},C.id)})})]}):null,n.jsxs("div",{className:"flex w-full flex-col",children:[p?n.jsxs("button",{type:"button",onClick:()=>U(C=>!C),"aria-expanded":y,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:[n.jsx("span",{children:"Connect by address"}),n.jsx(F,{name:"arrow-down-s",className:W("size-4 transition-transform duration-200",y&&"rotate-180")})]}):null,n.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:y?"1fr":"0fr"},children:n.jsx("div",{className:"min-h-0 overflow-hidden",children:n.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:z,children:[n.jsx("input",{...Ke,value:u,onChange:C=>D(C.target.value),placeholder:"http://192.168.1.74:2606","aria-label":"Server URL",type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:y?void 0:-1,className:W(Je,"text-center")}),n.jsx("input",{value:h,onChange:C=>m(C.target.value),placeholder:"Optional display name","aria-label":"Name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:y?void 0:-1,className:W(Je,"text-center")}),n.jsx("input",{...Ke,value:S,onChange:C=>k(C.target.value),placeholder:"Paste access token","aria-label":"Client token",tabIndex:y?void 0:-1,autoCapitalize:"none",className:W(Je,"text-center")}),n.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:"Only needed if your server requires a token instead of a password."}),o?n.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null,n.jsx(oe,{type:"submit",variant:p?"outline":"default",size:"lg",className:"h-12 w-full",disabled:l||w||!u.trim(),children:l?"Connecting...":"Connect"})]})})})]})]})]})})]})},$a=10,Wa=(e,t)=>On(e,t),Ka=({session:e,meta:t,active:s,onSelect:r})=>{const l=yr(e.id),i=br(e.id),o=l?.type??"idle",c=o==="busy"||o==="retry",u=!c&&i>0&&!s,d=gr(e.id,c),h=c&&d,m=ta(e.time?.updated??e.time?.created??0);return n.jsxs("button",{type:"button",className:W("flex w-full items-center gap-3 rounded-xl px-2.5 py-2 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",s&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]"),onClick:r,style:{touchAction:"manipulation"},children:[n.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[n.jsx("span",{className:W("block truncate typography-ui-label",s?"text-primary":"text-foreground"),children:Wa(e,"Untitled Session")}),t?n.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:t}):null]}),c?n.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-primary","aria-hidden":!0}):u?n.jsx(na,{label:"Session complete"}):null,h?n.jsx(sa,{sessionId:e.id,running:c,className:"typography-micro"}):u?null:m?n.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:m}):null]})},Ha=({open:e,onClose:t,anchorRef:s})=>{const{panelRef:r,wrapperRef:l,shouldRender:i,isExiting:o,anchorLeft:c,isPopover:u}=Os({open:e,onClose:t,anchorRef:s}),d=ye(w=>w.currentSessionId),h=ye(w=>w.setCurrentSession),m=Dn(w=>w.setActiveProjectIdOnly),S=ra(e||i,{maxParents:$a}),k=a.useCallback(w=>{h(w.id,Mn(w)),t()},[t,h]);return i?n.jsxs("div",{ref:l,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:[n.jsx("div",{ref:r,role:"dialog","aria-label":"Open session switcher",className:W("flex flex-col overflow-hidden rounded-[20px] border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",u?"absolute origin-top-left":"mx-3 mt-2",o?"pointer-events-none":"pointer-events-auto"),style:{animation:`${o?"session-switcher-out":"session-switcher-in"} ${o?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...u?{top:8,left:c??8,width:`min(${zs}px, calc(100% - 16px))`}:null},children:n.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:S.length===0?n.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:"No recent sessions"}):S.map(w=>{const T=w.node.session,A=[w.secondaryMeta?.projectLabel,w.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return n.jsx(Ka,{session:T,meta:A,active:T.id===d,onSelect:()=>{w.projectId&&m(w.projectId),k(T)}},T.id)})})}),n.jsx("style",{children:`
3
+ @keyframes session-switcher-in {
4
+ from { opacity: 0; transform: translateY(-8px) scale(0.985); }
5
+ to { opacity: 1; transform: translateY(0) scale(1); }
6
+ }
7
+ @keyframes session-switcher-out {
8
+ from { opacity: 1; transform: translateY(0) scale(1); }
9
+ to { opacity: 0; transform: translateY(-6px) scale(0.985); }
10
+ }
11
+ `})]}):null},Fa=({onOpenSessions:e,onOpenWorkspace:t,compactTitle:s=!1})=>{const[r,l]=a.useState(!1),[i,o]=a.useState(!1),c=a.useRef(null),u=An(p=>p.currentDirectory),d=ye(p=>p.currentSessionId),m=ye(a.useCallback(p=>d?p.getDirectoryForSession(d):null,[d]))||u,S=xr(d),k=ye(p=>!!p.newSessionDraft?.open),T=S?.title?.trim()||(d?On(S,"Untitled session"):"New session");a.useEffect(()=>{l(!1),o(!1)},[d,m]);const A=a.useCallback(()=>{l(!1),o(!1),e()},[e]),I=a.useCallback(p=>{l(y=>{const U=typeof p=="function"?p(y):p;return U&&o(!1),U})},[]),_=a.useCallback(()=>{o(p=>{const y=!p;return y&&l(!1),y})},[]);return n.jsxs(n.Fragment,{children:[n.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:n.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[n.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":"Open sessions and projects",onClick:A,style:{touchAction:"manipulation"},children:n.jsx(F,{name:"list-unordered",className:"size-5"})}),n.jsx("button",{ref:c,type:"button",className:W("flex h-10 min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",s?"shrink":"flex-1"),"aria-label":"Open session switcher","aria-haspopup":"dialog","aria-expanded":i,onClick:_,style:{touchAction:"manipulation"},children:n.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:T}),n.jsx(F,{name:"arrow-down-s",className:W("size-4 shrink-0 text-muted-foreground transition-transform duration-150",i&&"rotate-180")})]})}),s?n.jsx("div",{className:"min-w-0 flex-1"}):null,n.jsx(Us,{open:r,onOpenChange:I,currentSessionId:d,effectiveDirectory:m,isNewSessionDraftOpen:k}),n.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":"Open workspace panel",onClick:()=>{l(!1),o(!1),t()},style:{touchAction:"manipulation"},children:n.jsx(F,{name:"layout-right",className:"size-5"})})]})}),n.jsx(Ha,{open:i,onClose:()=>o(!1),anchorRef:c})]})},Va=({onActiveConnectionDeleted:e,onConnect:t})=>{const s=Kt(t),{connections:r,isBusy:l,isPasswordBusy:i,error:o,pendingConnection:c,connect:u,submitPassword:d,cancelPassword:h,saveConnection:m,removeConnection:S,setError:k}=s,[w,T]=a.useState(null),A=w?r.find(v=>v.id===w)??null:null,[I,_]=a.useState(null),[p,y]=a.useState(""),[U,g]=a.useState(""),[E,R]=a.useState(""),[L,z]=a.useState(""),[D,f]=a.useState(!1),[M,P]=a.useState(!1),[B,C]=a.useState(!1),[O,G]=a.useState(null),V=a.useRef(null),ee=a.useMemo(()=>It(),[]),[N,K]=a.useState(!1),[le,Ne]=a.useState(null),te=a.useCallback(()=>{T(null),y(""),g(""),R(""),k(null),K(!1)},[k]),ve=a.useCallback(v=>{v.preventDefault(),m({id:w??void 0,url:p,label:U,clientToken:E}).then($=>{$&&te()})},[E,w,U,te,m,p]),ce=a.useCallback(async()=>{if(V.current)return;k(null),f(!0);const v=new AbortController;V.current=v;try{const $=await os({signal:v.signal});switch(V.current===v&&(V.current=null,f(!1)),$.status){case"ok":y($.url),$.label&&g($.label),$.clientToken&&R($.clientToken),K(!0);break;case"pairing":P(!0),await s.redeemPairingConnection($.pairing);break;case"permission-denied":k("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":k("That QR code is not an PiChamber connection code.");break;case"unsupported":k("QR scanning is only available in the installed mobile app.");break;case"failed":k("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{P(!1),V.current===v&&(V.current=null,f(!1))}},[s,k]);a.useEffect(()=>()=>V.current?.abort(),[]);const ae=a.useCallback(v=>{v.preventDefault(),d(L)},[L,d]),we=a.useCallback(()=>{z(""),h()},[h]),x=a.useCallback(async()=>{if(!B){G(null),C(!0);try{const v=await Es();G(v==="copied"?"Diagnostics copied to the clipboard.":v==="downloaded"?"Diagnostics downloaded.":"Diagnostics ready to share.")}catch{G("Diagnostics export was cancelled or unavailable.")}finally{C(!1)}}},[B]),j=a.useCallback(v=>{_($=>$===v?null:v)},[]),H=a.useCallback(v=>{_(null),w===v&&te();const $=r.length===1;S(v).then(Q=>{Q&&($||Tt(Q))&&e()})},[r.length,w,e,S,te]),X=Je;return c?n.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:n.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:ae,children:n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[n.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:n.jsx(F,{name:"lock",className:"size-[18px]"})}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),n.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.candidates.some(v=>v.kind==="direct")?xe(c):"via PiChamber Relay"})]})]}),n.jsx("input",{...Ke,value:L,onChange:v=>z(v.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:X}),o?n.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:o}):null,n.jsx(oe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:i||!L.trim(),children:i?"Connecting...":"Unlock and connect"}),n.jsx(oe,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:we,children:"Use another server"})]})})}):n.jsxs(n.Fragment,{children:[D?n.jsx(ls,{onCancel:()=>V.current?.abort()}):null,M?n.jsx(cs,{}):null,n.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:n.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:n.jsxs("div",{className:"space-y-6",children:[r.length>0?n.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(v=>{const $=I===v.id,Q=Tt(v),q=le===v.id,Ce=q?"Connecting...":Q?et()?"Connected · Private relay":"Connected · Local network":v.candidates.some(ue=>ue.kind==="direct")?xe(v):"via PiChamber Relay";return n.jsxs("div",{className:W("flex items-center border-b border-border/70 transition-colors last:border-b-0",$&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[n.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:()=>{Q||(Ne(v.id),u({id:v.id,candidates:v.candidates,clientToken:v.clientToken,label:v.label}).finally(()=>Ne(null)))},disabled:l&&!q||$,children:[n.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[n.jsx(F,{name:"server",className:"size-[18px]"}),Q?n.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]}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:v.label}),n.jsx("span",{className:W("block truncate typography-small",Q&&!q?"text-[var(--status-success)]":"text-muted-foreground"),children:Ce})]}),q?n.jsx(F,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),n.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[$?n.jsxs("button",{type:"button","aria-label":`Confirm deleting ${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:()=>H(v.id),style:{touchAction:"manipulation"},children:[n.jsx(F,{name:"delete-bin",className:"size-[18px]"}),n.jsx("span",{className:"typography-ui-label",children:"Delete"})]}):v.candidates.some(ue=>ue.kind==="direct")?n.jsx("button",{type:"button","aria-label":"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:()=>{T(v.id),y(xe(v)),g(v.label),R(v.clientToken||""),k(null)},style:{touchAction:"manipulation"},children:n.jsx(F,{name:"edit",className:"size-[18px]"})}):null,n.jsx("button",{type:"button","aria-label":$?`Keep ${v.label}`:`Delete ${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:()=>j(v.id),style:{touchAction:"manipulation"},children:n.jsx(F,{name:$?"close":"delete-bin",className:"size-[18px]"})})]})]},v.id)})}):n.jsx("p",{className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:"No saved connections yet."}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs(oe,{type:"button",variant:"outline",size:"lg",className:"h-12 w-full",onClick:()=>{x()},disabled:B,children:[n.jsx(F,{name:"download",className:"size-[18px]"}),B?"Preparing diagnostics…":"Export diagnostics"]}),O?n.jsx("p",{className:"px-1 text-center typography-small text-muted-foreground",children:O}):null]}),!N&&!A?n.jsxs("div",{className:"space-y-2",children:[ee?n.jsxs(oe,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{ce()},disabled:D,children:[n.jsx(F,{name:"scan-2",className:W("size-[18px]",D&&"animate-pulse")}),"Scan QR code"]}):null,n.jsxs(oe,{type:"button",variant:ee?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{k(null),K(!0)},children:[n.jsx(F,{name:"add",className:"size-[18px]"}),"Add by address"]}),o?n.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null]}):n.jsxs("form",{className:"space-y-3",onSubmit:ve,children:[n.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[n.jsx("h3",{className:"typography-ui-label text-foreground",children:A?"Edit instance":"Add instance"}),n.jsx(oe,{type:"button",variant:"ghost",size:"xs",onClick:te,children:"Cancel"})]}),n.jsxs("label",{className:"block space-y-1.5",children:[n.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Server URL"}),n.jsx("input",{...Ke,value:p,onChange:v=>y(v.target.value),placeholder:"http://192.168.1.74:2606",type:"url",inputMode:"url",autoCapitalize:"none",className:X})]}),n.jsxs("label",{className:"block space-y-1.5",children:[n.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Name"}),n.jsx("input",{value:U,onChange:v=>g(v.target.value),placeholder:"Optional display name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:X})]}),n.jsxs("label",{className:"block space-y-1.5",children:[n.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Client token"}),n.jsx("input",{...Ke,value:E,onChange:v=>R(v.target.value),placeholder:"Paste access token",autoCapitalize:"none",className:X}),n.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:"Only needed if your server requires a token instead of a password."})]}),o?n.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:o}):null,n.jsx(oe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:A?"Save changes":"Save instance"})]})]})})})]})},Ge=320,Te="cubic-bezier(0.22, 1, 0.36, 1)",us=({side:e,enabled:t,open:s,drawerRef:r,scrimRef:l,onClose:i,widthRatio:o,prefersReducedMotion:c})=>{a.useEffect(()=>{if(!t||!s)return;const u=r.current,d=l.current;if(!u||!d)return;let h=!1,m=!1,S=!1,k=0,w=0,T=0,A=0;const I=c?0:Ge,_=e==="left"?"translateX(-100%)":"translateX(100%)",p=()=>({drawer:I?`transform ${I}ms ${Te}`:"none",scrim:I?`opacity ${I}ms ${Te}`:"none"}),y=()=>{const f=p();u.style.transition=f.drawer,d.style.transition=f.scrim,u.style.transform="none",d.style.opacity="1",d.style.pointerEvents="auto"},U=()=>{h=!1,m=!1,S=!1},g=()=>{if(!(h||m)){U();return}y(),U()},E=f=>{if(f.touches.length!==1){(h||m)&&g();return}if(Bs(f.target,u,{excludeInteractive:!1}))return;u.style.transition&&u.style.transition!=="none"&&(u.style.transition="none",d.style.transition="none");const M=f.touches[0];k=M.clientX,w=M.clientY,T=Date.now(),A=u.offsetWidth||window.innerWidth*o,A<10&&(A=window.innerWidth*o),h=!0,m=!1,S=!1},R=f=>{if(!h)return;if(f.touches.length!==1){g();return}const M=f.touches[0],P=M.clientX-k,B=M.clientY-w;if(!S){if(Math.abs(P)<Yt&&Math.abs(B)<Yt)return;if(Math.abs(B)>Math.abs(P)*Qt||!Zt(e,P)){h=!1;return}S=!0,m=!0,u.style.transition="none",d.style.transition="none"}if(!m)return;f.cancelable&&f.preventDefault();const C=en(e,P,A);u.style.transform=$s(e,C),d.style.opacity=String(C)},L=(f,M,P)=>{if(!h)return;const B=f-k,C=M-w,O=Math.max(1,Date.now()-T),G=en(e,B,A),V=Ks({side:e,dx:B,dy:C,dt:O,progress:G,isDragging:m}),ee=p();u.style.transition=ee.drawer,d.style.transition=ee.scrim,u.style.transform=V?_:"none",d.style.opacity=V?"0":"1",d.style.pointerEvents=V?"none":"auto",U(),V&&i()},z=f=>{const M=f.changedTouches[0];if(!M){g();return}const P=M.clientX-k,B=M.clientY-w,C=Math.abs(P)>=Ws&&Math.abs(B)<=Math.abs(P)*Qt&&Zt(e,P);h&&(m||C)&&f.cancelable&&f.preventDefault(),L(M.clientX,M.clientY)},D=()=>{g()};return u.addEventListener("touchstart",E,{passive:!0}),u.addEventListener("touchmove",R,{passive:!1}),u.addEventListener("touchend",z,{passive:!1}),u.addEventListener("touchcancel",D,{passive:!0}),()=>{try{g()}catch{}u.removeEventListener("touchstart",E),u.removeEventListener("touchmove",R),u.removeEventListener("touchend",z),u.removeEventListener("touchcancel",D)}},[r,t,i,s,c,l,e,o])},Ga=16,mn=a.memo(function({open:t,onOpenChange:s,variant:r="drawer",drawerRefExternal:l,scrimRefExternal:i,rootRefExternal:o}){const c=a.useRef(null),u=a.useCallback(()=>{const y=typeof document<"u"?document.activeElement:null;y instanceof HTMLElement&&c.current?.contains(y)&&y.blur(),s(!1)},[s]),[d,h]=a.useState(!1),m=a.useRef(null),S=a.useRef(null),k=l??m,w=i??S,T=a.useCallback(y=>{c.current=y,o&&(o.current=y)},[o]),A=a.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]);a.useEffect(()=>{const y=c.current;if(!y||t)return;const U=document.activeElement;U&&y.contains(U)&&U.blur()},[t]),a.useEffect(()=>{if(r!=="sidebar"){if(t){const y=window.setTimeout(()=>h(!0),A?0:Ga);return()=>window.clearTimeout(y)}h(!1)}},[t,A,r]),a.useEffect(()=>{if(r==="sidebar"||!t)return;const y=document.body.style.overflow;document.body.style.overflow="hidden";const U=g=>{g.key==="Escape"&&u()};return document.addEventListener("keydown",U),()=>{document.body.style.overflow=y,document.removeEventListener("keydown",U)}},[u,t,r]);const I=r==="sidebar",_=n.jsx(Hs,{mobileVariant:!I,isVisible:t,allowReselect:!0,onSessionSelected:I?void 0:u,onNavigateAway:I?void 0:u});if(us({side:"left",enabled:r==="drawer",open:t,drawerRef:k,scrimRef:w,onClose:u,widthRatio:.72,prefersReducedMotion:A}),r==="sidebar")return n.jsx("aside",{className:"relative flex h-full w-full flex-col bg-sidebar",children:_});if(typeof document>"u")return null;const p=A?0:Ge;return He.createPortal(n.jsxs("div",{ref:T,className:"fixed inset-0 z-50",inert:!t,style:{pointerEvents:t?"auto":"none"},"data-mobile-sessions-root":"true",children:[n.jsx("button",{ref:w,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close sessions",onClick:u,tabIndex:t?0:-1,style:{opacity:d?1:0,transition:`opacity ${p}ms ${Te}`},"data-mobile-sessions-scrim":"true"}),n.jsx("div",{ref:k,className:W("relative z-10 flex h-full w-[72%] max-w-[72%] flex-col bg-sidebar"),style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:d?"none":"translateX(-100%)",transition:p?`transform ${p}ms ${Te}`:"none",touchAction:"pan-x pan-y"},"data-mobile-sessions-drawer":"true",children:_})]}),document.body)}),yn="mobile-surface-root",St=16,it=200,Xa=()=>{if(typeof document>"u")return null;let e=document.getElementById(yn);return e||(e=document.createElement("div"),e.id=yn,document.body.appendChild(e)),e},Ct=({open:e,onClose:t,title:s,subtitle:r,trailing:l,disableEscapeDismiss:i=!1,headerless:o=!1,noHeaderBorder:c=!1,ariaLabel:u,variant:d="fullscreen",dialogAlign:h="chat",children:m})=>{const S=a.useRef(null),[k,w]=a.useState(!1),[T,A]=a.useState(!1),I=a.useRef(null),_=a.useRef(null),p=a.useRef(t);if(a.useEffect(()=>{p.current=t},[t]),typeof document<"u"&&!S.current&&(S.current=Xa()),a.useEffect(()=>{if(!e){w(!1);return}const g=window.setTimeout(()=>w(!0),St);return()=>window.clearTimeout(g)},[e]),a.useEffect(()=>{if(!e){A(!1);return}const g=window.setTimeout(()=>A(!0),St+it+80);return()=>window.clearTimeout(g)},[e]),a.useEffect(()=>{if(!e)return;const g=document.body.style.overflow;_.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const E=()=>{const z=I.current;if(!z)return;(z.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??z).focus({preventScroll:!0})},R=window.setTimeout(E,St),L=z=>{if(z.key==="Escape"&&!i){p.current();return}if(z.key!=="Tab")return;const D=I.current;if(!D)return;const f=Array.from(D.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(C=>!C.hasAttribute("disabled")&&C.getAttribute("aria-hidden")!=="true");if(f.length===0){z.preventDefault(),D.focus({preventScroll:!0});return}const M=f[0],P=f[f.length-1],B=document.activeElement;z.shiftKey&&B===M?(z.preventDefault(),P.focus({preventScroll:!0})):!z.shiftKey&&B===P&&(z.preventDefault(),M.focus({preventScroll:!0}))};return document.addEventListener("keydown",L),()=>{window.clearTimeout(R),document.body.style.overflow=g,document.removeEventListener("keydown",L),_.current?.focus?.({preventScroll:!0}),_.current=null}},[i,e]),!e||!S.current)return null;const y=d==="dialog",U=n.jsxs("section",{ref:I,role:"dialog","aria-modal":"true","aria-label":u,tabIndex:-1,className:W("flex flex-col bg-background text-foreground",y?"h-[min(88dvh,860px)] w-full max-w-[720px] overflow-hidden rounded-2xl border border-border/70 shadow-[0_24px_64px_rgb(0_0_0_/_0.32)]":"oc-keyboard-inset-surface fixed inset-0 z-50"),style:y?{opacity:k?1:0,transform:k?"none":"scale(0.97)",transition:`opacity ${it}ms ease-out, transform ${it}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:k?"none":"translateX(100%)",transition:`transform ${it}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:g=>{k&&g.target===g.currentTarget&&g.propertyName==="transform"&&A(!0)},children:[o?null:n.jsxs("header",{className:W("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!c&&"border-b border-border/70"),children:[n.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":"Close",onClick:t,style:{touchAction:"manipulation"},children:n.jsx(F,{name:"close",className:"size-5"})}),n.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[s?typeof s=="string"?n.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:s}):s:null,r?typeof r=="string"?n.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:r}):r:null]}),l?n.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:l}):null]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:T?n.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:m}):null}),n.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return y?He.createPortal(n.jsx("div",{className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:k?1:0,paddingLeft:h==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:h==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:t,children:n.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:g=>g.stopPropagation(),children:U})}),S.current):He.createPortal(U,S.current)},qa=a.lazy(()=>Se(()=>import("./FilesView-DaqkPMqx.js"),__vite__mapDeps([10,0,1,2,4,5,6,7,8,9,11,12,3,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70])).then(e=>({default:e.FilesView}))),Ja=a.lazy(()=>Se(()=>import("./GitView-JK-QCK9R.js"),__vite__mapDeps([71,6,0,1,2,11,4,5,7,8,9,12,3,49,50,51,52,53,72,73,74,75,76,77,56,57,58,33,34,35,36,37,38,39,40,41,42,43,44,45,46,59,31,32,60,61,62,63,64,65,66,78,79,80,29,30])).then(e=>({default:e.GitView}))),Ya=a.lazy(()=>Se(()=>import("./PullRequestsSurface-D9beq2x9.js"),__vite__mapDeps([81,6,0,1,2,82,4,5,7,8,9,11,12,3,49,50,51,52,53,83,73,74,77,56,57,58,33,34,35,36,37,38,39,40,41,42,43,44,45,46,59,31,32,60,61,62,63,64,65,66,78,79,80,29,30])).then(e=>({default:e.PullRequestsSurface}))),Qa=a.lazy(()=>Se(()=>import("./IssuesSurface-CAqQzrsv.js"),__vite__mapDeps([84,0,1,2,82,4,5,6,7,8,9,11,12,3,49,50,51,52,53,83,73,74,85])).then(e=>({default:e.IssuesSurface}))),bn="mobile-surface-root",Za=16,gn=a.memo(function({open:t,onClose:s,tab:r,onTabChange:l,pendingChangesDiff:i,variant:o="drawer",drawerRefExternal:c,scrimRefExternal:u,rootRefExternal:d,githubTabsAvailable:h=!1}){const m=a.useRef(null),S=a.useRef(null),k=a.useRef(null),w=a.useRef(null),T=c??S,A=u??k,I=d??w,_=a.useCallback(N=>{w.current=N,d&&(d.current=N)},[d]),p=a.useCallback(()=>{const N=typeof document<"u"?document.activeElement:null;N instanceof HTMLElement&&I.current?.contains(N)&&N.blur(),s()},[s]),[y,U]=a.useState(!1),[g,E]=a.useState(t),R=`mobile-workspace-tab-${a.useId()}`,L=a.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[z,D]=a.useState(()=>new Set),[f,M]=a.useState(null),[P,B]=a.useState(null);if(a.useEffect(()=>{t&&D(N=>{if(N.has(r))return N;const K=new Set(N);return K.add(r),K})},[t,r]),typeof document<"u"&&!m.current){let N=document.getElementById(bn);N||(N=document.createElement("div"),N.id=bn,document.body.appendChild(N)),m.current=N}if(a.useEffect(()=>{if(t){E(!0);const K=window.setTimeout(()=>U(!0),L?0:Za);return()=>window.clearTimeout(K)}U(!1);const N=window.setTimeout(()=>E(!1),Ge+40);return()=>window.clearTimeout(N)},[t,L]),a.useEffect(()=>{if(!t)return;const N=document.body.style.overflow;o==="drawer"&&(document.body.style.overflow="hidden");const K=le=>{le.key==="Escape"&&r!=="terminal"&&p()};return document.addEventListener("keydown",K),()=>{o==="drawer"&&(document.body.style.overflow=N),document.removeEventListener("keydown",K)}},[p,t,r,o]),a.useEffect(()=>{const N=I.current;if(!N||t||o!=="drawer")return;const K=document.activeElement;K&&N.contains(K)&&K.blur()},[t,o]),us({side:"right",enabled:o==="drawer",open:t,drawerRef:T,scrimRef:A,onClose:p,widthRatio:1,prefersReducedMotion:L}),o==="drawer"&&!m.current)return null;const C=L?0:Ge,O=Fs(h),G=L?{duration:0}:{type:"spring",stiffness:520,damping:40,mass:.8},V=n.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 py-1 overflow-x-auto overflow-y-hidden scrollbar-none",role:"tablist","aria-label":"Workspace","data-no-drawer-swipe":"true",children:O.map(N=>{const K=r===N.id;return n.jsxs(gt.button,{layout:"position",transition:G,type:"button",role:"tab","aria-selected":K,"aria-label":N.label,onClick:()=>l(N.id),className:W("relative flex min-h-[44px] items-center justify-center gap-1 rounded-lg py-2 typography-ui-label transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",K?"min-w-0 shrink px-2.5 text-foreground":"size-11 shrink-0 text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[K?n.jsx(gt.span,{layoutId:R,transition:G,className:"absolute inset-0 bg-interactive-selection",style:{borderRadius:8},"aria-hidden":"true"}):null,n.jsx(F,{name:N.icon,className:"relative size-5 shrink-0"}),K?n.jsx(gt.span,{initial:L?!1:{opacity:0,x:-4},animate:{opacity:1,x:0},transition:G,className:"relative truncate",children:N.label},N.id):null]},N.id)})}),ee=n.jsxs(n.Fragment,{children:[o==="panel"?null:n.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2",children:[V,n.jsx("button",{type:"button",onClick:p,"aria-label":"Close workspace panel",className:"flex size-11 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:n.jsx(F,{name:"close",className:"size-5"})})]}),n.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[z.has("changes")?n.jsx("div",{className:W("h-full",r!=="changes"&&"hidden"),children:n.jsx(fe,{children:n.jsx(a.Suspense,{fallback:null,children:n.jsx(Ja,{isActive:t&&r==="changes",chrome:"mobile",initialDiffPath:i?.path??null,initialDiffStaged:i?.staged===!0})})})},i?`changes:${i.path}:${i.staged}`:"changes"):null,z.has("files")?n.jsx("div",{className:W("h-full",r!=="files"&&"hidden"),children:n.jsx(fe,{children:n.jsx(a.Suspense,{fallback:null,children:n.jsx(qa,{chrome:"mobile",mode:"editor-only",isVisible:t&&r==="files"})})})}):null,z.has("terminal")?n.jsx("div",{className:W("h-full",r!=="terminal"&&"hidden"),children:n.jsx(fe,{children:n.jsx(Vs,{visible:t&&r==="terminal"})})}):null,z.has("pull-requests")?n.jsx("div",{className:W("h-full",r!=="pull-requests"&&"hidden"),children:n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background",children:[n.jsx(tn,{icon:at.find(N=>N.id==="pull-requests")?.icon,title:at.find(N=>N.id==="pull-requests")?.label??"Pull requests",actions:n.jsx("div",{ref:N=>{M(N)},className:"flex items-center gap-1"})}),n.jsx("div",{className:"min-h-0 flex-1",children:n.jsx(fe,{children:n.jsx(a.Suspense,{fallback:null,children:n.jsx(Ya,{hideFilesTab:!0,headerActionsSlot:t&&r==="pull-requests"?f:null,headerActionsPresentation:"drawer"})})})})]})}):null,z.has("issues")?n.jsx("div",{className:W("h-full",r!=="issues"&&"hidden"),children:n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background",children:[n.jsx(tn,{icon:at.find(N=>N.id==="issues")?.icon,title:at.find(N=>N.id==="issues")?.label??"Issues",actions:n.jsx("div",{ref:N=>{B(N)},className:"flex items-center gap-1"})}),n.jsx("div",{className:"min-h-0 flex-1",children:n.jsx(fe,{children:n.jsx(a.Suspense,{fallback:null,children:n.jsx(Qa,{headerActionsSlot:t&&r==="issues"?P:null,headerActionsPresentation:"drawer"})})})})]})}):null]})]});return o==="panel"?n.jsx("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:ee}):He.createPortal(n.jsxs("div",{ref:_,className:"fixed inset-0 z-50",inert:!t,style:{pointerEvents:t?"auto":"none",visibility:g?"visible":"hidden"},"data-mobile-workspace-root":"true",children:[n.jsx("button",{ref:A,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close workspace panel",onClick:p,tabIndex:t?0:-1,style:{opacity:y?1:0,transition:C?`opacity ${C}ms ${Te}`:"none"},"data-mobile-workspace-scrim":"true"}),n.jsx("section",{ref:T,role:"dialog","aria-modal":"true","aria-label":"Open workspace panel",className:"oc-keyboard-inset-surface absolute inset-y-0 right-0 z-10 flex h-full w-full flex-col bg-sidebar",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:y?"none":"translateX(100%)",transition:C?`transform ${C}ms ${Te}`:"none",touchAction:"pan-x pan-y"},"data-mobile-workspace-drawer":"true",children:ee})]}),m.current)}),ei="pichamber",ti=e=>e.replace(/^\/+|\/+$/g,""),ni=e=>{const t=ti(e.pathname).split("/").filter(Boolean);return e.host?[e.host,...t]:t};function si(e){if(typeof e!="string"||e.length===0)return null;let t;try{t=new URL(e)}catch{return null}if(t.protocol!==`${ei}:`)return null;const s=ni(t),r=(s[0]??"").toLowerCase(),l=s.slice(1),i=t.searchParams;switch(r){case"session":{const o=l[0]||i.get("id")||"";return o?{type:"session",sessionId:o,directory:i.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:i.get("dir")??void 0,projectId:i.get("project")??void 0,agent:i.get("agent")??void 0,model:i.get("model")??void 0};case"sessions":{const o=i.get("filter");return{type:"sessions",filter:o==="attention"||o==="recent"||o==="all"?o:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:l[0]||i.get("section")||void 0};case"changes":return{type:"changes",path:l.join("/")||i.get("path")||void 0,staged:i.get("staged")==="true"};case"view":{const o=(l[0]||"").toLowerCase();return o==="changes"?{type:"changes"}:o==="files"||o==="mcp"||o==="instances"||o==="update"?{type:"view",target:o}:null}default:return null}}let ie={},ds=!1,Ye=null;const ri=e=>{switch(e.type){case"session":return ye.getState().setCurrentSession(e.sessionId,e.directory??null),!0;case"new-session":{const t=ye.getState();return t.openNewSessionDraft(),(e.directory||e.projectId)&&t.setNewSessionDraftTarget({directoryOverride:e.directory??null,projectId:e.projectId??null,selectedProjectId:e.projectId??null}),!0}case"sessions":return ie.openSessions?(ie.openSessions(e.filter),!0):!1;case"status":return ie.openSessions?(ie.openSessions(),!0):!1;case"view":return ie.openView?(ie.openView(e.target),!0):!1;case"changes":return ie.openChanges?(ie.openChanges({path:e.path,staged:e.staged}),!0):!1;case"settings":return ie.openSettings?(ie.openSettings(e.section),!0):!1}},Ht=()=>{if(!ds||!Ye)return;const e=Ye;Ye=null,ri(e)||(Ye=e)},fs=e=>{Ye=e,Ht()},xn=e=>{const t=si(e);t&&fs(t)},ai=e=>{ds=e,Ht()},ii=e=>{a.useEffect(()=>(ie=e,Ht(),()=>{ie===e&&(ie={})}),[e])},oi=e=>{const{ready:t}=e;a.useEffect(()=>{ai(t)},[t]),a.useEffect(()=>{if(!Y())return;let s=!1;const r=[];return Se(()=>import("./vendor-capacitor-app-BjdQVib9.js"),__vite__mapDeps([86,6,0,1,2])).then(async({App:l})=>{if(s)return;const i=await l.addListener("appUrlOpen",o=>{xn(o?.url)});if(s){i.remove();return}r.push(()=>{i.remove()})}).catch(()=>{}),Se(()=>import("./vendor-capacitor-push-notifications-CBKq2Arn.js"),__vite__mapDeps([87,0,1,2])).then(async({PushNotifications:l})=>{if(s)return;const i=await l.addListener("pushNotificationActionPerformed",o=>{const c=o?.notification?.data,u=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(u){xn(u);return}const d=typeof c?.sessionId=="string"?c.sessionId:void 0;d&&fs({type:"session",sessionId:d})});if(s){i.remove();return}r.push(()=>{i.remove()})}).catch(()=>{}),()=>{s=!0,r.forEach(l=>l())}},[])},vn=e=>{const t=e.drawer.current,s=e.scrim.current,r=e.root.current;r&&(r.style.pointerEvents="auto",r.style.visibility="visible"),t&&(t.style.transition="none"),s&&(s.style.transition="none")},wn=(e,t,s)=>{const r=e.drawer.current,l=e.scrim.current;if(r&&(r.style.transform=s>=.999?"none":`translateX(${(t==="left"?s-1:1-s)*100}%)`),l){l.style.opacity=String(s);const i=s>.01?"auto":"none";l.style.pointerEvents!==i&&(l.style.pointerEvents=i)}},kn=(e,t,s)=>{const r=s.drawer.current,l=s.scrim.current,i=s.root.current;r&&(r.style.transition=`transform ${Ge}ms ${Te}`,r.style.transform=t?"none":e==="left"?"translateX(-100%)":"translateX(100%)"),l&&(l.style.transition=`opacity ${Ge}ms ${Te}`,l.style.opacity=t?"1":"0",l.style.pointerEvents=t?"auto":"none"),i&&(i.style.pointerEvents=t?"auto":"none",i.style.visibility=t?"visible":"")},Sn=e=>{const t=e.shell.current,s=e.inner.current;t&&(t.style.overflow="visible"),s&&(s.style.transition="none")},Cn=(e,t,s,r)=>{const l=e.inner.current;if(!l)return;const i=r==="left"?(t-1)*s:(1-t)*s;l.style.transform=t>=.999?"translateX(0)":`translateX(${i}px)`},jn=(e,t,s,r,l)=>{const i=e.shell.current,o=e.inner.current;return!i||!o?void 0:(o.style.transition="transform 200ms cubic-bezier(0.22, 1, 0.36, 1)",o.style.transform=t?"translateX(0)":`translateX(${r==="left"?-s:s}px)`,window.setTimeout(()=>{o.style.transition="",o.style.transform="",i.style.overflow=""},220))},En=({side:e,isResizing:t,ariaLabel:s,handleProps:r})=>n.jsx("div",{className:W("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",e==="left"?"right-0":"left-0"),role:"separator","aria-orientation":"vertical","aria-label":s,...r,children:n.jsx("div",{className:W("absolute inset-y-0 w-[3px] transition-colors",e==="left"?"right-0":"left-0",t&&"bg-[var(--interactive-border)]")})}),li=320,ci=380,Rn=280,ui=560,di=900;function Tn(e,t,s,r=ui){const l=a.useRef(null),[i,o]=a.useState(()=>{if(typeof window>"u")return s;const p=Number.parseInt(window.localStorage.getItem(t)??"",10);return Number.isFinite(p)?Math.min(r,Math.max(Rn,p)):s}),[c,u]=a.useState(!1),d=a.useRef(0),h=a.useRef(i),m=a.useRef(null),S=a.useRef(null),k=a.useCallback(p=>Math.min(r,Math.max(Rn,Math.round(p))),[r]),w=a.useCallback(p=>{const y=l.current;y&&(y.style.width=`${p}px`,y.style.minWidth=`${p}px`,y.style.maxWidth=`${p}px`,y.style.setProperty("--oc-ipad-sidebar-width",`${p}px`))},[]),T=a.useCallback(p=>{try{p.currentTarget.setPointerCapture(p.pointerId)}catch{}S.current=p.pointerId,d.current=p.clientX,h.current=i,m.current=i,u(!0),p.preventDefault()},[i]),A=a.useCallback(p=>{if(S.current!==p.pointerId)return;const y=p.clientX-d.current,U=k(h.current+(e==="left"?y:-y));m.current!==U&&(m.current=U,w(U))},[w,k,e]),I=a.useCallback(p=>{if(S.current!==p.pointerId)return;try{p.currentTarget.releasePointerCapture(p.pointerId)}catch{}const y=k(m.current??h.current);S.current=null,m.current=null,u(!1),o(y);try{window.localStorage.setItem(t,String(y))}catch{}},[k,t]),_=a.useMemo(()=>({onPointerDown:T,onPointerMove:A,onPointerUp:I,onPointerCancel:I}),[T,I,A]);return{asideRef:l,width:i,isResizing:c,handleProps:_}}const fi=a.memo(er),pi=({onActiveConnectionDeleted:e})=>{const[t,s]=a.useState(!1),[r,l]=a.useState(null),[i,o]=a.useState(!1),[c,u]=a.useState("changes"),d=a.useCallback(b=>{u(nn(b))},[]),h=c,[m,S]=a.useState("nav"),[k,w]=a.useState(null),T=a.useRef([]),A=a.useCallback(()=>{T.current.forEach(b=>window.clearTimeout(b)),T.current=[]},[]);a.useEffect(()=>()=>A(),[A]);const I=a.useRef(null),_=a.useRef(null),p=a.useRef(null),y=a.useRef(null),U=a.useRef(null),g=a.useRef(null),E=a.useRef(null),R=a.useRef(null),L=a.useRef(0),z=a.useRef(0),D=a.useCallback(b=>{A(),s(b)},[A]),f=a.useCallback(b=>{A(),o(b)},[A]),M=Ae(b=>b.setSettingsPage),P=Ae(b=>b.isArchivePageOpen),B=Ae(b=>b.setArchivePageOpen),C=We(b=>b.available),O=We(b=>b.runtimeType),G=a.useMemo(()=>Ln(),[]),V=!G&&C&&(O==="desktop"||O==="web"),ee=vr()??"",N=ee?Rs(ee):"",K=wr().github??null,le=sn(b=>b.ensureScope);a.useEffect(()=>{!N||!K||le(N,K)},[N,K,le]);const Ne=sn(b=>N?b.entriesByDirectory[N]??null:null),te=a.useMemo(()=>kr(Ne),[Ne]),ve=Sr(te);a.useEffect(()=>{!ve&&Gs(c)&&u(Xs(c))},[ve,c]);const ce=a.useCallback(()=>{l(null)},[]),ae=a.useCallback(b=>{l(b)},[]),we=a.useCallback(()=>{f(!1)},[f]),x=a.useCallback(b=>{S(b),ae("settings")},[ae]),{enabled:j,roomyForPanels:H}=Cr(),v=jr()==="portrait",$=Er(),Q=Ae(b=>b.setSidebarOpen),q=Ae(b=>b.isSidebarOpen),Ce=a.useRef(!1);a.useLayoutEffect(()=>{j&&!Ce.current&&Q(Rr().roomyForPanels),!j&&Ce.current&&Q(!1),Ce.current=j},[j,Q]);const ue=a.useCallback(()=>{w(null),d("files"),f(!0)},[d,f]),ke=a.useCallback((b=null)=>{w(b),d("changes"),f(!0)},[d,f]),ne=Tn("left","pichamber.ipad.leftSidebarWidth",li),de=Tn("right","pichamber.ipad.rightSidebarWidth",ci,di),Ft=H,be=Ft&&i?de.width:0,hs=qs(j&&q),Xe=j&&q?ne.width:0,ms=a.useCallback(b=>{const re=nn(b);i&&h===re?f(!1):(d(re),f(!0))},[i,h,d,f]),ys=a.useCallback(()=>{f(!i)},[i,f]),bs=a.useCallback(b=>{!b&&!H&&Q(!1)},[H,Q]);a.useEffect(()=>{if(typeof document>"u")return;const b=document.documentElement;return b.style.setProperty("--oc-chat-inset-left",`${Xe}px`),b.style.setProperty("--oc-chat-inset-right",`${be}px`),()=>{b.style.removeProperty("--oc-chat-inset-left"),b.style.removeProperty("--oc-chat-inset-right")}},[Xe,be]),a.useEffect(()=>{if(typeof document>"u")return;const b=j&&(v||$),re=document.documentElement;return re.classList.toggle("oc-keep-draft-starters",b),()=>re.classList.remove("oc-keep-draft-starters")},[$,j,v]);const Vt=a.useCallback(()=>{D(!1),f(!1)},[D,f]),gs=a.useMemo(()=>({openChanges:({diffPath:b,staged:re}={})=>{ke(b?{path:b,staged:re===!0}:null)},openFiles:()=>ue(),openSettings:b=>{b&&M(b),x(b?"page-content":"nav")},openInstances:G?()=>ae("instances"):void 0,instanceLabel:G?De():null,openUpdate:V?()=>ae("update"):void 0,closeDrawers:Vt}),[Vt,ke,ue,x,ae,M,G,V]),xs=a.useMemo(()=>({openSessions:()=>{j?Q(!0):D(!0)},openView:b=>{if(b==="files"){ue();return}(b==="instances"||b==="update"||b==="mcp")&&ae(b)},openChanges:({path:b,staged:re}={})=>{ke(b?{path:b,staged:re===!0}:null)},openSettings:b=>{b&&M(b),x(b?"page-content":"nav")}}),[j,ke,ue,x,ae,M,D,Q]);ii(xs);const Gt=a.useRef(null);Js(Gt,{leftOpen:j?q:t,rightOpen:i,leftWidth:()=>j?ne.width:I.current?.offsetWidth||window.innerWidth*.72,rightWidth:()=>j?de.width:y.current?.offsetWidth||window.innerWidth,onLeftProgress:b=>{if(L.current=b,j){Cn({inner:E},b,ne.width,"left");return}wn({drawer:I,scrim:_},"left",b)},onRightProgress:b=>{if(z.current=b,j&&H){Cn({inner:R},b,de.width,"right");return}wn({drawer:y,scrim:U},"right",b)},onLeftOpen:()=>{j?Q(!0):D(!0)},onLeftClose:()=>{j?Q(!1):D(!1)},onRightOpen:()=>f(!0),onRightClose:()=>f(!1),onDragStart:b=>{if(A(),b==="left"){L.current=j?q?1:0:t?1:0,j?Sn({shell:ne.asideRef,inner:E}):vn({drawer:I,scrim:_,root:p});return}z.current=i?1:0,j&&H?Sn({shell:de.asideRef,inner:R}):vn({drawer:y,scrim:U,root:g})},onDragEnd:(b,re)=>{if(b==="left"){const $e=typeof re=="boolean"?re:L.current>.5;if(L.current=$e?1:0,j){const Xt=jn({shell:ne.asideRef,inner:E},$e,ne.width,"left");Xt!==void 0&&T.current.push(Xt)}else kn("left",$e,{drawer:I,scrim:_,root:p});return}const bt=typeof re=="boolean"?re:z.current>.5;if(z.current=bt?1:0,j&&H){const $e=jn({shell:de.asideRef,inner:R},bt,de.width,"right");$e!==void 0&&T.current.push($e)}else kn("right",bt,{drawer:y,scrim:U,root:g})}});const vs=a.useCallback(()=>P?(B(!1),!0):r?(ce(),!0):i?(we(),!0):t?(D(!1),!0):!1,[r,ce,we,P,t,B,D,i]);At(vs);const yt=j?"dialog":"fullscreen";return n.jsx(Tr,{actions:gs,children:n.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area relative flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[j?n.jsxs("aside",{ref:ne.asideRef,className:W("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-sidebar motion-reduce:transition-none",!q&&"border-r-0"),style:{width:Xe,minWidth:Xe,maxWidth:Xe,"--oc-ipad-sidebar-width":`${ne.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!q,"data-page-scroll-lock":"true",children:[n.jsx("div",{ref:E,className:W("flex h-full shrink-0 flex-col",ne.isResizing&&"pointer-events-none",!q&&"pointer-events-none select-none"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:ne.isResizing||hs.slidIn?"translateX(0)":"translateX(-100%)",transition:ne.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:n.jsx(fe,{children:n.jsx(mn,{open:q,variant:"sidebar",onOpenChange:bs})})}),q?n.jsx(En,{side:"left",isResizing:ne.isResizing,ariaLabel:"Resize left panel",handleProps:ne.handleProps}):null]}):null,n.jsxs("div",{className:"relative flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[j?n.jsxs(n.Fragment,{children:[n.jsx(Ys,{}),n.jsx(Qs,{onToggleRightDrawer:ys,rightDrawerOpen:i,tabletWorkspaceTab:h,onSelectTabletWorkspaceTab:ms,tabletGitHubTabsAvailable:ve})]}):n.jsx(Fa,{onOpenSessions:()=>D(!0),onOpenWorkspace:()=>f(!0)}),n.jsx("main",{ref:Gt,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",style:{touchAction:"pan-x pan-y"},children:n.jsx("div",{className:"h-full w-full",children:n.jsx(fe,{children:n.jsx(fi,{})})})})]}),j?null:n.jsx(mn,{open:t,onOpenChange:D,drawerRefExternal:I,scrimRefExternal:_,rootRefExternal:p}),j?n.jsxs("aside",{ref:de.asideRef,className:W("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background motion-reduce:transition-none",!be&&"border-l-0"),style:{width:be,minWidth:be,maxWidth:be,"--oc-ipad-sidebar-width":`${de.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!be,"data-page-scroll-lock":"true",children:[n.jsx("div",{ref:R,className:W("flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",de.isResizing&&"pointer-events-none",!be&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:be?"translateX(0)":"translateX(100%)",transition:de.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1), opacity 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:n.jsx(fe,{children:n.jsx(gn,{open:i,onClose:we,tab:h,onTabChange:d,pendingChangesDiff:k,variant:Ft?"panel":"drawer",githubTabsAvailable:ve,drawerRefExternal:y,scrimRefExternal:U,rootRefExternal:g})})}),be?n.jsx(En,{side:"right",isResizing:de.isResizing,ariaLabel:"Resize right panel",handleProps:de.handleProps}):null]}):n.jsx(gn,{open:i,onClose:we,tab:h,onTabChange:d,pendingChangesDiff:k,githubTabsAvailable:ve,drawerRefExternal:y,scrimRefExternal:U,rootRefExternal:g}),r==="instances"&&G?n.jsx(Ct,{open:!0,variant:yt,dialogAlign:"app",onClose:ce,ariaLabel:"Instances",title:"Instances",children:n.jsx(Va,{onConnect:ce,onActiveConnectionDeleted:e})}):null,r==="settings"?n.jsx(Ct,{open:!0,variant:yt,dialogAlign:"app",onClose:ce,ariaLabel:"Settings",headerless:!0,children:n.jsx(fe,{children:n.jsx(Zr,{forceMobile:!j,isWindowed:!0,initialMobileStage:m,onClose:ce})})}):null,r==="update"?n.jsx(Ct,{open:!0,variant:yt,dialogAlign:"app",onClose:ce,ariaLabel:"Update",title:"Update",children:n.jsx(fe,{children:n.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:n.jsx(ea,{initialUpdateDialogOpen:!0})})})}):null,n.jsx(fe,{children:n.jsx(Zs,{})})]})})},hi=8,ps=6e4,mi=6e4,jt=[1e3,2e3,4e3,8e3,15e3,3e4,3e4,3e4],yi=(e,t)=>{if(t?.offline||t?.hidden)return ps;if(e<=0)return jt[0];const s=Math.min(e-1,jt.length-1);return jt[s]??3e4},ge=()=>typeof navigator<"u"&&typeof navigator.onLine=="boolean"?!navigator.onLine:!1,he=()=>typeof document<"u"&&typeof document.visibilityState=="string"?document.visibilityState==="hidden":!1;class bi{constructor(t,s,r=()=>""){this.probe=t,this.callbacks=s,this.getRuntimeIdentity=r}generation=0;attempt=0;timer=null;wakeCleanup=null;running=!1;exhausted=!1;probingGeneration=null;get currentGeneration(){return this.generation}get currentAttempt(){return this.attempt}get isRunning(){return this.running&&!this.exhausted}start(){me("recovery",{code:"start"}),this.startCycle(!1)}startCycle(t){this.clearTimer(),this.generation+=1,this.attempt=0,this.exhausted=!1,this.running=!0,t?this.runAttempt(this.generation):this.scheduleNext(this.generation)}retryNow(){if(this.exhausted){if(ge()||he())return;this.startCycle(!0);return}this.running&&(this.clearTimer(),this.runAttempt(this.generation))}cancel(){me("recovery",{code:"cancel"}),this.generation+=1,this.running=!1,this.exhausted=!1,this.attempt=0,this.probingGeneration=null,this.clearTimer()}async probeOnce(){return this.running||this.exhausted||this.probingGeneration!==null||ge()||he()?null:this.runGuardedProbe(this.generation)}async runGuardedProbe(t){this.probingGeneration=t;const s=this.getRuntimeIdentity();let r;try{r=await this.probe()}catch{r="unreachable"}finally{this.probingGeneration===t&&(this.probingGeneration=null)}return t!==this.generation||this.getRuntimeIdentity()!==s?null:r}settleTerminalOutcome(t){return t==="unreachable"?!1:(this.running=!1,this.exhausted=!1,this.clearTimer(),t==="needs-login"?this.callbacks.onAuthExpired():t==="no-connection"?this.callbacks.onNoConnection():this.callbacks.onHealthy(t),!0)}clearTimer(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.wakeCleanup&&(this.wakeCleanup(),this.wakeCleanup=null)}scheduleNext(t){if(t!==this.generation||!this.running||this.exhausted)return;if(this.attempt>=hi){this.exhausted=!0,this.running=!1,this.callbacks.onExhausted(),this.scheduleExhaustedPoll(t);return}const s=this.attempt+1,r=yi(s,{offline:ge(),hidden:he()});this.callbacks.onAttempt?.(s,r);const l=()=>{ge()||he()||t===this.generation&&(this.clearTimer(),this.runAttempt(t))},i=()=>l(),o=()=>{typeof document<"u"&&document.visibilityState==="visible"&&l()};typeof window<"u"&&window.addEventListener("online",i),typeof document<"u"&&document.addEventListener("visibilitychange",o),this.wakeCleanup=()=>{typeof window<"u"&&window.removeEventListener("online",i),typeof document<"u"&&document.removeEventListener("visibilitychange",o)},this.timer=setTimeout(()=>{if(this.timer=null,this.wakeCleanup?.(),this.wakeCleanup=null,!(t!==this.generation||!this.running||this.exhausted)){if(ge()||he()){this.scheduleNext(t);return}this.runAttempt(t)}},r)}async runAttempt(t){if(t!==this.generation||!this.running||this.exhausted||this.probingGeneration===t)return;if(ge()||he()){this.scheduleNext(t);return}const s=await this.runGuardedProbe(t);s===null||this.settleTerminalOutcome(s)||(this.attempt+=1,this.scheduleNext(t))}scheduleExhaustedPoll(t){if(t!==this.generation||!this.exhausted)return;this.clearTimer();const s=ge()||he()?ps:mi;this.timer=setTimeout(()=>{this.timer=null,this.runExhaustedPoll(t)},s)}async runExhaustedPoll(t){if(t!==this.generation||!this.exhausted)return;if(this.probingGeneration!==null||ge()||he()){this.scheduleExhaustedPoll(t);return}const s=await this.runGuardedProbe(t);s===null||!this.exhausted||this.settleTerminalOutcome(s)||this.scheduleExhaustedPoll(t)}}function gi(e=2500){const{uiFont:t}=Nr(),[s,r]=a.useState(!1);return a.useEffect(()=>{let l=!1;const i=()=>{l||r(!0)},o=()=>{requestAnimationFrame(()=>requestAnimationFrame(i))},c=Promise.all([Pr(t).catch(()=>{}),document.fonts?.ready?.then(()=>{}).catch(()=>{})??Promise.resolve(),aa.catch(()=>{})]).then(()=>{}),u=new Promise(d=>{window.setTimeout(d,e)});return Promise.race([c,u]).then(o),()=>{l=!0}},[t,e]),s}const xi=()=>{if(typeof window>"u")return;const e=window.__PICHAMBER_APNS_ENV__;if(e==="development")return"sandbox";if(e==="production")return"production"},vi=()=>{if(typeof window>"u")return!1;const t=window.Capacitor?.getPlatform?.();return t==="ios"||t==="android"},wi=e=>{const{enabled:t}=e,s=Ae(l=>l.nativeNotificationsEnabled),r=a.useRef(null);a.useEffect(()=>{if(!t||!s||!vi())return;let l=!1;const i=[];return Se(()=>import("./vendor-capacitor-push-notifications-CBKq2Arn.js"),__vite__mapDeps([87,0,1,2])).then(async({PushNotifications:o})=>{if(l)return;let c=await o.checkPermissions().catch(()=>null);if(c?.receive!=="granted"&&(c=await o.requestPermissions().catch(()=>null)),c?.receive!=="granted")return;const u=await o.addListener("registration",h=>{r.current=h.value,Rt()?.push?.registerApnsToken?.({token:h.value,platform:Nn(),environment:xi()})}),d=await o.addListener("registrationError",h=>{console.warn("[Push] Native registration error:",h)});if(await o.register().catch(()=>{}),l){u.remove(),d.remove();return}i.push(()=>{u.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{l=!0,i.forEach(o=>o())}},[t,s]),a.useEffect(()=>{if(s)return;const l=r.current;if(!l)return;r.current=null,Rt()?.push?.unregisterApnsToken?.({token:l})},[s])},ki=1e3;function Si({apis:e}){const t=je(x=>x.initializeApp),s=je(x=>x.isInitialized),r=je(x=>x.isConnected),l=je(x=>x.connectionPhase),i=je(x=>x.providers.length),o=je(x=>x.loadProviders),c=An(x=>x.currentDirectory),u=ye(x=>x.error),d=ye(x=>x.clearError),h=Ae(x=>x.setIsMobile),[m,S]=a.useState(0),[k,w]=a.useState(0),[T,A]=a.useState(!1),[I,_]=a.useState("idle"),p=Ir(),y=a.useRef(null),U=a.useRef(I);U.current=I;const[g,E]=a.useState("pending"),[R,L]=a.useState(null),z=a.useMemo(()=>De(),[]),[,D]=a.useReducer(x=>x+1,0),f=a.useMemo(()=>Ln(),[]),M=a.useRef(0),P=a.useRef(0),B=a.useRef(!1),[C,O]=a.useState(()=>f&&!!se());a.useEffect(()=>{const x=new bi(()=>Wt(),{onHealthy:j=>{if(me("recovery",{code:"success"}),_("idle"),Pe(!1),j==="unchanged"){As(),je.getState().initializeApp();const H=je.getState();H.providers.length===0&&H.loadProviders({source:"mobileApp:recovery"})}},onAuthExpired:()=>{me("recovery",{code:"auth-expired"}),_("idle"),Pe(!1),L({kind:"auth-expired",label:De()??""}),Ie({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),S(j=>j+1)},onNoConnection:()=>{me("recovery",{code:"no-connection"}),_("idle"),Pe(!1),Ie({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),S(j=>j+1)},onExhausted:()=>{me("recovery",{code:"exhausted"}),_("exhausted")},onAttempt:j=>{me("recovery",{code:"attempt",detail:String(j)})}},()=>`${pe()}|${se()}`);return y.current=x,()=>{x.cancel(),y.current=null}},[]);const G=a.useCallback(()=>{if(!f||!se())return;const x=y.current;if(x){if(x.isRunning){x.retryNow();return}_("recovering"),Pe(!0),x.start()}},[f]),V=a.useCallback(()=>{y.current?.cancel(),_("idle"),Pe(!1),O(!1)},[]),ee=a.useCallback(x=>{V(),x&&L(x),Ie({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),S(j=>j+1)},[V]),N=a.useCallback(()=>{const x=Date.now();x-M.current>=ki&&(M.current=x,window.dispatchEvent(new Event("pichamber:system-resume")))},[]),K=a.useCallback(()=>{const x=se(),j=P.current+1;if(P.current=j,!x){if(B.current)return;B.current=!0,ot().catch(()=>{}).finally(()=>{B.current=!1});return}if(y.current?.isRunning){y.current.retryNow(),N();return}if(U.current==="exhausted"){if(ge()||he())return;_("recovering"),Pe(!0),y.current?.start(),N();return}if(ge()||he()){G();return}const H=()=>{t(),i===0&&o({source:"mobileApp:nativeResume"})},X=y.current;X&&(X.probeOnce().then(v=>{if(v!==null&&P.current===j){if(v==="no-connection"){ee(null);return}if(v==="needs-login"){ee({kind:"auth-expired",label:De()??""});return}if(v==="unreachable"){G();return}v!=="switched"&&H()}}),N())},[ee,N,t,o,i,G]);Ar(),_r(K),a.useEffect(()=>Ts(),[]),a.useEffect(()=>{if(!f)return;let x;const j=()=>{if(y.current?.isRunning){y.current.retryNow();return}if(U.current==="exhausted"){if(he())return;_("recovering"),Pe(!0),y.current?.start();return}window.clearTimeout(x),x=window.setTimeout(()=>K(),1500)};return window.addEventListener("online",j),()=>{window.removeEventListener("online",j),window.clearTimeout(x)}},[f,K]),a.useEffect(()=>{if(f)return Ns(()=>{se()&&ee({kind:"auth-expired",label:De()??""})})},[ee,f]),a.useEffect(()=>(Jt(e),()=>Jt(null)),[e]),a.useEffect(()=>Ps(x=>{if(!!x.runtimeKey&&x.runtimeKey===x.previousRuntimeKey){tr(),D();return}V(),nr(x),w(H=>H+1),S(H=>H+1)}),[V]),a.useEffect(()=>{_n()},[k]),a.useEffect(()=>{if(!f||r||se()){E("done");return}let x=!1;return E("attempting"),ot().catch(()=>({status:"no-candidate"})).then(j=>{x||(me("auto-connect",{code:j.status}),j.status==="unreachable"?L({kind:"unreachable",label:j.label}):j.status==="needs-login"&&L({kind:"auth-expired",label:j.label}),E("done"))}),()=>{x=!0}},[]),a.useEffect(()=>{if(!f||!se()){O(!1);return}let x=!1;const j=X=>{X&&L(X),Ie({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),S(v=>v+1)},H=y.current;if(!H){O(!1);return}return(async()=>{try{const X=await H.probeOnce();if(x||X===null||X==="switched"||X==="unchanged")return;const v=De();if(X==="needs-login"){j({kind:"auth-expired",label:v??""});return}if(X==="unreachable"){G();return}const $=await ot().catch(()=>({status:"no-candidate"}));if(x||(me("auto-connect",{code:$.status}),$.status==="connected"))return;$.status==="needs-login"?j({kind:"auth-expired",label:$.label}):$.status==="unreachable"?j({kind:"unreachable",label:$.label}):j(null)}finally{x||O(!1)}})(),()=>{x=!0,O(!1)}},[G]),a.useEffect(()=>{h(!0)},[h]),a.useEffect(()=>{f&&!se()||t()},[m,t,f]),a.useEffect(()=>{r&&i===0&&o({source:"mobileApp:recovery"})},[r,o,i]);const le=a.useRef(!1),[Ne,te]=a.useState(f);a.useEffect(()=>{if(!f||!r||le.current)return;if(ye.getState().currentSessionId){le.current=!0,te(!1);return}const x=pe(),j=Dr(x);if(!j){le.current=!0,te(!1);return}const H=Is(j.directory??null);if(!H){le.current=!0,te(!1);return}const X=qe();let v=0;try{v=X.getRuntimeGeneration()}catch{v=0}let $=!1;const Q=window.setTimeout(()=>te(!1),6e3);return(async()=>{let q=null;try{q=await Mr([H])}catch{q=null}if($)return;if(!q){te(!1);return}const Ce=qe();let ue=v;try{ue=Ce.getRuntimeGeneration()}catch{ue=v}const ke=ma({persisted:j,persistedDirectory:H,stale:q.stale,ready:q.readyDirectories.has(H),catalog:q.catalog,runtimeKey:pe(),capturedRuntimeKey:x,storeIdentityMatches:Ce===X,generationMatches:ue===v});if(ke.action==="wait"){te(!1);return}if(le.current=!0,ke.action==="clear"){Lr(x),te(!1);return}const ne=ye.getState();if(pe()!==x||qe()!==X){te(!1);return}ne.currentSessionId||ne.setCurrentSession(ke.sessionId,ke.directory),te(!1)})(),()=>{$=!0,window.clearTimeout(Q)}},[m,r,f]),a.useEffect(()=>{r&&qe().focusProject(c,_s(c))},[c,r]),a.useEffect(()=>{if(!u)return;const x=window.setTimeout(()=>d(),5e3);return()=>window.clearTimeout(x)},[d,u]),a.useEffect(()=>{if(f&&I!=="idle"){A(!1);return}if(f&&C){A(!1);return}if(!(!r&&(f?!!se():!0))){A(!1);return}const j=window.setTimeout(()=>{A(!0)},f?4e3:8e3);return()=>window.clearTimeout(j)},[r,f,m,I,k,C]),Or(),Ds({enabled:!0}),sr(),wi({enabled:f&&r}),oi({ready:f&&r&&s});const ve=gi(),ce=!r&&l==="reconnecting",ae=!!se(),we=f&&ae&&I!=="idle";return ve?f&&!we&&(!ae||!r&&!ce)?ae?n.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:n.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[n.jsx(Ee,{width:120,height:120,isAnimated:!T}),T?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),n.jsx("p",{className:"typography-body text-muted-foreground",children:"Could not connect to the saved server. Check that it is running, or pick another instance."})]}),n.jsx(oe,{type:"button",variant:"outline",onClick:()=>{ee(null)},children:"Use another server"})]}):null]})}):g!=="done"?n.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[n.jsx(Ee,{width:120,height:120,isAnimated:!0}),z?n.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[n.jsx("p",{className:"typography-small text-muted-foreground",children:"Connecting to device:"}),n.jsx("div",{className:"flex justify-center",children:n.jsx(zr,{text:z,showElapsed:!1})})]}):null]}):n.jsx(n.Fragment,{children:n.jsx(Ba,{onConnected:()=>S(x=>x+1),notice:R})}):!f&&!r&&!ce?T?n.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:n.jsxs("div",{className:"max-w-sm space-y-3",children:[n.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),n.jsx("p",{className:"typography-body text-muted-foreground",children:"We could not verify the UI session. If you're opening PiChamber from another device on your local network, make sure Desktop Network Access is enabled on the desktop app and use the LAN address shown in Settings."})]})}):n.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:n.jsx(Ee,{width:120,height:120,isAnimated:!0})}):n.jsx(fe,{children:n.jsx(Ur,{children:n.jsxs(Br,{apis:e,children:[n.jsx($r,{}),n.jsx(Wr,{delayDuration:300,skipDelayDuration:150,children:n.jsxs(rr,{children:[n.jsx(ar,{}),n.jsxs("div",{className:"h-full bg-background text-foreground",children:[f&&Ne?n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:n.jsx(Ee,{width:120,height:120,isAnimated:!0})}):null,n.jsx(Kr,{embeddedBackgroundWorkEnabled:s&&!p}),we?n.jsxs("div",{role:"status","aria-live":"polite",className:"pointer-events-none fixed inset-x-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px)+10px)] z-40 flex justify-center",children:[n.jsx("span",{className:"flex size-11 items-center justify-center rounded-full border border-border/70 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm",children:n.jsx(Ee,{width:24,height:24,isAnimated:!0})}),n.jsx("span",{className:"sr-only",children:I==="exhausted"?"Server unreachable":"Reconnecting…"})]}):null,n.jsx(ha,{}),n.jsx(pi,{onActiveConnectionDeleted:()=>{V(),Ie({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),S(x=>x+1)}}),n.jsx(ir,{}),n.jsx(or,{}),n.jsx(Hr,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),n.jsx(Fr,{})]})]})})]})},k)}):n.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:n.jsx(Ee,{width:120,height:120,isAnimated:!0})})}const Ci=()=>{(async()=>{try{await Promise.all([_n(),Ms()])}catch(e){console.error("[mobile-main] settings init failed:",e)}Jr(),Yr(),cr(),Ls()})().finally(()=>{ia()})};function ji(e){window.__PICHAMBER_SURFACE__="mobile",Vr(),Ci(),pa(),Gr();const t=document.getElementById("root");if(!t)throw new Error("Root element not found");const r=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",l=e??Rt();if(!l)throw new Error("Runtime APIs not registered");const i=r?{...l,notifications:{notify:async()=>!1,canNotify:()=>!1}}:l,o=n.jsx(Si,{apis:i});ks.createRoot(t).render(n.jsx(Et.StrictMode,{children:n.jsx(Xr,{children:n.jsx(lr,{children:r?o:n.jsx(qr,{children:o})})})}))}const Ui=Object.freeze(Object.defineProperty({__proto__:null,renderMobileApp:ji},Symbol.toStringTag,{value:"Module"}));export{zi as m,Ui as r};