@thevinci/web 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +197 -0
- package/bin/cli-entry.js +55 -0
- package/bin/cli-output.js +145 -0
- package/bin/cli.js +4887 -0
- package/bin/cli.test.js +64 -0
- package/dist/apple-touch-icon-120x120.png +0 -0
- package/dist/apple-touch-icon-152x152.png +0 -0
- package/dist/apple-touch-icon-167x167.png +0 -0
- package/dist/apple-touch-icon-180x180.png +0 -0
- package/dist/apple-touch-icon.png +0 -0
- package/dist/apple-touch-icon.svg +528 -0
- package/dist/assets/JsonTreeView-CSm9OzXG.js +1 -0
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/MarkdownRendererImpl-DensKOLc.js +6 -0
- package/dist/assets/MultiRunWindow-Bo7THayo.js +1 -0
- package/dist/assets/OnboardingScreen-BDqmzTVR.js +2 -0
- package/dist/assets/SettingsWindow-coz__Ykw.js +1 -0
- package/dist/assets/TerminalView-DrZ-i3Dr.js +1 -0
- package/dist/assets/ToolOutputDialog-Eglzslt3.js +16 -0
- package/dist/assets/es-4o9ciP61.js +15 -0
- package/dist/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- package/dist/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- package/dist/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-600-normal-DWFSQ4vo.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
- package/dist/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
- package/dist/assets/ibm-plex-sans-latin-500-normal-BgVn5rGT.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
- package/dist/assets/index-DLTDToSP.css +1 -0
- package/dist/assets/index-DgiFEKGN.js +1 -0
- package/dist/assets/ko-B20imCHE.js +15 -0
- package/dist/assets/main-BV3KOtdA.css +1 -0
- package/dist/assets/main-CDKJj0sH.js +226 -0
- package/dist/assets/main-LC-PSNVM.js +2 -0
- package/dist/assets/miniChat-CQUiG_cr.js +2 -0
- package/dist/assets/modelPrefsAutoSave-Dm799vzR.js +6986 -0
- package/dist/assets/pl-DQJ7LSzj.js +15 -0
- package/dist/assets/pt-BR-OmjHUz9y.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-CARbeW0G.js +2 -0
- package/dist/assets/uk-BNFxOlO4.js +15 -0
- package/dist/assets/vendor--DBfsbEis.css +1 -0
- package/dist/assets/vendor-.bun-B9l0ZNi2.js +4094 -0
- package/dist/assets/wasm-CG6Dc4jp.js +1 -0
- package/dist/assets/wasmSttWorker-Dtlxac_K.js +1 -0
- package/dist/assets/wasmSttWorker-oo7Dm_jy.js +1806 -0
- package/dist/assets/worker-CbT6TVo7.js +155 -0
- package/dist/assets/zh-CN-C6T-Ac7F.js +15 -0
- package/dist/favicon-16.png +0 -0
- package/dist/favicon-32.png +0 -0
- package/dist/favicon.png +0 -0
- package/dist/favicon.svg +528 -0
- package/dist/index.html +607 -0
- package/dist/logo-dark-192x192.png +0 -0
- package/dist/logo-dark-512x512.png +0 -0
- package/dist/logo-dark-512x512.svg +528 -0
- package/dist/logo-light-192x192.png +0 -0
- package/dist/logo-light-512x512.png +0 -0
- package/dist/logo-light-512x512.svg +528 -0
- package/dist/mini-chat.html +16 -0
- package/dist/pwa-192.png +0 -0
- package/dist/pwa-512.png +0 -0
- package/dist/pwa-maskable-192.png +0 -0
- package/dist/pwa-maskable-512.png +0 -0
- package/dist/site.webmanifest +21 -0
- package/dist/sw.js +1 -0
- package/package.json +118 -0
- package/public/apple-touch-icon-120x120.png +0 -0
- package/public/apple-touch-icon-152x152.png +0 -0
- package/public/apple-touch-icon-167x167.png +0 -0
- package/public/apple-touch-icon-180x180.png +0 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/apple-touch-icon.svg +528 -0
- package/public/favicon-16.png +0 -0
- package/public/favicon-32.png +0 -0
- package/public/favicon.png +0 -0
- package/public/favicon.svg +528 -0
- package/public/logo-dark-192x192.png +0 -0
- package/public/logo-dark-512x512.png +0 -0
- package/public/logo-dark-512x512.svg +528 -0
- package/public/logo-light-192x192.png +0 -0
- package/public/logo-light-512x512.png +0 -0
- package/public/logo-light-512x512.svg +528 -0
- package/public/pwa-192.png +0 -0
- package/public/pwa-512.png +0 -0
- package/public/pwa-maskable-192.png +0 -0
- package/public/pwa-maskable-512.png +0 -0
- package/public/site.webmanifest +21 -0
- package/server/TERMINAL_WS_PROTOCOL.md +48 -0
- package/server/index.d.ts +39 -0
- package/server/index.js +1311 -0
- package/server/lib/cloudflare-tunnel.js +650 -0
- package/server/lib/event-stream/DOCUMENTATION.md +61 -0
- package/server/lib/event-stream/directory-ws-bridge.js +185 -0
- package/server/lib/event-stream/global-hub.js +158 -0
- package/server/lib/event-stream/global-hub.test.js +140 -0
- package/server/lib/event-stream/global-ws-bridge.js +206 -0
- package/server/lib/event-stream/index.js +25 -0
- package/server/lib/event-stream/protocol.js +131 -0
- package/server/lib/event-stream/protocol.test.js +182 -0
- package/server/lib/event-stream/runtime.js +180 -0
- package/server/lib/event-stream/runtime.test.js +512 -0
- package/server/lib/event-stream/upstream-reader.js +226 -0
- package/server/lib/event-stream/upstream-reader.test.js +276 -0
- package/server/lib/fs/DOCUMENTATION.md +36 -0
- package/server/lib/fs/routes.js +1040 -0
- package/server/lib/fs/search.js +238 -0
- package/server/lib/git/DOCUMENTATION.md +152 -0
- package/server/lib/git/credentials.js +74 -0
- package/server/lib/git/identity-storage.js +112 -0
- package/server/lib/git/index.js +6 -0
- package/server/lib/git/routes.js +972 -0
- package/server/lib/git/service.js +3432 -0
- package/server/lib/git/service.test.js +39 -0
- package/server/lib/github/DOCUMENTATION.md +171 -0
- package/server/lib/github/auth.js +307 -0
- package/server/lib/github/device-flow.js +50 -0
- package/server/lib/github/index.js +24 -0
- package/server/lib/github/octokit.js +10 -0
- package/server/lib/github/pr-status.js +519 -0
- package/server/lib/github/repo/fork-detection.js +102 -0
- package/server/lib/github/repo/index.js +55 -0
- package/server/lib/github/routes.js +1560 -0
- package/server/lib/magic-prompts/routes.js +63 -0
- package/server/lib/magic-prompts/runtime.js +119 -0
- package/server/lib/notifications/DOCUMENTATION.md +122 -0
- package/server/lib/notifications/emitter-runtime.js +102 -0
- package/server/lib/notifications/index.js +4 -0
- package/server/lib/notifications/message.js +52 -0
- package/server/lib/notifications/message.test.js +34 -0
- package/server/lib/notifications/push-runtime.js +304 -0
- package/server/lib/notifications/routes.js +315 -0
- package/server/lib/notifications/runtime.js +566 -0
- package/server/lib/notifications/template-runtime.js +349 -0
- package/server/lib/notifications/template-runtime.test.js +26 -0
- package/server/lib/opencode/DOCUMENTATION.md +362 -0
- package/server/lib/opencode/agents.js +634 -0
- package/server/lib/opencode/auth-state-runtime.js +88 -0
- package/server/lib/opencode/auth.js +83 -0
- package/server/lib/opencode/bootstrap-runtime.js +131 -0
- package/server/lib/opencode/cli-entry-runtime.js +43 -0
- package/server/lib/opencode/cli-options.js +128 -0
- package/server/lib/opencode/commands.js +339 -0
- package/server/lib/opencode/config-entity-routes.js +370 -0
- package/server/lib/opencode/core-routes.js +500 -0
- package/server/lib/opencode/core-routes.test.js +26 -0
- package/server/lib/opencode/env-config.js +74 -0
- package/server/lib/opencode/env-keys.js +68 -0
- package/server/lib/opencode/env-runtime.js +1162 -0
- package/server/lib/opencode/env-runtime.test.js +116 -0
- package/server/lib/opencode/feature-routes-runtime.js +244 -0
- package/server/lib/opencode/hmr-state-runtime.js +85 -0
- package/server/lib/opencode/index.js +66 -0
- package/server/lib/opencode/lifecycle.js +1019 -0
- package/server/lib/opencode/lifecycle.test.js +240 -0
- package/server/lib/opencode/mcp.js +278 -0
- package/server/lib/opencode/network-runtime.js +104 -0
- package/server/lib/opencode/network-runtime.test.js +37 -0
- package/server/lib/opencode/opencode-resolution-runtime.js +71 -0
- package/server/lib/opencode/path-utils.js +100 -0
- package/server/lib/opencode/path-utils.test.js +71 -0
- package/server/lib/opencode/project-directory-runtime.js +124 -0
- package/server/lib/opencode/project-icon-routes.js +399 -0
- package/server/lib/opencode/project-icon-routes.test.js +107 -0
- package/server/lib/opencode/providers.js +96 -0
- package/server/lib/opencode/proxy.js +445 -0
- package/server/lib/opencode/pwa-manifest-routes.js +257 -0
- package/server/lib/opencode/pwa-manifest-routes.test.js +133 -0
- package/server/lib/opencode/routes.js +541 -0
- package/server/lib/opencode/server-startup-runtime.js +156 -0
- package/server/lib/opencode/server-utils-runtime.js +168 -0
- package/server/lib/opencode/server-utils-runtime.test.js +135 -0
- package/server/lib/opencode/session-runtime.js +356 -0
- package/server/lib/opencode/session-runtime.test.js +151 -0
- package/server/lib/opencode/settings-helpers.js +770 -0
- package/server/lib/opencode/settings-helpers.test.js +109 -0
- package/server/lib/opencode/settings-normalization-runtime.js +428 -0
- package/server/lib/opencode/settings-runtime.js +826 -0
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/shared.js +615 -0
- package/server/lib/opencode/shutdown-runtime.js +139 -0
- package/server/lib/opencode/shutdown-runtime.test.js +58 -0
- package/server/lib/opencode/skill-routes.js +701 -0
- package/server/lib/opencode/skills.js +548 -0
- package/server/lib/opencode/startup-pipeline-runtime.js +130 -0
- package/server/lib/opencode/static-routes-runtime.js +65 -0
- package/server/lib/opencode/theme-runtime.js +167 -0
- package/server/lib/opencode/tunnel-auth.js +591 -0
- package/server/lib/opencode/tunnel-wiring-runtime.js +94 -0
- package/server/lib/opencode/vinci-routes.js +76 -0
- package/server/lib/opencode/watcher.js +115 -0
- package/server/lib/opencode/watcher.test.js +239 -0
- package/server/lib/preview/proxy-runtime.js +1333 -0
- package/server/lib/preview/proxy-runtime.test.js +144 -0
- package/server/lib/projects/project-config.js +567 -0
- package/server/lib/projects/project-config.test.js +175 -0
- package/server/lib/projects/project-id.js +13 -0
- package/server/lib/quota/DOCUMENTATION.md +58 -0
- package/server/lib/quota/index.js +25 -0
- package/server/lib/quota/providers/claude.js +107 -0
- package/server/lib/quota/providers/codex.js +113 -0
- package/server/lib/quota/providers/copilot.js +165 -0
- package/server/lib/quota/providers/google/api.js +92 -0
- package/server/lib/quota/providers/google/auth.js +108 -0
- package/server/lib/quota/providers/google/index.js +124 -0
- package/server/lib/quota/providers/google/transforms.js +109 -0
- package/server/lib/quota/providers/index.js +168 -0
- package/server/lib/quota/providers/interface.js +55 -0
- package/server/lib/quota/providers/kimi.js +108 -0
- package/server/lib/quota/providers/minimax-cn-coding-plan.js +140 -0
- package/server/lib/quota/providers/minimax-coding-plan.js +139 -0
- package/server/lib/quota/providers/nanogpt.js +124 -0
- package/server/lib/quota/providers/ollama-cloud.js +112 -0
- package/server/lib/quota/providers/openai.js +91 -0
- package/server/lib/quota/providers/openrouter.js +92 -0
- package/server/lib/quota/providers/zai.js +91 -0
- package/server/lib/quota/providers/zhipuai-coding-plan.js +133 -0
- package/server/lib/quota/providers/zhipuai.js +114 -0
- package/server/lib/quota/routes.js +27 -0
- package/server/lib/quota/utils/auth.js +50 -0
- package/server/lib/quota/utils/formatters.js +85 -0
- package/server/lib/quota/utils/formatters.test.js +54 -0
- package/server/lib/quota/utils/index.js +10 -0
- package/server/lib/quota/utils/transformers.js +55 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +44 -0
- package/server/lib/scheduled-tasks/routes.js +235 -0
- package/server/lib/scheduled-tasks/runtime.js +773 -0
- package/server/lib/scheduled-tasks/runtime.test.js +100 -0
- package/server/lib/security/request-security.js +115 -0
- package/server/lib/session-folders/routes.js +63 -0
- package/server/lib/session-folders/routes.test.js +102 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +178 -0
- package/server/lib/skills-catalog/cache.js +29 -0
- package/server/lib/skills-catalog/clawdhub/api.js +158 -0
- package/server/lib/skills-catalog/clawdhub/index.js +30 -0
- package/server/lib/skills-catalog/clawdhub/install.js +238 -0
- package/server/lib/skills-catalog/clawdhub/scan.js +113 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -0
- package/server/lib/skills-catalog/git.js +77 -0
- package/server/lib/skills-catalog/index.js +42 -0
- package/server/lib/skills-catalog/install.js +294 -0
- package/server/lib/skills-catalog/scan.js +221 -0
- package/server/lib/skills-catalog/source.js +87 -0
- package/server/lib/terminal/DOCUMENTATION.md +76 -0
- package/server/lib/terminal/index.js +31 -0
- package/server/lib/terminal/output-replay-buffer.js +78 -0
- package/server/lib/terminal/output-replay-buffer.test.js +75 -0
- package/server/lib/terminal/runtime.js +850 -0
- package/server/lib/terminal/runtime.test.js +96 -0
- package/server/lib/terminal/terminal-ws-protocol.js +68 -0
- package/server/lib/terminal/terminal-ws-protocol.test.js +145 -0
- package/server/lib/text/DOCUMENTATION.md +35 -0
- package/server/lib/text/summarization.js +138 -0
- package/server/lib/text/summarization.test.js +34 -0
- package/server/lib/tts/DOCUMENTATION.md +146 -0
- package/server/lib/tts/base-url.js +62 -0
- package/server/lib/tts/capability-runtime.js +31 -0
- package/server/lib/tts/index.js +19 -0
- package/server/lib/tts/routes.js +261 -0
- package/server/lib/tts/routes.test.js +53 -0
- package/server/lib/tts/service.js +178 -0
- package/server/lib/tts/stt.js +75 -0
- package/server/lib/tunnels/DOCUMENTATION.md +18 -0
- package/server/lib/tunnels/index.js +166 -0
- package/server/lib/tunnels/managed-config.js +201 -0
- package/server/lib/tunnels/providers/cloudflare.js +260 -0
- package/server/lib/tunnels/registry.js +51 -0
- package/server/lib/tunnels/routes.js +605 -0
- package/server/lib/tunnels/types.js +219 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +38 -0
- package/server/lib/ui-auth/ui-auth.js +673 -0
- package/server/lib/ui-auth/ui-passkeys.js +545 -0
- package/server/opencode-proxy.test.js +151 -0
- package/server/proxy-headers.js +61 -0
- package/server/proxy-headers.test.js +58 -0
- package/server/sse-routes.test.js +152 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-B9l0ZNi2.js","assets/vendor--DBfsbEis.css","assets/modelPrefsAutoSave-Dm799vzR.js","assets/index-DgiFEKGN.js","assets/index-DLTDToSP.css","assets/TerminalView-DrZ-i3Dr.js","assets/JsonTreeView-CSm9OzXG.js","assets/SettingsWindow-coz__Ykw.js","assets/MultiRunWindow-Bo7THayo.js","assets/OnboardingScreen-BDqmzTVR.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{aI as at,Z as o,bF as Ja,bE as oa,b5 as s,bH as Dl,C as Tl,Q as Xa,ac as cl,a_ as Jg,p as dl,o as Za,aG as eo,aL as gr,aS as Na,bh as Be,ag as Xg,af as Zg,bd as mo,aM as Ml,d as ex,e as tx,c as sx,ax as kr,bg as Wa,aB as Ef,bK as Hc,ay as Hi,bJ as Rf,aw as nx,av as rx,aq as ix,s as ax,ar as ox,bG as Br,q as lx,r as Xn,aV as cx,f as Sa,b8 as mu,aY as dx,b0 as ux,b6 as Ql,b1 as mx,aR as px,aZ as fx,bq as pu,bo as fu,ap as hx,Y as Ff,g as Lf,ad as gx,bp as hu,aT as xx,bc as bx,aF as yx,au as vx,E as wx,ae as jx,br as Nx,be as Of,b9 as Sx,a$ as Gc,aO as $f,b4 as Bf,b3 as ra,bv as Ba,H as qc,bw as ot,L as zf,b7 as Vf,aQ as kx,aD as Cx,F as Px,aJ as Ix,aX as Ax,X as Dx,bB as Tx,bC as Mx,K as Ex,bs as Rx,bD as gu,az as xu,bb as Jl,aE as Fx}from"./vendor-.bun-B9l0ZNi2.js";import{g as Lx,h as Ox,w as $x}from"./index-DgiFEKGN.js";import{ew as ut,eZ as Ie,e6 as rn,aG as ce,P,dW as ks,cF as mn,bY as pr,c2 as pi,dI as Xl,d4 as Zl,bh as ec,eE as As,cY as Zs,e8 as $s,ao as Pt,ar as It,ap as Dt,cE as pa,cp as Bi,bc as bu,x as $t,cW as Bx,cV as ul,aI as _n,dS as H,J as Es,F as Cn,w as Rs,v as Fs,c1 as _f,b0 as yu,a$ as zx,b3 as Vx,b6 as vu,b1 as _x,b2 as Ux,cM as Wx,aK as Kx,eG as Pn,cq as gn,cX as rr,bV as Yc,a0 as vn,y as Ka,m as Hx,e3 as xt,eQ as Ot,eN as Gx,eI as Uf,ev as Ei,d_ as Ad,el as Hn,aD as Dd,eX as El,aZ as qx,cN as wu,d3 as Yx,bx as Qx,eS as Wf,bq as Jx,ei as Xx,dr as Kf,ec as Td,ch as ml,dJ as Hf,br as Rl,bI as Zr,cd as Md,ba as Yo,af as Zx,k as eb,K as Xs,eC as Gf,eB as qf,Q as Bt,a5 as Cs,T as $r,dZ as fa,bg as tb,cA as Yf,r as bs,s as gs,B as ge,o as fs,n as hs,ey as zi,dy as sb,bW as nb,_ as Co,de as wn,aP as Qf,bs as Jf,eH as Fl,aV as rb,di as Xf,ce as ju,Z as Nu,ak as hn,i as ds,d2 as ib,aU as ab,dX as ob,aL as lb,b7 as cb,bM as db,bK as ub,bb as zs,cK as mb,aJ as pb,p as Is,dN as fb,aw as hb,d1 as gb,b8 as xb,N as Zn,a4 as po,U as bb,q as Vs,eD as Ll,ex as ia,bF as ha,b9 as ga,bZ as Su,bO as xa,bA as yb,a6 as is,ac as as,ad as us,a7 as os,a9 as Ft,bv as vb,ag as to,bC as wb,eb as Ir,ez as Ed,es as Ol,c3 as jb,ej as Rd,eq as Nb,em as Sb,ep as Fd,eo as kb,et as tn,c0 as fo,dB as Sr,bu as Cb,bL as Pb,bS as tc,e7 as $l,ee as Ld,ed as Bl,e5 as ho,ef as Bn,b$ as Od,bk as Vi,z as pl,E as fl,cv as so,t as Zf,ek as Ib,eY as Ar,cU as Ab,cm as Db,cl as Tb,cG as Mb,cz as Eb,bN as ku,bQ as hl,eT as zl,bw as eh,c_ as Rb,eL as Fb,aX as go,ci as Lb,A as $d,ck as Ob,cj as aa,cx as no,ea as th,cZ as ba,cB as sh,a1 as $b,b_ as Bb,e2 as Bd,eV as fi,co as la,eU as Ri,Y as Vl,bX as xo,W as bo,cL as Qc,aF as nh,ca as zd,dz as rh,bm as ro,dx as zb,V as Vb,X as _b,b4 as Ub,b5 as Wb,d8 as Fi,bE as sc,dl as Cu,dw as Kb,dk as Hb,bP as Gb,bd as qb,a2 as ta,dD as nc,bT as Yb,eA as Pu,cH as Li,dQ as Qb,as as Iu,l as Au,C as Du,D as Tu,dC as Qo,cR as Mu,eJ as Jb,aT as Xb,bU as Zb,bf as ey,be as rc,aE as Eu,d6 as ty,cy as sy,du as ny,dj as ry,e1 as iy,aB as ic,aA as ay,av as Ru,f1 as za,bH as oy,ds as ih,bD as ly,cO as sa,cI as cy,cC as Fu,at as dy,bj as uy,eh as ah,dA as Po,dp as Ha,dU as my,aO as oh,bR as py,c4 as fy,c8 as Lu,d0 as Ou,f0 as lh,en as ch,bt as ac,e4 as Io,f2 as hy,aN as gy,aM as xy,dY as by,j as dh,M as uh,d5 as Jc,by as Vd,dn as yy,cS as xs,cD as io,aS as ya,aH as ca,cP as $u,eK as Yn,cn as vy,dc as Ga,a as wy,bn as mh,dv as jy,dt as Ny,a8 as Xc,cu as Sy,c6 as ky,bi as Bu,c7 as Cy,e9 as Py,eW as _d,e_ as ph,eu as Iy,eO as Ay,eR as Dy,bp as Ty,aC as zu,G as My,I as Ey,H as Ry,bo as Fy,eP as oc,d$ as Ly,dK as fh,er as Oy,$ as $y,cr as By,cT as zy,dh as Vy,dG as _y,dO as Uy,aW as Wy,cb as Ky,d9 as Hy,az as Gy,dq as qy,aQ as Yy,aa as Vu,ab as Qy,c as hh,e as Jy,f as Xy,d as Zy,g as ev,cJ as si,u as tv,S as _u,bz as sv,c5 as Jo,c9 as Xo,dm as nv,dF as rv,bB as iv,dP as av,aR as Uu,bG as ov,dE as Wu,ax as lv,d7 as Ku,e0 as cv,eF as dv,e$ as uv,ai as Hu,a3 as Gu,aq as qu,au as mv,ah as gh,an as xh,cg as pv,cf as fv,dR as hv,ay as gv,dH as xv,dL as bv,dM as yv,O as vv,am as wv,al as jv,ae as Nv}from"./modelPrefsAutoSave-Dm799vzR.js";import{J as Sv}from"./JsonTreeView-CSm9OzXG.js";const kv=({transform:t})=>({...t,y:0}),Cv=t=>{const e=at.c(18),{id:n,children:r,className:i}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:l,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=Dl(a);let h;e[2]!==p?(h=Tl.Transform.toString(p),e[2]=p,e[3]=h):h=e[3];let x;e[4]!==h||e[5]!==m?(x={transform:h,transition:m},e[4]=h,e[5]=m,e[6]=x):x=e[6];const f=u&&"opacity-50";let v;e[7]!==i||e[8]!==f?(v=ce("h-full rounded-md",i,f),e[7]=i,e[8]=f,e[9]=v):v=e[9];let y;return e[10]!==l||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==x||e[16]!==v?(y=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:x,className:v,...l,...c,children:r}),e[10]=l,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=x,e[16]=v,e[17]=y):y=e[17],y},Pv=t=>{const e=at.c(6),{id:n,children:r,className:i}=t;let a;e[0]!==i?(a=ce("h-full",i),e[0]=i,e[1]=a):a=e[1];let l;return e[2]!==r||e[3]!==n||e[4]!==a?(l=s.jsx("div",{className:a,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=a,e[5]=l):l=e[5],l},Cr=t=>{const e=at.c(121),{items:n,activeId:r,onSelect:i,onClose:a,onReorder:l,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:h,animateActivePill:x,activePillLowercase:f,className:v}=t,y=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,b=h===void 0?!1:h,k=f===void 0?!0:f,{t:I}=ut(),j=Ie(Iv),{isTablet:N}=rn(),D=j||N,E=o.useRef(null);let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T={left:!1,right:!1},e[0]=T):T=e[0];const[C,S]=o.useState(T);let M;e[1]!==n?(M=n.map(Av),e[1]=n,e[2]=M):M=e[2];const A=M,R=y==="scrollable",z=g==="default",B=g==="active-pill",V=g==="animated",$=B||V,_=z,X=$||_,O=B&&R,J=$,Q=x??V,ne=typeof l=="function",G=ne?Cv:Pv;let le;e[3]===Symbol.for("react.memo_cache_sentinel")?(le=new Map,e[3]=le):le=e[3];const oe=o.useRef(le),[F,U]=o.useState(null);let W;e[4]===Symbol.for("react.memo_cache_sentinel")?(W={activationConstraint:{distance:8}},e[4]=W):W=e[4];const te=Ja(oa(Xa,W)),K=Dv;let ae;e[5]===Symbol.for("react.memo_cache_sentinel")?(ae=(Qe,he)=>{if(he){oe.current.set(Qe,he);return}oe.current.delete(Qe)},e[5]=ae):ae=e[5];const ve=ae;let re;e[6]!==r||e[7]!==X?(re=()=>{if(!X||!r){U(Tv);return}const Qe=E.current,he=oe.current.get(r);if(!Qe||!he){U(Mv);return}let Ge=0,Ve=0,it=he;for(;it&&it!==Qe;)Ge=Ge+it.offsetLeft,Ve=Ve+it.offsetTop,it=it.offsetParent;const dt={left:Ge,top:Ve,width:he.offsetWidth,height:he.offsetHeight};U(Ye=>K(Ye,dt)?Ye:dt)},e[6]=r,e[7]=X,e[8]=re):re=e[8];const be=re;let pe;e[9]!==R?(pe=()=>{if(!R){S({left:!1,right:!1});return}const Qe=E.current;if(!Qe){S({left:!1,right:!1});return}S({left:Qe.scrollLeft>2,right:Qe.scrollLeft+Qe.clientWidth<Qe.scrollWidth-2})},e[9]=R,e[10]=pe):pe=e[10];const ye=pe;let ie;e[11]!==R||e[12]!==ye?(ie=()=>{if(!R){S({left:!1,right:!1});return}const Qe=E.current;if(!Qe)return;ye(),Qe.addEventListener("scroll",ye,{passive:!0});const he=new ResizeObserver(ye);return he.observe(Qe),()=>{Qe.removeEventListener("scroll",ye),he.disconnect()}},e[11]=R,e[12]=ye,e[13]=ie):ie=e[13];let ue;e[14]!==R||e[15]!==n.length||e[16]!==ye?(ue=[R,n.length,ye],e[14]=R,e[15]=n.length,e[16]=ye,e[17]=ue):ue=e[17],o.useEffect(ie,ue);let se;e[18]!==r||e[19]!==be||e[20]!==X?(se=()=>{if(!X){U(null);return}be();const Qe=E.current;if(!Qe)return;const he=new ResizeObserver(be);if(he.observe(Qe),r){const Ge=oe.current.get(r);Ge&&he.observe(Ge)}return()=>{he.disconnect()}},e[18]=r,e[19]=be,e[20]=X,e[21]=se):se=e[21];let Ne;e[22]!==r||e[23]!==n.length||e[24]!==be||e[25]!==X?(Ne=[r,n.length,be,X],e[22]=r,e[23]=n.length,e[24]=be,e[25]=X,e[26]=Ne):Ne=e[26],o.useEffect(se,Ne);let Ce;e[27]!==be?(Ce=()=>{be()},e[27]=be,e[28]=Ce):Ce=e[28],o.useLayoutEffect(Ce);let je;e[29]!==r||e[30]!==R||e[31]!==ye?(je=()=>{if(!R||!r)return;const Qe=E.current;if(!Qe)return;const he=window.requestAnimationFrame(()=>{const Ge=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),Ve=Qe.querySelector(`[data-sortable-tab-id="${Ge}"]`);Ve&&(Ve.scrollIntoView({block:"nearest",inline:"nearest"}),ye())});return()=>{window.cancelAnimationFrame(he)}},e[29]=r,e[30]=R,e[31]=ye,e[32]=je):je=e[32];let we;e[33]!==r||e[34]!==R||e[35]!==n.length||e[36]!==ye?(we=[r,R,n.length,ye],e[33]=r,e[34]=R,e[35]=n.length,e[36]=ye,e[37]=we):we=e[37],o.useEffect(je,we);let ke;e[38]!==l?(ke=Qe=>{if(!l)return;const{active:he,over:Ge}=Qe;!Ge||he.id===Ge.id||l(String(he.id),String(Ge.id))},e[38]=l,e[39]=ke):ke=e[39];const xe=ke;let me;e[40]!==v?(me=ce("relative flex h-full min-w-0 flex-1",v),e[40]=v,e[41]=me):me=e[41];let Me;e[42]!==R||e[43]!==C||e[44]!==$?(Me=R&&C.left?s.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=R,e[43]=C,e[44]=$,e[45]=Me):Me=e[45];let Ue;e[46]!==R||e[47]!==C||e[48]!==$?(Ue=R&&C.right?s.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=R,e[47]=C,e[48]=$,e[49]=Ue):Ue=e[49];const q=$?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Se=$&&"@container/pill-tabs",$e=$&&"pill-tabs__track",Pe=$&&(p??"gap-0.5 py-0.5"),fe=_&&"items-center overflow-y-hidden",L=J&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_2%,transparent)] p-0.5 gap-0.5",Z=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Y;e[50]!==q||e[51]!==Se||e[52]!==$e||e[53]!==Pe||e[54]!==fe||e[55]!==L||e[56]!==Z?(Y=ce("relative flex h-full min-w-0 flex-1",q,Se,$e,Pe,fe,L,Z),e[50]=q,e[51]=Se,e[52]=$e,e[53]=Pe,e[54]=fe,e[55]=L,e[56]=Z,e[57]=Y):Y=e[57];let Ee;e[58]!==R?(Ee=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=Ee):Ee=e[59];let Ae;e[60]!==I?(Ae=I("sortableTabsStrip.aria.tabs"),e[60]=I,e[61]=Ae):Ae=e[61];let Je;e[62]!==F||e[63]!==Q||e[64]!==$?(Je=$&&F?s.jsx("div",{className:ce("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${F.left}px, ${F.top}px, 0)`,width:`${F.width}px`,height:`${F.height}px`,transition:Q?"transform 300ms cubic-bezier(0.65, 0, 0.35, 1), width 300ms cubic-bezier(0.65, 0, 0.35, 1), height 300ms cubic-bezier(0.65, 0, 0.35, 1)":void 0}}):null,e[62]=F,e[63]=Q,e[64]=$,e[65]=Je):Je=e[65];let de;e[66]!==F||e[67]!==_?(de=_&&F?s.jsx("div",{className:"pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",style:{transform:`translate3d(${F.left}px, 0, 0)`,width:`${F.width}px`},"aria-hidden":!0}):null,e[66]=F,e[67]=_,e[68]=de):de=e[68];let ze;if(e[69]!==G||e[70]!==r||e[71]!==m||e[72]!==k||e[73]!==D||e[74]!==b||e[75]!==w||e[76]!==B||e[77]!==j||e[78]!==R||e[79]!==n||e[80]!==a||e[81]!==i||e[82]!==O||e[83]!==$){let Qe;e[85]!==G||e[86]!==r||e[87]!==m||e[88]!==k||e[89]!==D||e[90]!==b||e[91]!==w||e[92]!==B||e[93]!==j||e[94]!==R||e[95]!==a||e[96]!==i||e[97]!==O||e[98]!==$?(Qe=he=>{const Ge=he.id===r,Ve=w&&$&&!Ge&&!!he.icon,it=!Ve,dt=!!he.icon&&(!b||Ge),Ye=w&&$&&Ge&&!R&&!O,_e=he.closable!==!1&&!!a,et=_e&&!!he.icon,gt=R||O?void 0:$?Ye?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",Lt=_e?mt=>{mt.button===1&&(mt.preventDefault(),mt.stopPropagation(),a?.(he.id))}:void 0,Ut=_e?Ev:void 0;return s.jsx(G,{id:he.id,className:gt,children:s.jsxs("div",{ref:mt=>ve(he.id,mt),onAuxClick:Lt,onMouseDown:Ut,className:ce("group flex h-full min-w-0 flex-nowrap items-center",R||O?"shrink-0":$?"w-full":"w-full min-w-0",$?"relative z-10 bg-transparent":Ge?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":Ge,"aria-label":Ve?he.title??he.label:void 0,onClick:()=>i(he.id),className:ce($?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",$&&k?"lowercase":null,$&&(Ve?"gap-0":"gap-1.5"),$?O?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":Ve?"px-2 !min-w-0 text-center":Ye?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":R?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",$?m??(B?j?"h-[38px]":"h-[31px]":"h-7"):null,$?Ge?"text-foreground":"text-muted-foreground hover:text-foreground":null,$?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:he.title??he.label,children:$?s.jsxs(s.Fragment,{children:[dt?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:ce("flex items-center justify-center transition-opacity",et&&(D?"opacity-0":"group-hover:opacity-0")),children:he.icon}),et?s.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Rv,onClick:mt=>{mt.stopPropagation(),a?.(he.id)},"aria-label":he.closeLabel??`Close ${he.label} tab`,title:he.closeLabel??`Close ${he.label} tab`,children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,it?s.jsx("span",{className:"animated-tabs__label truncate",children:he.label}):null]}):s.jsxs("span",{className:ce("flex min-w-0 flex-nowrap items-center gap-1.5",!R&&"justify-center"),children:[dt?s.jsxs("span",{className:ce("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Ge?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:ce("flex items-center justify-center transition-opacity",et&&(D?"opacity-0":"group-hover:opacity-0")),children:he.icon}),et?s.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Fv,onClick:mt=>{mt.stopPropagation(),a?.(he.id)},"aria-label":he.closeLabel??`Close ${he.label} tab`,title:he.closeLabel??`Close ${he.label} tab`,children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:he.label})]})}),_e&&!et?s.jsx("button",{type:"button",onPointerDown:Lv,onClick:mt=>{mt.stopPropagation(),a?.(he.id)},className:ce("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",$?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",$?Ge?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Ge?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":he.closeLabel??`Close ${he.label} tab`,title:he.closeLabel??`Close ${he.label} tab`,children:s.jsx(P,{name:"close",className:"h-3 w-3"})}):null]})},he.id)},e[85]=G,e[86]=r,e[87]=m,e[88]=k,e[89]=D,e[90]=b,e[91]=w,e[92]=B,e[93]=j,e[94]=R,e[95]=a,e[96]=i,e[97]=O,e[98]=$,e[99]=Qe):Qe=e[99],ze=n.map(Qe),e[69]=G,e[70]=r,e[71]=m,e[72]=k,e[73]=D,e[74]=b,e[75]=w,e[76]=B,e[77]=j,e[78]=R,e[79]=n,e[80]=a,e[81]=i,e[82]=O,e[83]=$,e[84]=ze}else ze=e[84];let rt;e[100]!==Y||e[101]!==Ee||e[102]!==Ae||e[103]!==Je||e[104]!==de||e[105]!==ze?(rt=s.jsxs("div",{ref:E,className:Y,style:Ee,role:"tablist","aria-label":Ae,children:[Je,de,ze]}),e[100]=Y,e[101]=Ee,e[102]=Ae,e[103]=Je,e[104]=de,e[105]=ze,e[106]=rt):rt=e[106];let Re;e[107]!==me||e[108]!==Me||e[109]!==Ue||e[110]!==rt?(Re=s.jsxs("div",{className:me,children:[Me,Ue,rt]}),e[107]=me,e[108]=Me,e[109]=Ue,e[110]=rt,e[111]=Re):Re=e[111];const Xe=Re;if(!ne)return Xe;let qe;e[112]===Symbol.for("react.memo_cache_sentinel")?(qe=[kv],e[112]=qe):qe=e[112];let Te;e[113]!==A||e[114]!==Xe?(Te=s.jsx(cl,{items:A,strategy:Jg,children:Xe}),e[113]=A,e[114]=Xe,e[115]=Te):Te=e[115];let We;e[116]===Symbol.for("react.memo_cache_sentinel")?(We=s.jsx(dl,{dropAnimation:null}),e[116]=We):We=e[116];let Ze;return e[117]!==xe||e[118]!==te||e[119]!==Te?(Ze=s.jsxs(Za,{sensors:te,collisionDetection:eo,onDragEnd:xe,modifiers:qe,children:[Te,We]}),e[117]=xe,e[118]=te,e[119]=Te,e[120]=Ze):Ze=e[120],Ze};function Iv(t){return t.isMobile}function Av(t){return t.id}function Dv(t,e){return!t||!e?t===e:Math.abs(t.left-e.left)<.5&&Math.abs(t.top-e.top)<.5&&Math.abs(t.width-e.width)<.5&&Math.abs(t.height-e.height)<.5}function Tv(t){return t===null?t:null}function Mv(t){return t===null?t:null}function Ev(t){t.button===1&&t.preventDefault()}function Rv(t){t.stopPropagation()}function Fv(t){t.stopPropagation()}function Lv(t){t.stopPropagation()}function Yu(t){const e=at.c(14);let n,r,i,a;e[0]!==t?({size:i,className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(n=e[1],r=e[2],i=e[3],a=e[4]);const l=typeof i=="number"?`${i}px`:i,c=typeof i=="number"?`${i}px`:i;let d;e[5]!==a||e[6]!==l||e[7]!==c?(d={width:l,height:c,...a},e[5]=a,e[6]=l,e[7]=c,e[8]=d):d=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=p):p=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:p}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Hr=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"zhipuai-coding-plan",name:"ZhipuAI"}];Hr.reduce((t,e)=>(t[e.id]=e,t),{});const Ov=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),$v=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,ao=(t,e)=>t??$v(e),Ud=(t,e)=>{if(!t)return e??"";try{const n=new Date(t);if(!Number.isFinite(n.getTime()))return e??"";const r=new Date;return n.toDateString()===r.toDateString()?n.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}):n.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit"})}catch{return e??""}},bh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",Wd=t=>t==="5h"?"5-Hour":t==="7d"?"7-Day Limit":t==="7d-sonnet"?"7-Day Sonnet Limit":t==="7d-opus"?"7-Day Opus Limit":t==="weekly"?"Weekly Limit":t==="daily"?"Daily":t==="monthly"?"Monthly Limit":t==="credits"?"Credits":t==="session"?"Session":t==="premium"?"Premium Interactions":t==="chat"?"Chat Requests":t==="completions"?"Completions":t==="premium_interactions"?"Premium interactions":t,Bv=t=>{const e=t.toLowerCase().trim();if(e==="5h")return 5*3600;if(e==="7d"||e==="weekly"||e==="7d-sonnet"||e==="7d-opus")return 7*86400;if(e==="monthly")return 30*86400;if(e==="24h"||e==="daily")return 86400;if(e==="1h")return 3600;const n=e.match(/^(\d+)h$/);if(n)return parseInt(n[1],10)*3600;const r=e.match(/^(\d+)d$/);return r?parseInt(r[1],10)*86400:null},oo=(t,e,n,r)=>{let i=n;if(i===null&&r&&(i=Bv(r)),t===null||e===null||i===null||i<=0)return null;const a=Date.now(),l=Math.max(0,(e-a)/1e3),c=Math.max(0,Math.min(i,i-l)),d=Math.max(0,Math.min(1,c/i)),p=t/100,m=t>=100&&l>0;let u;d>.01?u=Math.min(999,p/d*100):u=t;let h;m?h="exhausted":p<=d?h="on-track":u<=130?h="slightly-fast":h="too-fast";const x=i>=120*3600,f=x?86400:3600,v=x?"d":"h",y=i/f,g=Math.max(c/f,y*.01),w=t/g,b=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${v}`:"-",k=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let I=null;const j=i/86400;return j>=7&&(I=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:l,isExhausted:m,elapsedSeconds:c,totalSeconds:i,status:h,paceRateText:b,predictText:k,dailyAllocationPercent:I}},zv=t=>{switch(t){case"exhausted":case"too-fast":return"var(--status-error)";case"slightly-fast":return"var(--status-warning)";case"on-track":return"var(--status-success)"}},Qu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),i=Math.floor(r/24),a=r%24,l=n%60;return i>0?`${i}d ${a}h`:r>0?`${r}h`:n===0?"<1m":`${l}m`},ei=t=>Math.min(100,Math.max(0,t*100));function gl(t){const e=t.indexOf("/");if(e!==-1){const n=t.substring(0,e);if(n==="gemini"||n==="antigravity")return t.substring(e+1)}return t}const Vv=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],yh={google:Vv};function vh(t,e){const n=yh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function wh(t){return yh[t]??[]}function jh(t){return[...t].sort((e,n)=>e.order-n.order)}function _v(t,e){const n=new Map;for(const r of Object.keys(t)){const a=vh(r,e)?.id??null;n.has(a)||n.set(a,[]),n.get(a).push(r)}return n}function Uv(t,e,n){const r=new Map;for(const i of t){const a=e(i),c=vh(a,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(i)}return r}function Wv(t,e){return e.filter(n=>{const r=n.toLowerCase(),i=r.includes("/")?r.split("/")[1]:r;return!!(i.startsWith("gemini-3-")||i.startsWith("claude-"))})}const Kd=6e4,Ju=t=>{const e=Hr.map(u=>u.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):Kd,i=t?.usageDisplayMode==="remaining"?"remaining":"usage",a=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,l=a?a.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[u,h]of Object.entries(d))Array.isArray(h)&&(c[u]=h.filter(x=>typeof x=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,h]of Object.entries(m))Array.isArray(h)&&(p[u]=h.filter(x=>typeof x=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:i,dropdownProviderIds:l,selectedModels:c,expandedFamilies:p}},Kv=async()=>{const t=pr()?.settings;if(t)try{const n=(await t.load())?.settings;return Ju(n??null)}catch{}if(!mn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Ju(n)}}return{autoRefresh:!1,refreshIntervalMs:Kd,displayMode:"usage",dropdownProviderIds:Hr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ms=gr()(Na((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Kd,displayMode:"usage",dropdownProviderIds:Hr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Kv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Hr.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const i=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:i})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),i=await r.json().catch(()=>null);if(!r.ok)throw new Error(i?.error||"Failed to fetch quota");const a=i;t(l=>{const c=l.results.filter(d=>d.providerId!==n);return c.push(a),{results:c,error:null}})}catch(r){const i=r instanceof Error?r.message:"Failed to fetch quota",a={providerId:n,providerName:n,ok:!1,configured:!1,error:i,usage:null,fetchedAt:Date.now()};t(l=>{const c=l.results.filter(d=>d.providerId!==n);return c.push(a),{results:c,error:i}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(i=>({selectedModels:{...i.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(i=>{const a=i.selectedModels[n]??[],c=a.includes(r)?a.filter(d=>d!==r):[...a,r];return{selectedModels:{...i.selectedModels,[n]:c}}})},setExpandedFamilies:(n,r)=>{t(i=>({expandedFamilies:{...i.expandedFamilies,[n]:r}})),ks({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(i=>{const a=i.expandedFamilies[n]??[],c=a.includes(r)?a.filter(d=>d!==r):[...a,r];return{expandedFamilies:{...i.expandedFamilies,[n]:c}}}),ks({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const a=Wv(n,r);a.length!==0&&(t(l=>({selectedModels:{...l.selectedModels,[n]:a}})),ks({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Nh=()=>{const t=at.c(5),e=Ms(Hv),n=Ms(Gv),r=Ms(qv);let i,a;t[0]!==e||t[1]!==r||t[2]!==n?(i=()=>{if(!e)return;const l=window.setInterval(()=>{r()},n);return()=>window.clearInterval(l)},a=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=a):(i=t[3],a=t[4]),o.useEffect(i,a)};function Hv(t){return t.autoRefresh}function Gv(t){return t.refreshIntervalMs}function qv(t){return t.fetchAllQuotas}const xl=Be.forwardRef((t,e)=>{const n=at.c(11);let r,i;n[0]!==t?({className:r,...i}=t,n[0]=t,n[1]=r,n[2]=i):(r=n[1],i=n[2]);let a;n[3]!==r?(a=ce("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=a):a=n[4];let l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Xg,{className:ce("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=c):c=n[6];let d;return n[7]!==i||n[8]!==e||n[9]!==a?(d=s.jsx(Zg,{className:a,style:l,...i,ref:e,children:c}),n[7]=i,n[8]=e,n[9]=a,n[10]=d):d=n[10],d});xl.displayName="Switch";const Ao=()=>{try{const e=As.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=Zs.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},Xu=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],Zu=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},Do=t=>typeof t!="string"?void 0:t.trim()||void 0,lc=800,Yv=5e3,Qv="__default__",Zc=new Map,cc=new Map,Sh=t=>t?.trim()||Qv,dc=t=>{Zc.delete(Sh(t))},lo=gr()(Na(mo((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=Ao(),i=Sh(r),a=Date.now(),l=Zc.get(i)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&a-l<Yv)return!0;const d=cc.get(i);if(!n?.force&&d)return d;const p=(async()=>{t({isLoading:!0});try{const m=r?`?directory=${encodeURIComponent(r)}`:"",u=await fetch(`/api/config/mcp${m}`,{headers:r?{"x-opencode-directory":r}:void 0});if(!u.ok)throw new Error("Failed to load MCP configs");const h=await u.json();return t({mcpServers:h,isLoading:!1}),Zc.set(i,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();cc.set(i,p);try{return await p}finally{cc.delete(i)}},createMcp:async n=>{Xl("Creating MCP server configuration…");let r=!1;try{const i=em(n),a=Ao(),l=a?`?directory=${encodeURIComponent(a)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${l}`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-opencode-directory":a}:{}},body:JSON.stringify(i)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return dc(a),d?.requiresReload?(r=!0,await Zl({message:d.message,delayMs:d.reloadDelayMs??lc,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning})}catch(i){return console.error("[McpConfigStore] Failed to create MCP:",i),{ok:!1}}finally{r||ec()}},updateMcp:async(n,r)=>{Xl("Updating MCP server configuration…");let i=!1;try{const a=em(r),l=Ao(),c=l?`?directory=${encodeURIComponent(l)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},body:JSON.stringify(a)}),p=await d.json().catch(()=>null);if(!d.ok)throw new Error(p?.error||"Failed to update MCP server");return dc(l),p?.requiresReload?(i=!0,await Zl({message:p.message,delayMs:p.reloadDelayMs??lc,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning})}catch(a){throw console.error("[McpConfigStore] Failed to update MCP:",a),a}finally{i||ec()}},deleteMcp:async n=>{Xl("Deleting MCP server configuration…");let r=!1;try{const i=Ao(),a=i?`?directory=${encodeURIComponent(i)}`:"",l=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${a}`,{method:"DELETE",headers:i?{"x-opencode-directory":i}:void 0}),c=await l.json().catch(()=>null);if(!l.ok)throw new Error(c?.error||"Failed to delete MCP server");return dc(i),c?.requiresReload&&(r=!0,await Zl({message:c.message,delayMs:c.reloadDelayMs??lc,scopes:["all"]})),e().selectedMcpName===n&&t({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}}catch(i){return console.error("[McpConfigStore] Failed to delete MCP:",i),{ok:!1}}finally{r||ec()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:Ml(()=>pi()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function em(t){const e={};if(t.scope!==void 0&&(e.scope=t.scope),t.type!==void 0&&(e.type=t.type),(t.type==="local"||t.command!==void 0)&&(e.command=(t.command??[]).filter(n=>n.trim())),(t.type==="remote"||t.url!==void 0)&&(e.url=t.url?.trim()??""),t.environment!==void 0&&(e.environment=Zu(t.environment)??{}),t.headers!==void 0&&(e.headers=Zu(t.headers)??{}),t.oauthEnabled!==void 0||t.oauthClientId!==void 0||t.oauthClientSecret!==void 0||t.oauthScope!==void 0||t.oauthRedirectUri!==void 0)if(t.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:Do(t.oauthClientId),clientSecret:Do(t.oauthClientSecret),scope:Do(t.oauthScope),redirectUri:Do(t.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:t.oauthEnabled?e.oauth={}:e.oauth=!1}if(t.timeout!==void 0){const n=Number(t.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return t.enabled!==void 0&&(e.enabled=t.enabled),e}const Jv={},Xv={},Xr=t=>{if(typeof t!="string")return null;const e=t.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},Ji=t=>Xr(t)??"__global__",wi=t=>{const e=Xr(t);return e?Zs.getScopedApiClient(e):Zs.getApiClient()},yn=gr()(Na((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Ji(n??$s.getState().currentDirectory);return e().byDirectory[r]??Jv},getDiagnosticForDirectory:n=>{const r=Ji(n??$s.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Xv},getErrorForDirectory:n=>{const r=Ji(n??$s.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Xr(n?.directory??$s.getState().currentDirectory),i=Ji(r);n?.silent||t(a=>({loadingKeys:{...a.loadingKeys,[i]:!0},lastErrorKeys:{...a.lastErrorKeys,[i]:null}}));try{const c=(await wi(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[i]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[i]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[i]??{}).filter(([p])=>!c[p]))},loadingKeys:{...d.loadingKeys,[i]:!1},lastErrorKeys:{...d.lastErrorKeys,[i]:null}}))}catch(a){const l=a instanceof Error?a.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[i]:!1},lastErrorKeys:{...c.lastErrorKeys,[i]:l}}))}},connect:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory),a=Ji(i),l=wi(i);try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw t(p=>({diagnosticsByDirectory:{...p.diagnosticsByDirectory,[a]:{...p.diagnosticsByDirectory[a]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:i,silent:!0})},disconnect:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory);await wi(i).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},startAuth:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory),c=(await wi(i).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!c)throw new Error("Authorization URL was not returned");return c},completeAuth:async(n,r,i)=>{const a=Xr(i??$s.getState().currentDirectory);await wi(a).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},clearAuth:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory);await wi(i).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},testConnection:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory),a=Ji(i),l=wi(i),d=e().getStatusForDirectory(i)[n]?.status==="connected";let p,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(x){p=x instanceof Error?x.message:"Connection failed",t(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[a]:{...f.diagnosticsByDirectory[a]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:i,silent:!0});const u=e().getStatusForDirectory(i)[n],h=u;if(!d&&u?.status==="connected"){try{await l.mcp.disconnect({name:n},{throwOnError:!0})}catch(x){m=`Connection test succeeded, but cleanup disconnect failed: ${x instanceof Error?x.message:"Disconnect failed"}`}await e().refresh({directory:i,silent:!0})}return{status:h??e().getStatusForDirectory(i)[n],error:p,warning:m}}})));function Zv(t){const e=at.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let i;return e[2]!==t?(i=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=i):i=e[3],i}const ew=(t,e)=>{if(!t)return e("mcpDropdown.status.unknown");switch(t.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:t.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:t.error||""});default:return t.status}},tw=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},kh=({active:t,className:e})=>{const{t:n}=ut(),i=$s(g=>g.currentDirectory)??null,a=yn(g=>g.getStatusForDirectory(i)),l=yn(g=>g.refresh),c=yn(g=>g.connect),d=yn(g=>g.disconnect),p=lo(g=>g.mcpServers),m=lo(g=>g.loadMcpConfigs),[u,h]=o.useState(!1),[x,f]=o.useState(null);o.useEffect(()=>{l({directory:i,silent:!0})},[l,i]),o.useEffect(()=>{m({force:!0})},[m]),o.useEffect(()=>{t&&Promise.all([l({directory:i,silent:!0}),m({force:!0})])},[t,l,i,m]);const v=o.useMemo(()=>{const g=new Set(Object.keys(a));for(const w of p)w?.name&&g.add(w.name);return Array.from(g).sort((w,b)=>w.localeCompare(b))},[p,a]),y=o.useCallback(g=>{if(g?.preventDefault(),u)return;h(!0);const w=new Promise(b=>setTimeout(b,500));Promise.all([l({directory:i}),w]).finally(()=>{h(!1)})},[u,l,i]);return s.jsxs("div",{className:ce("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),i&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:i.split("/").pop()||i})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:u,onClick:y,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(P,{name:"refresh",className:ce("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[v.map(g=>{const w=a[g],b=tw(w),k=w?.status==="connected",I=x===g,j=ew(w,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:ce("h-2 w-2 rounded-full flex-shrink-0",b==="success"&&"bg-status-success",b==="error"&&"bg-status-error",b==="warning"&&"bg-status-warning",b==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(Dt,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(xl,{checked:k,disabled:I,className:"data-[checked]:bg-status-info",onCheckedChange:async N=>{f(g);try{N?await c(g,i):await d(g,i)}finally{f(null)}}})]},g)}),v.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},co=t=>{const e=at.c(20),{percent:n,tonePercent:r,className:i,expectedMarkerPercent:a}=t;let l;e[0]!==n?(l=Ov(n)??0,e[0]=n,e[1]=l):l=e[1];const c=l,d=r??n;let p;e[2]!==d?(p=bh(d),e[2]=d,e[3]=p):p=e[3];const m=p,u=a!=null?Math.max(0,Math.min(100,a)):null;let h;e[4]!==m?(h=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=h):h=e[5];const x=h;let f;e[6]!==i?(f=ce("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=f):f=e[7];const v=`${c}%`;let y;e[8]!==x||e[9]!==v?(y={...x,width:v},e[8]=x,e[9]=v,e[10]=y):y=e[10];let g;e[11]!==c||e[12]!==y?(g=s.jsx("div",{className:"h-full transition-all duration-300",style:y,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=y,e[13]=g):g=e[13];let w;e[14]!==u?(w=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=w):w=e[15];let b;return e[16]!==f||e[17]!==g||e[18]!==w?(b=s.jsxs("div",{className:f,children:[g,w]}),e[16]=f,e[17]=g,e[18]=w,e[19]=b):b=e[19],b},uo=t=>{const e=at.c(67),{paceInfo:n,className:r,compact:i}=t,a=i===void 0?!1:i,{t:l}=ut();let c;e[0]!==n.status?(c=zv(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let p;e:{switch(n.status){case"on-track":{let N;e[2]!==l?(N=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=N):N=e[3],p=N;break e}case"slightly-fast":{let N;e[4]!==l?(N=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=N):N=e[5],p=N;break e}case"too-fast":{let N;e[6]!==l?(N=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=N):N=e[7],p=N;break e}case"exhausted":{let N;e[8]!==l?(N=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=N):N=e[9],p=N;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==l?(u=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=u):u=e[12];const h=u;if(a){let N;e[13]!==r?(N=ce("flex items-center gap-1.5",r),e[13]=r,e[14]=N):N=e[14];let D;e[15]!==d?(D={backgroundColor:d},e[15]=d,e[16]=D):D=e[16];let E;e[17]!==m||e[18]!==D?(E=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:D,title:m}),e[17]=m,e[18]=D,e[19]=E):E=e[19];let T;e[20]!==d?(T={color:d},e[20]=d,e[21]=T):T=e[21];const C=n.isExhausted?void 0:h;let S;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(S=n.isExhausted?s.jsx(s.Fragment,{children:l("settings.usage.pace.wait",{duration:Qu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:l("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=l,e[26]=S):S=e[26];let M;e[27]!==S||e[28]!==T||e[29]!==C?(M=s.jsx("span",{className:"typography-micro tabular-nums",style:T,title:C,children:S}),e[27]=S,e[28]=T,e[29]=C,e[30]=M):M=e[30];let A;return e[31]!==M||e[32]!==N||e[33]!==E?(A=s.jsxs("div",{className:N,children:[E,M]}),e[31]=M,e[32]=N,e[33]=E,e[34]=A):A=e[34],A}let x;e[35]!==r?(x=ce("flex items-center justify-between gap-2",r),e[35]=r,e[36]=x):x=e[36];let f;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(f=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=l,e[40]=f):f=e[40];let v;e[41]!==f?(v=s.jsx("div",{className:"flex items-center gap-1.5",children:f}),e[41]=f,e[42]=v):v=e[42];let y;e[43]!==d?(y={color:d},e[43]=d,e[44]=y):y=e[44];let g;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==h||e[49]!==m||e[50]!==l?(g=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:Qu(n.remainingSeconds)})]}):s.jsxs("span",{title:h,children:[s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=h,e[49]=m,e[50]=l,e[51]=g):g=e[51];let w;e[52]!==y||e[53]!==g?(w=s.jsx("span",{className:"typography-micro tabular-nums",style:y,children:g}),e[52]=y,e[53]=g,e[54]=w):w=e[54];let b;e[55]!==d?(b={backgroundColor:d},e[55]=d,e[56]=b):b=e[56];let k;e[57]!==m||e[58]!==b?(k=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:b,title:m}),e[57]=m,e[58]=b,e[59]=k):k=e[59];let I;e[60]!==w||e[61]!==k?(I=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,k]}),e[60]=w,e[61]=k,e[62]=I):I=e[62];let j;return e[63]!==I||e[64]!==x||e[65]!==v?(j=s.jsxs("div",{className:x,children:[v,I]}),e[63]=I,e[64]=x,e[65]=v,e[66]=j):j=e[66],j},fr=ex,Pr=t=>{const e=at.c(14);let n,r,i,a;e[0]!==t?({className:i,asChild:n,children:r,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(n=e[1],r=e[2],i=e[3],a=e[4]);let l;e[5]!==n||e[6]!==r?(l=n&&Be.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=l):l=e[7];const c=l;let d;e[8]!==i?(d=ce("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",i),e[8]=i,e[9]=d):d=e[9];let p;return e[10]!==a||e[11]!==c||e[12]!==d?(p=s.jsx(tx,{className:d,...a,...c}),e[10]=a,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},hr=t=>{const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=ce("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(sx,{className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a},hi=[{id:"finder",label:"Finder",appName:"Finder"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm"},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"xcode",label:"Xcode",appName:"Xcode"},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"zed",label:"Zed",appName:"Zed"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"kiro",label:"Kiro",appName:"Kiro"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],ed="finder",td=new Set(["finder","terminal"]),sd=t=>t?hi.find(e=>e.id===t)??null:null,uc=()=>hi.filter(t=>td.has(t.id)).map(t=>({...t})),sw=()=>{if(typeof window>"u")return ed;const t=window.localStorage.getItem("openInAppId");return t&&sd(t)?t:ed};let mc=!1,Xi=!1,ci=!1,di=0,qa=null;const tm=()=>{qa&&(clearTimeout(qa),qa=null)},Lr=gr()((t,e)=>({selectedAppId:sw(),availableApps:uc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(mc||typeof window>"u")return;mc=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:uc(),hasLoadedApps:p});return}const m=new Set(d.map(f=>f.name)),u=new Map(d.map(f=>[f.name,f.iconDataUrl??void 0])),x=hi.filter(f=>m.has(f.appName)||td.has(f.id)).map(f=>({...f,iconDataUrl:u.get(f.appName)}));t({availableApps:x,hasLoadedApps:!0})},r=async d=>{if(!pa()||!Bi()||Xi||e().hasLoadedApps&&!d)return;const m=hi.map(u=>u.appName);tm(),Xi=!0,ci=!1,t({isScanning:!0});try{const{apps:u,success:h,hasCache:x,isCacheStale:f}=await bu(m,d),v=h&&!x&&u.length===0&&di<3;if(t({isCacheStale:x?f:!1}),n(u,h?!v:!1),h){if(v){const g=[800,1600,3200][di]??3200;di+=1,ci=!0,qa=setTimeout(()=>{r()},g);return}di=0,ci=!1;return}if(di<3){const g=[1e3,3e3,7e3][di]??7e3;di+=1,ci=!0,qa=setTimeout(()=>{r()},g)}}finally{Xi=!1,ci||t({isScanning:!1})}};r();const i=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&sd(p.openInAppId)?p.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},a=()=>{r()},l=d=>{const p=d.detail;Array.isArray(p)&&(di=3,ci=!1,t({isScanning:!1,isCacheStale:!1}),n(p))};window.addEventListener("vinci:settings-synced",i),window.addEventListener("vinci:app-ready",a),window.addEventListener("vinci:installed-apps-updated",l),window.__vinciAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(mc||e().initialize(),!pa()||!Bi()||Xi||e().hasLoadedApps&&!n)return;const i=hi.map(a=>a.appName);tm(),n&&t({hasLoadedApps:!1}),Xi=!0,ci=!1,t({isScanning:!0});try{const{apps:a,hasCache:l,isCacheStale:c}=await bu(i,n),d=new Set(a.map(h=>h.name)),p=new Map(a.map(h=>[h.name,h.iconDataUrl??void 0])),u=hi.filter(h=>d.has(h.appName)||td.has(h.id)).map(h=>({...h,iconDataUrl:p.get(h.appName)}));t({availableApps:u.length>0?u:uc(),hasLoadedApps:u.length>0,isCacheStale:l?c:!1})}finally{Xi=!1,ci||t({isScanning:!1})}},selectApp:async n=>{sd(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ks({openInAppId:n}))}})),nw="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",rw="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",pc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?nw:t.id==="terminal"?rw:void 0}),sm=t=>{const e=at.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:i}=t,[a,l]=o.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||i;if(p&&!a){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>l(!0),e[2]=h):h=e[2];let x;return e[3]!==p?(x=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:h}),e[3]=p,e[4]=x):x=e[4],x}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=ce("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let u;return e[6]!==d?(u=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=u):u=e[7],u},iw=t=>{const e=at.c(82),{directory:n,className:r}=t,{t:i}=ut(),a=Lr(aw),l=Lr(ow),c=Lr(lw),d=Lr(cw),p=Lr(dw),m=Lr(uw),u=Lr(mw);let h,x;e[0]!==p?(h=()=>{p()},x=[p],e[0]=p,e[1]=h,e[2]=x):(h=e[1],x=e[2]),o.useEffect(h,x);const f=pa()&&Bi();let v;e:{let K;e[3]!==l||e[4]!==a?(K=l.find(re=>re.id===a)??l.find(pw)??l[0]??hi[0],e[3]=l,e[4]=a,e[5]=K):K=e[5];const ae=K;if(ae){let re;e[6]!==ae?(re=pc(ae),e[6]=ae,e[7]=re):re=e[7],v=re;break e}let ve;e[8]===Symbol.for("react.memo_cache_sentinel")?(ve=pc(hi[0]),e[8]=ve):ve=e[8],v=ve}const y=v;if(!f||!n||l.length===0)return null;let g;e[9]!==n?(g=async K=>{await Bx(n,K.id,K.appName)||await ul(n,K.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let b;e[11]!==w||e[12]!==u?(b=async K=>{await u(K.id),await w(K)},e[11]=w,e[12]=u,e[13]=b):b=e[13];const k=b;let I;e[14]!==n||e[15]!==i?(I=async()=>{(await _n(n)).ok&&H.success(i("openInApp.toast.pathCopied"))},e[14]=n,e[15]=i,e[16]=I):I=e[16];const j=I;let N;e[17]!==r?(N=ce("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=N):N=e[18];let D;e[19]!==w||e[20]!==y?(D=()=>{w(y)},e[19]=w,e[20]=y,e[21]=D):D=e[21];let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=ce("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=E):E=e[22];let T;e[23]!==y.label||e[24]!==i?(T=i("openInApp.actions.openInAria",{app:y.label}),e[23]=y.label,e[24]=i,e[25]=T):T=e[25];let C;e[26]!==y.fallbackIconDataUrl||e[27]!==y.iconDataUrl||e[28]!==y.label?(C=s.jsx(sm,{label:y.label,iconDataUrl:y.iconDataUrl,fallbackIconDataUrl:y.fallbackIconDataUrl}),e[26]=y.fallbackIconDataUrl,e[27]=y.iconDataUrl,e[28]=y.label,e[29]=C):C=e[29];const S=d?"animate-pulse text-muted-foreground":void 0;let M;e[30]!==S?(M=ce("header-open-label",S),e[30]=S,e[31]=M):M=e[31];let A;e[32]!==i?(A=i("openInApp.actions.open"),e[32]=i,e[33]=A):A=e[33];let R;e[34]!==M||e[35]!==A?(R=s.jsx("span",{className:M,children:A}),e[34]=M,e[35]=A,e[36]=R):R=e[36];let z;e[37]!==T||e[38]!==C||e[39]!==R||e[40]!==D?(z=s.jsxs("button",{type:"button",onClick:D,className:E,"aria-label":T,children:[C,R]}),e[37]=T,e[38]=C,e[39]=R,e[40]=D,e[41]=z):z=e[41];let B;e[42]===Symbol.for("react.memo_cache_sentinel")?(B=ce("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[42]=B):B=e[42];let V;e[43]!==i?(V=i("openInApp.actions.chooseAppAria"),e[43]=i,e[44]=V):V=e[44];let $;e[45]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4"}),e[45]=$):$=e[45];let _;e[46]!==V?(_=s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:B,"aria-label":V,children:$})}),e[46]=V,e[47]=_):_=e[47];let X;e[48]===Symbol.for("react.memo_cache_sentinel")?(X={translate:"-30px 0"},e[48]=X):X=e[48];let O;e[49]!==j?(O=()=>{j()},e[49]=j,e[50]=O):O=e[50];let J;e[51]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(P,{name:"file-copy",className:"h-4 w-4"}),e[51]=J):J=e[51];let Q;e[52]!==i?(Q=i("openInApp.actions.copyPath"),e[52]=i,e[53]=Q):Q=e[53];let ne;e[54]!==Q?(ne=s.jsx("span",{className:"typography-ui-label text-foreground",children:Q}),e[54]=Q,e[55]=ne):ne=e[55];let G;e[56]!==O||e[57]!==ne?(G=s.jsxs($t,{className:"flex items-center gap-2",onClick:O,children:[J,ne]}),e[56]=O,e[57]=ne,e[58]=G):G=e[58];let le;e[59]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(Cn,{}),e[59]=le):le=e[59];let oe;if(e[60]!==l||e[61]!==k||e[62]!==y.id){let K;e[64]!==k||e[65]!==y.id?(K=ae=>{const ve=pc(ae);return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{k(ae)},children:[s.jsx(sm,{label:ae.label,iconDataUrl:ae.iconDataUrl,fallbackIconDataUrl:ve.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ae.label}),y.id===ae.id?s.jsx(P,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},ae.id)},e[64]=k,e[65]=y.id,e[66]=K):K=e[66],oe=l.map(K),e[60]=l,e[61]=k,e[62]=y.id,e[63]=oe}else oe=e[63];let F;e[67]!==c||e[68]!==m||e[69]!==i?(F=c?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(P,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("openInApp.actions.refreshApps")})]}):null,e[67]=c,e[68]=m,e[69]=i,e[70]=F):F=e[70];let U;e[71]!==G||e[72]!==oe||e[73]!==F?(U=s.jsxs(Rs,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:X,children:[G,le,oe,F]}),e[71]=G,e[72]=oe,e[73]=F,e[74]=U):U=e[74];let W;e[75]!==_||e[76]!==U?(W=s.jsxs(Fs,{children:[_,U]}),e[75]=_,e[76]=U,e[77]=W):W=e[77];let te;return e[78]!==z||e[79]!==W||e[80]!==N?(te=s.jsxs("div",{className:N,children:[z,W]}),e[78]=z,e[79]=W,e[80]=N,e[81]=te):te=e[81],te};function aw(t){return t.selectedAppId}function ow(t){return t.availableApps}function lw(t){return t.isCacheStale}function cw(t){return t.isScanning}function dw(t){return t.initialize}function uw(t){return t.loadInstalledApps}function mw(t){return t.selectApp}function pw(t){return t.id===ed}const fw=1e6,hw="terminal-store";let nm=!1;const fc=t=>typeof t=="object"&&t!==null,gw=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function Wn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const hc=(t,e)=>({id:t,terminalSessionId:null,lifecycle:"idle",label:e,iconKey:null,bufferChunks:[],bufferLength:0,isConnecting:!1,createdAt:Date.now(),previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1}),Ch=/\x1b\[[0-9;]*m/g,xw=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,bw=new Set([".",",",";",":","!","?"]),yw=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",i=e.slice(0,-1),a=(i.match(new RegExp(`\\${r}`,"g"))||[]).length,l=(i.match(new RegExp(`\\${n}`,"g"))||[]).length;if(a>l)break;e=i;continue}if(bw.has(n)){e=e.slice(0,-1);continue}break}return e},vw=t=>{if(!t)return null;const n=t.replace(Ch,"").match(xw);if(!n?.[1])return null;let r=yw(n[1]);return r=r.replace("0.0.0.0","127.0.0.1"),r=r.replace("[::1]","127.0.0.1"),r=r.replace("[::]","127.0.0.1"),r},ww=t=>{if(!t)return null;const n=t.replace(Ch,"").match(/Serving HTTP on .*? port (\d{2,5})/i);if(!n?.[1])return null;const r=Number.parseInt(n[1],10);return!Number.isFinite(r)||r<=0||r>65535?null:`http://127.0.0.1:${r}/`},gc=t=>({tabs:[t],activeTabId:t.id}),Rr=(t,e)=>t.tabs.findIndex(n=>n.id===e),on=gr()(Na(mo((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=Wn(n);r&&t(i=>{if(i.sessions.has(r))return i;const a=new Map(i.sessions),l=`tab-${i.nextTabId}`,c=hc(l,"Terminal");return a.set(r,gc(c)),{sessions:a,nextTabId:i.nextTabId+1}})},getDirectoryState:n=>{const r=Wn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=Wn(n),i=e().sessions.get(r);if(!i)return;const a=i.activeTabId;return a?i.tabs.find(l=>l.id===a)??i.tabs[0]:i.tabs[0]},createTab:n=>{const r=Wn(n);if(!r)return"tab-invalid";const i=`tab-${e().nextTabId}`;return t(a=>{const l=new Map(a.sessions),c=l.get(r),d=a.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=hc(i,m);return c?l.set(r,{...c,tabs:[...c.tabs,u]}):l.set(r,gc(u)),{sessions:l,nextTabId:d}}),i},setActiveTab:(n,r)=>{const i=Wn(n);t(a=>{const l=new Map(a.sessions),c=l.get(i);return!c||c.activeTabId===r||Rr(c,r)<0?a:(l.set(i,{...c,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,i)=>{const a=Wn(n),l=i.trim();l&&t(c=>{const d=new Map(c.sessions),p=d.get(a);if(!p)return c;const m=Rr(p,r);if(m<0||p.tabs[m]?.label===l)return c;const u=[...p.tabs];return u[m]={...u[m],label:l},d.set(a,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=i?.trim()||null;if(d.tabs[p]?.iconKey===m)return l;const u=[...d.tabs];return u[p]={...u[p],iconKey:m},c.set(a,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const i=Wn(n),c=e().sessions.get(i)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await Lx(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(i);if(!m)return d;const u=Rr(m,r);if(u<0)return d;const h=m.tabs.filter(y=>y.id!==r),x=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,y])=>!(y.directory===i&&y.tabId===r))),f=Object.keys(x).length!==Object.keys(d.projectActionRuns).length;if(h.length===0){const y=`tab-${d.nextTabId}`,g=hc(y,"Terminal");return p.set(i,gc(g)),{sessions:p,nextTabId:d.nextTabId+1,...f?{projectActionRuns:x}:{}}}let v=m.activeTabId;return m.activeTabId===r&&(v=h[Math.min(u,h.length-1)]?.id??h[0]?.id??null),p.set(i,{...m,tabs:h,activeTabId:v}),{sessions:p,...f?{projectActionRuns:x}:{}}})},setTabSessionId:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=d.tabs[p],u=i!==null&&m.terminalSessionId!==i,h=i?"running":m.terminalSessionId?"exited":m.lifecycle,x={...m,terminalSessionId:i,lifecycle:h,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},f=[...d.tabs];return f[p]=x,c.set(a,{...d,tabs:f}),{sessions:c}})},setTabLifecycle:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=[...d.tabs];return m[p]={...m[p],lifecycle:i,isConnecting:!1},c.set(a,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=[...d.tabs];return m[p]={...m[p],isConnecting:i},c.set(a,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,i)=>{if(!i)return;const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=d.tabs[p],u=l.nextChunkId,h={id:u,data:i},x=[...m.bufferChunks,h];let f=m.bufferLength+i.length;for(;f>fw&&x.length>1;){const w=x.shift();if(!w)break;f-=w.data.length}const v=m.previewUrlLocked?null:vw(i)??ww(i),y=!!(v&&v!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:x,bufferLength:f,...y?{previewUrl:v,previewAutoOpened:!1}:null},c.set(a,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,i,a={})=>{const l=Wn(n);t(c=>{const d=new Map(c.sessions),p=d.get(l);if(!p)return c;const m=Rr(p,r);if(m<0)return c;const u=p.tabs[m],h=a.autoOpened??u.previewAutoOpened,x=a.locked??u.previewUrlLocked;if(u.previewUrl===i&&u.previewAutoOpened===h&&u.previewUrlLocked===x)return c;const f=[...p.tabs];return f[m]={...u,previewUrl:i,previewAutoOpened:h,previewUrlLocked:x},d.set(l,{...p,tabs:f}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const i=Wn(n);t(a=>{const l=new Map(a.sessions),c=l.get(i);if(!c)return a;const d=Rr(c,r);if(d<0)return a;const p=c.tabs[d];if(!p.previewUrl||p.previewAutoOpened)return a;const m=[...c.tabs];return m[d]={...p,previewAutoOpened:!0},l.set(i,{...c,tabs:m}),{sessions:l}})},setProjectActionRun:n=>{t(r=>{const i=r.projectActionRuns[n.key];return i&&i.directory===n.directory&&i.actionId===n.actionId&&i.tabId===n.tabId&&i.sessionId===n.sessionId&&i.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(i=>{const a=i.projectActionRuns[n];return!a||a.status===r?i:{projectActionRuns:{...i.projectActionRuns,[n]:{...a,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const i={...r.projectActionRuns};return delete i[n],{projectActionRuns:i}})},clearBuffer:(n,r)=>{const i=Wn(n);t(a=>{const l=new Map(a.sessions),c=l.get(i);if(!c)return a;const d=Rr(c,r);if(d<0)return a;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},l.set(i,{...c,tabs:p}),{sessions:l}})},removeDirectory:n=>{const r=Wn(n);t(i=>{const a=new Map(i.sessions);a.delete(r);const l=Object.fromEntries(Object.entries(i.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:a,projectActionRuns:l}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:hw,storage:Ml(()=>_f()),partialize:t=>({sessions:Array.from(t.sessions.entries()).map(([e,n])=>[e,{activeTabId:n.activeTabId,tabs:n.tabs.map(r=>({id:r.id,label:r.label,iconKey:r.iconKey,terminalSessionId:r.terminalSessionId,lifecycle:r.lifecycle,createdAt:r.createdAt}))}]),nextTabId:t.nextTabId}),merge:(t,e)=>{if(!fc(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let i=0;for(const c of n){if(!Array.isArray(c)||c.length!==2)continue;const[d,p]=c;if(typeof d!="string"||!fc(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const f of m){if(!fc(f))continue;const v=typeof f.id=="string"?f.id:null;if(!v)continue;const y=gw(v);y!==null&&(i=Math.max(i,y));const g=typeof f.terminalSessionId=="string"||f.terminalSessionId===null?f.terminalSessionId:null,w=f.lifecycle,b=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:v,label:typeof f.label=="string"?f.label:"Terminal",iconKey:typeof f.iconKey=="string"?f.iconKey:null,terminalSessionId:g,lifecycle:b,createdAt:typeof f.createdAt=="number"?f.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const h=typeof p.activeTabId=="string"?p.activeTabId:null,x=h?u.some(f=>f.id===h):!1;r.set(d,{tabs:u,activeTabId:x?h:u[0].id})}const a=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,l=Math.max(e.nextTabId,a,i+1);return{...e,sessions:r,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!nm){nm=!0;const t=on.persist,e=()=>{on.getState().hasHydrated||on.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const rm=(t,e)=>e.updatedAtMs-t.updatedAtMs,Ys=gr((t,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){t({isLoading:!0,error:null});try{const[n,r]=await Promise.all([Ux(),vu()]),i={};for(const a of r.sort(rm))i[a.id]=a;e().listenerReady||await Wx(a=>{t(l=>({statusesById:{...l.statusesById,[a.id]:a}}))}),t({instances:n.instances,statusesById:i,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await _x();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await vu(),r={};for(const i of n.sort(rm))r[i.id]=i;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await Vx({instances:n}),t({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw t({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,i=r.some(a=>a.id===n.id)?r.map(a=>a.id===n.id?n:a):[n,...r];await e().setInstances(i)},createFromCommand:async(n,r,i)=>{const a=Kx(n,r);i&&i.trim()&&(a.nickname=i.trim()),await e().upsertInstance(a)},removeInstance:async n=>{await yu(n).catch(()=>{});const r=e().instances.filter(i=>i.id!==n);await e().setInstances(r),t(i=>{const a={...i.statusesById};return delete a[n],{statusesById:a}})},connect:async n=>{t({error:null});try{await zx(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},disconnect:async n=>{t({error:null});try{await yu(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>t({error:null})})),Ph=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],Zo=Object.fromEntries(Ph.map(t=>[t.key,t.Icon])),nd="vinci:project-actions-updated",Ih=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},ui=(t,e)=>`${Ih(t)}::${e}`,jw=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},im=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},Nw=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=im(e.localPort),r=im(e.remotePort);if(!n||!r)return null;const i=jw(e.localHost||t.localForward.bindHost||"127.0.0.1"),a=(e.remoteHost||"127.0.0.1").trim(),l=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${l} - ${i}:${n} -> ${a}:${r}`,url:`http://${i}:${n}`}},Ah=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const i=Nw(n,r);i&&e.push(i)}return e},Sw=(t,e)=>{const n=(t||"").trim();return n&&Ah(e).find(a=>a.id===n)?.url||null},kw=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Cw=["dev","start","preview","serve"];async function Pw(t,e,n){if(!t)return null;const r=Dw(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const i=Tw(n);if(i){const a=await Mw(t);return{command:`${a==="npm"?"npm run":a==="yarn"?"yarn":a==="pnpm"?"pnpm":a==="bun"?"bun run --shell=bun":"npm run"} ${i}`,label:`Start (${i})`}}}if(await Iw(t)){const i=await Aw(),a=typeof i=="number"&&Number.isFinite(i)&&i>0?i:8e3;return{command:`python3 -m http.server ${a}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${a}/`}}return null}async function Iw(t){const e=`${t}/index.html`,n=await bl(e);return typeof n=="string"&&n.trim().length>0}async function Aw(){try{const t=await fetch("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Dw(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Cw.some(i=>n.includes(i)))return e}return null}function Tw(t){for(const{pattern:e}of kw)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Mw(t){const e=await bl(`${t}/package.json`);if(e)try{const r=JSON.parse(e),i=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(i.startsWith("bun@"))return"bun";if(i.startsWith("pnpm@"))return"pnpm";if(i.startsWith("yarn@"))return"yarn";if(i.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,i]of n){const a=await bl(`${t}/${r}`);if(typeof a=="string"&&a.trim().length>0)return i}return"npm"}async function bl(t){const e=pr()?.files;if(e?.readFile)try{const n=await e.readFile(t,{optional:!0});return typeof n?.content=="string"?n.content:null}catch{return null}try{const n=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return n.ok?n.text():null}catch{return null}}async function Ew(t){try{const e=await bl(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const Rw=t=>new Promise(e=>{window.setTimeout(e,t)}),Fw="\x1B",Lw=new RegExp(`${Fw}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Ow=/https?:\/\/[^\s<>'"`]+/gi,or="__vinci_auto_discover_preview__",$w=15e3,Bw=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},zw=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},Vw=t=>{const n=t.replace(Lw,"").match(Ow);if(!n||n.length===0)return null;const r=n.map(a=>a.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const i=[];for(const a of r)try{const l=new URL(a);l.port&&l.port.length>0&&i.push({raw:a,parsed:l})}catch{}if(i.length>0){const a=l=>{const{parsed:c}=l,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,h=m==="/"||m==="",x=!!(c.search||c.hash);let f=0;return p&&(f+=50),h&&(f+=30),f-=Math.min(u*5,20),x&&(f-=10),f};return i.sort((l,c)=>a(c)-a(l)),i[0]?.parsed.origin??i[0]?.raw??null}return r[0]??null},_w=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const i=r[0],a=r[1].slice(0,3),l=`${i} ${a}`.trim();return r.length>2||l.length<n.length?`${l}...`:l}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},am=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:i=!1})=>{const{t:a}=ut(),{terminal:l,runtime:c}=Pn(),{isMobile:d}=rn(),p=o.useMemo(()=>gn(),[]),m=Ys(q=>q.instances),u=Ys(q=>q.load),h=Ie(q=>q.setBottomTerminalOpen),x=Ie(q=>q.setActiveMainTab),f=Ie(q=>q.setSettingsPage),v=Ie(q=>q.setSettingsDialogOpen),y=Ie(q=>q.setSettingsProjectsSelectedId),g=Ie(q=>q.openContextPreview),w=on(q=>q.sessions),b=on(q=>q.ensureDirectory),k=on(q=>q.setTabLabel),I=on(q=>q.setTabIconKey),j=on(q=>q.setActiveTab),N=on(q=>q.setConnecting),D=on(q=>q.setTabSessionId),E=on(q=>q.setTabPreviewUrl),T=on(q=>q.projectActionRuns),C=on(q=>q.setProjectActionRun),S=on(q=>q.updateProjectActionRunStatus),M=on(q=>q.removeProjectActionRun),[A,R]=o.useState([]),[z,B]=o.useState(null),[V,$]=o.useState(!1),_=o.useRef({}),X=o.useRef({}),O=o.useRef({}),J=o.useRef({}),Q=o.useRef(0),ne=t?.id??null,G=t?.path??"",le=o.useMemo(()=>ne?{id:ne,path:G}:null,[ne,G]);o.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const oe=o.useCallback(async q=>{await rr(q)},[]),F=o.useCallback(async()=>{if(!le)return;const q=Q.current+1;Q.current=q,$(!0);try{const Se=await Yc(le);if(Q.current!==q)return;const $e=Se.actions;R($e),B(Pe=>Pe===or||Pe&&$e.some(fe=>fe.id===Pe)?Pe:null)}catch{if(Q.current!==q)return}finally{Q.current===q&&$(!1)}},[le]),U=o.useMemo(()=>Ih(e||le?.path||""),[e,le?.path]),W=o.useMemo(()=>z?A.find(q=>q.id===z)??null:null,[A,z]),te=o.useMemo(()=>({id:or,name:a("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[a]),K=!d,ae=o.useMemo(()=>K?[te,...A]:A,[A,te,K]);o.useEffect(()=>{F()},[F]),o.useEffect(()=>{if(typeof window>"u")return;const q=Se=>{const $e=Se.detail;ne&&($e?.projectId&&$e.projectId!==ne||F())};return window.addEventListener(nd,q),()=>{window.removeEventListener(nd,q)}},[F,ne]),o.useEffect(()=>{z&&(z===or&&K||A.some(q=>q.id===z)||B(null))},[A,K,z]),o.useEffect(()=>{for(const[q,Se]of Object.entries(T)){const Pe=w.get(Se.directory)?.tabs.find(fe=>fe.id===Se.tabId);(!Pe||Pe.terminalSessionId!==Se.sessionId)&&M(q)}},[T,M,w]),o.useEffect(()=>{for(const[q,Se]of Object.entries(T)){const $e=X.current[q]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};X.current[q]=$e;const Pe=ae.find(de=>de.id===Se.actionId);if(!Pe)continue;const L=w.get(Se.directory)?.tabs.find(de=>de.id===Se.tabId);if(!L||!Array.isArray(L.bufferChunks)||L.bufferChunks.length===0)continue;const Z=L.bufferChunks.filter(de=>$e.lastSeenChunkId===null?!0:de.id>$e.lastSeenChunkId);if(Z.length===0)continue;const Y=Z.map(de=>de.data).join(""),Ee=`${$e.tail}${Y}`,Ae=!$e.openedUrl&&Pe.autoOpenUrl===!0?Vw(Ee):null,Je=Z[Z.length-1]?.id??$e.lastSeenChunkId;if($e.lastSeenChunkId=Je,$e.tail=Ee.slice(-512),Ae)if($e.openedUrl=!0,$e.openInPreview){const de=T[q];de&&(E(de.directory,de.tabId,Ae,{locked:!1,autoOpened:!1}),de.status==="waiting-for-preview"&&S(q,"running"),window.clearTimeout(J.current[q]),delete J.current[q],g(de.directory,Ae))}else oe(Ae),H.success(a("projectActions.toast.openedUrlFromOutput"));X.current[q]=$e}for(const q of Object.keys(X.current))T[q]||(delete X.current[q],window.clearTimeout(J.current[q]),delete J.current[q])},[ae,g,oe,T,E,a,w,S]);const ve=o.useCallback(async(q,Se={})=>{if(!U)throw new Error(a("projectActions.error.noActiveDirectory"));const $e=ui(U,q.id);b(U);const Pe=on.getState(),fe=Pe.getDirectoryState(U);let L=_.current[$e]||null;const Z=L?!!fe?.tabs.some(Ae=>Ae.id===L):!1;(!L||!Z)&&(L=Pe.createTab(U),_.current[$e]=L),k(U,L,`Action: ${q.name}`),I(U,L,q.icon||"play"),Se.revealTerminal!==!1&&(j(U,L),h(!0),x("terminal"));const Ee=on.getState().getDirectoryState(U)?.tabs.find(Ae=>Ae.id===L);return{key:$e,tabId:L,sessionId:Ee?.terminalSessionId??null}},[b,U,x,j,h,I,k,a]),re=o.useCallback(async q=>{if(c.isVSCode||!i&&d)return;if(!U){H.error(a("projectActions.error.noActiveDirectoryForAction"));return}const Se=ui(U,q.id),$e=T[Se];if(!($e&&$e.status==="running"))try{const Pe=q.id===or?await(async()=>{const[Re,Xe]=await Promise.all([Yc({id:le?.id??"",path:U}),Ew(U)]),qe=await Pw(U,Re.actions,Xe);if(!qe)throw new Error(a("contextPanel.preview.noDevServer"));return{id:or,name:a("projectActions.actions.autoDiscover"),command:qe.command,icon:"search",autoOpenUrl:!0,openUrl:qe.previewUrlHint||""}})():q,fe=Pe.autoOpenUrl===!0&&(Pe.openUrl||"").trim().length>0,{key:L,tabId:Z,sessionId:Y}=await ve(Pe,{revealTerminal:!fe&&q.id!==or});let Ee=Y,Ae=!1;if(!Ee){N(U,Z,!0);try{Ee=(await l.createSession({cwd:U})).sessionId,Ae=!0,D(U,Z,Ee)}finally{N(U,Z,!1)}}if(!Ee)throw new Error(a("projectActions.error.failedToCreateTerminalSession"));Ae&&await Rw(350),Pe.id===or&&(O.current[L]?.(),N(U,Z,!0),O.current[L]=Ox(Ee,Re=>{Re.type==="data"&&typeof Re.data=="string"&&Re.data.length>0&&on.getState().appendToBuffer(U,Z,Re.data),Re.type==="exit"&&(on.getState().setTabLifecycle(U,Z,"exited"),on.getState().setConnecting(U,Z,!1),on.getState().removeProjectActionRun(L),delete X.current[L],O.current[L]?.(),delete O.current[L],window.clearTimeout(J.current[L]),delete J.current[L])},()=>{on.getState().setConnecting(U,Z,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Je=Pe.autoOpenUrl===!0&&p&&(Pe.desktopOpenSshForward||"").trim().length>0,de=Pe.autoOpenUrl?zw(Pe.openUrl):null,ze=Pe.autoOpenUrl&&p?Sw(Pe.desktopOpenSshForward,m):null;C({key:L,directory:U,actionId:Pe.id,tabId:Z,sessionId:Ee,status:Pe.id===or&&!de?"waiting-for-preview":"running"}),window.clearTimeout(J.current[L]),delete J.current[L],Pe.id===or&&!de&&(J.current[L]=window.setTimeout(()=>{on.getState().updateProjectActionRunStatus(L,"running"),delete J.current[L]},$w)),ze?(E(U,Z,null,{locked:!0}),oe(ze),H.success(a("projectActions.toast.openedForwardedUrl"))):de?(E(U,Z,de,{locked:!0,autoOpened:!0}),g(U,de),H.success(a("projectActions.toast.openedActionUrl"))):fe?(E(U,Z,null,{locked:!0}),H.error(a("projectActions.error.invalidCustomUrlFormat"))):Je?(E(U,Z,null,{locked:!0}),H.error(a("projectActions.error.selectedDesktopSshForwardUnavailable"))):E(U,Z,null,{locked:!1,autoOpened:!1}),X.current[L]={lastSeenChunkId:null,openedUrl:!!ze||!!de||fe,tail:"",openInPreview:Pe.id===or};const rt=Bw(Pe.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
+
`));await l.sendInput(Ee,`${rt}\r`)}catch(Pe){M(Se),delete X.current[Se],O.current[Se]?.(),delete O.current[Se],window.clearTimeout(J.current[Se]),delete J.current[Se],H.error(Pe instanceof Error?Pe.message:a("projectActions.error.failedToRunAction"))}},[m,ve,i,d,p,U,oe,g,T,c.isVSCode,M,N,C,E,D,le?.id,a,l]),be=o.useCallback(async q=>{const Se=ui(U,q.id),$e=T[Se];if(!$e)return;S(Se,"stopping");try{await l.sendInput($e.sessionId,"")}catch{}if(await new Promise(L=>{window.setTimeout(L,1e3)}),on.getState().getDirectoryState($e.directory)?.tabs.find(L=>L.id===$e.tabId)?.terminalSessionId===$e.sessionId){if(typeof l.forceKill=="function")try{await l.forceKill({sessionId:$e.sessionId})}catch{}else try{await l.close($e.sessionId)}catch{}D($e.directory,$e.tabId,null)}M(Se),delete X.current[Se],O.current[Se]?.(),delete O.current[Se],window.clearTimeout(J.current[Se]),delete J.current[Se]},[U,T,M,D,l,S]),pe=o.useCallback(()=>{const q=W??ae[0];if(!q)return;const Se=ui(U,q.id),$e=T[Se];if($e?.status!=="stopping"){if($e){be(q);return}re(q)}},[ae,U,re,T,W,be]),ye=o.useCallback((q,Se=!1)=>{if(B(q.id),!Se){re(q);return}const $e=ui(U,q.id),Pe=T[$e];if(Pe?.status!=="stopping"){if(Pe){be(q);return}re(q)}},[U,re,T,be]),ie=o.useCallback(()=>{le?.id&&(y(le.id),f("projects"),v(!0))},[v,f,y,le?.id]);if(c.isVSCode||!i&&d||!le||!U)return null;const ue=W??ae[0]??null;if(!ue)return null;const se=ue.icon||"play",Ne=ue.id===or?"search":Zo[se]||"play",Ce=_w(ue.name,a("projectActions.label.fallbackAction")),je=ui(U,ue.id),we=T[je],ke=we?.status==="stopping",xe=we?.status==="waiting-for-preview",me=we?w.get(we.directory)?.tabs.find(q=>q.id===we.tabId)?.previewUrl??null:null,Me=!!(we&&me),Ue=()=>{!we||!me||g(we.directory,me)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:V||ke,className:ce("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:pe,"aria-label":we?a("projectActions.actions.stopNamedAria",{name:ue.name}):a("projectActions.actions.runNamedAria",{name:ue.name}),children:ke||xe?s.jsx(P,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):we?s.jsx(P,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(P,{name:Ne,className:"h-5 w-5"})}),Me?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":a("projectActions.actions.openPreview"),onClick:Ue,children:s.jsx(P,{name:"global",className:"h-4 w-4"})})}),s.jsx(Dt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":a("projectActions.actions.chooseActionAria"),children:s.jsx(P,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Rs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:ie,children:[s.jsx(P,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx(Cn,{}),ae.map(q=>{const Se=q.icon||"play",$e=q.id===or?"search":Zo[Se]||"play",Pe=ui(U,q.id),fe=T[Pe],L=!!fe,Z=fe?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{ye(q,!0)},children:[s.jsx(P,{name:$e,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),Z||fe?.status==="waiting-for-preview"?s.jsx(P,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):L?s.jsx(P,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]}):s.jsxs("div",{className:ce("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsxs("button",{type:"button",onClick:pe,disabled:V||ke,className:ce("inline-flex h-full items-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 justify-center px-0":"gap-2 px-3","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":we?a("projectActions.actions.stopNamedAria",{name:ue.name}):a("projectActions.actions.runNamedAria",{name:ue.name}),children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ke||xe?s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):we?s.jsx(P,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(P,{name:Ne,className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:Ce})]}),Me?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ue,className:ce(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":a("projectActions.actions.openPreview"),children:s.jsx(P,{name:"global",className:"h-4 w-4"})})}),s.jsx(Dt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:ce(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":a("projectActions.actions.chooseActionAria"),children:s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Rs,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:ie,children:[s.jsx(P,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx(Cn,{}),ae.map(q=>{const Se=q.icon||"play",$e=q.id===or?"search":Zo[Se]||"play",Pe=ui(U,q.id),fe=T[Pe],L=!!fe,Z=fe?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{ye(q)},children:[s.jsx(P,{name:$e,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),Z||fe?.status==="waiting-for-preview"?s.jsx(P,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):L?s.jsx(P,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]})},_l="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:bg-interactive-hover transition-colors",Uw="app-region-no-drag inline-flex h-9 w-9 items-center justify-center gap-2 p-2 rounded-md typography-ui-label font-medium text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:text-foreground hover:bg-interactive-hover transition-colors",Ta=o.memo(function(e){const n=at.c(13),{visible:r,title:i,ariaLabel:a,onClick:l,className:c,Icon:d,iconClassName:p}=e;if(!(r===void 0?!0:r))return null;const u=c??_l,h=p??"h-[18px] w-[18px]";let x;n[0]!==d||n[1]!==h?(x=s.jsx(P,{name:d,className:h}),n[0]=d,n[1]=h,n[2]=x):x=n[2];let f;n[3]!==a||n[4]!==l||n[5]!==u||n[6]!==x?(f=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,"aria-label":a,className:u,children:x})}),n[3]=a,n[4]=l,n[5]=u,n[6]=x,n[7]=f):f=n[7];let v;n[8]!==i?(v=s.jsx(Dt,{children:s.jsx("p",{children:i})}),n[8]=i,n[9]=v):v=n[9];let y;return n[10]!==f||n[11]!==v?(y=s.jsxs(Pt,{children:[f,v]}),n[10]=f,n[11]=v,n[12]=y):y=n[12],y}),Ww=o.memo(function(e){const n=at.c(42),{isMobile:r,githubAuthStatus:i,githubAccounts:a,githubAvatarUrl:l,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=ut();if(!i?.connected||r)return null;if(a.length>1){let f;n[0]===Symbol.for("react.memo_cache_sentinel")?(f=ce(_l,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=f):f=n[0];let v;n[1]!==c||n[2]!==m?(v=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=v):v=n[3];let y;n[4]!==l||n[5]!==c||n[6]!==m?(y=l?s.jsx("img",{src:l,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(P,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=l,n[5]=c,n[6]=m,n[7]=y):y=n[7];let g;n[8]!==d||n[9]!==v||n[10]!==y?(g=s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:f,title:v,disabled:d,children:y})}),n[8]=d,n[9]=v,n[10]=y,n[11]=g):g=n[11];let w;n[12]!==m?(w=m("header.github.accountsTitle"),n[12]=m,n[13]=w):w=n[13];let b;n[14]!==w?(b=s.jsx(Ka,{className:"typography-ui-header font-semibold text-foreground",children:w}),n[14]=w,n[15]=b):b=n[15];let k;n[16]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(Cn,{}),n[16]=k):k=n[16];let I;if(n[17]!==a||n[18]!==p||n[19]!==d||n[20]!==m){let D;n[22]!==p||n[23]!==d||n[24]!==m?(D=E=>{const T=E.user,C=!!E.current;return s.jsxs($t,{className:"gap-2",disabled:C||d,onSelect:()=>{C||p(E.id)},children:[T?.avatarUrl?s.jsx("img",{src:T.avatarUrl,alt:T.login?m("header.github.avatarWithLogin",{login:T.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(P,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:T?.name?.trim()||T?.login||"GitHub"}),T?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:T.login}):null]}),C?s.jsx(P,{name:"check",className:"h-4 w-4 text-primary"}):null]},E.id)},n[22]=p,n[23]=d,n[24]=m,n[25]=D):D=n[25],I=a.map(D),n[17]=a,n[18]=p,n[19]=d,n[20]=m,n[21]=I}else I=n[21];let j;n[26]!==b||n[27]!==I?(j=s.jsxs(Rs,{align:"end",className:"w-64",children:[b,k,I]}),n[26]=b,n[27]=I,n[28]=j):j=n[28];let N;return n[29]!==g||n[30]!==j?(N=s.jsxs(Fs,{children:[g,j]}),n[29]=g,n[30]=j,n[31]=N):N=n[31],N}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let h;n[35]!==l||n[36]!==c||n[37]!==m?(h=l?s.jsx("img",{src:l,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(P,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=l,n[36]=c,n[37]=m,n[38]=h):h=n[38];let x;return n[39]!==u||n[40]!==h?(x=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:u,children:h}),n[39]=u,n[40]=h,n[41]=x):x=n[41],x}),Kw=o.memo(function(e){const n=at.c(76),{isDesktopApp:r,currentInstanceLabel:i,compactCurrentInstanceLabel:a,isDesktopServicesOpen:l,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:h,servicesTabItems:x,quotaLastUpdated:f,quotaDisplayMode:v,quotaDisplayTabItems:y,handleDisplayModeChange:g,handleUsageRefresh:w,isQuotaLoading:b,isUsageRefreshSpinning:k,hasRateLimits:I,rateLimitGroups:j,expandedFamilies:N,toggleFamilyExpanded:D,shortcutLabel:E,showDevShutdown:T,isDevShutdownInFlight:C,onDevShutdown:S}=e,{t:M}=ut();let A;n[0]!==p||n[1]!==h||n[2]!==u||n[3]!==d||n[4]!==c?(A=te=>{c(te),te&&(d(),p==="usage"&&u===0&&h())},n[0]=p,n[1]=h,n[2]=u,n[3]=d,n[4]=c,n[5]=A):A=n[5];let R;n[6]!==i||n[7]!==r||n[8]!==M?(R=r?M("header.services.openWithCurrent",{current:i}):M("header.services.open"),n[6]=i,n[7]=r,n[8]=M,n[9]=R):R=n[9];const z=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let B;n[10]!==z?(B=ce(_l,z),n[10]=z,n[11]=B):B=n[11];let V;n[12]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(P,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=V):V=n[12];let $;n[13]!==a||n[14]!==r?($=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:a}):null,n[13]=a,n[14]=r,n[15]=$):$=n[15];let _;n[16]!==R||n[17]!==B||n[18]!==$?(_=s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":R,className:B,children:[V,$]})})}),n[16]=R,n[17]=B,n[18]=$,n[19]=_):_=n[19];let X;n[20]!==i||n[21]!==r||n[22]!==E||n[23]!==M?(X=r?M("header.services.tooltip.currentInstanceWithShortcuts",{current:i,toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}):M("header.services.tooltip.servicesWithShortcuts",{toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}),n[20]=i,n[21]=r,n[22]=E,n[23]=M,n[24]=X):X=n[24];let O;n[25]!==X?(O=s.jsx(Dt,{children:s.jsx("p",{children:X})}),n[25]=X,n[26]=O):O=n[26];let J;n[27]!==_||n[28]!==O?(J=s.jsxs(Pt,{children:[_,O]}),n[27]=_,n[28]=O,n[29]=J):J=n[29];let Q;n[30]!==h||n[31]!==u||n[32]!==m?(Q=te=>{const K=te;m(K),K==="usage"&&u===0&&h()},n[30]=h,n[31]=u,n[32]=m,n[33]=Q):Q=n[33];let ne;n[34]!==p||n[35]!==x||n[36]!==Q?(ne=s.jsx("div",{className:"sticky top-0 z-20 px-2 pt-1.5 pb-px",children:s.jsx("div",{className:"h-9",children:s.jsx(Cr,{items:x,activeId:p,onSelect:Q,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=p,n[35]=x,n[36]=Q,n[37]=ne):ne=n[37];let G;n[38]!==p||n[39]!==r||n[40]!==l||n[41]!==c?(G=r&&p==="instance"?s.jsx(Hx,{embedded:!0,open:l&&p==="instance",onOpenChange:qw,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=l,n[41]=c,n[42]=G):G=n[42];let le;n[43]!==p||n[44]!==l?(le=p==="mcp"?s.jsx(kh,{active:l&&p==="mcp"}):null,n[43]=p,n[44]=l,n[45]=le):le=n[45];let oe;n[46]!==p||n[47]!==N||n[48]!==g||n[49]!==w||n[50]!==I||n[51]!==b||n[52]!==k||n[53]!==v||n[54]!==y||n[55]!==f||n[56]!==j||n[57]!==M||n[58]!==D?(oe=p==="usage"?s.jsxs("div",{className:"overflow-x-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5",children:[s.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:M("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Dh(f)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Cr,{items:y,activeId:v,onSelect:te=>{g(te)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:ce("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:w,disabled:b||k,"aria-label":M("header.services.refreshRateLimitsAria"),children:s.jsx(P,{name:"refresh",className:ce("h-4 w-4",k&&"animate-spin")})})]})]}),I?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:M("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:j.map((te,K)=>{const ae=N[te.providerId]??[];return s.jsxs(o.Fragment,{children:[K>0?s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(vn,{providerId:te.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:te.providerName})]}),te.entries.length===0&&(!te.modelFamilies||te.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:te.error??M("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[te.entries.map(ve=>{const[re,be]=ve,pe=v==="remaining"?be.remainingPercent:be.usedPercent,ye=oo(be.usedPercent,be.resetAt,be.windowSeconds,re),ie=ye?.dailyAllocationPercent!=null?v==="remaining"?100-ei(ye.elapsedRatio):ei(ye.elapsedRatio):null,ue=ao(be.valueLabel,pe),se=Ud(be.resetAt,be.resetAfterFormatted??be.resetAtFormatted);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Wd(re)}),se?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:se}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ue==="-"?"":ue})]}),s.jsx(co,{percent:pe,tonePercent:be.usedPercent,className:"h-1.5",expectedMarkerPercent:ie}),ye?s.jsx(uo,{paceInfo:ye,compact:!0}):null]},`${te.providerId}-${re}`)}),te.modelFamilies&&te.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:te.modelFamilies.map(ve=>{const re=ve.familyId??"other",be=ae.includes(re);return s.jsxs(fr,{open:be,onOpenChange:()=>D(te.providerId,re),children:[s.jsxs(Pr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:ve.familyLabel}),be?s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(hr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:ve.models.map(pe=>{const[ye,ie]=pe,ue=v==="remaining"?ie.remainingPercent:ie.usedPercent,se=oo(ie.usedPercent,ie.resetAt,ie.windowSeconds),Ne=se?.dailyAllocationPercent!=null?v==="remaining"?100-ei(se.elapsedRatio):ei(se.elapsedRatio):null,Ce=ao(ie.valueLabel,ue);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:gl(ye)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ce==="-"?"":Ce})]}),s.jsx(co,{percent:ue,tonePercent:ie.usedPercent,className:"h-1.5",expectedMarkerPercent:Ne}),se?s.jsx(uo,{paceInfo:se,compact:!0}):null]},`${te.providerId}-${ye}`)})})})]},re)})}):null]})]},te.providerId)})})]}):null,n[46]=p,n[47]=N,n[48]=g,n[49]=w,n[50]=I,n[51]=b,n[52]=k,n[53]=v,n[54]=y,n[55]=f,n[56]=j,n[57]=M,n[58]=D,n[59]=oe):oe=n[59];let F;n[60]!==C||n[61]!==S||n[62]!==T||n[63]!==M?(F=T?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx($t,{disabled:C,onSelect:()=>{S()},children:M("header.services.shutdownDev")})})]}):null,n[60]=C,n[61]=S,n[62]=T,n[63]=M,n[64]=F):F=n[64];let U;n[65]!==ne||n[66]!==G||n[67]!==le||n[68]!==oe||n[69]!==F?(U=s.jsxs(Rs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[ne,G,le,oe,F]}),n[65]=ne,n[66]=G,n[67]=le,n[68]=oe,n[69]=F,n[70]=U):U=n[70];let W;return n[71]!==l||n[72]!==A||n[73]!==J||n[74]!==U?(W=s.jsxs(Fs,{open:l,onOpenChange:A,children:[J,U]}),n[71]=l,n[72]=A,n[73]=J,n[74]=U,n[75]=W):W=n[75],W}),Hw=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),Gw=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],i=n[1].slice(0,3),a=`${r} ${i}`.trim();return n.length>2||a.length<e.length?`${a}...`:a}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},Dh=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},lr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},To=t=>!t?.isOpen||!Array.isArray(t.tabs)||t.tabs.length===0?null:(t.tabs.find(n=>n.id===t.activeTabId)??t.tabs[t.tabs.length-1])?.mode??null,om=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:i=null})=>{const{t:a}=ut(),l=Ie(Fe=>Fe.setSessionSwitcherOpen),c=Ie(Fe=>Fe.toggleSidebar),d=Ie(Fe=>Fe.isSidebarOpen),p=Ie(Fe=>Fe.isRightSidebarOpen),m=Ie(Fe=>Fe.toggleBottomTerminal),u=Ie(Fe=>Fe.toggleRightSidebar),h=Ie(Fe=>Fe.openContextOverview),x=Ie(Fe=>Fe.openContextPlan),f=Ie(Fe=>Fe.openContextBrowser),v=Ie(Fe=>Fe.closeContextPanel),y=Ie(Fe=>Fe.contextPanelByDirectory),g=Ie(Fe=>Fe.activeMainTab),w=Ie(Fe=>Fe.setActiveMainTab),b=Ie(Fe=>Fe.shortcutOverrides),k=xt(Fe=>Fe.getCurrentModel),I=Pn(),[j,N]=o.useState(!1),D=Ot(Fe=>Fe.getContextUsage),E=Ot(Fe=>Fe.openNewSessionDraft),T=Ot(Fe=>!!Fe.newSessionDraft?.open),C=Ot(Fe=>Fe.currentSessionId),S=Gx(C??""),M=Uf(C??null),A=Ei(Fe=>Fe.activeSessions),R=Ad(),z=As(Fe=>Fe.activeProjectId?Fe.projects.find(Ct=>Ct.id===Fe.activeProjectId)??null:null),B=o.useMemo(()=>{if(!z)return null;const Fe=z.label?.trim();if(Fe)return Fe;const Ct=z.path.split(/[\\/]/).filter(Boolean);return Ct[Ct.length-1]??null},[z]),V=Ms(Fe=>Fe.results),$=Ms(Fe=>Fe.fetchAllQuotas),_=Ms(Fe=>Fe.isLoading),X=Ms(Fe=>Fe.lastUpdated),O=Ms(Fe=>Fe.displayMode),J=Ms(Fe=>Fe.dropdownProviderIds),Q=Ms(Fe=>Fe.loadSettings),ne=Ms(Fe=>Fe.setDisplayMode),{isMobile:G}=rn(),le=Hn(Fe=>Fe.status),oe=Hn(Fe=>Fe.setStatus),F=o.useRef(null),[U,W]=o.useState(()=>typeof window>"u"?!1:gn()),te=o.useMemo(()=>Dd(),[]),K=El(),[ae,ve]=o.useState(!1),re=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),be=o.useMemo(()=>{if(typeof window>"u")return null;const Fe=window.__APP_MACOS_MAJOR__;if(typeof Fe=="number"&&Number.isFinite(Fe)&&Fe>0)return Fe;if(typeof navigator>"u")return null;const Ct=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Ct)return null;const Zt=Number.parseInt(Ct[1],10),ls=Number.parseInt(Ct[2],10);return Number.isNaN(Zt)?null:Zt===10?ls:Zt},[]);Be.useEffect(()=>{typeof window>"u"||W(gn())},[]);const pe=k(),ye=pe&&typeof pe.limit=="object"&&pe.limit!==null?pe.limit:null,ie=ye&&typeof ye.context=="number"?ye.context:0,ue=ye&&typeof ye.output=="number"?ye.output:0,se=D(ie,ue),[Ne,Ce]=o.useState(null),je=!C||S;Be.useEffect(()=>{if(!C){Ce(Fe=>Fe===null?Fe:null);return}if(se&&se.totalTokens>0){Ce(Fe=>Hw(Fe,se)?Fe:se);return}je&&Ce(Fe=>Fe===null?Fe:null)},[se,C,je]);const we=Ie(Fe=>Fe.isSessionSwitcherOpen),ke=le?.connected?le.user?.avatarUrl??null:null,xe=le?.connected?le.user?.login??null:null,me=le?.accounts??[],[Me,Ue]=o.useState(!1),[q,Se]=o.useState(!1),[$e,Pe]=o.useState(!1),[fe,L]=o.useState(!1),[Z,Y]=o.useState("Local"),Ee=o.useMemo(()=>Gw(Z),[Z]),[Ae,Je]=o.useState(U?"instance":"usage"),[de,ze]=o.useState("usage");Be.useEffect(()=>{!U&&Ae==="instance"&&Je("usage")},[Ae,U]);const rt=o.useMemo(()=>mn(),[]),Re=o.useMemo(()=>G?typeof t=="function"?!!n:we:d,[G,we,d,n,t]),Xe=!rt&&g==="chat"&&!!Ne&&Ne.totalTokens>0,qe=Ne&&Ne.contextLimit>0?Math.min(999,Ne.totalTokens/Ne.contextLimit*100):0,Te=o.useCallback(async()=>{if(!(typeof window>"u"||!U))try{const Fe=await qx(),Ct=window.location.href,Zt=window.__APP_LOCAL_ORIGIN__||window.location.origin;if(wu(Ct,Zt)){Y("Local");return}const ls=Fe.hosts.find(Bs=>wu(Ct,Bs.url));if(ls?.label?.trim()){Y(Yx(ls.label.trim()));return}Y("Instance")}catch{Y("Local")}},[U]);Be.useEffect(()=>{Te()},[Te]),Nh();const We=Ms(Fe=>Fe.selectedModels),Ze=Ms(Fe=>Fe.expandedFamilies),Qe=Ms(Fe=>Fe.toggleFamilyExpanded),he=o.useMemo(()=>{const Fe=[];for(const Ct of Hr){if(!J.includes(Ct.id))continue;const Zt=V.find(en=>en.providerId===Ct.id),ls=Zt?.usage?.windows??{},Bs=Zt?.usage?.models,Js=Object.entries(ls),ws={providerId:Ct.id,providerName:Ct.name,entries:Js,error:Zt&&!Zt.ok&&Zt.configured?Zt.error:void 0};if(Bs&&Object.keys(Bs).length>0){const en=We[Ct.id]??[],nn=en.length>0,Rn=_v(Bs,Ct.id),Fn=wh(Ct.id),Ur=jh(Fn);ws.modelFamilies=[];for(const Ln of Ur){const er=Rn.get(Ln.id)??[];if(er.length===0)continue;const br=nn?er.filter(dn=>en.includes(dn)):er;if(br.length===0)continue;const ar=[];for(const dn of br){const On=Bs[dn];if(On?.windows){const bn=Object.entries(On.windows);bn.length>0&&ar.push([dn,bn[0][1]])}}ar.length>0&&ws.modelFamilies.push({familyId:Ln.id,familyLabel:Ln.label,models:ar})}const xr=Rn.get(null)??[],Wr=nn?xr.filter(Ln=>en.includes(Ln)):xr;if(Wr.length>0){const Ln=[];for(const er of Wr){const br=Bs[er];if(br?.windows){const ar=Object.entries(br.windows);ar.length>0&&Ln.push([er,ar[0][1]])}}Ln.length>0&&ws.modelFamilies.push({familyId:null,familyLabel:a("header.services.modelFamily.other"),models:Ln})}}(Js.length>0||ws.modelFamilies&&ws.modelFamilies.length>0||ws.error)&&Fe.push(ws)}return Fe},[J,V,We,a]),Ge=he.length>0;o.useEffect(()=>{Q()},[Q]);const Ve=o.useCallback(async Fe=>{ne(Fe);try{await ks({usageDisplayMode:Fe})}catch(Ct){console.warn("Failed to update usage display mode:",Ct)}},[ne]),it=o.useCallback(()=>{if(fe)return;L(!0);const Fe=new Promise(Ct=>setTimeout(Ct,500));Promise.all([$(),Fe]).finally(()=>{L(!1)})},[$,fe]),dt=o.useMemo(()=>C?R.find(Fe=>Fe.id===C)??A.find(Fe=>Fe.id===C)??M??Qx().find(Fe=>Fe.id===C)??null:null,[C,M,A,R]),Ye=o.useRef(null),[_e,et]=o.useState(0);o.useEffect(()=>{if(!C){Ye.current&&(Ye.current=null,et(ls=>ls+1));return}if(dt){Ye.current={sessionId:C,session:dt,expiresAt:Date.now()+2e3};return}const Fe=Ye.current;if(!Fe||Fe.sessionId!==C)return;const Ct=Fe.expiresAt-Date.now();if(Ct<=0){Ye.current=null,et(ls=>ls+1);return}const Zt=window.setTimeout(()=>{Ye.current?.sessionId===C&&(Ye.current=null),et(ls=>ls+1)},Ct);return()=>{window.clearTimeout(Zt)}},[C,dt]);const gt=(()=>{if(dt)return dt;if(!C)return null;const Fe=Ye.current;return Fe&&Fe.sessionId===C&&Fe.expiresAt>Date.now()?Fe.session:null})(),Lt=Ot(Fe=>C?Fe.worktreeMetadata.get(C)?.path??"":""),Ut=Ot(Fe=>C?Fe.worktreeMetadata.get(C)?.branch?.trim()??null:null),mt=Wf(Fe=>C?Fe.getAttachment(C):void 0),Nt=o.useMemo(()=>mt?Jx(mt):null,[mt]),Xt=o.useMemo(()=>mt?mt.legacy?"legacy":mt.degraded?"degraded":mt.worktreeStatus==="missing"?"missing":mt.worktreeStatus==="invalid"?"invalid":mt.attentionReason?"attention":null:null,[mt]),_t=o.useMemo(()=>lr(Lt||""),[Lt]),Gt=o.useMemo(()=>{const Fe=typeof gt?.directory=="string"?gt.directory:"";return lr(Fe||"")},[gt?.directory]),lt=Ot(Fe=>Fe.newSessionDraft?.open?lr(Fe.newSessionDraft.bootstrapPendingDirectory??Fe.newSessionDraft.directoryOverride??""):""),Tt=o.useMemo(()=>_t||Gt||lt,[lt,Gt,_t]),rs=Ot(Fe=>{const Ct=lr(_t||Gt||"");if(!Ct)return null;for(const Zt of Fe.availableWorktreesByProject.values()){const Bs=Zt.find(Js=>lr(Js.path)===Ct)?.branch?.trim();if(Bs)return Bs}return null}),ys=Xx(Tt||null)||Ut||rs,vs=o.useMemo(()=>{if(!C)return B??"Vinci";const Fe=gt?.title?.trim();return Fe&&Fe.length>0?Fe:"Untitled Session"},[B,gt?.title,C]),Wt=o.useMemo(()=>Kf(gt?.summary),[gt?.summary]),He=o.useMemo(()=>Wt||{additions:0,deletions:0},[Wt]),kt=He.additions>0||He.deletions>0,Kt=o.useMemo(()=>lr(Tt||z?.path||""),[z?.path,Tt]),wt=o.useMemo(()=>z?{id:z.id,path:z.path}:null,[z]),Qt=o.useRef(null);o.useEffect(()=>{!wt||!Kt||(Qt.current={projectRef:wt,directory:Kt})},[Kt,wt]);const cs=o.useMemo(()=>wt&&Kt?{projectRef:wt,directory:Kt}:Qt.current,[Kt,wt]),Ls=Td(Fe=>Fe.planModeEnabled),Ss=Ot(Fe=>Fe.isSessionPlanAvailable),ns=Ls&&C?Ss(C):!1,Os=ns,Ks=o.useRef("");o.useEffect(()=>{if(!Ls){Ie.getState().activeMainTab==="plan"&&Ie.getState().setActiveMainTab("chat");return}if(!C)return;const Fe=`${C||"none"}:${Gt||"none"}:${gt?.time?.created||0}:${gt?.slug||"none"}`;Ks.current!==Fe&&(Ks.current=Fe),!ns&&Ie.getState().activeMainTab==="plan"&&Ie.getState().setActiveMainTab("chat")},[Ls,ns,gt?.slug,gt?.time?.created,C,Gt]);const bt=o.useCallback(async Fe=>{if(!(!Fe||Me)){Ue(!0);try{const Ct=I.github?await I.github.authActivate(Fe):await(async()=>{const Zt=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Fe})}),ls=await Zt.json().catch(()=>null);if(!Zt.ok||!ls)throw new Error(ls?.error||Zt.statusText);return ls})();oe(Ct)}catch(Ct){console.error("Failed to switch GitHub account:",Ct)}finally{Ue(!1)}}},[Me,I.github,oe]),Mt=o.useCallback(()=>{if(typeof document>"u")return;const Fe=document.activeElement;if(!Fe)return;const Ct=Fe.tagName;(Ct==="INPUT"||Ct==="TEXTAREA"||Ct==="SELECT"||Fe.isContentEditable)&&Fe.blur()},[]),At=o.useCallback(()=>{if(G){Mt(),l(!we);return}c()},[Mt,G,we,l,c]),ee=o.useCallback(()=>{w("chat"),l(!1),E()},[E,w,l]),ht=o.useCallback(()=>{ml("desktop_open_draft_mini_chat_window",{directory:lr(Tt||z?.path||""),projectId:z?.id??null}).catch(Fe=>{console.warn("[header] failed to open draft mini chat window",Fe)})},[z?.id,z?.path,Tt]),St=o.useCallback(()=>{if(T){ht();return}C&&ml("desktop_open_session_mini_chat_window",{sessionId:C,directory:lr(Tt||z?.path||"")}).catch(Fe=>{console.warn("[header] failed to open session mini chat window",Fe)})},[z?.path,C,ht,T,Tt]),qt=o.useCallback(()=>{const Fe=lr(Tt||"");if(!Fe)return;const Ct=y[Fe];if(To(Ct)==="context"){v(Fe);return}h(Fe)},[v,y,h,Tt]),ms=o.useMemo(()=>{const Fe=lr(Tt||"");if(!Fe)return!1;const Ct=y[Fe];return To(Ct)==="context"},[y,Tt]),Ds=o.useCallback(()=>{const Fe=lr(Tt||"");if(!Fe)return;const Ct=y[Fe];if(To(Ct)==="plan"){v(Fe);return}x(Fe)},[v,y,x,Tt]),Ke=o.useCallback(()=>{const Fe=lr(Tt||"");Fe&&f(Fe)},[f,Tt]),yt=o.useMemo(()=>{const Fe=lr(Tt||"");if(!Fe)return!1;const Ct=y[Fe];return To(Ct)==="plan"},[y,Tt]),Et=_l,Ht=Uw,ss=o.useMemo(()=>!d&&(U&&re&&!ae||K)?"pl-[5.5rem]":"pl-3",[U,ae,re,d,K]);Be.useEffect(()=>{if(!U||!re){ve(!1);return}let Fe=!1,Ct=null;const Zt=async()=>{try{const{getCurrentWindow:Bs}=await kr(async()=>{const{getCurrentWindow:en}=await import("./vendor-.bun-B9l0ZNi2.js").then(nn=>nn.bM);return{getCurrentWindow:en}},__vite__mapDeps([0,1])),ws=await Bs().isFullscreen();Fe||ve(ws)}catch{Fe||ve(!1)}},ls=async()=>{try{const{getCurrentWindow:Bs}=await kr(async()=>{const{getCurrentWindow:ws}=await import("./vendor-.bun-B9l0ZNi2.js").then(en=>en.bM);return{getCurrentWindow:ws}},__vite__mapDeps([0,1]));Ct=await Bs().onResized(()=>{Zt()})}catch{}};return Zt(),ls(),()=>{Fe=!0,Ct&&Ct()}},[U,re]);const Rt=o.useMemo(()=>!U||!re||be===null?"":be>=26?"h-12":be<=15?"h-14":"",[U,re,be]),Ps=o.useMemo(()=>{if(!(U||rt))return{paddingLeft:K&&!d?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[U,d,K,rt]),Qs=o.useCallback(()=>{if(typeof document>"u")return;const Fe=F.current?.getBoundingClientRect().height;Fe&&document.documentElement.style.setProperty("--oc-header-height",`${Fe}px`)},[]);Be.useEffect(()=>{if(typeof window>"u")return;Qs();const Fe=F.current;if(!Fe||typeof ResizeObserver>"u")return()=>{};let Ct=0;const Zt=()=>{Ct||(Ct=requestAnimationFrame(()=>{Ct=0,Qs()}))},ls=new ResizeObserver(Zt);return ls.observe(Fe),window.addEventListener("resize",Zt),window.addEventListener("orientationchange",Zt),()=>{Ct&&cancelAnimationFrame(Ct),ls.disconnect(),window.removeEventListener("resize",Zt),window.removeEventListener("orientationchange",Zt)}},[Qs]),Be.useEffect(()=>{Qs()},[Qs,G,Rt]);const Hs=o.useCallback(async Fe=>{const Ct=Fe.target;Ct.closest(".app-region-no-drag")||Ct.closest("button, a, input, select, textarea")||Fe.button===0&&U&&await Hf()},[U]),ts=o.useMemo(()=>{if(G){const Fe=[{id:"chat",label:a("layout.mainTab.chat"),icon:"chat-4"}];return Os&&Fe.push({id:"plan",label:a("layout.mainTab.plan"),icon:"file-text"}),Fe.push({id:"diff",label:a("layout.mainTab.diff"),icon:"diff"},{id:"files",label:a("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:a("layout.mainTab.terminal"),icon:"terminal-box"}),Fe}return[]},[G,Os,a]),Ns=o.useCallback(Fe=>Rl(Zr(Fe,b)),[b]);Be.useEffect(()=>{!G&&(g==="git"||g==="terminal"||g==="diff"||g==="files")&&w("chat")},[g,G,w]);const jn=o.useMemo(()=>{const Fe=[];return U&&Fe.push({value:"instance",label:a("layout.services.instance"),icon:"server"}),Fe.push({value:"usage",label:a("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:Zv}),Fe},[U,a]),sn=o.useMemo(()=>jn.map(Fe=>({id:Fe.value,label:Fe.label,icon:s.jsx(P,{name:Fe.icon,className:"h-3.5 w-3.5"})})),[jn]),Dr=o.useMemo(()=>{if(typeof window>"u"||U||rt)return!1;const Fe=window.location.hostname;return Fe==="localhost"||Fe==="127.0.0.1"||Fe==="::1"},[U,rt]),Tr=o.useCallback(async()=>{if(j)return;N(!0),Pe(!1);const Fe=[];let Ct=!1;try{try{for(const[,Zt]of on.getState().sessions.entries())for(const ls of Zt.tabs)ls.previewUrl&&Fe.push(ls.previewUrl)}catch{}try{await $x({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Fe})})).ok?Ct=!0:Ct=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Ct||N(!1)}},[j,Pe]),zr=o.useMemo(()=>[{value:"usage",label:a("header.services.used")},{value:"remaining",label:a("header.services.remaining")}],[a]),Vr=o.useMemo(()=>zr.map(Fe=>({id:Fe.value,label:Fe.label})),[zr]),Gs=o.useMemo(()=>[{id:"usage",label:a("layout.services.usage"),icon:s.jsx(P,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(P,{name:"command",className:"h-3.5 w-3.5"})}],[a]);Be.useEffect(()=>{const Fe=Ct=>{if(Md(Ct)&&!Ct.shiftKey&&!Ct.altKey){const Zt=parseInt(Ct.key,10);Zt>=1&&Zt<=ts.length&&(Ct.preventDefault(),w(ts[Zt-1].id))}};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[ts,w]),Be.useEffect(()=>{const Fe=Ct=>{const Zt=Zr("toggle_services_menu",b);if(Yo(Ct,Zt)){Ct.preventDefault(),$e?Pe(!1):(Pe(!0),Te(),Ae==="usage"&&V.length===0&&$());return}const ls=Zr("cycle_services_tab",b);if(Yo(Ct,ls)){Ct.preventDefault();const Js=jn.map(Rn=>Rn.value);if(Js.length===0)return;const ws=Js.indexOf(Ae),en=ws===-1?0:(ws+1)%Js.length,nn=Js[en];Je(nn),Pe(!0),Te(),nn==="usage"&&V.length===0&&$();return}const Bs=Zr("toggle_context_plan",b);Yo(Ct,Bs)&&(Ct.preventDefault(),Ds())};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[b,$e,Ae,jn,V.length,$,Te,Ds]);const Mn=Fe=>{const Ct=g===Fe.id,Zt=Fe.icon==="diff",ls=Zt?null:Fe.icon,Bs=Fe.id==="chat",Js=en=>Zt?s.jsx(Yu,{size:en}):ls?s.jsx(P,{name:ls,className:`h-${en/4} w-${en/4}`}):null,ws=s.jsxs("button",{type:"button",onClick:()=>w(Fe.id),className:ce("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Ct?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",Bs&&!G&&"min-w-[100px] justify-center"),"aria-label":Fe.label,"aria-selected":Ct,role:"tab",children:[G?Js(20):s.jsxs(s.Fragment,{children:[Js(16),s.jsx("span",{className:"header-tab-label",children:Fe.label})]}),Fe.badge!==void 0&&Fe.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Fe.badge})]});return s.jsx(o.Fragment,{children:ws},Fe.id)},ir=s.jsxs(s.Fragment,{children:[Os&&s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.openPlanAria"),onClick:Ds,className:ce(Et,yt&&"bg-[var(--interactive-hover)]"),children:s.jsx(P,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(Dt,{children:s.jsx("p",{children:a("header.actions.planWithShortcut",{shortcut:Ns("toggle_context_plan")})})})]}),s.jsx(iw,{directory:Kt,className:"mr-1"}),s.jsx(Kw,{isDesktopApp:U,currentInstanceLabel:Z,compactCurrentInstanceLabel:Ee,isDesktopServicesOpen:$e,setIsDesktopServicesOpen:Pe,refreshCurrentInstanceLabel:Te,desktopServicesTab:Ae,setDesktopServicesTab:Je,quotaResultsLength:V.length,fetchAllQuotas:$,servicesTabItems:sn,quotaLastUpdated:X,quotaDisplayMode:O,quotaDisplayTabItems:Vr,handleDisplayModeChange:Ve,handleUsageRefresh:it,isQuotaLoading:_,isUsageRefreshSpinning:fe,hasRateLimits:Ge,rateLimitGroups:he,expandedFamilies:Ze,toggleFamilyExpanded:Qe,shortcutLabel:Ns,showDevShutdown:Dr,isDevShutdownInFlight:j,onDevShutdown:Tr}),s.jsx(Ta,{title:a("header.actions.terminalPanelWithShortcut",{shortcut:Ns("toggle_terminal")}),ariaLabel:a("header.actions.toggleTerminalPanelAria"),onClick:m,Icon:"terminal-box"}),te?s.jsx(Ta,{title:a("contextPanel.browser.open"),ariaLabel:a("contextPanel.browser.open"),onClick:Ke,Icon:"global"}):null,s.jsx(Ta,{title:a("header.actions.rightSidebarWithShortcut",{shortcut:Ns("toggle_right_sidebar")}),ariaLabel:a("header.actions.toggleRightSidebarAria"),onClick:u,Icon:"layout-right"}),s.jsx(Ww,{isMobile:G,githubAuthStatus:le,githubAccounts:me,githubAvatarUrl:ke,githubLogin:xe,isSwitchingGitHubAccount:Me,handleGitHubAccountSwitch:bt})]}),En=!p||!i,_r=te&&(T||!!C),In=()=>s.jsxs("div",{onMouseDown:Hs,className:ce("app-region-drag relative flex h-12 select-none items-center pr-3",ss,Rt),style:Ps,role:"tablist","aria-label":a("header.navigation.mainAria"),children:[s.jsx(Ta,{visible:!d,title:a("header.actions.openSessionsWithShortcut",{shortcut:Ns("toggle_sidebar")}),ariaLabel:a("header.actions.openSessionsAria"),onClick:At,className:`${Et} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:ce("flex min-w-0 flex-1 items-center",!d&&"pl-3"),children:[Re?null:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.newSessionAria"),onClick:ee,className:ce(Et,"mr-6 shrink-0"),children:s.jsx(P,{name:"chat-new",className:"h-[18px] w-[18px]"})})}),s.jsx(Dt,{children:s.jsx("p",{children:a("header.actions.newSessionWithShortcut",{shortcut:Ns("new_chat")})})})]}),cs&&s.jsx(am,{projectRef:cs.projectRef,directory:cs.directory,className:"mr-2"}),s.jsx(Zx,{children:s.jsxs("button",{type:"button","aria-label":a("sessions.switcher.openAria"),className:"app-region-no-drag mr-3 flex min-w-0 flex-col items-start rounded-md px-1 py-0.5 -my-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:T?a("sessions.switcher.draftTitle"):vs}),B||ys||!T&&(kt||Xt)?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[B?s.jsx("span",{className:"truncate",children:B}):null,ys?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ys})]}):null,!T&&kt?s.jsxs("span",{className:"inline-flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",He.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",He.deletions]})]}):null,!T&&Xt?s.jsxs("span",{className:ce("inline-flex min-w-0 items-center gap-0.5",Xt==="attention"||Xt==="invalid"||Xt==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(P,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Nt})]}):null]}):null]})}),ts.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:ts.map(Fe=>Mn(Fe))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Xe&&Ne?s.jsx(eb,{totalTokens:Ne.totalTokens,percentage:qe,colorPercentage:Ne.percentage,contextLimit:Ne.contextLimit,outputLimit:Ne.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:qt,pressed:ms,className:En&&!_r?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Ta,{visible:_r,title:a(T?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:a(T?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:St,className:ce(Et,En&&Xe?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),En?ir:null,!En&&i?Wa.createPortal(ir,i):null]})]})]}),ln=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t?s.jsx("button",{type:"button",onClick:t,className:ce(Ht,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":a(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(P,{name:"layout-left",className:"h-5 w-5"})}):we?s.jsx("button",{type:"button",onClick:()=>l(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":a("header.actions.backAria"),children:s.jsx(P,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:At,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":a("header.actions.openSessionsAria"),children:s.jsx(P,{name:"play-list-add",className:"h-5 w-5"})}),we&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:a("header.sessions.title")})]}),!we&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":a("header.navigation.mainAria"),children:ts.map(Fe=>{const Ct=g===Fe.id,Zt=Fe.icon==="diff",ls=Zt?null:Fe.icon;return s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{G&&Mt(),w(Fe.id)},"aria-label":Fe.label,"aria-selected":Ct,role:"tab",className:ce(Ht,"relative rounded-lg",Ct&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Zt?s.jsx(Yu,{className:"h-5 w-5"}):ls?s.jsx(P,{name:ls,className:"h-5 w-5"}):null,Fe.badge!==void 0&&Fe.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Fe.badge}),Fe.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":a("header.changes.availableAria")})]})}),s.jsx(Dt,{children:s.jsx("p",{children:Fe.label})})]},Fe.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[cs&&s.jsx(am,{projectRef:cs.projectRef,directory:cs.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(Fs,{open:q,onOpenChange:Fe=>{Se(Fe),Fe&&V.length===0&&$()},children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.services.viewAria"),className:Ht,children:s.jsx(P,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Dt,{children:s.jsx("p",{children:a("header.services.title")})})]}),s.jsx(Rs,{align:"end",sideOffset:0,className:"h-dvh w-[100vw] max-h-none rounded-none border-0 p-0 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(Cr,{items:Gs,activeId:de,onSelect:Fe=>{const Ct=Fe;ze(Ct),Ct==="usage"&&V.length===0&&$()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>Se(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":a("header.services.closeAria"),children:s.jsx(P,{name:"close",className:"h-5 w-5"})})]})}),de==="mcp"&&s.jsx(kh,{active:q&&de==="mcp"}),de==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:a("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Dh(X)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>Ve("usage"),className:ce("typography-ui-label px-1 pb-0.5 transition-colors",O==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>Ve("remaining"),className:ce("typography-ui-label px-1 pb-0.5 transition-colors",O==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.remaining")})]}),s.jsx("button",{type:"button",className:ce("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:it,disabled:_||fe,"aria-label":a("header.services.refreshRateLimitsAria"),children:s.jsx(P,{name:"refresh",className:ce("h-4 w-4",fe&&"animate-spin")})})]})]})}),!Ge&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:a("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:he.map((Fe,Ct)=>s.jsxs(o.Fragment,{children:[Ct>0?s.jsx("div",{className:"mx-4 my-1 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(vn,{providerId:Fe.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Fe.providerName})]}),Fe.entries.length===0&&(!Fe.modelFamilies||Fe.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Fe.error??a("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Fe.entries.map(([Zt,ls])=>{const Bs=O==="remaining"?ls.remainingPercent:ls.usedPercent,Js=oo(ls.usedPercent,ls.resetAt,ls.windowSeconds,Zt),ws=Js?.dailyAllocationPercent!=null?O==="remaining"?100-ei(Js.elapsedRatio):ei(Js.elapsedRatio):null,en=ao(ls.valueLabel,Bs),nn=Ud(ls.resetAt,ls.resetAfterFormatted??ls.resetAtFormatted);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Wd(Zt)}),nn?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:nn}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:en==="-"?"":en})]}),s.jsx(co,{percent:Bs,tonePercent:ls.usedPercent,className:"h-1.5",expectedMarkerPercent:ws}),Js?s.jsx(uo,{paceInfo:Js,compact:!0}):null]},`${Fe.providerId}-${Zt}`)}),Fe.modelFamilies&&Fe.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Fe.modelFamilies.map(Zt=>{const Bs=(Ze[Fe.providerId]??[]).includes(Zt.familyId??"other");return s.jsxs(fr,{open:Bs,onOpenChange:()=>Qe(Fe.providerId,Zt.familyId??"other"),children:[s.jsxs(Pr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Zt.familyLabel}),Bs?s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(hr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Zt.models.map(([Js,ws])=>{const en=O==="remaining"?ws.remainingPercent:ws.usedPercent,nn=oo(ws.usedPercent,ws.resetAt,ws.windowSeconds),Rn=nn?.dailyAllocationPercent!=null?O==="remaining"?100-ei(nn.elapsedRatio):ei(nn.elapsedRatio):null,Fn=ao(ws.valueLabel,en);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:gl(Js)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Fn==="-"?"":Fn})]}),s.jsx(co,{percent:en,tonePercent:ws.usedPercent,className:"h-1.5",expectedMarkerPercent:Rn}),nn?s.jsx(uo,{paceInfo:nn,compact:!0}):null]},`${Fe.providerId}-${Js}`)})})})]},Zt.familyId??"other")})})]})]},Fe.providerId))})]})]})})]}),e?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:ce(Ht,"relative",r&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(P,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Dt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),an=ce("header-safe-area relative z-10",G&&"border-b border-border/50","bg-background");return s.jsx("header",{ref:F,className:an,style:{"--padding-scale":"1"},children:G?ln():In()})};function qw(){}const lm=180,cm=640,Yw=110,Qw=t=>{const e=at.c(44),{isOpen:n,isMobile:r,children:i}=t,{t:a}=ut(),l=Ie(Jw),c=Ie(Xw),d=Ie(Zw),p=Ie(e1),[m,u]=o.useState(null),[h,x]=o.useState(!1),f=o.useRef(null),v=o.useRef(0),y=o.useRef(l||300),g=Math.min(cm,Math.max(lm,l||300));let w,b;e[0]!==n?(w=()=>{n||(u(null),x(!1))},b=[n],e[0]=n,e[1]=w,e[2]=b):(w=e[1],b=e[2]),o.useEffect(w,b);let k,I;e[3]!==c||e[4]!==r||e[5]!==n?(k=()=>{if(r||!n||!c)return;const Q=()=>{const le=f.current?.parentElement?.getBoundingClientRect().height;if(!le||le<=0)return;const oe=Math.max(0,Math.round(le));u(F=>F===oe?F:oe)};Q();const ne=f.current?.parentElement;if(!ne)return;const G=new ResizeObserver(Q);return G.observe(ne),()=>{G.disconnect()}},I=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=k,e[7]=I):(k=e[6],I=e[7]),o.useEffect(k,I);let j,N;if(e[8]!==c||e[9]!==r||e[10]!==h||e[11]!==d||e[12]!==p?(j=()=>{if(r||!h||c)return;const Q=G=>{const le=v.current-G.clientY,oe=Math.min(cm,Math.max(lm,y.current+le));d(oe)},ne=()=>{x(!1),Ie.getState().bottomTerminalHeight<=Yw&&p(!1)};return window.addEventListener("pointermove",Q),window.addEventListener("pointerup",ne,{once:!0}),()=>{window.removeEventListener("pointermove",Q),window.removeEventListener("pointerup",ne)}},N=[c,r,h,d,p],e[8]=c,e[9]=r,e[10]=h,e[11]=d,e[12]=p,e[13]=j,e[14]=N):(j=e[13],N=e[14]),o.useEffect(j,N),r)return null;const D=n?c?Math.max(0,m??g):g:0,E=n&&c;let T;e[15]!==D||e[16]!==c||e[17]!==n?(T=Q=>{!n||c||(x(!0),v.current=Q.clientY,y.current=D,Q.preventDefault())},e[15]=D,e[16]=c,e[17]=n,e[18]=T):T=e[18];const C=T,S=E?"absolute inset-x-0 bottom-0 z-40":"relative",M=h?"transition-none":"transition-[height] duration-300 ease-in-out",A=!n&&"border-t-0";let R;e[19]!==A||e[20]!==S||e[21]!==M?(R=ce("flex overflow-hidden border-t border-border bg-sidebar",S,M,A),e[19]=A,e[20]=S,e[21]=M,e[22]=R):R=e[22];let z;e[23]!==D||e[24]!==E?(z=E?{top:"var(--oc-header-height, 48px)"}:{height:`${D}px`,minHeight:`${D}px`,maxHeight:`${D}px`},e[23]=D,e[24]=E,e[25]=z):z=e[25];const B=!n||!c&&D===0;let V;e[26]!==C||e[27]!==c||e[28]!==n||e[29]!==h||e[30]!==a?(V=n&&!c&&s.jsx("div",{className:ce("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",h&&"bg-[var(--interactive-border)]"),onPointerDown:C,role:"separator","aria-orientation":"horizontal","aria-label":a("terminalView.bottomDock.resizeAria")}),e[26]=C,e[27]=c,e[28]=n,e[29]=h,e[30]=a,e[31]=V):V=e[31];const $=!n&&"pointer-events-none select-none opacity-0";let _;e[32]!==$?(_=ce("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",$),e[32]=$,e[33]=_):_=e[33];const X=!n;let O;e[34]!==i||e[35]!==_||e[36]!==X?(O=s.jsx("div",{className:_,"aria-hidden":X,children:i}),e[34]=i,e[35]=_,e[36]=X,e[37]=O):O=e[37];let J;return e[38]!==R||e[39]!==z||e[40]!==B||e[41]!==V||e[42]!==O?(J=s.jsxs("section",{ref:f,className:R,style:z,"aria-hidden":B,children:[V,O]}),e[38]=R,e[39]=z,e[40]=B,e[41]=V,e[42]=O,e[43]=J):J=e[43],J};function Jw(t){return t.bottomTerminalHeight}function Xw(t){return t.isBottomTerminalExpanded}function Zw(t){return t.setBottomTerminalHeight}function e1(t){return t.setBottomTerminalOpen}const rd=280,dm=280,um=500,t1=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:i}=ut(),a=Ie(k=>k.sidebarWidth),l=Ie(k=>k.setSidebarWidth),[c,d]=o.useState(!1),p=o.useRef(0),m=o.useRef(a||rd),u=o.useRef(null),h=o.useRef(null),x=o.useRef(null),f=o.useCallback(k=>Math.min(um,Math.max(dm,k)),[]),v=o.useCallback(k=>{const I=x.current;I&&I.style.setProperty("--oc-left-sidebar-width",`${k}px`)},[]);if(o.useEffect(()=>{e&&c&&d(!1)},[e,c]),o.useEffect(()=>{c||(u.current=null,h.current=null)},[c]),e)return null;const y=t?Math.min(um,Math.max(dm,a||rd)):0,g=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}h.current=k.pointerId,d(!0),p.current=k.clientX,m.current=y,u.current=y,v(y),k.preventDefault()}},w=k=>{if(e||!c||h.current!==k.pointerId)return;const I=k.clientX-p.current,j=f(m.current+I);u.current!==j&&(u.current=j,v(j))},b=k=>{if(h.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const I=f(u.current??y);h.current=null,u.current=null,d(!1),l(I)};return s.jsxs("aside",{ref:x,className:ce("relative flex h-full overflow-hidden border-r border-border/40","bg-sidebar",c?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-r-0",r),style:{width:"var(--oc-left-sidebar-width)",minWidth:"var(--oc-left-sidebar-width)",maxWidth:"var(--oc-left-sidebar-width)","--oc-left-sidebar-width":`${c?u.current??y:y}px`,overflowX:"clip"},"aria-hidden":!t||y===0,children:[t&&s.jsx("div",{className:ce("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:g,onPointerMove:w,onPointerUp:b,onPointerCancel:b,role:"separator","aria-orientation":"vertical","aria-label":i("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:ce("relative z-10 flex h-full flex-col transition-opacity duration-300 ease-in-out",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Xs,{children:n})})})]})},Th=420,mm=400,pm=860,s1=({isOpen:t,children:e,className:n,onTopActionsHostChange:r})=>{const{t:i}=ut(),a=Ie(E=>E.rightSidebarWidth),l=Ie(E=>E.setRightSidebarWidth),c=o.useMemo(()=>gn(),[]),d=o.useMemo(()=>mn(),[]),p=El(),[m,u]=o.useState(!1),h=o.useRef(0),x=o.useRef(a||420),f=o.useRef(null),v=o.useRef(null),y=o.useRef(null),g=o.useCallback(E=>Math.min(pm,Math.max(mm,E)),[]),w=o.useCallback(E=>{const T=y.current;T&&T.style.setProperty("--oc-right-sidebar-width",`${E}px`)},[]),b=t?Math.min(pm,Math.max(mm,a||Th)):0,k=E=>{if(t){try{E.currentTarget.setPointerCapture(E.pointerId)}catch{}v.current=E.pointerId,u(!0),h.current=E.clientX,x.current=b,f.current=b,w(b),E.preventDefault()}},I=E=>{if(!m||v.current!==E.pointerId)return;const T=h.current-E.clientX,C=g(x.current+T);f.current!==C&&(f.current=C,w(C))},j=E=>{if(v.current!==E.pointerId)return;try{E.currentTarget.releasePointerCapture(E.pointerId)}catch{}const T=g(f.current??b);v.current=null,f.current=null,u(!1),l(T)};o.useEffect(()=>{m||(f.current=null,v.current=null)},[m]),o.useEffect(()=>{t||r?.(null)},[t,r]);const N=o.useCallback(async E=>{const T=E.target;T.closest(".app-region-no-drag")||T.closest("button, a, input, select, textarea")||E.button===0&&c&&await Hf()},[c]),D=o.useMemo(()=>{if(!(c||d))return{paddingLeft:"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",...p?{paddingTop:"var(--oc-safe-area-top, 0px)"}:null}},[c,p,d]);return s.jsxs("aside",{ref:y,className:ce("relative flex h-full overflow-hidden border-l border-border/40","bg-sidebar",m?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-l-0",n),style:{width:"var(--oc-right-sidebar-width)",minWidth:"var(--oc-right-sidebar-width)",maxWidth:"var(--oc-right-sidebar-width)","--oc-right-sidebar-width":`${m?f.current??b:b}px`,overflowX:"clip"},"aria-hidden":!t||b===0,children:[t?s.jsx("div",{onMouseDown:N,className:ce("app-region-drag absolute inset-x-0 top-0 z-20 flex items-center justify-end px-3","h-[var(--oc-header-height,56px)]"),style:D,"aria-hidden":!0,children:s.jsx("div",{ref:r,className:"app-region-no-drag flex items-center gap-1"})}):null,t&&s.jsx("div",{className:ce("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",m&&"bg-[var(--interactive-border)]"),onPointerDown:k,onPointerMove:I,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":i("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:ce("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",m&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:t?{paddingTop:"var(--oc-header-height, 56px)"}:void 0,"aria-hidden":!t,children:t?e:null})]})},n1=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),r1=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=n1.format(t);return e.endsWith(".0")?e.slice(0,-2):e},yo=({providerId:t,modelId:e,onChange:n,className:r,allowedProviderIds:i,placeholder:a})=>{const{t:l}=ut(),{isReady:c,isUnavailable:d}=Gf(),p=xt(F=>F.providers),m=xt(F=>F.modelsMetadata),u=Ie(F=>F.isMobile),h=Ie(F=>F.hiddenModels),x=Ie(F=>F.toggleFavoriteModel),f=Ie(F=>F.isFavoriteModel),v=Ie(F=>F.addRecentModel),{favoriteModelsList:y,recentModelsList:g}=qf(),{isMobile:w}=rn(),b=u||w,[k,I]=o.useState(!1),[j,N]=o.useState(new Set),[D,E]=o.useState(!1),[T,C]=o.useState(""),[S,M]=o.useState(0),A=o.useRef([]),R=o.useMemo(()=>!Array.isArray(i)||i.length===0?null:new Set(i),[i]),z=o.useMemo(()=>(R?p.filter(U=>R.has(String(U.id))):p).map(U=>{const te=(Array.isArray(U.models)?U.models:[]).filter(K=>{const ae=typeof K?.id=="string"?K.id:"";return!h.some(ve=>ve.providerID===String(U.id)&&ve.modelID===ae)});return{...U,models:te}}).filter(U=>U.models.length>0),[p,R,h]),B=()=>I(!1),V=F=>{N(U=>{const W=new Set(U);return W.has(F)?W.delete(F):W.add(F),W})};o.useEffect(()=>{D||(C(""),M(0))},[D]),o.useEffect(()=>{M(0)},[T]);const $=F=>{const U=F?.name||F?.id||"",W=String(U);return W.length>40?W.substring(0,37)+"...":W},_=(F,U)=>{const W=`${F}/${U}`;return m.get(W)},X=(F,U)=>{n(F,U),F&&U&&v(F,U),E(!1)},O=(F,U)=>{if(!T.trim())return!0;const W=T.toLowerCase();return F.toLowerCase().includes(W)||U.toLowerCase().includes(W)},J=(F,U,W,te,K,ae)=>{const ve=_(U,W),re=r1(ve?.limit?.context),be=t===U&&e===W,pe=f(U,W),ye=te==="fav"||te==="recent";return s.jsxs($t,{ref:ie=>{A.current[K]=ie},className:ce("group flex items-center gap-2",ae&&"bg-interactive-selection"),onSelect:()=>X(U,W),onMouseEnter:()=>M(K),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[ye&&s.jsx(vn,{providerId:U,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(F)}),re?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:re}):null]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[be&&s.jsx(P,{name:"check",className:"h-4 w-4 text-primary"}),s.jsx("button",{onClick:ie=>{ie.preventDefault(),ie.stopPropagation(),x(U,W)},className:ce("model-favorite-button flex h-4 w-4 items-center justify-center hover:text-primary/80",pe?"text-primary":"text-muted-foreground"),"aria-label":l(pe?"settings.agents.modelSelector.actions.unfavorite":"settings.agents.modelSelector.actions.favorite"),title:l(pe?"settings.agents.modelSelector.actions.removeFromFavorites":"settings.agents.modelSelector.actions.addToFavorites"),children:pe?s.jsx(P,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"star",className:"h-3.5 w-3.5"})})]})]},`${te}-${U}-${W}`)},Q=y.filter(({model:F,providerID:U})=>{if(R&&!R.has(U))return!1;const te=p.find(ae=>ae.id===U)?.name||U,K=$(F);return O(K,te)}),ne=g.filter(({model:F,providerID:U})=>{if(R&&!R.has(U))return!1;const te=p.find(ae=>ae.id===U)?.name||U,K=$(F);return O(K,te)}),G=z.map(F=>{const W=(Array.isArray(F.models)?F.models:[]).filter(te=>{const K=$(te);return O(K,F.name||F.id||"")});return{...F,models:W}}).filter(F=>F.models.length>0),le=Q.length>0||ne.length>0||G.length>0,oe=()=>b?s.jsx($r,{open:k,onClose:B,title:l("settings.agents.modelSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[y.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:l("settings.agents.modelSelector.section.favorites")}),s.jsx("div",{className:"border-t border-border/20",children:y.map(({model:F,providerID:U,modelID:W})=>{const te=U===t&&W===e;return s.jsxs("div",{className:ce("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",te?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{X(U,W),B()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vn,{providerId:U,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(F)})]})}),s.jsx("button",{onClick:K=>{K.preventDefault(),K.stopPropagation(),x(U,W)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-primary hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":l("settings.agents.modelSelector.actions.unfavorite"),children:s.jsx(P,{name:"star-fill",className:"h-4 w-4"})})]},`fav-mobile-${U}-${W}`)})})]}),g.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:l("settings.agents.modelSelector.section.recents")}),s.jsx("div",{className:"border-t border-border/20",children:g.map(({model:F,providerID:U,modelID:W})=>{const te=U===t&&W===e;return s.jsxs("div",{className:ce("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",te?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{X(U,W),B()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vn,{providerId:U,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(F)})]})}),s.jsx("button",{onClick:K=>{K.preventDefault(),K.stopPropagation(),x(U,W)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-muted-foreground/50 hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":l("settings.agents.modelSelector.actions.favorite"),children:s.jsx(P,{name:"star",className:"h-4 w-4"})})]},`recent-mobile-${U}-${W}`)})})]}),z.map(F=>{const U=Array.isArray(F.models)?F.models:[];if(U.length===0)return null;const W=F.id===t,te=j.has(F.id);return s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)]",children:[s.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-1.5 px-2 py-1.5 text-left",onClick:()=>V(F.id),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vn,{providerId:F.id,className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:F.name}),W&&s.jsx("span",{className:"typography-micro text-primary/80",children:l("settings.agents.modelSelector.badge.current")})]}),te?s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"}):s.jsx(P,{name:"arrow-right-s",className:"h-3 w-3 text-muted-foreground"})]}),te&&s.jsx("div",{className:"border-t border-border/20",children:U.map(K=>{const ae=F.id===t&&K.id===e;return s.jsxs("div",{className:ce("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",ae?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{X(F.id,K.id),B()},children:s.jsx("span",{className:"font-medium truncate",children:$(K)})}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx("button",{onClick:ve=>{ve.preventDefault(),ve.stopPropagation(),x(F.id,K.id)},className:ce("flex h-8 w-8 items-center justify-center active:scale-95 touch-manipulation hover:text-primary/80",f(F.id,K.id)?"text-primary":"text-muted-foreground/50"),"aria-label":f(F.id,K.id)?l("settings.agents.modelSelector.actions.unfavorite"):l("settings.agents.modelSelector.actions.favorite"),children:f(F.id,K.id)?s.jsx(P,{name:"star-fill",className:"h-4 w-4"}):s.jsx(P,{name:"star",className:"h-4 w-4"})}),ae&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]})]},K.id)})})]},F.id)}),s.jsx("button",{type:"button",className:"flex w-full items-center justify-between rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",onClick:()=>{X("",""),B()},children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:a||l("settings.agents.modelSelector.noModelOptional")})})]})}):null;return s.jsxs(s.Fragment,{children:[b?s.jsxs("button",{type:"button",onClick:c?()=>I(!0):void 0,disabled:!c,className:ce("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",r),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[c?t?s.jsx(vn,{providerId:t,className:"h-3.5 w-3.5"}):s.jsx(P,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),c&&s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t&&e?`${t}/${e}`:a||l("settings.agents.modelSelector.selectPlaceholder")})]}),s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):s.jsxs(Fs,{open:c&&D,onOpenChange:c?E:void 0,children:[s.jsx(Es,{asChild:!0,children:s.jsxs("div",{className:ce("border-input data-[placeholder]:text-muted-foreground flex items-center justify-between gap-2 rounded-lg border bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover data-[popup-open]:bg-interactive-active h-6 w-fit",r),children:[c?s.jsxs(s.Fragment,{children:[t?s.jsxs(s.Fragment,{children:[s.jsx(vn,{providerId:t,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx(P,{name:"pencil-ai",className:"h-3 w-3 text-primary/60 hidden"})]}):s.jsx(P,{name:"pencil-ai",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-foreground",children:t&&e?`${t}/${e}`:a||l("settings.agents.modelSelector.notSelected")})]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsx(Rs,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:(()=>{const F=[];Q.forEach(({model:K,providerID:ae,modelID:ve})=>{F.push({model:K,providerID:ae,modelID:ve,section:"fav"})}),ne.forEach(({model:K,providerID:ae,modelID:ve})=>{F.push({model:K,providerID:ae,modelID:ve,section:"recent"})}),G.forEach(K=>{K.models.forEach(ae=>{F.push({model:ae,providerID:K.id,modelID:ae.id,section:"provider"})})});const U=F.length,W=K=>{if(K.stopPropagation(),K.key==="ArrowDown"){K.preventDefault();const ae=(S+1)%Math.max(1,U);M(ae),setTimeout(()=>{A.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(K.key==="ArrowUp"){K.preventDefault();const ae=(S-1+Math.max(1,U))%Math.max(1,U);M(ae),setTimeout(()=>{A.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(K.key==="Enter"){K.preventDefault();const ae=F[S];ae&&X(ae.providerID,ae.modelID)}else K.key==="Escape"&&(K.preventDefault(),E(!1))};let te=0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(P,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{type:"text",placeholder:l("settings.agents.modelSelector.searchPlaceholder"),value:T,onChange:K=>C(K.target.value),onKeyDown:W,className:"pl-8 h-8 typography-meta",autoFocus:!0})]})}),s.jsx(Cs,{outerClassName:"max-h-[min(400px,calc(100dvh-12rem))] flex-1",children:s.jsxs("div",{className:"p-1",children:[s.jsxs($t,{className:ce("flex items-center gap-2"),onSelect:()=>X("",""),children:[s.jsx(P,{name:"close",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-muted-foreground",children:a||l("settings.agents.modelSelector.notSelected")}),!t&&!e&&s.jsx(P,{name:"check",className:"h-4 w-4 text-primary ml-auto"})]}),s.jsx(Cn,{}),!le&&T&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("settings.agents.modelSelector.state.noModelsFound")}),Q.length>0&&s.jsxs("div",{children:[s.jsxs(Ka,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(P,{name:"star-fill",className:"h-4 w-4 text-primary"}),l("settings.agents.modelSelector.section.favorites")]}),Q.map(({model:K,providerID:ae,modelID:ve})=>{const re=te++;return J(K,ae,ve,"fav",re,S===re)})]}),ne.length>0&&s.jsxs("div",{children:[Q.length>0&&s.jsx(Cn,{}),s.jsxs(Ka,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(P,{name:"time",className:"h-4 w-4"}),l("settings.agents.modelSelector.section.recent")]}),ne.map(({model:K,providerID:ae,modelID:ve})=>{const re=te++;return J(K,ae,ve,"recent",re,S===re)})]}),(Q.length>0||ne.length>0)&&G.length>0&&s.jsx(Cn,{}),G.map((K,ae)=>s.jsxs("div",{children:[ae>0&&s.jsx(Cn,{}),s.jsxs(Ka,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(vn,{providerId:K.id,className:"h-4 w-4 flex-shrink-0"}),K.name]}),K.models.map(ve=>{const re=te++;return J(ve,K.id,ve.id,"provider",re,S===re)})]},K.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:l("settings.agents.modelSelector.keyboardHints")})]})})()})]}),oe()]})},Ul=t=>{const e=at.c(34),{agentName:n,onChange:r,className:i,filter:a}=t,{t:l}=ut(),{isReady:c,isUnavailable:d}=Gf(),p=xt(i1),m=fa(a1),u=fa(o1),h=xt(l1);let x;e:{if(Array.isArray(p)&&p.length>0){x=p;break e}let B;e[0]!==m?(B=Array.isArray(m)?m:[],e[0]=m,e[1]=B):B=e[1],x=B}const f=x;let v;if(e[2]!==a||e[3]!==f){const B=tb(f);v=a?B.filter(a):B,e[2]=a,e[3]=f,e[4]=v}else v=e[4];const y=v,g=Ie(c1),{isMobile:w}=rn(),b=g||w,[k,I]=o.useState(!1);let j,N;e[5]!==u||e[6]!==h||e[7]!==f.length?(j=()=>{f.length>0||(h(),u())},N=[f.length,h,u],e[5]=u,e[6]=h,e[7]=f.length,e[8]=j,e[9]=N):(j=e[8],N=e[9]),o.useEffect(j,N);let D;e[10]===Symbol.for("react.memo_cache_sentinel")?(D=()=>I(!1),e[10]=D):D=e[10];const E=D;let T;e[11]!==r?(T=B=>{r(B)},e[11]=r,e[12]=T):T=e[12];const C=T;let S;e[13]!==n||e[14]!==y||e[15]!==C||e[16]!==b||e[17]!==k||e[18]!==l?(S=()=>b?s.jsx($r,{open:k,onClose:E,title:l("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:ce("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",n?"text-foreground":"bg-primary/10 text-primary"),onClick:()=>{C(""),E()},children:[s.jsx("span",{className:ce("typography-meta",n?"text-muted-foreground":"font-medium"),children:l("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),y.map(B=>{const V=B.name===n;return s.jsxs("button",{type:"button",className:ce("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",V?"bg-primary/10 text-primary":"text-foreground"),onClick:()=>{C(B.name),E()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:B.name}),B.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:B.description})]}),V&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},B.name)})]})}):null,e[13]=n,e[14]=y,e[15]=C,e[16]=b,e[17]=k,e[18]=l,e[19]=S):S=e[19];const M=S;let A;e[20]!==n||e[21]!==y||e[22]!==i||e[23]!==C||e[24]!==b||e[25]!==c||e[26]!==d||e[27]!==l?(A=b?s.jsxs("button",{type:"button",onClick:c?()=>I(!0):void 0,disabled:!c,className:ce("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",i),children:[s.jsx("div",{className:"flex items-center gap-2",children:c?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"robot-2",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:n||l("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]})}),s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsxs("div",{className:ce("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 cursor-pointer hover:bg-interactive-hover/30 h-6 w-fit",i),children:[s.jsx(P,{name:"robot-2",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap",children:n||l("settings.commands.agentSelector.notSelected")}),s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(Rs,{className:"max-w-[300px]",children:[s.jsx($t,{className:"typography-meta",onSelect:()=>C(""),children:s.jsx("span",{className:"text-muted-foreground",children:l("settings.commands.agentSelector.notSelected")})}),y.map(B=>s.jsx($t,{className:"typography-meta",onSelect:()=>C(B.name),children:s.jsx("span",{className:"font-medium",children:B.name})},B.name))]})]}):s.jsxs("div",{className:ce("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60",i),children:[s.jsx(P,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=y,e[22]=i,e[23]=C,e[24]=b,e[25]=c,e[26]=d,e[27]=l,e[28]=A):A=e[28];let R;e[29]!==M?(R=M(),e[29]=M,e[30]=R):R=e[30];let z;return e[31]!==A||e[32]!==R?(z=s.jsxs(s.Fragment,{children:[A,R]}),e[31]=A,e[32]=R,e[33]=z):z=e[33],z};function i1(t){return t.agents}function a1(t){return t.agents}function o1(t){return t.loadAgents}function l1(t){return t.loadAgents}function c1(t){return t.isMobile}const fm=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),d1=t=>{const e=at.c(38),{value:n,options:r,disabled:i,onChange:a}=t,{t:l}=ut();let c;e[0]!==l||e[1]!==n?(c=n||l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=l,e[1]=n,e[2]=c):c=e[2];const d=c,p=i?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==p?(m=ce("flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2",p),e[3]=p,e[4]=m):m=e[4];let u;e[5]!==d?(u=s.jsx("span",{className:"typography-micro whitespace-nowrap font-medium capitalize",children:d}),e[5]=d,e[6]=u):u=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=h):h=e[7];let x;e[8]!==m||e[9]!==u?(x=s.jsxs("div",{className:m,children:[u,h]}),e[8]=m,e[9]=u,e[10]=x):x=e[10];const f=x;if(i)return f;let v;e[11]!==f?(v=s.jsx(Es,{asChild:!0,children:f}),e[11]=f,e[12]=v):v=e[12];let y;e[13]!==a?(y=()=>a(""),e[13]=a,e[14]=y):y=e[14];const g=!n&&"text-primary";let w;e[15]!==g?(w=ce("font-medium",g),e[15]=g,e[16]=w):w=e[16];let b;e[17]!==l?(b=l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=l,e[18]=b):b=e[18];let k;e[19]!==w||e[20]!==b?(k=s.jsx("span",{className:w,children:b}),e[19]=w,e[20]=b,e[21]=k):k=e[21];let I;e[22]!==k||e[23]!==y?(I=s.jsx($t,{className:"typography-meta",onSelect:y,children:k}),e[22]=k,e[23]=y,e[24]=I):I=e[24];let j;if(e[25]!==a||e[26]!==r||e[27]!==n){let E;e[29]!==a||e[30]!==n?(E=T=>s.jsx($t,{className:"typography-meta",onSelect:()=>a(T),children:s.jsx("span",{className:ce("font-medium capitalize",n===T&&"text-primary"),children:T})},T),e[29]=a,e[30]=n,e[31]=E):E=e[31],j=r.map(E),e[25]=a,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let N;e[32]!==I||e[33]!==j?(N=s.jsxs(Rs,{align:"start",className:"max-w-[220px]",children:[I,j]}),e[32]=I,e[33]=j,e[34]=N):N=e[34];let D;return e[35]!==N||e[36]!==v?(D=s.jsxs(Fs,{children:[v,N]}),e[35]=N,e[36]=v,e[37]=D):D=e[37],D};function Mh(t){const e=at.c(99),{t:n}=ut(),{open:r,onOpenChange:i,target:a,projectDirectory:l,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=xt(v1),u=xt(y1),h=fa(b1),x=xt(x1),f=xt(g1),v=xt(h1),y=xt(f1),g=xt(p1);let w;e[0]!==g||e[1]!==v||e[2]!==f||e[3]!==y?(w=()=>fm({providerID:f,modelID:v,variant:y,agent:g}),e[0]=g,e[1]=v,e[2]=f,e[3]=y,e[4]=w):w=e[4];const[b,k]=o.useState(w);let I,j;e[5]!==h||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==l?(I=()=>{r&&(m({directory:l}),u({directory:l}),h())},j=[r,m,u,h,l],e[5]=h,e[6]=u,e[7]=m,e[8]=r,e[9]=l,e[10]=I,e[11]=j):(I=e[10],j=e[11]),o.useEffect(I,j);let N,D;e[12]!==g||e[13]!==v||e[14]!==f||e[15]!==y||e[16]!==r?(N=()=>{r&&k(fm({providerID:f,modelID:v,variant:y,agent:g}))},D=[r,f,v,y,g],e[12]=g,e[13]=v,e[14]=f,e[15]=y,e[16]=r,e[17]=N,e[18]=D):(N=e[17],D=e[18]),o.useEffect(N,D);let E,T;e[19]!==b.modelID||e[20]!==b.providerID||e[21]!==r||e[22]!==x?(E=()=>{if(!r||x.length===0)return;const we=x.find(Me=>Me.id===b.providerID)??x[0],ke=Array.isArray(we?.models)?we.models:[],xe=ke.some(Me=>Me.id===b.modelID),me=ke[0]?.id??"";we?.id===b.providerID&&xe||k(Me=>({...Me,providerID:we?.id??"",modelID:xe?Me.modelID:me,variant:""}))},T=[r,x,b.providerID,b.modelID],e[19]=b.modelID,e[20]=b.providerID,e[21]=r,e[22]=x,e[23]=E,e[24]=T):(E=e[23],T=e[24]),o.useEffect(E,T);const C=m1;let S;if(e[25]!==b.modelID||e[26]!==b.providerID||e[27]!==x){let we;e[29]!==b.providerID?(we=xe=>xe.id===b.providerID,e[29]=b.providerID,e[30]=we):we=e[30],S=x.find(we)?.models?.find(xe=>xe.id===b.modelID),e[25]=b.modelID,e[26]=b.providerID,e[27]=x,e[28]=S}else S=e[28];const M=S;let A;e[31]!==M?(A=M?.variants?Object.keys(M.variants):[],e[31]=M,e[32]=A):A=e[32];const R=A,z=R.length>0;let B,V;e[33]!==b.variant||e[34]!==z?(B=()=>{z||!b.variant||k(u1)},V=[z,b.variant],e[33]=b.variant,e[34]=z,e[35]=B,e[36]=V):(B=e[35],V=e[36]),o.useEffect(B,V);let $;e[37]!==b.modelID||e[38]!==b.providerID?($=b.providerID.trim().length>0&&b.modelID.trim().length>0,e[37]=b.modelID,e[38]=b.providerID,e[39]=$):$=e[39];const _=$;let X;e[40]!==_||e[41]!==b||e[42]!==d||e[43]!==p?(X=()=>{!_||p||d(b)},e[40]=_,e[41]=b,e[42]=d,e[43]=p,e[44]=X):X=e[44];const O=X;let J,Q;e[45]!==O||e[46]!==r?(J=()=>{if(!r)return;const we=ke=>{(ke.metaKey||ke.ctrlKey)&&ke.key==="Enter"&&(ke.preventDefault(),O())};return window.addEventListener("keydown",we),()=>window.removeEventListener("keydown",we)},Q=[r,O],e[45]=O,e[46]=r,e[47]=J,e[48]=Q):(J=e[47],Q=e[48]),o.useEffect(J,Q);let ne;e[49]!==n||e[50]!==a?(ne=n(a==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=a,e[51]=ne):ne=e[51];const G=ne;let le;e[52]!==i||e[53]!==p?(le=we=>{p||i(we)},e[52]=i,e[53]=p,e[54]=le):le=e[54];let oe;e[55]!==G?(oe=s.jsx(bs,{children:s.jsx(gs,{children:G})}),e[55]=G,e[56]=oe):oe=e[56];let F;e[57]===Symbol.for("react.memo_cache_sentinel")?(F=(we,ke)=>{k(xe=>({...xe,providerID:we,modelID:ke,variant:""}))},e[57]=F):F=e[57];let U;e[58]!==b.modelID||e[59]!==b.providerID?(U=s.jsx(yo,{providerId:b.providerID,modelId:b.modelID,onChange:F}),e[58]=b.modelID,e[59]=b.providerID,e[60]=U):U=e[60];const W=!z;let te;e[61]===Symbol.for("react.memo_cache_sentinel")?(te=we=>k(ke=>({...ke,variant:we})),e[61]=te):te=e[61];let K;e[62]!==b.variant||e[63]!==W||e[64]!==R?(K=s.jsx(d1,{value:b.variant,options:R,disabled:W,onChange:te}),e[62]=b.variant,e[63]=W,e[64]=R,e[65]=K):K=e[65];let ae;e[66]===Symbol.for("react.memo_cache_sentinel")?(ae=we=>k(ke=>({...ke,agent:we})),e[66]=ae):ae=e[66];let ve;e[67]!==b.agent?(ve=s.jsx(Ul,{agentName:b.agent,filter:C,onChange:ae}),e[67]=b.agent,e[68]=ve):ve=e[68];let re;e[69]!==U||e[70]!==K||e[71]!==ve?(re=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[U,K,ve]}),e[69]=U,e[70]=K,e[71]=ve,e[72]=re):re=e[72];let be;e[73]!==i?(be=()=>i(!1),e[73]=i,e[74]=be):be=e[74];let pe;e[75]!==n?(pe=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=pe):pe=e[76];let ye;e[77]!==p||e[78]!==be||e[79]!==pe?(ye=s.jsx(ge,{variant:"ghost",size:"sm",onClick:be,disabled:p,children:pe}),e[77]=p,e[78]=be,e[79]=pe,e[80]=ye):ye=e[80];const ie=!_||p;let ue;e[81]!==p||e[82]!==n?(ue=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=ue):ue=e[83];let se;e[84]!==O||e[85]!==ie||e[86]!==ue?(se=s.jsx(ge,{size:"sm",onClick:O,disabled:ie,children:ue}),e[84]=O,e[85]=ie,e[86]=ue,e[87]=se):se=e[87];let Ne;e[88]!==ye||e[89]!==se?(Ne=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[ye,se]}),e[88]=ye,e[89]=se,e[90]=Ne):Ne=e[90];let Ce;e[91]!==oe||e[92]!==re||e[93]!==Ne?(Ce=s.jsxs(fs,{className:"max-w-lg",children:[oe,re,Ne]}),e[91]=oe,e[92]=re,e[93]=Ne,e[94]=Ce):Ce=e[94];let je;return e[95]!==r||e[96]!==le||e[97]!==Ce?(je=s.jsx(hs,{open:r,onOpenChange:le,children:Ce}),e[95]=r,e[96]=le,e[97]=Ce,e[98]=je):je=e[98],je}function u1(t){return{...t,variant:""}}function m1(t){return Yf(t.mode)}function p1(t){return t.currentAgentName||""}function f1(t){return t.currentVariant||""}function h1(t){return t.currentModelId}function g1(t){return t.currentProviderId}function x1(t){return t.providers}function b1(t){return t.loadAgents}function y1(t){return t.loadAgents}function v1(t){return t.loadProviders}const id=5,Eh=15,el=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},w1=(t,e)=>{const n=el(e);return Math.max(n*id,Math.min(n*Eh,n*t))},j1=async(t,e)=>{const n=await ib(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},N1=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,S1=t=>{const e=at.c(20),{id:n,children:r}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:a,listeners:l,setNodeRef:c,setActivatorNodeRef:d,transform:p,transition:m,isDragging:u}=Dl(i);let h;e[2]!==p?(h=Tl.Transform.toString(p),e[2]=p,e[3]=h):h=e[3];let x;e[4]!==h||e[5]!==m?(x={transform:h,transition:m},e[4]=h,e[5]=m,e[6]=x):x=e[6];const f=u&&"opacity-60";let v;e[7]!==f?(v=ce(f),e[7]=f,e[8]=v):v=e[8];let y;e[9]!==a||e[10]!==r||e[11]!==u||e[12]!==l||e[13]!==d?(y=r({attributes:a,listeners:l,setActivatorNodeRef:d,isDragging:u}),e[9]=a,e[10]=r,e[11]=u,e[12]=l,e[13]=d,e[14]=y):y=e[14];let g;return e[15]!==c||e[16]!==x||e[17]!==v||e[18]!==y?(g=s.jsx("li",{ref:c,style:x,className:v,children:y}),e[15]=c,e[16]=x,e[17]=v,e[18]=y,e[19]=g):g=e[19],g},k1=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:i})=>{const{t:a}=ut(),[l,c]=o.useState(!1),[d,p]=o.useState(""),[m,u]=o.useState([]),[h,x]=o.useState(""),[f,v]=o.useState(null),[y,g]=o.useState(()=>new Set),[w,b]=o.useState([]),[k,I]=o.useState(null),[j,N]=o.useState(!1),[D,E]=o.useState(0),T=o.useRef(!1),C=o.useRef(""),S=Ie(L=>L.todoPanelHeight),M=Ie(L=>L.setTodoPanelHeight),A=Ie(L=>L.notesPanelHeight),R=Ie(L=>L.setNotesPanelHeight),[z,B]=o.useState(!1),V=o.useRef(0),$=o.useRef(S),_=Ot(L=>L.currentSessionId),X=Ot(L=>L.createSession),O=Ot(L=>L.initializeNewSession),J=Ot(L=>L.sendMessage),Q=Ot(L=>L.setCurrentSession),ne=zi(L=>L.setPendingInputText),G=$s(L=>L.currentDirectory),le=Ie(L=>L.openContextPanelTab),oe=Ie(L=>L.setActiveMainTab),F=Ie(L=>L.setSessionSwitcherOpen),U=Ie(L=>L.padding),W=o.useCallback(async(L,Z)=>{if(!t)return!1;const Y=await sb(t,{notes:L,todos:Z});return Y||H.error(a("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),Y},[t,a]);o.useEffect(()=>{if(!t){p(""),u([]),b([]),x(""),g(new Set);return}let L=!1;return c(!0),(async()=>{try{const Z=await nb(t),Y=await Promise.all(Z.plans.map(Ee=>j1(Ee,a("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(L)return;p(Z.notes),u(Z.todos),b(Y),C.current=Z.notes,T.current=!0,x(""),g(new Set)}catch{L||(H.error(a("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),b([]),C.current="",T.current=!0)}finally{L||c(!1)}})(),()=>{L=!0}},[D,t,a]),o.useEffect(()=>{if(!t)return;const L=Z=>{const Y=Z.detail;Y?.projectId&&Y.projectId!==t.id||E(Ee=>Ee+1)};return window.addEventListener("vinci:project-plan-saved",L),window.addEventListener("vinci:project-notes-updated",L),()=>{window.removeEventListener("vinci:project-plan-saved",L),window.removeEventListener("vinci:project-notes-updated",L)}},[t]),o.useEffect(()=>{if(m.length<7)return;const L=w1(m.length,U),Z=el(U)*id;(S<Z||S>L)&&M(L)},[m.length,U,S,M]),o.useEffect(()=>{if(!z)return;const L=Y=>{const Ee=Y.clientY-V.current,Ae=Math.min(el(U)*Eh,Math.max(el(U)*id,$.current+Ee));M(Ae)},Z=()=>{B(!1)};return window.addEventListener("pointermove",L),window.addEventListener("pointerup",Z,{once:!0}),window.addEventListener("pointercancel",Z,{once:!0}),()=>{window.removeEventListener("pointermove",L),window.removeEventListener("pointerup",Z),window.removeEventListener("pointercancel",Z)}},[z,U,M]);const te=o.useCallback(L=>{B(!0),V.current=L.clientY,$.current=S,L.preventDefault()},[S]),K=o.useCallback(()=>{C.current=d,W(d,m)},[d,W,m]);o.useEffect(()=>{if(!t||!T.current||d===C.current)return;const L=window.setTimeout(()=>{C.current=d,W(d,m)},400);return()=>{window.clearTimeout(L)}},[d,W,t,m]);const ae=o.useCallback(()=>{const L=h.trim();if(!L)return;const Z=[...m,{id:N1(),text:L.slice(0,Co),completed:!1,createdAt:Date.now()}];u(Z),x(""),W(d,Z)},[h,d,W,m]),ve=o.useCallback(L=>{g(Z=>{const Y=new Set(Z);return Y.has(L)?Y.delete(L):Y.add(L),Y})},[]),re=o.useCallback((L,Z)=>{const Y=m.map(Ee=>Ee.id===L?{...Ee,completed:Z}:Ee);u(Y),W(d,Y)},[d,W,m]),be=o.useCallback(L=>{const Z=m.filter(Y=>Y.id!==L);u(Z),W(d,Z)},[d,W,m]),pe=o.useCallback(()=>{const L=m.filter(Z=>!Z.completed);L.length!==m.length&&(u(L),W(d,L))},[d,W,m]),ye=o.useCallback(L=>{const{active:Z,over:Y}=L;if(!Y||Z.id===Y.id)return;const Ee=m.findIndex(de=>de.id===Z.id),Ae=m.findIndex(de=>de.id===Y.id);if(Ee===-1||Ae===-1)return;const Je=Ef(m,Ee,Ae);u(Je),W(d,Je)},[d,W,m]),ie=Ja(oa(Xa,{activationConstraint:{distance:8}})),ue=h.slice(0,Co),se=m.reduce((L,Z)=>L+(Z.completed?1:0),0),Ne=o.useCallback(()=>{oe("chat"),F(!1)},[oe,F]),Ce=o.useCallback((L,Z)=>{!t||f||I({kind:"session",todoId:L,todoText:Z})},[t,f]),je=o.useCallback(L=>{if(!_){H.error(a("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Ne();const Z=`\`\`\`md
|
|
4
|
+
${L}
|
|
5
|
+
\`\`\``;ne(Z,"append"),H.success(a("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[_,r,Ne,ne,a]),we=o.useCallback((L,Z)=>{if(!(!t||f)){if(!n){H.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}I({kind:"worktree",todoId:L,todoText:Z})}},[n,t,f,a]),ke=o.useCallback(async L=>{if(!t||!k)return;const Z=await wn("plan.todo.visible",{todo_text:k.todoText}),Ee=[{synthetic:!0,text:await wn("plan.todo.instructions",{todo_text:k.todoText})}];N(!0),v(k.todoId);try{Ne();let Ae=null,Je=t.path;if(k.kind==="worktree"){if(!n){H.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const ze=await Qf(t.path,Jf());if(!ze?.id)return;Ae=ze.id,Je=null}else{const ze=await X(void 0,t.path,null);if(!ze?.id){H.error(a("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}Ae=ze.id,Je=ze.directory??t.path,O(ze.id,xt.getState().agents??[])}if(!Ae)return;const de=Fl.getState();de.saveSessionModelSelection(Ae,L.providerID,L.modelID),L.agent.trim()&&(de.saveSessionAgentSelection(Ae,L.agent),de.saveAgentModelForSession(Ae,L.agent,L.providerID,L.modelID),de.saveAgentModelVariantForSession(Ae,L.agent,L.providerID,L.modelID,L.variant||void 0)),Q(Ae,Je),await J(Z,L.providerID,L.modelID,L.agent.trim()||void 0,void 0,void 0,Ee,L.variant||void 0),H.success(k.kind==="worktree"?a("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):a("rightSidebar.contextNotesTodo.toast.sentToNewSession")),I(null),r?.()}catch(Ae){const Je=Ae instanceof Error?Ae.message:void 0;H.error(a("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Je?{description:Je}:void 0)}finally{N(!1),v(null)}},[n,X,O,r,k,t,Ne,J,Q,a]),xe=o.useRef(null),[me,Me]=o.useState(!1),[Ue,q]=o.useState(null),Se=o.useCallback(async L=>{if(!(!t||Ue)){q(L);try{if(!await rb(t,L)){H.error(a("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}b(Y=>Y.filter(Ee=>Ee.id!==L)),window.dispatchEvent(new CustomEvent("vinci:project-plan-saved",{detail:{projectId:t.id}}))}finally{q(null)}}},[Ue,t,a]),$e=o.useCallback(async()=>{if(!t||me)return;const L=await Xf({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(L.success&&L.path){Me(!0);try{const Z=new URLSearchParams({path:L.path,allowOutsideWorkspace:"true"}),Y=await fetch(`/api/fs/read?${Z.toString()}`,{cache:"no-store"});if(!Y.ok){H.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const Ee=await Y.text();if(!Ee.trim()){H.error(a("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Ae=L.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await ju(t,Ee,Ae)){H.error(a("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("vinci:project-plan-saved",{detail:{projectId:t.id}})),H.success(a("rightSidebar.contextNotesTodo.toast.planImported"))}catch(Z){const Y=Z instanceof Error?Z.message:void 0;H.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Y?{description:Y}:void 0)}finally{Me(!1)}}else L.error==="Native file picker not available"&&xe.current?.click()},[me,t,a]),Pe=o.useCallback(async L=>{if(!(!t||!L)){Me(!0);try{const Z=await L.text();if(!Z.trim()){H.error(a("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Y=L.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await ju(t,Z,Y)){H.error(a("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("vinci:project-plan-saved",{detail:{projectId:t.id}})),H.success(a("rightSidebar.contextNotesTodo.toast.planImported"))}catch(Z){const Y=Z instanceof Error?Z.message:void 0;H.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Y?{description:Y}:void 0)}finally{Me(!1)}}},[t,a]),fe=o.useCallback(L=>{const Z=t?.path?.trim(),Y=G?.trim()||Z;Y&&le(Y,{mode:"plan",targetPath:L.path,dedupeKey:L.path,label:L.title})},[G,le,t]);return t?s.jsxs("div",{className:ce("w-full min-w-0 space-y-3 p-3",i),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:a("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d.length,"/",Nu]})]}),s.jsx(hn,{value:d,onChange:L=>p(L.target.value.slice(0,Nu)),onBlur:K,placeholder:a("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:A,onResizeHeightChange:R,useScrollShadow:!0,scrollShadowSize:56,disabled:l})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:a("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?a("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):a("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:pe,disabled:l||se===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:a("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[ue.length,"/",Co]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{value:ue,onChange:L=>x(L.target.value.slice(0,Co)),onKeyDown:L=>{L.key==="Enter"&&(L.preventDefault(),ae())},placeholder:a("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:l,className:"h-8"}),s.jsx("button",{type:"button",onClick:ae,disabled:l||ue.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":a("rightSidebar.contextNotesTodo.todo.addAria"),title:a("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(P,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:ce("overflow-y-auto rounded-lg border border-border/60 bg-background/40",z&&"transition-none"),style:m.length<7?void 0:{height:`${S}px`,maxHeight:`${S}px`},children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(Za,{sensors:ie,collisionDetection:eo,onDragEnd:ye,children:s.jsx(cl,{items:m.map(L=>L.id),strategy:Hc,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(L=>{const Z=y.has(L.id);return s.jsx(S1,{id:L.id,children:Y=>s.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("button",{type:"button",ref:Y.setActivatorNodeRef,...Y.attributes,...Y.listeners,onClick:Ee=>{Ee.preventDefault(),Ee.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":a("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:L.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:L.text}),children:s.jsx(P,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(ds,{checked:L.completed,onChange:Ee=>re(L.id,Ee),ariaLabel:a("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:L.text})})}),s.jsx("button",{type:"button",onClick:()=>ve(L.id),className:ce("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-6 text-foreground",Z?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",L.completed&&"text-muted-foreground line-through"),title:Z?void 0:L.text,"aria-label":Z?a("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:L.text}):a("rightSidebar.contextNotesTodo.todo.actions.expand",{text:L.text}),children:L.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>be(L.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:L.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:L.text}),children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",disabled:f===L.id,className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":a("rightSidebar.contextNotesTodo.todo.actions.send",{text:L.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.send",{text:L.text}),children:s.jsx(P,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(Rs,{align:"end",className:"w-56",children:[s.jsx($t,{onClick:()=>je(L.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx($t,{onClick:()=>Ce(L.id,L.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx($t,{onClick:()=>{we(L.id,L.text)},disabled:!n,children:a("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},L.id)})})})})}),m.length>=7&&s.jsx("div",{className:ce("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",z&&"bg-[var(--interactive-border)]"),onPointerDown:te,role:"separator","aria-orientation":"horizontal","aria-label":a("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:a("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:w.length===1?a("rightSidebar.contextNotesTodo.plans.filesSingle",{count:w.length}):a("rightSidebar.contextNotesTodo.plans.filesPlural",{count:w.length})})]}),s.jsx("input",{ref:xe,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:L=>{const Z=L.target.files?.[0]??null;Pe(Z),L.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:$e,disabled:!t||me,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":a("rightSidebar.contextNotesTodo.plans.importFromFile"),title:a("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(P,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:w.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:w.map(L=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>fe(L),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:L.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(L.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Se(L.id)},disabled:Ue===L.id,className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",title:a("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":a("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:L.title}),children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},L.id))})})]}),s.jsx(Mh,{open:k!==null,onOpenChange:L=>{!L&&!j&&I(null)},target:k?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:ke})]}):s.jsx("div",{className:ce("w-full min-w-0 p-3",i),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.empty.selectProject")})})},Rh=12,C1=[{id:"left",x:22,y:58,delay:0,radius:120,colorVar:"--status-success"},{id:"center",x:50,y:42,delay:120,radius:150,colorVar:"--primary-base"},{id:"right",x:78,y:55,delay:200,radius:130,colorVar:"--status-info"}],P1=t=>{const e=at.c(18),{isActive:n,burstKey:r,className:i,durationMs:a,bursts:l,onComplete:c}=t,d=r===void 0?0:r,p=a===void 0?900:a,m=l===void 0?C1:l,u=Be.useRef(!1);let h,x;e[0]!==n||e[1]!==c?(h=()=>{!n&&u.current&&c?.(),n&&(u.current=!0)},x=[n,c],e[0]=n,e[1]=c,e[2]=h,e[3]=x):(h=e[2],x=e[3]),Be.useEffect(h,x);let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=Array.from({length:Rh},I1),e[4]=f):f=e[4];const v=f;if(!n)return null;let y;e[5]!==i?(y=ce("fireworks-overlay pointer-events-none",i),e[5]=i,e[6]=y):y=e[6];let g;if(e[7]!==d||e[8]!==m||e[9]!==p){let b;e[11]!==d||e[12]!==p?(b=k=>{const I={"--burst-delay":`${k.delay}ms`,"--burst-x":`${k.x}%`,"--burst-y":`${k.y}%`,"--firework-color":`var(${k.colorVar})`,"--firework-duration":`${p}ms`};return s.jsx("div",{className:"firework-burst",style:I,children:v.map((j,N)=>{const D=j.x*k.radius,E=j.y*k.radius,T={"--translate-x":`${D}px`,"--translate-y":`${E}px`,"--particle-delay":`${j.delay}ms`,color:`var(${k.colorVar})`};return s.jsx("span",{className:"firework-particle",style:T},`${k.id}-${N}-${d}`)})},`${k.id}-${d}`)},e[11]=d,e[12]=p,e[13]=b):b=e[13],g=m.map(b),e[7]=d,e[8]=m,e[9]=p,e[10]=g}else g=e[10];let w;return e[14]!==d||e[15]!==y||e[16]!==g?(w=s.jsx("div",{className:y,"aria-hidden":"true","data-burst-key":d,children:g}),e[14]=d,e[15]=y,e[16]=g,e[17]=w):w=e[17],w};function I1(t,e){const n=Math.PI*2*e/Rh;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const A1=t=>{const e=at.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,i=r===void 0?3400:r;let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={isActive:!1,cycle:0},e[2]=a):a=e[2];const[l,c]=Be.useState(a),d=Be.useRef(null);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=p):p=e[3];const m=p;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),c(D1)},e[4]=u):u=e[4];const h=u;let x;e[5]!==i?(x=()=>{m(),c(T1),d.current=window.setTimeout(()=>{c(M1),d.current=null},i)},e[5]=i,e[6]=x):x=e[6];const f=x;let v,y;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>m(),y=[m],e[7]=v,e[8]=y):(v=e[7],y=e[8]),Be.useEffect(v,y);let g;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==f?(g={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:f,dismissFireworks:h},e[9]=l.cycle,e[10]=l.isActive,e[11]=f,e[12]=g):g=e[12],g};function D1(t){return t.isActive?{...t,isActive:!1}:t}function T1(t){return{isActive:!0,cycle:t.cycle+1}}function M1(t){return t.isActive?{...t,isActive:!1}:t}const Fh=o.createContext(void 0),E1=t=>{const e=at.c(10),{children:n}=t,{isActive:r,burstKey:i,triggerFireworks:a,dismissFireworks:l}=A1();let c;e[0]!==l||e[1]!==a?(c={triggerFireworks:a,dismissFireworks:l},e[0]=l,e[1]=a,e[2]=c):c=e[2];const d=c;let p;e[3]!==i||e[4]!==r?(p=s.jsx(P1,{isActive:r,burstKey:i}),e[3]=i,e[4]=r,e[5]=p):p=e[5];let m;return e[6]!==n||e[7]!==p||e[8]!==d?(m=s.jsxs(Fh.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},R1=()=>{const t=o.useContext(Fh);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Qn=gr()(Na(mo((t,e)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{t({selectedProfileId:n})},loadProfiles:async()=>{t({isLoading:!0});const n=e().profiles;try{const r=await ub();return t({profiles:r,isLoading:!1}),!0}catch(r){return console.error("Failed to load git identity profiles:",r),t({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=await db();if(n&&n.userName&&n.userEmail){const r={id:"global",name:"Global Identity",userName:n.userName,userEmail:n.userEmail,authType:n.sshCommand?"ssh":void 0,sshKey:n.sshCommand?n.sshCommand.replace("ssh -i ",""):null,color:"info",icon:"house"};t({globalIdentity:r})}else t({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),t({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=await cb();return t({discoveredCredentials:n}),!0}catch(n){return console.error("Failed to discover git credentials:",n),t({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=r=>{if(typeof r!="string")return null;const i=r.trim();return i.length>0?i:null};try{let r=null;if(r===null){const i=pr()?.settings;if(i)try{const l=(await i.load())?.settings||{};r=n(l.defaultGitIdentityId)}catch{}}if(r===null)try{const i=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(i.ok){const a=await i.json().catch(()=>null);r=n(a?.defaultGitIdentityId)}}catch{}return t({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",i=r.length>0?r:"";return await ks({defaultGitIdentityId:i}),t({defaultGitIdentityId:i.length>0?i:null}),!0}catch(r){return console.error("Failed to save default git identity setting:",r),!1}},createProfile:async n=>{try{const r={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};return await lb(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const i=e().profiles.find(l=>l.id===n);if(!i)throw new Error("Profile not found");const a={...i,...r};return await ob(n,a),await e().loadProfiles(),!0}catch(i){return console.error("Failed to update git identity profile:",i),!1}},deleteProfile:async n=>{try{return await ab(n),e().selectedProfileId===n&&t({selectedProfileId:null}),await e().loadProfiles(),!0}catch(r){return console.error("Failed to delete git identity profile:",r),!1}},getProfileById:n=>{const{profiles:r,globalIdentity:i}=e();return n==="global"?i||void 0:r.find(a=>a.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=e();return r.filter(i=>!n.some(a=>a.authType==="token"&&a.host===i.host))}}),{name:"git-identities-store",storage:Ml(()=>pi()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Qn);function _i(t){const e=at.c(12);let n,r,i;e[0]!==t?({className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i):(n=e[1],r=e[2],i=e[3]);let a;e[4]!==i?(a={color:"var(--surface-elevated-foreground)",...i},e[4]=i,e[5]=a):a=e[5];let l;e[6]!==n?(l=ce("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=l):l=e[7];let c;return e[8]!==r||e[9]!==a||e[10]!==l?(c=s.jsx(Hi,{"data-slot":"command",style:a,className:l,...r}),e[8]=r,e[9]=a,e[10]=l,e[11]=c):c=e[11],c}const xi=Be.forwardRef((t,e)=>{const n=at.c(10);let r,i;n[0]!==t?({className:r,...i}=t,n[0]=t,n[1]=r,n[2]=i):(r=n[1],i=n[2]);let a;n[3]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(P,{name:"search",className:"size-4 shrink-0 opacity-50"}),n[3]=a):a=n[3];let l;n[4]!==r?(l=ce("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=l):l=n[5];let c;return n[6]!==i||n[7]!==e||n[8]!==l?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[a,s.jsx(Hi.Input,{ref:e,"data-slot":"command-input",className:l,...i})]}),n[6]=i,n[7]=e,n[8]=l,n[9]=c):c=n[9],c});xi.displayName="CommandInput";function Ui(t){const e=at.c(14);let n,r,i,a,l;e[0]!==t?({className:r,children:n,scrollbarClassName:l,disableHorizontal:i,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a,e[5]=l):(n=e[1],r=e[2],i=e[3],a=e[4],l=e[5]);let c;e[6]!==r?(c=ce("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=c):c=e[7];const d=l??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",p=i??!0;let m;return e[8]!==n||e[9]!==a||e[10]!==c||e[11]!==d||e[12]!==p?(m=s.jsx(Cs,{as:Hi.List,"data-slot":"command-list",outerClassName:"max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0",className:c,scrollbarClassName:d,disableHorizontal:p,...a,children:n}),e[8]=n,e[9]=a,e[10]=c,e[11]=d,e[12]=p,e[13]=m):m=e[13],m}function Wi(t){const e=at.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Hi.Empty,{"data-slot":"command-empty",className:"py-6 text-center typography-ui-label",...n}),e[2]=n,e[3]=r):r=e[3],r}function zn(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=ce("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Hi.Group,{"data-slot":"command-group",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function Ti(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=ce("bg-border -mx-1 h-px",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Hi.Separator,{"data-slot":"command-separator",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function kn(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=ce("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Hi.Item,{"data-slot":"command-item",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function F1(t){const e=at.c(12);let n,r,i,a;if(e[0]!==t){const{className:c,...d}=t,p=O1,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(L1).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=ce("text-muted-foreground ml-auto flex items-center gap-1 typography-meta",c),e[5]=c,e[6]=r):r=e[6],i=d,a=u.length>0?u.map((h,x)=>s.jsxs(Be.Fragment,{children:[x>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),p(h)]},`${h}-${x}`)):d.children,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a}else n=e[1],r=e[2],i=e[3],a=e[4];let l;return e[7]!==n||e[8]!==r||e[9]!==i||e[10]!==a?(l=s.jsx("span",{"data-slot":n,className:r,...i,children:a}),e[7]=n,e[8]=r,e[9]=i,e[10]=a,e[11]=l):l=e[11],l}function L1(t){return t.trim()}function O1(t){const e=t.trim().toLowerCase();return e==="ctrl"||e==="control"?s.jsx("span",{className:"text-xs font-medium",children:"ctrl"}):e==="cmd"||e==="⌘"||e==="command"||e==="meta"?s.jsx(P,{name:"command",className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(P,{name:"arrow-up",className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const ad=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},$1=t=>{const e=ad(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function B1(t,e,n){const r=at.c(5),[i,a]=o.useState();let l,c;return r[0]!==n||r[1]!==t||r[2]!==e?(l=()=>{if(e){a(void 0);return}if(!t){a(void 0);return}a(void 0);let d=!1;return(async()=>{const[p,m]=await Promise.all([zs("git rev-parse --absolute-git-dir",t),zs("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=ad((p.stdout||"").trim()),h=$1(u);if(!h)return;const x=ad((m.stdout||"").trim());if(!x||x===h)return;const f=n||"",v=x.split("/").filter(Boolean).pop()||x;a({source:"sdk",path:x,projectDirectory:h,branch:f,label:f||v,name:v,worktreeRoot:x,worktreeStatus:"ready",headState:f?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},c=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=l,r[4]=c):(l=r[3],c=r[4]),o.useEffect(l,c),e??i}const Jn=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},va=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),ti=t=>!!t.success,Wl=t=>(t.stdout||"").trim(),Oi=t=>(t.stderr||"").trim();async function z1(t){const n=((await zs("git worktree list --porcelain",t)).stdout||"").split(/\r?\n/),r=[];let i=null;for(const a of n){if(a.startsWith("worktree ")){i&&r.push(i),i={path:a.slice(9).trim(),branchRef:null};continue}i&&a.startsWith("branch ")&&(i.branchRef=a.slice(7).trim())}return i&&r.push(i),r.filter(a=>!!a.path)}async function V1(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),i=(await z1(t.repoRoot)).filter(l=>l.branchRef===e).map(l=>l.path).filter(l=>l&&!n.has(l)),a=[];for(const l of i){const c=await zs("git status --porcelain",l);Wl(c)||a.push(l)}return a}async function Lh(t,e){for(const n of e)await zs("git reset --hard",n).catch(()=>{})}async function _1(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await zs(`git show-ref --verify --quiet ${Jn(`refs/heads/${n}`)}`,t);if(ti(r))return n;if(n.startsWith("remotes/")){const l=n.slice(8).split("/"),c=l[0]||"origin",d=l.slice(1).join("/");if(d)return await zs(`git branch --track ${Jn(d)} ${Jn(`${c}/${d}`)}`,t),d}const i=await zs(`git show-ref --verify --quiet ${Jn(`refs/remotes/origin/${n}`)}`,t);return ti(i)&&await zs(`git branch --track ${Jn(n)} ${Jn(`origin/${n}`)}`,t),n}async function Ma(t){const e=t.repoRoot,n=t.sourceBranch.trim(),r=t.targetBranch.trim();if(!n||!r)return{repoRoot:e,sourceBranch:n,targetBranch:r,commits:[]};const i=await _1(e,r),a=await zs(`git cherry ${Jn(i)} ${Jn(n)}`,e),l=va(a.stdout),c=new Set;for(const u of l){const h=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);h&&c.add(h[1])}const d=await zs(`git rev-list --reverse ${Jn(`${i}..${n}`)}`,e),m=va(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:i,commits:m}}async function U1(t,e){const n=await zs('mkdir -p "$HOME/.config/vinci/tmp"',t);if(!ti(n))throw new Error(Oi(n)||"Failed to create temp directory parent");const r=await zs('mktemp -d "$HOME/.config/vinci/tmp/vinci-integrate-XXXXXX"',t),i=Wl(r);if(!i)throw new Error(Oi(r)||"Failed to create temp directory");const a=await zs(`git worktree add --force ${Jn(i)} ${Jn(e)}`,t);if(!ti(a))throw new Error(Oi(a)||"Failed to create temp worktree");return i}async function yl(t,e){await zs(`git worktree remove --force ${Jn(e)}`,t).catch(()=>{}),await zs("git worktree prune",t).catch(()=>{})}async function W1(t){const e=await zs("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Wl(e);if(!n)return;await zs("git fetch",t);const r=await zs(`git merge --ff-only ${Jn(n)}`,t);if(!ti(r))throw new Error(Oi(r)||"Fast-forward failed")}async function vl(t){const e=await zs("git status --porcelain",t),n=await zs("git diff --name-only --diff-filter=U",t),r=await zs("git diff",t),i=await zs("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),a=await zs("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:va(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:i.stdout||i.stderr||"",currentPatch:a.stdout||a.stderr||""}}async function K1(t){return vl(t)}async function H1(t){const e=await zs("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return ti(e)}async function G1(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await U1(t.repoRoot,t.targetBranch);let n=[];try{await W1(e);const r=await zs("git status --porcelain",e);if(Wl(r))throw new Error("Target branch has local changes; abort integration and retry");const i=await V1({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const a=n[0],l=await zs(`git cherry-pick ${Jn(a)}`,e);if(ti(l)){n.shift();continue}const c=await zs("git diff --name-only --diff-filter=U",e);if(va(c.stdout).length>0){const p=await vl(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:i,remainingCommits:n,currentCommit:a},details:p}}throw new Error(Oi(l)||"Cherry-pick failed")}return await yl(t.repoRoot,e),await Lh(t.repoRoot,i).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await yl(t.repoRoot,e).catch(()=>{}),r}}async function q1(t){await zs("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await yl(t.repoRoot,t.tempWorktreePath)}async function Y1(t){const e=await zs("git cherry-pick --continue",t.tempWorktreePath);if(!ti(e)){const a=await zs("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(va(a.stdout).length>0){const c=await vl(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(Oi(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const i=[...r];for(;i.length>0;){const a=i[0],l=await zs(`git cherry-pick ${Jn(a)}`,n);if(ti(l)){i.shift();continue}const c=await zs("git diff --name-only --diff-filter=U",n);if(va(c.stdout).length>0){const p=await vl(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:i,currentCommit:a},details:p}}throw new Error(Oi(l)||"Cherry-pick failed")}return await yl(t.repoRoot,t.tempWorktreePath),await Lh(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const Q1=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:i,refreshKey:a,onRefresh:l})=>{const{t:c}=ut(),d=Ot($=>$.currentSessionId),p=Ie($=>$.setActiveMainTab),[m,u]=Be.useState(!1),h=Be.useRef(null),[x,f]=Be.useState(i);Be.useEffect(()=>{f(i)},[i]),Be.useEffect(()=>{if(m){const $=setTimeout(()=>{h.current?.focus()},0);return()=>clearTimeout($)}},[m]);const v=!!(t&&e&&x&&x!=="HEAD"&&e!==x),[y,g]=Be.useState({kind:"idle"}),[w,b]=Be.useState(!1),[k,I]=Be.useState([]),j=Be.useMemo(()=>d?`vinci.integrate.conflict:${d}`:null,[d]);Be.useEffect(()=>{if(!j||typeof window>"u")return;const $=window.localStorage.getItem(j);if(!$)return;let _=!1;try{const X=JSON.parse($);if(!X?.tempWorktreePath||X.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const O=await H1(X.tempWorktreePath).catch(()=>!1);if(_)return;if(!O){window.localStorage.removeItem(j);return}const J=await K1(X.tempWorktreePath).catch(()=>null);_||J&&g({kind:"conflict",state:X,details:J})})()}catch{window.localStorage.removeItem(j)}return()=>{_=!0}},[j,t]),Be.useEffect(()=>{if(!v){g({kind:"idle"});return}let $=!1;return g({kind:"loading"}),(async()=>{try{const _=await Ma({repoRoot:t,sourceBranch:e,targetBranch:x});if($)return;if(g({kind:"ready",plan:_}),_.commits.length>0){const J=_.commits.slice(-50).reverse().map(le=>JSON.stringify(le)).join(" "),ne=((await zs(`git show -s --format=%H%x09%h%x09%s ${J}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),G=[];for(const le of ne){const[oe,F,U]=le.split(" ");!oe||!F||G.push({sha:oe,short:F,subject:U||""})}$||(I(G),b(!1))}else $||(I([]),b(!1))}catch{$||g({kind:"idle"})}})(),()=>{$=!0}},[v,t,e,x,a]);const N=Be.useCallback($=>{d&&Ot.getState().setWorktreeMetadata(d,{...n,createdFromBranch:$})},[d,n]),D=Ot($=>$.openNewSessionDraft),E=Be.useCallback(async $=>{const _=await wn("git.integrate.cherrypick.resolve.visible",{current_commit:$.state.currentCommit,target_branch:$.state.targetBranch}),X=await wn("git.integrate.cherrypick.resolve.instructions",{repo_root:$.state.repoRoot,temp_worktree_path:$.state.tempWorktreePath,source_branch:$.state.sourceBranch,target_branch:$.state.targetBranch,current_commit:$.state.currentCommit}),O=`Cherry-pick conflict context (JSON)
|
|
6
|
+
${JSON.stringify({repoRoot:$.state.repoRoot,tempWorktreePath:$.state.tempWorktreePath,sourceBranch:$.state.sourceBranch,targetBranch:$.state.targetBranch,currentCommit:$.state.currentCommit,remainingCommits:$.state.remainingCommits,statusPorcelain:$.details.statusPorcelain,unmergedFiles:$.details.unmergedFiles,currentPatchMeta:$.details.currentPatchMeta,currentPatch:$.details.currentPatch,diff:$.details.diff},null,2)}`;return{visibleText:_,instructionsText:X,payloadText:O}},[]),T=zi($=>$.setPendingInputText),C=zi($=>$.setPendingSyntheticParts),S=Be.useCallback(async($,_)=>{const X=await E($);if(_){D({directoryOverride:$.state.tempWorktreePath,initialPrompt:X.visibleText,syntheticParts:[{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]}),p("chat");return}if(!d){H.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}T(X.visibleText,"replace"),C([{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]),p("chat")},[d,p,E,D,T,C,c]),M=Be.useCallback(async()=>{if(y.kind==="ready"){if(y.plan.commits.length===0){H.message(c("gitView.integrate.noCommitsToMoveToast"));return}g({kind:"running",plan:y.plan});try{const $=await G1(y.plan);if($.kind==="success"){H.success(c("gitView.integrate.commitsMovedToast"),{description:$.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:$.moved,branch:y.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:$.moved,branch:y.plan.targetBranch})});const _=await Ma(y.plan);g({kind:"ready",plan:_}),l?.();return}$.kind==="conflict"&&(H.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),g({kind:"conflict",state:$.state,details:$.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify($.state)))}catch($){const _=$ instanceof Error?$.message:String($);H.error(c("gitView.integrate.failedToMoveToast"),{description:_});const X=await Ma({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);g(X?{kind:"ready",plan:X}:{kind:"idle"})}}},[y,l,t,e,x,j,c]),A=Be.useCallback(async()=>{if(y.kind==="conflict")try{await q1(y.state),H.message(c("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const $=await Ma({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);g($?{kind:"ready",plan:$}:{kind:"idle"})}},[y,t,e,x,j,c]),R=Be.useCallback(async()=>{if(y.kind==="conflict")try{const $=await Y1(y.state);if($.kind==="success"){H.success(c("gitView.integrate.cherryPickFinishedToast"));const _=await Ma({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);g(_?{kind:"ready",plan:_}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),l?.();return}$.kind==="conflict"&&(g({kind:"conflict",state:$.state,details:$.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify($.state)))}catch($){const _=$ instanceof Error?$.message:String($);H.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:_})}},[y,t,e,x,l,j,c]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(P,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.integrate.title")}),y.kind==="ready"&&y.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:c("gitView.integrate.toMoveCount",{count:y.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:y.kind==="loading"||y.kind==="running"?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",x]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(Fs,{open:m,onOpenChange:u,children:[s.jsx(Es,{asChild:!0,children:s.jsxs(ge,{variant:"outline",size:"sm",className:"gap-1.5",children:[c("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:x}),s.jsx(P,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(Rs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(_i,{className:"h-full min-h-0",children:[s.jsx(xi,{ref:h,placeholder:c("gitView.branch.searchPlaceholder"),onKeyDown:$=>$.stopPropagation()}),s.jsxs(Ui,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Wi,{children:c("gitView.branch.empty")}),s.jsx(zn,{heading:c("gitView.branch.localBranches"),children:r.map($=>s.jsx(kn,{value:$,onSelect:()=>{f($),N($),u(!1)},children:$},$))})]})]})})]}),y.kind==="ready"?s.jsx(ge,{size:"sm",onClick:()=>{M()},disabled:!v||y.plan.commits.length===0,children:c("gitView.integrate.move")}):y.kind==="loading"?s.jsx(ge,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):y.kind==="running"?s.jsx(ge,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.moving")}):null]}),y.kind==="ready"&&y.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.noCommitsToMove")}),y.kind==="ready"&&y.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[c("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",y.plan.commits.length,")"]})]}),k.length>0&&y.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>b($=>!$),className:"typography-micro text-muted-foreground hover:text-foreground",children:c(w?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(w?k:k.slice(0,5)).map($=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:$.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:$.subject||$.sha})]},$.sha)),k.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.previewUnavailable")}),y.plan.commits.length>k.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c("gitView.integrate.showingFirstCommits",{count:k.length})})]})]}),y.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:c("gitView.integrate.conflictsInFiles",{count:y.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[c("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:y.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[y.details.unmergedFiles.slice(0,6).map($=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:$},$)),y.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:c("gitView.integrate.moreFiles",{count:y.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ge,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{A()},children:c("gitView.operation.abort")}),s.jsxs(ge,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{S({state:y.state,details:y.details},!1)},children:[s.jsx(P,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(ge,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{S({state:y.state,details:y.details},!0)},children:[s.jsx(P,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(ge,{size:"sm",className:"typography-meta",onClick:()=>{R()},children:c("gitView.operation.continue")})]})]})]})]})},J1=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),X1=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:i,onCreate:a,remotes:l=[],disabled:c=!1})=>{const{t:d}=ut(),[p,m]=o.useState(!1),[u,h]=o.useState(""),[x,f]=o.useState(!1),[v,y]=o.useState(!1),[g,w]=o.useState(""),[b,k]=o.useState(!1),I=o.useRef(null),j=o.useCallback(B=>{B.stopPropagation()},[]),N=l.length>1,D=o.useMemo(()=>J1(g),[g]),E=o.useMemo(()=>{const B=u.toLowerCase();return B?e.filter(V=>V.toLowerCase().includes(B)):e},[u,e]),T=o.useMemo(()=>{const B=u.toLowerCase();return B?n.filter(V=>V.toLowerCase().includes(B)):n},[u,n]),C=B=>{if(B===t){m(!1);return}i(B),m(!1),h("")},S=()=>{f(!0),setTimeout(()=>I.current?.focus(),50)},M=async()=>{if(!(!D||b)){if(N){y(!0);return}k(!0);try{await a(D,l[0]),w(""),f(!1),m(!1)}finally{k(!1)}}},A=async B=>{if(!(!D||b)){k(!0);try{await a(D,B),w(""),f(!1),y(!1),m(!1)}finally{k(!1)}}},R=()=>{y(!1)},z=()=>{w(""),f(!1),y(!1)};return o.useEffect(()=>{p||(h(""),f(!1),y(!1),w(""))},[p]),s.jsxs(Fs,{open:p,onOpenChange:m,children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsxs(ge,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:c,children:[s.jsx(P,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:t||d("gitView.branch.detachedHead")}),s.jsx(P,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),s.jsx(Dt,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(Rs,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(_i,{className:"h-full min-h-0",children:[s.jsx(xi,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:h,onKeyDown:j}),s.jsxs(Ui,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Wi,{children:d("gitView.branch.empty")}),s.jsx(zn,{children:v?s.jsxs("div",{className:"px-2 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("button",{type:"button",onClick:R,disabled:b,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(P,{name:"arrow-left",className:"size-4"})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d("gitView.branch.pushToPrefix")," ",s.jsx("span",{className:"text-foreground font-medium",children:D})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:l.map(B=>s.jsxs("button",{type:"button",onClick:()=>A(B),disabled:b,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[b?s.jsx(P,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,B.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:B.pushUrl})]},B.name))})]}):x?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:I,placeholder:d("gitView.branch.newBranchPlaceholder"),value:g,onChange:B=>w(B.target.value),onClick:B=>B.stopPropagation(),onKeyDown:B=>{j(B),B.key==="Enter"?(B.preventDefault(),M()):B.key==="Escape"&&(B.preventDefault(),z())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:M,disabled:!D||b,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:b?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:z,disabled:b,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(P,{name:"close",className:"size-4"})})]}):s.jsxs(kn,{onSelect:S,children:[s.jsx(P,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(Ti,{}),s.jsxs(zn,{heading:d("gitView.branch.localBranches"),children:[E.map(B=>s.jsxs(kn,{onSelect:()=>C(B),children:[s.jsxs("span",{className:"flex flex-1 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:B}),(r?.[B]?.ahead||r?.[B]?.behind)&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[B].ahead||0," ahead ·"," ",r[B].behind||0," behind"]})]}),t===B&&s.jsx("span",{className:"typography-micro text-primary",children:d("gitView.branch.currentBadge")})]},`local-${B}`)),E.length===0&&s.jsx(kn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(Ti,{}),s.jsxs(zn,{heading:d("gitView.branch.remoteBranches"),children:[T.map(B=>s.jsx(kn,{onSelect:()=>C(B),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:B})},`remote-${B}`)),T.length===0&&s.jsx(kn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},Z1=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),ej=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=ut(),[i,a]=o.useState(!1),[l,c]=o.useState(t||""),[d,p]=o.useState(!1),m=o.useRef(null),u=()=>{!t||!e||(c(t),a(!0),setTimeout(()=>m.current?.focus(),0))},h=async()=>{if(!t||!e||!l.trim())return;const v=Z1(l);if(v===t){a(!1);return}p(!0);try{await e(t,v),a(!1),c("")}finally{p(!1)}},x=()=>{a(!1),c("")},f=v=>{v.key==="Enter"?(v.preventDefault(),h()):v.key==="Escape"&&(v.preventDefault(),x())};return i?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:v=>{v.preventDefault(),h()},children:[s.jsx(P,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:l,onChange:v=>c(v.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:f,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,"aria-label":r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:x,disabled:d,"aria-label":r("gitView.branch.renameCancel"),title:r("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(P,{name:"close",className:"size-4"})})]})}):s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[s.jsx(P,{name:"git-branch",className:"size-4 text-primary shrink-0"}),s.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:t||r("gitView.branch.detachedHead")}),n&&e&&t&&s.jsx(ge,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(P,{name:"edit",className:"size-4"})})]})]})},tj=t=>{const e=at.c(41),{syncAction:n,remotes:r,onFetch:i,onSync:a,onRemoveRemote:l,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:h}=t,x=r===void 0?[]:r,f=d===void 0?null:d,v=p===void 0?0:p,y=m===void 0?0:m,g=h===void 0?!1:h,{t:w}=ut(),b=o.useRef(!1),k=!!f,I=x.find(pe=>pe.name===u)??x[0],j=y>0&&g,N=c||n!==null||k||!I||j,D=c||n!==null||k||x.length===0,E=v>0||y>0;let T;e[0]!==w?(T=w("gitView.sync.sync"),e[0]=w,e[1]=T):T=e[1];const C=y>0?`↓${y}`:null,S=v>0?`↑${v}`:null;let M;e[2]!==T||e[3]!==C||e[4]!==S?(M=[T,C,S].filter(Boolean),e[2]=T,e[3]=C,e[4]=S,e[5]=M):M=e[5];const A=M.join(" "),R=j?w("gitView.sync.commitOrStashTooltip"):I?E?w("gitView.sync.syncChangesTooltip",{ahead:v,behind:y}):w("gitView.sync.syncChanges"):w("gitView.sync.noRemoteTooltip"),z=()=>{I&&a(I)},B="inline-flex items-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] border border-border/60 bg-[var(--surface-elevated)] overflow-hidden";let V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=ce("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=V):V=e[6];let $;e[7]!==w?($=w("gitView.sync.syncChanges"),e[7]=w,e[8]=$):$=e[8];let _;e[9]!==n?(_=n==="sync"?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=_):_=e[10];let X;e[11]!==A?(X=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:A}),e[11]=A,e[12]=X):X=e[12];let O;e[13]!==z||e[14]!==N||e[15]!==$||e[16]!==_||e[17]!==X?(O=s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:z,disabled:N,className:V,"aria-label":$,children:[_,X]})}),e[13]=z,e[14]=N,e[15]=$,e[16]=_,e[17]=X,e[18]=O):O=e[18];let J;e[19]!==R?(J=s.jsx(Dt,{sideOffset:8,children:R}),e[19]=R,e[20]=J):J=e[20];let Q;e[21]!==O||e[22]!==J?(Q=s.jsxs(Pt,{children:[O,J]}),e[21]=O,e[22]=J,e[23]=Q):Q=e[23];const ne=Fs;let G;e[24]===Symbol.for("react.memo_cache_sentinel")?(G=ce("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[24]=G):G=e[24];let le;e[25]!==w?(le=w("gitView.sync.moreActionsAria"),e[25]=w,e[26]=le):le=e[26];let oe;e[27]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx(P,{name:"arrow-down-s",className:"size-4"}),e[27]=oe):oe=e[27];let F;e[28]!==D||e[29]!==le?(F=s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:G,disabled:D,"aria-label":le,children:oe})}),e[28]=D,e[29]=le,e[30]=F):F=e[30];const U=Rs,W="start",te=-40,K="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ae=x.map(pe=>s.jsx($t,{onSelect:ye=>{if(b.current){ye.preventDefault(),b.current=!1;return}i(pe)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(P,{name:"refresh",className:"size-4 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:w("gitView.sync.fetchFromRemote",{name:pe.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:pe.fetchUrl})]})}),l&&pe.name!==u?s.jsx(ge,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||k,onPointerDown:ye=>{b.current=!0,ye.preventDefault(),ye.stopPropagation()},onClick:ye=>{b.current=!0,ye.preventDefault(),ye.stopPropagation(),l(pe)},"aria-label":w("gitView.header.removeRemoteAria",{name:pe.name}),title:w("gitView.header.removeRemoteTitle",{name:pe.name}),children:f===pe.name?s.jsx(P,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(P,{name:"close",className:"size-3.5"})}):null]})},pe.name));let ve;e[31]!==U||e[32]!==ae?(ve=s.jsx(U,{align:W,alignOffset:te,className:K,children:ae}),e[31]=U,e[32]=ae,e[33]=ve):ve=e[33];let re;e[34]!==ne||e[35]!==F||e[36]!==ve?(re=s.jsxs(ne,{children:[F,ve]}),e[34]=ne,e[35]=F,e[36]=ve,e[37]=re):re=e[37];let be;return e[38]!==Q||e[39]!==re?(be=s.jsxs("div",{className:B,children:[Q,re]}),e[38]=Q,e[39]=re,e[40]=be):be=e[40],be},sj={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},nj={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)",success:"var(--status-success)",info:"var(--status-info)",warning:"var(--status-warning)"};function Oh(t){return t&&nj[t]||"var(--primary)"}const hm=t=>{const e=at.c(8),{icon:n,className:r,colorToken:i}=t,a=sj[n??"branch"]??"user-3";let l;e[0]!==i?(l=Oh(i),e[0]=i,e[1]=l):l=e[1];let c;e[2]!==l?(c={color:l},e[2]=l,e[3]=c):c=e[3];let d;return e[4]!==r||e[5]!==a||e[6]!==c?(d=s.jsx(P,{name:a,className:r,style:c}),e[4]=r,e[5]=a,e[6]=c,e[7]=d):d=e[7],d},$h=t=>{const e=at.c(35),{activeProfile:n,identities:r,onSelect:i,isApplying:a,iconOnly:l}=t,c=l===void 0?!1:l,{t:d}=ut(),p=a||r.length===0,m=n?.color;let u;e[0]!==m?(u=Oh(m),e[0]=m,e[1]=u):u=e[1];let h;e[2]!==u?(h={color:u},e[2]=u,e[3]=h):h=e[3];let x;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==a?(x=a?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(hm,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=a,e[7]=x):x=e[7];let f;e[8]!==n?.name||e[9]!==c||e[10]!==d?(f=!c&&s.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||d("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=c,e[10]=d,e[11]=f):f=e[11];let v;e[12]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(P,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=v):v=e[12];let y;e[13]!==p||e[14]!==h||e[15]!==x||e[16]!==f?(y=s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsxs(ge,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:h,disabled:p,children:[x,f,v]})})}),e[13]=p,e[14]=h,e[15]=x,e[16]=f,e[17]=y):y=e[17];let g;e[18]!==d?(g=d("gitView.header.identityTooltip"),e[18]=d,e[19]=g):g=e[19];let w;e[20]!==g?(w=s.jsx(Dt,{sideOffset:8,children:g}),e[20]=g,e[21]=w):w=e[21];let b;e[22]!==w||e[23]!==y?(b=s.jsxs(Pt,{children:[y,w]}),e[22]=w,e[23]=y,e[24]=b):b=e[24];let k;e[25]!==n?.id||e[26]!==r||e[27]!==i||e[28]!==d?(k=r.length===0?s.jsx("div",{className:"px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:d("gitView.header.noProfiles")})}):r.map(N=>{const D=n?.id===N.id;return s.jsx($t,{onSelect:()=>i(N),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(hm,{icon:N.icon,colorToken:N.color,className:"size-4"}),s.jsxs("span",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:N.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:N.userEmail})]}),D?s.jsx(P,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},N.id)}),e[25]=n?.id,e[26]=r,e[27]=i,e[28]=d,e[29]=k):k=e[29];let I;e[30]!==k?(I=s.jsx(Rs,{align:"end",className:"w-64",children:k}),e[30]=k,e[31]=I):I=e[31];let j;return e[32]!==b||e[33]!==I?(j=s.jsxs(Fs,{children:[b,I]}),e[32]=b,e[33]=I,e[34]=j):j=e[34],j},rj=t=>{const e=at.c(48),{status:n,localBranches:r,remoteBranches:i,branchInfo:a,syncAction:l,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:h,onCreateBranch:x,onRenameBranch:f,activeIdentityProfile:v,availableIdentities:y,onSelectIdentity:g,isApplyingIdentity:w,isWorktreeMode:b,onOpenHistory:k,actionTabItems:I,activeActionTab:j,onSelectActionTab:N}=t,{t:D}=ut();if(!n)return null;let E;e[0]!==k||e[1]!==D?(E=k?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:k,children:s.jsx(P,{name:"history",className:"size-4"})})}),s.jsx(Dt,{sideOffset:8,children:D("gitView.history.title")})]}):null,e[0]=k,e[1]=D,e[2]=E):E=e[2];let T;e[3]!==E?(T=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:E}),e[3]=E,e[4]=T):T=e[4];const C=T,S=!n;let M;e[5]!==n.tracking?(M=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=M):M=e[6];const A=(n.files?.length??0)>0;let R;e[7]!==d||e[8]!==m||e[9]!==p||e[10]!==c||e[11]!==u||e[12]!==n.ahead||e[13]!==n.behind||e[14]!==l||e[15]!==S||e[16]!==M||e[17]!==A?(R=s.jsx(tj,{syncAction:l,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:S,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:M,hasUncommittedChanges:A}),e[7]=d,e[8]=m,e[9]=p,e[10]=c,e[11]=u,e[12]=n.ahead,e[13]=n.behind,e[14]=l,e[15]=S,e[16]=M,e[17]=A,e[18]=R):R=e[18];const z=R;let B;e[19]!==v||e[20]!==y||e[21]!==w||e[22]!==g?(B=s.jsx($h,{activeProfile:v,identities:y,onSelect:g,isApplying:w,iconOnly:!0}),e[19]=v,e[20]=y,e[21]=w,e[22]=g,e[23]=B):B=e[23];const V=B;let $;e[24]!==a||e[25]!==b||e[26]!==r||e[27]!==h||e[28]!==x||e[29]!==f||e[30]!==i||e[31]!==c||e[32]!==n.current?($=s.jsx("div",{className:"min-w-0 flex-1",children:b?s.jsx(ej,{currentBranch:n.current,onRename:f}):s.jsx(X1,{currentBranch:n.current,localBranches:r,remoteBranches:i,branchInfo:a,onCheckout:h,onCreate:x,remotes:c})}),e[24]=a,e[25]=b,e[26]=r,e[27]=h,e[28]=x,e[29]=f,e[30]=i,e[31]=c,e[32]=n.current,e[33]=$):$=e[33];let _;e[34]!==V||e[35]!==C?(_=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[C,V]}),e[34]=V,e[35]=C,e[36]=_):_=e[36];let X;e[37]!==$||e[38]!==_?(X=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[$,_]}),e[37]=$,e[38]=_,e[39]=X):X=e[39];let O;e[40]!==I||e[41]!==j||e[42]!==N||e[43]!==z?(O=I&&j&&N?s.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(Cr,{items:I,activeId:j,onSelect:N,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:z})]}):null,e[40]=I,e[41]=j,e[42]=N,e[43]=z,e[44]=O):O=e[44];let J;return e[45]!==X||e[46]!==O?(J=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[X,O]}),e[45]=X,e[46]=O,e[47]=J):J=e[47],J},ij=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,uncommittedFileCount:i,onChanged:a})=>{const{t:l}=ut(),[c,d]=o.useState([]),[p,m]=o.useState(!1),[u,h]=o.useState(""),[x,f]=o.useState(""),[v,y]=o.useState(null),[g,w]=o.useState({}),b=o.useCallback(async()=>{if(n){m(!0);try{const E=await mb(n);d(E.stashes),w({})}catch(E){H.error(E instanceof Error?E.message:l("gitView.stashes.toast.loadFailed"))}finally{m(!1)}}},[n,l]);o.useEffect(()=>{t&&b()},[b,t]),o.useEffect(()=>{if(!t||!n||c.length===0)return;let E=!1;const T=c.map(C=>C.ref);return pb(n,T).then(C=>{E||w(C.counts)}).catch(()=>{}),()=>{E=!0}},[n,t,c]);const k=o.useMemo(()=>{const E=u.trim().toLowerCase();return E?c.filter(T=>`${T.ref} ${T.message} ${T.relativeTime}`.toLowerCase().includes(E)):c},[u,c]),I=o.useCallback(async()=>{await b(),await a?.()},[b,a]),j=async()=>{if(!(!n||v)){y("create");try{(await fb(n,{message:x.trim()||void 0})).created?(H.success(l("gitView.stashes.toast.created")),f("")):H.info(l("gitView.stashes.toast.noChanges")),await I()}catch(E){H.error(E instanceof Error?E.message:l("gitView.stashes.toast.createFailed"))}finally{y(null)}}},N=async(E,T)=>{if(!(!n||v)&&!(T==="drop"&&!window.confirm(l("gitView.stashes.confirm.drop",{ref:E.ref})))){y(`${T}:${E.ref}`);try{T==="apply"&&await hb(n,{ref:E.ref}),T==="pop"&&await gb(n,{ref:E.ref}),T==="drop"&&await xb(n,{ref:E.ref});const C=T==="apply"?"gitView.stashes.toast.applySuccess":T==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";H.success(l(C)),await I()}catch(C){const S=T==="apply"?"gitView.stashes.toast.applyFailed":T==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";H.error(C instanceof Error?C.message:l(S)),await I()}finally{y(null)}}},D=v!==null;return s.jsx(hs,{open:t,onOpenChange:e,children:s.jsxs(fs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(bs,{children:[s.jsxs(gs,{className:"flex items-center gap-2",children:[s.jsx(P,{name:"archive-stack",className:"h-5 w-5"}),l("gitView.stashes.title")]}),s.jsx(Is,{children:l("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(Bt,{value:x,onChange:E=>f(E.target.value),placeholder:l("gitView.stashes.messagePlaceholder"),disabled:D||!r,className:"flex-1"}),s.jsxs(ge,{onClick:j,disabled:!r||D||!n,children:[v==="create"?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"inbox-archive",className:"size-4"}),l("gitView.stashes.actions.stashCurrentWithCount",{count:i})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:l("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(P,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(Bt,{value:u,onChange:E=>h(E.target.value),placeholder:l("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:p?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(P,{name:"loader-4",className:"size-5 animate-spin"})}):k.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:l(u?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):k.map((E,T)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:E.message||l("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{children:T===0&&!u.trim()?l("gitView.stashes.latestLabel"):l("gitView.stashes.itemNumber",{number:T+1})})}),s.jsx(Dt,{sideOffset:6,children:E.ref})]})," · ",E.relativeTime," · ",typeof g[E.ref]=="number"?l("gitView.stashes.fileCount",{count:g[E.ref]}):l("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(xc,{label:l("gitView.stashes.actions.apply"),loading:v===`apply:${E.ref}`,onClick:()=>N(E,"apply"),disabled:D,children:s.jsx(P,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(xc,{label:l("gitView.stashes.actions.pop"),loading:v===`pop:${E.ref}`,onClick:()=>N(E,"pop"),disabled:D,children:s.jsx(P,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(xc,{label:l("gitView.stashes.actions.drop"),loading:v===`drop:${E.ref}`,onClick:()=>N(E,"drop"),disabled:D,destructive:!0,children:s.jsx(P,{name:"delete-bin",className:"size-4"})})]})]},E.ref))})]})})},xc=t=>{const e=at.c(17),{label:n,loading:r,disabled:i,destructive:a,onClick:l,children:c}=t,d=r||void 0,p=a?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let m;e[0]!==p?(m=ce("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",p),e[0]=p,e[1]=m):m=e[1];let u;e[2]!==c||e[3]!==r?(u=r?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):c,e[2]=c,e[3]=r,e[4]=u):u=e[4];let h;e[5]!==i||e[6]!==n||e[7]!==l||e[8]!==d||e[9]!==m||e[10]!==u?(h=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:l,disabled:i,children:u})}),e[5]=i,e[6]=n,e[7]=l,e[8]=d,e[9]=m,e[10]=u,e[11]=h):h=e[11];let x;e[12]!==n?(x=s.jsx(Dt,{sideOffset:6,children:n}),e[12]=n,e[13]=x):x=e[13];let f;return e[14]!==h||e[15]!==x?(f=s.jsxs(Pt,{children:[h,x]}),e[14]=h,e[15]=x,e[16]=f):f=e[16],f},Bh={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}},aj=Bh.M;function oj(t){const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"}function lj(t){const e=oj(t);return Bh[e]??aj}const gm=o.memo(function(e){const n=at.c(71),{file:r,checked:i,onToggle:a,onViewDiff:l,onRevert:c,isReverting:d,stats:p,rowPaddingClassName:m,indentPx:u}=e,h=u===void 0?0:u;let x;n[0]!==r?(x=lj(r),n[0]=r,n[1]=x):x=n[1];const f=x,{t:v}=ut(),y=f.description,g=p?.insertions??0,w=p?.deletions??0;let b;n[2]!==a||n[3]!==l?(b=F=>{F.key===" "?(F.preventDefault(),a()):F.key==="Enter"&&(F.preventDefault(),l())},n[2]=a,n[3]=l,n[4]=b):b=n[4];const k=b;let I;n[5]!==c?(I=F=>{F.preventDefault(),F.stopPropagation(),c()},n[5]=c,n[6]=I):I=n[6];const j=I,N=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${m??"px-3"}`;let D;n[7]!==h?(D=h>0?{paddingLeft:`${h}px`}:void 0,n[7]=h,n[8]=D):D=n[8];let E;n[9]!==a?(E=()=>a(),n[9]=a,n[10]=E):E=n[10];let T;n[11]!==r.path||n[12]!==v?(T=v("gitView.changes.selectFileAria",{path:r.path}),n[11]=r.path,n[12]=v,n[13]=T):T=n[13];let C;n[14]!==i||n[15]!==E||n[16]!==T?(C=s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",onClick:cj,children:s.jsx(ds,{size:"sm",checked:i,onChange:E,ariaLabel:T})}),n[14]=i,n[15]=E,n[16]=T,n[17]=C):C=n[17];let S;n[18]!==f.color?(S={color:f.color},n[18]=f.color,n[19]=S):S=n[19];let M;n[20]!==f.code||n[21]!==y||n[22]!==S?(M=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:S,title:y,"aria-label":y,children:f.code}),n[20]=f.code,n[21]=y,n[22]=S,n[23]=M):M=n[23];let A;n[24]!==r.path?(A=s.jsx(Zn,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[24]=r.path,n[25]=A):A=n[25];let R;if(n[26]!==r.path){e:{const F=r.path.lastIndexOf("/");if(F===-1){let re;n[28]===Symbol.for("react.memo_cache_sentinel")?(re={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[28]=re):re=n[28],R=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:re,title:r.path,children:r.path});break e}const U=r.path.slice(0,F),W=r.path.slice(F);let te;n[29]===Symbol.for("react.memo_cache_sentinel")?(te={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[29]=te):te=n[29];let K;n[30]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[30]=K):K=n[30];const ae=s.jsx("span",{className:"text-foreground",children:W.slice(1)});let ve;n[31]!==ae?(ve=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[K,ae]}),n[31]=ae,n[32]=ve):ve=n[32],R=s.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:r.path,children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:te,children:U}),ve]})}n[26]=r.path,n[27]=R}else R=n[27];let z;n[33]===Symbol.for("react.memo_cache_sentinel")?(z={color:"var(--status-success)"},n[33]=z):z=n[33];let B;n[34]!==g?(B=s.jsxs("span",{style:z,children:["+",g]}),n[34]=g,n[35]=B):B=n[35];let V,$;n[36]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),$={color:"var(--status-error)"},n[36]=V,n[37]=$):(V=n[36],$=n[37]);let _;n[38]!==w?(_=s.jsxs("span",{style:$,children:["-",w]}),n[38]=w,n[39]=_):_=n[39];let X;n[40]!==B||n[41]!==_?(X=s.jsxs("span",{className:"shrink-0 typography-micro",children:[B,V,_]}),n[40]=B,n[41]=_,n[42]=X):X=n[42];let O;n[43]!==r.path||n[44]!==v?(O=v("gitView.changes.revertFileAria",{path:r.path}),n[43]=r.path,n[44]=v,n[45]=O):O=n[45];let J;n[46]!==d?(J=d?s.jsx(P,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(P,{name:"arrow-go-back",className:"size-3.5"}),n[46]=d,n[47]=J):J=n[47];let Q;n[48]!==j||n[49]!==d||n[50]!==O||n[51]!==J?(Q=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,disabled:d,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":O,children:J})}),n[48]=j,n[49]=d,n[50]=O,n[51]=J,n[52]=Q):Q=n[52];let ne;n[53]!==v?(ne=v("gitView.changes.revertFileTooltip"),n[53]=v,n[54]=ne):ne=n[54];let G;n[55]!==ne?(G=s.jsx(Dt,{sideOffset:8,children:ne}),n[55]=ne,n[56]=G):G=n[56];let le;n[57]!==Q||n[58]!==G?(le=s.jsxs(Pt,{children:[Q,G]}),n[57]=Q,n[58]=G,n[59]=le):le=n[59];let oe;return n[60]!==k||n[61]!==l||n[62]!==M||n[63]!==A||n[64]!==R||n[65]!==X||n[66]!==le||n[67]!==N||n[68]!==D||n[69]!==C?(oe=s.jsxs("div",{className:N,role:"button",tabIndex:0,onClick:l,onKeyDown:k,style:D,children:[C,M,A,R,X,le]}),n[60]=k,n[61]=l,n[62]=M,n[63]=A,n[64]=R,n[65]=X,n[66]=le,n[67]=N,n[68]=D,n[69]=C,n[70]=oe):oe=n[70],oe});function cj(t){t.stopPropagation()}const dj=1e3,uj=34,xm=14,zh=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),bm=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),mj=t=>{const e=bm("","");for(const n of t){const r=zh(n.path);if(!r)continue;const a=r.split("/").filter(Boolean).slice(0,-1);let l=e;if(l.files.push(n),a.length>0){let c="";for(const d of a){c=c?`${c}/${d}`:d;const p=l.children.get(d);if(p){p.files.push(n),l=p;continue}const m=bm(c,d);m.files.push(n),l.children.set(d,m),l=m}}l.directFiles.push(n)}return e},pj=(t,e)=>{const n=[],r=(i,a)=>{const l=Array.from(i.children.values()).sort((d,p)=>d.path.localeCompare(p.path));for(const d of l)n.push({key:d.id,kind:"directory",depth:a,directory:d}),e.has(d.path)&&r(d,a+1);const c=[...i.directFiles].sort((d,p)=>d.path.localeCompare(p.path));for(const d of c)n.push({key:`file:${zh(d.path)}`,kind:"file",depth:a,file:d})};return r(t,0),n},ym=(t,e)=>{if(t.files.length===0)return"none";let n=0;for(const r of t.files)e.has(r.path)&&(n+=1);return n===0?"none":n===t.files.length?"all":"partial"},fj=({changeEntries:t,selectedPaths:e,diffStats:n,revertingPaths:r,onToggleFile:i,onSelectAll:a,onClearSelection:l,onRevertAll:c,onViewDiff:d,onRevertFile:p,isRevertingAll:m=!1,maxListHeightClassName:u,onVisiblePathsChange:h,onOpenStashes:x})=>{const{t:f}=ut(),v=o.useRef(null),g=Ie(oe=>oe.gitChangesViewMode)==="tree",w=e.size,b=t.length,[k,I]=o.useState(!1),j=o.useMemo(()=>mj(t),[t]),[N,D]=o.useState(new Set),E=o.useMemo(()=>Array.from(j.children.values()).map(oe=>oe.path),[j]);o.useEffect(()=>{g&&D(oe=>{const F=new Set,U=new Set(E);return oe.forEach(W=>{if(W.includes("/")){F.add(W);return}U.has(W)&&F.add(W)}),E.forEach(W=>F.add(W)),F})},[g,E]);const T=o.useMemo(()=>pj(j,N),[N,j]),C=o.useMemo(()=>g?T:t,[t,g,T]),S=C.length,M=S>=dj,A=w>0,R=b>0&&w===b,z=A&&!R,B=Rf({count:S,getScrollElement:()=>v.current,estimateSize:()=>uj,overscan:10,enabled:M});o.useEffect(()=>{if(!M)return;const oe=v.current;if(!oe)return;const F=new ResizeObserver(()=>{B.measure()});return F.observe(oe),()=>F.disconnect()},[M,B]);const V=B.getTotalSize(),$=o.useMemo(()=>M&&V>=0?B.getVirtualItems():[],[M,B,V]);o.useEffect(()=>{if(!h)return;if(S===0){h([]);return}const oe=F=>{if(!g)return F.path;const U=F;return U.kind==="file"?U.file.path:null};if(!M){h(C.slice(0,Math.min(30,S)).map(F=>oe(F)).filter(F=>!!F));return}h($.map(F=>C[F.index]).map(F=>F?oe(F):null).filter(F=>!!F))},[g,h,S,C,M,$]);const _="flex flex-col flex-1 min-h-0",X="flex items-center justify-between gap-2 px-0 py-3 border-b border-border/40",O=`flex-1 min-h-0 pr-0 ${u??""}`.trim(),J="pl-0 pr-2",Q=o.useCallback(oe=>{D(F=>{const U=new Set(F);return U.has(oe)?U.delete(oe):U.add(oe),U})},[]),ne=o.useCallback(oe=>{const U=ym(oe,e)!=="all";for(const W of oe.files){const te=e.has(W.path);(U&&!te||!U&&te)&&i(W.path)}},[i,e]),G=o.useCallback(oe=>{if(!g){const K=oe;return s.jsx(gm,{file:K,checked:e.has(K.path),stats:n?.[K.path],onToggle:()=>i(K.path),onViewDiff:()=>d(K.path),onRevert:()=>p(K.path),isReverting:r.has(K.path)||m,rowPaddingClassName:J})}const F=oe;if(F.kind==="file"){const K=F.file;return s.jsx(gm,{file:K,checked:e.has(K.path),stats:n?.[K.path],onToggle:()=>i(K.path),onViewDiff:()=>d(K.path),onRevert:()=>p(K.path),isReverting:r.has(K.path)||m,rowPaddingClassName:J,indentPx:F.depth*xm})}const U=F.directory,W=N.has(U.path),te=ym(U,e);return s.jsxs("div",{className:ce("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",J),style:{paddingLeft:`${F.depth*xm}px`},children:[s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",children:s.jsx(ds,{size:"sm",checked:te==="all",indeterminate:te==="partial",onChange:()=>ne(U),ariaLabel:f("gitView.changes.toggleDirectorySelectionAria",{path:U.path})})}),s.jsxs("button",{type:"button",onClick:()=>Q(U.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":W?f("gitView.changes.collapseDirectoryAria",{path:U.path}):f("gitView.changes.expandDirectoryAria",{path:U.path}),children:[W?s.jsx(P,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(P,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:U.path,children:U.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:U.files.length})]})]})},[n,N,m,g,p,i,d,r,J,e,f,Q,ne]),le=o.useCallback(async()=>{!c||m||t.length===0||(await c(t.map(oe=>oe.path)),I(!1))},[t,m,c]);return s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:_,children:[s.jsxs("header",{className:X,children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:f("gitView.changes.title")}),b>0?s.jsxs("div",{className:ce("inline-flex h-6 items-center gap-1 rounded px-1.5",m&&"cursor-not-allowed opacity-50"),children:[s.jsx(ds,{size:"sm",checked:A,indeterminate:z,disabled:m,onChange:()=>R?l():a(),ariaLabel:f(R?"gitView.changes.clearSelectionAria":"gitView.changes.selectAllAria")}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[w,"/",b]})]}):null,x?s.jsx(ge,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-1.5",onClick:x,"aria-label":f("gitView.stashes.title"),title:f("gitView.stashes.title"),children:s.jsx(P,{name:"archive-stack",className:"size-4"})}):null]}),s.jsx("div",{className:"flex items-center gap-2 pr-1",children:b>0&&c?s.jsx(ge,{variant:"destructive",size:"xs",onClick:()=>I(!0),disabled:m,children:f("gitView.changes.revertAll")}):null})]}),s.jsxs("div",{className:ce("relative flex flex-col min-h-0 w-full overflow-hidden",O),children:[s.jsx(po,{ref:v,className:"overlay-scrollbar-target overlay-scrollbar-container flex-1 min-h-0 w-full overflow-y-auto overflow-x-hidden",children:M?s.jsx("div",{className:"relative w-full",style:{height:`${B.getTotalSize()}px`},children:$.map(oe=>{const F=C[oe.index];if(!F)return null;const U=g?F.key:`file:${F.path}`;return s.jsx("div",{ref:B.measureElement,"data-index":oe.index,className:ce("absolute left-0 top-0 w-full",oe.index>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),style:{transform:`translateY(${oe.start}px)`},children:G(F)},U)})}):s.jsx("div",{role:"list","aria-label":f("gitView.changes.changedFilesAria"),children:C.map((oe,F)=>s.jsx("div",{className:ce("relative",F>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:G(oe)},g?oe.key:`file:${oe.path}`))})}),s.jsx(bb,{containerRef:v,disableHorizontal:!0})]})]}),s.jsx(hs,{open:k,onOpenChange:oe=>{m||I(oe)},children:s.jsxs(fs,{className:"max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:f("gitView.changes.revertAllDialogTitle")}),s.jsx(Is,{children:b===1?f("gitView.changes.revertAllDescriptionSingle",{count:b}):f("gitView.changes.revertAllDescriptionPlural",{count:b})})]}),s.jsxs(Vs,{children:[s.jsx(ge,{variant:"outline",size:"sm",onClick:()=>I(!1),disabled:m,children:f("gitView.common.cancel")}),s.jsx(ge,{variant:"destructive",size:"sm",onClick:()=>{le()},disabled:m,children:f(m?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},bc=38,Mo=200,hj=t=>{const e=at.c(20),{value:n,onChange:r,placeholder:i,disabled:a,hasTouchInput:l,isMobile:c}=t,d=a===void 0?!1:a,p=l===void 0?!1:l,m=c===void 0?!1:c,{t:u}=ut(),h=o.useRef(null),x=Ie(gj);let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{const E=h.current;if(!E)return;const T=document.activeElement===E,C=()=>{E.style.height=`${bc}px`;const M=E.scrollHeight,A=Math.min(Math.max(M,bc),Mo);E.style.height=`${A}px`,E.style.overflowY=M>Mo?"auto":"hidden",M>Mo&&!T&&(E.scrollTop=E.scrollHeight)};C();const S=window.requestAnimationFrame(C);return()=>{window.cancelAnimationFrame(S)}},e[0]=f):f=e[0];let v;e[1]!==n?(v=[n],e[1]=n,e[2]=v):v=e[2],o.useLayoutEffect(f,v);let y;e[3]!==r?(y=E=>r(E.target.value),e[3]=r,e[4]=y):y=e[4];let g;e[5]!==i||e[6]!==u?(g=i??u("gitView.commit.messagePlaceholder"),e[5]=i,e[6]=u,e[7]=g):g=e[7];const w=p?"on":"off",b=p?"sentences":"off",k=m||x,I=d&&"opacity-50";let j;e[8]!==I?(j=ce("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",I),e[8]=I,e[9]=j):j=e[9];let N;e[10]===Symbol.for("react.memo_cache_sentinel")?(N={minHeight:bc,maxHeight:Mo},e[10]=N):N=e[10];let D;return e[11]!==d||e[12]!==k||e[13]!==j||e[14]!==y||e[15]!==g||e[16]!==w||e[17]!==b||e[18]!==n?(D=s.jsx("textarea",{ref:h,value:n,onChange:y,placeholder:g,rows:1,disabled:d,autoCorrect:w,autoCapitalize:b,spellCheck:k,className:j,style:N}),e[11]=d,e[12]=k,e[13]=j,e[14]=y,e[15]=g,e[16]=w,e[17]=b,e[18]=n,e[19]=D):D=e[19],D};function gj(t){return t.inputSpellcheckEnabled}const xj=t=>{const e=at.c(30),{highlights:n,onInsert:r}=t,{t:i}=ut();if(n.length===0)return null;let a;e[0]!==n||e[1]!==r?(a=()=>{r(n)},e[0]=n,e[1]=r,e[2]=a):a=e[2];const l=a;let c;e[3]!==i?(c=i("gitView.commit.aiHighlights.title"),e[3]=i,e[4]=c):c=e[4];let d;e[5]!==c?(d=s.jsx("p",{className:"typography-micro text-muted-foreground",children:c}),e[5]=c,e[6]=d):d=e[6];let p;e[7]!==i?(p=i("gitView.commit.aiHighlights.insertAria"),e[7]=i,e[8]=p):p=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(P,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==l||e[11]!==p?(u=s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"icon",className:"size-6",onClick:l,"aria-label":p,children:m})}),e[10]=l,e[11]=p,e[12]=u):u=e[12];let h;e[13]!==i?(h=i("gitView.commit.aiHighlights.insertTooltip"),e[13]=i,e[14]=h):h=e[14];let x;e[15]!==h?(x=s.jsx(Dt,{sideOffset:8,children:h}),e[15]=h,e[16]=x):x=e[16];let f;e[17]!==u||e[18]!==x?(f=s.jsxs(Pt,{children:[u,x]}),e[17]=u,e[18]=x,e[19]=f):f=e[19];let v;e[20]!==d||e[21]!==f?(v=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,f]}),e[20]=d,e[21]=f,e[22]=v):v=e[22];let y;e[23]!==n?(y=n.map(bj),e[23]=n,e[24]=y):y=e[24];let g;e[25]!==y?(g=s.jsx("ul",{className:"space-y-1",children:y}),e[25]=y,e[26]=g):g=e[26];let w;return e[27]!==v||e[28]!==g?(w=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[v,g]}),e[27]=v,e[28]=g,e[29]=w):w=e[29],w};function bj(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const yj=t=>{const e=at.c(72),{selectedCount:n,commitMessage:r,onCommitMessageChange:i,generatedHighlights:a,onInsertHighlights:l,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,gitmojiEnabled:h,onOpenGitmojiPicker:x}=t,{t:f}=ut(),v=n>0;let y;e[0]!==u||e[1]!==r||e[2]!==v?(y=r.trim()&&v&&u===null,e[0]=u,e[1]=r,e[2]=v,e[3]=y):y=e[3];const g=y,{isMobile:w,hasTouchInput:b}=rn();let k;e[4]!==f?(k=f("gitView.commit.title"),e[4]=f,e[5]=k):k=e[5];let I;e[6]!==k?(I=s.jsx("div",{className:"flex w-full items-center justify-between px-0 pt-2 pb-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:k})}),e[6]=k,e[7]=I):I=e[7];let j;e[8]!==v||e[9]!==f?(j=v?null:s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.commit.selectFilesHint")}),e[8]=v,e[9]=f,e[10]=j):j=e[10];let N;e[11]!==a||e[12]!==l?(N=s.jsx(xj,{highlights:a,onInsert:l}),e[11]=a,e[12]=l,e[13]=N):N=e[13];let D;e[14]!==f?(D=f("gitView.commit.messagePlaceholder"),e[14]=f,e[15]=D):D=e[15];const E=u!==null;let T;e[16]!==r||e[17]!==b||e[18]!==w||e[19]!==i||e[20]!==D||e[21]!==E?(T=s.jsx(hj,{value:r,onChange:i,placeholder:D,disabled:E,hasTouchInput:b,isMobile:w}),e[16]=r,e[17]=b,e[18]=w,e[19]=i,e[20]=D,e[21]=E,e[22]=T):T=e[22];let C;e[23]!==h||e[24]!==x||e[25]!==f?(C=h&&s.jsxs(ge,{variant:"outline",size:"sm",onClick:x,className:"w-fit",type:"button",children:[s.jsx(P,{name:"emotion-happy",className:"size-4"}),f("gitView.commit.addGitmoji")]}),e[23]=h,e[24]=x,e[25]=f,e[26]=C):C=e[26];const S=d||u!==null||n===0;let M;e[27]!==f?(M=f("gitView.commit.generateAria"),e[27]=f,e[28]=M):M=e[28];let A;e[29]!==d?(A=d?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"ai-generate-2",className:"size-4 text-primary"}),e[29]=d,e[30]=A):A=e[30];let R;e[31]!==f?(R=f("gitView.commit.generate"),e[31]=f,e[32]=R):R=e[32];let z;e[33]!==R?(z=s.jsx("span",{className:"commit-actions__label",children:R}),e[33]=R,e[34]=z):z=e[34];let B;e[35]!==c||e[36]!==S||e[37]!==M||e[38]!==A||e[39]!==z?(B=s.jsxs(ge,{variant:"outline",size:"sm",onClick:c,disabled:S,type:"button","aria-label":M,className:"commit-actions__btn",children:[A,z]}),e[35]=c,e[36]=S,e[37]=M,e[38]=A,e[39]=z,e[40]=B):B=e[40];let V;e[41]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("div",{className:"flex-1"}),e[41]=V):V=e[41];const $=!g||d;let _;e[42]!==f?(_=f("gitView.commit.commitAria"),e[42]=f,e[43]=_):_=e[43];let X;e[44]!==u||e[45]!==f?(X=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.commit")})]}),e[44]=u,e[45]=f,e[46]=X):X=e[46];let O;e[47]!==p||e[48]!==$||e[49]!==_||e[50]!==X?(O=s.jsx(ge,{size:"sm",variant:"outline",onClick:p,disabled:$,className:"commit-actions__btn whitespace-nowrap","aria-label":_,children:X}),e[47]=p,e[48]=$,e[49]=_,e[50]=X,e[51]=O):O=e[51];let J;e[52]!==g||e[53]!==u||e[54]!==d||e[55]!==w||e[56]!==m||e[57]!==f?(J=w?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"default",size:"sm",onClick:()=>m(),disabled:!g||d,className:"h-7 w-7 p-0","aria-label":f("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(Dt,{side:"top",children:s.jsx("p",{children:f("gitView.commit.push")})})]}):s.jsx(ge,{size:"sm",variant:"default",onClick:()=>m(),disabled:!g||d,className:"commit-actions__btn","aria-label":f("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.push")})]})}),e[52]=g,e[53]=u,e[54]=d,e[55]=w,e[56]=m,e[57]=f,e[58]=J):J=e[58];let Q;e[59]!==B||e[60]!==O||e[61]!==J?(Q=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[B,V,O,J]}),e[59]=B,e[60]=O,e[61]=J,e[62]=Q):Q=e[62];let ne;e[63]!==Q||e[64]!==j||e[65]!==N||e[66]!==T||e[67]!==C?(ne=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[j,N,T,C,Q]}),e[63]=Q,e[64]=j,e[65]=N,e[66]=T,e[67]=C,e[68]=ne):ne=e[68];let G;return e[69]!==ne||e[70]!==I?(G=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[I,ne]}),e[69]=ne,e[70]=I,e[71]=G):G=e[71],G},vj=t=>{const e=at.c(16),{onOpenStashes:n}=t,{t:r}=ut();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(P,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=i):i=e[0];let a;e[1]!==r?(a=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=a):a=e[2];let l;e[3]!==a?(l=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:a}),e[3]=a,e[4]=l):l=e[4];let c;e[5]!==r?(c=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=c):c=e[6];let d;e[7]!==c?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:c}),e[7]=c,e[8]=d):d=e[8];let p;e[9]!==n||e[10]!==r?(p=n?s.jsxs(ge,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(P,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=p):p=e[11];let m;return e[12]!==l||e[13]!==d||e[14]!==p?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[i,l,d,p]}),e[12]=l,e[13]=d,e[14]=p,e[15]=m):m=e[15],m};function Vh(t){const e=at.c(63),{draft:n,onEdit:r,onDelete:i,className:a,maxWidth:l}=t,{t:c}=ut(),p=Ll()?.currentTheme,[m,u]=Be.useState(!1),h=typeof n.text=="string"?n.text:"";let x;e[0]!==h?(x=h.length>150||h.split(`
|
|
7
|
+
`).length>3,e[0]=h,e[1]=x):x=e[1];const f=x;let v;e[2]!==a?(v=ce("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",a),e[2]=a,e[3]=v):v=e[3];const y=p?.colors?.surface?.elevated,g=p?.colors?.interactive?.border,w=l?`${Math.max(200,Math.floor(l))}px`:void 0;let b;e[4]!==y||e[5]!==g||e[6]!==w?(b={backgroundColor:y,borderColor:g,maxWidth:w},e[4]=y,e[5]=g,e[6]=w,e[7]=b):b=e[7];let k;e[8]!==n.fileLabel?(k=s.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[8]=n.fileLabel,e[9]=k):k=e[9];let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx("span",{children:"•"}),e[10]=I):I=e[10];let j;e[11]!==n.endLine||e[12]!==n.startLine||e[13]!==c?(j=c("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[11]=n.endLine,e[12]=n.startLine,e[13]=c,e[14]=j):j=e[14];let N;e[15]!==j?(N=s.jsx("span",{children:j}),e[15]=j,e[16]=N):N=e[16];let D;e[17]!==n.side?(D=n.side&&s.jsxs("span",{children:["(",n.side,")"]}),e[17]=n.side,e[18]=D):D=e[18];let E;e[19]!==N||e[20]!==D||e[21]!==k?(E=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[k,I,N,D]}),e[19]=N,e[20]=D,e[21]=k,e[22]=E):E=e[22];const T=m||!f,C=!m&&f&&"line-clamp-3";let S;e[23]!==C?(S=ce("text-sm whitespace-pre-wrap break-words leading-relaxed",C),e[23]=C,e[24]=S):S=e[24];let M;e[25]!==h||e[26]!==S?(M=s.jsx("div",{className:S,children:h}),e[25]=h,e[26]=S,e[27]=M):M=e[27];let A;e[28]!==f||e[29]!==m||e[30]!==c?(A=f&&s.jsx(Pr,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"arrow-up-s",className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"arrow-down-s",className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=f,e[29]=m,e[30]=c,e[31]=A):A=e[31];let R;e[32]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(hr,{}),e[32]=R):R=e[32];let z;e[33]!==T||e[34]!==M||e[35]!==A?(z=s.jsxs(fr,{open:T,onOpenChange:u,children:[M,A,R]}),e[33]=T,e[34]=M,e[35]=A,e[36]=z):z=e[36];let B;e[37]!==E||e[38]!==z?(B=s.jsxs("div",{className:"flex-1 min-w-0",children:[E,z]}),e[37]=E,e[38]=z,e[39]=B):B=e[39];let V;e[40]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(Es,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"more",className:"size-4"})})}),e[40]=V):V=e[40];let $;e[41]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(P,{name:"edit",className:"size-4 mr-2"}),e[41]=$):$=e[41];let _;e[42]!==c?(_=c("inlineComment.actions.editComment"),e[42]=c,e[43]=_):_=e[43];let X;e[44]!==r||e[45]!==_?(X=s.jsxs($t,{onClick:r,children:[$,_]}),e[44]=r,e[45]=_,e[46]=X):X=e[46];let O;e[47]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(P,{name:"delete-bin",className:"size-4 mr-2"}),e[47]=O):O=e[47];let J;e[48]!==c?(J=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=J):J=e[49];let Q;e[50]!==i||e[51]!==J?(Q=s.jsxs($t,{onClick:i,className:"text-destructive",children:[O,J]}),e[50]=i,e[51]=J,e[52]=Q):Q=e[52];let ne;e[53]!==X||e[54]!==Q?(ne=s.jsxs(Fs,{children:[V,s.jsxs(Rs,{align:"end",children:[X,Q]})]}),e[53]=X,e[54]=Q,e[55]=ne):ne=e[55];let G;e[56]!==B||e[57]!==ne?(G=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[B,ne]}),e[56]=B,e[57]=ne,e[58]=G):G=e[58];let le;return e[59]!==v||e[60]!==G||e[61]!==b?(le=s.jsx("div",{className:v,style:b,"data-comment-card":"true",children:G}),e[59]=v,e[60]=G,e[61]=b,e[62]=le):le=e[62],le}function wl(t){const e=at.c(57),{initialText:n,onSave:r,onCancel:i,fileLabel:a,lineRange:l,isEditing:c,className:d,maxWidth:p}=t,m=n===void 0?"":n,u=c===void 0?!1:c,{t:h}=ut(),f=Ll()?.currentTheme,{isMobile:v}=rn(),[y,g]=o.useState(m),w=Be.useRef(null),b=Be.useRef(l);let k,I;e[0]!==l?(k=()=>{l&&(b.current=l)},I=[l],e[0]=l,e[1]=k,e[2]=I):(k=e[1],I=e[2]),Be.useEffect(k,I);const j=Pj,N=j(l);let D,E;e[3]!==v?(D=()=>{const ye=w.current;if(!ye)return;const ie=ye.closest(".overlay-scrollbar-container"),ue=ie?.scrollTop??window.scrollY,se=ie?.scrollLeft??window.scrollX;if(v){ye.scrollIntoView({behavior:"auto",block:"nearest"});try{ye.focus({preventScroll:!0})}catch{ye.focus()}return}try{ye.focus({preventScroll:!0})}catch{ye.focus()}const Ne=ye.value.length;try{ye.setSelectionRange(Ne,Ne)}catch{}requestAnimationFrame(()=>{ie?(ie.scrollTop=ue,ie.scrollLeft=se):window.scrollTo({top:ue,left:se})})},E=[v],e[3]=v,e[4]=D,e[5]=E):(D=e[4],E=e[5]),Be.useEffect(D,E);let T;e[6]!==i||e[7]!==r||e[8]!==y?(T=ye=>{(ye.metaKey||ye.ctrlKey)&&ye.key==="Enter"?(ye.preventDefault(),y.trim()&&r(y,j(b.current))):ye.key==="Escape"&&(ye.preventDefault(),i())},e[6]=i,e[7]=r,e[8]=y,e[9]=T):T=e[9];const C=T;let S;e[10]!==r||e[11]!==y?(S=ye=>{ye.stopPropagation(),y.trim()&&r(y,j(b.current))},e[10]=r,e[11]=y,e[12]=S):S=e[12];const M=S;let A;e[13]!==d?(A=ce("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",d),e[13]=d,e[14]=A):A=e[14];const R=f?.colors?.surface?.elevated,z=f?.colors?.interactive?.border,B=p?`${Math.max(200,Math.floor(p))}px`:void 0;let V;e[15]!==R||e[16]!==z||e[17]!==B?(V={backgroundColor:R,borderColor:z,maxWidth:B},e[15]=R,e[16]=z,e[17]=B,e[18]=V):V=e[18];const $="true",_=Cj,X=kj,O="p-3",J=(a||l)&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[a&&s.jsx("span",{className:"truncate max-w-[200px]",children:a}),a&&l&&s.jsx("span",{children:"•"}),N&&s.jsx("span",{children:h("inlineComment.range.lines",{start:N.start,end:N.end})})]});let Q;e[19]===Symbol.for("react.memo_cache_sentinel")?(Q=ye=>g(ye.target.value),e[19]=Q):Q=e[19];let ne;e[20]!==h?(ne=h("inlineComment.input.placeholder"),e[20]=h,e[21]=ne):ne=e[21];let G;e[22]!==C||e[23]!==ne||e[24]!==y?(G=s.jsx(hn,{simple:!0,ref:w,value:y,onChange:Q,onKeyDown:C,placeholder:ne,outerClassName:"rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]",className:"min-h-[80px] px-3 py-2.5 text-sm resize-y"}),e[22]=C,e[23]=ne,e[24]=y,e[25]=G):G=e[25];let le;e[26]!==h?(le=h("inlineComment.actions.cancel"),e[26]=h,e[27]=le):le=e[27];let oe;e[28]!==i||e[29]!==le?(oe=s.jsx(ge,{variant:"ghost",size:"sm",onClick:i,onPointerDown:Sj,onTouchStart:Nj,className:"h-8 text-muted-foreground hover:text-foreground",children:le}),e[28]=i,e[29]=le,e[30]=oe):oe=e[30];let F;e[31]!==y?(F=y.trim(),e[31]=y,e[32]=F):F=e[32];const U=!F,W=f?.colors?.status?.success,te=f?.colors?.status?.successForeground;let K;e[33]!==W||e[34]!==te?(K={backgroundColor:W,color:te},e[33]=W,e[34]=te,e[35]=K):K=e[35];let ae;e[36]!==u||e[37]!==h?(ae=h(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=h,e[38]=ae):ae=e[38];let ve;e[39]!==M||e[40]!==U||e[41]!==K||e[42]!==ae?(ve=s.jsx(ge,{size:"sm",onClick:M,onPointerDown:jj,onTouchStart:wj,disabled:U,className:"h-8 min-w-[80px]",style:K,children:ae}),e[39]=M,e[40]=U,e[41]=K,e[42]=ae,e[43]=ve):ve=e[43];let re;e[44]!==oe||e[45]!==ve?(re=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[oe,ve]}),e[44]=oe,e[45]=ve,e[46]=re):re=e[46];let be;e[47]!==J||e[48]!==G||e[49]!==re?(be=s.jsxs("div",{className:O,children:[J,G,re]}),e[47]=J,e[48]=G,e[49]=re,e[50]=be):be=e[50];let pe;return e[51]!==V||e[52]!==_||e[53]!==X||e[54]!==be||e[55]!==A?(pe=s.jsx("div",{className:A,style:V,"data-comment-input":$,onPointerDown:_,onTouchStart:X,children:be}),e[51]=V,e[52]=_,e[53]=X,e[54]=be,e[55]=A,e[56]=pe):pe=e[56],pe}function wj(t){return t.stopPropagation()}function jj(t){return t.stopPropagation()}function Nj(t){return t.stopPropagation()}function Sj(t){return t.stopPropagation()}function kj(t){return t.stopPropagation()}function Cj(t){return t.stopPropagation()}function Pj(t){if(!t)return;const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}}const Ij=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},jl=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function Hd(t){const e=at.c(40),{t:n}=ut(),{source:r,fileLabel:i,language:a,getCodeForRange:l,toStoreRange:c,fromDraftRange:d}=t,p=Ot(Rj),m=Ot(Ej),u=ia(Mj),h=ia(Tj),x=ia(Dj),f=ia(Aj),[v,y]=o.useState(null),[g,w]=o.useState(""),[b,k]=o.useState(null),I=p??(m?"draft":null);let j;e:{if(!I||!i){let O;e[0]===Symbol.for("react.memo_cache_sentinel")?(O=[],e[0]=O):O=e[0],j=O;break e}let $;e[1]!==f||e[2]!==I?($=f[I]??[],e[1]=f,e[2]=I,e[3]=$):$=e[3];const _=$;let X;if(e[4]!==i||e[5]!==_||e[6]!==r){let O;e[8]!==i||e[9]!==r?(O=J=>J.source===r&&J.fileLabel===i,e[8]=i,e[9]=r,e[10]=O):O=e[10],X=_.filter(O),e[4]=i,e[5]=_,e[6]=r,e[7]=X}else X=e[7];j=X}const N=j;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{y(null),w(""),k(null)},e[11]=D):D=e[11];const E=D;let T;e[12]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{E()},e[12]=T):T=e[12];const C=T;let S;e[13]!==d?(S=$=>{const _=jl(d($));y(_),w($.text),k($.id)},e[13]=d,e[14]=S):S=e[14];const M=S;let A;e[15]!==b||e[16]!==x?(A=$=>{x($.sessionKey,$.id),b===$.id&&E()},e[15]=b,e[16]=x,e[17]=A):A=e[17];const R=A;let z;e[18]!==u||e[19]!==b||e[20]!==i||e[21]!==l||e[22]!==a||e[23]!==v||e[24]!==I||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==h?(z=($,_)=>{const X=_??v,O=$.trim();if(!X||!O||!i)return;if(!I){H.error(n("inlineComment.toast.selectSessionToSave"));return}const J=jl(X),Q=Ij(c(J)),ne=l(J);b?h(I,b,{fileLabel:i,startLine:Q.startLine,endLine:Q.endLine,side:Q.side,code:ne,language:a,text:O}):u({sessionKey:I,source:r,fileLabel:i,startLine:Q.startLine,endLine:Q.endLine,side:Q.side,code:ne,language:a,text:O}),E()},e[18]=u,e[19]=b,e[20]=i,e[21]=l,e[22]=a,e[23]=v,e[24]=I,e[25]=r,e[26]=n,e[27]=c,e[28]=h,e[29]=z):z=e[29];const B=z;let V;return e[30]!==g||e[31]!==R||e[32]!==N||e[33]!==b||e[34]!==d||e[35]!==B||e[36]!==v||e[37]!==I||e[38]!==M?(V={sessionKey:I,drafts:N,selection:v,setSelection:y,commentText:g,setCommentText:w,editingDraftId:b,setEditingDraftId:k,reset:E,cancel:C,startEdit:M,deleteDraft:R,saveComment:B,fromDraftRange:d},e[30]=g,e[31]=R,e[32]=N,e[33]=b,e[34]=d,e[35]=B,e[36]=v,e[37]=I,e[38]=M,e[39]=V):V=e[39],V}function Aj(t){return t.drafts}function Dj(t){return t.removeDraft}function Tj(t){return t.updateDraft}function Mj(t){return t.addDraft}function Ej(t){return t.newSessionDraft?.open}function Rj(t){return t.currentSessionId}function _h(t){const{drafts:e,editingDraftId:n,commentText:r,selection:i,isDragging:a,fileLabel:l,newWidgetId:c,mapDraftToRange:d,onSave:p,onCancel:m,onEdit:u,onDelete:h}=t,x=[];for(const f of e){const v=d(f);if(f.id===n){x.push({afterLine:v.end,id:`edit-${f.id}`,content:s.jsx(wl,{initialText:r,fileLabel:l,lineRange:v,isEditing:!0,onSave:p,onCancel:m},`edit-${f.id}`)});continue}x.push({afterLine:v.end,id:`card-${f.id}`,content:s.jsx(Vh,{draft:f,onEdit:()=>u(f),onDelete:()=>h(f)},`card-${f.id}`)})}if(i&&!n&&!a){const f={...i,start:Math.min(i.start,i.end),end:Math.max(i.start,i.end)};x.push({afterLine:f.end,id:c,content:s.jsx(wl,{initialText:r,fileLabel:l,lineRange:f,isEditing:!1,onSave:p,onCancel:m},c)})}return x}const tl=t=>{if(t.type==="new"){const e=Math.min(t.selection.start,t.selection.end),n=Math.max(t.selection.start,t.selection.end);return`new-comment-${t.selection.side??"additions"}-${e}-${n}`}return`draft-${t.draft.id}`},Fj=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,i=[];for(const a of e){if(!Number.isFinite(a.endLine))continue;const l=Math.max(1,Math.floor(a.endLine)),c=a.side==="original"?"deletions":"additions";i.push({lineNumber:l,side:c,metadata:{type:a.id===n?"edit":"saved",draft:a}})}return r&&!n&&i.push({lineNumber:Math.max(r.start,r.end),side:r.side??"additions",metadata:{type:"new",selection:r}}),i};function Lj(t){const e=t.trim();if(!e)return null;if(/^-?\d+(\.\d+)?$/.test(e)){const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}if(e.endsWith("px")){const n=Number.parseFloat(e.slice(0,-2));return Number.isFinite(n)?n:null}return null}function vm(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function Oj(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:i,commentText:a,fileLabel:l,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,h]=o.useState(0),[x,f]=o.useState(null),v=o.useMemo(()=>!r||i?null:tl({type:"new",selection:r}),[i,r]),y=o.useMemo(()=>{const b=n.map(k=>tl({type:k.id===i?"edit":"saved",draft:k}));return v&&b.push(v),b},[n,i,v]),g=o.useCallback(b=>{const k=e.current;if(!k)return null;const I=k.querySelector("diffs-container");if(!(I instanceof HTMLElement))return null;const j=I.querySelector(`[data-annotation-id="${b}"]`);if(j instanceof HTMLElement)return j;const N=I.shadowRoot;return N?N.querySelector(`[data-annotation-id="${b}"]`):null},[e]);o.useEffect(()=>{if(y.length===0)return;let b=!1,k=0;const I=12,j=()=>{b||y.every(D=>!!g(D))||k>=I||(k+=1,requestAnimationFrame(()=>{b||(h(D=>D+1),j())}))};return j(),()=>{b=!0}},[y,g]),o.useEffect(()=>{const b=e.current;if(!b)return;const k=()=>{const j=getComputedStyle(b),N=Lj(j.getPropertyValue("--oc-context-panel-width")),D=b.getBoundingClientRect(),E=N??D.width;f(E>0?E:null)};k();const I=new ResizeObserver(()=>{k()});return I.observe(b),window.addEventListener("resize",k),()=>{I.disconnect(),window.removeEventListener("resize",k)}},[e]);const w=o.useCallback(b=>{const I=e.current?.getBoundingClientRect(),j=b.closest("[data-annotation-content]"),N=j instanceof HTMLElement?j.getBoundingClientRect():b.getBoundingClientRect(),D=[N.width];I&&D.push(I.right-N.left);const E=D.filter(T=>Number.isFinite(T)&&T>0);return E.length>0?vm(Math.min(...E)):vm(x)},[e,x]);return s.jsxs(s.Fragment,{children:[n.map(b=>{const k=tl({type:b.id===i?"edit":"saved",draft:b}),I=g(k);if(!I)return null;const j=w(I);return b.id===i?Wa.createPortal(s.jsx(wl,{initialText:a,fileLabel:l,lineRange:{start:b.startLine,end:b.endLine,side:b.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:j}),I,`draft-edit-${b.id}`):Wa.createPortal(s.jsx(Vh,{draft:b,onEdit:()=>p(b),onDelete:()=>m(b),maxWidth:j}),I,`draft-card-${b.id}`)}),r&&!i&&v&&(()=>{const b=g(v);if(!b)return null;const k=w(b);return Wa.createPortal(s.jsx(wl,{initialText:a,fileLabel:l,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:k}),b,v)})()]})}function $j(){return new Worker(nx,{type:"module"})}const Bj=["typescript","javascript","tsx","jsx","json","markdown"],od={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let wm,jm;const Nm=t=>{const e=od[t],n=new rx({workerFactory:$j,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:Bj,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},zj=t=>{if(!(typeof window>"u"))return t==="split"?(jm??=Nm("split"),jm):(wm??=Nm("unified"),wm)},Vj=t=>{const e=at.c(7),{children:n,renderTheme:r}=t,i=ld("unified"),a=ld("split");let l,c;e[0]!==r||e[1]!==a||e[2]!==i?(l=()=>{i&&i.setRenderOptions({theme:r,lineDiffType:od.unified.lineDiffType}),a&&a.setRenderOptions({theme:r,lineDiffType:od.split.lineDiffType})},c=[r,a,i],e[0]=r,e[1]=a,e[2]=i,e[3]=l,e[4]=c):(l=e[3],c=e[4]),Be.useEffect(l,c);let d;return e[5]!==n?(d=s.jsx(s.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},_j=t=>{const e=at.c(11),{children:n}=t,r=Ll();let i,a;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=ha(!1),m=ha(!0),u=r?.lightThemeId??p.metadata.id,h=r?.darkThemeId??m.metadata.id;a=r?.availableThemes.find(x=>x.metadata.id===u)??p,i=r?.availableThemes.find(x=>x.metadata.id===h)??m,ga(a),ga(i),e[0]=r?.availableThemes,e[1]=r?.darkThemeId,e[2]=r?.lightThemeId,e[3]=i,e[4]=a}else i=e[3],a=e[4];let l;e[5]!==i.metadata.id||e[6]!==a.metadata.id?(l={light:a.metadata.id,dark:i.metadata.id},e[5]=i.metadata.id,e[6]=a.metadata.id,e[7]=l):l=e[7];const c=l;let d;return e[8]!==n||e[9]!==c?(d=s.jsx(Vj,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},ld=t=>{const e=at.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=zj(n),e[0]=n,e[1]=r):r=e[1],r},Uj=5e5,Wj=`
|
|
8
|
+
:host {
|
|
9
|
+
font-family: var(--font-mono);
|
|
10
|
+
font-size: var(--text-code);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
pre, [data-code] {
|
|
14
|
+
font-family: var(--font-mono);
|
|
15
|
+
font-size: var(--text-code);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Mobile touch selection support */
|
|
19
|
+
[data-line-number] {
|
|
20
|
+
touch-action: manipulation;
|
|
21
|
+
-webkit-tap-highlight-color: transparent;
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Ensure interactive line numbers work on touch */
|
|
26
|
+
pre[data-interactive-line-numbers] [data-line-number] {
|
|
27
|
+
touch-action: manipulation;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
[data-diff-header],
|
|
31
|
+
[data-diff] {
|
|
32
|
+
[data-separator] {
|
|
33
|
+
height: 24px !important;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;function Kj(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return e.toString(16)}function Sm(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${Kj(e)}`}const Hj=(t,e,n)=>{const a=(n.side==="deletions"?t:e).split(`
|
|
37
|
+
`),l=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,l),p=Math.min(a.length,c);return d>p?"":a.slice(d-1,p).join(`
|
|
38
|
+
`)},Gj=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,Eo=new WeakMap,qj={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function Yj(t){const e=t.closest("[data-diff-virtual-root]");if(e instanceof HTMLElement){const n=e.querySelector("[data-diff-virtual-content]");return{key:e,root:e,content:n instanceof HTMLElement?n:void 0}}return{key:document,root:document,content:void 0}}function Qj(t){if(typeof document>"u")return null;const e=Yj(t);let n=Eo.get(e.key);if(!n){const i=new ox;i.setup(e.root,e.content),n={virtualizer:i,refs:0},Eo.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const i=Eo.get(e.key);i&&(i.refs-=1,!(i.refs>0)&&(i.virtualizer.cleanUp(),Eo.delete(e.key)))}}}const Gd=({original:t,modified:e,language:n,fileName:r,renderSideBySide:i,wrapLines:a,layout:l="fill"})=>{const c=Ll(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(W=>W.metadata.id===c.lightThemeId)??ha(!1),m=c?.availableThemes.find(W=>W.metadata.id===c.darkThemeId)??ha(!0),{isMobile:u}=rn(),h=Hd({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:W=>Hj(t,e,W),toStoreRange:W=>({startLine:W.start,endLine:W.end,side:W.side==="deletions"?"original":"modified"}),fromDraftRange:W=>({start:W.startLine,end:W.endLine,side:W.side==="original"?"deletions":"additions"})}),{drafts:x,selection:f,setSelection:v,commentText:y,setCommentText:g,editingDraftId:w,saveComment:b,cancel:k,startEdit:I,deleteDraft:j}=h,N=Be.useRef(null),D=Be.useRef(null),E=Be.useRef(!1),T=Be.useRef(null);Be.useEffect(()=>{N.current=f},[f]),Be.useEffect(()=>{D.current=w},[w]);const C=Be.useCallback(W=>{if(E.current)return;const te=N.current;if(u&&te&&W&&W.side===te.side){const K=Math.min(te.start,W.start),ae=Math.max(te.end,W.end);v({...W,start:K,end:ae})}else v(W);W&&(D.current||g(""))},[u,g,v]),S=Be.useCallback(()=>{k()},[k]),M=Be.useCallback(W=>{const te=document.createElement("div");te.style.position="relative";const K=tl(W.metadata);return te.dataset.annotationId=K,te.dataset.annotationSide=W.side,te.dataset.annotationLine=String(W.lineNumber),te},[]),A=Be.useCallback((W,te)=>{b(W,te??f??void 0)},[b,f]),R=Be.useCallback(W=>{v(W);const te=_.current;if(te)try{E.current=!0,te.setSelectedLines(W),T.current=W}catch{}finally{E.current=!1}},[v]),z=Be.useCallback(W=>{const te=W.closest("[data-line-type]")?.getAttribute("data-line-type")??W.getAttribute("data-line-type");if(te==="change-deletion")return"deletions";if(te==="change-addition")return"additions";const K=W.getAttribute("data-column-side")??W.getAttribute("data-side")??W.closest("[data-column-side]")?.getAttribute("data-column-side");if(K==="deletions"||K==="left"||K==="original")return"deletions";if(K==="additions"||K==="right"||K==="modified")return"additions";const ae=W.closest("[data-line-type]");if(ae instanceof HTMLElement){const ve=ae.getBoundingClientRect(),re=W.getBoundingClientRect(),be=ve.left+ve.width/2;return re.left+re.width/2<be?"deletions":"additions"}return"additions"},[]);ga(p),ga(m);const B=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,V=Be.useRef(null),$=Be.useRef(null),_=Be.useRef(null),X=Be.useRef(null),[,O]=o.useReducer(W=>W+1,0),J=ld(i?"split":"unified"),Q=Be.useMemo(()=>Su(p),[p]),ne=Be.useMemo(()=>Su(m),[m]);o.useLayoutEffect(()=>{const W=V.current;if(!W)return;const te=W.querySelector("diffs-container");if(!te)return;const K=d?ne:Q,ae=(je,we)=>je.colors?.[we],ve=ae(Q,"terminal.ansiGreen"),re=ae(Q,"terminal.ansiRed"),be=ae(Q,"terminal.ansiBlue"),pe=ae(ne,"terminal.ansiGreen"),ye=ae(ne,"terminal.ansiRed"),ie=ae(ne,"terminal.ansiBlue");te.style.setProperty("--shiki-light",Q.fg),te.style.setProperty("--shiki-light-bg",Q.bg),ve&&te.style.setProperty("--shiki-light-addition-color",ve),re&&te.style.setProperty("--shiki-light-deletion-color",re),be&&te.style.setProperty("--shiki-light-modified-color",be),te.style.setProperty("--shiki-dark",ne.fg),te.style.setProperty("--shiki-dark-bg",ne.bg),pe&&te.style.setProperty("--shiki-dark-addition-color",pe),ye&&te.style.setProperty("--shiki-dark-deletion-color",ye),ie&&te.style.setProperty("--shiki-dark-modified-color",ie),te.style.setProperty("--diffs-bg",K.bg),te.style.setProperty("--diffs-fg",K.fg);const ue=d?pe:ve,se=d?ye:re,Ne=d?ie:be;ue&&te.style.setProperty("--diffs-addition-color-override",ue),se&&te.style.setProperty("--diffs-deletion-color-override",se),Ne&&te.style.setProperty("--diffs-modified-color-override",Ne);const Ce=te.shadowRoot?.querySelector("pre");Ce&&(Ce.style.setProperty("--shiki-light",Q.fg),Ce.style.setProperty("--shiki-light-bg",Q.bg),ve&&Ce.style.setProperty("--shiki-light-addition-color",ve),re&&Ce.style.setProperty("--shiki-light-deletion-color",re),be&&Ce.style.setProperty("--shiki-light-modified-color",be),Ce.style.setProperty("--shiki-dark",ne.fg),Ce.style.setProperty("--shiki-dark-bg",ne.bg),pe&&Ce.style.setProperty("--shiki-dark-addition-color",pe),ye&&Ce.style.setProperty("--shiki-dark-deletion-color",ye),ie&&Ce.style.setProperty("--shiki-dark-modified-color",ie),Ce.style.setProperty("--diffs-bg",K.bg),Ce.style.setProperty("--diffs-fg",K.fg),ue&&Ce.style.setProperty("--diffs-addition-color-override",ue),se&&Ce.style.setProperty("--diffs-deletion-color-override",se),Ne&&Ce.style.setProperty("--diffs-modified-color-override",Ne))},[ne,B,d,Q]);const G=Be.useMemo(()=>Math.max(t.length,e.length)>Uj,[t.length,e.length]),le=Be.useMemo(()=>({theme:{dark:m.metadata.id,light:p.metadata.id},themeType:d?"dark":"light",diffStyle:i?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:G?0:1e3,maxLineLengthForHighlighting:G?1:1e3,expansionLineCount:20,overflow:a?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:C,unsafeCSS:Wj,renderAnnotation:M}),[m.metadata.id,d,G,p.metadata.id,i,a,C,M]),oe=Be.useMemo(()=>Fj({drafts:x,editingDraftId:w,selection:f}),[w,x,f]),F=Be.useRef(oe);if(Be.useEffect(()=>{F.current=oe},[oe]),Be.useEffect(()=>{if(typeof window>"u")return;const W=$.current;if(!W||!J)return;_.current?.cleanUp(),_.current=null,X.current?.release(),X.current=null,W.innerHTML="";const te=Qj(W);X.current=te;const K=te?new ix(le,te.virtualizer,qj,J):new ax(le,J);_.current=K,T.current=null;const ae={name:r||"",contents:t,lang:n,cacheKey:`old:${B}:${r}:${Sm(t)}`},ve={name:r||"",contents:e,lang:n,cacheKey:`new:${B}:${r}:${Sm(e)}`};return K.render({oldFile:ae,newFile:ve,lineAnnotations:F.current,containerWrapper:W}),requestAnimationFrame(()=>{O()}),()=>{K.cleanUp(),_.current===K&&(_.current=null),te?.release(),te&&X.current===te&&(X.current=null),W.innerHTML=""}},[B,r,n,e,le,t,J]),Be.useEffect(()=>{const W=_.current;if(W){try{W.setLineAnnotations(oe)}catch(te){console.error("Failed to apply diff line annotations",te);try{W.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(_.current===W){try{W.rerender()}catch{}O()}})}},[oe]),Be.useEffect(()=>{const W=_.current;if(!W||f!==null)return;const te=T.current;if(!Gj(f,te))try{E.current=!0,W.setSelectedLines(f),T.current=f}catch{}finally{E.current=!1}},[f]),Be.useEffect(()=>{const W=$.current;if(!W)return;let te=null,K=()=>{};const ae=()=>{const re=W.querySelector("diffs-container")?.shadowRoot;if(!re){te=requestAnimationFrame(ae);return}const be=pe=>{if(!(pe instanceof MouseEvent)||pe.button!==0||!(pe.target instanceof Element))return;const ye=pe.target.closest("[data-column-number]");if(!(ye instanceof HTMLElement))return;const ie=ye.getAttribute("data-column-number"),ue=ie?parseInt(ie,10):NaN;if(Number.isNaN(ue))return;const se=z(ye);C({start:ue,end:ue,side:se}),pe.preventDefault(),pe.stopPropagation()};re.addEventListener("click",be,!0),K=()=>{re.removeEventListener("click",be,!0)}};return ae(),()=>{te!==null&&cancelAnimationFrame(te),K()}},[B,r,C,z]),Be.useEffect(()=>{const W=$.current;if(!W)return;let te=null,K=null;const ve=setTimeout(()=>{const re=W.querySelector("diffs-container");if(!(re instanceof HTMLElement))return;const be=re.shadowRoot;te=new MutationObserver(()=>{K&&cancelAnimationFrame(K),K=requestAnimationFrame(()=>{O(),K=null})}),te.observe(re,{childList:!0,subtree:!0}),be&&te.observe(be,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(ve),K&&cancelAnimationFrame(K),te?.disconnect()}},[B,r]),typeof window>"u")return null;const U=s.jsx(Oj,{diffRootRef:V,drafts:x,selection:f,editingDraftId:w,commentText:y,fileLabel:r?.split("/").pop()??"",onSave:A,onCancel:S,onEdit:W=>{R({start:W.startLine,end:W.endLine,side:W.side==="original"?"deletions":"additions"}),I(W)},onDelete:j});return l==="fill"?s.jsx("div",{className:ce("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:s.jsxs("div",{className:"flex-1 relative min-h-0",children:[s.jsx(Cs,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:s.jsx("div",{ref:V,className:"size-full relative",children:s.jsx("div",{ref:$,className:"size-full"})})}),U]})}):s.jsxs("div",{className:ce("relative","w-full"),children:[s.jsx("div",{ref:V,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:s.jsx("div",{ref:$,className:"w-full"})}),U]})},km=15e3,Cm=500,Pm=12,Im=8*1024*1024,Am=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Dm=t=>{if(t.size<=Pm){let i=0;for(const a of t.values())i+=Am(a);if(i<=Im)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[i,a]of e){if(n.size>=Pm)continue;const l=Am(a);r+l>Im&&n.size>0||(n.set(i,a),r+=l)}return new Map(Array.from(n.entries()).reverse())};function Tm(t){const e=new Date(t);return Number.isNaN(e.getTime())?t:e.toLocaleString(void 0,{hour12:!1,year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Jj(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}const Xj=o.memo(t=>{const e=at.c(71),{entry:n,isExpanded:r,onToggle:i,files:a,isLoadingFiles:l,onCopyHash:c,directory:d}=t,{t:p}=ut();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[0]=m):m=e[0];const[u,h]=o.useState(m);let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=new Map,e[1]=x):x=e[1];const[f,v]=o.useState(x);let y;e[2]===Symbol.for("react.memo_cache_sentinel")?(y=new Set,e[2]=y):y=e[2];const[g,w]=o.useState(y);let b;e[3]!==d||e[4]!==n.hash?(b=async W=>{const te=W.path;if(!d){v(K=>new Map(K).set(te,"error"));return}v(K=>Dm(new Map(K).set(te,"loading")));try{const K=yb(d,n.hash,W.path,!1),ae=new Promise(Zj),ve=await Promise.race([K,ae]);v(re=>Dm(new Map(re).set(te,ve)))}catch{v(K=>new Map(K).set(te,"error"))}},e[3]=d,e[4]=n.hash,e[5]=b):b=e[5];const k=b;let I;e[6]!==f||e[7]!==g||e[8]!==k||e[9]!==u?(I=async W=>{const te=W.path;if(W.changeType==="R"||W.isBinary){h(re=>{const be=new Set(re);return be.has(te)?be.delete(te):be.add(te),be});return}const K=f.get(te);if(u.has(te)&&K&&K!=="error"){h(re=>{const be=new Set(re);return be.delete(te),be});return}h(re=>{const be=new Set(re);return be.add(te),be}),!(K&&K!=="error"||W.insertions+W.deletions>Cm&&!g.has(te))&&await k(W)},e[6]=f,e[7]=g,e[8]=k,e[9]=u,e[10]=I):I=e[10];const j=I,N=r?"bg-sidebar/90":"hover:bg-sidebar/40";let D;e[11]!==N?(D=ce("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",N),e[11]=N,e[12]=D):D=e[12];let E;e[13]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),e[13]=E):E=e[13];let T;e[14]!==n.message?(T=s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:n.message}),e[14]=n.message,e[15]=T):T=e[15];let C;e[16]!==n.author_name?(C=s.jsx("span",{className:"truncate min-w-[3ch]",title:n.author_name,children:n.author_name}),e[16]=n.author_name,e[17]=C):C=e[17];let S;e[18]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx("span",{className:"shrink-0",children:"·"}),e[18]=S):S=e[18];let M;e[19]!==n.date?(M=Tm(n.date),e[19]=n.date,e[20]=M):M=e[20];let A;e[21]!==n.date?(A=Tm(n.date),e[21]=n.date,e[22]=A):A=e[22];let R;e[23]!==M||e[24]!==A?(R=s.jsx("span",{className:"truncate min-w-0",title:M,children:A}),e[23]=M,e[24]=A,e[25]=R):R=e[25];let z;e[26]!==C||e[27]!==R?(z=s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[C,S,R]}),e[26]=C,e[27]=R,e[28]=z):z=e[28];let B;e[29]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx("span",{className:"shrink-0",children:"·"}),e[29]=B):B=e[29];let V;e[30]!==n.hash?(V=n.hash.slice(0,8),e[30]=n.hash,e[31]=V):V=e[31];let $;e[32]!==V?($=s.jsx("code",{className:"shrink-0 font-mono",children:V}),e[32]=V,e[33]=$):$=e[33];let _;e[34]!==n.hash||e[35]!==c?(_=W=>{W.stopPropagation(),c(n.hash)},e[34]=n.hash,e[35]=c,e[36]=_):_=e[36];let X;e[37]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(P,{name:"file-copy",className:"size-3"}),e[37]=X):X=e[37];let O;e[38]!==_?(O=s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:_,children:X})}),e[38]=_,e[39]=O):O=e[39];let J;e[40]!==p?(J=p("gitView.history.copySha"),e[40]=p,e[41]=J):J=e[41];let Q;e[42]!==J?(Q=s.jsx(Dt,{sideOffset:8,children:J}),e[42]=J,e[43]=Q):Q=e[43];let ne;e[44]!==O||e[45]!==Q?(ne=s.jsxs(Pt,{children:[O,Q]}),e[44]=O,e[45]=Q,e[46]=ne):ne=e[46];let G;e[47]!==z||e[48]!==$||e[49]!==ne?(G=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[z,B,$,ne]}),e[47]=z,e[48]=$,e[49]=ne,e[50]=G):G=e[50];let le;e[51]!==G||e[52]!==T?(le=s.jsxs("div",{className:"min-w-0 flex-1",children:[T,G]}),e[51]=G,e[52]=T,e[53]=le):le=e[53];let oe;e[54]!==i||e[55]!==le||e[56]!==D?(oe=s.jsxs("button",{type:"button",onClick:i,className:D,children:[E,le]}),e[54]=i,e[55]=le,e[56]=D,e[57]=oe):oe=e[57];let F;e[58]!==f||e[59]!==a||e[60]!==g||e[61]!==r||e[62]!==l||e[63]!==k||e[64]!==u||e[65]!==p||e[66]!==j?(F=r&&s.jsx("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:l?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:p("gitView.history.loadingFiles")})]}):a.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:p("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:a.map(W=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>j(W),className:ce("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",u.has(W.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:ce("font-semibold w-3 text-center shrink-0",Jj(W.changeType)),children:W.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:W.path,children:W.path}),!W.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",W.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",W.deletions]})]}),W.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:p("gitView.history.binary")}),s.jsx(P,{name:u.has(W.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),u.has(W.path)&&s.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:W.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.renamedNoDiff")}):W.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.binaryNoDiff")}):(()=>{const te=W.insertions+W.deletions;if(!g.has(W.path)&&te>Cm)return s.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:p("gitView.history.largeDiffTitle",{count:te})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:p("gitView.history.largeDiffDescription")}),s.jsx(ge,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{w(ae=>new Set(ae).add(W.path)),k(W)},children:p("gitView.history.renderDiffAnyway")})]});const K=f.get(W.path);return K==="loading"||K===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.loadingDiff")}):K==="error"?s.jsx("button",{type:"button",onClick:()=>j(W),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:p("gitView.history.diffError")}):s.jsx(Gd,{original:K.original,modified:K.modified,language:xa(W.path)||"",fileName:W.path,renderSideBySide:!1,layout:"inline"})})()})]},W.path))})}),e[58]=f,e[59]=a,e[60]=g,e[61]=r,e[62]=l,e[63]=k,e[64]=u,e[65]=p,e[66]=j,e[67]=F):F=e[67];let U;return e[68]!==oe||e[69]!==F?(U=s.jsxs("li",{children:[oe,F]}),e[68]=oe,e[69]=F,e[70]=U):U=e[70],U});function Zj(t,e){setTimeout(()=>e(new Error(`Timed out after ${km}ms`)),km)}const e0=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],t0=t=>{const e=at.c(56),{log:n,isLogLoading:r,logMaxCount:i,onLogMaxCountChange:a,expandedCommitHashes:l,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,directory:u,showHeader:h,contentMaxHeightClassName:x,branchDivider:f}=t,v=h===void 0?!0:h,y=x===void 0?"max-h-[50vh]":x,g=f===void 0?null:f,{t:w}=ut(),[b,k]=o.useState(!0);if(!n)return null;const I=g!==null&&g.insertBeforeIndex>0&&g.insertBeforeIndex<n.all.length,j=g!==null&&g.insertBeforeIndex===n.all.length,N=I||j;let D;e[0]!==g||e[1]!==I||e[2]!==j||e[3]!==n.all?(D=I?n.all.slice(0,g.insertBeforeIndex):j?n.all:[],e[0]=g,e[1]=I,e[2]=j,e[3]=n.all,e[4]=D):D=e[4];const E=D;let T;if(e[5]!==g||e[6]!==d||e[7]!==y||e[8]!==u||e[9]!==l||e[10]!==I||e[11]!==N||e[12]!==p||e[13]!==n.all||e[14]!==m||e[15]!==c||e[16]!==w||e[17]!==E){const _=I?n.all.slice(g.insertBeforeIndex):[];let X;e[19]!==g?.direction?(X=g?.direction==="down"?s.jsx(P,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(P,{name:"arrow-up",className:"size-3.5"}),e[19]=g?.direction,e[20]=X):X=e[20];const O=X;let J;e[21]!==d||e[22]!==u||e[23]!==l||e[24]!==p||e[25]!==m||e[26]!==c?(J=ne=>s.jsx("ul",{className:"divide-y divide-border/60",children:ne.map(G=>s.jsx(Xj,{entry:G,isExpanded:l.has(G.hash),onToggle:()=>c(G.hash),files:d.get(G.hash)??[],isLoadingFiles:p.has(G.hash),onCopyHash:m,directory:u},G.hash))}),e[21]=d,e[22]=u,e[23]=l,e[24]=p,e[25]=m,e[26]=c,e[27]=J):J=e[27];const Q=J;T=s.jsx(Cs,{outerClassName:`min-h-0 ${y}`,className:"h-full w-full",children:n.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:w("gitView.history.noCommits")})}):N&&g?s.jsxs("div",{className:"flex flex-col gap-0",children:[E.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Q(E)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:g.branchName,children:g.branchName}),O]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),_.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Q(_)}):null]}):Q(n.all)}),e[5]=g,e[6]=d,e[7]=y,e[8]=u,e[9]=l,e[10]=I,e[11]=N,e[12]=p,e[13]=n.all,e[14]=m,e[15]=c,e[16]=w,e[17]=E,e[18]=T}else T=e[18];const C=T;if(!v){if(N){let X;return e[28]!==C?(X=s.jsx("section",{className:"h-full min-h-0",children:C}),e[28]=C,e[29]=X):X=e[29],X}let _;return e[30]!==C?(_=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:C}),e[30]=C,e[31]=_):_=e[31],_}let S;e[32]!==w?(S=w("gitView.history.title"),e[32]=w,e[33]=S):S=e[33];let M;e[34]!==S?(M=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:S}),e[34]=S,e[35]=M):M=e[35];let A;e[36]!==r||e[37]!==b||e[38]!==i||e[39]!==a||e[40]!==w?(A=b&&s.jsx("div",{onClick:s0,onPointerDown:n0,children:s.jsxs(is,{value:String(i),onValueChange:_=>a(Number(_)),disabled:r,children:[s.jsx(as,{size:"sm",className:"data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0",disabled:r,children:s.jsx(us,{placeholder:w("gitView.history.commitsPlaceholder")})}),s.jsx(os,{children:e0.map(_=>s.jsx(Ft,{value:String(_.value),children:w(_.labelKey)},_.value))})]})}),e[36]=r,e[37]=b,e[38]=i,e[39]=a,e[40]=w,e[41]=A):A=e[41];let R;e[42]!==b?(R=b?s.jsx(P,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(P,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[42]=b,e[43]=R):R=e[43];let z;e[44]!==A||e[45]!==R?(z=s.jsxs("div",{className:"flex items-center gap-2",children:[A,R]}),e[44]=A,e[45]=R,e[46]=z):z=e[46];let B;e[47]!==z||e[48]!==M?(B=s.jsxs(Pr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[M,z]}),e[47]=z,e[48]=M,e[49]=B):B=e[49];let V;e[50]!==C?(V=s.jsx(hr,{children:C}),e[50]=C,e[51]=V):V=e[51];let $;return e[52]!==b||e[53]!==B||e[54]!==V?($=s.jsxs(fr,{open:b,onOpenChange:k,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[B,V]}),e[52]=b,e[53]=B,e[54]=V,e[55]=$):$=e[55],$};function s0(t){return t.stopPropagation()}function n0(t){return t.stopPropagation()}const r0=9e4,i0=15e3,a0=5*6e4,o0=[2e3,5e3],l0=6e4,c0=2*6e4,d0=5*6e4,u0=720*6e4,m0="vinci.github-pr-status",p0=t=>t==="closed"||t==="merged",f0=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Ya=(t,e,n)=>`${t}::${e}`,Ro=new Map,Fo=new Map,Ea=new Set,Mm=new Map,Va=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),Nl=t=>t?.params?.directory&&t.params.branch?{directory:t.params.directory,branch:t.params.branch,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null}:!t?.identity?.directory||!t.identity.branch?null:t.identity,qd=t=>{const e=Nl(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},Uh=(t,e)=>Object.entries(t).filter(([,n])=>qd(n)===e).map(([n])=>n),h0=(t,e)=>{const n=e.remoteName??t.params?.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null;return{...t,params:t.params?{...t.params,...e,remoteName:n}:{...e,remoteName:n},identity:{directory:e.directory,branch:e.branch,remoteName:n}}},Lo=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},g0=(t,e,n)=>{const r=Uh(t,e),i=r.map(d=>Lo(t[d])).filter(d=>!!d);if(i.length===0)return null;const a=Lo(t[n]);if(a&&qd(t[n])===e)return a;const l=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&Lo(d)));if(l)return Lo(l);const c=i.find(d=>!!d.remoteName);return c||(i[0]??null)},x0=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:Nl(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),b0=t=>({...Va(),status:t?.status??null,isInitialStatusResolved:t?.isInitialStatusResolved??!1,lastRefreshAt:t?.lastRefreshAt??0,lastDiscoveryPollAt:t?.lastDiscoveryPollAt??0,identity:t?.identity??null,resolvedRemoteName:t?.resolvedRemoteName??t?.status?.resolvedRemoteName??null}),mr=gr()(mo((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:Va()}})},setParams:(n,r)=>{t(i=>{const a=i.entries[n]??Va();return{entries:{...i.entries,[n]:h0(a,r)}}})},startWatching:n=>{if(t(a=>{const l=a.entries[n]??Va();return{entries:{...a.entries,[n]:{...l,watchers:l.watchers+1}}}}),Ro.has(n))return;const r=a=>{const l=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const d=e().entries[n];!d||d.watchers<=0||d.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},a),c=Fo.get(n)??[];c.push(l),Fo.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),o0.forEach(a=>r(a));const i=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const a=e().entries[n];if(!a||a.watchers<=0)return;if(!!!a.status?.pr){const p=Date.now();if(p-a.lastDiscoveryPollAt<a0)return;t(m=>{const u=m.entries[n];return u?{entries:{...m.entries,[n]:{...u,lastDiscoveryPollAt:p}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(p0(a.status?.pr?.state))return;const c=Date.now()-a.lastRefreshAt,d=f0(a.status)?l0:a.status?.checks&&a.status.checks.state!=="pending"?d0:c0;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},i0);Ro.set(n,i)},stopWatching:n=>{t(l=>{const c=l.entries[n];if(!c)return l;const d=Math.max(0,c.watchers-1);return{entries:{...l.entries,[n]:{...c,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const i=Ro.get(n);typeof i=="number"&&window.clearInterval(i),Ro.delete(n);const a=Fo.get(n);a&&a.length>0&&a.forEach(l=>{window.clearTimeout(l)}),Fo.delete(n)},refresh:async(n,r)=>{const i=e(),a=i.entries[n],l=qd(a);if(!a||!l)return;const c=Uh(i.entries,l),d=c.some(u=>!!i.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const p=Mm.get(l)??0;if(!r?.force&&Date.now()-p<r0||Ea.has(l))return;const m=g0(i.entries,l,n);if(m){if(Ea.add(l),Mm.set(l,Date.now()),t(u=>{const h={...u.entries};return c.forEach(x=>{const f=h[x];f&&(h[x]={...f,lastRefreshAt:Date.now(),isLoading:r?.silent?f.isLoading:!0,error:null})}),{entries:h}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const h={...u.entries};return c.forEach(x=>{const f=h[x];f&&(h[x]={...f,status:{connected:!1},error:null,isLoading:r?.silent?f.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?f.isInitialStatusResolved:!0})}),{entries:h}}),Ea.delete(l);return}if(!m.github?.prStatus){t(u=>{const h={...u.entries};return c.forEach(x=>{const f=h[x];f&&(h[x]={...f,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?f.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?f.isInitialStatusResolved:!0})}),{entries:h}}),Ea.delete(l);return}try{t(h=>({...h,activeRequestCount:h.activeRequestCount+1,totalRequestCount:h.totalRequestCount+1}));const u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(h=>{const x={...h.entries};return c.forEach(f=>{const v=x[f];if(!v)return;const y=v.status?.pr,g=u.pr,b=!!(g&&y&&g.number===y.number&&(!g.body||!g.body.trim())&&typeof y.body=="string"&&y.body.trim().length>0)&&g&&y?.body?{...u,pr:{...g,body:y.body}}:u,k=b.resolvedRemoteName??v.resolvedRemoteName??m.remoteName??null,I=Nl(v)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};x[f]={...v,status:b,error:null,isLoading:r?.silent?v.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?v.isInitialStatusResolved:!0,resolvedRemoteName:k,identity:{...I,remoteName:k??I.remoteName??null}}}),{entries:x}})}catch(u){const h=u instanceof Error?u.message:String(u);t(x=>{const f={...x.entries};return c.forEach(v=>{const y=f[v];y&&(f[v]={...y,error:h||"Failed to load PR status",isLoading:r?.silent?y.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?y.isInitialStatusResolved:!0})}),{entries:f}})}finally{Ea.delete(l),t(u=>({...u,activeRequestCount:Math.max(0,u.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const i=Array.from(new Set(n.map(a=>{const l=a.directory.trim(),c=a.branch.trim();return!l||!c?null:Ya(l,c,a.remoteName??null)}).filter(a=>!!a)));await Promise.all(i.map(a=>e().refresh(a,r)))},updateStatus:(n,r)=>{t(i=>{const a=i.entries[n]??Va();return{entries:{...i.entries,[n]:{...a,status:r(a.status)}}}})}}),{name:m0,storage:Ml(()=>pi()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=Nl(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<u0}).map(([e,n])=>[e,x0(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([i,a])=>[i,b0(a)]))}}})),y0=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",i=e.mergeable===!1||r==="blocked"||r==="dirty";return n||i?"blocked":"open"},v0=t=>{const e=y0(t.status??null),n=t.status?.pr;return!e||!n?.number?null:{number:n.number,visualState:e,prState:n.state,draft:!!n.draft,title:typeof n.title=="string"&&n.title.trim().length>0?n.title:null,url:typeof n.url=="string"&&n.url.trim().length>0?n.url:null,base:typeof n.base=="string"&&n.base.trim().length>0?n.base:null,head:typeof n.head=="string"&&n.head.trim().length>0?n.head:null,checks:t.status?.checks?{state:t.status.checks.state,total:t.status.checks.total,success:t.status.checks.success,failure:t.status.checks.failure,pending:t.status.checks.pending}:null,canMerge:typeof t.status?.canMerge=="boolean"?t.status.canMerge:null,mergeableState:typeof n.mergeableState=="string"?n.mergeableState:null,repo:t.status?.repo?{owner:t.status.repo.owner,repo:t.status.repo.repo}:null}},w0=t=>`${t.number}:${t.visualState}:${t.prState}:${t.draft}:${t.title??""}:${t.url??""}:${t.base??""}:${t.head??""}:${t.canMerge??""}:${t.mergeableState??""}:${t.checks?.state??""}:${t.checks?.total??""}:${t.checks?.success??""}:${t.checks?.failure??""}:${t.checks?.pending??""}:${t.repo?.owner??""}:${t.repo?.repo??""}`;let yc=new Map,Em=new Map;const j0=t=>{const e=at.c(2);let n;return e[0]!==t?(n=r=>{const i=new Map,a=new Map;for(const l of t){const c=r.entries[l];if(!c)continue;const d=v0(c);if(!d)continue;const p=w0(d);i.set(l,p),a.set(l,d)}if(i.size===yc.size){let l=!0;for(const[c,d]of i)if(yc.get(c)!==d){l=!1;break}if(l)return Em}return yc=i,Em=a,a},e[0]=t,e[1]=n):n=e[1],mr(n)},N0=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},S0=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",i=e.mergeable===!1||r==="blocked"||r==="dirty";return n||i?"blocked":"open"},k0=[2e3,5e3],Rm=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),mi=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},C0=(t,e)=>{const n=mi(t);if(!n||n.includes("->"))return"";if(e){const i=`${e}/`;return n.startsWith(i)?n.slice(i.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},P0=(t,e)=>`${t}::${e}`,Yd=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},vc=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const a=t.find(l=>l.name===n);if(a)return a}const r=Yd(e.trackingBranch);if(r){const a=r==="origin"?t.find(c=>c.name==="upstream"):null;if(a)return a;const l=t.find(c=>c.name===r);if(l)return l}const i=t.find(a=>a.name==="origin");return i||(t[0]??null)},I0=t=>t.startsWith("pr-"),A0=(t,e)=>{const n=Yd(e),r=new Map(t.map(l=>[l.name,l])),i=[],a=l=>{l&&(i.some(c=>c.name===l.name)||i.push(l))};return n&&a(r.get(n)),a(r.get("upstream")),a(r.get("origin")),t.filter(l=>!I0(l.name)).forEach(l=>a(l)),t.forEach(l=>a(l)),i},wc=new Map,jc=rr;function D0(t,e){const[n,r]=o.useState(null),[i,a]=o.useState([]),l=o.useRef(null);return o.useEffect(()=>{r(null),a([])},[t]),o.useEffect(()=>{if(!t||!e?.repoUpstream||l.current===t)return;l.current=t;let c=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(c||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const p=await e.repoBranches(d.upstream.owner,d.upstream.repo);c||a(p)}catch{}}catch{}})(),()=>{c=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:i}}const T0=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:i=[],remoteBranches:a=[],onGeneratedDescription:l})=>{const{t:c}=ut(),{github:d}=Pn(),p=Hn(Ke=>Ke.status),m=Hn(Ke=>Ke.hasChecked),u=Ie(Ke=>Ke.setSettingsDialogOpen),h=Ie(Ke=>Ke.setSettingsPage),x=Ie(Ke=>Ke.setActiveMainTab),f=Ot(Ke=>Ke.currentSessionId),{isMobile:v,hasTouchInput:y}=rn(),g=o.useCallback(()=>{h("github"),u(!0)},[u,h]),w=o.useMemo(()=>P0(t,e),[t,e]),b=o.useMemo(()=>wc.get(w)??null,[w]),k=mr(Ke=>Ke.ensureEntry),I=mr(Ke=>Ke.setParams),j=mr(Ke=>Ke.startWatching),N=mr(Ke=>Ke.stopWatching),D=mr(Ke=>Ke.refresh),E=mr(Ke=>Ke.updateStatus),[T,C]=o.useState(()=>b?.title??Rm(e)),[S,M]=o.useState(()=>b?.body??""),[A,R]=o.useState(()=>b?.draft??!1),[z,B]=o.useState(()=>b?.additionalContext??""),[V,$]=o.useState(()=>{const Ke=typeof b?.targetBaseBranch=="string"?mi(b.targetBaseBranch):"";return Ke||mi(n)}),[_,X]=o.useState("squash"),[O,J]=o.useState(!1),[Q,ne]=o.useState(!1),[G,le]=o.useState(!1),[oe,F]=o.useState(!1),[U,W]=o.useState(!1),[te,K]=o.useState(!1),[ae,ve]=o.useState(null),[re,be]=o.useState(""),[pe,ye]=o.useState(""),[ie,ue]=o.useState(!1),[se,Ne]=o.useState(!1),[Ce,je]=o.useState(()=>vc(i,{selectedRemoteName:b?.selectedRemoteName,trackingBranch:r})),[we,ke]=o.useState(!1),{detectedUpstream:xe,upstreamBranches:me}=D0(t,d);o.useEffect(()=>{ke(!1)},[t]);const Me=i.some(Ke=>Ke.name==="upstream"),q=!!(t&&e&&n&&(e!==n||(Me||xe!==null))),Se=o.useMemo(()=>Ya(t,e),[t,e]),$e=mr(Ke=>Ke.entries[Se]),Pe=$e?.isLoading??!1,fe=$e?.status??null,L=$e?.error??null,Z=$e?.isInitialStatusResolved??!1,Y=o.useMemo(()=>{const Ke=we?null:Ce?.name?.trim()||null,yt=new Set;for(const ss of a){const Rt=C0(ss,Ke);!Rt||Rt==="HEAD"||yt.add(Rt)}if(we)for(const ss of me)ss&&ss!=="HEAD"&&yt.add(ss);const Et=mi(n);Et&&Et!=="HEAD"&&yt.add(Et);const Ht=mi(V);return Ht&&Ht!=="HEAD"&&yt.add(Ht),Array.from(yt).sort((ss,Rt)=>ss.localeCompare(Rt))},[n,a,Ce?.name,V,me,we]);o.useEffect(()=>{if(i.length===0){Ce&&je(null);return}(!Ce||!i.some(Ke=>Ke.name===Ce.name))&&je(vc(i,{selectedRemoteName:b?.selectedRemoteName,trackingBranch:r}))},[b?.selectedRemoteName,i,Ce,r]),o.useEffect(()=>{const Ke=mi(n);if(!V&&Ke){$(Ke);return}if(Y.length!==0&&!Y.includes(V)){const yt=Y.includes(Ke)?Ke:Y[0];yt&&$(yt)}},[Y,n,V]);const[Ee,Ae]=o.useState(!1),[Je,de]=o.useState(null),[ze,rt]=o.useState(!1),[Re,Xe]=o.useState(new Set),[qe,Te]=o.useState(!1),[We,Ze]=o.useState(null),[Qe,he]=o.useState(!1),Ge=o.useRef(new Set),Ve=o.useRef(null),it=o.useRef(!1),dt=o.useRef(new Set),Ye=o.useRef([]);o.useEffect(()=>{xe&&!Me&&ke(!0)},[xe,Me]),o.useEffect(()=>{we&&xe?.defaultBranch&&$(xe.defaultBranch)},[we,xe?.defaultBranch]);const _e=fe?.pr??null,et=_e?`${t}#${_e.number}`:null,gt=!!(et&&ae===et);o.useEffect(()=>{if(!d?.prContext||!_e||typeof _e.body=="string"&&_e.body.length>0)return;const Ke=`${t}#${_e.number}`;if(Ge.current.has(Ke))return;Ge.current.add(Ke),ve(Ke);let yt=!1;return d.prContext(t,_e.number,{includeDiff:!1,includeCheckDetails:!1}).then(Et=>{if(yt)return;const Ht=Et?.pr;Ht&&E(Se,ss=>!ss?.pr||ss.pr.number!==_e.number?ss:{...ss,pr:{...ss.pr,body:Ht.body||""}})}).catch(()=>{}).finally(()=>{yt||ve(Et=>Et===Ke?null:Et)}),()=>{yt=!0}},[t,d,_e,Se,E]),o.useEffect(()=>{if(!_e){K(!1),be(""),ye(""),Ve.current=null;return}const Ke=Ve.current!==null&&Ve.current!==_e.number;Ke&&K(!1),(!te||Ke)&&(be(_e.title||""),ye(_e.body||"")),Ve.current=_e.number},[te,_e]);const Lt=o.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(_e){Ae(!0),Xe(new Set),rt(!0);try{const Ke=await d.prContext(t,_e.number,{includeDiff:!1,includeCheckDetails:!0});de(Ke)}catch(Ke){const yt=Ke instanceof Error?Ke.message:String(Ke);H.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:yt})}finally{rt(!1)}}},[t,d,_e,c]),Ut=o.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(_e){Te(!0),he(!0);try{const Ke=await d.prContext(t,_e.number,{includeDiff:!1,includeCheckDetails:!1});Ze(Ke)}catch(Ke){const yt=Ke instanceof Error?Ke.message:String(Ke);H.error(c("gitView.pr.toast.loadCommentsFailed"),{description:yt})}finally{he(!1)}}},[t,d,_e,c]),mt=o.useCallback(Ke=>{if(!Ke)return"";const yt=Date.parse(Ke);return Number.isFinite(yt)?new Date(yt).toLocaleString():Ke},[]),Nt=o.useMemo(()=>{const Ke=p?.user?.login;return typeof Ke=="string"?Ke.trim():""},[p]),Xt=o.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),_t=o.useCallback(Ke=>{const yt=Nt.toLowerCase(),Et=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return Ke.replace(Et,(Ht,ss,Rt)=>{const Ps=`@${Rt}`,Qs=Rt.toLowerCase();return`${ss}[${Ps}](https://github.com/${Qs}${yt&&Qs===yt?"?oc-self-mention=1":""})`})},[Nt]),Gt=o.useMemo(()=>{const Ke=(We?.issueComments??[]).map(Ht=>({id:`issue-${Ht.id}`,body:Ht.body||"",authorName:Ht.author?.name||Ht.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Ht.author?.login||null,avatarUrl:Ht.author?.avatarUrl||null,createdAt:Ht.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),yt=(We?.reviewComments??[]).map(Ht=>({id:`review-${Ht.id}`,body:Ht.body||"",authorName:Ht.author?.name||Ht.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Ht.author?.login||null,avatarUrl:Ht.author?.avatarUrl||null,createdAt:Ht.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Ht.path||null,line:Ht.line??null})),Et=[...Ke,...yt];return Et.sort((Ht,ss)=>{const Rt=Ht.createdAt?Date.parse(Ht.createdAt):0,Ps=ss.createdAt?Date.parse(ss.createdAt):0,Qs=Number.isFinite(Rt)?Rt:0,Hs=Number.isFinite(Ps)?Ps:0;return Qs-Hs}),Et},[We,c]),lt=o.useCallback(()=>{if(!f)return H.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:Ke,currentModelId:yt,currentAgentName:Et,currentVariant:Ht}=xt.getState(),ss=Fl.getState().lastUsedProvider,Rt=Ke||ss?.providerID,Ps=yt||ss?.modelID;return!Rt||!Ps?(H.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:f,providerID:Rt,modelID:Ps,currentAgentName:Et??null,currentVariant:Ht??null}},[f,c]),Tt=o.useCallback((Ke,yt,Et,Ht)=>{Ot.getState().sendMessage(yt,Ke.providerID,Ke.modelID,Ke.currentAgentName??void 0,void 0,void 0,[{text:Et,synthetic:!0},{text:Ht,synthetic:!0}],Ke.currentVariant??void 0).catch(ss=>{const Rt=ss instanceof Error?ss.message:String(ss);H.error(c("gitView.pr.toast.sendMessageFailed"),{description:Rt})})},[c]),rs=o.useCallback(Ke=>{const yt=Ke.status||"unknown",Et=Ke.conclusion??void 0,Ht=Et?`${yt} / ${Et}`:yt,ss=Ke.app?.name||Ke.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:Ke.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:ss?`${ss} · ${Ht}`:Ht})]}),Ke.detailsUrl?s.jsx(ge,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:Ke.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(P,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),Ke.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:Ke.output.title}):null,Ke.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:Ke.output.summary}):null,Ke.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:Ke.output.text}):null,Array.isArray(Ke.annotations)&&Ke.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",Ke.annotations.length>20?` (showing 20/${Ke.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:Ke.annotations.slice(0,20).map((Rt,Ps)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro text-[var(--status-error)]",children:[Rt.title||Rt.level||"Issue",Rt.path?` · ${Rt.path}`:"",typeof Rt.startLine=="number"?`:${Rt.startLine}`:"",typeof Rt.endLine=="number"&&Rt.endLine!==Rt.startLine?`-${Rt.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:Rt.message}),Rt.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:Rt.rawDetails}):null]},`${Rt.path||"file"}:${Rt.startLine||Ps}:${Ps}`))})]}):null,Ke.job?.steps&&Ke.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:Ke.job.steps.map((Rt,Ps)=>{const Qs=(Rt.conclusion||"").toLowerCase(),Hs=Qs&&!["success","neutral","skipped"].includes(Qs),ts=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${Rt.number??Ps}:${Rt.name}`,Ns=Re.has(ts);return Hs?s.jsxs(fr,{open:Ns,children:[s.jsxs("button",{type:"button",onClick:()=>{Xe(jn=>{const sn=new Set(jn);return sn.has(ts)?sn.delete(ts):sn.add(ts),sn})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Hs?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Ns?s.jsx(P,{name:"arrow-down-s",className:"size-4"}):s.jsx(P,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:Rt.name}),Rt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Rt.conclusion}):null]}),s.jsx(hr,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof Rt.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",Rt.number]}):null,Rt.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",Rt.status]}):null,Rt.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",Rt.conclusion]}):null,Rt.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",mt(Rt.startedAt)]}):null,Rt.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",mt(Rt.completedAt)]}):null]})})]},ts):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:Rt.name}),Rt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Rt.conclusion}):null]},ts)})})]}):null]})},[Re,mt,c]),js=o.useCallback(async()=>{if(x("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!_e)return;const Ke=lt();if(Ke)try{const yt=await d.prContext(t,_e.number,{includeDiff:!1,includeCheckDetails:!0}),Ht=(yt.checkRuns??[]).filter(Hs=>{const ts=typeof Hs.conclusion=="string"?Hs.conclusion.toLowerCase():"";return ts?!["success","neutral","skipped"].includes(ts):!1});if(Ht.length===0){H.message(c("gitView.pr.toast.noFailedChecks"));return}const ss=await wn("github.pr.checks.review.visible"),Rt=await wn("github.pr.checks.review.instructions"),Ps=Ht.flatMap(Hs=>(Array.isArray(Hs.annotations)?Hs.annotations:[]).map(Ns=>({run:Hs.name,level:Ns.level,title:Ns.title,path:Ns.path,startLine:Ns.startLine,endLine:Ns.endLine,message:Ns.message,rawDetails:Ns.rawDetails}))),Qs=`GitHub PR failed checks (JSON)
|
|
39
|
+
${JSON.stringify({repo:yt.repo??null,pr:yt.pr??null,failedChecks:Ht,failedAnnotations:Ps},null,2)}`;Tt(Ke,ss,Rt,Qs)}catch(yt){const Et=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.loadChecksFailed"),{description:Et})}},[t,Tt,d,_e,lt,x,c]),ys=o.useCallback(async()=>{if(x("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!_e)return;const Ke=lt();if(Ke)try{const yt=await d.prContext(t,_e.number,{includeDiff:!1,includeCheckDetails:!1}),Et=yt.issueComments??[],Ht=yt.reviewComments??[];if(Et.length+Ht.length===0){H.message(c("gitView.pr.toast.noPrComments"));return}const Rt=await wn("github.pr.comments.review.visible"),Ps=await wn("github.pr.comments.review.instructions"),Qs=`GitHub PR comments (JSON)
|
|
40
|
+
${JSON.stringify({repo:yt.repo??null,pr:yt.pr??null,issueComments:Et,reviewComments:Ht},null,2)}`;Tt(Ke,Rt,Ps,Qs)}catch(yt){const Et=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:Et})}},[t,Tt,d,_e,lt,x,c]),vs=o.useCallback(async Ke=>{Te(!1),x("chat");const yt=lt();if(!yt)return;const Et=await wn("github.pr.comment.single.visible"),Ht=await wn("github.pr.comment.single.instructions"),ss=`GitHub PR comment (JSON)
|
|
41
|
+
${JSON.stringify({repo:We?.repo??null,pr:We?.pr??_e??null,comment:Ke},null,2)}`;Tt(yt,Et,Ht,ss)},[We,Tt,_e,lt,x]),Wt=o.useCallback(async Ke=>{await D(Se,Ke)},[Se,D]),He=o.useCallback(()=>{Ye.current.forEach(Ke=>{window.clearTimeout(Ke)}),Ye.current=k0.map(Ke=>window.setTimeout(()=>{Wt({force:!0,silent:!0,markInitialResolved:!0})},Ke))},[Wt]);o.useEffect(()=>{if(!d?.prStatus||!q||i.length<=1||it.current||fe?.pr)return;const Ke=`${w}::${Ce?.name??""}`;if(dt.current.has(Ke))return;dt.current.add(Ke);const yt=A0(i,r).filter(ss=>ss.name!==Ce?.name);if(yt.length===0)return;let Et=!1;return(async()=>{for(const ss of yt){if(Et)return;try{if(!(await d.prStatus(t,e,ss.name))?.pr)continue;if(Et)return;je(Ps=>Ps?.name===ss.name?Ps:ss);return}catch{}}})(),()=>{Et=!0}},[e,q,t,d,i,Ce?.name,w,fe?.pr,r]),o.useEffect(()=>{k(Se),I(Se,{directory:t,branch:e,remoteName:Ce?.name??null,canShow:q,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,q,t,k,d,m,p?.connected,Se,Ce?.name,I]),o.useEffect(()=>(j(Se),()=>{N(Se)}),[Se,j,N]),o.useEffect(()=>{const Ke=wc.get(w)??null;C(Ke?.title??Rm(e)),M(Ke?.body??""),R(Ke?.draft??!1),$(Ke?.targetBaseBranch?mi(Ke.targetBaseBranch):mi(n));const yt=vc(i,{selectedRemoteName:Ke?.selectedRemoteName,trackingBranch:r});je(Et=>Et?.name===yt?.name?Et:yt)},[n,e,i,w,r]),o.useEffect(()=>{Wt({markInitialResolved:!0})},[Se,Wt]),o.useEffect(()=>{!q||!Ce?.name||Wt({force:!0,silent:!0,markInitialResolved:!0})},[q,Wt,Ce?.name]),o.useEffect(()=>{const Ke=fe?.resolvedRemoteName?.trim();if(!Ke||it.current)return;const yt=i.find(Et=>Et.name===Ke);yt&&je(Et=>Et?.name===yt.name?Et:yt)},[i,fe?.resolvedRemoteName]),o.useEffect(()=>{const Ke=fe?.pr?.state==="closed"||fe?.pr?.state==="merged",yt=$e?.lastRefreshAt??0,Et=Date.now()-yt>6e4,Ht=!Ke&&Et,ss=()=>{Ht&&Wt({force:!0,silent:!0})},Rt=()=>{document.visibilityState==="visible"&&Ht&&Wt({force:!0,silent:!0})};return window.addEventListener("focus",ss),document.addEventListener("visibilitychange",Rt),()=>{window.removeEventListener("focus",ss),document.removeEventListener("visibilitychange",Rt)}},[Wt,fe?.pr?.state,$e?.lastRefreshAt]),o.useEffect(()=>{m&&p?.connected===!1&&Wt({force:!0,silent:!0,markInitialResolved:!0})},[m,p,Wt]),o.useEffect(()=>{!t||!e||wc.set(w,{title:T,body:S,draft:A,additionalContext:z,targetBaseBranch:V,selectedRemoteName:Ce?.name})},[w,T,S,A,z,V,Ce?.name,t,e]),o.useEffect(()=>{const Ke=Ye.current;return()=>{Ke.forEach(yt=>{window.clearTimeout(yt)}),Ye.current=[]}},[]);const kt=o.useCallback(async()=>{if(!O&&t){J(!0);try{const yt={base:we&&xe?.defaultBranchSha?xe.defaultBranchSha:V,head:e};z&&(yt.context=z);const Et=await vb(t,yt);Et.title?.trim()&&C(Et.title.trim()),Et.body?.trim()&&M(Et.body.trim()),l?.()}catch(Ke){const yt=Ke instanceof Error?Ke.message:String(Ke);H.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:yt})}finally{J(!1)}}},[z,e,xe?.defaultBranchSha,t,O,l,V,c,we]),Kt=o.useCallback(async()=>{if(!d?.prCreate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const Ke=T.trim();if(!Ke){H.error(c("gitView.pr.toast.titleRequired"));return}const yt=V.trim();if(!yt){H.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!we&&yt===e){H.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}ne(!0);try{const Et=Yd(r),Ht=we&&xe,ss=await d.prCreate({directory:t,title:Ke,head:e,base:yt,...S.trim()?{body:S}:{},draft:A,...Ht?{targetRepo:{owner:xe.owner,repo:xe.repo},headRemote:"origin"}:{...Ce?{remote:Ce.name}:{},...Et&&Et!==Ce?.name?{headRemote:Et}:{}}});H.success(c("gitView.pr.toast.prCreated")),E(Se,Rt=>Rt&&{...Rt,pr:ss}),await Wt({force:!0}),He()}catch(Et){const Ht=Et instanceof Error?Et.message:String(Et);H.error(c("gitView.pr.toast.createPrFailed"),{description:Ht})}finally{ne(!1)}},[S,e,xe,t,A,d,Se,Wt,He,Ce,V,T,r,E,we,c]),wt=o.useCallback(async Ke=>{if(!d?.prMerge){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}F(!0);try{const yt=await d.prMerge({directory:t,number:Ke.number,method:_});yt.merged?H.success(c("gitView.pr.toast.prMerged")):H.message(c("gitView.pr.toast.prNotMerged"),{description:yt.message||c("gitView.pr.notMergeable")}),await Wt({force:!0}),He()}catch(yt){const Et=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.mergeFailed"),{description:Et}),Ke.url&&jc(Ke.url)}finally{F(!1)}},[t,d,_,Wt,He,c]),Qt=o.useCallback(async Ke=>{if(!d?.prReady){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}W(!0);try{await d.prReady({directory:t,number:Ke.number}),H.success(c("gitView.pr.toast.markedReady")),await Wt({force:!0}),He()}catch(yt){const Et=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.markReadyFailed"),{description:Et}),Ke.url&&jc(Ke.url)}finally{W(!1)}},[t,d,Wt,He,c]),cs=o.useCallback(async Ke=>{if(!d?.prUpdate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const yt=re.trim();if(!yt){H.error(c("gitView.pr.toast.titleRequired"));return}le(!0);try{const Et=await d.prUpdate({directory:t,number:Ke.number,title:yt,body:pe});E(Se,Ht=>Ht&&{...Ht,pr:{...Ht.pr??Ke,...Et}}),K(!1),H.success(c("gitView.pr.toast.prUpdated")),await Wt({force:!0}),He()}catch(Et){const Ht=Et instanceof Error?Et.message:String(Et);H.error(c("gitView.pr.toast.updatePrFailed"),{description:Ht})}finally{le(!1)}},[t,pe,re,d,Se,Wt,He,E,c]);if(!q)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pullRequest.availableOnFeatureBranches")})]})});const Ls=fe?.repo?.url||null,Ss=we&&xe?.url?xe.url:Ls,ns=fe?.checks??null,Os=!!fe?.canMerge,Ks=!!fe?.connected,bt=m&&fe?.connected===!1,Mt=S0(fe),At=Mt?`var(--pr-${Mt})`:"var(--status-info)",ee=Mt==="draft"?"git-pr-draft":Mt==="merged"?"git-merge":Mt==="closed"?"git-close-pull-request":"git-pull-request",ht=_e?[`${_e.state}${_e.draft?" (draft)":""}`,_e.mergeable===!1?c("gitView.pr.notMergeable"):null,_e.state==="open"&&typeof _e.mergeableState=="string"&&_e.mergeableState&&_e.mergeableState!=="unknown"?_e.mergeableState:null].filter(Boolean).join(" · "):"",St=ns?ns.total>0?`${ns.success}/${ns.total} ${c("gitView.pr.checks.label")}`:`${ns.state} ${c("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[_e?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{jc(_e.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(P,{name:ee,className:"size-4 shrink-0",style:{color:At}})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(P,{name:ee,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.pullRequest.title")}),_e?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",_e.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Pe?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:Pe,onClick:()=>{Wt({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(P,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.refresh")})})]})]})]}),_e?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:At},children:ht}),ns?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${N0(ns.state)}`}),St]}):null,r&&Ce&&r.split("/")[0]!==Ce.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",Ce.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[bt?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(ge,{variant:"outline",size:"sm",onClick:g,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,L?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:L}),Ss?s.jsx(ge,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:Ss,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(P,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!_e&&!Z&&!L&&!bt?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),c("gitView.pr.checkingStatus")]}):_e?s.jsx("div",{className:"flex flex-col gap-2",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[te?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Bt,{value:re,onChange:Ke=>be(Ke.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y}),s.jsx(hn,{value:pe,onChange:Ke=>ye(Ke.target.value),className:"min-h-[120px] bg-background/80",placeholder:c("gitView.pr.placeholder.description"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:_e.title}),_e.body?.trim()?s.jsx(to,{content:_e.body,className:"typography-markdown-body text-muted-foreground break-words mt-1"}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:c(gt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),Os&&_e.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,Os?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.noMergePermission")})]}),s.jsxs("div",{className:"order-first w-full flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[_e.state==="open"?te?s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{K(!1),be(_e.title||""),ye(_e.body||"")},disabled:G,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(P,{name:"close",className:"size-4"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>cs(_e),disabled:G||!re.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:G?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"check",className:"size-4"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.savePr")})})]})]}):s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>K(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(P,{name:"edit",className:"size-4"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,ns?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Lt,disabled:ze,"aria-label":c("gitView.pr.actions.openChecksAria"),children:ze?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"information",className:"size-4"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,ns?.failure?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:js,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(P,{name:"error-warning",className:"size-4"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Ut,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(P,{name:"chat-4",className:"size-4"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.openComments")})})]}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:ys,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(P,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),Os&&_e.draft&&_e.state==="open"?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Qt(_e),disabled:U||oe||G||te,"aria-label":c("gitView.pr.actions.markReadyAria"),children:U?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:Os?s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:_,onValueChange:Ke=>X(Ke),disabled:oe||_e.state!=="open",children:[s.jsx(as,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(us,{})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"squash",children:c("gitView.pr.mergeMethod.squash")}),s.jsx(Ft,{value:"merge",children:c("gitView.pr.mergeMethod.merge")}),s.jsx(Ft,{value:"rebase",children:c("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>wt(_e),disabled:oe||U||_e.state!=="open"||_e.draft||G||te,"aria-label":c("gitView.pr.actions.mergePrAria"),children:oe?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"git-merge",className:"size-4"})})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.mergePr")})})]})]}):null})]})]})}):s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",V," ",s.jsxs("span",{className:"opacity-60",children:["(",we&&xe?"upstream":"remote",")"]})]})]}),Ss?s.jsx(ge,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:Ss,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(P,{name:"external-link",className:"size-4"}),c("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.title")}),s.jsx(Bt,{value:T,onChange:Ke=>C(Ke.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.baseBranch")}),Y.length>0?s.jsxs(is,{value:V,onValueChange:$,children:[s.jsx(as,{className:"h-9",children:s.jsx(us,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(os,{children:Y.map(Ke=>s.jsx(Ft,{value:Ke,children:Ke},Ke))})]}):s.jsx(Bt,{value:V,onChange:Ke=>$(Ke.target.value),placeholder:c("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.description")}),s.jsx(hn,{value:S,onChange:Ke=>M(Ke.target.value),className:"min-h-[110px]",placeholder:c("gitView.pr.placeholder.whatChanged"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":A,onClick:()=>R(Ke=>!Ke),onKeyDown:Ke=>{(Ke.key===" "||Ke.key==="Enter")&&(Ke.preventDefault(),R(yt=>!yt))},children:[s.jsx(ds,{size:"sm",checked:A,onChange:Ke=>R(Ke),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),v?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx(ge,{variant:"outline",size:"sm",onClick:()=>Ne(!0),children:z.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),z.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:c("gitView.pr.additionalContext.added")})})]}):s.jsxs(fr,{open:ie,onOpenChange:ue,children:[s.jsxs(Pr,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:ie?c("gitView.pr.actions.hide"):z.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(hr,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(hn,{value:z,onChange:Ke=>B(Ke.target.value),className:"min-h-[100px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})})]}),s.jsx($r,{open:se,onClose:()=>Ne(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(ge,{size:"sm",onClick:()=>Ne(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(hn,{value:z,onChange:Ke=>B(Ke.target.value),className:"min-h-[200px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ge,{variant:"outline",size:"sm",onClick:kt,disabled:O||Q,children:[O?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"ai-generate-2",className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(ge,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Kt,disabled:Q||!Ks||!V.trim()||!we&&V.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:Q?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(hs,{open:Ee,onOpenChange:Ae,children:s.jsxs(fs,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(bs,{children:[s.jsxs(gs,{className:"flex items-center gap-2",children:[s.jsx(P,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.checkDetails.title")]}),s.jsx(Is,{children:_e?c("gitView.pr.numberLabel",{number:_e.number}):c("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[ze?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,ze?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(Je?.checkRuns)&&Je?.checkRuns.length>0?Je.checkRuns.map((Ke,yt)=>{const Et=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${Ke.name}:${yt}`;return s.jsx("div",{className:"p-1",children:rs(Ke)},Et)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(hs,{open:qe,onOpenChange:Te,children:s.jsxs(fs,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(bs,{children:s.jsxs(gs,{className:"flex items-center gap-2",children:[s.jsx(P,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.comments.title"),_e?s.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.numberLabel",{number:_e.number})}):null]})}),s.jsxs(po,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[Qe?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,Qe?null:s.jsx("div",{className:"space-y-4",children:Gt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Gt.map((Ke,yt)=>{const Et=(Ke.authorName||"?").charAt(0).toUpperCase(),Ht=yt===Gt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Ht?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:Ke.avatarUrl?s.jsx("img",{src:Ke.avatarUrl,alt:Ke.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Et})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[Ke.authorName,Ke.authorLogin&&Ke.authorLogin!==Ke.authorName?` · @${Ke.authorLogin}`:""]}),Ke.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:mt(Ke.createdAt)}):null,s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs(ge,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{vs(Ke)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(P,{name:"ai-generate-2",className:"size-3.5"}),c("gitView.pr.actions.sendToAgent")]})}),s.jsx(Dt,{children:s.jsx("p",{children:c("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Ke.context,Ke.path?` · ${Ke.path}`:"",Ke.line?`:${Ke.line}`:""]}),s.jsx(to,{content:_t(Ke.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Xt].filter(Boolean).join(" ")})]})]},Ke.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},M0=t=>{const e=at.c(150),{open:n,onOpenChange:r,conflictFiles:i,directory:a,operation:l,onAbort:c,onClearState:d}=t;let p;e[0]!==i?(p=i===void 0?[]:i,e[0]=i,e[1]=p):p=e[1];const m=p,{t:u}=ut(),h=Ot(E0),x=Ot(R0),f=zi(F0),v=zi(L0),y=Ie(O0),[g,w]=o.useState(!1),[b,k]=o.useState(null),[I,j]=o.useState(null);let N,D;e[2]!==a||e[3]!==n||e[4]!==u?(N=()=>{!n||!a||(w(!0),j(null),k(null),wb(a).then(ke=>{k(ke)}).catch(ke=>{const xe=ke instanceof Error?ke.message:u("gitView.conflict.loadFailed");j(xe)}).finally(()=>{w(!1)}))},D=[n,a,u],e[2]=a,e[3]=n,e[4]=u,e[5]=N,e[6]=D):(N=e[5],D=e[6]),o.useEffect(N,D);let E;e[7]!==b||e[8]!==a||e[9]!==l?(E=async()=>{if(!b)return null;const ke=l==="merge"?"merge":"rebase",xe=b.headInfo||(l==="merge"?"MERGE_HEAD":"REBASE_HEAD"),me=l==="merge"?"git commit --no-edit":"git rebase --continue",Me=await wn("git.conflict.resolve.visible",{operation_label:ke,head_ref:xe}),Ue=await wn("git.conflict.resolve.instructions",{operation_label:ke,directory:a,operation:l,head_info:b.headInfo||"N/A",continue_cmd:me}),q=`${ke} conflict context (JSON)
|
|
42
|
+
${JSON.stringify({directory:a,operation:b.operation,headInfo:b.headInfo,statusPorcelain:b.statusPorcelain,unmergedFiles:b.unmergedFiles,diff:b.diff},null,2)}`;return{visibleText:Me,instructionsText:Ue,payloadText:q}},e[7]=b,e[8]=a,e[9]=l,e[10]=E):E=e[10];const T=E;let C;e[11]!==c||e[12]!==r?(C=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=C):C=e[13];const S=C;let M;e[14]!==d||e[15]!==r?(M=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=M):M=e[16];const A=M;let R;e[17]!==T||e[18]!==x||e[19]!==d||e[20]!==r||e[21]!==y||e[22]!==f||e[23]!==v||e[24]!==u?(R=async()=>{const ke=await T();if(!ke){H.error(u("gitView.conflict.noDetailsAvailable"));return}if(!x){H.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}f(ke.visibleText,"replace"),v([{text:ke.instructionsText,synthetic:!0},{text:ke.payloadText,synthetic:!0}]),y("chat"),d?.(),r(!1)},e[17]=T,e[18]=x,e[19]=d,e[20]=r,e[21]=y,e[22]=f,e[23]=v,e[24]=u,e[25]=R):R=e[25];const z=R;let B;e[26]!==T||e[27]!==a||e[28]!==d||e[29]!==r||e[30]!==h||e[31]!==y||e[32]!==u?(B=async()=>{const ke=await T();if(!ke){H.error(u("gitView.conflict.noDetailsAvailable"));return}h({directoryOverride:a,initialPrompt:ke.visibleText,syntheticParts:[{text:ke.instructionsText,synthetic:!0},{text:ke.payloadText,synthetic:!0}]}),y("chat"),d?.(),r(!1)},e[26]=T,e[27]=a,e[28]=d,e[29]=r,e[30]=h,e[31]=y,e[32]=u,e[33]=B):B=e[33];const V=B;let $,_,X,O,J,Q,ne,G,le,oe,F,U,W,te,K,ae,ve,re,be,pe,ye,ie;if(e[34]!==b||e[35]!==m||e[36]!==x||e[37]!==S||e[38]!==A||e[39]!==z||e[40]!==V||e[41]!==g||e[42]!==I||e[43]!==r||e[44]!==n||e[45]!==l||e[46]!==u){const ke=u(l==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),xe=b?.unmergedFiles||m;X=hs,ye=n,ie=r,_=fs,pe="max-w-md w-[calc(100vw-2rem)]",te="flex flex-col gap-4 overflow-hidden";let me;e[69]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(P,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=me):me=e[69];const Me=s.jsxs("div",{className:"flex items-center gap-2",children:[me,s.jsx(gs,{children:u("gitView.conflict.detectedTitle",{operation:ke})})]});let Ue;e[70]!==l||e[71]!==u?(Ue=u("gitView.conflict.detectedDescription",{operation:l}),e[70]=l,e[71]=u,e[72]=Ue):Ue=e[72];let q;e[73]!==Ue?(q=s.jsx(Is,{children:Ue}),e[73]=Ue,e[74]=q):q=e[74],e[75]!==Me||e[76]!==q?(K=s.jsxs(bs,{children:[Me,q]}),e[75]=Me,e[76]=q,e[77]=K):K=e[77],e[78]!==g||e[79]!==u?(ae=g&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:u("gitView.conflict.loading")})]}),e[78]=g,e[79]=u,e[80]=ae):ae=e[80],e[81]!==I||e[82]!==u?(ve=I&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:u("gitView.conflict.errorLoadingDetails",{message:I})}),e[81]=I,e[82]=u,e[83]=ve):ve=e[83],e[84]!==xe||e[85]!==u?(re=xe.length>0&&s.jsxs("div",{className:"space-y-2 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:xe.length})]}),s.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:s.jsx("ul",{className:"space-y-1",children:xe.map($0)})})]}),e[84]=xe,e[85]=u,e[86]=re):re=e[86],e[87]!==b||e[88]!==u?(be=b?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:b.headInfo})]}),e[87]=b,e[88]=u,e[89]=be):be=e[89],F="flex flex-col gap-2 pt-2";let Se;e[90]!==V?(Se=()=>{V()},e[90]=V,e[91]=Se):Se=e[91];const $e=g||!b;let Pe;e[92]!==g?(Pe=g?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"add",className:"size-4"}),e[92]=g,e[93]=Pe):Pe=e[93];let fe;e[94]!==u?(fe=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=fe):fe=e[95],e[96]!==Se||e[97]!==$e||e[98]!==Pe||e[99]!==fe?(U=s.jsxs(ge,{variant:"default",onClick:Se,disabled:$e,className:"w-full gap-2",children:[Pe,fe]}),e[96]=Se,e[97]=$e,e[98]=Pe,e[99]=fe,e[100]=U):U=e[100];let L;e[101]!==z?(L=()=>{z()},e[101]=z,e[102]=L):L=e[102];const Z=g||!b||!x;let Y;e[103]!==g?(Y=g?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"chat-1",className:"size-4"}),e[103]=g,e[104]=Y):Y=e[104];let Ee;e[105]!==u?(Ee=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=Ee):Ee=e[106],e[107]!==L||e[108]!==Z||e[109]!==Y||e[110]!==Ee?(W=s.jsxs(ge,{variant:"outline",onClick:L,disabled:Z,className:"w-full gap-2",children:[Y,Ee]}),e[107]=L,e[108]=Z,e[109]=Y,e[110]=Ee,e[111]=W):W=e[111],le="flex gap-2 pt-1";let Ae;e[112]!==u?(Ae=u("gitView.conflict.continueLater"),e[112]=u,e[113]=Ae):Ae=e[113],e[114]!==A||e[115]!==Ae?(oe=s.jsx(ge,{variant:"ghost",size:"sm",onClick:A,className:"flex-1",children:Ae}),e[114]=A,e[115]=Ae,e[116]=oe):oe=e[116],$=ge,O="destructive",J="sm",Q=S,ne="flex-1",G=u("gitView.conflict.abortOperation",{operation:ke}),e[34]=b,e[35]=m,e[36]=x,e[37]=S,e[38]=A,e[39]=z,e[40]=V,e[41]=g,e[42]=I,e[43]=r,e[44]=n,e[45]=l,e[46]=u,e[47]=$,e[48]=_,e[49]=X,e[50]=O,e[51]=J,e[52]=Q,e[53]=ne,e[54]=G,e[55]=le,e[56]=oe,e[57]=F,e[58]=U,e[59]=W,e[60]=te,e[61]=K,e[62]=ae,e[63]=ve,e[64]=re,e[65]=be,e[66]=pe,e[67]=ye,e[68]=ie}else $=e[47],_=e[48],X=e[49],O=e[50],J=e[51],Q=e[52],ne=e[53],G=e[54],le=e[55],oe=e[56],F=e[57],U=e[58],W=e[59],te=e[60],K=e[61],ae=e[62],ve=e[63],re=e[64],be=e[65],pe=e[66],ye=e[67],ie=e[68];let ue;e[117]!==$||e[118]!==O||e[119]!==J||e[120]!==Q||e[121]!==ne||e[122]!==G?(ue=s.jsx($,{variant:O,size:J,onClick:Q,className:ne,children:G}),e[117]=$,e[118]=O,e[119]=J,e[120]=Q,e[121]=ne,e[122]=G,e[123]=ue):ue=e[123];let se;e[124]!==le||e[125]!==oe||e[126]!==ue?(se=s.jsxs("div",{className:le,children:[oe,ue]}),e[124]=le,e[125]=oe,e[126]=ue,e[127]=se):se=e[127];let Ne;e[128]!==F||e[129]!==U||e[130]!==W||e[131]!==se?(Ne=s.jsxs("div",{className:F,children:[U,W,se]}),e[128]=F,e[129]=U,e[130]=W,e[131]=se,e[132]=Ne):Ne=e[132];let Ce;e[133]!==te||e[134]!==K||e[135]!==ae||e[136]!==ve||e[137]!==re||e[138]!==be||e[139]!==Ne?(Ce=s.jsxs("div",{className:te,children:[K,ae,ve,re,be,Ne]}),e[133]=te,e[134]=K,e[135]=ae,e[136]=ve,e[137]=re,e[138]=be,e[139]=Ne,e[140]=Ce):Ce=e[140];let je;e[141]!==_||e[142]!==pe||e[143]!==Ce?(je=s.jsx(_,{className:pe,children:Ce}),e[141]=_,e[142]=pe,e[143]=Ce,e[144]=je):je=e[144];let we;return e[145]!==X||e[146]!==ye||e[147]!==ie||e[148]!==je?(we=s.jsx(X,{open:ye,onOpenChange:ie,children:je}),e[145]=X,e[146]=ye,e[147]=ie,e[148]=je,e[149]=we):we=e[149],we};function E0(t){return t.openNewSessionDraft}function R0(t){return t.currentSessionId}function F0(t){return t.setPendingInputText}function L0(t){return t.setPendingSyntheticParts}function O0(t){return t.setActiveMainTab}function $0(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const B0=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:i})=>{const{t:a}=ut(),[l,c]=o.useState(!0),[d,p]=o.useState(!1),m=a(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{p(!0);try{await i(l),e(!1)}catch(x){const f=x instanceof Error?x.message:`Failed to ${n}`;H.error(f)}finally{p(!1)}},h=()=>{d||e(!1)};return s.jsx(hs,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(fs,{className:"max-w-md",children:[s.jsxs(bs,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(gs,{children:a("gitView.stash.title")})]}),s.jsx(Is,{children:a("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:a("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:a("gitView.stash.stepStash")}),s.jsxs("li",{children:[a(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",a(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),l&&s.jsx("li",{children:a("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(ds,{checked:l,onChange:c,disabled:d,ariaLabel:a("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&c(!l),children:a("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(Vs,{className:"gap-2",children:[s.jsx(ge,{variant:"ghost",size:"sm",onClick:h,disabled:d,children:a("gitView.common.cancel")}),s.jsx(ge,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.common.processing")]}):a("gitView.stash.confirmButton",{operation:m})})]})]})})},z0=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:i,hasUnresolvedConflicts:a=!1,isLoading:l=!1})=>{const{t:c}=ut(),[d,p]=o.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),h=m?"merge":u?"rebase":null;if(!h)return null;const x=async()=>{p("continue");try{await n()}finally{p(null)}},f=async()=>{p("abort");try{await r()}finally{p(null)}},v=d!==null,y=c(h==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),g=h==="merge"?"git-merge":"git-branch";let w="";return t?w=t.message?c("gitView.operation.mergingMessage",{message:t.message}):c("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(w=e.headName?c("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):c("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(P,{name:g,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:c("gitView.operation.inProgressTitle",{operation:y})}),w&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:w})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a&&i&&s.jsxs(ge,{variant:"outline",size:"sm",onClick:i,disabled:v||l,className:"gap-1.5",children:[s.jsx(P,{name:"sparkling",className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(ge,{variant:"ghost",size:"sm",onClick:f,disabled:v||l,className:"gap-1.5",children:[d==="abort"?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"close",className:"size-4"}),c("gitView.operation.abort")]}),!a&&s.jsxs(ge,{variant:"default",size:"sm",onClick:x,disabled:v||l,className:"gap-1.5",children:[d==="continue"?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"check",className:"size-4"}),c("gitView.operation.continue")]})]}),a&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:c("gitView.operation.resolveConflictsHint")})]})})},V0=t=>{const e=at.c(104),{currentBranch:n,localBranches:r,remoteBranches:i,onMerge:a,onRebase:l,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:h}=t,x=c===void 0?!1:c,f=d===void 0?!1:d,v=p===void 0?[]:p,y=u===void 0?"dialog":u,{t:g}=ut(),[w,b]=o.useState(!1),[k,I]=o.useState("merge"),[j,N]=o.useState(null),[D,E]=o.useState(!1),[T,C]=o.useState(""),S=o.useRef(null),M=o.useRef(null),A=x||f,R=n||g("gitView.branch.currentBranchFallback"),z=v.length>0&&v.every(_0),B=v.some(U0);let V;e[0]===Symbol.for("react.memo_cache_sentinel")?(V=()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},e[0]=V):V=e[0],o.useEffect(V,[v]);let $;if(e[1]!==T||e[2]!==n||e[3]!==r||e[4]!==i){e:{const L=T.toLowerCase();let Z;e[6]!==i?(Z=new Set(i.map(W0).filter(Boolean)),e[6]=i,e[7]=Z):Z=e[7];const Y=Z;let Ee;e[8]!==n||e[9]!==Y?(Ee=Je=>Je!==n&&!Y.has(Je),e[8]=n,e[9]=Y,e[10]=Ee):Ee=e[10];const Ae=r.filter(Ee);if(!L){$=Ae;break e}$=Ae.filter(Je=>Je.toLowerCase().includes(L))}e[1]=T,e[2]=n,e[3]=r,e[4]=i,e[5]=$}else $=e[5];const _=$;let X;if(e[11]!==T||e[12]!==i){e:{const L=T.toLowerCase();if(!L){X=i;break e}X=i.filter(Z=>Z.toLowerCase().includes(L))}e[11]=T,e[12]=i,e[13]=X}else X=e[13];const O=X;let J;e[14]!==h||e[15]!==r||e[16]!==i?(J=()=>h&&(i.includes(h)||r.includes(h))?h:null,e[14]=h,e[15]=r,e[16]=i,e[17]=J):J=e[17];const Q=J;let ne;e[18]!==Q||e[19]!==b?(ne=()=>{b(!0),N(Q()),I("merge"),C("")},e[18]=Q,e[19]=b,e[20]=ne):ne=e[20];const G=ne;let le;e[21]===Symbol.for("react.memo_cache_sentinel")?(le=L=>{N(L),E(!1),C("")},e[21]=le):le=e[21];const oe=le;let F;e[22]!==a||e[23]!==l||e[24]!==k||e[25]!==j?(F=()=>{j&&(k==="merge"?a(j):l(j))},e[22]=a,e[23]=l,e[24]=k,e[25]=j,e[26]=F):F=e[26];const U=F;let W;e[27]!==f||e[28]!==b?(W=()=>{f||(N(null),I("merge"),C(""),b(!1))},e[27]=f,e[28]=b,e[29]=W):W=e[29];const te=W,K=()=>{f&&!z||(z&&m?.(),N(null),I("merge"),C(""),b(!1))};let ae,ve;e[30]!==D?(ae=()=>{D||C("")},ve=[D],e[30]=D,e[31]=ae,e[32]=ve):(ae=e[31],ve=e[32]),o.useEffect(ae,ve);let re,be;e[33]!==y||e[34]!==Q||e[35]!==j?(re=()=>{y!=="inline"||j||N(Q())},be=[y,Q,j],e[33]=y,e[34]=Q,e[35]=j,e[36]=re,e[37]=be):(re=e[36],be=e[37]),o.useEffect(re,be);const ie=f?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:M,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:v.map(K0)})}),z?y==="dialog"?s.jsx(Vs,{children:s.jsx(ge,{variant:"default",size:"sm",onClick:K,children:g(B?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(ge,{variant:"default",size:"sm",onClick:K,children:g(B?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:g("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>I("merge"),className:ce("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",k==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"git-merge",className:ce("size-4",k==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:ce("typography-ui-label",k==="merge"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>I("rebase"),className:ce("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",k==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"git-branch",className:ce("size-4",k==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:ce("typography-ui-label",k==="rebase"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:k==="merge"?g("gitView.branch.branchToMergeInto",{branch:R}):g("gitView.branch.branchToRebaseOnto")}),s.jsxs(Fs,{open:D,onOpenChange:E,modal:!1,children:[s.jsx(Es,{asChild:!0,children:s.jsxs(ge,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:ce("truncate",!j&&"text-muted-foreground"),children:j||g("gitView.branch.selectBranch")}),s.jsx(P,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Rs,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(_i,{className:"h-full min-h-0",children:[s.jsx(xi,{ref:S,placeholder:g("gitView.branch.searchPlaceholder"),value:T,onValueChange:C,onKeyDown:H0}),s.jsxs(Ui,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(Wi,{children:g("gitView.branch.empty")}),_.length>0&&s.jsx(zn,{heading:g("gitView.branch.localBranches"),children:_.map(L=>s.jsx(kn,{onSelect:()=>oe(L),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:L})},`local-${L}`))}),_.length>0&&O.length>0?s.jsx(Ti,{}):null,O.length>0&&s.jsx(zn,{heading:g("gitView.branch.remoteBranches"),children:O.map(L=>s.jsx(kn,{onSelect:()=>oe(L),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:L})},`remote-${L}`))})]})]})})]})]}),j?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:k==="merge"?s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})," ",g("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})]}):s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})," ",g("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})]})})}):null,y==="dialog"?s.jsxs(Vs,{className:"gap-2 pt-1",children:[s.jsx(ge,{variant:"ghost",size:"sm",onClick:te,children:g("gitView.common.cancel")}),s.jsx(ge,{variant:"default",size:"sm",onClick:U,disabled:!j,className:"gap-1.5",children:k==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"git-merge",className:"size-4"}),g("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"git-branch",className:"size-4"}),g("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ge,{variant:"destructive",size:"sm",onClick:te,disabled:A,children:g("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(ge,{variant:"default",size:"sm",onClick:U,disabled:A||!j,children:g(k==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(y==="inline"){let L;e[38]!==g?(L=g("gitView.branch.updateTitle"),e[38]=g,e[39]=L):L=e[39];let Z;e[40]!==L?(Z=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:L}),e[40]=L,e[41]=Z):Z=e[41];let Y;e[42]!==g?(Y=g("gitView.branch.updateDescriptionPrefix"),e[42]=g,e[43]=Y):Y=e[43];let Ee;e[44]!==R?(Ee=s.jsx("span",{className:"font-mono text-foreground",children:R}),e[44]=R,e[45]=Ee):Ee=e[45];let Ae;e[46]!==Y||e[47]!==Ee?(Ae=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Y," ",Ee,"."]}),e[46]=Y,e[47]=Ee,e[48]=Ae):Ae=e[48];let Je;e[49]!==Z||e[50]!==Ae?(Je=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[Z,Ae]})}),e[49]=Z,e[50]=Ae,e[51]=Je):Je=e[51];let de;e[52]!==ie?(de=s.jsx("div",{className:"pt-3",children:ie}),e[52]=ie,e[53]=de):de=e[53];let ze;return e[54]!==Je||e[55]!==de?(ze=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Je,de]}),e[54]=Je,e[55]=de,e[56]=ze):ze=e[56],ze}let ue;e[57]!==f?(ue=f?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"git-merge",className:"size-4"}),e[57]=f,e[58]=ue):ue=e[58];let se;e[59]!==g?(se=g("gitView.branch.mergeRebase"),e[59]=g,e[60]=se):se=e[60];let Ne;e[61]!==se?(Ne=s.jsx("span",{children:se}),e[61]=se,e[62]=Ne):Ne=e[62];let Ce;e[63]!==G||e[64]!==A||e[65]!==ue||e[66]!==Ne?(Ce=s.jsx(It,{asChild:!0,children:s.jsxs(ge,{variant:"outline",size:"sm",className:"gap-1.5",onClick:G,disabled:A,children:[ue,Ne]})}),e[63]=G,e[64]=A,e[65]=ue,e[66]=Ne,e[67]=Ce):Ce=e[67];let je;e[68]!==g?(je=g("gitView.branch.mergeRebaseTooltip"),e[68]=g,e[69]=je):je=e[69];let we;e[70]!==je?(we=s.jsx(Dt,{sideOffset:8,children:je}),e[70]=je,e[71]=we):we=e[71];let ke;e[72]!==Ce||e[73]!==we?(ke=s.jsxs(Pt,{children:[Ce,we]}),e[72]=Ce,e[73]=we,e[74]=ke):ke=e[74];let xe;e[75]!==K||e[76]!==b?(xe=L=>{L?b(!0):K()},e[75]=K,e[76]=b,e[77]=xe):xe=e[77];let me;e[78]!==g?(me=g("gitView.branch.updateTitle"),e[78]=g,e[79]=me):me=e[79];let Me;e[80]!==me?(Me=s.jsx(gs,{children:me}),e[80]=me,e[81]=Me):Me=e[81];let Ue;e[82]!==B||e[83]!==f||e[84]!==k||e[85]!==z||e[86]!==g||e[87]!==R?(Ue=f?g(z?B?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":k==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[g("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R}),"."]}),e[82]=B,e[83]=f,e[84]=k,e[85]=z,e[86]=g,e[87]=R,e[88]=Ue):Ue=e[88];let q;e[89]!==Ue?(q=s.jsx(Is,{children:Ue}),e[89]=Ue,e[90]=q):q=e[90];let Se;e[91]!==Me||e[92]!==q?(Se=s.jsxs(bs,{children:[Me,q]}),e[91]=Me,e[92]=q,e[93]=Se):Se=e[93];let $e;e[94]!==ie||e[95]!==Se?($e=s.jsxs(fs,{className:"max-w-md",children:[Se,ie]}),e[94]=ie,e[95]=Se,e[96]=$e):$e=e[96];let Pe;e[97]!==w||e[98]!==xe||e[99]!==$e?(Pe=s.jsx(hs,{open:w,onOpenChange:xe,children:$e}),e[97]=w,e[98]=xe,e[99]=$e,e[100]=Pe):Pe=e[100];let fe;return e[101]!==ke||e[102]!==Pe?(fe=s.jsxs(s.Fragment,{children:[ke,Pe]}),e[101]=ke,e[102]=Pe,e[103]=fe):fe=e[103],fe};function _0(t){return t.status==="done"||t.status==="error"}function U0(t){return t.status==="error"}function W0(t){return t.slice(t.indexOf("/")+1)}function K0(t,e){return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"mt-0.5 shrink-0",children:[t.status==="running"&&s.jsx(P,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(P,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(P,{name:"close",className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className:ce("typography-micro",t.status==="error"&&"text-destructive",t.status==="done"&&"text-muted-foreground",t.status==="running"&&"text-foreground",t.status==="pending"&&"text-muted-foreground/60"),children:t.message})]},e)}function H0(t){return t.stopPropagation()}const Fm="oc.git.actionTab",G0=t=>t==="commit"||t==="branch"||t==="pr",Wh="gitmojiCache",q0=1e3*60*60*24*7,Kh="1",Y0=40,Q0=20,J0="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Lm={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Hh=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},X0=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(Wh);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==Kh||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Hh),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Z0=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:Kh};localStorage.setItem(Wh,JSON.stringify(e))}catch{return}},eN=t=>Date.now()-t.fetchedAt<q0,tN=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,i=n.match(r);if(i){const c=i[1],d=Lm[c];if(d)return e.find(p=>p.code===d)||null}const a=n.split(" ")[0],l=Lm[a];return l&&e.find(c=>c.code===l)||null},Om=new Map,ji=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Gh=()=>{const{t}=ut(),{git:e}=Pn(),n=Ir(),[r,i]=o.useState(null),[a,l]=o.useState(!1),c=Ot(Oe=>Oe.currentSessionId),d=Ot(Oe=>Oe.newSessionDraft),p=Ot(Oe=>Oe.setDraftBootstrapPendingDirectory),m=Ot(Oe=>Oe.worktreeMetadata),u=Ot(Oe=>Oe.availableWorktrees),h=ji(n),x=o.useMemo(()=>{if(!h)return;const Oe=u.find(tt=>ji(tt.path)===h);if(Oe)return Oe;for(const tt of m.values())if(ji(tt.path)===h)return tt},[u,h,m]),f=o.useMemo(()=>{if(c)return m.get(c)??x;if(d?.open)return x},[c,x,d?.open,m]),{profiles:v,globalIdentity:y,defaultGitIdentityId:g,loadProfiles:w,loadGlobalIdentity:b,loadDefaultGitIdentityId:k}=Qn(Br(Oe=>({profiles:Oe.profiles,globalIdentity:Oe.globalIdentity,defaultGitIdentityId:Oe.defaultGitIdentityId,loadProfiles:Oe.loadProfiles,loadGlobalIdentity:Oe.loadGlobalIdentity,loadDefaultGitIdentityId:Oe.loadDefaultGitIdentityId}))),I=Ed(n??null),j=Ol(n??null),N=Wf(Oe=>c?Oe.getAttachment(c):void 0),D=N?jb(N):[],E=N&&!N.degraded&&!N.legacy?N.worktreeRoot??void 0:void 0,T=B1(n,f,j?.current??void 0),C=Rd(n??null),S=Nb(n??null),M=Sb(n??null),A=Fd(n??null),R=kb(n??null),z=tn(Oe=>Oe.setActiveDirectory),B=tn(Oe=>Oe.fetchAll),V=tn(Oe=>Oe.ensureAll),$=tn(Oe=>Oe.fetchStatus),_=tn(Oe=>Oe.fetchBranches),X=tn(Oe=>Oe.fetchLog),O=tn(Oe=>Oe.fetchIdentity),J=tn(Oe=>Oe.prefetchDiffs),Q=tn(Oe=>Oe.setLogMaxCount),ne=Ie(Oe=>Oe.isMobile),G=Ie(Oe=>Oe.openContextDiff),le=Ie(Oe=>Oe.navigateToDiff),oe=Ie(Oe=>Oe.setRightSidebarOpen),F=o.useRef(null);o.useEffect(()=>{if(!n){i(null),l(!1);return}let Oe=!1,tt=null;const nt=async()=>{try{const ct=await Pb(n);if(Oe)return;i(ct.status),ct.status==="pending"&&(tt=window.setTimeout(()=>{nt()},500))}catch{Oe||i(null)}};return nt(),()=>{Oe=!0,tt!==null&&window.clearTimeout(tt)}},[n]),o.useEffect(()=>{const Oe=F.current;F.current=r,!(!n||!e)&&(Oe==="pending"&&r==="ready"&&(l(!0),B(n,e).finally(()=>{window.setTimeout(()=>{l(!1)},1200)})),r==="failed"&&(p(null),l(!1)))},[n,B,e,p,r]);const U=ji(d?.bootstrapPendingDirectory??null),W=!!(n&&U&&U===ji(n)),K=!!(n&&(r==="pending"||W))||a,ae=o.useMemo(()=>n?Om.get(n)??null:null,[n]),ve=xt(Oe=>Oe.settingsGitmojiEnabled),[re,be]=o.useState(null);o.useEffect(()=>{const Oe=E||T?.projectDirectory;if(!Oe){be(null);return}let tt=!1;return fo(Oe).then(nt=>{if(tt)return;const ct=nt.trim();be(ct&&ct!=="HEAD"?ct:null)}).catch(()=>{tt||be(null)}),()=>{tt=!0}},[E,T?.projectDirectory]);const[pe,ye]=o.useState(ae?.commitMessage??""),[ie,ue]=o.useState([]),[se,Ne]=o.useState(!1),Ce=o.useRef(null),[je,we]=o.useState(null),[ke,xe]=o.useState(!1),[me,Me]=o.useState(null),[Ue,q]=o.useState(25),[Se,$e]=o.useState(!1),{triggerFireworks:Pe}=R1(),fe=o.useRef(new Map),L=o.useRef(0),Z=o.useCallback(()=>{L.current+=1,$e(!0)},[]),Y=o.useCallback(()=>{L.current=Math.max(0,L.current-1),L.current===0&&$e(!1)},[]),[Ee,Ae]=o.useState(()=>new Set(ae?.selectedPaths??[])),[Je,de]=o.useState(!1),[ze,rt]=o.useState(new Set),[Re,Xe]=o.useState(!1),[qe,Te]=o.useState(0),[We,Ze]=o.useState(!1),[Qe,he]=o.useState(ae?.generatedHighlights??[]),Ge=o.useCallback(()=>{const Oe=Ce.current;Oe&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Oe.scrollTo({top:Oe.scrollHeight,behavior:"smooth"})})})},[]),Ve=E||T?.projectDirectory||null,it=j?.current||null,dt=o.useMemo(()=>{const Oe=j?.tracking;return Oe?Oe.startsWith("origin/"):!0},[j?.tracking]),Ye=o.useMemo(()=>{const Oe=T?.createdFromBranch,tt=typeof Oe=="string"?Oe.trim():"",nt=typeof j?.current=="string"?j.current.trim():"",ct=typeof re=="string"?re.trim():"";return tt?tt===nt&&tt.startsWith("opencode/")&&ct.length>0&&ct!==tt?ct:tt:ct||nt||"HEAD"},[T?.createdFromBranch,j,re]),_e=o.useCallback(()=>{he([])},[]),[et,gt]=o.useState(new Set),[Lt,Ut]=o.useState(new Map),[mt,Nt]=o.useState(new Set),[Xt,_t]=o.useState(null),[Gt,lt]=o.useState(null),[Tt,rs]=o.useState([]),[js,ys]=o.useState(""),[vs,Wt]=o.useState(!1),He=o.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(P,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(P,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(P,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[kt,Kt]=o.useState(()=>{if(typeof window>"u")return"commit";const Oe=window.localStorage.getItem(Fm);return Oe==="worktree"?"branch":G0(Oe)?Oe:"commit"}),[wt,Qt]=o.useState([]),[cs,Ls]=o.useState(null),[Ss,ns]=o.useState(null),[Os,Ks]=o.useState([]),[bt,Mt]=o.useState(!1),[At,ee]=o.useState([]),[ht,St]=o.useState("merge"),qt=o.useMemo(()=>c?`vinci.conflict:${c}`:null,[c]),ms=o.useCallback((Oe,tt,nt)=>{if(!qt||typeof window>"u")return;const ct={directory:Oe,conflictFiles:tt,operation:nt};window.localStorage.setItem(qt,JSON.stringify(ct))},[qt]),Ds=o.useCallback(()=>{!qt||typeof window>"u"||window.localStorage.removeItem(qt)},[qt]);o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Fm,kt)},[kt]),o.useEffect(()=>{if(!qt||typeof window>"u"||!n)return;const Oe=window.localStorage.getItem(qt);if(Oe)try{const tt=JSON.parse(Oe);if(tt.directory!==n){window.localStorage.removeItem(qt);return}ee(tt.conflictFiles??[]),St(tt.operation??"merge"),Mt(!0)}catch{window.localStorage.removeItem(qt)}},[qt,n]);const[Ke,yt]=o.useState(!1),[Et,Ht]=o.useState("merge"),[ss,Rt]=o.useState(""),Ps=o.useCallback(Oe=>{_n(Oe).then(tt=>{if(tt.ok){H.success(t("gitView.toast.commitHashCopied"));return}H.error(t("gitView.toast.copyFailed"))})},[t]),Qs=o.useCallback(Oe=>{gt(tt=>{const nt=new Set(tt);return nt.has(Oe)?nt.delete(Oe):nt.add(Oe),nt})},[]);o.useEffect(()=>{if(!n||!e)return;const Oe=Array.from(et).filter(tt=>!Lt.has(tt)&&!mt.has(tt));if(Oe.length!==0){Nt(tt=>{const nt=new Set(tt);for(const ct of Oe)nt.add(ct);return nt});for(const tt of Oe)e.getCommitFiles(n,tt).then(nt=>{Ut(ct=>new Map(ct).set(tt,nt.files))}).catch(nt=>{console.error("Failed to fetch commit files:",nt),Ut(ct=>new Map(ct).set(tt,[]))}).finally(()=>{Nt(nt=>{const ct=new Set(nt);return ct.delete(tt),ct})})}},[et,n,e,Lt,mt]),o.useEffect(()=>{n&&Om.set(n,{directory:n,selectedPaths:Array.from(Ee),commitMessage:pe,generatedHighlights:Qe})},[pe,n,Ee,Qe]),o.useEffect(()=>{w(),b(),k()},[w,b,k]),o.useEffect(()=>{if(!n||!e?.getRemoteUrl){lt(null);return}e.getRemoteUrl(n).then(lt).catch(()=>lt(null))},[n,e]);const Hs=o.useCallback(async()=>{if(!n||!e?.getRemotes){Qt([]);return}try{const Oe=await e.getRemotes(n);Qt(Oe)}catch{Qt([])}},[n,e]);o.useEffect(()=>{Hs()},[Hs]),o.useEffect(()=>{if(!ve){rs([]);return}let Oe=!1;const tt=X0();return tt&&(rs(tt.gitmojis),eN(tt))?()=>{Oe=!0}:((async()=>{try{const ct=await fetch(J0);if(!ct.ok)throw new Error(`Failed to load gitmojis: ${ct.statusText}`);const zt=await ct.json(),es=Array.isArray(zt.gitmojis)?zt.gitmojis.filter(Hh):[];Oe||(rs(es),Z0(es))}catch(ct){Oe||console.warn("Failed to load gitmoji list:",ct)}})(),()=>{Oe=!0})},[ve]),o.useEffect(()=>{n&&(z(n),V(n,e))},[n,z,V,e]),o.useEffect(()=>{if(n)return Sr.onGitRefreshHint(Oe=>{ji(Oe.directory)===ji(n)&&$(n,e)})},[n,$,e]);const ts=o.useCallback(async(Oe=!0)=>{if(n)try{await Promise.all([$(n,e),_(n,e)])}catch(tt){if(Oe){const nt=tt instanceof Error?tt.message:t("gitView.toast.refreshRepositoryFailed");H.error(nt)}}},[n,e,$,_,t]),Ns=o.useCallback(async()=>{n&&await X(n,e,Ue)},[n,e,X,Ue]),jn=o.useCallback(async()=>{n&&await O(n,e)},[n,e,O]);o.useEffect(()=>{if(!n||!e?.hasLocalIdentity||I!==!0)return;const Oe=typeof g=="string"?g.trim():"";if(!Oe||Oe==="global"||fe.current.get(n)===Oe)return;let nt=!1;return(async()=>{try{const zt=await e.hasLocalIdentity?.(n);if(nt||zt===!0)return;Z(),await e.setGitIdentity(n,Oe),fe.current.set(n,Oe),await jn()}catch(zt){console.warn("Failed to auto-apply default git identity:",zt)}finally{nt||Y()}})(),()=>{nt=!0}},[Z,n,g,Y,e,I,jn]);const sn=o.useMemo(()=>{if(!j)return[];const Oe=j.files??[],tt=new Map;for(const nt of Oe)tt.set(nt.path,nt);return Array.from(tt.values()).sort((nt,ct)=>nt.path.localeCompare(ct.path))},[j]);o.useEffect(()=>{if(!n||sn.length===0)return;const Oe=[],tt=new Set,nt=zt=>{!zt||tt.has(zt)||(tt.add(zt),Oe.push(zt))};if(Array.from(Ee).forEach(nt),ie.forEach(nt),sn.slice(0,Q0).forEach(zt=>nt(zt.path)),Oe.length===0)return;const ct=window.setTimeout(()=>{J(n,e,Oe,{maxFiles:Y0})},120);return()=>{window.clearTimeout(ct)}},[sn,n,e,J,Ee,ie]),o.useEffect(()=>{if(!j||sn.length===0){Ae(new Set),de(!1);return}Ae(Oe=>{const tt=new Set,nt=Oe??new Set;for(const ct of sn)nt.has(ct.path)?tt.add(ct.path):Je||tt.add(ct.path);return tt})},[j,sn,Je]);const Dr=async(Oe,tt)=>{if(n){we(Oe);try{const nt=ct=>{const zt=`${ct.name}/`,es=j?.tracking?.startsWith(zt)?j.tracking.slice(zt.length):void 0;return{remote:ct.name,branch:es,rebase:!0}};if(Oe==="fetch"){if(!tt)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:tt.name}),H.success(t("gitView.toast.fetchedFromRemote",{name:tt.name}))}else if(Oe==="pull"){if(!tt)throw new Error("No remote available for pull");const ct=await e.gitPull(n,nt(tt));H.success(ct.files.length===1?t("gitView.toast.pulledFilesSingle",{count:ct.files.length,name:tt.name}):t("gitView.toast.pulledFilesPlural",{count:ct.files.length,name:tt.name}))}else if(Oe==="push")await e.gitPush(n),H.success(t("gitView.toast.pushedToUpstream"));else if(Oe==="sync"){if(!tt)throw new Error("No remote available for sync");let ct=0,zt=!1;await e.gitFetch(n,{remote:tt.name});const es=await e.getGitStatus(n);if((es.behind??0)>0){if((es.files?.length??0)>0){H.error(t("gitView.toast.commitOrStashBeforeSync"));return}ct=(await e.gitPull(n,nt(tt))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),zt=!0),ct>0&&zt?H.success(ct===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:ct,name:tt.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:ct,name:tt.name})):ct>0?H.success(ct===1?t("gitView.toast.pulledFilesSingle",{count:ct,name:tt.name}):t("gitView.toast.pulledFilesPlural",{count:ct,name:tt.name})):zt?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate"))}await ts(!1),await Ns()}catch(nt){const ct=nt instanceof Error?nt.message:t("gitView.toast.syncActionFailed",{action:Oe==="sync"?t("gitView.sync.syncChanges"):Oe==="pull"?t("gitView.sync.pull"):Oe});H.error(ct)}finally{we(null)}}},Tr=o.useCallback(async Oe=>{if(!n)return;const tt=Oe.name.trim();if(!tt){H.error(t("gitView.toast.remoteNameRequired"));return}if(tt==="origin"){H.error(t("gitView.toast.cannotRemoveOriginRemote"));return}Ls(tt);try{await e.removeRemote(n,{remote:tt}),H.success(t("gitView.toast.removedRemote",{name:tt})),await Promise.all([ts(!1),Hs()])}catch(nt){const ct=nt instanceof Error?nt.message:`Failed to remove ${tt}`;H.error(ct)}finally{Ls(null)}},[n,e,Hs,ts,t]),zr=async(Oe={})=>{if(!n)return;if(!pe.trim()){H.error(t("gitView.toast.enterCommitMessage"));return}const tt=Array.from(Ee).sort();if(tt.length===0){H.error(t("gitView.toast.selectFileToCommit"));return}const nt=Oe.pushAfter?"commitAndPush":"commit";Me(nt);try{if(await e.createGitCommit(n,pe.trim(),{files:tt}),H.success(t("gitView.toast.commitCreated")),ye(""),Ae(new Set),de(!1),_e(),await ts(),Oe.pushAfter){we("sync");const ct=j?.tracking?.split("/")[0],zt=an.find(vr=>vr.name===ct)??an[0];if(!zt)throw new Error("No remote available for sync");const es=`${zt.name}/`,_s=j?.tracking?.startsWith(es)?j.tracking.slice(es.length):void 0;let pn=0,Mr=!1;await e.gitFetch(n,{remote:zt.name}),((await e.getGitStatus(n)).behind??0)>0&&(pn=(await e.gitPull(n,{remote:zt.name,branch:_s,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Mr=!0),pn>0&&Mr?H.success(pn===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:pn,name:zt.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:pn,name:zt.name})):pn>0?H.success(pn===1?t("gitView.toast.pulledFilesSingle",{count:pn,name:zt.name}):t("gitView.toast.pulledFilesPlural",{count:pn,name:zt.name})):Mr?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate")),Pe(),await ts(!1)}else await ts(!1);await Ns(),Te(ct=>ct+1)}catch(ct){const zt=ct instanceof Error?ct.message:t("gitView.toast.createCommitFailed");H.error(zt)}finally{Me(null),Oe.pushAfter&&we(null)}},Vr=o.useCallback(async()=>{if(n){if(Ee.size===0){H.error(t("gitView.toast.selectFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Ee.size}),Ze(!0);try{const{message:Oe}=await Cb(n,Array.from(Ee)),tt=Oe.subject?.trim()??"",nt=Array.isArray(Oe.highlights)?Oe.highlights:[];if(tt){let ct=tt;if(ve&&Tt.length>0){const zt=tN(tt,Tt);if(zt){const{code:es,emoji:_s}=zt;!tt.startsWith(es)&&!tt.startsWith(_s)&&(ct=`${es} ${tt}`)}}ye(ct)}he(nt),Ge()}catch(Oe){console.error("[git-generation][browser] GitView generate handler failed",{message:Oe instanceof Error?Oe.message:String(Oe),error:Oe});const tt=Oe instanceof Error?Oe.message:t("gitView.toast.generateCommitMessageFailed");H.error(tt)}finally{Ze(!1)}}},[n,Ee,ve,Tt,Ge,t]),Gs=Oe=>Oe.reason==="attention"?`${Oe.attentionReason} in progress`:Oe.reason==="missing"?"worktree is missing":"worktree is invalid",Mn=async(Oe,tt)=>{if(!n||!j)return;const nt=tc(N);if(nt.length>0){H.error(t("gitView.toast.cannotCreateBranch",{reason:Gs(nt[0])}));return}const ct=j.current??null,zt=tt?.name??"origin";try{await e.createBranch(n,Oe,ct??"HEAD"),H.success(t("gitView.toast.createdBranch",{name:Oe})),await e.checkoutBranch(n,Oe);let es=!1;try{await e.gitPush(n,{remote:zt,branch:Oe,options:["--set-upstream"]}),es=!0}catch(_s){const pn=_s instanceof Error?_s.message:`Unable to push new branch to ${zt}.`;H.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",pn]})})}await ts(),await Ns(),es&&H.success(t("gitView.toast.upstreamSet",{branch:Oe,remote:zt}))}catch(es){const _s=es instanceof Error?es.message:t("gitView.toast.createBranchFailed");throw H.error(_s),es}},ir=async(Oe,tt)=>{if(!n)return;const nt=tc(N);if(nt.length>0){H.error(t("gitView.toast.cannotRenameBranch",{reason:Gs(nt[0])}));return}try{await e.renameBranch(n,Oe,tt),H.success(t("gitView.toast.renamedBranch",{oldName:Oe,newName:tt})),await ts(),await Ns()}catch(ct){const zt=ct instanceof Error?ct.message:t("gitView.toast.renameBranchFailed",{oldName:Oe,newName:tt});H.error(zt)}},En=async Oe=>{if(!n)return;const tt=tc(N);if(tt.length>0){H.error(t("gitView.toast.cannotCheckout",{reason:Gs(tt[0])}));return}const nt=Oe.replace(/^remotes\//,"");if(j?.current!==nt)try{await e.checkoutBranch(n,nt),H.success(t("gitView.toast.checkedOut",{name:nt})),await ts(),await Ns()}catch(ct){const zt=ct instanceof Error?ct.message:t("gitView.toast.checkoutFailed",{name:nt});H.error(zt)}},_r=async Oe=>{if(n){Z();try{await e.setGitIdentity(n,Oe.id),H.success(t("gitView.toast.appliedIdentity",{name:Oe.name})),await jn()}catch(tt){const nt=tt instanceof Error?tt.message:t("gitView.toast.applyIdentityFailed");H.error(nt)}finally{Y()}}},In=o.useMemo(()=>C?.all?C.all.filter(Oe=>!Oe.startsWith("remotes/")).sort():[],[C]),ln=o.useMemo(()=>C?.all?C.all.filter(Oe=>Oe.startsWith("remotes/")).map(Oe=>Oe.replace(/^remotes\//,"")).sort():[],[C]),an=o.useMemo(()=>{if(wt.length>0)return wt;const Oe=new Set,tt=j?.tracking?.trim();tt&&tt.includes("/")&&Oe.add(tt.split("/")[0]);for(const nt of ln){const ct=nt.indexOf("/");ct>0&&Oe.add(nt.slice(0,ct))}return Oe.size===0&&Gt&&Oe.add("origin"),Array.from(Oe).map(nt=>({name:nt,fetchUrl:Gt??"",pushUrl:Gt??""}))},[wt,ln,Gt,j?.tracking]),Fe=o.useMemo(()=>{const Oe=new Set(an.map(zt=>zt.name)),tt=zt=>{if(!zt)return"";let es=zt.trim();if(!es||es==="HEAD")return"";if(In.includes(es))return es;es.startsWith("refs/heads/")&&(es=es.slice(11)),es.startsWith("heads/")&&(es=es.slice(6)),es.startsWith("remotes/")&&(es=es.slice(8));const _s=es.indexOf("/");if(_s>0){const pn=es.slice(0,_s);if(Oe.has(pn)){const Mr=es.slice(_s+1).trim();Mr&&(es=Mr)}}return es},nt=tt(typeof T?.createdFromBranch=="string"?T.createdFromBranch:"");if(nt)return nt;const ct=tt(typeof re=="string"?re:"");return ct||(In.includes("main")?"main":In.includes("master")?"master":In.includes("develop")?"develop":"main")},[an,In,re,T?.createdFromBranch]),Ct=o.useMemo(()=>an.map(nt=>nt.name).map(nt=>`${nt}/${Fe}`).find(nt=>ln.includes(nt))??Fe,[Fe,an,ln]),Zt=o.useMemo(()=>{const Oe=new Map;y&&Oe.set(y.id,y);let tt=null;if(Gt)try{let nt=Gt.trim();nt.startsWith("git@")&&(nt=`https://${nt.slice(4).replace(":","/")}`),nt.endsWith(".git")&&(nt=nt.slice(0,-4));const ct=new URL(nt);tt=ct.hostname+ct.pathname}catch{}for(const nt of v){if(nt.authType!=="token"){Oe.set(nt.id,nt);continue}const ct=nt.host;if(!ct){Oe.set(nt.id,nt);continue}if(!ct.includes("/")){Oe.set(nt.id,nt);continue}tt&&tt===ct&&Oe.set(nt.id,nt)}return Array.from(Oe.values())},[v,y,Gt]),ls=o.useMemo(()=>{if(M?.userName&&M?.userEmail){const Oe=v.find(tt=>tt.userName===M.userName&&tt.userEmail===M.userEmail);return Oe||(y&&y.userName===M.userName&&y.userEmail===M.userEmail?y:{id:"local-config",name:M.userName,userName:M.userName,userEmail:M.userEmail,sshKey:M.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return y??null},[M,v,y]),Bs=Ee.size,Js=A||je!==null||me!==null,ws=j?.current??null,en=!!(T&&Ve&&it&&dt),nn=!!(n&&ws),Rn=!!ws,Fn=en&&Ve&&it&&T?{repoRoot:Ve,sourceBranch:it,worktreeMetadata:T}:null,Ur=o.useMemo(()=>!nn||!n||!ws?null:{directory:n,branch:ws},[nn,ws,n]);o.useEffect(()=>{if(!n||!e||!S?.all?.length||!ws||!Fe||ws===Fe){_t(null);return}let Oe=!1;return(async()=>{try{const nt=await e.getGitLog(n,{from:Fe,to:"HEAD",maxCount:Ue});if(Oe)return;const ct=new Set((nt?.all??[]).map(es=>es.hash).filter(es=>typeof es=="string"&&es.length>0));if(ct.size===0){_t(null);return}const zt=S.all.findIndex(es=>!ct.has(es.hash));if(zt===0){_t(null);return}if(zt===-1){_t({insertBeforeIndex:S.all.length,branchName:ws,direction:"up"});return}_t({insertBeforeIndex:zt,branchName:ws,direction:"up"})}catch{Oe||_t(null)}})(),()=>{Oe=!0}},[Fe,ws,n,e,S,Ue]);const xr=Oe=>{Ae(tt=>{const nt=new Set(tt);return nt.has(Oe)?nt.delete(Oe):nt.add(Oe),nt}),de(!0)},Wr=()=>{const Oe=new Set(sn.map(tt=>tt.path));Ae(Oe),de(!0)},Ln=()=>{Ae(new Set),de(!0)},er=o.useCallback(async Oe=>{if(n){rt(tt=>{const nt=new Set(tt);return nt.add(Oe),nt});try{await e.revertGitFile(n,Oe),H.success(t("gitView.toast.revertedFile",{path:Oe})),await ts(!1)}catch(tt){const nt=tt instanceof Error?tt.message:t("gitView.toast.revertFailed");H.error(nt)}finally{rt(tt=>{const nt=new Set(tt);return nt.delete(Oe),nt})}}},[n,ts,e,t]),br=o.useCallback(async Oe=>{if(!n||Oe.length===0||Re)return;const tt=Array.from(new Set(Oe));Xe(!0),rt(ct=>{const zt=new Set(ct);return tt.forEach(es=>zt.add(es)),zt});const nt=[];try{if(await Promise.all(tt.map(async ct=>{try{await e.revertGitFile(n,ct)}catch(zt){nt.push({path:ct,message:zt instanceof Error?zt.message:t("gitView.toast.revertFailed")})}})),await ts(!1),nt.length===0)H.success(tt.length===1?t("gitView.toast.revertedFilesSingle",{count:tt.length}):t("gitView.toast.revertedFilesPlural",{count:tt.length}));else if(nt.length===tt.length)H.error(nt[0]?.message||t("gitView.toast.revertFailed"));else{const ct=tt.length-nt.length;H.warning(ct===1?t("gitView.toast.revertedSomeSingle",{success:ct,failed:nt.length}):t("gitView.toast.revertedSomePlural",{success:ct,failed:nt.length}))}}finally{rt(ct=>{const zt=new Set(ct);return tt.forEach(es=>zt.delete(es)),zt}),Xe(!1)}},[n,e,Re,ts,t]),ar=o.useCallback(Oe=>{if(Oe.length===0)return;const tt=Oe.map(nt=>nt.trim()).filter(Boolean);if(tt.length===0){_e();return}ye(nt=>{const ct=nt.trim(),zt=ct.length>0?`
|
|
43
|
+
|
|
44
|
+
`:"";return`${ct}${zt}${tt.join(`
|
|
45
|
+
`)}`.trim()}),_e()},[_e]),dn=o.useCallback((Oe,tt)=>{const nt=tt||Oe;ye(ct=>{const zt=ct.trimStart();return zt.startsWith(Oe)||tt&&zt.startsWith(tt)?ct:`${nt.endsWith(" ")?nt:`${nt} `}${ct}`.trimStart()}),ys(""),Ne(!1)},[]),On=o.useCallback(Oe=>{q(Oe),n&&(Q(n,Oe),X(n,e,Oe))},[n,Q,X,e]),bn=o.useCallback(Oe=>{const tt=Oe instanceof Error?Oe.message.toLowerCase():"";return tt.includes("uncommitted changes")||tt.includes("local changes")||tt.includes("your local changes would be overwritten")||tt.includes("please commit your changes or stash them")||tt.includes("cannot rebase: you have unstaged changes")||tt.includes("error: cannot pull with rebase")},[]),Gn=o.useCallback((Oe,tt)=>{Ks(nt=>[...nt,{message:Oe,status:tt,timestamp:Date.now()}])},[]),Nn=o.useCallback((Oe,tt)=>{Ks(nt=>{if(nt.length===0)return nt;const ct=[...nt];return ct[ct.length-1]={...ct[ct.length-1],status:Oe,...tt?{message:tt}:{}},ct})},[]),ni=o.useCallback(()=>{Ks([])},[]),Gi=o.useCallback(()=>{Ks([]),ns(null)},[]),tr=o.useCallback(Oe=>{const tt=Oe.trim(),nt=new Set(an.map(zt=>zt.name)),ct=tt.indexOf("/");if(ct>0){const zt=tt.slice(0,ct),es=tt.slice(ct+1);if(nt.has(zt)&&es)return{branch:tt,remote:zt,remoteBranch:es}}for(const zt of an){const es=`${zt.name}/${tt}`;if(ln.includes(es))return{branch:es,remote:zt.name,remoteBranch:tt}}return{branch:tt,remote:null,remoteBranch:null}},[an,ln]),bi=o.useCallback(async Oe=>{if(!n)return;ns("merge"),ni();const tt=j?.current,nt=tr(Oe);try{nt.remote&&nt.remoteBranch&&(Gn(`Fetching ${nt.remote}/${nt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:nt.remote,branch:nt.remoteBranch}),Nn("done",`Fetched ${nt.remote}/${nt.remoteBranch}`)),Gn(`Merging ${nt.branch} into ${tt}...`,"running");const ct=await e.merge(n,{branch:nt.branch});ct.conflict?(Nn("error","Merge conflicts detected"),ee(ct.conflictFiles??[]),St("merge"),Mt(!0),ms(n,ct.conflictFiles??[],"merge")):(Nn("done",`Merged ${nt.branch} into ${tt}`),Ds(),Gn("Refreshing repository status...","running"),await ts(),await Ns(),Nn("done","Repository status updated"))}catch(ct){if(bn(ct))Nn("error","Uncommitted changes detected"),Ht("merge"),Rt(nt.branch),yt(!0);else{const zt=ct instanceof Error?ct.message:`Failed to merge ${nt.branch}`;Nn("error",zt)}}},[n,e,j,tr,ts,Ns,bn,ms,Ds,Gn,Nn,ni]),Sn=o.useCallback(async Oe=>{if(!n)return;ns("rebase"),ni();const tt=j?.current,nt=tr(Oe);try{nt.remote&&nt.remoteBranch&&(Gn(`Fetching ${nt.remote}/${nt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:nt.remote,branch:nt.remoteBranch}),Nn("done",`Fetched ${nt.remote}/${nt.remoteBranch}`)),Gn(`Rebasing ${tt} onto ${nt.branch}...`,"running");const ct=await e.rebase(n,{onto:nt.branch});ct.conflict?(Nn("error","Rebase conflicts detected"),ee(ct.conflictFiles??[]),St("rebase"),Mt(!0),ms(n,ct.conflictFiles??[],"rebase")):(Nn("done",`Rebased ${tt} onto ${nt.branch}`),Ds(),Gn("Refreshing repository status...","running"),await ts(),await Ns(),Nn("done","Repository status updated"))}catch(ct){if(bn(ct))Nn("error","Uncommitted changes detected"),Ht("rebase"),Rt(nt.branch),yt(!0);else{const zt=ct instanceof Error?ct.message:`Failed to rebase onto ${nt.branch}`;Nn("error",zt)}}},[n,e,j,tr,ts,Ns,bn,ms,Ds,Gn,Nn,ni]),yr=o.useCallback(async()=>{if(n)try{ht==="merge"?(await e.abortMerge(n),H.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),H.success(t("gitView.toast.rebaseAborted"))),Ds(),await ts(),await Ns()}catch(Oe){const tt=Oe instanceof Error?Oe.message:`Failed to abort ${ht}`;H.error(tt)}},[n,e,ht,ts,Ns,Ds,t]),qn=o.useMemo(()=>j?.files?j.files.some(Oe=>Oe.index==="U"||Oe.working_dir==="U"||Oe.index==="A"&&Oe.working_dir==="A"||Oe.index==="D"&&Oe.working_dir==="D"):!1,[j?.files]),Gr=o.useCallback(async()=>{if(n)try{const Oe=!!j?.mergeInProgress?.head,tt=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(Oe){const nt=await e.continueMerge(n);nt.conflict?(ee(nt.conflictFiles??[]),St("merge"),Mt(!0),ms(n,nt.conflictFiles??[],"merge"),H.error(t("gitView.toast.mergeConflictsDetected"))):(Ds(),H.success(t("gitView.toast.mergeCompleted")),await ts(),await Ns())}else if(tt){const nt=await e.continueRebase(n);nt.conflict?(ee(nt.conflictFiles??[]),St("rebase"),Mt(!0),ms(n,nt.conflictFiles??[],"rebase"),H.error(t("gitView.toast.rebaseConflictsDetected"))):(Ds(),H.success(t("gitView.toast.rebaseStepCompleted")),await ts(),await Ns())}}catch(Oe){const tt=Oe instanceof Error?Oe.message:t("gitView.toast.continueOperationFailed");H.error(tt)}},[n,e,j,ts,Ns,ms,Ds,t]),Kr=o.useCallback(async()=>{if(n)try{!!j?.mergeInProgress?.head?(await e.abortMerge(n),H.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),H.success(t("gitView.toast.rebaseAborted"))),Ds(),await ts(),await Ns()}catch(Oe){const tt=Oe instanceof Error?Oe.message:t("gitView.toast.abortOperationFailed");H.error(tt)}},[n,e,j,ts,Ns,Ds,t]),qi=o.useCallback(()=>{if(!n)return;const tt=!!j?.mergeInProgress?.head?"merge":"rebase",nt=j?.files?.filter(ct=>ct.index==="U"||ct.working_dir==="U").map(ct=>ct.path)??[];nt.length>0&&ee(nt),St(tt),Mt(!0)},[n,j]),cn=o.useCallback(async Oe=>{if(!n)return;const tt=j?.current,nt=Et,ct=ss;try{await e.stash(n,{message:`Auto-stash before ${nt} with ${ct}`,includeUntracked:!0})}catch(_s){const pn=_s instanceof Error?_s.message:"Failed to stash changes";H.error(pn);return}let zt=!1,es=!1;try{if(nt==="merge"){const _s=await e.merge(n,{branch:ct});_s.conflict?(es=!0,ee(_s.conflictFiles??[]),St("merge"),Mt(!0)):(zt=!0,H.success(t("gitView.toast.mergedIntoBranch",{branch:ct,currentBranch:tt||""})))}else{const _s=await e.rebase(n,{onto:ct});_s.conflict?(es=!0,ee(_s.conflictFiles??[]),St("rebase"),Mt(!0)):(zt=!0,H.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:tt||"",branch:ct})))}if(Oe&&zt)try{await e.stashPop(n),H.success(t("gitView.toast.stashedRestored"))}catch(_s){const pn=_s instanceof Error?_s.message:t("gitView.toast.restoreStashFailed");H.error(pn)}else Oe&&es&&H.info(t("gitView.toast.restoreStashManually"));await ts(),await Ns()}catch(_s){if(Oe)try{await e.stashPop(n)}catch{}throw _s}},[n,e,j,Et,ss,ts,Ns,t]);return n?A&&I===null?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):I===!1?K?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(P,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(P,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.notGitRepositoryDescription")}),D.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:t("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:ce("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(rj,{status:j,localBranches:In,remoteBranches:ln,branchInfo:C?.branches,syncAction:je,remotes:an,onFetch:Oe=>Dr("fetch",Oe),onSync:Oe=>Dr("sync",Oe),onRemoveRemote:Tr,removingRemoteName:cs,onCheckoutBranch:En,onCreateBranch:Mn,onRenameBranch:ir,activeIdentityProfile:ls,availableIdentities:Zt,onSelectIdentity:_r,isApplyingIdentity:Se,isWorktreeMode:!!T,onOpenHistory:()=>Wt(!0),actionTabItems:He,activeActionTab:kt,onSelectActionTab:Oe=>Kt(Oe)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(z0,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:Gr,onAbort:Kr,onResolveWithAI:qi,hasUnresolvedConflicts:qn,isLoading:A}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:ce("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(Cs,{as:po,ref:Ce,outerClassName:"flex-1 min-h-0",className:ce("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[kt==="commit"?s.jsx("div",{className:"space-y-4",children:(sn?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx(fj,{maxListHeightClassName:"max-h-[40vh]",changeEntries:sn,onVisiblePathsChange:ue,selectedPaths:Ee,diffStats:j?.diffStats,revertingPaths:ze,onToggleFile:xr,onSelectAll:Wr,onClearSelection:Ln,onRevertAll:br,onViewDiff:Oe=>{if(n&&!ne){G(n,Oe);return}le(Oe),ne&&oe(!1)},onRevertFile:er,isRevertingAll:Re,onOpenStashes:()=>xe(!0)}),s.jsx(yj,{selectedCount:Bs,commitMessage:pe,onCommitMessageChange:ye,generatedHighlights:Qe,onInsertHighlights:ar,onGenerateMessage:Vr,isGeneratingMessage:We,onCommit:()=>zr({pushAfter:!1}),onCommitAndPush:()=>zr({pushAfter:!0}),commitAction:me,gitmojiEnabled:ve,onOpenGitmojiPicker:()=>Ne(!0)})]}):s.jsx(vj,{onOpenStashes:()=>xe(!0)})}):null,kt==="branch"?s.jsx("div",{className:"space-y-4",children:Rn?s.jsxs(s.Fragment,{children:[s.jsx(V0,{mode:"inline",currentBranch:j?.current,localBranches:In,remoteBranches:ln,defaultTargetBranch:Ct,onMerge:bi,onRebase:Sn,disabled:Js,isOperating:Ss!==null,operationLogs:Os,onOperationComplete:Gi}),Fn?s.jsx(Q1,{repoRoot:Fn.repoRoot,sourceBranch:Fn.sourceBranch,worktreeMetadata:Fn.worktreeMetadata,localBranches:In,defaultTargetBranch:Ye,refreshKey:qe,onRefresh:()=>{n&&($(n,e),_(n,e),X(n,e,Ue))}},Fn.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,kt==="pr"?s.jsx("div",{className:"space-y-4",children:Ur?s.jsx(T0,{directory:Ur.directory,branch:Ur.branch,baseBranch:Fe,trackingBranch:j?.tracking??void 0,remotes:wt,remoteBranches:ln,onGeneratedDescription:Ge}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:t("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(hs,{open:vs,onOpenChange:Wt,children:s.jsxs(fs,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:t("gitView.history.title")}),s.jsx(Is,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(t0,{log:S,isLogLoading:R,logMaxCount:Ue,onLogMaxCountChange:On,expandedCommitHashes:et,onToggleCommit:Qs,commitFilesMap:Lt,loadingCommitHashes:mt,onCopyHash:Ps,directory:n??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Xt})})]})}),s.jsx(ij,{open:ke,onOpenChange:xe,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,uncommittedFileCount:j?.files?.length??0,onChanged:async()=>{await ts(!1),await Ns()}}),s.jsx(hs,{open:se,onOpenChange:Ne,children:s.jsxs(fs,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(bs,{className:"px-4 pt-4",children:s.jsx(gs,{children:t("gitView.gitmoji.title")})}),s.jsxs(_i,{className:"h-[420px]",children:[s.jsx(xi,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:js,onValueChange:ys}),s.jsxs(Ui,{children:[s.jsx(Wi,{children:t("gitView.gitmoji.empty")}),s.jsx(zn,{children:(Tt.length===0?[]:Tt.filter(Oe=>{const tt=js.trim().toLowerCase();return tt?Oe.emoji.includes(tt)||Oe.code.toLowerCase().includes(tt)||Oe.description.toLowerCase().includes(tt):!0})).map(Oe=>s.jsxs(kn,{onSelect:()=>dn(Oe.emoji,Oe.code),children:[s.jsx("span",{className:"text-lg",children:Oe.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Oe.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Oe.description})]},Oe.code))})]})]})]})}),n&&s.jsx(M0,{open:bt,onOpenChange:Mt,conflictFiles:At,directory:n,operation:ht,onAbort:yr,onClearState:Ds}),s.jsx(B0,{open:Ke,onOpenChange:yt,operation:Et,targetBranch:ss,onConfirm:cn})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:t("gitView.empty.selectSessionOrDirectory")})})},sN=Object.freeze(Object.defineProperty({__proto__:null,GitView:Gh},Symbol.toStringTag,{value:"Module"})),cd=5e3,nN=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},rN=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},iN=async(t,e)=>{if(t.readFile)return(await t.readFile(e,{allowOutsideWorkspace:!0,optional:!0})).content??"";const n=new URLSearchParams({path:e,allowOutsideWorkspace:"true",optional:"true"}),r=await fetch(`/api/fs/read?${n.toString()}`,{cache:"no-store"});if(!r.ok){const i=await r.json().catch(()=>({error:r.statusText}));throw new Error(i.error||"Failed to read file")}return r.text()},Qd=async(t,e)=>{try{const n=await iN(t,e);return nN(n,cd)>cd?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:rN(n)}}},Jd=t=>t==="too-large"?`File is too large to open (>${cd.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",aN=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Kn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},qh=(t,e)=>{const n=Kn(e),r=Kn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},oN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),lN=new Set(["node_modules"]),cN=t=>lN.has(t),dN=t=>{const e=Kn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Yh=(t,e)=>s.jsx(Zn,{filePath:t,extension:e}),uN=t=>{const e=at.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const i=r[n];let a;return e[1]!==i?(a=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:i}}),e[1]=i,e[2]=a):a=e[2],a},mN=t=>{const e=at.c(63),{node:n,root:r,isExpanded:i,isActive:a,status:l,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:h,onToggle:x,onRevealPath:f,onOpenDialog:v}=t,{t:y}=ut(),g=n.type==="directory",{canRename:w,canCreateFile:b,canCreateFolder:k,canDelete:I,canReveal:j}=d;let N;e[0]!==b||e[1]!==k||e[2]!==I||e[3]!==w||e[4]!==j||e[5]!==n.path||e[6]!==u?(N=Q=>{!w&&!b&&!k&&!I&&!j||(Q?.preventDefault(),u(n.path))},e[0]=b,e[1]=k,e[2]=I,e[3]=w,e[4]=j,e[5]=n.path,e[6]=u,e[7]=N):N=e[7];const D=N;let E;e[8]!==g||e[9]!==n||e[10]!==h||e[11]!==x?(E=()=>{g?x(n.path):h(n)},e[8]=g,e[9]=n,e[10]=h,e[11]=x,e[12]=E):E=e[12];const T=E;let C;e[13]!==n.path||e[14]!==u?(C=Q=>{Q.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=C):C=e[15];const S=C;let M;e[16]!==n.path||e[17]!==r?(M=Q=>{const ne=qh(r,n.path);!ne||ne==="."||(Q.dataTransfer.setData("application/x-vinci-file-path",ne),Q.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=M):M=e[18];const A=M,R=a?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let z;e[19]!==R?(z=ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",R,"cursor-grab active:cursor-grabbing"),e[19]=R,e[20]=z):z=e[20];let B;e[21]!==g||e[22]!==i||e[23]!==n.extension||e[24]!==n.path?(B=g?i?s.jsx(P,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(P,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):Yh(n.path,n.extension),e[21]=g,e[22]=i,e[23]=n.extension,e[24]=n.path,e[25]=B):B=e[25];let V;e[26]!==n.name||e[27]!==n.path?(V=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[26]=n.name,e[27]=n.path,e[28]=V):V=e[28];let $;e[29]!==g||e[30]!==l?($=!g&&l&&s.jsx(uN,{status:l}),e[29]=g,e[30]=l,e[31]=$):$=e[31];let _;e[32]!==c||e[33]!==g?(_=g&&c&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[c.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",c.modified]}),c.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",c.added]})]}),e[32]=c,e[33]=g,e[34]=_):_=e[34];let X;e[35]!==D||e[36]!==A||e[37]!==T||e[38]!==_||e[39]!==z||e[40]!==B||e[41]!==V||e[42]!==$?(X=s.jsxs("button",{type:"button",onClick:T,onContextMenu:D,draggable:!0,onDragStart:A,className:z,children:[B,V,$,_]}),e[35]=D,e[36]=A,e[37]=T,e[38]=_,e[39]=z,e[40]=B,e[41]=V,e[42]=$,e[43]=X):X=e[43];let O;e[44]!==b||e[45]!==k||e[46]!==I||e[47]!==w||e[48]!==j||e[49]!==m||e[50]!==p||e[51]!==S||e[52]!==g||e[53]!==n||e[54]!==v||e[55]!==f||e[56]!==u||e[57]!==y?(O=(w||b||k||I||j)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(Fs,{open:m===n.path,onOpenChange:Q=>u(Q?n.path:null),children:[s.jsx(Es,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:S,children:s.jsx(P,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsxs(Rs,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[w&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),v("rename",n)},children:[s.jsx(P,{name:"edit",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.rename")]}),s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),_n(n.path).then(ne=>{if(ne.ok){H.success(y("sidebarFilesTree.toast.pathCopied"));return}H.error(y("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(P,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.copyPath")]}),!g&&p&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),p(n.path)},children:[s.jsx(P,{name:"download",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.save")]}),j&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),f(n.path)},children:[s.jsx(P,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",y(Od())]}),g&&(b||k)&&s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),b&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),v("createFile",n)},children:[s.jsx(P,{name:"file-add",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.newFile")]}),k&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),v("createFolder",n)},children:[s.jsx(P,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.newFolder")]})]}),I&&s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),v("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=b,e[45]=k,e[46]=I,e[47]=w,e[48]=j,e[49]=m,e[50]=p,e[51]=S,e[52]=g,e[53]=n,e[54]=v,e[55]=f,e[56]=u,e[57]=y,e[58]=O):O=e[58];let J;return e[59]!==D||e[60]!==X||e[61]!==O?(J=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:D,children:[X,O]}),e[59]=D,e[60]=X,e[61]=O,e[62]=J):J=e[62],J},pN=()=>{const t=at.c(240),{t:e}=ut(),{files:n,runtime:r}=Pn(),i=Ir()??"";let a;t[0]!==i?(a=Kn(i.trim()),t[0]=i,t[1]=a):a=t[1];const l=a,c=$l(),d=Ld(),p=Bl(fN),m=Ie(hN),u=Ol(i),[h,x]=o.useState(""),f=ho(h,200),v=o.useRef(null);let y;t[2]===Symbol.for("react.memo_cache_sentinel")?(y=[],t[2]=y):y=t[2];const[g,w]=o.useState(y),[b,k]=o.useState(!1);let I;t[3]===Symbol.for("react.memo_cache_sentinel")?(I={},t[3]=I):I=t[3];const[j,N]=o.useState(I);let D;t[4]===Symbol.for("react.memo_cache_sentinel")?(D=new Set,t[4]=D):D=t[4];const E=o.useRef(D);let T;t[5]===Symbol.for("react.memo_cache_sentinel")?(T=new Set,t[5]=T):T=t[5];const C=o.useRef(T);let S;t[6]===Symbol.for("react.memo_cache_sentinel")?(S=[],t[6]=S):S=t[6];const M=S;let A;t[7]===Symbol.for("react.memo_cache_sentinel")?(A=[],t[7]=A):A=t[7];const R=A;let z;t[8]!==l?(z=Mt=>l?Mt.byRoot[l]?.expandedPaths??M:M,t[8]=l,t[9]=z):z=t[9];const B=Bn(z);let V;t[10]!==l?(V=Mt=>l?Mt.byRoot[l]?.selectedPath??null:null,t[10]=l,t[11]=V):V=t[11];const $=Bn(V),_=Bn(gN),X=Bn(xN),O=Bn(bN),J=Bn(yN);let Q;t[12]!==l?(Q=Mt=>l?Mt.contextPanelByDirectory[l]?.tabs??R:R,t[12]=l,t[13]=Q):Q=t[13];const ne=Ie(Q);let G;t[14]!==ne?(G=new Set(ne.map(vN).filter(wN).map(jN)),t[14]=ne,t[15]=G):G=t[15];const le=G,[oe,F]=o.useState(null),[U,W]=o.useState(null),[te,K]=o.useState(null),[ae,ve]=o.useState(""),[re,be]=o.useState(!1),pe=!!n.writeFile,ye=!!n.createDirectory,ie=!!n.rename,ue=!!n.delete,se=!!n.revealPath;let Ne;t[16]!==pe||t[17]!==ye||t[18]!==ue||t[19]!==ie||t[20]!==se?(Ne={canRename:ie,canCreateFile:pe,canCreateFolder:ye,canDelete:ue,canReveal:se},t[16]=pe,t[17]=ye,t[18]=ue,t[19]=ie,t[20]=se,t[21]=Ne):Ne=t[21];const Ce=Ne;let je;t[22]!==n||t[23]!==e?(je=Mt=>{n.revealPath&&n.revealPath(Mt).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=je):je=t[24];const we=je;let ke;t[25]===Symbol.for("react.memo_cache_sentinel")?(ke=(Mt,At)=>{W(Mt),K(At),ve(Mt==="rename"&&At.name||""),be(!1)},t[25]=ke):ke=t[25];const xe=ke;let me;t[26]!==d||t[27]!==c?(me=(Mt,At)=>{const ee=At.filter(NN).filter(ht=>c||!ht.name.startsWith(".")).filter(ht=>d||!cN(ht.name)).map(ht=>{const St=ht.name,qt=Kn(ht.path||""),ms=qt?oN(qt)?qt:Kn(`${Mt}/${qt}`):Kn(`${Mt}/${St}`),Ds=ht.isDirectory?"directory":"file",Ke=Ds==="file"&&St.includes(".")?St.split(".").pop()?.toLowerCase():void 0;return{name:St,path:ms,type:Ds,extension:Ke}});return aN(ee)},t[26]=d,t[27]=c,t[28]=me):me=t[28];const Me=me;let Ue;t[29]!==n||t[30]!==Me||t[31]!==r.isDesktop||t[32]!==d?(Ue=async Mt=>{const At=Kn(Mt.trim());if(!At||E.current.has(At)||C.current.has(At))return;C.current=new Set(C.current),C.current.add(At);const ee=!d;await(r.isDesktop?n.listDirectory(At,{respectGitignore:ee}).then(kN):Zs.listLocalDirectory(At,{respectGitignore:ee}).then(PN)).then(St=>{const qt=Me(At,St);E.current=new Set(E.current),E.current.add(At),N(ms=>({...ms,[At]:qt}))}).catch(()=>{N(St=>({...St,[At]:St[At]??[]}))}).finally(()=>{C.current=new Set(C.current),C.current.delete(At)})},t[29]=n,t[30]=Me,t[31]=r.isDesktop,t[32]=d,t[33]=Ue):Ue=t[33];const q=Ue;let Se;t[34]!==q||t[35]!==l?(Se=async()=>{l&&(E.current=new Set,C.current=new Set,N(IN),await q(l))},t[34]=q,t[35]=l,t[36]=Se):Se=t[36];const $e=Se;let Pe;t[37]!==q||t[38]!==$e?(Pe=async Mt=>{if(!Mt){await $e();return}const At=Kn(Mt);E.current=new Set(E.current),E.current.delete(At),C.current=new Set(C.current),C.current.delete(At),await q(At)},t[37]=q,t[38]=$e,t[39]=Pe):Pe=t[39];const fe=Pe;let L;t[40]!==q||t[41]!==l?(L=()=>{l&&(E.current=new Set,C.current=new Set,N(AN),q(l))},t[40]=q,t[41]=l,t[42]=L):L=t[42];let Z;t[43]!==q||t[44]!==l||t[45]!==d||t[46]!==c?(Z=[q,l,c,d],t[43]=q,t[44]=l,t[45]=d,t[46]=c,t[47]=Z):Z=t[47],o.useEffect(L,Z);let Y,Ee;t[48]!==B||t[49]!==q||t[50]!==l?(Y=()=>{if(!l||B.length===0)return;const Mt=B.map(DN).filter(ee=>!!ee&&ee!==l&&ee.startsWith(`${l}/`)&&!E.current.has(ee)&&!C.current.has(ee)).sort(TN);if(Mt.length===0)return;let At=!1;return(async()=>{for(let ee=0;ee<Mt.length&&!At;ee=ee+3,ee){const ht=Mt.slice(ee,ee+3);await Promise.all(ht.map(St=>q(St)))}})(),()=>{At=!0}},Ee=[B,q,l],t[48]=B,t[49]=q,t[50]=l,t[51]=Y,t[52]=Ee):(Y=t[51],Ee=t[52]),o.useEffect(Y,Ee);let Ae,Je;t[53]!==i||t[54]!==f||t[55]!==p||t[56]!==d||t[57]!==c?(Ae=()=>{if(!i){w([]),k(!1);return}const Mt=f.trim();if(!Mt){w([]),k(!1);return}let At=!1;return k(!0),p(i,Mt,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(ee=>{if(At)return;const St=ee.filter(qt=>d||!dN(qt.path)).map(MN);w(St)}).catch(()=>{At||w([])}).finally(()=>{At||k(!1)}),()=>{At=!0}},Je=[i,f,p,c,d],t[53]=i,t[54]=f,t[55]=p,t[56]=d,t[57]=c,t[58]=Ae,t[59]=Je):(Ae=t[58],Je=t[59]),o.useEffect(Ae,Je);let de;t[60]!==u||t[61]!==le||t[62]!==l?(de=Mt=>{if(le.has(Mt))return"open";if(u?.files){const At=Mt.startsWith(l+"/")?Mt.slice(l.length+1):Mt,ee=u.files.find(ht=>ht.path===At);if(ee){if(ee.index==="A"||ee.working_dir==="?")return"git-added";if(ee.index==="D")return"git-deleted";if(ee.index==="M"||ee.working_dir==="M")return"git-modified"}}return null},t[60]=u,t[61]=le,t[62]=l,t[63]=de):de=t[63];const ze=de;let rt;t[64]!==u||t[65]!==l?(rt=Mt=>{if(!u?.files)return null;const At=Mt.startsWith(l+"/")?Mt.slice(l.length+1):Mt,ee=At?`${At}/`:"";let ht=0,St=0;for(const qt of u.files)qt.path.startsWith(ee)&&((qt.index==="M"||qt.working_dir==="M")&&ht++,(qt.index==="A"||qt.working_dir==="?")&&St++);return ht+St>0?{modified:ht,added:St}:null},t[64]=u,t[65]=l,t[66]=rt):rt=t[66];const Re=rt;let Xe;t[67]!==X||t[68]!==n||t[69]!==m||t[70]!==l||t[71]!==_?(Xe=async Mt=>{if(!l)return;const At=await Qd(n,Mt.path);if(!At.ok){H.error(Jd(At.reason));return}_(l,Mt.path),X(l,Mt.path),m(l,Mt.path)},t[67]=X,t[68]=n,t[69]=m,t[70]=l,t[71]=_,t[72]=Xe):Xe=t[72];const qe=Xe;let Te;t[73]!==q||t[74]!==l||t[75]!==J?(Te=async Mt=>{const At=Kn(Mt);l&&(J(l,At),E.current.has(At)||await q(At))},t[73]=q,t[74]=l,t[75]=J,t[76]=Te):Te=t[76];const We=Te;let Ze;t[77]!==U||t[78]!==te||t[79]!==ae||t[80]!==n||t[81]!==fe||t[82]!==O||t[83]!==l||t[84]!==$||t[85]!==_||t[86]!==e?(Ze=async Mt=>{if(Mt?.preventDefault(),!te||!U)return;be(!0);const At=()=>be(!1),ee=()=>W(null);if(U==="createFile"){if(!ae.trim()){H.error(e("sidebarFilesTree.toast.filenameRequired")),At();return}if(!n.writeFile){H.error(e("sidebarFilesTree.toast.writeNotSupported")),At();return}const ht=te.path,St=ht?`${ht}/`:"",qt=Kn(`${St}${ae.trim()}`);await n.writeFile(qt,"").then(async ms=>{ms.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await fe(ht)),ee()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(At);return}if(U==="createFolder"){if(!ae.trim()){H.error(e("sidebarFilesTree.toast.folderNameRequired")),At();return}const ht=te.path,St=ht?`${ht}/`:"",qt=Kn(`${St}${ae.trim()}`);await n.createDirectory(qt).then(async ms=>{ms.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await fe(ht)),ee()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(At);return}if(U==="rename"){if(!ae.trim()){H.error(e("sidebarFilesTree.toast.nameRequired")),At();return}if(!n.rename){H.error(e("sidebarFilesTree.toast.renameNotSupported")),At();return}const ht=te.path,St=ht.split("/").slice(0,-1).join("/"),qt=St?`${St}/`:"",ms=Kn(`${qt}${ae.trim()}`);await n.rename(ht,ms).then(async Ds=>{Ds.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await fe(St),l&&O(l,ht),($===ht||$&&$.startsWith(`${ht}/`))&&_(l,null)),ee()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(At);return}if(U==="delete"){if(!n.delete){H.error(e("sidebarFilesTree.toast.deleteNotSupported")),At();return}const ht=te.path,St=ht.split("/").slice(0,-1).join("/");await n.delete(ht).then(async qt=>{qt.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await fe(St),l&&O(l,ht),($===ht||$&&$.startsWith(ht+"/"))&&_(l,null)),ee()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(At);return}At()},t[77]=U,t[78]=te,t[79]=ae,t[80]=n,t[81]=fe,t[82]=O,t[83]=l,t[84]=$,t[85]=_,t[86]=e,t[87]=Ze):Ze=t[87];const Qe=Ze;let he,Ge,Ve,it,dt,Ye,_e;if(t[88]!==pe||t[89]!==ye||t[90]!==j||t[91]!==oe||t[92]!==i||t[93]!==B||t[94]!==Ce||t[95]!==n.downloadFile||t[96]!==ze||t[97]!==Re||t[98]!==qe||t[99]!==we||t[100]!==$e||t[101]!==l||t[102]!==h||t[103]!==g||t[104]!==b||t[105]!==$||t[106]!==e||t[107]!==We){let Mt=function(Ps,Qs){const Hs=j[Ps]??[];return Hs.map((ts,Ns)=>{const jn=ts.type==="directory",sn=jn&&B.includes(ts.path),Dr=$===ts.path,Tr=Ns===Hs.length-1;return s.jsxs("li",{className:"relative",children:[Qs>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Tr&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(mN,{node:ts,root:l,isExpanded:sn,isActive:Dr,status:jn?void 0:ze(ts.path),badge:jn?Re(ts.path):void 0,permissions:Ce,downloadFile:n.downloadFile,contextMenuPath:oe,setContextMenuPath:F,onSelect:qe,onToggle:We,onRevealPath:we,onOpenDialog:xe}),jn&&sn&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Mt(ts.path,Qs+1)})]},ts.path)})};const At=!!(l&&j[l]);Ye="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let ee;t[115]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsx(P,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[115]=ee):ee=t[115];let ht;t[116]===Symbol.for("react.memo_cache_sentinel")?(ht=Ps=>x(Ps.target.value),t[116]=ht):ht=t[116];let St;t[117]!==e?(St=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=St):St=t[118];let qt;t[119]!==h||t[120]!==St?(qt=s.jsx(Bt,{ref:v,value:h,onChange:ht,placeholder:St,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=h,t[120]=St,t[121]=qt):qt=t[121];let ms;t[122]!==h||t[123]!==e?(ms=h.trim().length>0?s.jsx("button",{type:"button","aria-label":e("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{x(""),v.current?.focus()},children:s.jsx(P,{name:"close",className:"h-4 w-4"})}):null,t[122]=h,t[123]=e,t[124]=ms):ms=t[124];let Ds;t[125]!==qt||t[126]!==ms?(Ds=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[ee,qt,ms]}),t[125]=qt,t[126]=ms,t[127]=Ds):Ds=t[127];let Ke;t[128]!==pe||t[129]!==i||t[130]!==e?(Ke=pe&&s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>xe("createFile",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(P,{name:"file-add",className:"h-4 w-4"})}),t[128]=pe,t[129]=i,t[130]=e,t[131]=Ke):Ke=t[131];let yt;t[132]!==ye||t[133]!==i||t[134]!==e?(yt=ye&&s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>xe("createFolder",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(P,{name:"folder-add",className:"h-4 w-4"})}),t[132]=ye,t[133]=i,t[134]=e,t[135]=yt):yt=t[135];let Et;t[136]!==$e?(Et=()=>{$e()},t[136]=$e,t[137]=Et):Et=t[137];let Ht;t[138]!==e?(Ht=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Ht):Ht=t[139];let ss;t[140]===Symbol.for("react.memo_cache_sentinel")?(ss=s.jsx(P,{name:"refresh",className:"h-4 w-4"}),t[140]=ss):ss=t[140];let Rt;t[141]!==Et||t[142]!==Ht?(Rt=s.jsx(ge,{variant:"ghost",size:"sm",onClick:Et,className:"h-8 w-8 p-0 flex-shrink-0",title:Ht,children:ss}),t[141]=Et,t[142]=Ht,t[143]=Rt):Rt=t[143],t[144]!==Ds||t[145]!==Ke||t[146]!==yt||t[147]!==Rt?(_e=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[Ds,Ke,yt,Rt]}),t[144]=Ds,t[145]=Ke,t[146]=yt,t[147]=Rt,t[148]=_e):_e=t[148],he=Cs,it="flex-1 min-h-0",dt="p-2",Ge="flex flex-col",Ve=b?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):g.length>0?g.map(Ps=>{const Qs=$===Ps.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>qe(Ps),draggable:!0,onDragStart:Hs=>{const ts=Ps.relativePath||qh(l??"",Ps.path);!ts||ts==="."||(Hs.dataTransfer.setData("application/x-vinci-file-path",ts),Hs.dataTransfer.effectAllowed="copy")},className:ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",Qs?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:Ps.path,children:[Yh(Ps.path,Ps.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:Ps.relativePath??Ps.path})]})},Ps.path)}):At&&l?Mt(l,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=pe,t[89]=ye,t[90]=j,t[91]=oe,t[92]=i,t[93]=B,t[94]=Ce,t[95]=n.downloadFile,t[96]=ze,t[97]=Re,t[98]=qe,t[99]=we,t[100]=$e,t[101]=l,t[102]=h,t[103]=g,t[104]=b,t[105]=$,t[106]=e,t[107]=We,t[108]=he,t[109]=Ge,t[110]=Ve,t[111]=it,t[112]=dt,t[113]=Ye,t[114]=_e}else he=t[108],Ge=t[109],Ve=t[110],it=t[111],dt=t[112],Ye=t[113],_e=t[114];let et;t[149]!==Ge||t[150]!==Ve?(et=s.jsx("ul",{className:Ge,children:Ve}),t[149]=Ge,t[150]=Ve,t[151]=et):et=t[151];let gt;t[152]!==he||t[153]!==it||t[154]!==dt||t[155]!==et?(gt=s.jsx(he,{outerClassName:it,className:dt,children:et}),t[152]=he,t[153]=it,t[154]=dt,t[155]=et,t[156]=gt):gt=t[156];const Lt=!!U;let Ut;t[157]===Symbol.for("react.memo_cache_sentinel")?(Ut=Mt=>!Mt&&W(null),t[157]=Ut):Ut=t[157];let mt;t[158]!==U||t[159]!==e?(mt=U==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[158]=U,t[159]=e,t[160]=mt):mt=t[160];let Nt;t[161]!==U||t[162]!==e?(Nt=U==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[161]=U,t[162]=e,t[163]=Nt):Nt=t[163];let Xt;t[164]!==U||t[165]!==e?(Xt=U==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[164]=U,t[165]=e,t[166]=Xt):Xt=t[166];let _t;t[167]!==U||t[168]!==e?(_t=U==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[167]=U,t[168]=e,t[169]=_t):_t=t[169];let Gt;t[170]!==mt||t[171]!==Nt||t[172]!==Xt||t[173]!==_t?(Gt=s.jsxs(gs,{children:[mt,Nt,Xt,_t]}),t[170]=mt,t[171]=Nt,t[172]=Xt,t[173]=_t,t[174]=Gt):Gt=t[174];let lt;t[175]!==U||t[176]!==te?.path||t[177]!==e?(lt=U==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:te?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[175]=U,t[176]=te?.path,t[177]=e,t[178]=lt):lt=t[178];let Tt;t[179]!==U||t[180]!==te?.path||t[181]!==e?(Tt=U==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:te?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[179]=U,t[180]=te?.path,t[181]=e,t[182]=Tt):Tt=t[182];let rs;t[183]!==U||t[184]!==te?.name||t[185]!==e?(rs=U==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:te?.name??""}),t[183]=U,t[184]=te?.name,t[185]=e,t[186]=rs):rs=t[186];let js;t[187]!==U||t[188]!==te?.name||t[189]!==e?(js=U==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:te?.name??""}),t[187]=U,t[188]=te?.name,t[189]=e,t[190]=js):js=t[190];let ys;t[191]!==lt||t[192]!==Tt||t[193]!==rs||t[194]!==js?(ys=s.jsxs(Is,{children:[lt,Tt,rs,js]}),t[191]=lt,t[192]=Tt,t[193]=rs,t[194]=js,t[195]=ys):ys=t[195];let vs;t[196]!==Gt||t[197]!==ys?(vs=s.jsxs(bs,{children:[Gt,ys]}),t[196]=Gt,t[197]=ys,t[198]=vs):vs=t[198];let Wt;t[199]!==U||t[200]!==ae||t[201]!==Qe||t[202]!==e?(Wt=U!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Bt,{value:ae,onChange:Mt=>ve(Mt.target.value),placeholder:e(U==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:Mt=>{Mt.key==="Enter"&&Qe()},autoFocus:!0})}),t[199]=U,t[200]=ae,t[201]=Qe,t[202]=e,t[203]=Wt):Wt=t[203];let He;t[204]===Symbol.for("react.memo_cache_sentinel")?(He=()=>W(null),t[204]=He):He=t[204];let kt;t[205]!==e?(kt=e("sidebarFilesTree.dialog.cancel"),t[205]=e,t[206]=kt):kt=t[206];let Kt;t[207]!==re||t[208]!==kt?(Kt=s.jsx(ge,{variant:"outline",onClick:He,disabled:re,children:kt}),t[207]=re,t[208]=kt,t[209]=Kt):Kt=t[209];const wt=U==="delete"?"destructive":"default";let Qt;t[210]!==Qe?(Qt=()=>{Qe()},t[210]=Qe,t[211]=Qt):Qt=t[211];let cs;t[212]!==U||t[213]!==ae||t[214]!==re?(cs=re||U!=="delete"&&!ae.trim(),t[212]=U,t[213]=ae,t[214]=re,t[215]=cs):cs=t[215];let Ls;t[216]!==U||t[217]!==re||t[218]!==e?(Ls=re?s.jsx(P,{name:"loader-4",className:"animate-spin"}):e(U==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[216]=U,t[217]=re,t[218]=e,t[219]=Ls):Ls=t[219];let Ss;t[220]!==wt||t[221]!==Qt||t[222]!==cs||t[223]!==Ls?(Ss=s.jsx(ge,{variant:wt,onClick:Qt,disabled:cs,children:Ls}),t[220]=wt,t[221]=Qt,t[222]=cs,t[223]=Ls,t[224]=Ss):Ss=t[224];let ns;t[225]!==Kt||t[226]!==Ss?(ns=s.jsxs(Vs,{children:[Kt,Ss]}),t[225]=Kt,t[226]=Ss,t[227]=ns):ns=t[227];let Os;t[228]!==vs||t[229]!==Wt||t[230]!==ns?(Os=s.jsxs(fs,{children:[vs,Wt,ns]}),t[228]=vs,t[229]=Wt,t[230]=ns,t[231]=Os):Os=t[231];let Ks;t[232]!==Lt||t[233]!==Os?(Ks=s.jsx(hs,{open:Lt,onOpenChange:Ut,children:Os}),t[232]=Lt,t[233]=Os,t[234]=Ks):Ks=t[234];let bt;return t[235]!==Ye||t[236]!==_e||t[237]!==gt||t[238]!==Ks?(bt=s.jsxs("section",{className:Ye,children:[_e,gt,Ks]}),t[235]=Ye,t[236]=_e,t[237]=gt,t[238]=Ks,t[239]=bt):bt=t[239],bt};function fN(t){return t.searchFiles}function hN(t){return t.openContextFile}function gN(t){return t.setSelectedPath}function xN(t){return t.addOpenPath}function bN(t){return t.removeOpenPathsByPrefix}function yN(t){return t.toggleExpandedPath}function vN(t){return t.mode==="file"?t.targetPath:null}function wN(t){return typeof t=="string"&&t.length>0}function jN(t){return Kn(t)}function NN(t){return t&&typeof t.name=="string"&&t.name.length>0}function SN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function kN(t){return t.entries.map(SN)}function CN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function PN(t){return t.map(CN)}function IN(t){return Object.keys(t).length===0?t:{}}function AN(t){return Object.keys(t).length===0?t:{}}function DN(t){return Kn(t)}function TN(t,e){return t.split("/").length-e.split("/").length}function MN(t){return{name:t.name,path:Kn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function EN(t,e){const n=at.c(6),{git:r}=Pn(),i=tn(RN);let a,l;n[0]!==t||n[1]!==i||n[2]!==r||n[3]!==e?(a=()=>{if(!t||!r||!e)return;i(t,r);const c=setInterval(()=>{typeof document<"u"&&document.hidden||i(t,r)},1e4);return()=>clearInterval(c)},l=[t,r,e,i],n[0]=t,n[1]=i,n[2]=r,n[3]=e,n[4]=a,n[5]=l):(a=n[4],l=n[5]),o.useEffect(a,l)}function RN(t){return t.ensureStatus}const FN=()=>{const t=at.c(17),e=As(ON),n=As($N),r=$s(BN),i=tn(zN);let a;e:{if(e){let f;t[0]!==e||t[1]!==n?(f=n.find(v=>v.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=f):f=t[2],a=f;break e}a=n[0]??null}const l=a;let c;e:{if(!l){c=null;break e}let f;t[3]!==l.id||t[4]!==l.path?(f={id:l.id,path:l.path},t[3]=l.id,t[4]=l.path,t[5]=f):f=t[5],c=f}const d=c;let p;e:{if(!l){p=null;break e}let f;t[6]!==l.label||t[7]!==l.path||t[8]!==r?(f=l.label?.trim()||Vi(l.path,r)||l.path,t[6]=l.label,t[7]=l.path,t[8]=r,t[9]=f):f=t[9],p=f}const m=p;let u;e:{if(!l){u=!1;break e}let f;t[10]!==l.path||t[11]!==i?(f=i.get(l.path)?.isGitRepo,t[10]=l.path,t[11]=i,t[12]=f):f=t[12],u=f===!0}const h=u;let x;return t[13]!==h||t[14]!==m||t[15]!==d?(x=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(k1,{projectRef:d,projectLabel:m,canCreateWorktree:h})}),t[13]=h,t[14]=m,t[15]=d,t[16]=x):x=t[16],x},LN=()=>{const t=at.c(38),{t:e}=ut(),n=Ie(VN),r=Ie(_N),i=Ie(UN),a=Ir();EN(a,i);let l;t[0]!==e?(l=e("layout.rightSidebar.git"),t[0]=e,t[1]=l):l=t[1];let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(P,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=c):c=t[2];let d;t[3]!==l?(d={id:"git",label:l,icon:c},t[3]=l,t[4]=d):d=t[4];let p;t[5]!==e?(p=e("layout.rightSidebar.files"),t[5]=e,t[6]=p):p=t[6];let m;t[7]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(P,{name:"folder-3",className:"h-3.5 w-3.5"}),t[7]=m):m=t[7];let u;t[8]!==p?(u={id:"files",label:p,icon:m},t[8]=p,t[9]=u):u=t[9];let h;t[10]!==e?(h=e("layout.rightSidebar.context"),t[10]=e,t[11]=h):h=t[11];let x;t[12]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(P,{name:"booklet",className:"h-3.5 w-3.5"}),t[12]=x):x=t[12];let f;t[13]!==h?(f={id:"context",label:h,icon:x},t[13]=h,t[14]=f):f=t[14];let v;t[15]!==d||t[16]!==u||t[17]!==f?(v=[d,u,f],t[15]=d,t[16]=u,t[17]=f,t[18]=v):v=t[18];const y=v;let g;t[19]!==r?(g=D=>r(D),t[19]=r,t[20]=g):g=t[20];let w;t[21]!==n||t[22]!==g||t[23]!==y?(w=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Cr,{items:y,activeId:n,onSelect:g,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=g,t[23]=y,t[24]=w):w=t[24];let b;t[25]!==n?(b=n==="git"&&s.jsx(Gh,{}),t[25]=n,t[26]=b):b=t[26];let k;t[27]!==n?(k=n==="files"&&s.jsx(pN,{}),t[27]=n,t[28]=k):k=t[28];let I;t[29]!==n?(I=n==="context"&&s.jsx(FN,{}),t[29]=n,t[30]=I):I=t[30];let j;t[31]!==b||t[32]!==k||t[33]!==I?(j=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[b,k,I]}),t[31]=b,t[32]=k,t[33]=I,t[34]=j):j=t[34];let N;return t[35]!==w||t[36]!==j?(N=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[w,j]}),t[35]=w,t[36]=j,t[37]=N):N=t[37],N};function ON(t){return t.activeProjectId}function $N(t){return t.projects}function BN(t){return t.homeDirectory}function zN(t){return t.directories}function VN(t){return t.rightSidebarTab}function _N(t){return t.setRightSidebarTab}function UN(t){return t.isRightSidebarOpen}const WN=1100,dd=15e3,$m=500,KN=t=>t<=6?t:t<=12?6:t<=25?4:2,Qh=o.memo(()=>{const t=at.c(4),{t:e}=ut();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),Jh={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},HN=Jh.M,sl=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],GN=t=>{const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"},Xh=t=>{const e=GN(t);return Jh[e]??HN},qN=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},YN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),QN=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(YN(r))return r;const i=r.replace(/^\/+/,"");return n?`${n}/${i}`:i},Bm=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),zm=(t,e)=>{const n=t.split(`
|
|
46
|
+
`),r=e.split(`
|
|
47
|
+
`),i=Math.min(n.length,r.length);for(let a=0;a<i;a+=1)if(n[a]!==r[a])return a+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},JN=t=>{if(!t)return null;const e=t.match(/@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/m);if(!e)return null;const n=Number.parseInt(e[1],10);return!Number.isFinite(n)||n<1?null:n},Sl=(t,e)=>{const n=t??0,r=e??0;return!n&&!r?null:s.jsxs("span",{className:"typography-meta flex flex-shrink-0 items-center gap-1 text-xs whitespace-nowrap",children:[n?s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",n]}):null,r?s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",r]}):null]})},XN=o.memo(t=>{const e=at.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:i,onSelectFile:a,isMobile:l,showModeSelector:c,mode:d,onModeChange:p}=t,m=c===void 0?!1:c,{t:u}=ut();let h;e[0]!==l?(h=N=>{if(!l)return N;const D=N.lastIndexOf("/");return D>=0?N.slice(D+1):N},e[0]=l,e[1]=h):h=e[1];const x=h;if(n.length===0)return null;let f;e[2]!==x||e[3]!==i||e[4]!==u?(f=i?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(Zn,{filePath:i.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:x(i.path)}),Sl(i.insertions,i.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:u("diffView.selector.selectFile")}),e[2]=x,e[3]=i,e[4]=u,e[5]=f):f=e[5];let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(P,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=v):v=e[6];let y;e[7]!==f?(y=s.jsx(Es,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[f,v]})}),e[7]=f,e[8]=y):y=e[8];let g;e[9]!==d||e[10]!==p||e[11]!==m||e[12]!==u?(g=m&&d&&p?s.jsxs(s.Fragment,{children:[s.jsx(Ka,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(pl,{value:d,onValueChange:N=>p(N),children:sl.map(N=>s.jsx(fl,{value:N.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(N.labelKey)})},N.value))}),s.jsx(Cn,{})]}):null,e[9]=d,e[10]=p,e[11]=m,e[12]=u,e[13]=g):g=e[13];const w=r??"";let b;if(e[14]!==n||e[15]!==x){let N;e[17]!==x?(N=D=>s.jsx(fl,{value:D.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(Zn,{filePath:D.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:x(D.path)}),s.jsx("span",{className:"ml-auto",children:Sl(D.insertions,D.deletions)})]})},D.path),e[17]=x,e[18]=N):N=e[18],b=n.map(N),e[14]=n,e[15]=x,e[16]=b}else b=e[16];let k;e[19]!==a||e[20]!==w||e[21]!==b?(k=s.jsx(pl,{value:w,onValueChange:a,children:b}),e[19]=a,e[20]=w,e[21]=b,e[22]=k):k=e[22];let I;e[23]!==g||e[24]!==k?(I=s.jsxs(Rs,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[g,k]}),e[23]=g,e[24]=k,e[25]=I):I=e[25];let j;return e[26]!==I||e[27]!==y?(j=s.jsxs(Fs,{children:[y,I]}),e[26]=I,e[27]=y,e[28]=j):j=e[28],j}),ZN=o.memo(t=>{const e=at.c(31),{mode:n,onModeChange:r}=t,{t:i}=ut();let a,l,c,d,p,m;if(e[0]!==n||e[1]!==i){const b=sl.find(k=>k.value===n)??sl[0];l=Fs,a=Es,m=!0,p="flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",c="min-w-0 truncate typography-meta",d=i(b.labelKey),e[0]=n,e[1]=i,e[2]=a,e[3]=l,e[4]=c,e[5]=d,e[6]=p,e[7]=m}else a=e[2],l=e[3],c=e[4],d=e[5],p=e[6],m=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsx("span",{className:c,children:d}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(P,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=h):h=e[11];let x;e[12]!==p||e[13]!==u?(x=s.jsxs("button",{className:p,children:[u,h]}),e[12]=p,e[13]=u,e[14]=x):x=e[14];let f;e[15]!==a||e[16]!==m||e[17]!==x?(f=s.jsx(a,{asChild:m,children:x}),e[15]=a,e[16]=m,e[17]=x,e[18]=f):f=e[18];let v;e[19]!==r?(v=b=>r(b),e[19]=r,e[20]=v):v=e[20];let y;e[21]!==i?(y=sl.map(b=>s.jsx(fl,{value:b.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:i(b.labelKey)})},b.value)),e[21]=i,e[22]=y):y=e[22];let g;e[23]!==n||e[24]!==y||e[25]!==v?(g=s.jsx(Rs,{className:"min-w-[140px]",children:s.jsx(pl,{value:n,onValueChange:v,children:y})}),e[23]=n,e[24]=y,e[25]=v,e[26]=g):g=e[26];let w;return e[27]!==l||e[28]!==g||e[29]!==f?(w=s.jsxs(l,{children:[f,g]}),e[27]=l,e[28]=g,e[29]=f,e[30]=w):w=e[30],w}),e2=o.memo(t=>{const e=at.c(11),{changedFiles:n,selectedFile:r,onSelectFile:i}=t,{t:a}=ut();if(n.length===0)return null;let l;if(e[0]!==n||e[1]!==i||e[2]!==r||e[3]!==a){let d;e[5]!==i||e[6]!==r||e[7]!==a?(d=p=>{const m=Xh(p),u=r===p.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>i(p.path),className:ce("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(Zn,{filePath:p.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:m.color},title:a(m.descriptionKey),"aria-label":a(m.descriptionKey),children:m.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:p.path,children:p.path}),Sl(p.insertions,p.deletions)]})},p.path)},e[5]=i,e[6]=r,e[7]=a,e[8]=d):d=e[8],l=n.map(d),e[0]=n,e[1]=i,e[2]=r,e[3]=a,e[4]=l}else l=e[4];let c;return e[9]!==l?(c=s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:l})}),e[9]=l,e[10]=c):c=e[10],c}),t2=o.memo(t=>{const e=at.c(21),{filePath:n,diff:r,isVisible:i,renderSideBySide:a}=t,{t:l}=ut(),c=r.original.length>0,d=r.modified.length>0;if(!i){let v;return e[0]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=v):v=e[0],v}const p=a?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=a?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"size layout"},e[1]=u):u=e[1];let h;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==a||e[7]!==l?(h=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l("diffView.image.original")}),s.jsx("img",{src:r.original,alt:l("diffView.image.originalAlt",{path:n}),className:a?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=c,e[5]=m,e[6]=a,e[7]=l,e[8]=h):h=e[8];let x;e[9]!==r.modified||e[10]!==n||e[11]!==d||e[12]!==c||e[13]!==m||e[14]!==a||e[15]!==l?(x=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:l("diffView.image.modifiedAlt",{path:n}),className:a?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=d,e[12]=c,e[13]=m,e[14]=a,e[15]=l,e[16]=x):x=e[16];let f;return e[17]!==p||e[18]!==h||e[19]!==x?(f=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:u,children:s.jsxs("div",{className:p,children:[h,x]})}),e[17]=p,e[18]=h,e[19]=x,e[20]=f):f=e[20],f}),s2=o.memo(t=>{const e=at.c(20),{filePath:n,diff:r,renderSideBySide:i}=t,{t:a}=ut(),l=r.original.length>0,c=r.modified.length>0,d=i?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",p=i?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let u;e[1]!==r.original||e[2]!==n||e[3]!==l||e[4]!==p||e[5]!==i||e[6]!==a?(u=l&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a("diffView.image.original")}),s.jsx("img",{src:r.original,alt:a("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=l,e[4]=p,e[5]=i,e[6]=a,e[7]=u):u=e[7];let h;e[8]!==r.modified||e[9]!==n||e[10]!==c||e[11]!==l||e[12]!==p||e[13]!==i||e[14]!==a?(h=c&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a(l?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:a("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=c,e[11]=l,e[12]=p,e[13]=i,e[14]=a,e[15]=h):h=e[15];let x;return e[16]!==d||e[17]!==u||e[18]!==h?(x=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,h]})}),e[16]=d,e[17]=u,e[18]=h,e[19]=x):x=e[19],x}),n2=o.memo(t=>{const e=at.c(15),{filePath:n,diff:r,renderSideBySide:i,wrapLines:a}=t;let l;e[0]!==n?(l=xa(n)||"text",e[0]=n,e[1]=l):l=e[1];const c=l;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Qh,{}),e[2]=m):m=e[2],m}if(so(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==i?(m=s.jsx(s2,{filePath:n,diff:r,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=i,e[6]=m):m=e[6],m}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==c||e[12]!==i||e[13]!==a?(p=s.jsx("div",{className:"w-full",style:d,children:s.jsx(Gd,{original:r.original,modified:r.modified,language:c,fileName:n,renderSideBySide:i,wrapLines:a,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=c,e[12]=i,e[13]=a,e[14]=p):p=e[14],p}),r2=o.memo(t=>{const e=at.c(15),{filePath:n,diff:r,isVisible:i,renderSideBySide:a,wrapLines:l}=t;let c;e[0]!==n?(c=xa(n)||"text",e[0]=n,e[1]=c):c=e[1];const d=c;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Qh,{}),e[2]=m):m=e[2],m}if(!i)return null;if(so(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==i||e[6]!==a?(m=s.jsx(t2,{filePath:n,diff:r,isVisible:i,renderSideBySide:a}),e[3]=r,e[4]=n,e[5]=i,e[6]=a,e[7]=m):m=e[7],m}let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==d||e[12]!==a||e[13]!==l?(p=s.jsx(Cs,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Gd,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:a,wrapLines:l,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=a,e[13]=l,e[14]=p):p=e[14],p}),i2=o.memo(t=>{const e=at.c(122),{directory:n,file:r,layout:i,wrapLines:a,scrollRootRef:l,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:h,showOpenInEditorAction:x,isOpeningInEditor:f,onOpenInEditor:v}=t,y=m===void 0?!1:m,g=u===void 0?null:u,w=h===void 0?0:h,b=x===void 0?!1:x,k=f===void 0?!1:f,{t:I}=ut(),{git:j}=Pn();let N;e[0]!==n||e[1]!==r.path?(N=qe=>qe.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=N):N=e[2];const D=tn(N),E=tn(o2),T=Ie(l2),[C,S]=o.useState(!y),[M,A]=o.useState(!1),[R,z]=o.useState(0),[B,V]=o.useState(null),[$,_]=o.useState(!1),[X,O]=o.useState(!1),J=o.useRef(null),Q=o.useRef(null);let ne;e[3]!==r?(ne=Xh(r),e[3]=r,e[4]=ne):ne=e[4];const G=ne,le=i==="side-by-side";let oe;e:{if(!D){oe=null;break e}let qe;e[5]!==D.isBinary||e[6]!==D.modified||e[7]!==D.original?(qe={original:D.original,modified:D.modified,isBinary:D.isBinary},e[5]=D.isBinary,e[6]=D.modified,e[7]=D.original,e[8]=qe):qe=e[8],oe=qe}const F=oe;let U;e[9]!==r.path||e[10]!==p?(U=qe=>{Q.current=qe,p(r.path,qe)},e[9]=r.path,e[10]=p,e[11]=U):U=e[11];const W=U;let te;e[12]===Symbol.for("react.memo_cache_sentinel")?(te=qe=>{S(qe),qe&&A(!0)},e[12]=te):te=e[12];const K=te;let ae;e[13]!==r.path||e[14]!==d?(ae=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=ae):ae=e[15];const ve=ae;let re,be;e[16]!==M||e[17]!==C||e[18]!==l?(re=()=>{if(!C||M)return;const qe=Q.current;if(!qe)return;if(!l.current||typeof IntersectionObserver>"u"){A(!0);return}const Te=new IntersectionObserver(We=>{We.some(c2)&&(A(!0),Te.disconnect())},{root:l.current,rootMargin:"200px 0px",threshold:.1});return Te.observe(qe),()=>Te.disconnect()},be=[M,C,l],e[16]=M,e[17]=C,e[18]=l,e[19]=re,e[20]=be):(re=e[19],be=e[20]),o.useEffect(re,be);let pe,ye;e[21]!==w||e[22]!==g||e[23]!==r.path?(pe=()=>{w<=0||g!==r.path||(S(!0),A(!0))},ye=[w,g,r.path],e[21]=w,e[22]=g,e[23]=r.path,e[24]=pe,e[25]=ye):(pe=e[24],ye=e[25]),o.useEffect(pe,ye);let ie,ue;e[26]!==F||e[27]!==R||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==M||e[32]!==C||e[33]!==E?(ie=()=>{if(!C||!M)return;if(!n||F){J.current=null,_(!1);return}const qe=`${n}::${r.path}::${R}`;if(J.current===qe)return;J.current=qe,V(null),_(!0);let Te=!1;const We=j.getGitFileDiff(n,{path:r.path}),Ze=new Promise(d2);return Promise.race([We,Ze]).then(Qe=>{Te||(E(n,r.path,{original:Qe.original??"",modified:Qe.modified??"",isBinary:Qe.isBinary}),_(!1))}).catch(Qe=>{if(Te)return;const he=Qe instanceof Error?Qe.message:String(Qe);V(he),_(!1)}),()=>{Te=!0,J.current===qe&&(J.current=null)}},ue=[n,F,R,r.path,j,M,C,E],e[26]=F,e[27]=R,e[28]=n,e[29]=r.path,e[30]=j,e[31]=M,e[32]=C,e[33]=E,e[34]=ie,e[35]=ue):(ie=e[34],ue=e[35]),o.useEffect(ie,ue);let se;e[36]!==ve||e[37]!==C?(se=()=>{K(!C),ve()},e[36]=ve,e[37]=C,e[38]=se):se=e[38];const Ne=se,Ce=C?"rounded-b-none":"rounded-b-xl",je=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let we;e[39]!==Ce||e[40]!==je?(we=ce("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Ce,"text-muted-foreground hover:text-foreground",je),e[39]=Ce,e[40]=je,e[41]=we):we=e[41];let ke;e[42]===Symbol.for("react.memo_cache_sentinel")?(ke=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[42]=ke):ke=e[42];let xe;e[43]!==C?(xe=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:C?s.jsx(P,{name:"arrow-down-s",className:"size-4"}):s.jsx(P,{name:"arrow-right-s",className:"size-4"})}),e[43]=C,e[44]=xe):xe=e[44];let me;e[45]!==G.color?(me={color:G.color},e[45]=G.color,e[46]=me):me=e[46];let Me;e[47]!==G.descriptionKey||e[48]!==I?(Me=I(G.descriptionKey),e[47]=G.descriptionKey,e[48]=I,e[49]=Me):Me=e[49];let Ue;e[50]!==G.descriptionKey||e[51]!==I?(Ue=I(G.descriptionKey),e[50]=G.descriptionKey,e[51]=I,e[52]=Ue):Ue=e[52];let q;e[53]!==G.code||e[54]!==me||e[55]!==Me||e[56]!==Ue?(q=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:me,title:Me,"aria-label":Ue,children:G.code}),e[53]=G.code,e[54]=me,e[55]=Me,e[56]=Ue,e[57]=q):q=e[57];const Se=r.path;let $e;e[58]!==r.path?($e=s.jsx(Zn,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=$e):$e=e[59];let Pe;if(e[60]!==r.path){e:{const qe=r.path.lastIndexOf("/");if(qe===-1){let it;e[62]===Symbol.for("react.memo_cache_sentinel")?(it={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[62]=it):it=e[62],Pe=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:it,children:r.path});break e}const Te=r.path.slice(0,qe),We=r.path.slice(qe+1);let Ze;e[63]===Symbol.for("react.memo_cache_sentinel")?(Ze={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=Ze):Ze=e[63];let Qe;e[64]!==Te?(Qe=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:Ze,children:Te}),e[64]=Te,e[65]=Qe):Qe=e[65];let he;e[66]===Symbol.for("react.memo_cache_sentinel")?(he=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[66]=he):he=e[66];let Ge;e[67]!==We?(Ge=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[he,s.jsx("span",{className:"text-foreground",children:We})]}),e[67]=We,e[68]=Ge):Ge=e[68];let Ve;e[69]!==Qe||e[70]!==Ge?(Ve=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[Qe,Ge]}),e[69]=Qe,e[70]=Ge,e[71]=Ve):Ve=e[71],Pe=Ve}e[60]=r.path,e[61]=Pe}else Pe=e[61];let fe;e[72]!==$e||e[73]!==Pe?(fe=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[$e,Pe]}),e[72]=$e,e[73]=Pe,e[74]=fe):fe=e[74];let L;e[75]!==r.path||e[76]!==fe?(L=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Se,children:fe}),e[75]=r.path,e[76]=fe,e[77]=L):L=e[77];let Z;e[78]!==xe||e[79]!==q||e[80]!==L?(Z=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[xe,q,L]}),e[78]=xe,e[79]=q,e[80]=L,e[81]=Z):Z=e[81];let Y;e[82]!==r.deletions||e[83]!==r.insertions?(Y=Sl(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=Y):Y=e[84];let Ee;e[85]!==F||e[86]!==r.path||e[87]!==k||e[88]!==v||e[89]!==b||e[90]!==I?(Ee=b&&v?s.jsx(ge,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:I("diffView.actions.openFileInEditorAtChange"),onClick:qe=>{qe.stopPropagation(),v(r.path,F)},disabled:k,children:k?s.jsx(P,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(P,{name:"edit",className:"size-3.5"})}):null,e[85]=F,e[86]=r.path,e[87]=k,e[88]=v,e[89]=b,e[90]=I,e[91]=Ee):Ee=e[91];const Ae=le?"side-by-side":"unified";let Je;e[92]!==r.path||e[93]!==T?(Je=qe=>{const Te=qe==="side-by-side"?"side-by-side":"inline";T(r.path,Te)},e[92]=r.path,e[93]=T,e[94]=Je):Je=e[94];let de;e[95]!==Ae||e[96]!==Je?(de=s.jsx(Zf,{mode:Ae,onModeChange:Je,className:"opacity-70"}),e[95]=Ae,e[96]=Je,e[97]=de):de=e[97];let ze;e[98]!==Y||e[99]!==Ee||e[100]!==de?(ze=s.jsxs("div",{className:"relative flex items-center gap-2",children:[Y,Ee,de]}),e[98]=Y,e[99]=Ee,e[100]=de,e[101]=ze):ze=e[101];let rt;e[102]!==Ne||e[103]!==we||e[104]!==Z||e[105]!==ze?(rt=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:Ne,className:we,children:[ke,Z,ze]})}),e[102]=Ne,e[103]=we,e[104]=Z,e[105]=ze,e[106]=rt):rt=e[106];let Re;e[107]!==F||e[108]!==B||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==X||e[113]!==C||e[114]!==$||e[115]!==le||e[116]!==a?(Re=C&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[B?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:B}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>z(u2),children:"Retry"})]}):null,$&&!F&&!B?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"animate-spin"}),"Loading diff…"]}):null,F&&!X&&r.insertions+r.deletions>$m?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsxs("div",{className:"typography-ui-label font-semibold text-foreground",children:["Large diff (",r.insertions+r.deletions," changed lines)"]}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>O(!0),children:"Render anyway"})]}):null,F&&(X||r.insertions+r.deletions<=$m)?s.jsx(n2,{filePath:r.path,diff:F,renderSideBySide:le,wrapLines:a}):null]}),e[107]=F,e[108]=B,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=X,e[113]=C,e[114]=$,e[115]=le,e[116]=a,e[117]=Re):Re=e[117];let Xe;return e[118]!==W||e[119]!==rt||e[120]!==Re?(Xe=s.jsxs("div",{ref:W,className:"scroll-mt-4",children:[rt,Re]}),e[118]=W,e[119]=rt,e[120]=Re,e[121]=Xe):Xe=e[121],Xe}),Zh=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:i=!1})=>{const{t:a}=ut(),{git:l,files:c}=Pn(),d=Ir(),{screenWidth:p,isMobile:m}=rn(),u=Ed(d??null),h=Ol(d??null),x=Fd(d??null),f=tn(Z=>Z.setActiveDirectory),v=tn(Z=>Z.ensureStatus),y=tn(Z=>Z.fetchStatus),g=tn(Z=>Z.setDiff),[w,b]=o.useState(null),[k,I]=o.useState(null),[j,N]=o.useState(0),[D,E]=o.useState(null),[T,C]=o.useState(0),[S,M]=o.useState(null),A=o.useRef(null),R=Ie(Z=>Z.pendingDiffFile),z=Ie(Z=>Z.setPendingDiffFile),B=Ie(Z=>Z.diffLayoutPreference),V=Ie(Z=>Z.diffFileLayout),$=Ie(Z=>Z.setDiffFileLayout),_=Ie(Z=>Z.diffWrapLines),X=Ie(Z=>Z.setDiffWrapLines),O=Ie(Z=>Z.diffViewMode),J=Ie(Z=>Z.setDiffViewMode),Q=Ie(Z=>Z.openContextFileAtLine),ne=_,G=O==="stacked",le=m||p<=768,oe=!t&&!le&&p>=1024,F=o.useRef(null),U=o.useRef(new Map),W=o.useRef(null),te=o.useRef(null),K=o.useRef(!1);o.useEffect(()=>{if(!r||!G||!D)return;const Z=F.current;if(!Z)return;let Y=null,Ee=!1,Ae=0;const Je=Date.now()+1200;let de=0;const ze=()=>{Ee||(Ee=!0,E(null))},rt=()=>{ze()},Re=()=>{if(de>0){de-=1;return}ze()};window.addEventListener("wheel",rt,{passive:!0,capture:!0}),window.addEventListener("touchstart",rt,{passive:!0,capture:!0}),window.addEventListener("pointerdown",rt,{capture:!0}),window.addEventListener("keydown",rt,{capture:!0}),Z.addEventListener("scroll",Re,{passive:!0});const Xe=()=>{if(Ee||Date.now()>Je){ze();return}const qe=F.current,Te=U.current.get(D);if(!qe||!Te){ze();return}const We=qe.getBoundingClientRect(),Qe=Te.getBoundingClientRect().top-We.top;if(Math.abs(Qe)<=1){if(Ae+=1,Ae>=2){ze();return}}else{Ae=0;const he=Math.max(0,qe.scrollHeight-qe.clientHeight),Ge=Math.min(he,Math.max(0,qe.scrollTop+Qe));if(Math.abs(Ge-qe.scrollTop)<=.5){ze();return}de+=1,qe.scrollTop=Ge}Y=window.requestAnimationFrame(Xe)};return Y=window.requestAnimationFrame(Xe),()=>{Ee=!0,Y!==null&&window.cancelAnimationFrame(Y),window.removeEventListener("wheel",rt,!0),window.removeEventListener("touchstart",rt,!0),window.removeEventListener("pointerdown",rt,!0),window.removeEventListener("keydown",rt,!0),Z.removeEventListener("scroll",Re)}},[G,r,D]);const ae=o.useMemo(()=>{if(!h?.files)return[];const Z=h.diffStats??{};return h.files.map(Y=>({...Y,insertions:Z[Y.path]?.insertions??0,deletions:Z[Y.path]?.deletions??0,isNew:qN(Y)})).sort((Y,Ee)=>Y.path.localeCompare(Ee.path))},[h]),ve=o.useMemo(()=>w?ae.find(Z=>Z.path===w)??null:null,[ae,w]),re=o.useCallback(Z=>{const Y=V[Z.path];if(Y)return Y;if(B==="inline")return"inline";if(B==="side-by-side")return"side-by-side";const Ee=p<WN;return Z.isNew||Ee?"inline":"side-by-side"},[V,B,p]),be=o.useMemo(()=>ve?re(ve):null,[re,ve]);o.useEffect(()=>{d&&(f(d),v(d,l))},[d,f,v,l]),o.useEffect(()=>{if(d)return Sr.onGitRefreshHint(Z=>{Bm(Z.directory)===Bm(d)&&y(d,l)})},[d,y,l]),o.useEffect(()=>{R&&(b(R),z(null),G&&(K.current=!0,W.current=R,I(R),N(Z=>Z+1)))},[G,R,z]),o.useEffect(()=>{!w&&!R&&ae.length>0&&b(ae[0].path)},[ae,w,R]),o.useEffect(()=>{w&&ae.length>0&&(ae.some(Y=>Y.path===w)||b(ae[0]?.path??null))},[ae,w]);const pe=o.useCallback((Z,Y)=>{const Ee=U.current;Y?Ee.set(Z,Y):Ee.delete(Z)},[]),ye=o.useCallback(Z=>{const Y=U.current.get(Z),Ee=F.current;if(!Y||!Ee)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const Ae=Ee.getBoundingClientRect(),de=Y.getBoundingClientRect().top-Ae.top,ze=Math.max(0,Ee.scrollHeight-Ee.clientHeight),rt=Ee.scrollTop+de,Re=Math.min(ze,Math.max(0,rt)),Xe=Math.abs(Re-Ee.scrollTop)>.5;Ee.scrollTop=Re;const qe=Math.abs(de)<=1,Te=Re<=.5||Re>=ze-.5;return{ok:!0,aligned:qe,didMove:Xe,atScrollLimit:Te,delta:de}},[]);o.useEffect(()=>{if(!G){W.current=null,K.current=!1,te.current!==null&&(window.cancelAnimationFrame(te.current),te.current=null);return}if(!W.current)return;let Y=0;const Ee=120;let Ae=!1,Je=0,de=!1,ze=0;const rt=Date.now()+2e3,Re=()=>{de||(de=!0,window.removeEventListener("wheel",qe,!0),window.removeEventListener("touchstart",qe,!0),window.removeEventListener("pointerdown",qe,!0),window.removeEventListener("keydown",qe,!0),We?.removeEventListener("scroll",Te))},Xe=()=>{Ae||(Ae=!0,Re(),W.current=null,K.current=!1,te.current!==null&&(window.cancelAnimationFrame(te.current),te.current=null))},qe=()=>{Xe()},Te=()=>{if(Je>0){Je-=1;return}Xe()},We=F.current;window.addEventListener("wheel",qe,{passive:!0,capture:!0}),window.addEventListener("touchstart",qe,{passive:!0,capture:!0}),window.addEventListener("pointerdown",qe,{capture:!0}),window.addEventListener("keydown",qe,{capture:!0}),We?.addEventListener("scroll",Te,{passive:!0});const Ze=()=>{if(Date.now()>rt){Xe(),te.current=null;return}if(Ae){te.current=null;return}const Qe=W.current;if(!Qe){Xe(),te.current=null;return}Je+=1;const he=ye(Qe);if(!he.ok){Je=Math.max(0,Je-1),Y+=1,Y<Ee?te.current=window.requestAnimationFrame(Ze):(Xe(),te.current=null);return}if(!he.aligned){if(Y+=1,he.didMove){if(ze=0,Y<Ee){te.current=window.requestAnimationFrame(Ze);return}}else if(ze+=1,ze<6&&(he.atScrollLimit||Math.abs(he.delta)>1)){te.current=window.requestAnimationFrame(Ze);return}}r&&K.current&&E(Qe),Xe()};return te.current=window.requestAnimationFrame(Ze),()=>{Ae=!0,Re(),te.current!==null&&(window.cancelAnimationFrame(te.current),te.current=null)}},[G,r,ye,w,j]);const ie=o.useCallback(Z=>{b(Z)},[]),ue=o.useCallback(Z=>{if(te.current!==null&&(window.cancelAnimationFrame(te.current),te.current=null),W.current=null,b(Z),!G){K.current=!1;return}K.current=!0,W.current=Z,ye(Z)},[G,ye]),se=o.useCallback(Z=>{J(Z),Z==="stacked"&&w&&(ye(w).aligned||(W.current=w))},[ye,w,J]),Ne=o.useCallback(Z=>{const Y=Z==="side-by-side"?"side-by-side":"inline";if(G){ae.forEach(Ee=>{$(Ee.path,Y)});return}ve&&$(ve.path,Y)},[ae,G,ve,$]),Ce=(be??"side-by-side")==="side-by-side",je=!n&&(!G||!oe),we=tn(o.useCallback(Z=>!d||!w?null:Z.directories.get(d)?.diffCache.get(w)??null,[d,w])),ke=o.useMemo(()=>we?{original:we.original,modified:we.modified,isBinary:we.isBinary}:null,[we]),[xe,me]=o.useState(null),Me=o.useCallback(async(Z,Y)=>{if(!(!d||!Z)){me(Z);try{let Ee=null;if(Y&&!Y.isBinary&&!so(Z)&&(Ee=zm(Y.original,Y.modified)),Ee===null)try{const rt=await l.getGitDiff(d,{path:Z,contextLines:3});Ee=JN(rt.diff)}catch{Ee=null}let Ae=Y;if(Ee===null||!Ae){const rt=await l.getGitFileDiff(d,{path:Z});Ae={original:rt.original??"",modified:rt.modified??"",isBinary:rt.isBinary},g(d,Z,Ae)}const Je=Ee??(Ae.isBinary||so(Z)?1:zm(Ae.original,Ae.modified)),de=QN(d,Z),ze=await Qd(c,de);if(!ze.ok){H.error(Jd(ze.reason));return}Q(d,de,Je,1)}finally{me(Ee=>Ee===Z?null:Ee)}}},[d,c,l,Q,g]),Ue=o.useCallback(async()=>{w&&await Me(w,ke)},[Me,ke,w]),q=!!(w&&xe===w),Se=!!we,$e=!G&&!!w&&!Se;o.useEffect(()=>{if(G)return;if(M(null),!d||!w){A.current=null;return}if(we){A.current=null;return}const Z=`${d}::${w}::${T}`;if(A.current===Z)return;A.current=Z;let Y=!1;const Ee=l.getGitFileDiff(d,{path:w}),Ae=dd,Je=new Promise((de,ze)=>{setTimeout(()=>ze(new Error(`Timed out after ${Ae}ms`)),Ae)});return Promise.race([Ee,Je]).then(de=>{Y||g(d,w,{original:de.original??"",modified:de.modified??"",isBinary:de.isBinary})}).catch(de=>{if(Y)return;const ze=de instanceof Error?de.message:String(de);M(ze)}),()=>{Y=!0,A.current===Z&&(A.current=null)}},[d,G,w,we,l,g,T]);const Pe=()=>!d||!w||!ke?null:s.jsx(r2,{filePath:w,diff:ke,isVisible:!0,renderSideBySide:Ce,wrapLines:ne},w),fe=()=>{if(!d)return null;const Z=KN(ae.length);return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[oe&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:a("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:ae.length})]}),s.jsx(e2,{changedFiles:ae,selectedFile:w,onSelectFile:ue})]}),s.jsx(Cs,{ref:F,outerClassName:"flex-1 min-h-0 h-full",className:"pr-2",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx("div",{className:"flex flex-col gap-3",children:ae.map((Y,Ee)=>s.jsx(i2,{directory:d,file:Y,layout:re(Y),wrapLines:ne,scrollRootRef:F,isSelected:Y.path===w,onSelect:ie,registerSectionRef:pe,defaultCollapsed:e?!0:Ee>=Z,expandRequestPath:k,expandRequestNonce:j,showOpenInEditorAction:i,isOpeningInEditor:xe===Y.path,onOpenInEditor:(Ae,Je)=>{Me(Ae,Je)}},Y.path))})})]})},L=()=>d?x&&!h?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"animate-spin"}),a("diffView.state.loadingRepositoryStatus")]}):u===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:a("diffView.state.notGitRepository")}):ae.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:a("diffView.state.cleanWorkingTree")}):G?fe():s.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden px-3 py-3 relative","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[Pe(),$e&&!Se&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:S?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:a("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:S}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{M(null),C(Z=>Z+1)},children:a("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"animate-spin"}),a("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:a("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!m&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(P,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:x&&!h?a("diffView.state.loadingChanges"):ae.length===1?a("diffView.summary.changedFilesSingle",{count:ae.length}):a("diffView.summary.changedFilesPlural",{count:ae.length})})]}),!le&&s.jsx(ZN,{mode:O,onModeChange:se}),je&&s.jsx(XN,{changedFiles:ae,selectedFile:w,selectedFileEntry:ve,onSelectFile:ue,isMobile:le,showModeSelector:le,mode:O,onModeChange:se}),s.jsx("div",{className:"flex-1"}),ve&&s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>X(!_),className:ce("h-5 w-5 p-0 transition-opacity",ne?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:a(ne?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(P,{name:"text-wrap",className:"size-4"})}),i&&ve&&!G&&s.jsx(ge,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Ue()},disabled:q,title:a("diffView.actions.openFileAtFirstChangedLine"),children:q?s.jsx(P,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(P,{name:"edit",className:"size-3.5"})}),ve&&be&&s.jsx(Zf,{mode:be==="side-by-side"?"side-by-side":"unified",onModeChange:Ne})]}),L()]})},a2=()=>{const t=at.c(6),{git:e}=Pn(),n=Ir(),r=tn(m2),i=tn(p2),a=Ib(n??null);let l,c;return t[0]!==n||t[1]!==i||t[2]!==e||t[3]!==r?(l=()=>{n&&(r(n),i(n,e))},c=[n,r,i,e],t[0]=n,t[1]=i,t[2]=e,t[3]=r,t[4]=l,t[5]=c):(l=t[4],c=t[5]),o.useEffect(l,c),a};function o2(t){return t.setDiff}function l2(t){return t.setDiffFileLayout}function c2(t){return t.isIntersecting}function d2(t,e){setTimeout(()=>e(new Error(`Timed out after ${dd}ms`)),dd)}function u2(t){return t+1}function m2(t){return t.setActiveDirectory}function p2(t){return t.ensureStatus}const f2=Object.freeze(Object.defineProperty({__proto__:null,DiffView:Zh,useDiffFileCount:a2},Symbol.toStringTag,{value:"Module"})),h2={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},g2={case:"Match case",re:"Regular expression",word:"Match whole word"};function x2(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(h2)){const i=e.querySelector(`button[name="${n}"]`);i&&!i.title&&(i.title=r)}for(const[n,r]of Object.entries(g2)){const a=e.querySelector(`input[name="${n}"]`)?.parentElement;a&&!a.title&&(a.title=r)}}}const Vm=new Sa,_m=new Sa,Um=new Sa,Wm=new Sa,Km=new Sa,Hm=new Sa,Gm=t=>t,Nc=xx,b2=bx,y2=yx;class v2 extends vx{constructor(e,n){super(),this.id=e,this.containerMap=n}id;containerMap;toDOM(){let e=this.containerMap.get(this.id);return e||(e=document.createElement("div"),e.className="oc-block-widget",e.dataset.widgetId=this.id,this.containerMap.set(this.id,e)),e}eq(e){return e.id===this.id}destroy(){}}const qm=(t,e)=>!t||t.length===0?[]:gx.define({create(n){const r=new Ff,i=[...t].sort((a,l)=>a.afterLine-l.afterLine);for(const a of i){const l=n.doc.lines;if(a.afterLine>l)continue;const c=n.doc.line(a.afterLine);r.add(c.to,c.to,Lf.widget({widget:new v2(a.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>Xn.decorations.from(n)}),Ym=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return hx.fromClass(class{decorations;constructor(r){this.decorations=this.build(r)}update(r){(r.docChanged||r.viewportChanged)&&(this.decorations=this.build(r.view))}build(r){const i=new Ff;for(let a=e;a<=n&&a<=r.state.doc.lines;a+=1){const l=r.state.doc.line(a);i.add(l.from,l.from,Lf.line({class:"oc-cm-selected-line"}))}return i.finish()}},{decorations:r=>r.decorations})};function ud({value:t,onChange:e,extensions:n,className:r,readOnly:i,lineNumbersConfig:a,highlightLines:l,onViewReady:c,onViewDestroy:d,blockWidgets:p,enableSearch:m,searchOpen:u,onSearchOpenChange:h}){const x=o.useRef(null),f=o.useRef(null),v=o.useRef(t),y=o.useRef(e),g=o.useRef(c),w=o.useRef(d),b=o.useRef(h),k=o.useRef(p),I=o.useRef(new Map),[j,N]=o.useState([]),D=o.useCallback(T=>{const C=(T??[]).map(S=>{const M=I.current.get(S.id);return M?{id:S.id,content:S.content,container:M}:null}).filter(S=>S!==null);N(S=>S.length===C.length&&S.every((M,A)=>{const R=C[A];return M.id===R.id&&M.content===R.content&&M.container===R.container})?S:C)},[]),E=o.useCallback(T=>{const C=x.current,S=T??f.current;if(!C||!S)return;const M=S.dom.querySelector(".cm-gutters"),A=M instanceof HTMLElement?M.getBoundingClientRect().width:0;C.style.setProperty("--oc-editor-gutter-width",`${A}px`)},[]);return o.useEffect(()=>{v.current=t},[t]),o.useEffect(()=>{y.current=e},[e]),o.useEffect(()=>{g.current=c,w.current=d},[c,d]),o.useEffect(()=>{b.current=h},[h]),o.useEffect(()=>{k.current=p,D(p)},[p,D]),o.useEffect(()=>{if(!x.current)return;const T=(()=>{if(typeof document>"u")return null;const S=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(S)return S;const M=window.__APP_CSP_NONCE__;return typeof M=="string"&&M.length>0?M:null})(),C=lx.create({doc:v.current,extensions:[...T?[Xn.cspNonce.of(T)]:[],cx({fixed:!0}),Vm.of(mu(a)),dx(),ux.of(" "),Ql.of([mx,...px,...fx]),Xn.updateListener.of(S=>{E(S.view),(S.viewportChanged||S.geometryChanged)&&D(k.current);const M=pu(S.startState),A=pu(S.state);if(M!==A&&b.current?.(A),!S.docChanged)return;const R=S.state.doc.toString();v.current=R,y.current(R),D(k.current)}),_m.of(Xn.editable.of(!i)),Um.of(n??[]),Wm.of(Ym(l)),Km.of(qm(p,I.current)),Hm.of(m?[fu({top:!0}),Ql.of(Gm(hu))]:[])]});return f.current=new Xn({state:C,parent:x.current}),Nc(f.current,f.current.state.doc.length,200),f.current.requestMeasure(),requestAnimationFrame(()=>{E(f.current),D(k.current)}),f.current&&g.current?.(f.current),()=>{w.current?.(),f.current?.destroy(),f.current=null,N([])}},[k,E,D]),o.useEffect(()=>{const T=f.current;T&&(T.dispatch({effects:[Vm.reconfigure(mu(a)),_m.reconfigure(Xn.editable.of(!i)),Um.reconfigure(n??[]),Wm.reconfigure(Ym(l)),Km.reconfigure(qm(p,I.current)),Hm.reconfigure(m?[fu({top:!0}),Ql.of(Gm(hu))]:[])]}),Nc(T,T.state.doc.length,200),T.requestMeasure(),requestAnimationFrame(()=>{E(T),D(k.current)}))},[n,l,a,i,p,m,E,D]),o.useEffect(()=>{const T=f.current;!T||m===!1||(u?(b2(T),requestAnimationFrame(()=>{x2(T.dom)})):y2(T))},[u,m]),o.useEffect(()=>{const T=f.current;if(!T)return;const C=T.state.doc.toString();C!==t&&(T.dispatch({changes:{from:0,to:C.length,insert:t}}),Nc(T,T.state.doc.length,300),T.requestMeasure(),requestAnimationFrame(()=>E(T)))},[t,E]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:x,className:ce("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),j.map(T=>Wa.createPortal(T.content,T.container,T.id))]})}const w2=(t,e)=>{if(!e)return null;const n=Number.parseInt(t.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,e.state.doc.lines)},Qm=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Jm=(t,e,n)=>{const r=t.state.doc.line(e),i=Math.max(1,Math.min(n,r.length+1)),a=r.from+i-1;t.dispatch({selection:wx.cursor(a),effects:Xn.scrollIntoView(a,{y:"center"})})};function j2({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:i}=ut(),[a,l]=o.useState(""),c=o.useRef(null),d=o.useRef(!1),p=o.useRef(null),m=o.useRef(null),u=o.useMemo(()=>w2(a,n),[a,n]);o.useEffect(()=>{!t||!n||(d.current=!1,c.current=Qm(n,n.state.selection),l(""))},[t,n]),o.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),o.useEffect(()=>{if(!(!t||!n||!c.current)){if(u===null){const{selection:y}=c.current;n.dispatch({selection:y,effects:Xn.scrollIntoView(y.main.from,{y:"center"})});return}Jm(n,u,c.current.character)}},[u,t,n]);const h=o.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:y}=c.current;n.dispatch({selection:y,effects:Xn.scrollIntoView(y.main.from,{y:"center"})})},[n]),x=o.useCallback(y=>{y||h(),e(y)},[e,h]),f=o.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,Jm(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);o.useEffect(()=>{if(!t)return;const y=w=>{const b=p.current,k=w.target;!b||!(k instanceof Node)||b.contains(k)||x(!1)},g=w=>{w.key==="Escape"&&(w.preventDefault(),x(!1))};return document.addEventListener("pointerdown",y,!0),document.addEventListener("keydown",g,!0),()=>{document.removeEventListener("pointerdown",y,!0),document.removeEventListener("keydown",g,!0)}},[x,t,r]);const v=o.useMemo(()=>{if(!n)return i("goToLineDialog.helper.editorUnavailable");if(u===null){const y=c.current??Qm(n,n.state.selection);return i("goToLineDialog.helper.currentLineRange",{current:y.lineNumber,max:n.state.doc.lines})}return i("goToLineDialog.helper.goToLine",{line:u})},[u,i,n]);return r==="inline"?t?s.jsxs("div",{ref:p,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Bt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:a,onChange:y=>l(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),f())},placeholder:i("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(ge,{variant:"outline",size:"xs",onClick:f,disabled:!n||u===null,className:"h-6 px-2",children:i("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:p,className:ce("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(Bt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:a,onChange:y=>l(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),f())},placeholder:i("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:v})]})})}const md=t=>{const e=at.c(11),{currentMode:n,onToggle:r}=t,i=n==="preview",a=i?"Switch to edit mode":"Switch to preview mode",l=i?"Edit":"Preview";let c;e[0]!==i?(c=i?s.jsx(P,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(P,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=i,e[1]=c):c=e[1];let d;e[2]!==a||e[3]!==r||e[4]!==c?(d=s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"sm",onClick:r,"aria-label":a,className:"h-5 w-5 p-0",children:c})}),e[2]=a,e[3]=r,e[4]=c,e[5]=d):d=e[5];let p;e[6]!==l?(p=s.jsx(Dt,{sideOffset:8,children:l}),e[6]=l,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs(Pt,{children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},pd=jx.define(Nx);function N2(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return pd;case"json":case"jsonc":case"json5":return Bf().language;case"js":case"javascript":return ra().language;case"jsx":return ra({jsx:!0}).language;case"ts":case"typescript":return ra({typescript:!0}).language;case"tsx":return ra({typescript:!0,jsx:!0}).language;case"html":return Gc().language;case"css":return $f().language;case"py":case"python":return Of().language;case"heex":case"eex":case"leex":return Gc().language;default:return zf.matchLanguageName(Vf,e,!0)}}const eg=t=>t.split("/").pop()?.toLowerCase()??"",S2=t=>{const e=eg(t);return e?zf.matchFilename(Vf,e):null},k2=()=>Ba(qc.define([{tag:[ot.heading1,ot.heading2,ot.heading3,ot.heading4,ot.heading5,ot.heading6],fontWeight:"600"},{tag:ot.strong,fontWeight:"600"},{tag:ot.emphasis,fontStyle:"italic"},{tag:ot.strikethrough,textDecoration:"line-through"},{tag:[ot.link,ot.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:ot.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:ot.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:ot.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:ot.heading,color:"var(--markdown-heading1, currentColor)"}]));function tg(t){const e=t.toLowerCase();switch(eg(e)){case"makefile":case"gnumakefile":return pd}const r=e.lastIndexOf("."),i=r>=0?e.slice(r+1):"";switch(i){case"ts":case"tsx":case"mts":case"cts":return ra({typescript:!0,jsx:i==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return ra({typescript:!1,jsx:i==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return Bf();case"css":case"scss":case"sass":case"less":return $f();case"html":case"htm":return Gc();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[Sx({codeLanguages:N2}),k2()];case"sh":case"bash":case"zsh":case"fish":case"env":return pd;case"py":case"pyw":case"pyi":return Of();default:return null}}async function C2(t){const e=S2(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function fd(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},i=t.colors.syntax.tokens||{},a=Xn.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:i.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:i.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:i.boolean||t.colors.syntax.base.number},".cm-builtin":{color:i.functionCall||t.colors.syntax.base.function},".cm-def":{color:i.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:i.variableOther||i.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:i.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:i.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:i.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:i.tag||t.colors.syntax.base.keyword},".cm-link":{color:i.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),l=qc.define([{tag:[ot.comment,ot.docComment,ot.meta,ot.documentMeta],class:"cm-comment"},{tag:[ot.keyword,ot.controlKeyword,ot.moduleKeyword,ot.definitionKeyword,ot.modifier],class:"cm-keyword"},{tag:[ot.operatorKeyword,ot.operator,ot.derefOperator,ot.updateOperator,ot.definitionOperator,ot.typeOperator,ot.controlOperator,ot.logicOperator,ot.bitwiseOperator,ot.arithmeticOperator,ot.compareOperator],class:"cm-operator"},{tag:[ot.punctuation,ot.separator,ot.bracket,ot.paren,ot.brace,ot.squareBracket,ot.angleBracket],class:"cm-punctuation"},{tag:[ot.string,ot.regexp,ot.attributeValue,ot.special(ot.string),ot.monospace],class:"cm-string"},{tag:ot.escape,class:"cm-string-2"},{tag:[ot.number,ot.bool,ot.atom,ot.null,ot.self],class:"cm-number"},{tag:[ot.function(ot.variableName),ot.function(ot.definition(ot.variableName)),ot.function(ot.propertyName),ot.standard(ot.variableName),ot.special(ot.variableName)],class:"cm-builtin"},{tag:ot.definition(ot.variableName),class:"cm-def"},{tag:[ot.variableName,ot.local(ot.variableName),ot.constant(ot.variableName),ot.literal],class:"cm-variable"},{tag:ot.propertyName,class:"cm-property"},{tag:ot.attributeName,class:"cm-attribute"},{tag:[ot.className,ot.typeName,ot.namespace],class:"cm-variable-3"},{tag:[ot.tagName,ot.labelName,ot.annotation,ot.macroName],class:"cm-tag"},{tag:ot.link,class:"cm-link"},{tag:[ot.heading,ot.heading1,ot.heading2,ot.heading3,ot.heading4,ot.heading5,ot.heading6],class:"cm-keyword"}]),c=qc.define([{tag:[ot.comment,ot.docComment,ot.meta,ot.documentMeta],color:t.colors.syntax.base.comment},{tag:[ot.keyword,ot.controlKeyword,ot.moduleKeyword,ot.definitionKeyword,ot.modifier],color:t.colors.syntax.base.keyword},{tag:[ot.operatorKeyword,ot.operator,ot.derefOperator,ot.updateOperator,ot.definitionOperator,ot.typeOperator,ot.controlOperator,ot.logicOperator,ot.bitwiseOperator,ot.arithmeticOperator,ot.compareOperator],color:t.colors.syntax.base.operator},{tag:[ot.string,ot.regexp,ot.attributeValue,ot.special(ot.string),ot.monospace],color:t.colors.syntax.base.string},{tag:ot.escape,color:i.stringEscape||t.colors.syntax.base.string},{tag:[ot.number,ot.bool,ot.atom,ot.null,ot.self],color:t.colors.syntax.base.number},{tag:[ot.function(ot.variableName),ot.function(ot.definition(ot.variableName)),ot.function(ot.propertyName),ot.standard(ot.variableName),ot.special(ot.variableName)],color:t.colors.syntax.base.function},{tag:ot.definition(ot.variableName),color:i.variableGlobal||t.colors.syntax.base.variable},{tag:[ot.variableName,ot.local(ot.variableName),ot.constant(ot.variableName),ot.literal],color:t.colors.syntax.base.variable},{tag:ot.propertyName,color:i.variableProperty||t.colors.syntax.base.variable},{tag:ot.attributeName,color:i.variableOther||t.colors.syntax.base.variable},{tag:[ot.className,ot.typeName,ot.namespace],color:t.colors.syntax.base.type},{tag:[ot.tagName,ot.labelName,ot.annotation,ot.macroName],color:i.tag||t.colors.syntax.base.keyword},{tag:ot.link,color:i.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[ot.punctuation,ot.separator,ot.bracket,ot.paren,ot.brace,ot.squareBracket,ot.angleBracket],color:i.punctuation||t.colors.syntax.base.comment}]);return[a,Ba(kx,{fallback:!0}),Ba(Cx),Ba(l),Ba(c)]}const P2=t=>{const e=fn(t);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const r=e.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},I2=t=>{const e=at.c(8),{label:n,iconDataUrl:r}=t,[i,a]=o.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const c=l;if(r&&!i){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>a(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=ce("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let p;return e[6]!==c?(p=s.jsx("span",{className:d,children:c}),e[6]=c,e[7]=p):p=e[7],p},A2=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),fn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const i=r==="/",a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,"")),r},D2=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Xm=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,kl=(t,e)=>{const n=fn(e),r=fn(t);if(!n||!r)return!1;const i=Xm(n),a=Xm(r);return a===i||a.startsWith(`${i}/`)},Zm=(t,e)=>{const n=fn(e),r=fn(t);if(!kl(r,n))return[];const a=r.slice(n.length).replace(/^\//,"").split("/"),l=[];let c=n;for(let d=0;d<a.length-1;d++)c=c?`${c}/${a[d]}`:a[d],l.push(c);return l},hd=(t,e)=>{if(!e)return"";const n=fn(e);if(!t||!kl(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},T2=new Set(["node_modules"]),M2=t=>{const e=at.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const i=r[n];let a;return e[1]!==i?(a=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:i}}),e[1]=i,e[2]=a):a=e[2],a},E2=t=>T2.has(t),R2=t=>{const e=fn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},F2=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Ra=2e5,sg="vinci:files:auto-save-enabled",L2=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(sg)!=="false"}catch{return!0}},ng=(t,e)=>s.jsx(Zn,{filePath:t,extension:e}),O2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},$2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},Sc=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},B2=t=>{const e=at.c(62),{node:n,root:r,isExpanded:i,isActive:a,isMobile:l,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:h,setContextMenuPath:x,onSelect:f,onToggle:v,onRevealPath:y,onOpenDialog:g}=t,{t:w}=ut(),b=n.type==="directory",{canRename:k,canCreateFile:I,canCreateFolder:j,canDelete:N,canReveal:D}=m;let E;e[0]!==I||e[1]!==j||e[2]!==N||e[3]!==k||e[4]!==D||e[5]!==n.path||e[6]!==x?(E=G=>{!k&&!I&&!j&&!N&&!D||(G?.preventDefault(),x(n.path))},e[0]=I,e[1]=j,e[2]=N,e[3]=k,e[4]=D,e[5]=n.path,e[6]=x,e[7]=E):E=e[7];const T=E;let C;e[8]!==b||e[9]!==n||e[10]!==f||e[11]!==v?(C=()=>{b?v(n.path):f(n)},e[8]=b,e[9]=n,e[10]=f,e[11]=v,e[12]=C):C=e[12];const S=C;let M;e[13]!==n.path||e[14]!==x?(M=G=>{G.stopPropagation(),x(n.path)},e[13]=n.path,e[14]=x,e[15]=M):M=e[15];const A=M,R=l?void 0:T,z=l?void 0:T,B=a?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[16]!==B?(V=ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",B),e[16]=B,e[17]=V):V=e[17];let $;e[18]!==b||e[19]!==i||e[20]!==n.extension||e[21]!==n.path?($=b?i?s.jsx(P,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(P,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):ng(n.path,n.extension),e[18]=b,e[19]=i,e[20]=n.extension,e[21]=n.path,e[22]=$):$=e[22];let _;e[23]!==n.name||e[24]!==n.path?(_=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=_):_=e[25];let X;e[26]!==b||e[27]!==d?(X=!b&&d&&s.jsx(M2,{status:d}),e[26]=b,e[27]=d,e[28]=X):X=e[28];let O;e[29]!==p||e[30]!==b?(O=b&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[29]=p,e[30]=b,e[31]=O):O=e[31];let J;e[32]!==S||e[33]!==X||e[34]!==O||e[35]!==z||e[36]!==V||e[37]!==$||e[38]!==_?(J=s.jsxs("button",{type:"button",onClick:S,onContextMenu:z,className:V,children:[$,_,X,O]}),e[32]=S,e[33]=X,e[34]=O,e[35]=z,e[36]=V,e[37]=$,e[38]=_,e[39]=J):J=e[39];let Q;e[40]!==c||e[41]!==I||e[42]!==j||e[43]!==N||e[44]!==k||e[45]!==D||e[46]!==h||e[47]!==u||e[48]!==A||e[49]!==b||e[50]!==l||e[51]!==n||e[52]!==g||e[53]!==y||e[54]!==r||e[55]!==x||e[56]!==w?(Q=(k||I||j||N||D)&&s.jsx("div",{className:ce("absolute right-1 top-1/2 -translate-y-1/2",c?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(Fs,{open:h===n.path,onOpenChange:G=>x(G?n.path:null),children:[s.jsx(Es,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"icon",className:"size-6",onClick:A,children:s.jsx(P,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(Rs,{align:"end",side:"bottom",onCloseAutoFocus:()=>x(null),children:[k&&s.jsxs($t,{onClick:G=>{G.stopPropagation(),g("rename",n)},children:[s.jsx(P,{name:"edit",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.rename")]}),s.jsxs($t,{onClick:G=>{G.stopPropagation(),_n(n.path).then(le=>{if(le.ok){H.success(w("sidebarFilesTree.toast.pathCopied"));return}H.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(P,{name:"file-copy",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.copyPath")]}),s.jsxs($t,{onClick:G=>{G.stopPropagation();const le=hd(r,n.path)||n.path;_n(le).then(oe=>{if(oe.ok){H.success(w("filesView.toast.relativePathCopied"));return}H.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(P,{name:"file-copy-2",className:"mr-2 size-4"})," ",w("filesView.tree.menu.copyRelativePath")]}),!b&&u&&s.jsxs($t,{onClick:G=>{G.stopPropagation(),u(n.path)},children:[s.jsx(P,{name:"download",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.save")]}),D&&s.jsxs($t,{onClick:G=>{G.stopPropagation(),y(n.path)},children:[s.jsx(P,{name:"folder-received",className:"mr-2 size-4"})," ",w(Od())]}),b&&(I||j)&&s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),I&&s.jsxs($t,{onClick:G=>{G.stopPropagation(),g("createFile",n)},children:[s.jsx(P,{name:"file-add",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs($t,{onClick:G=>{G.stopPropagation(),g("createFolder",n)},children:[s.jsx(P,{name:"folder-add",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.newFolder")]})]}),N&&s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),s.jsxs($t,{onClick:G=>{G.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"delete-bin",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=I,e[42]=j,e[43]=N,e[44]=k,e[45]=D,e[46]=h,e[47]=u,e[48]=A,e[49]=b,e[50]=l,e[51]=n,e[52]=g,e[53]=y,e[54]=r,e[55]=x,e[56]=w,e[57]=Q):Q=e[57];let ne;return e[58]!==J||e[59]!==Q||e[60]!==R?(ne=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:R,children:[J,Q]}),e[58]=J,e[59]=Q,e[60]=R,e[61]=ne):ne=e[61],ne},z2=t=>{const e=at.c(83),{activeDialog:n,dialogData:r,dialogInputValue:i,onDialogInputChange:a,isDialogSubmitting:l,onDialogSubmit:c,onClose:d,inputRef:p}=t,{t:m}=ut(),u=!!n;let h;e[0]!==d?(h=$=>!$&&d(),e[0]=d,e[1]=h):h=e[1];let x;e[2]!==n||e[3]!==m?(x=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=x):x=e[4];let f;e[5]!==n||e[6]!==m?(f=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=f):f=e[7];let v;e[8]!==n||e[9]!==m?(v=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=v):v=e[10];let y;e[11]!==n||e[12]!==m?(y=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=y):y=e[13];let g;e[14]!==x||e[15]!==f||e[16]!==v||e[17]!==y?(g=s.jsxs(gs,{children:[x,f,v,y]}),e[14]=x,e[15]=f,e[16]=v,e[17]=y,e[18]=g):g=e[18];let w;e[19]!==n||e[20]!==r?.path||e[21]!==m?(w=n==="createFile"&&m("filesView.dialog.createFile.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=m,e[22]=w):w=e[22];let b;e[23]!==n||e[24]!==r?.path||e[25]!==m?(b=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=m,e[26]=b):b=e[26];let k;e[27]!==n||e[28]!==r?.name||e[29]!==m?(k=n==="rename"&&m("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=m,e[30]=k):k=e[30];let I;e[31]!==n||e[32]!==r?.name||e[33]!==m?(I=n==="delete"&&m("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=m,e[34]=I):I=e[34];let j;e[35]!==k||e[36]!==I||e[37]!==w||e[38]!==b?(j=s.jsxs(Is,{children:[w,b,k,I]}),e[35]=k,e[36]=I,e[37]=w,e[38]=b,e[39]=j):j=e[39];let N;e[40]!==j||e[41]!==g?(N=s.jsxs(bs,{children:[g,j]}),e[40]=j,e[41]=g,e[42]=N):N=e[42];let D;e[43]!==n||e[44]!==i||e[45]!==p||e[46]!==a||e[47]!==c||e[48]!==m?(D=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Bt,{value:i,onChange:$=>a($.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:$=>{$.key==="Enter"&&c()},ref:p})}),e[43]=n,e[44]=i,e[45]=p,e[46]=a,e[47]=c,e[48]=m,e[49]=D):D=e[49];let E;e[50]!==m?(E=m("filesView.dialog.cancel"),e[50]=m,e[51]=E):E=e[51];let T;e[52]!==l||e[53]!==d||e[54]!==E?(T=s.jsx(ge,{variant:"outline",onClick:d,disabled:l,children:E}),e[52]=l,e[53]=d,e[54]=E,e[55]=T):T=e[55];const C=n==="delete"?"destructive":"default";let S;e[56]!==c?(S=()=>{c()},e[56]=c,e[57]=S):S=e[57];let M;e[58]!==n||e[59]!==i||e[60]!==l?(M=l||n!=="delete"&&!i.trim(),e[58]=n,e[59]=i,e[60]=l,e[61]=M):M=e[61];let A;e[62]!==n||e[63]!==l||e[64]!==m?(A=l?s.jsx(P,{name:"loader-4",className:"animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=l,e[64]=m,e[65]=A):A=e[65];let R;e[66]!==C||e[67]!==S||e[68]!==M||e[69]!==A?(R=s.jsx(ge,{variant:C,onClick:S,disabled:M,children:A}),e[66]=C,e[67]=S,e[68]=M,e[69]=A,e[70]=R):R=e[70];let z;e[71]!==T||e[72]!==R?(z=s.jsxs(Vs,{children:[T,R]}),e[71]=T,e[72]=R,e[73]=z):z=e[73];let B;e[74]!==p||e[75]!==N||e[76]!==D||e[77]!==z?(B=s.jsxs(fs,{initialFocus:p,children:[N,D,z]}),e[74]=p,e[75]=N,e[76]=D,e[77]=z,e[78]=B):B=e[78];let V;return e[79]!==u||e[80]!==h||e[81]!==B?(V=s.jsx(hs,{open:u,onOpenChange:h,children:B}),e[79]=u,e[80]=h,e[81]=B,e[82]=V):V=e[82],V},rg=({mode:t="full"})=>{const{t:e}=ut(),{files:n,runtime:r}=Pn(),{currentTheme:i,availableThemes:a,lightThemeId:l,darkThemeId:c}=Ar(),{isMobile:d,isTablet:p,screenWidth:m}=rn(),u=d||p,h=$l(),x=Ld(),f=Ir()??"",v=fn(f.trim()),y=d||t!=="editor-only",g=t==="editor-only"&&!d,w=Bl(De=>De.searchFiles),b=Ol(f),[k,I]=o.useState(""),j=ho(k,200),N=o.useRef(null),[D,E]=o.useState(!1),[T,C]=o.useState(!0),[S,M]=o.useState(!1),[A,R]=o.useState(!1),[z,B]=o.useState(!1),V=o.useRef(null),$=o.useRef(0),_=o.useCallback(De=>{$.current=Math.max(0,$.current+(De?1:-1))},[]),X=o.useCallback(De=>De instanceof Element?De.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);o.useEffect(()=>{if(!z)return;const De=st=>{$.current>0||X(st.target)||V.current&&!V.current.contains(st.target)&&B(!1)};return document.addEventListener("mousedown",De),()=>document.removeEventListener("mousedown",De)},[X,z]);const[O,J]=o.useState("edit"),[Q,ne]=o.useState("edit"),[G,le]=o.useState("tree"),[oe,F]=o.useState("edit"),U=o.useRef({}),W=o.useRef({}),te=o.useRef({}),K=o.useMemo(()=>a.find(De=>De.metadata.id===l)??ha(!1),[a,l]),ae=o.useMemo(()=>a.find(De=>De.metadata.id===c)??ha(!0),[a,c]);o.useEffect(()=>{ga(K),ga(ae)},[K,ae]);const ve=o.useMemo(()=>[],[]),re=Bn(De=>v?De.byRoot[v]?.openPaths??ve:ve),be=Bn(De=>v?De.byRoot[v]?.selectedPath??null:null),pe=Bn(De=>v?De.byRoot[v]?.expandedPaths??ve:ve),ye=Bn(De=>De.addOpenPath),ie=Bn(De=>De.removeOpenPath),ue=Bn(De=>De.removeOpenPathsByPrefix),se=Bn(De=>De.setSelectedPath),Ne=Bn(De=>De.toggleExpandedPath),Ce=Bn(De=>De.expandPaths),je=o.useCallback(De=>{const st=fn(De),pt=st.split("/"),jt=pt[pt.length-1]||st,Vt=jt.includes(".")?jt.split(".").pop()?.toLowerCase():void 0;return{name:jt,path:st,type:"file",extension:Vt}},[]),we=o.useMemo(()=>re.map(je),[re,je]),ke=o.useMemo(()=>be??re[0]??null,[re,be]),xe=o.useMemo(()=>ke?je(ke):null,[ke,je]),me=xe?.path??"",Me=!!(v&&me&&!kl(me,v)),Ue=o.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Me}),[t,Me]),q=o.useRef(null),[Se,$e]=o.useState({left:!1,right:!1}),Pe=o.useCallback(()=>{const De=q.current;De&&$e({left:De.scrollLeft>2,right:De.scrollLeft+De.clientWidth<De.scrollWidth-2})},[]),fe=o.useRef(Pe);fe.current=Pe,o.useEffect(()=>{const De=q.current;if(!De)return;const st=()=>fe.current();st(),De.addEventListener("scroll",st,{passive:!0});const pt=new ResizeObserver(st);return pt.observe(De),()=>{De.removeEventListener("scroll",st),pt.disconnect()}},[we.length]);const[L,Z]=o.useState({}),Y=o.useRef(new Set),Ee=o.useRef(new Set),Ae=o.useRef(new Map),Je=o.useRef(0),[de,ze]=o.useState([]),[rt,Re]=o.useState(!1),[Xe,qe]=o.useState(""),[Te,We]=o.useState(!1),[Ze,Qe]=o.useState(null),[he,Ge]=o.useState(""),[Ve,it]=o.useState(""),[dt,Ye]=o.useState(null),[_e,et]=o.useState(""),[gt,Lt]=o.useState(!1),Ut=o.useRef(null),mt=o.useRef(null),Nt=o.useRef(null),Xt=o.useRef(0),[_t,Gt]=o.useState("idle"),[lt,Tt]=o.useState(L2),[rs,js]=o.useState(!1),ys=o.useRef(null),vs=o.useRef(null),Wt=o.useRef(null),He=o.useRef(!1),kt=o.useRef(null),Kt=o.useRef(null),wt=o.useRef(null),Qt=o.useRef(null),[cs,Ls]=o.useState(0),Ss=o.useRef(null),ns=o.useRef({key:"",attempts:0});o.useEffect(()=>()=>{Ss.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Ss.current),Ss.current=null)},[]);const[Os,Ks]=o.useState(null),[bt,Mt]=o.useState(null),[At,ee]=o.useState(""),[ht,St]=o.useState(!1),[qt,ms]=o.useState(null),[Ds,Ke]=o.useState(!1),[yt,Et]=o.useState(!1),[Ht,ss]=o.useState(!1),Rt=!!n.writeFile,Ps=!!n.createDirectory,Qs=!!n.rename,Hs=!!n.delete,ts=!!n.revealPath,Ns=Lr(De=>De.availableApps),jn=Lr(De=>De.isCacheStale),sn=Lr(De=>De.initialize),Dr=Lr(De=>De.loadInstalledApps);o.useEffect(()=>{sn()},[sn]);const Tr=o.useCallback(De=>{n.revealPath&&n.revealPath(De).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),zr=o.useCallback(async De=>{if(!xe?.path||await Ab(xe.path,De.id,De.appName)||await ul(xe.path,De.appName))return;const jt=P2(xe.path)||v;jt&&await ul(jt,De.appName)||H.error(e("filesView.toast.openInAppFailed",{app:De.appName}))},[v,xe?.path,e]),Vr=o.useCallback((De,st)=>{Ks(De),Mt(st),ee(De==="rename"&&st.name||""),St(!1)},[]),[Gs,Mn]=o.useState(null),ir=o.useRef(!1),En=o.useRef(null),[_r,In]=o.useState(!1),ln=Ie(De=>De.setMainTabGuard),an=Ie(De=>De.pendingFileNavigation),Fe=Ie(De=>De.setPendingFileNavigation),Ct=Ie(De=>De.pendingFileFocusPath),Zt=Ie(De=>De.setPendingFileFocusPath),ls=Ie(De=>De.shortcutOverrides),Bs=xt(De=>De.settingsDefaultFileViewerPreview);o.useEffect(()=>{const De=()=>{ir.current=!1,En.current=null,In(!1)};return document.addEventListener("mouseup",De),()=>document.removeEventListener("mouseup",De)},[]),o.useEffect(()=>()=>{kt.current!==null&&window.clearTimeout(kt.current),Kt.current!==null&&window.clearTimeout(Kt.current)},[]);const Js=o.useCallback((De,st)=>{const pt=De.split(`
|
|
48
|
+
`),jt=Math.max(1,st.start),Vt=Math.min(pt.length,st.end);return jt>Vt?"":pt.slice(jt-1,Vt).join(`
|
|
49
|
+
`)},[]),ws=Hd({source:"file",fileLabel:xe?.path??null,language:xe?.path&&xa(xe.path)||"text",getCodeForRange:De=>Js(Xe,jl(De)),toStoreRange:De=>({startLine:De.start,endLine:De.end}),fromDraftRange:De=>({start:De.startLine,end:De.endLine})}),{drafts:en,commentText:nn,editingDraftId:Rn,setSelection:Fn,saveComment:Ur,cancel:xr,reset:Wr,startEdit:Ln,deleteDraft:er}=ws;o.useEffect(()=>{Mn(null),Wr(),ln(null),et(""),Lt(!1)},[xe?.path,Wr,ln]),o.useEffect(()=>{Fn(Gs)},[Gs,Fn]),o.useEffect(()=>{if(!Gs&&!Rn)return;const De=pt=>{const jt=pt.target;jt.closest('[data-comment-input="true"]')||jt.closest('[data-comment-card="true"]')||jt.closest(".cm-gutterElement")||jt.closest("[data-sonner-toast]")||jt.closest("[data-sonner-toaster]")||(Mn(null),xr())},st=setTimeout(()=>{document.addEventListener("click",De)},100);return()=>{clearTimeout(st),document.removeEventListener("click",De)}},[xr,Rn,Gs]);const br=o.useCallback((De,st)=>{const pt=st??Gs??void 0;st&&Mn(st),Ur(De,pt),Mn(null)},[Gs,Ur]),ar=o.useCallback((De,st)=>{const pt=[];for(const jt of st){if(!(jt&&typeof jt.name=="string"&&jt.name.length>0)||!h&&jt.name.startsWith(".")||!x&&E2(jt.name))continue;const Vt=jt.name,Jt=fn(jt.path||""),Ts=Jt?D2(Jt)?Jt:fn(`${De}/${Jt}`):fn(`${De}/${Vt}`),qs=jt.isDirectory?"directory":"file",Un=qs==="file"&&Vt.includes(".")?Vt.split(".").pop()?.toLowerCase():void 0;pt.push({name:Vt,path:Ts,type:qs,extension:Un})}return A2(pt)},[x,h]),dn=o.useCallback(async De=>{const st=fn(De.trim());if(!st||Y.current.has(st)||Ee.current.has(st))return;Ee.current=new Set(Ee.current),Ee.current.add(st);const pt=Je.current+1;Je.current=pt,Ae.current=new Map(Ae.current),Ae.current.set(st,pt);const jt=()=>Ae.current.get(st)===pt,Vt=!x;await(r.isDesktop?n.listDirectory(st,{respectGitignore:Vt}).then(Ts=>Ts.entries.map(qs=>({name:qs.name,path:qs.path,isDirectory:qs.isDirectory}))):Zs.listLocalDirectory(st,{respectGitignore:Vt}).then(Ts=>Ts.map(qs=>({name:qs.name,path:qs.path,isDirectory:qs.isDirectory})))).then(Ts=>{if(!jt())return;const qs=ar(st,Ts);Y.current=new Set(Y.current),Y.current.add(st),Z(Un=>({...Un,[st]:qs}))}).catch(()=>{jt()&&Z(Ts=>({...Ts,[st]:Ts[st]??[]}))}).finally(()=>{jt()&&(Ae.current=new Map(Ae.current),Ae.current.delete(st),Ee.current=new Set(Ee.current),Ee.current.delete(st))})},[n,ar,r.isDesktop,x]),On=o.useCallback(async()=>{v&&(Y.current=new Set,Ee.current=new Set,Ae.current=new Map,Z(De=>Object.keys(De).length===0?De:{}),await dn(v))},[dn,v]),bn=o.useCallback(async De=>{if(!De){await On();return}const st=fn(De);Y.current=new Set(Y.current),Y.current.delete(st),Ee.current=new Set(Ee.current),Ee.current.delete(st),await dn(st)},[dn,On]),Gn=o.useRef(""),Nn=o.useRef("");o.useEffect(()=>{if(!v)return;const De=`${v}|h${h?"1":"0"}|g${x?"1":"0"}`,st=Gn.current!==v,pt=Nn.current!==De;!st&&!pt||(st&&(Gn.current=v,qe(""),Qe(null),Ge(""),Ye(null),E(!1)),pt&&(Nn.current=De,Y.current=new Set,Ee.current=new Set,Ae.current=new Map,Z(jt=>Object.keys(jt).length===0?jt:{}),dn(v)))},[dn,v,x,h]),o.useEffect(()=>{if(!n.listDirectory)return;const De=()=>{if(!document.hidden&&pe.length>0)for(const st of pe)bn(st)};return document.addEventListener("visibilitychange",De),()=>document.removeEventListener("visibilitychange",De)},[pe,n.listDirectory,bn]),o.useEffect(()=>{if(!n.listDirectory||pe.length===0)return;const De=setInterval(()=>{if(!document.hidden)for(const st of pe)bn(st)},8e3);return()=>clearInterval(De)},[pe,n.listDirectory,bn]);const ni=o.useCallback(async De=>{if(De?.preventDefault(),!bt||!Os)return;St(!0);const st=()=>{Ks(null)},pt=Vt=>{H.error(Vt)},jt=()=>{St(!1)};if(Os==="createFile"){if(!At.trim()){pt(e("sidebarFilesTree.toast.filenameRequired")),jt();return}if(!n.writeFile){pt(e("sidebarFilesTree.toast.writeNotSupported")),jt();return}const Vt=bt.path,Jt=Vt?`${Vt}/`:"",Ts=fn(`${Jt}${At.trim()}`);await n.writeFile(Ts,"").then(async qs=>{qs.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await bn(Vt)),st()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}if(Os==="createFolder"){if(!At.trim()){pt(e("sidebarFilesTree.toast.folderNameRequired")),jt();return}const Vt=bt.path,Jt=Vt?`${Vt}/`:"",Ts=fn(`${Jt}${At.trim()}`);await n.createDirectory(Ts).then(async qs=>{qs.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await bn(Vt)),st()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}if(Os==="rename"){if(!At.trim()){pt(e("sidebarFilesTree.toast.nameRequired")),jt();return}if(!n.rename){pt(e("sidebarFilesTree.toast.renameNotSupported")),jt();return}const Vt=bt.path,Jt=Vt.split("/").slice(0,-1).join("/"),Ts=Jt?`${Jt}/`:"",qs=fn(`${Ts}${At.trim()}`);await n.rename(Vt,qs).then(async Un=>{Un.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await bn(Jt),v&&ue(v,Vt),(xe?.path===Vt||xe?.path.startsWith(`${Vt}/`))&&(v&&se(v,null),qe(""),Qe(null),Ge(""),Ye(null),d&&E(!1))),st()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}if(Os==="delete"){if(!n.delete){pt(e("sidebarFilesTree.toast.deleteNotSupported")),jt();return}const Vt=bt.path,Jt=Vt.split("/").slice(0,-1).join("/");await n.delete(Vt).then(async Ts=>{Ts.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await bn(Jt),v&&ue(v,Vt),(xe?.path===Vt||xe?.path.startsWith(`${Vt}/`))&&(v&&se(v,null),qe(""),Qe(null),Ge(""),Ye(null),d&&E(!1))),st()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}jt()},[Os,bt,At,n,bn,d,ue,v,xe?.path,se,e]);o.useEffect(()=>{if(!f){ze([]),Re(!1);return}const De=j.trim();if(!De){ze([]),Re(!1);return}let st=!1;return Re(!0),w(f,De,150,{includeHidden:h,respectGitignore:!x,type:"file"}).then(pt=>{if(st)return;const Vt=pt.filter(Jt=>x||!R2(Jt.path)).map(Jt=>({name:Jt.name,path:fn(Jt.path),type:"file",extension:Jt.extension,relativePath:Jt.relativePath}));ze(Vt)}).catch(()=>{st||ze([])}).finally(()=>{st||Re(!1)}),()=>{st=!0}},[f,j,w,h,x]);const Gi=o.useCallback(async(De,st)=>{if(n.readFile)return(await n.readFile(De,st)).content??"";const pt=new URLSearchParams({path:De});st?.allowOutsideWorkspace&&pt.set("allowOutsideWorkspace","true"),st?.optional&&pt.set("optional","true");const jt=await fetch(`/api/fs/read?${pt.toString()}`,{cache:st?.optional?"no-store":"default"});if(!jt.ok){const Vt=await jt.json().catch(()=>({error:jt.statusText}));throw new Error(Vt.error||e("filesView.error.readFileFailed"))}return jt.text()},[n,e]),tr=o.useCallback(async(De,st)=>{if(n.statFile){const pt=await n.statFile(De,st);return{path:pt.path,size:pt.size,mtimeMs:pt.mtimeMs}}return null},[n]),bi=o.useMemo(()=>Xe.length>Ra?`${Xe.slice(0,Ra)}
|
|
50
|
+
|
|
51
|
+
… truncated …`:Xe,[Xe]),Sn=_e!==bi,yr=o.useCallback(async()=>{if(!xe||!n.writeFile)return H.error(e("filesView.toast.savingNotSupported")),!1;if(!Sn)return!0;Lt(!0);try{return(await n.writeFile(xe.path,_e))?.success?(qe(_e),tr(xe.path).then(st=>{st&&(Nt.current=st)}).catch(()=>{}),!0):(H.error(e("filesView.toast.writeFileFailed")),!1)}catch(De){return H.error(De instanceof Error?De.message:e("filesView.toast.saveFailed")),!1}finally{Lt(!1)}},[_e,n,Sn,tr,xe,e]);o.useEffect(()=>{if(!Sn){ln(null);return}const De=st=>He.current?(He.current=!1,!0):(js(!0),vs.current=st,!1);return ln(De),()=>{Ie.getState().mainTabGuard===De&&ln(null)}},[Sn,ln]),o.useEffect(()=>{try{window.localStorage.setItem(sg,lt?"true":"false")}catch{}},[lt]),o.useEffect(()=>{lt||(Gt("idle"),mt.current&&(clearTimeout(mt.current),mt.current=null))},[lt]);const qn=1500;o.useEffect(()=>{const De=!!(xe&&n.writeFile);if(!(!lt||!Sn||!De||gt))return mt.current=setTimeout(()=>{yr().then(st=>{st&&(Gt("saved"),setTimeout(()=>Gt("idle"),2e3))})},qn),()=>{mt.current&&(clearTimeout(mt.current),mt.current=null)}},[lt,_e,Sn,xe,n.writeFile,gt,yr]),o.useEffect(()=>{Gt("idle")},[xe?.path]),o.useEffect(()=>{const De=st=>{Md(st)&&(st.key.toLowerCase()==="s"?(st.preventDefault(),mt.current&&(clearTimeout(mt.current),mt.current=null),gt||yr().then(pt=>{pt&&(Gt("saved"),setTimeout(()=>Gt("idle"),2e3))})):st.key.toLowerCase()==="f"&&(st.preventDefault(),R(!0)))};return window.addEventListener("keydown",De),()=>window.removeEventListener("keydown",De)},[gt,yr]);const Gr=o.useCallback(async De=>{const st=Xt.current+1;Xt.current=st;const pt=()=>{if(!v)return!1;const Ts=Bn.getState().byRoot[v],qs=Ts?.selectedPath??Ts?.openPaths[0]??null;return Xt.current===st&&qs===De.path};Qe(null),Ge(""),Ye(null);const jt=De.path.toLowerCase().endsWith(".svg"),Vt=Db(De.path)&&!jt;if(d&&E(!0),r.isDesktop&&Vt){qe(""),et(""),We(!0);return}if(!r.isDesktop&&Vt){qe(""),et(""),Ye(De.path),We(!1);return}We(!0);const Jt={allowOutsideWorkspace:t==="editor-only"&&!!v&&!kl(De.path,v)};await Gi(De.path,Jt).then(Ts=>{pt()&&(qe(Ts),et(Ts.length>Ra?`${Ts.slice(0,Ra)}
|
|
52
|
+
|
|
53
|
+
… truncated …`:Ts),Ye(De.path),tr(De.path,Jt).then(qs=>{qs&&pt()&&(Nt.current=qs)}).catch(()=>{}))}).catch(Ts=>{if(pt()){if(F2(Ts)){if(We(!1),v&&se(v,null),Qe(null),qe(""),et(""),Ye(null),Nt.current=null,k.trim().length>0&&I(""),d&&E(!1),v){const Un=[...Zm(De.path,v),De.path];Un.length>0&&Ce(v,Un);for(const ko of Un)Y.current.has(ko)||dn(ko)}return}qe(""),et(""),Qe(Ts instanceof Error?Ts.message:e("filesView.error.readFileFailed")),Nt.current=null}}).finally(()=>{pt()&&We(!1)})},[Ce,d,dn,t,Gi,tr,v,r.isDesktop,k,se,e]),Kr=o.useCallback(async(De,st)=>{if(!v)return;const pt=Zm(De,v),jt=st?[...pt,De]:pt;jt.length>0&&Ce(v,jt);const Vt=jt.map(Jt=>{if(!Y.current.has(Jt))return dn(Jt)}).filter(Boolean);await Promise.all(Vt)},[Ce,dn,v]),qi=o.useCallback((De,st)=>{const pt=st.findIndex(jt=>jt.path===De);return pt===-1||st.length<=1?null:st[pt+1]??st[pt-1]??null},[]),cn=o.useCallback(async De=>{if(He.current)He.current=!1;else if(Sn){js(!0),ys.current=De;return}v&&(se(v,De.path),ye(v,De.path),Kr(De.path,!1)),Qe(null),Ge(""),it(""),qe(""),et(""),Ye(null),d&&E(!0)},[ye,Kr,Sn,d,v,se]);o.useEffect(()=>{xe?.path&&Kr(xe.path,!1)},[Kr,xe?.path]),o.useEffect(()=>{if(!xe){Xt.current+=1,We(!1);return}dt!==xe.path&&Gr(xe)},[Gr,dt,xe]);const Oe=o.useRef(Sn);Oe.current=Sn,o.useEffect(()=>{if(!xe?.path||dt!==xe.path)return;let De=!1;const st=window.setInterval(()=>{document.hidden||tr(xe.path,Ue).then(pt=>{if(De||!pt)return;const jt=Nt.current;if(!jt||jt.path!==xe.path){Nt.current=pt;return}const Vt=pt.mtimeMs!==void 0&&jt.mtimeMs!==void 0&&pt.mtimeMs!==jt.mtimeMs,Jt=pt.size!==jt.size;!Vt&&!Jt||Oe.current||(Nt.current=pt,Ye(null))}).catch(()=>{})},2e3);return()=>{De=!0,window.clearInterval(st)}},[dt,tr,xe?.path,Ue]);const tt=o.useCallback(()=>{const De=ys.current,st=vs.current,pt=Wt.current;if(ys.current=null,vs.current=null,Wt.current=null,He.current=!0,js(!1),et(bi),pt){v&&ie(v,pt),xe?.path===pt&&(De?cn(De):(v&&se(v,null),qe(""),Qe(null),Ge(""),Ye(null),d&&E(!1)));return}if(De){cn(De);return}st&&(ln(null),Ie.getState().setActiveMainTab(st))},[bi,cn,d,ie,v,xe?.path,ln,se]),nt=o.useCallback(async()=>{const De=ys.current,st=vs.current,pt=Wt.current;if(!await yr()){He.current=!1;return}if(ys.current=null,vs.current=null,Wt.current=null,He.current=!0,js(!1),pt){v&&ie(v,pt),xe?.path===pt&&(De?await cn(De):(v&&se(v,null),qe(""),Qe(null),Ge(""),Ye(null),d&&E(!1)));return}if(De){await cn(De);return}st&&(ln(null),Ie.getState().setActiveMainTab(st))},[cn,d,ie,v,yr,xe?.path,ln,se]),ct=o.useCallback(De=>{const st=xe?.path===De,pt=qi(De,we);if(st&&Sn){js(!0),ys.current=pt,Wt.current=De;return}if(v&&ie(v,De),!!st){if(pt){cn(pt);return}v&&se(v,null),qe(""),Qe(null),Ge(""),Ye(null),d&&E(!1)}},[qi,cn,Sn,d,we,ie,v,xe?.path,se]),zt=o.useCallback(De=>{if(re.includes(De))return"open";if(b?.files){const st=De.startsWith(v+"/")?De.slice(v.length+1):De,pt=b.files.find(jt=>jt.path===st);if(pt){if(pt.index==="A"||pt.working_dir==="?")return"git-added";if(pt.index==="D")return"git-deleted";if(pt.index==="M"||pt.working_dir==="M")return"git-modified"}}return null},[re,b,v]),es=o.useCallback(De=>{if(!b?.files)return null;const st=De.startsWith(v+"/")?De.slice(v.length+1):De,pt=st?`${st}/`:"";let jt=0,Vt=0;for(const Jt of b.files)Jt.path.startsWith(pt)&&((Jt.index==="M"||Jt.working_dir==="M")&&jt++,(Jt.index==="A"||Jt.working_dir==="?")&&Vt++);return jt+Vt>0?{modified:jt,added:Vt}:null},[b,v]),_s=o.useCallback(async De=>{const st=fn(De);v&&(Ne(v,st),Y.current.has(st)||await dn(st))},[dn,v,Ne]),pn=o.useMemo(()=>({canRename:Qs,canCreateFile:Rt,canCreateFolder:Ps,canDelete:Hs,canReveal:ts}),[Qs,Rt,Ps,Hs,ts]);function Mr(De,st){const pt=L[De]??[];return pt.map((jt,Vt)=>{const Jt=jt.type==="directory",Ts=Jt&&pe.includes(jt.path),qs=xe?.path===jt.path,Un=Vt===pt.length-1;return s.jsxs("li",{className:"relative",children:[st>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Un&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(B2,{node:jt,root:v,isExpanded:Ts,isActive:qs,isMobile:d,alwaysShowActions:u,status:Jt?void 0:zt(jt.path),badge:Jt?es(jt.path):void 0,permissions:pn,downloadFile:n.downloadFile,contextMenuPath:qt,setContextMenuPath:ms,onSelect:cn,onToggle:_s,onRevealPath:Tr,onOpenDialog:Vr}),Jt&&Ts&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Mr(jt.path,st+1)})]},jt.path)})}const An=!!(xe?.path&&so(xe.path)),qr=!!(xe?.path&&xe.path.toLowerCase().endsWith(".svg")),vr=!!(xe?.path&&Tb(xe.path)),ri=!!(xe?.path&&Mb(xe.path)),ii=!!(xe?.path&&Eb(xe.path)),ai=An||vr||ri||ii,yi=o.useMemo(()=>fn(an?.path??""),[an?.path]),Us=!!(an&&yi&&me&&me===yi&&!Te&&!Ze&&!ai),oi=o.useMemo(()=>hd(v,me),[me,v]),Ca=!!(xe&&(!ai||qr)&&Xe.length>0),Hl=!!(xe&&oi.length>0),sr=!!(xe&&!Me&&!ai&&n.writeFile&&Xe.length<=Ra),Er=!!(xe?.path&&O2(xe.path)),xn=!!(xe?.path&&$2(xe.path)),Pa=!!(xe?.path&&Sc(xe.path)),Ia=!!(xe&&!ai)&&!Er&&!(Pa&&oe==="preview"),Yi=o.useMemo(()=>me?tg(me):null,[me]),[wo,li]=o.useState(null);o.useEffect(()=>{let De=!1;const st=xe?.path;if(!st||Yi){li(null);return}return li(null),C2(st).then(pt=>{De||li(pt)}),()=>{De=!0}},[xe?.path,Yi]),o.useEffect(()=>{!sr&&O==="edit"&&J("view")},[sr,O]);const Qi="vinci:files:md-viewer-mode",jo="vinci:files:html-viewer-mode",No="vinci:files:json-viewer-mode";o.useEffect(()=>{const De=xe?.path;if(!De)return;const st=Bs?"view":"edit";J(U.current[De]??st);let pt=Bs?"preview":"edit";try{const Jt=localStorage.getItem(Qi);(Jt==="preview"||Jt==="edit")&&(pt=Jt)}catch{}ne(W.current[De]??pt);let jt=Bs?"preview":"edit";try{const Jt=localStorage.getItem(jo);(Jt==="preview"||Jt==="edit")&&(jt=Jt)}catch{}F(te.current[De]??jt);let Vt=Bs?"tree":"text";try{const Jt=localStorage.getItem(No);(Jt==="tree"||Jt==="text")&&(Vt=Jt)}catch{}le(Vt)},[xe?.path,Bs]);const Gl=o.useCallback(De=>{const st=xe?.path;st&&(U.current[st]=De),J(De)},[xe?.path]),Le=o.useCallback(De=>{const st=xe?.path;st&&(W.current[st]=De),ne(De);try{localStorage.setItem(Qi,De)}catch{}},[xe?.path]),vt=o.useCallback(()=>Q,[Q]),ft=o.useCallback(De=>{le(De);try{localStorage.setItem(No,De)}catch{}},[]),Yt=o.useCallback(De=>{const st=xe?.path;st&&(te.current[st]=De),F(De);try{localStorage.setItem(jo,De)}catch{}},[xe?.path]),ps=o.useCallback(()=>oe,[oe]);o.useEffect(()=>{if(!an||!v)return;const De=()=>{typeof window>"u"||Ss.current===null&&(Ss.current=window.requestAnimationFrame(()=>{Ss.current=null,Ls(Yr=>Yr+1)}))},st=(Yr,vi)=>{if(Yr.state.doc.length!==vi.length)return!1;if(vi.length===0)return!0;const Yl=Math.min(128,vi.length);if(Yr.state.sliceDoc(0,Yl)!==vi.slice(0,Yl))return!1;const uu=Math.max(0,vi.length-Yl);return Yr.state.sliceDoc(uu,vi.length)===vi.slice(uu)},pt=fn(an.path);if(!pt){Fe(null),ns.current={key:"",attempts:0};return}const jt=`${pt}:${an.line}:${an.column??1}`;if(ns.current.key!==jt&&(ns.current={key:jt,attempts:0}),xe?.path!==pt){if(rs)return;cn(je(pt));return}if(Te||dt!==pt)return;if(Ze||An){Fe(null),ns.current={key:"",attempts:0};return}if(!sr)return;if(O!=="edit"){J("edit");return}const Vt=wt.current;if(!Vt){De();return}if(!st(Vt,_e)){De();return}const Jt=Math.max(1,Math.min(an.line,Vt.state.doc.lines)),Ts=Vt.state.doc.line(Jt),qs=Math.max(1,an.column||1),Un=Math.max(0,Ts.to-Ts.from),ko=Math.min(Un,qs-1),Da=Ts.from+ko;if(!(Vt.state.selection.main.head===Da)||ns.current.attempts===0){ns.current.attempts+=1,Vt.dispatch({selection:{anchor:Da},effects:Xn.scrollIntoView(Da,{y:"center"})}),Vt.focus(),De();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const Yr=wt.current;Yr&&(Yr.dispatch({selection:{anchor:Da},effects:Xn.scrollIntoView(Da,{y:"center"})}),Yr.focus())}),Fe(null),ns.current={key:"",attempts:0}},[sr,rs,_e,cs,Ze,Te,An,dt,cn,an,v,xe?.path,Fe,O,je]),o.useEffect(()=>{if(!Ct||!v)return;const De=fn(Ct);if(!De){Zt(null);return}if(xe?.path!==De){if(rs)return;cn(je(De));return}if(!(Te||dt!==De||Ze||An)){if(sr&&O==="edit"){const st=wt.current;if(!st)return;st.focus()}Zt(null)}},[sr,rs,Ze,Te,cn,An,dt,Ct,v,xe?.path,Zt,O,je]);const Ws=o.useCallback(De=>{if(!d||!De||!De.hasFocus||typeof window>"u")return;const st=window.visualViewport;if(!st)return;const pt=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,pt-(st.offsetTop+st.height))<=0)return;const Vt=De.state.selection.main.head,Jt=De.coordsAtPos(Vt);if(!Jt)return;const Ts=Math.round(st.offsetTop+st.height),Un=Jt.bottom+20-Ts;Un<=0||(De.scrollDOM.scrollTop+=Un)},[d]);o.useEffect(()=>{if(!d||typeof window>"u")return;const De=()=>{window.requestAnimationFrame(()=>{Ws(wt.current)})},st=window.visualViewport;return st?.addEventListener("resize",De),st?.addEventListener("scroll",De,{passive:!0}),document.addEventListener("selectionchange",De),()=>{st?.removeEventListener("resize",De),st?.removeEventListener("scroll",De),document.removeEventListener("selectionchange",De)}},[d,Ws]),o.useEffect(()=>{if(!sr||O!=="edit"||d)return;const De=Zr("open_go_to_line",ls),st=pt=>{const jt=pt.target;if(jt?.closest('[role="dialog"]'))return;const Vt=!!jt?.closest(".cm-editor");jt?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!Vt||!document.activeElement?.closest(".cm-editor")||Yo(pt,De)&&(pt.preventDefault(),ss(!0))};return window.addEventListener("keydown",st),()=>window.removeEventListener("keydown",st)},[sr,d,ls,O]);const Dn=o.useMemo(()=>{if(!xe?.path)return[fd(i)];const De=[fd(i)],st=Yi??wo;return st&&De.push(st),T&&De.push(Xn.lineWrapping),d&&De.push(Xn.updateListener.of(pt=>{pt.view.hasFocus&&(pt.selectionSet||pt.focusChanged||pt.viewportChanged||pt.geometryChanged)&&window.requestAnimationFrame(()=>{Ws(pt.view)})})),De},[i,xe?.path,Yi,wo,T,d,Ws]),wr=o.useMemo(()=>({light:K.metadata.id,dark:ae.metadata.id}),[K.metadata.id,ae.metadata.id]),nr=xe?.path?`/api/fs/raw?${new URLSearchParams({path:xe.path,...Ue.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"",Tn=xe?.path&&An?r.isDesktop?qr?`data:${ku(xe.path)};utf8,${encodeURIComponent(Xe)}`:he:qr?`data:${ku(xe.path)};utf8,${encodeURIComponent(Xe)}`:nr:"",un=xe?.path&&(vr||ri||ii)?r.isDesktop?Ve:nr:"";o.useEffect(()=>{let De=!1;return(async()=>{if(!r.isDesktop||!xe?.path||qr){Ge(""),it("");return}if(!(An||vr||ri||ii)){Ge(""),it("");return}Qe(null),await(n.readFileBinary?n.readFileBinary(xe.path,Ue).then(Vt=>Vt.dataUrl):Promise.resolve(Ix(xe.path,"asset"))).then(Vt=>{De||(An?Ge(Vt):it(Vt),Ye(xe.path))}).catch(Vt=>{De||(Ge(""),it(""),Qe(Vt instanceof Error?Vt.message:e("filesView.error.readFileFailed")),Ye(null))}).finally(()=>{De||We(!1)})})(),()=>{De=!0}},[n,An,vr,ri,ii,qr,r.isDesktop,xe?.path,Ue,e]);const Aa=o.useCallback(()=>Ks(null),[]),So=o.useMemo(()=>_h({drafts:en,editingDraftId:Rn,commentText:nn,selection:Gs,isDragging:_r,fileLabel:xe?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:De=>({start:De.startLine,end:De.endLine}),onSave:br,onCancel:()=>{Mn(null),xr()},onEdit:De=>{Ln(De),Mn({start:De.startLine,end:De.endLine})},onDelete:er}),[xr,nn,er,Rn,en,br,_r,Gs,xe?.path,Ln]),lu=o.useCallback((De,st)=>s.jsx("div",{className:"h-full",children:s.jsx(Px,{file:{name:De.name,contents:st,lang:xa(De.path)||void 0},options:{disableFileHeader:!0,overflow:T?"wrap":"scroll",theme:wr,themeType:i.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[i.metadata.variant,wr,T]),cu=({exitFullscreenOnly:De=!1}={})=>xe?s.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",children:[sr&&O==="edit"&&s.jsxs(s.Fragment,{children:[gt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(P,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):lt&&_t==="saved"&&!Sn?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(P,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Sn?s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{yr()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(lt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${hl()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${hl()}+S`}),children:s.jsx(P,{name:"save-3",className:"size-4"})}):null,s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>Tt(st=>!st),className:ce("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",lt?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(lt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(lt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:lt?s.jsx(P,{name:"file-check-fill",className:"size-4"}):s.jsx(P,{name:"file-check",className:"size-4"})})]}),s.jsxs(Fs,{onOpenChange:_,children:[s.jsx(Es,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(P,{name:"file-transfer",className:"size-4"})})}),s.jsxs(Rs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ns.map(st=>s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{zr(st)},children:[s.jsx(I2,{label:st.label,iconDataUrl:st.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:st.label})]},st.id)),jn?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{Dr(!0)},children:[s.jsx(P,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!An&&s.jsxs(s.Fragment,{children:[s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>C(!T),className:ce("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",T?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(T?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(P,{name:"text-wrap",className:"size-4"})}),O==="edit"&&s.jsxs(s.Fragment,{children:[s.jsx(ge,{variant:"ghost",size:"sm",onClick:st=>{R(!A),st.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(P,{name:"search",className:"size-4"})}),s.jsx(ge,{variant:"ghost",size:"sm",onClick:st=>{ss(pt=>!pt),st.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(P,{name:"menu-fold-2",className:"size-4"})}),s.jsx(j2,{open:Ht,onOpenChange:ss,view:wt.current,variant:"inline"})]})]}),Ia&&sr&&!xn&&!Pa&&s.jsx(md,{currentMode:O==="view"?"preview":"edit",onToggle:()=>{Gl(O==="view"?"edit":"view")}}),(Er||Sc(xe?.path??""))&&s.jsx(md,{currentMode:Er?vt():ps(),onToggle:()=>{Sc(xe?.path??"")?Yt(ps()==="preview"?"edit":"preview"):Le(vt()==="preview"?"edit":"preview")}}),xn&&s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>ft(G==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(G==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:G==="tree"?s.jsx(P,{name:"code-sslash",className:"size-4"}):s.jsx(P,{name:"node-tree",className:"size-4"})}),Ca&&s.jsx(ge,{variant:"ghost",size:"sm",onClick:async()=>{(await _n(Xe)).ok?(Ke(!0),kt.current!==null&&window.clearTimeout(kt.current),kt.current=window.setTimeout(()=>{Ke(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Ds?s.jsx(P,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(P,{name:"clipboard",className:"size-4"})}),Hl&&s.jsx(ge,{variant:"ghost",size:"sm",onClick:async()=>{(await _n(oi)).ok?(Et(!0),Kt.current!==null&&window.clearTimeout(Kt.current),Kt.current=window.setTimeout(()=>{Et(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:oi}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:oi}),children:yt?s.jsx(P,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(P,{name:"file-copy-2",className:"size-4"})}),n.downloadFile&&s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{const st=n.downloadFile;st&&st(xe.path)},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(P,{name:"download",className:"size-4"})}),De?s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>M(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(P,{name:"fullscreen-exit",className:"size-4"})}):!d&&t==="full"&&s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>M(!S),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(S?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(S?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:S?s.jsx(P,{name:"fullscreen-exit",className:"size-4"}):s.jsx(P,{name:"fullscreen",className:"size-4"})})]}):null,ql=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(hs,{open:rs,onOpenChange:De=>{De||js(!0)},children:s.jsxs(fs,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:e("filesView.unsaved.title")}),s.jsx(Is,{children:e("filesView.unsaved.description")})]}),s.jsxs(Vs,{children:[s.jsx(ge,{variant:"outline",onClick:()=>{nt()},disabled:gt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(ge,{variant:"destructive",onClick:tt,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:ce("flex flex-col flex-shrink-0",y&&"border-b border-border/40"),children:y?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[d&&D&&s.jsx("button",{type:"button",onClick:()=>E(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(P,{name:"arrow-left-s",className:"size-5"})}),d?xe?s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(Zn,{filePath:xe.path,extension:xe.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:xe.name}),s.jsx(P,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Rs,{align:"start",className:"min-w-[16rem]",children:we.map(De=>{const st=xe?.path===De.path;return s.jsxs($t,{onSelect:pt=>{if(pt.target.closest("[data-close-open-file]")){pt.preventDefault();return}st||cn(De)},className:ce("flex items-center justify-between gap-2",st&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 truncate",children:[s.jsx(Zn,{filePath:De.path,extension:De.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:De.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:pt=>{pt.preventDefault(),pt.stopPropagation()},onClick:pt=>{pt.preventDefault(),pt.stopPropagation(),ct(De.path)},className:"inline-flex size-6 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:De.name}),children:s.jsx(P,{name:"close",className:"size-3.5"})})]},De.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):we.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Se.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),Se.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:q,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:we.map(De=>{const st=xe?.path===De.path;return s.jsxs("div",{title:hd(v,De.path),className:ce("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",st?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(Zn,{filePath:De.path,extension:De.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{st||cn(De)},className:"max-w-[12rem] truncate text-left",children:De.name}),s.jsx("button",{type:"button",onClick:pt=>{pt.stopPropagation(),ct(De.path)},className:ce("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!st&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:De.name}),children:s.jsx(P,{name:"close",className:"size-3.5"})})]},De.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[xe&&!A&&s.jsx("div",{ref:V,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>B(!0),onMouseLeave:()=>{$.current>0||B(!1)},children:z?cu():s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>B(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(P,{name:"more-2-fill",className:"size-4"})})}),s.jsx(Cs,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:xe?Te?g?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):Ze?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Ze}):An?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:Tn,alt:xe?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):ri?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("video",{controls:!0,src:un,className:"max-w-full max-h-[70vh] rounded-md",children:e("filesView.editor.videoUnsupported")})}):vr?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsxs("div",{className:"flex flex-col items-center gap-3 w-full max-w-md",children:[s.jsx(P,{name:"music",className:"h-10 w-10 text-muted-foreground"}),s.jsx("audio",{controls:!0,src:un,className:"w-full",children:e("filesView.editor.audioUnsupported")})]})}):ii?s.jsx("div",{className:"h-full",children:s.jsx("iframe",{src:un,className:"w-full h-full border-none",title:xe?.name??"PDF"})}):xe&&xn&&G==="tree"?s.jsx(Xs,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Sv,{jsonString:Xe,maxHeight:"100%",initiallyExpandedDepth:2})})}):xe&&Er&&vt()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Xe.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Xe.length/1024)})}),s.jsx(Xs,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(to,{content:Xe,className:"typography-markdown-body",stripFrontmatter:!0})})]}):xe&&Pa&&oe==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const De=xe.path.substring(0,xe.path.lastIndexOf("/")+1);if(!De)return Xe;const st=`<base href="${r.isDesktop,De}">`;return Xe.replace(/<head([^>]*)>/i,`<head$1>${st}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):xe&&Ia&&O==="view"?lu(xe,_e):s.jsxs("div",{className:ce("relative h-full",Us&&"overflow-hidden"),ref:Qt,children:[s.jsx("div",{className:ce("h-full",Us&&"invisible"),children:s.jsx(ud,{value:_e,onChange:et,readOnly:!sr,extensions:Dn,className:"h-full",blockWidgets:So,onViewReady:De=>{wt.current=De,Ls(st=>st+1),window.requestAnimationFrame(()=>{Ws(De)})},onViewDestroy:()=>{wt.current&&(wt.current=null),Ls(De=>De+1)},enableSearch:!0,searchOpen:A,onSearchOpenChange:R,highlightLines:Gs?{start:Math.min(Gs.start,Gs.end),end:Math.max(Gs.start,Gs.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(De,st,pt)=>{if(!(pt instanceof MouseEvent)||pt.button!==0)return!1;pt.preventDefault();const jt=De.state.doc.lineAt(st.from).number;if(d&&Gs&&!pt.shiftKey){const Vt=Math.min(Gs.start,Gs.end,jt),Jt=Math.max(Gs.start,Gs.end,jt);return Mn({start:Vt,end:Jt}),ir.current=!1,En.current=null,In(!1),!0}if(ir.current=!0,En.current=jt,In(!0),Gs&&pt.shiftKey){const Vt=Math.min(Gs.start,jt),Jt=Math.max(Gs.end,jt);Mn({start:Vt,end:Jt})}else Mn({start:jt,end:jt});return!0},mouseover:(De,st,pt)=>{if(!(pt instanceof MouseEvent)||pt.buttons!==1||!ir.current||En.current===null)return!1;const jt=De.state.doc.lineAt(st.from).number,Vt=Math.min(En.current,jt),Jt=Math.max(En.current,jt);return Mn({start:Vt,end:Jt}),In(!0),!1},mouseup:()=>(ir.current=!1,En.current=null,In(!1),!1)}}})}),Us&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),Yg=!!(v&&L[v]),du=s.jsxs("section",{className:ce("flex min-h-0 flex-col overflow-hidden",d?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:ce("flex flex-col gap-2 py-2",d?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(P,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(Bt,{ref:N,value:k,onChange:De=>I(De.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),k.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{I(""),N.current?.focus()},children:s.jsx(P,{name:"close",className:"size-4"})})]}),s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>Vr("createFile",{path:f,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),children:s.jsx(P,{name:"file-add",className:"size-4"})}),s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>Vr("createFolder",{path:f,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),children:s.jsx(P,{name:"folder-add",className:"size-4"})}),s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{On()},className:"size-8 p-0 flex-shrink-0",children:s.jsx(P,{name:"refresh",className:"size-4"})})]})}),s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:ce("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:rt?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):de.length>0?de.map(De=>{const st=xe?.path===De.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{cn(De)},className:ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",st?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[ng(De.path,De.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:De.path,children:De.relativePath??De.path})]})},De.path)}):Yg?Mr(v,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Qg=t==="full"&&S&&xe&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:cu({exitFullscreenOnly:!0})}),s.jsx(Cs,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Te?g?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Ze?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Ze}):An?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:Tn,alt:xe.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):ri?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("video",{controls:!0,src:un,className:"max-w-full max-h-full rounded-md",children:e("filesView.editor.videoUnsupported")})}):vr?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsxs("div",{className:"flex flex-col items-center gap-3 w-full max-w-md",children:[s.jsx(P,{name:"music",className:"h-10 w-10 text-muted-foreground"}),s.jsx("audio",{controls:!0,src:un,className:"w-full",children:e("filesView.editor.audioUnsupported")})]})}):ii?s.jsx("div",{className:"h-full",children:s.jsx("iframe",{src:un,className:"w-full h-full border-none",title:xe.name})}):Er&&vt()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Xe.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Xe.length/1024)})}),s.jsx(Xs,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(to,{content:Xe,className:"typography-markdown-body",stripFrontmatter:!0})})]}):Ia&&O==="view"?lu(xe,_e):s.jsxs("div",{className:ce("relative h-full",Us&&"overflow-hidden"),children:[s.jsx("div",{className:ce("h-full",Us&&"invisible"),children:s.jsx(ud,{value:_e,onChange:et,readOnly:!sr,extensions:Dn,className:"h-full",onViewReady:De=>{wt.current=De,window.requestAnimationFrame(()=>{Ws(De)})},onViewDestroy:()=>{wt.current&&(wt.current=null)}})}),Us&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(z2,{activeDialog:Os,dialogData:bt,dialogInputValue:At,onDialogInputChange:ee,isDialogSubmitting:ht,onDialogSubmit:ni,onClose:Aa,inputRef:Ut}),Qg,d?D?ql:du:t==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:ql})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[m>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:du}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:ql})]})]})},V2=Object.freeze(Object.defineProperty({__proto__:null,FilesView:rg},Symbol.toStringTag,{value:"Module"})),Or=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},kc=(t,e)=>{const n=Or(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},_2=(t,e,n)=>kc(kc(kc(t,".opencode"),"plans"),`${e}-${n}.md`),U2=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,W2=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},K2=(t,e)=>{const n=Or(e.currentDirectory),r=Or(e.homeDirectory),i=Or(t);return n&&i.startsWith(n+"/")?i.slice(n.length+1):r&&i===r?"~":r&&i.startsWith(r+"/")?`~${i.slice(r.length)}`:i},H2=(t,e,n)=>{const r=Or(t.trim());if(!r)return null;const i=n?e.find(l=>l.id===n)??null:null;if(i?.path){const l=Or(i.path);if(r===l||r.startsWith(`${l}/`))return{id:i.id,path:i.path}}const a=e.filter(l=>{const c=Or(l.path);return r===c||r.startsWith(`${c}/`)}).sort((l,c)=>Or(c.path).length-Or(l.path).length)[0];return a?{id:a.id,path:a.path}:null},ig=({targetPath:t=null})=>{const{t:e}=ut(),n=Ot(fe=>fe.currentSessionId),r=Ot(fe=>fe.createSession),i=Ot(fe=>fe.initializeNewSession),a=Ot(fe=>fe.sendMessage),l=Ot(fe=>fe.setCurrentSession),c=zl(),d=$s(fe=>fe.homeDirectory),p=Td(fe=>fe.planModeEnabled),m=As(fe=>fe.projects),u=As(fe=>fe.activeProjectId),h=tn(fe=>fe.directories),x=Ir()??"",f=Ie(fe=>fe.setActiveMainTab),v=Ie(fe=>fe.setSessionSwitcherOpen),y=Pn(),{isMobile:g}=rn(),{currentTheme:w}=Ar();o.useMemo(()=>eh(w),[w]);const b=o.useMemo(()=>n?c.find(fe=>fe.id===n)??null:null,[n,c]),k=o.useMemo(()=>{const fe=typeof b?.directory=="string"?b.directory:"";return Or(fe||"")},[b?.directory]),I=o.useMemo(()=>Or(x||k),[x,k]),j=o.useMemo(()=>H2(I,m,u),[u,I,m]),N=o.useMemo(()=>j?h.get(j.path)?.isGitRepo===!0:!1,[j,h]),[D,E]=o.useState(null),[T,C]=o.useState(!1),[S,M]=o.useState(null),A=o.useMemo(()=>!S||!k||!d?S:K2(S,{currentDirectory:k,homeDirectory:d}),[S,k,d]),[R,z]=o.useState(""),[B,V]=o.useState(null),$=o.useMemo(()=>A&&A.split("/").pop()||e("planView.file.defaultName"),[A,e]),_=o.useMemo(()=>R.trim()&&Rb(R).title||e("planView.title.default"),[R,e]),X=o.useMemo(()=>_.trim()||e("planView.title.default"),[_,e]),[O,J]=o.useState(!1),[Q,ne]=o.useState(!1),[G,le]=o.useState("edit"),oe=o.useRef(null),[F,U]=o.useState(null),W=o.useRef(null),te=o.useRef(null),K="vinci:plan:md-viewer-mode";o.useEffect(()=>{try{const fe=localStorage.getItem(K);if(!fe)return;const L=JSON.parse(fe);(L==="preview"||L==="edit")&&le(L)}catch{}},[]);const ae=o.useCallback(fe=>{le(fe);try{localStorage.setItem(K,JSON.stringify(fe))}catch{}},[]),ve=o.useRef(!1),re=o.useRef(null),[be,pe]=o.useState(!1);o.useEffect(()=>{const fe=()=>{ve.current=!1,re.current=null,pe(!1)};return document.addEventListener("mouseup",fe),()=>document.removeEventListener("mouseup",fe)},[]);const ye=o.useCallback((fe,L)=>{const Z=fe.split(`
|
|
54
|
+
`),Y=Math.max(1,L.start),Ee=Math.min(Z.length,L.end);return Y>Ee?"":Z.slice(Y-1,Ee).join(`
|
|
55
|
+
`)},[]),ie=Hd({source:"plan",fileLabel:$,language:S&&xa(S)||"markdown",getCodeForRange:fe=>ye(R,jl(fe)),toStoreRange:fe=>({startLine:fe.start,endLine:fe.end}),fromDraftRange:fe=>({start:fe.startLine,end:fe.endLine})}),{drafts:ue,commentText:se,editingDraftId:Ne,setSelection:Ce,saveComment:je,cancel:we,reset:ke,startEdit:xe,deleteDraft:me}=ie;o.useEffect(()=>{U(null),ke()},[R,ke]),o.useEffect(()=>{Ce(F)},[F,Ce]);const Me=o.useCallback(()=>{U(null),we()},[we]),Ue=o.useCallback((fe,L)=>{L&&U(L),je(fe,L??F??void 0),U(null)},[F,je]);o.useEffect(()=>{if(!F)return;const fe=Z=>{const Y=Z.target;Y.closest('[data-comment-card="true"]')||Y.closest('[data-comment-input="true"]')||Y.closest(".oc-block-widget")||Y.closest(".cm-gutterElement")||Y.closest("[data-sonner-toast]")||Y.closest("[data-sonner-toaster]")||(U(null),we())},L=window.setTimeout(()=>{document.addEventListener("click",fe)},100);return()=>{window.clearTimeout(L),document.removeEventListener("click",fe)}},[we,Ne,g,F]);const q=o.useMemo(()=>{const fe=[fd(w)],L=tg(S||"plan.md");return L&&fe.push(L),fe.push(Xn.lineWrapping),fe},[w,S]);o.useEffect(()=>{if(!p&&!t){M(null),z(""),J(!1);return}let fe=!1;const L=async Y=>{if(y.files?.readFile)return(await y.files.readFile(Y))?.content??"";const Ee=pr()?.files;if(Ee?.readFile)return(await Ee.readFile(Y,{optional:!0}))?.content??"";const Ae=await fetch(`/api/fs/read?path=${encodeURIComponent(Y)}&optional=true`,{cache:"no-store"});if(!Ae.ok)throw new Error(`Failed to read plan file (${Ae.status})`);return Ae.text()};return(async()=>{if(M(null),z(""),V(null),t){J(!0);try{const Y=await L(t);if(fe)return;M(t),z(Y)}catch{if(fe)return;M(null),z("")}finally{fe||J(!1)}return}if(!b?.slug||!b?.time?.created||!k){M(null),z("");return}J(!0);try{const Y=_2(k,b.time.created,b.slug),Ee=W2(U2(b.time.created,b.slug),d||null);let Ae=null,Je=null;try{Je=await L(Y),Ae=Y}catch{}if(!Ae)try{Je=await L(Ee),Ae=Ee}catch{}if(fe)return;if(!Ae||Je===null){M(null),z("");return}M(Ae),z(Je)}catch{if(fe)return;M(null),z("")}finally{fe||J(!1)}})(),()=>{fe=!0}},[d,p,y.files,k,b?.slug,b?.time?.created,t]),o.useEffect(()=>{if(!S){V(null);return}const fe=window.setTimeout(async()=>{V(null);try{if(y.files?.writeFile){if(!(await y.files.writeFile(S,R))?.success)throw new Error(e("planView.error.writeFailed"))}else{const L=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:S,content:R})});if(!L.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:L.status}))}}catch(L){V(L instanceof Error?L.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(fe)}},[R,S,y.files,e]),o.useEffect(()=>()=>{oe.current!==null&&window.clearTimeout(oe.current)},[]);const Se=o.useCallback(()=>{f("chat"),v(!1)},[f,v]),$e=o.useCallback(async fe=>{if(!j||!D)return;const L=await wn(D.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:X}),Y=[{synthetic:!0,text:await wn(D.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:X,plan_path:S??""})}];C(!0);try{Se();let Ee=null,Ae=j.path;if(D.target==="worktree"){if(!N)return;const de=await Qf(j.path,Jf());if(!de?.id)return;Ee=de.id,Ae=null}else{const de=await r(void 0,j.path,null);if(!de?.id)return;Ee=de.id,Ae=de.directory??j.path,i(de.id,xt.getState().agents??[])}if(!Ee)return;const Je=Fl.getState();Je.saveSessionModelSelection(Ee,fe.providerID,fe.modelID),fe.agent.trim()&&(Je.saveSessionAgentSelection(Ee,fe.agent),Je.saveAgentModelForSession(Ee,fe.agent,fe.providerID,fe.modelID),Je.saveAgentModelVariantForSession(Ee,fe.agent,fe.providerID,fe.modelID,fe.variant||void 0)),l(Ee,Ae),await a(L,fe.providerID,fe.modelID,fe.agent.trim()||void 0,void 0,void 0,Y,fe.variant||void 0),E(null)}finally{C(!1)}},[N,r,j,i,D,S,Se,a,X,l]),Pe=o.useMemo(()=>_h({drafts:ue,editingDraftId:Ne,commentText:se,selection:F,isDragging:be,fileLabel:$,newWidgetId:"plan-new-comment-input",mapDraftToRange:fe=>({start:fe.startLine,end:fe.endLine}),onSave:Ue,onCancel:Me,onEdit:fe=>{xe(fe),U({start:fe.startLine,end:fe.endLine})},onDelete:me}),[se,me,Ne,Me,Ue,be,F,ue,$,xe]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:_}),B?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:B,children:e("planView.error.saveFailed")}):null]}),S?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(Fs,{children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!R.trim(),children:s.jsx(P,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(Dt,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(Rs,{align:"end",children:[s.jsx($t,{onClick:()=>E({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx($t,{onClick:()=>E({action:"improve",target:"worktree"}),disabled:!N,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(Fs,{children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx(ge,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!R.trim(),children:s.jsx(P,{name:"code-ai",className:"size-4"})})})}),s.jsx(Dt,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(Rs,{align:"end",children:[s.jsx($t,{onClick:()=>E({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx($t,{onClick:()=>E({action:"implement",target:"worktree"}),disabled:!N,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(md,{currentMode:G,onToggle:()=>ae(G==="preview"?"edit":"preview")}),s.jsx(ge,{variant:"ghost",size:"sm",onClick:async()=>{(await _n(R)).ok&&(ne(!0),oe.current!==null&&window.clearTimeout(oe.current),oe.current=window.setTimeout(()=>{ne(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:Q?s.jsx(P,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(P,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(Mh,{open:D!==null,onOpenChange:fe=>{!fe&&!T&&E(null)},target:D?.target??"session",projectDirectory:j?.path??null,submitting:T,onConfirm:$e}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Cs,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:O?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("planView.state.loading")}):s.jsx("div",{className:"relative h-full",children:s.jsx("div",{className:"h-full",children:G==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(Xs,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("planView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("planView.error.switchToEditMode")})]}),children:s.jsx(to,{content:R,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:te,children:s.jsx(ud,{value:R,onChange:z,readOnly:!1,className:"h-full",extensions:q,onViewReady:fe=>{W.current=fe},onViewDestroy:()=>{W.current=null},blockWidgets:Pe,highlightLines:F?{start:Math.min(F.start,F.end),end:Math.max(F.start,F.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(fe,L,Z)=>{if(!(Z instanceof MouseEvent)||Z.button!==0)return!1;Z.preventDefault();const Y=fe.state.doc.lineAt(L.from).number;if(g&&F&&!Z.shiftKey){const Ee=Math.min(F.start,F.end,Y),Ae=Math.max(F.start,F.end,Y);return U({start:Ee,end:Ae}),ve.current=!1,re.current=null,pe(!1),!0}if(ve.current=!0,re.current=Y,pe(!0),F&&Z.shiftKey){const Ee=Math.min(F.start,Y),Ae=Math.max(F.end,Y);U({start:Ee,end:Ae})}else U({start:Y,end:Y});return!0},mouseover:(fe,L,Z)=>{if(!(Z instanceof MouseEvent)||Z.buttons!==1||!ve.current||re.current===null)return!1;const Y=fe.state.doc.lineAt(L.from).number,Ee=Math.min(re.current,Y),Ae=Math.max(re.current,Y);return U({start:Ee,end:Ae}),pe(!0),!1},mouseup:()=>(ve.current=!1,re.current=null,pe(!1),!1)}}})})})})})})]})},G2=Object.freeze(Object.defineProperty({__proto__:null,PlanView:ig},Symbol.toStringTag,{value:"Module"})),gd={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},nl={user:0,assistant:0,tool:0,other:0},Pi=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,ep=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(p=>p.tokens!==void 0)?.tokens;if(typeof n=="number")return{...gd,total:Pi(n)};if(!n||typeof n!="object")return gd;const r=n,i=Pi(r.input),a=Pi(r.output),l=Pi(r.reasoning),c=Pi(r.cache?.read),d=Pi(r.cache?.write);return{input:i,output:a,reasoning:l,cacheRead:c,cacheWrite:d,total:i+a+l+c+d}},q2=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},cr=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+cr(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+cr(n),0):0,Y2=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...nl,assistant:cr(n.text)+cr(n.content)};const i=q2(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:cr(n.input)+cr(n.output)+cr(n.error)+cr(n.call?.input)+cr(n.call?.output)+cr(n.call?.error)+cr(n.raw)+Math.round(cr(n.metadata)*.25)+Math.round(cr(n.state)*.1),other:0}:e==="user"?{user:i.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:i.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:i.length}},tp=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),Q2=t=>{const e=go(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},J2=(t,e)=>{if(t.length===0)return{...nl};const n=t.reduce((r,i)=>{const a=Q2(i);let l={...nl};for(const c of i.parts)l=tp(l,Y2(c,a));return tp(r,l)},{...nl});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},na=t=>t.toLocaleString(),X2=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,Z2=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),eS=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),tS=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,sS=(t,e,n)=>{const r=t.find(a=>a.id===e),i=r?.models?.find(a=>a.id===n);return{providerName:r?.name||e||"-",modelName:i?.name||n||"-",contextLimit:typeof i?.limit?.context=="number"?i.limit.context:null}},nS=()=>{const t=at.c(199),{t:e}=ut(),{currentTheme:n}=Ar();let r;t[0]!==n?(r=eh(n),t[0]=n,t[1]=r):r=t[1];const i=r;let a;t[2]===Symbol.for("react.memo_cache_sentinel")?(a={},t[2]=a):a=t[2];const[l,c]=o.useState(a),[d,p]=o.useState(null),m=o.useRef(null),u=Ot(rS),h=zl(),x=Fb(u??""),f=xt(iS);let v;t[3]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(aS),p(null)},t[3]=v):v=t[3];let y;t[4]!==u?(y=[u],t[4]=u,t[5]=y):y=t[5],o.useEffect(v,y);let g,w;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},w=[],t[6]=g,t[7]=w):(g=t[6],w=t[7]),o.useEffect(g,w);let b;t[8]===Symbol.for("react.memo_cache_sentinel")?(b=async(mt,Nt)=>{(await _n(Nt)).ok?(p(mt),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(_t=>_t===mt?null:_t),m.current=null},2e3)):p(null)},t[8]=b):b=t[8];const k=b;let I;t[9]!==u||t[10]!==h?(I=u?h.find(mt=>mt.id===u)??null:null,t[9]=u,t[10]=h,t[11]=I):I=t[11];const j=I;let N,D,E,T,C;if(t[12]!==f||t[13]!==x){N=x.filter(oS);let mt;t[19]!==x?(mt=x.filter(lS),t[19]=x,t[20]=mt):mt=t[20],C=mt;let Nt=null;for(let _t=N.length-1;_t>=0;_t=_t-1,_t){const Gt=N[_t];if(ep(Gt).total>0){Nt=Gt;break}}E=Nt?ep(Nt):gd,T=N.reduce(cS,0);const Xt=Nt?.info??null;D=sS(f,Xt?.providerID||"",Xt?.modelID||""),t[12]=f,t[13]=x,t[14]=N,t[15]=D,t[16]=E,t[17]=T,t[18]=C}else N=t[14],D=t[15],E=t[16],T=t[17],C=t[18];const S=D,M=S.contextLimit,A=M&&M>0?Math.min(999,E.total/M*100):0;let R;if(t[21]!==x){const mt=[...x].reverse().find(dS)?.info?.system||"";R=J2(x,mt),t[21]=x,t[22]=R}else R=t[22];const z=R,B=z.user,V=z.assistant,$=z.tool,_=Math.max(0,E.input-B-V-$),X=B+V+$+_,O=x[0]?.info?.time?.created,J=x.length>0?x[x.length-1]?.info?.time?.created:null;let Q;t[23]!==j?.title||t[24]!==e?(Q=j?.title||e("contextSidebar.session.untitled"),t[23]=j?.title,t[24]=e,t[25]=Q):Q=t[25];const ne=j?.time?.created??O??null,G=J??j?.time?.created??null;let le;t[26]!==V||t[27]!==_||t[28]!==$||t[29]!==B?(le={user:B,assistant:V,tool:$,other:_},t[26]=V,t[27]=_,t[28]=$,t[29]=B,t[30]=le):le=t[30];let oe;t[31]!==N.length||t[32]!==X||t[33]!==M||t[34]!==S||t[35]!==x.length||t[36]!==Q||t[37]!==ne||t[38]!==G||t[39]!==le||t[40]!==E||t[41]!==T||t[42]!==A||t[43]!==C.length?(oe={sessionTitle:Q,messagesCount:x.length,userMessagesCount:C.length,assistantMessagesCount:N.length,createdAt:ne,lastActivityAt:G,providerModel:S,tokenBreakdown:E,usagePercent:A,totalAssistantCost:T,contextLimit:M,breakdown:le,breakdownTotal:X},t[31]=N.length,t[32]=X,t[33]=M,t[34]=S,t[35]=x.length,t[36]=Q,t[37]=ne,t[38]=G,t[39]=le,t[40]=E,t[41]=T,t[42]=A,t[43]=C.length,t[44]=oe):oe=t[44];const F=oe;if(!u){let mt;t[45]!==e?(mt=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=mt):mt=t[46];let Nt;return t[47]!==mt?(Nt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:mt}),t[47]=mt,t[48]=Nt):Nt=t[48],Nt}let U;t[49]!==e?(U=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=U):U=t[50];let W;t[51]!==U||t[52]!==F.breakdown.user?(W={key:"user",label:U,value:F.breakdown.user,color:"var(--status-success)"},t[51]=U,t[52]=F.breakdown.user,t[53]=W):W=t[53];let te;t[54]!==e?(te=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=te):te=t[55];let K;t[56]!==te||t[57]!==F.breakdown.assistant?(K={key:"assistant",label:te,value:F.breakdown.assistant,color:"var(--primary-base)"},t[56]=te,t[57]=F.breakdown.assistant,t[58]=K):K=t[58];let ae;t[59]!==e?(ae=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=ae):ae=t[60];let ve;t[61]!==ae||t[62]!==F.breakdown.tool?(ve={key:"tool",label:ae,value:F.breakdown.tool,color:"var(--status-warning)"},t[61]=ae,t[62]=F.breakdown.tool,t[63]=ve):ve=t[63];let re;t[64]!==e?(re=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=re):re=t[65];let be;t[66]!==re||t[67]!==F.breakdown.other?(be={key:"other",label:re,value:F.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=re,t[67]=F.breakdown.other,t[68]=be):be=t[68];let pe;t[69]!==W||t[70]!==K||t[71]!==ve||t[72]!==be?(pe=[W,K,ve,be],t[69]=W,t[70]=K,t[71]=ve,t[72]=be,t[73]=pe):pe=t[73];const ye=pe;let ie;t[74]!==F.sessionTitle?(ie=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:F.sessionTitle}),t[74]=F.sessionTitle,t[75]=ie):ie=t[75];let ue;t[76]!==F.providerModel.modelName||t[77]!==F.providerModel.providerName?(ue=s.jsxs("span",{children:[F.providerModel.providerName," / ",F.providerModel.modelName]}),t[76]=F.providerModel.modelName,t[77]=F.providerModel.providerName,t[78]=ue):ue=t[78];let se;t[79]!==F.createdAt?(se=F.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:Z2(F.createdAt)})]}),t[79]=F.createdAt,t[80]=se):se=t[80];let Ne;t[81]!==ue||t[82]!==se?(Ne=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[ue,se]}),t[81]=ue,t[82]=se,t[83]=Ne):Ne=t[83];let Ce;t[84]!==ie||t[85]!==Ne?(Ce=s.jsxs("div",{className:"mb-6",children:[ie,Ne]}),t[84]=ie,t[85]=Ne,t[86]=Ce):Ce=t[86];let je;t[87]!==e?(je=e("contextSidebar.section.context"),t[87]=e,t[88]=je):je=t[88];let we;t[89]!==je?(we=s.jsx("span",{className:"typography-micro text-muted-foreground",children:je}),t[89]=je,t[90]=we):we=t[90];let ke;t[91]!==F.tokenBreakdown.total?(ke=na(F.tokenBreakdown.total),t[91]=F.tokenBreakdown.total,t[92]=ke):ke=t[92];let xe;t[93]!==F.contextLimit?(xe=F.contextLimit?` / ${na(F.contextLimit)}`:"",t[93]=F.contextLimit,t[94]=xe):xe=t[94];let me;t[95]!==ke||t[96]!==xe?(me=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[ke,xe]}),t[95]=ke,t[96]=xe,t[97]=me):me=t[97];let Me;t[98]!==we||t[99]!==me?(Me=s.jsxs("div",{className:"flex items-baseline justify-between",children:[we,me]}),t[98]=we,t[99]=me,t[100]=Me):Me=t[100];let Ue;t[101]!==F.usagePercent?(Ue=F.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,F.usagePercent)}%`,backgroundColor:F.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=F.usagePercent,t[102]=Ue):Ue=t[102];let q;t[103]!==Ue?(q=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Ue}),t[103]=Ue,t[104]=q):q=t[104];let Se;t[105]!==e||t[106]!==F.usagePercent?(Se=e("contextSidebar.context.percentUsed",{percent:F.usagePercent.toFixed(1)}),t[105]=e,t[106]=F.usagePercent,t[107]=Se):Se=t[107];let $e;t[108]!==Se?($e=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Se}),t[108]=Se,t[109]=$e):$e=t[109];let Pe;t[110]!==Me||t[111]!==q||t[112]!==$e?(Pe=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Me,q,$e]}),t[110]=Me,t[111]=q,t[112]=$e,t[113]=Pe):Pe=t[113];let fe;t[114]!==e?(fe=e("contextSidebar.stats.messages"),t[114]=e,t[115]=fe):fe=t[115];let L;t[116]!==F.messagesCount?(L=na(F.messagesCount),t[116]=F.messagesCount,t[117]=L):L=t[117];let Z;t[118]!==fe||t[119]!==L?(Z={label:fe,value:L},t[118]=fe,t[119]=L,t[120]=Z):Z=t[120];let Y;t[121]!==e?(Y=e("contextSidebar.stats.user"),t[121]=e,t[122]=Y):Y=t[122];let Ee;t[123]!==F.userMessagesCount?(Ee=na(F.userMessagesCount),t[123]=F.userMessagesCount,t[124]=Ee):Ee=t[124];let Ae;t[125]!==Y||t[126]!==Ee?(Ae={label:Y,value:Ee},t[125]=Y,t[126]=Ee,t[127]=Ae):Ae=t[127];let Je;t[128]!==e?(Je=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=Je):Je=t[129];let de;t[130]!==F.assistantMessagesCount?(de=na(F.assistantMessagesCount),t[130]=F.assistantMessagesCount,t[131]=de):de=t[131];let ze;t[132]!==Je||t[133]!==de?(ze={label:Je,value:de},t[132]=Je,t[133]=de,t[134]=ze):ze=t[134];let rt;t[135]!==e?(rt=e("contextSidebar.stats.cost"),t[135]=e,t[136]=rt):rt=t[136];let Re;t[137]!==F.totalAssistantCost?(Re=X2(F.totalAssistantCost),t[137]=F.totalAssistantCost,t[138]=Re):Re=t[138];let Xe;t[139]!==rt||t[140]!==Re?(Xe={label:rt,value:Re},t[139]=rt,t[140]=Re,t[141]=Xe):Xe=t[141];let qe;t[142]!==Z||t[143]!==Ae||t[144]!==ze||t[145]!==Xe?(qe=[Z,Ae,ze,Xe],t[142]=Z,t[143]=Ae,t[144]=ze,t[145]=Xe,t[146]=qe):qe=t[146];const Te=qe;let We;t[147]!==Te?(We=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:Te.map(uS)}),t[147]=Te,t[148]=We):We=t[148];let Ze;t[149]!==e?(Ze=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=Ze):Ze=t[150];let Qe;t[151]!==Ze?(Qe=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ze}),t[151]=Ze,t[152]=Qe):Qe=t[152];let he;t[153]!==e||t[154]!==F.tokenBreakdown.cacheRead||t[155]!==F.tokenBreakdown.cacheWrite||t[156]!==F.tokenBreakdown.input||t[157]!==F.tokenBreakdown.output||t[158]!==F.tokenBreakdown.reasoning?(he=s.jsx("div",{className:"mt-2.5 grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:F.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:F.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:F.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:F.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:F.tokenBreakdown.cacheWrite}].map(mS)}),t[153]=e,t[154]=F.tokenBreakdown.cacheRead,t[155]=F.tokenBreakdown.cacheWrite,t[156]=F.tokenBreakdown.input,t[157]=F.tokenBreakdown.output,t[158]=F.tokenBreakdown.reasoning,t[159]=he):he=t[159];let Ge;t[160]!==Qe||t[161]!==he?(Ge=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Qe,he]}),t[160]=Qe,t[161]=he,t[162]=Ge):Ge=t[162];let Ve;t[163]!==ye||t[164]!==F.breakdownTotal?(Ve=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ye.map(mt=>mt.value<=0||F.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${mt.value/F.breakdownTotal*100}%`,backgroundColor:mt.color}},mt.key))}),t[163]=ye,t[164]=F.breakdownTotal,t[165]=Ve):Ve=t[165];let it;t[166]!==ye||t[167]!==F.breakdownTotal?(it=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ye.map(mt=>{const Nt=F.breakdownTotal>0?mt.value/F.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:mt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[mt.label," ",s.jsxs("span",{className:"tabular-nums",children:[Nt.toFixed(0),"%"]})]})]},mt.key)})}),t[166]=ye,t[167]=F.breakdownTotal,t[168]=it):it=t[168];let dt;t[169]!==Ve||t[170]!==it?(dt=s.jsxs("div",{className:"mb-6",children:[Ve,it]}),t[169]=Ve,t[170]=it,t[171]=dt):dt=t[171];let Ye;t[172]!==e?(Ye=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=Ye):Ye=t[173];let _e;t[174]!==Ye?(_e=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ye}),t[174]=Ye,t[175]=_e):_e=t[175];let et;if(t[176]!==d||t[177]!==l||t[178]!==x||t[179]!==i||t[180]!==e){let mt;t[182]!==d||t[183]!==l||t[184]!==i||t[185]!==e?(mt=Nt=>{const Xt=go(Nt.info).role,_t=l[Nt.info.id]===!0,Gt=d===Nt.info.id,lt=Nt.info.time?.created??null,Tt=_t?JSON.stringify({info:Nt.info,parts:Nt.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":_t,onClick:()=>{c(rs=>({...rs,[Nt.info.id]:rs[Nt.info.id]!==!0}))},children:s.jsxs("div",{className:"flex items-center justify-between gap-2 whitespace-nowrap overflow-hidden",children:[s.jsxs("span",{className:"min-w-0 inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:tS(Xt)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:Nt.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:eS(lt)})]})}),_t&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:rs=>{rs.stopPropagation(),k(Nt.info.id,Tt)},"aria-label":e(Gt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Gt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Gt?s.jsx(P,{name:"check",className:"size-3.5"}):s.jsx(P,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Ax,{language:"json",style:i,PreTag:"div",customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},codeTagProps:{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"break-word"}},wrapLongLines:!0,children:Tt})]})})]},Nt.info.id)},t[182]=d,t[183]=l,t[184]=i,t[185]=e,t[186]=mt):mt=t[186],et=[...x].reverse().map(mt),t[176]=d,t[177]=l,t[178]=x,t[179]=i,t[180]=e,t[181]=et}else et=t[181];let gt;t[187]!==et?(gt=s.jsx("div",{className:"mt-2.5 space-y-1",children:et}),t[187]=et,t[188]=gt):gt=t[188];let Lt;t[189]!==_e||t[190]!==gt?(Lt=s.jsxs("div",{children:[_e,gt]}),t[189]=_e,t[190]=gt,t[191]=Lt):Lt=t[191];let Ut;return t[192]!==Ce||t[193]!==Pe||t[194]!==We||t[195]!==Ge||t[196]!==dt||t[197]!==Lt?(Ut=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[Ce,Pe,We,Ge,dt,Lt]})}),t[192]=Ce,t[193]=Pe,t[194]=We,t[195]=Ge,t[196]=dt,t[197]=Lt,t[198]=Ut):Ut=t[198],Ut};function rS(t){return t.currentSessionId}function iS(t){return t.providers}function aS(t){return Object.keys(t).length>0?{}:t}function oS(t){return go(t.info).role==="assistant"}function lS(t){return go(t.info).isUser}function cS(t,e){const n=Pi(e.info.cost);return t+n}function dS(t){return go(t.info).isUser&&typeof t.info.system=="string"}function uS(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function mS(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:na(t.value)})]},t.label)}const pS=360,fS=1400,ag=600,hS=24,sp=200,gS=(t,e)=>e==="all"?!0:e==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":e==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",xd=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="string"&&typeof e.selector=="string"&&typeof e.path=="string"&&!!n&&typeof n?.x=="number"&&typeof n?.y=="number"&&typeof n?.width=="number"&&typeof n?.height=="number"},og=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:i,intro:a})=>{const l=r.text.trim(),c=Object.entries(r.attributes).map(([x,f])=>`${x}="${f}"`).join(" "),d=r.computedStyle,p=r.bounds,m=r.center,u=a.replace(/[.:]+$/g,""),h=r.ancestry.map(x=>x.selectorPart).join(" > ");return[`${u}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${i?"attached":"not attached"}`,`Element: ${r.tag}`,l?`Text: ${l}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,h?`- Ancestry: ${h}`:null,c?`- Attributes: ${c}`:null,`- Bounds: x=${Math.round(p.x)}, y=${Math.round(p.y)}, width=${Math.round(p.width)}, height=${Math.round(p.height)}`,`- Center: x=${Math.round(m.x)}, y=${Math.round(m.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(x=>typeof x=="string").join(`
|
|
56
|
+
`)},xS=async(t,e)=>{const n=typeof window<"u"?window.__TAURI__:void 0;if(typeof n?.core?.invoke=="function")try{const r=t.getBoundingClientRect(),i=await n.core.invoke("desktop_capture_page_rect",{x:r.left,y:r.top,width:r.width,height:r.height}),a=new Image;await new Promise((v,y)=>{a.onload=()=>v(),a.onerror=()=>y(new Error("Failed to load desktop preview screenshot")),a.src=`data:${i.mime};base64,${i.base64}`});const l=Math.max(1,a.naturalWidth||i.width||Math.floor(r.width)),c=Math.max(1,a.naturalHeight||i.height||Math.floor(r.height)),p=Math.min(1,1200/l),m=document.createElement("canvas");m.width=Math.floor(l*p),m.height=Math.floor(c*p);const u=m.getContext("2d");if(!u)return null;u.scale(p,p),u.drawImage(a,0,0,l,c);const h=l/Math.max(1,r.width),x=c/Math.max(1,r.height);u.fillStyle="rgba(37, 99, 235, 0.28)",u.strokeStyle="rgb(37, 99, 235)",u.lineWidth=Math.max(2,2*h),u.fillRect(e.bounds.x*h,e.bounds.y*x,e.bounds.width*h,e.bounds.height*x),u.strokeRect(e.bounds.x*h,e.bounds.y*x,e.bounds.width*h,e.bounds.height*x);const f=await new Promise(v=>m.toBlob(v,"image/jpeg",.82));return f?new File([f],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},bS=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},np=t=>Number.isFinite(t)?Math.min(fS,Math.max(pS,Math.round(t))):ag,yS=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},vS=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":t==="browser"?"contextPanel.mode.browser":"contextPanel.mode.context"),wS=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},jS=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return wS(t.targetPath)||e("contextPanel.mode.files");if(t.mode==="preview"){const n=t.targetPath;if(n)try{const r=new URL(n);return r.host||r.hostname||e("contextPanel.mode.preview")}catch{}return e("contextPanel.mode.preview")}return vS(t.mode,e)},NS=t=>{if(t.mode==="file")return t.targetPath?s.jsx(Zn,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(P,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(P,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(P,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(P,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(P,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(P,{name:"global",className:"h-3.5 w-3.5"})},SS=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,kS=`new Promise((resolve) => {
|
|
57
|
+
const existing = document.getElementById('__vinci_desktop_browser_overlay');
|
|
58
|
+
if (existing) existing.remove();
|
|
59
|
+
if (typeof window.__vinciDesktopBrowserCancelInspect === 'function') {
|
|
60
|
+
try { window.__vinciDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
61
|
+
}
|
|
62
|
+
const overlay = document.createElement('div');
|
|
63
|
+
overlay.id = '__vinci_desktop_browser_overlay';
|
|
64
|
+
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
65
|
+
document.documentElement.appendChild(overlay);
|
|
66
|
+
const cssEscape = (value) => {
|
|
67
|
+
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
68
|
+
};
|
|
69
|
+
const selectorPart = (element) => {
|
|
70
|
+
const tag = element.tagName.toLowerCase();
|
|
71
|
+
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
72
|
+
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
73
|
+
return tag + className;
|
|
74
|
+
};
|
|
75
|
+
const metadata = (element) => {
|
|
76
|
+
const rect = element.getBoundingClientRect();
|
|
77
|
+
const style = getComputedStyle(element);
|
|
78
|
+
const ancestry = [];
|
|
79
|
+
let current = element;
|
|
80
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
81
|
+
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
82
|
+
current = current.parentElement;
|
|
83
|
+
}
|
|
84
|
+
const attrs = {};
|
|
85
|
+
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
86
|
+
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
87
|
+
return {
|
|
88
|
+
frame: 'top',
|
|
89
|
+
tag: element.tagName.toLowerCase(),
|
|
90
|
+
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
91
|
+
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
92
|
+
path,
|
|
93
|
+
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
94
|
+
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
95
|
+
attributes: attrs,
|
|
96
|
+
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
97
|
+
ancestry,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const move = (event) => {
|
|
101
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
102
|
+
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
103
|
+
const rect = element.getBoundingClientRect();
|
|
104
|
+
overlay.style.display = 'block';
|
|
105
|
+
overlay.style.left = rect.left + 'px';
|
|
106
|
+
overlay.style.top = rect.top + 'px';
|
|
107
|
+
overlay.style.width = rect.width + 'px';
|
|
108
|
+
overlay.style.height = rect.height + 'px';
|
|
109
|
+
};
|
|
110
|
+
const cleanup = () => {
|
|
111
|
+
window.removeEventListener('mousemove', move, true);
|
|
112
|
+
window.removeEventListener('click', click, true);
|
|
113
|
+
window.removeEventListener('keydown', keydown, true);
|
|
114
|
+
if (window.__vinciDesktopBrowserCancelInspect === cancel) {
|
|
115
|
+
delete window.__vinciDesktopBrowserCancelInspect;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const cancel = () => {
|
|
119
|
+
cleanup();
|
|
120
|
+
overlay.remove();
|
|
121
|
+
resolve(null);
|
|
122
|
+
};
|
|
123
|
+
const click = (event) => {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
event.stopPropagation();
|
|
126
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
127
|
+
const result = element ? metadata(element) : null;
|
|
128
|
+
cleanup();
|
|
129
|
+
overlay.remove();
|
|
130
|
+
resolve(result);
|
|
131
|
+
};
|
|
132
|
+
const keydown = (event) => {
|
|
133
|
+
if (event.key !== 'Escape') return;
|
|
134
|
+
cancel();
|
|
135
|
+
};
|
|
136
|
+
window.__vinciDesktopBrowserCancelInspect = cancel;
|
|
137
|
+
window.addEventListener('mousemove', move, true);
|
|
138
|
+
window.addEventListener('click', click, true);
|
|
139
|
+
window.addEventListener('keydown', keydown, true);
|
|
140
|
+
});`,Cc=`(() => {
|
|
141
|
+
if (typeof window.__vinciDesktopBrowserCancelInspect === 'function') {
|
|
142
|
+
window.__vinciDesktopBrowserCancelInspect();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const overlay = document.getElementById('__vinci_desktop_browser_overlay');
|
|
146
|
+
if (overlay) overlay.remove();
|
|
147
|
+
})()`,Pc=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},CS=async(t,e,n,r,i,a)=>{if(!t)return null;try{const l=new Image;await new Promise((y,g)=>{l.onload=()=>y(),l.onerror=()=>g(new Error("Failed to load desktop browser screenshot")),l.src=`data:image/jpeg;base64,${t}`});const c=Math.max(1,l.naturalWidth||e),d=Math.max(1,l.naturalHeight||n),m=Math.min(1,1200/c),u=document.createElement("canvas");u.width=Math.floor(c*m),u.height=Math.floor(d*m);const h=u.getContext("2d");if(!h)return null;h.scale(m,m),h.drawImage(l,0,0,c,d);const x=c/Math.max(1,r||c),f=d/Math.max(1,i||d);h.fillStyle="rgba(37, 99, 235, 0.14)",h.strokeStyle="rgb(37, 99, 235)",h.lineWidth=Math.max(2,2*x),h.fillRect(a.bounds.x*x,a.bounds.y*f,a.bounds.width*x,a.bounds.height*f),h.strokeRect(a.bounds.x*x,a.bounds.y*f,a.bounds.width*x,a.bounds.height*f);const v=await new Promise(y=>u.toBlob(y,"image/jpeg",.82));return v?new File([v],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},PS=(t,e,n)=>{if(typeof window>"u")return"";const r=new URL(window.location.pathname,window.location.origin);return r.searchParams.set("ocPanel","session-chat"),r.searchParams.set("sessionId",t),n?r.searchParams.set("readOnly","1"):r.searchParams.delete("readOnly"),e&&e.trim().length>0?r.searchParams.set("directory",e):r.searchParams.delete("directory"),r.hash="",r.toString()},IS=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Ai=new Map,AS=3e4,DS=t=>{const e=Ai.get(t);return e?e.expiresAt-Date.now()<=AS?(Ai.delete(t),null):e:null},TS=({rawUrl:t,onNavigate:e})=>{const{t:n}=ut(),{currentTheme:r}=Ar(),[i,a]=o.useReducer(re=>re+1,0),[l,c]=o.useReducer(re=>re+1,0),[d,p]=o.useState({status:"idle"}),m=o.useRef(null),u=o.useRef(1),[h,x]=o.useState(!1),[f,v]=o.useState(!1),[y,g]=o.useState("all"),[w,b]=o.useState([]),[k,I]=o.useState(!1),[j,N]=o.useState(null),D=Ot(re=>re.currentSessionId),E=Ot(re=>re.newSessionDraft?.open),T=ia(re=>re.addDraft),C=zi(re=>re.addAttachedFile);let S=null;try{S=t?new URL(t):null}catch{S=null}const M=S?S.hostname==="localhost"||S.hostname==="127.0.0.1"||S.hostname==="::1"||S.hostname==="[::1]"||S.hostname==="0.0.0.0":!1,A=S?S.hostname==="0.0.0.0"?new URL(S.toString().replace("0.0.0.0","127.0.0.1")):S:null,R=A?A.toString():"",z=r.metadata.variant;o.useEffect(()=>{if(!R||!M){p({status:"idle"});return}const re=DS(R);if(re){p({status:"ready",proxyBasePath:re.proxyBasePath,expiresAt:re.expiresAt});return}let be=!1;return p({status:"loading"}),(async()=>{try{const pe=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:R})});if(!pe.ok){Ai.delete(R);const se=await pe.json().catch(()=>({})),Ne=typeof se?.error=="string"?se.error:`HTTP ${pe.status}`;be||p({status:"error",message:Ne});return}const ye=await pe.json(),ie=typeof ye.proxyBasePath=="string"?ye.proxyBasePath:"",ue=typeof ye.expiresAt=="number"?ye.expiresAt:0;if(!ie){Ai.delete(R),be||p({status:"error",message:n("contextPanel.preview.proxyError")});return}Ai.set(R,{proxyBasePath:ie,expiresAt:ue}),be||p({status:"ready",proxyBasePath:ie,expiresAt:ue})}catch(pe){if(Ai.delete(R),!be){const ye=pe instanceof Error?pe.message:String(pe);p({status:"error",message:ye})}}})(),()=>{be=!0}},[M,l,n,R]);const B=A&&(A.protocol==="http:"||A.protocol==="https:")?A.toString():"",V=M&&d.status==="ready"&&A?(()=>{const re=A.pathname||"/",be=new URLSearchParams(A.search);be.set("ocPreview",String(i));const pe=be.toString(),ye=A.hash||"";return`${d.proxyBasePath}${re}${pe?`?${pe}`:""}${ye}`})():"",$=M?V:B,_=$||B,X=M&&(d.status==="loading"||d.status==="idle"),O=M&&d.status==="error",J=o.useCallback(re=>{const be=D??(E?"draft":null);if(!be){H.error(n("contextPanel.preview.inspect.attachNoSession"));return}const pe=t||$||"",ye=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},ie=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let ue=!1;try{const se=m.current,Ne=se?await xS(se,re):null;Ne&&(await C(Ne),ue=!0)}catch{ue=!1}T({sessionKey:be,source:"preview-annotation",fileLabel:pe||"preview",startLine:1,endLine:1,code:og({pageUrl:pe,viewport:ye,devicePixelRatio:ie,target:re,screenshotAttached:ue,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),H.success(n("contextPanel.preview.inspect.attached"))})()},[C,T,D,$,E,t,n]);o.useEffect(()=>{x(!1),b([]),v(!1),g("all"),I(!1),N(null),u.current=1},[$]),o.useEffect(()=>{const re=m.current?.contentWindow;!h||!re||re.postMessage({source:"vinci-preview-parent",version:1,type:"set-inspect-mode",enabled:k},window.location.origin)},[h,k]),o.useEffect(()=>{const re=m.current?.contentWindow;!h||!re||re.postMessage({source:"vinci-preview-parent",version:1,type:"set-color-scheme",scheme:z},window.location.origin)},[h,z]),o.useEffect(()=>{if(!k||typeof window>"u")return;const re=be=>{be.key==="Escape"&&(be.preventDefault(),be.stopImmediatePropagation(),I(!1))};return window.addEventListener("keydown",re,!0),()=>window.removeEventListener("keydown",re,!0)},[k]),o.useEffect(()=>{if(!M||typeof window>"u")return;const re=ye=>{if(typeof ye=="string")return ye;if(ye==null)return"";try{return JSON.stringify(ye)}catch{return String(ye)}},be=ye=>{const ie=u.current;u.current+=1,b(ue=>{const se=[...ue,{...ye,id:ie}];return se.length>sp?se.slice(se.length-sp):se})},pe=ye=>{if(ye.source!==m.current?.contentWindow)return;const ie=ye.data;if(!(!ie||ie.source!=="vinci-preview-bridge"||ie.version!==1)){if(ie.type==="ready"){x(!0);return}if(ie.type==="console"){const ue=ie.level==="error"||ie.level==="warn"||ie.level==="info"||ie.level==="debug"?ie.level:"log",se=Array.isArray(ie.args)?ie.args.map(re).filter(Boolean):[];be({level:ue,message:se.join(" "),ts:typeof ie.ts=="number"?ie.ts:Date.now()});return}if(ie.type==="runtime-error"){const ue=re(ie.filename),se=typeof ie.line=="number"?ie.line:null,Ne=typeof ie.column=="number"?ie.column:null,Ce=ue?`${ue}${se!==null?`:${se}${Ne!==null?`:${Ne}`:""}`:""}`:"",je=re(ie.stack);be({level:"runtime",message:re(ie.message)||n("contextPanel.preview.console.runtimeError"),details:[Ce,je].filter(Boolean).join(`
|
|
148
|
+
`),ts:typeof ie.ts=="number"?ie.ts:Date.now()});return}if(ie.type==="resource-error"){const ue=re(ie.tag)||"resource",se=re(ie.url);be({level:"resource",message:se?`${ue}: ${se}`:ue,details:re(ie.outerHTML),ts:typeof ie.ts=="number"?ie.ts:Date.now()});return}if(ie.type==="hover"){N(xd(ie.target)?ie.target:null);return}if(ie.type==="select"&&xd(ie.target)){N(ie.target),I(!1),J(ie.target);return}if(ie.type==="navigate-preview"){const ue=typeof ie.url=="string"?ie.url:"",se=ie.navigation==="external"?"external":"proxy";if(ue&&se==="external"){rr(ue);return}ue&&e(ue)}}};return window.addEventListener("message",pe),()=>{window.removeEventListener("message",pe)}},[J,M,e,n]);const Q=w.filter(re=>re.level==="error"||re.level==="runtime"||re.level==="resource").length,ne=w.filter(re=>gS(re,y)),G=o.useCallback(()=>{const re=[`Preview URL: ${t||$||""}`,`Events: ${w.length}`,""].join(`
|
|
149
|
+
`),be=w.map(pe=>{const ye=new Date(pe.ts).toISOString(),ie=pe.details?`
|
|
150
|
+
${pe.details}`:"";return`[${ye}] [${pe.level}] ${pe.message}${ie}`}).join(`
|
|
151
|
+
`);_n(`${re}${be}`).then(pe=>{pe.ok?H.success(n("contextPanel.preview.console.copied")):H.error(n("contextPanel.preview.console.copyFailed"))})},[w,$,t,n]),le=o.useCallback(()=>{const re=D??(E?"draft":null);if(!re){H.error(n("contextPanel.preview.console.attachNoSession"));return}const be=[`Preview URL: ${t||$||""}`,`Events: ${w.length}`,""].join(`
|
|
152
|
+
`),pe=w.map(ye=>{const ie=new Date(ye.ts).toISOString(),ue=ye.details?`
|
|
153
|
+
${ye.details}`:"";return`[${ie}] [${ye.level}] ${ye.message}${ue}`}).join(`
|
|
154
|
+
`);T({sessionKey:re,source:"preview-console",fileLabel:t||$||"preview",startLine:1,endLine:Math.max(1,w.length),code:`${be}${pe}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),H.success(n("contextPanel.preview.console.attached"))},[T,w,D,$,E,t,n]),[oe,F]=o.useState("unknown"),U=o.useRef(0),W=o.useRef(0),te=15e3;o.useEffect(()=>{if(!V){F("unknown"),U.current=0,W.current=0;return}let re=!1;return U.current||(U.current=Date.now(),W.current=0),F("unknown"),(async()=>{const pe=await(async()=>{try{return await fetch(V,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(re)return;if(!pe){F("unreachable");return}if(pe.status===403||pe.status===404){Ai.delete(R),p({status:"loading"}),c();return}if(pe.status!==502){F("reachable");return}const ye=U.current||Date.now();if(Date.now()-ye<te){F("starting"),W.current+=1;const ue=W.current,se=Math.min(2e3,250*Math.pow(2,Math.min(4,ue)));setTimeout(()=>{re||a()},se).unref?.();return}F("unreachable")})(),()=>{re=!0}},[V,i,R]);const K=M&&d.status==="ready"&&(oe==="unknown"||oe==="starting"),ae=M&&d.status==="ready"&&oe==="unreachable",ve=o.useCallback(re=>{if(!M||d.status!=="ready"||typeof window>"u")return;const be=re.currentTarget.contentWindow;if(be)try{const pe=be.location;if(pe.origin!==window.location.origin||pe.pathname.startsWith(d.proxyBasePath))return;const ye=`${d.proxyBasePath}${pe.pathname}${pe.search}${pe.hash}`;be.location.replace(ye)}catch{}},[M,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:_||t,children:_||t||n("contextPanel.preview.empty")}),s.jsx(ge,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>a(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!$,children:s.jsx(P,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(ge,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{B&&rr(B)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!B,children:s.jsx(P,{name:"external-link",className:"h-3.5 w-3.5"})}),M?s.jsx(ge,{type:"button",size:"sm",variant:k?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>I(re=>!re),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!h,children:s.jsx(P,{name:"cursor",className:"h-3.5 w-3.5"})}):null,M?s.jsxs(ge,{type:"button",size:"sm",variant:f?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(re=>!re),title:n(h?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(h?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!h&&w.length===0,children:[s.jsx(P,{name:"terminal-box",className:"h-3.5 w-3.5"}),Q>0?s.jsx("span",{className:"typography-micro text-status-error",children:Q}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[K?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):ae?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(ge,{type:"button",size:"sm",variant:"outline",onClick:()=>a(),children:n("contextPanel.preview.actions.retry")})]}):$&&(!M||oe==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:$,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:z},onLoad:ve,sandbox:M?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${$}:${i}`),k&&j?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:j.bounds.x,top:j.bounds.y,width:j.bounds.width,height:j.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[j.tag,j.text?` · ${j.text}`:""]})}):null]}):X?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):O?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),f?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:le,disabled:w.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:G,disabled:w.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:()=>b([]),disabled:w.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(re=>s.jsx(ge,{type:"button",size:"xs",variant:y===re?"secondary":"ghost",onClick:()=>g(re),children:n(re==="all"?"contextPanel.preview.console.filter.all":re==="errors"?"contextPanel.preview.console.filter.errors":re==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},re))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:w.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):ne.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ne.map(re=>s.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:ce("shrink-0 uppercase",re.level==="error"||re.level==="runtime"||re.level==="resource"?"text-status-error":re.level==="warn"?"text-status-warning":"text-muted-foreground"),children:re.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:re.message})]})},re.id))})]}):null]})]})},MS=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=ut(),i=o.useRef(null),a=Ie(E=>E.setContextPanelTabTargetPath),l=Pc(t),c=l!=="about:blank"?l:"",[d,p]=o.useState(c),[m,u]=o.useState(c),[h,x]=o.useState(!1),[f,v]=o.useState(!0),y=o.useRef(null),g=f,w=o.useCallback(E=>{!E||E==="about:blank"||!e||!n||a(e,n,E)},[e,n,a]),b=Ot(E=>E.currentSessionId),k=Ot(E=>E.newSessionDraft?.open),I=ia(E=>E.addDraft),j=zi(E=>E.addAttachedFile);o.useEffect(()=>{const E=i.current;if(!E)return;const T=()=>{try{const R=E.getURL();R&&R!=="about:blank"&&(u(R),p(R),w(R))}catch{}},C=R=>{const z=R.detail;typeof z?.url=="string"&&z.url&&(u(z.url),p(z.url),w(z.url))},S=()=>{y.current&&clearTimeout(y.current),y.current=setTimeout(()=>v(!0),200)},M=()=>{y.current&&clearTimeout(y.current),v(!1),T()},A=R=>{const z=R.detail;if(z?.disposition==="new-window"||z?.disposition==="foreground-tab"||z?.disposition==="background-tab"){R.preventDefault();const B=i.current;typeof B?.loadURL=="function"&&z.url&&B.loadURL(z.url)}};E.addEventListener("did-navigate",C),E.addEventListener("did-navigate-in-page",C),E.addEventListener("did-start-loading",S),E.addEventListener("did-stop-loading",M),E.addEventListener("new-window",A);try{E.isLoading()||(v(!1),T())}catch{}return()=>{y.current&&clearTimeout(y.current),E.removeEventListener("did-navigate",C),E.removeEventListener("did-navigate-in-page",C),E.removeEventListener("did-start-loading",S),E.removeEventListener("did-stop-loading",M),E.removeEventListener("new-window",A)}},[w]),o.useEffect(()=>{const E=setTimeout(()=>v(!1),3e4);return()=>clearTimeout(E)},[]),o.useEffect(()=>{if(!h)return;const E=T=>{if(T.key!=="Escape")return;T.preventDefault(),T.stopImmediatePropagation(),x(!1);const C=i.current;try{C?.executeJavaScript?.(Cc).catch(()=>{})}catch{}};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[h]),o.useEffect(()=>{const E=i.current;return()=>{try{const T=E?.getURL?.();T&&T!=="about:blank"&&a(e,n,T)}catch{}try{E?.executeJavaScript?.(Cc).catch(()=>{})}catch{}}},[e,n,a]);const N=o.useCallback(E=>{const T=i.current;if(typeof T?.loadURL!="function")return;const C=Pc(E);try{T.loadURL(C)}catch{}},[]),D=o.useCallback(()=>{const E=i.current;if(E){if(h){x(!1);try{E.executeJavaScript?.(Cc).catch(()=>{})}catch{}return}x(!0),E.executeJavaScript?.(kS,!0).then(async T=>{if(x(!1),!T||!xd(T))return;const C=b??(k?"draft":null);if(!C){H.error(r("contextPanel.preview.inspect.attachNoSession"));return}const S=typeof E.getWebContentsId=="function"?E.getWebContentsId():null;if(S==null)return;const M=await Lb("desktop_browser_capture_page",{webContentsId:S}),A=await E.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),R=Number.isFinite(A?.width)?A.width:M.width,z=Number.isFinite(A?.height)?A.height:M.height,B=await CS(M.base64,M.width,M.height,R,z,T),V=!!B;B&&await j(B),I({sessionKey:C,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:og({pageUrl:m,viewport:{width:R,height:z},devicePixelRatio:window.devicePixelRatio||1,target:T,screenshotAttached:V,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),H.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>x(!1))}},[j,I,b,m,h,k,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{i.current?.goBack?.()}catch{}},children:s.jsx(P,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{i.current?.goForward?.()}catch{}},children:s.jsx(P,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{i.current?.reload?.()}catch{}},children:s.jsx(P,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:E=>{E.preventDefault(),N(d)},children:s.jsx("input",{value:d,onChange:E=>p(E.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(ge,{type:"button",variant:h?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:D,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(P,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{rr(m)},children:s.jsx(P,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:i,src:Pc(t),partition:"persist:vinci-browser",style:{width:"100%",height:"100%",border:"none"}}),(!m||m==="about:blank")&&!f?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx($d,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,g?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},ES=()=>{const{t}=ut(),e=Ir()??"",n=o.useMemo(()=>bS(e),[e]),r=Ie(K=>n?K.contextPanelByDirectory[n]:void 0),i=Ie(K=>K.closeContextPanel),a=Ie(K=>K.closeContextPanelTab),l=Ie(K=>K.toggleContextPanelExpanded),c=Ie(K=>K.setContextPanelWidth),d=Ie(K=>K.setActiveContextPanelTab),p=Ie(K=>K.reorderContextPanelTabs),m=Ie(K=>K.setPendingDiffFile),u=Bn(K=>K.setSelectedPath),h=Ie(K=>K.openContextPreview),{themeMode:x,lightThemeId:f,darkThemeId:v,currentTheme:y}=Ar(),g=o.useMemo(()=>r?.tabs??[],[r?.tabs]),w=g.find(K=>K.id===r?.activeTabId)??g[g.length-1]??null,b=!!(r?.isOpen&&w),k=!!(b&&r?.expanded),I=np(r?.width??ag),[j,N]=o.useState(!1),D=o.useRef(0),E=o.useRef(I),T=o.useRef(null),C=o.useRef(null),S=o.useRef(null),M=o.useRef(new Map),A=o.useRef(!1);o.useEffect(()=>{if(!b||A.current){A.current=b;return}const K=window.requestAnimationFrame(()=>{S.current?.focus({preventScroll:!0})});return A.current=!0,()=>window.cancelAnimationFrame(K)},[b]);const R=o.useCallback(K=>{const ae=S.current;ae&&ae.style.setProperty("--oc-context-panel-width",`${K}px`)},[]),z=o.useCallback(K=>{if(!(!b||k||!n)){try{K.currentTarget.setPointerCapture(K.pointerId)}catch{}C.current=K.pointerId,N(!0),D.current=K.clientX,E.current=I,T.current=I,R(I),K.preventDefault()}},[R,n,k,b,I]),B=o.useCallback(K=>{if(!j||C.current!==K.pointerId)return;const ae=D.current-K.clientX,ve=np(E.current+ae);T.current!==ve&&(T.current=ve,R(ve))},[R,j]),V=o.useCallback(K=>{if(C.current!==K.pointerId||!n)return;try{K.currentTarget.releasePointerCapture(K.pointerId)}catch{}const ae=T.current??I;N(!1),C.current=null,T.current=null,c(n,ae)},[n,c,I]);o.useEffect(()=>{j||(T.current=null)},[j]);const $=o.useCallback(()=>{n&&i(n)},[i,n]),_=o.useCallback(()=>{n&&l(n)},[n,l]),X=o.useCallback(K=>{K.key==="Escape"&&(K.preventDefault(),K.stopPropagation(),$())},[$]);o.useEffect(()=>{if(!(!n||!w)){if(w.mode==="file"&&w.targetPath){u(n,w.targetPath);return}w.mode==="diff"&&w.targetPath&&m(w.targetPath)}},[w,n,m,u]);const O=w?.mode==="chat"?w.id:null,J=o.useCallback(()=>{if(typeof window>"u")return;const K={themeMode:x,lightThemeId:f,darkThemeId:v,currentTheme:y};for(const ae of M.current.values()){const ve=ae.contentWindow;if(!ve)continue;const re=ve.__vinciApplyThemeSync;if(typeof re=="function")try{re(K);continue}catch{}ve.postMessage({type:"vinci:theme-sync",payload:K},window.location.origin)}},[y,v,f,x]),Q=o.useCallback(()=>{if(!(typeof window>"u"))for(const[K,ae]of M.current.entries()){const ve=ae.contentWindow;if(!ve)continue;const re={visible:O===K},be=ve.__vinciSetEmbeddedVisibility;if(typeof be=="function")try{be(re);continue}catch{}ve.postMessage({type:"vinci:embedded-visibility",payload:re},window.location.origin)}},[O]);o.useLayoutEffect(()=>{g.some(ae=>ae.mode==="chat")&&(J(),Q())},[v,f,Q,J,g,x]);const ne=o.useMemo(()=>g.map(K=>{const ae=jS(K,t),ve=IS(ae,hS),re=yS(K.targetPath,e);return{id:K.id,label:ve,icon:NS(K),title:re?`${ae}: ${re}`:ae,closeLabel:t("contextPanel.tab.closeTabAria",{label:ve})}}),[e,t,g]),G=w?.mode==="diff"?s.jsx(Zh,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0}):w?.mode==="context"?s.jsx(nS,{}):w?.mode==="plan"?s.jsx(ig,{targetPath:w.targetPath}):w?.mode==="preview"?s.jsx(TS,{rawUrl:w.targetPath??"",onNavigate:K=>h(e,K)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(P,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),le=o.useMemo(()=>g.filter(K=>K.mode==="chat"),[g]),oe=o.useMemo(()=>g.filter(K=>K.mode==="browser"),[g]),F=o.useMemo(()=>g.some(K=>K.mode==="file"),[g]),U=w?.mode==="file",W=s.jsxs("header",{className:"flex h-8 items-stretch border-b border-transparent",children:[s.jsx(Cr,{items:ne,activeId:w?.id??null,onSelect:K=>{n&&d(n,K)},onClose:K=>{n&&a(n,K)},onReorder:(K,ae)=>{n&&p(n,K,ae)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:_,className:"h-7 w-7 p-0",title:t(k?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(k?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:k?s.jsx(P,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:$,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]})]});if(!b)return null;const te=k?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"var(--oc-context-panel-width)",minWidth:"var(--oc-context-panel-width)",maxWidth:"var(--oc-context-panel-width)","--oc-context-panel-width":`${j?T.current??I:I}px`};return s.jsxs("aside",{ref:S,"data-context-panel":"true",tabIndex:-1,className:ce("flex min-h-0 flex-col overflow-hidden bg-background",!k&&"border-l border-border/40",k?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",j?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:X,style:te,children:[!k&&s.jsx("div",{className:ce("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",j&&"bg-[var(--interactive-border)]"),onPointerDown:z,onPointerMove:B,onPointerUp:V,onPointerCancel:V,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),W,s.jsxs("div",{className:ce("relative min-h-0 flex-1 overflow-hidden",j&&"pointer-events-none"),children:[F?s.jsx("div",{className:ce("absolute inset-0",U?"block":"hidden"),children:s.jsx(rg,{mode:"editor-only"})}):null,le.map(K=>{const ae=SS(K.dedupeKey);if(!ae)return null;const ve=PS(ae,n||null,K.readOnly);return ve?s.jsx("iframe",{ref:re=>{if(!re){M.current.delete(K.id);return}M.current.set(K.id,re)},src:ve,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ae}),className:ce("absolute inset-0 h-full w-full border-0 bg-background",O===K.id?"block":"hidden"),onLoad:()=>{J(),Q()}},K.id):null}),oe.map(K=>s.jsx("div",{className:ce("absolute inset-0",w?.mode!=="browser"&&"hidden"),children:s.jsx(MS,{initialUrl:K.targetPath??"",directory:n,tabID:K.id})},K.id)),w?.mode!=="chat"&&!U&&w?.mode!=="browser"?G:null]})]})},Xd=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"split",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:t=>t.isDesktop&&!t.isWeb&&!t.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"usage",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"skills.installed",title:"Skills",group:"skills",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"skills",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"git",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:t=>!t.isVSCode},{slug:"appearance",title:"Appearance",group:"appearance",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:t=>!t.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"general",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:t=>!t.isVSCode},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"voice",title:"Voice",group:"advanced",kind:"single",keywords:["tts","speech","voice"],isAvailable:t=>!t.isVSCode},{slug:"tunnel",title:"Remote Tunnel",group:"advanced",kind:"single",keywords:["tunnel","cloudflare","qr","remote","mobile","share"],isAvailable:t=>!t.isVSCode}],RS={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function _a(t){const e=t.trim().toLowerCase();return Xd.find(n=>n.slug===e)??null}function lg(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=RS[e];if(n)return n;const r=_a(e);return r?r.slug:"home"}const cg=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),vo=t=>{const e=at.c(39),{className:n}=t,{t:r}=ut(),i=As(FS),a=As(LS),l=As(OS),c=mn();let d;e[0]!==i?(d=[...i].sort($S),e[0]=i,e[1]=d):d=e[1];const p=d;let m;e:{if(p.length===0){m=null;break e}let A;e[2]!==a||e[3]!==p?(A=p.find(R=>R.id===a)??p[0],e[2]=a,e[3]=p,e[4]=A):A=e[4],m=A}const u=m;if(c||p.length===0)return null;let h;e[5]!==u||e[6]!==r?(h=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||r("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=r,e[7]=h):h=e[7];const x=h;let f;e[8]!==x?(f=cg(x),e[8]=x,e[9]=f):f=e[9];const v=f;let y;e[10]!==n?(y=ce(n),e[10]=n,e[11]=y):y=e[11];let g;e[12]!==r?(g=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=g):g=e[13];let w;e[14]!==r?(w=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=w):w=e[15];let b,k;e[16]===Symbol.for("react.memo_cache_sentinel")?(b=ce("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),k=s.jsx(P,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=b,e[17]=k):(b=e[16],k=e[17]);let I;e[18]!==v?(I=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:v}),e[18]=v,e[19]=I):I=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(P,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let N;e[21]!==I||e[22]!==g||e[23]!==w?(N=s.jsx(Es,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":g,title:w,className:b,children:[k,I,j]})}),e[21]=I,e[22]=g,e[23]=w,e[24]=N):N=e[24];const D=u?.id??"";let E;e[25]!==l?(E=A=>{A&&l(A)},e[25]=l,e[26]=E):E=e[26];let T;e[27]!==p?(T=p.map(BS),e[27]=p,e[28]=T):T=e[28];let C;e[29]!==D||e[30]!==E||e[31]!==T?(C=s.jsx(Rs,{align:"start",className:"w-auto",children:s.jsx(pl,{value:D,onValueChange:E,children:T})}),e[29]=D,e[30]=E,e[31]=T,e[32]=C):C=e[32];let S;e[33]!==N||e[34]!==C?(S=s.jsxs(Fs,{children:[N,C]}),e[33]=N,e[34]=C,e[35]=S):S=e[35];let M;return e[36]!==S||e[37]!==y?(M=s.jsx("div",{className:y,children:S}),e[36]=S,e[37]=y,e[38]=M):M=e[38],M};function FS(t){return t.projects}function LS(t){return t.activeProjectId}function OS(t){return t.setActiveProject}function $S(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function BS(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=cg(e);return s.jsx(fl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function zS(t,e){return`opencode:sidebar-group:${t}:${e}`}const bd=t=>{const e=at.c(33),{label:n,count:r,storageKey:i,defaultExpanded:a,children:l}=t,c=a===void 0?!0:a;let d;e[0]!==n||e[1]!==i?(d=zS(i,n),e[0]=n,e[1]=i,e[2]=d):d=e[2];const p=d,m=o.useId();let u;e[3]!==c||e[4]!==p?(u=()=>{try{const C=localStorage.getItem(p);if(C!==null)return C==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=u):u=e[5];const[h,x]=Be.useState(u);let f,v;e[6]!==h||e[7]!==p?(f=()=>{try{localStorage.setItem(p,String(h))}catch{}},v=[p,h],e[6]=h,e[7]=p,e[8]=f,e[9]=v):(f=e[8],v=e[9]),Be.useEffect(f,v);let y;e[10]===Symbol.for("react.memo_cache_sentinel")?(y=()=>x(VS),e[10]=y):y=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=ce("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=g):g=e[11];const w=!h&&"-rotate-90";let b;e[12]!==w?(b=ce("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",w),e[12]=w,e[13]=b):b=e[13];let k;e[14]!==b?(k=s.jsx(P,{name:"arrow-down-s",className:b}),e[14]=b,e[15]=k):k=e[15];let I;e[16]!==n?(I=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=I):I=e[17];let j;e[18]!==r?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:r}),e[18]=r,e[19]=j):j=e[19];let N;e[20]!==m||e[21]!==h||e[22]!==k||e[23]!==I||e[24]!==j?(N=s.jsxs("button",{type:"button",onClick:y,"aria-expanded":h,"aria-controls":m,className:g,children:[k,I,j]}),e[20]=m,e[21]=h,e[22]=k,e[23]=I,e[24]=j,e[25]=N):N=e[25];const D=!h;let E;e[26]!==l||e[27]!==m||e[28]!==D?(E=s.jsx("div",{id:m,hidden:D,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=m,e[28]=D,e[29]=E):E=e[29];let T;return e[30]!==N||e[31]!==E?(T=s.jsxs("div",{children:[N,E]}),e[30]=N,e[31]=E,e[32]=T):T=e[32],T};function VS(t){return!t}const _S=t=>{if(!Array.isArray(t))return[];const e=[];for(const n of t){if(!n||typeof n!="object")continue;const r=n;typeof r.permission!="string"||typeof r.pattern!="string"||typeof r.action!="string"||r.action!=="allow"&&r.action!=="ask"&&r.action!=="deny"||e.push({permission:r.permission,pattern:r.pattern,action:r.action})}return e},US=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},rp=t=>{const e=US(_S(t));if(e.length===0)return;const n={};for(const i of e)i.permission&&((n[i.permission]||={})[i.pattern]=i.action);const r={};for(const[i,a]of Object.entries(n)){const l=Object.keys(a);if(l.length===1&&l[0]==="*"){r[i]=a["*"];continue}r[i]=a}return Object.keys(r).length>0?r:void 0},WS=({onItemSelect:t})=>{const{t:e}=ut(),[n,r]=o.useState(null),[i,a]=o.useState(""),[l,c]=o.useState(null),[d,p]=o.useState(null),[m,u]=o.useState(!1),[h,x]=o.useState(null),{selectedAgentName:f,agents:v,setSelectedAgent:y,setAgentDraft:g,createAgent:w,deleteAgent:b,loadAgents:k}=fa(Br(_=>({selectedAgentName:_.selectedAgentName,agents:_.agents,setSelectedAgent:_.setSelectedAgent,setAgentDraft:_.setAgentDraft,createAgent:_.createAgent,deleteAgent:_.deleteAgent,loadAgents:_.loadAgents})));o.useEffect(()=>{k()},[k]);const I="bg-background",j=()=>{const _="new-agent";let X=_,O=1;for(;v.some(J=>J.name===X);)X=`${_}-${O}`,O++;g({name:X,scope:"user"}),y(X),t?.()},N=async _=>{if(aa(_)){H.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(_),p("delete")},D=async _=>{aa(_)&&(c(_),p("reset"))},E=()=>{c(null),p(null)},T=async()=>{if(!l||!d)return;u(!0),await b(l.name)?(d==="delete"?H.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):H.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),E()):d==="delete"?H.error(e("settings.agents.sidebar.toast.deleteFailed")):H.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},C=_=>{const X=_.name;let O=1,J=`${X}-copy`;for(;v.some(le=>le.name===J);)O++,J=`${X}-copy-${O}`;const Q=_,ne=_.model?.providerID&&_.model?.modelID?`${_.model.providerID}/${_.model.modelID}`:null,G=_;g({name:J,scope:Q.scope||"user",description:_.description,model:ne,temperature:_.temperature,top_p:_.topP,prompt:_.prompt,mode:_.mode,permission:rp(_.permission),disable:G.disable}),y(J)},S=_=>{a(_.name),r(_)},M=async()=>{if(!n)return;const _=i.trim().replace(/\s+/g,"-");if(!_){H.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(_===n.name){r(null);return}if(v.some(Q=>Q.name===_)){H.error(e("settings.agents.sidebar.toast.agentExists"));return}const X=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,O=n;await w({name:_,description:n.description,model:X,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:rp(n.permission),disable:O.disable,scope:O.scope})?await b(n.name)?(H.success(`Agent renamed to "${_}"`),y(_)):H.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):H.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},A=_=>{switch(_){case"primary":return s.jsx(P,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(P,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(P,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},R=v.filter(_=>!Ob(_)),z=R.filter(aa),B=R.filter(_=>!aa(_)),{groupedCustomAgents:V,ungroupedCustomAgents:$}=Be.useMemo(()=>{const _={},X=[];for(const J of B){const Q=J;Q.group?(_[Q.group]||(_[Q.group]=[]),_[Q.group].push(J)):X.push(J)}return{groupedCustomAgents:Object.keys(_).sort((J,Q)=>J.localeCompare(Q)).map(J=>({name:J,agents:_[J]})),ungroupedCustomAgents:X}},[B]);return s.jsxs("div",{className:ce("flex h-full flex-col",I),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),s.jsx(vo,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:R.length})}),s.jsx(ge,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:s.jsx(P,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:R.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(P,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[z.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),z.map(_=>s.jsx(Ic,{agent:_,isSelected:f===_.name,onSelect:()=>{y(_.name),t?.()},onReset:()=>D(_),onDuplicate:()=>C(_),getAgentModeIcon:A,isMenuOpen:h===_.name,onMenuOpenChange:X=>x(X?_.name:null)},_.name))]}),B.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),V.map(({name:_,agents:X})=>s.jsx(bd,{label:_,count:X.length,storageKey:"agents",children:X.map(O=>s.jsx(Ic,{agent:O,isSelected:f===O.name,onSelect:()=>{y(O.name),t?.()},onRename:()=>S(O),onDelete:()=>N(O),onDuplicate:()=>C(O),getAgentModeIcon:A,isMenuOpen:h===O.name,onMenuOpenChange:J=>x(J?O.name:null)},O.name))},_)),$.map(_=>s.jsx(Ic,{agent:_,isSelected:f===_.name,onSelect:()=>{y(_.name),t?.()},onRename:()=>S(_),onDelete:()=>N(_),onDuplicate:()=>C(_),getAgentModeIcon:A,isMenuOpen:h===_.name,onMenuOpenChange:X=>x(X?_.name:null)},_.name))]})]})}),s.jsx(hs,{open:l!==null&&d!==null,onOpenChange:_=>{!_&&!m&&E()},children:s.jsxs(fs,{className:"max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Is,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(Vs,{children:[s.jsx(ge,{size:"sm",variant:"ghost",onClick:E,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(ge,{size:"sm",onClick:T,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(hs,{open:n!==null,onOpenChange:_=>!_&&r(null),children:s.jsxs(fs,{children:[s.jsxs(bs,{children:[s.jsx(gs,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Is,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Bt,{value:i,onChange:_=>a(_.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:_=>{_.key==="Enter"&&M()}}),s.jsxs(Vs,{children:[s.jsx(ge,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(ge,{size:"sm",onClick:M,children:e("settings.common.actions.rename")})]})]})})]})},Ic=t=>{const e=at.c(58),{agent:n,isSelected:r,onSelect:i,onDelete:a,onReset:l,onRename:c,onDuplicate:d,getAgentModeIcon:p,isMenuOpen:m,onMenuOpenChange:u}=t,{t:h}=ut(),x=n;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=no(),e[0]=f):f=e[0];const v=f,y=r?"bg-interactive-selection":"hover:bg-interactive-hover";let g;e[1]!==y?(g=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",y),e[1]=y,e[2]=g):g=e[2];let w;e[3]!==u?(w=v?void 0:X=>{X.preventDefault(),u(!0)},e[3]=u,e[4]=w):w=e[4];let b;e[5]!==n.name?(b=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=b):b=e[6];let k;e[7]!==n.mode||e[8]!==p?(k=p(n.mode),e[7]=n.mode,e[8]=p,e[9]=k):k=e[9];let I;e[10]!==n||e[11]!==x.scope||e[12]!==h?(I=(x.scope||aa(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:aa(n)?h("settings.agents.sidebar.badge.system"):x.scope}),e[10]=n,e[11]=x.scope,e[12]=h,e[13]=I):I=e[13];let j;e[14]!==b||e[15]!==k||e[16]!==I?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[b,k,I]}),e[14]=b,e[15]=k,e[16]=I,e[17]=j):j=e[17];let N;e[18]!==n.description?(N=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=N):N=e[19];let D;e[20]!==i||e[21]!==j||e[22]!==N?(D=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[j,N]}),e[20]=i,e[21]=j,e[22]=N,e[23]=D):D=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Es,{asChild:!0,children:s.jsx(ge,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(P,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=E):E=e[24];let T;e[25]!==c||e[26]!==h?(T=c&&s.jsxs($t,{onClick:X=>{X.stopPropagation(),c()},children:[s.jsx(P,{name:"edit",className:"h-4 w-4 mr-px"}),h("settings.common.actions.rename")]}),e[25]=c,e[26]=h,e[27]=T):T=e[27];let C;e[28]!==d?(C=X=>{X.stopPropagation(),d()},e[28]=d,e[29]=C):C=e[29];let S;e[30]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(P,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=S):S=e[30];let M;e[31]!==h?(M=h("settings.common.actions.duplicate"),e[31]=h,e[32]=M):M=e[32];let A;e[33]!==C||e[34]!==M?(A=s.jsxs($t,{onClick:C,children:[S,M]}),e[33]=C,e[34]=M,e[35]=A):A=e[35];let R;e[36]!==l||e[37]!==h?(R=l&&s.jsxs($t,{onClick:X=>{X.stopPropagation(),l()},children:[s.jsx(P,{name:"restart",className:"h-4 w-4 mr-px"}),h("settings.common.actions.reset")]}),e[36]=l,e[37]=h,e[38]=R):R=e[38];let z;e[39]!==a||e[40]!==h?(z=a&&s.jsxs($t,{onClick:X=>{X.stopPropagation(),a()},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"delete-bin",className:"h-4 w-4 mr-px"}),h("settings.common.actions.delete")]}),e[39]=a,e[40]=h,e[41]=z):z=e[41];let B;e[42]!==T||e[43]!==A||e[44]!==R||e[45]!==z?(B=s.jsxs(Rs,{align:"end",className:"w-fit min-w-20",children:[T,A,R,z]}),e[42]=T,e[43]=A,e[44]=R,e[45]=z,e[46]=B):B=e[46];let V;e[47]!==m||e[48]!==u||e[49]!==B?(V=s.jsxs(Fs,{open:m,onOpenChange:u,children:[E,B]}),e[47]=m,e[48]=u,e[49]=B,e[50]=V):V=e[50];let $;e[51]!==D||e[52]!==V?($=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[D,V]}),e[51]=D,e[52]=V,e[53]=$):$=e[53];let _;return e[54]!==$||e[55]!==g||e[56]!==w?(_=s.jsx("div",{className:g,onContextMenu:w,children:$}),e[54]=$,e[55]=g,e[56]=w,e[57]=_):_=e[57],_};function ip(t,e,n){return Math.min(n,Math.max(e,t))}function KS(t){if(!Number.isFinite(t))return 0;const e=String(t);if(e.includes("e-")){const[,r]=e.split("e-");return Number(r)||0}const n=e.split(".");return n.length===2?n[1].length:0}function ap(t,e){const n=KS(e);return n<=0?t:Number(t.toFixed(n))}const Vn=Be.forwardRef((t,e)=>{const n=at.c(125);let r,i,a,l,c,d,p,m,u,h,x,f,v;n[0]!==t?({value:v,onValueChange:p,min:u,max:h,step:x,className:r,containerClassName:i,onBlur:c,disabled:a,fallbackValue:l,onClear:d,emptyLabel:f,...m}=t,n[0]=t,n[1]=r,n[2]=i,n[3]=a,n[4]=l,n[5]=c,n[6]=d,n[7]=p,n[8]=m,n[9]=u,n[10]=h,n[11]=x,n[12]=f,n[13]=v):(r=n[1],i=n[2],a=n[3],l=n[4],c=n[5],d=n[6],p=n[7],m=n[8],u=n[9],h=n[10],x=n[11],f=n[12],v=n[13]);const y=u===void 0?-1/0:u,g=h===void 0?1/0:h,w=x===void 0?1:x,b=f===void 0?"—":f,{t:k}=ut();let I;n[14]!==v?(I=()=>v===void 0?"":String(v),n[14]=v,n[15]=I):I=n[15];const[j,N]=Be.useState(I),{isMobile:D}=rn(),E=Be.useRef(!1),T=Be.useRef(null);let C;n[16]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{if(typeof document>"u"||typeof window>"u")return;T.current?.();const ke=Me=>{Me.preventDefault(),Me.stopPropagation(),Me.stopImmediatePropagation?.(),T.current?.()},xe=window.setTimeout(()=>{T.current?.()},700),me=()=>{window.clearTimeout(xe),document.removeEventListener("click",ke,!0),T.current=null};T.current=me,document.addEventListener("click",ke,!0)},n[16]=C):C=n[16];const S=C;let M,A;n[17]===Symbol.for("react.memo_cache_sentinel")?(M=()=>()=>{T.current?.()},A=[],n[17]=M,n[18]=A):(M=n[17],A=n[18]),Be.useEffect(M,A);let R,z;n[19]!==v?(z=()=>{N(v===void 0?"":String(v))},R=[v],n[19]=v,n[20]=R,n[21]=z):(R=n[20],z=n[21]),Be.useEffect(z,R);let B;e:{if(v!==void 0){B=v;break e}if(l!==void 0){B=l;break e}if(Number.isFinite(y)){B=y;break e}B=0}const V=B;let $;n[22]!==g||n[23]!==y||n[24]!==p||n[25]!==w?($=ke=>{const xe=ip(ke,y,g);p(ap(xe,w))},n[22]=g,n[23]=y,n[24]=p,n[25]=w,n[26]=$):$=n[26];const _=$;let X;n[27]!==_||n[28]!==d?(X=ke=>{const xe=ke.target.value;if(N(xe),xe.trim()===""){d?.();return}const me=Number(xe);Number.isFinite(me)&&_(me)},n[27]=_,n[28]=d,n[29]=X):X=n[29];const O=X;let J;n[30]!==j||n[31]!==g||n[32]!==y||n[33]!==c||n[34]!==d||n[35]!==p||n[36]!==w||n[37]!==v?(J=ke=>{if(j.trim()===""){d||N(v===void 0?"":String(v)),c?.(ke);return}const xe=Number(j);if(!Number.isFinite(xe))N(v===void 0?"":String(v));else{const me=ip(xe,y,g),Me=ap(me,w);Me!==v&&p(Me),N(String(Me))}c?.(ke)},n[30]=j,n[31]=g,n[32]=y,n[33]=c,n[34]=d,n[35]=p,n[36]=w,n[37]=v,n[38]=J):J=n[38];const Q=J,ne=!!(a||V>=g),G=!!(a||V<=y);let le;n[39]!==V||n[40]!==_||n[41]!==G||n[42]!==w?(le=()=>{G||_(V-w)},n[39]=V,n[40]=_,n[41]=G,n[42]=w,n[43]=le):le=n[43];const oe=le;let F;n[44]!==V||n[45]!==_||n[46]!==ne||n[47]!==w?(F=()=>{ne||_(V+w)},n[44]=V,n[45]=_,n[46]=ne,n[47]=w,n[48]=F):F=n[48];const U=F;let W;if(n[49]!==r||n[50]!==i||n[51]!==G||n[52]!==j||n[53]!==b||n[54]!==oe||n[55]!==U||n[56]!==ne||n[57]!==D||n[58]!==k||n[59]!==v){W=Symbol.for("react.early_return_sentinel");e:{const ke=me=>Me=>{Me.preventDefault(),Me.stopPropagation(),E.current=!0,S(),me()},xe=me=>Me=>{if(E.current){E.current=!1,Me.preventDefault(),Me.stopPropagation();return}me()};if(D){let me;n[61]!==i?(me=ce("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",i),n[61]=i,n[62]=me):me=n[62];let Me;n[63]!==k?(Me=k("numberInput.actions.decreaseAria"),n[63]=k,n[64]=Me):Me=n[64];const Ue=ke(oe),q=xe(oe),Se=!G&&"active:bg-interactive-hover";let $e;n[65]!==Se?($e=ce("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",Se),n[65]=Se,n[66]=$e):$e=n[66];let Pe;n[67]===Symbol.for("react.memo_cache_sentinel")?(Pe=s.jsx(P,{name:"subtract",className:"block h-4 w-4"}),n[67]=Pe):Pe=n[67];const fe=s.jsx("button",{type:"button","aria-label":Me,disabled:G,onTouchStart:Ue,onClick:q,className:$e,children:Pe});let L;n[68]!==r?(L=ce("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",r),n[68]=r,n[69]=L):L=n[69];const Z=v===void 0?b:j;let Y;n[70]!==L||n[71]!==Z?(Y=s.jsx("div",{className:L,"aria-live":"polite",children:Z}),n[70]=L,n[71]=Z,n[72]=Y):Y=n[72];let Ee;n[73]!==k?(Ee=k("numberInput.actions.increaseAria"),n[73]=k,n[74]=Ee):Ee=n[74];const Ae=ke(U),Je=xe(U),de=!ne&&"active:bg-interactive-hover";let ze;n[75]!==de?(ze=ce("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",de),n[75]=de,n[76]=ze):ze=n[76];let rt;n[77]===Symbol.for("react.memo_cache_sentinel")?(rt=s.jsx(P,{name:"add",className:"block h-4 w-4"}),n[77]=rt):rt=n[77];const Re=s.jsx("button",{type:"button","aria-label":Ee,disabled:ne,onTouchStart:Ae,onClick:Je,className:ze,children:rt});let Xe;n[78]!==me||n[79]!==fe||n[80]!==Y||n[81]!==Re?(Xe=s.jsxs("div",{className:me,children:[fe,Y,Re]}),n[78]=me,n[79]=fe,n[80]=Y,n[81]=Re,n[82]=Xe):Xe=n[82],W=Xe;break e}}n[49]=r,n[50]=i,n[51]=G,n[52]=j,n[53]=b,n[54]=oe,n[55]=U,n[56]=ne,n[57]=D,n[58]=k,n[59]=v,n[60]=W}else W=n[60];if(W!==Symbol.for("react.early_return_sentinel"))return W;let te;n[83]!==i?(te=ce("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",i),n[83]=i,n[84]=te):te=n[84];let K;n[85]!==k?(K=k("numberInput.actions.decreaseAria"),n[85]=k,n[86]=K):K=n[86];let ae;n[87]!==V||n[88]!==_||n[89]!==w?(ae=()=>_(V-w),n[87]=V,n[88]=_,n[89]=w,n[90]=ae):ae=n[90];let ve,re;n[91]===Symbol.for("react.memo_cache_sentinel")?(ve=ce("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),re=s.jsx(P,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=ve,n[92]=re):(ve=n[91],re=n[92]);let be;n[93]!==G||n[94]!==K||n[95]!==ae?(be=s.jsx("button",{type:"button","aria-label":K,disabled:G,onClick:ae,className:ve,children:re}),n[93]=G,n[94]=K,n[95]=ae,n[96]=be):be=n[96];const pe=m.inputMode??"numeric";let ye;n[97]!==r?(ye=ce("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",r),n[97]=r,n[98]=ye):ye=n[98];let ie;n[99]!==a||n[100]!==j||n[101]!==Q||n[102]!==O||n[103]!==m||n[104]!==e||n[105]!==pe||n[106]!==ye?(ie=s.jsx("input",{...m,ref:e,type:"text",inputMode:pe,value:j,onChange:O,onBlur:Q,disabled:a,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ye}),n[99]=a,n[100]=j,n[101]=Q,n[102]=O,n[103]=m,n[104]=e,n[105]=pe,n[106]=ye,n[107]=ie):ie=n[107];let ue;n[108]!==k?(ue=k("numberInput.actions.increaseAria"),n[108]=k,n[109]=ue):ue=n[109];let se;n[110]!==V||n[111]!==_||n[112]!==w?(se=()=>_(V+w),n[110]=V,n[111]=_,n[112]=w,n[113]=se):se=n[113];let Ne,Ce;n[114]===Symbol.for("react.memo_cache_sentinel")?(Ne=ce("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Ce=s.jsx(P,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=Ne,n[115]=Ce):(Ne=n[114],Ce=n[115]);let je;n[116]!==ne||n[117]!==ue||n[118]!==se?(je=s.jsx("button",{type:"button","aria-label":ue,disabled:ne,onClick:se,className:Ne,children:Ce}),n[116]=ne,n[117]=ue,n[118]=se,n[119]=je):je=n[119];let we;return n[120]!==te||n[121]!==be||n[122]!==ie||n[123]!==je?(we=s.jsxs("div",{className:te,children:[be,ie,je]}),n[120]=te,n[121]=be,n[122]=ie,n[123]=je,n[124]=we):we=n[124],we});Vn.displayName="NumberInput";const op=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],rl=t=>t==="allow"||t==="ask"||t==="deny",Di=(t,e)=>`${t}::${e}`,Ki=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&rl(n.action)&&e.set(Di(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},Oo=t=>{const e=new Map;for(const n of Ki(t))e.set(Di(n.permission,n.pattern),n);return e},lp=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),HS=(t,e)=>{const n=lp(Ki(t)),r=lp(Ki(e));return n.length!==r.length?!1:n.every((i,a)=>{const l=r[a];return i.permission===l.permission&&i.pattern===l.pattern&&i.action===l.action})},GS=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",qS=(t,e)=>Ki(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),YS=t=>{if(rl(t))return[{permission:"*",pattern:"*",action:t}];if(!t||typeof t!="object"||Array.isArray(t))return[];const e=[];for(const[n,r]of Object.entries(t))if(n!=="__originalKeys"){if(rl(r)){e.push({permission:n,pattern:"*",action:r});continue}if(r&&typeof r=="object"&&!Array.isArray(r))for(const[i,a]of Object.entries(r))rl(a)&&e.push({permission:n,pattern:i,action:a})}return e},QS=(t,e)=>{const n=Ki(e),r={};for(const a of n)(r[a.permission]||={})[a.pattern]=a.action;const i={"*":t};for(const[a,l]of Object.entries(r))if(a!=="*"){if(Object.keys(l).length===1&&l["*"]){i[a]=l["*"];continue}i[a]=l}return i},JS=()=>{const{t}=ut(),{isMobile:e}=rn(),{selectedAgentName:n,getAgentByName:r,createAgent:i,updateAgent:a,agents:l,agentDraft:c,setAgentDraft:d}=fa(Br(me=>({selectedAgentName:me.selectedAgentName,getAgentByName:me.getAgentByName,createAgent:me.createAgent,updateAgent:me.updateAgent,agents:me.agents,agentDraft:me.agentDraft,setAgentDraft:me.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,h]=o.useState(""),[x,f]=o.useState("user"),[v,y]=o.useState(""),[g,w]=o.useState("subagent"),[b,k]=o.useState(""),[I,j]=o.useState(void 0),[N,D]=o.useState(void 0),[E,T]=o.useState(""),[C,S]=o.useState("allow"),[M,A]=o.useState([]),[R,z]=o.useState([]),[B,V]=o.useState(""),[$,_]=o.useState("*"),[X,O]=o.useState(!1),[J,Q]=o.useState(!1),ne=o.useRef(null),G=$s(me=>me.currentDirectory??null),[le,oe]=o.useState([]),F=th(me=>me.permission);o.useEffect(()=>{let me=!1;return(async()=>{const Ue=await Zs.listToolIds({directory:G});if(me)return;const q=new Set(["write","patch","multiedit"]),Se=Ue.map($e=>typeof $e=="string"?$e.trim():"").filter(Boolean).filter($e=>$e!=="*").filter($e=>$e!=="invalid").filter($e=>!q.has($e));oe(Array.from(new Set(Se)).sort(($e,Pe)=>$e.localeCompare(Pe)))})(),()=>{me=!0}},[G]);const U=o.useMemo(()=>{const me=new Set;for(const Me of l){const Ue=Ki(Array.isArray(Me.permission)?Me.permission:[]);for(const q of Ue)q.permission&&q.permission!=="*"&&q.permission!=="invalid"&&me.add(q.permission)}for(const Me of Object.values(F))for(const Ue of Me){const q=Ue.permission?.trim();q&&q!=="invalid"&&me.add(q)}for(const Me of le)me.add(Me);return Array.from(me).sort((Me,Ue)=>Me.localeCompare(Ue))},[l,F,le]),W=o.useMemo(()=>Oo(M),[M]),te=o.useMemo(()=>Oo(R),[R]),K=o.useCallback(me=>te.get(Di(me,"*"))?.action,[te]),ae=o.useCallback(me=>R.filter(Me=>Me.permission===me&&Me.pattern!=="*").sort((Me,Ue)=>Me.pattern.localeCompare(Ue.pattern)),[R]),ve=o.useMemo(()=>{const me=new Set;for(const Me of op)me.add(Me);for(const Me of U)me.add(Me);return Array.from(me).sort((Me,Ue)=>Me.localeCompare(Ue))},[U]),re=o.useCallback(me=>{const Me=me==="*"?C:K(me)??C,Ue=ae(me),q=!1,Se=Ue.reduce((Pe,fe)=>(Pe[fe.action]=(Pe[fe.action]??0)+1,Pe),{allow:0,ask:0,deny:0}),$e=["allow","ask","deny"].filter(Pe=>Se[Pe]>0).map(Pe=>`${Se[Pe]} ${Pe}`).join(", ");return{defaultAction:Me,patternRulesCount:Ue.length,patternSummary:$e,hasDefaultHint:q}},[ae,K,C]),be=o.useCallback(me=>t(me==="allow"?"settings.common.permission.allow":me==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),pe=o.useCallback(me=>me==="global"?t("settings.common.scope.global"):be(me),[be,t]),ye=o.useMemo(()=>{const me=new Set;for(const Me of op)me.add(Me);for(const Me of U)me.add(Me);return Array.from(me).sort((Me,Ue)=>Me.localeCompare(Ue))},[U]),ie=o.useCallback((me,Me,Ue)=>{z(q=>{const Se=Oo(q);return Se.set(Di(me,Me),{permission:me,pattern:Me,action:Ue}),Array.from(Se.values())})},[]),ue=o.useCallback((me,Me)=>{z(Ue=>{const q=Oo(Ue);return q.delete(Di(me,Me)),Array.from(q.values())})},[]),se=o.useCallback((me,Me)=>{const Ue=W.get(Di(me,Me));if(Ue){ie(me,Me,Ue.action);return}ue(me,Me)},[W,ue,ie]),Ne=o.useCallback((me,Me,Ue)=>{ie(me,Me,Ue)},[ie]),Ce=o.useCallback(me=>{S(me),z(Me=>Me.filter(Ue=>!(Ue.pattern==="*"&&Ue.action===me)))},[]),je=o.useCallback(me=>{const Me=B.trim();if(!Me){H.error(t("settings.agents.page.toast.permissionNameRequired"));return}const Ue=$.trim()||"*";if(Me==="*"&&Ue==="*"){Ce(me),V(""),_("*");return}Ue==="*"&&Me!=="*"&&me===C?ue(Me,"*"):ie(Me,Ue,me),V(""),_("*")},[C,B,$,ue,Ce,t,ie]),we=o.useCallback(me=>me==="*"?t("settings.agents.page.permissions.defaultLabel"):me==="webfetch"?"WebFetch":me==="websearch"?"WebSearch":me==="codesearch"?"CodeSearch":me==="doom_loop"?"Doom Loop":me==="external_directory"?"External Directory":me==="todowrite"?"TodoWrite":me==="todoread"?"TodoRead":me.split(/[_-]+/g).filter(Boolean).map(Me=>Me.charAt(0).toUpperCase()+Me.slice(1)).join(" "),[t]);o.useEffect(()=>{V(""),_("*");const me=Me=>{const Ue=Ki(Me),q=GS(Ue),Se=qS(Ue,q);return S(q),A(Se),z(Se),{global:q,rules:Se}};if(m&&c){const Me=c.name||"",Ue=c.scope||"user",q=c.description||"",Se=c.mode||"subagent",$e=c.model||"",Pe=c.temperature,fe=c.top_p,L=c.prompt||"";h(Me),f(Ue),y(q),w(Se),k($e),j(Pe),D(fe),T(L);const Z=YS(c.permission),Y=me(Z);ne.current={draftName:Me,draftScope:Ue,description:q,mode:Se,model:$e,temperature:Pe,topP:fe,prompt:L,globalPermission:Y.global,permissionRules:Y.rules};return}if(p&&n===p.name){const Me=p.description||"",Ue=p.mode||"subagent",q=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",Se=p.temperature,$e=p.topP,Pe=p.prompt||"";y(Me),w(Ue),k(q),j(Se),D($e),T(Pe);const fe=me(Array.isArray(p.permission)?p.permission:[]);ne.current={draftName:"",draftScope:"user",description:Me,mode:Ue,model:q,temperature:Se,topP:$e,prompt:Pe,globalPermission:fe.global,permissionRules:fe.rules}}},[c,m,p,n]);const ke=o.useMemo(()=>{const me=ne.current;return me?!!(m&&(u!==me.draftName||x!==me.draftScope)||v!==me.description||g!==me.mode||b!==me.model||I!==me.temperature||N!==me.topP||E!==me.prompt||C!==me.globalPermission||!HS(R,me.permissionRules)):!1},[v,u,x,C,m,g,b,R,E,I,N]),xe=async()=>{const me=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!me){H.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&l.some(Me=>Me.name===me)){H.error(t("settings.agents.sidebar.toast.agentExists"));return}Q(!0);try{const Me=b.trim(),Ue=QS(C,R),q={name:me,description:v.trim()||void 0,mode:g,model:Me===""?null:Me,temperature:I,top_p:N,prompt:E.trim()||void 0,permission:Ue,scope:m?x:void 0};let Se;m?(Se=await i(q),Se&&d(null)):Se=await a(me,q),Se?H.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):H.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(Me){console.error("Error saving agent:",Me);const Ue=Me instanceof Error&&Me.message?Me.message:t("settings.agents.page.toast.saveUnexpectedError");H.error(Ue)}finally{Q(!1)}};return n?s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:m?t("settings.agents.page.title.new"):n}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(m?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.identityRole")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[m&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.agentName")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(Bt,{value:u,onChange:me=>h(me.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(is,{value:x,onValueChange:me=>f(me),children:[s.jsx(as,{className:"w-fit min-w-[100px]",children:s.jsx(us,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(os,{align:"end",children:[s.jsx(Ft,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ft,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(hn,{value:v,onChange:me=>y(me.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.mode")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.modeTooltip")})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":g==="primary",onClick:()=>w("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":g==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":g==="all",onClick:()=>w("all"),className:"!font-normal",children:t("settings.agents.page.mode.all")})]})]})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.modelParameters")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(yo,{providerId:ba(b)?.providerId??"",modelId:ba(b)?.modelId??"",onChange:(me,Me)=>{k(me&&Me?`${me}/${Me}`:"")}})})]}),s.jsxs("div",{className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.temperature")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.temperatureTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.temperatureRange")})]}),s.jsxs("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(Vn,{value:I,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),I!==void 0&&s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.topP")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.topPTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.topPRange")})]}),s.jsxs("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(Vn,{value:N,fallbackValue:.9,onValueChange:D,onClear:()=>D(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),N!==void 0&&s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>D(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.systemPrompt")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(hn,{value:E,onChange:me=>T(me.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.toolPermissions")}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>O(me=>!me),children:t(X?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),X?s.jsxs("div",{className:"space-y-6 px-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.permissions.globalDefault")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),s.jsxs(is,{value:C,onValueChange:me=>Ce(me),children:[s.jsx(as,{className:"w-[100px]",children:s.jsx(us,{children:be(C)})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Ft,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Ft,{value:"deny",children:t("settings.common.permission.deny")})]})]})]}),s.jsx("div",{className:"space-y-4",children:ve.filter(me=>me!=="*").map(me=>{const Me=we(me),{defaultAction:Ue,patternRulesCount:q}=re(me),Se=K(me),$e=Se??"global",Pe=ae(me),fe=["allow","ask","deny"].filter(L=>L!==C);return s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[s.jsxs("div",{className:"flex items-center justify-between py-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Me}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:me})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:q>0?t("settings.agents.page.permissions.globalSummary",{summary:Ue}):Ue})]}),s.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Se&&s.jsx(ge,{size:"sm",variant:"ghost",onClick:()=>se(me,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(P,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(is,{value:$e,onValueChange:L=>{if(L==="global"){ue(me,"*");return}ie(me,"*",L)},children:[s.jsx(as,{className:"w-[90px]",children:s.jsx(us,{children:pe($e)})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"global",children:t("settings.common.scope.global")}),fe.map(L=>s.jsx(Ft,{value:L,className:"capitalize",children:be(L)},L))]})]})]}),Pe.map(L=>{const Z=Di(L.permission,L.pattern),Y=W.get(Z),Ee=!Y,Ae=!!(Y&&Y.action!==L.action);return s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:L.pattern}),Ee&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),Ae&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(Ee||Ae)&&s.jsx(ge,{size:"sm",variant:"ghost",onClick:()=>Ee?ue(L.permission,L.pattern):se(L.permission,L.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(P,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(is,{value:L.action,onValueChange:Je=>Ne(L.permission,L.pattern,Je),children:[s.jsx(as,{className:"w-[90px]",children:s.jsx(us,{children:be(L.action)})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Ft,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Ft,{value:"deny",children:t("settings.common.permission.deny")})]})]})]},Z)})]})]},me)})}),s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[s.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:t("settings.agents.page.permissions.addCustomRule")}),s.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[s.jsxs(is,{value:B,onValueChange:V,children:[s.jsx(as,{className:"w-full sm:w-[160px]",children:B?s.jsx("span",{className:"truncate",children:we(B)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(os,{children:ye.map(me=>s.jsx(Ft,{value:me,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:we(me)})})},me))})]}),s.jsx(Bt,{value:$,onChange:me=>_(me.target.value),placeholder:t("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),s.jsxs("div",{className:"flex gap-1",children:[s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>je("allow"),children:t("settings.common.permission.allow")}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>je("ask"),children:t("settings.common.permission.ask")}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>je("deny"),children:t("settings.common.permission.deny")})]})]})]})]}):s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ve.map((me,Me)=>{const{defaultAction:Ue,patternRulesCount:q,patternSummary:Se,hasDefaultHint:$e}=re(me),Pe=we(me),fe=$e?`${Ue} (env blocked)`:Ue;return s.jsxs("div",{className:ce("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",Me>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Pe}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:me})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[q>0?s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.globalSummary",{summary:fe})}):s.jsx("span",{className:ce("typography-micro capitalize px-1.5 py-0.5 rounded",fe==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":fe==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:fe}),q>0&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.rulesSummary",{summary:Se})})]})]},me)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ge,{onClick:xe,disabled:J||!ke,size:"xs",className:"!font-normal",children:t(J?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(P,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},XS="~/.config/opencode/AGENTS.md",dg=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},ZS=t=>t.length>0&&!t.endsWith(`
|
|
155
|
+
`)?`${t}
|
|
156
|
+
`:t,$o={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},ek=(t,e)=>t==="custom"?e:Bb(t),tk=t=>t==="custom"?"custom":sh(t)?t:"concise",cp={concise:"settings.behavior.page.responseStyle.option.concise",detailed:"settings.behavior.page.responseStyle.option.detailed",mentor:"settings.behavior.page.responseStyle.option.mentor",pushback:"settings.behavior.page.responseStyle.option.pushback",noFiller:"settings.behavior.page.responseStyle.option.noFiller",matchEnergy:"settings.behavior.page.responseStyle.option.matchEnergy",warmPeer:"settings.behavior.page.responseStyle.option.warmPeer"},dp=async(t,e)=>{const n=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(await dg(n,e))},sk=()=>{const{t}=ut(),[e,n]=o.useState(""),[r,i]=o.useState($o.responseStyleEnabled),[a,l]=o.useState($o.responseStylePreset),[c,d]=o.useState($o.responseStyleCustomInstructions),[p,m]=o.useState(!0),[u,h]=o.useState(!1),[x,f]=o.useState(""),v=o.useRef(null);o.useEffect(()=>{const b=new AbortController;return(async()=>{try{const[I,j]=await Promise.all([fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:b.signal}),fetch("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:b.signal})]);let N=$o;if(I.ok){const D=await I.json();N={...N,responseStyleEnabled:D.responseStyleEnabled===!0,responseStylePreset:tk(D.responseStylePreset),responseStyleCustomInstructions:typeof D.responseStyleCustomInstructions=="string"?D.responseStyleCustomInstructions:""},typeof D.globalBehaviorPrompt=="string"&&(N={...N,prompt:D.globalBehaviorPrompt})}if(!N.prompt.trim()&&j.ok){const D=await j.json();typeof D.content=="string"&&(N={...N,prompt:D.content})}n(N.prompt),i(N.responseStyleEnabled),l(N.responseStylePreset),d(N.responseStyleCustomInstructions),f(N.prompt),v.current={enabled:N.responseStyleEnabled,preset:N.responseStylePreset,custom:N.responseStyleCustomInstructions}}catch(I){I.name!=="AbortError"&&console.warn("Failed to load behavior settings:",I)}finally{m(!1)}})(),()=>b.abort()},[]),o.useEffect(()=>{if(p)return;const b=v.current;if(b&&b.enabled===r&&b.preset===a&&b.custom===c)return;const k={enabled:r,preset:a,custom:c},I=setTimeout(async()=>{try{await dp({responseStyleEnabled:k.enabled,responseStylePreset:k.preset,responseStyleCustomInstructions:k.custom},t("settings.behavior.page.toast.saveFailed")),v.current=k}catch(j){const N=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");H.error(N)}},400);return()=>clearTimeout(I)},[r,a,c,p,t]);const y=ek(a,c),g=e!==x,w=async()=>{h(!0);try{const b=ZS(e),k=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:b})});if(!k.ok)throw new Error(await dg(k,t("settings.behavior.page.toast.saveFailed")));await dp({globalBehaviorPrompt:b},t("settings.behavior.page.toast.saveFailed")),n(b),f(b),H.success(t("settings.behavior.page.toast.saved"))}catch(b){console.error("Failed to save behavior:",b);const k=b instanceof Error?b.message:t("settings.behavior.page.toast.saveFailed");H.error(k)}finally{h(!1)}};return s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8 space-y-6",children:[s.jsx("div",{className:"space-y-1",children:s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.behavior.page.title")})}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.systemPrompt")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:XS})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(hn,{value:e,onChange:b=>n(b.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(ge,{onClick:w,disabled:u||!g||p,size:"xs",className:"!font-normal",children:t(u?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.responseStyle")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t("settings.behavior.page.responseStyle.tooltip")})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[s.jsx(ds,{checked:r,onChange:i,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(is,{value:a,onValueChange:b=>l(b),disabled:p||!r,children:[s.jsx(as,{className:"w-full sm:w-56",size:"lg",children:s.jsx(us,{children:b=>b==="custom"?t("settings.behavior.page.responseStyle.option.custom"):sh(b)?t(cp[b]):null})}),s.jsxs(os,{children:[$b.map(b=>s.jsx(Ft,{value:b,children:t(cp[b])},b)),s.jsx(Ft,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(hn,{value:y,onChange:b=>d(b.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!r||a!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},nk=t=>{const e=at.c(169),{onItemSelect:n}=t,{t:r}=ut(),[i,a]=o.useState(null),[l,c]=o.useState(""),[d,p]=o.useState(null),[m,u]=o.useState(null),[h,x]=o.useState(!1),[f,v]=o.useState(null),{selectedCommandName:y,commands:g,setSelectedCommand:w,setCommandDraft:b,createCommand:k,deleteCommand:I,loadCommands:j}=Bd(Br(rk)),N=fi(ik),D=fi(ak);let E,T;e[0]!==j||e[1]!==D?(E=()=>{j(),D()},T=[j,D],e[0]=j,e[1]=D,e[2]=E,e[3]=T):(E=e[2],T=e[3]),o.useEffect(E,T);let C;e[4]!==N?(C=new Set(N.map(ok)),e[4]=N,e[5]=C):C=e[5];const S=C;let M;if(e[6]!==g||e[7]!==S){let Ve;e[9]!==S?(Ve=it=>!S.has(it.name),e[9]=S,e[10]=Ve):Ve=e[10],M=g.filter(Ve),e[6]=g,e[7]=S,e[8]=M}else M=e[8];const A=M;let R,z;e[11]!==y||e[12]!==w||e[13]!==S?(R=()=>{y&&S.has(y)&&w(null)},z=[y,w,S],e[11]=y,e[12]=w,e[13]=S,e[14]=R,e[15]=z):(R=e[14],z=e[15]),o.useEffect(R,z);let B;e[16]!==g||e[17]!==n||e[18]!==b||e[19]!==w?(B=()=>{let Ve="new-command",it=1;for(;g.some(dt=>dt.name===Ve);)Ve=`new-command-${it}`,it++;b({name:Ve,scope:"user"}),w(Ve),n?.()},e[16]=g,e[17]=n,e[18]=b,e[19]=w,e[20]=B):B=e[20];const V=B;let $;e[21]!==r?($=async Ve=>{if(la(Ve)){H.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p(Ve),u("delete")},e[21]=r,e[22]=$):$=e[22];const _=$;let X;e[23]===Symbol.for("react.memo_cache_sentinel")?(X=async Ve=>{la(Ve)&&(p(Ve),u("reset"))},e[23]=X):X=e[23];const O=X;let J;e[24]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{p(null),u(null)},e[24]=J):J=e[24];const Q=J;let ne;e[25]!==d||e[26]!==m||e[27]!==I||e[28]!==r?(ne=async()=>{if(!d||!m)return;x(!0),await I(d.name)?(m==="delete"?H.success(r("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):H.success(r("settings.commands.sidebar.toast.commandReset",{name:d.name})),Q()):m==="delete"?H.error(r("settings.commands.sidebar.toast.deleteFailed")):H.error(r("settings.commands.sidebar.toast.resetFailed")),x(!1)},e[25]=d,e[26]=m,e[27]=I,e[28]=r,e[29]=ne):ne=e[29];const G=ne;let le;e[30]!==g||e[31]!==b||e[32]!==w?(le=Ve=>{const it=Ve.name;let dt=1,Ye=`${it}-copy`;for(;g.some(_e=>_e.name===Ye);)dt++,Ye=`${it}-copy-${dt}`;b({name:Ye,scope:Ve.scope||"user",description:Ve.description,template:Ve.template,agent:Ve.agent,model:Ve.model}),w(Ye)},e[30]=g,e[31]=b,e[32]=w,e[33]=le):le=e[33];const oe=le;let F;e[34]===Symbol.for("react.memo_cache_sentinel")?(F=Ve=>{c(Ve.name),a(Ve)},e[34]=F):F=e[34];const U=F;let W;e[35]!==g||e[36]!==k||e[37]!==I||e[38]!==i||e[39]!==l||e[40]!==w||e[41]!==r?(W=async()=>{if(!i)return;const Ve=l.trim().replace(/\s+/g,"-");if(!Ve){H.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ve===i.name){a(null);return}if(g.some(dt=>dt.name===Ve)){H.error(r("settings.commands.sidebar.toast.commandExists"));return}await k({name:Ve,description:i.description,template:i.template,agent:i.agent,model:i.model})?await I(i.name)?(H.success(`Command renamed to "${Ve}"`),w(Ve)):H.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):H.error(r("settings.commands.sidebar.toast.renameFailed")),a(null)},e[35]=g,e[36]=k,e[37]=I,e[38]=i,e[39]=l,e[40]=w,e[41]=r,e[42]=W):W=e[42];const te=W;let K,ae,ve,re,be,pe;if(e[43]!==A||e[44]!==V||e[45]!==_||e[46]!==oe||e[47]!==n||e[48]!==f||e[49]!==y||e[50]!==w||e[51]!==r){const Ve=A.filter(la),it=A.filter(lk);e[58]===Symbol.for("react.memo_cache_sentinel")?(be=ce("flex h-full flex-col","bg-background"),e[58]=be):be=e[58];let dt;e[59]!==r?(dt=r("settings.commands.sidebar.title"),e[59]=r,e[60]=dt):dt=e[60];let Ye;e[61]!==dt?(Ye=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:dt}),e[61]=dt,e[62]=Ye):Ye=e[62];let _e;e[63]===Symbol.for("react.memo_cache_sentinel")?(_e=s.jsx(vo,{className:"mb-3"}),e[63]=_e):_e=e[63];let et;e[64]!==A.length||e[65]!==r?(et=r("settings.commands.sidebar.total",{count:A.length}),e[64]=A.length,e[65]=r,e[66]=et):et=e[66];let gt;e[67]!==et?(gt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:et}),e[67]=et,e[68]=gt):gt=e[68];let Lt;e[69]===Symbol.for("react.memo_cache_sentinel")?(Lt=s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),e[69]=Lt):Lt=e[69];let Ut;e[70]!==V?(Ut=s.jsx(ge,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:V,children:Lt}),e[70]=V,e[71]=Ut):Ut=e[71];let mt;e[72]!==gt||e[73]!==Ut?(mt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[gt,Ut]}),e[72]=gt,e[73]=Ut,e[74]=mt):mt=e[74],e[75]!==Ye||e[76]!==mt?(pe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Ye,_e,mt]}),e[75]=Ye,e[76]=mt,e[77]=pe):pe=e[77],K=Cs,ae="flex-1 min-h-0",ve="space-y-1 px-3 py-2",re=A.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(P,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[Ve.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.builtIn")}),[...Ve].sort(ck).map(Nt=>s.jsx(up,{command:Nt,isSelected:y===Nt.name,onSelect:()=>{w(Nt.name),n?.()},onReset:()=>O(Nt),onDuplicate:()=>oe(Nt),isMenuOpen:f===Nt.name,onMenuOpenChange:Xt=>v(Xt?Nt.name:null)},Nt.name))]}),it.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.custom")}),[...it].sort(dk).map(Nt=>s.jsx(up,{command:Nt,isSelected:y===Nt.name,onSelect:()=>{w(Nt.name),n?.()},onRename:()=>U(Nt),onDelete:()=>_(Nt),onDuplicate:()=>oe(Nt),isMenuOpen:f===Nt.name,onMenuOpenChange:Xt=>v(Xt?Nt.name:null)},Nt.name))]})]}),e[43]=A,e[44]=V,e[45]=_,e[46]=oe,e[47]=n,e[48]=f,e[49]=y,e[50]=w,e[51]=r,e[52]=K,e[53]=ae,e[54]=ve,e[55]=re,e[56]=be,e[57]=pe}else K=e[52],ae=e[53],ve=e[54],re=e[55],be=e[56],pe=e[57];let ye;e[78]!==K||e[79]!==ae||e[80]!==ve||e[81]!==re?(ye=s.jsx(K,{outerClassName:ae,className:ve,children:re}),e[78]=K,e[79]=ae,e[80]=ve,e[81]=re,e[82]=ye):ye=e[82];const ie=d!==null&&m!==null;let ue;e[83]!==h?(ue=Ve=>{!Ve&&!h&&Q()},e[83]=h,e[84]=ue):ue=e[84];let se;e[85]!==m||e[86]!==r?(se=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=se):se=e[87];let Ne;e[88]!==se?(Ne=s.jsx(gs,{children:se}),e[88]=se,e[89]=Ne):Ne=e[89];let Ce;e[90]!==d?.name||e[91]!==m||e[92]!==r?(Ce=m==="delete"?r("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):r("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[90]=d?.name,e[91]=m,e[92]=r,e[93]=Ce):Ce=e[93];let je;e[94]!==Ce?(je=s.jsx(Is,{children:Ce}),e[94]=Ce,e[95]=je):je=e[95];let we;e[96]!==Ne||e[97]!==je?(we=s.jsxs(bs,{children:[Ne,je]}),e[96]=Ne,e[97]=je,e[98]=we):we=e[98];let ke;e[99]!==r?(ke=r("settings.common.actions.cancel"),e[99]=r,e[100]=ke):ke=e[100];let xe;e[101]!==h||e[102]!==ke?(xe=s.jsx(ge,{size:"sm",variant:"ghost",onClick:Q,disabled:h,children:ke}),e[101]=h,e[102]=ke,e[103]=xe):xe=e[103];let me;e[104]!==m||e[105]!==r?(me=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=me):me=e[106];let Me;e[107]!==G||e[108]!==h||e[109]!==me?(Me=s.jsx(ge,{size:"sm",onClick:G,disabled:h,children:me}),e[107]=G,e[108]=h,e[109]=me,e[110]=Me):Me=e[110];let Ue;e[111]!==xe||e[112]!==Me?(Ue=s.jsxs(Vs,{children:[xe,Me]}),e[111]=xe,e[112]=Me,e[113]=Ue):Ue=e[113];let q;e[114]!==we||e[115]!==Ue?(q=s.jsxs(fs,{className:"max-w-md",children:[we,Ue]}),e[114]=we,e[115]=Ue,e[116]=q):q=e[116];let Se;e[117]!==ie||e[118]!==ue||e[119]!==q?(Se=s.jsx(hs,{open:ie,onOpenChange:ue,children:q}),e[117]=ie,e[118]=ue,e[119]=q,e[120]=Se):Se=e[120];const $e=i!==null;let Pe;e[121]===Symbol.for("react.memo_cache_sentinel")?(Pe=Ve=>!Ve&&a(null),e[121]=Pe):Pe=e[121];let fe;e[122]!==r?(fe=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=fe):fe=e[123];let L;e[124]!==fe?(L=s.jsx(gs,{children:fe}),e[124]=fe,e[125]=L):L=e[125];const Z=i?.name??"";let Y;e[126]!==r||e[127]!==Z?(Y=r("settings.commands.sidebar.renameDialog.description",{name:Z}),e[126]=r,e[127]=Z,e[128]=Y):Y=e[128];let Ee;e[129]!==Y?(Ee=s.jsx(Is,{children:Y}),e[129]=Y,e[130]=Ee):Ee=e[130];let Ae;e[131]!==L||e[132]!==Ee?(Ae=s.jsxs(bs,{children:[L,Ee]}),e[131]=L,e[132]=Ee,e[133]=Ae):Ae=e[133];let Je;e[134]===Symbol.for("react.memo_cache_sentinel")?(Je=Ve=>c(Ve.target.value),e[134]=Je):Je=e[134];let de;e[135]!==r?(de=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=de):de=e[136];let ze;e[137]!==te?(ze=Ve=>{Ve.key==="Enter"&&te()},e[137]=te,e[138]=ze):ze=e[138];let rt;e[139]!==l||e[140]!==de||e[141]!==ze?(rt=s.jsx(Bt,{value:l,onChange:Je,placeholder:de,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:ze}),e[139]=l,e[140]=de,e[141]=ze,e[142]=rt):rt=e[142];let Re;e[143]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>a(null),e[143]=Re):Re=e[143];let Xe;e[144]!==r?(Xe=r("settings.common.actions.cancel"),e[144]=r,e[145]=Xe):Xe=e[145];let qe;e[146]!==Xe?(qe=s.jsx(ge,{size:"sm",variant:"ghost",onClick:Re,children:Xe}),e[146]=Xe,e[147]=qe):qe=e[147];let Te;e[148]!==r?(Te=r("settings.common.actions.rename"),e[148]=r,e[149]=Te):Te=e[149];let We;e[150]!==te||e[151]!==Te?(We=s.jsx(ge,{size:"sm",onClick:te,children:Te}),e[150]=te,e[151]=Te,e[152]=We):We=e[152];let Ze;e[153]!==qe||e[154]!==We?(Ze=s.jsxs(Vs,{children:[qe,We]}),e[153]=qe,e[154]=We,e[155]=Ze):Ze=e[155];let Qe;e[156]!==Ae||e[157]!==rt||e[158]!==Ze?(Qe=s.jsxs(fs,{children:[Ae,rt,Ze]}),e[156]=Ae,e[157]=rt,e[158]=Ze,e[159]=Qe):Qe=e[159];let he;e[160]!==$e||e[161]!==Qe?(he=s.jsx(hs,{open:$e,onOpenChange:Pe,children:Qe}),e[160]=$e,e[161]=Qe,e[162]=he):he=e[162];let Ge;return e[163]!==be||e[164]!==pe||e[165]!==ye||e[166]!==Se||e[167]!==he?(Ge=s.jsxs("div",{className:be,children:[pe,ye,Se,he]}),e[163]=be,e[164]=pe,e[165]=ye,e[166]=Se,e[167]=he,e[168]=Ge):Ge=e[168],Ge},up=t=>{const e=at.c(53),{command:n,isSelected:r,onSelect:i,onDelete:a,onReset:l,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=ut();let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=no(),e[0]=h):h=e[0];const x=h,f=r?"bg-interactive-selection":"hover:bg-interactive-hover";let v;e[1]!==f?(v=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",f),e[1]=f,e[2]=v):v=e[2];let y;e[3]!==m?(y=x?void 0:V=>{V.preventDefault(),m(!0)},e[3]=m,e[4]=y):y=e[4];let g;e[5]!==n.name?(g=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[5]=n.name,e[6]=g):g=e[6];let w;e[7]!==n||e[8]!==u?(w=(n.scope||la(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:la(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=w):w=e[9];let b;e[10]!==g||e[11]!==w?(b=s.jsxs("div",{className:"flex items-center gap-2",children:[g,w]}),e[10]=g,e[11]=w,e[12]=b):b=e[12];let k;e[13]!==n.description?(k=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[13]=n.description,e[14]=k):k=e[14];let I;e[15]!==i||e[16]!==b||e[17]!==k?(I=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[b,k]}),e[15]=i,e[16]=b,e[17]=k,e[18]=I):I=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Es,{asChild:!0,children:s.jsx(ge,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(P,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[19]=j):j=e[19];let N;e[20]!==c||e[21]!==u?(N=c&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),c()},children:[s.jsx(P,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=N):N=e[22];let D;e[23]!==d?(D=V=>{V.stopPropagation(),d()},e[23]=d,e[24]=D):D=e[24];let E;e[25]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(P,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[25]=E):E=e[25];let T;e[26]!==u?(T=u("settings.common.actions.duplicate"),e[26]=u,e[27]=T):T=e[27];let C;e[28]!==D||e[29]!==T?(C=s.jsxs($t,{onClick:D,children:[E,T]}),e[28]=D,e[29]=T,e[30]=C):C=e[30];let S;e[31]!==l||e[32]!==u?(S=l&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),l()},children:[s.jsx(P,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=l,e[32]=u,e[33]=S):S=e[33];let M;e[34]!==a||e[35]!==u?(M=a&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),a()},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=a,e[35]=u,e[36]=M):M=e[36];let A;e[37]!==N||e[38]!==C||e[39]!==S||e[40]!==M?(A=s.jsxs(Rs,{align:"end",className:"w-fit min-w-20",children:[N,C,S,M]}),e[37]=N,e[38]=C,e[39]=S,e[40]=M,e[41]=A):A=e[41];let R;e[42]!==p||e[43]!==m||e[44]!==A?(R=s.jsxs(Fs,{open:p,onOpenChange:m,children:[j,A]}),e[42]=p,e[43]=m,e[44]=A,e[45]=R):R=e[45];let z;e[46]!==R||e[47]!==I?(z=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,R]}),e[46]=R,e[47]=I,e[48]=z):z=e[48];let B;return e[49]!==z||e[50]!==v||e[51]!==y?(B=s.jsx("div",{className:v,onContextMenu:y,children:z}),e[49]=z,e[50]=v,e[51]=y,e[52]=B):B=e[52],B};function rk(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function ik(t){return t.skills}function ak(t){return t.loadSkills}function ok(t){return t.name}function lk(t){return!la(t)}function ck(t,e){return t.name.localeCompare(e.name)}function dk(t,e){return t.name.localeCompare(e.name)}const uk=()=>{const{t}=ut(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:i,commands:a,commandDraft:l,setCommandDraft:c}=Bd(Br(C=>({selectedCommandName:C.selectedCommandName,getCommandByName:C.getCommandByName,createCommand:C.createCommand,updateCommand:C.updateCommand,commands:C.commands,commandDraft:C.commandDraft,setCommandDraft:C.setCommandDraft}))),d=e?n(e):null,p=!!(l&&l.name===e&&!d),[m,u]=o.useState(""),[h,x]=o.useState("user"),[f,v]=o.useState(""),[y,g]=o.useState(""),[w,b]=o.useState(""),[k,I]=o.useState(""),[j,N]=o.useState(!1),D=o.useRef(null);o.useEffect(()=>{if(p&&l){const C=l.name||"",S=l.scope||"user",M=l.description||"",A=l.agent||"",R=l.model||"",z=l.template||"";u(C),x(S),v(M),g(A),b(R),I(z),D.current={draftName:C,draftScope:S,description:M,agent:A,model:R,template:z}}else if(d){const C=d.description||"",S=d.agent||"",M=d.model||"",A=d.template||"";v(C),g(S),b(M),I(A),D.current={draftName:"",draftScope:"user",description:C,agent:S,model:M,template:A}}},[d,p,e,a,l]);const E=o.useMemo(()=>{const C=D.current;return C?!!(p&&(m!==C.draftName||h!==C.draftScope)||f!==C.description||y!==C.agent||w!==C.model||k!==C.template):!1},[y,f,m,h,p,w,k]),T=async()=>{const C=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!C){H.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!k.trim()){H.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&a.some(S=>S.name===C)){H.error(t("settings.commands.sidebar.toast.commandExists"));return}N(!0);try{const S=y.trim(),M=w.trim(),A=k.trim(),R={name:C,description:f.trim()||void 0,agent:S===""?null:S,model:M===""?null:M,template:A,scope:p?h:void 0};let z;p?(z=await r(R),z&&c(null)):z=await i(C,R),z?H.success(t(p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):H.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(S){console.error("Error saving command:",S),H.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{N(!1)}};return e?s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p?t("settings.commands.page.title.new"):`/${e}`}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(p?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.identity")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.commands.page.field.commandName")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(Bt,{value:m,onChange:C=>u(C.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(is,{value:h,onValueChange:C=>x(C),children:[s.jsx(as,{className:"w-fit min-w-[100px]",children:s.jsx(us,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(os,{align:"end",children:[s.jsx(Ft,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ft,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(hn,{value:f,onChange:C=>v(C.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.executionContext")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.commands.page.field.overrideAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Ul,{agentName:y,onChange:C=>g(C)})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(yo,{providerId:ba(w)?.providerId??"",modelId:ba(w)?.modelId??"",onChange:(C,S)=>{b(C&&S?`${C}/${S}`:"")}})})]})]})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.template")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(hn,{value:k,onChange:C=>I(C.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ge,{onClick:T,disabled:j||!E,size:"xs",className:"!font-normal",children:t(j?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(P,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},mp=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},pp=t=>{const e=at.c(5),{tone:n,enabled:r}=t;if(!r){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let i;e[1]!==n?(i=ce("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[n]),e[1]=n,e[2]=i):i=e[2];let a;return e[3]!==i?(a=s.jsx("span",{className:i}),e[3]=i,e[4]=a):a=e[4],a},mk=t=>{const e=at.c(116),{onItemSelect:n}=t,{t:r}=ut(),{mcpServers:i,selectedMcpName:a,setSelectedMcp:l,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=lo(Br(pk)),m=$s(fk);let u;e[0]!==m?(u=fe=>fe.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const h=yn(u),x=yn(hk),f=yn(gk),[v,y]=o.useState(null),[g,w]=o.useState(!1),[b,k]=o.useState(null),[I,j]=o.useState(!1);let N;e[2]!==i?(N=i.filter(xk),e[2]=i,e[3]=N):N=e[3];const D=N;let E;e[4]!==i?(E=i.filter(bk),e[4]=i,e[5]=E):E=e[5];const T=E;let C,S;e[6]!==d?(C=()=>{d()},S=[d],e[6]=d,e[7]=C,e[8]=S):(C=e[7],S=e[8]),o.useEffect(C,S);let M;e[9]!==m||e[10]!==f||e[11]!==I||e[12]!==x?(M=()=>{if(I)return;j(!0);const fe=new Promise(yk);Promise.all([x({directory:m,silent:!0}),fe]).then(()=>{const L=f(m);L&&H.error(L)}).finally(()=>{j(!1)})},e[9]=m,e[10]=f,e[11]=I,e[12]=x,e[13]=M):M=e[13];const A=M;let R;e[14]!==i||e[15]!==n||e[16]!==c||e[17]!==l?(R=()=>{let fe="new-mcp-server",L=1;for(;i.some(Y=>Y.name===fe);)fe=`new-mcp-server-${L}`,L++;c({name:fe,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),l(fe),n?.()},e[14]=i,e[15]=n,e[16]=c,e[17]=l,e[18]=R):R=e[18];const z=R;let B;e[19]!==p||e[20]!==v||e[21]!==r?(B=async()=>{if(!v)return;w(!0);const fe=await p(v.name);fe.ok?fe.reloadFailed?H.warning(fe.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:fe.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):H.success(fe.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:v.name})):H.error(r("settings.mcp.sidebar.toast.deleteFailed")),y(null),w(!1)},e[19]=p,e[20]=v,e[21]=r,e[22]=B):B=e[22];const V=B;let $;e[23]===Symbol.for("react.memo_cache_sentinel")?($=ce("flex h-full flex-col","bg-background"),e[23]=$):$=e[23];let _;e[24]!==r?(_=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=_):_=e[25];let X;e[26]!==_?(X=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:_}),e[26]=_,e[27]=X):X=e[27];let O;e[28]!==r?(O=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=O):O=e[29];let J;e[30]!==r?(J=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=J):J=e[31];const Q=I&&"animate-spin";let ne;e[32]!==Q?(ne=ce("h-4 w-4",Q),e[32]=Q,e[33]=ne):ne=e[33];let G;e[34]!==ne?(G=s.jsx(P,{name:"refresh",className:ne}),e[34]=ne,e[35]=G):G=e[35];let le;e[36]!==A||e[37]!==I||e[38]!==O||e[39]!==J||e[40]!==G?(le=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:I,onClick:A,"aria-label":O,title:J,children:G}),e[36]=A,e[37]=I,e[38]=O,e[39]=J,e[40]=G,e[41]=le):le=e[41];let oe;e[42]!==X||e[43]!==le?(oe=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[X,le]}),e[42]=X,e[43]=le,e[44]=oe):oe=e[44];let F;e[45]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(vo,{className:"mb-3"}),e[45]=F):F=e[45];let U;e[46]!==i.length||e[47]!==r?(U=r("settings.mcp.sidebar.total",{count:i.length}),e[46]=i.length,e[47]=r,e[48]=U):U=e[48];let W;e[49]!==U?(W=s.jsx("span",{className:"typography-meta text-muted-foreground",children:U}),e[49]=U,e[50]=W):W=e[50];let te;e[51]!==r?(te=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=te):te=e[52];let K;e[53]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),e[53]=K):K=e[53];let ae;e[54]!==z||e[55]!==te?(ae=s.jsx(ge,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:z,title:te,children:K}),e[54]=z,e[55]=te,e[56]=ae):ae=e[56];let ve;e[57]!==W||e[58]!==ae?(ve=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[W,ae]}),e[57]=W,e[58]=ae,e[59]=ve):ve=e[59];let re;e[60]!==oe||e[61]!==ve?(re=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[oe,F,ve]}),e[60]=oe,e[61]=ve,e[62]=re):re=e[62];let be;e[63]!==i.length||e[64]!==h||e[65]!==n||e[66]!==b||e[67]!==D||e[68]!==a||e[69]!==c||e[70]!==l||e[71]!==r||e[72]!==T?(be=s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:i.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(P,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[D.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.projectServers")}),D.map(fe=>{const L=h[fe.name],Z=mp(L?.status),Y=a===fe.name,Ee=no();return s.jsxs("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Y?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ee?void 0:Ae=>{Ae.preventDefault(),k(fe.name)},children:[s.jsxs("button",{onClick:()=>{l(fe.name),c(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(pp,{tone:Z,enabled:fe.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:fe.name}),s.jsx("span",{title:fe.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:fe.type==="local"?s.jsx(P,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(P,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:fe.type==="local"?fe.command?.join(" ")??"":fe.url??""})]}),s.jsxs(Fs,{open:b===fe.name,onOpenChange:Ae=>k(Ae?fe.name:null),children:[s.jsx(Es,{asChild:!0,children:s.jsx(ge,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(P,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Rs,{align:"end",className:"w-fit min-w-20",children:s.jsxs($t,{onClick:Ae=>{Ae.stopPropagation(),y(fe)},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},fe.name)})]}),T.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.userServers")}),T.map(fe=>{const L=h[fe.name],Z=mp(L?.status),Y=a===fe.name,Ee=no();return s.jsxs("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Y?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ee?void 0:Ae=>{Ae.preventDefault(),k(fe.name)},children:[s.jsxs("button",{onClick:()=>{l(fe.name),c(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(pp,{tone:Z,enabled:fe.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:fe.name}),s.jsx("span",{title:fe.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:fe.type==="local"?s.jsx(P,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(P,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:fe.type==="local"?fe.command?.join(" ")??"":fe.url??""})]}),s.jsxs(Fs,{open:b===fe.name,onOpenChange:Ae=>k(Ae?fe.name:null),children:[s.jsx(Es,{asChild:!0,children:s.jsx(ge,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(P,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Rs,{align:"end",className:"w-fit min-w-20",children:s.jsxs($t,{onClick:Ae=>{Ae.stopPropagation(),y(fe)},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},fe.name)})]})]})}),e[63]=i.length,e[64]=h,e[65]=n,e[66]=b,e[67]=D,e[68]=a,e[69]=c,e[70]=l,e[71]=r,e[72]=T,e[73]=be):be=e[73];const pe=v!==null;let ye;e[74]!==g?(ye=fe=>{!fe&&!g&&y(null)},e[74]=g,e[75]=ye):ye=e[75];let ie;e[76]!==r?(ie=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=ie):ie=e[77];let ue;e[78]!==ie?(ue=s.jsx(gs,{children:ie}),e[78]=ie,e[79]=ue):ue=e[79];const se=v?.name||"";let Ne;e[80]!==r||e[81]!==se?(Ne=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:se}),e[80]=r,e[81]=se,e[82]=Ne):Ne=e[82];let Ce;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=Ce):Ce=e[83];let je;e[84]!==Ne?(je=s.jsxs(Is,{children:[Ne," ",Ce,"."]}),e[84]=Ne,e[85]=je):je=e[85];let we;e[86]!==ue||e[87]!==je?(we=s.jsxs(bs,{children:[ue,je]}),e[86]=ue,e[87]=je,e[88]=we):we=e[88];let ke;e[89]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>y(null),e[89]=ke):ke=e[89];let xe;e[90]!==r?(xe=r("settings.common.actions.cancel"),e[90]=r,e[91]=xe):xe=e[91];let me;e[92]!==g||e[93]!==xe?(me=s.jsx(ge,{size:"sm",variant:"ghost",onClick:ke,disabled:g,children:xe}),e[92]=g,e[93]=xe,e[94]=me):me=e[94];let Me;e[95]!==g||e[96]!==r?(Me=r(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=g,e[96]=r,e[97]=Me):Me=e[97];let Ue;e[98]!==V||e[99]!==g||e[100]!==Me?(Ue=s.jsx(ge,{size:"sm",onClick:V,disabled:g,children:Me}),e[98]=V,e[99]=g,e[100]=Me,e[101]=Ue):Ue=e[101];let q;e[102]!==me||e[103]!==Ue?(q=s.jsxs(Vs,{children:[me,Ue]}),e[102]=me,e[103]=Ue,e[104]=q):q=e[104];let Se;e[105]!==we||e[106]!==q?(Se=s.jsxs(fs,{className:"max-w-md",children:[we,q]}),e[105]=we,e[106]=q,e[107]=Se):Se=e[107];let $e;e[108]!==pe||e[109]!==ye||e[110]!==Se?($e=s.jsx(hs,{open:pe,onOpenChange:ye,children:Se}),e[108]=pe,e[109]=ye,e[110]=Se,e[111]=$e):$e=e[111];let Pe;return e[112]!==re||e[113]!==be||e[114]!==$e?(Pe=s.jsxs("div",{className:$,children:[re,be,$e]}),e[112]=re,e[113]=be,e[114]=$e,e[115]=Pe):Pe=e[115],Pe};function pk(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function fk(t){return t.currentDirectory}function hk(t){return t.refresh}function gk(t){return t.getErrorForDirectory}function xk(t){return t.scope==="project"}function bk(t){return t.scope!=="project"}function yk(t){return setTimeout(t,500)}function gi(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Fa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Ni(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Ac(t,e,n){const r=vk(n),i=typeof n.url=="string"?n.url.trim():"",a=fp(n,"env","environment"),l=fp(n,"headers"),c=wk(n),d=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",m=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",u=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",h=jk(n),x=Nk(n);return{ok:!0,name:t,type:e,command:r,url:i,environment:a,headers:l,oauthEnabled:c,oauthClientId:d,oauthClientSecret:p,oauthScope:m,oauthRedirectUri:u,timeout:h,enabled:x}}function vk(t){const e=t.command,n=t.args;if(Fa(e)&&Fa(n))return[...e,...n];if(Fa(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return Fa(n)?[...r,...n]:r}return Fa(n)?n:[]}function fp(t,...e){for(const n of e){const r=t[n];if(!gi(r))continue;const i=Object.entries(r).filter(([a,l])=>a&&typeof l=="string");if(i.length>0)return i.map(([a,l])=>({key:a,value:String(l)}))}return[]}function wk(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!gi(t.oauth))return!1;const e=t.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function jk(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const n=Number(e);if(Number.isFinite(n)&&n>0)return String(Math.floor(n))}return""}function Nk(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function Sk(t){const e=t.mcpServers;if(gi(e)){const r=Object.keys(e);if(r.length===1){const i=r[0],a=e[i];if(gi(a))return{name:i,entry:a}}if(r.length>1)return null}const n=Object.keys(t).filter(r=>{const i=t[r];return r!=="mcpServers"&&gi(i)});if(n.length===1){const r=n[0],i=t[r];if(ug(i))return{name:r,entry:i}}return null}function ug(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function kk(t,e){let n;try{const l=t.trim();if(!l)return Ni("No JSON content provided");n=JSON.parse(l)}catch(l){return Ni(l instanceof Error?`Invalid JSON: ${l.message}`:"Invalid JSON")}if(!gi(n))return Ni("Expected a JSON object, not an array or primitive");const r=n,i=r.mcpServers;if(gi(i)){const l=Object.keys(i);if(l.length===0)return Ni("mcpServers object is empty",n);if(l.length>1)return Ni("Paste one server at a time. Found "+l.length+" servers in mcpServers",n);const c=l[0],d=i[c];return gi(d)?Ac(c,Dc(d),d):Ni("Server entry is not a valid object",n)}const a=Sk(r);if(a)return Ac(a.name,Dc(a.entry),a.entry);if(ug(r)){const l=Dc(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return Ac(c,l,r)}return Ni("No recognizable MCP server configuration found in JSON",n)}function Dc(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function Ck(t,e,n){const r=n?.isNewServer??!1,i=t.name,a=r&&i?i:e.name??"";return{...e,name:a,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}const mg="/mcp/oauth/callback",Pk=t=>{if(typeof window>"u")return null;try{const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=e.length%4===0?"":"=".repeat(4-e.length%4),r=window.atob(e+n),i=Uint8Array.from(r,a=>a.charCodeAt(0));return new TextDecoder().decode(i)}catch{return null}},pg=t=>{const e=Ik(t.get("state"));if(e)return e;const n=t.get("server");if(typeof n!="string"||!n.trim())return null;const r=t.get("directory");return{name:n.trim(),directory:typeof r=="string"&&r.trim()?r.trim():null}},Zd=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},Ik=t=>{if(typeof t!="string"||!t.trim())return null;const e=Pk(t.trim());if(!e)return null;try{const n=JSON.parse(e);return n?.v!==1||typeof n.n!="string"||!n.n.trim()?null:{name:n.n.trim(),directory:typeof n.d=="string"&&n.d.trim()?n.d.trim():null}}catch{return null}};function Ak(t){const e=[];let n="",r=!1,i=!1;for(let a=0;a<t.length;a++){const l=t[a];if(l==="'"&&!i){r=!r;continue}if(l==='"'&&!r){i=!i;continue}if((l===" "||l===" ")&&!r&&!i){n&&(e.push(n),n="");continue}n+=l}return n&&e.push(n),e}function Dk(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const n=new URL(e),r=n.searchParams.get("code");if(typeof r=="string"&&r.trim())return{code:r.trim(),context:pg(n.searchParams),stateKey:Zd(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Tk=({value:t,onChange:e,pasteCommandTitle:n,pasteCommandLabel:r,pasteSuccess:i,clipboardReadFailed:a,preview:l})=>{const[c,d]=o.useState(()=>t.join(`
|
|
157
|
+
`)),p=o.useRef(t);o.useEffect(()=>{JSON.stringify(p.current)!==JSON.stringify(t)&&(p.current=t,d(t.join(`
|
|
158
|
+
`)))},[t]);const m=h=>{const x=h.split(`
|
|
159
|
+
`).filter(f=>f.trim().length>0);e(x)},u=async()=>{try{const x=(await navigator.clipboard.readText()).trim(),f=x.includes(`
|
|
160
|
+
`)?x.split(`
|
|
161
|
+
`).filter(v=>v.trim()):Ak(x);d(f.join(`
|
|
162
|
+
`)),e(f),H.success(i(f.length))}catch{H.error(a)}};return s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[s.jsx("div",{className:"flex items-center justify-end gap-2",children:s.jsxs(ge,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(P,{name:"clipboard",className:"h-3 w-3"}),r]})}),s.jsx(hn,{value:c,onChange:h=>{d(h.target.value),m(h.target.value)},onBlur:()=>{const h=c.split(`
|
|
163
|
+
`).map(x=>x.trimEnd()).join(`
|
|
164
|
+
`);d(h),m(h)},placeholder:`npx
|
|
165
|
+
-y
|
|
166
|
+
@modelcontextprotocol/server-postgres
|
|
167
|
+
postgresql://user:pass@host/db`,rows:Math.max(4,t.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),t.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:l(t.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:t.map((h,x)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",x,"]"]}),h]},x))})})]})]})},Mk=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),hp=({value:t,onChange:e,keyTransform:n=Mk,keyPlaceholder:r="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:a="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:p,keyLabel:m,valueLabel:u,valuePlaceholder:h,hideValueTitle:x,showValueTitle:f,addVariable:v,plainTextWarning:y,removeVariableAria:g})=>{const[w,b]=o.useState(new Set),k=()=>e([...t,{key:"",value:""}]),I=T=>{e(t.filter((C,S)=>S!==T)),b(C=>{const S=new Set(C);return S.delete(T),S})},j=(T,C,S)=>{const M=[...t];M[T]={...M[T],[C]:S},e(M)},N=T=>{b(C=>{const S=new Set(C);return S.has(T)?S.delete(T):S.add(T),S})},D=async()=>{try{const T=await navigator.clipboard.readText(),C=[];for(const M of T.split(`
|
|
168
|
+
`)){const A=M.trim();if(!A||A.startsWith("#"))continue;const R=A.indexOf("=");if(R===-1)continue;const z=A.slice(0,R).trim();let B=A.slice(R+1).trim();(B.startsWith('"')&&B.endsWith('"')||B.startsWith("'")&&B.endsWith("'"))&&(B=B.slice(1,-1)),z&&C.push({key:z,value:B})}if(C.length===0){H.error(c);return}const S=[...t];for(const M of C){const A=S.findIndex(R=>R.key===M.key);A!==-1?S[A]=M:S.push(M)}e(S),H.success(d(C.length))}catch{H.error(p)}},E=t.some(T=>T.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:u})]}),s.jsxs(ge,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:D,type:"button",title:l,children:[s.jsx(P,{name:"clipboard",className:"h-3 w-3"}),a]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((T,C)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:T.key,onChange:S=>j(C,"key",n(S.target.value)),placeholder:r,className:i,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Bt,{type:w.has(C)?"text":"password",value:T.value,onChange:S=>j(C,"value",S.target.value),placeholder:h,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>N(C),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:w.has(C)?x:f,children:w.has(C)?s.jsx(P,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(ge,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>I(C),"aria-label":g,children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},C))}),s.jsxs(ge,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:k,type:"button",children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),v]}),E&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:y})]})},gp=t=>{const e=at.c(14),{status:n,enabled:r,getStatusLabel:i,variant:a}=t,l=a===void 0?"compact":a;if(!r||!n)return null;let c,d;if(e[0]!==i||e[1]!==n||e[2]!==l){d=Symbol.for("react.early_return_sentinel");e:{const h={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[n]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const x=ce("typography-micro font-medium rounded-full px-2 py-0.5",h.text,h.bg);let f;e[5]!==i||e[6]!==n?(f=i(n),e[5]=i,e[6]=n,e[7]=f):f=e[7],d=s.jsxs("span",{className:x,children:["● ",f]});break e}c=ce("typography-micro font-medium",h.text)}e[0]=i,e[1]=n,e[2]=l,e[3]=c,e[4]=d}else c=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;let p;e[8]!==i||e[9]!==n?(p=i(n),e[8]=i,e[9]=n,e[10]=p):p=e[10];let m;return e[11]!==c||e[12]!==p?(m=s.jsxs("span",{className:c,children:["● ",p]}),e[11]=c,e[12]=p,e[13]=m):m=e[13],m},Ek=(t,e,n)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return n?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return n?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},Rk=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Fk=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),xp=(t,e)=>{if(typeof window>"u")return null;const n=new URL(mg,window.location.origin);return typeof t=="string"&&t.trim()&&n.searchParams.set("server",t.trim()),typeof e=="string"&&e.trim()&&n.searchParams.set("directory",e.trim()),n.toString()},Lk=async t=>{const e=await fetch("/api/mcp/auth/pending",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:t.state,name:t.name,directory:typeof t.directory=="string"&&t.directory.trim()?t.directory.trim():null})});if(!e.ok){const n=await e.json().catch(()=>null);throw new Error(n?.error||"Failed to prepare MCP authorization callback")}},Ok=async t=>{const e=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const n=await e.json().catch(()=>null);return n?.name?.trim()?{name:n.name.trim(),directory:typeof n.directory=="string"&&n.directory.trim()?n.directory.trim():null}:null},La=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Tc=(t,e,n)=>{const r=t instanceof Error?t.message:e;return/oauth state required/i.test(r)?n("settings.mcp.page.toast.authSessionExpired"):r},$k=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},Bk=()=>{const{t}=ut(),e=o.useCallback((He,kt)=>t(He,kt),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:i,setMcpDraft:a,setSelectedMcp:l,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=lo(Br(He=>({selectedMcpName:He.selectedMcpName,mcpServers:He.mcpServers,mcpDraft:He.mcpDraft,setMcpDraft:He.setMcpDraft,setSelectedMcp:He.setSelectedMcp,getMcpByName:He.getMcpByName,createMcp:He.createMcp,updateMcp:He.updateMcp,deleteMcp:He.deleteMcp}))),u=$s(He=>He.currentDirectory),h=o.useMemo(()=>mn(),[]),x=yn(He=>He.getStatusForDirectory(u??null)),f=yn(He=>He.getDiagnosticForDirectory(u??null)),v=yn(He=>He.refresh),y=yn(He=>He.connect),g=yn(He=>He.disconnect),w=yn(He=>He.startAuth),b=yn(He=>He.completeAuth),k=yn(He=>He.clearAuth),I=yn(He=>He.testConnection),j=n?c(n):null,N=!!(i&&i.name===n&&!j),[D,E]=o.useState(""),[T,C]=o.useState("user"),[S,M]=o.useState("local"),[A,R]=o.useState([]),[z,B]=o.useState(""),[V,$]=o.useState([]),[_,X]=o.useState([]),[O,J]=o.useState(!0),[Q,ne]=o.useState(""),[G,le]=o.useState(""),[oe,F]=o.useState(""),[U,W]=o.useState(""),[te,K]=o.useState(""),[ae,ve]=o.useState(!0),[re,be]=o.useState(!1),[pe,ye]=o.useState(!1),[ie,ue]=o.useState(!1),[se,Ne]=o.useState(!1),[Ce,je]=o.useState(!1),[we,ke]=o.useState(!1),[xe,me]=o.useState(!1),[Me,Ue]=o.useState(!1),[q,Se]=o.useState(null),[$e,Pe]=o.useState(null),[fe,L]=o.useState(""),[Z,Y]=o.useState(!1),Ee=o.useRef(0),Ae=o.useRef(!1),[Je,de]=o.useState(!1),[ze,rt]=o.useState(!1),[Re,Xe]=o.useState(""),[qe,Te]=o.useState(null),We=o.useMemo(()=>$k(n,u),[u,n]),Ze=o.useRef(We),Qe=o.useRef(null),he=o.useCallback(()=>{Se(null),Pe(null),L(""),Y(!1),Ee.current=0,Ue(!1),je(!1),ke(!1),Ae.current=!1},[]),Ge=o.useCallback(()=>{Xe(""),Te(null),rt(!0)},[]),Ve=o.useCallback(async()=>{try{const He=await navigator.clipboard.readText();Xe(He),Te(null)}catch{H.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),it=o.useCallback(()=>{const He=kk(Re,{fallbackName:D});if(!He.ok){Te(He.error);return}const Kt=Ck(He,{name:D,scope:T,type:S,command:A,url:z,environment:V,headers:_,oauthEnabled:O,oauthClientId:Q,oauthClientSecret:G,oauthScope:oe,oauthRedirectUri:U,timeout:te,enabled:ae},{isNewServer:N});E(Kt.name),M(Kt.type),R(Kt.command??[]),B(Kt.url??""),$(Kt.environment??[]),X(Kt.headers??[]),J(Kt.oauthEnabled??!1),ne(Kt.oauthClientId??""),le(Kt.oauthClientSecret??""),F(Kt.oauthScope??""),W(Kt.oauthRedirectUri??""),K(Kt.timeout??""),ve(Kt.enabled??!0),rt(!1),Xe(""),Te(null),H.success(t("settings.mcp.page.toast.configImported"))},[Re,D,T,S,A,z,V,_,O,Q,G,oe,U,te,ae,N,t]);o.useEffect(()=>{if(N&&i){E(i.name),C(i.scope||"user"),M(i.type),R(i.command),B(i.url),$(i.environment),X(i.headers),J(i.oauthEnabled),ne(i.oauthClientId),le(i.oauthClientSecret),F(i.oauthScope),W(i.oauthRedirectUri),K(i.timeout),ve(i.enabled),de(!1),Qe.current={mcpType:i.type,command:i.command,url:i.url,envEntries:i.environment,headerEntries:i.headers,oauthEnabled:i.oauthEnabled,oauthClientId:i.oauthClientId,oauthClientSecret:i.oauthClientSecret,oauthScope:i.oauthScope,oauthRedirectUri:i.oauthRedirectUri,timeout:i.timeout,enabled:i.enabled};return}if(j){C(j.scope==="project"?"project":"user");const He=Xu(j.environment),kt=j.type==="remote"?j:null,Kt=Xu(kt?.headers),wt=kt?.oauth,Qt=wt&&typeof wt=="object"?wt:null,cs=wt!==!1,Ls=j.type,Ss=Ls==="local"?j.command??[]:[],ns=Ls==="remote"?j.url??"":"",Os=typeof kt?.timeout=="number"&&Number.isFinite(kt.timeout)?String(kt.timeout):"";M(Ls),R(Ss),B(ns),$(He),X(Kt),J(cs),ne(cs?Qt?.clientId??"":""),le(cs?Qt?.clientSecret??"":""),F(cs?Qt?.scope??"":""),W(cs?Qt?.redirectUri??"":""),K(Os),ve(j.enabled),de(!1),Qe.current={mcpType:Ls,command:Ss,url:ns,envEntries:He,headerEntries:Kt,oauthEnabled:cs,oauthClientId:cs?Qt?.clientId??"":"",oauthClientSecret:cs?Qt?.clientSecret??"":"",oauthScope:cs?Qt?.scope??"":"",oauthRedirectUri:cs?Qt?.redirectUri??"":"",timeout:Os,enabled:j.enabled}}},[j,N,i]);const dt=o.useMemo(()=>{const He=Qe.current;return He?S!==He.mcpType||ae!==He.enabled||JSON.stringify(A)!==JSON.stringify(He.command)||z!==He.url||JSON.stringify(V)!==JSON.stringify(He.envEntries)||JSON.stringify(_)!==JSON.stringify(He.headerEntries)||O!==He.oauthEnabled||Q!==He.oauthClientId||G!==He.oauthClientSecret||oe!==He.oauthScope||U!==He.oauthRedirectUri||te!==He.timeout:!1},[S,A,z,V,_,O,Q,G,oe,U,te,ae]),Ye=async()=>{const He=N?D.trim():n??"";if(!He){H.error(t("settings.mcp.page.toast.nameRequired"));return}if(N&&r.some(Kt=>Kt.name===He)){H.error(t("settings.mcp.page.toast.serverNameExists"));return}if(S==="local"&&A.filter(Boolean).length===0){H.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(S==="remote"&&!z.trim()){H.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const kt={name:He,scope:T,type:S,command:A,url:z,environment:V,headers:_,oauthEnabled:O,oauthClientId:Q,oauthClientSecret:G,oauthScope:oe,oauthRedirectUri:U,timeout:te,enabled:ae};be(!0);try{const Kt=N?await d(kt):await p(He,kt);Kt.ok?(await La($e),he(),N&&(a(null),l(He)),await v({directory:u,silent:!0}),Kt.reloadFailed?H.warning(Kt.message||t(N?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Kt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):H.success(Kt.message||t(N?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):H.error(t("settings.mcp.page.toast.saveFailed"))}catch(Kt){H.error(Kt instanceof Error?Kt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{be(!1)}},_e=async()=>{if(!n)return;ue(!0);const He=await m(n);He.ok?(await La($e),he(),He.reloadFailed?H.warning(He.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:He.warning||t("settings.mcp.page.toast.refreshListIfStale")}):H.success(He.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),ye(!1)):H.error(t("settings.mcp.page.toast.deleteFailed")),ue(!1)},et=async()=>{if(n){Ne(!0);try{if(x[n]?.status==="connected")await g(n,u),H.success(t("settings.mcp.page.toast.disconnected"));else{await y(n,u),await v({directory:u,silent:!0});const kt=yn.getState().getStatusForDirectory(u??null)[n];kt?.status==="connected"?H.success(t("settings.mcp.page.toast.connected")):kt?.status==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):kt?.status==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):kt?.status==="failed"?H.error(kt.error||t("settings.mcp.page.toast.connectionFailed")):H.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await v({directory:u,silent:!0})}catch(He){H.error(He instanceof Error?He.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Ne(!1)}}},gt=o.useCallback(()=>N?(H.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):dt?(H.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[dt,N,t]),Lt=o.useCallback(async(He=!1)=>{try{await v({directory:u,silent:He})}catch(kt){He||H.error(kt instanceof Error?kt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,v,t]);o.useEffect(()=>{Lt(!0)},[Lt]),o.useEffect(()=>{Ze.current=We,Ne(!1),me(!1),he()},[he,We]);const Ut=o.useCallback(async()=>{if(!n||S!=="remote"||!gt())return;je(!0);const He=We;let kt=null;try{const Kt=yn.getState().getStatusForDirectory(u??null)[n]?.status;Ae.current=Kt==="needs_auth"||Kt==="needs_client_registration";const wt=xp(n,u);if(!wt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!U.trim()&&!h){const Ss=await p(n,{oauthEnabled:O,oauthClientId:Q,oauthClientSecret:G,oauthScope:oe,oauthRedirectUri:wt});if(!Ss.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(Ss.reloadFailed)throw new Error(Ss.warning||Ss.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(Ze.current!==He)return;W(wt),Qe.current=Qe.current?{...Qe.current,oauthRedirectUri:wt}:Qe.current}const Qt=await w(n,u),cs=Zd(new URL(Qt).searchParams);if(cs&&(kt=cs,await Lk({state:cs,name:n,directory:u})),Ze.current!==He)return;Se(Qt),Pe(cs??null),Y(!0),Ee.current=0;const Ls=await rr(Qt);if(Ze.current!==He)return;Ls?H.message(t(h?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):H.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Kt){await La(kt),Ze.current===He&&H.error(Tc(Kt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{Ze.current===He&&je(!1)}},[u,h,S,Q,G,O,U,oe,gt,We,n,w,t,e,p]),mt=o.useCallback(async()=>{if(!n||!gt())return;ke(!0);const He=We;try{if(await k(n,u),Ze.current!==He)return;Se(null),Pe(null),L(""),Y(!1),Ee.current=0,await La($e),H.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(kt){Ze.current===He&&H.error(Tc(kt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{Ze.current===He&&ke(!1)}},[$e,k,u,gt,We,n,t,e]),Nt=o.useCallback(async()=>{if(!q)return;if((await _n(q)).ok){H.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}H.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[q,t]),Xt=o.useCallback(async()=>{const He=Dk(fe);if(!He.code){H.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const kt=He.stateKey?await Ok(He.stateKey):null,Kt=He.context??kt,wt=Kt?.name??n,Qt=Kt?.directory??u;if(!wt){H.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Kt&&!gt())return;Ue(!0);const cs=We;try{if(await b(wt,He.code,Qt),await La(He.stateKey??$e),Ze.current!==cs)return;L(""),Se(null),Pe(null),Y(!1),Ee.current=0,H.success(wt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:wt}))}catch(Ls){Ze.current===cs&&H.error(Tc(Ls,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{Ze.current===cs&&Ue(!1)}},[fe,$e,b,u,gt,We,n,t,e]),_t=o.useCallback(async()=>{if(!(!n||!gt())){if(!ae){H.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}me(!0);try{const He=await I(n,u),kt=He.status?.status;He.warning?H.warning(He.warning):kt==="connected"?H.success(t("settings.mcp.page.toast.connectionTestSucceeded")):kt==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):kt==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):kt==="failed"?H.error(He.status?.error||He.error||t("settings.mcp.page.toast.connectionTestFailed")):He.error?H.error(He.error):H.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(He){H.error(He instanceof Error?He.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{me(!1)}}},[u,ae,gt,n,t,I]);if(o.useEffect(()=>{if(!Z||!n)return;const He=window.setInterval(()=>{(async()=>{Ee.current+=1,await v({directory:u,silent:!0});const kt=yn.getState().getStatusForDirectory(u??null)[n];if(kt){if(Ae.current&&kt.status!=="needs_auth"&&kt.status!=="needs_client_registration"){Y(!1),Ee.current=0,Ae.current=!1,Se(null),L(""),kt.status==="connected"&&H.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!Ae.current&&kt.status==="failed"){Y(!1),Ee.current=0,Ae.current=!1,H.error(kt.error||t("settings.mcp.page.toast.authorizationFailed"));return}Ee.current>=30&&(Y(!1),Ee.current=0,Ae.current=!1,H.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(He)}},[u,Z,v,n,t]),!n)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(P,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Gt=x[n],lt=n?f[n]:void 0,Tt=Gt??lt,rs=Gt?.status==="connected",js=Gt?.status==="needs_auth"||Gt?.status==="needs_client_registration",ys=h?null:xp(n,u),vs=Ek(Tt?.status,e,Tt&&"error"in Tt?Tt.error:void 0),Wt=He=>{switch(He){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");default:return He}};return s.jsxs(Cs,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[N?s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.mcp.page.header.newServer")}):s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:n}),s.jsx(gp,{status:Tt?.status,enabled:ae,getStatusLabel:Wt,variant:"pill"})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:N?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(S==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!N&&s.jsxs(s.Fragment,{children:[s.jsx(ge,{variant:rs?"outline":"default",size:"xs",className:"!font-normal",onClick:et,disabled:se||!ae,children:t(se?"settings.mcp.page.actions.working":rs?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),S==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(ge,{variant:js?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{Ut()},disabled:Ce||!ae,children:t(Ce?"settings.mcp.page.actions.starting":js?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(ge,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{mt()},disabled:we||!ae,children:t(we?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),rs&&s.jsx(ge,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{_t()},disabled:xe||!ae,children:t(xe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!N&&Fk(Tt?.status,q,js,Z)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:ce("rounded-lg border p-3",Rk(Tt?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(gp,{status:Tt?.status,enabled:ae,getStatusLabel:Wt})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:vs}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:T==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:u??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!rs&&s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_t()},disabled:xe||!ae,children:t(xe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),q&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:q}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rr(q)},children:[s.jsx(P,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nt()},children:[s.jsx(P,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),S==="remote"&&(js||Z||q)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(hn,{value:fe,onChange:He=>L(He.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Xt()},disabled:Me,children:t(Me?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Z&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.server.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[N&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.name")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Bt,{value:D,onChange:He=>E(He.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 font-mono px-2",autoFocus:!0}),s.jsxs(is,{value:T,onValueChange:He=>C(He),children:[s.jsx(as,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:t(T==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:T==="user"?s.jsx(P,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"folder",className:"h-3.5 w-3.5"})}),s.jsxs(os,{align:"end",children:[s.jsx(Ft,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ft,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),N&&s.jsx("div",{className:"py-1.5",children:s.jsxs(ge,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:Ge,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(P,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]})}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ae,onClick:()=>ve(!ae),onKeyDown:He=>{(He.key===" "||He.key==="Enter")&&(He.preventDefault(),ve(!ae))},children:[s.jsx(ds,{checked:ae,onChange:ve,ariaLabel:t("settings.mcp.page.server.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.enable")})]}),s.jsx("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:s.jsxs("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.transportMode")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":S==="local",onClick:()=>M("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":S==="remote",onClick:()=>M("remote"),className:"!font-normal",children:t("settings.mcp.page.transport.remote")})]})]})})]})]}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t(S==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:S==="local"?s.jsx(Tk,{value:A,onChange:R,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:He=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:He}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:He=>t("settings.mcp.page.connection.previewArgs",{count:He})}):s.jsx(Bt,{value:z,onChange:He=>B(He.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),S==="remote"&&s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.advanced.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs(fr,{open:Je,onOpenChange:de,children:[s.jsxs(Pr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",t(O?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",_.length," ",t("settings.mcp.page.advanced.headers"),te?` · ${te}ms`:"",")"]})]}),Je?s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(hr,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.advanced.timeoutMs")})}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Bt,{type:"number",min:"1",step:"1",value:te,onChange:He=>K(He.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground sm:pl-64",children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-2 typography-ui-label text-foreground",children:[t("settings.mcp.page.advanced.requestHeaders"),_.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",_.length,")"]})]}),s.jsx(hp,{value:_,onChange:X,keyTransform:He=>He.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:He=>t("settings.mcp.page.toast.importedVariablesCount",{count:He}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":O,onClick:()=>J(!O),onKeyDown:He=>{(He.key===" "||He.key==="Enter")&&(He.preventDefault(),J(!O))},children:[s.jsx(ds,{checked:O,onChange:J,ariaLabel:t("settings.mcp.page.advanced.oauthAutoDetectionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.advanced.oauthAutoDetection")})]}),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsx(Bt,{value:Q,onChange:He=>ne(He.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!O,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Bt,{value:G,onChange:He=>le(He.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!O,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Bt,{value:oe,onChange:He=>F(He.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!O,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Bt,{value:U,onChange:He=>W(He.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!O,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),ys&&s.jsxs("p",{className:"typography-micro text-muted-foreground",children:[t("settings.mcp.page.advanced.oauthCallbackHint"),s.jsx("span",{className:"mt-1 block break-all font-mono text-foreground/80",children:ys})]})]})]})})]})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.mcp.page.env.title"),V.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",V.length,")"]})]})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:V.length===0?s.jsxs(ge,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>$([{key:"",value:""}]),children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(hp,{value:V,onChange:$,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:He=>t("settings.mcp.page.toast.importedVariablesCount",{count:He}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})})]}),s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[s.jsx(ge,{onClick:Ye,disabled:re||!dt&&!N,size:"xs",className:"!font-normal",children:t(re?"settings.common.actions.saving":N?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!N&&s.jsx(ge,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ye(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(hs,{open:ze,onOpenChange:He=>{He||(rt(!1),Xe(""),Te(null))},children:s.jsxs(fs,{className:"max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Is,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(hn,{value:Re,onChange:He=>{Xe(He.target.value),Te(null)},placeholder:`{
|
|
169
|
+
"mcpServers": {
|
|
170
|
+
"postgres": {
|
|
171
|
+
"command": "npx",
|
|
172
|
+
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),qe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:qe}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(ge,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ve,type:"button",children:[s.jsx(P,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Vs,{children:[s.jsx(ge,{variant:"outline",onClick:()=>{rt(!1),Xe(""),Te(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(ge,{onClick:it,disabled:!Re.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(hs,{open:pe,onOpenChange:He=>{!He&&!ie&&ye(!1)},children:s.jsxs(fs,{className:"max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Is,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Vs,{children:[s.jsx(ge,{variant:"outline",onClick:()=>ye(!1),disabled:ie,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(ge,{variant:"destructive",size:"sm",onClick:_e,disabled:ie,children:t(ie?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},zk=t=>{const e=at.c(150),{onItemSelect:n}=t,{t:r}=ut(),[i,a]=o.useState(null),[l,c]=o.useState(""),[d,p]=o.useState(null),[m,u]=o.useState(!1),[h,x]=o.useState(null),{selectedSkillName:f,skills:v,setSelectedSkill:y,setSkillDraft:g,createSkill:w,deleteSkill:b,getSkillDetail:k}=fi(Br(Vk));let I;e[0]!==n||e[1]!==y||e[2]!==g||e[3]!==v?(I=()=>{let Ve="new-skill",it=1;for(;v.some(dt=>dt.name===Ve);)Ve=`new-skill-${it}`,it++;g({name:Ve,scope:"user",source:"opencode",description:""}),y(Ve),n?.()},e[0]=n,e[1]=y,e[2]=g,e[3]=v,e[4]=I):I=e[4];const j=I;let N;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=async Ve=>{p(Ve)},e[5]=N):N=e[5];const D=N;let E;e[6]!==d||e[7]!==b||e[8]!==r?(E=async()=>{if(!d)return;u(!0),await b(d.name)?(H.success(r("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),p(null)):H.error(r("settings.skills.sidebar.toast.deleteSkillFailed")),u(!1)},e[6]=d,e[7]=b,e[8]=r,e[9]=E):E=e[9];const T=E;let C;e[10]!==k||e[11]!==y||e[12]!==g||e[13]!==v||e[14]!==r?(C=async Ve=>{const it=Ve.name;let dt=1,Ye=`${it}-copy`;for(;v.some(et=>et.name===Ye);)dt++,Ye=`${it}-copy-${dt}`;const _e=await k(Ve.name);if(!_e){H.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}g({name:Ye,scope:Ve.scope||"user",source:Ve.source||"opencode",description:(_e.sources.md.fields.includes("description"),""),instructions:""}),y(Ye)},e[10]=k,e[11]=y,e[12]=g,e[13]=v,e[14]=r,e[15]=C):C=e[15];const S=C;let M;e[16]===Symbol.for("react.memo_cache_sentinel")?(M=Ve=>{c(Ve.name),a(Ve)},e[16]=M):M=e[16];const A=M;let R;e[17]!==w||e[18]!==b||e[19]!==k||e[20]!==i||e[21]!==l||e[22]!==y||e[23]!==v||e[24]!==r?(R=async()=>{if(!i)return;const Ve=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Ve){H.error(r("settings.skills.page.toast.skillNameRequired"));return}if(Ve===i.name){a(null);return}if(v.some(Ye=>Ye.name===Ve)){H.error(r("settings.skills.page.toast.skillExists"));return}if(!await k(i.name)){H.error(r("settings.skills.sidebar.toast.renameLoadFailed")),a(null);return}await w({name:Ve,description:"Renamed skill",scope:i.scope,source:i.source})?await b(i.name)?(H.success(`Skill renamed to "${Ve}"`),y(Ve)):H.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):H.error(r("settings.skills.sidebar.toast.renameFailed")),a(null)},e[17]=w,e[18]=b,e[19]=k,e[20]=i,e[21]=l,e[22]=y,e[23]=v,e[24]=r,e[25]=R):R=e[25];const z=R;let B;e[26]!==v?(B=v.filter(_k),e[26]=v,e[27]=B):B=e[27];const V=B;let $;e[28]!==v?($=v.filter(Uk),e[28]=v,e[29]=$):$=e[29];const _=$;let X;e[30]===Symbol.for("react.memo_cache_sentinel")?(X=function(it){const dt={},Ye=[];for(const et of it)et.group?(dt[et.group]||(dt[et.group]=[]),dt[et.group].push(et)):Ye.push(et);const _e=Object.keys(dt).sort(Wk).map(et=>({name:et,skills:[...dt[et]].sort(Kk)}));return Ye.sort(Hk),{sortedGroups:_e,ungrouped:Ye}},e[30]=X):X=e[30];const O=X;let J;e[31]!==V?(J=O(V),e[31]=V,e[32]=J):J=e[32];const Q=J;let ne;e[33]!==_?(ne=O(_),e[33]=_,e[34]=ne):ne=e[34];const G=ne;let le;e[35]===Symbol.for("react.memo_cache_sentinel")?(le=ce("flex h-full flex-col","bg-background"),e[35]=le):le=e[35];let oe;e[36]!==r?(oe=r("settings.skills.sidebar.title"),e[36]=r,e[37]=oe):oe=e[37];let F;e[38]!==oe?(F=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:oe}),e[38]=oe,e[39]=F):F=e[39];let U;e[40]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(vo,{className:"mb-3"}),e[40]=U):U=e[40];let W;e[41]!==v.length||e[42]!==r?(W=r("settings.skills.sidebar.total",{count:v.length}),e[41]=v.length,e[42]=r,e[43]=W):W=e[43];let te;e[44]!==W?(te=s.jsx("span",{className:"typography-meta text-muted-foreground",children:W}),e[44]=W,e[45]=te):te=e[45];let K;e[46]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),e[46]=K):K=e[46];let ae;e[47]!==j?(ae=s.jsx(ge,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:K}),e[47]=j,e[48]=ae):ae=e[48];let ve;e[49]!==te||e[50]!==ae?(ve=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[te,ae]}),e[49]=te,e[50]=ae,e[51]=ve):ve=e[51];let re;e[52]!==F||e[53]!==ve?(re=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[F,U,ve]}),e[52]=F,e[53]=ve,e[54]=re):re=e[54];let be;e[55]!==Q||e[56]!==G||e[57]!==S||e[58]!==n||e[59]!==h||e[60]!==V||e[61]!==f||e[62]!==y||e[63]!==v.length||e[64]!==r||e[65]!==_?(be=s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(P,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[V.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.project")}),Q.sortedGroups.map(Ve=>{const{name:it,skills:dt}=Ve;return s.jsx(bd,{label:it,count:dt.length,storageKey:"project-skills",children:dt.map(Ye=>s.jsx(Bo,{skill:Ye,isSelected:f===Ye.name,onSelect:()=>{y(Ye.name),n?.()},onRename:()=>A(Ye),onDelete:()=>D(Ye),onDuplicate:()=>S(Ye),isMenuOpen:h===Ye.name,onMenuOpenChange:_e=>x(_e?Ye.name:null)},Ye.name))},it)}),Q.ungrouped.map(Ve=>s.jsx(Bo,{skill:Ve,isSelected:f===Ve.name,onSelect:()=>{y(Ve.name),n?.()},onRename:()=>A(Ve),onDelete:()=>D(Ve),onDuplicate:()=>S(Ve),isMenuOpen:h===Ve.name,onMenuOpenChange:it=>x(it?Ve.name:null)},Ve.name))]}),_.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.user")}),G.sortedGroups.map(Ve=>{const{name:it,skills:dt}=Ve;return s.jsx(bd,{label:it,count:dt.length,storageKey:"user-skills",children:dt.map(Ye=>s.jsx(Bo,{skill:Ye,isSelected:f===Ye.name,onSelect:()=>{y(Ye.name),n?.()},onRename:()=>A(Ye),onDelete:()=>D(Ye),onDuplicate:()=>S(Ye),isMenuOpen:h===Ye.name,onMenuOpenChange:_e=>x(_e?Ye.name:null)},Ye.name))},it)}),G.ungrouped.map(Ve=>s.jsx(Bo,{skill:Ve,isSelected:f===Ve.name,onSelect:()=>{y(Ve.name),n?.()},onRename:()=>A(Ve),onDelete:()=>D(Ve),onDuplicate:()=>S(Ve),isMenuOpen:h===Ve.name,onMenuOpenChange:it=>x(it?Ve.name:null)},Ve.name))]})]})}),e[55]=Q,e[56]=G,e[57]=S,e[58]=n,e[59]=h,e[60]=V,e[61]=f,e[62]=y,e[63]=v.length,e[64]=r,e[65]=_,e[66]=be):be=e[66];const pe=d!==null;let ye;e[67]!==m?(ye=Ve=>{!Ve&&!m&&p(null)},e[67]=m,e[68]=ye):ye=e[68];let ie;e[69]!==r?(ie=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=ie):ie=e[70];let ue;e[71]!==ie?(ue=s.jsx(gs,{children:ie}),e[71]=ie,e[72]=ue):ue=e[72];const se=d?.name??"";let Ne;e[73]!==r||e[74]!==se?(Ne=r("settings.skills.sidebar.deleteDialog.description",{name:se}),e[73]=r,e[74]=se,e[75]=Ne):Ne=e[75];let Ce;e[76]!==Ne?(Ce=s.jsx(Is,{children:Ne}),e[76]=Ne,e[77]=Ce):Ce=e[77];let je;e[78]!==ue||e[79]!==Ce?(je=s.jsxs(bs,{children:[ue,Ce]}),e[78]=ue,e[79]=Ce,e[80]=je):je=e[80];let we;e[81]===Symbol.for("react.memo_cache_sentinel")?(we=()=>p(null),e[81]=we):we=e[81];let ke;e[82]!==r?(ke=r("settings.common.actions.cancel"),e[82]=r,e[83]=ke):ke=e[83];let xe;e[84]!==m||e[85]!==ke?(xe=s.jsx(ge,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:we,disabled:m,children:ke}),e[84]=m,e[85]=ke,e[86]=xe):xe=e[86];let me;e[87]!==r?(me=r("settings.common.actions.delete"),e[87]=r,e[88]=me):me=e[88];let Me;e[89]!==T||e[90]!==m||e[91]!==me?(Me=s.jsx(ge,{size:"sm",onClick:T,disabled:m,children:me}),e[89]=T,e[90]=m,e[91]=me,e[92]=Me):Me=e[92];let Ue;e[93]!==xe||e[94]!==Me?(Ue=s.jsxs(Vs,{children:[xe,Me]}),e[93]=xe,e[94]=Me,e[95]=Ue):Ue=e[95];let q;e[96]!==je||e[97]!==Ue?(q=s.jsxs(fs,{className:"max-w-md",children:[je,Ue]}),e[96]=je,e[97]=Ue,e[98]=q):q=e[98];let Se;e[99]!==pe||e[100]!==ye||e[101]!==q?(Se=s.jsx(hs,{open:pe,onOpenChange:ye,children:q}),e[99]=pe,e[100]=ye,e[101]=q,e[102]=Se):Se=e[102];const $e=i!==null;let Pe;e[103]===Symbol.for("react.memo_cache_sentinel")?(Pe=Ve=>!Ve&&a(null),e[103]=Pe):Pe=e[103];let fe;e[104]!==r?(fe=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=fe):fe=e[105];let L;e[106]!==fe?(L=s.jsx(gs,{children:fe}),e[106]=fe,e[107]=L):L=e[107];const Z=i?.name??"";let Y;e[108]!==r||e[109]!==Z?(Y=r("settings.skills.sidebar.renameDialog.description",{name:Z}),e[108]=r,e[109]=Z,e[110]=Y):Y=e[110];let Ee;e[111]!==Y?(Ee=s.jsx(Is,{children:Y}),e[111]=Y,e[112]=Ee):Ee=e[112];let Ae;e[113]!==L||e[114]!==Ee?(Ae=s.jsxs(bs,{children:[L,Ee]}),e[113]=L,e[114]=Ee,e[115]=Ae):Ae=e[115];let Je;e[116]===Symbol.for("react.memo_cache_sentinel")?(Je=Ve=>c(Ve.target.value),e[116]=Je):Je=e[116];let de;e[117]!==r?(de=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=de):de=e[118];let ze;e[119]!==z?(ze=Ve=>{Ve.key==="Enter"&&z()},e[119]=z,e[120]=ze):ze=e[120];let rt;e[121]!==l||e[122]!==de||e[123]!==ze?(rt=s.jsx(Bt,{value:l,onChange:Je,placeholder:de,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:ze}),e[121]=l,e[122]=de,e[123]=ze,e[124]=rt):rt=e[124];let Re;e[125]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>a(null),e[125]=Re):Re=e[125];let Xe;e[126]!==r?(Xe=r("settings.common.actions.cancel"),e[126]=r,e[127]=Xe):Xe=e[127];let qe;e[128]!==Xe?(qe=s.jsx(ge,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Re,children:Xe}),e[128]=Xe,e[129]=qe):qe=e[129];let Te;e[130]!==r?(Te=r("settings.common.actions.rename"),e[130]=r,e[131]=Te):Te=e[131];let We;e[132]!==z||e[133]!==Te?(We=s.jsx(ge,{size:"sm",onClick:z,children:Te}),e[132]=z,e[133]=Te,e[134]=We):We=e[134];let Ze;e[135]!==qe||e[136]!==We?(Ze=s.jsxs(Vs,{children:[qe,We]}),e[135]=qe,e[136]=We,e[137]=Ze):Ze=e[137];let Qe;e[138]!==Ae||e[139]!==rt||e[140]!==Ze?(Qe=s.jsxs(fs,{children:[Ae,rt,Ze]}),e[138]=Ae,e[139]=rt,e[140]=Ze,e[141]=Qe):Qe=e[141];let he;e[142]!==$e||e[143]!==Qe?(he=s.jsx(hs,{open:$e,onOpenChange:Pe,children:Qe}),e[142]=$e,e[143]=Qe,e[144]=he):he=e[144];let Ge;return e[145]!==re||e[146]!==be||e[147]!==Se||e[148]!==he?(Ge=s.jsxs("div",{className:le,children:[re,be,Se,he]}),e[145]=re,e[146]=be,e[147]=Se,e[148]=he,e[149]=Ge):Ge=e[149],Ge},Bo=t=>{const e=at.c(61),{skill:n,isSelected:r,onSelect:i,onDelete:a,onRename:l,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=ut();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=no(),e[0]=u):u=e[0];const h=u;let x;e[1]!==n.source||e[2]!==m?(x=n.source==="claude"?m("settings.skills.sidebar.badge.claude"):n.source==="agents"?m("settings.skills.sidebar.badge.agents"):m("settings.skills.sidebar.badge.opencode"),e[1]=n.source,e[2]=m,e[3]=x):x=e[3];const f=x,v=r?"bg-interactive-selection":"hover:bg-interactive-hover";let y;e[4]!==v?(y=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",v),e[4]=v,e[5]=y):y=e[5];let g;e[6]!==p?(g=h?void 0:Q=>{Q.preventDefault(),p(!0)},e[6]=p,e[7]=g):g=e[7];let w;e[8]!==n.name?(w=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[8]=n.name,e[9]=w):w=e[9];let b;e[10]!==n.scope?(b=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:n.scope}),e[10]=n.scope,e[11]=b):b=e[11];let k;e[12]!==f?(k=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:f}),e[12]=f,e[13]=k):k=e[13];let I;e[14]!==w||e[15]!==b||e[16]!==k?(I=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,b,k]}),e[14]=w,e[15]=b,e[16]=k,e[17]=I):I=e[17];let j;e[18]!==i||e[19]!==I?(j=s.jsx("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:I}),e[18]=i,e[19]=I,e[20]=j):j=e[20];let N;e[21]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(Es,{asChild:!0,children:s.jsx(ge,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(P,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[21]=N):N=e[21];let D;e[22]!==l?(D=Q=>{Q.stopPropagation(),l()},e[22]=l,e[23]=D):D=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(P,{name:"edit",className:"h-4 w-4 mr-px"}),e[24]=E):E=e[24];let T;e[25]!==m?(T=m("settings.common.actions.rename"),e[25]=m,e[26]=T):T=e[26];let C;e[27]!==D||e[28]!==T?(C=s.jsxs($t,{onClick:D,children:[E,T]}),e[27]=D,e[28]=T,e[29]=C):C=e[29];let S;e[30]!==c?(S=Q=>{Q.stopPropagation(),c()},e[30]=c,e[31]=S):S=e[31];let M;e[32]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(P,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[32]=M):M=e[32];let A;e[33]!==m?(A=m("settings.common.actions.duplicate"),e[33]=m,e[34]=A):A=e[34];let R;e[35]!==S||e[36]!==A?(R=s.jsxs($t,{onClick:S,children:[M,A]}),e[35]=S,e[36]=A,e[37]=R):R=e[37];let z;e[38]!==a?(z=Q=>{Q.stopPropagation(),a()},e[38]=a,e[39]=z):z=e[39];let B;e[40]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(P,{name:"delete-bin",className:"h-4 w-4 mr-px"}),e[40]=B):B=e[40];let V;e[41]!==m?(V=m("settings.common.actions.delete"),e[41]=m,e[42]=V):V=e[42];let $;e[43]!==z||e[44]!==V?($=s.jsxs($t,{onClick:z,className:"text-destructive focus:text-destructive",children:[B,V]}),e[43]=z,e[44]=V,e[45]=$):$=e[45];let _;e[46]!==C||e[47]!==R||e[48]!==$?(_=s.jsxs(Rs,{align:"end",className:"w-fit min-w-20",children:[C,R,$]}),e[46]=C,e[47]=R,e[48]=$,e[49]=_):_=e[49];let X;e[50]!==d||e[51]!==p||e[52]!==_?(X=s.jsxs(Fs,{open:d,onOpenChange:p,children:[N,_]}),e[50]=d,e[51]=p,e[52]=_,e[53]=X):X=e[53];let O;e[54]!==j||e[55]!==X?(O=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[j,X]}),e[54]=j,e[55]=X,e[56]=O):O=e[56];let J;return e[57]!==O||e[58]!==y||e[59]!==g?(J=s.jsx("div",{className:y,onContextMenu:g,children:O}),e[57]=O,e[58]=y,e[59]=g,e[60]=J):J=e[60],J};function Vk(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function _k(t){return t.scope==="project"}function Uk(t){return t.scope==="user"}function Wk(t,e){return t.localeCompare(e)}function Kk(t,e){return t.name.localeCompare(e.name)}function Hk(t,e){return t.name.localeCompare(e.name)}const Gk=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,qk=t=>{const e=t.trim(),n=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(n==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(n==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const r=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return r?`${r[1]}/${r[2].replace(/\.git$/i,"")}`:e},Yk=async()=>{try{const t=pr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Qk=t=>{const e=at.c(158),{open:n,onOpenChange:r}=t,{t:i}=ut(),a=Ri(Jk),l=Ri(Xk),c=Ri(Zk),d=Qn(e3),p=Qn(t3),[m,u]=o.useState(""),[h,x]=o.useState(""),[f,v]=o.useState("");let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=[],e[0]=y):y=e[0];const[g,w]=o.useState(y),[b,k]=o.useState(null),[I,j]=o.useState(!1);let N;e[1]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[1]=N):N=e[1];const[D,E]=o.useState(N),[T,C]=o.useState(null),S=o.useRef(0);let M;e[2]===Symbol.for("react.memo_cache_sentinel")?(M=he=>{S.current=S.current+1,j(!1),k(null),he?.clearIdentity&&(E([]),C(null))},e[2]=M):M=e[2];const A=M;let R,z;e[3]!==p||e[4]!==n?(R=()=>{n&&(S.current=S.current+1,u(""),x(""),v(""),k(null),j(!1),E([]),C(null),p(),(async()=>{const he=await Yk(),Ge=Array.isArray(he?.skillCatalogs)?he?.skillCatalogs:[];w(Ge||[])})())},z=[n,p],e[3]=p,e[4]=n,e[5]=R,e[6]=z):(R=e[5],z=e[6]),o.useEffect(R,z);let B;e[7]!==h?(B=h.trim(),e[7]=h,e[8]=B):B=e[8];const V=B;let $;e[9]!==f?($=f.trim(),e[9]=f,e[10]=$):$=e[10];const _=$;let X;if(e[11]!==g||e[12]!==V||e[13]!==_){let he;e[15]!==V||e[16]!==_?(he=Ge=>{const Ve=(Ge.source||"").trim(),it=(Ge.subpath||"").trim();return Ve===V&&it===_},e[15]=V,e[16]=_,e[17]=he):he=e[17],X=g.some(he),e[11]=g,e[12]=V,e[13]=_,e[14]=X}else X=e[14];const O=X;let J;e[18]!==d||e[19]!==T||e[20]!==m||e[21]!==a||e[22]!==h||e[23]!==f||e[24]!==i?(J=async()=>{const he=h.trim();if(!he){H.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(qk(he)),j(!1),k(null);const Ge=S.current+1;S.current=Ge;const Ve=await a({source:he,subpath:f.trim()||void 0,gitIdentityId:T||void 0});if(S.current!==Ge)return;if(!Ve.ok){if(Ve.error?.kind==="authRequired"){if(mn()){H.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const dt=Ve.error.identities||[];if(E(dt),!T&&dt.length>0){const Ye=d&&d!=="global"&&dt.some(_e=>_e.id===d)?d:dt[0].id;C(Ye)}H.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}H.error(Ve.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const it=Ve.items?.length||0;if(k(it),it===0){H.error(i("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}E([]),j(!0),H.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:it}))},e[18]=d,e[19]=T,e[20]=m,e[21]=a,e[22]=h,e[23]=f,e[24]=i,e[25]=J):J=e[25];const Q=J;let ne;e[26]!==g||e[27]!==T||e[28]!==O||e[29]!==m||e[30]!==l||e[31]!==r||e[32]!==I||e[33]!==h||e[34]!==f||e[35]!==i?(ne=async()=>{const he=m.trim(),Ge=h.trim(),Ve=f.trim();if(!he){H.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!Ge){H.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!I){H.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(O){H.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const it={id:Gk(),label:he,source:Ge,...Ve?{subpath:Ve}:{},...T?{gitIdentityId:T}:{}},dt=[...g,it];try{await ks({skillCatalogs:dt}),w(dt),H.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),r(!1)}catch(Ye){const _e=Ye;H.error(_e instanceof Error?_e.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=g,e[27]=T,e[28]=O,e[29]=m,e[30]=l,e[31]=r,e[32]=I,e[33]=h,e[34]=f,e[35]=i,e[36]=ne):ne=e[36];const G=ne;let le;e[37]!==i?(le=i("settings.skills.catalog.add.title"),e[37]=i,e[38]=le):le=e[38];let oe;e[39]!==le?(oe=s.jsx(gs,{children:le}),e[39]=le,e[40]=oe):oe=e[40];let F;e[41]!==i?(F=i("settings.skills.catalog.add.descriptionPrefix"),e[41]=i,e[42]=F):F=e[42];let U;e[43]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[43]=U):U=e[43];let W;e[44]!==i?(W=i("settings.skills.catalog.add.descriptionSuffix"),e[44]=i,e[45]=W):W=e[45];let te;e[46]!==F||e[47]!==W?(te=s.jsxs(Is,{children:[F," ",U,W]}),e[46]=F,e[47]=W,e[48]=te):te=e[48];let K;e[49]!==oe||e[50]!==te?(K=s.jsxs(bs,{children:[oe,te]}),e[49]=oe,e[50]=te,e[51]=K):K=e[51];let ae;e[52]!==i?(ae=i("settings.skills.catalog.add.field.catalogName"),e[52]=i,e[53]=ae):ae=e[53];let ve;e[54]!==ae?(ve=s.jsx("label",{className:"typography-ui-label text-foreground",children:ae}),e[54]=ae,e[55]=ve):ve=e[55];let re;e[56]===Symbol.for("react.memo_cache_sentinel")?(re=he=>u(he.target.value),e[56]=re):re=e[56];let be;e[57]!==i?(be=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=i,e[58]=be):be=e[58];let pe;e[59]!==m||e[60]!==be?(pe=s.jsx(Bt,{value:m,onChange:re,placeholder:be}),e[59]=m,e[60]=be,e[61]=pe):pe=e[61];let ye;e[62]!==ve||e[63]!==pe?(ye=s.jsxs("div",{className:"space-y-2",children:[ve,pe]}),e[62]=ve,e[63]=pe,e[64]=ye):ye=e[64];let ie;e[65]!==i?(ie=i("settings.skills.catalog.add.field.repository"),e[65]=i,e[66]=ie):ie=e[66];let ue;e[67]!==ie?(ue=s.jsx("label",{className:"typography-ui-label text-foreground",children:ie}),e[67]=ie,e[68]=ue):ue=e[68];let se;e[69]===Symbol.for("react.memo_cache_sentinel")?(se=he=>{x(he.target.value),A({clearIdentity:!0})},e[69]=se):se=e[69];let Ne;e[70]!==i?(Ne=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[70]=i,e[71]=Ne):Ne=e[71];let Ce;e[72]!==h||e[73]!==Ne?(Ce=s.jsx(Bt,{value:h,onChange:se,placeholder:Ne}),e[72]=h,e[73]=Ne,e[74]=Ce):Ce=e[74];let je;e[75]!==i?(je=i("settings.skills.catalog.add.field.repositoryHint"),e[75]=i,e[76]=je):je=e[76];let we;e[77]!==je?(we=s.jsx("p",{className:"typography-micro text-muted-foreground",children:je}),e[77]=je,e[78]=we):we=e[78];let ke;e[79]!==ue||e[80]!==Ce||e[81]!==we?(ke=s.jsxs("div",{className:"space-y-2",children:[ue,Ce,we]}),e[79]=ue,e[80]=Ce,e[81]=we,e[82]=ke):ke=e[82];let xe;e[83]!==i?(xe=i("settings.skills.catalog.add.field.optionalSubpath"),e[83]=i,e[84]=xe):xe=e[84];let me;e[85]!==xe?(me=s.jsx("label",{className:"typography-ui-label text-foreground",children:xe}),e[85]=xe,e[86]=me):me=e[86];let Me;e[87]===Symbol.for("react.memo_cache_sentinel")?(Me=he=>{v(he.target.value),A({clearIdentity:!0})},e[87]=Me):Me=e[87];let Ue;e[88]!==i?(Ue=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=i,e[89]=Ue):Ue=e[89];let q;e[90]!==f||e[91]!==Ue?(q=s.jsx(Bt,{value:f,onChange:Me,placeholder:Ue}),e[90]=f,e[91]=Ue,e[92]=q):q=e[92];let Se;e[93]!==me||e[94]!==q?(Se=s.jsxs("div",{className:"space-y-2",children:[me,q]}),e[93]=me,e[94]=q,e[95]=Se):Se=e[95];let $e;e[96]!==T||e[97]!==D||e[98]!==i?($e=D.length>0&&!mn()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:i("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:i("settings.skills.catalog.shared.auth.description")})]}),s.jsxs(is,{value:T||"",onValueChange:he=>{C(he),A()},children:[s.jsx(as,{className:"w-fit",children:s.jsx("span",{children:D.find(he=>he.id===T)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(os,{align:"start",children:D.map(s3)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:i("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=T,e[97]=D,e[98]=i,e[99]=$e):$e=e[99];let Pe;e[100]!==b||e[101]!==i?(Pe=b!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:b})}):null,e[100]=b,e[101]=i,e[102]=Pe):Pe=e[102];let fe;e[103]!==O||e[104]!==i?(fe=O?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=O,e[104]=i,e[105]=fe):fe=e[105];let L;e[106]!==ye||e[107]!==ke||e[108]!==Se||e[109]!==$e||e[110]!==Pe||e[111]!==fe?(L=s.jsxs("div",{className:"space-y-4",children:[ye,ke,Se,$e,Pe,fe]}),e[106]=ye,e[107]=ke,e[108]=Se,e[109]=$e,e[110]=Pe,e[111]=fe,e[112]=L):L=e[112];let Z;e[113]!==r?(Z=()=>r(!1),e[113]=r,e[114]=Z):Z=e[114];let Y;e[115]!==i?(Y=i("settings.common.actions.cancel"),e[115]=i,e[116]=Y):Y=e[116];let Ee;e[117]!==Z||e[118]!==Y?(Ee=s.jsx(ge,{size:"sm",variant:"ghost",onClick:Z,children:Y}),e[117]=Z,e[118]=Y,e[119]=Ee):Ee=e[119];let Ae;e[120]!==Q?(Ae=()=>{Q()},e[120]=Q,e[121]=Ae):Ae=e[121];let Je;e[122]!==c||e[123]!==h?(Je=c||!h.trim(),e[122]=c,e[123]=h,e[124]=Je):Je=e[124];let de;e[125]===Symbol.for("react.memo_cache_sentinel")?(de=s.jsx(P,{name:"git-repository",className:"h-4 w-4"}),e[125]=de):de=e[125];let ze;e[126]!==c||e[127]!==i?(ze=i(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=i,e[128]=ze):ze=e[128];let rt;e[129]!==Ae||e[130]!==Je||e[131]!==ze?(rt=s.jsxs(ge,{size:"sm",className:"gap-2",variant:"ghost",onClick:Ae,disabled:Je,children:[de,ze]}),e[129]=Ae,e[130]=Je,e[131]=ze,e[132]=rt):rt=e[132];let Re;e[133]!==G?(Re=()=>{G()},e[133]=G,e[134]=Re):Re=e[134];let Xe;e[135]!==O||e[136]!==m||e[137]!==I||e[138]!==h?(Xe=!I||O||!m.trim()||!h.trim(),e[135]=O,e[136]=m,e[137]=I,e[138]=h,e[139]=Xe):Xe=e[139];let qe;e[140]!==i?(qe=i("settings.skills.catalog.add.actions.addCatalog"),e[140]=i,e[141]=qe):qe=e[141];let Te;e[142]!==Re||e[143]!==Xe||e[144]!==qe?(Te=s.jsx(ge,{size:"sm",onClick:Re,disabled:Xe,children:qe}),e[142]=Re,e[143]=Xe,e[144]=qe,e[145]=Te):Te=e[145];let We;e[146]!==Ee||e[147]!==rt||e[148]!==Te?(We=s.jsxs(Vs,{children:[Ee,rt,Te]}),e[146]=Ee,e[147]=rt,e[148]=Te,e[149]=We):We=e[149];let Ze;e[150]!==K||e[151]!==L||e[152]!==We?(Ze=s.jsxs(fs,{className:"max-w-xl",children:[K,L,We]}),e[150]=K,e[151]=L,e[152]=We,e[153]=Ze):Ze=e[153];let Qe;return e[154]!==r||e[155]!==n||e[156]!==Ze?(Qe=s.jsx(hs,{open:n,onOpenChange:r,children:Ze}),e[154]=r,e[155]=n,e[156]=Ze,e[157]=Qe):Qe=e[157],Qe};function Jk(t){return t.scanRepo}function Xk(t){return t.loadCatalog}function Zk(t){return t.isScanning}function e3(t){return t.defaultGitIdentityId}function t3(t){return t.loadDefaultGitIdentityId}function s3(t){return s.jsx(Ft,{value:t.id,children:t.name},t.id)}const n3=t=>{const e=at.c(85),{open:n,onOpenChange:r,conflicts:i,onConfirm:a}=t,{t:l}=ut();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[d,p]=o.useState(c);let m,u;e[1]!==i||e[2]!==n?(m=()=>{if(!n)return;const oe={};for(const F of i)oe[F.skillName]="skip";p(oe)},u=[n,i],e[1]=i,e[2]=n,e[3]=m,e[4]=u):(m=e[3],u=e[4]),o.useEffect(m,u);let h;e[5]!==i?(h=oe=>{const F={};for(const U of i)F[U.skillName]=oe;p(F)},e[5]=i,e[6]=h):h=e[6];const x=h;let f;e[7]!==i||e[8]!==d?(f=i.length>0&&i.every(oe=>d[oe.skillName]),e[7]=i,e[8]=d,e[9]=f):f=e[9];const v=f;let y;e[10]!==l?(y=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=y):y=e[11];let g;e[12]!==y?(g=s.jsx(gs,{children:y}),e[12]=y,e[13]=g):g=e[13];let w;e[14]!==l?(w=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=w):w=e[15];let b;e[16]!==w?(b=s.jsx(Is,{children:w}),e[16]=w,e[17]=b):b=e[17];let k;e[18]!==g||e[19]!==b?(k=s.jsxs(bs,{children:[g,b]}),e[18]=g,e[19]=b,e[20]=k):k=e[20];let I;e[21]!==i.length||e[22]!==l?(I=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=l,e[23]=I):I=e[23];let j;e[24]!==I?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[24]=I,e[25]=j):j=e[25];let N;e[26]!==x?(N=()=>x("skip"),e[26]=x,e[27]=N):N=e[27];let D;e[28]!==l?(D=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=D):D=e[29];let E;e[30]!==N||e[31]!==D?(E=s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:N,children:D}),e[30]=N,e[31]=D,e[32]=E):E=e[32];let T;e[33]!==x?(T=()=>x("overwrite"),e[33]=x,e[34]=T):T=e[34];let C;e[35]!==l?(C=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=C):C=e[36];let S;e[37]!==T||e[38]!==C?(S=s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:T,children:C}),e[37]=T,e[38]=C,e[39]=S):S=e[39];let M;e[40]!==E||e[41]!==S?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[E,S]}),e[40]=E,e[41]=S,e[42]=M):M=e[42];let A;e[43]!==j||e[44]!==M?(A=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,M]}),e[43]=j,e[44]=M,e[45]=A):A=e[45];let R;if(e[46]!==i||e[47]!==d||e[48]!==l){let oe;e[50]!==d||e[51]!==l?(oe=F=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:F.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:F.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:F.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(is,{value:d[F.skillName]||"skip",onValueChange:U=>p(W=>({...W,[F.skillName]:U})),children:[s.jsx(as,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[F.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(os,{align:"end",children:[s.jsx(Ft,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Ft,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},F.skillName),e[50]=d,e[51]=l,e[52]=oe):oe=e[52],R=i.map(oe),e[46]=i,e[47]=d,e[48]=l,e[49]=R}else R=e[49];let z;e[53]!==R?(z=s.jsx("div",{className:"space-y-2",children:R}),e[53]=R,e[54]=z):z=e[54];let B;e[55]!==A||e[56]!==z?(B=s.jsxs("div",{className:"space-y-3",children:[A,z]}),e[55]=A,e[56]=z,e[57]=B):B=e[57];let V;e[58]!==r?(V=()=>r(!1),e[58]=r,e[59]=V):V=e[59];let $;e[60]!==l?($=l("settings.common.actions.cancel"),e[60]=l,e[61]=$):$=e[61];let _;e[62]!==V||e[63]!==$?(_=s.jsx(ge,{size:"sm",variant:"ghost",onClick:V,children:$}),e[62]=V,e[63]=$,e[64]=_):_=e[64];let X;e[65]!==d||e[66]!==a?(X=()=>a(d),e[65]=d,e[66]=a,e[67]=X):X=e[67];const O=!v;let J;e[68]!==l?(J=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=J):J=e[69];let Q;e[70]!==X||e[71]!==O||e[72]!==J?(Q=s.jsx(ge,{size:"sm",onClick:X,disabled:O,children:J}),e[70]=X,e[71]=O,e[72]=J,e[73]=Q):Q=e[73];let ne;e[74]!==_||e[75]!==Q?(ne=s.jsxs(Vs,{children:[_,Q]}),e[74]=_,e[75]=Q,e[76]=ne):ne=e[76];let G;e[77]!==k||e[78]!==B||e[79]!==ne?(G=s.jsxs(fs,{className:"max-w-2xl",children:[k,B,ne]}),e[77]=k,e[78]=B,e[79]=ne,e[80]=G):G=e[80];let le;return e[81]!==r||e[82]!==n||e[83]!==G?(le=s.jsx(hs,{open:n,onOpenChange:r,children:G}),e[81]=r,e[82]=n,e[83]=G,e[84]=le):le=e[84],le},eu=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function Qa(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function fg(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=eu.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const r3=t=>{const e=at.c(124),{open:n,onOpenChange:r,item:i}=t,{t:a}=ut(),l=Ri(i3),c=Ri(a3),[d,p]=o.useState("user"),[m,u]=o.useState("opencode"),h=As(o3),x=As(l3),[f,v]=o.useState(null),[y,g]=o.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=[],e[0]=w):w=e[0];const[b,k]=o.useState(w),[I,j]=o.useState(null);let N,D;e[1]!==x||e[2]!==n?(N=()=>{n&&(p("user"),u("opencode"),v(x),g(!1),k([]),j(null))},D=[n,x],e[1]=x,e[2]=n,e[3]=N,e[4]=D):(N=e[3],D=e[4]),o.useEffect(N,D);let E;e[5]!==a?(E=Pe=>{switch(Pe){case"project-opencode":return a("settings.skills.location.option.projectOpencode.label");case"user-agents":return a("settings.skills.location.option.userAgents.label");case"project-agents":return a("settings.skills.location.option.projectAgents.label");default:return a("settings.skills.location.option.userOpencode.label")}},e[5]=a,e[6]=E):E=e[6];const T=E;let C;e[7]!==a?(C=Pe=>{switch(Pe){case"project-opencode":return a("settings.skills.location.option.projectOpencode.description");case"user-agents":return a("settings.skills.location.option.userAgents.description");case"project-agents":return a("settings.skills.location.option.projectAgents.description");default:return a("settings.skills.location.option.userOpencode.description")}},e[7]=a,e[8]=C):C=e[8];const S=C;let M;e:{if(h.length===0){M=null;break e}if(f&&h.some(Pe=>Pe.id===f)){M=f;break e}if(x&&h.some(Pe=>Pe.id===x)){M=x;break e}M=h[0]?.id??null}const A=M;let R;e:{if(d!=="project"){R=null;break e}const Pe=A;if(!Pe){R=null;break e}let fe;if(e[9]!==Pe||e[10]!==h){let Z;e[12]!==Pe?(Z=Y=>Y.id===Pe,e[12]=Pe,e[13]=Z):Z=e[13],fe=h.find(Z),e[9]=Pe,e[10]=h,e[11]=fe}else fe=e[11];R=fe?.path??null}const z=R;let B;e[14]!==l||e[15]!==i||e[16]!==r||e[17]!==a?(B=async Pe=>{const fe={skillDir:Pe.skillDir};i?.clawdhub&&(fe.clawdhub={slug:i.clawdhub.slug,version:i.clawdhub.version});const L=await l({source:Pe.source,subpath:Pe.subpath,gitIdentityId:i?.gitIdentityId,scope:Pe.scope,targetSource:Pe.targetSource,selections:[fe],conflictPolicy:"prompt",conflictDecisions:Pe.conflictDecisions},{directory:Pe.directoryOverride??null});if(L.ok){H.success(a("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(L.error?.kind==="conflicts"){j({source:Pe.source,subpath:Pe.subpath,scope:Pe.scope,targetSource:Pe.targetSource,skillDir:Pe.skillDir,directoryOverride:Pe.directoryOverride??null}),k(L.error.conflicts),g(!0);return}if(L.error?.kind==="authRequired"){H.error(L.error.message||a("settings.skills.catalog.installSkill.toast.authRequired"));return}H.error(L.error?.message||a("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i,e[16]=r,e[17]=a,e[18]=B):B=e[18];const V=B;if(!i)return null;let $;e[19]!==a?($=a("settings.skills.catalog.installSkill.title"),e[19]=a,e[20]=$):$=e[20];let _;e[21]!==$?(_=s.jsx(gs,{children:$}),e[21]=$,e[22]=_):_=e[22];let X;e[23]!==a?(X=a("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=a,e[24]=X):X=e[24];let O;e[25]!==i.skillName?(O=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=O):O=e[26];let J;e[27]!==a?(J=a("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=a,e[28]=J):J=e[28];let Q;e[29]!==X||e[30]!==O||e[31]!==J?(Q=s.jsxs(Is,{children:[X," ",O," ",J]}),e[29]=X,e[30]=O,e[31]=J,e[32]=Q):Q=e[32];let ne;e[33]!==_||e[34]!==Q?(ne=s.jsxs(bs,{children:[_,Q]}),e[33]=_,e[34]=Q,e[35]=ne):ne=e[35];let G;e[36]!==a?(G=a("settings.skills.catalog.installSkill.field.destination"),e[36]=a,e[37]=G):G=e[37];let le;e[38]!==G?(le=s.jsx("span",{className:"typography-ui-label text-foreground",children:G}),e[38]=G,e[39]=le):le=e[39];let oe;e[40]!==d||e[41]!==m?(oe=Qa(d,m),e[40]=d,e[41]=m,e[42]=oe):oe=e[42];let F;e[43]===Symbol.for("react.memo_cache_sentinel")?(F=Pe=>{const fe=fg(Pe);p(fe.scope),u(fe.source==="agents"?"agents":"opencode")},e[43]=F):F=e[43];let U;e[44]!==d?(U=d==="user"?s.jsx(P,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=U):U=e[45];let W;e[46]!==m?(W=m==="agents"?s.jsx(P,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=W):W=e[47];let te;e[48]!==T||e[49]!==d||e[50]!==m?(te=T(Qa(d,m)),e[48]=T,e[49]=d,e[50]=m,e[51]=te):te=e[51];let K;e[52]!==te?(K=s.jsx("span",{children:te}),e[52]=te,e[53]=K):K=e[53];let ae;e[54]!==U||e[55]!==W||e[56]!==K?(ae=s.jsxs(as,{className:"w-fit gap-1.5",children:[U,W,K]}),e[54]=U,e[55]=W,e[56]=K,e[57]=ae):ae=e[57];let ve;e[58]!==S||e[59]!==T?(ve=eu.map(Pe=>s.jsx(Ft,{value:Pe.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[Pe.scope==="user"?s.jsx(P,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"folder",className:"h-3.5 w-3.5"}),Pe.source==="agents"?s.jsx(P,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:T(Pe.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:S(Pe.value)})]})},Pe.value)),e[58]=S,e[59]=T,e[60]=ve):ve=e[60];let re;e[61]!==ve?(re=s.jsx(os,{align:"start",children:ve}),e[61]=ve,e[62]=re):re=e[62];let be;e[63]!==oe||e[64]!==ae||e[65]!==re?(be=s.jsxs(is,{value:oe,onValueChange:F,children:[ae,re]}),e[63]=oe,e[64]=ae,e[65]=re,e[66]=be):be=e[66];let pe;e[67]!==le||e[68]!==be?(pe=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[le,be]}),e[67]=le,e[68]=be,e[69]=pe):pe=e[69];let ye;e[70]!==h||e[71]!==A||e[72]!==d||e[73]!==a?(ye=d==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.installSkill.field.project")}),h.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(is,{value:A??"",onValueChange:Pe=>v(Pe),disabled:h.length===1,children:[s.jsx(as,{className:"w-fit",children:s.jsx(us,{placeholder:a("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(os,{align:"start",children:h.map(c3)})]})]}),e[70]=h,e[71]=A,e[72]=d,e[73]=a,e[74]=ye):ye=e[74];let ie;e[75]!==i.warnings?(ie=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=ie):ie=e[76];let ue;e[77]!==pe||e[78]!==ye||e[79]!==ie?(ue=s.jsxs("div",{className:"mt-2 space-y-3",children:[pe,ye,ie]}),e[77]=pe,e[78]=ye,e[79]=ie,e[80]=ue):ue=e[80];let se;e[81]!==r?(se=()=>r(!1),e[81]=r,e[82]=se):se=e[82];let Ne;e[83]!==a?(Ne=a("settings.common.actions.cancel"),e[83]=a,e[84]=Ne):Ne=e[84];let Ce;e[85]!==se||e[86]!==Ne?(Ce=s.jsx(ge,{size:"sm",variant:"ghost",onClick:se,children:Ne}),e[85]=se,e[86]=Ne,e[87]=Ce):Ce=e[87];const je=c||!i.installable||d==="project"&&!z;let we;e[88]!==z||e[89]!==V||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==d||e[94]!==m?(we=()=>{V({source:i.repoSource,subpath:i.repoSubpath,scope:d,targetSource:m,skillDir:i.skillDir,directoryOverride:z})},e[88]=z,e[89]=V,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=d,e[94]=m,e[95]=we):we=e[95];let ke;e[96]!==c||e[97]!==a?(ke=a(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=a,e[98]=ke):ke=e[98];let xe;e[99]!==je||e[100]!==we||e[101]!==ke?(xe=s.jsx(ge,{size:"sm",disabled:je,onClick:we,children:ke}),e[99]=je,e[100]=we,e[101]=ke,e[102]=xe):xe=e[102];let me;e[103]!==Ce||e[104]!==xe?(me=s.jsxs(Vs,{children:[Ce,xe]}),e[103]=Ce,e[104]=xe,e[105]=me):me=e[105];let Me;e[106]!==ne||e[107]!==ue||e[108]!==me?(Me=s.jsxs(fs,{className:"max-w-md",children:[ne,ue,me]}),e[106]=ne,e[107]=ue,e[108]=me,e[109]=Me):Me=e[109];let Ue;e[110]!==r||e[111]!==n||e[112]!==Me?(Ue=s.jsx(hs,{open:n,onOpenChange:r,children:Me}),e[110]=r,e[111]=n,e[112]=Me,e[113]=Ue):Ue=e[113];let q;e[114]!==I||e[115]!==V?(q=Pe=>{I&&(V({source:I.source,subpath:I.subpath,scope:I.scope,targetSource:I.targetSource,skillDir:I.skillDir,conflictDecisions:Pe,directoryOverride:I.directoryOverride??null}),g(!1))},e[114]=I,e[115]=V,e[116]=q):q=e[116];let Se;e[117]!==b||e[118]!==y||e[119]!==q?(Se=s.jsx(n3,{open:y,onOpenChange:g,conflicts:b,onConfirm:q}),e[117]=b,e[118]=y,e[119]=q,e[120]=Se):Se=e[120];let $e;return e[121]!==Ue||e[122]!==Se?($e=s.jsxs(s.Fragment,{children:[Ue,Se]}),e[121]=Ue,e[122]=Se,e[123]=$e):$e=e[123],$e};function i3(t){return t.installSkills}function a3(t){return t.isInstalling}function o3(t){return t.projects}function l3(t){return t.activeProjectId}function c3(t){return s.jsx(Ft,{value:t.id,children:t.label||t.path},t.id)}const d3=async()=>{try{const t=pr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},u3=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=ut(),{sources:i,itemsBySource:a,selectedSourceId:l,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:h,isLoadingMore:x,loadedSourceIds:f,clawdhubHasMoreBySource:v,lastCatalogError:y}=Ri(Br(_=>({sources:_.sources,itemsBySource:_.itemsBySource,selectedSourceId:_.selectedSourceId,setSelectedSource:_.setSelectedSource,loadCatalog:_.loadCatalog,loadSource:_.loadSource,loadMoreClawdHub:_.loadMoreClawdHub,isLoadingCatalog:_.isLoadingCatalog,isLoadingSource:_.isLoadingSource,isLoadingMore:_.isLoadingMore,loadedSourceIds:_.loadedSourceIds,clawdhubHasMoreBySource:_.clawdhubHasMoreBySource,lastCatalogError:_.lastCatalogError}))),[g,w]=o.useState(""),[b,k]=o.useState(!1),[I,j]=o.useState(!1),[N,D]=o.useState(null),[E,T]=o.useState(!1),[C,S]=o.useState(!1);o.useEffect(()=>{d()},[d]),o.useEffect(()=>{l&&(f[l]||p(l))},[l,f,p]);const M=o.useMemo(()=>l?a[l]||[]:[],[a,l]),A=o.useMemo(()=>{const _=g.trim().toLowerCase();return _?M.filter(X=>{const O=X.skillName.toLowerCase(),J=(X.description||"").toLowerCase(),Q=(X.frontmatterName||"").toLowerCase();return O.includes(_)||J.includes(_)||Q.includes(_)}):M},[M,g]),R=o.useMemo(()=>i.find(_=>_.id===l)||null,[i,l]),z=!!(l&&l.startsWith("custom:")),B=R?.source==="clawdhub:registry"||R?.sourceType==="clawdhub",V=!!(l&&(v[l]??!0)),$=async()=>{if(!(!l||!z)){T(!0);try{const _=await d3(),O=(Array.isArray(_?.skillCatalogs)?_?.skillCatalogs:[]).filter(J=>J.id!==l);await ks({skillCatalogs:O}),await d({refresh:!0}),S(!1)}finally{T(!1)}}};return s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4",children:[n&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(Cr,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:_=>e(_),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground px-1",children:r("settings.skills.catalog.page.title")})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:r("settings.skills.catalog.page.section.sourceRepository")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsxs(is,{value:l||"",onValueChange:_=>c(_),children:[s.jsx(as,{className:"w-fit",children:s.jsx(us,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:R?.label})}),s.jsx(os,{align:"start",children:i.map(_=>s.jsx(Ft,{value:_.id,children:_.label},_.id))})]}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l?p(l,{refresh:!0}):d({refresh:!0})},disabled:u||h,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(P,{name:"refresh",className:ce("h-3.5 w-3.5",(u||h)&&"animate-spin")})}),z&&s.jsx(ge,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>S(!0),disabled:E,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(ge,{size:"xs",className:"!font-normal gap-1",onClick:()=>k(!0),children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"})," ",r("settings.skills.catalog.page.actions.addCatalog")]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"relative",children:[s.jsx(P,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{value:g,onChange:_=>w(_.target.value),placeholder:r("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:u?r("settings.skills.catalog.page.loading.catalog"):r("settings.skills.catalog.page.foundCount",{count:A.length})})]})]})]}),y&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:r("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:y.message})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("section",{className:"px-2 pb-2 pt-0",children:A.length===0&&!h?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:r("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.catalog.page.empty.noSkillsDescription")})]}):h?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(P,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:r("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:A.map(_=>{const X=_.installed?.isInstalled,O=_.installed?.scope;return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:_.skillName}),X&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.installed",{scope:O||r("settings.skills.catalog.page.badge.unknown")})}),!_.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.notInstallable")})]}),_.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:_.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),_.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[_.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:_.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(P,{name:"download",className:"h-3 w-3"}),_.clawdhub.downloads?.toLocaleString()??0]}),(_.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(P,{name:"star",className:"h-3 w-3"}),_.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",_.clawdhub.version]})]}),_.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:_.warnings.join(" · ")}):null]}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!_.installable,onClick:()=>{D(_),j(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${_.sourceId}:${_.skillDir}`)})})}),B&&V&&!h&&A.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:x,children:r(x?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),s.jsx(Qk,{open:b,onOpenChange:k}),s.jsx(r3,{open:I,onOpenChange:j,item:N}),s.jsx(hs,{open:C,onOpenChange:_=>{E||S(_)},children:s.jsxs(fs,{className:"max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Is,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Vs,{children:[s.jsx(ge,{size:"sm",variant:"ghost",onClick:()=>S(!1),disabled:E,children:r("settings.common.actions.cancel")}),s.jsx(ge,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:E,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},m3=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(u3,{mode:"external",onModeChange:f3,showModeTabs:!1}),t[0]=e):e=t[0],e},p3=()=>{const{t}=ut(),{selectedSkillName:e,getSkillByName:n,getSkillDetail:r,createSkill:i,updateSkill:a,skills:l,skillDraft:c,setSkillDraft:d,setSelectedSkill:p}=fi(Br(je=>({selectedSkillName:je.selectedSkillName,getSkillByName:je.getSkillByName,getSkillDetail:je.getSkillDetail,createSkill:je.createSkill,updateSkill:je.updateSkill,skills:je.skills,skillDraft:je.skillDraft,setSkillDraft:je.setSkillDraft,setSelectedSkill:je.setSelectedSkill}))),m=e?n(e):null,u=!!(c&&c.name===e&&!m),h=!!(e&&!m&&!c);o.useEffect(()=>{h&&p(null)},[h,p]);const[x,f]=o.useState(""),[v,y]=o.useState("user"),[g,w]=o.useState("opencode"),[b,k]=o.useState(""),[I,j]=o.useState(""),[N,D]=o.useState([]),[E,T]=o.useState([]),[C,S]=o.useState(!1),[M,A]=o.useState(!1),[R,z]=o.useState(""),[B,V]=o.useState(""),[$,_]=o.useState(!1),[X,O]=o.useState(""),[J,Q]=o.useState(""),[ne,G]=o.useState(null),[le,oe]=o.useState(!1),[F,U]=o.useState(""),[W,te]=o.useState(null),[K,ae]=o.useState(!1),ve=u?x.trim()!==""||b.trim()!==""||I.trim()!==""||E.length>0:b!==R||I!==B,re=ne?J!==F:X.trim()!=="",be=o.useCallback(je=>{switch(je){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),pe=o.useCallback(je=>{switch(je){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);o.useEffect(()=>{(async()=>{if(u&&c)f(c.name||""),y(c.scope||"user"),w(c.source==="agents"?"agents":"opencode"),k(c.description||""),j(c.instructions||""),z(""),V(""),D([]),T(c.pendingFiles||[]);else if(e&&m){A(!0);try{const we=await r(e);if(we){const ke=we.sources.md;k(ke.description||""),j(ke.instructions||""),z(ke.description||""),V(ke.instructions||""),D(ke.supportingFiles||[])}}catch(we){console.error("Failed to load skill details:",we)}finally{A(!1)}}})()},[m,u,e,l,c,r]);const ye=async()=>{const je=u?x.trim().replace(/\s+/g,"-").toLowerCase():e?.trim();if(!je){H.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(je)||je.length>64){H.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!b.trim()){H.error(t("settings.skills.page.toast.descriptionRequired"));return}if(u&&l.some(we=>we.name===je)){H.error(t("settings.skills.page.toast.skillExists"));return}S(!0);try{const we={name:je,description:b.trim(),instructions:I.trim()||void 0,scope:u?v:void 0,source:u?g:void 0,targetPath:u?void 0:m?.path,supportingFiles:u&&E.length>0?E:void 0};let ke;u?(ke=await i(we),ke&&(d(null),T([]),p(je))):(ke=await a(je,we),ke&&(z(b.trim()),V(I.trim()))),ke?H.success(t(u?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):H.error(t(u?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(we){console.error("Error saving skill:",we),H.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{S(!1)}},ie=()=>{G(null),O(""),Q(""),U(""),_(!0)},ue=async je=>{if(G(je),O(je),u){const ke=E.find(xe=>xe.path===je)?.content||"";Q(ke),U(ke),_(!0);return}if(e){oe(!0),_(!0);try{const{readSupportingFile:we}=fi.getState(),ke=await we(e,je);Q(ke||""),U(ke||"")}catch{H.error(t("settings.skills.page.toast.loadFileContentFailed")),Q(""),U("")}finally{oe(!1)}}},se=async()=>{if(!X.trim()){H.error(t("settings.skills.page.toast.fileNameRequired"));return}const je=X.trim(),we=ne!==null;if(u){if(we)T(me=>me.map(Me=>Me.path===ne?{path:je,content:J}:Me)),H.success(t("settings.skills.page.toast.fileUpdated",{path:je}));else{if(E.some(me=>me.path===je)){H.error(t("settings.skills.page.toast.fileExists"));return}T(me=>[...me,{path:je,content:J}]),H.success(t("settings.skills.page.toast.fileAdded",{path:je}))}_(!1),G(null);return}if(!e){H.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:ke}=fi.getState();if(await ke(e,je,J)){H.success(we?t("settings.skills.page.toast.fileUpdated",{path:je}):t("settings.skills.page.toast.fileCreated",{path:je})),_(!1),G(null);const me=await r(e);me&&D(me.sources.md.supportingFiles||[])}else H.error(t(we?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ne=je=>{if(u){T(we=>we.filter(ke=>ke.path!==je)),H.success(t("settings.skills.page.toast.fileRemoved",{path:je}));return}e&&te(je)},Ce=async()=>{if(!W||!e)return;ae(!0);const{deleteSupportingFile:je}=fi.getState();if(await je(e,W)){H.success(t("settings.skills.page.toast.fileDeleted",{path:W}));const ke=await r(e);ke&&D(ke.sources.md.supportingFiles||[]),te(null)}else H.error(t("settings.skills.page.toast.deleteFileFailed"));ae(!1)};return!e&&!c||h?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(P,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):M?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(Cs,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:u?t("settings.skills.page.title.newSkill"):e}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:m?t("settings.skills.page.subtitle.skillLocation",{location:be(Qa(m.scope,m.source))}):t("settings.skills.page.subtitle.newSkill")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.basicInformation")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[u&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.skills.page.field.skillNameLocation")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.skillNameHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx(Bt,{value:x,onChange:je=>f(je.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(is,{value:Qa(v,g),onValueChange:je=>{const we=fg(je);y(we.scope),w(we.source==="agents"?"agents":"opencode")},children:[s.jsxs(as,{className:"w-fit gap-1.5",children:[v==="user"?s.jsx(P,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"folder",className:"h-3.5 w-3.5"}),g==="agents"?s.jsx(P,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:be(Qa(v,g))})]}),s.jsx(os,{align:"start",children:eu.map(je=>s.jsx(Ft,{value:je.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[je.scope==="user"?s.jsx(P,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"folder",className:"h-3.5 w-3.5"}),je.source==="agents"?s.jsx(P,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:be(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:pe(je.value)})]})},je.value))})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.descriptionHint")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(hn,{value:b,onChange:je=>k(je.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent"})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.instructions")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(hn,{value:I,onChange:je=>j(je.target.value),placeholder:t("settings.skills.page.field.instructionsPlaceholder"),className:"min-h-[220px] max-h-[60vh] font-mono typography-meta"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.supportingFiles")}),s.jsxs(ge,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:ie,children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:(()=>{const je=u?E:N;return je.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:je.map(we=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>ue(we.path),children:[s.jsx(P,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:we.path}),u&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),s.jsx(ge,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:ke=>{ke.stopPropagation(),Ne(we.path)},children:s.jsx(P,{name:"delete-bin",className:"h-3 w-3"})})]},we.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ge,{onClick:ye,disabled:C||!ve,size:"xs",className:"!font-normal",children:t(C?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(hs,{open:W!==null,onOpenChange:je=>{!je&&!K&&te(null)},children:s.jsxs(fs,{className:"max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Is,{children:t("settings.skills.page.deleteFileDialog.description",{path:W??""})})]}),s.jsxs(Vs,{children:[s.jsx(ge,{size:"sm",variant:"ghost",onClick:()=>te(null),disabled:K,children:t("settings.common.actions.cancel")}),s.jsx(ge,{size:"sm",variant:"destructive",onClick:Ce,disabled:K,children:t("settings.common.actions.delete")})]})]})}),s.jsx(hs,{open:$,onOpenChange:je=>{_(je),je||G(null)},children:s.jsxs(fs,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(bs,{className:"flex-shrink-0",children:[s.jsx(gs,{children:t(ne?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Is,{children:t(ne?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),le?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:t("settings.skills.page.fileDialog.field.filePath")}),s.jsx(Bt,{value:X,onChange:je=>O(je.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:ne!==null}),!ne&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground flex-shrink-0",children:t("settings.skills.page.fileDialog.field.content")}),s.jsx(hn,{value:J,onChange:je=>Q(je.target.value),placeholder:t("settings.skills.page.fileDialog.field.contentPlaceholder"),outerClassName:"h-[45vh] min-h-[250px] max-h-[55vh]",className:"h-full min-h-0 font-mono typography-meta"})]})]}),s.jsxs(Vs,{className:"mt-4",children:[s.jsx(ge,{size:"sm",variant:"ghost",onClick:()=>{_(!1),G(null)},children:t("settings.common.actions.cancel")}),s.jsx(ge,{size:"sm",onClick:se,disabled:le||!re,children:t(ne?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},bp=t=>{const e=at.c(2),{view:n}=t,r=n===void 0?"installed":n;let i;return e[0]!==r?(i=r==="catalog"?s.jsx(m3,{}):s.jsx(p3,{}),e[0]=r,e[1]=i):i=e[1],i};function f3(){}const hg=t=>{const e=at.c(26),{header:n,footer:r,children:i,className:a,variant:l}=t,c=l===void 0?"sidebar":l,d=mn(),p=o.useRef(null),[m,u]=o.useState(!1),[h,x]=o.useState(!1),f=c==="background"||d?"bg-background":"bg-sidebar",v=f==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{const S=p.current;if(!S){u(!1),x(!1);return}if(!(S.scrollHeight>S.clientHeight+1)){u(!1),x(!1);return}u(S.scrollTop>1),x(S.scrollTop+S.clientHeight<S.scrollHeight-1)},e[0]=y):y=e[0];const g=y;let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{g()},e[1]=w):w=e[1];let b;e[2]!==i?(b=[i,g],e[2]=i,e[3]=b):b=e[3],o.useEffect(w,b);let k,I;e[4]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const S=p.current;if(!S)return;const M=()=>g();return S.addEventListener("scroll",M,{passive:!0}),()=>S.removeEventListener("scroll",M)},I=[g],e[4]=k,e[5]=I):(k=e[4],I=e[5]),o.useEffect(k,I);let j;e[6]!==f||e[7]!==a?(j=ce("flex h-full flex-col",f,a),e[6]=f,e[7]=a,e[8]=j):j=e[8];let N;e[9]!==i?(N=s.jsx(Cs,{ref:p,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=N):N=e[10];let D;e[11]!==v||e[12]!==m?(D=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${v} 0%, transparent 100%)`}}),e[11]=v,e[12]=m,e[13]=D):D=e[13];let E;e[14]!==v||e[15]!==h?(E=h&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${v} 0%, transparent 100%)`}}),e[14]=v,e[15]=h,e[16]=E):E=e[16];let T;e[17]!==E||e[18]!==N||e[19]!==D?(T=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[N,D,E]}),e[17]=E,e[18]=N,e[19]=D,e[20]=T):T=e[20];let C;return e[21]!==r||e[22]!==n||e[23]!==T||e[24]!==j?(C=s.jsxs("div",{className:j,children:[n,T,r]}),e[21]=r,e[22]=n,e[23]=T,e[24]=j,e[25]=C):C=e[25],C},gg=t=>{const e=at.c(23),{title:n,metadata:r,selected:i,onSelect:a,icon:l,actions:c,className:d}=t,p=i===void 0?!1:i,m=c&&c.length>0,u=p?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[0]!==d||e[1]!==u?(h=ce("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",u,d),e[0]=d,e[1]=u,e[2]=h):h=e[2];let x;e[3]!==n?(x=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=x):x=e[4];let f;e[5]!==l||e[6]!==x?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,x]}),e[5]=l,e[6]=x,e[7]=f):f=e[7];let v;e[8]!==r?(v=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=v):v=e[9];let y;e[10]!==a||e[11]!==f||e[12]!==v?(y=s.jsxs("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[f,v]}),e[10]=a,e[11]=f,e[12]=v,e[13]=y):y=e[13];let g;e[14]!==c||e[15]!==m?(g=m&&s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx(ge,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(P,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Rs,{align:"end",className:"w-fit min-w-20",children:c.map(h3)})]}),e[14]=c,e[15]=m,e[16]=g):g=e[16];let w;e[17]!==y||e[18]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[y,g]}),e[17]=y,e[18]=g,e[19]=w):w=e[19];let b;return e[20]!==h||e[21]!==w?(b=s.jsx("div",{className:h,children:w}),e[20]=h,e[21]=w,e[22]=b):b=e[22],b};function h3(t){const e=t.icon;return s.jsxs($t,{onClick:n=>{n.stopPropagation(),t.onClick()},className:ce(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(P,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const g3=t=>{const e=at.c(41),{onItemSelect:n}=t,{t:r}=ut(),i=As(x3),a=Ie(b3),l=Ie(y3),{currentTheme:c}=Ar();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[0]=d):d=e[0];const[p,m]=o.useState(d);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=mn(),e[1]=u):u=e[1];const h=u,x=v3;let f,v;e[2]!==i||e[3]!==a||e[4]!==l?(f=()=>{if(i.length===0){a!==null&&l(null);return}a&&i.some(T=>T.id===a)||l(i[0].id)},v=[i,a,l],e[2]=i,e[3]=a,e[4]=l,e[5]=f,e[6]=v):(f=e[5],v=e[6]),o.useEffect(f,v);let y;e[7]===Symbol.for("react.memo_cache_sentinel")?(y=ce("border-b px-3","pt-4 pb-3"),e[7]=y):y=e[7];let g;e[8]!==r?(g=r("settings.page.projects.title"),e[8]=r,e[9]=g):g=e[9];let w;e[10]!==g?(w=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[10]=g,e[11]=w):w=e[11];let b;e[12]!==i.length||e[13]!==r?(b=r("settings.projects.sidebar.total",{count:i.length}),e[12]=i.length,e[13]=r,e[14]=b):b=e[14];let k;e[15]!==b?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:b}),e[15]=b,e[16]=k):k=e[16];let I;e[17]!==r?(I=!h&&s.jsx(ge,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:x,"aria-label":r("settings.projects.sidebar.actions.addProject"),children:s.jsx(P,{name:"add",className:"size-4"})}),e[17]=r,e[18]=I):I=e[18];let j;e[19]!==I||e[20]!==k?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,I]}),e[19]=I,e[20]=k,e[21]=j):j=e[21];let N;e[22]!==j||e[23]!==w?(N=s.jsxs("div",{className:y,children:[w,j]}),e[22]=j,e[23]=w,e[24]=N):N=e[24];let D;if(e[25]!==p||e[26]!==c||e[27]!==n||e[28]!==i||e[29]!==a||e[30]!==l){let T;e[32]!==p||e[33]!==c||e[34]!==n||e[35]!==a||e[36]!==l?(T=C=>{const S=C.id===a,M=C.icon?Vl[C.icon]:null,A=`${C.id}:${C.iconImage?.updatedAt??0}`,R=p.has(A)?null:xo(C,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),z=C.color?bo[C.color]??null:null,B=R?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:C.iconBackground?{backgroundColor:C.iconBackground}:void 0,children:s.jsx("img",{src:R,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m(V=>{if(V.has(A))return V;const $=new Set(V);return $.add(A),$})}})}):M?s.jsx(P,{name:M,className:ce("h-4 w-4",S?"text-foreground":"text-muted-foreground/70"),style:z?{color:z}:void 0}):s.jsx(P,{name:"folder",className:ce("h-4 w-4",S?"text-foreground":"text-muted-foreground/70"),style:z?{color:z}:void 0});return s.jsx(gg,{title:C.label||C.path,icon:B,selected:S,onSelect:()=>{l(C.id),n?.()}},C.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=a,e[36]=l,e[37]=T):T=e[37],D=i.map(T),e[25]=p,e[26]=c,e[27]=n,e[28]=i,e[29]=a,e[30]=l,e[31]=D}else D=e[31];let E;return e[38]!==N||e[39]!==D?(E=s.jsx(hg,{variant:"background",header:N,children:D}),e[38]=N,e[39]=D,e[40]=E):E=e[40],E};function x3(t){return t.projects}function b3(t){return t.settingsProjectsSelectedId}function y3(t){return t.setSettingsProjectsSelectedId}function v3(){Sr.requestDirectoryDialog()}const w3=({projectRef:t=null})=>{const{t:e}=ut(),{isMobile:n,isTablet:r}=rn(),i=n||r,a=As(M=>M.getActiveProject()),l=t?.path??a?.path??null,c=Ot(M=>M.getWorktreeMetadata),d=zl(),p=$s(M=>M.homeDirectory),[m,u]=o.useState([]),[h,x]=o.useState(!1),[f,v]=o.useState(null),[y,g]=o.useState([]),[w,b]=o.useState(!1),k=o.useMemo(()=>t?.id&&t?.path?{id:t.id,path:t.path}:!a?.id||!l?null:{id:a.id,path:l},[a?.id,l,t?.id,t?.path]),I=o.useCallback(async()=>{if(!(!k||f===!1))try{const M=await Qc(k);g(M)}catch{}},[k,f]);o.useEffect(()=>{if(!l)return;let M=!1;return v(null),(async()=>{try{const A=await nh(l);if(M)return;v(A)}catch{}})(),()=>{M=!0}},[l]),o.useEffect(()=>{if(!k){g([]),b(!1);return}if(f===!1){g([]),b(!1);return}let M=!1;return b(!0),g([]),(async()=>{try{const A=await Qc(k);if(M)return;g(A)}catch{}finally{M||b(!1)}})(),()=>{M=!0}},[k,f]),o.useEffect(()=>{if(!k)return;let M=!1;return x(!0),(async()=>{try{const A=await zd(k);M||u(A.length>0?A:[""])}catch{M||u([""])}finally{M||x(!1)}})(),()=>{M=!0}},[k]);const j=o.useCallback((M,A)=>{u(R=>{const z=[...R];return z[M]=A,z})},[]),N=o.useCallback(()=>{u(M=>[...M,""])},[]),D=o.useCallback(async M=>{if(!k)return;const A=M.filter(R=>R.trim().length>0);await rh(k,A)},[k]),E=o.useCallback(M=>{u(A=>{const R=A.filter((z,B)=>B!==M);return D(R),R.length>0?R:[""]})},[D]),T=o.useCallback(()=>{D(m)},[D,m]),C=o.useCallback(M=>{const A=O=>O.replace(/\\/g,"/").replace(/\/+$/,""),R=A(M.path),z=d.filter(O=>{const J=c(O.id);if(J?.path&&A(J.path)===R)return!0;const Q=O.directory;return!!(Q&&A(Q)===R)}),B=new Set(z.map(O=>O.id)),V=O=>{const J=d.filter(ne=>{const G=ne.parentID;return G&&O.has(G)});if(J.length===0)return[];const Q=new Set(J.map(ne=>ne.id));return[...J,...V(Q)]},$=V(B),_=new Set,X=[...z,...$].filter(O=>_.has(O.id)?!1:(_.add(O.id),!0));Sr.requestDelete({sessions:X,mode:"worktree",worktree:M})},[d,c]),S=o.useMemo(()=>d.map(M=>M.id).join(","),[d]);return o.useEffect(()=>{f&&l&&I()},[S,f,l,I]),l?f===!1?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.vinci.worktrees.state.gitOnly")}):s.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.vinci.worktrees.setup.title")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Dt,{sideOffset:8,className:"max-w-xs",children:[e("settings.vinci.worktrees.setup.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs bg-sidebar-accent/50 px-1 rounded",children:"$ROOT_PROJECT_PATH"})," ",e("settings.vinci.worktrees.setup.tooltipSuffix")]})]})]})}),h?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.vinci.worktrees.setup.loading")}):s.jsxs("div",{className:"space-y-2 px-1",children:[m.map((M,A)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Bt,{value:M,onChange:R=>j(A,R.target.value),onBlur:T,placeholder:e("settings.vinci.worktrees.setup.commandPlaceholder"),className:"h-7 w-[30rem] max-w-full font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{E(A)},className:"flex-shrink-0 flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.vinci.worktrees.setup.removeCommandAria"),children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]},A)),s.jsxs(ge,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:N,children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),e("settings.vinci.worktrees.setup.addCommand")]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-border/40 pt-4",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.vinci.worktrees.list.title")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:e("settings.vinci.worktrees.list.tooltip")})]})]})}),w?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.vinci.worktrees.list.loading")}):y.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.vinci.worktrees.list.empty")}):s.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:y.map(M=>s.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("p",{className:"typography-meta text-foreground truncate min-w-0",children:M.label||M.branch||e("settings.vinci.worktrees.list.detachedHead")}),s.jsx("span",{className:"typography-micro text-muted-foreground/60 px-1.5 py-[1px] rounded bg-sidebar-accent/40 flex-shrink-0 self-center leading-none",children:"OpenCode"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground/60 truncate",children:ro(M.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>C(M),className:ce("flex-shrink-0 flex h-7 w-7 items-center justify-center rounded text-muted-foreground/50 hover:text-destructive hover:bg-destructive/10 transition-opacity focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",i?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.vinci.worktrees.list.deleteWorktreeAria",{name:M.branch||M.label||M.path}),children:s.jsx(P,{name:"delete-bin",className:"h-4 w-4"})})]},M.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.vinci.worktrees.state.selectProject")})},j3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,N3=()=>({id:j3(),name:"",command:"",icon:"play"}),S3=({projectRef:t})=>{const{t:e}=ut(),n=o.useMemo(()=>gn(),[]),r=Ys(N=>N.instances),i=Ys(N=>N.load),[a,l]=o.useState([]),[c,d]=o.useState(!1),[p,m]=o.useState(!1),[u,h]=o.useState(null),[x,f]=o.useState({});o.useEffect(()=>{n&&i().catch(()=>{})},[n,i]),o.useEffect(()=>{let N=!1;return d(!0),(async()=>{try{const D=await Yc(t);if(N)return;l(D.actions),h(JSON.stringify({actions:D.actions}))}catch{if(N)return;l([]),h(JSON.stringify({actions:[]}))}finally{N||d(!1)}})(),()=>{N=!0}},[t]);const v=o.useMemo(()=>n?Ah(r):[],[r,n]),y=o.useMemo(()=>a.some(D=>D.name.trim().length===0||D.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[a,e]),g=o.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:a}),[a,u]),w=o.useCallback(()=>{const N=N3();l(D=>[...D,N]),f(D=>({...D,[N.id]:!0}))},[]),b=o.useCallback(N=>{l(D=>D.filter(E=>E.id!==N)),f(D=>{const E={...D};return delete E[N],E})},[]),k=o.useCallback((N,D)=>{l(E=>E.map(T=>T.id===N?D(T):T))},[]),I=o.useCallback(async()=>{if(y){H.error(y);return}m(!0);try{if(!await zb(t,{actions:a,primaryActionId:null})){H.error(e("settings.projects.actions.toast.saveFailed"));return}h(JSON.stringify({actions:a})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(nd,{detail:{projectId:t.id}})),H.success(e("settings.projects.actions.toast.saved"))}catch{H.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[a,t,e,y]),j=!p&&!c&&g&&!y;return s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:w,children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]})]}),s.jsxs("section",{className:"pb-2 pt-0 space-y-2",children:[c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):a.length===0?s.jsx("div",{className:"py-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")})}):s.jsx("div",{className:"space-y-0 max-w-[30rem]",children:a.map(N=>{const D=N.icon||"play",E=Zo[D]||"play",T=x[N.id]??!1,C=N.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(fr,{open:T,onOpenChange:S=>{f(M=>({...M,[N.id]:S}))},className:ce("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(Pr,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[T?s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx(P,{name:E,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:C})})})]}),s.jsx(ge,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>b(N.id),children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(hr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-2 pb-6 pl-3 pr-3",children:[s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":e("settings.projects.actions.field.selectIconAria"),children:s.jsx(P,{name:E,className:"h-4 w-4"})})}),s.jsx(Rs,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:Ph.map(S=>{const M=S.Icon,A=(N.icon||"play")===S.key;return s.jsx("button",{type:"button",onClick:()=>k(N.id,R=>({...R,icon:S.key})),className:ce("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",A&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:S.label}),children:s.jsx(P,{name:M,className:"h-4 w-4"})},S.key)})})})]}),s.jsx(Bt,{value:N.name,onChange:S=>k(N.id,M=>({...M,name:S.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),s.jsxs("div",{className:"py-1",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),s.jsx(hn,{value:N.command,onChange:S=>k(N.id,M=>({...M,command:S.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] font-mono text-xs"})]}),s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":N.autoOpenUrl===!0,onClick:()=>k(N.id,S=>({...S,...S.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),k(N.id,M=>({...M,...M.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(ds,{checked:N.autoOpenUrl===!0,onChange:S=>k(N.id,M=>({...M,...S?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:C})}),s.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),N.autoOpenUrl===!0?s.jsxs("div",{className:"mt-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:N.openUrl||"",onChange:S=>k(N.id,M=>({...M,openUrl:S.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]})]}),n?s.jsxs("div",{className:"mt-2",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),v.length>0?s.jsxs(is,{value:N.desktopOpenSshForward&&v.some(S=>S.id===N.desktopOpenSshForward)?N.desktopOpenSshForward:"__none__",onValueChange:S=>{k(N.id,M=>({...M,...S==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:S}}))},children:[s.jsx(as,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(us,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),v.map(S=>s.jsx(Ft,{value:S.id,children:S.label},S.id))]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},N.id)})}),s.jsxs("div",{className:"pt-3",children:[y?s.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:y}):null,s.jsx(ge,{type:"button",size:"xs",className:"!font-normal",onClick:I,disabled:!j,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},k3=()=>{const t=at.c(201),{t:e}=ut(),n=As(C3),r=As(P3),i=As(I3),a=As(A3),l=As(D3),c=Ie(T3),d=Ie(M3),{currentTheme:p}=Ar();let m;e:{if(!c){m=null;break e}let wt;t[0]!==n||t[1]!==c?(wt=n.find(Qt=>Qt.id===c)??null,t[0]=n,t[1]=c,t[2]=wt):wt=t[2],m=wt}const u=m;let h,x;t[3]!==n||t[4]!==c||t[5]!==d?(h=()=>{if(n.length===0){d(null);return}c&&n.some(wt=>wt.id===c)||d(n[0].id)},x=[n,c,d],t[3]=n,t[4]=c,t[5]=d,t[6]=h,t[7]=x):(h=t[6],x=t[7]),o.useEffect(h,x);const[f,v]=o.useState(""),[y,g]=o.useState(null),[w,b]=o.useState(null),[k,I]=o.useState(null),[j,N]=o.useState(!1),[D,E]=o.useState(!1),[T,C]=o.useState(!1),[S,M]=o.useState(!1),[A,R]=o.useState(null),[z,B]=o.useState(null),[V,$]=o.useState(!1),_=o.useRef(null);let X;t[8]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{R(null),B(E3)},t[8]=X):X=t[8];const O=X;let J;e:{if(!u){J=null;break e}let wt;t[9]!==u.id||t[10]!==u.path?(wt={id:u.id,path:u.path},t[9]=u.id,t[10]=u.path,t[11]=wt):wt=t[11],J=wt}const Q=J;let ne,G;t[12]!==u?(ne=()=>{if(!u){v(""),g(null),b(null),I(null);return}v(u.label??""),g(u.icon??null),b(u.color??null),I(u.iconBackground??null),M(!1),O(),$(!1)},G=[u,O],t[12]=u,t[13]=ne,t[14]=G):(ne=t[13],G=t[14]),o.useEffect(ne,G);let le,oe;t[15]===Symbol.for("react.memo_cache_sentinel")?(le=()=>()=>{O()},oe=[O],t[15]=le,t[16]=oe):(le=t[15],oe=t[16]),o.useEffect(le,oe);let F;t[17]!==w||t[18]!==y||t[19]!==k||t[20]!==f||t[21]!==S||t[22]!==A||t[23]!==u?(F=!!u&&(f.trim()!==(u?.label??"").trim()||y!==(u?.icon??null)||w!==(u?.color??null)||k!==(u?.iconBackground??null)||S||!!A),t[17]=w,t[18]=y,t[19]=k,t[20]=f,t[21]=S,t[22]=A,t[23]=u,t[24]=F):F=t[24];const U=F;let W;t[25]!==w||t[26]!==y||t[27]!==k||t[28]!==f||t[29]!==S||t[30]!==A||t[31]!==a||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==i?(W=async()=>{if(!u)return;if(A){N(!0);const Qt=await i(u.id,A);if(N(!1),!Qt.ok){H.error(Qt.error||e("settings.projects.page.toast.uploadIconFailed"));return}H.success(e("settings.projects.page.toast.iconUpdated")),O(),M(!1)}const wt=S&&!!u.iconImage;if(wt){E(!0);const Qt=await a(u.id);if(E(!1),!Qt.ok){H.error(Qt.error||e("settings.projects.page.toast.removeIconFailed"));return}H.success(e("settings.projects.page.toast.iconRemoved")),M(!1),I(null)}r(u.id,{label:f.trim(),icon:y,color:w,iconBackground:wt?null:k})},t[25]=w,t[26]=y,t[27]=k,t[28]=f,t[29]=S,t[30]=A,t[31]=a,t[32]=u,t[33]=e,t[34]=r,t[35]=i,t[36]=W):W=t[36];const te=W,K=w?bo[w]??null:null,ae=!!u?.iconImage,ve=!!(A&&z),re=u?.iconImage?.source==="custom",be=ae&&!S||ve,pe=be;let ye;t[37]!==p||t[38]!==ve||t[39]!==ae||t[40]!==S||t[41]!==z||t[42]!==V||t[43]!==u?(ye=V?null:ve?z:u&&ae&&!S?xo(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=ve,t[39]=ae,t[40]=S,t[41]=z,t[42]=V,t[43]=u,t[44]=ye):ye=t[44];const ie=ye;let ue;t[45]!==j||t[46]!==u?(ue=wt=>{!u||!wt||j||(M(!1),$(!1),R(wt),B(Qt=>(Qt&&URL.revokeObjectURL(Qt),URL.createObjectURL(wt))))},t[45]=j,t[46]=u,t[47]=ue):ue=t[47];const se=ue;let Ne;t[48]!==ve||t[49]!==pe||t[50]!==ae||t[51]!==D||t[52]!==u?(Ne=()=>{!u||!pe||D||(ve&&O(),M(!!ae),$(!1))},t[48]=ve,t[49]=pe,t[50]=ae,t[51]=D,t[52]=u,t[53]=Ne):Ne=t[53];const Ce=Ne;let je;t[54]!==l||t[55]!==T||t[56]!==u||t[57]!==e?(je=async()=>{!u||T||(O(),M(!1),$(!1),C(!0),l(u.id).then(wt=>{if(!wt.ok){H.error(wt.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(wt.skipped){H.success(e("settings.projects.page.toast.customIconAlreadySet"));return}H.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{C(!1)}))},t[54]=l,t[55]=T,t[56]=u,t[57]=e,t[58]=je):je=t[58];const we=je;if(!u){let wt;t[59]!==e?(wt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=wt):wt=t[60];let Qt;return t[61]!==wt?(Qt=s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:wt})})}),t[61]=wt,t[62]=Qt):Qt=t[62],Qt}let ke;t[63]!==u.label||t[64]!==e?(ke=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=ke):ke=t[65];let xe;t[66]!==ke?(xe=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ke}),t[66]=ke,t[67]=xe):xe=t[67];let me;t[68]!==u.path?(me=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=me):me=t[69];let Me;t[70]!==xe||t[71]!==me?(Me=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[xe,me]})}),t[70]=xe,t[71]=me,t[72]=Me):Me=t[72];let Ue;t[73]!==e?(Ue=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=Ue):Ue=t[74];let q;t[75]!==Ue?(q=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Ue})}),t[75]=Ue,t[76]=q):q=t[76];let Se;t[77]===Symbol.for("react.memo_cache_sentinel")?(Se=wt=>v(wt.target.value),t[77]=Se):Se=t[77];let $e;t[78]!==e?($e=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=$e):$e=t[79];let Pe;t[80]!==f||t[81]!==$e?(Pe=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Bt,{value:f,onChange:Se,placeholder:$e,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=f,t[81]=$e,t[82]=Pe):Pe=t[82];let fe;t[83]!==q||t[84]!==Pe?(fe=s.jsxs("div",{className:"py-1.5",children:[q,Pe]}),t[83]=q,t[84]=Pe,t[85]=fe):fe=t[85];let L;t[86]!==e?(L=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=L):L=t[87];let Z;t[88]!==L?(Z=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:L})}),t[88]=L,t[89]=Z):Z=t[89];let Y;t[90]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>b(null),t[90]=Y):Y=t[90];const Ee=w===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let Ae;t[91]!==Ee?(Ae=ce("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Ee),t[91]=Ee,t[92]=Ae):Ae=t[92];let Je;t[93]!==e?(Je=e("settings.projects.page.field.none"),t[93]=e,t[94]=Je):Je=t[94];let de;t[95]===Symbol.for("react.memo_cache_sentinel")?(de=s.jsx(P,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[95]=de):de=t[95];let ze;t[96]!==Ae||t[97]!==Je?(ze=s.jsx("button",{type:"button",onClick:Y,className:Ae,title:Je,children:de}),t[96]=Ae,t[97]=Je,t[98]=ze):ze=t[98];let rt;t[99]!==w?(rt=Vb.map(wt=>s.jsx("button",{type:"button",onClick:()=>b(wt.key),className:ce("h-7 w-7 rounded-md border transition-colors",w===wt.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:wt.cssVar},title:wt.label},wt.key)),t[99]=w,t[100]=rt):rt=t[100];let Re;t[101]!==ze||t[102]!==rt?(Re=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[ze,rt]}),t[101]=ze,t[102]=rt,t[103]=Re):Re=t[103];let Xe;t[104]!==Z||t[105]!==Re?(Xe=s.jsxs("div",{className:"py-1.5",children:[Z,Re]}),t[104]=Z,t[105]=Re,t[106]=Xe):Xe=t[106];let qe;t[107]!==e?(qe=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=qe):qe=t[108];let Te;t[109]!==qe?(Te=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:qe})}),t[109]=qe,t[110]=Te):Te=t[110];let We;t[111]!==se?(We=s.jsx("input",{ref:_,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:wt=>{const Qt=wt.target.files?.[0]??null;se(Qt),wt.currentTarget.value=""}}),t[111]=se,t[112]=We):We=t[112];let Ze;t[113]===Symbol.for("react.memo_cache_sentinel")?(Ze=()=>g(null),t[113]=Ze):Ze=t[113];const Qe=y===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let he;t[114]!==Qe?(he=ce("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Qe),t[114]=Qe,t[115]=he):he=t[115];let Ge;t[116]!==e?(Ge=e("settings.projects.page.field.none"),t[116]=e,t[117]=Ge):Ge=t[117];let Ve;t[118]===Symbol.for("react.memo_cache_sentinel")?(Ve=s.jsx(P,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[118]=Ve):Ve=t[118];let it;t[119]!==he||t[120]!==Ge?(it=s.jsx("button",{type:"button",onClick:Ze,className:he,title:Ge,children:Ve}),t[119]=he,t[120]=Ge,t[121]=it):it=t[121];let dt;t[122]!==K||t[123]!==y?(dt=_b.map(wt=>{const Qt=wt.Icon;return s.jsx("button",{type:"button",onClick:()=>g(wt.key),className:ce("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",y===wt.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:wt.label,children:s.jsx(P,{name:Qt,className:"w-4 h-4",style:K&&y===wt.key?{color:K}:void 0})},wt.key)}),t[122]=K,t[123]=y,t[124]=dt):dt=t[124];let Ye;t[125]!==it||t[126]!==dt?(Ye=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[it,dt]}),t[125]=it,t[126]=dt,t[127]=Ye):Ye=t[127];let _e;t[128]!==be||t[129]!==k||t[130]!==ie||t[131]!==e?(_e=be&&ie&&s.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.projects.page.field.preview")}),s.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/60 bg-[var(--surface-elevated)] p-1",children:s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:k?{backgroundColor:k}:void 0,children:s.jsx("img",{src:ie,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>$(!0)})})})]}),t[128]=be,t[129]=k,t[130]=ie,t[131]=e,t[132]=_e):_e=t[132];let et;t[133]!==be||t[134]!==k||t[135]!==e?(et=be&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:k??"#000000",onChange:wt=>I(wt.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":e("settings.projects.page.field.projectIconBackgroundAria")}),s.jsx(Bt,{value:k??"",onChange:wt=>I(wt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(ge,{type:"button",size:"xs",variant:"outline",onClick:()=>I(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!k,children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]}),t[133]=be,t[134]=k,t[135]=e,t[136]=et):et=t[136];let gt;t[137]!==we||t[138]!==re||t[139]!==T||t[140]!==j||t[141]!==e?(gt=!re&&s.jsxs(s.Fragment,{children:[s.jsx(ge,{size:"xs",className:"h-6 !font-normal",onClick:()=>_.current?.click(),disabled:j,children:e(j?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(ge,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{we()},disabled:T,children:e(T?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=we,t[138]=re,t[139]=T,t[140]=j,t[141]=e,t[142]=gt):gt=t[142];let Lt;t[143]!==Ce||t[144]!==pe||t[145]!==D||t[146]!==e?(Lt=pe&&s.jsx(ge,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Ce()},disabled:D,children:e(D?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=Ce,t[144]=pe,t[145]=D,t[146]=e,t[147]=Lt):Lt=t[147];let Ut;t[148]!==D||t[149]!==S||t[150]!==e?(Ut=S&&s.jsx(ge,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>M(!1),disabled:D,children:e("settings.projects.page.actions.undoRemove")}),t[148]=D,t[149]=S,t[150]=e,t[151]=Ut):Ut=t[151];let mt;t[152]!==gt||t[153]!==Lt||t[154]!==Ut?(mt=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[gt,Lt,Ut]}),t[152]=gt,t[153]=Lt,t[154]=Ut,t[155]=mt):mt=t[155];let Nt;t[156]!==Te||t[157]!==We||t[158]!==Ye||t[159]!==_e||t[160]!==et||t[161]!==mt?(Nt=s.jsxs("div",{className:"py-1.5",children:[Te,We,Ye,_e,et,mt]}),t[156]=Te,t[157]=We,t[158]=Ye,t[159]=_e,t[160]=et,t[161]=mt,t[162]=Nt):Nt=t[162];let Xt;t[163]!==fe||t[164]!==Xe||t[165]!==Nt?(Xt=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[fe,Xe,Nt]}),t[163]=fe,t[164]=Xe,t[165]=Nt,t[166]=Xt):Xt=t[166];let _t;t[167]!==U||t[168]!==D||t[169]!==j||t[170]!==f?(_t=!U||f.trim().length===0||j||D,t[167]=U,t[168]=D,t[169]=j,t[170]=f,t[171]=_t):_t=t[171];let Gt;t[172]!==e?(Gt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=Gt):Gt=t[173];let lt;t[174]!==te||t[175]!==_t||t[176]!==Gt?(lt=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(ge,{onClick:te,disabled:_t,size:"xs",className:"!font-normal",children:Gt})}),t[174]=te,t[175]=_t,t[176]=Gt,t[177]=lt):lt=t[177];let Tt;t[178]!==Xt||t[179]!==lt?(Tt=s.jsxs("div",{className:"mb-8",children:[Xt,lt]}),t[178]=Xt,t[179]=lt,t[180]=Tt):Tt=t[180];let rs;t[181]!==Q?(rs=Q&&s.jsx(S3,{projectRef:Q}),t[181]=Q,t[182]=rs):rs=t[182];let js;t[183]!==rs?(js=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:rs})}),t[183]=rs,t[184]=js):js=t[184];let ys;t[185]!==e?(ys=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=ys):ys=t[186];let vs;t[187]!==ys?(vs=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:ys})}),t[187]=ys,t[188]=vs):vs=t[188];let Wt;t[189]!==Q?(Wt=Q&&s.jsx(w3,{projectRef:Q}),t[189]=Q,t[190]=Wt):Wt=t[190];let He;t[191]!==Wt?(He=s.jsx("section",{className:"px-2 pb-2 pt-0",children:Wt}),t[191]=Wt,t[192]=He):He=t[192];let kt;t[193]!==vs||t[194]!==He?(kt=s.jsxs("div",{className:"mb-8",children:[vs,He]}),t[193]=vs,t[194]=He,t[195]=kt):kt=t[195];let Kt;return t[196]!==Me||t[197]!==Tt||t[198]!==js||t[199]!==kt?(Kt=s.jsx(Cs,{outerClassName:"h-full",className:"w-full bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:[Me,Tt,js,kt]})}),t[196]=Me,t[197]=Tt,t[198]=js,t[199]=kt,t[200]=Kt):Kt=t[200],Kt};function C3(t){return t.projects}function P3(t){return t.updateProjectMeta}function I3(t){return t.uploadProjectIcon}function A3(t){return t.removeProjectIcon}function D3(t){return t.discoverProjectIcon}function T3(t){return t.settingsProjectsSelectedId}function M3(t){return t.setSettingsProjectsSelectedId}function E3(t){return t&&URL.revokeObjectURL(t),null}const R3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,F3=()=>Math.floor(2e4+Math.random()*3e4),L3=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},O3=t=>{switch(t){case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"error":return"settings.remoteInstances.sidebar.phase.error";case"degraded":return"settings.remoteInstances.sidebar.phase.reconnect";case"installing":return"settings.remoteInstances.sidebar.phase.installing";case"updating":return"settings.remoteInstances.sidebar.phase.updating";case"forwarding":return"settings.remoteInstances.sidebar.phase.forwarding";case"server_starting":return"settings.remoteInstances.sidebar.phase.starting";case"master_connecting":return"settings.remoteInstances.sidebar.phase.connecting";default:return"settings.remoteInstances.sidebar.phase.idle"}},$3=({onItemSelect:t})=>{const{t:e}=ut(),n=Ys(g=>g.instances),r=Ys(g=>g.statusesById),i=Ys(g=>g.isLoading),a=Ys(g=>g.load),l=Ys(g=>g.loadImports),c=Ys(g=>g.createFromCommand),d=Ys(g=>g.connect),p=Ys(g=>g.disconnect),m=Ys(g=>g.retry),u=Ys(g=>g.removeInstance),h=Ys(g=>g.upsertInstance),x=Ie(g=>g.settingsRemoteInstancesSelectedId),f=Ie(g=>g.setSettingsRemoteInstancesSelectedId);o.useEffect(()=>{a(),l()},[a,l]),o.useEffect(()=>{if(!i){if(n.length===0){x!==null&&f(null);return}x&&n.some(g=>g.id===x)||f(n[0].id)}},[n,i,x,f]);const v=o.useCallback(async()=>{const g=R3();try{await c(g,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),f(g),t?.()}catch(w){H.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:w instanceof Error?w.message:String(w)})}},[c,t,f,e]),y=o.useCallback(async g=>{try{await d(g.id);return}catch(w){if(!L3(w)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw w;const k={...g,localForward:{...g.localForward,preferredLocalPort:F3()}};await h(k),await d(k.id),H.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,h]);return s.jsx(hg,{variant:"background",header:s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.remoteInstances.sidebar.title")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.remoteInstances.sidebar.total",{count:n.length})}),s.jsx(ge,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{v()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(P,{name:"add",className:"size-4"})})]})]}),children:n.map(g=>{const w=r[g.id],b=g.id===x,k=g.nickname?.trim()||g.sshParsed?.destination||g.id,I=`${e(O3(w?.phase))}${w?.localUrl?` · ${w.localUrl}`:""}`,j=w?.phase==="ready",N=w?.phase==="error"||w?.phase==="degraded";return s.jsx(gg,{title:k,metadata:I,selected:b,onSelect:()=>{f(g.id),t?.()},actions:[{label:e(j?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:j?"stop":"plug-2",onClick:()=>{(j?p(g.id):y(g)).catch(E=>{H.error(e(j?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:E instanceof Error?E.message:String(E)})})}},{label:e("settings.remoteInstances.sidebar.actions.retry"),icon:"refresh",onClick:()=>{N&&m(g.id).catch(D=>{H.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:D instanceof Error?D.message:String(D)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:"delete-bin",destructive:!0,onClick:()=>{u(g.id).then(()=>{if(x===g.id){const D=n.find(E=>E.id!==g.id);f(D?.id||null)}}).catch(D=>{H.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:D instanceof Error?D.message:String(D)})})}}]},g.id)})})},yp=t=>{const e=at.c(10),{children:n,className:r,outerClassName:i}=t;let a;e[0]!==i?(a=ce("h-full",i),e[0]=i,e[1]=a):a=e[1];let l;e[2]!==r?(l=ce("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",r),e[2]=r,e[3]=l):l=e[3];let c;e[4]!==n||e[5]!==l?(c=s.jsx("div",{className:l,children:n}),e[4]=n,e[5]=l,e[6]=c):c=e[6];let d;return e[7]!==a||e[8]!==c?(d=s.jsx(Cs,{outerClassName:a,className:"w-full",children:c}),e[7]=a,e[8]=c,e[9]=d):d=e[9],d},yd=()=>Math.floor(2e4+Math.random()*3e4),B3=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},z3=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingVinci";case"updating":return"settings.remoteInstances.page.phase.updatingVinci";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},V3=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),xg=t=>!!(t&&V3.has(t)),_3=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||xg(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",U3=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,W3=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:yd(),remoteHost:"127.0.0.1",remotePort:80}),K3=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Qr=t=>{const e=at.c(8),{label:n,hint:r}=t;let i;e[0]!==n?(i=s.jsx("span",{children:n}),e[0]=n,e[1]=i):i=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=a):a=e[2];let l;e[3]!==r?(l=s.jsxs(Pt,{children:[a,s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s.jsx("div",{className:"typography-meta text-foreground",children:r})})]}),e[3]=r,e[4]=l):l=e[4];let c;return e[5]!==i||e[6]!==l?(c=s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[i,l]}),e[5]=i,e[6]=l,e[7]=c):c=e[7],c},H3=t=>{switch(t){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},vp=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},G3=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},q3=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const n=Number(e[1]),r=Number.isFinite(n)?new Date(n).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),a=e[3]||"";return`[${r}] [${i}] ${a}`},Y3=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Q3=t=>{const e=t.sshCommand.trim(),n=t.nickname?.trim(),r=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...n?{nickname:n}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteVinci:{...t.remoteVinci,preferredPort:typeof t.remoteVinci.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteVinci.preferredPort))):void 0},portForwards:r}},J3=()=>{const{t}=ut(),e=Ys(L=>L.instances),n=Ys(L=>L.statusesById),r=Ys(L=>L.importCandidates),i=Ys(L=>L.isImportsLoading),a=Ys(L=>L.isSaving),l=Ys(L=>L.error),c=Ys(L=>L.load),d=Ys(L=>L.loadImports),p=Ys(L=>L.refreshStatuses),m=Ys(L=>L.upsertInstance),u=Ys(L=>L.createFromCommand),h=Ys(L=>L.removeInstance),x=Ys(L=>L.connect),f=Ys(L=>L.disconnect),v=Ys(L=>L.retry),y=Ie(L=>L.settingsRemoteInstancesSelectedId),g=Ie(L=>L.setSettingsRemoteInstancesSelectedId),w=o.useMemo(()=>y&&e.find(L=>L.id===y)||null,[e,y]),[b,k]=o.useState(null),[I,j]=o.useState(!1),[N,D]=o.useState(!1),[E,T]=o.useState(null),[C,S]=o.useState([]),[M,A]=o.useState(null),[R,z]=o.useState(""),[B,V]=o.useState(!1),[$,_]=o.useState({}),[X,O]=o.useState(!1),[J,Q]=o.useState(!1),[ne,G]=o.useState(()=>Date.now());o.useEffect(()=>{c(),d()},[c,d]),o.useEffect(()=>{k(w)},[w]),o.useEffect(()=>{if(!y)return;const L=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||p()},2e3);return()=>{window.clearInterval(L)}},[p,y]),o.useEffect(()=>{let L=null,Z=Date.now();const Y=()=>{const Ae=Date.now();Ae-Z>=1e3&&(G(Ae),Z=Ae),L=requestAnimationFrame(Y)};(typeof document>"u"||document.visibilityState==="visible")&&(L=requestAnimationFrame(Y));const Ee=()=>{document.visibilityState==="visible"&&L===null?L=requestAnimationFrame(Y):document.visibilityState!=="visible"&&L!==null&&(cancelAnimationFrame(L),L=null)};return document.addEventListener("visibilitychange",Ee),()=>{document.removeEventListener("visibilitychange",Ee),L!==null&&cancelAnimationFrame(L)}},[]);const le=y?n[y]:null,oe=le?.phase,F=oe==="ready",U=oe==="degraded",W=xg(oe),K=F||(W||U),ae=le?Math.max(0,ne-le.updatedAtMs):0,ve=U&&ae>12e3,re=o.useMemo(()=>!b||!w?!1:JSON.stringify(b)!==JSON.stringify(w),[b,w]),be=o.useCallback(L=>{k(Z=>Z&&L(Z))},[]),pe=o.useCallback(async()=>{if(!b)return;const L=Q3(b);if(!L.sshCommand.trim()){H.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(L.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(L.auth.sshPassword?.enabled&&L.auth.sshPassword.value?.trim()&&L.auth.sshPassword.store!=="settings"){const Z=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));L.auth.sshPassword.store=Z?"settings":"never",Z||(L.auth.sshPassword.value=void 0)}if(L.auth.vinciPassword?.enabled&&L.auth.vinciPassword.value?.trim()&&L.auth.vinciPassword.store!=="settings"){const Z=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));L.auth.vinciPassword.store=Z?"settings":"never",Z||(L.auth.vinciPassword.value=void 0)}try{await m(L),H.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(Z){H.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:Z instanceof Error?Z.message:String(Z)})}}},[b,t,m]),ye=o.useCallback(async(L,Z)=>{const Y=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(Y,`ssh ${Z}`,L),g(Y),H.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Ee){return H.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Ee instanceof Error?Ee.message:String(Ee)}),!1}},[u,g,t]),ie=o.useCallback(()=>{B||(A(null),z(""))},[B]),ue=o.useCallback((L,Z)=>{if(Z){A(L),z(K3(L));return}ye(L,L)},[ye]),se=o.useCallback(async()=>{const L=M,Z=R.trim();if(L){if(!Z){H.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}V(!0);try{await ye(L,Z)&&(A(null),z(""))}finally{V(!1)}}},[ye,R,M,t]),Ne=o.useCallback(async()=>{if(w)try{await x(w.id);return}catch(L){if(!B3(L)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw L;const Y={...w,localForward:{...w.localForward,preferredLocalPort:yd()}};await m(Y),await x(Y.id),H.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[x,w,t,m]),Ce=o.useCallback(async L=>(await Ub(L,600)).map(Y=>q3(Y)),[]),je=o.useCallback(async()=>{if(b){j(!0),D(!0),T(null);try{const L=await Ce(b.id);S(L)}catch(L){S([]),T(L instanceof Error?L.message:String(L))}finally{D(!1)}}},[b,Ce]);o.useEffect(()=>{if(!I||!b)return;let L=!1;const Z=async()=>{try{const Ee=await Ce(b.id);L||(S(Ee),T(null))}catch(Ee){L||T(Ee instanceof Error?Ee.message:String(Ee))}};Z();const Y=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Z()},1e3);return()=>{L=!0,window.clearInterval(Y)}},[b,I,Ce]);const we=o.useMemo(()=>C.join(`
|
|
176
|
+
`),[C]),ke=o.useCallback(()=>{if(!we.trim()){H.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}_n(we).then(L=>{L.ok&&H.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[we,t]),xe=o.useCallback(async()=>{if(b)try{await Wb(b.id),S([]),H.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(L){H.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:L instanceof Error?L.message:String(L)})}},[b,t]),me=o.useCallback(async()=>{if(!le?.localUrl){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const L=le.localUrl.trim();if(!L){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Y3(L)},[le?.localUrl,t]),Me=o.useCallback(()=>{if(!b)return;O(!0),(K?f(b.id):Ne()).catch(Z=>{const Y=K?F?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";H.error(t(Y),{description:Z instanceof Error?Z.message:String(Z)})}).finally(()=>{O(!1)})},[K,Ne,f,b,F,t]),Ue=o.useCallback(()=>{if(!b||W)return;Q(!0),(U?f(b.id).then(()=>Ne()):v(b.id)).catch(Z=>{H.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:Z instanceof Error?Z.message:String(Z)})}).finally(()=>{Q(!1)})},[Ne,f,b,W,U,v,t]),q=t(W?"settings.remoteInstances.page.actions.connecting":U?ve?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Se=!X&&!J&&(oe==="error"||oe==="idle"||!oe||U&&ve)&&!W,$e=t(F?"settings.remoteInstances.sidebar.actions.disconnect":K?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!b)return s.jsxs(yp,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.description")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.empty.selectInstance")})})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.import.sectionTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneFound")}):s.jsx("div",{className:"space-y-2",children:r.map(L=>s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--interactive-border)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label text-foreground truncate",children:[L.host,L.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[L.source," config"]})]}),s.jsx(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ue(L.host,L.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${L.source}:${L.host}`))})})]}),s.jsx(hs,{open:!!M,onOpenChange:L=>{L||ie()},children:s.jsxs(fs,{className:"sm:max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Is,{children:M?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:M}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),se()},children:[s.jsx(Bt,{value:R,onChange:L=>z(L.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ie,disabled:B,children:t("settings.common.actions.cancel")}),s.jsx(ge,{type:"submit",size:"xs",className:"!font-normal",disabled:B,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Pe=b.remoteVinci.mode==="managed",fe=b.nickname?.trim()||b.sshParsed?.destination||b.id;return s.jsxs(yp,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:fe}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${_3(oe)}`}),s.jsx("span",{children:t(z3(oe))}),le?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:le.localUrl}):null,ve?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.actions")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.actionsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ge,{type:"button",variant:K?"outline":"default",size:"xs",className:"!font-normal",onClick:Me,disabled:X||J,children:[K?s.jsx(P,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"plug-2",className:"h-3.5 w-3.5"}),$e]}),s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ue,disabled:!Se,children:[s.jsx(P,{name:"refresh",className:`h-3.5 w-3.5 ${W||U&&!ve?"animate-spin":""}`}),q]}),s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{je()},children:[s.jsx(P,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&h(b.id).then(()=>{g(null),H.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(Z=>{H.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Z instanceof Error?Z.message:String(Z)})})},children:[s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),le?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:le.localUrl})]}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.instance")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.instanceDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(Bt,{className:"h-7 md:max-w-xl",value:b.sshCommand,onChange:L=>be(Z=>({...Z,sshCommand:L.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(Bt,{className:"h-7 md:max-w-sm",value:b.nickname||"",onChange:L=>be(Z=>({...Z,nickname:L.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(Vn,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:b.connectionTimeoutSec,onValueChange:L=>{be(Z=>({...Z,connectionTimeoutSec:Number.isFinite(L)?L:Z.connectionTimeoutSec}))}})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.remoteServer")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.remoteServerDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qr,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(is,{value:b.remoteVinci.mode,onValueChange:L=>be(Z=>({...Z,remoteVinci:{...Z.remoteVinci,mode:L==="external"?"external":"managed"}})),children:[s.jsx(as,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(Ft,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qr,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(Vn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:b.remoteVinci.preferredPort,onValueChange:L=>{be(Z=>({...Z,remoteVinci:{...Z.remoteVinci,preferredPort:Number.isFinite(L)&&L>0?L:void 0}}))},onClear:()=>{be(L=>({...L,remoteVinci:{...L.remoteVinci,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Pe?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qr,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(is,{value:b.remoteVinci.installMethod,onValueChange:L=>be(Z=>({...Z,remoteVinci:{...Z.remoteVinci,installMethod:L==="npm"||L==="download_release"||L==="upload_bundle"?L:"bun"}})),children:[s.jsx(as,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"bun",children:"bun"}),s.jsx(Ft,{value:"npm",children:"npm"}),s.jsx(Ft,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(Ft,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,Pe?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qr,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(xl,{checked:b.remoteVinci.keepRunning,onCheckedChange:L=>be(Z=>({...Z,remoteVinci:{...Z.remoteVinci,keepRunning:L}}))})})]}):null]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.mainTunnel")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.mainTunnelDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qr,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(is,{value:b.localForward.bindHost,onValueChange:L=>{L==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||be(Z=>({...Z,localForward:{...Z.localForward,bindHost:L==="localhost"||L==="0.0.0.0"?L:"127.0.0.1"}}))},children:[s.jsx(as,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(Ft,{value:"localhost",children:"localhost"}),s.jsx(Ft,{value:"0.0.0.0",children:"0.0.0.0"})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qr,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(Vn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:b.localForward.preferredLocalPort,onValueChange:L=>{be(Z=>({...Z,localForward:{...Z.localForward,preferredLocalPort:Number.isFinite(L)&&L>0?L:void 0}}))},onClear:()=>{be(L=>({...L,localForward:{...L.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>be(L=>({...L,localForward:{...L.localForward,preferredLocalPort:yd()}})),children:s.jsx(P,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.authentication")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.authenticationDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshPasswordOptional")}),s.jsx(Bt,{className:"h-7 md:max-w-sm",type:"password",value:b.auth.sshPassword?.value||"",onChange:L=>be(Z=>({...Z,auth:{...Z.auth,sshPassword:{enabled:L.target.value.trim().length>0,value:L.target.value,store:Z.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.uiPasswordOptional")}),s.jsx(Bt,{className:"h-7 md:max-w-sm",type:"password",value:b.auth.vinciPassword?.value||"",onChange:L=>be(Z=>({...Z,auth:{...Z.auth,vinciPassword:{enabled:L.target.value.trim().length>0,value:L.target.value,store:Z.auth.vinciPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.portForwards")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.portForwardsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[b.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,b.portForwards.map((L,Z)=>{const Y=We=>{be(Ze=>({...Ze,portForwards:Ze.portForwards.map((Qe,he)=>he===Z?We(Qe):Qe)}))},Ee=L.type==="remote"?"Local target":"Local listen",Ae=L.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",Je=L.type==="remote"?"Remote listen":"Remote target",de=L.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",ze=vp(L.localHost||"localhost",L.localPort),rt=vp(L.remoteHost||"localhost",L.remotePort),Re=L.type==="local"&&typeof L.localPort=="number"&&L.localPort>0,Xe=Re?`http://${G3(L.localHost)}:${L.localPort}`:"",qe=!!$[L.id],Te=L.type==="local"?t("settings.remoteInstances.page.forwardType.local"):L.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(fr,{open:qe,onOpenChange:We=>{_(Ze=>({...Ze,[L.id]:We}))},className:`${Z>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(Pr,{className:"flex items-center gap-2 group",children:[s.jsx(P,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${qe?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:U3(L)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Te})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xl,{checked:L.enabled,onCheckedChange:We=>Y(Ze=>({...Ze,enabled:We})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(ge,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>be(We=>({...We,portForwards:We.portForwards.filter(Ze=>Ze.id!==L.id)})),children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(hr,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:t(H3(L.type))}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qr,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(is,{value:L.type,onValueChange:We=>Y(Ze=>({...Ze,type:We==="dynamic"||We==="remote"?We:"local"})),children:[s.jsx(as,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(Ft,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(Ft,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qr,{label:Ee,hint:Ae})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{className:"h-7 w-32",value:L.localHost||"127.0.0.1",onChange:We=>Y(Ze=>({...Ze,localHost:We.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Vn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:L.localPort,onValueChange:We=>{Y(Ze=>({...Ze,localPort:Number.isFinite(We)&&We>0?We:void 0}))},onClear:()=>{Y(We=>({...We,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),L.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qr,{label:Je,hint:de})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{className:"h-7 w-32",value:L.remoteHost||"",onChange:We=>Y(Ze=>({...Ze,remoteHost:We.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Vn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:L.remotePort,onValueChange:We=>{Y(Ze=>({...Ze,remotePort:Number.isFinite(We)&&We>0?We:void 0}))},onClear:()=>{Y(We=>({...We,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:L.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ze}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):L.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:rt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(P,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(P,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ze}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ze}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(P,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(P,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:rt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Re?s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rr(Xe).then(We=>{We||H.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(P,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},L.id)}),s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const L=W3();be(Z=>({...Z,portForwards:[...Z.portForwards,L]})),_(Z=>({...Z,[L.id]:!0}))},children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.import.sectionTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneAvailable")}):s.jsx("div",{children:r.slice(0,8).map((L,Z)=>s.jsxs("div",{className:`flex items-center justify-between gap-2 px-1 py-2 ${Z>0?"border-t border-[var(--surface-subtle)]":""}`,children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label text-foreground truncate",children:[L.host,L.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:L.sshCommand})]}),s.jsx(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ue(L.host,L.pattern)},children:t("settings.common.actions.import")})]},`${L.source}:${L.host}`))})})]}),s.jsx("div",{className:"sticky bottom-0 z-10 -mx-3 sm:-mx-6 bg-[var(--surface-background)] border-t border-[var(--interactive-border)] px-3 sm:px-6 py-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{pe()},disabled:!re||a,children:t("settings.common.actions.saveChanges")}),le?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_n(le.localUrl||"").then(L=>{L.ok&&H.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(P,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{me()},children:[s.jsx(P,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,l?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:l}):null]})}),s.jsx(hs,{open:I,onOpenChange:j,children:s.jsxs(fs,{className:"sm:max-w-2xl",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Is,{children:b?.nickname?.trim()||b?.sshParsed?.destination||b?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ke,disabled:N||!we.trim(),children:[s.jsx(P,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{xe()},disabled:N,children:[s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),N?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):E?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:E}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:C.length>0?C.join(`
|
|
177
|
+
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(hs,{open:!!M,onOpenChange:L=>{L||ie()},children:s.jsxs(fs,{className:"sm:max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Is,{children:M?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:M}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),se()},children:[s.jsx(Bt,{value:R,onChange:L=>z(L.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ie,disabled:B,children:t("settings.common.actions.cancel")}),s.jsx(ge,{type:"submit",size:"xs",className:"!font-normal",disabled:B,children:t("settings.common.actions.create")})]})]})]})})]})},X3="__add_provider__",Z3=()=>{const t=Zs.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},e5=({onItemSelect:t})=>{const{t:e}=ut(),n=xt(h=>h.providers),r=xt(h=>h.selectedProviderId),i=xt(h=>h.setSelectedProvider),a=As(h=>h.activeProjectId),[l,c]=o.useState({}),d=o.useMemo(()=>Z3(),[a]);o.useEffect(()=>{if(n.length===0){c({});return}let h=!1;return(async()=>{const f=n.map(async v=>{try{const y=d?`?directory=${encodeURIComponent(d)}`:"",g=await fetch(`/api/provider/${encodeURIComponent(v.id)}/source${y}`,{method:"GET",headers:{Accept:"application/json"}});if(!g.ok)return;const w=await g.json().catch(()=>null),b=w?.sources??w?.data?.sources;if(!b||h)return;c(k=>({...k,[v.id]:b}))}catch{}});await Promise.all(f)})(),()=>{h=!0}},[d,n]);const p="bg-background",m=o.useMemo(()=>n.filter(h=>!!l[h.id]?.project?.exists),[n,l]),u=o.useMemo(()=>n.filter(h=>!l[h.id]?.project?.exists),[n,l]);return s.jsxs("div",{className:ce("flex h-full flex-col",p),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.providers.sidebar.title")}),s.jsx(vo,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(ge,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{i(X3),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(P,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(P,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[u.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),u.map(h=>s.jsx(wp,{provider:h,selectedProviderId:r,onSelect:()=>{i(h.id),t?.()}},h.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ce("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",u.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(h=>s.jsx(wp,{provider:h,selectedProviderId:r,onSelect:()=>{i(h.id),t?.()}},h.id))]})]})})]})},wp=t=>{const e=at.c(17),{provider:n,selectedProviderId:r,onSelect:i}=t,a=Array.isArray(n.models)?n.models.length:0,l=n.id===r,c=n.id,d=l?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==d?(p=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",d),e[0]=d,e[1]=p):p=e[1];let m;e[2]!==n.id?(m=s.jsx(vn,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const u=n.name||n.id;let h;e[4]!==u?(h=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:u}),e[4]=u,e[5]=h):h=e[5];let x;e[6]!==a?(x=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:a}),e[6]=a,e[7]=x):x=e[7];let f;e[8]!==i||e[9]!==m||e[10]!==h||e[11]!==x?(f=s.jsxs("button",{type:"button",onClick:i,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,h,x]}),e[8]=i,e[9]=m,e[10]=h,e[11]=x,e[12]=f):f=e[12];let v;return e[13]!==n.id||e[14]!==p||e[15]!==f?(v=s.jsx("div",{className:p,children:f},c),e[13]=n.id,e[14]=p,e[15]=f,e[16]=v):v=e[16],v},t5=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),jp=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=t5.format(t);return e.endsWith(".0")?e.slice(0,-2):e},zo="__add_provider__",wa=t=>typeof t=="object"&&t!==null,Np=t=>{const e=typeof t.type=="string"?t.type:"",n=`${t.name??""} ${t.label??""}`.toLowerCase(),r=`${e} ${n}`.toLowerCase();return r.includes("oauth")?"oauth":r.includes("api")?"api":e.toLowerCase()},s5=t=>{if(!wa(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(i=>wa(i)));return e},n5=t=>{if(typeof t=="string")return{id:t};if(!wa(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const n=typeof t.name=="string"?t.name:void 0;return{id:e,name:n}},r5=t=>{let e=[];Array.isArray(t)?e=t:wa(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(i=>n5(i)).filter(i=>!!i),r=new Set;return n.filter(i=>r.has(i.id)?!1:(r.add(i.id),!0))},i5=()=>{const{t}=ut(),e=xt(ie=>ie.providers),n=xt(ie=>ie.selectedProviderId),r=xt(ie=>ie.setSelectedProvider),i=xt(ie=>ie.getModelMetadata),a=Ie(ie=>ie.hiddenModels),l=Ie(ie=>ie.toggleHiddenModel),c=Ie(ie=>ie.hideAllModels),d=Ie(ie=>ie.showAllModels),[p,m]=o.useState({}),[u,h]=o.useState(!1),[x,f]=o.useState({}),[v,y]=o.useState(null),[g,w]=o.useState(""),[b,k]=o.useState(null),[I,j]=o.useState({}),[N,D]=o.useState({}),[E,T]=o.useState([]),[C,S]=o.useState(!1),[M,A]=o.useState(null),[R,z]=o.useState(""),[B,V]=o.useState(""),[$,_]=o.useState(!1),[X,O]=o.useState({}),[J,Q]=o.useState(!1);o.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),o.useEffect(()=>{let ie=!0;return(async()=>{h(!0);try{const se=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!se.ok)throw new Error(`Auth methods request failed (${se.status})`);const Ne=await se.json().catch(()=>({}));if(!ie)return;m(s5(Ne))}catch(se){if(!ie)return;console.error("Failed to load provider auth methods:",se),H.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{ie&&h(!1)}})(),()=>{ie=!1}},[t]),o.useEffect(()=>{let ie=!0;return(async()=>{S(!0),A(null);try{const se=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!se.ok)throw new Error(`Provider list request failed (${se.status})`);const Ne=await se.json().catch(()=>({}));if(!ie)return;T(r5(Ne))}catch(se){if(!ie)return;console.error("Failed to load available providers:",se),A(t("settings.providers.page.state.unableToLoadProviderList"))}finally{ie&&S(!1)}})(),()=>{ie=!1}},[t]);const ne=o.useMemo(()=>new Set(e.map(ie=>ie.id)),[e]),G=o.useMemo(()=>E.filter(ie=>!ne.has(ie.id)).sort((ie,ue)=>{const se=(ie.name||ie.id).toLowerCase(),Ne=(ue.name||ue.id).toLowerCase();return se.localeCompare(Ne)}),[E,ne]);o.useEffect(()=>{n===zo&&R&&!G.some(ie=>ie.id===R)&&z("")},[n,R,G]),o.useEffect(()=>{if(n===zo){Q(!0);return}Q(!1)},[n,t]),o.useEffect(()=>{if(!n||n===zo)return;let ie=!1;return(async()=>{try{const se=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),Ne=await se.json().catch(()=>null);if(!se.ok)throw new Error(Ne?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Ce=Ne?.sources??Ne?.data?.sources;!ie&&Ce&&O(je=>({...je,[n]:Ce}))}catch(se){ie||console.error("Failed to load provider sources:",se)}})(),()=>{ie=!0}},[n,t]);const le=e.find(ie=>ie.id===n),oe=n?X[n]:void 0,F=async ie=>{const ue=x[ie]?.trim()??"";if(!ue){H.error(t("settings.providers.page.toast.apiKeyRequired"));return}const se=`api:${ie}`;y(se);try{const Ne=await fetch(`/api/auth/${encodeURIComponent(ie)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:ue})}),Ce=await Ne.json().catch(()=>null);if(!Ne.ok){const je=Ce?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(je)}H.success(t("settings.providers.page.toast.apiKeySaved")),f(je=>({...je,[ie]:""})),await Fi({scopes:["providers"],mode:"active"}),r(ie)}catch(Ne){console.error("Failed to save API key:",Ne),H.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{y(null)}},U=async(ie,ue)=>{const se=`oauth:${ie}:${ue}`;y(se);try{const Ne=await fetch(`/api/provider/${encodeURIComponent(ie)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:ue})}),Ce=await Ne.json().catch(()=>null);if(!Ne.ok){const Ue=Ce?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(Ue)}const je=wa(Ce)?Ce:{},we=wa(je.data)?je.data:je,ke=typeof we.url=="string"&&we.url||typeof we.verification_uri_complete=="string"&&we.verification_uri_complete||typeof we.verification_uri=="string"&&we.verification_uri||void 0,xe=typeof we.instructions=="string"&&we.instructions||typeof we.message=="string"&&we.message||void 0,me=typeof we.user_code=="string"&&we.user_code||typeof we.code=="string"&&we.code||typeof we.userCode=="string"&&we.userCode||void 0;if(!ke&&!xe&&!me)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const Me=`${ie}:${ue}`;D(Ue=>({...Ue,[Me]:{url:ke,instructions:xe,userCode:me}})),ke&&rr(ke),k({providerId:ie,methodIndex:ue}),H.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(Ne){console.error("Failed to start OAuth flow:",Ne),H.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{y(null)}},W=async(ie,ue)=>{const se=`${ie}:${ue}`,Ne=I[se]?.trim(),Ce=`oauth-complete:${ie}:${ue}`;y(Ce);try{const je={method:ue};Ne&&(je.code=Ne);const we=await fetch(`/api/provider/${encodeURIComponent(ie)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(je)}),ke=await we.json().catch(()=>null);if(!we.ok){const xe=ke?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(xe)}H.success(t("settings.providers.page.toast.oauthCompleted")),j(xe=>({...xe,[se]:""})),k(null),await Fi({scopes:["providers"],mode:"active"}),r(ie)}catch(je){console.error("Failed to complete OAuth flow:",je),H.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{y(null)}},te=async ie=>{const ue=await _n(ie);if(ue.ok){H.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",ue.error),H.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},K=async ie=>{const ue=await _n(ie);if(ue.ok){H.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",ue.error),H.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},ae=async ie=>{const ue=`disconnect:${ie}`;y(ue);try{const se=await fetch(`/api/provider/${encodeURIComponent(ie)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),Ne=await se.json().catch(()=>null);if(!se.ok){const Ce=Ne?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(Ce)}H.success(t("settings.providers.page.toast.providerDisconnected")),await Fi({scopes:["providers"],mode:"active"})}catch(se){console.error("Failed to disconnect provider:",se),H.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{y(null)}},ve=n===zo;if(!ve&&e.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(P,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(ve)return s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.providers.page.connect.title")})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.connect.selectProviderTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),C?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):M?s.jsx("p",{className:"typography-meta text-muted-foreground",children:M}):G.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(Fs,{open:$,onOpenChange:ie=>{_(ie),ie||V("")},children:[s.jsx(Es,{asChild:!0,children:s.jsxs("button",{type:"button",className:ce("flex items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover h-6 w-fit"),children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[R?s.jsx(vn,{providerId:R,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ce("truncate typography-ui-label font-normal",R?"text-foreground":"text-muted-foreground"),children:R?G.find(ie=>ie.id===R)?.name||R:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Rs,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:ie=>ie.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:ie=>ie.stopPropagation(),children:[s.jsx(P,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:B,onChange:ie=>V(ie.target.value),onKeyDown:ie=>ie.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Cs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const ie=G.filter(ue=>{const se=B.toLowerCase();return(ue.name||ue.id).toLowerCase().includes(se)||ue.id.toLowerCase().includes(se)});return ie.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):ie.map(ue=>s.jsxs($t,{onSelect:()=>{z(ue.id),_(!1),V("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(vn,{providerId:ue.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ue.name||ue.id})]}),R===ue.id&&s.jsx(P,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ue.id))})()})]})]})]})})]}),R&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")})}),u?s.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Bt,{type:"password",value:x[R]??"",onChange:ie=>f(ue=>({...ue,[R]:ie.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(ge,{size:"xs",className:"!font-normal shrink-0",onClick:()=>F(R),disabled:v===`api:${R}`,children:v===`api:${R}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const ue=(p[R]??[]).filter(se=>Np(se)==="oauth");return ue.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ue.map((se,Ne)=>{const Ce=se.label||se.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Ne+1)}),je=`${R}:${Ne}`,we=b?.providerId===R&&b?.methodIndex===Ne;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:Ce}),(se.description||se.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(se.description||se.help)})]}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>U(R,Ne),disabled:v===`oauth:${R}:${Ne}`,children:t("settings.providers.page.actions.connect")})]}),N[je]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:N[je]?.instructions}),N[je]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:N[je]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(N[je]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),N[je]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:N[je]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rr(N[je]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>te(N[je]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),we&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:I[je]??"",onChange:ke=>j(xe=>({...xe,[je]:ke.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(ge,{size:"xs",className:"!font-normal",onClick:()=>W(R,Ne),disabled:v===`oauth-complete:${R}:${Ne}`,children:v===`oauth-complete:${R}:${Ne}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${R}-${Ce}`)})})})()]})]})]})});if(!le)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(P,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const re=Array.isArray(le.models)?le.models:[],pe=(p[le.id]??[]).filter(ie=>Np(ie)==="oauth"),ye=re.filter(ie=>{const ue=typeof ie?.name=="string"?ie.name:"",se=typeof ie?.id=="string"?ie.id:"",Ne=g.trim().toLowerCase();return Ne?ue.toLowerCase().includes(Ne)||se.toLowerCase().includes(Ne):!0});return s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s.jsx(vn,{providerId:le.id,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:le.name||le.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:le.id})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Q(ie=>!ie),children:t(J?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:J?u?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Bt,{type:"password",value:x[le.id]??"",onChange:ie=>f(ue=>({...ue,[le.id]:ie.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(ge,{size:"xs",className:"!font-normal shrink-0",onClick:()=>F(le.id),disabled:v===`api:${le.id}`,children:v===`api:${le.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),pe.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:pe.map((ie,ue)=>{const se=ie.label||ie.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(ue+1)}),Ne=`${le.id}:${ue}`,Ce=b?.providerId===le.id&&b?.methodIndex===ue;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:se}),(ie.description||ie.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(ie.description||ie.help)})]}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>U(le.id,ue),disabled:v===`oauth:${le.id}:${ue}`,children:t("settings.providers.page.actions.connect")})]}),N[Ne]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:N[Ne]?.instructions}),N[Ne]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:N[Ne]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(N[Ne]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),N[Ne]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:N[Ne]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rr(N[Ne]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>te(N[Ne]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Ce&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:I[Ne]??"",onChange:je=>j(we=>({...we,[Ne]:je.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(ge,{size:"xs",className:"!font-normal",onClick:()=>W(le.id,ue),disabled:v===`oauth-complete:${le.id}:${ue}`,children:v===`oauth-complete:${le.id}:${ue}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${le.id}-${se}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(P,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-1",children:t("settings.providers.page.auth.useReconnectHint")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.connectionDetails.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:oe&&(oe.auth.exists||oe.user.exists||oe.project.exists||oe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[oe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,oe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,oe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,oe.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(ge,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ae(le.id),disabled:v===`disconnect:${le.id}`,children:v===`disconnect:${le.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.providers.page.models.title"),re.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",re.length,")"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const ie=re.map(ue=>typeof ue?.id=="string"?ue.id:"").filter(ue=>ue.length>0);c(le.id,ie)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(ge,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(le.id),children:t("settings.providers.page.actions.showAll")})]})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(P,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{value:g,onChange:ie=>w(ie.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ye.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:ye.map(ie=>{const ue=typeof ie?.id=="string"?ie.id:"",se=typeof ie?.name=="string"?ie.name:ue,Ne=ue?i(le.id,ue):void 0,Ce=a.some(xe=>xe.providerID===le.id&&xe.modelID===ue),je=jp(Ne?.limit?.context),we=jp(Ne?.limit?.output),ke=[];return Ne?.tool_call&&ke.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Ne?.reasoning&&ke.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Ne?.attachment&&ke.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:ce("flex items-center gap-3",Ce&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:se}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(je||we)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[je?`${je} ${t("settings.providers.page.models.tokenBadge.context")}`:"",je&&we?" · ":"",we?`${we} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),ke.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:ke.map(({key:xe,icon:me,label:Me})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Me,"aria-label":Me,children:s.jsx(P,{name:me,className:"h-3 w-3"})},xe))}),s.jsx("button",{type:"button",onClick:()=>l(le.id,ue),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(Ce?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Ce?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Ce?s.jsx(P,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ue)})})]})]})]})})},a5=t=>{const e=t?.windows??{},n=Object.values(e).map(r=>r.usedPercent).filter(r=>typeof r=="number");return n.length===0?null:Math.max(...n)},o5=t=>{const e=at.c(106),{onItemSelect:n}=t,{t:r}=ut(),i=Ms(l5),a=Ms(c5),l=Ms(d5),c=Ms(u5),d=Ms(m5),p=Ms(p5),m=Ms(f5),u=Ms(h5),h=Ms(g5),x=Ms(x5),f=Ms(b5),v=Ms(y5);let y,g;e[0]!==v?(y=()=>{v()},g=[v],e[0]=v,e[1]=y,e[2]=g):(y=e[1],g=e[2]),o.useEffect(y,g);const w=v5;let b;e[3]!==h?(b=me=>{h(me),w({usageAutoRefresh:me})},e[3]=h,e[4]=b):b=e[4];const k=b;let I;e[5]!==x?(I=me=>{const Me=Number(me);Number.isFinite(Me)&&(x(Me),w({usageRefreshIntervalMs:Me}))},e[5]=x,e[6]=I):I=e[6];const j=I;let N;e[7]!==f?(N=me=>{me!=="usage"&&me!=="remaining"||(f(me),w({usageDisplayMode:me}))},e[7]=f,e[8]=N):N=e[8];const D=N;let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=ce("flex h-full flex-col","bg-background"),e[9]=E):E=e[9];let T;e[10]!==r?(T=r("settings.usage.sidebar.title"),e[10]=r,e[11]=T):T=e[11];let C;e[12]!==T?(C=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:T}),e[12]=T,e[13]=C):C=e[13];let S;e[14]!==r?(S=r("settings.usage.sidebar.total",{count:Hr.length}),e[14]=r,e[15]=S):S=e[15];let M;e[16]!==S?(M=s.jsx("span",{className:"typography-meta text-muted-foreground",children:S}),e[16]=S,e[17]=M):M=e[17];let A;e[18]!==r?(A=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=A):A=e[19];let R;e[20]!==k||e[21]!==A||e[22]!==p?(R=s.jsx(It,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(ds,{checked:p,onChange:k,ariaLabel:A})})}),e[20]=k,e[21]=A,e[22]=p,e[23]=R):R=e[23];let z;e[24]!==r?(z=r("settings.usage.sidebar.tooltip.autoRefresh"),e[24]=r,e[25]=z):z=e[25];let B;e[26]!==z?(B=s.jsx(Dt,{side:"bottom",children:z}),e[26]=z,e[27]=B):B=e[27];let V;e[28]!==R||e[29]!==B?(V=s.jsxs(Pt,{children:[R,B]}),e[28]=R,e[29]=B,e[30]=V):V=e[30];const $=String(m),_=!p;let X;e[31]!==r?(X=r("settings.usage.sidebar.field.intervalPlaceholder"),e[31]=r,e[32]=X):X=e[32];let O;e[33]!==X?(O=s.jsx(as,{className:"w-fit",children:s.jsx(us,{placeholder:X})}),e[33]=X,e[34]=O):O=e[34];let J;e[35]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsxs(os,{children:[s.jsx(Ft,{value:"30000",children:"30s"}),s.jsx(Ft,{value:"60000",children:"1m"}),s.jsx(Ft,{value:"300000",children:"5m"})]}),e[35]=J):J=e[35];let Q;e[36]!==j||e[37]!==$||e[38]!==_||e[39]!==O?(Q=s.jsxs(is,{value:$,onValueChange:j,disabled:_,children:[O,J]}),e[36]=j,e[37]=$,e[38]=_,e[39]=O,e[40]=Q):Q=e[40];let ne;e[41]!==c?(ne=()=>c(),e[41]=c,e[42]=ne):ne=e[42];let G;e[43]!==r?(G=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=G):G=e[44];let le;e[45]!==r?(le=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=le):le=e[46];const oe=d&&"animate-spin";let F;e[47]!==oe?(F=ce("h-3.5 w-3.5",oe),e[47]=oe,e[48]=F):F=e[48];let U;e[49]!==F?(U=s.jsx(P,{name:"refresh",className:F}),e[49]=F,e[50]=U):U=e[50];let W;e[51]!==d||e[52]!==ne||e[53]!==G||e[54]!==le||e[55]!==U?(W=s.jsx(ge,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ne,"aria-label":G,title:le,disabled:d,children:U}),e[51]=d,e[52]=ne,e[53]=G,e[54]=le,e[55]=U,e[56]=W):W=e[56];let te;e[57]!==V||e[58]!==Q||e[59]!==W?(te=s.jsxs("div",{className:"flex items-center gap-2",children:[V,Q,W]}),e[57]=V,e[58]=Q,e[59]=W,e[60]=te):te=e[60];let K;e[61]!==M||e[62]!==te?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[M,te]}),e[61]=M,e[62]=te,e[63]=K):K=e[63];let ae;e[64]!==r?(ae=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=ae):ae=e[65];let ve;e[66]!==ae?(ve=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ae}),e[66]=ae,e[67]=ve):ve=e[67];let re;e[68]!==r?(re=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=re):re=e[69];let be;e[70]!==re?(be=s.jsx(as,{className:"w-fit",children:s.jsx(us,{placeholder:re})}),e[70]=re,e[71]=be):be=e[71];let pe;e[72]!==r?(pe=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=pe):pe=e[73];let ye;e[74]!==pe?(ye=s.jsx(Ft,{value:"usage",children:pe}),e[74]=pe,e[75]=ye):ye=e[75];let ie;e[76]!==r?(ie=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=ie):ie=e[77];let ue;e[78]!==ie?(ue=s.jsx(Ft,{value:"remaining",children:ie}),e[78]=ie,e[79]=ue):ue=e[79];let se;e[80]!==ye||e[81]!==ue?(se=s.jsxs(os,{children:[ye,ue]}),e[80]=ye,e[81]=ue,e[82]=se):se=e[82];let Ne;e[83]!==D||e[84]!==be||e[85]!==se||e[86]!==u?(Ne=s.jsxs(is,{value:u,onValueChange:D,children:[be,se]}),e[83]=D,e[84]=be,e[85]=se,e[86]=u,e[87]=Ne):Ne=e[87];let Ce;e[88]!==ve||e[89]!==Ne?(Ce=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ve,Ne]}),e[88]=ve,e[89]=Ne,e[90]=Ce):Ce=e[90];let je;e[91]!==K||e[92]!==Ce||e[93]!==C?(je=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,K,Ce]}),e[91]=K,e[92]=Ce,e[93]=C,e[94]=je):je=e[94];let we;e[95]!==n||e[96]!==i||e[97]!==a||e[98]!==l||e[99]!==r?(we=Hr.map(me=>{const Me=i.find(fe=>fe.providerId===me.id),Ue=a5(Me?.usage),q=bh(Ue),Se=me.id===a,$e=Me?.configured??!1,Pe=$e?q==="critical"?{backgroundColor:"var(--status-error)"}:q==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",Se?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(me.id),n?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:Pe}),s.jsx(vn,{providerId:me.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:me.name}),!$e&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},me.id)}),e[95]=n,e[96]=i,e[97]=a,e[98]=l,e[99]=r,e[100]=we):we=e[100];let ke;e[101]!==we?(ke=s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:we}),e[101]=we,e[102]=ke):ke=e[102];let xe;return e[103]!==je||e[104]!==ke?(xe=s.jsxs("div",{className:E,children:[je,ke]}),e[103]=je,e[104]=ke,e[105]=xe):xe=e[105],xe};function l5(t){return t.results}function c5(t){return t.selectedProviderId}function d5(t){return t.setSelectedProvider}function u5(t){return t.fetchAllQuotas}function m5(t){return t.isLoading}function p5(t){return t.autoRefresh}function f5(t){return t.refreshIntervalMs}function h5(t){return t.displayMode}function g5(t){return t.setAutoRefresh}function x5(t){return t.setRefreshInterval}function b5(t){return t.setDisplayMode}function y5(t){return t.loadSettings}async function v5(t){try{await ks(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Mc=t=>{const e=at.c(52),{title:n,window:r,subtitle:i,showToggle:a,toggleEnabled:l,onToggle:c}=t,d=a===void 0?!1:a,p=l===void 0?!1:l,m=Ms(w5),u=m==="remaining"?r.remainingPercent:r.usedPercent,h=m==="remaining"?"remaining":"used";let x;e[0]!==u||e[1]!==r.valueLabel?(x=ao(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=x):x=e[2];const f=x,v=r.resetAfterFormatted??r.resetAtFormatted;let y;e[3]!==v||e[4]!==r.resetAt?(y=Ud(r.resetAt,v),e[3]=v,e[4]=r.resetAt,e[5]=y):y=e[5];const g=y;let w;e[6]!==n?(w=Wd(n),e[6]=n,e[7]=w):w=e[7];const b=w;let k;e[8]!==n||e[9]!==r.resetAt||e[10]!==r.usedPercent||e[11]!==r.windowSeconds?(k=oo(r.usedPercent,r.resetAt,r.windowSeconds,n),e[8]=n,e[9]=r.resetAt,e[10]=r.usedPercent,e[11]=r.windowSeconds,e[12]=k):k=e[12];const I=k;let j;e:{if(!I||I.dailyAllocationPercent===null){j=null;break e}const Q=ei(I.elapsedRatio);j=m==="remaining"?100-Q:Q}const N=j;let D;e[13]!==c||e[14]!==d||e[15]!==p?(D=d&&s.jsx(ds,{checked:p,onChange:Q=>c?.(Q),ariaLabel:"Show in dropdown"}),e[13]=c,e[14]=d,e[15]=p,e[16]=D):D=e[16];let E;e[17]!==b?(E=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:b}),e[17]=b,e[18]=E):E=e[18];let T;e[19]!==i?(T=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[19]=i,e[20]=T):T=e[20];let C;e[21]!==E||e[22]!==T?(C=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[E,T]}),e[21]=E,e[22]=T,e[23]=C):C=e[23];let S;e[24]!==C||e[25]!==D?(S=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[D,C]}),e[24]=C,e[25]=D,e[26]=S):S=e[26];const M=f==="-"?"":f;let A;e[27]!==M?(A=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:M}),e[27]=M,e[28]=A):A=e[28];let R;e[29]!==S||e[30]!==A?(R=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[S,A]}),e[29]=S,e[30]=A,e[31]=R):R=e[31];let z;e[32]!==u||e[33]!==N||e[34]!==r.usedPercent?(z=s.jsx(co,{percent:u,tonePercent:r.usedPercent,expectedMarkerPercent:N,className:"h-1.5"}),e[32]=u,e[33]=N,e[34]=r.usedPercent,e[35]=z):z=e[35];const B=g?`Resets ${g}`:"";let V;e[36]!==B?(V=s.jsx("span",{className:"typography-micro text-muted-foreground",children:B}),e[36]=B,e[37]=V):V=e[37];let $;e[38]!==h?($=s.jsx("span",{className:"typography-micro text-muted-foreground",children:h}),e[38]=h,e[39]=$):$=e[39];let _;e[40]!==V||e[41]!==$?(_=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[V,$]}),e[40]=V,e[41]=$,e[42]=_):_=e[42];let X;e[43]!==z||e[44]!==_?(X=s.jsxs("div",{className:"mt-2.5",children:[z,_]}),e[43]=z,e[44]=_,e[45]=X):X=e[45];let O;e[46]!==I?(O=I&&s.jsx("div",{className:"mt-1.5",children:s.jsx(uo,{paceInfo:I})}),e[46]=I,e[47]=O):O=e[47];let J;return e[48]!==R||e[49]!==X||e[50]!==O?(J=s.jsxs("div",{className:"py-3",children:[R,X,O]}),e[48]=R,e[49]=X,e[50]=O,e[51]=J):J=e[51],J};function w5(t){return t.displayMode}const j5=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},N5=()=>{const{t}=ut(),e=Ms(S=>S.results),n=Ms(S=>S.selectedProviderId),r=Ms(S=>S.setSelectedProvider),i=Ms(S=>S.loadSettings),a=Ms(S=>S.fetchAllQuotas),l=Ms(S=>S.isLoading),c=Ms(S=>S.lastUpdated),d=Ms(S=>S.error),p=Ms(S=>S.dropdownProviderIds),m=Ms(S=>S.setDropdownProviderIds),u=Ms(S=>S.selectedModels),h=Ms(S=>S.toggleModelSelected),x=Ms(S=>S.applyDefaultSelections);Nh(),o.useEffect(()=>{i(),a()},[i,a]),o.useEffect(()=>{if(n||e.length===0)return;const S=e.find(M=>M.configured)?.providerId;r(S??Hr[0]?.id??null)},[e,n,r]);const f=e.find(S=>S.providerId===n)??null,y=Hr.find(S=>S.id===n)?.name??n??t("settings.usage.sidebar.title"),g=f?.usage,w=n?p.includes(n):!1,b=o.useCallback(S=>{if(!n)return;const M=S?Array.from(new Set([...p,n])):p.filter(A=>A!==n);m(M),ks({usageDropdownProviders:M})},[p,n,m]),k=o.useMemo(()=>g?.models?Object.entries(g.models).map(([S,M])=>({name:S,windows:M})).filter(S=>Object.keys(S.windows.windows).length>0):[],[g?.models]);o.useEffect(()=>{n&&k.length>0&&x(n,k.map(S=>S.name))},[n,k,x]);const I=o.useMemo(()=>!n||k.length===0?new Map:Uv(k,S=>S.name,n),[k,n]),j=o.useMemo(()=>{if(!n)return[];const S=wh(n);return jh(S)},[n]),[N,D]=o.useState(()=>({})),E=o.useCallback(S=>{D(M=>({...M,[S]:!M[S]}))},[]),T=o.useCallback(S=>{if(!n)return;h(n,S);const M=u[n]??[],R=M.includes(S)?M.filter(B=>B!==S):[...M,S],z={...u,[n]:R};ks({usageSelectedModels:z})},[n,u,h]),C=n?u[n]??[]:[];return n?s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s.jsx(vn,{providerId:n,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.usage.page.header.providerUsage",{provider:y})}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:l?s.jsx("span",{className:"animate-pulse",children:t("settings.usage.page.header.refreshing")}):t("settings.usage.page.header.lastUpdated",{time:j5(c)})})]})]}),s.jsx("div",{className:"mb-8 px-2",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>b(!w),onKeyDown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),b(!w))},children:[s.jsx(ds,{checked:w,onChange:b,ariaLabel:t("settings.usage.page.options.showInHeaderAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.options.showInHeader")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!f&&s.jsx("div",{className:"mb-8 px-2",children:s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noData")})}),d&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:d})]}),f&&!f.configured&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([S,M])=>s.jsx(Mc,{title:S,window:M},S))})})}),k.length>0&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.usage.page.section.modelQuotas")})}),s.jsxs("div",{className:"space-y-3",children:[j.map(S=>{const M=I.get(S.id)??[];if(M.length===0)return null;const A=N[S.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(fr,{open:!A,onOpenChange:()=>E(S.id),children:[s.jsxs(Pr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:S.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",M.length,")"]})]}),A?s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(hr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:M.map(R=>{const z=Object.entries(R.windows.windows);if(z.length===0)return null;const[B,V]=z[0],$=C.includes(R.name);return s.jsx(Mc,{title:B,subtitle:gl(R.name),window:V,showToggle:!0,toggleEnabled:$,onToggle:()=>T(R.name)},R.name)})})})]})},S.id)}),(()=>{const S=I.get(null)??[];if(S.length===0)return null;const M=N.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(fr,{open:!M,onOpenChange:()=>E("other"),children:[s.jsxs(Pr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",S.length,")"]})]}),M?s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(hr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:S.map(A=>{const R=Object.entries(A.windows.windows);if(R.length===0)return null;const[z,B]=R[0],V=C.includes(A.name);return s.jsx(Mc,{title:z,subtitle:gl(A.name),window:B,showToggle:!0,toggleEnabled:V,onToggle:()=>T(A.name)},A.name)})})})]})})})()]})]}),f?.configured&&g&&Object.keys(g.windows??{}).length===0&&k.length===0&&s.jsxs("div",{className:"mb-8 px-2",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]})}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},S5="git.commit.generate",vd=gr(t=>({selectedPromptId:S5,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),k5=t=>{const e=at.c(23),{onItemSelect:n}=t,{t:r}=ut(),i=vd(C5),a=vd(P5);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[l,c,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=p):p=e[3];const m=p;let u;e[4]!==r?(u=r("settings.magicPrompts.sidebar.title"),e[4]=r,e[5]=u):u=e[5];let h;e[6]!==u?(h=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:u}),e[6]=u,e[7]=h):h=e[7];let x;e[8]!==r?(x=r("settings.magicPrompts.sidebar.description"),e[8]=r,e[9]=x):x=e[9];let f;e[10]!==x?(f=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:x}),e[10]=x,e[11]=f):f=e[11];let v;e[12]!==h||e[13]!==f?(v=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[h,f]}),e[12]=h,e[13]=f,e[14]=v):v=e[14];let y;e[15]!==n||e[16]!==i||e[17]!==a||e[18]!==r?(y=s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(w=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:r(w.groupKey)}),w.items.map(b=>{const k=i===b.id;return s.jsx("button",{type:"button",onClick:()=>{a(b.id),n?.()},className:ce("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",k?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:r(b.titleKey)})},b.id)})]},w.groupKey))}),e[15]=n,e[16]=i,e[17]=a,e[18]=r,e[19]=y):y=e[19];let g;return e[20]!==y||e[21]!==v?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[v,y]}),e[20]=y,e[21]=v,e[22]=g):g=e[22],g};function C5(t){return t.selectedPromptId}function P5(t){return t.setSelectedPromptId}const Sp={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},kp=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Cp=t=>t.endsWith(".visible"),I5=()=>{const{t}=ut(),e=o.useCallback(j=>t(j),[t]),n=vd(j=>j.selectedPromptId),[r,i]=o.useState(!0),[a,l]=o.useState({}),[c,d]=o.useState({}),[p,m]=o.useState({}),[u,h]=o.useState({}),[x,f]=o.useState(!1);o.useEffect(()=>{let j=!0;return(async()=>{i(!0);try{const D=await qb();if(!j)return;l(D)}catch(D){console.warn("Failed to load magic prompts:",D),H.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&i(!1)}})(),()=>{j=!1}},[t]);const v=Sp[n]??Sp["git.commit.generate"],y=o.useCallback(j=>kp(a,j)?a[j]:sc(j),[a]),g=o.useCallback(j=>c[j]??y(j),[c,y]),w=o.useCallback((j,N)=>{d(D=>D[j]===N?D:{...D,[j]:N})},[]),b=o.useCallback(async j=>{const N=g(j);if(Cp(j)&&N.trim().length===0){H.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(D=>({...D,[j]:!0}));try{const D=N===sc(j)?await Cu(j):await Kb(j,N);l(D.overrides),H.success(t("settings.magicPrompts.page.toast.saved"))}catch(D){const E=D instanceof Error?D.message:String(D);H.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:E})}finally{m(D=>({...D,[j]:!1}))}},[g,t]),k=o.useCallback(async j=>{h(N=>({...N,[j]:!0}));try{const N=await Cu(j);l(N.overrides),d(D=>({...D,[j]:sc(j)})),H.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(N){const D=N instanceof Error?N.message:String(N);H.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:D})}finally{h(N=>({...N,[j]:!1}))}},[t]),I=o.useCallback(async()=>{f(!0);try{const j=await Hb();l(j.overrides),d({}),H.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const N=j instanceof Error?j.message:String(j);H.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:N})}finally{f(!1)}},[t]);return r?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(v.titleKey)}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:e(v.descriptionKey)})]})]})}),s.jsx(ge,{variant:"outline",size:"sm",onClick:()=>{I()},disabled:x||Object.keys(a).length===0,children:t(x?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),v.blocks.map((j,N)=>{const D=Gb(j.id),E=y(j.id),T=g(j.id),C=kp(a,j.id),S=T!==E,M=Cp(j.id)&&T.trim().length===0,A=p[j.id]===!0,R=u[j.id]===!0;return s.jsxs("section",{className:N>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label text-foreground",children:e(j.titleKey)}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:D.description})]})]}),D.placeholders&&D.placeholders.length>0&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[t("settings.magicPrompts.page.placeholdersLabel")," ",D.placeholders.map(z=>`{{${z.key}}}`).join(", ")]})]}),s.jsx(hn,{value:T,onChange:z=>w(j.id,z.target.value),className:"min-h-[220px] font-mono text-sm"}),M&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(S?"settings.magicPrompts.page.status.unsavedChanges":C?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{variant:"outline",size:"sm",onClick:()=>{k(j.id)},disabled:!C||A||R,children:t(R?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(ge,{size:"sm",onClick:()=>{b(j.id)},disabled:!S||A||R||M,children:t(A?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})]})})},bg=()=>{const{t}=ut(),e=xt(u=>u.settingsGitmojiEnabled),n=xt(u=>u.setSettingsGitmojiEnabled),r=Ld(),i=Ie(u=>u.gitChangesViewMode),a=Ie(u=>u.setGitChangesViewMode),[l,c]=o.useState(!0),d=o.useMemo(()=>[{id:"flat",label:t("settings.vinci.git.option.flatList")},{id:"tree",label:t("settings.vinci.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{let h=null;if(!h){const x=pr()?.settings;if(x)try{const v=(await x.load())?.settings;v&&(h={gitmojiEnabled:typeof v.gitmojiEnabled=="boolean"?v.gitmojiEnabled:void 0,gitChangesViewMode:v.gitChangesViewMode==="flat"||v.gitChangesViewMode==="tree"?v.gitChangesViewMode:void 0})}catch{}}if(!h){const x=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});x.ok&&(h=await x.json())}h&&(typeof h.gitmojiEnabled=="boolean"&&n(h.gitmojiEnabled),(h.gitChangesViewMode==="flat"||h.gitChangesViewMode==="tree")&&a(h.gitChangesViewMode))}catch(h){console.warn("Failed to load git settings:",h)}finally{c(!1)}})()},[a,n]);const p=o.useCallback(async u=>{n(u);try{await ks({gitmojiEnabled:u})}catch(h){console.warn("Failed to save gitmoji setting:",h)}},[n]),m=o.useCallback(u=>{u!==i&&(a(u),ks({gitChangesViewMode:u}))},[i,a]);return l?null:s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.vinci.git.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"pt-1 pb-1",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:t("settings.vinci.git.changesViewTitle")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.vinci.git.changesViewAria"),className:"mt-0.5 space-y-0",children:d.map(u=>{const h=i===u.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":h,onClick:()=>{m(u.id)},onKeyDown:x=>{(x.key===" "||x.key==="Enter")&&(x.preventDefault(),m(u.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ta,{checked:h,onChange:()=>{m(u.id)},ariaLabel:t("settings.vinci.git.optionAria",{option:u.label})}),s.jsx("span",{className:h?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:u.label})]},u.id)})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{p(!e)},onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),p(!e))},children:[s.jsx(ds,{checked:e,onChange:u=>{p(u)},ariaLabel:t("settings.vinci.git.enableGitmojiAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.git.enableGitmoji")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":r,onClick:()=>nc(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),nc(!r))},children:[s.jsx(ds,{checked:r,onChange:nc,ariaLabel:t("settings.vinci.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.git.showGitignored")})]})]})]})},yg=()=>{const{t}=ut(),{isMobile:e}=rn(),n=pr()?.github,r=Hn(D=>D.status),i=Hn(D=>D.isLoading),a=Hn(D=>D.hasChecked),l=Hn(D=>D.refreshStatus),c=Hn(D=>D.setStatus),d=o.useCallback(async D=>{await rr(D)},[]),[p,m]=o.useState(!1),[u,h]=o.useState(null),[x,f]=o.useState(null),v=o.useRef(null),y=o.useCallback(()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null),f(null)},[]);o.useEffect(()=>((async()=>{try{a||await l(n)}catch(D){console.warn("Failed to load GitHub auth status:",D)}})(),()=>{y()}),[a,l,n,y]);const g=o.useCallback(async()=>{m(!0);try{const D=n?await n.authStart():await(async()=>{const T=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),C=await T.json().catch(()=>null);if(!T.ok||!C||!("deviceCode"in C))throw new Error(C?.error||T.statusText);return C})();h(D),f(Math.max(1,D.interval)*1e3);const E=D.verificationUriComplete||D.verificationUri;d(E)}catch(D){console.error("Failed to start GitHub connect:",D),H.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),w=o.useCallback(async D=>{if(n)return n.authComplete(D);const E=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:D})}),T=await E.json().catch(()=>null);if(!E.ok||!T)throw new Error(T?.error||E.statusText);return T},[n]);o.useEffect(()=>{if(!(!u?.deviceCode||!x)&&v.current==null)return v.current=window.setInterval(()=>{(async()=>{try{const D=await w(u.deviceCode);if(D.connected){H.success(t("settings.github.page.toast.connected")),h(null),y(),await l(n,{force:!0});return}D.status==="slow_down"&&f(E=>E?E+5e3:5e3),(D.status==="expired_token"||D.status==="access_denied")&&(H.error(D.error||t("settings.github.page.toast.authorizationFailed")),h(null),y())}catch(D){console.warn("GitHub polling failed:",D)}})()},x),()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null)}},[u,x,w,l,n,y,t]);const b=o.useCallback(async()=>{m(!0);try{if(y(),h(null),n)await n.authDisconnect();else{const D=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!D.ok)throw new Error(D.statusText)}H.success(t("settings.github.page.toast.disconnected")),await l(n,{force:!0})}catch(D){console.error("Failed to disconnect GitHub:",D),H.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[l,n,y,t]),k=o.useCallback(async D=>{if(D){m(!0);try{const E=n?await n.authActivate(D):await(async()=>{const T=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:D})}),C=await T.json().catch(()=>null);if(!T.ok||!C)throw new Error(C?.error||T.statusText);return C})();c(E),H.success(t("settings.github.page.toast.accountSwitched"))}catch(E){console.error("Failed to switch GitHub account:",E),H.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(i)return null;const I=!!r?.connected,j=r?.user,N=r?.accounts??[];return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"GitHub"}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t("settings.github.page.tooltip.connectAccount")})]})]})}),s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[I?s.jsxs("div",{className:ce("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ce("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:j.login?t("settings.github.page.avatarAlt.withLogin",{login:j.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:j?.name?.trim()||j?.login||"GitHub"}),s.jsxs("div",{className:ce("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(P,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:j?.login||t("settings.github.page.label.unknownUser")}),j?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&s.jsx("span",{children:j.email})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:r.scope})})]})]}),s.jsx(ge,{size:"sm",variant:"outline",onClick:b,disabled:p,className:ce("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(ge,{size:"sm",variant:"default",onClick:g,disabled:p,children:t("settings.github.page.actions.connect")})]}),N.length>1&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:N.map(D=>{const E=D.user,T=!!D.current;return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[E?.avatarUrl?s.jsx("img",{src:E.avatarUrl,alt:E.login?t("settings.github.page.avatarAlt.withLogin",{login:E.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(P,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:E?.name?.trim()||E?.login||"GitHub"}),E?.login&&s.jsx("span",{className:"typography-micro text-muted-foreground truncate font-mono",children:E.login})]})]}),T?s.jsx("span",{className:"typography-micro text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:t("settings.github.page.status.active")}):s.jsx(ge,{size:"sm",variant:"ghost",onClick:()=>k(D.id),disabled:p,children:t("settings.github.page.actions.switchTo")})]},D.id)})})]})]}),I&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(ge,{size:"sm",variant:"outline",onClick:g,disabled:p,className:ce(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),u&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h4",{className:"typography-ui-label text-foreground",children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:u.userCode}),s.jsx(ge,{size:"sm",asChild:!0,children:s.jsx("a",{href:u.verificationUriComplete||u.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(ge,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{y(),h(null)},children:t("settings.common.actions.cancel")})]})]})]})},Pp=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],A5=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],D5=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:i}=ut(),a=Qn(O=>O.getProfileById),l=Qn(O=>O.createProfile),c=Qn(O=>O.updateProfile),d=Qn(O=>O.deleteProfile),p=o.useMemo(()=>n&&n!=="new"&&!r?a(n):null,[n,a,r]),m=n==="new"||r!=null,u=n==="global",[h,x]=o.useState(""),[f,v]=o.useState(""),[y,g]=o.useState(""),[w,b]=o.useState("ssh"),[k,I]=o.useState(""),[j,N]=o.useState(""),[D,E]=o.useState("keyword"),[T,C]=o.useState("branch"),[S,M]=o.useState(!1),[A,R]=o.useState(!1),[z,B]=o.useState(!1);o.useEffect(()=>{if(t){if(r){const O=r.host.split("/"),J=O.length>=3?O[O.length-1]:r.host;x(J),v(r.username),g(""),b("token"),I(""),N(r.host),E("string"),C("code")}else if(m)x(""),v(""),g(""),b("ssh"),I(""),N(""),E("keyword"),C("branch");else if(p)x(p.name),v(p.userName),g(p.userEmail),b(p.authType||"ssh"),I(p.sshKey||""),N(p.host||""),E(p.color||"keyword"),C(p.icon||"branch");else if(u){const O=a("global");O&&(x(O.name),v(O.userName),g(O.userEmail),b(O.authType||"ssh"),I(O.sshKey||""),N(O.host||""),E(O.color||"keyword"),C(O.icon||"branch"))}}},[t,n,p,m,r,u,a]);const V=async()=>{if(!f.trim()||!y.trim()){H.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(w==="token"&&!j.trim()){H.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}M(!0);try{const O={name:h.trim()||f.trim(),userName:f.trim(),userEmail:y.trim(),authType:w,sshKey:w==="ssh"&&k.trim()||null,host:w==="token"&&j.trim()||null,color:D,icon:T};let J;if(m)J=await l(O);else if(n)J=await c(n,O);else return;J?(H.success(i(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):H.error(i(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(O){console.error("Error saving profile:",O),H.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{M(!1)}},$=async()=>{if(!(!n||m)){B(!0);try{await d(n)?(H.success(i("settings.gitIdentities.editor.toast.profileDeleted")),R(!1),e(!1)):H.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(O){console.error("Error deleting profile:",O),H.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{B(!1)}}},_=o.useMemo(()=>Pp.find(J=>J.key===D)?.cssVar||"var(--syntax-keyword)",[D]),X=r?i("settings.gitIdentities.editor.title.importCredential"):m?i("settings.gitIdentities.editor.title.newIdentity"):u?i("settings.gitIdentities.editor.title.globalIdentity"):p?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(hs,{open:t,onOpenChange:e,children:s.jsxs(fs,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:X}),s.jsx(Is,{children:i(u?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!u&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-ui-label text-foreground block mb-1.5",children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(Bt,{value:h,onChange:O=>x(O.target.value),placeholder:i("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Pp.map(O=>s.jsx("button",{type:"button",onClick:()=>E(O.key),className:ce("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",D===O.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:O.cssVar},title:O.label},O.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:A5.map(O=>{const J=O.Icon;return s.jsx("button",{type:"button",onClick:()=>C(O.key),className:ce("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",T===O.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:O.label,children:s.jsx(P,{name:J,className:"w-3.5 h-3.5",style:{color:T===O.key?_:"var(--surface-muted-foreground)"}})},O.key)})})]})]}),!u&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.userName")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),s.jsx(Bt,{value:f,onChange:O=>v(O.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.emailAddress")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),s.jsx(Bt,{type:"email",value:y,onChange:O=>g(O.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]})]}),!u&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(ge,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="ssh",onClick:()=>b("ssh"),children:[s.jsx(P,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(ge,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="token",onClick:()=>b("token"),children:[s.jsx(P,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),w==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),s.jsx(Bt,{value:k,onChange:O=>I(O.target.value),placeholder:i("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),w==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]})]}),s.jsx(Bt,{value:j,onChange:O=>N(O.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Vs,{className:"gap-2",children:[!u&&!m&&s.jsxs(ge,{variant:"outline",size:"sm",onClick:()=>R(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(P,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.common.actions.delete")]}),s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:i(u?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!u&&s.jsx(ge,{size:"sm",onClick:V,disabled:S,children:i(S?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(hs,{open:A,onOpenChange:O=>{z||R(O)},children:s.jsxs(fs,{className:"max-w-md",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Is,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||h})})]}),s.jsxs(Vs,{children:[s.jsx(ge,{variant:"ghost",onClick:()=>R(!1),disabled:z,children:i("settings.common.actions.cancel")}),s.jsx(ge,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:z,children:i("settings.common.actions.delete")})]})]})})]})},T5={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},M5={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},E5=()=>{const t=at.c(116),{t:e}=ut(),{profiles:n,globalIdentity:r,defaultGitIdentityId:i,deleteProfile:a,loadProfiles:l,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=Qn(Br(F5)),[h,x]=o.useState(!1),[f,v]=o.useState(null),[y,g]=o.useState(null),[w,b]=o.useState(null),[k,I]=o.useState(!1);let j,N;t[0]!==p||t[1]!==d||t[2]!==c||t[3]!==l?(j=()=>{l(),c(),d(),p()},N=[l,c,d,p],t[0]=p,t[1]=d,t[2]=c,t[3]=l,t[4]=j,t[5]=N):(j=t[4],N=t[5]),o.useEffect(j,N);let D,E,T,C,S,M,A,R,z,B,V,$,_;if(t[6]!==i||t[7]!==w||t[8]!==a||t[9]!==u||t[10]!==r||t[11]!==n||t[12]!==m||t[13]!==e){const je=u();let we;t[27]===Symbol.for("react.memo_cache_sentinel")?(we=(L,Z)=>{v(L),g(Z??null),x(!0)},t[27]=we):we=t[27];const ke=we;let xe;t[28]!==i||t[29]!==m||t[30]!==e?(xe=async L=>{const Z=i===L?null:L;if(!await m(Z)){H.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}H.success(e(Z?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[28]=i,t[29]=m,t[30]=e,t[31]=xe):xe=t[31];const me=xe;let Me;t[32]!==w||t[33]!==a||t[34]!==e?(Me=async()=>{if(!w)return;I(!0),await a(w.id)?(H.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:w.name})),b(null)):H.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),I(!1)},t[32]=w,t[33]=a,t[34]=e,t[35]=Me):Me=t[35],E=Me,D=Cs,C="h-full",S="w-full bg-background",_="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",t[36]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(yg,{}),t[36]=T):T=t[36],V="border-t border-border/40 pt-6";let Ue;t[37]!==e?(Ue=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=Ue):Ue=t[38];let q;t[39]!==Ue?(q=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:Ue})}),t[39]=Ue,t[40]=q):q=t[40];let Se,$e;t[41]===Symbol.for("react.memo_cache_sentinel")?(Se=()=>ke("new"),$e=s.jsx(P,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Se,t[42]=$e):(Se=t[41],$e=t[42]);let Pe;t[43]!==e?(Pe=e("settings.common.badge.new"),t[43]=e,t[44]=Pe):Pe=t[44];let fe;t[45]!==Pe?(fe=s.jsxs(ge,{size:"sm",variant:"outline",onClick:Se,children:[$e," ",Pe]}),t[45]=Pe,t[46]=fe):fe=t[46],t[47]!==q||t[48]!==fe?($=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[q,fe]}),t[47]=q,t[48]=fe,t[49]=$):$=t[49],M="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",A=r&&s.jsx(Ip,{profile:r,isDefault:i==="global",onEdit:()=>ke("global"),onToggleDefault:()=>me("global"),isReadOnly:!0,hasBorder:n.length>0||je.length>0}),R=n.map((L,Z)=>s.jsx(Ip,{profile:L,isDefault:i===L.id,onEdit:()=>ke(L.id),onToggleDefault:()=>me(L.id),onDelete:()=>b(L),hasBorder:Z<n.length-1||je.length>0},L.id)),z=!r&&n.length===0&&je.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(P,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),B=je.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),je.map((L,Z)=>s.jsx(R5,{credential:L,onImport:()=>ke("new",{host:L.host,username:L.username}),hasBorder:Z<je.length-1},`${L.host}-${L.username}`))]}),t[6]=i,t[7]=w,t[8]=a,t[9]=u,t[10]=r,t[11]=n,t[12]=m,t[13]=e,t[14]=D,t[15]=E,t[16]=T,t[17]=C,t[18]=S,t[19]=M,t[20]=A,t[21]=R,t[22]=z,t[23]=B,t[24]=V,t[25]=$,t[26]=_}else D=t[14],E=t[15],T=t[16],C=t[17],S=t[18],M=t[19],A=t[20],R=t[21],z=t[22],B=t[23],V=t[24],$=t[25],_=t[26];let X;t[50]!==M||t[51]!==A||t[52]!==R||t[53]!==z||t[54]!==B?(X=s.jsxs("div",{className:M,children:[A,R,z,B]}),t[50]=M,t[51]=A,t[52]=R,t[53]=z,t[54]=B,t[55]=X):X=t[55];let O;t[56]!==X||t[57]!==V||t[58]!==$?(O=s.jsxs("div",{className:V,children:[$,X]}),t[56]=X,t[57]=V,t[58]=$,t[59]=O):O=t[59];let J;t[60]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(bg,{}),t[60]=J):J=t[60];let Q;t[61]!==T||t[62]!==O||t[63]!==_?(Q=s.jsxs("div",{className:_,children:[T,O,J]}),t[61]=T,t[62]=O,t[63]=_,t[64]=Q):Q=t[64];let ne;t[65]!==D||t[66]!==C||t[67]!==S||t[68]!==Q?(ne=s.jsx(D,{outerClassName:C,className:S,children:Q}),t[65]=D,t[66]=C,t[67]=S,t[68]=Q,t[69]=ne):ne=t[69];let G;t[70]!==y||t[71]!==h||t[72]!==f?(G=s.jsx(D5,{open:h,onOpenChange:x,profileId:f,importData:y}),t[70]=y,t[71]=h,t[72]=f,t[73]=G):G=t[73];const le=w!==null;let oe;t[74]!==k?(oe=je=>{k||je||b(null)},t[74]=k,t[75]=oe):oe=t[75];let F;t[76]!==e?(F=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=F):F=t[77];let U;t[78]!==F?(U=s.jsx(gs,{children:F}),t[78]=F,t[79]=U):U=t[79];const W=w?.name??"";let te;t[80]!==e||t[81]!==W?(te=e("settings.gitIdentities.page.deleteDialog.description",{name:W}),t[80]=e,t[81]=W,t[82]=te):te=t[82];let K;t[83]!==te?(K=s.jsx(Is,{children:te}),t[83]=te,t[84]=K):K=t[84];let ae;t[85]!==U||t[86]!==K?(ae=s.jsxs(bs,{children:[U,K]}),t[85]=U,t[86]=K,t[87]=ae):ae=t[87];let ve;t[88]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>b(null),t[88]=ve):ve=t[88];let re;t[89]!==e?(re=e("settings.common.actions.cancel"),t[89]=e,t[90]=re):re=t[90];let be;t[91]!==k||t[92]!==re?(be=s.jsx(ge,{variant:"ghost",onClick:ve,disabled:k,children:re}),t[91]=k,t[92]=re,t[93]=be):be=t[93];let pe;t[94]!==E?(pe=()=>{E()},t[94]=E,t[95]=pe):pe=t[95];let ye;t[96]!==e?(ye=e("settings.common.actions.delete"),t[96]=e,t[97]=ye):ye=t[97];let ie;t[98]!==k||t[99]!==pe||t[100]!==ye?(ie=s.jsx(ge,{size:"sm",variant:"destructive",onClick:pe,disabled:k,children:ye}),t[98]=k,t[99]=pe,t[100]=ye,t[101]=ie):ie=t[101];let ue;t[102]!==be||t[103]!==ie?(ue=s.jsxs(Vs,{children:[be,ie]}),t[102]=be,t[103]=ie,t[104]=ue):ue=t[104];let se;t[105]!==ae||t[106]!==ue?(se=s.jsxs(fs,{className:"max-w-md",children:[ae,ue]}),t[105]=ae,t[106]=ue,t[107]=se):se=t[107];let Ne;t[108]!==le||t[109]!==oe||t[110]!==se?(Ne=s.jsx(hs,{open:le,onOpenChange:oe,children:se}),t[108]=le,t[109]=oe,t[110]=se,t[111]=Ne):Ne=t[111];let Ce;return t[112]!==ne||t[113]!==G||t[114]!==Ne?(Ce=s.jsxs(s.Fragment,{children:[ne,G,Ne]}),t[112]=ne,t[113]=G,t[114]=Ne,t[115]=Ce):Ce=t[115],Ce},Ip=t=>{const e=at.c(54),{profile:n,isDefault:r,onEdit:i,onToggleDefault:a,onDelete:l,isReadOnly:c,hasBorder:d}=t,{t:p}=ut(),m=T5[n.icon||"branch"]||"git-branch",u=M5[n.color||""],h=n.authType||"ssh",x=d&&"border-b border-[var(--surface-subtle)]";let f;e[0]!==x?(f=ce("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",x),e[0]=x,e[1]=f):f=e[1];let v;e[2]!==i?(v=V=>{(V.key==="Enter"||V.key===" ")&&i()},e[2]=i,e[3]=v):v=e[3];let y;e[4]!==u?(y={color:u},e[4]=u,e[5]=y):y=e[5];let g;e[6]!==m||e[7]!==y?(g=s.jsx(P,{name:m,className:"w-4 h-4 shrink-0",style:y}),e[6]=m,e[7]=y,e[8]=g):g=e[8];let w;e[9]!==n.name?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=w):w=e[10];let b;e[11]!==h?(b=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:h}),e[11]=h,e[12]=b):b=e[12];let k;e[13]!==r||e[14]!==p?(k=r&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:p("settings.gitIdentities.page.badge.default")}),e[13]=r,e[14]=p,e[15]=k):k=e[15];let I;e[16]!==c||e[17]!==p?(I=c&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:p("settings.agents.sidebar.badge.system")}),e[16]=c,e[17]=p,e[18]=I):I=e[18];let j;e[19]!==w||e[20]!==b||e[21]!==k||e[22]!==I?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,b,k,I]}),e[19]=w,e[20]=b,e[21]=k,e[22]=I,e[23]=j):j=e[23];const N=h==="token"&&n.host?n.host:n.userEmail;let D;e[24]!==N?(D=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:N}),e[24]=N,e[25]=D):D=e[25];let E;e[26]!==j||e[27]!==D?(E=s.jsxs("div",{className:"min-w-0",children:[j,D]}),e[26]=j,e[27]=D,e[28]=E):E=e[28];let T;e[29]!==E||e[30]!==g?(T=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[g,E]}),e[29]=E,e[30]=g,e[31]=T):T=e[31];let C;e[32]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(Es,{asChild:!0,children:s.jsx(ge,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:L5,children:s.jsx(P,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=C):C=e[32];let S;e[33]!==a?(S=V=>{V.stopPropagation(),a()},e[33]=a,e[34]=S):S=e[34];let M;e[35]!==r||e[36]!==p?(M=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=M):M=e[37];let A;e[38]!==S||e[39]!==M?(A=s.jsx($t,{onClick:S,children:M}),e[38]=S,e[39]=M,e[40]=A):A=e[40];let R;e[41]!==c||e[42]!==l||e[43]!==p?(R=!c&&l&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]}),e[41]=c,e[42]=l,e[43]=p,e[44]=R):R=e[44];let z;e[45]!==A||e[46]!==R?(z=s.jsxs(Fs,{children:[C,s.jsxs(Rs,{align:"end",className:"w-fit min-w-28",children:[A,R]})]}),e[45]=A,e[46]=R,e[47]=z):z=e[47];let B;return e[48]!==i||e[49]!==T||e[50]!==f||e[51]!==z||e[52]!==v?(B=s.jsxs("div",{className:f,onClick:i,role:"button",tabIndex:0,onKeyDown:v,children:[T,z]}),e[48]=i,e[49]=T,e[50]=f,e[51]=z,e[52]=v,e[53]=B):B=e[53],B},R5=t=>{const e=at.c(21),{credential:n,onImport:r,hasBorder:i}=t,{t:a}=ut();let l;e[0]!==n.host?(l=n.host.split("/"),e[0]=n.host,e[1]=l):l=e[1];const c=l,d=c.length>=3?c[c.length-1]:n.host,p=n.host.includes("/"),m=i&&"border-b border-[var(--surface-subtle)]";let u;e[2]!==m?(u=ce("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=u):u=e[3];let h;e[4]!==d?(h=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=h):h=e[5];const x=p?n.host:n.username;let f;e[6]!==x?(f=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:x}),e[6]=x,e[7]=f):f=e[7];let v;e[8]!==h||e[9]!==f?(v=s.jsxs("div",{className:"min-w-0",children:[h,f]}),e[8]=h,e[9]=f,e[10]=v):v=e[10];let y;e[11]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(P,{name:"download",className:"h-3 w-3"}),e[11]=y):y=e[11];let g;e[12]!==a?(g=a("settings.gitIdentities.page.actions.import"),e[12]=a,e[13]=g):g=e[13];let w;e[14]!==r||e[15]!==g?(w=s.jsxs(ge,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[y,g]}),e[14]=r,e[15]=g,e[16]=w):w=e[16];let b;return e[17]!==w||e[18]!==u||e[19]!==v?(b=s.jsxs("div",{className:u,children:[v,w]}),e[17]=w,e[18]=u,e[19]=v,e[20]=b):b=e[20],b};function F5(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function L5(t){return t.stopPropagation()}const vg=()=>{const t=Yb();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},wg=()=>{const t=at.c(2),[e,n]=o.useState(O5);let r,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const a=[window.matchMedia("(display-mode: standalone)"),window.matchMedia("(display-mode: minimal-ui)"),window.matchMedia("(display-mode: fullscreen)"),window.matchMedia("(display-mode: window-controls-overlay)")],l=()=>{n(vg())};l();for(const c of a)typeof c.addEventListener=="function"?c.addEventListener("change",l):typeof c.addListener=="function"&&c.addListener(l);return window.addEventListener("appinstalled",l),window.addEventListener("focus",l),()=>{for(const c of a)typeof c.removeEventListener=="function"?c.removeEventListener("change",l):typeof c.removeListener=="function"&&c.removeListener(l);window.removeEventListener("appinstalled",l),window.removeEventListener("focus",l)}},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),o.useEffect(r,i),e};function O5(){return vg()}const $5=[{value:"system",labelKey:"settings.vinci.visual.option.themeMode.system"},{value:"light",labelKey:"settings.vinci.visual.option.themeMode.light"},{value:"dark",labelKey:"settings.vinci.visual.option.themeMode.dark"}],B5=[{id:"dynamic",labelKey:"settings.vinci.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.vinci.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.vinci.visual.option.diffLayout.inline.label",descriptionKey:"settings.vinci.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.vinci.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.vinci.visual.option.diffLayout.sideBySide.description"}],z5=[{id:"single",labelKey:"settings.vinci.visual.option.diffViewMode.single.label",descriptionKey:"settings.vinci.visual.option.diffViewMode.single.description"},{id:"stacked",labelKey:"settings.vinci.visual.option.diffViewMode.stacked.label",descriptionKey:"settings.vinci.visual.option.diffViewMode.stacked.description"}],V5=[{id:"svg",labelKey:"settings.vinci.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.vinci.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.vinci.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.vinci.visual.option.mermaidRendering.ascii.description"}],Oa="Vinci - AI Creative Assistant",Ap=[{id:"system",labelKey:"settings.vinci.visual.option.pwaOrientation.system.label",descriptionKey:"settings.vinci.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.vinci.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.vinci.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.vinci.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.vinci.visual.option.pwaOrientation.landscape.description"}],Dp=[{id:"native",labelKey:"settings.vinci.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.vinci.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.vinci.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.vinci.visual.option.mobileKeyboardMode.resizeContent.description"}],Ec=t=>t==="portrait"||t==="landscape"?t:"system",_5=[{id:"markdown",labelKey:"settings.vinci.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.vinci.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.vinci.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.vinci.visual.option.userMessageRendering.plain.description"}],U5=[{id:"sorted",labelKey:"settings.vinci.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.vinci.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.vinci.visual.option.chatRenderMode.live.label",descriptionKey:"settings.vinci.visual.option.chatRenderMode.live.description"}],Tp=[{id:"auto",labelKey:"settings.vinci.visual.option.messageTransport.auto.label",descriptionKey:"settings.vinci.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.vinci.visual.option.messageTransport.ws.label",descriptionKey:"settings.vinci.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.vinci.visual.option.messageTransport.sse.label",descriptionKey:"settings.vinci.visual.option.messageTransport.sse.description"}],W5=[{id:"collapsed",labelKey:"settings.vinci.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.vinci.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.vinci.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.vinci.visual.option.activityRenderMode.summary.description"}],Mp=[{id:"auto",labelKey:"settings.vinci.visual.option.timeFormat.auto.label",descriptionKey:"settings.vinci.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.vinci.visual.option.timeFormat.24h.label",descriptionKey:"settings.vinci.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.vinci.visual.option.timeFormat.12h.label",descriptionKey:"settings.vinci.visual.option.timeFormat.12h.description"}],Ep=[{id:"auto",labelKey:"settings.vinci.visual.option.weekStart.auto.label",descriptionKey:"settings.vinci.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.vinci.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.vinci.visual.option.weekStart.sunday.label"}],K5=t=>t==="markdown"?"markdown":"plain",tu=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:i,t:a}=ut(),l=o.useCallback(ee=>a(ee),[a]),{isMobile:c}=rn(),{browserTab:d}=wg(),p=$l(),m=Ie(ee=>ee.showReasoningTraces),u=Ie(ee=>ee.setShowReasoningTraces),h=Ie(ee=>ee.collapsibleThinkingBlocks),x=Ie(ee=>ee.setCollapsibleThinkingBlocks),f=Ie(ee=>ee.mermaidRenderingMode),v=Ie(ee=>ee.setMermaidRenderingMode),y=Ie(ee=>ee.userMessageRenderingMode),g=Ie(ee=>ee.setUserMessageRenderingMode),w=Ie(ee=>ee.stickyUserHeader),b=Ie(ee=>ee.setStickyUserHeader),k=Ie(ee=>ee.wideChatLayoutEnabled),I=Ie(ee=>ee.setWideChatLayoutEnabled),j=Ie(ee=>ee.chatRenderMode),N=Ie(ee=>ee.setChatRenderMode),D=Ie(ee=>ee.activityRenderMode),E=Ie(ee=>ee.setActivityRenderMode),T=Ie(ee=>ee.fontSize),C=Ie(ee=>ee.setFontSize),S=Ie(ee=>ee.terminalFontSize),M=Ie(ee=>ee.setTerminalFontSize),A=Ie(ee=>ee.uiFont),R=Ie(ee=>ee.setUiFont),z=Ie(ee=>ee.monoFont),B=Ie(ee=>ee.setMonoFont),V=Ie(ee=>ee.padding),$=Ie(ee=>ee.setPadding),_=Ie(ee=>ee.inputBarOffset),X=Ie(ee=>ee.setInputBarOffset),O=Ie(ee=>ee.mobileKeyboardMode),J=Ie(ee=>ee.setMobileKeyboardMode),Q=Ie(ee=>ee.diffLayoutPreference),ne=Ie(ee=>ee.setDiffLayoutPreference),G=Ie(ee=>ee.diffViewMode),le=Ie(ee=>ee.setDiffViewMode),oe=Ie(ee=>ee.showTerminalQuickKeysOnDesktop),F=Ie(ee=>ee.setShowTerminalQuickKeysOnDesktop),U=Pu(ee=>ee.queueModeEnabled),W=Pu(ee=>ee.setQueueMode),te=Ie(ee=>ee.persistChatDraft),K=Ie(ee=>ee.setPersistChatDraft),ae=Ie(ee=>ee.inputSpellcheckEnabled),ve=Ie(ee=>ee.setInputSpellcheckEnabled),re=Ie(ee=>ee.showToolFileIcons),be=Ie(ee=>ee.setShowToolFileIcons),pe=Ie(ee=>ee.showExpandedBashTools),ye=Ie(ee=>ee.setShowExpandedBashTools),ie=Ie(ee=>ee.showExpandedEditTools),ue=Ie(ee=>ee.setShowExpandedEditTools),se=Ie(ee=>ee.timeFormatPreference),Ne=Ie(ee=>ee.setTimeFormatPreference),Ce=Ie(ee=>ee.weekStartPreference),je=Ie(ee=>ee.setWeekStartPreference),we=Ie(ee=>ee.showSplitAssistantMessageActions),ke=Ie(ee=>ee.setShowSplitAssistantMessageActions),xe=Ie(ee=>ee.showMobileSessionStatusBar),me=Ie(ee=>ee.setShowMobileSessionStatusBar),Me=xt(ee=>ee.settingsMessageStreamTransport),Ue=xt(ee=>ee.setSettingsMessageStreamTransport),q=Ie(ee=>ee.isSettingsDialogOpen),{themeMode:Se,setThemeMode:$e,availableThemes:Pe,customThemesLoading:fe,reloadCustomThemes:L,lightThemeId:Z,darkThemeId:Y,setLightThemePreference:Ee,setDarkThemePreference:Ae}=Ar(),[Je,de]=o.useState(!1),[ze,rt]=o.useState(0),Re=Ie(ee=>ee.reportUsage),Xe=Ie(ee=>ee.setReportUsage),qe=o.useCallback(ee=>{Xe(ee),ks({reportUsage:ee})},[Xe]),Te=q&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Te)return;let ee=null,ht=Date.now();const St=()=>{const ms=Date.now();ms-ht>=420&&(rt(Ds=>(Ds+1)%24),ht=ms),ee=requestAnimationFrame(St)};(typeof document>"u"||document.visibilityState==="visible")&&(ee=requestAnimationFrame(St));const qt=()=>{document.visibilityState==="visible"&&ee===null?ee=requestAnimationFrame(St):document.visibilityState!=="visible"&&ee!==null&&(cancelAnimationFrame(ee),ee=null)};return document.addEventListener("visibilitychange",qt),()=>{document.removeEventListener("visibilitychange",qt),ee!==null&&cancelAnimationFrame(ee)}},[Te]);const We=o.useCallback(ee=>{g(ee),ks({userMessageRenderingMode:ee})},[g]),Ze=o.useCallback(ee=>{b(ee),ks({stickyUserHeader:ee})},[b]),Qe=o.useCallback(ee=>{I(ee),ks({wideChatLayoutEnabled:ee})},[I]),he=o.useCallback(ee=>{ke(ee),ks({showSplitAssistantMessageActions:ee})},[ke]),Ge=o.useCallback(ee=>{ve(ee),ks({inputSpellcheckEnabled:ee})},[ve]),Ve=o.useCallback(ee=>{N(ee),ks({chatRenderMode:ee})},[N]),it=o.useCallback(ee=>{Ue(ee),ks({messageStreamTransport:ee})},[Ue]),dt=o.useCallback(ee=>{E(ee),ks({activityRenderMode:ee})},[E]),Ye=o.useCallback(ee=>{v(ee),ks({mermaidRenderingMode:ee})},[v]),_e=o.useCallback(ee=>{be(ee),ks({showToolFileIcons:ee})},[be]),et=o.useCallback(ee=>{ye(ee),ks({showExpandedBashTools:ee})},[ye]),gt=o.useCallback(ee=>{ue(ee),ks({showExpandedEditTools:ee})},[ue]),Lt=o.useCallback(ee=>{Ne(ee),ks({timeFormatPreference:ee})},[Ne]),Ut=o.useCallback(ee=>{je(ee),ks({weekStartPreference:ee})},[je]),mt=o.useMemo(()=>Pe.filter(ee=>ee.metadata.variant==="light").sort((ee,ht)=>ee.metadata.name.localeCompare(ht.metadata.name)),[Pe]),Nt=o.useMemo(()=>Pe.filter(ee=>ee.metadata.variant==="dark").sort((ee,ht)=>ee.metadata.name.localeCompare(ht.metadata.name)),[Pe]),Xt=o.useMemo(()=>mt.find(ee=>ee.metadata.id===Z)??mt[0],[mt,Z]),_t=o.useMemo(()=>Nt.find(ee=>ee.metadata.id===Y)??Nt[0],[Nt,Y]),Gt=o.useCallback((ee,ht)=>{const St=ht==="dark"?" Dark":" Light";return ee.endsWith(St)?ee.slice(0,-St.length):ee},[]),lt=ee=>t?t.includes(ee):!0,Tt=mn(),rs=lt("theme")&&!Tt,js=lt("theme")||lt("timeFormat")||lt("weekStart"),ys=Tt?js:lt("theme")||lt("pwaInstallName")||lt("pwaOrientation")||lt("timeFormat")||lt("weekStart"),vs=lt("fontSize")||lt("terminalFontSize")||lt("spacing")||lt("inputBarOffset"),Wt=lt("terminalQuickKeys")&&!c,He=lt("mermaidRendering")||lt("userMessageRendering")||lt("chatRenderMode")||lt("messageTransport")||lt("activityRenderMode")&&j==="sorted"||lt("stickyUserHeader")||lt("wideChatLayout")||lt("splitAssistantMessageActions")||lt("diffLayout")||lt("mobileStatusBar")&&c||lt("dotfiles")||lt("reasoning")||lt("queueMode")||lt("persistDraft")||lt("showToolFileIcons")||lt("expandedTools")||!c&<("inputSpellcheck"),kt=lt("pwaInstallName")&&Li()&&d&&!gn()&&!Tt,Kt=lt("pwaOrientation")&&Li()&&!gn()&&!Tt,wt=lt("mobileKeyboardMode")&&Li()&&!gn()&&!Tt&&Qb(),[Qt,cs]=o.useState(""),[Ls,Ss]=o.useState("system"),ns=o.useMemo(()=>{const ee=Mp.find(ht=>ht.id===se);return l(ee?.labelKey??"settings.vinci.visual.option.timeFormat.auto.label")},[se,l]),Os=o.useMemo(()=>{const ee=Ep.find(ht=>ht.id===Ce);return l(ee?.labelKey??"settings.vinci.visual.option.weekStart.auto.label")},[Ce,l]),Ks=o.useMemo(()=>{const ee=Ap.find(ht=>ht.id===Ls);return ee?l(ee.labelKey):void 0},[Ls,l]),bt=o.useMemo(()=>{const ee=Dp.find(ht=>ht.id===O);return ee?l(ee.labelKey):void 0},[O,l]),Mt=o.useCallback(async ee=>{if(typeof window>"u")return;const ht=window,qt=ee.trim().replace(/\s+/g," ").slice(0,64);if(await ks({pwaAppName:qt}),typeof ht.__APP_SET_PWA_INSTALL_NAME__=="function"){const ms=ht.__APP_SET_PWA_INSTALL_NAME__(qt);cs(ms);return}cs(qt||Oa),ht.__APP_UPDATE_PWA_MANIFEST__?.()},[]),At=o.useCallback(async ee=>{if(typeof window>"u")return;const ht=window,St=Ec(ee);if(await ks({pwaOrientation:St}),typeof ht.__APP_SET_PWA_ORIENTATION__=="function"){const qt=ht.__APP_SET_PWA_ORIENTATION__(St);Ss(qt);return}Ss(St),ht.__APP_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!kt&&!Kt&&!wt)return;let ee=!1;return(async()=>{try{const St=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!St.ok){ee||cs(Oa);return}const qt=await St.json().catch(()=>({})),Ds=(typeof qt?.pwaAppName=="string"?qt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ke=Ec(qt?.pwaOrientation),yt=Mu(qt?.mobileKeyboardMode);ee||(kt&&cs(Ds||Oa),Kt&&Ss(Ke),wt&&J(yt))}catch{ee||(kt&&cs(Oa),Kt&&Ss("system"),wt&&J("native"))}})(),()=>{ee=!0}},[J,wt,kt,Kt]),s.jsxs("div",{className:"space-y-8",children:[ys&&s.jsxs("div",{className:"mb-8 space-y-6",children:[rs&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.colorMode")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:$5.map(ee=>s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":Se===ee.value,className:"!font-normal",onClick:()=>$e(ee.value),children:l(ee.labelKey)},ee.value))})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:a("settings.vinci.visual.field.lightTheme")}),s.jsxs(is,{value:Xt?.metadata.id??"",onValueChange:Ee,children:[s.jsx(as,{"aria-label":a("settings.vinci.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(us,{placeholder:a("settings.vinci.visual.field.selectThemePlaceholder"),children:Xt?Gt(Xt.metadata.name,"light"):void 0})}),s.jsx(os,{children:mt.map(ee=>s.jsx(Ft,{value:ee.metadata.id,children:Gt(ee.metadata.name,"light")},ee.metadata.id))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:a("settings.vinci.visual.field.darkTheme")}),s.jsxs(is,{value:_t?.metadata.id??"",onValueChange:Ae,children:[s.jsx(as,{"aria-label":a("settings.vinci.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(us,{placeholder:a("settings.vinci.visual.field.selectThemePlaceholder"),children:_t?Gt(_t.metadata.name,"dark"):void 0})}),s.jsx(os,{children:Nt.map(ee=>s.jsx(Ft,{value:ee.metadata.id,children:Gt(ee.metadata.name,"dark")},ee.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:fe||Je,onClick:()=>{const ee=Date.now();de(!0),L().finally(()=>{const ht=Date.now()-ee;if(ht<500){window.setTimeout(()=>{de(!1)},500-ht);return}de(!1)})},className:"inline-flex items-center typography-ui-label font-normal text-foreground underline decoration-[1px] underline-offset-2 hover:text-foreground/80 disabled:cursor-not-allowed disabled:text-muted-foreground/60",children:a(Je?"settings.vinci.visual.actions.reloadingThemes":"settings.vinci.visual.actions.reloadThemes")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"flex items-center justify-center rounded-md p-1 text-muted-foreground/70 hover:text-foreground","aria-label":a("settings.vinci.visual.field.themeImportInfoAria"),children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(Dt,{sideOffset:8,children:a("settings.vinci.visual.field.themeImportInfoTooltip")})]})]})]}),js&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.localization")}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:a("settings.appearance.language.label")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.appearance.language.description")})]}),s.jsxs(is,{value:e,onValueChange:ee=>r(ee),children:[s.jsx(as,{"aria-label":a("settings.appearance.language.select"),className:"w-fit",children:s.jsx(us,{children:i(e)})}),s.jsx(os,{children:n.map(ee=>s.jsx(Ft,{value:ee,children:i(ee)},ee))})]})]}),!Tt&&(lt("timeFormat")||lt("weekStart"))&&s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[lt("timeFormat")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:a("settings.vinci.visual.field.timeFormat")}),s.jsxs(is,{value:se,onValueChange:ee=>Lt(ee),children:[s.jsx(as,{"aria-label":a("settings.vinci.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(us,{children:ns})}),s.jsx(os,{children:Mp.map(ee=>s.jsx(Ft,{value:ee.id,children:l(ee.labelKey)},ee.id))})]})]}),lt("weekStart")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:a("settings.vinci.visual.field.weekStartsOn")}),s.jsxs(is,{value:Ce,onValueChange:ee=>Ut(ee),children:[s.jsx(as,{"aria-label":a("settings.vinci.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(us,{children:Os})}),s.jsx(os,{children:Ep.map(ee=>s.jsx(Ft,{value:ee.id,children:l(ee.labelKey)},ee.id))})]})]})]})]}),(kt||Kt||wt)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[kt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.installAppName")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.vinci.visual.field.installAppNameHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[s.jsx(Bt,{value:Qt,onChange:ee=>{cs(ee.target.value)},onBlur:()=>{Mt(Qt)},onKeyDown:ee=>{ee.key==="Enter"&&(ee.preventDefault(),Mt(Qt))},className:"h-7",maxLength:64,"aria-label":a("settings.vinci.visual.field.pwaInstallAppNameAria")}),s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>{cs(Oa),Mt("")},className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.vinci.visual.actions.resetInstallAppNameAria"),title:a("settings.common.actions.reset"),children:s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Kt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.installOrientation")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.vinci.visual.field.installOrientationHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(is,{value:Ls,onValueChange:ee=>{const ht=Ec(ee);Ss(ht),At(ht)},children:[s.jsx(as,{"aria-label":a("settings.vinci.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(us,{placeholder:a("settings.vinci.visual.field.selectOrientationPlaceholder"),children:Ks})}),s.jsx(os,{children:Ap.map(ee=>s.jsx(Ft,{value:ee.id,children:l(ee.labelKey)},ee.id))})]}),s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ss("system"),At("system")},disabled:Ls==="system",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.vinci.visual.actions.resetInstallOrientationAria"),title:a("settings.common.actions.reset"),children:s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),wt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.mobileKeyboardMode")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.vinci.visual.field.mobileKeyboardModeHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(is,{value:O,onValueChange:ee=>{const ht=Mu(ee);J(ht),ks({mobileKeyboardMode:ht})},children:[s.jsx(as,{"aria-label":a("settings.vinci.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(us,{placeholder:a("settings.vinci.visual.field.selectMobileKeyboardModePlaceholder"),children:bt})}),s.jsx(os,{children:Dp.map(ee=>s.jsx(Ft,{value:ee.id,children:l(ee.labelKey)},ee.id))})]}),s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>{J("native"),ks({mobileKeyboardMode:"native"})},disabled:O==="native",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.vinci.visual.actions.resetMobileKeyboardModeAria"),title:a("settings.common.actions.reset"),children:s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),vs&&s.jsx("div",{className:"mb-8 space-y-3",children:s.jsxs("section",{className:"p-2 space-y-0.5",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.spacingAndLayout")}),s.jsxs("div",{className:"pl-2",children:[lt("fontSize")&&!c&&s.jsxs("div",{className:"flex items-center gap-8 py-1",children:[s.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.interfaceFont")})}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsxs(is,{value:A,onValueChange:ee=>R(ee),children:[s.jsx(as,{"aria-label":a("settings.vinci.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(us,{children:Iu.find(ee=>ee.id===A)?.label})}),s.jsx(os,{children:Iu.map(ee=>s.jsx(Ft,{value:ee.id,children:s.jsx("span",{style:{fontFamily:ee.stack},children:ee.label})},ee.id))})]}),s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(Au),disabled:A===Au,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.vinci.visual.actions.resetInterfaceFontAria"),title:a("settings.common.actions.reset"),children:s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),lt("terminalFontSize")&&s.jsxs("div",{className:ce("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ce("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.codeFont")})}),s.jsxs("div",{className:ce("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsxs(is,{value:z,onValueChange:ee=>B(ee),children:[s.jsx(as,{"aria-label":a("settings.vinci.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(us,{children:Du.find(ee=>ee.id===z)?.label})}),s.jsx(os,{children:Du.map(ee=>s.jsx(Ft,{value:ee.id,children:s.jsx("span",{style:{fontFamily:ee.stack},children:ee.label})},ee.id))})]}),s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>B(Tu),disabled:z===Tu,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.vinci.visual.actions.resetCodeFontAria"),title:a("settings.common.actions.reset"),children:s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),lt("fontSize")&&!c&&s.jsxs("div",{className:"flex items-center gap-8 py-1",children:[s.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.interfaceFontSize")})}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(Vn,{value:T,onValueChange:C,min:50,max:200,step:5,"aria-label":a("settings.vinci.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>C(100),disabled:T===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.vinci.visual.actions.resetFontSizeAria"),title:a("settings.common.actions.reset"),children:s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),lt("terminalFontSize")&&s.jsxs("div",{className:ce("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ce("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.terminalFontSize")})}),s.jsxs("div",{className:ce("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Vn,{value:S,onValueChange:M,min:9,max:52,step:1,className:"w-16"}),s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>M(13),disabled:S===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.vinci.visual.actions.resetTerminalFontSizeAria"),title:a("settings.common.actions.reset"),children:s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),lt("spacing")&&s.jsxs("div",{className:ce("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ce("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.spacingDensity")})}),s.jsxs("div",{className:ce("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Vn,{value:V,onValueChange:$,min:50,max:200,step:5,className:"w-16"}),s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>$(100),disabled:V===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.vinci.visual.actions.resetSpacingAria"),title:a("settings.common.actions.reset"),children:s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),lt("inputBarOffset")&&s.jsxs("div",{className:ce("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ce("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.inputBarOffset")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:a("settings.vinci.visual.field.inputBarOffsetTooltip")})]})]})}),s.jsxs("div",{className:ce("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Vn,{value:_,onValueChange:X,min:0,max:100,step:5,className:"w-16"}),s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:()=>X(0),disabled:_===0,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.vinci.visual.actions.resetInputBarOffsetAria"),title:a("settings.common.actions.reset"),children:s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),Wt&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.navigation")}),lt("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":oe,onClick:()=>F(!oe),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),F(!oe))},children:[s.jsx(ds,{checked:oe,onChange:F,ariaLabel:a("settings.vinci.visual.field.terminalQuickKeysAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.terminalQuickKeys")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:a("settings.vinci.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),He&&s.jsxs("div",{className:"space-y-3",children:[(lt("userMessageRendering")||lt("mermaidRendering")||lt("chatRenderMode")||lt("messageTransport")||lt("activityRenderMode")&&j==="sorted"||lt("diffLayout")&&!Tt)&&s.jsxs("div",{className:"grid grid-cols-1 gap-y-2 md:grid-cols-[minmax(0,16rem)_minmax(0,16rem)] md:justify-start md:gap-x-2",children:[lt("chatRenderMode")&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.chatRenderMode")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.vinci.visual.section.chatRenderModeAria"),className:"mt-1 grid w-full max-w-[26rem] grid-cols-1 gap-3 sm:grid-cols-2",children:U5.map(ee=>{const ht=j===ee.id,St=ze%12;return s.jsxs("button",{type:"button",onClick:()=>Ve(ee.id),"aria-pressed":ht,className:ce("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",ht?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ce("typography-ui-label",ht?"text-foreground":"text-muted-foreground"),children:l(ee.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:ee.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(qt=>{const ms=qt*3+1,Ds=St-ms+1,Ke=Ds<=0?0:Ds===1?42:Ds===2?68:92,yt=Ke>0;return s.jsxs("div",{className:ce("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",yt?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${Ke}%`}})]},qt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(qt=>{const ms=St>=(qt+1)*3;return s.jsxs("div",{className:ce("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",ms?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},qt)})})})]},ee.id)})})]}),lt("messageTransport")&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.messageStreamTransport")}),s.jsxs("div",{className:"mt-1 flex max-w-[24rem] flex-col gap-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Tp.map(ee=>s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":Me===ee.id,className:"!font-normal",onClick:()=>it(ee.id),children:l(ee.labelKey)},ee.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const ee=Tp.find(ht=>ht.id===Me);return ee?.descriptionKey?l(ee.descriptionKey):""})()})]})]}),lt("activityRenderMode")&&j==="sorted"&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.activityDefault")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.vinci.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:W5.map(ee=>{const ht=D===ee.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>dt(ee.id),onKeyDown:St=>{(St.key===" "||St.key==="Enter")&&(St.preventDefault(),dt(ee.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ta,{checked:ht,onChange:()=>dt(ee.id),ariaLabel:a("settings.vinci.visual.field.activityDefaultModeAria",{option:l(ee.labelKey)})}),s.jsx("span",{className:ce("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:l(ee.labelKey)})]},ee.id)})})]}),lt("expandedTools")&&s.jsxs("section",{className:"p-2 md:col-span-2 space-y-0.5",children:[s.jsx("div",{className:"typography-ui-header font-medium text-foreground py-1.5",children:a("settings.vinci.visual.section.showToolsOpenedByDefault")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":pe,onClick:()=>et(!pe),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),et(!pe))},children:[s.jsx(ds,{checked:pe,onChange:et,ariaLabel:a("settings.vinci.visual.field.showExpandedBashToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.bash")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ie,onClick:()=>gt(!ie),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),gt(!ie))},children:[s.jsx(ds,{checked:ie,onChange:gt,ariaLabel:a("settings.vinci.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.editTools")})]})]}),lt("userMessageRendering")&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.userMessageRendering")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.vinci.visual.section.userMessageRenderingAria"),className:"mt-0.5 space-y-0",children:_5.map(ee=>{const ht=K5(y)===ee.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>We(ee.id),onKeyDown:St=>{(St.key===" "||St.key==="Enter")&&(St.preventDefault(),We(ee.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ta,{checked:ht,onChange:()=>We(ee.id),ariaLabel:a("settings.vinci.visual.field.userMessageRenderingAria",{option:l(ee.labelKey)})}),s.jsx("span",{className:ce("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:l(ee.labelKey)})]},ee.id)})})]}),lt("mermaidRendering")&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.mermaidRendering")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.vinci.visual.section.mermaidRenderingAria"),className:"mt-0.5 space-y-0",children:V5.map(ee=>{const ht=f===ee.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>Ye(ee.id),onKeyDown:St=>{(St.key===" "||St.key==="Enter")&&(St.preventDefault(),Ye(ee.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ta,{checked:ht,onChange:()=>Ye(ee.id),ariaLabel:a("settings.vinci.visual.field.mermaidRenderingAria",{option:l(ee.labelKey)})}),s.jsx("span",{className:ce("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:l(ee.labelKey)})]},ee.id)})})]}),lt("diffLayout")&&!Tt&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.diffLayout")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.vinci.visual.section.diffLayoutAria"),className:"mt-0.5 space-y-0",children:B5.map(ee=>{const ht=Q===ee.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>ne(ee.id),onKeyDown:St=>{(St.key===" "||St.key==="Enter")&&(St.preventDefault(),ne(ee.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ta,{checked:ht,onChange:()=>ne(ee.id),ariaLabel:a("settings.vinci.visual.field.diffLayoutAria",{option:l(ee.labelKey)})}),s.jsx("span",{className:ce("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:l(ee.labelKey)})]},ee.id)})})]}),lt("diffLayout")&&!Tt&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.vinci.visual.section.diffViewMode")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.vinci.visual.section.diffViewModeAria"),className:"mt-0.5 space-y-0",children:z5.map(ee=>{const ht=G===ee.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>le(ee.id),onKeyDown:St=>{(St.key===" "||St.key==="Enter")&&(St.preventDefault(),le(ee.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ta,{checked:ht,onChange:()=>le(ee.id),ariaLabel:a("settings.vinci.visual.field.diffViewModeAria",{option:l(ee.labelKey)})}),s.jsx("span",{className:ce("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:l(ee.labelKey)})]},ee.id)})})]})]}),(lt("stickyUserHeader")||lt("wideChatLayout")||lt("splitAssistantMessageActions")||lt("mobileStatusBar")&&c||lt("dotfiles")||lt("queueMode")||lt("persistDraft")||lt("showToolFileIcons")||!c&<("inputSpellcheck")||lt("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[lt("reasoning")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),u(!m))},children:[s.jsx(ds,{checked:m,onChange:u,ariaLabel:a("settings.vinci.visual.field.showReasoningTracesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.showReasoningTraces")})]}),lt("reasoning")&&m&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":h,onClick:()=>x(!h),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),x(!h))},children:[s.jsx(ds,{checked:h,onChange:x,ariaLabel:a("settings.vinci.visual.field.collapsibleThinkingBlocksAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.collapsibleThinkingBlocks")})]}),lt("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>Ze(!w),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),Ze(!w))},children:[s.jsx(ds,{checked:w,onChange:Ze,ariaLabel:a("settings.vinci.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.stickyUserHeader")})]}),lt("wideChatLayout")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":k,onClick:()=>Qe(!k),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),Qe(!k))},children:[s.jsx(ds,{checked:k,onChange:Qe,ariaLabel:a("settings.vinci.visual.field.wideChatLayoutAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.wideChatLayout")})]}),lt("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":we,onClick:()=>he(!we),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),he(!we))},children:[s.jsx(ds,{checked:we,onChange:he,ariaLabel:a("settings.vinci.visual.field.showSplitAssistantMessageActionsAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.showSplitAssistantMessageActions")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:a("settings.vinci.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),lt("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":re,onClick:()=>_e(!re),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),_e(!re))},children:[s.jsx(ds,{checked:re,onChange:_e,ariaLabel:a("settings.vinci.visual.field.showToolFileIconsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.showToolFileIcons")})]}),lt("mobileStatusBar")&&c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":xe,onClick:()=>me(!xe),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),me(!xe))},children:[s.jsx(ds,{checked:xe,onChange:me,ariaLabel:a("settings.vinci.visual.field.showMobileStatusBarAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.showMobileStatusBar")})]}),lt("dotfiles")&&!mn()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>Qo(!p),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),Qo(!p))},children:[s.jsx(ds,{checked:p,onChange:Qo,ariaLabel:a("settings.vinci.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.showDotfiles")})]}),lt("queueMode")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":U,onClick:()=>W(!U),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),W(!U))},children:[s.jsx(ds,{checked:U,onChange:W,ariaLabel:a("settings.vinci.visual.field.queueMessagesByDefaultAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.queueMessagesByDefault")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:a("settings.vinci.visual.field.queueMessagesByDefaultTooltip",{modifier:hl()})})]})]})]}),lt("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":te,onClick:()=>K(!te),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),K(!te))},children:[s.jsx(ds,{checked:te,onChange:K,ariaLabel:a("settings.vinci.visual.field.persistDraftMessagesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.persistDraftMessages")})]}),!c&<("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ae,onClick:()=>Ge(!ae),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),Ge(!ae))},children:[s.jsx(ds,{checked:ae,onChange:Ge,ariaLabel:a("settings.vinci.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.enableSpellcheckInTextInputs")})]})]})]}),lt("reportUsage")&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground mb-2",children:a("settings.vinci.visual.section.privacy")}),s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(ds,{checked:Re,onChange:qe,ariaLabel:a("settings.vinci.visual.field.sendAnonymousUsageReportsAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[s.jsx("div",{className:"group flex cursor-pointer",role:"button",tabIndex:0,"aria-pressed":Re,onClick:()=>qe(!Re),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),qe(!Re))},children:s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.vinci.visual.field.sendAnonymousUsageReports")})}),s.jsx("span",{className:"typography-meta text-muted-foreground pointer-events-none",children:a("settings.vinci.visual.field.sendAnonymousUsageReportsHint")})]})]})]})})]})},Rp="https://github.com/jaygupta17/vinci",H5=()=>{const{t}=ut(),{isMobile:e}=rn(),[n,r]=o.useState(null);o.useEffect(()=>{(async()=>{try{const l=await fetch("/api/system/info");if(l.ok){const c=await l.json();typeof c.vinciVersion=="string"&&c.vinciVersion.trim()&&r(c.vinciVersion)}}catch{}})()},[]);const i=n||"1.0.0";return e?s.jsxs("div",{className:"w-full space-y-2",children:[s.jsx("div",{className:"flex items-center justify-between",children:s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["v",i]})}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs("a",{href:Rp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"github-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/eSSmgeX8Q",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"discord-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/guptajay17",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"twitter-xfill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@guptajay17"})]})]})]}):s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-3 px-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.vinci.about.title")})}),s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[s.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:i})]})}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:Rp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(P,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/eSSmgeX8Q",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(P,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/guptajay17",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(P,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@guptajay17"})]})]})]})]})},G5=1,q5=365,Fp=30,Y5=[{value:"archive",labelKey:"settings.vinci.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.vinci.sessionRetention.action.delete"}],jg=()=>{const t=at.c(113),{t:e}=ut(),n=Ie(Q5),r=Ie(J5),i=Ie(X5),a=Ie(Z5),l=Ie(eC),c=Ie(tC);let d;t[0]===Symbol.for("react.memo_cache_sentinel")?(d={autoRun:!1},t[0]=d):d=t[0];const{candidates:p,isRunning:m,runCleanup:u,action:h}=Jb(d),x=p.length;let f;t[1]!==u||t[2]!==e?(f=async()=>{const se=await u({force:!0});if(se.completedIds.length===0&&se.failedIds.length===0){H.message(se.action==="archive"?e("settings.vinci.sessionRetention.toast.noneEligibleArchive"):e("settings.vinci.sessionRetention.toast.noneEligibleDelete"));return}se.completedIds.length>0&&H.success(se.action==="archive"?e("settings.vinci.sessionRetention.toast.archivedCount",{count:se.completedIds.length}):e("settings.vinci.sessionRetention.toast.deletedCount",{count:se.completedIds.length})),se.failedIds.length>0&&H.error(se.action==="archive"?e("settings.vinci.sessionRetention.toast.failedArchiveCount",{count:se.failedIds.length}):e("settings.vinci.sessionRetention.toast.failedDeleteCount",{count:se.failedIds.length}))},t[1]=u,t[2]=e,t[3]=f):f=t[3];const v=f;let y;t[4]!==e?(y=e("settings.vinci.sessionRetention.title"),t[4]=e,t[5]=y):y=t[5];let g;t[6]!==y?(g=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:y}),t[6]=y,t[7]=g):g=t[7];let w;t[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=w):w=t[8];let b;t[9]!==e?(b=e("settings.vinci.sessionRetention.tooltip"),t[9]=e,t[10]=b):b=t[10];let k;t[11]!==b?(k=s.jsxs(Pt,{children:[w,s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:b})]}),t[11]=b,t[12]=k):k=t[12];let I;t[13]!==g||t[14]!==k?(I=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[g,k]})}),t[13]=g,t[14]=k,t[15]=I):I=t[15];let j,N;t[16]!==n||t[17]!==a?(j=()=>a(!n),N=se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),a(!n))},t[16]=n,t[17]=a,t[18]=j,t[19]=N):(j=t[18],N=t[19]);let D;t[20]!==e?(D=e("settings.vinci.sessionRetention.field.enableAutoCleanupAria"),t[20]=e,t[21]=D):D=t[21];let E;t[22]!==n||t[23]!==a||t[24]!==D?(E=s.jsx(ds,{checked:n,onChange:a,ariaLabel:D}),t[22]=n,t[23]=a,t[24]=D,t[25]=E):E=t[25];let T;t[26]!==e?(T=e("settings.vinci.sessionRetention.field.enableAutoCleanup"),t[26]=e,t[27]=T):T=t[27];let C;t[28]!==T?(C=s.jsx("span",{className:"typography-ui-label text-foreground",children:T}),t[28]=T,t[29]=C):C=t[29];let S;t[30]!==n||t[31]!==E||t[32]!==C||t[33]!==j||t[34]!==N?(S=s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:j,onKeyDown:N,children:[E,C]}),t[30]=n,t[31]=E,t[32]=C,t[33]=j,t[34]=N,t[35]=S):S=t[35];let M;t[36]!==e?(M=e("settings.vinci.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=M):M=t[37];let A;t[38]!==M?(A=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:M})}),t[38]=M,t[39]=A):A=t[39];let R;t[40]!==e?(R=e("settings.vinci.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=R):R=t[41];let z;t[42]!==r||t[43]!==l||t[44]!==R?(z=s.jsx(Vn,{value:r,onValueChange:l,min:G5,max:q5,step:1,"aria-label":R,className:"w-20 tabular-nums"}),t[42]=r,t[43]=l,t[44]=R,t[45]=z):z=t[45];let B;t[46]!==e?(B=e("settings.vinci.sessionRetention.field.days"),t[46]=e,t[47]=B):B=t[47];let V;t[48]!==B?(V=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:B}),t[48]=B,t[49]=V):V=t[49];let $;t[50]!==l?($=()=>l(Fp),t[50]=l,t[51]=$):$=t[51];const _=r===Fp;let X;t[52]!==e?(X=e("settings.vinci.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=X):X=t[53];let O;t[54]!==e?(O=e("settings.common.actions.reset"),t[54]=e,t[55]=O):O=t[55];let J;t[56]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(P,{name:"restart",className:"h-3.5 w-3.5"}),t[56]=J):J=t[56];let Q;t[57]!==$||t[58]!==_||t[59]!==X||t[60]!==O?(Q=s.jsx(ge,{size:"sm",type:"button",variant:"ghost",onClick:$,disabled:_,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":X,title:O,children:J}),t[57]=$,t[58]=_,t[59]=X,t[60]=O,t[61]=Q):Q=t[61];let ne;t[62]!==z||t[63]!==V||t[64]!==Q?(ne=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[z,V,Q]}),t[62]=z,t[63]=V,t[64]=Q,t[65]=ne):ne=t[65];let G;t[66]!==A||t[67]!==ne?(G=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[A,ne]}),t[66]=A,t[67]=ne,t[68]=G):G=t[68];let le;t[69]!==e?(le=e("settings.vinci.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=le):le=t[70];let oe;t[71]!==le?(oe=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:le})}),t[71]=le,t[72]=oe):oe=t[72];let F;t[73]!==i||t[74]!==c||t[75]!==e?(F=Y5.map(se=>s.jsx(ge,{type:"button",variant:"chip",size:"xs","aria-pressed":i===se.value,className:"!font-normal",onClick:()=>c(se.value),children:e(se.labelKey)},se.value)),t[73]=i,t[74]=c,t[75]=e,t[76]=F):F=t[76];let U;t[77]!==F?(U=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:F}),t[77]=F,t[78]=U):U=t[78];let W;t[79]!==oe||t[80]!==U?(W=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[oe,U]}),t[79]=oe,t[80]=U,t[81]=W):W=t[81];let te;t[82]!==S||t[83]!==G||t[84]!==W?(te=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[S,G,W]}),t[82]=S,t[83]=G,t[84]=W,t[85]=te):te=t[85];let K;t[86]!==e?(K=e("settings.vinci.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=K):K=t[87];let ae;t[88]!==K?(ae=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("p",{className:"typography-meta text-foreground font-medium",children:K})}),t[88]=K,t[89]=ae):ae=t[89];let ve;t[90]!==m||t[91]!==e?(ve=e(m?"settings.vinci.sessionRetention.actions.cleaningUp":"settings.vinci.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=ve):ve=t[92];let re;t[93]!==v||t[94]!==m||t[95]!==ve?(re=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(ge,{type:"button",variant:"outline",size:"xs",onClick:v,disabled:m,className:"!font-normal",children:ve})}),t[93]=v,t[94]=m,t[95]=ve,t[96]=re):re=t[96];let be;t[97]!==ae||t[98]!==re?(be=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ae,re]}),t[97]=ae,t[98]=re,t[99]=be):be=t[99];let pe;t[100]!==h||t[101]!==x||t[102]!==e?(pe=h==="archive"?e("settings.vinci.sessionRetention.manualCleanup.eligibleArchiveNow",{count:x}):e("settings.vinci.sessionRetention.manualCleanup.eligibleDeleteNow",{count:x}),t[100]=h,t[101]=x,t[102]=e,t[103]=pe):pe=t[103];let ye;t[104]!==pe?(ye=s.jsx("p",{className:"typography-meta text-muted-foreground",children:pe}),t[104]=pe,t[105]=ye):ye=t[105];let ie;t[106]!==be||t[107]!==ye?(ie=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[be,ye]}),t[106]=be,t[107]=ye,t[108]=ie):ie=t[108];let ue;return t[109]!==te||t[110]!==ie||t[111]!==I?(ue=s.jsxs("div",{className:"mb-8",children:[I,te,ie]}),t[109]=te,t[110]=ie,t[111]=I,t[112]=ue):ue=t[112],ue};function Q5(t){return t.autoDeleteEnabled}function J5(t){return t.autoDeleteAfterDays}function X5(t){return t.sessionRetentionAction}function Z5(t){return t.setAutoDeleteEnabled}function eC(t){return t.setAutoDeleteAfterDays}function tC(t){return t.setSessionRetentionAction}const Lp=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),Ng=()=>{const{t}=ut(),[e,n]=o.useState(!1),[r,i]=o.useState(!0),[a,l]=o.useState(!1),[c,d]=o.useState(null),[p,m]=o.useState(!1),[u,h]=o.useState([]),[x,f]=o.useState(Xb),[v,y]=o.useState(""),g=o.useMemo(()=>Zb(),[]),w=o.useCallback(async()=>{i(!0),y("");try{const j=await ey();h(j)}catch(j){const N=j instanceof Error?j.message:t("settings.vinci.passkeys.toast.loadFailed");y(N)}finally{i(!1)}},[t]);o.useEffect(()=>{let j=!1;return(async()=>{try{if(!g.supported){j||(n(!1),i(!1));return}j||n(!0)}catch{j||n(!1)}if(!j){const N=await rc();if(f(N),!N.enabled){h([]),i(!1);return}await w()}})(),()=>{j=!0,Eu()}},[w,g.supported]);const b=o.useCallback(async()=>{if(!x.enabled){const j=t("settings.vinci.passkeys.toast.enableUiPasswordFirst");y(j),H.message(j);return}if(!e){y(g.reason),H.message(g.reason);return}if(a){Eu(),l(!1);return}y(""),l(!0);try{await ty(),f(await rc()),await w(),H.success(t("settings.vinci.passkeys.toast.added"))}catch(j){if(sy(j)){H.message(t("settings.vinci.passkeys.toast.setupCanceled"));return}const N=j instanceof Error?j.message:t("settings.vinci.passkeys.toast.addFailed");y(N),H.error(N)}finally{l(!1)}},[a,w,x.enabled,g.reason,e,t]),k=o.useCallback(async j=>{d(j),y("");try{await ny(j),f(await rc()),await w(),H.success(t("settings.vinci.passkeys.toast.removed"))}catch(N){const D=N instanceof Error?N.message:t("settings.vinci.passkeys.toast.removeFailed");y(D),H.error(D)}finally{d(null)}},[w,t]),I=o.useCallback(async()=>{m(!0),y("");try{await ry(),window.location.reload()}catch(j){const N=j instanceof Error?j.message:t("settings.vinci.passkeys.toast.clearAuthFailed");y(N),H.error(N),m(!1)}},[t]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.vinci.passkeys.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.passkeys.field.currentDevice")})}),s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[s.jsx(ge,{type:"button",variant:a?"secondary":"outline",size:"xs",onClick:()=>{b()},disabled:r||p,className:"!font-normal",children:t(a?"settings.vinci.passkeys.actions.cancelSetup":"settings.vinci.passkeys.actions.add")}),s.jsx(ge,{type:"button",variant:"ghost",size:"xs",onClick:()=>{I()},disabled:r||a||p,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(p?"settings.vinci.passkeys.actions.signingOut":"settings.vinci.passkeys.actions.signOutEverywhere")})]})]}),!x.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.vinci.passkeys.state.uiPasswordRequired")}),x.enabled&&!e&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.vinci.passkeys.state.loading")}):u.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.vinci.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:u.map(j=>s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j.label})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:j.lastUsedAt?t("settings.vinci.passkeys.item.lastUsed",{time:Lp(j.lastUsedAt,t("settings.vinci.passkeys.time.neverUsed"))}):t("settings.vinci.passkeys.item.added",{time:Lp(j.createdAt,t("settings.vinci.passkeys.time.neverUsed"))})}),s.jsx(ge,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k(j.id)},disabled:c===j.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===j.id?t("settings.vinci.passkeys.actions.removing"):t("settings.common.actions.delete")})]})]},j.id))})]}),v&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v})})]})},sC=t=>{const e=ba(t);return e||{providerId:"",modelId:""}},Sg=()=>{const{t}=ut(),e=xt(A=>A.setProvider),n=xt(A=>A.setModel),r=xt(A=>A.setAgent),i=xt(A=>A.setCurrentVariant),a=xt(A=>A.setSettingsDefaultModel),l=xt(A=>A.setSettingsDefaultVariant),c=xt(A=>A.setSettingsDefaultAgent),d=xt(A=>A.setSettingsDefaultFileViewerPreview),p=xt(A=>A.settingsDefaultFileViewerPreview),m=Ie(A=>A.showDeletionDialog),u=Ie(A=>A.setShowDeletionDialog),h=xt(A=>A.providers),[x,f]=o.useState(),[v,y]=o.useState(),[g,w]=o.useState(),[b,k]=o.useState(!0),I=o.useMemo(()=>sC(x),[x]);o.useEffect(()=>{(async()=>{try{let R=null;if(!R){const z=pr()?.settings;if(z)try{const V=(await z.load())?.settings;V&&(R={defaultModel:typeof V.defaultModel=="string"?V.defaultModel:void 0,defaultVariant:typeof V.defaultVariant=="string"?V.defaultVariant:void 0,defaultAgent:typeof V.defaultAgent=="string"?V.defaultAgent:void 0})}catch{}}if(!R){const z=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});z.ok&&(R=await z.json())}if(R){const z=typeof R.defaultModel=="string"&&R.defaultModel.trim().length>0?R.defaultModel.trim():void 0,B=typeof R.defaultVariant=="string"&&R.defaultVariant.trim().length>0?R.defaultVariant.trim():void 0,V=typeof R.defaultAgent=="string"&&R.defaultAgent.trim().length>0?R.defaultAgent.trim():void 0;z!==void 0&&f(z),B!==void 0&&y(B),V!==void 0&&w(V)}}catch(R){console.warn("Failed to load defaults settings:",R)}finally{k(!1)}})()},[]);const j=o.useCallback(async(A,R)=>{const z=A&&R?`${A}/${R}`:void 0;f(z),y(void 0),l(void 0),i(void 0),a(z),A&&R&&h.find(V=>V.id===A)&&(e(A),n(R));try{await ks({defaultModel:z??"",defaultVariant:""});const B=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:z})});B.ok||console.warn("Failed to save default model to server:",B.status,B.statusText)}catch(B){console.warn("Failed to save default model:",B)}},[h,i,n,e,a,l]),N="__default__",D=o.useCallback(A=>A===N?t("settings.vinci.defaults.option.default"):A.charAt(0).toUpperCase()+A.slice(1),[t]),E=o.useCallback(async A=>{const R=A===N?void 0:A||void 0;y(R),l(R),i(R);try{await ks({defaultVariant:R??""})}catch(z){console.warn("Failed to save default variant:",z)}},[i,l]),T=o.useCallback(async A=>{const R=A||void 0;w(R),c(R),A&&r(A);try{await ks({defaultAgent:R??""})}catch(z){console.warn("Failed to save default agent:",z)}},[r,c]),C=o.useCallback(()=>{const A=!p;d(A),ks({defaultFileViewerPreview:A}).catch(console.warn)},[p,d]),S=o.useMemo(()=>{if(!I.providerId||!I.modelId)return[];const z=h.find(B=>B.id===I.providerId)?.models.find(B=>B.id===I.modelId)?.variants;return z?Object.keys(z):[]},[I.modelId,I.providerId,h]),M=S.length>0;return o.useEffect(()=>{!M&&v&&(y(void 0),l(void 0),i(void 0),ks({defaultVariant:""}).catch(()=>{}))},[v,i,l,M]),b?null:s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-0.5 px-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.vinci.defaults.title")})})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.vinci.defaults.summaryPrefix")," ",I.providerId?s.jsxs("span",{className:"text-foreground",children:[I.providerId,"/",I.modelId,M?` (${v??t("settings.vinci.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.vinci.defaults.summaryOpenCodeDefault")}),g&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:g})]})]}),s.jsxs("div",{className:ce("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.defaults.field.defaultModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(yo,{providerId:I.providerId,modelId:I.modelId,onChange:j})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.defaults.field.defaultThinking")})}),s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsxs(is,{value:v??N,onValueChange:E,disabled:!M,children:[s.jsx(as,{className:"w-fit min-w-[120px]",children:s.jsx(us,{placeholder:t("settings.vinci.defaults.field.thinkingPlaceholder"),children:D(v??N)})}),s.jsxs(os,{children:[s.jsx(Ft,{value:N,children:t("settings.vinci.defaults.option.default")}),S.map(A=>s.jsx(Ft,{value:A,children:D(A)},A))]})]})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.defaults.field.defaultAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Ul,{agentName:g||"",onChange:T})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:A=>{(A.key===" "||A.key==="Enter")&&(A.preventDefault(),u(!m))},children:[s.jsx(ds,{checked:m,onChange:u,ariaLabel:t("settings.vinci.defaults.field.showDeletionDialogAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.defaults.field.showDeletionDialog")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":p,onClick:C,onKeyDown:A=>{(A.key===" "||A.key==="Enter")&&(A.preventDefault(),C())},children:[s.jsx(ds,{checked:p,onChange:d,ariaLabel:t("settings.vinci.defaults.field.openFilesPreviewAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.defaults.field.openFilesPreview")})]})]})]})},Op={completion:{titleKey:"settings.notifications.page.template.defaults.completion.title",messageKey:"settings.notifications.page.template.defaults.completion.message"},error:{titleKey:"settings.notifications.page.template.defaults.error.title",messageKey:"settings.notifications.page.template.defaults.error.message"},question:{titleKey:"settings.notifications.page.template.defaults.question.title",messageKey:"settings.notifications.page.template.defaults.question.message"},subtask:{titleKey:"settings.notifications.page.template.defaults.subtask.title",messageKey:"settings.notifications.page.template.defaults.subtask.message"}},nC={completion:"settings.notifications.page.template.event.completion",subtask:"settings.notifications.page.template.event.subtask",error:"settings.notifications.page.template.event.error",question:"settings.notifications.page.template.event.question"},rC=()=>{const{t}=ut(),e=o.useMemo(()=>gn(),[]),n=o.useMemo(()=>mn(),[]),r=!e&&!n,i=Ie(O=>O.nativeNotificationsEnabled),a=Ie(O=>O.setNativeNotificationsEnabled),l=Ie(O=>O.notificationMode),c=Ie(O=>O.setNotificationMode),d=Ie(O=>O.notifyOnSubtasks),p=Ie(O=>O.setNotifyOnSubtasks),m=Ie(O=>O.notifyOnCompletion),u=Ie(O=>O.setNotifyOnCompletion),h=Ie(O=>O.notifyOnError),x=Ie(O=>O.setNotifyOnError),f=Ie(O=>O.notifyOnQuestion),v=Ie(O=>O.setNotifyOnQuestion),y=Ie(O=>O.notificationTemplates),g=Ie(O=>O.setNotificationTemplates),[w,b]=o.useState("default"),[k,I]=o.useState(!1),[j,N]=o.useState(!1),[D,E]=o.useState(!1);o.useEffect(()=>{if(!r){I(!1),N(!1);return}typeof Notification<"u"&&b(Notification.permission);const O=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;I(O),(async()=>{if(!O){N(!1);return}try{const Q=await navigator.serviceWorker.getRegistration();if(!Q){N(!1);return}const ne=await Q.pushManager.getSubscription();N(!!ne)}catch{N(!1)}})()},[r]);const T=async O=>{if(e){a(O);return}if(!r){a(O);return}if(O&&typeof Notification<"u"&&Notification.permission==="default")try{const J=await Notification.requestPermission();b(J),J==="granted"?a(!0):H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(J){console.error("Failed to request notification permission:",J),H.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else a(!!(O&&w==="granted"))},C=e||n||r&&typeof Notification<"u"&&Notification.permission==="granted",S=(O,J,Q)=>{g({...y,[O]:{...y[O],[J]:Q}})},M=O=>{const J="=".repeat((4-O.length%4)%4),Q=(O+J).replace(/-/g,"+").replace(/_/g,"/"),ne=atob(Q),G=new Uint8Array(ne.length);for(let le=0;le<ne.length;le+=1)G[le]=ne.charCodeAt(le);return G},A=async(O,J,Q)=>{let ne=null;const G=new Promise((le,oe)=>{ne=setTimeout(()=>{oe(new Error(Q))},J)});try{return await Promise.race([O,G])}finally{ne&&clearTimeout(ne)}},R=async O=>{if(O.active)return;const J=O.installing||O.waiting;J&&J.state!=="activated"&&await A(new Promise(Q=>{const ne=()=>{J.state==="activated"&&(J.removeEventListener("statechange",ne),Q())};J.addEventListener("statechange",ne),ne()}),15e3,"Service worker activation timed out")},z=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const O=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let J=null;for(const Q of O)try{const ne=Q.opts?navigator.serviceWorker.register("/sw.js",Q.opts):navigator.serviceWorker.register("/sw.js");return await A(ne,1e4,`Service worker registration timed out (${Q.label})`)}catch(ne){J=ne}throw J instanceof Error?J:new Error("Service worker registration failed")},B=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const O=await navigator.serviceWorker.getRegistration();if(O)return O;const J=await z();try{await J.update()}catch{}return await R(J),J},V=O=>{const J=O,Q=[`type=${typeof O}`,`toString=${String(O)}`,`name=${String(J?.name??"")}`,`message=${String(J?.message??"")}`];let ne="";try{ne=JSON.stringify(O)}catch{}return{summary:Q.filter(Boolean).join(" | "),json:ne,stack:typeof J?.stack=="string"?J.stack:""}},$=async()=>{const O=pr();if(!O?.notifications){H.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await O.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"vinci-test"})?H.success(t("settings.notifications.page.toast.testNotificationSent")):H.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(J){console.error("Test notification failed:",J),H.error(t("settings.notifications.page.toast.testNotificationFailed"))}},_=async()=>{if(!k){H.error(t("settings.notifications.page.toast.pushUnsupported"));return}const O=pr();if(!O?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}E(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const U=await Notification.requestPermission();if(b(U),U!=="granted"){H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const J=await O.push.getVapidPublicKey();if(!J?.publicKey){H.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Q=await B();await R(Q);const ne=await Q.pushManager.getSubscription();if(!("pushManager"in Q)||!Q.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const le=(ne??await A(Q.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:M(J.publicKey)}),15e3,"Push subscription timed out")).toJSON(),oe=le.keys;if(!le.endpoint||!oe?.p256dh||!oe.auth)throw new Error("Push subscription missing keys");if(!(await A(O.push.subscribe({endpoint:le.endpoint,keys:{p256dh:oe.p256dh,auth:oe.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){H.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}N(!0),H.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(J){console.error("[Push] Enable failed:",J);const Q=V(J);H.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:Q.summary})}finally{E(!1)}},X=async()=>{if(!k){N(!1);return}const O=pr();if(!O?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}E(!0);try{const Q=await(await B()).pushManager.getSubscription();if(!Q){N(!1);return}const ne=Q.endpoint;await Q.unsubscribe(),await O.push.unsubscribe({endpoint:ne}),N(!1),H.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{E(!1)}};return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.delivery.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":i&&C,onClick:()=>{T(!(i&&C))},onKeyDown:O=>{(O.key===" "||O.key==="Enter")&&(O.preventDefault(),T(!(i&&C)))},children:[s.jsx(ds,{checked:i&&C,onChange:O=>{T(O)},ariaLabel:t("settings.notifications.page.delivery.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.enableLabel")})]}),i&&C&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":l==="always",onClick:()=>c(l==="always"?"hidden-only":"always"),onKeyDown:O=>{(O.key===" "||O.key==="Enter")&&(O.preventDefault(),c(l==="always"?"hidden-only":"always"))},children:[s.jsx(ds,{checked:l==="always",onChange:O=>c(O?"always":"hidden-only"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.focusedLabel")})]}),s.jsx("div",{className:"py-2",children:s.jsx(ge,{type:"button",variant:"outline",size:"sm",onClick:()=>{$()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&s.jsxs("div",{className:"mt-1 px-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.browserPermissionHint")}),w==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),w==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),n&&s.jsx("div",{className:"mt-1 px-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.vscodeHint")})})]}),i&&C&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.events.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:O=>{(O.key===" "||O.key==="Enter")&&(O.preventDefault(),u(!m))},children:[s.jsx(ds,{checked:m,onChange:u,ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.completionLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":d,onClick:()=>p(!d),onKeyDown:O=>{(O.key===" "||O.key==="Enter")&&(O.preventDefault(),p(!d))},children:[s.jsx(ds,{checked:d,onChange:p,ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.subtaskLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":h,onClick:()=>x(!h),onKeyDown:O=>{(O.key===" "||O.key==="Enter")&&(O.preventDefault(),x(!h))},children:[s.jsx(ds,{checked:h,onChange:x,ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.errorLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>v(!f),onKeyDown:O=>{(O.key===" "||O.key==="Enter")&&(O.preventDefault(),v(!f))},children:[s.jsx(ds,{checked:f,onChange:v,ariaLabel:t("settings.notifications.page.events.questionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.questionLabel")})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.template.title")}),s.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),s.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(O=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(nC[O])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(Bt,{value:y[O].title,onChange:J=>S(O,"title",J.target.value),className:"h-7",placeholder:t(Op[O].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(Bt,{value:y[O].message,onChange:J=>S(O,"message",J.target.value),className:"h-7",placeholder:t(Op[O].messageKey)})]})]})]},O))})]})]}),r&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.push.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(ds,{checked:k?j:!1,disabled:!k||D,onChange:O=>{O?_():X()},ariaLabel:t("settings.notifications.page.push.enableAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:ce("typography-ui-label",k?"text-foreground":"text-muted-foreground"),children:t("settings.notifications.page.push.enableLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t(k?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),D&&s.jsx("div",{className:"pt-0.5 text-muted-foreground",children:s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")})})]})})]})]})},iC=[{value:"en-US",label:"English"},{value:"es-ES",label:"Español"},{value:"fr-FR",label:"Français"},{value:"de-DE",label:"Deutsch"},{value:"ja-JP",label:"日本語"},{value:"zh-CN",label:"中文"},{value:"pt-BR",label:"Português"},{value:"it-IT",label:"Italiano"},{value:"ko-KR",label:"한국어"},{value:"uk-UA",label:"Українська"}],aC=t=>{const e=at.c(45),{modelId:n}=t,{t:r}=ut();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=za.getModelStatus(),e[0]=i):i=e[0];const[a,l]=Be.useState(i),[c,d]=Be.useState(!1);let p,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{const j=N=>l(N);return za.onModelStatusChange=j,cC},m=[],e[1]=p,e[2]=m):(p=e[1],m=e[2]),Be.useEffect(p,m);const u=za.getCurrentModelId(),h=a.state==="downloading"||a.state==="loading";let x,f;e[3]!==a.state?(x=()=>{a.state!=="downloading"&&a.state!=="loading"&&d(!1)},f=[a.state],e[3]=a.state,e[4]=x,e[5]=f):(x=e[4],f=e[5]),Be.useEffect(x,f);let v;e[6]!==n?(v=async()=>{d(!0);try{await za.loadModel(n)}catch{}},e[6]=n,e[7]=v):v=e[7];const y=v;if(a.state==="ready"&&u===n){let j;e[8]!==r?(j=r("settings.voice.page.stt.wasmLoaded"),e[8]=r,e[9]=j):j=e[9];let N;return e[10]!==j?(N=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-compact text-green-600 dark:text-green-400",children:j})}),e[10]=j,e[11]=N):N=e[11],N}if(h){let j;e[12]!==a.progress||e[13]!==a.state?(j=a.state==="downloading"?Math.round(a.progress):void 0,e[12]=a.progress,e[13]=a.state,e[14]=j):j=e[14];const N=j;let D;e[15]!==a.state||e[16]!==r?(D=a.state==="downloading"?r("settings.voice.page.stt.wasmDownloading"):r("settings.voice.page.stt.wasmLoading"),e[15]=a.state,e[16]=r,e[17]=D):D=e[17];const E=N!==void 0?` (${N}%)`:"";let T;return e[18]!==D||e[19]!==E?(T=s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[D,E]})}),e[18]=D,e[19]=E,e[20]=T):T=e[20],T}if(a.state==="error"){let j;e[21]!==a.error?(j=s.jsx("span",{className:"typography-ui-compact text-destructive",children:a.error}),e[21]=a.error,e[22]=j):j=e[22];let N;e[23]!==r?(N=r("settings.voice.page.stt.wasmRetry"),e[23]=r,e[24]=N):N=e[24];let D;e[25]!==y||e[26]!==c||e[27]!==N?(D=s.jsx(ge,{variant:"chip",size:"xs",disabled:c,onClick:y,children:N}),e[25]=y,e[26]=c,e[27]=N,e[28]=D):D=e[28];let E;return e[29]!==j||e[30]!==D?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[j,D]}),e[29]=j,e[30]=D,e[31]=E):E=e[31],E}let g;e[32]!==r?(g=r("settings.voice.page.stt.wasmNotLoaded"),e[32]=r,e[33]=g):g=e[33];let w;e[34]!==g?(w=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:g}),e[34]=g,e[35]=w):w=e[35];let b;e[36]!==r?(b=r("settings.voice.page.stt.wasmDownload"),e[36]=r,e[37]=b):b=e[37];let k;e[38]!==y||e[39]!==c||e[40]!==b?(k=s.jsx(ge,{variant:"chip",size:"xs",disabled:c,onClick:y,children:b}),e[38]=y,e[39]=c,e[40]=b,e[41]=k):k=e[41];let I;return e[42]!==k||e[43]!==w?(I=s.jsxs("div",{className:"flex items-center gap-2",children:[w,k]}),e[42]=k,e[43]=w,e[44]=I):I=e[44],I},oC=[{value:"alloy",label:"Alloy"},{value:"ash",label:"Ash"},{value:"ballad",label:"Ballad"},{value:"coral",label:"Coral"},{value:"echo",label:"Echo"},{value:"fable",label:"Fable"},{value:"nova",label:"Nova"},{value:"onyx",label:"Onyx"},{value:"sage",label:"Sage"},{value:"shimmer",label:"Shimmer"},{value:"verse",label:"Verse"},{value:"marin",label:"Marin"},{value:"cedar",label:"Cedar"}],lC=()=>{const{t}=ut(),{isMobile:e}=rn(),{isSupported:n,language:r,setLanguage:i}=iy(),a=xt(Y=>Y.voiceProvider),l=xt(Y=>Y.setVoiceProvider),c=xt(Y=>Y.speechRate),d=xt(Y=>Y.setSpeechRate),p=xt(Y=>Y.speechPitch),m=xt(Y=>Y.setSpeechPitch),u=xt(Y=>Y.speechVolume),h=xt(Y=>Y.setSpeechVolume),x=xt(Y=>Y.sayVoice),f=xt(Y=>Y.setSayVoice),v=xt(Y=>Y.browserVoice),y=xt(Y=>Y.setBrowserVoice),g=xt(Y=>Y.openaiVoice),w=xt(Y=>Y.setOpenaiVoice),b=xt(Y=>Y.openaiApiKey),k=xt(Y=>Y.setOpenaiApiKey),I=xt(Y=>Y.openaiCompatibleUrl),j=xt(Y=>Y.setOpenaiCompatibleUrl),N=xt(Y=>Y.openaiCompatibleVoice),D=xt(Y=>Y.setOpenaiCompatibleVoice),E=xt(Y=>Y.openaiCompatibleTtsModel),T=xt(Y=>Y.setOpenaiCompatibleTtsModel),C=xt(Y=>Y.showMessageTTSButtons),S=xt(Y=>Y.sttProvider),M=xt(Y=>Y.setSttProvider),A=xt(Y=>Y.sttServerUrl),R=xt(Y=>Y.setSttServerUrl),z=xt(Y=>Y.sttModel),B=xt(Y=>Y.setSttModel),V=xt(Y=>Y.wasmSttModel),$=xt(Y=>Y.setWasmSttModel),_=xt(Y=>Y.sttLanguage),X=xt(Y=>Y.setSttLanguage),O=xt(Y=>Y.sttSilenceThresholdDb),J=xt(Y=>Y.setSttSilenceThresholdDb),Q=xt(Y=>Y.sttSilenceHoldMs),ne=xt(Y=>Y.setSttSilenceHoldMs),G=xt(Y=>Y.sttTranscribeOnStop),le=xt(Y=>Y.setSttTranscribeOnStop),oe=xt(Y=>Y.setShowMessageTTSButtons),F=xt(Y=>Y.voiceModeEnabled),U=xt(Y=>Y.setVoiceModeEnabled),[W,te]=Be.useState(!1),[K,ae]=Be.useState([]),[ve,re]=Be.useState(!1),[be,pe]=Be.useState(null),[ye,ie]=Be.useState(!1),[ue,se]=Be.useState(!1),[Ne,Ce]=Be.useState(null),[je,we]=Be.useState(!1),[ke,xe]=Be.useState(null),[me,Me]=Be.useState([]),[Ue,q]=Be.useState(!1);Be.useEffect(()=>((async()=>{const Ee=await ic.waitForVoices();Me(Ee)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Me(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Se=Be.useMemo(()=>me.filter(Y=>Y.lang).sort((Y,Ee)=>{const Ae=Y.lang.startsWith("en"),Je=Ee.lang.startsWith("en");if(Ae&&!Je)return-1;if(!Ae&&Je)return 1;const de=Y.lang.localeCompare(Ee.lang);return de!==0?de:Y.name.localeCompare(Ee.name)}),[me]),$e=Be.useCallback(()=>{if(Ue){ic.cancelSpeech(),q(!1);return}const Y=me.find(de=>de.name===v),Ee=Y?.name??t("settings.voice.page.preview.browserVoiceFallback"),Ae=t("settings.voice.page.preview.voiceLine",{voiceName:Ee});q(!0);const Je=new SpeechSynthesisUtterance(Ae);Je.rate=c,Je.pitch=p,Je.volume=u,Y&&(Je.voice=Y,Je.lang=Y.lang),Je.onend=()=>q(!1),Je.onerror=()=>q(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(Je)},[v,me,c,p,u,Ue,t]);Be.useEffect(()=>()=>{Ue&&ic.cancelSpeech()},[Ue]),Be.useEffect(()=>{if(!F||a!=="openai"&&a!=="openai-compatible"){ie(b.trim().length>0);return}(async()=>{try{const Je=(await(await fetch("/api/tts/status")).json()).available,de=b.trim().length>0;ie(Je||de)}catch{ie(b.trim().length>0)}})()},[b,F,a]),Be.useEffect(()=>{if(!F){te(!1),ae([]);return}fetch("/api/tts/say/status").then(Y=>Y.json()).then(Y=>{if(te(Y.available),Y.voices){const Ee=Y.voices.filter((Ae,Je,de)=>de.findIndex(ze=>ze.name===Ae.name)===Je).sort((Ae,Je)=>Ae.name.localeCompare(Je.name));ae(Ee)}}).catch(()=>{te(!1)})},[F]);const Pe=Be.useCallback(async()=>{if(be){be.pause(),be.currentTime=0,pe(null),re(!1);return}re(!0);try{const Y=await fetch("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:x}),voice:x,rate:Math.round(100+(c-.5)*200)})});if(!Y.ok)throw new Error("Preview failed");const Ee=await Y.blob(),Ae=URL.createObjectURL(Ee),Je=new Audio(Ae);Je.onended=()=>{URL.revokeObjectURL(Ae),pe(null),re(!1)},Je.onerror=()=>{URL.revokeObjectURL(Ae),pe(null),re(!1)},pe(Je),await Je.play()}catch{re(!1)}},[x,c,be,t]);Be.useEffect(()=>()=>{be&&be.pause()},[be]);const fe=Be.useCallback(async()=>{if(Ne){Ne.pause(),Ne.currentTime=0,Ce(null),se(!1);return}se(!0);try{const Y=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:g}),voice:g,speed:c,apiKey:b||void 0})});if(!Y.ok){const de=await Y.json().catch(()=>({error:"Unknown error"}));throw new Error(de.error||`HTTP ${Y.status}`)}const Ee=await Y.blob(),Ae=URL.createObjectURL(Ee),Je=new Audio(Ae);Je.onended=()=>{URL.revokeObjectURL(Ae),Ce(null),se(!1)},Je.onerror=()=>{URL.revokeObjectURL(Ae),Ce(null),se(!1)},Ce(Je),await Je.play()}catch{se(!1)}},[g,c,Ne,b,t]);Be.useEffect(()=>()=>{Ne&&Ne.pause()},[Ne]);const L=Be.useCallback(async()=>{if(ke){ke.pause(),ke.currentTime=0,xe(null),we(!1);return}if(I.trim()){we(!0);try{const Y=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:N,model:E||void 0,speed:c,baseURL:I})});if(!Y.ok){const de=await Y.json().catch(()=>({error:"Unknown error"}));throw new Error(de.error||`HTTP ${Y.status}`)}const Ee=await Y.blob(),Ae=URL.createObjectURL(Ee),Je=new Audio(Ae);Je.onended=()=>{URL.revokeObjectURL(Ae),xe(null),we(!1)},Je.onerror=()=>{URL.revokeObjectURL(Ae),xe(null),we(!1)},xe(Je),await Je.play()}catch{we(!1)}}},[I,N,E,c,ke,t]);Be.useEffect(()=>()=>{ke&&ke.pause()},[ke]);const Z="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.voiceSetup")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":F,onClick:()=>U(!F),onKeyDown:Y=>{(Y.key===" "||Y.key==="Enter")&&(Y.preventDefault(),U(!F))},children:[s.jsx(ds,{checked:F,onChange:U,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),F&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:"OpenAI:"})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":a==="browser",onClick:()=>l("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":a==="openai",onClick:()=>l("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":a==="openai-compatible",onClick:()=>l("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),W&&s.jsxs(ge,{variant:"chip",size:"xs","aria-pressed":a==="say",onClick:()=>l("say"),className:"!font-normal",children:[s.jsx(P,{name:"apple",className:"w-3.5 h-3.5 mr-0.5"}),t("settings.voice.page.provider.say")]})]})]})}),a==="openai"&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:ce("typography-ui-label text-foreground",!ye&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ce("typography-meta ml-2",ye?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(ye&&!b?"settings.voice.page.field.apiKeyHintUsingConfig":ye?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:b,onChange:Y=>k(Y.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),b&&s.jsx("button",{type:"button",onClick:()=>k(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:ce("typography-ui-label text-foreground",!I.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.serverUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:I,onChange:Y=>j(Y.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),I&&s.jsx("button",{type:"button",onClick:()=>j(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:E,onChange:Y=>T(Y.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.voice")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.voiceIdentifierHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx("div",{className:"relative max-w-xs flex-1",children:s.jsx("input",{type:"text",value:N,onChange:Y=>D(Y.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(ge,{size:"xs",variant:"ghost",onClick:L,title:t("settings.voice.page.actions.preview"),disabled:!I.trim(),children:je?s.jsx(P,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(P,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.voice")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[a==="openai"&&ye&&s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:g,onValueChange:w,children:[s.jsx(as,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(os,{children:oC.map(Y=>s.jsx(Ft,{value:Y.value,children:Y.label},Y.value))})]}),s.jsx(ge,{size:"xs",variant:"ghost",onClick:fe,title:t("settings.voice.page.actions.preview"),children:ue?s.jsx(P,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(P,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&W&&K.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:x,onValueChange:f,children:[s.jsx(as,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(os,{children:K.map(Y=>s.jsx(Ft,{value:Y.name,children:Y.name},Y.name))})]}),s.jsx(ge,{size:"xs",variant:"ghost",onClick:Pe,title:t("settings.voice.page.actions.preview"),children:ve?s.jsx(P,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(P,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Se.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:v||"$auto",onValueChange:Y=>y(Y==="$auto"?"":Y),children:[s.jsx(as,{className:"w-fit max-w-[200px]",children:s.jsx(us,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"$auto",children:t("settings.voice.page.field.auto")}),Se.map(Y=>s.jsxs(Ft,{value:Y.name,children:[Y.name," (",Y.lang,")"]},Y.name))]})]}),s.jsx(ge,{size:"xs",variant:"ghost",onClick:$e,title:t("settings.voice.page.actions.preview"),children:Ue?s.jsx(P,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(P,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechRate")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:c,onChange:Y=>d(Number(Y.target.value)),disabled:!n,className:Z}),s.jsx(Vn,{value:c,onValueChange:d,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechPitch")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:p,onChange:Y=>m(Number(Y.target.value)),disabled:!n,className:Z}),s.jsx(Vn,{value:p,onValueChange:m,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechVolume")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:u,onChange:Y=>h(Number(Y.target.value)),disabled:!n,className:Z}),e?s.jsx(Vn,{value:Math.round(u*100),onValueChange:Y=>h(Y/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(u*100),"%"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.language")}),s.jsx("div",{className:"flex items-center gap-2 w-fit",children:s.jsxs(is,{value:r,onValueChange:i,disabled:!n,children:[s.jsx(as,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(os,{children:iC.map(Y=>s.jsx(Ft,{value:Y.value,children:Y.label},Y.value))})]})})]})]})]})]}),F&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.speechRecognition")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.sttBrowser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":S==="browser",onClick:()=>M("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":S==="server",onClick:()=>M("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")}),s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":S==="wasm",onClick:()=>M("wasm"),className:"!font-normal",children:t("settings.voice.page.provider.wasm")})]})]})}),S==="server"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":G,onClick:()=>le(!G),onKeyDown:Y=>{(Y.key===" "||Y.key==="Enter")&&(Y.preventDefault(),le(!G))},children:[s.jsx(ds,{checked:G,onChange:le,ariaLabel:t("settings.voice.page.field.transcribeOnStopAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.transcribeOnStop")})]}),!ay.isSupported()&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:t("settings.voice.page.field.sttBrowserSupportError")}),s.jsxs("div",{children:[s.jsx("span",{className:ce("typography-ui-label text-foreground",!A.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttServerUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:A,onChange:Y=>R(Y.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),A&&s.jsx("button",{type:"button",onClick:()=>R(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:z,onChange:Y=>B(Y.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.language")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttLanguageHint")}),s.jsx("div",{className:"relative mt-1.5 max-w-[8rem]",children:s.jsx("input",{type:"text",value:_,onChange:Y=>X(Y.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceThreshold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:-60,max:-20,step:1,value:O,onChange:Y=>J(Number(Y.target.value)),className:Z}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[O," dB"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceHold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:500,max:3e3,step:100,value:Q,onChange:Y=>ne(Number(Y.target.value)),className:Z}),s.jsx(Vn,{value:Q,onValueChange:ne,min:500,max:3e3,step:100,className:"w-20 tabular-nums"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.millisecondsUnit")})]})]})]}),S==="wasm"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:t("settings.voice.page.stt.wasmModel")}),s.jsxs(is,{value:V,onValueChange:$,children:[s.jsx(as,{className:"mt-0.5",children:s.jsx(us,{placeholder:t("settings.voice.page.stt.wasmModel")})}),s.jsx(os,{children:Ru.map(Y=>s.jsx(Ft,{value:Y.id,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{children:Y.name}),s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[Y.size," · ",Y.languages]})]})},Y.id))})]}),s.jsx("p",{className:"typography-ui-compact text-muted-foreground mt-0.5",children:Ru.find(Y=>Y.id===V)?.description})]}),s.jsx(aC,{modelId:V})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.playbackAndSummary")})}),s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":C,onClick:()=>oe(!C),onKeyDown:Y=>{(Y.key===" "||Y.key==="Enter")&&(Y.preventDefault(),oe(!C))},children:[s.jsx(ds,{checked:C,onChange:oe,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]})}),F&&n&&s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t("settings.voice.page.hint.shiftClickPrefix")," ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Shift"})," + ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Click"})," ",t("settings.voice.page.hint.shiftClickSuffix")]})})]})]})};function cC(){za.onModelStatusChange=null}const Rc=[{value:"1800000",label:"30m",ms:1800*1e3},{value:"180000",label:"3m",ms:180*1e3},{value:"7200000",label:"2h",ms:7200*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3}],Fc=[{value:"3600000",label:"1h",ms:3600*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"43200000",label:"12h",ms:720*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3},{value:"604800000",label:"1w",ms:10080*60*1e3},{value:"2592000000",label:"30d",ms:720*60*60*1e3}],dC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",uC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",$p=[{value:"quick",labelKey:"settings.vinci.tunnel.option.mode.quick.label",tooltipKey:"settings.vinci.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.vinci.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.vinci.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.vinci.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.vinci.tunnel.option.mode.managedLocal.tooltip"}],mC=[".yml",".yaml",".json"],pC="settings.vinci.tunnel.error.invalidConfigExtension",$a=t=>{const e=t.trim().toLowerCase();return mC.some(n=>e.endsWith(n))},kg=t=>t==="cloudflare"?"Cloudflare":t,Bp=t=>{const e=at.c(11),{provider:n}=t;let r;e[0]!==n?(r=kg(n),e[0]=n,e[1]=r):r=e[1];const i=r,l=n==="cloudflare"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==l?(c=ce("size-4 shrink-0",l),e[2]=l,e[3]=c):c=e[3];let d;e[4]!==c?(d=s.jsx(P,{name:"cloud",className:c}),e[4]=c,e[5]=d):d=e[5];let p;e[6]!==i?(p=s.jsx("span",{children:i}),e[6]=i,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs("span",{className:"flex items-center gap-2",children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},Si=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",zp=(t,e,n)=>t.find(i=>i.ms===e)?.value||n,Vp=t=>{const e=Math.max(0,t),n=Math.floor(e/1e3),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60;return r>0?`${r}h ${i}m`:i>0?`${i}m ${a}s`:`${a}s`},fC=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),il=t=>{const e=t.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},hC=t=>{if(!Array.isArray(t))return[];const e=new Set,n=new Set,r=[];for(const i of t){if(!i||typeof i!="object")continue;const a=i,l=typeof a.id=="string"?a.id.trim():"",c=typeof a.name=="string"?a.name.trim():"",d=il(typeof a.hostname=="string"?a.hostname:"");!l||!c||!d||e.has(l)||n.has(d)||(e.add(l),n.add(d),r.push({id:l,name:c,hostname:d}))}return r},gC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,xC=()=>{const{t}=ut(),e=o.useCallback(he=>t(he),[t]),[n,r]=o.useState("checking"),[i,a]=o.useState(null),[l,c]=o.useState(null),[d,p]=o.useState(null),[m,u]=o.useState(null),[h,x]=o.useState(null),[f,v]=o.useState(!1),[y,g]=o.useState(!1),[w,b]=o.useState(!1),[k,I]=o.useState("cloudflare"),[j,N]=o.useState([]),[D,E]=o.useState("quick"),[T,C]=o.useState(null),[S,M]=o.useState([]),[A,R]=o.useState({}),[z,B]=o.useState(""),[V,$]=o.useState({}),[_,X]=o.useState(new Set),[O,J]=o.useState(!1),[Q,ne]=o.useState(""),[G,le]=o.useState(""),[oe,F]=o.useState(""),[U,W]=o.useState(1800*1e3),[te,K]=o.useState(480*60*1e3),[ae,ve]=o.useState(""),[re,be]=o.useState([]),[pe,ye]=o.useState(()=>Date.now()),[ie,ue]=o.useState(null),se=t(pC),Ne=o.useRef(null),Ce=o.useMemo(()=>T?!$a(T):!1,[T]),je=o.useMemo(()=>S.find(he=>he.id===z)||S[0]||null,[S,z]),we=o.useMemo(()=>re.map(he=>{const Ge=he.expiresAt<=pe,Ve=he.status==="active"&&!Ge,it=Ve?Vp(he.expiresAt-pe):he.inactiveReason==="expired"||Ge?"expired":"inactive",dt=it==="expired"?t("settings.vinci.tunnel.state.expired"):he.inactiveReason==="tunnel-revoked"?t("settings.vinci.tunnel.state.revoked"):t("settings.vinci.tunnel.state.inactive"),Ye=Si(he.mode);return{...he,isActive:Ve,mode:Ye,remainingTextForSession:it,inactiveLabel:dt}}),[pe,re,t]),ke=o.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>pe:!1,[pe,i?.bootstrapExpiresAt,i?.connectUrl]),xe=o.useMemo(()=>!i||n!=="active"&&n!=="stopping"?!1:l===D,[l,n,i,D]),me=o.useMemo(()=>!i||n!=="active"||!l?!1:l!==D,[l,n,i,D]),Me=o.useMemo(()=>{if(typeof ie=="number"&&Number.isFinite(ie)&&ie>0)return ie;if(typeof window>"u")return null;const he=Number(window.location.port);return Number.isFinite(he)&&he>0?he:null},[ie]),Ue=o.useCallback(async he=>{await rr(he)},[]),q=o.useCallback(async he=>{try{const[Ge,Ve,it,dt]=await Promise.all([fetch("/api/vinci/tunnel/check",{signal:he}),fetch("/api/vinci/tunnel/status",{signal:he}),fetch("/api/config/settings",{signal:he,headers:{Accept:"application/json"}}),fetch("/api/vinci/tunnel/providers",{signal:he})]),Ye=await Ge.json(),_e=await Ve.json(),et=it.ok?await it.json():{},gt=dt.ok?await dt.json():{},Lt=_e.ttlConfig?.bootstrapTtlMs??(et?.tunnelBootstrapTtlMs===null?null:typeof et?.tunnelBootstrapTtlMs=="number"?et.tunnelBootstrapTtlMs:1800*1e3),Ut=typeof _e.ttlConfig?.sessionTtlMs=="number"?_e.ttlConfig.sessionTtlMs:typeof et?.tunnelSessionTtlMs=="number"?et.tunnelSessionTtlMs:480*60*1e3,mt=Si(_e.mode??et?.tunnelMode),Nt=typeof et?.tunnelProvider=="string"&&et.tunnelProvider.trim().length>0?et.tunnelProvider.trim().toLowerCase():"cloudflare",Xt=typeof et?.managedLocalTunnelConfigPath=="string"&&et.managedLocalTunnelConfigPath.trim()||null,_t=hC(_e?.managedRemoteTunnelPresets),Gt=typeof _e.managedRemoteTunnelHostname=="string"?_e.managedRemoteTunnelHostname:"",lt=_t.length>0?_t:Gt?[{id:`legacy-${il(Gt)}`,name:Gt,hostname:il(Gt)}]:[],Tt=lt[0]?.id||"";if(W(Lt),K(Ut),I(Nt),N(Array.isArray(gt?.providers)?gt.providers:[]),E(mt),C(Xt),M(lt),B(Tt),be(Array.isArray(_e.activeSessions)?_e.activeSessions:[]),c(_e.activeTunnelMode?Si(_e.activeTunnelMode):_e.active&&_e.mode?Si(_e.mode):null),X(new Set(Array.isArray(_e.managedRemoteTunnelTokenPresetIds)?_e.managedRemoteTunnelTokenPresetIds:[])),ue(typeof _e.localPort=="number"?_e.localPort:null),_e.active&&_e.url){a({url:_e.url,connectUrl:null,bootstrapExpiresAt:typeof _e.bootstrapExpiresAt=="number"?_e.bootstrapExpiresAt:null}),r("active");return}r(Ye.available?"idle":"not-available")}catch{he.aborted||(r("error"),u(t("settings.vinci.tunnel.toast.checkAvailabilityFailed")))}},[t]);o.useEffect(()=>{const he=new AbortController;return q(he.signal),()=>he.abort()},[q]),o.useEffect(()=>{if(!i?.connectUrl){p(null);return}let he=!1;return Dx.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Ge=>{he||p(Ge)}).catch(()=>{he||p(null)}),()=>{he=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){ve(t("settings.vinci.tunnel.state.noExpiry"));return}let he=null,Ge=Date.now();const Ve=()=>{const Ye=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;Ye<=0?ve(t("settings.vinci.tunnel.state.expired")):ve(Vp(Ye))},it=()=>{const Ye=Date.now();Ye-Ge>=1e3&&(Ve(),Ge=Ye),he=requestAnimationFrame(it)};Ve(),(typeof document>"u"||document.visibilityState==="visible")&&(he=requestAnimationFrame(it));const dt=()=>{document.visibilityState==="visible"&&he===null?he=requestAnimationFrame(it):document.visibilityState!=="visible"&&he!==null&&(cancelAnimationFrame(he),he=null)};return document.addEventListener("visibilitychange",dt),()=>{document.removeEventListener("visibilitychange",dt),he!==null&&cancelAnimationFrame(he)}},[t,i?.bootstrapExpiresAt]),o.useEffect(()=>{let he=null,Ge=Date.now();const Ve=()=>{const dt=Date.now();dt-Ge>=1e3&&(ye(dt),Ge=dt),he=requestAnimationFrame(Ve)};(typeof document>"u"||document.visibilityState==="visible")&&(he=requestAnimationFrame(Ve));const it=()=>{document.visibilityState==="visible"&&he===null?he=requestAnimationFrame(Ve):document.visibilityState!=="visible"&&he!==null&&(cancelAnimationFrame(he),he=null)};return document.addEventListener("visibilitychange",it),()=>{document.removeEventListener("visibilitychange",it),he!==null&&cancelAnimationFrame(he)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let he=!1;const Ge=async()=>{try{const it=await fetch("/api/vinci/tunnel/status");if(!it.ok||he)return;const dt=await it.json();if(he)return;be(Array.isArray(dt.activeSessions)?dt.activeSessions:[]),X(new Set(Array.isArray(dt.managedRemoteTunnelTokenPresetIds)?dt.managedRemoteTunnelTokenPresetIds:[])),ue(typeof dt.localPort=="number"?dt.localPort:null)}catch{}},Ve=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ge()},5e3);return()=>{he=!0,window.clearInterval(Ve)}},[n]);const Se=o.useCallback(async he=>{b(!0);try{await ks(he),Object.prototype.hasOwnProperty.call(he,"tunnelMode")&&he.tunnelMode&&E(he.tunnelMode),Object.prototype.hasOwnProperty.call(he,"tunnelProvider")&&typeof he.tunnelProvider=="string"&&I(he.tunnelProvider),Object.prototype.hasOwnProperty.call(he,"managedLocalTunnelConfigPath")&&C(he.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(he,"managedRemoteTunnelPresets")&&he.managedRemoteTunnelPresets&&M(he.managedRemoteTunnelPresets)}catch{H.error(t("settings.vinci.tunnel.toast.saveSettingsFailed"))}finally{b(!1)}},[t]),$e=o.useCallback(async(he,Ge)=>{g(!0);try{await ks({tunnelBootstrapTtlMs:he,tunnelSessionTtlMs:Ge})}catch{H.error(t("settings.vinci.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),Pe=o.useCallback(async he=>{const Ge=he.token.trim();if(Ge)try{const Ve={...V,[he.presetId]:Ge};await ks({managedRemoteTunnelPresetTokens:Ve}),X(it=>{const dt=new Set(it);return dt.add(he.presetId),dt})}catch{H.error(t("settings.vinci.tunnel.toast.saveTokenFailed"))}},[V,t]),fe=o.useCallback(async he=>{x(null),u(null),await Se({tunnelProvider:he})},[Se]),L=o.useCallback(async()=>{const he=await Xf({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(he.success&&typeof he.path=="string"&&he.path.trim().length>0){const Ge=he.path.trim();if(!$a(Ge)){H.error(se);return}C(Ge),await Se({managedLocalTunnelConfigPath:Ge});return}Ne.current?.click()},[se,Se]),Z=o.useCallback(he=>{const Ge=he.trim();C(Ge.length>0?Ge:null)},[]),Y=o.useCallback(async()=>{if(T&&!$a(T)){H.error(se);return}await Se({managedLocalTunnelConfigPath:T})},[se,T,Se]),Ee=o.useCallback(async()=>{C(null),await Se({managedLocalTunnelConfigPath:null})},[Se]),Ae=o.useCallback(async he=>{const Ge=he.target.files?.[0];if(!Ge)return;const Ve=Ge.name.trim();if(Ve.length!==0){if(!$a(Ve)){H.error(se);return}C(Ve),await Se({managedLocalTunnelConfigPath:Ve}),he.target.value=""}},[se,Se]),Je=o.useCallback(async()=>{if(u(null),x(null),D==="managed-local"&&T&&!$a(T)){u(se),H.error(se);return}r("starting");try{let he="",Ge="";if(D==="managed-remote"){if(!je){r("idle"),x(t("settings.vinci.tunnel.toast.selectOrAddManagedRemoteFirst")),H.error(t("settings.vinci.tunnel.toast.selectOrAddManagedRemoteFirst"));return}he=je.hostname,Ge=(V[je.id]||"").trim(),await Se({tunnelMode:"managed-remote",managedRemoteTunnelPresets:S})}const Ve=await fetch("/api/vinci/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:k,mode:D,...D==="managed-remote"&&je?{managedRemoteTunnelPresetId:je.id,managedRemoteTunnelPresetName:je.name}:{},...D==="managed-remote"&&he?{managedRemoteTunnelHostname:he}:{},...D==="managed-remote"&&Ge?{managedRemoteTunnelToken:Ge}:{},...D==="managed-local"&&T?{configPath:T}:{}})}),it=await Ve.json();if(!Ve.ok||!it.ok){if(D==="managed-remote"&&typeof it.error=="string"&&it.error.includes("Managed remote tunnel token is required")){r("idle"),x(t("settings.vinci.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),H.error(t("settings.vinci.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(it.error||t("settings.vinci.tunnel.toast.startFailed")),H.error(it.error||t("settings.vinci.tunnel.toast.startFailed"));return}const dt=typeof it.url=="string"?it.url:"";if(!dt){r("error"),u(t("settings.vinci.tunnel.toast.startedButNoPublicUrl")),H.error(t("settings.vinci.tunnel.toast.startedButNoPublicUrl"));return}if(a({url:dt,connectUrl:typeof it.connectUrl=="string"?it.connectUrl:null,bootstrapExpiresAt:typeof it.bootstrapExpiresAt=="number"?it.bootstrapExpiresAt:null}),c(it.activeTunnelMode?Si(it.activeTunnelMode):it.mode?Si(it.mode):D),be(Array.isArray(it.activeSessions)?it.activeSessions:[]),Array.isArray(it.managedRemoteTunnelTokenPresetIds)&&X(new Set(it.managedRemoteTunnelTokenPresetIds)),typeof it.localPort=="number"&&ue(it.localPort),typeof it.mode=="string"&&E(Si(it.mode)),r("active"),it.replacedTunnel){const Ye=typeof it.revokedBootstrapCount=="number"?it.revokedBootstrapCount:0,_e=typeof it.invalidatedSessionCount=="number"?it.invalidatedSessionCount:0;Ye===1&&_e===1?H.warning(t("settings.vinci.tunnel.toast.replacedTunnelSingleSingle")):Ye===1?H.warning(t("settings.vinci.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:_e})):_e===1?H.warning(t("settings.vinci.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:Ye})):H.warning(t("settings.vinci.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:Ye,invalidatedSessionCount:_e}))}else H.success(t("settings.vinci.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.vinci.tunnel.toast.startFailed")),H.error(t("settings.vinci.tunnel.toast.startFailed"))}},[se,S,Se,je,V,t,k,D,T]),de=o.useCallback(async()=>{r("stopping");try{await fetch("/api/vinci/tunnel/stop",{method:"POST"});const he=await fetch("/api/vinci/tunnel/status");if(he.ok){const Ge=await he.json();be(Array.isArray(Ge.activeSessions)?Ge.activeSessions:[]),X(new Set(Array.isArray(Ge.managedRemoteTunnelTokenPresetIds)?Ge.managedRemoteTunnelTokenPresetIds:[])),ue(typeof Ge.localPort=="number"?Ge.localPort:null)}a(null),c(null),p(null),r("idle"),H.success(t("settings.vinci.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.vinci.tunnel.toast.stopFailed")),H.error(t("settings.vinci.tunnel.toast.stopFailed"))}},[t]),ze=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),v(!0),H.success(t("settings.vinci.tunnel.toast.connectLinkCopied")),setTimeout(()=>v(!1),2e3)}catch{H.error(t("settings.vinci.tunnel.toast.copyUrlFailed"))}},[t,i?.connectUrl]),rt=o.useCallback(async he=>{const Ge=Rc.find(Ve=>Ve.value===he);Ge&&(W(Ge.ms),await $e(Ge.ms,te))},[$e,te]),Re=o.useCallback(async he=>{const Ge=Fc.find(Ve=>Ve.value===he);!Ge||Ge.ms===null||(K(Ge.ms),await $e(U,Ge.ms))},[U,$e]),Xe=o.useCallback(async he=>{x(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await Se({tunnelMode:he,managedRemoteTunnelPresets:S})},[S,Se,n]),qe=o.useCallback(async(he,Ge)=>{try{await ks({managedRemoteTunnelPresets:Ge})}catch{H.error(t("settings.vinci.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Te=o.useCallback(he=>{const Ge=S.find(Ve=>Ve.id===he);Ge&&(B(Ge.id),x(null),qe(Ge,S))},[S,qe]),We=o.useCallback(async()=>{const he=Q.trim(),Ge=il(G),Ve=oe.trim();if(!he){H.error(t("settings.vinci.tunnel.toast.tunnelNameRequired"));return}if(!Ge){H.error(t("settings.vinci.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Ve){H.error(t("settings.vinci.tunnel.toast.managedRemoteTokenRequired"));return}if(S.some(Ye=>Ye.hostname===Ge)){H.error(t("settings.vinci.tunnel.toast.hostnameAlreadyExists"));return}const it={id:gC(),name:he,hostname:Ge},dt=[...S,it];M(dt),B(it.id),R(Ye=>({...Ye,[it.id]:!0})),$(Ye=>({...Ye,[it.id]:Ve})),x(null),J(!1),ne(""),le(""),F(""),await Se({tunnelMode:"managed-remote",managedRemoteTunnelPresets:dt,managedRemoteTunnelPresetTokens:{...V,[it.id]:Ve}}),await Pe({presetId:it.id,presetName:it.name,hostname:it.hostname,token:Ve}),H.success(t("settings.vinci.tunnel.toast.managedRemoteSaved"))},[S,G,Q,oe,Pe,Se,V,t]),Ze=o.useCallback(async he=>{const Ge=S.find(_e=>_e.id===he);if(!Ge)return;const Ve=S.filter(_e=>_e.id!==Ge.id),it=Ve[0]?.id||"",dt=z===Ge.id?it:z,Ye=Object.fromEntries(Object.entries(V).filter(([_e,et])=>_e!==Ge.id&&et.trim().length>0));M(Ve),B(dt),R(_e=>{const et={..._e};return delete et[Ge.id],et}),$(_e=>{const et={..._e};return delete et[Ge.id],et}),X(_e=>{const et=new Set(_e);return et.delete(Ge.id),et}),x(null),await Se({managedRemoteTunnelPresets:Ve,managedRemoteTunnelPresetTokens:Ye}),H.success(t("settings.vinci.tunnel.toast.managedRemoteRemoved"))},[S,Se,z,V,t]),Qe="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.vinci.tunnel.state.loading")})}):s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.vinci.tunnel.title")}),s.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/70",children:t("settings.vinci.tunnel.description")}),s.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:t("settings.vinci.tunnel.note.serverSideEnforced")}),s.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:t("settings.vinci.tunnel.note.connectLinksOneTime")})]}),we.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(P,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.vinci.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:we.map(he=>{const Ge=he.mode==="quick",Ve=he.mode==="managed-remote",it=Ge?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Ve?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",dt=he.isActive?Ge?"text-[var(--status-warning)]":Ve?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",Ye=t(Ge?"settings.vinci.tunnel.badge.quick":Ve?"settings.vinci.tunnel.badge.remote":"settings.vinci.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(P,{name:"checkbox-blank-circle-fill",className:ce("size-2.5 shrink-0",dt)}),s.jsx("span",{className:ce("typography-micro rounded border px-1.5 py-0.5 uppercase",it),children:Ye}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.vinci.tunnel.session.redeemedAt",{time:fC(he.createdAt)})}),s.jsx("span",{className:"typography-meta text-foreground",children:he.isActive?t("settings.vinci.tunnel.session.expiresIn",{remaining:he.remainingTextForSession}):he.inactiveLabel===t("settings.vinci.tunnel.state.inactive")?t("settings.vinci.tunnel.state.inactive"):t("settings.vinci.tunnel.session.inactiveWithReason",{reason:he.inactiveLabel})})]},he.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(P,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.vinci.tunnel.notAvailable.cloudflaredNotFound")}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.vinci.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:"brew install cloudflared"})]})]})}),n!=="not-available"&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.vinci.tunnel.field.provider")}),s.jsxs(is,{value:k,onValueChange:he=>{fe(he)},disabled:w||n==="starting"||n==="stopping",children:[s.jsx(as,{className:"max-w-[16rem]",children:s.jsx(us,{placeholder:t("settings.vinci.tunnel.field.providerPlaceholder"),children:kg(k)})}),s.jsxs(os,{children:[j.length>0?j.map(he=>s.jsx(Ft,{value:he.provider,children:s.jsx(Bp,{provider:he.provider})},he.provider)):s.jsx(Ft,{value:"cloudflare",children:s.jsx(Bp,{provider:"cloudflare"})}),s.jsx(Ft,{value:"__more-soon",disabled:!0,children:t("settings.vinci.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.vinci.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:$p.map(he=>s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{variant:"chip",size:"xs","aria-pressed":D===he.value,className:"!font-normal",onClick:()=>{Xe(he.value)},disabled:w||n==="starting"||n==="stopping",children:e(he.labelKey)})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:e(he.tooltipKey)})]},he.value))})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.vinci.tunnel.field.connectLinkTtl")}),s.jsxs(is,{value:zp(Rc,U,"1800000"),onValueChange:he=>{rt(he)},disabled:y||w||n==="starting"||n==="stopping",children:[s.jsx(as,{className:"max-w-[11rem] min-w-0",children:s.jsx(us,{className:"truncate"})}),s.jsx(os,{children:Rc.map(he=>s.jsx(Ft,{value:he.value,children:he.label},he.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.vinci.tunnel.field.tunnelSessionTtl")}),s.jsxs(is,{value:zp(Fc,te,"28800000"),onValueChange:he=>{Re(he)},disabled:y||w||n==="starting"||n==="stopping",children:[s.jsx(as,{className:"max-w-[11rem] min-w-0",children:s.jsx(us,{className:"truncate"})}),s.jsx(os,{children:Fc.map(he=>s.jsx(Ft,{value:he.value,children:he.label},he.value))})]})]})]}),D==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(P,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.vinci.tunnel.option.mode.quick.tooltip")}),s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.vinci.tunnel.warning.quickModeReliability")})]})]})}),D==="managed-remote"&&s.jsxs("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Me=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.vinci.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Me]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.vinci.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(ge,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>J(he=>!he),disabled:n==="starting"||n==="stopping"||w,children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),S.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:S.map((he,Ge)=>{const Ve=V[he.id]||"",it=_.has(he.id),dt=A[he.id]??!1;return s.jsx("div",{className:ce(Ge<S.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(fr,{open:dt,onOpenChange:Ye=>{R(_e=>({..._e,[he.id]:Ye})),Ye&&Te(he.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Pr,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||w,children:[dt?s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:he.name})]}),s.jsx(ge,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.vinci.tunnel.actions.removePresetAria",{name:he.name}),onClick:()=>{Ze(he.id)},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(hr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.vinci.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:he.hostname})]}),s.jsx(Bt,{type:"password",value:Ve,onChange:Ye=>{const _e=Ye.target.value;x(null),$(et=>({...et,[he.id]:_e}))},onBlur:Ye=>{const _e=Ye.currentTarget.value.trim();_e&&Pe({presetId:he.id,presetName:he.name,hostname:he.hostname,token:_e})},placeholder:t(it?"settings.vinci.tunnel.field.savedTokenAvailablePlaceholder":"settings.vinci.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(ge,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Ve.trim().length===0,onClick:()=>{Pe({presetId:he.id,presetName:he.name,hostname:he.hostname,token:Ve})},children:t("settings.vinci.tunnel.actions.saveToken")})})]})})]})},he.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.vinci.tunnel.empty.noManagedRemoteTunnels")}),O&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Bt,{value:Q,onChange:he=>ne(he.target.value),placeholder:t("settings.vinci.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Bt,{value:G,onChange:he=>le(he.target.value),placeholder:t("settings.vinci.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Bt,{type:"password",value:oe,onChange:he=>F(he.target.value),placeholder:t("settings.vinci.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),typeof Me=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.vinci.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Me]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{We()},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(ge,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{J(!1),ne(""),le(""),F("")},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.vinci.tunnel.note.tokensSavedPerTunnel")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground/70 hover:text-foreground","aria-label":t("settings.vinci.tunnel.field.managedRemoteTokenInfoAria"),children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t("settings.vinci.tunnel.tooltip.tokensSavedPath")})]})]}),!je&&h&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:h})]}),D==="managed-local"&&s.jsx("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.vinci.tunnel.field.configurationFile")}),s.jsx("input",{ref:Ne,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:he=>{Ae(he)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:T||"",onChange:he=>{Z(he.target.value)},onBlur:()=>{Y()},placeholder:t("settings.vinci.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||w}),s.jsx(ge,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.vinci.tunnel.actions.browseConfigFileAria"),onClick:()=>{L()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(P,{name:"folder",className:"size-3.5"})}),T&&s.jsx(ge,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.vinci.tunnel.actions.clearConfigFileAria"),onClick:()=>{Ee()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(P,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(T?"settings.vinci.tunnel.note.customConfigUsed":"settings.vinci.tunnel.note.defaultConfigUsed")}),Ce&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:se})]})}),!xe&&s.jsxs("div",{className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(P,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[D==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.vinci.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ue(dC)},children:[t("settings.vinci.tunnel.actions.openManagedRemoteDocs"),s.jsx(P,{name:"external-link",className:"size-3.5"})]})]}),D==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.vinci.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ue(uC)},children:[t("settings.vinci.tunnel.actions.openManagedLocalDocs"),s.jsx(P,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.vinci.tunnel.note.startModeAndGenerateLink",{mode:e($p.find(he=>he.value===D)?.labelKey??"settings.vinci.tunnel.option.mode.quick.label")})})]})]})}),D==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.vinci.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(is,{value:z||(S[0]?.id??""),onValueChange:he=>{Te(he)},disabled:w||n==="starting"||n==="stopping"||S.length<=1,children:[s.jsx(as,{children:s.jsx(us,{placeholder:t("settings.vinci.tunnel.field.selectSavedTunnelPlaceholder"),children:je?.name})}),s.jsx(os,{fitContent:!0,children:S.map(he=>s.jsx(Ft,{value:he.id,children:he.name},he.id))})]})]}),me&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(P,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.vinci.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(ge,{size:"sm",variant:"outline",onClick:Je,disabled:n==="starting"||w||D==="managed-remote"&&!je||D==="managed-local"&&Ce,className:ce(Qe,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.vinci.tunnel.actions.startingTunnel")]}):t("settings.vinci.tunnel.actions.startTunnel")})]})]}),xe&&i&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.vinci.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.vinci.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.url})]}),ke&&i.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.vinci.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.connectUrl}),s.jsxs(ge,{size:"sm",variant:"ghost",onClick:ze,className:"shrink-0 gap-1.5",children:[f?s.jsx(P,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(P,{name:"file-copy",className:"size-3.5"}),t(f?"settings.vinci.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.vinci.tunnel.field.expires"),": ",i.bootstrapExpiresAt?ae:t("settings.vinci.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[d?s.jsx("img",{src:d,alt:t("settings.vinci.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.vinci.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ge,{size:"sm",variant:"outline",onClick:Je,disabled:n==="stopping"||w||D==="managed-local"&&Ce,className:Qe,children:[s.jsx(P,{name:"restart",className:"size-3.5"}),t("settings.vinci.tunnel.actions.newConnectLink")]}),s.jsx(ge,{size:"sm",variant:"ghost",onClick:de,disabled:n==="stopping"||w,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.vinci.tunnel.actions.stopping")]}):t("settings.vinci.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&m&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m}),s.jsx(ge,{size:"sm",variant:"ghost",onClick:Je,children:t("settings.vinci.tunnel.actions.retry")})]})]})},Cg=()=>{const{t}=ut(),[e,n]=Be.useState(""),[r,i]=Be.useState(!0),[a,l]=Be.useState(!1),c=Ie(u=>u.showOpenCodeUpdateNotifications),d=Ie(u=>u.setShowOpenCodeUpdateNotifications);Be.useEffect(()=>{let u=!1;return(async()=>{try{const h=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!h.ok)return;const x=await h.json().catch(()=>null);if(u||!x)return;const f=typeof x.opencodeBinary=="string"?x.opencodeBinary.trim():"";n(f)}catch{}finally{u||i(!1)}})(),()=>{u=!0}},[]);const p=Be.useCallback(async()=>{if(typeof window>"u"||!gn()||!pa())return;const u=window.__TAURI__;if(u?.dialog?.open)try{const h=await u.dialog.open({title:t("settings.vinci.opencodeCli.dialog.selectBinaryTitle"),multiple:!1,directory:!1});typeof h=="string"&&h.trim().length>0&&n(h.trim())}catch{}},[t]),m=Be.useCallback(async()=>{l(!0);try{await ks({opencodeBinary:e.trim()}),await Fi({message:t("settings.vinci.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{l(!1)}},[t,e]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.vinci.opencodeCli.title")}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Dt,{sideOffset:8,className:"max-w-xs",children:[t("settings.vinci.opencodeCli.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs",children:"opencode"}),t("settings.vinci.opencodeCli.tooltipSuffix")]})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-3",children:[s.jsx("div",{className:"flex min-w-0 flex-col shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.opencodeCli.field.binaryPath")})}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:w-[20rem]",children:[s.jsx(Bt,{value:e,onChange:u=>n(u.target.value),placeholder:t("settings.vinci.opencodeCli.field.binaryPathPlaceholder"),disabled:r||a,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),s.jsx(ge,{type:"button",variant:"outline",size:"xs",onClick:p,disabled:r||a||!gn()||!pa(),className:"h-7 w-7 p-0","aria-label":t("settings.vinci.opencodeCli.actions.browseAria"),title:t("settings.vinci.opencodeCli.actions.browse"),children:s.jsx(P,{name:"folder",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"typography-micro text-muted-foreground/70",children:[t("settings.vinci.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.vinci.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/vinci/settings.json"}),"."]})}),s.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5",children:[s.jsx(ds,{checked:c,onChange:d,ariaLabel:t("settings.vinci.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.vinci.opencodeCli.field.showUpdateNotifications")})]}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(ge,{type:"button",size:"xs",onClick:m,disabled:r||a,className:"shrink-0 !font-normal",children:t(a?"settings.common.actions.saving":"settings.vinci.opencodeCli.actions.saveAndReload")})})]})]})},Pg=()=>{const{t}=ut(),e=gn()&&Bi(),[n,r]=Be.useState(!1),[i,a]=Be.useState(!1),[l,c]=Be.useState(!0),[d,p]=Be.useState(!1),[m,u]=Be.useState(null),[h,x]=Be.useState(null);Be.useEffect(()=>{if(!e){c(!1);return}let b=!1;return(async()=>{try{const k=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)throw new Error(t("settings.vinci.desktopNetwork.error.loadFailed"));const I=await k.json().catch(()=>null);if(b)return;const j=I?.desktopLanAccessEnabled===!0;r(j),a(j),u(null)}catch(k){b||u(k instanceof Error?k.message:t("settings.vinci.desktopNetwork.error.loadFailed"))}finally{b||c(!1)}})(),()=>{b=!0}},[e,t]),Be.useEffect(()=>{if(!e||!i){x(null);return}let b=!1;return(async()=>{const k=await oy();b||x(k)})(),()=>{b=!0}},[i,e]);const f=i!==n,v=Be.useMemo(()=>{if(typeof window>"u")return null;const b=Number(window.location.port);return Number.isFinite(b)&&b>0?b:null},[]),y=i&&h&&v?`http://${h}:${v}`:null,g=Be.useCallback(()=>{a(b=>!b)},[]),w=Be.useCallback(async()=>{if(f){p(!0),u(null);try{if(!(await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:i})})).ok)throw new Error(t("settings.vinci.desktopNetwork.error.saveFailed"));if(r(i),!await ih())throw new Error(t("settings.vinci.desktopNetwork.error.savedRestartFailed"))}catch(b){u(b instanceof Error?b.message:t("settings.vinci.desktopNetwork.error.saveFailed")),p(!1)}}},[i,f,t]);return e?s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.vinci.desktopNetwork.title")})}),s.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:g,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),g())},children:[s.jsx(ds,{checked:i,onChange:g,ariaLabel:t("settings.vinci.desktopNetwork.field.allowLanAccessAria"),disabled:l||d}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.vinci.desktopNetwork.field.allowLanAccess")}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.vinci.desktopNetwork.field.allowLanAccessDescription")}),s.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:t("settings.vinci.desktopNetwork.field.warning")})]})]}),m?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:m}):null,y?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(f&&!n?"settings.vinci.desktopNetwork.hint.openAfterRestart":"settings.vinci.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:y})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(ge,{type:"button",size:"xs",onClick:w,disabled:l||d||!f,className:"shrink-0 !font-normal",children:t(d?"settings.common.actions.saving":"settings.vinci.desktopNetwork.actions.saveAndRestart")})})]})]}):null},bC=new Set(["shift","control","alt","meta"]),yC=t=>{if(bC.has(t.key.toLowerCase()))return null;const e=[];(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt");const n=cy(t.key);return n?(e.push(n),sa(e.join("+"))):null},vC=()=>{const t=at.c(58),{t:e}=ut();let n;t[0]!==e?(n=oe=>e(oe),t[0]=e,t[1]=n):n=t[1];const r=n,i=Ie(wC),a=Ie(jC),l=Ie(NC),c=Ie(SC);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=ly(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(oe,F)=>{const U=`settings.vinci.keyboardShortcuts.action.${oe}.label`,W=r(U);return W===U?F:W},t[3]=r,t[4]=m):m=t[4];const u=m,[h,x]=o.useState(null);let f;t[5]===Symbol.for("react.memo_cache_sentinel")?(f={},t[5]=f):f=t[5];const[v,y]=o.useState(f),[g,w]=o.useState(""),[b,k]=o.useState(""),[I,j]=o.useState(null);let N;t[6]!==i?(N=(oe,F)=>{const U=sa(F);for(const W of p){if(W.id===oe)continue;const te=Zr(W.id,i);if(sa(te)===U)return W.id}return null},t[6]=i,t[7]=N):N=t[7];const D=N;let E;t[8]!==D||t[9]!==a||t[10]!==e?(E=(oe,F)=>{const U=sa(F),W=D(oe,U);if(W){j({actionId:oe,combo:U,conflictActionId:W}),w("");return}a(oe,U),j(null),w(""),k(Fu(U)?e("settings.vinci.keyboardShortcuts.warning.riskyBrowserShortcut"):""),y(te=>{const K={...te};return delete K[oe],K})},t[8]=D,t[9]=a,t[10]=e,t[11]=E):E=t[11];const T=E;let C;t[12]!==I||t[13]!==a||t[14]!==e?(C=()=>{I&&(a(I.conflictActionId,dy),a(I.actionId,I.combo),j(null),w(""),k(Fu(I.combo)?e("settings.vinci.keyboardShortcuts.warning.riskyBrowserShortcut"):""),y(oe=>{const F={...oe};return delete F[I.actionId],F}))},t[12]=I,t[13]=a,t[14]=e,t[15]=C):C=t[15];const S=C;let M;t[16]!==l?(M=oe=>{l(oe),y(F=>{const U={...F};return delete U[oe],U}),j(null),w(""),k("")},t[16]=l,t[17]=M):M=t[17];const A=M;let R;t[18]!==e?(R=e("settings.vinci.keyboardShortcuts.title"),t[18]=e,t[19]=R):R=t[19];let z;t[20]!==R?(z=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:R}),t[20]=R,t[21]=z):z=t[21];let B;t[22]!==c?(B=()=>{c(),y({}),j(null),w(""),k("")},t[22]=c,t[23]=B):B=t[23];let V;t[24]!==e?(V=e("settings.vinci.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=V):V=t[25];let $;t[26]!==B||t[27]!==V?($=s.jsx(ge,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:B,children:V}),t[26]=B,t[27]=V,t[28]=$):$=t[28];let _;t[29]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(It,{asChild:!0,children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=_):_=t[29];let X;t[30]!==e?(X=e("settings.vinci.keyboardShortcuts.tooltip"),t[30]=e,t[31]=X):X=t[31];let O;t[32]!==X?(O=s.jsxs(Pt,{children:[_,s.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:X})]}),t[32]=X,t[33]=O):O=t[33];let J;t[34]!==$||t[35]!==O||t[36]!==z?(J=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[z,$,O]})}),t[34]=$,t[35]=O,t[36]=z,t[37]=J):J=t[37];let Q;t[38]!==S||t[39]!==g||t[40]!==I||t[41]!==e||t[42]!==b?(Q=(g||b||I)&&s.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[I&&s.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-foreground",children:e("settings.vinci.keyboardShortcuts.overwritePrompt")}),s.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.jsx(ge,{type:"button",size:"xs",className:"!font-normal",onClick:S,children:e("settings.vinci.keyboardShortcuts.actions.overwrite")}),s.jsx(ge,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>j(null),children:e("settings.common.actions.cancel")})]})]}),g&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:g}),b&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:b})]}),t[38]=S,t[39]=g,t[40]=I,t[41]=e,t[42]=b,t[43]=Q):Q=t[43];let ne;t[44]!==u||t[45]!==h||t[46]!==v||t[47]!==A||t[48]!==T||t[49]!==i||t[50]!==e?(ne=p.map((oe,F)=>{const U=Zr(oe.id,i),W=v[oe.id],te=W??U,K=typeof W=="string"&&sa(W)!==sa(U);return s.jsxs("div",{className:ce("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",F>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:u(oe.id,oe.label)})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Bt,{readOnly:!0,value:h===oe.id?e("settings.vinci.keyboardShortcuts.field.pressKeys"):Rl(te),onFocus:()=>{x(oe.id),w("")},onBlur:()=>{h===oe.id&&x(null)},onKeyDown:ae=>{if(ae.preventDefault(),ae.stopPropagation(),ae.key==="Escape"){x(null);return}const ve=yC(ae);ve&&(y(re=>({...re,[oe.id]:ve})),x(null),j(null),w(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(ge,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const ae=v[oe.id];if(!ae){w(e("settings.vinci.keyboardShortcuts.error.captureFirst"));return}T(oe.id,ae)},disabled:!K,children:e("settings.common.actions.saveChanges")}),s.jsx(ge,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>A(oe.id),children:e("settings.common.actions.reset")})]})]},oe.id)}),t[44]=u,t[45]=h,t[46]=v,t[47]=A,t[48]=T,t[49]=i,t[50]=e,t[51]=ne):ne=t[51];let G;t[52]!==ne?(G=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:ne}),t[52]=ne,t[53]=G):G=t[53];let le;return t[54]!==J||t[55]!==Q||t[56]!==G?(le=s.jsxs("div",{className:"mb-8",children:[J,Q,G]}),t[54]=J,t[55]=Q,t[56]=G,t[57]=le):le=t[57],le};function wC(t){return t.shortcutOverrides}function jC(t){return t.setShortcutOverride}function NC(t){return t.clearShortcutOverride}function SC(t){return t.resetAllShortcutOverrides}const _p=[{key:"ELEVENLABS_API_KEY",value:""},{key:"KLIPY_APP_KEY",value:""},{key:"PEXELS_API_KEY",value:""},{key:"PIXABAY_API_KEY",value:""},{key:"FREESOUND_API_KEY",value:""},{key:"JAMENDO_CLIENT_ID",value:""}],Up=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Ig=()=>{const t=xt(k=>k.settingsKlipyAppKey),e=xt(k=>k.settingsElevenlabsApiKey),n=xt(k=>k.settingsExtraEnvVars),r=xt(k=>k.setSettingsKlipyAppKey),i=xt(k=>k.setSettingsElevenlabsApiKey),a=xt(k=>k.setSettingsExtraEnvVars),l=o.useCallback(()=>{const k=new Set(_p.map(N=>N.key)),I=n||{},j=_p.map(N=>({key:N.key,value:typeof I[N.key]=="string"?I[N.key]:""}));if(e){const N=j.findIndex(D=>D.key==="ELEVENLABS_API_KEY");N!==-1&&(j[N]={...j[N],value:e})}if(t){const N=j.findIndex(D=>D.key==="KLIPY_APP_KEY");N!==-1&&(j[N]={...j[N],value:t})}for(const[N,D]of Object.entries(I))k.has(N)||j.push({key:N,value:D});return j},[t,e,n]),[c,d]=o.useState([]),[p,m]=o.useState(new Set),[u,h]=o.useState(!1);o.useEffect(()=>{d(l())},[l]);const x=o.useMemo(()=>{const k=l();return k.length!==c.length?!0:k.some((I,j)=>I.key!==c[j]?.key||I.value!==c[j]?.value)},[c,l]),f=(k,I,j)=>{const N=[...c];N[k]={...N[k],[I]:j},d(N)},v=()=>d([...c,{key:"",value:""}]),y=k=>{d(c.filter((I,j)=>j!==k)),m(I=>{const j=new Set(I);return j.delete(k),j})},g=k=>{m(I=>{const j=new Set(I);return j.has(k)?j.delete(k):j.add(k),j})},w=async()=>{try{const k=await navigator.clipboard.readText(),I=[];for(const N of k.split(`
|
|
178
|
+
`)){const D=N.trim();if(!D||D.startsWith("#"))continue;const E=D.indexOf("=");if(E===-1)continue;const T=D.slice(0,E).trim();let C=D.slice(E+1).trim();(C.startsWith('"')&&C.endsWith('"')||C.startsWith("'")&&C.endsWith("'"))&&(C=C.slice(1,-1)),T&&I.push({key:Up(T),value:C})}if(I.length===0){H.error("No KEY=VALUE pairs found in clipboard");return}const j=[...c];for(const N of I){const D=j.findIndex(E=>E.key===N.key);D!==-1?j[D]=N:j.push(N)}d(j),H.success(`Imported ${I.length} environment variable(s)`)}catch{H.error("Failed to read clipboard")}},b=o.useCallback(async()=>{if(x){h(!0);try{const k={},I={};for(const j of c)j.key==="ELEVENLABS_API_KEY"?k.elevenlabsApiKey=j.value:j.key==="KLIPY_APP_KEY"?k.klipyAppKey=j.value:j.key&&j.value&&(I[j.key]=j.value);i(k.elevenlabsApiKey||""),r(k.klipyAppKey||""),a(I),await ks({elevenlabsApiKey:k.elevenlabsApiKey||"",klipyAppKey:k.klipyAppKey||"",extraEnvVars:I}),H.success("Environment variables updated. Restarting OpenCode server..."),await uy(),await Fi({message:"Applying environment variables and restarting background OpenCode server...",mode:"projects",scopes:["all"]})}catch(k){console.warn("Failed to apply environment variables:",k),H.error("Failed to update environment variables.")}finally{h(!1)}}},[c,x,r,i,a]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:"Environment Variables"})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70 leading-relaxed",children:"Configure environment variables for API keys and services used by agents and tools. Saving will automatically restart the background OpenCode server to load the new values."}),s.jsxs("div",{className:"typography-micro text-muted-foreground/50 leading-relaxed border border-warning/20 bg-warning/5 rounded-md px-3 py-2",children:[s.jsx("strong",{children:"Remote server?"})," Set these as environment variables on the remote machine instead."]}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-36 shrink-0",children:"Variable Name"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:"Value"})]}),s.jsxs(ge,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:w,type:"button",title:"Paste KEY=VALUE lines from clipboard",children:[s.jsx(P,{name:"clipboard",className:"h-3 w-3"}),"Paste .env"]})]}),s.jsx("div",{className:"space-y-1.5",children:c.map((k,I)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:k.key,onChange:j=>f(I,"key",Up(j.target.value)),placeholder:"API_KEY",className:"w-36 shrink-0 font-mono typography-meta uppercase","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Bt,{type:p.has(I)?"text":"password",value:k.value,onChange:j=>f(I,"value",j.target.value),placeholder:"Enter value",className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>g(I),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:p.has(I)?"Hide value":"Show value",children:p.has(I)?s.jsx(P,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(ge,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>y(I),"aria-label":"Remove variable",children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},I))}),s.jsxs(ge,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:v,type:"button",children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),"Add Variable"]}),s.jsx("div",{className:"flex justify-start pt-2",children:s.jsx(ge,{type:"button",size:"xs",onClick:b,disabled:u||!x,className:"shrink-0 !font-normal",children:u?"Saving & Applying...":"Save & Apply"})})]})]})},kC=t=>{const e=at.c(20),{section:n}=t,{isMobile:r}=rn();let i;e[0]!==r?(i=r&&Li(),e[0]=r,e[1]=i):i=e[1];const a=i;let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=mn(),e[2]=l):l=e[2];const c=l;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=gn()&&Bi(),e[3]=d):d=e[3];const p=d;if(!n){let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(tu,{}),e[4]=f):f=e[4];let v,y,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Sg,{})}),y=!c&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Cg,{})}),s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})})]}),g=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Pg,{})}),e[5]=v,e[6]=y,e[7]=g):(v=e[5],y=e[6],g=e[7]);let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(jg,{})}),e[8]=w):w=e[8];let b;e[9]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})}),e[9]=b):b=e[9];let k;e[10]!==a?(k=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(H5,{})}),e[10]=a,e[11]=k):k=e[11];let I;return e[12]!==k?(I=s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"vinci-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[f,v,y,g,w,b,k]})}),e[12]=k,e[13]=I):I=e[13],I}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(PC,{});case"chat":return s.jsx(IC,{});case"sessions":return s.jsx(AC,{});case"shortcuts":return s.jsx(CC,{});case"git":return s.jsx(DC,{});case"github":return s.jsx(TC,{});case"notifications":return s.jsx(MC,{});case"voice":return s.jsx(EC,{});case"tunnel":return s.jsx(RC,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const u=m;let h;e[16]!==u?(h=u(),e[16]=u,e[17]=h):h=e[17];let x;return e[18]!==h?(x=s.jsx(Cs,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"vinci-page-body mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",children:h})}),e[18]=h,e[19]=x):x=e[19],x},CC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(vC,{}),t[0]=e):e=t[0],e},PC=()=>{const t=at.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=mn(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(tu,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},IC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(tu,{visibleSettings:["chatRenderMode","messageTransport","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","expandedTools","stickyUserHeader","wideChatLayout","splitAssistantMessageActions","diffLayout","mobileStatusBar","dotfiles","queueMode","persistDraft","inputSpellcheck"]}),t[0]=e):e=t[0],e},AC=()=>{const t=at.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=mn(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=gn()&&Bi(),t[1]=r):r=t[1];const i=r;let a,l,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(Sg,{}),l=!n&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Cg,{})}),s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})})]}),c=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Pg,{})}),t[2]=a,t[3]=l,t[4]=c):(a=t[2],l=t[3],c=t[4]);let d;t[5]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(jg,{})}),t[5]=d):d=t[5];let p;return t[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs("div",{className:"space-y-6",children:[a,l,c,d,s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})})]}),t[6]=p):p=t[6],p},DC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(bg,{})}),t[0]=e):e=t[0],e},TC=()=>{const t=at.c(1);if(mn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(yg,{}),t[0]=e):e=t[0],e},MC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(rC,{}),t[0]=e):e=t[0],e},EC=()=>{const t=at.c(1);if(mn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(lC,{}),t[0]=e):e=t[0],e},RC=()=>{const t=at.c(1);if(mn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(xC,{}),t[0]=e):e=t[0],e},wd=176,jd=280,Wp=8;function Lc(t){return Math.min(jd,Math.max(wd,t))}const FC=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","projects","remote-instances","agents","behavior","commands","mcp","providers","usage","skills.installed","skills.catalog","voice","tunnel"];function LC(t){const e=mn(),n=!t&&Li();return{isVSCode:e,isWeb:n,isDesktop:t}}function Kp(t,e){return t.isAvailable?t.isAvailable(e):!0}function su(t){switch(t){case"projects":return"folders";case"remote-instances":return"server";case"appearance":return"palette";case"chat":return"chat-ai-3";case"magic-prompts":return"ai-generate-2";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"chat-history";case"providers":return"cloud";case"agents":return"ai-agent";case"behavior":return"brain";case"commands":return"slash-commands-2";case"mcp":return"plug-2";case"skills.installed":return"book-open";case"skills.catalog":return"book";case"git":return"git-branch";case"usage":return"bar-chart-2";case"voice":return"mic";case"tunnel":return"global";case"home":return null;default:return"robot-2"}}const Oc=t=>{const e=at.c(95),{onOpen:n}=t,{t:r}=ut();let i;e[0]!==r?(i=r("settings.view.home.title"),e[0]=r,e[1]=i):i=e[1];let a;e[2]!==i?(a=s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:i}),e[2]=i,e[3]=a):a=e[3];let l;e[4]!==r?(l=r("settings.view.home.description"),e[4]=r,e[5]=l):l=e[5];let c;e[6]!==l?(c=s.jsx("p",{className:"typography-ui text-muted-foreground",children:l}),e[6]=l,e[7]=c):c=e[7];let d;e[8]!==a||e[9]!==c?(d=s.jsxs("div",{className:"space-y-1",children:[a,c]}),e[8]=a,e[9]=c,e[10]=d):d=e[10];let p;e[11]!==n?(p=()=>n("providers"),e[11]=n,e[12]=p):p=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=m):m=e[13];let u;e[14]!==r?(u=r("settings.view.home.cards.providers.title"),e[14]=r,e[15]=u):u=e[15];let h;e[16]!==u?(h=s.jsx("div",{className:"typography-ui-label text-foreground",children:u}),e[16]=u,e[17]=h):h=e[17];let x;e[18]!==r?(x=r("settings.view.home.cards.providers.description"),e[18]=r,e[19]=x):x=e[19];let f;e[20]!==x?(f=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:x}),e[20]=x,e[21]=f):f=e[21];let v;e[22]!==f||e[23]!==p||e[24]!==h?(v=s.jsxs("button",{type:"button",onClick:p,className:m,children:[h,f]}),e[22]=f,e[23]=p,e[24]=h,e[25]=v):v=e[25];let y;e[26]!==n?(y=()=>n("agents"),e[26]=n,e[27]=y):y=e[27];let g;e[28]===Symbol.for("react.memo_cache_sentinel")?(g=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=g):g=e[28];let w;e[29]!==r?(w=r("settings.view.home.cards.agents.title"),e[29]=r,e[30]=w):w=e[30];let b;e[31]!==w?(b=s.jsx("div",{className:"typography-ui-label text-foreground",children:w}),e[31]=w,e[32]=b):b=e[32];let k;e[33]!==r?(k=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=k):k=e[34];let I;e[35]!==k?(I=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:k}),e[35]=k,e[36]=I):I=e[36];let j;e[37]!==y||e[38]!==b||e[39]!==I?(j=s.jsxs("button",{type:"button",onClick:y,className:g,children:[b,I]}),e[37]=y,e[38]=b,e[39]=I,e[40]=j):j=e[40];let N;e[41]!==n?(N=()=>n("skills.catalog"),e[41]=n,e[42]=N):N=e[42];let D;e[43]===Symbol.for("react.memo_cache_sentinel")?(D=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=D):D=e[43];let E;e[44]!==r?(E=r("settings.view.home.cards.skillsCatalog.title"),e[44]=r,e[45]=E):E=e[45];let T;e[46]!==E?(T=s.jsx("div",{className:"typography-ui-label text-foreground",children:E}),e[46]=E,e[47]=T):T=e[47];let C;e[48]!==r?(C=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=C):C=e[49];let S;e[50]!==C?(S=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:C}),e[50]=C,e[51]=S):S=e[51];let M;e[52]!==N||e[53]!==T||e[54]!==S?(M=s.jsxs("button",{type:"button",onClick:N,className:D,children:[T,S]}),e[52]=N,e[53]=T,e[54]=S,e[55]=M):M=e[55];let A;e[56]!==n?(A=()=>n("mcp"),e[56]=n,e[57]=A):A=e[57];let R;e[58]===Symbol.for("react.memo_cache_sentinel")?(R=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=R):R=e[58];let z;e[59]!==r?(z=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=z):z=e[60];let B;e[61]!==z?(B=s.jsx("div",{className:"typography-ui-label text-foreground",children:z}),e[61]=z,e[62]=B):B=e[62];let V;e[63]!==r?(V=r("settings.view.home.cards.mcp.description"),e[63]=r,e[64]=V):V=e[64];let $;e[65]!==V?($=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:V}),e[65]=V,e[66]=$):$=e[66];let _;e[67]!==A||e[68]!==B||e[69]!==$?(_=s.jsxs("button",{type:"button",onClick:A,className:R,children:[B,$]}),e[67]=A,e[68]=B,e[69]=$,e[70]=_):_=e[70];let X;e[71]!==n?(X=()=>n("usage"),e[71]=n,e[72]=X):X=e[72];let O;e[73]===Symbol.for("react.memo_cache_sentinel")?(O=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=O):O=e[73];let J;e[74]!==r?(J=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=J):J=e[75];let Q;e[76]!==J?(Q=s.jsx("div",{className:"typography-ui-label text-foreground",children:J}),e[76]=J,e[77]=Q):Q=e[77];let ne;e[78]!==r?(ne=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=ne):ne=e[79];let G;e[80]!==ne?(G=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ne}),e[80]=ne,e[81]=G):G=e[81];let le;e[82]!==X||e[83]!==Q||e[84]!==G?(le=s.jsxs("button",{type:"button",onClick:X,className:O,children:[Q,G]}),e[82]=X,e[83]=Q,e[84]=G,e[85]=le):le=e[85];let oe;e[86]!==v||e[87]!==j||e[88]!==M||e[89]!==_||e[90]!==le?(oe=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[v,j,M,_,le]}),e[86]=v,e[87]=j,e[88]=M,e[89]=_,e[90]=le,e[91]=oe):oe=e[91];let F;return e[92]!==oe||e[93]!==d?(F=s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl px-6 py-6 space-y-6",children:[d,oe]})}),e[92]=oe,e[93]=d,e[94]=F):F=e[94],F},OC=t=>{const e=at.c(104),{onClose:n,forceMobile:r,isWindowed:i}=t,{t:a}=ut(),l=rn(),c=r??l.isMobile,d=Ie($C),p=Ie(BC),m=Ie(zC);let u;e[0]!==d?(u=lg(d),e[0]=d,e[1]=u):u=e[1];const h=u,[x,f]=o.useState("nav"),v=o.useRef(null),[y,g]=o.useState(216),[w,b]=o.useState(!1),[k,I]=o.useState(!1),j=o.useRef(0),N=o.useRef(y),D=o.useRef(null);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=gn(),e[2]=E):E=e[2];const T=E;let C;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=LC(T),e[3]=C):C=e[3];const S=C;let M;if(e[4]!==c){let Pe;e[6]===Symbol.for("react.memo_cache_sentinel")?(Pe=L=>Kp(L,S),e[6]=Pe):Pe=e[6];let fe;e[7]===Symbol.for("react.memo_cache_sentinel")?(fe=L=>!(S.isVSCode&&L.slug==="projects"),e[7]=fe):fe=e[7],M=Xd.filter(VC).filter(Pe).filter(fe).filter(L=>!(c&&L.slug==="shortcuts")),e[4]=c,e[5]=M}else M=e[5];const A=M;let R;e[8]===Symbol.for("react.memo_cache_sentinel")?(R=new Map(FC.map(_C)),e[8]=R):R=e[8];const z=R;let B;if(e[9]!==A){let Pe;e[11]===Symbol.for("react.memo_cache_sentinel")?(Pe=(fe,L)=>(z.get(fe.slug)??999)-(z.get(L.slug)??999),e[11]=Pe):Pe=e[11],B=A.slice().sort(Pe),e[9]=A,e[10]=B}else B=e[10];const V=B,$=As(UC);let _,X;e[12]!==w?(_=()=>{if(typeof window>"u")return;const Pe=()=>{if(!w){const fe=Lc(Math.floor(window.innerWidth*.12));g(fe)}};return window.addEventListener("resize",Pe),()=>window.removeEventListener("resize",Pe)},X=[w],e[12]=w,e[13]=_,e[14]=X):(_=e[13],X=e[14]),o.useEffect(_,X);let O,J;e[15]!==k?(J=()=>{if(!k)return;const Pe=L=>{const Z=L.clientX-j.current,Y=Lc(N.current+Z);g(Y),b(!0)},fe=()=>I(!1);return window.addEventListener("pointermove",Pe),window.addEventListener("pointerup",fe,{once:!0}),()=>{window.removeEventListener("pointermove",Pe),window.removeEventListener("pointerup",fe)}},O=[k],e[15]=k,e[16]=O,e[17]=J):(O=e[16],J=e[17]),o.useEffect(J,O);let Q;e[18]!==y?(Q=Pe=>{I(!0),j.current=Pe.clientX,N.current=y,Pe.preventDefault()},e[18]=y,e[19]=Q):Q=e[19];const ne=Q;let G;e[20]!==y?(G=Pe=>{const fe=Pe.shiftKey?Wp*4:Wp;let L;e:switch(Pe.key){case"ArrowLeft":{L=y-fe;break e}case"ArrowRight":{L=y+fe;break e}case"Home":{L=wd;break e}case"End":{L=jd;break e}default:return}Pe.preventDefault(),g(Lc(L)),b(!0)},e[20]=y,e[21]=G):G=e[21];const le=G;let oe;e[22]!==p||e[23]!==i||e[24]!==h?(oe=()=>{if(!(!p&&!S.isVSCode&&!i)){if(h==="agents"){fa.getState().loadAgents();return}if(h==="commands"){Bd.getState().loadCommands();return}if(h==="mcp"){lo.getState().loadMcpConfigs();return}(h==="skills.installed"||h==="skills.catalog")&&(fi.getState().loadSkills(),Ri.getState().loadCatalog())}},e[22]=p,e[23]=i,e[24]=h,e[25]=oe):oe=e[25];let F;e[26]!==$||e[27]!==p||e[28]!==i||e[29]!==h?(F=[$,p,i,S.isVSCode,h],e[26]=$,e[27]=p,e[28]=i,e[29]=h,e[30]=F):F=e[30],o.useEffect(oe,F);let U;e[31]!==c||e[32]!==m?(U=Pe=>{if(m(Pe),v.current=Pe,!c)return;const fe=_a(Pe);if(!fe||fe.slug==="home"){f("nav");return}f(fe.kind==="split"?"page-sidebar":"page-content")},e[31]=c,e[32]=m,e[33]=U):U=e[33];const W=U;let te;e[34]!==h?(te=_a(h),e[34]=h,e[35]=te):te=e[35];const K=te;let ae;e[36]===Symbol.for("react.memo_cache_sentinel")?(ae={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[36]=ae):ae=e[36];const ve=ae;let re;e[37]!==a?(re=Pe=>{switch(Pe){case"projects":return a("settings.page.projects.title");case"remote-instances":return a("settings.page.remoteInstances.title");case"providers":return a("settings.page.providers.title");case"usage":return a("settings.page.usage.title");case"agents":return a("settings.page.agents.title");case"behavior":return a("settings.page.behavior.title");case"commands":return a("settings.page.commands.title");case"mcp":return a("settings.page.mcp.title");case"skills.installed":return a("settings.page.skills.title");case"skills.catalog":return a("settings.page.skillsCatalog.title");case"git":return a("settings.page.git.title");case"appearance":return a("settings.page.appearance.title");case"chat":return a("settings.page.chat.title");case"shortcuts":return a("settings.page.shortcuts.title");case"sessions":return a("settings.page.sessions.title");case"magic-prompts":return a("settings.page.magicPrompts.title");case"notifications":return a("settings.page.notifications.title");case"voice":return a("settings.page.voice.title");case"tunnel":return a("settings.page.tunnel.title");default:return a("settings.view.home.title")}},e[37]=a,e[38]=re):re=e[38];const be=re;let pe;e[39]!==a?(pe=()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:a("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:a("settings.view.unavailable.description")})]})}),e[39]=a,e[40]=pe):pe=e[40];const ye=pe,ie=WC;let ue;e[41]!==W||e[42]!==ye?(ue=Pe=>{const fe=_a(Pe);if(fe&&!Kp(fe,S))return ye();switch(Pe){case"home":return s.jsx(Oc,{onOpen:W});case"projects":return s.jsx(k3,{});case"remote-instances":return s.jsx(J3,{});case"agents":return s.jsx(JS,{});case"behavior":return s.jsx(sk,{});case"commands":return s.jsx(uk,{});case"mcp":return s.jsx(Bk,{});case"skills.installed":return s.jsx(bp,{view:"installed"});case"skills.catalog":return s.jsx(bp,{view:"catalog"});case"providers":return s.jsx(i5,{});case"usage":return s.jsx(N5,{});case"magic-prompts":return s.jsx(I5,{});case"git":return s.jsx(E5,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const L=ve[Pe]??"visual";return s.jsx(kC,{section:L})}default:return s.jsx(Oc,{onOpen:W})}},e[41]=W,e[42]=ye,e[43]=ue):ue=e[43];const se=ue;let Ne,Ce;e[44]!==c||e[45]!==x||e[46]!==h?(Ne=()=>{if(!c||x!=="nav"||h==="home"||v.current===h)return;const Pe=_a(h);!Pe||Pe.slug==="home"||(v.current=h,f(Pe.kind==="split"?"page-sidebar":"page-content"))},Ce=[c,x,h],e[44]=c,e[45]=x,e[46]=h,e[47]=Ne,e[48]=Ce):(Ne=e[47],Ce=e[48]),o.useEffect(Ne,Ce);const je=c&&x!=="nav";let we,ke,xe,me,Me,Ue,q;if(e[49]!==K||e[50]!==be||e[51]!==c||e[52]!==i||e[53]!==x||e[54]!==n||e[55]!==W||e[56]!==se||e[57]!==h||e[58]!==je||e[59]!==V||e[60]!==a){const Pe=hl();let fe;e[68]===Symbol.for("react.memo_cache_sentinel")?(fe=()=>{f("nav")},e[68]=fe):fe=e[68];const L=fe;let Z;e[69]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>{f("page-sidebar")},e[69]=Z):Z=e[69];const Y=Z;let Ee;e[70]!==be||e[71]!==W||e[72]!==h||e[73]!==V||e[74]!==a?(Ee=()=>s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 pt-4 pb-2 px-2",children:V.map(de=>{const ze=h===de.slug,rt=su(de.slug);return rt?s.jsx(Pt,{children:s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>W(de.slug),"aria-current":ze?"page":void 0,className:ce("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",ze?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(P,{name:rt,className:"h-4 w-4 shrink-0"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:be(de.slug)}),(de.slug==="voice"||de.slug==="tunnel")&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:a("settings.view.badge.beta")})]})]})})},de.slug):null})})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-sidebar px-2 py-1 space-y-0.5",children:!S.isVSCode&&s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",className:ce("flex h-7 w-full items-center gap-2 rounded-md px-2 overflow-hidden whitespace-nowrap","text-sm font-semibold text-sidebar-foreground/90","hover:text-sidebar-foreground hover:bg-interactive-hover"),onClick:KC,children:[s.jsx(P,{name:"restart",className:"h-4 w-4 shrink-0"}),s.jsx("span",{children:a("settings.view.actions.reloadOpenCode")})]})}),s.jsx(Dt,{children:a("settings.view.actions.reloadOpenCodeTooltip")})]})})})]}),e[70]=be,e[71]=W,e[72]=h,e[73]=V,e[74]=a,e[75]=Ee):Ee=e[75],xe=Ee;let Ae;e[76]!==K||e[77]!==x||e[78]!==se||e[79]!==xe||e[80]!==h?(Ae=()=>{if(x==="nav")return s.jsx("div",{className:ce("flex-1 min-h-0 overflow-hidden",S.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(Xs,{children:xe()})})});if(!K)return s.jsx("div",{className:"flex-1 bg-background"});if(x==="page-sidebar"){if(K.kind!=="split"){const ze=se(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:ze})})}return s.jsx("div",{className:ce("flex-1 min-h-0 overflow-hidden",S.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(Xs,{children:ie(h,{onItemSelect:()=>f("page-content")})})})}const de=se(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:de})})},e[76]=K,e[77]=x,e[78]=se,e[79]=xe,e[80]=h,e[81]=Ae):Ae=e[81],ke=Ae;let Je;e[82]!==K||e[83]!==W||e[84]!==se||e[85]!==h?(Je=()=>!K||h==="home"?s.jsx(Oc,{onOpen:W}):K.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ce("w-[264px] min-w-[264px] border-r",S.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(Xs,{children:ie(h,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:se(h)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:se(h)})}),e[82]=K,e[83]=W,e[84]=se,e[85]=h,e[86]=Je):Je=e[86],we=Je,me=D,Me="true",e[87]===Symbol.for("react.memo_cache_sentinel")?(Ue=ce("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[87]=Ue):Ue=e[87],q=c?s.jsxs("div",{className:ce("flex items-center gap-2 px-3 py-2 border-b","bg-background"),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("button",{type:"button",onClick:je?L:n,"aria-label":a(je?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(P,{name:"arrow-left-s",className:"h-5 w-5"})}),s.jsx("div",{className:"min-w-0 flex-1 typography-ui-label font-medium text-foreground truncate",children:x==="nav"?a("settings.view.home.title"):K?be(K.slug):a("settings.view.home.title")}),x==="page-content"&&K?.kind==="split"&&s.jsx("button",{type:"button",onClick:Y,"aria-label":a("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(P,{name:"list-unordered",className:"h-5 w-5"})}),n&&s.jsx("button",{type:"button",onClick:n,"aria-label":a("settings.view.actions.closeSettings"),title:a("settings.view.actions.closeSettingsWithShortcut",{shortcut:Pe}),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(P,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[je&&s.jsx("div",{className:ce("absolute left-3 z-50",i?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:L,"aria-label":a("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(P,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&s.jsx("div",{className:ce("absolute right-0.5 z-50",i?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:n,"aria-label":a("settings.view.actions.closeSettings"),title:a("settings.view.actions.closeSettingsWithShortcut",{shortcut:Pe}),className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(P,{name:"close",className:"h-5 w-5"})})})]}),e[49]=K,e[50]=be,e[51]=c,e[52]=i,e[53]=x,e[54]=n,e[55]=W,e[56]=se,e[57]=h,e[58]=je,e[59]=V,e[60]=a,e[61]=we,e[62]=ke,e[63]=xe,e[64]=me,e[65]=Me,e[66]=Ue,e[67]=q}else we=e[61],ke=e[62],xe=e[63],me=e[64],Me=e[65],Ue=e[66],q=e[67];let Se;e[88]!==ne||e[89]!==le||e[90]!==c||e[91]!==k||e[92]!==y||e[93]!==we||e[94]!==ke||e[95]!==xe||e[96]!==a?(Se=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?ke():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:ce("relative flex h-full min-h-0 flex-col overflow-hidden border-r",T?"bg-sidebar":S.isVSCode?"bg-background":"bg-sidebar",k?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${y}px`,minWidth:`${y}px`,borderColor:"var(--interactive-border)"},children:[s.jsx("div",{className:ce("absolute right-0 top-0 z-20 h-full w-[6px] -mr-[3px] cursor-col-resize","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",k?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:ne,onKeyDown:le,role:"separator","aria-orientation":"vertical","aria-valuemin":wd,"aria-valuemax":jd,"aria-valuenow":y,"aria-label":a("settings.view.actions.resizeNavigation")}),s.jsx(Xs,{children:xe()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:we()})]})}),e[88]=ne,e[89]=le,e[90]=c,e[91]=k,e[92]=y,e[93]=we,e[94]=ke,e[95]=xe,e[96]=a,e[97]=Se):Se=e[97];let $e;return e[98]!==me||e[99]!==Me||e[100]!==Ue||e[101]!==q||e[102]!==Se?($e=s.jsxs("div",{ref:me,"data-settings-view":Me,className:Ue,children:[q,Se]}),e[98]=me,e[99]=Me,e[100]=Ue,e[101]=q,e[102]=Se,e[103]=$e):$e=e[103],$e};function $C(t){return t.settingsPage}function BC(t){return t.isSettingsDialogOpen}function zC(t){return t.setSettingsPage}function VC(t){return t.slug!=="home"}function _C(t,e){return[t,e]}function UC(t){return t.activeProjectId}function WC(t,e){switch(t){case"projects":return s.jsx(g3,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx($3,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(WS,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(nk,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(mk,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(zk,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(e5,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(o5,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(k5,{onItemSelect:e.onItemSelect});default:return null}}function KC(){Fi({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const HC=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:OC,getSettingsNavIcon:su},Symbol.toStringTag,{value:"Module"})),Nd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const i=r==="/",a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,"")),r},GC=()=>{const t=at.c(162),{t:e}=ut(),n=Ie(qC),r=Ie(YC),i=Ie(QC),a=Ie(JC),l=Ie(XC),c=Ie(ZC),d=Ie(e4),p=Ie(t4),m=Ie(s4),u=Ie(n4),h=Ie(r4),x=Ie(i4),f=Ot(a4),v=Ot(o4),y=Ei(l4),g=$s(c4),w=As(d4),b=Ir(),k=Bl(u4),{files:I,git:j}=Pn(),N=tn(m4),{isMobile:D}=rn();let E;t[0]!==b?(E=b?Nd(b):null,t[0]=b,t[1]=E):E=t[1];const T=E,[C,S]=o.useState(""),M=ho(C,200);let A;t[2]!==M?(A=M.trim(),t[2]=M,t[3]=A):A=t[3];const R=A;let z;t[4]!==C?(z=C.trim(),t[4]=C,t[5]=z):z=t[5];const B=z;let V,$;t[6]!==n?(V=()=>{n&&S("")},$=[n],t[6]=n,t[7]=V,t[8]=$):(V=t[7],$=t[8]),o.useEffect(V,$);let _,X;t[9]!==y||t[10]!==N||t[11]!==j||t[12]!==n?(_=()=>{if(!n||!j)return;const Ye=setTimeout(()=>{const _e=new Set;for(const et of y){const gt=Ha(et);!gt||_e.has(gt)||(_e.add(gt),N(gt,j))}},0);return()=>clearTimeout(Ye)},X=[n,y,j,N],t[9]=y,t[10]=N,t[11]=j,t[12]=n,t[13]=_,t[14]=X):(_=t[13],X=t[14]),o.useEffect(_,X);let O;t[15]!==r?(O=()=>r(!1),t[15]=r,t[16]=O):O=t[16];const J=O;let Q;t[17]!==J?(Q=Ye=>()=>{J(),Ye()},t[17]=J,t[18]=Q):Q=t[18];const ne=Q;let G;t[19]!==w?.id||t[20]!==w?.path||t[21]!==g||t[22]!==D||t[23]!==u||t[24]!==f||t[25]!==ne||t[26]!==i||t[27]!==c||t[28]!==a||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(G=()=>{const Ye=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(P,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:ne(()=>{i("chat"),c(!1),f()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(P,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:ne(p4)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(P,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:ne(f4)},{id:"toggle-sidebar",title:e(D?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(P,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(D?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:ne(()=>{if(D){const{isSessionSwitcherOpen:_e}=Ie.getState();c(!_e)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(P,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:ne(()=>p())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(P,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:ne(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(P,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:ne(()=>{g&&u(g)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(P,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:ne(()=>a(!0))}];return Dd()&&Ye.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(P,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:ne(()=>{ml("desktop_open_draft_mini_chat_window",{directory:Nd(g||w?.path||""),projectId:w?.id??null}).catch(h4)})}),Ye},t[19]=w?.id,t[20]=w?.path,t[21]=g,t[22]=D,t[23]=u,t[24]=f,t[25]=ne,t[26]=i,t[27]=c,t[28]=a,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=G):G=t[33],w?.id,w?.path;let le;t[34]!==G?(le=G(),t[34]=G,t[35]=le):le=t[35];const oe=le;let F;t[36]===Symbol.for("react.memo_cache_sentinel")?(F=gn(),t[36]=F):F=t[36];const U=F;let W;t[37]===Symbol.for("react.memo_cache_sentinel")?(W={isVSCode:mn(),isWeb:!U&&Li(),isDesktop:U},t[37]=W):W=t[37];const te=W;let K;if(t[38]!==ne||t[39]!==a||t[40]!==l){let Ye;t[42]===Symbol.for("react.memo_cache_sentinel")?(Ye=_e=>_e.isAvailable?_e.isAvailable(te):!0,t[42]=Ye):Ye=t[42],K=Xd.filter(g4).filter(Ye).map(_e=>{const et=su(_e.slug)??"settings-3",gt=(_e.keywords??[]).join(" ");return{id:`settings:${_e.slug}`,title:_e.title,icon:s.jsx(P,{name:et,className:"mr-2 h-4 w-4"}),searchText:`${_e.title} ${_e.group} ${gt}`,onSelect:ne(()=>{l(_e.slug),a(!0)})}}),t[38]=ne,t[39]=a,t[40]=l,t[41]=K}else K=t[41];const ae=K,ve=x4;let re;if(t[43]!==y){let Ye;t[45]===Symbol.for("react.memo_cache_sentinel")?(Ye=(_e,et)=>ve(et)-ve(_e),t[45]=Ye):Ye=t[45],re=[...y].sort(Ye),t[43]=y,t[44]=re}else re=t[44];const be=re,pe=ah(),ye=Ot(b4);let ie;t[46]!==pe||t[47]!==ye?(ie=(Ye,_e)=>{const et=ye.get(Ye);return et?.branch?et.branch.trim()||null:_e&&pe.get(_e)?.trim()||null},t[46]=pe,t[47]=ye,t[48]=ie):ie=t[48];const ue=ie;let se;t[49]===Symbol.for("react.memo_cache_sentinel")?(se=[],t[49]=se):se=t[49];const[Ne,Ce]=o.useState(se),[je,we]=o.useState(!1);let ke,xe;t[50]!==T||t[51]!==n||t[52]!==k||t[53]!==R?(ke=()=>{if(!n){Ce([]),we(!1);return}if(!T||R.length===0){Ce([]),we(!1);return}let Ye=!1;return we(!0),k(T,R,10,{type:"file"}).then(_e=>{Ye||Ce(_e.map(y4))}).catch(()=>{Ye||Ce([])}).finally(()=>{Ye||we(!1)}),()=>{Ye=!0}},xe=[n,T,R,k],t[50]=T,t[51]=n,t[52]=k,t[53]=R,t[54]=ke,t[55]=xe):(ke=t[54],xe=t[55]),o.useEffect(ke,xe);const me=B.length>0;let Me;e:{if(!me){let _e;t[56]!==oe?(_e=oe.map(v4),t[56]=oe,t[57]=_e):_e=t[57],Me=_e;break e}let Ye;t[58]!==oe||t[59]!==B?(Ye=Po(oe,B,w4,{limit:7,noFuzzy:!0}),t[58]=oe,t[59]=B,t[60]=Ye):Ye=t[60],Me=Ye}const Ue=Me;let q;e:{if(!me){let _e;t[61]===Symbol.for("react.memo_cache_sentinel")?(_e=[],t[61]=_e):_e=t[61],q=_e;break e}let Ye;t[62]!==B||t[63]!==ae?(Ye=Po(ae,B,j4,{limit:7,noFuzzy:!0}),t[62]=B,t[63]=ae,t[64]=Ye):Ye=t[64],q=Ye}const Se=q;let $e;e:{if(!me){let _e;t[65]!==be?(_e=be.slice(0,5).map(N4),t[65]=be,t[66]=_e):_e=t[66],$e=_e;break e}let Ye;t[67]!==B||t[68]!==be?(Ye=Po(be,B,S4,{limit:7,threshold:.2}),t[67]=B,t[68]=be,t[69]=Ye):Ye=t[69],$e=Ye}const Pe=$e;let fe;e:{if(!me||Ne.length===0){let _e;t[70]===Symbol.for("react.memo_cache_sentinel")?(_e=[],t[70]=_e):_e=t[70],fe=_e;break e}let Ye;t[71]!==Ne||t[72]!==B?(Ye=Po(Ne,B,k4,{limit:10,threshold:.4}),t[71]=Ne,t[72]=B,t[73]=Ye):Ye=t[73],fe=Ye}const L=fe;let Z,Y,Ee,Ae,Je,de,ze,rt,Re,Xe,qe,Te,We,Ze,Qe;if(t[74]!==ue||t[75]!==J||t[76]!==T||t[77]!==I||t[78]!==me||t[79]!==n||t[80]!==h||t[81]!==C||t[82]!==Ue||t[83]!==L||t[84]!==Pe||t[85]!==Se||t[86]!==r||t[87]!==v||t[88]!==x||t[89]!==e){const Ye=Ue.map(C4),_e=Se.map(P4),et=Pe.map(I4);Qe=me?L.map(A4):[];let gt;e:{if(!me){gt=["commands","sessions"];break e}const Wt=D4,He=[{key:"commands",score:Wt(Ue)},{key:"settings",score:Wt(Se)},{key:"sessions",score:Wt(Pe)},{key:"files",score:Wt(L)}];He.sort(T4),gt=He.map(M4)}const Lt=gt;let Ut;t[105]!==J||t[106]!==v?(Ut=Wt=>{J(),v(Wt.id,Ha(Wt))},t[105]=J,t[106]=v,t[107]=Ut):Ut=t[107];const mt=Ut;let Nt;t[108]!==J||t[109]!==T||t[110]!==I||t[111]!==h?(Nt=async Wt=>{if(!T)return;const He=await Qd(I,Wt);if(!He.ok){H.error(Jd(He.reason));return}h(T,Wt),J()},t[108]=J,t[109]=T,t[110]=I,t[111]=h,t[112]=Nt):Nt=t[112];const Xt=Nt;let _t;t[113]!==x?(_t=Wt=>Rl(Zr(Wt,x)),t[113]=x,t[114]=_t):_t=t[114];const Gt=_t;Ae=hs,Te=n,We=r;let lt;t[115]!==e?(lt=e("commandPalette.title"),t[115]=e,t[116]=lt):lt=t[116];let Tt;t[117]!==lt?(Tt=s.jsx(gs,{children:lt}),t[117]=lt,t[118]=Tt):Tt=t[118];let rs;t[119]!==e?(rs=e("commandPalette.description"),t[119]=e,t[120]=rs):rs=t[120];let js;t[121]!==rs?(js=s.jsx(Is,{children:rs}),t[121]=rs,t[122]=js):js=t[122],t[123]!==Tt||t[124]!==js?(Ze=s.jsxs(bs,{className:"sr-only",children:[Tt,js]}),t[123]=Tt,t[124]=js,t[125]=Ze):Ze=t[125],Ee=fs,Xe="overflow-hidden p-0",qe=!0,Y=_i,ze=!1,rt="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let ys;t[126]!==e?(ys=e("commandPalette.input.placeholder"),t[126]=e,t[127]=ys):ys=t[127],t[128]!==C||t[129]!==ys?(Re=s.jsx(xi,{value:C,onValueChange:S,placeholder:ys}),t[128]=C,t[129]=ys,t[130]=Re):Re=t[130],Z=Ui;let vs;t[131]!==e?(vs=e("commandPalette.empty.noResults"),t[131]=e,t[132]=vs):vs=t[132],t[133]!==vs?(Je=s.jsx(Wi,{children:vs}),t[133]=vs,t[134]=Je):Je=t[134],de=Lt.map(Wt=>Wt==="commands"&&Ye.length>0?s.jsx(zn,{children:Ye.map(He=>s.jsxs(kn,{value:He.id,onSelect:He.onSelect,children:[He.icon,s.jsx("span",{children:He.title}),He.shortcutId?s.jsx(F1,{children:Gt(He.shortcutId)}):null]},He.id))},"commands"):Wt==="settings"&&_e.length>0?s.jsx(zn,{children:_e.map(E4)},"settings"):Wt==="sessions"&&et.length>0?s.jsx(zn,{children:et.map(He=>{const kt=He.title||e("commandPalette.session.untitled"),Kt=Ha(He),wt=ue(He.id,Kt);return s.jsxs(kn,{value:`session:${He.id}`,onSelect:()=>mt(He),children:[s.jsx(P,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:kt}),wt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:wt})]}):null]},He.id)})},"sessions"):Wt==="files"&&Qe.length>0?s.jsx(zn,{children:Qe.map(He=>{const kt=my(He.relativePath||He.name,{maxLength:80});return s.jsxs(kn,{value:`file:${He.path}`,onSelect:()=>{Xt(He.path)},children:[s.jsx(Zn,{filePath:He.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":He.relativePath,children:kt})]},`file:${He.path}`)})},"files"):null),t[74]=ue,t[75]=J,t[76]=T,t[77]=I,t[78]=me,t[79]=n,t[80]=h,t[81]=C,t[82]=Ue,t[83]=L,t[84]=Pe,t[85]=Se,t[86]=r,t[87]=v,t[88]=x,t[89]=e,t[90]=Z,t[91]=Y,t[92]=Ee,t[93]=Ae,t[94]=Je,t[95]=de,t[96]=ze,t[97]=rt,t[98]=Re,t[99]=Xe,t[100]=qe,t[101]=Te,t[102]=We,t[103]=Ze,t[104]=Qe}else Z=t[90],Y=t[91],Ee=t[92],Ae=t[93],Je=t[94],de=t[95],ze=t[96],rt=t[97],Re=t[98],Xe=t[99],qe=t[100],Te=t[101],We=t[102],Ze=t[103],Qe=t[104];let he;t[135]!==me||t[136]!==je||t[137]!==e||t[138]!==Qe?(he=me&&je&&Qe.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=me,t[136]=je,t[137]=e,t[138]=Qe,t[139]=he):he=t[139];let Ge;t[140]!==Z||t[141]!==Je||t[142]!==de||t[143]!==he?(Ge=s.jsxs(Z,{children:[Je,de,he]}),t[140]=Z,t[141]=Je,t[142]=de,t[143]=he,t[144]=Ge):Ge=t[144];let Ve;t[145]!==Y||t[146]!==ze||t[147]!==rt||t[148]!==Re||t[149]!==Ge?(Ve=s.jsxs(Y,{shouldFilter:ze,className:rt,children:[Re,Ge]}),t[145]=Y,t[146]=ze,t[147]=rt,t[148]=Re,t[149]=Ge,t[150]=Ve):Ve=t[150];let it;t[151]!==Ee||t[152]!==Xe||t[153]!==qe||t[154]!==Ve?(it=s.jsx(Ee,{className:Xe,showCloseButton:qe,children:Ve}),t[151]=Ee,t[152]=Xe,t[153]=qe,t[154]=Ve,t[155]=it):it=t[155];let dt;return t[156]!==Ae||t[157]!==Te||t[158]!==We||t[159]!==Ze||t[160]!==it?(dt=s.jsxs(Ae,{open:Te,onOpenChange:We,children:[Ze,it]}),t[156]=Ae,t[157]=Te,t[158]=We,t[159]=Ze,t[160]=it,t[161]=dt):dt=t[161],dt};function qC(t){return t.isCommandPaletteOpen}function YC(t){return t.setCommandPaletteOpen}function QC(t){return t.setActiveMainTab}function JC(t){return t.setSettingsDialogOpen}function XC(t){return t.setSettingsPage}function ZC(t){return t.setSessionSwitcherOpen}function e4(t){return t.toggleSidebar}function t4(t){return t.toggleRightSidebar}function s4(t){return t.toggleBottomTerminal}function n4(t){return t.openContextOverview}function r4(t){return t.openContextFile}function i4(t){return t.shortcutOverrides}function a4(t){return t.openNewSessionDraft}function o4(t){return t.setCurrentSession}function l4(t){return t.activeSessions}function c4(t){return t.currentDirectory}function d4(t){return t.getActiveProject()}function u4(t){return t.searchFiles}function m4(t){return t.ensureStatus}function p4(){oh()}function f4(){Sr.requestDirectoryDialog()}function h4(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function g4(t){return t.slug!=="home"}function x4(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function b4(t){return t.worktreeMetadata}function y4(t){return{path:Nd(t.path),name:t.name,relativePath:t.relativePath}}function v4(t){return{item:t,score:0}}function w4(t){return t.searchText}function j4(t){return t.searchText}function N4(t){return{item:t,score:0}}function S4(t){return t.title||""}function k4(t){return t.name}function C4(t){return t.item}function P4(t){return t.item}function I4(t){return t.item}function A4(t){return t.item}function D4(t){return t.length?t[0].score:1/0}function T4(t,e){return t.score-e.score}function M4(t){return t.key}function E4(t){return s.jsxs(kn,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Hp=(t,e,n)=>fy(t)?Rl(Zr(t,n)):e,R4=()=>{const t=at.c(68),{t:e}=ut(),n=Ie(F4),r=Ie(L4),i=Ie(O4);let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=py(),t[0]=a):a=t[0];const l=a;let c,d,p,m,u,h,x,f,v;if(t[1]!==n||t[2]!==r||t[3]!==i||t[4]!==e){const R=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${l} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${l} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];d=hs,f=n,v=r,c=fs,h="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let z;t[14]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(P,{name:"settings-3",className:"h-5 w-5"}),t[14]=z):z=t[14];let B;t[15]!==e?(B=e("helpDialog.title"),t[15]=e,t[16]=B):B=t[16];let V;t[17]!==B?(V=s.jsxs(gs,{className:"flex items-center gap-2",children:[z,B]}),t[17]=B,t[18]=V):V=t[18];let $;t[19]!==e?($=e("helpDialog.description"),t[19]=e,t[20]=$):$=t[20];let _;t[21]!==$?(_=s.jsx(Is,{children:$}),t[21]=$,t[22]=_):_=t[22],t[23]!==V||t[24]!==_?(x=s.jsxs(bs,{children:[V,_]}),t[23]=V,t[24]=_,t[25]=x):x=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",p="space-y-4",m=R.map(X=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(X.categoryKey)}),s.jsx("div",{className:"space-y-1",children:X.items.map(O=>{const J=O.id?Hp(O.id,Array.isArray(O.keys)?O.keys[0]:O.keys,i):Array.isArray(O.keys)?O.keys:O.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[O.icon&&s.jsx(P,{name:O.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(O.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(J)?J:[J]).map((Q,ne)=>s.jsxs(o.Fragment,{children:[ne>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:Q})]},`${Q}-${ne}`))})]},O.id||O.descriptionKey)})})]},X.categoryKey)),t[1]=n,t[2]=r,t[3]=i,t[4]=e,t[5]=c,t[6]=d,t[7]=p,t[8]=m,t[9]=u,t[10]=h,t[11]=x,t[12]=f,t[13]=v}else c=t[5],d=t[6],p=t[7],m=t[8],u=t[9],h=t[10],x=t[11],f=t[12],v=t[13];let y;t[26]!==p||t[27]!==m?(y=s.jsx("div",{className:p,children:m}),t[26]=p,t[27]=m,t[28]=y):y=t[28];let g;t[29]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(P,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=g):g=t[29];let w;t[30]!==e?(w=e("helpDialog.proTips.title"),t[30]=e,t[31]=w):w=t[31];let b;t[32]!==w?(b=s.jsx("p",{className:"font-medium mb-1",children:w}),t[32]=w,t[33]=b):b=t[33];let k;t[34]!==i||t[35]!==e?(k=e("helpDialog.proTips.commandPalette",{shortcut:Hp("open_command_palette",`${l} P`,i)}),t[34]=i,t[35]=e,t[36]=k):k=t[36];let I;t[37]!==k?(I=s.jsxs("li",{children:["• ",k]}),t[37]=k,t[38]=I):I=t[38];let j;t[39]!==e?(j=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=j):j=t[40];let N;t[41]!==j?(N=s.jsxs("li",{children:["• ",j]}),t[41]=j,t[42]=N):N=t[42];let D;t[43]!==e?(D=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=D):D=t[44];let E;t[45]!==D?(E=s.jsxs("li",{children:["• ",D]}),t[45]=D,t[46]=E):E=t[46];let T;t[47]!==I||t[48]!==N||t[49]!==E?(T=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[I,N,E]}),t[47]=I,t[48]=N,t[49]=E,t[50]=T):T=t[50];let C;t[51]!==b||t[52]!==T?(C=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[g,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[b,T]})]})}),t[51]=b,t[52]=T,t[53]=C):C=t[53];let S;t[54]!==C||t[55]!==u||t[56]!==y?(S=s.jsxs("div",{className:u,children:[y,C]}),t[54]=C,t[55]=u,t[56]=y,t[57]=S):S=t[57];let M;t[58]!==c||t[59]!==S||t[60]!==h||t[61]!==x?(M=s.jsxs(c,{className:h,children:[x,S]}),t[58]=c,t[59]=S,t[60]=h,t[61]=x,t[62]=M):M=t[62];let A;return t[63]!==d||t[64]!==M||t[65]!==f||t[66]!==v?(A=s.jsx(d,{open:f,onOpenChange:v,children:M}),t[63]=d,t[64]=M,t[65]=f,t[66]=v,t[67]=A):A=t[67],A};function F4(t){return t.isHelpDialogOpen}function L4(t){return t.setHelpDialogOpen}function O4(t){return t.shortcutOverrides}const $4=()=>{const t=at.c(32),{t:e}=ut(),n=Ie(B4),r=Ie(z4),i=Ie(V4);let a;t[0]!==i||t[1]!==e?(a=async()=>{if(!i)return;if((await _n(i)).ok){H.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}H.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=i,t[1]=e,t[2]=a):a=t[2];const l=a;let c;t[3]!==e?(c=e("openCodeStatusDialog.title"),t[3]=e,t[4]=c):c=t[4];let d;t[5]!==c?(d=s.jsx(gs,{children:c}),t[5]=c,t[6]=d):d=t[6];let p;t[7]!==e?(p=e("openCodeStatusDialog.description"),t[7]=e,t[8]=p):p=t[8];let m;t[9]!==p?(m=s.jsx(Is,{children:p}),t[9]=p,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(bs,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let h;t[14]!==e?(h=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=h):h=t[15];let x;t[16]!==l||t[17]!==h?(x=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:l,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:h})}),t[16]=l,t[17]=h,t[18]=x):x=t[18];let f;t[19]!==i||t[20]!==e?(f=i||e("openCodeStatusDialog.empty.noData"),t[19]=i,t[20]=e,t[21]=f):f=t[21];let v;t[22]!==f?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:f}),t[22]=f,t[23]=v):v=t[23];let y;t[24]!==u||t[25]!==x||t[26]!==v?(y=s.jsxs(fs,{className:"max-w-2xl",children:[u,x,v]}),t[24]=u,t[25]=x,t[26]=v,t[27]=y):y=t[27];let g;return t[28]!==n||t[29]!==r||t[30]!==y?(g=s.jsx(hs,{open:n,onOpenChange:r,children:y}),t[28]=n,t[29]=r,t[30]=y,t[31]=g):g=t[31],g};function B4(t){return t.isOpenCodeStatusDialogOpen}function z4(t){return t.setOpenCodeStatusDialogOpen}function V4(t){return t.openCodeStatusText}const _4=180,Gp=600,U4=1,W4=6,K4=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const i=o.useRef(new Map),a=o.useRef([]),l=o.useRef(new Set),c=o.useCallback(()=>{if(!(typeof window>"u"))for(;l.current.size<U4&&a.current.length>0;){const p=a.current.shift();if(!p)break;Ot.getState().currentSessionId!==p&&(Lu(p).renderable||(l.current.add(p),r(p).catch(()=>{}).finally(()=>{l.current.delete(p),c()})))}},[r]),d=o.useCallback(p=>{if(!p||p===t||typeof window>"u"||Lu(p).renderable||l.current.has(p)||a.current.includes(p))return;a.current.length>=W4&&a.current.shift();const m=i.current.get(p);m!==void 0&&window.clearTimeout(m);const u=window.setTimeout(()=>{i.current.delete(p),a.current.push(p),c()},_4);i.current.set(p,u)},[t,c]);o.useEffect(()=>{if(!t||e.length===0)return;const p=window.setTimeout(()=>{const m=e.findIndex(u=>u.id===t);m<0||(d(e[m-1]?.id),d(e[m+1]?.id))},Gp);return()=>window.clearTimeout(p)},[t,d,e]),o.useEffect(()=>{if(!t||n.length===0)return;const p=window.setTimeout(()=>{const m=n.indexOf(t);m<0||(d(n[m-1]),d(n[m+1]))},Gp);return()=>window.clearTimeout(p)},[t,n,d]),o.useEffect(()=>{const p=i.current;return()=>{p.forEach(m=>{clearTimeout(m)}),p.clear(),a.current=[]}},[])};function qp(t){const{localBranches:e,remoteBranches:n,query:r}=t,i=r.trim();if(!i)return{matching:[],otherLocal:e,otherRemote:n};const a=Ou(e,i,m=>m),l=Ou(n,i,m=>m),c=[],d=a.other,p=l.other;for(const m of a.matching)c.push({label:m,value:m,source:"local"});for(const m of l.matching)c.push({label:m,value:`remotes/${m}`,source:"remote"});return c.sort((m,u)=>{const h=m.label.localeCompare(u.label,void 0,{sensitivity:"accent"});return h!==0?h:m.source!==u.source?m.source.localeCompare(u.source):m.value.localeCompare(u.value)}),{matching:c,otherLocal:d,otherRemote:p}}function H4({open:t,onOpenChange:e,onSelect:n}){const{t:r}=ut(),i=Ie(pe=>pe.isMobile),{github:a}=Pn(),l=Hn(pe=>pe.status),c=Hn(pe=>pe.hasChecked),d=Ie(pe=>pe.setSettingsDialogOpen),p=Ie(pe=>pe.setSettingsPage),m=As(pe=>pe.getActiveProject()),u=m?.path??null,h=Be.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[x,f]=Be.useState("issues"),[v,y]=Be.useState(""),[g,w]=Be.useState([]),[b,k]=Be.useState([]),[I,j]=Be.useState(!1),[N,D]=Be.useState(!1),[E,T]=Be.useState(null),[C,S]=Be.useState(null),[M,A]=Be.useState(null),[R,z]=Be.useState(!1),[B,V]=Be.useState(new Map),[$,_]=Be.useState(1),[X,O]=Be.useState(!1),J=Be.useCallback(async()=>{if(!(!u||!a)&&!(c&&l?.connected===!1)){j(!0),T(null),_(1),O(!1);try{if(x==="issues"&&a.issuesList){const pe=await a.issuesList(u,{page:1});pe.connected===!1?(T(r("session.githubIntegration.error.notConnected")),w([])):(w(pe.issues??[]),_(pe.page??1),O(!!pe.hasMore))}else if(x==="prs"&&a.prsList){const pe=await a.prsList(u,{page:1});pe.connected===!1?(T(r("session.githubIntegration.error.notConnected")),k([])):(k(pe.prs??[]),_(pe.page??1),O(!!pe.hasMore))}}catch(pe){T(pe instanceof Error?pe.message:r("session.githubIntegration.error.loadDataFailed"))}finally{j(!1)}}},[u,a,c,l,x,r]),Q=Be.useCallback(async()=>{if(!(!u||!a)&&!(I||N)&&X){D(!0);try{const pe=$+1;if(x==="issues"&&a.issuesList){const ye=await a.issuesList(u,{page:pe});ye.connected!==!1&&(w(ie=>[...ie,...ye.issues??[]]),_(ye.page??pe),O(!!ye.hasMore))}else if(x==="prs"&&a.prsList){const ye=await a.prsList(u,{page:pe});ye.connected!==!1&&(k(ie=>[...ie,...ye.prs??[]]),_(ye.page??pe),O(!!ye.hasMore))}}catch{}finally{D(!1)}}},[u,a,x,$,X,I,N]);Be.useEffect(()=>{if(!t){f("issues"),y(""),w([]),k([]),S(null),A(null),z(!1),T(null),V(new Map),_(1),O(!1);return}J()},[t,J]);const ne=Be.useCallback(async pe=>{if(!(!h||!pe)&&!B.has(pe))try{const ie=(await lh(h,{mode:"new",branchName:pe,worktreeName:pe})).errors.find(ue=>ue.code==="branch_in_use");V(ue=>new Map(ue).set(pe,{isValid:!ie,error:ie?r(ie.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{V(ye=>new Map(ye).set(pe,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[h,B,r]);Be.useEffect(()=>{!t||x!=="prs"||b.forEach(pe=>{pe.head&&ne(pe.head)})},[t,x,b,ne]);const G=Be.useMemo(()=>{const pe=v.trim().toLowerCase();return pe?g.filter(ye=>String(ye.number)===pe.replace(/^#/,"")?!0:ye.title.toLowerCase().includes(pe)):g},[g,v]),le=Be.useMemo(()=>{const pe=v.trim().toLowerCase();return pe?b.filter(ye=>String(ye.number)===pe.replace(/^#/,"")?!0:ye.title.toLowerCase().includes(pe)):b},[b,v]),oe=c&&l?.connected===!0,F=()=>{p("github"),d(!0)},U=pe=>{S(pe),A(null)},W=pe=>{A(pe),S(null)},te=()=>{C?n({type:"issue",item:C}):M&&n({type:"pr",item:M,includeDiff:R}),e(!1)},K=()=>{S(null),A(null),z(!1)},ae=C||M&&B.get(M.head??"")?.isValid!==!1,ve=pe=>pe.head?B.get(pe.head)?.isValid===!1:!0,re=s.jsx(s.Fragment,{children:oe?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(P,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(Bt,{value:v,onChange:pe=>y(pe.target.value),placeholder:r(x==="issues"?"session.githubIntegration.search.issuesPlaceholder":"session.githubIntegration.search.prsPlaceholder"),className:"h-8 pl-9"})]}),s.jsx("div",{className:"mt-2 h-[300px] overflow-hidden",children:s.jsxs("div",{className:"h-full overflow-y-auto",children:[I&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(P,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),E&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[s.jsx(P,{name:"error-warning",className:"h-4 w-4"}),s.jsx("span",{className:"typography-small",children:E})]})}),!I&&!E&&x==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[G.length>0?G.map(pe=>s.jsx("button",{onClick:()=>U(pe),className:ce("w-full text-left px-2 py-1.5 rounded transition-colors",C?.number===pe.number?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",pe.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:pe.title}),pe.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block",children:[pe.sourceRepo.owner,"/",pe.sourceRepo.repo]}):null]})]})},`${pe.sourceRepo?.owner??""}-${pe.sourceRepo?.repo??""}-${pe.number}`)):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noIssuesFound")}),X&&!N&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{Q()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),N&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!I&&!E&&x==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[le.length>0?le.map(pe=>{const ye=ve(pe),ie=pe.head?B.get(pe.head):void 0;return s.jsx("button",{onClick:()=>!ye&&W(pe),disabled:ye,className:ce("w-full text-left px-2 py-1.5 rounded transition-colors",M?.number===pe.number?"bg-interactive-selection text-interactive-selection-foreground":ye?"opacity-50 cursor-not-allowed":"hover:bg-interactive-hover"),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",pe.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:pe.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[pe.head," → ",pe.base]}),pe.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[pe.sourceRepo.owner,"/",pe.sourceRepo.repo]}):null,ye&&ie?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:ie.error})]})]})]})},`${pe.sourceRepo?.owner??""}-${pe.sourceRepo?.repo??""}-${pe.number}`)}):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noPullRequestsFound")}),X&&!N&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{Q()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),N&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]})]})})]}):s.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 gap-4",children:[s.jsx(P,{name:"github",className:"h-12 w-12 text-muted-foreground"}),s.jsxs("div",{className:"text-center",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:r("session.githubIntegration.connect.title")}),s.jsx("p",{className:"typography-small text-muted-foreground mt-1",children:r("session.githubIntegration.connect.description")})]}),s.jsx(ge,{onClick:F,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),be=s.jsxs("div",{className:ce("w-full",i?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:ce("flex items-center gap-4",i?"w-full justify-center order-1":"flex-1"),children:[!i&&(C||M)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(P,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate max-w-[150px]",children:C?r("session.githubIntegration.selected.issueNumber",{number:C.number}):r("session.githubIntegration.selected.prNumber",{number:M?.number??""})}),s.jsx("button",{onClick:K,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]}),x==="prs"&&M&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(ds,{checked:R,onChange:pe=>z(pe),ariaLabel:r("session.githubIntegration.includeDiffAria")}),s.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),s.jsxs("div",{className:ce("flex gap-2",i?"w-full order-2":"justify-end"),children:[s.jsx(ge,{variant:"outline",size:"sm",onClick:()=>e(!1),className:ce(i&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(ge,{size:"sm",onClick:te,disabled:!ae,className:ce(i&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:i?s.jsx($r,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:oe?be:void 0,renderHeader:pe=>s.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2 border-b border-border/40",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:r("session.githubIntegration.title")}),pe]}),s.jsx("div",{className:"w-full",children:s.jsx(Cr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(P,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(P,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:x,onSelect:ye=>{f(ye),y("")},variant:"active-pill",layoutMode:"fit"})}),(C||M)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(P,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:C?r("session.githubIntegration.selected.issueNumber",{number:C.number}):r("session.githubIntegration.selected.prNumber",{number:M?.number??""})}),s.jsx("button",{onClick:K,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:re}):s.jsx(hs,{open:t,onOpenChange:e,children:s.jsxs(fs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(bs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(gs,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(P,{name:"github",className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(Cr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(P,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(P,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:x,onSelect:pe=>{f(pe),y("")},variant:"active-pill",layoutMode:"fit"})})]})}),re,s.jsx(Vs,{className:"mt-1",children:be})]})})})}const Ua=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),$n=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,"").split("/").join("-").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"").slice(0,80),Yp="oc:lastWorktreeSourceBranch",G4=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",Qp=(t,e,n)=>{const r=Ua(t.head||"");if(!r)throw new Error("PR head branch is missing");if(e.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};const i=n.find(p=>{const m=p.indexOf("/");return m<=0||m>=p.length-1?!1:p.slice(m+1)===r});if(i){const p=i.indexOf("/"),m=i.slice(0,p);return{existingBranch:`remotes/${i}`,setUpstream:!0,upstreamRemote:m,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${m}/${r}`}}const a=String(t.headLabel||"").split(":")[0]?.trim(),l=t.headRepo?.owner||a||"pr-head",c=`pr-${G4(l)}`,d=t.headRepo?.sshUrl||t.headRepo?.cloneUrl||"";if(!d)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${c}/${r}`,setUpstream:!0,upstreamRemote:c,upstreamBranch:r,ensureRemoteName:c,ensureRemoteUrl:d,sourceLabel:`${c}/${r}`}},q4=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
|
|
179
|
+
${JSON.stringify(e,null,2)}`},Y4=t=>`GitHub pull request context (JSON)
|
|
180
|
+
${JSON.stringify(t,null,2)}`;function Q4({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=ut(),{github:i,git:a}=Pn(),l=Ie(de=>de.isMobile),c=Hn(de=>de.status),d=Hn(de=>de.hasChecked),p=As(de=>de.getActiveProject()),m=p?.path??null,u=Be.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[h,x]=Be.useState("new-branch"),[f,v]=Be.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[y,g]=Be.useState({selectedBranch:"",worktreeName:""}),w=Rd(m),b=ch(m),k=tn(de=>de.fetchBranches),I=Be.useMemo(()=>w?.all?w.all.filter(de=>!de.startsWith("remotes/")).sort():[],[w]),j=Be.useMemo(()=>w?.all?w.all.filter(de=>de.startsWith("remotes/")).map(de=>de.replace(/^remotes\//,"")).sort():[],[w]),N=Ot(de=>de.availableWorktreesByProject),D=Be.useMemo(()=>{if(!m)return new Set;const de=N.get(m)??[];return new Set(de.map(ze=>ze.name))},[N,m]),E=Be.useCallback((de=10)=>{for(let ze=0;ze<de;ze++){const rt=ac();if(!D.has(rt))return rt}return`${ac()}-${Date.now().toString(36).slice(-4)}`},[D]),[T,C]=Be.useState(!1),[S,M]=Be.useState(!1),[A,R]=Be.useState(!1),[z,B]=Be.useState(!1),[V,$]=Be.useState(!1),[_,X]=Be.useState(""),[O,J]=Be.useState(""),Q=Be.useRef(null),ne=Be.useRef(null),G=Be.useRef(null),le=Be.useRef(null),oe=Be.useCallback(de=>{de.stopPropagation()},[]),F=Be.useCallback(de=>{let ze=de;for(;ze&&ze!==document.body;){const{overflowY:rt}=window.getComputedStyle(ze);if((rt==="auto"||rt==="scroll")&&ze.scrollHeight>ze.clientHeight)return ze;ze=ze.parentElement}return null},[]),U=Be.useCallback(de=>{de&&(de.scrollTop=0)},[]),W=Be.useCallback(de=>{const ze=de.current?.querySelector('[data-slot="command-list"]')??null;U(ze)},[U]),te=Be.useCallback(de=>{const ze=F(de.current);U(ze)},[F,U]),K=Be.useMemo(()=>qp({localBranches:I,remoteBranches:j,query:_}),[I,j,_]),ae=Be.useMemo(()=>qp({localBranches:I,remoteBranches:j,query:O}),[I,j,O]),ve=_.trim().length>0,re=O.trim().length>0,be=K.matching.length>0,pe=ae.matching.length>0,ye=!!(m&&a),ie=Be.useCallback(()=>{!m||!a||k(m,a)},[m,a,k]);Be.useEffect(()=>{!S&&!z&&X("")},[S,z]),Be.useEffect(()=>{!A&&!V&&J("")},[A,V]),Be.useEffect(()=>{S&&W(Q),z&&te(G)},[S,z,_,W,te]),Be.useEffect(()=>{A&&W(ne),V&&te(le)},[A,V,O,W,te]);const[ue,se]=Be.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Ne,Ce]=Be.useState(!1),[je,we]=Be.useState(null),ke=Be.useCallback(()=>{const de=xt.getState(),ze=de.getVisibleAgents();if(de.settingsDefaultAgent){const rt=ze.find(Re=>Re.name===de.settingsDefaultAgent);if(rt)return rt.name}return ze.find(rt=>rt.name==="build")?.name||ze[0]?.name},[]),xe=Be.useCallback(()=>{const de=xt.getState(),ze=de.settingsDefaultModel;if(!ze)return null;const rt=ba(ze);if(!rt)return null;const{providerId:Re,modelId:Xe}=rt;return de.getModelMetadata(Re,Xe)?{providerID:Re,modelID:Xe}:null},[]),me=Be.useCallback((de,ze)=>{const rt=xt.getState(),Re=rt.settingsDefaultVariant;if(!Re)return;const Te=rt.providers.find(We=>We.id===de)?.models.find(We=>We.id===ze)?.variants;if(Te&&Object.prototype.hasOwnProperty.call(Te,Re))return Re},[]),Me=Be.useCallback(de=>{const ze=xt.getState();try{Io.getState().saveSessionModelSelection(de.sessionId,de.providerID,de.modelID)}catch{}if(de.agentName){try{ze.setAgent(de.agentName)}catch{}try{Io.getState().saveSessionAgentSelection(de.sessionId,de.agentName)}catch{}try{Io.getState().saveAgentModelForSession(de.sessionId,de.agentName,de.providerID,de.modelID)}catch{}if(de.variant!==void 0){try{ze.setCurrentVariant(de.variant)}catch{}try{Io.getState().saveAgentModelVariantForSession(de.sessionId,de.agentName,de.providerID,de.modelID,de.variant)}catch{}}}},[]),Ue=Be.useCallback(async de=>{if(!m||!i)return;const ze=xt.getState(),rt=Fl.getState().lastUsedProvider,Re=xe(),Xe=Re?.providerID||ze.currentProviderId||rt?.providerID,qe=Re?.modelID||ze.currentModelId||rt?.modelID,Te=ke()||ze.currentAgentName||void 0;if(!Xe||!qe){H.error(r("session.newWorktree.error.noModelSelected"));return}const We=me(Xe,qe);if(Me({sessionId:de.sessionId,providerID:Xe,modelID:qe,agentName:Te,variant:We}),de.issue){if(!i.issueGet||!i.issueComments)return;const Ze=await i.issueGet(m,de.issue.number);if(Ze.connected===!1||!Ze.repo||!Ze.issue)throw new Error("Failed to load issue context");const Qe=await i.issueComments(m,de.issue.number);if(Qe.connected===!1)throw new Error("Failed to load issue comments");const he=await wn("github.issue.review.visible",{issue_number:String(de.issue.number)}),Ge=await wn("github.issue.review.instructions"),Ve=q4({repo:Ze.repo,issue:Ze.issue,comments:Qe.comments??[]});await Zs.sendMessage({id:de.sessionId,providerID:Xe,modelID:qe,agent:Te,variant:We,text:he,additionalParts:[{text:Ge,synthetic:!0},{text:Ve,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(de.pr){if(!i.prContext)return;const Ze=await i.prContext(m,de.pr.number,{includeDiff:de.includeDiff,includeCheckDetails:!1});if(Ze.connected===!1||!Ze.repo||!Ze.pr)throw new Error("Failed to load PR context");const Qe=await wn("github.pr.review.visible",{pr_number:String(de.pr.number)}),he=await wn("github.pr.review.instructions"),Ge=Y4(Ze);await Zs.sendMessage({id:de.sessionId,providerID:Xe,modelID:qe,agent:Te,variant:We,text:Qe,additionalParts:[{text:he,synthetic:!0},{text:Ge,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromPr"))}},[Me,i,m,ke,xe,me,r]),q=h==="new-branch"?f:y;Be.useEffect(()=>{if(!w?.all||!m||f.sourceBranch)return;(async()=>{try{const ze=await fo(m).catch(()=>null),rt=localStorage.getItem(Yp),Re=rt&&w.all?.includes(rt)?rt:ze&&w.all?.includes(ze)?ze:w.all?.includes("main")?"main":w.all?.includes("master")?"master":w.all?.[0]||"";Re&&v(Xe=>({...Xe,sourceBranch:Re}))}catch{}})()},[w,m,f.sourceBranch]),Be.useEffect(()=>{if(!t)return;x("new-branch"),g({selectedBranch:"",worktreeName:""}),M(!1),R(!1),B(!1),$(!1),X(""),J(""),se({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const de=E();v({branchName:de,worktreeName:de,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,E]),Be.useEffect(()=>{if(h!=="new-branch"||!f.isSyncingWorktreeName)return;const de=Ua(f.branchName),ze=$n(de);v(rt=>({...rt,worktreeName:ze}))},[h,f.branchName,f.isSyncingWorktreeName]);const Se=Be.useCallback(async()=>{if(!u||!ue.touched||Ne)return;je&&je.abort();const de=new AbortController;we(de),se(ze=>({...ze,isValidating:!0}));try{const ze=h==="new-branch"?f.branchName:y.selectedBranch,rt=q.worktreeName,Re=Ua(ze),Xe=$n(rt);let qe=null,Te=null;if(Re||(qe=r("session.newWorktree.error.branchNameRequired")),Xe||(Te=r("session.newWorktree.error.worktreeDirectoryRequired")),Re&&Xe){const We=h==="new-branch"?f.linkedPr:null,Ze=We?Qp(We,I,j):null,Qe=await lh(u,{mode:h==="existing-branch"||Ze?"existing":"new",branchName:Re,worktreeName:Xe,existingBranch:Ze?.existingBranch??(h==="existing-branch"?Re:void 0),...Ze?.ensureRemoteName?{ensureRemoteName:Ze.ensureRemoteName}:{},...Ze?.ensureRemoteUrl?{ensureRemoteUrl:Ze.ensureRemoteUrl}:{}});if(de.signal.aborted)return;Qe.ok||Qe.errors.forEach(he=>{if(he.code==="worktree_exists"){Te=Te??he.message;return}he.code.startsWith("branch_")&&(qe=qe??he.message)})}de.signal.aborted||se(We=>({...We,isValidating:!1,branchError:qe,worktreeError:Te}))}catch{de.signal.aborted||se(ze=>({...ze,isValidating:!1}))}},[u,h,f.branchName,f.linkedPr,y.selectedBranch,q.worktreeName,I,j,ue.touched,je,Ne,r]),$e=h==="new-branch"?f.branchName:y.selectedBranch;Be.useEffect(()=>{if(!t||!u||!ue.touched||Ne)return;const de=setTimeout(()=>{Se()},300);return()=>clearTimeout(de)},[q.worktreeName,$e,t,u,Se,ue.touched,Ne]);const Pe=async()=>{if(!u||!m){H.error(r("session.newWorktree.error.noActiveProject"));return}se(Xe=>({...Xe,touched:!0}));const de=h==="new-branch"?f.branchName:y.selectedBranch,ze=q.worktreeName,rt=Ua(de),Re=$n(ze);if(!rt){H.error(r("session.newWorktree.error.branchNameRequired"));return}if(!Re){H.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}je&&(je.abort(),we(null)),se(Xe=>({...Xe,isValidating:!1,branchError:null,worktreeError:null})),Ce(!0);try{const Xe=await zd(u),qe=h==="new-branch"?f.linkedPr:null,Te=f.sourceBranch;let We="";const Ze=(()=>{if(qe){const Ye=Qp(qe,I,j);return We=Ye.sourceLabel,{preferredName:rt||Re,mode:"existing",branchName:rt,worktreeName:Re,existingBranch:Ye.existingBranch,setupCommands:Xe,setUpstream:Ye.setUpstream,upstreamRemote:Ye.upstreamRemote,upstreamBranch:Ye.upstreamBranch,...Ye.ensureRemoteName?{ensureRemoteName:Ye.ensureRemoteName}:{},...Ye.ensureRemoteUrl?{ensureRemoteUrl:Ye.ensureRemoteUrl}:{}}}return We=h==="new-branch"?Te:"",{preferredName:rt||Re,mode:h==="existing-branch"?"existing":"new",branchName:h==="existing-branch"?void 0:rt,worktreeName:Re,existingBranch:h==="existing-branch"?rt:void 0,setupCommands:Xe,...Te&&h==="new-branch"?{startRef:Te}:{}}})(),Qe=await hy(m,Ze),he=await gy(u,Qe),Ge=h==="new-branch"?f.linkedIssue:null,Ve=h==="new-branch"?f.linkedPr:null,it=h==="new-branch"?f.includePrDiff:!1;let dt=null;if(Ge||Ve){const Ye=Ge?`#${Ge.number} ${Ge.title}`.trim():Ve?`#${Ve.number} ${Ve.title}`.trim():r("session.newWorktree.newSessionTitle"),_e=await xy(Ye,he.path,null);if(!_e?.id)throw new Error("Failed to create session");dt=_e.id,by(_e.id,Ye).catch(()=>{});try{Ot.getState().initializeNewSession(_e.id,xt.getState().agents)}catch{}}f.sourceBranch&&h==="new-branch"&&!f.linkedPr&&localStorage.setItem(Yp,f.sourceBranch),H.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${he.branch||he.name}${We?` ${r("session.newWorktree.fromSource",{source:We})}`:""}`})}),e(!1),dt?(n?.(he.path,{sessionId:dt}),Ue({sessionId:dt,issue:Ge,pr:Ve,includeDiff:it}).catch(Ye=>{const _e=Ye instanceof Error?Ye.message:r("session.newWorktree.error.sendGitHubContextFailed");H.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:_e})})):n?.(he.path)}catch(Xe){const qe=Xe instanceof Error?Xe.message:r("session.newWorktree.error.createWorktreeFailed");H.error(r("session.newWorktree.error.createWorktreeFailed"),{description:qe})}finally{Ce(!1)}},fe=de=>{x(de),se(ze=>({...ze,touched:!1,branchError:null,worktreeError:null}))},L=de=>{if(!de){v(ze=>({...ze,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(de.type==="issue"){const ze=de.item,rt=`issue-${ze.number}-${ac()}`;v(Re=>({...Re,linkedIssue:ze,linkedPr:null,includePrDiff:!1,branchName:rt,worktreeName:$n(rt),isSyncingWorktreeName:!0}))}else if(de.type==="pr"){const ze=de.item;v(rt=>({...rt,linkedPr:ze,linkedIssue:null,includePrDiff:de.includeDiff??!1,branchName:ze.head,worktreeName:$n(ze.head),isSyncingWorktreeName:!0}))}},Z=d&&c?.connected===!0,Ee=(h==="existing-branch"?!!y.selectedBranch&&!!y.worktreeName&&!ue.branchError&&!ue.worktreeError:!!Ua(f.branchName)&&!!f.worktreeName&&!ue.branchError&&!ue.worktreeError)&&!Ne,Ae=()=>{v(de=>({...de,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Je=s.jsxs("div",{className:ce("flex gap-2",l?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:ce("flex items-center gap-1.5 text-destructive",l?"w-full justify-center order-first":"mr-auto"),children:ue.touched&&(ue.branchError||ue.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:ue.branchError||ue.worktreeError})]})}),s.jsxs("div",{className:ce("flex gap-2",l&&"w-full"),children:[s.jsx(ge,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Ne,className:ce(l&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(ge,{size:"sm",onClick:Pe,disabled:!Ee||Ne,className:ce("gap-1.5",l&&"flex-1"),children:[Ne&&s.jsx(P,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Ne?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[l?s.jsxs($r,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:Je,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Cr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(P,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(P,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:h,onSelect:de=>fe(de),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[h==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ge,{variant:"outline",size:"sm",onClick:()=>B(!0),className:"flex-1 justify-between h-9",children:[s.jsx("span",{className:y.selectedBranch?"text-foreground":"text-muted-foreground",children:y.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(P,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(ge,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ie,disabled:!ye||b,title:r("session.newWorktree.fetchBranches"),children:b?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"refresh",className:"size-4"})})]}),s.jsx($r,{open:z,title:r("session.newWorktree.selectBranch"),onClose:()=>B(!1),children:s.jsxs("div",{className:"space-y-4",ref:G,children:[s.jsx(Bt,{value:_,onChange:de=>X(de.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),b?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):I.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[ve&&be&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:K.matching.map(de=>s.jsx("button",{onClick:()=>{g(ze=>({...ze,selectedBranch:de.value,worktreeName:$n(de.label)})),se(ze=>({...ze,touched:!0})),B(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",y.selectedBranch===de.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de.label})},`${de.source}-${de.value}`))})]}),ve&&!be&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),K.otherLocal.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ve?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:K.otherLocal.map(de=>s.jsx("button",{onClick:()=>{g(ze=>({...ze,selectedBranch:de,worktreeName:$n(de)})),se(ze=>({...ze,touched:!0})),B(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",y.selectedBranch===de?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de})},de))})]}),K.otherRemote.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ve?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:K.otherRemote.map(de=>s.jsx("button",{onClick:()=>{g(ze=>({...ze,selectedBranch:`remotes/${de}`,worktreeName:$n(de)})),se(ze=>({...ze,touched:!0})),B(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",y.selectedBranch===`remotes/${de}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de})},`remotes/${de}`))})]})]})]})})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),h==="new-branch"&&Z&&s.jsxs(ge,{variant:"outline",size:"sm",onClick:()=>C(!0),className:"gap-1.5 h-7",children:[s.jsx(P,{name:"github",className:"size-4 text-status-success"}),f.linkedIssue||f.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Bt,{value:f.branchName,onChange:de=>{v(ze=>({...ze,branchName:de.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>se(de=>({...de,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!f.linkedPr,className:ce("h-8",ue.touched&&ue.branchError&&"border-destructive",f.linkedPr&&"bg-muted text-muted-foreground")}),f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(P,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:f.linkedPr.head})})]}),f.linkedIssue&&!f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(P,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:f.linkedIssue.number,title:f.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),h!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const de=$n(h==="new-branch"?f.branchName:"");v(ze=>({...ze,worktreeName:de,isSyncingWorktreeName:!0}))},disabled:!f.branchName||f.worktreeName===$n(f.branchName),className:ce("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",f.worktreeName===$n(f.branchName)||!f.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(P,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Bt,{value:q.worktreeName,onChange:de=>{h==="new-branch"?v(ze=>({...ze,worktreeName:de.target.value,isSyncingWorktreeName:!1})):g(ze=>({...ze,worktreeName:de.target.value}))},onBlur:()=>se(de=>({...de,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ce("h-8",ue.touched&&ue.worktreeError&&"border-destructive")})]}),h==="new-branch"&&!f.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(ge,{variant:"outline",size:"sm",onClick:()=>$(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:f.sourceBranch?"text-foreground":"text-muted-foreground",children:f.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(P,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),f.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:f.sourceBranch})}),s.jsx($r,{open:V,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>$(!1),children:s.jsxs("div",{className:"space-y-4",ref:le,children:[s.jsx(Bt,{value:O,onChange:de=>J(de.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),b?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):I.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[re&&pe&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:ae.matching.map(de=>s.jsx("button",{onClick:()=>{v(ze=>({...ze,sourceBranch:de.value})),$(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===de.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de.label})},`${de.source}-${de.value}`))})]}),re&&!pe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ae.otherLocal.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(re?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:ae.otherLocal.map(de=>s.jsx("button",{onClick:()=>{v(ze=>({...ze,sourceBranch:de})),$(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===de?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de})},de))})]}),ae.otherRemote.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(re?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:ae.otherRemote.map(de=>s.jsx("button",{onClick:()=>{v(ze=>({...ze,sourceBranch:`remotes/${de}`})),$(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===`remotes/${de}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de})},`remotes/${de}`))})]})]})]})})]}),(f.linkedIssue||f.linkedPr)&&h==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),f.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:f.linkedIssue.number})}),f.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:f.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:f.linkedIssue?.title||f.linkedPr?.title}),s.jsx("a",{href:f.linkedIssue?.url||f.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:de=>de.stopPropagation(),children:s.jsx(P,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Ae,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]}),f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[f.linkedPr.head," → ",f.linkedPr.base]}),f.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):s.jsx(hs,{open:t,onOpenChange:e,children:s.jsxs(fs,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(bs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(gs,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(P,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Cr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(P,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(P,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:h,onSelect:de=>fe(de),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[h==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(Fs,{open:S,onOpenChange:M,children:[s.jsx(Es,{asChild:!0,children:s.jsxs(ge,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ce("truncate",y.selectedBranch?"text-foreground":"text-muted-foreground"),children:y.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Rs,{align:"start",sideOffset:6,portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:Q,children:s.jsxs(_i,{shouldFilter:!1,children:[s.jsx(xi,{placeholder:r("session.newWorktree.searchBranches"),value:_,onValueChange:X,onKeyDown:oe}),s.jsx(Ui,{disableHorizontal:!0,children:b?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):I.length===0&&j.length===0?s.jsx(Wi,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ve&&be&&s.jsx(zn,{heading:r("session.newWorktree.matchingBranches"),children:K.matching.map(de=>s.jsx(kn,{value:de.value,onSelect:()=>{g(ze=>({...ze,selectedBranch:de.value,worktreeName:$n(de.label)})),se(ze=>({...ze,touched:!0})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de.label})},`${de.source}-${de.value}`))}),ve&&!be&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),K.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[ve&&s.jsx(Ti,{}),s.jsx(zn,{heading:r(ve?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:K.otherLocal.map(de=>s.jsx(kn,{value:de,onSelect:()=>{g(ze=>({...ze,selectedBranch:de,worktreeName:$n(de)})),se(ze=>({...ze,touched:!0})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de})},`local-${de}`))})]}),K.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(K.otherLocal.length>0||ve)&&s.jsx(Ti,{}),s.jsx(zn,{heading:r(ve?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:K.otherRemote.map(de=>s.jsx(kn,{value:`remotes/${de}`,onSelect:()=>{g(ze=>({...ze,selectedBranch:`remotes/${de}`,worktreeName:$n(de)})),se(ze=>({...ze,touched:!0})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de})},`remote-${de}`))})]})]})})]})})]}),s.jsx(ge,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ie,disabled:!ye||b,title:r("session.newWorktree.fetchBranches"),children:b?s.jsx(P,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(P,{name:"refresh",className:"size-4"})})]})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),h==="new-branch"&&Z&&s.jsxs(ge,{variant:"outline",size:"sm",onClick:()=>C(!0),className:"gap-1.5 h-7",children:[s.jsx(P,{name:"github",className:"size-4 text-status-success"}),f.linkedIssue||f.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Bt,{value:f.branchName,onChange:de=>{v(ze=>({...ze,branchName:de.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>se(de=>({...de,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!f.linkedPr,className:ce("h-8",ue.touched&&ue.branchError&&"border-destructive",f.linkedPr&&"bg-muted text-muted-foreground")}),f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(P,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:f.linkedPr.head})})]}),f.linkedIssue&&!f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(P,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:f.linkedIssue.number,title:f.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),h!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const de=$n(h==="new-branch"?f.branchName:"");v(ze=>({...ze,worktreeName:de,isSyncingWorktreeName:!0}))},disabled:!f.branchName||f.worktreeName===$n(f.branchName),className:ce("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",f.worktreeName===$n(f.branchName)||!f.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(P,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Bt,{value:q.worktreeName,onChange:de=>{h==="new-branch"?v(ze=>({...ze,worktreeName:de.target.value,isSyncingWorktreeName:!1})):g(ze=>({...ze,worktreeName:de.target.value}))},onBlur:()=>se(de=>({...de,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ce("h-8",ue.touched&&ue.worktreeError&&"border-destructive")})]}),h==="new-branch"&&!f.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(Fs,{open:A,onOpenChange:R,children:[s.jsx(Es,{asChild:!0,children:s.jsxs(ge,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ce("truncate",f.sourceBranch?"text-foreground":"text-muted-foreground"),children:f.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Rs,{align:"start",portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:ne,children:s.jsxs(_i,{shouldFilter:!1,children:[s.jsx(xi,{placeholder:r("session.newWorktree.searchBranches"),value:O,onValueChange:J,onKeyDown:oe}),s.jsx(Ui,{disableHorizontal:!0,children:b?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):I.length===0&&j.length===0?s.jsx(Wi,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[re&&pe&&s.jsx(zn,{heading:r("session.newWorktree.matchingBranches"),children:ae.matching.map(de=>s.jsx(kn,{value:de.value,onSelect:()=>{v(ze=>({...ze,sourceBranch:de.value})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de.label})},`${de.source}-${de.value}`))}),re&&!pe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ae.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[re&&s.jsx(Ti,{}),s.jsx(zn,{heading:r(re?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ae.otherLocal.map(de=>s.jsx(kn,{value:de,onSelect:()=>{v(ze=>({...ze,sourceBranch:de})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de})},`local-${de}`))})]}),ae.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(ae.otherLocal.length>0||re)&&s.jsx(Ti,{}),s.jsx(zn,{heading:r(re?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ae.otherRemote.map(de=>s.jsx(kn,{value:`remotes/${de}`,onSelect:()=>{v(ze=>({...ze,sourceBranch:`remotes/${de}`})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de})},`remote-${de}`))})]})]})})]})})]}),f.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:f.sourceBranch})})]}),(f.linkedIssue||f.linkedPr)&&h==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),f.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:f.linkedIssue.number})}),f.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:f.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:f.linkedIssue?.title||f.linkedPr?.title}),s.jsx("a",{href:f.linkedIssue?.url||f.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:de=>de.stopPropagation(),children:s.jsx(P,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Ae,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]}),f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[f.linkedPr.head," → ",f.linkedPr.base]}),f.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]}),s.jsxs(Vs,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:ue.touched&&(ue.branchError||ue.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:ue.branchError||ue.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Ne,children:r("session.newWorktree.actions.cancel")}),s.jsxs(ge,{size:"sm",onClick:Pe,disabled:!Ee||Ne,className:"gap-1.5",children:[Ne&&s.jsx(P,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Ne?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(H4,{open:T,onOpenChange:C,onSelect:L})]})}let da=null,ua=null,al=null,Cl=0;const $i=new Set,J4=3e4,X4=45e3,Ag=()=>{al&&(clearTimeout(al),al=null)},Dg=()=>{if(ua||$i.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(Cl,5)),J4);ua=setTimeout(()=>{ua=null,Cl+=1,Tg()},t)},Pl=()=>{Ag(),da&&da.close(),da=null},Jp=()=>{Ag(),$i.size!==0&&(al=setTimeout(()=>{Pl(),Dg()},X4))},Z4=t=>{if(!t||t.trim().length===0)return null;try{const e=JSON.parse(t),n=typeof e?.type=="string"?e.type:"",r=e?.properties;return n?{type:n,properties:r}:null}catch{return null}},eP=t=>{if(t.type==="vinci:event-stream-ready"){Cl=0;return}if(t.type==="vinci:heartbeat"||t.type!=="vinci:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",i=typeof e?.ranAt=="number"?e.ranAt:Date.now(),a=e?.status,l=a==="running"||a==="error"?a:"success";if(!n||!r)return;const c={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:i,status:l,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of $i)d(c)},Tg=()=>{if(typeof window>"u"||$i.size===0||typeof EventSource!="function"||da&&da.readyState!==EventSource.CLOSED)return;Pl();const t=new EventSource("/api/vinci/events");t.onopen=()=>{Jp()},t.onmessage=e=>{Jp();const n=Z4(e.data);n&&eP(n)},t.onerror=()=>{Pl(),Dg()},da=t},Mg=t=>($i.add(t),Tg(),()=>{$i.delete(t),$i.size===0&&(ua&&(clearTimeout(ua),ua=null),Cl=0,Pl())}),Kl=async(t,e)=>{try{const n=await t.json();if(n&&typeof n.error=="string"&&n.error.trim().length>0)return n.error}catch{return e}return e},ja=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},tP=async t=>{const e=ja(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Kl(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Xp=async(t,e)=>{const n=ja(t),r=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({task:e})});if(!r.ok)throw new Error(await Kl(r,"Failed to save scheduled task"));const i=await r.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},sP=async(t,e)=>{const n=ja(t),r=ja(e),i=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!i.ok)throw new Error(await Kl(i,"Failed to delete scheduled task"));const a=await i.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},nP=async(t,e)=>{const n=ja(t),r=ja(e),i=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!i.ok)throw new Error(await Kl(i,"Failed to run scheduled task"));const a=await i.json().catch(()=>null);return{sessionId:typeof a?.sessionId=="string"&&a.sessionId.length>0?a.sessionId:void 0}},Eg=[0,1,2,3,4,5,6],Zp=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?Intl.supportedValuesOf("timeZone"):["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],ef=()=>{const t=new Date,e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},ol=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),i=Number(e[3]),a=new Date(n,r-1,i);return Number.isNaN(a.getTime())||a.getFullYear()!==n||a.getMonth()!==r-1||a.getDate()!==i?null:a},tf=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},rP=(t,e,n)=>{const r=ol(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},sf=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),iP=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),l=(new Date(n,r,1).getDay()-e+7)%7,c=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),p=[];for(let m=0;m<42;m+=1){const u=m-l+1;if(u<=0){const h=d+u;p.push({date:new Date(n,r-1,h),inCurrentMonth:!1});continue}if(u>c){p.push({date:new Date(n,r+1,u-c),inCurrentMonth:!1});continue}p.push({date:new Date(n,r,u),inCurrentMonth:!0})}return p},aP=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],i=n>=12?"PM":"AM",a=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(a).padStart(2,"0"),minute:r,meridiem:i}},ki=(t,e,n)=>{const r=Number(t),i=Number(e),a=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,l=Number.isFinite(i)?Math.min(59,Math.max(0,i)):0;let c=a%12;return n==="PM"&&(c+=12),`${String(c).padStart(2,"0")}:${String(l).padStart(2,"0")}`},ka=(t,e)=>{const{max:n,min:r=0,loop:i=!1}=e;let a=Number.parseInt(t,10);return Number.isFinite(a)?(i?(a>n&&(a=r),a<r&&(a=n)):(a>n&&(a=n),a<r&&(a=r)),String(a).padStart(2,"0")):"00"},nf=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:ka(t,{min:1,max:12}),Vo=t=>/^[0-5][0-9]$/.test(t)?t:ka(t,{max:59}),oP=(t,e)=>ka(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),rf=(t,e)=>ka(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),lP=t=>{try{const e=Intl.Locale;if(typeof e!="function")return 1;const r=new e(t).weekInfo?.firstDay;return typeof r!="number"?1:r%7}catch{return 1}},cP=t=>{try{const e=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions();return typeof e.hour12=="boolean"?!e.hour12:e.hourCycle==="h23"||e.hourCycle==="h24"}catch{return!0}},dP=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Eg.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},uP=(t,e)=>[...t.slice(e),...t.slice(0,e)],jr=t=>{const e=at.c(6),{htmlFor:n,required:r,children:i}=t;let a;e[0]!==r?(a=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=a):a=e[1];let l;return e[2]!==i||e[3]!==n||e[4]!==a?(l=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,a]})}),e[2]=i,e[3]=n,e[4]=a,e[5]=l):l=e[5],l},af=t=>{const e=at.c(84),{value:n,onChange:r,use24Hour:i,hourAriaLabel:a,minuteAriaLabel:l,periodAriaLabel:c,amLabel:d,pmLabel:p}=t;let m;e[0]!==n?(m=aP(n),e[0]=n,e[1]=m):m=e[1];const u=m,h=Be.useRef(null),x=Be.useRef(null),[f,v]=Be.useState(null),[y,g]=Be.useState(null),w=Be.useRef(null),b=Be.useRef(null);let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=se=>{w.current=se,v(se)},e[2]=k):k=e[2];const I=k;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=se=>{b.current=se,g(se)},e[3]=j):j=e[3];const N=j,D=xP,E=bP,T=yP;let C;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==i?(C=se=>{const Ne=se.replace(/\D/g,"").slice(0,2);I(Ne),Ne.length===2&&(r(i?T(D(Ne),u.minute):ki(nf(Ne),u.minute,u.meridiem)),I(null),x.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=i,e[8]=C):C=e[8];const S=C;let M;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==i?(M=()=>{const se=w.current;if(se!==null&&(I(null),se.length!==0)){if(i){r(T(D(se.padStart(2,"0")),u.minute));return}r(ki(nf(se.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=i,e[13]=M):M=e[13];const A=M;let R;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==i?(R=se=>{const Ne=se.replace(/\D/g,"").slice(0,2);N(Ne),Ne.length===2&&(r(i?T(u.hour24,Vo(Ne)):ki(u.hour12,Vo(Ne),u.meridiem)),N(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=i,e[19]=R):R=e[19];const z=R;let B;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==i?(B=()=>{const se=b.current;se!==null&&(N(null),se.length!==0&&r(i?T(u.hour24,Vo(se.padStart(2,"0"))):ki(u.hour12,Vo(se.padStart(2,"0")),u.meridiem)))},e[20]=r,e[21]=u.hour12,e[22]=u.hour24,e[23]=u.meridiem,e[24]=i,e[25]=B):B=e[25];const V=B;let $;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==i?($=se=>r(i?T(E(u.hour24,se),u.minute):ki(oP(u.hour12,se),u.minute,u.meridiem)),e[26]=r,e[27]=u.hour12,e[28]=u.hour24,e[29]=u.meridiem,e[30]=u.minute,e[31]=i,e[32]=$):$=e[32];const _=$;let X;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==i?(X=se=>r(i?T(u.hour24,rf(u.minute,se)):ki(u.hour12,rf(u.minute,se),u.meridiem)),e[33]=r,e[34]=u.hour12,e[35]=u.hour24,e[36]=u.meridiem,e[37]=u.minute,e[38]=i,e[39]=X):X=e[39];const O=X;let J;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(J=se=>{se!==u.meridiem&&r(ki(u.hour12,u.minute,se))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=J):J=e[44];const Q=J;let ne;e[45]!==A||e[46]!==_?(ne=se=>{if(se.key==="ArrowRight"){se.preventDefault(),A(),x.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),I(null),_(se.key==="ArrowUp"?1:-1))},e[45]=A,e[46]=_,e[47]=ne):ne=e[47];const G=ne;let le;e[48]!==V||e[49]!==O?(le=se=>{if(se.key==="ArrowLeft"&&(se.currentTarget.selectionStart??0)===0){se.preventDefault(),V(),h.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),N(null),O(se.key==="ArrowUp"?1:-1))},e[48]=V,e[49]=O,e[50]=le):le=e[50];const oe=le,F=i?"px-2":"pl-2 pr-1";let U;e[51]!==F?(U=ce("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",F),e[51]=F,e[52]=U):U=e[52];const W=f??(i?u.hour24:u.hour12);let te;e[53]!==S?(te=se=>S(se.target.value),e[53]=S,e[54]=te):te=e[54];let K;e[55]===Symbol.for("react.memo_cache_sentinel")?(K=()=>I(""),e[55]=K):K=e[55];let ae;e[56]!==A||e[57]!==a||e[58]!==G||e[59]!==W||e[60]!==te?(ae=s.jsx("input",{ref:h,inputMode:"numeric",value:W,onChange:te,onKeyDown:G,onFocus:K,onBlur:A,maxLength:2,"aria-label":a,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=A,e[57]=a,e[58]=G,e[59]=W,e[60]=te,e[61]=ae):ae=e[61];let ve;e[62]===Symbol.for("react.memo_cache_sentinel")?(ve=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=ve):ve=e[62];const re=y??u.minute;let be;e[63]!==z?(be=se=>z(se.target.value),e[63]=z,e[64]=be):be=e[64];let pe;e[65]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>N(""),e[65]=pe):pe=e[65];let ye;e[66]!==V||e[67]!==l||e[68]!==oe||e[69]!==re||e[70]!==be?(ye=s.jsx("input",{ref:x,inputMode:"numeric",value:re,onChange:be,onKeyDown:oe,onFocus:pe,onBlur:V,maxLength:2,"aria-label":l,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=V,e[67]=l,e[68]=oe,e[69]=re,e[70]=be,e[71]=ye):ye=e[71];let ie;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==Q||e[77]!==i?(ie=i?null:s.jsxs(is,{value:u.meridiem,onValueChange:se=>Q(se),children:[s.jsx(as,{"aria-label":c,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(us,{})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"AM",children:d}),s.jsx(Ft,{value:"PM",children:p})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=p,e[76]=Q,e[77]=i,e[78]=ie):ie=e[78];let ue;return e[79]!==U||e[80]!==ae||e[81]!==ye||e[82]!==ie?(ue=s.jsxs("div",{className:U,children:[ae,ve,ye,ie]}),e[79]=U,e[80]=ae,e[81]=ye,e[82]=ie,e[83]=ue):ue=e[83],ue},of=t=>new Date(t.getFullYear(),t.getMonth(),1),mP=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},lf=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),pP=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(i=>typeof i=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(i)).map(i=>i.trim()),r=Array.from(new Set(n)).sort((i,a)=>i.localeCompare(a));return r.length>0?r:["09:00"]},cf=(t,e)=>{const n=Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC";return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:pP(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:ef(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:t.schedule.timezone||n},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||""},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:ef(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},fP=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},hP=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))};function gP(t){const{open:e,task:n,onOpenChange:r,onSave:i}=t,{t:a,locale:l}=ut(),c=xt(q=>q.loadProviders),d=xt(q=>q.loadAgents),p=xt(q=>q.providers),m=xt(q=>q.currentProviderId),u=xt(q=>q.currentModelId),h=xt(q=>q.currentVariant||""),x=xt(q=>q.currentAgentName||""),f=Ie(q=>q.timeFormatPreference),v=Ie(q=>q.weekStartPreference),y=Ie(q=>q.isMobile),[g,w]=Be.useState(()=>cf(n,{providerID:m,modelID:u,variant:h,agent:x})),[b,k]=Be.useState(!1),[I,j]=Be.useState(!1),[N,D]=Be.useState(!1),[E,T]=Be.useState(""),[C,S]=Be.useState(!1),[M,A]=Be.useState(""),[R,z]=Be.useState(()=>{const q=ol(n?.schedule?.date||"")||new Date;return new Date(q.getFullYear(),q.getMonth(),1)}),B=Be.useRef(null),V=Be.useRef(null),$=Be.useRef(null),_=Be.useRef(null),X=Be.useMemo(()=>cP(l),[l]),O=Be.useMemo(()=>lP(l),[l]),J=Be.useMemo(()=>f==="24h"?!0:f==="12h"?!1:X,[f,X]),Q=Be.useMemo(()=>v==="sunday"?0:v==="monday"?1:O,[v,O]),ne=Be.useMemo(()=>{const q=dP(l);return uP(Eg.map(Se=>({value:Se,label:q[Se]||""})),Q)},[l,Q]);Be.useEffect(()=>{e&&(c(),d())},[e,c,d]),Be.useEffect(()=>{if(!e)return;w(cf(n,{providerID:m,modelID:u,variant:h,agent:x}));const q=ol(n?.schedule?.date||"")||new Date;z(new Date(q.getFullYear(),q.getMonth(),1)),j(!1),S(!1),D(!1),A(""),T("")},[e,n,m,u,h,x]),Be.useEffect(()=>{if(!I)return;const q=Se=>{B.current&&!B.current.contains(Se.target)&&j(!1)};return document.addEventListener("mousedown",q),()=>{document.removeEventListener("mousedown",q)}},[I]);const G=Be.useMemo(()=>{const Se=p.find($e=>$e.id===g.execution.providerID)?.models?.find($e=>$e.id===g.execution.modelID);return Se?.variants?Object.keys(Se.variants):[]},[p,g.execution.providerID,g.execution.modelID]),le=G.length>0,oe=Be.useMemo(()=>!le||!g.execution.variant?"__default":G.includes(g.execution.variant)?g.execution.variant:"__default",[g.execution.variant,le,G]);Be.useEffect(()=>{le||!g.execution.variant||w(q=>({...q,execution:{...q.execution,variant:""}}))},[le,g.execution.variant]);const F=Be.useCallback((q,Se)=>{w($e=>{const Pe=new Set($e.schedule.weekdays);return Se?Pe.add(q):Pe.delete(q),{...$e,schedule:{...$e.schedule,weekdays:Array.from(Pe).sort((fe,L)=>fe-L)}}})},[]),U=Be.useCallback((q,Se)=>{w($e=>{const Pe=$e.schedule.times.slice();return Pe[q]=Se,{...$e,schedule:{...$e.schedule,times:Pe}}})},[]),W=Be.useCallback(q=>{w(Se=>{const $e=Se.schedule.times.filter((Pe,fe)=>fe!==q);return{...Se,schedule:{...Se.schedule,times:$e.length>0?$e:["09:00"]}}})},[]),te=Be.useCallback(()=>{w(q=>({...q,schedule:{...q.schedule,times:[...q.schedule.times,"12:00"]}}))},[]),K=Be.useMemo(()=>mP(),[]),ae=Be.useMemo(()=>of(K),[K]),ve=Be.useMemo(()=>{const q=ol(g.schedule.onceDate);return q?lf(q,K)?a("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(l,{weekday:"short"}).format(q):null},[g.schedule.onceDate,l,a,K]),re=Be.useMemo(()=>of(R).getTime()<=ae.getTime(),[R,ae]),be=Be.useMemo(()=>ne.map(q=>q.label),[ne]),pe=Be.useCallback(q=>{w(Se=>({...Se,schedule:{...Se.schedule,onceDate:q}}))},[]),ye=Be.useCallback((q,Se)=>{if(q.startsWith("/")){const fe=q.indexOf(" "),L=q.indexOf(`
|
|
181
|
+
`),Z=Math.min(fe===-1?q.length:fe,L===-1?q.length:L);if(Se<=Z&&fe===-1){A(q.substring(1,Z)),S(!0),D(!1);return}}S(!1);const $e=q.substring(0,Se),Pe=$e.lastIndexOf("@");if(Pe!==-1){const fe=Pe>0?$e[Pe-1]:null,L=$e.substring(Pe+1);(!fe||/\s/.test(fe))&&!L.includes(" ")&&!L.includes(`
|
|
182
|
+
`)?(T(L),D(!0)):D(!1);return}D(!1)},[]),ie=Be.useCallback(q=>{w(Se=>({...Se,execution:{...Se.execution,prompt:q}}))},[]),ue=Be.useCallback(q=>{const Se=g.execution.prompt,Pe=V.current?.selectionStart??Se.length,L=Se.substring(0,Pe).lastIndexOf("@"),Z=q.relativePath&&q.relativePath.trim().length>0?q.relativePath.trim():q.path||q.name,Y=L!==-1?L:Pe,Ee=`${Se.substring(0,Y)}@${Z} ${Se.substring(Pe)}`,Ae=Y+Z.length+2;ie(Ee),D(!1),T(""),requestAnimationFrame(()=>{const Je=V.current;Je&&(Je.selectionStart=Ae,Je.selectionEnd=Ae,Je.focus()),ye(Ee,Ae)})},[g.execution.prompt,ie,ye]),se=Be.useCallback(q=>{const Se=g.execution.prompt,Pe=V.current?.selectionStart??Se.length,L=Se.substring(0,Pe).lastIndexOf("@"),Z=L!==-1?L:Pe,Y=`${Se.substring(0,Z)}@${q} ${Se.substring(Pe)}`,Ee=Z+q.length+2;ie(Y),D(!1),T(""),requestAnimationFrame(()=>{const Ae=V.current;Ae&&(Ae.selectionStart=Ee,Ae.selectionEnd=Ee,Ae.focus()),ye(Y,Ee)})},[g.execution.prompt,ie,ye]),Ne=Be.useCallback(q=>{const Se=`/${q.name} `;ie(Se),S(!1),A(""),requestAnimationFrame(()=>{const $e=V.current;$e&&($e.focus(),$e.selectionStart=$e.value.length,$e.selectionEnd=$e.value.length),ye(Se,Se.length)})},[ie,ye]),Ce=Be.useCallback(q=>{if(C&&_.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")){q.preventDefault(),_.current.handleKeyDown(q.key);return}N&&$.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")&&(q.preventDefault(),$.current.handleKeyDown(q.key))},[C,N]),je=Be.useCallback(async()=>{const q=fP(g,a);if(q){H.error(q);return}const Se=hP(g.schedule.times),$e={...g.id?{id:g.id}:{},name:g.name.trim(),enabled:g.enabled,schedule:{kind:g.schedule.kind,timezone:g.schedule.timezone.trim(),...g.schedule.kind==="once"?{date:g.schedule.onceDate,time:g.schedule.onceTime}:{times:Se,...g.schedule.kind==="weekly"?{weekdays:g.schedule.weekdays}:{}}},execution:{prompt:g.execution.prompt,providerID:g.execution.providerID,modelID:g.execution.modelID,...g.execution.variant.trim()?{variant:g.execution.variant.trim()}:{},...g.execution.agent.trim()?{agent:g.execution.agent.trim()}:{}},...g.state?{state:g.state}:{}};k(!0);try{await i($e),r(!1)}catch(Pe){H.error(Pe instanceof Error?Pe.message:a("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{k(!1)}},[g,r,i,a]),we=Be.useId(),ke=Be.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),xe=a(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),me=a("sessions.scheduledTasks.editor.description"),Me=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(jr,{htmlFor:"sched-name",required:!0,children:a("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Bt,{id:"sched-name",value:g.name,onChange:q=>w(Se=>({...Se,name:q.target.value})),placeholder:a("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(jr,{children:a("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(is,{value:g.schedule.kind,onValueChange:q=>{w(Se=>({...Se,schedule:{...Se.schedule,kind:q}}))},children:[s.jsx(as,{className:"w-fit max-w-full",children:s.jsx(us,{children:q=>a(q==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":q==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"daily",children:a("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Ft,{value:"weekly",children:a("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Ft,{value:"once",children:a("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),g.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:B,children:[s.jsx(jr,{children:a("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(q=>!q),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(P,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:rP(g.schedule.onceDate,a("sessions.scheduledTasks.editor.date.placeholder"),l)})]}),s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),I?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>z(q=>sf(q,-1)),"aria-label":a("sessions.scheduledTasks.editor.date.previousMonth"),disabled:re,children:s.jsx(P,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(l,{month:"long",year:"numeric"}).format(R)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>z(q=>sf(q,1)),"aria-label":a("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:be.map((q,Se)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:q},`${q}-${Se}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:iP(R,Q).map(({date:q,inCurrentMonth:Se})=>{const $e=tf(q),Pe=$e===g.schedule.onceDate,fe=lf(q,K),L=q.getTime()<K.getTime(),Z=Pe?"bg-interactive-selection text-interactive-selection-foreground":L?"text-muted-foreground/40":Se?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{L||(pe($e),j(!1))},disabled:L,className:["h-8 rounded-md typography-ui-label",Z,fe&&!Pe?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",L?"cursor-not-allowed opacity-45":""].join(" "),children:q.getDate()},$e)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:ve||""}),s.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:()=>{pe(tf(K)),z(new Date(K.getFullYear(),K.getMonth(),1))},children:a("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(jr,{children:a("sessions.scheduledTasks.editor.time.label")}),s.jsx(af,{value:g.schedule.onceTime,use24Hour:J,hourAriaLabel:a("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:a("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:a("sessions.scheduledTasks.editor.time.periodAria"),amLabel:a("sessions.scheduledTasks.editor.time.period.am"),pmLabel:a("sessions.scheduledTasks.editor.time.period.pm"),onChange:q=>w(Se=>({...Se,schedule:{...Se.schedule,onceTime:q}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(jr,{children:a("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(is,{value:g.schedule.timezone,onValueChange:q=>{w(Se=>({...Se,schedule:{...Se.schedule,timezone:q}}))},children:[s.jsx(as,{className:"w-fit max-w-full",children:s.jsx(us,{})}),s.jsx(os,{children:Zp.map(q=>s.jsx(Ft,{value:q,children:q},q))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[g.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(jr,{children:a("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:ne.map(q=>{const Se=g.schedule.weekdays.includes(q.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",Se?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(ds,{checked:Se,onChange:$e=>F(q.value,$e),ariaLabel:q.label}),s.jsx("button",{type:"button",onClick:()=>F(q.value,!Se),className:"group-hover:text-foreground",children:q.label})]},q.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(jr,{children:a("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:g.schedule.times.map((q,Se)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(af,{value:q,use24Hour:J,hourAriaLabel:a("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:a("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:a("sessions.scheduledTasks.editor.time.periodAria"),amLabel:a("sessions.scheduledTasks.editor.time.period.am"),pmLabel:a("sessions.scheduledTasks.editor.time.period.pm"),onChange:$e=>U(Se,$e)}),g.schedule.times.length>1?s.jsx(ge,{type:"button",size:"icon",variant:"ghost",onClick:()=>W(Se),"aria-label":a("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(P,{name:"close",className:"h-4 w-4"})}):null]},Se))}),s.jsx("div",{children:s.jsxs(ge,{type:"button",size:"sm",variant:"outline",onClick:te,children:[s.jsx(P,{name:"add",className:"mr-1 h-4 w-4"})," ",a("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(jr,{children:a("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(is,{value:g.schedule.timezone,onValueChange:q=>{w(Se=>({...Se,schedule:{...Se.schedule,timezone:q}}))},children:[s.jsx(as,{className:"w-fit max-w-full",children:s.jsx(us,{})}),s.jsx(os,{children:Zp.map(q=>s.jsx(Ft,{value:q,children:q},q))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(jr,{required:!0,children:a("sessions.scheduledTasks.editor.model.label")}),s.jsx(yo,{providerId:g.execution.providerID,modelId:g.execution.modelID,onChange:(q,Se)=>{w($e=>({...$e,execution:{...$e.execution,providerID:q,modelID:Se,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(jr,{children:a("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(is,{value:oe,disabled:!le,onValueChange:q=>{w(Se=>({...Se,execution:{...Se.execution,variant:q==="__default"?"":q}}))},children:[s.jsx(as,{className:"w-fit max-w-full",children:s.jsx(us,{children:q=>q==="__default"?a("sessions.scheduledTasks.editor.thinkingLevel.default"):q})}),s.jsxs(os,{children:[s.jsx(Ft,{value:"__default",children:a("sessions.scheduledTasks.editor.thinkingLevel.default")}),G.map(q=>s.jsx(Ft,{value:q,children:q},q))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(jr,{children:a("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Ul,{agentName:g.execution.agent,filter:q=>Yf(q.mode),onChange:q=>w(Se=>({...Se,execution:{...Se.execution,agent:q}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(jr,{htmlFor:"sched-prompt",required:!0,children:a("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(hn,{id:"sched-prompt",ref:V,value:g.execution.prompt,onChange:q=>{const Se=q.target.value;ie(Se);const $e=q.target.selectionStart??Se.length;ye(Se,$e)},onKeyDown:Ce,rows:8,placeholder:a("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),C?s.jsx(dh,{ref:_,searchQuery:M,onCommandSelect:Ne,onClose:()=>S(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,N?s.jsx(uh,{ref:$,searchQuery:E,onFileSelect:ue,onAgentSelect:se,onClose:()=>D(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),Ue=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(ds,{checked:g.enabled,onChange:q=>w(Se=>({...Se,enabled:q})),ariaLabel:a("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:a("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:b,children:a("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(ge,{type:"button",size:"sm",onClick:je,disabled:b,children:a(b?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return y?s.jsx($r,{open:e,title:xe,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:q=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:xe}),q]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:me})]}),footer:Ue,children:Me}):s.jsx(hs,{open:e,onOpenChange:q=>{!q&&ke()||r(q)},children:s.jsxs(fs,{"aria-describedby":we,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Is,{id:we,className:"sr-only",children:me}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(gs,{className:"typography-ui-label font-medium text-foreground",children:xe}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:me})]})}),s.jsx(po,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:Me})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:Ue})})]})})}function xP(t){return ka(t,{min:0,max:23})}function bP(t,e){return ka(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function yP(t,e){const n=Number(t),r=Number(e),i=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,a=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(i).padStart(2,"0")}:${String(a).padStart(2,"0")}`}const vP=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,i)=>r.localeCompare(i))},wP=(t,e)=>{const n=vP(t).join(", ")||"--:--",r=i=>e(i===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":i===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":i===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":i===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":i===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":i===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":i===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const i=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(a=>r(a)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:i,time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:i,time:n})}if(t.schedule.kind==="once"){const i=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),a=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:i,time:a,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.once",{date:i,time:a})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},jP=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),df=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),i=6e4,a=60*i,l=24*a,c=n>=0;if(r<i)return e(c?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<a){const u=Math.round(r/i);return c?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:u}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:u})}if(r<l){const u=Math.floor(r/a),h=Math.round(r%a/i),x=h>0?`${u}h ${h}m`:`${u}h`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:x}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:x})}const d=Math.floor(r/l),p=Math.round(r%l/a),m=p>0?`${d}d ${p}h`:`${d}d`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},NP={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},SP=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function kP(){const{t}=ut(),e=Ie(A=>A.isScheduledTasksDialogOpen),n=Ie(A=>A.setScheduledTasksDialogOpen),r=Ie(A=>A.isMobile),i=As(A=>A.projects),a=As(A=>A.getActiveProject()),l=$s(A=>A.homeDirectory),{currentTheme:c}=Ar(),[d,p]=Be.useState(""),[m,u]=Be.useState([]),[h,x]=Be.useState(!0),[f,v]=Be.useState(!1),[y,g]=Be.useState(null),[w,b]=Be.useState(null),k=Be.useMemo(()=>i.find(A=>A.id===d)||null,[i,d]),I=Be.useCallback(A=>{const R=A.label?.trim()||Vi(A.path,l||void 0),z=xo({id:A.id,iconImage:A.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),B=A.icon?Vl[A.icon]:null,V=A.color?bo[A.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[z?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:A.iconBackground?{backgroundColor:A.iconBackground}:void 0,children:s.jsx("img",{src:z,alt:"",className:"h-full w-full object-contain",draggable:!1})}):B?s.jsx(P,{name:B,className:"h-3.5 w-3.5 shrink-0",style:V?{color:V}:void 0}):s.jsx(P,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:V?{color:V}:void 0}),s.jsx("span",{className:"truncate",children:R})]})},[l,c.metadata.variant,c.colors.surface.foreground]),j=Be.useCallback(async(A,R)=>{if(!A){u([]);return}R?.silent||x(!0);try{const z=await tP(A);z.sort((B,V)=>{if(B.enabled!==V.enabled)return B.enabled?-1:1;const $=B.name.localeCompare(V.name);return $!==0?$:(B.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u(z)}catch(z){H.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),R?.silent||u([])}finally{R?.silent||x(!1)}},[t]);Be.useEffect(()=>{if(!e)return;const A=a?.id||i[0]?.id||"";p(A),A?j(A):(u([]),x(!1))},[e,a,i,j]),Be.useEffect(()=>{if(!e)return;let A=null;const R=Mg(z=>{z.type==="scheduled-task-ran"&&z.projectId===d&&(A&&clearTimeout(A),A=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{A&&clearTimeout(A),R()}},[e,d,j]);const N=Be.useCallback(async A=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Xp(d,A),await j(d),H.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),D=Be.useCallback(async(A,R)=>{if(d){b(A.id),u(z=>z.map(B=>B.id===A.id?{...B,enabled:R}:B));try{await Xp(d,{...A,enabled:R}),await j(d,{silent:!0})}catch(z){H.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{b(null)}}},[d,j,t]),E=Be.useCallback(async A=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:A.name})))){b(A.id);try{await sP(d,A.id),await j(d,{silent:!0}),H.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(z){H.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{b(null)}}},[d,j,t]),T=Be.useCallback(async A=>{if(d){b(A.id);try{await nP(d,A.id),await Promise.all([j(d,{silent:!0}),Jc()]),H.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(R){H.error(R instanceof Error?R.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{b(null)}}},[d,j,t]),C=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(is,{value:d||"__none",onValueChange:A=>{const R=A==="__none"?"":A;p(R),R?j(R):u([])},children:[s.jsx(as,{className:r?"w-full":void 0,children:k?s.jsx(us,{children:I(k)}):s.jsx(us,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(os,{children:[i.length===0?s.jsx(Ft,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,i.map(A=>s.jsx(Ft,{value:A.id,children:I(A)},A.id))]})]})]}),S=()=>{g(null),v(!0)},M=s.jsxs("div",{className:"space-y-4",children:[r?C:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[C,s.jsxs(ge,{onClick:S,disabled:!d,children:[s.jsx(P,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:h?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(A=>{const R=w===A.id,z=A.state?.lastStatus||"idle",B=NP[z],V=t(z==="success"?"sessions.scheduledTasks.dialog.status.success":z==="error"?"sessions.scheduledTasks.dialog.status.error":z==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),$=A.state?.nextRunAt,_=A.state?.lastRunAt;return s.jsxs("div",{className:ce("rounded-lg border border-border p-4 transition-opacity",!A.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:A.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:wP(A,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(P,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),$?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:df($,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:jP($)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(P,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),z==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(P,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):_?s.jsxs(s.Fragment,{children:[B.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${B.tone})`},children:[s.jsx(P,{name:B.Icon,className:"h-3.5 w-3.5"}),V]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:df(_,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),A.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:SP("error"),children:[s.jsx(P,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:A.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:ce("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",A.enabled?"text-foreground":"text-muted-foreground",R&&"cursor-not-allowed opacity-50"),children:[s.jsx(ds,{checked:A.enabled,onChange:X=>{D(A,X)},ariaLabel:A.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:A.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:A.name}),disabled:R}),A.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(ge,{variant:"outline",size:"sm",onClick:()=>{T(A)},disabled:R,children:[s.jsx(P,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(ge,{variant:"outline",size:"sm",onClick:()=>{g(A),v(!0)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:A.name}),children:[s.jsx(P,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(ge,{variant:"destructive",size:"sm",onClick:()=>{E(A)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:A.name}),children:s.jsx(P,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},A.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx($r,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:A=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),A]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(ge,{className:"w-full",onClick:S,disabled:!d,children:[s.jsx(P,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:M}):s.jsx(hs,{open:e,onOpenChange:n,children:s.jsxs(fs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Is,{children:t("sessions.scheduledTasks.dialog.description")})]}),M]})}),s.jsx(gP,{open:f,task:y,onOpenChange:v,onSave:N})]})}const CP=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(c=>xs(c.path)??c.path).filter(c=>!!c)]),a=(c=>c.filter(d=>io(d,t.normalizedPath,r)))(e.archivedSessions),l=e.sessions.filter(c=>c.time?.archived||xs(c.directory??null)?!1:io(c,t.normalizedPath,r));return ya([...a,...l])},PP=t=>{const e=at.c(12),{normalizedProjects:n,sessions:r,archivedSessions:i,availableWorktreesByProject:a,isVSCode:l,isSessionsLoading:c,foldersMap:d,createFolder:p,addSessionToFolder:m,cleanupSessions:u}=t;let h,x;e[0]!==m||e[1]!==i||e[2]!==a||e[3]!==u||e[4]!==p||e[5]!==d||e[6]!==c||e[7]!==l||e[8]!==n||e[9]!==r?(h=()=>{c||n.forEach(f=>{const v=Vd(f.normalizedPath),y=CP(f,{sessions:r,archivedSessions:i,availableWorktreesByProject:a,isVSCode:l}),g=new Set(y.map(IP)),w=d[v]??[],b=new Map(w.map(AP));y.forEach(k=>{const I=yy(k,f.normalizedPath),j=I.toLowerCase();let N=b.get(j);N||(N=p(v,I),b.set(j,N)),N.sessionIds.includes(k.id)||m(v,N.id,k.id)}),u(v,g)})},x=[n,r,i,a,l,c,d,p,m,u],e[0]=m,e[1]=i,e[2]=a,e[3]=u,e[4]=p,e[5]=d,e[6]=c,e[7]=l,e[8]=n,e[9]=r,e[10]=h,e[11]=x):(h=e[10],x=e[11]),o.useEffect(h,x)};function IP(t){return t.id}function AP(t){return[t.name.toLowerCase(),t]}const DP=t=>{const e=at.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:i,availableWorktreesByProject:a,projectRepoStatus:l,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:h,buildGroupSearchText:x,foldersMap:f}=t;let v;if(e[0]!==a||e[1]!==p||e[2]!==i||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==l||e[7]!==c){let T;e[9]!==a||e[10]!==p||e[11]!==i||e[12]!==r||e[13]!==d||e[14]!==l||e[15]!==c?(T=C=>{const S=ya([...r(C),...i(C)]),M=a.get(C.normalizedPath)??[],A=l.has(C.id)?!!l.get(C.id):d,R=p(S,C.normalizedPath,M,c.get(C.id)??null,A);return{project:C,groups:R}},e[9]=a,e[10]=p,e[11]=i,e[12]=r,e[13]=d,e[14]=l,e[15]=c,e[16]=T):T=e[16],v=n.map(T),e[0]=a,e[1]=p,e[2]=i,e[3]=r,e[4]=d,e[5]=n,e[6]=l,e[7]=c,e[8]=v}else v=e[8];const y=v,g=y;let w;if(e[17]!==x||e[18]!==h||e[19]!==f||e[20]!==m||e[21]!==u||e[22]!==g){e:{const T=new WeakMap;if(!m){w=T;break e}const C=S=>S.reduce((M,A)=>M+1+C(A.children),0);g.forEach(S=>{S.groups.forEach(M=>{const A=h(M.sessions,u),R=C(A),z=x(M).includes(u),B=xs(M.directory??null),$=(B?f[B]??[]:[]).filter(_=>_.name.toLowerCase().includes(u)).length;T.set(M,{filteredNodes:A,matchedSessionCount:R,folderNameMatchCount:$,groupMatches:z,hasMatch:z||R>0||$>0})})}),w=T}e[17]=x,e[18]=h,e[19]=f,e[20]=m,e[21]=u,e[22]=g,e[23]=w}else w=e[23];const b=w;let k;e:{if(!m){k=g;break e}let T;if(e[24]!==b||e[25]!==g){let C;e[27]!==b?(C=S=>({...S,groups:S.groups.filter(M=>b.get(M)?.hasMatch===!0)}),e[27]=b,e[28]=C):C=e[28],T=g.map(C).filter(TP),e[24]=b,e[25]=g,e[26]=T}else T=e[26];k=T}const I=k,j=m?I:g;let N;e:{if(!m){N=0;break e}let T;if(e[29]!==b||e[30]!==j){let C;e[32]!==b?(C=(S,M)=>S+M.groups.reduce((A,R)=>{const z=b.get(R);if(!z)return A;const B=z.folderNameMatchCount+(z.groupMatches?1:0);return A+z.matchedSessionCount+B},0),e[32]=b,e[33]=C):C=e[33],T=j.reduce(C,0),e[29]=b,e[30]=j,e[31]=T}else T=e[31];N=T}const D=N;let E;return e[34]!==b||e[35]!==y||e[36]!==D||e[37]!==I||e[38]!==j||e[39]!==g?(E={projectSections:y,visibleProjectSections:g,groupSearchDataByGroup:b,searchableProjectSections:I,sectionsForRender:j,searchMatchCount:D},e[34]=b,e[35]=y,e[36]=D,e[37]=I,e[38]=j,e[39]=g,e[40]=E):E=e[40],E};function TP(t){return t.groups.length>0}const MP=t=>{const e=at.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:i,setActiveSessionByProject:a,currentSessionId:l,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:h,sessions:x,worktreeMetadata:f}=t;let v,y;if(e[0]!==n){y=new Map,v=new Map;const C=(S,M,A,R)=>{y.has(S)||y.set(S,new Map);const z=y.get(S);R.forEach(B=>{const V=xs(B.worktree?.path??B.session.directory??A??M);z.set(B.session.id,{directory:V}),v.has(S)||v.set(S,{id:B.session.id,directory:V}),B.children.length>0&&C(S,M,V,B.children)})};n.forEach(S=>{S.groups.forEach(M=>{C(S.project.id,S.project.normalizedPath,M.directory,M.sessions)})}),e[0]=n,e[1]=v,e[2]=y}else v=e[1],y=e[2];let g;e[3]!==v||e[4]!==y?(g={metaByProject:y,firstSessionByProject:v},e[3]=v,e[4]=y,e[5]=g):g=e[5];const w=g,b=o.useRef(null);let k,I;e[6]!==r||e[7]!==i||e[8]!==l||e[9]!==c||e[10]!==p||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==w||e[15]!==u||e[16]!==a||e[17]!==h?(k=()=>{if(!r||d||b.current===r)return;const C=n.find(V=>V.project.id===r);if(!C)return;b.current=r;const S=w.metaByProject.get(r);if(l&&S&&S.has(l)){a(V=>{if(V.get(r)===l)return V;const $=new Map(V);return $.set(r,l),$});return}if(!S||S.size===0){u("chat"),p&&h(!1),m({directoryOverride:C.project.normalizedPath});return}const M=i.get(r),A=M&&S.has(M)?M:null,R=w.firstSessionByProject.get(r)?.id??null,z=A??R;if(!z||z===l)return;const B=S.get(z)?.directory??null;c(z,B,!1,r)},I=[r,i,l,c,d,p,m,n,w,u,h,a],e[6]=r,e[7]=i,e[8]=l,e[9]=c,e[10]=p,e[11]=d,e[12]=m,e[13]=n,e[14]=w,e[15]=u,e[16]=a,e[17]=h,e[18]=k,e[19]=I):(k=e[18],I=e[19]),o.useLayoutEffect(k,I);let j,N;e[20]!==r||e[21]!==l||e[22]!==w||e[23]!==a?(j=()=>{if(!r||!l)return;const C=w.metaByProject.get(r);!C||!C.has(l)||a(S=>{if(S.get(r)===l)return S;const M=new Map(S);return M.set(r,l),M})},N=[r,l,w,a],e[20]=r,e[21]=l,e[22]=w,e[23]=a,e[24]=j,e[25]=N):(j=e[24],N=e[25]),o.useEffect(j,N);let D;if(e[26]!==l||e[27]!==x||e[28]!==f){e:{if(!l){D=null;break e}const C=f.get(l)?.path;if(C){D=xs(C)??C;break e}let S;e[30]!==l?(S=A=>A.id===l,e[30]=l,e[31]=S):S=e[31];const M=x.find(S);if(!M){D=null;break e}D=xs(M.directory??null)}e[26]=l,e[27]=x,e[28]=f,e[29]=D}else D=e[29];const E=D;let T;return e[32]!==E?(T={currentSessionDirectory:E},e[32]=E,e[33]=T):T=e[33],T},EP=t=>{const e=at.c(4);let n;e[0]!==t?(n=(a,l)=>{const c=t.get(a);if(!c||c.length===0)return l;const d=new Map(l.map(RP)),p=[];return c.forEach(m=>{const u=d.get(m);u&&(p.push(u),d.delete(m))}),l.forEach(m=>{d.has(m.id)&&p.push(m)}),p},e[0]=t,e[1]=n):n=e[1];const r=n;let i;return e[2]!==r?(i={getOrderedGroups:r},e[2]=r,e[3]=i):i=e[3],i};function RP(t){return[t.id,t]}const _o=t=>!!t.time?.archived,FP=t=>{const{t:e}=ut(),n=o.useCallback(l=>[l.label,l.branch??"",l.description??"",l.directory??""].join(" ").toLowerCase(),[]),r=o.useCallback(l=>{const c=xs(l.directory??null)??"";return`${(l.title||e("sessions.sidebar.session.untitled")).trim()} ${c}`.toLowerCase()},[e]),i=o.useCallback((l,c)=>c?l.flatMap(d=>{if(r(d.session).includes(c))return[d];const m=i(d.children,c);return m.length===0?[]:[{...d,children:m}]}):l,[r]),a=o.useCallback((l,c,d,p,m)=>{const u=xs(c??null),h=ya(l).sort((C,S)=>ca(C,S,t.pinnedSessionIds)),x=new Map(h.map(C=>[C.id,C])),f=new Map;h.forEach(C=>{const S=C.parentID;if(!S)return;const M=x.get(S);if(!M||_o(M)!==_o(C))return;const A=f.get(S)??[];A.push(C),f.set(S,A)}),f.forEach(C=>C.sort((S,M)=>ca(S,M,t.pinnedSessionIds)));const v=new Map;d.forEach(C=>{if(C.path){const S=xs(C.path)??C.path;v.set(S,C)}});const y=C=>{const S=xs(C.directory??null),M=t.worktreeMetadata.get(C.id)??null;if(M)return M;if(S){const A=v.get(S)??null;if(A&&S!==u)return A}return null},g=C=>{const S=f.get(C.id)??[];return{session:C,children:S.map(M=>g(M)),worktree:y(C)}},w=h.filter(C=>{const S=C.parentID;if(!S)return!0;const M=x.get(S);return M?_o(M)!==_o(C):!0}),b=new Map,k="__archived__",I=C=>{if(C.time?.archived)return k;const S=xs(t.worktreeMetadata.get(C.id)?.path??null),M=xs(C.directory??null);if(!S&&!M)return k;const A=xs(C.project?.worktree??null),R=S??M??A;return R?R!==u&&v.has(R)?R:R===u?u??"__project_root__":k:k};w.forEach(C=>{const S=g(C),M=I(C);b.has(M)||b.set(M,[]),b.get(M)?.push(S)});const j=u??"__project_root__",N=[{id:"root",label:m&&p&&p!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:p}):e("sessions.sidebar.grouping.projectRoot"),branch:p??null,description:u?ro(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:b.get(j)??[]}],D=new Map;d.forEach(C=>{const S=xs(C.path)??C.path,M=b.get(S)??[],A=M.length>0,R=M.reduce((z,B)=>{const V=Number(B.session.time?.updated??B.session.time?.created??0);return Number.isFinite(V)?Math.max(z,V):z},0);D.set(S,{hasActiveSession:A,lastUpdatedAt:R})}),[...d].sort((C,S)=>{const M=xs(C.path)??C.path,A=xs(S.path)??S.path,R=D.get(M)??{hasActiveSession:!1,lastUpdatedAt:0},z=D.get(A)??{hasActiveSession:!1,lastUpdatedAt:0};if(R.hasActiveSession!==z.hasActiveSession)return R.hasActiveSession?-1:1;if(R.hasActiveSession&&z.hasActiveSession)return z.lastUpdatedAt-R.lastUpdatedAt;const B=(C.label||C.branch||C.name||C.path||"").toLowerCase(),V=(S.label||S.branch||S.name||S.path||"").toLowerCase();return B.localeCompare(V)}).forEach(C=>{const S=xs(C.path)??C.path,M=t.gitBranches.get(S)?.trim()||null,A=C.branch?.trim()||null,z=!!(M&&A&&C.label&&$u(C.label)===$u(A))?M:C.label||C.name||Vi(S,t.homeDirectory)||S;N.push({id:`worktree:${S}`,label:z,branch:M||A,description:ro(S,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:C,directory:S,folderScopeKey:S,sessions:b.get(S)??[]})});const T=b.get(k)??[];return T.length>0&&N.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&u?Vd(u):null,sessions:T}),N},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:i,buildGroupedSessions:a}},LP=t=>{const e=at.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:i,sessionSearchContainerRef:a}=t;let l,c;e[0]!==n||e[1]!==i?(l=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()});return()=>window.cancelAnimationFrame(m)},c=[n,i],e[0]=n,e[1]=i,e[2]=l,e[3]=c):(l=e[2],c=e[3]),o.useEffect(l,c);let d,p;e[4]!==n||e[5]!==a||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=u=>{a.current&&(a.current.contains(u.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},p=[n,r,a],e[4]=n,e[5]=a,e[6]=r,e[7]=d,e[8]=p):(d=e[7],p=e[8]),o.useEffect(d,p)},OP=t=>{const e=at.c(42),{t:n}=ut(),[r,i]=o.useState(null),a=o.useRef(null);let l,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>()=>{a.current&&clearTimeout(a.current)},c=[],e[0]=l,e[1]=c):(l=e[0],c=e[1]),o.useEffect(l,c);let d;e[2]!==t?(d=(z,B,V,$)=>{if(V)return;const _=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if($&&$!==t.activeProjectId&&t.setActiveProjectIdOnly($),B&&B!==t.currentDirectory&&t.setDirectory(B,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),z===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(z),_();return}t.setCurrentSession(z,B??null),t.onSessionSelected?.(z),_()},e[2]=t,e[3]=d):d=e[3];const p=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const u=m;let h;e[6]!==t?(h=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=h):h=e[7];const x=h;let f;e[8]!==t?(f=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=f):f=e[9];const v=f;let y;e[10]!==t||e[11]!==n?(y=async z=>{const B=await t.shareSession(z.id);B&&B.share?.url?H.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):H.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=y):y=e[12];const g=y;let w;e[13]!==n?(w=(z,B)=>{_n(z).then(V=>{if(!V.ok){H.error(n("sessions.sidebar.session.share.copyUrlError"));return}i(B),a.current&&clearTimeout(a.current),a.current=window.setTimeout(()=>{i(null),a.current=null},2e3)}).catch(()=>{H.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=w):w=e[14];const b=w;let k;e[15]!==t||e[16]!==n?(k=async z=>{await t.unshareSession(z)?H.success(n("sessions.sidebar.session.unshare.success")):H.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=k):k=e[17];const I=k;let j;e[18]!==t.childrenMap?(j=z=>{const B=[],V=$=>{(t.childrenMap.get($)??[]).forEach(X=>{B.push(X),V(X.id)})};return V(z),B},e[18]=t.childrenMap,e[19]=j):j=e[19];const N=j,D=BP;let E;e[20]!==t||e[21]!==N||e[22]!==n?(E=async(z,B,V)=>{const $=B?.archivedBucket===!0,_=V?.descendantIds??D(N(z.id),$).map(zP);if(_.length===0){($?await t.deleteSession(z.id):await t.archiveSession(z.id))?H.success(n($?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):H.error(n($?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const X=[z.id,..._];if($){const{deletedIds:Q,failedIds:ne}=await t.deleteSessions(X);Q.length>0&&H.success(Q.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:Q.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:Q.length})),ne.length>0&&H.error(ne.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ne.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:ne.length}));return}const{archivedIds:O,failedIds:J}=await t.archiveSessions(X);O.length>0&&H.success(O.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:O.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:O.length})),J.length>0&&H.error(J.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:J.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:J.length}))},e[20]=t,e[21]=N,e[22]=n,e[23]=E):E=e[23];const T=E;let C;e[24]!==t||e[25]!==N||e[26]!==T?(C=(z,B)=>{const V=B?.archivedBucket===!0,$=D(N(z.id),V).map(VP);if(!t.showDeletionDialog){T(z,B,{descendantIds:$});return}t.setDeleteSessionConfirm({session:z,descendantCount:$.length,descendantIds:$,archivedBucket:V})},e[24]=t,e[25]=N,e[26]=T,e[27]=C):C=e[27];const S=C;let M;e[28]!==t||e[29]!==T?(M=async()=>{if(!t.deleteSessionConfirm)return;const{session:z,archivedBucket:B,descendantIds:V}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await T(z,{archivedBucket:B},{descendantIds:V})},e[28]=t,e[29]=T,e[30]=M):M=e[30];const A=M;let R;return e[31]!==A||e[32]!==r||e[33]!==v||e[34]!==b||e[35]!==S||e[36]!==x||e[37]!==u||e[38]!==p||e[39]!==g||e[40]!==I?(R={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:x,handleCancelEdit:v,handleShareSession:g,handleCopyShareUrl:b,handleUnshareSession:I,handleDeleteSession:S,confirmDeleteSession:A},e[31]=A,e[32]=r,e[33]=v,e[34]=b,e[35]=S,e[36]=x,e[37]=u,e[38]=p,e[39]=g,e[40]=I,e[41]=R):R=e[41],R};function $P(t){return!t.time?.archived}function BP(t,e){return e?t:t.filter($P)}function zP(t){return t.id}function VP(t){return t.id}const _P=["project:active:","project:archived:","recent:active:","recent:archived:"],UP=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:i,sessions:a,setPinnedSessionIds:l,groupOrderByProject:c,activeSessionByProject:d,collapsedGroups:p,setExpandedParents:m,setCollapsedProjects:u}=t,h=o.useRef(null),x=o.useRef(null),f=o.useCallback(()=>{if(e)return;const y=x.current;if(x.current=null,h.current=null,!y)return;const{projects:g}=As.getState(),w=g.map(b=>({...b,sidebarCollapsed:y.has(b.id)}));ks({projects:w}).catch(()=>{})},[e]),v=o.useCallback(y=>{typeof window>"u"||e||(x.current=y,h.current!==null&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{f()},700))},[e,f]);return o.useEffect(()=>()=>{typeof window<"u"&&h.current!==null&&window.clearTimeout(h.current),h.current=null,x.current=null},[]),o.useEffect(()=>{try{const y=r.getItem(i.sessionExpanded);if(y){const w=JSON.parse(y);Array.isArray(w)&&m(new Set(w.filter(b=>typeof b=="string")))}else{const w=r.getItem(i.sessionExpandedLegacy);if(w){try{const b=JSON.parse(w);if(Array.isArray(b)){const k=new Set;if(b.forEach(I=>{typeof I!="string"||I.length===0||_P.forEach(j=>k.add(`${j}${I}`))}),k.size>0){m(k);try{r.setItem(i.sessionExpanded,JSON.stringify(Array.from(k)))}catch{}}}}catch{}try{r.removeItem?.(i.sessionExpandedLegacy)}catch{}}}const g=r.getItem(i.projectCollapse);if(g){const w=JSON.parse(g);Array.isArray(w)&&u(new Set(w.filter(b=>typeof b=="string")))}}catch{}},[i.projectCollapse,i.sessionExpanded,i.sessionExpandedLegacy,r,u,m]),o.useEffect(()=>{if(!n)return;const y=new Set(a.map(g=>g.id));l(g=>{let w=!1;const b=new Set;return g.forEach(k=>{y.has(k)?b.add(k):w=!0}),w?b:g})},[n,a,l]),o.useEffect(()=>{try{const y=Object.fromEntries(c.entries());r.setItem(i.groupOrder,JSON.stringify(y))}catch{}},[c,i.groupOrder,r]),o.useEffect(()=>{try{const y=Object.fromEntries(d.entries());r.setItem(i.projectActiveSession,JSON.stringify(y))}catch{}},[d,i.projectActiveSession,r]),o.useEffect(()=>{try{r.setItem(i.groupCollapse,JSON.stringify(Array.from(p)))}catch{}},[p,i.groupCollapse,r]),{scheduleCollapsedProjectsPersist:v}},WP=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),i=new Array(t.length);let a=0;const l=async()=>{for(;;){const c=a;if(a+=1,c>=t.length)return;i[c]=await n(t[c])}};return await Promise.all(Array.from({length:r},()=>l())),i},KP=t=>{const e=at.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:i,setProjectRootBranches:a}=t,{git:l}=Pn(),c=tn(HP);let d,p;e[0]!==c||e[1]!==l||e[2]!==n||e[3]!==i?(d=()=>{if(!l||n.length===0){i(new Map);return}n.forEach(y=>{c(y.normalizedPath,l)})},p=[n,l,c,i],e[0]=c,e[1]=l,e[2]=n,e[3]=i,e[4]=d,e[5]=p):(d=e[4],p=e[5]),o.useEffect(d,p);let m,u;e[6]!==r||e[7]!==n||e[8]!==i?(m=()=>{const y=new Map;n.forEach(g=>{y.set(g.id,r.get(g.normalizedPath)?.isGitRepo??null)}),i(y)},u=[n,r,i],e[6]=r,e[7]=n,e[8]=i,e[9]=m,e[10]=u):(m=e[9],u=e[10]),o.useEffect(m,u);let h;if(e[11]!==r||e[12]!==n){let y;e[14]!==r?(y=g=>{const w=r.get(g.normalizedPath)?.branch??"";return`${g.id}:${w}`},e[14]=r,e[15]=y):y=e[15],h=n.map(y).join("|"),e[11]=r,e[12]=n,e[13]=h}else h=e[13];const x=h;let f;e[16]!==n||e[17]!==a?(f=()=>{let y=!1;return(async()=>{const w=await WP(n,2,qP);y||a(b=>{const k=new Map(b);return w.forEach(I=>{const{id:j,branch:N}=I;N&&k.set(j,N)}),k})})(),()=>{y=!0}},e[16]=n,e[17]=a,e[18]=f):f=e[18];let v;e[19]!==n||e[20]!==x||e[21]!==a?(v=[n,x,a],e[19]=n,e[20]=x,e[21]=a,e[22]=v):v=e[22],o.useEffect(f,v)};function HP(t){return t.ensureStatus}function GP(){return null}async function qP(t){const e=await fo(t.normalizedPath).catch(GP);return{id:t.id,branch:e}}const YP=t=>{const e=at.c(14),{isVSCode:n,sessions:r,archivedSessions:i,availableWorktreesByProject:a}=t;let l;e[0]!==r?(l=new Map,r.forEach(x=>{const f=xs(x.directory??null)??xs(x.project?.worktree??null);if(!f)return;const v=l.get(f)??[];v.push(x),l.set(f,v)}),e[0]=r,e[1]=l):l=e[1];const c=l;let d;e[2]!==a||e[3]!==n||e[4]!==c?(d=x=>{const f=n?[]:a.get(x.normalizedPath)??[],v=[x.normalizedPath,...f.map(QP).filter(JP)],y=new Set,g=[];return v.forEach(w=>{(c.get(w)??[]).forEach(k=>{y.has(k.id)||(y.add(k.id),g.push(k))})}),g},e[2]=a,e[3]=n,e[4]=c,e[5]=d):d=e[5];const p=d;let m;e[6]!==i||e[7]!==a||e[8]!==n||e[9]!==r?(m=x=>{if(n){const b=i.filter(I=>{const j=xs(I.directory??null),N=xs(I.project?.worktree??null);return j?j===x.normalizedPath:N===x.normalizedPath}),k=r.filter(I=>I.time?.archived||xs(I.directory??null)?!1:xs(I.project?.worktree??null)===x.normalizedPath);return ya([...b,...k])}const f=n?[]:a.get(x.normalizedPath)??[],v=new Set([x.normalizedPath,...f.map(XP).filter(ZP)]),g=(b=>b.filter(k=>io(k,x.normalizedPath,v)))(i),w=r.filter(b=>{if(b.time?.archived||xs(b.directory??null))return!1;const I=xs(b.project?.worktree??null);return I?I===x.normalizedPath||I.startsWith(`${x.normalizedPath}/`):!1});return ya([...g,...w])},e[6]=i,e[7]=a,e[8]=n,e[9]=r,e[10]=m):m=e[10];const u=m;let h;return e[11]!==u||e[12]!==p?(h={getSessionsForProject:p,getArchivedSessionsForProject:u},e[11]=u,e[12]=p,e[13]=h):h=e[13],h};function QP(t){return xs(t.path)??t.path}function JP(t){return!!t}function XP(t){return xs(t.path)??t.path}function ZP(t){return!!t}const eI=t=>{const e=at.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:i,normalizedProjects:a,isVSCode:l,availableWorktreesByProject:c,cleanupSessions:d}=t;let p,m;e[0]!==i||e[1]!==c||e[2]!==d||e[3]!==n||e[4]!==l||e[5]!==a||e[6]!==r?(p=()=>{if(n)return;const u=new Map;r.forEach(f=>{const v=xs(f.directory??null);if(!v)return;const y=u.get(v);if(y){y.add(f.id);return}u.set(v,new Set([f.id]))}),a.forEach(f=>{const v=Vd(f.normalizedPath),y=l?[]:c.get(f.normalizedPath)??[],g=new Set([f.normalizedPath,...y.map(tI).filter(sI)]),w=ya([...i,...r.filter(b=>b.time?.archived||xs(b.directory??null)?!1:io(b,f.normalizedPath,g))]).filter(b=>io(b,f.normalizedPath,g));u.set(v,new Set(w.map(nI)))});const h=Yn.getState().foldersMap;new Set([...Object.keys(h),...u.keys()]).forEach(f=>{d(f,u.get(f)??new Set)})},m=[i,c,d,n,l,a,r],e[0]=i,e[1]=c,e[2]=d,e[3]=n,e[4]=l,e[5]=a,e[6]=r,e[7]=p,e[8]=m):(p=e[7],m=e[8]),o.useEffect(p,m)};function tI(t){return xs(t.path)??t.path}function sI(t){return!!t}function nI(t){return t.id}const rI=t=>{const e=at.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:i}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[l,c]=o.useState(a);let d;e[1]!==n||e[2]!==i?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(h=>{const x=h.target.dataset.projectId;x&&c(f=>{const v=new Set(f);return h.isIntersecting?v.delete(x):v.add(x),v})})},{threshold:0});return i.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=i,e[3]=d):d=e[3];let p;return e[4]!==n||e[5]!==i||e[6]!==r?(p=[n,i,r],e[4]=n,e[5]=i,e[6]=r,e[7]=p):p=e[7],o.useEffect(d,p),l},iI=t=>{const e=at.c(85),{folder:n,sessions:r,subFolderItems:i,isCollapsed:a,onToggle:l,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:h,alwaysShowActions:x,isRenaming:f,renameDraft:v,onRenameDraftChange:y,onRenameSave:g,onRenameCancel:w,droppableRef:b,isDropTarget:k,onNewSession:I,onNewSubFolder:j,depth:N,hideActions:D,archivedBucket:E}=t,C=x===void 0?h===void 0?!1:h:x,S=f===void 0?!1:f,M=v===void 0?"":v,A=k===void 0?!1:k,R=N===void 0?0:N,z=D===void 0?!1:D,B=E===void 0?!1:E,{t:V}=ut(),[$,_]=o.useState(!1),[X,O]=o.useState(""),J=o.useRef(null),Q=S||$,ne=S?M:X;let G;e[0]!==n.name?(G=()=>{O(n.name),_(!0)},e[0]=n.name,e[1]=G):G=e[1];const le=G;let oe;e[2]!==ne||e[3]!==n.name||e[4]!==S||e[5]!==c||e[6]!==g?(oe=()=>{const Z=ne.trim();Z&&Z!==n.name&&c(Z),S&&g&&g(),_(!1),O("")},e[2]=ne,e[3]=n.name,e[4]=S,e[5]=c,e[6]=g,e[7]=oe):oe=e[7];const F=oe;let U;e[8]!==S||e[9]!==w?(U=()=>{S&&w&&w(),_(!1),O("")},e[8]=S,e[9]=w,e[10]=U):U=e[10];const W=U;let te;e[11]!==S||e[12]!==y?(te=Z=>{S&&y?y(Z):O(Z)},e[11]=S,e[12]=y,e[13]=te):te=e[13];const K=te;let ae,ve;e[14]!==S?(ae=()=>{if(!S)return;const Z=()=>{const Ae=J.current;Ae&&(Ae.focus(),Ae.select())},Y=requestAnimationFrame(Z),Ee=window.setTimeout(Z,0);return()=>{cancelAnimationFrame(Y),window.clearTimeout(Ee)}},ve=[S],e[14]=S,e[15]=ae,e[16]=ve):(ae=e[15],ve=e[16]),o.useEffect(ae,ve);const re=a?"folder":"folder-open",pe=R>0&&"ml-3";let ye;e[17]!==pe?(ye=ce("oc-folder",pe),e[17]=pe,e[18]=ye):ye=e[18];const ie=A&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ue;e[19]!==ie?(ue=ce("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",ie),e[19]=ie,e[20]=ue):ue=e[20];const se=Q?void 0:l,Ne=Q?void 0:"button",Ce=Q?void 0:0;let je;e[21]!==l||e[22]!==Q?(je=Q?void 0:Z=>{(Z.key==="Enter"||Z.key===" ")&&(Z.preventDefault(),l())},e[21]=l,e[22]=Q,e[23]=je):je=e[23];let we;e[24]!==n.name||e[25]!==a||e[26]!==V?(we=a?V("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):V("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=a,e[26]=V,e[27]=we):we=e[27];const ke=B?C?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let xe;e[28]!==ke?(xe=ce("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",ke),e[28]=ke,e[29]=xe):xe=e[29];const me=A?"text-primary":"text-muted-foreground";let Me;e[30]!==me?(Me=ce("h-3.5 w-3.5 flex-shrink-0",me),e[30]=me,e[31]=Me):Me=e[31];let Ue;e[32]!==re||e[33]!==Me?(Ue=s.jsx(P,{name:re,className:Me}),e[32]=re,e[33]=Me,e[34]=Ue):Ue=e[34];let q;e[35]!==ne||e[36]!==n.name||e[37]!==W||e[38]!==K||e[39]!==F||e[40]!==a||e[41]!==A||e[42]!==Q||e[43]!==r||e[44]!==V?(q=Q?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:oI,onMouseDown:lI,onSubmit:Z=>{Z.preventDefault(),F()},children:[s.jsx("input",{ref:J,value:ne,onChange:Z=>K(Z.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:V("sessions.sidebar.folderItem.namePlaceholder"),onClick:cI,onPointerDown:dI,onMouseDown:uI,onKeyDown:Z=>{if(Z.key==="Escape"){Z.stopPropagation(),W();return}(Z.key===" "||Z.key==="Enter")&&Z.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:mI,onPointerDown:pI,onMouseDown:fI,children:s.jsx(P,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:Z=>{Z.stopPropagation(),W()},onPointerDown:hI,onMouseDown:gI,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:ce("typography-ui-label font-semibold truncate",A?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),a?s.jsx(P,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(P,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=ne,e[36]=n.name,e[37]=W,e[38]=K,e[39]=F,e[40]=a,e[41]=A,e[42]=Q,e[43]=r,e[44]=V,e[45]=q):q=e[45];let Se;e[46]!==xe||e[47]!==Ue||e[48]!==q?(Se=s.jsxs("div",{className:xe,children:[Ue,q]}),e[46]=xe,e[47]=Ue,e[48]=q,e[49]=Se):Se=e[49];let $e;e[50]!==C||e[51]!==B||e[52]!==R||e[53]!==n.name||e[54]!==le||e[55]!==z||e[56]!==d||e[57]!==I||e[58]!==j||e[59]!==Q||e[60]!==V?($e=!Q&&(!z||B)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:ce("flex items-center gap-0.5 transition-opacity",C?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",B&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!B&&I?s.jsx("button",{type:"button",onClick:Z=>{Z.stopPropagation(),I()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:V("sessions.sidebar.project.actions.newSession"),children:s.jsx(P,{name:"add",className:"h-3.5 w-3.5"})}):null,!B&&j&&R===0?s.jsx("button",{type:"button",onClick:Z=>{Z.stopPropagation(),j()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:V("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(P,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,B?null:s.jsx("button",{type:"button",onClick:Z=>{Z.stopPropagation(),le()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(P,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:Z=>{Z.stopPropagation(),d()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":B?V("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):V("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=C,e[51]=B,e[52]=R,e[53]=n.name,e[54]=le,e[55]=z,e[56]=d,e[57]=I,e[58]=j,e[59]=Q,e[60]=V,e[61]=$e):$e=e[61];let Pe;e[62]!==b||e[63]!==ue||e[64]!==se||e[65]!==Ne||e[66]!==Ce||e[67]!==je||e[68]!==we||e[69]!==Se||e[70]!==$e?(Pe=s.jsxs("div",{ref:b,className:ue,onClick:se,role:Ne,tabIndex:Ce,onKeyDown:je,"aria-label":we,children:[Se,$e]}),e[62]=b,e[63]=ue,e[64]=se,e[65]=Ne,e[66]=Ce,e[67]=je,e[68]=we,e[69]=Se,e[70]=$e,e[71]=Pe):Pe=e[71];let fe;e[72]!==B||e[73]!==m||e[74]!==a||e[75]!==u||e[76]!==p||e[77]!==r||e[78]!==i||e[79]!==V?(fe=a?null:s.jsxs("div",{className:"pb-1 pl-2",children:[i,r.length>0?r.map(Z=>p(Z,0,m??null,u??null,B)):i?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:V("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=B,e[73]=m,e[74]=a,e[75]=u,e[76]=p,e[77]=r,e[78]=i,e[79]=V,e[80]=fe):fe=e[80];let L;return e[81]!==ye||e[82]!==Pe||e[83]!==fe?(L=s.jsxs("div",{className:ye,children:[Pe,fe]}),e[81]=ye,e[82]=Pe,e[83]=fe,e[84]=L):L=e[84],L},aI=o.memo(iI);function oI(t){return t.stopPropagation()}function lI(t){return t.stopPropagation()}function cI(t){return t.stopPropagation()}function dI(t){return t.stopPropagation()}function uI(t){return t.stopPropagation()}function mI(t){return t.stopPropagation()}function pI(t){return t.stopPropagation()}function fI(t){return t.stopPropagation()}function hI(t){return t.stopPropagation()}function gI(t){return t.stopPropagation()}const xI=t=>{const e=at.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:i,children:a}=t,l=`session-drag:${n}`;let c;e[0]!==r||e[1]!==n||e[2]!==i?(c={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:i},e[0]=r,e[1]=n,e[2]=i,e[3]=c):c=e[3];let d;e[4]!==l||e[5]!==c?(d={id:l,data:c},e[4]=l,e[5]=c,e[6]=d):d=e[6];const{attributes:p,listeners:m,setNodeRef:u,isDragging:h}=Tx(d);let x;e[7]!==m?(x=g=>{g.stopPropagation(),m?.onPointerDown&&m.onPointerDown(g)},e[7]=m,e[8]=x):x=e[8];const f=x,v=h?"opacity-30":void 0;let y;return e[9]!==p||e[10]!==a||e[11]!==f||e[12]!==u||e[13]!==v?(y=s.jsx("div",{ref:u,...p,onPointerDown:f,className:v,children:a}),e[9]=p,e[10]=a,e[11]=f,e[12]=u,e[13]=v,e[14]=y):y=e[14],y},bI=t=>{const e=at.c(11),{folderId:n,children:r}=t,i=`folder-drop:${n}`;let a;e[0]!==n?(a={type:"folder",folderId:n},e[0]=n,e[1]=a):a=e[1];let l;e[2]!==i||e[3]!==a?(l={id:i,data:a},e[2]=i,e[3]=a,e[4]=l):l=e[4];const{setNodeRef:c,isOver:d}=Mx(l);let p;e[5]!==r||e[6]!==d||e[7]!==c?(p=r(c,d),e[5]=r,e[6]=d,e[7]=c,e[8]=p):p=e[8];let m;return e[9]!==p?(m=s.jsx(s.Fragment,{children:p}),e[9]=p,e[10]=m):m=e[10],m},yI=t=>{const e=at.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:i,children:a}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const c=Ja(oa(Xa,l)),[d,p]=o.useState(null),[m,u]=o.useState("Session"),[h,x]=o.useState(null),[f,v]=o.useState(null);if(!n){let N;return e[1]!==a?(N=s.jsx(s.Fragment,{children:a}),e[1]=a,e[2]=N):N=e[2],N}let y;e[3]!==i?(y=N=>{p(null),x(null),v(null);const{active:D,over:E}=N;if(!E)return;const T=D.data.current,C=E.data.current;T?.type==="session"&&T.sessionId&&C?.type==="folder"&&C.folderId&&i(T.sessionId,C.folderId)},e[3]=i,e[4]=y):y=e[4];const g=y;let w,b;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=N=>{const D=N.active.data.current;if(D?.type==="session"&&D.sessionId){p(D.sessionId),u(D.sessionTitle??"Session");const E=N.active.rect.current.initial?.width,T=N.active.rect.current.initial?.height;x(typeof E=="number"?E:null),v(typeof T=="number"?T:null)}},b=()=>{p(null),x(null),v(null)},e[5]=w,e[6]=b):(w=e[5],b=e[6]);let k;e[7]!==f||e[8]!==d||e[9]!==m||e[10]!==h||e[11]!==r?(k=d&&r?s.jsxs("div",{style:{width:h?`${h}px`:"auto",height:f?`${f}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(P,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=f,e[8]=d,e[9]=m,e[10]=h,e[11]=r,e[12]=k):k=e[12];let I;e[13]!==k?(I=s.jsx(dl,{children:k}),e[13]=k,e[14]=I):I=e[14];let j;return e[15]!==a||e[16]!==g||e[17]!==c||e[18]!==I?(j=s.jsxs(Za,{sensors:c,collisionDetection:eo,onDragStart:w,onDragCancel:b,onDragEnd:g,children:[a,I]}),e[15]=a,e[16]=g,e[17]=c,e[18]=I,e[19]=j):j=e[19],j},Mi=gr()(mo(t=>({displayMode:"default",showRecentSection:!0,setDisplayMode:e=>t({displayMode:e}),setShowRecentSection:e=>t({showRecentSection:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection}))}),{name:"session-display-mode"})),vI=50,wI=28;function jI(t){const{t:e}=ut(),{group:n,groupKey:r,projectId:i,hideGroupLabel:a,hasSessionSearchQuery:l,normalizedSessionSearchQuery:c,groupSearchDataByGroup:d,expandedSessionGroups:p,collapsedGroups:m,hideDirectoryControls:u,collapsedFolderIds:h,toggleFolderCollapse:x,renameFolder:f,deleteFolder:v,showDeletionDialog:y,setDeleteFolderConfirm:g,renderSessionNode:w,projectRepoStatus:b,lastRepoStatus:k,toggleGroupSessionLimit:I,mobileVariant:j,alwaysShowActions:N,activeProjectId:D,setActiveProjectIdOnly:E,setActiveMainTab:T,setSessionSwitcherOpen:C,openNewSessionDraft:S,addSessionToFolder:M,createFolderAndStartRename:A,renamingFolderId:R,renameFolderDraft:z,setRenameFolderDraft:B,setRenamingFolderId:V,pinnedSessionIds:$,sessionOrderIndex:_,prVisualStateByDirectoryBranch:X,onToggleCollapsedGroup:O,dragHandleProps:J,compactBodyPadding:Q=!1}=t,ne=o.useCallback((et,gt)=>{const Lt=_.get(et.session.id),Ut=_.get(gt.session.id);if(Lt!==void 0||Ut!==void 0){if(Lt===void 0)return 1;if(Ut===void 0)return-1;if(Lt!==Ut)return Lt-Ut}return ca(et.session,gt.session,$)},[$,_]),G=l?d.get(n):null,le=Mi(et=>et.displayMode),oe=Yn(et=>et.foldersMap),F=le==="minimal",U=p.has(r),W=l?!1:m.has(r),te=u?10:5,K=l?G?.groupMatches===!0:!1,ae=l,ve=o.useMemo(()=>[...ae?G?.filteredNodes??[]:n.sessions].sort(ne),[ne,n.sessions,G?.filteredNodes,ae]),re=n.folderScopeKey??xs(n.directory??null),be=o.useMemo(()=>re?oe[re]??[]:[],[re,oe]),pe=o.useMemo(()=>{const et=new Map,gt=Lt=>{Lt.forEach(Ut=>{et.set(Ut.session.id,Ut),Ut.children.length>0&>(Ut.children)})};return gt(ve),et},[ve]),ye=o.useMemo(()=>be.map(et=>{const gt=et.sessionIds.map(Lt=>pe.get(Lt)).filter(Lt=>!!Lt).sort(ne);return{folder:et,nodes:gt}}),[be,pe,ne]),ie=o.useMemo(()=>{const et=new Map(ye.map(mt=>[mt.folder.id,mt])),gt=new Map;for(const{folder:mt}of ye){if(!mt.parentId)continue;const Nt=gt.get(mt.parentId);Nt?Nt.push(mt.id):gt.set(mt.parentId,[mt.id])}const Lt=new Map,Ut=mt=>{const Nt=Lt.get(mt);if(Nt!==void 0)return Nt;const Xt=et.get(mt);if(!Xt)return Lt.set(mt,!1),!1;const _t=gt.get(mt)??[];if(n.isArchivedBucket&&Xt.nodes.length===0){const Tt=_t.some(rs=>Ut(rs));return Lt.set(mt,Tt),Tt}if(!l||Xt.folder.name.toLowerCase().includes(c)||Xt.nodes.length>0)return Lt.set(mt,!0),!0;const lt=_t.some(Tt=>Ut(Tt));return Lt.set(mt,lt),lt};return ye.filter(({folder:mt})=>Ut(mt.id))},[ye,n.isArchivedBucket,l,c]),ue=o.useMemo(()=>new Set(ie.flatMap(et=>et.folder.sessionIds)),[ie]),se=o.useMemo(()=>ve.filter(et=>!ue.has(et.session.id)),[ve,ue]),Ne=o.useMemo(()=>ie.filter(({folder:et})=>!et.parentId),[ie]),Ce=se.length,je=n.isArchivedBucket||l||U?se:se.slice(0,te),we=Ce-je.length,ke=n.isArchivedBucket===!0&&!l&&je.length>=vI,xe=o.useRef(null),[me,Me]=o.useState(null),[Ue,q]=o.useState(0),Se=Rf({count:je.length,getScrollElement:()=>me,estimateSize:()=>wI,overscan:8,enabled:ke&&me!==null,scrollMargin:Ue});o.useLayoutEffect(()=>{if(!ke){me!==null&&Me(null),Ue!==0&&q(0);return}const et=xe.current;if(!et)return;let gt=me;if(!gt||!gt.contains(et)){let Ut=et.parentElement;for(;Ut;){const mt=window.getComputedStyle(Ut);if(mt.overflowY==="auto"||mt.overflowY==="scroll"){gt=Ut;break}Ut=Ut.parentElement}if(gt!==me){Me(gt);return}}if(!gt)return;const Lt=et.getBoundingClientRect().top-gt.getBoundingClientRect().top+gt.scrollTop;q(Ut=>Math.abs(Ut-Lt)<1?Ut:Lt)}),o.useEffect(()=>{if(!ke||!me)return;const et=new ResizeObserver(()=>{Se.measure()});return et.observe(me),()=>et.disconnect()},[ke,me,Se]);const $e=Se.getTotalSize(),Pe=ke&&me!==null?Se.getVirtualItems():[];if(l&&!K&&Ne.length===0&&se.length===0)return null;const fe=et=>{const gt=[],Lt=Ut=>{Ut.forEach(mt=>{gt.push(mt.session),mt.children.length>0&&Lt(mt.children)})};return Lt(et),gt},L=fe(ve),Z=i&&b.has(i)?!!b.get(i):k,Y=xs(n.directory??null),Ee=n.branch?.trim()??null,Ae=Y&&Ee?X.get(`${Y}::${Ee}`)??null:null,Je=!!(Ae&&n.branch),de=!Ae&&!n.isMain&&!!n.branch,ze=Ae?.visualState??null,rt=Ae&&Ae.state==="open"&&Ae.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Ae.checks.success,total:Ae.checks.total}):null,Re=Ae&&Ae.state==="open"&&Ae.checks?[Ae.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:Ae.checks.failure}):null,Ae.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:Ae.checks.pending}):null].filter(et=>!!et).join(", "):null,Xe=Ae&&Ae.state==="open"?Ae.mergeableState==="blocked"||Ae.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):Ae.mergeableState==="clean"||Ae.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,qe=Ae&&Ae.state==="open"&&Ae.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Ae.mergeableState}):null,Te=Ae?.base??null,We=Ae?.head??null,Ze=(()=>{if(!Ae)return n.branch&&vy(n.branch,n.label)?{label:n.branch,color:null}:null;switch(Ae.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return Ae.canMerge===!0||Ae.mergeableState==="clean"||Ae.checks?.state==="success"?{label:e("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:e("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"};case"blocked":return{label:Ae.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked"),color:"var(--pr-blocked)"};case"draft":return{label:e("sessions.sidebar.group.pr.status.draft"),color:"var(--pr-draft)"};case"closed":return{label:e("sessions.sidebar.group.pr.status.closed"),color:"var(--pr-closed)"};default:return null}})(),Qe=Ze?.color??(ze?`var(--pr-${ze})`:void 0),he=et=>{et.preventDefault(),et.stopPropagation();const gt=Ae?.url;gt&&rr(gt)},Ge=(et,gt,Lt)=>{const Ut=ie.filter(({folder:_t})=>_t.parentId===et.id),mt=Ut.length>0?s.jsx(s.Fragment,{children:Ut.map(({folder:_t,nodes:Gt})=>Ge(_t,Gt,Lt+1))}):void 0,Nt=_t=>{const Gt=ie.find(({folder:Tt})=>Tt.id===_t)?.nodes??[],lt=ie.filter(({folder:Tt})=>Tt.parentId===_t);return[...fe(Gt),...lt.flatMap(({folder:Tt})=>Nt(Tt.id))]},Xt=n.isArchivedBucket?Nt(et.id):[];return s.jsx(bI,{folderId:et.id,children:(_t,Gt)=>s.jsx(aI,{folder:et,sessions:gt,subFolderItems:mt,isCollapsed:l?!1:h.has(et.id),onToggle:()=>x(et.id),onRename:lt=>{re&&f(re,et.id,lt)},onDelete:()=>{if(n.isArchivedBucket){Sr.requestDelete({sessions:Xt,mode:"session"});return}if(!re)return;if(!y){v(re,et.id);return}const lt=ie.filter(({folder:rs})=>rs.parentId===et.id).length,Tt=gt.length;g({scopeKey:re,folderId:et.id,folderName:et.name,subFolderCount:lt,sessionCount:Tt})},renderSessionNode:w,groupDirectory:n.directory,projectId:i,mobileVariant:j,alwaysShowActions:N,isRenaming:R===et.id,renameDraft:R===et.id?z:void 0,onRenameDraftChange:lt=>B(lt),onRenameSave:()=>{const lt=z.trim();lt&&re&&f(re,et.id,lt),V(null),B("")},onRenameCancel:()=>{V(null),B("")},droppableRef:_t,isDropTarget:Gt,depth:Lt,onNewSession:()=>{i&&i!==D&&E(i),T("chat"),j&&C(!1),S({directoryOverride:n.directory,targetFolderId:et.id})},onNewSubFolder:Lt===0?()=>{re&&A(re,et.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},et.id)},Ve=()=>Ne.map(({folder:et,nodes:gt})=>Ge(et,gt,0)),it=!!(!n.isMain&&n.worktree),dt=N?it?"pr-14":"pr-7":F?it?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":it?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",Ye=s.jsxs(yI,{scopeKey:re,hasFolders:ie.length>0,onSessionDroppedOnFolder:(et,gt)=>{re&&M(re,gt,et)},children:[Ve(),ke?s.jsx("div",{ref:xe,style:{position:"relative",height:$e>0?$e:void 0,width:"100%"},children:Pe.map(et=>{const gt=je[et.index];return gt?s.jsx("div",{"data-index":et.index,ref:Se.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${et.start-Ue}px)`},children:w(gt,0,n.directory,i,!0)},et.key):null})}):je.map(et=>w(et,0,n.directory,i,n.isArchivedBucket===!0)),Ce===0&&ie.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,we>0&&!U?s.jsx("button",{type:"button",onClick:()=>I(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:we===1?e("sessions.sidebar.group.showMoreSingle",{count:we}):e("sessions.sidebar.group.showMorePlural",{count:we})}):null,U&&Ce>te?s.jsx("button",{type:"button",onClick:()=>I(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),_e=Q?"pb-2 pl-1":"pb-3 pl-4";return a?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:ce("oc-group-body",_e),children:Ye})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:ce("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>O(r),role:"button",tabIndex:0,onKeyDown:et=>{(et.key==="Enter"||et.key===" ")&&(et.preventDefault(),O(r))},"aria-label":W?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!W,children:[s.jsx("div",{ref:J?.setActivatorNodeRef,className:ce("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",dt),...J?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:Je&&Ae?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(P,{name:"git-branch",className:ce("h-3.5 w-3.5 shrink-0",N?"hidden":"group-hover/gh:hidden"),style:Qe?{color:Qe}:void 0}),s.jsx("span",{className:ce("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:W?s.jsx(P,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),Ae.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:et=>et.stopPropagation(),onClick:he,children:["#",Ae.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Ae.number]})]})}),s.jsx(Dt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Te||We?s.jsx("div",{className:"text-muted-foreground truncate",children:Te&&We?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Te}),s.jsx(P,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:We})]}):s.jsx("span",{children:Te??We??""})}):null,qe?s.jsx("div",{className:"text-muted-foreground truncate",children:qe}):null,Xe||rt?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Xe??"",Xe&&rt?" • ":"",rt??"",Re?` (${Re})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:n.branch})]}):n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(P,{name:"archive",className:ce("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:ce("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:W?s.jsx(P,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ga(n.label,c)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(P,{name:"git-branch",className:ce("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden"),style:Qe?{color:Qe}:void 0}),s.jsx("span",{className:ce("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:W?s.jsx(P,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ga(n.label,c)})]}):Ga(n.label,c)}),de&&Ze?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(P,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||Z?Je&&Ae?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(P,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:Qe?{color:Qe}:void 0})})}),s.jsx(Dt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Te||We?s.jsx("div",{className:"text-muted-foreground truncate",children:Te&&We?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Te}),s.jsx(P,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:We})]}):s.jsx("span",{children:Te??We??""})}):null,qe?s.jsx("div",{className:"text-muted-foreground truncate",children:qe}):null,Xe||rt?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Xe??"",Xe&&rt?" • ":"",rt??"",Re?` (${Re})`:""]}):null]})})]}):s.jsx(P,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Qe?{color:Qe}:void 0}):null,s.jsx("span",{className:ce("min-w-0 truncate text-[11px] font-medium",!Ze.color&&"text-muted-foreground/80"),style:Ze.color?{color:Ze.color}:void 0,children:Ze.label})]}):null]})}),n.isArchivedBucket&&L.length>0?s.jsx("div",{className:ce("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:et=>{et.stopPropagation(),Sr.requestDelete({sessions:L,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(P,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:ce("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:et=>{et.stopPropagation(),Sr.requestDelete({sessions:L,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(P,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:ce("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:et=>{et.stopPropagation(),i&&i!==D&&E(i),T("chat"),j&&C(!1),S({directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(P,{name:"add",className:"h-4 w-4"})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),W?null:s.jsx("div",{className:ce("oc-group-body",_e),children:Ye})]})}function NI(t){const e=at.c(37),{t:n}=ut(),{hideDirectoryControls:r,handleOpenDirectoryDialog:i,handleNewSession:a,canOpenMultiRun:l,openMultiRunLauncher:c,headerActionIconClass:d,reserveHeaderActionsSpace:p,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:h,sessionSearchInputRef:x,sessionSearchQuery:f,setSessionSearchQuery:v,hasSessionSearchQuery:y,searchMatchCount:g,collapseAllProjects:w,expandAllProjects:b,openScheduledTasksDialog:k,selectionModeEnabled:I,onToggleSelectionMode:j,showSidebarToggle:N,onToggleSidebar:D,avoidWindowControlsOverlay:E}=t,T=N===void 0?!1:N,C=E===void 0?!1:E,S=Mi(II),M=Mi(PI),A=Mi(CI),R=Mi(kI);if(r)return null;const z=T?C?"pl-[5.5rem] pr-3":"pl-3 pr-3":"px-2.5 py-1";let B;e[0]!==z?(B=ce("select-none flex-shrink-0",z),e[0]=z,e[1]=B):B=e[1];let V;e[2]!==C||e[3]!==T?(V=T&&C?{paddingTop:"var(--oc-safe-area-top, 0px)"}:void 0,e[2]=C,e[3]=T,e[4]=V):V=e[4];let $;e[5]!==C||e[6]!==l||e[7]!==w||e[8]!==S||e[9]!==b||e[10]!==a||e[11]!==i||e[12]!==y||e[13]!==m||e[14]!==d||e[15]!==u||e[16]!==j||e[17]!==D||e[18]!==c||e[19]!==k||e[20]!==p||e[21]!==g||e[22]!==I||e[23]!==x||e[24]!==f||e[25]!==A||e[26]!==h||e[27]!==v||e[28]!==M||e[29]!==T||e[30]!==n||e[31]!==R?($=p?s.jsxs("div",{className:ce("flex h-auto flex-col gap-1",T?C?"min-h-[calc(var(--oc-header-height,56px)-var(--oc-safe-area-top,0px))] justify-center":"min-h-[var(--oc-header-height,56px)] justify-center":"min-h-8"),children:[s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[T&&D?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50","aria-label":n("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(P,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.closeSessions")})})]}):null,s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:m,"aria-label":n("sessions.sidebar.header.actions.addProject"),children:s.jsx(P,{name:"folder-add",className:d})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.addProject")})})]}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:m,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(P,{name:"chat-new",className:d})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:m,"aria-label":n("sessions.sidebar.header.actions.newMultiRun"),disabled:!l,children:s.jsx(wy,{className:d})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newMultiRun")})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:k,className:m,"aria-label":n("sessions.sidebar.header.actions.scheduledTasks"),children:s.jsx(P,{name:"calendar-schedule",className:d})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.scheduledTasks")})})]}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>h(SI),className:m,"aria-label":n("sessions.sidebar.header.actions.searchSessions"),"aria-expanded":u,children:s.jsx(P,{name:"search",className:d})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.searchSessions")})})]}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:ce(m,I&&"bg-interactive-hover text-primary"),"aria-label":n(I?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),"aria-pressed":I,children:s.jsx(P,{name:"checkbox-multiple",className:d})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n(I?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions")})})]}),s.jsxs(Fs,{children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":n("sessions.sidebar.header.actions.sessionDisplayMode"),children:s.jsx(P,{name:"equalizer-2",className:d})})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.displayMode.label")})})]}),s.jsxs(Rs,{align:"end",className:"min-w-[160px]",children:[s.jsxs($t,{onClick:()=>A("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),S==="default"?s.jsx(P,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs($t,{onClick:()=>A("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),S==="minimal"?s.jsx(P,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Cn,{}),s.jsxs($t,{onClick:R,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),M?s.jsx(P,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Cn,{}),s.jsxs($t,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(P,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs($t,{onClick:b,className:"flex items-center gap-2",children:[s.jsx(P,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]})]})]})]}),u?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[y?s.jsx("span",{children:g===1?n("sessions.sidebar.header.search.matchCountSingle",{count:g}):n("sessions.sidebar.header.search.matchCountPlural",{count:g})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(P,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:x,value:f,onChange:X=>v(X.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:X=>{X.key==="Escape"&&(X.stopPropagation(),y?v(""):h(!1))}}),f.length>0?s.jsx("button",{type:"button",onClick:()=>v(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[5]=C,e[6]=l,e[7]=w,e[8]=S,e[9]=b,e[10]=a,e[11]=i,e[12]=y,e[13]=m,e[14]=d,e[15]=u,e[16]=j,e[17]=D,e[18]=c,e[19]=k,e[20]=p,e[21]=g,e[22]=I,e[23]=x,e[24]=f,e[25]=A,e[26]=h,e[27]=v,e[28]=M,e[29]=T,e[30]=n,e[31]=R,e[32]=$):$=e[32];let _;return e[33]!==B||e[34]!==V||e[35]!==$?(_=s.jsx("div",{className:B,style:V,children:$}),e[33]=B,e[34]=V,e[35]=$,e[36]=_):_=e[36],_}function SI(t){return!t}function kI(t){return t.toggleRecentSection}function CI(t){return t.setDisplayMode}function PI(t){return t.showRecentSection}function II(t){return t.displayMode}const uf=7;function AI(t){const e=at.c(20),{sections:n,renderSessionNode:r}=t,{t:i}=ut();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[l,c]=o.useState(a);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[p,m]=o.useState(d);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=b=>{c(k=>{const I=new Set(k);return I.has(b)?I.delete(b):I.add(b),I})},e[2]=u):u=e[2];const h=u;let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=b=>{m(k=>{const I=new Set(k);return I.has(b)?I.delete(b):I.add(b),I})},e[3]=x):x=e[3];const f=x;let v,y,g;if(e[4]!==l||e[5]!==p||e[6]!==r||e[7]!==n||e[8]!==i){g=Symbol.for("react.early_return_sentinel");e:{const b=n.filter(DI);if(b.length===0){g=null;break e}v="space-y-2 pb-2 pt-1";let k;e[12]!==l||e[13]!==p||e[14]!==r||e[15]!==i?(k=I=>{const j=l.has(I.key),N=p.has(I.key),D=N?I.items:I.items.slice(0,uf),E=I.items.length-D.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>h(I.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?s.jsx(P,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:I.title})]}),j?null:s.jsxs("div",{className:ce("space-y-0.5 pl-7"),children:[D.map(T=>r(T.node,0,T.groupDirectory,T.projectId,!1,T.secondaryMeta,"recent")),E>0&&!N?s.jsx("button",{type:"button",onClick:()=>f(I.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:E===1?i("sessions.sidebar.group.showMoreSingle",{count:E}):i("sessions.sidebar.group.showMorePlural",{count:E})}):null,N&&I.items.length>uf?s.jsx("button",{type:"button",onClick:()=>f(I.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:i("sessions.sidebar.group.showFewer")}):null]})]},I.key)},e[12]=l,e[13]=p,e[14]=r,e[15]=i,e[16]=k):k=e[16],y=b.map(k)}e[4]=l,e[5]=p,e[6]=r,e[7]=n,e[8]=i,e[9]=v,e[10]=y,e[11]=g}else v=e[9],y=e[10],g=e[11];if(g!==Symbol.for("react.early_return_sentinel"))return g;let w;return e[17]!==v||e[18]!==y?(w=s.jsx("div",{className:v,children:y}),e[17]=v,e[18]=y,e[19]=w):w=e[19],w}function DI(t){return t.items.length>0}const $c="inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50";function TI(t){const e=at.c(8),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:i,showRuntimeButtons:a}=t,l=a===void 0?!0:a,{t:c}=ut();let d;e[0]!==i||e[1]!==n||e[2]!==r||e[3]!==l||e[4]!==c?(d=l?s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:$c,"aria-label":c("sessions.sidebar.footer.actions.settings"),children:s.jsx(P,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:c("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:$c,"aria-label":c("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(P,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:c("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:$c,"aria-label":c("sessions.sidebar.footer.actions.aboutVinci"),children:s.jsx(P,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:c("sessions.sidebar.footer.actions.aboutVinci")})})]})]}):null,e[0]=i,e[1]=n,e[2]=r,e[3]=l,e[4]=c,e[5]=d):d=e[5];let p;return e[6]!==d?(p=s.jsx("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:d}),e[6]=d,e[7]=p):p=e[7],p}const MI=t=>{const e=at.c(58),{id:n,projectLabel:r,projectDescription:i,projectIcon:a,projectColor:l,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:h,isStuck:x,hideDirectoryControls:f,alwaysShowActions:v,onToggle:y,onNewSession:g,onNewWorktreeSession:w,onRenameStart:b,onClose:k,sentinelRef:I,children:j,showCreateButtons:N,hideHeader:D,openSidebarMenuKey:E,setOpenSidebarMenuKey:T}=t,C=N===void 0?!0:N,S=D===void 0?!1:D,{t:M}=ut(),{currentTheme:A}=Ar();let R;e[0]!==n?(R={id:n},e[0]=n,e[1]=R):R=e[1];const{attributes:z,listeners:B,setNodeRef:V,transform:$,transition:_,isDragging:X}=Dl(R),[O,J]=o.useState(!1),Q=o.useRef(!1),ne=`project:${n}`,G=E===ne;let le;e[2]===Symbol.for("react.memo_cache_sentinel")?(le=()=>{J(!1)},e[2]=le):le=e[2];const oe=c?.updatedAt;let F;e[3]!==n||e[4]!==oe?(F=[n,oe],e[3]=n,e[4]=oe,e[5]=F):F=e[5],o.useEffect(le,F);const U=a?Vl[a]:null,W=l?bo[l]??null:null;let te;e[6]!==A||e[7]!==n||e[8]!==O||e[9]!==c?(te=O?null:xo({id:n,iconImage:c},{themeVariant:A.metadata.variant,iconColor:A.colors.surface.foreground}),e[6]=A,e[7]=n,e[8]=O,e[9]=c,e[10]=te):te=e[10];const K=te;let ae;e[11]!==ne||e[12]!==T?(ae=me=>{T(me?ne:null)},e[11]=ne,e[12]=T,e[13]=ae):ae=e[13];const ve=ae,re=FI,be=LI,pe=OI;let ye;e[14]===Symbol.for("react.memo_cache_sentinel")?(ye=me=>{(me.button===2||me.button===0&&me.ctrlKey)&&(Q.current=!0)},e[14]=ye):ye=e[14];const ie=ye;let ue;e[15]!==y?(ue=()=>{if(Q.current){Q.current=!1;return}y()},e[15]=y,e[16]=ue):ue=e[16];const se=ue;let Ne;e[17]!==$?(Ne=Tl.Transform.toString($),e[17]=$,e[18]=Ne):Ne=e[18];let Ce;e[19]!==Ne||e[20]!==_?(Ce={transform:Ne,transition:_},e[19]=Ne,e[20]=_,e[21]=Ce):Ce=e[21];const je=X&&"opacity-30";let we;e[22]!==je?(we=ce("relative",je),e[22]=je,e[23]=we):we=e[23];let ke;e[24]!==v||e[25]!==z||e[26]!==ve||e[27]!==se||e[28]!==f||e[29]!==S||e[30]!==W||e[31]!==n||e[32]!==K||e[33]!==m||e[34]!==p||e[35]!==h||e[36]!==G||e[37]!==u||e[38]!==x||e[39]!==B||e[40]!==k||e[41]!==g||e[42]!==w||e[43]!==b||e[44]!==i||e[45]!==d||e[46]!==U||e[47]!==r||e[48]!==I||e[49]!==C||e[50]!==M?(ke=S?null:s.jsxs(s.Fragment,{children:[h&&s.jsx("div",{ref:I,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:ce("w-full text-left group/project select-none"),style:{backgroundColor:h&&x?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...z,children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:ie,onClick:se,...B,className:ce("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",u&&!f?v?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":v?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:ce("h-3.5 w-3.5 items-center justify-center text-muted-foreground",v?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:p?s.jsx(P,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),K?s.jsx("span",{className:ce("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",v?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:K,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>J(!0)})}):U?s.jsx(P,{name:U,className:ce("h-3.5 w-3.5",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:W?{color:W}:void 0}):s.jsx(P,{name:"folder",className:ce("h-3.5 w-3.5 text-muted-foreground/80",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:W?{color:W}:void 0})]}),s.jsx("span",{className:ce("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(Dt,{side:"right",sideOffset:8,children:i})]}),s.jsxs("div",{className:ce("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",C?"right-7":"right-0.5"),children:[C&&u&&!f&&w?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),w()},className:ce("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(P,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(Fs,{open:G,onOpenChange:ve,children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:ce("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",G?"opacity-100 pointer-events-auto":v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.projectMenu"),onPointerDown:be,onMouseDown:pe,onClick:re,children:s.jsx(P,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(Rs,{align:"end",className:"min-w-[180px]",children:[C&&!u&&!f&&g&&s.jsxs($t,{onClick:g,children:[s.jsx(P,{name:"add",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.newSession")]}),s.jsxs($t,{onClick:b,children:[s.jsx(P,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.session.menu.rename")]}),s.jsxs($t,{onClick:k,className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.closeProject")]})]})]})]}),C&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),g()},className:ce("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(P,{name:"add",className:"h-4 w-4"})})}),s.jsx(Dt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=v,e[25]=z,e[26]=ve,e[27]=se,e[28]=f,e[29]=S,e[30]=W,e[31]=n,e[32]=K,e[33]=m,e[34]=p,e[35]=h,e[36]=G,e[37]=u,e[38]=x,e[39]=B,e[40]=k,e[41]=g,e[42]=w,e[43]=b,e[44]=i,e[45]=d,e[46]=U,e[47]=r,e[48]=I,e[49]=C,e[50]=M,e[51]=ke):ke=e[51];let xe;return e[52]!==j||e[53]!==V||e[54]!==Ce||e[55]!==we||e[56]!==ke?(xe=s.jsxs("div",{ref:V,style:Ce,className:we,children:[ke,j]}),e[52]=j,e[53]=V,e[54]=Ce,e[55]=we,e[56]=ke,e[57]=xe):xe=e[57],xe},EI=t=>{const e=at.c(21),{id:n,disabled:r,children:i}=t,a=r===void 0?!1:r;let l;e[0]!==a||e[1]!==n?(l={id:n,disabled:a},e[0]=a,e[1]=n,e[2]=l):l=e[2];const{listeners:c,setNodeRef:d,setActivatorNodeRef:p,transform:m,transition:u,isDragging:h}=Dl(l);let x;e[3]!==c||e[4]!==p?(x={listeners:c,setActivatorNodeRef:p},e[3]=c,e[4]=p,e[5]=x):x=e[5];const f=x;let v;e[6]!==m?(v=Tl.Transform.toString(m),e[6]=m,e[7]=v):v=e[7];let y;e[8]!==v||e[9]!==u?(y={transform:v,transition:u},e[8]=v,e[9]=u,e[10]=y):y=e[10];const g=h&&"opacity-50";let w;e[11]!==g?(w=ce("space-y-0.5 rounded-md",g),e[11]=g,e[12]=w):w=e[12];let b;e[13]!==i||e[14]!==f?(b=typeof i=="function"?i(f):i,e[13]=i,e[14]=f,e[15]=b):b=e[15];let k;return e[16]!==d||e[17]!==y||e[18]!==w||e[19]!==b?(k=s.jsx("div",{ref:d,style:y,className:w,children:b}),e[16]=d,e[17]=y,e[18]=w,e[19]=b,e[20]=k):k=e[20],k},RI=o.memo(EI);function FI(t){t.stopPropagation()}function LI(t){t.stopPropagation()}function OI(t){t.stopPropagation()}function $I(t){const e=at.c(25),{t:n}=ut();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let i;e[1]===Symbol.for("react.memo_cache_sentinel")?(i={coordinateGetter:Rx},e[1]=i):i=e[1];const a=Ja(oa(Xa,r),oa(Ex,i));let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[2]=l):l=e[2];const c=Ja(oa(Xa,l));if(t.projectSections.length===0){const h=(t.mobileVariant,"");let x;e[3]!==h?(x=ce("space-y-1 pb-1 pl-2.5 pr-2",h),e[3]=h,e[4]=x):x=e[4];let f;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==x?(f=s.jsxs(Cs,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:x,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=x,e[8]=f):f=e[8],f}if(t.sectionsForRender.length===0){const h=(t.mobileVariant,"");let x;e[9]!==h?(x=ce("space-y-1 pb-1 pl-2.5 pr-2",h),e[9]=h,e[10]=x):x=e[10];let f;return e[11]!==t.searchEmptyState||e[12]!==x?(f=s.jsx(Cs,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:x,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=x,e[13]=f):f=e[13],f}const d=(t.mobileVariant,"");let p;e[14]!==d?(p=ce("space-y-1 pb-1 pl-2.5 pr-2",d),e[14]=d,e[15]=p):p=e[15];let m;e[16]!==c||e[17]!==a||e[18]!==t||e[19]!==n?(m=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const h=t.sectionsForRender.find(y=>y.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!h)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const x=h.groups.find(HI)??h.groups.find(KI)??h.groups.find(WI)??h.groups[0];if(!x)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const f=h.groups.find(UI);return[x,...f&&f.id!==x.id?[f]:[]].map(y=>{const g=`${h.project.id}:${y.id}`,w=y.id===x.id;return s.jsx(o.Fragment,{children:t.renderGroupSessions(y,g,h.project.id,w,null,!0)},g)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Za,{sensors:a,collisionDetection:eo,onDragEnd:h=>{if(t.isInlineEditing)return;const{active:x,over:f}=h;if(!f||x.id===f.id)return;const v=t.sectionsForRender.findIndex(g=>g.project.id===x.id),y=t.sectionsForRender.findIndex(g=>g.project.id===f.id);v===-1||y===-1||v===y||t.reorderProjects(v,y)},children:[s.jsx(cl,{items:t.sectionsForRender.map(_I),strategy:Hc,children:t.sectionsForRender.map(h=>{const x=h.project,f=x.id,v=mh(x.label?.trim()||Vi(x.normalizedPath,t.homeDirectory)||x.normalizedPath),y=ro(x.normalizedPath,t.homeDirectory),g=t.collapsedProjects.has(f),w=f===t.activeProjectId,b=t.projectRepoStatus.get(f),k=t.getOrderedGroups(f,h.groups),I=k.find(VI)??null,j=I?k.filter(N=>N.id!==I.id):k;return s.jsx(MI,{id:f,projectLabel:v,projectDescription:y,projectIcon:x.icon,projectColor:x.color,projectIconImage:x.iconImage,projectIconBackground:x.iconBackground,isCollapsed:g,isActiveProject:w,isRepo:!!b,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(f),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(f),onNewSession:()=>{f!==t.activeProjectId&&t.setActiveProjectIdOnly(f),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:x.normalizedPath})},onNewWorktreeSession:()=>{f!==t.activeProjectId&&t.setActiveProjectIdOnly(f),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(f),onClose:()=>t.removeProject(f),sentinelRef:N=>{t.projectHeaderSentinelRefs.current.set(f,N)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:g?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:h.groups.length>0?s.jsxs(Za,{sensors:c,collisionDetection:eo,onDragEnd:N=>{if(t.isInlineEditing)return;const{active:D,over:E}=N;if(!E||D.id===E.id)return;const T=j.findIndex(A=>A.id===D.id),C=j.findIndex(A=>A.id===E.id);if(T===-1||C===-1||T===C)return;const S=Ef(j,T,C).map(zI),M=I?[I.id,...S]:S;t.setGroupOrderByProject(A=>{const R=new Map(A);return R.set(f,M),R})},children:[I?t.renderGroupSessions(I,`${f}:${I.id}`,f,!0):null,s.jsx(cl,{items:j.map(BI),strategy:Hc,children:j.map(N=>{const D=`${f}:${N.id}`;return s.jsx(RI,{id:N.id,disabled:t.isInlineEditing,children:E=>t.renderGroupSessions(N,D,f,!1,E)},N.id)})}),s.jsx(dl,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},f)})}),s.jsx(dl,{dropAnimation:null})]})}),e[16]=c,e[17]=a,e[18]=t,e[19]=n,e[20]=m):m=e[20];let u;return e[21]!==t.topContent||e[22]!==p||e[23]!==m?(u=s.jsxs(Cs,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:p,children:[t.topContent,m]}),e[21]=t.topContent,e[22]=p,e[23]=m,e[24]=u):u=e[24],u}function BI(t){return t.id}function zI(t){return t.id}function VI(t){return t.isMain}function _I(t){return t.project.id}function UI(t){return t.isArchivedBucket}function WI(t){return t.isMain}function KI(t){return t.sessions.length>0}function HI(t){return t.isMain&&t.sessions.length>0}function GI(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(void 0,{month:"short"}),r=e.getDate(),i=e.getFullYear(),a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${i}, ${a}:${l}`}function qI(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function YI(t){const e=t.info.role==="user"?"User":"Assistant",n=GI(t.info.time?.created),r=qI(t),i=n&&r?`${n} (${r})`:n||r;return i?`**${e}**
|
|
183
|
+
|
|
184
|
+
*${i}*`:`**${e}**`}function QI(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Rg(t){const e=YI(t),n=QI(t.parts).trim();return n?`${e}
|
|
185
|
+
|
|
186
|
+
${n}`:""}function Fg(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",i=`${n} Sub-agent: ${t.title}${r}
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
`,a=t.records.map(Rg).filter(Boolean).join(`
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
`),l=[i+a];for(const c of t.children)l.push(Fg(c,e+1));return l.join(`
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
`)}function JI(t,e,n){const r=e?.trim()||"Session",i=new Date().toISOString().split("T")[0],a=`# ${r}
|
|
199
|
+
|
|
200
|
+
*Exported on ${i}*
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
`,l=t.map(Rg).filter(Boolean).join(`
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
`);let c=a+l;if(n&&n.length>0){const d=n.map(p=>Fg(p,1)).join(`
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
`);c+=`
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
`+d}return c}function XI(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}async function ZI(t,e){const n=await jy(e,t);if(n)return n;if(!mn())return null;try{const r=await fetch("/api/vscode/save-markdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileName:e,content:t})});if(!r.ok)return null;const i=await r.json();if(i.saved!==!0)return null;const a=typeof i.path=="string"?i.path.trim():"";return a.length>0?a:null}catch{return null}}async function eA(t){const e=pr()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Ny(t)?!0:ul(t)}function tA(){return Od()}function sA(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",i=new Date().toISOString().split("T")[0];return`${r}-${i}.md`}const nA=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const i of t){r.has(i)||(r.add(i),n.push(i));const a=e.get(i);if(a)for(const l of a)r.has(l)||(r.add(l),n.push(l))}return n},ur=gr()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,i)=>{const a=e(),l=new Set(a.selectedIds);let c=a.scopeKey,d=a.anchorId;r!==null&&a.scopeKey!==null&&r!==a.scopeKey?(l.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const m=i&&i.length>0?[n,...i]:[n];if(l.has(n)){for(const h of m)l.delete(h);d===n&&(d=null)}else{for(const h of m)l.add(h);d=n}l.size===0?t({selectedIds:l,scopeKey:null,anchorId:null}):t({selectedIds:l,scopeKey:c,anchorId:d})},setRange:(n,r,i,a,l)=>{const c=e();if(i.length===0)return;const d=n&&i.includes(n)?n:i[0],p=i.indexOf(d),m=i.indexOf(r);if(p<0||m<0)return;const[u,h]=p<=m?[p,m]:[m,p],x=i.slice(u,h+1),f=nA(x,l),y=a!==null&&c.scopeKey!==null&&a!==c.scopeKey?new Set:new Set(c.selectedIds);for(const g of f)y.add(g);t({selectedIds:y,scopeKey:a??c.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const i=new Set(r.selectedIds);for(const a of n)i.delete(a);i.size!==r.selectedIds.size&&(i.size===0?t({selectedIds:i,scopeKey:null,anchorId:null}):t({selectedIds:i}))}})),rA=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,ll=t=>{if(!t)return null;const e=t.split("/");if(e.length!==3&&e.length!==4)return null;const[n,r,i,a]=e;if(!rA.test(n)||!r?.trim()||!i?.trim()||r!==r.trim()||i!==i.trim())return null;if(e.length===3)return{groupSlug:n,providerID:r,modelID:i,fusion:!1};if(a==="fusion")return{groupSlug:n,providerID:r,modelID:i,fusion:!0};if(!/^\d+$/.test(a))return null;const l=Number.parseInt(a,10);return!Number.isSafeInteger(l)||l<=0?null:{groupSlug:n,providerID:r,modelID:i,index:l,fusion:!1}},iA=(t,e,n)=>`${t}/${e}/${n}/fusion`,Lg=t=>{const e=at.c(35),{value:n,onChange:r,className:i,disabled:a,id:l,portalToBody:c}=t,{t:d}=ut(),p=xt(aA),m=xt(oA),u=xt(lA);let h;e[0]!==p?(h=p(),e[0]=p,e[1]=h):h=e[1];const x=h;let f;e[2]!==x?(f=x.filter(cA),e[2]=x,e[3]=f):f=e[3];const v=f;let y,g;e[4]!==m?(y=()=>{m()},g=[m],e[4]=m,e[5]=y,e[6]=g):(y=e[5],g=e[6]),o.useEffect(y,g);let w,b;e[7]!==u||e[8]!==a||e[9]!==r||e[10]!==v||e[11]!==n?(w=()=>{if(a)return;const S=n.trim();if(S.length>0&&v.some(R=>R.name===S))return;const M=typeof u=="string"&&u.trim().length>0?u.trim():null;if(M&&v.some(R=>R.name===M)){r(M);return}const A=v[0]?.name;A&&r(A)},b=[u,a,r,v,n],e[7]=u,e[8]=a,e[9]=r,e[10]=v,e[11]=n,e[12]=w,e[13]=b):(w=e[12],b=e[13]),o.useEffect(w,b);const k=n.trim().length>0?n:void 0;let I;e[14]!==i?(I=ce("max-w-full typography-meta text-foreground !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 data-[popup-open]:!bg-[var(--interactive-active)]/70",i),e[14]=i,e[15]=I):I=e[15];let j;e[16]!==d?(j=d("multirun.agentSelector.placeholder"),e[16]=d,e[17]=j):j=e[17];let N;e[18]!==j?(N=s.jsx(us,{placeholder:j}),e[18]=j,e[19]=N):N=e[19];let D;e[20]!==l||e[21]!==I||e[22]!==N?(D=s.jsx(as,{id:l,size:"lg",className:I,children:N}),e[20]=l,e[21]=I,e[22]=N,e[23]=D):D=e[23];let E;e[24]!==v?(E=v.length>0&&s.jsx(Xc,{children:v.map(dA)}),e[24]=v,e[25]=E):E=e[25];let T;e[26]!==c||e[27]!==E?(T=s.jsx(os,{fitContent:!0,portalToBody:c,children:E}),e[26]=c,e[27]=E,e[28]=T):T=e[28];let C;return e[29]!==a||e[30]!==r||e[31]!==k||e[32]!==D||e[33]!==T?(C=s.jsxs(is,{value:k,onValueChange:r,disabled:a,children:[D,T]}),e[29]=a,e[30]=r,e[31]=k,e[32]=D,e[33]=T,e[34]=C):C=e[34],C};function aA(t){return t.getVisibleAgents}function oA(t){return t.loadAgents}function lA(t){return t.currentAgentName}function cA(t){return t.mode!=="subagent"}function dA(t){return s.jsx(Ft,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Og="h-7",Il=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,uA=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),mA=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=uA.format(t);return e.endsWith(".0")?e.slice(0,-2):e},pA=t=>{const e=at.c(12),{model:n,instanceIndex:r,totalSameModel:i,onRemove:a}=t,l=n.displayName||`${n.providerID}/${n.modelID}`,c=i>1?`${l} (${r})`:l;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=ce("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Og),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(vn,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=p):p=e[2];let m;e[3]!==c?(m=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:c}),e[3]=c,e[4]=m):m=e[4];let u;e[5]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(P,{name:"close",className:"h-3.5 w-3.5"}),e[5]=u):u=e[5];let h;e[6]!==a?(h=s.jsx("button",{type:"button",onClick:a,className:"text-muted-foreground hover:text-foreground ml-0.5",children:u}),e[6]=a,e[7]=h):h=e[7];let x;return e[8]!==p||e[9]!==m||e[10]!==h?(x=s.jsxs("div",{className:d,children:[p,m,h]}),e[8]=p,e[9]=m,e[10]=h,e[11]=x):x=e[11],x},$g=({selectedModels:t,onAdd:e,onRemove:n,onUpdate:r,minModels:i,addButtonLabel:a,showChips:l=!0,maxModels:c,addButtonClassName:d,dropdownSide:p="top",dropdownClassName:m,containerClassName:u,triggerIcon:h})=>{const{t:x}=ut(),f=xt(G=>G.providers),v=xt(G=>G.modelsMetadata),{favoriteModelsList:y,recentModelsList:g}=qf(),[w,b]=o.useState(!1),[k,I]=o.useState(""),[j,N]=o.useState(0),[D,E]=o.useState(null),T=o.useRef(null),C=o.useRef(null),S=o.useRef(null),M=o.useRef([]),A=c===1,R=c===void 0||t.length<c||A,z=o.useMemo(()=>{const G=new Map;for(const le of t){const oe=`${le.providerID}:${le.modelID}`;G.set(oe,(G.get(oe)||0)+1)}return G},[t]),B=o.useCallback(G=>t.filter(oe=>oe.providerID===G.providerID&&oe.modelID===G.modelID).findIndex(oe=>oe.instanceId===G.instanceId)+1,[t]),V=(G,le)=>{const oe=`${G}/${le}`;return v.get(oe)},$=G=>{const le=G?.name||G?.id||"",oe=String(le);return oe.length>40?oe.substring(0,37)+"...":oe},_=o.useCallback((G,le)=>{if(!k.trim())return!0;const oe=k.toLowerCase();return G.toLowerCase().includes(oe)||le.toLowerCase().includes(oe)},[k]),X=o.useMemo(()=>y.filter(({model:G,providerID:le})=>{const F=f.find(W=>W.id===le)?.name||le,U=$(G);return _(U,F)}),[y,f,_]),O=o.useMemo(()=>g.filter(({model:G,providerID:le})=>{const F=f.find(W=>W.id===le)?.name||le,U=$(G);return _(U,F)}),[g,f,_]),J=o.useMemo(()=>f.map(G=>{const oe=(Array.isArray(G.models)?G.models:[]).filter(F=>{const U=$(F);return _(U,G.name||G.id||"")});return{...G,models:oe}}).filter(G=>G.models.length>0),[f,_]),Q=X.length>0||O.length>0||J.length>0;o.useEffect(()=>{if(!w||!S.current)return;const G=S.current.getBoundingClientRect();if(p==="bottom"){const te=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-G.bottom-16-112;E(Math.max(160,Math.min(320,te)));return}let le=S.current.parentElement;for(;le&&!(le.getAttribute("role")==="dialog"||le.hasAttribute("data-scroll-shadow"));){const U=getComputedStyle(le);if(U.overflow==="auto"||U.overflow==="hidden"||U.overflowY==="auto"||U.overflowY==="hidden")break;le=le.parentElement}const oe=le?le.getBoundingClientRect().top:0,F=G.top-oe-16;E(Math.max(150,Math.min(300,F)))},[p,w]),o.useEffect(()=>{w&&T.current&&T.current.focus()},[w]),o.useEffect(()=>{!R&&w&&(b(!1),I(""),N(0))},[R,w]),o.useEffect(()=>{if(!w)return;const G=le=>{C.current&&!C.current.contains(le.target)&&(b(!1),I(""),N(0))};return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[w]),o.useEffect(()=>{N(0)},[k]);const ne=(G,le,oe,F,U,W)=>{const te=`${le}:${oe}`,K=z.get(te)||0,ae=V(le,oe),ve=mA(ae?.limit?.context),re=F==="fav"||F==="recent";return s.jsxs("button",{ref:be=>{M.current[U]=be},type:"button",disabled:!R,onClick:()=>{const be={providerID:le,modelID:oe,displayName:G.name||oe,instanceId:Il()};if(A&&t.length>0&&r){r(0,be),b(!1),I(""),N(0);return}e({...be}),A&&(b(!1),I(""),N(0))},onMouseEnter:()=>N(U),className:ce("w-full text-left px-2 py-1.5 rounded-md typography-meta transition-colors flex items-center gap-2",R&&(W?"bg-interactive-selection":"hover:bg-interactive-hover/50"),!R&&"cursor-not-allowed opacity-60"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[re&&s.jsx(vn,{providerId:le,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(G)}),ve&&s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:ve})]}),K>0&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:["×",K]})]},`${F}-${te}`)};return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[s.jsxs("div",{className:ce("relative",u),ref:C,children:[s.jsxs(ge,{ref:S,type:"button",variant:"outline",size:"sm",className:ce(Og,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",d),disabled:!R,onClick:()=>{b(!w)},children:[h??s.jsx(P,{name:"add",className:"h-3.5 w-3.5 mr-1"}),a??x("multirun.modelMultiSelect.actions.addModel")]}),w&&(()=>{const G=[];X.forEach(({model:U,providerID:W,modelID:te})=>{G.push({model:U,providerID:W,modelID:te,section:"fav"})}),O.forEach(({model:U,providerID:W,modelID:te})=>{G.push({model:U,providerID:W,modelID:te,section:"recent"})}),J.forEach(U=>{U.models.forEach(W=>{G.push({model:W,providerID:U.id,modelID:W.id,section:"provider"})})});const le=G.length,oe=U=>{if(!Sy(U))if(U.key==="ArrowDown"){U.preventDefault(),U.stopPropagation();const W=(j+1)%Math.max(1,le);N(W),setTimeout(()=>{M.current[W]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(U.key==="ArrowUp"){U.preventDefault(),U.stopPropagation();const W=(j-1+Math.max(1,le))%Math.max(1,le);N(W),setTimeout(()=>{M.current[W]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(U.key==="Enter"){U.preventDefault(),U.stopPropagation();const W=G[j];if(W&&R){const te={providerID:W.providerID,modelID:W.modelID,displayName:W.model.name||W.modelID,instanceId:Il()};A&&t.length>0&&r?r(0,te):e(te),A&&(b(!1),I(""),N(0))}}else U.key==="Escape"&&(U.preventDefault(),U.stopPropagation(),b(!1),I(""),N(0))};let F=0;return s.jsxs("div",{className:ce("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",p==="top"?"bottom-full mb-1":"top-full mt-1",m),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(P,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{ref:T,type:"text",placeholder:x("multirun.modelMultiSelect.search.placeholder"),value:k,onChange:U=>I(U.target.value),onKeyDown:oe,className:"h-8 pl-8 typography-meta"})]})}),s.jsx(Cs,{outerClassName:"flex-1",style:{maxHeight:D?`${D}px`:"300px"},children:s.jsxs("div",{className:"p-1",children:[!Q&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:x("multirun.modelMultiSelect.search.noResults")}),X.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(P,{name:"star-fill",className:"h-4 w-4 text-primary"}),x("multirun.modelMultiSelect.sections.favorites")]}),X.map(({model:U,providerID:W,modelID:te})=>{const K=F++;return ne(U,W,te,"fav",K,j===K)})]}),O.length>0&&s.jsxs(s.Fragment,{children:[X.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(P,{name:"time",className:"h-4 w-4"}),x("multirun.modelMultiSelect.sections.recent")]}),O.map(({model:U,providerID:W,modelID:te})=>{const K=F++;return ne(U,W,te,"recent",K,j===K)})]}),(X.length>0||O.length>0)&&J.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),J.map((U,W)=>s.jsxs(o.Fragment,{children:[W>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(vn,{providerId:U.id,className:"h-4 w-4 flex-shrink-0"}),U.name]}),U.models.map(te=>{const K=F++;return ne(te,U.id,te.id,"provider",K,j===K)})]},U.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:x("multirun.modelMultiSelect.keyboard.hint")})]})})()]}),l&&t.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:t.map((G,le)=>{const oe=`${G.providerID}:${G.modelID}`,F=z.get(oe)||1,U=B(G),te=f.find(be=>be.id===G.providerID)?.models.find(be=>be.id===G.modelID),K=te?.variants?Object.keys(te.variants):[],ae=K.length>0,ve="__default__",re=G.variant??ve;return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(pA,{model:G,instanceIndex:U,totalSameModel:F,onRemove:()=>n(le)}),ae&&s.jsxs(is,{value:re,onValueChange:be=>{if(!r)return;r(le,{...G,variant:be===ve?void 0:be})},children:[s.jsxs(as,{size:"chip",className:"px-2 gap-1.5 rounded-md !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground",children:[s.jsx(P,{name:"brain-ai-3",className:ce("h-3.5 w-3.5 flex-shrink-0",re===ve?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(us,{placeholder:x("multirun.modelMultiSelect.variant.placeholder"),children:be=>be===ve?x("multirun.modelMultiSelect.variant.default"):be})]}),s.jsxs(os,{fitContent:!0,children:[s.jsx(Ft,{value:ve,className:"pr-2 [&>span:first-child]:hidden",children:x("multirun.modelMultiSelect.variant.default")}),K.map(be=>s.jsx(Ft,{value:be,className:"pr-2 [&>span:first-child]:hidden",children:be},be))]})]})]},G.instanceId)})})]}),i!==void 0&&t.length<i&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:c!==void 0?x("multirun.modelMultiSelect.validation.minToMax",{min:i,max:c}):x("multirun.modelMultiSelect.validation.minOnly",{min:i})})]})},fA=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
217
|
+
|
|
218
|
+
--- RESULT ${n+1}: ${r} ---
|
|
219
|
+
${e.trim()}
|
|
220
|
+
--- END RESULT ${n+1} ---`},mf=(t,e)=>Ot.getState().getWorktreeMetadata(t)?.projectDirectory??e,hA=async t=>{const e=t.directory??void 0,n=ky(t.session.id,e);if(n.length===0&&t.directory){const i=(await Zs.withDirectory(t.directory,()=>Zs.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let a=i.length-1;a>=0;a-=1){const l=i[a];if(l.info?.role==="assistant")return Bu(l.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const i=n[r];if(i.role==="assistant")return Bu(Cy(i.id,e)).trim()}return""};function gA({session:t,open:e,onOpenChange:n}){const{t:r}=ut(),i=Ad(),a=Ei(V=>V.activeSessions),l=Ei(V=>V.archivedSessions),c=xt(V=>V.providers),d=xt(V=>V.currentProviderId),p=xt(V=>V.currentModelId),m=xt(V=>V.currentAgentName),[u,h]=o.useState(d??""),[x,f]=o.useState(p??""),[v,y]=o.useState(()=>d&&p?[{providerID:d,modelID:p,instanceId:Il()}]:[]),[g,w]=o.useState(""),[b,k]=o.useState(m??""),[I,j]=o.useState([]),[N,D]=o.useState(!1),E=o.useMemo(()=>ll(t.title),[t.title]),T=o.useMemo(()=>{const V=new Map;for(const $ of i)V.set($.id,$);for(const $ of a)V.set($.id,$);for(const $ of l)V.set($.id,$);return t.id&&V.set(t.id,t),Array.from(V.values())},[a,l,i,t]);o.useEffect(()=>{if(!e||!E)return;const V=Ot.getState().getDirectoryForSession(t.id),$=mf(t.id,V),_=T.map(X=>{const O=ll(X.title);if(!O||O.groupSlug!==E.groupSlug||O.fusion)return null;const J=Ot.getState().getDirectoryForSession(X.id)??Ha(X),Q=mf(X.id,J);return $&&Q&&$!==Q?null:{session:X,directory:J,projectDirectory:Q}}).filter(X=>X!==null).sort((X,O)=>(X.session.time?.created??0)-(O.session.time?.created??0));j(_)},[T,e,E,t.id]);const S=c.find(V=>V.id===u)?.models.find(V=>V.id===x),M=S?.variants?Object.keys(S.variants):[],A=!!(E&&u&&x&&I.length>0&&!N),R=o.useCallback(V=>{y([V]),h(V.providerID),f(V.modelID),w("")},[]),z=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),B=async()=>{if(!(!E||!u||!x)){D(!0);try{const V=await Promise.all(I.map(ne=>hA(ne))),$=I.map((ne,G)=>({source:ne,text:V[G]??""})).filter(ne=>ne.text.trim().length>0);if($.length===0){H.error(r("multirun.fusion.toast.noOutputs"));return}const _=I[0]?.projectDirectory??I[0]?.directory??null,X=iA(E.groupSlug,u,x),[O,J]=await Promise.all([wn("session.fusion.visible"),wn("session.fusion.instructions")]),Q=await Ot.getState().createSession(X,_,null);if(!Q)throw new Error("Failed to create fusion session");Ot.getState().setCurrentSession(Q.id,_),n(!1),await Zs.withDirectory(_??Zs.getDirectory(),()=>Zs.sendMessage({id:Q.id,providerID:u,modelID:x,variant:g||void 0,agent:b||void 0,text:O,additionalParts:[{text:J,synthetic:!0},...$.map((ne,G)=>({text:fA(ne.source,ne.text,G),synthetic:!0})),{text:`
|
|
221
|
+
|
|
222
|
+
--- FUSION INPUTS END ---
|
|
223
|
+
Now write the final fused answer.`,synthetic:!0}]}))}catch(V){console.error("[MultiRunFusion] Failed to start fusion",V),H.error(r("multirun.fusion.toast.failed"))}finally{D(!1)}}};return s.jsx(hs,{open:e,onOpenChange:n,children:s.jsxs(fs,{className:"max-w-xl overflow-visible",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:r("multirun.fusion.title")}),s.jsx(Is,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx($g,{selectedModels:v,onAdd:R,onUpdate:(V,$)=>R($),onRemove:()=>{y([]),h(""),f(""),w("")},maxModels:1,addButtonLabel:z,showChips:!1,addButtonClassName:"h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:u?s.jsx(vn,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),M.length>0?s.jsxs(is,{value:g||"__default__",onValueChange:V=>w(V==="__default__"?"":V),children:[s.jsxs(as,{size:"lg",className:"h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5",children:[s.jsx(P,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(us,{children:V=>V==="__default__"?r("multirun.modelMultiSelect.variant.default"):V})]}),s.jsxs(os,{fitContent:!0,portalToBody:!0,children:[s.jsx(Ft,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),M.map(V=>s.jsx(Ft,{value:V,children:V},V))]})]}):null,s.jsx(Lg,{value:b,onChange:k,portalToBody:!0,className:"h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:I.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:I.map(V=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(vn,{providerId:ll(V.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:V.session.title||V.session.id}),s.jsx("button",{type:"button",onClick:()=>j($=>$.filter(_=>_.session.id!==V.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]},V.session.id))})]}),s.jsxs(Vs,{children:[s.jsx(ge,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(ge,{onClick:B,disabled:!A,children:r(N?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function xA(t){const e=at.c(7);let n,r,i,a,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),i=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),a=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),l=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=i,e[3]=a,e[4]=l):(n=e[0],r=e[1],i=e[2],a=e[3],l=e[4]);let c;return e[5]!==t?(c=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,i,a,l]}),e[5]=t,e[6]=c):c=e[6],c}const pf=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),Ii=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Ii(n,e))return!0;return!1},Sd=(t,e,n,r)=>{if(!e)return!1;if(`${n}:${r?"archived":"active"}:${t.session.id}`===e)return!0;for(const a of t.children)if(Sd(a,e,n,r))return!0;return!1},bA=(t,e)=>{const n=t.node.session,r=e.node.session,i=n.id,a=r.id;if(i!==a||t.node.session!==e.node.session||pf(t.node)!==pf(e.node)||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket)return!1;if(t.currentSessionId!==e.currentSessionId){const m=Ii(t.node,t.currentSessionId),u=Ii(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(i)!==e.pinnedSessionIds.has(a))return!1;{const m=t.renderContext??"project",u=e.renderContext??"project",h=t.archivedBucket??!1,x=e.archivedBucket??!1,f=`${m}:${h?"archived":"active"}:${i}`,v=`${u}:${x?"archived":"active"}:${a}`;if(t.expandedParents.has(f)!==e.expandedParents.has(v))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=Ii(t.node,t.editingId),u=Ii(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=Ii(t.node,t.editingId),u=Ii(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===i!=(e.copiedSessionId===a))return!1;const l=Sd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=Sd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(l!==c)return!1;const d=xs(n.directory??null)??xs(t.groupDirectory??null),p=xs(r.directory??null)??xs(e.groupDirectory??null);return!(d!==p||(d?t.directoryStatus.get(d):null)!==(p?e.directoryStatus.get(p):null)||(t.secondaryMeta?.projectLabel??null)!==(e.secondaryMeta?.projectLabel??null)||(t.secondaryMeta?.branchLabel??null)!==(e.secondaryMeta?.branchLabel??null)||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||(t.renderContext??"project")!==(e.renderContext??"project")||t.renamingFolderId!==e.renamingFolderId)};function yA(t){const{t:e}=ut(),{node:n,depth:r=0,groupDirectory:i,projectId:a,archivedBucket:l=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:h,notifyOnSubtasks:x,editingId:f,setEditingId:v,editTitle:y,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:b,toggleParent:k,handleSessionSelect:I,handleSessionDoubleClick:j,togglePinnedSession:N,handleShareSession:D,copiedSessionId:E,handleCopyShareUrl:T,handleUnshareSession:C,openSidebarMenuKey:S,setOpenSidebarMenuKey:M,renamingFolderId:A,getFoldersForScope:R,getSessionFolderId:z,removeSessionFromFolder:B,addSessionToFolder:V,createFolderAndStartRename:$,openContextPanelTab:_,handleDeleteSession:X,mobileVariant:O,alwaysShowActions:J,renderSessionNode:Q,secondaryMeta:ne,renderContext:G="project"}=t,le=!!ne?.projectLabel,oe=!!ne?.branchLabel,U=Mi(bt=>bt.displayMode)==="minimal",W=o.useMemo(()=>mn(),[]),te=o.useMemo(()=>Dd(),[]),K=W?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",ae=W?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",ve=!l&&!O,re=U?W?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":W?ve?"group-hover:pr-12":"group-hover:pr-5":ve?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",be=ve?"pr-13":"pr-7",pe=o.useRef(!1),[ye,ie]=o.useState(!1),ue=n.session,Ne=Uf(ue.id)??ue,Ce=xs(ue.directory??null)??xs(i??null),je=Py(Ce??void 0),we=_d(),ke=ur(bt=>bt.enabled),xe=ur(o.useCallback(bt=>bt.selectedIds.has(ue.id),[ue.id])),me=ur(bt=>bt.toggleSelected),Me=ur(bt=>bt.setRange),Ue=o.useCallback(bt=>{const Mt=[],At=ee=>{ee.children.forEach(ht=>{Mt.push(ht.session.id),At(ht)})};return At(bt),Mt},[]),[q,Se]=o.useState(!1),[$e,Pe]=o.useState(!0),fe=`${G}:${l?"archived":"active"}:${ue.id}`,L=ph(o.useCallback(bt=>!!bt.sessionMemoryState.get(ue.id)?.isZombie,[ue.id])),Z=Iy(ue.id),Y=Ay(ue.id,Ce??void 0),Ae=(Ce?c.get(Ce):null)==="missing",Je=d===ue.id,de=Ne.title||e("sessions.sidebar.session.untitled"),ze=n.children.length>0,rt=p.has(ue.id),Re=fe,Xe=u?!0:m.has(Re),qe=!!Ne.parentID,We=Dy(ue.id)>0&&(!qe||x),Ze=Ne.summary,Qe=Kf(Ze),he=Ne.time?.updated||Ne.time?.created||Date.now(),Ge=Ty(he),Ve=Fy(he),it=S===fe,dt=o.useMemo(()=>ll(Ne.title)!==null,[Ne.title]),[Ye,_e]=o.useState(!1),et=o.useMemo(()=>Ue(n).length,[Ue,n]),gt=o.useCallback(async bt=>{const Mt=[];let At=0;for(const ee of bt)try{await we.ensureSessionRenderable(ee.session.id);const ht=zu(je.getState(),ee.session.id).list,St=ee.session.title||e("sessions.sidebar.session.export.untitledSubagent"),qt=ee.session.agent,ms=await gt(ee.children);At+=ms.skipped,Mt.push({title:St,agent:qt,records:ht,children:ms.children})}catch{At+=Ue(ee).length+1}return{children:Mt,skipped:At}},[Ue,je,we,e]),Lt=o.useCallback(bt=>{bt<=0||H.warning(bt===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:bt}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:bt}))},[e]),Ut=o.useCallback(async bt=>{if(!Ce){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}await we.ensureSessionRenderable(ue.id);const Mt=zu(je.getState(),ue.id).list;if(Mt.length===0){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}let At,ee=0;if(bt&&n.children.length>0){const ms=await gt(n.children);At=ms.children,ee=ms.skipped}const ht=JI(Mt,Ne.title??null,At),St=sA(Ne.title??null),qt=await ZI(ht,St);if(qt){H.success(e("sessions.sidebar.session.export.success"),{action:{label:e(tA()),onClick:()=>{eA(qt).then(ms=>{ms||H.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Lt(ee);return}XI(ht,St),H.success(e("sessions.sidebar.session.export.success")),Lt(ee)},[gt,je,n.children,Ne.title,ue.id,Ce,Lt,we,e]),mt=o.useCallback(async()=>{if(n.children.length>0){Pe(!0),Se(!0);return}await Ut(!1)},[Ut,n.children.length]),Nt=o.useCallback(()=>{Ce&&ml("desktop_open_session_mini_chat_window",{sessionId:ue.id,directory:Ce}).catch(bt=>{console.warn("[session-sidebar] failed to open mini chat window",bt)})},[ue.id,Ce]);if(f===ue.id)return s.jsx("div",{className:ce("group relative flex items-center rounded-sm px-1.5 py-1",r>0&&"pl-[20px]"),children:s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:bt=>{bt.preventDefault(),w()},children:[s.jsx("input",{value:y,onChange:bt=>g(bt.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:bt=>{if(bt.key==="Escape"){bt.stopPropagation(),b();return}(bt.key===" "||bt.key==="Enter")&&bt.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:b,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"size-4"})})]}),U?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[ze?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Xe?s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(P,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:Ge}),Qe?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Qe.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Qe.deletions]})]}):null,le?s.jsx("span",{className:"truncate",children:ne?.projectLabel}):null,oe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ne?.branchLabel})]}):null]})})]})},ue.id);const Xt=Z?.type??"idle",_t=Xt==="busy"||Xt==="retry",Gt=Y.length,Tt=_t||!_t&&We&&!Je,rs=_t?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-busy-pulse","aria-label":e("sessions.sidebar.session.status.active"),title:e("sessions.sidebar.session.status.active")}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":e("sessions.sidebar.session.status.unread"),title:e("sessions.sidebar.session.status.unread")}),js=Tt||rt?s.jsxs("span",{className:ce("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",U?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",Tt&&rt?"left-[-18px] w-6":"left-[-10px] w-3.5",ze&&!J?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[Tt?rs:null,rt?s.jsx(P,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,ys=ze?s.jsx("span",{role:"button",tabIndex:0,onClick:bt=>{bt.stopPropagation(),k(Re)},onKeyDown:bt=>{(bt.key==="Enter"||bt.key===" ")&&(bt.preventDefault(),bt.stopPropagation(),k(Re))},className:ce("absolute left-[-10px] inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",U?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",U&&Tt&&!J?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(Xe?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Xe?s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(P,{name:"arrow-right-s",className:"h-3 w-3"})}):null,vs=L?s.jsx(P,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Wt=bt=>{M(bt?fe:null)},He=bt=>{bt.preventDefault(),bt.stopPropagation(),M(it?null:fe)},kt=bt=>{bt.preventDefault(),bt.stopPropagation()},Kt=bt=>{bt.preventDefault(),bt.stopPropagation()},wt=bt=>{bt.preventDefault(),bt.stopPropagation()},Qt=bt=>{bt.preventDefault(),bt.stopPropagation()},cs=bt=>{bt.preventDefault(),bt.stopPropagation(),M(null),X(ue,{archivedBucket:l})},Ls=bt=>{if(pe.current){pe.current=!1;return}if(ke){if(bt?.preventDefault(),bt?.stopPropagation(),bt?.shiftKey){const At=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(St=>St.getAttribute("data-session-row")).filter(St=>typeof St=="string"&&St.length>0),ee=ur.getState().anchorId,ht=new Map;ht.set(ue.id,Ue(n)),Me(ee,ue.id,At,Ce??null,ht);return}me(ue.id,Ce??null,Ue(n));return}I(ue.id,Ce,Ae,a)},Ss=bt=>{(bt.button===2||bt.button===0&&bt.ctrlKey&&!ke)&&(pe.current=!0)},ns=bt=>{O&&bt.pointerType==="touch"&&ie(!0)},Os=bt=>{O&&bt.pointerType==="touch"&&ie(!1)},Ks=s.jsxs(Rs,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:bt=>{A&&bt.preventDefault()},children:[s.jsxs($t,{onClick:()=>{v(ue.id),g(de)},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs($t,{onClick:()=>N(ue.id),className:"[&>svg]:mr-1",children:[rt?s.jsx(P,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(P,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(rt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Ne.share?s.jsxs(s.Fragment,{children:[s.jsx($t,{onClick:()=>{Ne.share?.url&&T(Ne.share.url,ue.id)},className:"[&>svg]:mr-1",children:E===ue.id?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs($t,{onClick:()=>C(ue.id),className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs($t,{onClick:()=>D(Ne),className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs($t,{onClick:()=>{mt()},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),dt?s.jsxs($t,{onClick:()=>_e(!0),className:"[&>svg]:mr-1",children:[s.jsx(xA,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ce&&!l?(()=>{const bt=R(Ce),Mt=z(Ce,ue.id);return s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),s.jsxs(My,{children:[s.jsxs(Ey,{className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Ry,{className:"min-w-[180px]",children:[bt.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):bt.map(At=>s.jsxs($t,{onClick:()=>{Mt===At.id?B(Ce,ue.id):V(Ce,At.id,ue.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:At.name}),Mt===At.id?s.jsx(P,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},At.id)),s.jsx(Cn,{}),s.jsxs($t,{onClick:()=>{const At=$(Ce);At&&V(Ce,At.id,ue.id)},children:[s.jsx(P,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Mt?s.jsxs($t,{onClick:()=>{B(Ce,ue.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,W?null:s.jsxs($t,{disabled:!Ce,onClick:()=>{Ce&&_(Ce,{mode:"chat",dedupeKey:`session:${ue.id}`,label:de})},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),te?s.jsxs($t,{disabled:!Ce,onClick:Nt,className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Cn,{}),s.jsxs($t,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>X(ue,{archivedBucket:l}),children:[s.jsx(P,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(l?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(o.Fragment,{children:[s.jsx(xI,{sessionId:ue.id,sessionDirectory:Ce??null,sessionTitle:de,children:s.jsxs("div",{"data-session-row":ue.id,"data-session-scope":Ce??"","data-session-archived":l?"1":"0",className:ce("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",Ae?"opacity-75":"",r>0&&"pl-[20px]",xe&&"bg-primary/15"),children:[js,ys,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:U?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",disabled:Ae,onPointerDown:ns,onPointerUp:Os,onPointerCancel:Os,onMouseDown:Ss,onClick:bt=>Ls(bt),onDoubleClick:bt=>{bt.stopPropagation(),j()},className:ce("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ye&&"bg-interactive-hover/70",J?W?re:be:re),children:s.jsxs("div",{className:ce("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ce("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:Ga(de,h)}),J?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Ve}):null,J?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:ce("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",it?"opacity-0":ae),children:Ve})}),Gt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(P,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Gt})]}):null]})})}),s.jsx(Dt,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:ce("flex items-center gap-3 text-left text-muted-foreground",ne?.projectLabel?"justify-between":"justify-start"),children:[ne?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ne.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:Ge})]}),ne?.branchLabel||Qe?s.jsxs("div",{className:ce("flex items-center gap-3 text-left text-muted-foreground",ne?.branchLabel?"justify-between":"justify-start"),children:[ne?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ne.branchLabel})]})}):null,Qe?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Qe.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Qe.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:Ae,onPointerDown:ns,onPointerUp:Os,onPointerCancel:Os,onMouseDown:Ss,onClick:bt=>Ls(bt),onDoubleClick:bt=>{bt.stopPropagation(),j()},className:ce("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ye&&"bg-interactive-hover/70",J?W?re:be:re),children:[s.jsxs("div",{className:ce("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ce("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:Ga(de,h)}),Gt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(P,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Gt})]}):null]}),U?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:Ge}),Qe?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Qe.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Qe.deletions]})]}):null,le?s.jsx("span",{className:"truncate",children:ne?.projectLabel}):null,oe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ne?.branchLabel})]}):null]})})]})}),vs&&!O?s.jsx("div",{className:ce("absolute top-1/2 -translate-y-1/2 z-10",U?"right-0":"right-[30px]"),children:vs}):null,s.jsxs("div",{className:ce("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",it||J&&!W?"opacity-100":ce("opacity-0",K)),children:[ve?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:ce("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",U&&!J?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:wt,onMouseDown:Qt,onClick:cs,onKeyDown:bt=>bt.stopPropagation(),children:s.jsx(P,{name:"archive",className:ce(U&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Dt,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(Fs,{open:it,onOpenChange:Wt,children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:ce("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",U&&!J?it?"h-4 w-4 opacity-100":ce("h-4 w-4 opacity-0",K):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:kt,onMouseDown:Kt,onClick:He,onKeyDown:bt=>bt.stopPropagation(),children:s.jsx(P,{name:"more-2",className:ce(U&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),Ks]})]})]})}),ze&&Xe?n.children.map(bt=>Q(bt,r+1,Ce??i,a,l,void 0,G)):null,s.jsx(hs,{open:q,onOpenChange:Se,children:s.jsxs(fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Is,{children:et===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:et}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:et})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$e,onChange:bt=>Pe(bt.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Vs,{children:[s.jsx(ge,{type:"button",onClick:()=>Se(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ge,{type:"button",onClick:()=>{Se(!1),Ut($e)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),dt?s.jsx(gA,{session:Ne,open:Ye,onOpenChange:_e}):null]},ue.id)}const vA=o.memo(yA,bA);function wA(t){const e=at.c(71),{t:n}=ut(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:l,onConfirm:c}=t;let d,p,m,u,h,x,f,v,y,g;if(e[0]!==i||e[1]!==n||e[2]!==r){const $=n("sessions.sidebar.session.untitled");u=hs,y=!!r,e[13]!==i?(g=X=>{X||i(null)},e[13]=i,e[14]=g):g=e[14],m=fs,f=!1,v="max-w-sm gap-5",p=bs;let _;e[15]!==n||e[16]!==r?.archivedBucket?(_=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=_):_=e[17],e[18]!==_?(x=s.jsx(gs,{children:_}),e[18]=_,e[19]=x):x=e[19],d=Is,h=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||$}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||$}),e[0]=i,e[1]=n,e[2]=r,e[3]=d,e[4]=p,e[5]=m,e[6]=u,e[7]=h,e[8]=x,e[9]=f,e[10]=v,e[11]=y,e[12]=g}else d=e[3],p=e[4],m=e[5],u=e[6],h=e[7],x=e[8],f=e[9],v=e[10],y=e[11],g=e[12];let w;e[20]!==d||e[21]!==h?(w=s.jsx(d,{children:h}),e[20]=d,e[21]=h,e[22]=w):w=e[22];let b;e[23]!==p||e[24]!==x||e[25]!==w?(b=s.jsxs(p,{children:[x,w]}),e[23]=p,e[24]=x,e[25]=w,e[26]=b):b=e[26];let k;e[27]!==l||e[28]!==a?(k=()=>l(!a),e[27]=l,e[28]=a,e[29]=k):k=e[29];const I=!a;let j;e[30]!==a?(j=a?s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=a,e[31]=j):j=e[31];let N;e[32]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=N):N=e[33];let D;e[34]!==j||e[35]!==N||e[36]!==k||e[37]!==I?(D=s.jsxs("button",{type:"button",onClick:k,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":I,children:[j,N]}),e[34]=j,e[35]=N,e[36]=k,e[37]=I,e[38]=D):D=e[38];let E;e[39]!==i?(E=()=>i(null),e[39]=i,e[40]=E):E=e[40];let T;e[41]!==n?(T=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=T):T=e[42];let C;e[43]!==E||e[44]!==T?(C=s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:T}),e[43]=E,e[44]=T,e[45]=C):C=e[45];let S;e[46]!==c?(S=()=>{c()},e[46]=c,e[47]=S):S=e[47];let M;e[48]!==n||e[49]!==r?.archivedBucket?(M=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=M):M=e[50];let A;e[51]!==S||e[52]!==M?(A=s.jsx("button",{type:"button",onClick:S,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:M}),e[51]=S,e[52]=M,e[53]=A):A=e[53];let R;e[54]!==C||e[55]!==A?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[C,A]}),e[54]=C,e[55]=A,e[56]=R):R=e[56];let z;e[57]!==D||e[58]!==R?(z=s.jsxs(Vs,{className:"w-full sm:items-center sm:justify-between",children:[D,R]}),e[57]=D,e[58]=R,e[59]=z):z=e[59];let B;e[60]!==m||e[61]!==f||e[62]!==z||e[63]!==v||e[64]!==b?(B=s.jsxs(m,{showCloseButton:f,className:v,children:[b,z]}),e[60]=m,e[61]=f,e[62]=z,e[63]=v,e[64]=b,e[65]=B):B=e[65];let V;return e[66]!==u||e[67]!==B||e[68]!==y||e[69]!==g?(V=s.jsx(u,{open:y,onOpenChange:g,children:B}),e[66]=u,e[67]=B,e[68]=y,e[69]=g,e[70]=V):V=e[70],V}function jA(t){const e=at.c(57),{t:n}=ut(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:l,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let h;e[4]!==d||e[5]!==p||e[6]!==n?(h=d?p===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:p}):p===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:p}),e[4]=d,e[5]=p,e[6]=n,e[7]=h):h=e[7];const x=h,f=!!r;let v;e[8]!==i?(v=V=>{V||i(null)},e[8]=i,e[9]=v):v=e[9];let y;e[10]!==u?(y=s.jsx(gs,{children:u}),e[10]=u,e[11]=y):y=e[11];let g;e[12]!==x?(g=s.jsx(Is,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==y||e[15]!==g?(w=s.jsxs(bs,{children:[y,g]}),e[14]=y,e[15]=g,e[16]=w):w=e[16];let b;e[17]!==l||e[18]!==a?(b=()=>l(!a),e[17]=l,e[18]=a,e[19]=b):b=e[19];const k=!a;let I;e[20]!==a?(I=a?s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=a,e[21]=I):I=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let N;e[24]!==j||e[25]!==b||e[26]!==k||e[27]!==I?(N=s.jsxs("button",{type:"button",onClick:b,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":k,children:[I,j]}),e[24]=j,e[25]=b,e[26]=k,e[27]=I,e[28]=N):N=e[28];let D;e[29]!==i?(D=()=>i(null),e[29]=i,e[30]=D):D=e[30];let E;e[31]!==n?(E=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=E):E=e[32];let T;e[33]!==D||e[34]!==E?(T=s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:E}),e[33]=D,e[34]=E,e[35]=T):T=e[35];let C;e[36]!==c?(C=()=>{c()},e[36]=c,e[37]=C):C=e[37];let S;e[38]!==d||e[39]!==n?(S=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=S):S=e[40];let M;e[41]!==C||e[42]!==S?(M=s.jsx("button",{type:"button",onClick:C,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:S}),e[41]=C,e[42]=S,e[43]=M):M=e[43];let A;e[44]!==T||e[45]!==M?(A=s.jsxs("div",{className:"flex items-center gap-2",children:[T,M]}),e[44]=T,e[45]=M,e[46]=A):A=e[46];let R;e[47]!==N||e[48]!==A?(R=s.jsxs(Vs,{className:"w-full sm:items-center sm:justify-between",children:[N,A]}),e[47]=N,e[48]=A,e[49]=R):R=e[49];let z;e[50]!==R||e[51]!==w?(z=s.jsxs(fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,R]}),e[50]=R,e[51]=w,e[52]=z):z=e[52];let B;return e[53]!==f||e[54]!==z||e[55]!==v?(B=s.jsx(hs,{open:f,onOpenChange:v,children:z}),e[53]=f,e[54]=z,e[55]=v,e[56]=B):B=e[56],B}function NA(t){const e=at.c(36),{t:n}=ut(),{value:r,setValue:i,onConfirm:a}=t,l=!!r;let c;e[0]!==i?(c=I=>{I||i(null)},e[0]=i,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(gs,{children:d}),e[4]=d,e[5]=p):p=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let u;e[9]!==m?(u=s.jsx(Is,{children:m}),e[9]=m,e[10]=u):u=e[10];let h;e[11]!==p||e[12]!==u?(h=s.jsxs(bs,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=h):h=e[13];let x;e[14]!==i?(x=()=>i(null),e[14]=i,e[15]=x):x=e[15];let f;e[16]!==n?(f=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=f):f=e[17];let v;e[18]!==x||e[19]!==f?(v=s.jsx("button",{type:"button",onClick:x,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:f}),e[18]=x,e[19]=f,e[20]=v):v=e[20];let y;e[21]!==n?(y=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=y):y=e[22];let g;e[23]!==a||e[24]!==y?(g=s.jsx("button",{type:"button",onClick:a,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:y}),e[23]=a,e[24]=y,e[25]=g):g=e[25];let w;e[26]!==g||e[27]!==v?(w=s.jsxs(Vs,{children:[v,g]}),e[26]=g,e[27]=v,e[28]=w):w=e[28];let b;e[29]!==w||e[30]!==h?(b=s.jsxs(fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[h,w]}),e[29]=w,e[30]=h,e[31]=b):b=e[31];let k;return e[32]!==l||e[33]!==c||e[34]!==b?(k=s.jsx(hs,{open:l,onOpenChange:c,children:b}),e[32]=l,e[33]=c,e[34]=b,e[35]=k):k=e[35],k}const SA=t=>{const e=at.c(46),{selectedCount:n,scopeKey:r,scopeFolders:i,archivedBucket:a,onMoveToFolder:l,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:h}=ut(),x=!!r&&!a;let f;e[0]!==a||e[1]!==h?(f=h(a?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=a,e[1]=h,e[2]=f):f=e[2];const v=f;let y;e[3]!==n||e[4]!==h?(y=h("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=h,e[5]=y):y=e[5];let g;e[6]!==y?(g=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:y}),e[6]=y,e[7]=g):g=e[7];let w;e[8]!==x||e[9]!==p||e[10]!==c||e[11]!==l||e[12]!==d||e[13]!==i||e[14]!==h?(w=x?s.jsxs(Fs,{children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":h("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(P,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Rs,{align:"end",className:"min-w-[180px]",children:[i.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:h("sessions.sidebar.folders.none")}):i.map(z=>s.jsx($t,{onClick:()=>l(z.id),children:s.jsx("span",{className:"flex-1 truncate",children:z.name})},z.id)),s.jsx(Cn,{}),s.jsxs($t,{onClick:c,children:[s.jsx(P,{name:"add",className:"mr-1 h-4 w-4"}),h("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs($t,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-1 h-4 w-4"}),h("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=x,e[9]=p,e[10]=c,e[11]=l,e[12]=d,e[13]=i,e[14]=h,e[15]=w):w=e[15];let b;e[16]===Symbol.for("react.memo_cache_sentinel")?(b=ce("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=b):b=e[16];let k;e[17]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(P,{name:"delete-bin",className:"h-4 w-4"}),e[17]=k):k=e[17];let I;e[18]!==v||e[19]!==m?(I=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:b,"aria-label":v,children:k})}),e[18]=v,e[19]=m,e[20]=I):I=e[20];let j;e[21]!==v?(j=s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:v})}),e[21]=v,e[22]=j):j=e[22];let N;e[23]!==I||e[24]!==j?(N=s.jsxs(Pt,{children:[I,j]}),e[23]=I,e[24]=j,e[25]=N):N=e[25];let D;e[26]!==h?(D=h("sessions.sidebar.header.actions.exitSelection"),e[26]=h,e[27]=D):D=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(P,{name:"close",className:"h-4 w-4"}),e[28]=E):E=e[28];let T;e[29]!==u||e[30]!==D?(T=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":D,children:E})}),e[29]=u,e[30]=D,e[31]=T):T=e[31];let C;e[32]!==h?(C=h("sessions.sidebar.header.actions.exitSelection"),e[32]=h,e[33]=C):C=e[33];let S;e[34]!==C?(S=s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:C})}),e[34]=C,e[35]=S):S=e[35];let M;e[36]!==T||e[37]!==S?(M=s.jsxs(Pt,{children:[T,S]}),e[36]=T,e[37]=S,e[38]=M):M=e[38];let A;e[39]!==M||e[40]!==w||e[41]!==N?(A=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,N,M]}),e[39]=M,e[40]=w,e[41]=N,e[42]=A):A=e[42];let R;return e[43]!==A||e[44]!==g?(R=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[g,A]}),e[43]=A,e[44]=g,e[45]=R):R=e[45],R},Bg="oc.sessions.activeNow",kA=2160*60*1e3,zg=t=>!!t.parentID,nu=t=>!!t.time?.archived,kd=t=>{const e=t.time?.updated,n=t.time?.created;return typeof e=="number"&&Number.isFinite(e)?e:typeof n=="number"&&Number.isFinite(n)?n:0},CA=t=>{try{const e=t.getItem(Bg);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,i=[];return n.forEach(a=>{const l=typeof a=="string"?a:a&&typeof a=="object"&&"sessionId"in a&&typeof a.sessionId=="string"?a.sessionId:null;!l||r.has(l)||(r.add(l),i.push({sessionId:l}))}),i}catch{return[]}},Bc=(t,e)=>{try{t.setItem(Bg,JSON.stringify(e))}catch{}},PA=(t,e,n=Date.now())=>{const r=n-kA;return t.filter(i=>{const a=e.get(i.sessionId);return a?nu(a)?!1:kd(a)>=r:!0})},IA=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],Vg=t=>[...t].sort((e,n)=>kd(n)-kd(e)),AA=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!nu(r)).filter(r=>!zg(r));return Vg(n)},DA=(t,e)=>{const n=t.filter(r=>{if(nu(r)||zg(r))return!1;const i=e[r.id];return i?.type==="busy"||i?.type==="retry"});return Vg(n)},Uo=pi(),zc=gr((t,e)=>({entries:CA(Uo),setEntries:n=>{n!==e().entries&&(t({entries:n}),Bc(Uo,n))},addSession:n=>{const r=IA(e().entries,n);r!==e().entries&&(t({entries:r}),Bc(Uo,r))},prune:n=>{const r=e().entries,i=PA(r,n);i.length===r.length&&i.every((a,l)=>a.sessionId===r[l]?.sessionId)||(t({entries:i}),Bc(Uo,i))}})),Wo="oc.sessions.projectCollapse",ff="oc.sessions.groupOrder",hf="oc.sessions.groupCollapse",gf="oc.sessions.activeSessionByProject",Vc="oc.sessions.expandedParents.v2",TA="oc.sessions.expandedParents",MA="oc.sessions.pinned",EA=(t,e)=>{const n=new Set;for(const r of t){const i=xs(r.path)?.toLowerCase();i&&n.add(i)}for(const r of e.values())for(const i of r){const a=xs(i.path)?.toLowerCase();a&&n.add(a)}return n},RA=(t,e)=>{if(t.time?.archived)return!0;const n=xs(Ha(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},FA=5*6e4,xf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:i=!1})=>{const{t:a}=ut(),[l,c]=o.useState(!1),[d,p]=o.useState(""),m=o.useRef(null),u=o.useRef(null),h=o.useRef(new Set),[x,f]=o.useState(null),[v,y]=o.useState(""),[g,w]=o.useState(null),[b,k]=o.useState(new Set),[I]=o.useState(()=>new Map),j=o.useMemo(()=>pi(),[]),N=zc(Le=>Le.entries),D=zc(Le=>Le.addSession),E=zc(Le=>Le.prune),[T,C]=o.useState(new Set),[S,M]=o.useState(new Map),[A,R]=o.useState(new Set),[z,B]=o.useState(!1),[V,$]=o.useState(null),[_,X]=o.useState(null),[O,J]=o.useState(""),[Q,ne]=o.useState(null),[G,le]=o.useState(null),[oe,F]=o.useState(null),U=oc(Le=>Le.ids),W=oc(Le=>Le.setIds),te=oc(Le=>Le.toggle),[K,ae]=o.useState(()=>{try{const Le=pi().getItem(hf);if(!Le)return new Set;const vt=JSON.parse(Le);return new Set(Array.isArray(vt)?vt.filter(ft=>typeof ft=="string"):[])}catch{return new Set}}),[ve,re]=o.useState(()=>{try{const Le=pi().getItem(ff);if(!Le)return new Map;const vt=JSON.parse(Le),ft=new Map;return Object.entries(vt).forEach(([Yt,ps])=>{Array.isArray(ps)&&ft.set(Yt,ps.filter(Ws=>typeof Ws=="string"))}),ft}catch{return new Map}}),[be,pe]=o.useState(()=>{try{const Le=pi().getItem(gf);if(!Le)return new Map;const vt=JSON.parse(Le),ft=new Map;return Object.entries(vt).forEach(([Yt,ps])=>{typeof ps=="string"&&ps.length>0&&ft.set(Yt,ps)}),ft}catch{return new Map}}),[ye,ie]=o.useState(new Map),ue=o.useRef(new Map),se=o.useRef(0),Ne=$s(Le=>Le.homeDirectory),Ce=$s(Le=>Le.currentDirectory),je=$s(Le=>Le.setDirectory),we=As(Le=>Le.projects),ke=As(Le=>Le.activeProjectId),xe=As(Le=>Le.removeProject),me=As(Le=>Le.setActiveProjectIdOnly),Me=As(Le=>Le.updateProjectMeta),Ue=As(Le=>Le.reorderProjects),q=Ie(Le=>Le.setActiveMainTab),Se=Ie(Le=>Le.openContextPanelTab),$e=Ie(Le=>Le.setSettingsDialogOpen),Pe=Ie(Le=>Le.toggleHelpDialog),fe=Ie(Le=>Le.setAboutDialogOpen),L=Ie(Le=>Le.setSessionSwitcherOpen),Z=Ie(Le=>Le.setScheduledTasksDialogOpen),Y=Ie(Le=>Le.toggleSidebar),Ee=Ie(Le=>Le.openMultiRunLauncher),Ae=Ie(Le=>Le.notifyOnSubtasks),Je=Ie(Le=>Le.showDeletionDialog),de=Ie(Le=>Le.setShowDeletionDialog),ze=ho(d,120),rt=o.useMemo(()=>ze.trim().toLowerCase(),[ze]),Re=rt.length>0,Xe=Yn(Le=>Le.collapsedFolderIds),qe=Yn(Le=>Le.foldersMap),Te=Yn(Le=>Le.getFoldersForScope),We=Yn(Le=>Le.createFolder),Ze=Yn(Le=>Le.renameFolder),Qe=Yn(Le=>Le.deleteFolder),he=Yn(Le=>Le.addSessionToFolder),Ge=Yn(Le=>Le.addSessionsToFolder),Ve=Yn(Le=>Le.removeSessionFromFolder),it=Yn(Le=>Le.removeSessionsFromFolders),dt=Yn(Le=>Le.toggleFolderCollapse),Ye=Yn(Le=>Le.cleanupSessions),_e=Yn(Le=>Le.getSessionFolderId);LP({isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const et=ah(),gt=_d(),Lt=Ad(),Ut=Ly(),mt=Ei(Le=>Le.hasLoaded),Nt=Ei(Le=>Le.activeSessions),Xt=Ei(Le=>Le.archivedSessions),_t=Ot(Le=>Le.currentSessionId),Gt=Ot(Le=>!!Le.newSessionDraft?.open),lt=Ot(Le=>Le.setCurrentSession),Tt=Ot(Le=>Le.updateSessionTitle),rs=Ot(Le=>Le.shareSession),js=Ot(Le=>Le.unshareSession),ys=Ot(Le=>Le.worktreeMetadata),vs=Ot(Le=>Le.availableWorktreesByProject),Wt=Ot(Le=>Le.openNewSessionDraft),He=o.useMemo(()=>EA(we,vs),[vs,we]),kt=o.useMemo(()=>{const Le=new Map(Lt.map(Yt=>[Yt.id,Yt])),vt=Nt.map(Yt=>Le.get(Yt.id)??Yt),ft=new Set(vt.map(Yt=>Yt.id));return Lt.forEach(Yt=>{ft.has(Yt.id)||vt.push(Yt)}),vt.filter(Yt=>RA(Yt,He))},[Nt,He,Lt]),Kt=o.useMemo(()=>Lt.map(Le=>{const vt=xs(Le.directory??null)??"";return`${Le.id}:${Le.title??""}:${Le.time?.archived?1:0}:${vt}`}).join("|"),[Lt]),wt=o.useRef(Lt);o.useEffect(()=>{wt.current=Lt},[Kt,Lt]),o.useEffect(()=>{let Le=!1;const vt=async()=>{const ft=As.getState().projects;if(ft.length===0)return;const Yt=new Map,ps=[];await Promise.all(ft.map(async Ws=>{const Dn=xs(Ws.path);if(Dn)try{if(!(tn.getState().directories.get(Dn)?.isGitRepo??await kr(()=>import("./modelPrefsAutoSave-Dm799vzR.js").then(un=>un.cc),__vite__mapDeps([2,0,1,3,4])).then(un=>un.checkIsGitRepository(Dn))))return;const Tn=await Qc({id:Ws.id,path:Dn});if(Le||Tn.length===0)return;Yt.set(Dn,Tn),ps.push(...Tn)}catch{}})),!Le&&Ot.setState({availableWorktrees:ps,availableWorktreesByProject:Yt})};return Jc(wt.current),vt(),()=>{Le=!0}},[Ce,Kt,we]),o.useEffect(()=>{let Le=null;const vt=Mg(ft=>{ft.type==="scheduled-task-ran"&&(Le&&clearTimeout(Le),Le=setTimeout(()=>{Jc(wt.current)},500))});return()=>{Le&&clearTimeout(Le),vt()}},[]);const Qt=o.useMemo(()=>gn(),[]),cs=El(),[Ls,Ss]=o.useState(!1),ns=o.useMemo(()=>mn(),[]),{isTablet:Os}=rn(),Ks=t||Os,bt=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Mt=!t&&!ns&&!Qt,At=!t&&!ns&&!Mt,ee=Qt&&bt&&!Ls||cs?"pl-[5.5rem]":"pl-3",ht="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";o.useEffect(()=>{if(!Qt||!bt){Ss(!1);return}let Le=!1,vt=null;const ft=async()=>{try{const ps=await By();Le||Ss(ps)}catch{Le||Ss(!1)}},Yt=async()=>{try{vt=zy(()=>{ft()})}catch{}};return ft(),Yt(),()=>{Le=!0,vt&&vt()}},[Qt,bt]);const St=o.useCallback(async Le=>{const vt=Le.target;vt.closest(".app-region-no-drag")||vt.closest("button, a, input, select, textarea")||Le.button===0&&Qt&&await fh()},[Qt]),{buildGroupSearchText:qt,filterSessionNodesForSearch:ms,buildGroupedSessions:Ds}=FP({homeDirectory:Ne,worktreeMetadata:ys,pinnedSessionIds:U,gitBranches:et,isVSCode:ns}),{scheduleCollapsedProjectsPersist:Ke}=UP({isVSCode:ns,hasLoadedGlobalSessions:mt,safeStorage:j,keys:{sessionExpanded:Vc,sessionExpandedLegacy:TA,projectCollapse:Wo,sessionPinned:MA,groupOrder:ff,projectActiveSession:gf,groupCollapse:hf},sessions:kt,setPinnedSessionIds:W,groupOrderByProject:ve,activeSessionByProject:be,collapsedGroups:K,setExpandedParents:k,setCollapsedProjects:C}),yt=o.useMemo(()=>[...kt].sort((Le,vt)=>ca(Le,vt,U)),[kt,U]),Et=o.useMemo(()=>new Map(yt.map((Le,vt)=>[Le.id,vt])),[yt]),Ht=o.useMemo(()=>{const Le=new Map;return yt.forEach(vt=>{const ft=vt.parentID;if(!ft)return;const Yt=Le.get(ft)??[];Yt.push(vt),Le.set(ft,Yt)}),Le.forEach(vt=>vt.sort((ft,Yt)=>ca(ft,Yt,U))),Le},[yt,U]),ss=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noSessions.description")})]}),Rt=o.useMemo(()=>we.find(Le=>Le.id===g)??null,[we,g]),Ps=o.useCallback(Le=>{g&&(Me(g,Le),w(null))},[g,Me]),Qs=o.useCallback(()=>{B(!0)},[]),Hs=o.useCallback(()=>{t&&L(!1),$e(!0)},[t,L,$e]),ts=Ot(Le=>Le.deleteSession),Ns=Ot(Le=>Le.deleteSessions),jn=Ot(Le=>Le.archiveSession),sn=Ot(Le=>Le.archiveSessions),{copiedSessionId:Dr,handleSessionSelect:Tr,handleSessionDoubleClick:zr,handleSaveEdit:Vr,handleCancelEdit:Gs,handleShareSession:Mn,handleCopyShareUrl:ir,handleUnshareSession:En,handleDeleteSession:_r,confirmDeleteSession:In}=OP({activeProjectId:ke,currentDirectory:Ce,currentSessionId:_t,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:l,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:me,setDirectory:je,setActiveMainTab:q,setSessionSwitcherOpen:L,setCurrentSession:lt,updateSessionTitle:Tt,shareSession:rs,unshareSession:js,deleteSession:ts,deleteSessions:Ns,archiveSession:jn,archiveSessions:sn,childrenMap:Ht,showDeletionDialog:Je,setDeleteSessionConfirm:ne,deleteSessionConfirm:Q,setEditingId:f,setEditTitle:y,editingId:x,editTitle:v}),ln=o.useCallback(()=>{if(!G)return;const{scopeKey:Le,folderId:vt}=G;le(null),Qe(Le,vt)},[G,Qe]),an=o.useCallback(()=>{Sr.requestDirectoryDialog()},[]);o.useEffect(()=>{if(!_t)return;const vt=kt.find(Yt=>Yt.id===_t)?.parentID;if(!vt)return;const ft=[`project:active:${vt}`,`project:archived:${vt}`,`recent:active:${vt}`,`recent:archived:${vt}`];k(Yt=>{if(ft.every(Ws=>Yt.has(Ws)))return Yt;const ps=new Set(Yt);ft.forEach(Ws=>ps.add(Ws));try{j.setItem(Vc,JSON.stringify(Array.from(ps)))}catch{}return ps})},[_t,kt,j]);const Fe=o.useCallback(Le=>{k(vt=>{const ft=new Set(vt);ft.has(Le)?ft.delete(Le):ft.add(Le);try{j.setItem(Vc,JSON.stringify(Array.from(ft)))}catch{}return ft})},[j]),Ct=o.useCallback((Le,vt)=>{if(!Le)return null;vt&&Xe.has(vt)&&dt(vt);const ft=We(Le,a("sessions.sidebar.folder.newFolderName"),vt);return X(ft.id),J(ft.name),ft},[Xe,dt,We,a]),Zt=o.useCallback(Le=>{R(vt=>{const ft=new Set(vt);return ft.has(Le)?ft.delete(Le):ft.add(Le),ft})},[]),ls=o.useCallback(()=>{se.current=Date.now()+150,C(()=>{const Le=new Set(we.map(vt=>vt.id));try{j.setItem(Wo,JSON.stringify(Array.from(Le)))}catch{}return ns||Ke(Le),Le})},[we,ns,j,Ke]),Bs=o.useCallback(()=>{se.current=Date.now()+150,C(()=>{const Le=new Set;try{j.setItem(Wo,JSON.stringify([]))}catch{}return ns||Ke(Le),Le})},[ns,j,Ke]),Js=o.useCallback(Le=>{se.current=Date.now()+150,C(vt=>{const ft=new Set(vt);ft.has(Le)?ft.delete(Le):ft.add(Le);try{j.setItem(Wo,JSON.stringify(Array.from(ft)))}catch{}return ns||Ke(ft),ft})},[ns,j,Ke]),ws=o.useMemo(()=>we.map(Le=>({...Le,normalizedPath:xs(Le.path)})).filter(Le=>!!Le.normalizedPath),[we]),en=o.useMemo(()=>ws.map(Le=>Le.normalizedPath),[ws]),{github:nn}=Pn(),Rn=Hn(Le=>Le.status),Fn=Hn(Le=>Le.hasChecked),Ur=Oy(en),xr=mr(Le=>Le.ensureEntry),Wr=mr(Le=>Le.setParams),Ln=mr(Le=>Le.refreshTargets);KP({normalizedProjects:ws,gitRepoStatus:Ur,setProjectRepoStatus:M,setProjectRootBranches:ie});const er=Ot(Le=>Le.isLoading);eI({isSessionsLoading:er,sessions:kt,archivedSessions:Xt,normalizedProjects:ws,isVSCode:ns,availableWorktreesByProject:vs,cleanupSessions:Ye});const{getSessionsForProject:br,getArchivedSessionsForProject:ar}=YP({isVSCode:ns,sessions:kt,archivedSessions:Xt,availableWorktreesByProject:vs});PP({normalizedProjects:ws,sessions:kt,archivedSessions:Xt,availableWorktreesByProject:vs,isVSCode:ns,isSessionsLoading:er,foldersMap:qe,createFolder:We,addSessionToFolder:he,cleanupSessions:Ye});const dn=o.useRef(!1);ke&&S.has(ke)&&(dn.current=!!S.get(ke));const{projectSections:On,groupSearchDataByGroup:bn,sectionsForRender:Gn,searchMatchCount:Nn}=DP({normalizedProjects:ws,getSessionsForProject:br,getArchivedSessionsForProject:ar,availableWorktreesByProject:vs,projectRepoStatus:S,projectRootBranches:ye,lastRepoStatus:dn.current,buildGroupedSessions:Ds,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:rt,filterSessionNodesForSearch:ms,buildGroupSearchText:qt,foldersMap:qe}),ni=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noMatches.description")})]}),Gi=!0,{currentSessionDirectory:tr}=MP({projectSections:On,activeProjectId:ke,activeSessionByProject:be,setActiveSessionByProject:pe,currentSessionId:_t,handleSessionSelect:Tr,newSessionDraftOpen:Gt,mobileVariant:t,openNewSessionDraft:Wt,setActiveMainTab:q,setSessionSwitcherOpen:L,sessions:kt,worktreeMetadata:ys}),{getOrderedGroups:bi}=EP(ve),Sn=o.useRef(!1);o.useEffect(()=>{if(Sn.current||On.length===0)return;const Le=On.flatMap(vt=>vt.groups.filter(ft=>ft.isArchivedBucket).map(ft=>`${vt.project.id}:${ft.id}`));Le.length>0&&ae(vt=>new Set([...vt,...Le])),Sn.current=!0},[On]);const yr=o.useMemo(()=>{const Le=new Map,vt=new Map;return On.forEach(ft=>{const Yt=mh(ft.project.label?.trim()||Vi(ft.project.normalizedPath,Ne)||ft.project.normalizedPath);ft.groups.forEach(ps=>{const Ws=ps.branch&&ps.branch!=="HEAD"&&ps.branch!==Yt?ps.branch:null,Dn={projectLabel:Yt,branchLabel:Ws},wr=nr=>{nr.forEach(Tn=>{const un=ft.project.normalizedPath.length,Aa=vt.get(Tn.session.id)??-1;un<Aa||(Le.set(Tn.session.id,{node:Tn,projectId:ft.project.id,groupDirectory:ps.directory,secondaryMeta:Dn}),vt.set(Tn.session.id,un),Tn.children.length>0&&wr(Tn.children))})};wr(ps.sessions)})}),Le},[On,Ne]),qn=Mi(Le=>Le.showRecentSection),Gr=o.useMemo(()=>qn?AA(N,new Map(kt.map(Le=>[Le.id,Le]))).sort((Le,vt)=>ca(Le,vt,U)):[],[N,U,kt,qn]),Kr=o.useMemo(()=>qn?DA(kt,Ut):[],[Ut,kt,qn]);o.useEffect(()=>{!qn||Kr.length===0||Kr.forEach(Le=>D(Le.id))},[D,Kr,qn]),o.useEffect(()=>{if(!qn)return;const Le=new Map;[...kt,...Xt].forEach(vt=>{Le.set(vt.id,vt)}),E(Le)},[Xt,E,kt,qn]);const qi=o.useMemo(()=>{if(!qn)return[];const Le=vt=>{const ft=yr.get(vt.id),Yt=xs(vt.directory??null);return{node:ft?.node??{session:vt,children:[],worktree:null},projectId:ft?.projectId??null,groupDirectory:ft?.groupDirectory??Yt,secondaryMeta:ft?.secondaryMeta??null}};return[{key:"active-now",title:a("sessions.sidebar.activity.recentTitle"),items:Gr.map(Le)}]},[Gr,yr,qn,a]),cn=o.useMemo(()=>new Set(Gr.map(Le=>Le.id)),[Gr]),Oe=o.useMemo(()=>[...cn],[cn]);K4({currentSessionId:_t,sortedSessions:yt,recentSessionIds:Oe,ensureSessionRenderable:gt.ensureSessionRenderable});const tt=o.useMemo(()=>{if(!ns||Re||cn.size===0)return Gn;const Le=vt=>vt.reduce((ft,Yt)=>{if(cn.has(Yt.session.id))return ft;const ps=Le(Yt.children);return ps.length===Yt.children.length?(ft.push(Yt),ft):(ft.push({...Yt,children:ps}),ft)},[]);return Gn.map(vt=>({...vt,groups:vt.groups.map(ft=>({...ft,sessions:Le(ft.sessions)}))}))},[ns,Re,cn,Gn]),nt=o.useMemo(()=>{const Le=new Set;return tt.forEach(vt=>{vt.groups.forEach(ft=>{const Yt=xs(ft.directory??null),ps=ft.branch?.trim()||et.get(Yt||"")?.trim();!Yt||!ps||Le.add(Ya(Yt,ps))})}),[...Le]},[et,tt]),ct=j0(nt);o.useEffect(()=>{if(!Fn||!Rn?.connected||!nn)return;const Le=[],vt=Date.now();if(tt.forEach(Yt=>{T.has(Yt.project.id)||Yt.groups.forEach(ps=>{const Ws=xs(ps.directory??null),Dn=ps.branch?.trim()||et.get(Ws||"")?.trim();if(!Ws||!Dn)return;const wr=Ya(Ws,Dn),nr=mr.getState().entries[wr],Tn=!!nr?.status?.pr,un=`${Ws}::${Dn}`,Aa=Math.max(nr?.lastRefreshAt??0,nr?.lastDiscoveryPollAt??0),So=!!(nr?.isInitialStatusResolved&&!Tn&&(!h.current.has(un)||vt-Aa>=FA));(!nr||!nr.isInitialStatusResolved||So)&&(So&&h.current.add(un),Le.push({directory:Ws,branch:Dn}))})}),Le.length===0)return;const ft=new Map;Le.forEach(Yt=>{const ps=Ya(Yt.directory,Yt.branch,Yt.remoteName??null);ft.has(ps)||ft.set(ps,Yt)}),ft.forEach((Yt,ps)=>{xr(ps),Wr(ps,{directory:Yt.directory,branch:Yt.branch,remoteName:Yt.remoteName??null,canShow:!0,github:nn,githubAuthChecked:Fn,githubConnected:Rn.connected})}),Ln([...ft.values()],{force:!0,silent:!0,markInitialResolved:!0})},[T,xr,nn,Fn,Rn?.connected,et,Ln,tt,Wr]);const _s=t?"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed":"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed",pn="h-4.5 w-4.5",Mr=rI({isDesktopShellRuntime:Qt,projectSections:On,projectHeaderSentinelRefs:ue}),An=o.useCallback((Le,vt=0,ft,Yt,ps=!1,Ws,Dn="project")=>s.jsx(vA,{node:Le,depth:vt,groupDirectory:ft,projectId:Yt,archivedBucket:ps,directoryStatus:I,currentSessionId:_t,pinnedSessionIds:U,expandedParents:b,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:rt,notifyOnSubtasks:Ae,editingId:x,setEditingId:f,editTitle:v,setEditTitle:y,handleSaveEdit:Vr,handleCancelEdit:Gs,toggleParent:Fe,handleSessionSelect:Tr,handleSessionDoubleClick:zr,togglePinnedSession:te,handleShareSession:Mn,copiedSessionId:Dr,handleCopyShareUrl:ir,handleUnshareSession:En,openSidebarMenuKey:V,setOpenSidebarMenuKey:$,renamingFolderId:_,getFoldersForScope:Te,getSessionFolderId:_e,removeSessionFromFolder:Ve,addSessionToFolder:he,createFolderAndStartRename:Ct,openContextPanelTab:Se,handleDeleteSession:_r,mobileVariant:t,alwaysShowActions:Ks,renderSessionNode:An,secondaryMeta:Ws,renderContext:Dn}),[I,_t,U,b,Re,rt,Ae,x,f,v,y,Vr,Gs,Fe,Tr,zr,te,Mn,Dr,ir,En,V,$,_,Te,_e,Ve,he,Ct,Se,_r,t,Ks]),qr=o.useCallback(Le=>{ae(vt=>{const ft=new Set(vt);return ft.has(Le)?ft.delete(Le):ft.add(Le),ft})},[]),vr=o.useMemo(()=>{const Le=new Map;for(const[vt,ft]of ct)Le.set(vt,{visualState:ft.visualState,number:ft.number,url:ft.url,state:ft.prState,draft:ft.draft,title:ft.title,base:ft.base,head:ft.head,checks:ft.checks,canMerge:ft.canMerge,mergeableState:ft.mergeableState,repo:ft.repo});return Le},[ct]),ri=o.useCallback((Le,vt,ft,Yt,ps,Ws)=>s.jsx(jI,{group:Le,groupKey:vt,projectId:ft,hideGroupLabel:Yt,compactBodyPadding:Ws,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:rt,groupSearchDataByGroup:bn,expandedSessionGroups:A,collapsedGroups:K,hideDirectoryControls:r,collapsedFolderIds:Xe,toggleFolderCollapse:dt,renameFolder:Ze,deleteFolder:Qe,showDeletionDialog:Je,setDeleteFolderConfirm:le,renderSessionNode:An,currentSessionDirectory:tr,projectRepoStatus:S,lastRepoStatus:dn.current,toggleGroupSessionLimit:Zt,mobileVariant:t,alwaysShowActions:Ks,activeProjectId:ke,setActiveProjectIdOnly:me,setActiveMainTab:q,setSessionSwitcherOpen:L,openNewSessionDraft:Wt,addSessionToFolder:he,createFolderAndStartRename:Ct,renamingFolderId:_,renameFolderDraft:O,setRenameFolderDraft:J,setRenamingFolderId:X,pinnedSessionIds:U,sessionOrderIndex:Et,prVisualStateByDirectoryBranch:vr,onToggleCollapsedGroup:qr,dragHandleProps:ps}),[Re,rt,bn,A,K,r,Xe,dt,Ze,Qe,Je,An,tr,S,Zt,t,Ks,ke,me,q,L,Wt,he,Ct,_,O,U,Et,vr,qr]),ii=qn&&!Re?s.jsx(AI,{sections:qi,renderSessionNode:An}):null,ai=!!(_||x||g),yi=ur(Le=>Le.enabled),Us=ur(Le=>Le.selectedIds),oi=ur(Le=>Le.scopeKey),Ca=ur,Hl=o.useCallback(()=>{ur.getState().toggleMode()},[]),sr=o.useCallback(()=>{ur.getState().disable()},[]),Er=o.useMemo(()=>{if(Us.size===0||typeof document>"u")return!1;let Le=!1,vt=!1;for(const ft of Us){const Yt=document.querySelectorAll(`[data-session-row="${CSS.escape(ft)}"]`);for(const ps of Yt)ps.getAttribute("data-session-archived")==="1"?vt=!0:Le=!0}return vt&&!Le},[Us]),xn=o.useMemo(()=>{if(oi)return oi;if(Us.size===0||typeof document>"u")return null;for(const Le of Us){const ft=document.querySelector(`[data-session-row="${CSS.escape(Le)}"]`)?.getAttribute("data-session-scope");if(ft&&ft.length>0)return ft}return null},[Us,oi]),Pa=o.useMemo(()=>xn?qe[xn]??[]:[],[qe,xn]),ou=o.useMemo(()=>{if(!xn||Us.size===0)return!1;const Le=qe[xn]??[];for(const vt of Le)for(const ft of vt.sessionIds)if(Us.has(ft))return!0;return!1},[qe,xn,Us]),Ia=o.useCallback(Le=>{!xn||Us.size===0||Ge(xn,Le,Array.from(Us))},[Ge,Us,xn]),Yi=o.useCallback(()=>{if(!xn||Us.size===0)return;const Le=Ct(xn);Le&&Ge(xn,Le.id,Array.from(Us))},[Ge,Ct,Us,xn]),wo=o.useCallback(()=>{!xn||Us.size===0||it(xn,Array.from(Us))},[it,Us,xn]),li=o.useCallback(async()=>{const Le=Array.from(Us);if(Le.length!==0){if(Er){const{deletedIds:vt,failedIds:ft}=await Ns(Le);vt.length>0&&H.success(vt.length===1?a("sessions.sidebar.bulkActions.deletedSingle",{count:vt.length}):a("sessions.sidebar.bulkActions.deletedPlural",{count:vt.length})),ft.length>0&&H.error(ft.length===1?a("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ft.length}):a("sessions.sidebar.bulkActions.failedDeletePlural",{count:ft.length}))}else{const{archivedIds:vt,failedIds:ft}=await sn(Le);vt.length>0&&H.success(vt.length===1?a("sessions.sidebar.bulkActions.archivedSingle",{count:vt.length}):a("sessions.sidebar.bulkActions.archivedPlural",{count:vt.length})),ft.length>0&&H.error(ft.length===1?a("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ft.length}):a("sessions.sidebar.bulkActions.failedArchivePlural",{count:ft.length}))}ur.getState().clear()}},[sn,Er,Ns,Us,a]),Qi=o.useCallback(()=>{const Le=Us.size;if(Le!==0){if(!Je){li();return}F({sessionCount:Le,archivedBucket:Er})}},[Er,li,Us,Je]),jo=o.useCallback(async()=>{F(null),await li()},[li]);o.useEffect(()=>{if(!yi)return;const Le=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),vt=ft=>{if(ai)return;const Yt=ft.target;if(Yt&&(Yt.tagName==="INPUT"||Yt.tagName==="TEXTAREA"||Yt.isContentEditable))return;const ps=Le?ft.metaKey:ft.ctrlKey;if(ft.key==="Escape"){ft.preventDefault(),ur.getState().disable();return}if(ps&&ft.key==="Backspace"){ft.preventDefault(),Qi();return}if(ps&&(ft.key==="a"||ft.key==="A")){const Ws=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Ws.length===0)return;ft.preventDefault();const wr=Ca.getState().scopeKey??Ws[0]?.getAttribute("data-session-scope")??null,nr=un=>wr?un.getAttribute("data-session-scope")===wr:!0,Tn=Ws.filter(nr).map(un=>un.getAttribute("data-session-row")).filter(un=>typeof un=="string"&&un.length>0);if(Tn.length===0)return;Ca.getState().replaceAll(Tn,wr||null)}};return window.addEventListener("keydown",vt),()=>window.removeEventListener("keydown",vt)},[Qi,ai,Ca,yi]);const No=o.useCallback(()=>{q("chat"),t&&L(!1),Wt()},[t,Wt,q,L]),Gl=o.useCallback(()=>{q("chat"),t&&L(!1),Ee()},[t,Ee,q,L]);return s.jsxs("div",{ref:m,className:ce("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[At?s.jsx("div",{onMouseDown:St,className:ce("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",ee),children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Y,className:ht,"aria-label":a("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(P,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Dt,{children:s.jsx("p",{children:a("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(NI,{hideDirectoryControls:r,handleOpenDirectoryDialog:an,handleNewSession:No,canOpenMultiRun:we.length>0,openMultiRunLauncher:Gl,headerActionIconClass:pn,reserveHeaderActionsSpace:Gi,headerActionButtonClass:_s,isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:Re,searchMatchCount:Nn,collapseAllProjects:ls,expandAllProjects:Bs,openScheduledTasksDialog:()=>Z(!0),selectionModeEnabled:yi,onToggleSelectionMode:Hl,showSidebarToggle:Mt,onToggleSidebar:Y,avoidWindowControlsOverlay:cs}),s.jsx($I,{topContent:ii,sectionsForRender:tt,projectSections:On,activeProjectId:ke,showOnlyMainWorkspace:i,hasSessionSearchQuery:Re,emptyState:ss,searchEmptyState:ni,renderGroupSessions:ri,homeDirectory:Ne,collapsedProjects:T,hideDirectoryControls:r,projectRepoStatus:S,isDesktopShellRuntime:Qt,stuckProjectHeaders:Mr,mobileVariant:t,alwaysShowActions:Ks,toggleProject:Js,setActiveProjectIdOnly:me,setActiveMainTab:q,setSessionSwitcherOpen:L,openNewSessionDraft:Wt,openNewWorktreeDialog:Qs,openProjectEditDialog:w,removeProject:xe,projectHeaderSentinelRefs:ue,reorderProjects:Ue,getOrderedGroups:bi,setGroupOrderByProject:re,openSidebarMenuKey:V,setOpenSidebarMenuKey:$,isInlineEditing:ai}),yi&&Us.size>0?s.jsx(SA,{selectedCount:Us.size,scopeKey:xn,scopeFolders:Pa,archivedBucket:Er,onMoveToFolder:Ia,onCreateFolderAndMove:Yi,onRemoveFromFolder:wo,canRemoveFromFolder:ou,onDelete:Qi,onDone:sr}):null,s.jsx(TI,{onOpenSettings:Hs,onOpenShortcuts:Pe,onOpenAbout:()=>fe(!0),showRuntimeButtons:!ns}),Rt?s.jsx($y,{open:!!Rt,onOpenChange:Le=>{Le||w(null)},projectId:Rt.id,projectName:Rt.label||Vi(Rt.path,Ne),projectPath:Rt.path,initialIcon:Rt.icon,initialColor:Rt.color,initialIconBackground:Rt.iconBackground,onSave:Ps}):null,s.jsx(Q4,{open:z,onOpenChange:B,onWorktreeCreated:(Le,vt)=>{if(q("chat"),t&&L(!1),vt?.sessionId){lt(vt.sessionId);return}Wt({directoryOverride:Le})}}),s.jsx(kP,{}),s.jsx(wA,{value:Q,setValue:ne,showDeletionDialog:Je,setShowDeletionDialog:de,onConfirm:In}),s.jsx(NA,{value:G,setValue:le,onConfirm:ln}),s.jsx(jA,{value:oe,setValue:F,showDeletionDialog:Je,setShowDeletionDialog:de,onConfirm:jo})]})},LA=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Jr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");let n=e.replace(/\/+$/g,"");return n=n.replace(/\/+/g,"/"),n===""?e.startsWith("/")?"/":"":n},OA=()=>{const{t}=ut(),{runtime:e,files:n}=Pn(),r=Ir()??"",i=Jr(r.trim()),a=Bl(C=>C.searchFiles),l=Ie(C=>C.setSelectedMediaFilePath),c=Ie(C=>C.setCreativeRightSidebarTab),d=Ie(C=>C.setPreviewInfoOpen),[p,m]=o.useState(""),u=ho(p,200),h=o.useRef(null),[x,f]=o.useState([]),[v,y]=o.useState(!1),[g,w]=o.useState({}),[b,k]=o.useState(new Set),I=o.useRef(new Set),j=o.useRef(new Set),N=o.useCallback(async C=>{const S=Jr(C.trim());if(!S||I.current.has(S)||j.current.has(S))return;j.current=new Set(j.current),j.current.add(S),await(e.isDesktop?n.listDirectory(S,{respectGitignore:!0}).then(A=>A.entries.map(R=>({name:R.name,path:R.path,isDirectory:R.isDirectory}))):Zs.listLocalDirectory(S,{respectGitignore:!0})).then(A=>{const R=A.filter(B=>B.name&&!B.name.startsWith(".")).map(B=>{const V=B.name,$=Jr(B.path||"")||Jr(`${S}/${V}`),_=B.isDirectory?"directory":"file",X=_==="file"&&V.includes(".")?V.split(".").pop()?.toLowerCase():void 0;return{name:V,path:$,type:_,extension:X}}),z=LA(R);I.current=new Set(I.current),I.current.add(S),w(B=>({...B,[S]:z}))}).catch(()=>{w(A=>({...A,[S]:A[S]??[]}))}).finally(()=>{j.current=new Set(j.current),j.current.delete(S)})},[n,e.isDesktop]);o.useEffect(()=>{i&&(I.current=new Set,j.current=new Set,w({}),N(i))},[i]),o.useEffect(()=>{if(!i||b.size===0)return;const C=[...b].map(M=>Jr(M)).filter(M=>!!M&&M!==i&&M.startsWith(`${i}/`)&&!I.current.has(M)&&!j.current.has(M)).sort((M,A)=>M.split("/").length-A.split("/").length);if(C.length===0)return;let S=!1;return(async()=>{for(let M=0;M<C.length&&!S;M+=3){const A=C.slice(M,M+3);await Promise.all(A.map(R=>N(R)))}})(),()=>{S=!0}},[b,N,i]),o.useEffect(()=>{if(!r){f([]),y(!1);return}const C=u.trim();if(!C){f([]),y(!1);return}let S=!1;return y(!0),a(r,C,150,{includeHidden:!1,respectGitignore:!0,type:"file"}).then(M=>{if(S)return;const A=M.map(R=>({name:R.name,path:Jr(R.path),type:"file",extension:R.extension}));f(A)}).catch(()=>{S||f([])}).finally(()=>{S||y(!1)}),()=>{S=!0}},[r,u,a]);const D=o.useCallback(C=>{if(C.type==="directory"){const S=Jr(C.path);k(M=>{const A=new Set(M);return A.has(S)?A.delete(S):A.add(S),A}),I.current.has(S)||N(S);return}l(C.path),d(!1),c("preview")},[N,c,d,l]);function E(C,S){return(g[C]??[]).map(A=>{const R=A.type==="directory",z=R&&b.has(Jr(A.path));return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>D(A),className:ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors","hover:bg-interactive-hover/40 select-none"),title:A.path,children:[R?z?s.jsx(P,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(P,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(Zn,{filePath:A.path,extension:A.extension}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:A.name})]}),R&&z&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40",children:(()=>{const B=Jr(A.path),V=g[B];return I.current.has(B)&&(!V||V.length===0)?s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground italic",children:t("creative.mediaTree.empty")}):E(A.path)})()})]},A.path)})}const T=!!(i&&g[i]);return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[s.jsx("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:s.jsxs("div",{className:"relative min-w-0 flex-1",children:[s.jsx(P,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Bt,{ref:h,value:p,onChange:C=>m(C.target.value),placeholder:t("creative.mediaTree.searchPlaceholder"),className:"h-8 pl-8 pr-8 typography-meta"}),p.trim().length>0&&s.jsx("button",{type:"button","aria-label":"Clear search",className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{m(""),h.current?.focus()},children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]})}),s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"p-2",children:s.jsx("ul",{className:"flex flex-col",children:x.length>0?x.map(C=>s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>D(C),className:"flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors hover:bg-interactive-hover/40 select-none",title:C.path,children:[s.jsx(Zn,{filePath:C.path,extension:C.extension}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:C.name})]})},C.path)):v?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("creative.mediaTree.loading")]}):T?E(i):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground italic",children:t("creative.mediaTree.empty")})})})]})},$A=[{type:"all",icon:"stack",labelKey:"creative.preview.filter.all"},{type:"image",icon:"file-image",labelKey:"creative.preview.filter.image"},{type:"audio",icon:"music",labelKey:"creative.preview.filter.audio"},{type:"video",icon:"file-video",labelKey:"creative.preview.filter.video"},{type:"model",icon:"folder-3",labelKey:"creative.preview.filter.model"},{type:"document",icon:"file-text",labelKey:"creative.preview.filter.document"}],BA=["public","output"],zA={jpg:"image",jpeg:"image",png:"image",gif:"image",webp:"image",bmp:"image",tiff:"image",tif:"image",svg:"image",mp4:"video",webm:"video",mov:"video",avi:"video",mkv:"video",wmv:"video",flv:"video",m4v:"video",mp3:"audio",wav:"audio",ogg:"audio",flac:"audio",aac:"audio",wma:"audio",m4a:"audio",glb:"model",gltf:"model",obj:"model",stl:"model",fbx:"model",pdf:"document"},VA=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`,_A=t=>["mp4","webm","mov","avi","mkv","wmv","flv","m4v"].includes(t),UA=t=>["mp3","wav","ogg","flac","aac","wma","m4a"].includes(t),WA=t=>["jpg","jpeg","png","gif","webp","bmp","tiff","tif","svg"].includes(t),bf=t=>t.split(".").pop()?.toLowerCase()??"";function KA(t){const e=t.split("."),n=e.length>1?e.pop().toLowerCase():"",r=zA[n];return r?{mediaType:r,extension:n}:null}async function HA(t,e,n){const r=[],i=new Set,a=[];for(const l of e)a.push(`${t}/${l}`);for(;a.length>0;){const l=a.pop();try{const{entries:c}=await n(l,{respectGitignore:!0});for(const d of c){if(d.isDirectory){a.push(d.path);continue}const p=KA(d.name);p&&(i.has(d.path)||(i.add(d.path),r.push({name:d.name,path:d.path,mediaType:p.mediaType,extension:p.extension})))}}catch{}}return r}const GA=()=>{const t=at.c(46),{t:e}=ut(),n=Ie(qA),r=Ie(YA),i=Ie(QA),a=Ie(JA),l=Ir(),{files:c}=Pn(),[d,p]=o.useState(null),[m,u]=o.useState(!1),[h,x]=o.useState(!1);let f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=[],t[0]=f):f=t[0];const[v,y]=o.useState(f),[g,w]=o.useState(!1),[b,k]=o.useState("all");let I,j;t[1]!==l||t[2]!==c?(I=()=>{if(!l){y([]);return}let Q=!1;return w(!0),HA(l,BA,c.listDirectory.bind(c)).then(ne=>{Q||(y(ne),w(!1))}).catch(()=>{Q||w(!1)}),()=>{Q=!0}},j=[l,c],t[1]=l,t[2]=c,t[3]=I,t[4]=j):(I=t[3],j=t[4]),o.useEffect(I,j);let N,D;t[5]!==n?(N=()=>{if(!n){p(null),u(!1),x(!1);return}u(!0),x(!1),fetch(`/api/fs/stat?path=${encodeURIComponent(n)}`).then(XA).then(Q=>{const ne=bf(n);p({name:n.split("/").pop()??"",path:n,size:Q.size??0,type:Q.mime??ne.toUpperCase(),modified:Q.modified?new Date(Q.modified).toLocaleString():"-"}),u(!1)}).catch(()=>{x(!0),u(!1)})},D=[n],t[5]=n,t[6]=N,t[7]=D):(N=t[6],D=t[7]),o.useEffect(N,D);let E;e:{if(b==="all"){E=v;break e}let Q;if(t[8]!==b||t[9]!==v){let ne;t[11]!==b?(ne=G=>G.mediaType===b,t[11]=b,t[12]=ne):ne=t[12],Q=v.filter(ne),t[8]=b,t[9]=v,t[10]=Q}else Q=t[10];E=Q}const T=E;let C;t[13]!==a||t[14]!==r?(C=Q=>{r(Q.path),a(!1)},t[13]=a,t[14]=r,t[15]=C):C=t[15];const S=C;let M;t[16]!==b||t[17]!==e?(M=()=>s.jsx("div",{className:"flex gap-2 px-3 py-2 border-b border-border/40 overflow-x-auto shrink-0",children:$A.map(Q=>s.jsxs("button",{type:"button",onClick:()=>k(Q.type),className:ce("flex items-center gap-1.5 rounded-full px-2.5 py-1 typography-meta whitespace-nowrap transition-colors",b===Q.type?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground hover:bg-interactive-hover/40"),children:[s.jsx(P,{name:Q.icon,className:"h-3.5 w-3.5"}),e(Q.labelKey)]},Q.type))}),t[16]=b,t[17]=e,t[18]=M):M=t[18];const A=M;let R;t[19]!==T||t[20]!==S||t[21]!==g||t[22]!==n||t[23]!==e?(R=()=>g?s.jsx("div",{className:"flex items-center justify-center py-8",children:s.jsx(P,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}):T.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[s.jsx(P,{name:"file",className:"h-8 w-8 mb-2"}),s.jsx("p",{className:"typography-meta",children:e("creative.preview.noMediaFiles")})]}):s.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-1 p-2",children:T.map(Q=>s.jsxs("button",{type:"button",onClick:()=>S(Q),className:ce("flex flex-col items-center gap-1 rounded-md p-1.5 transition-colors text-left","hover:bg-interactive-hover/40 select-none",n===Q.path&&"bg-interactive-selection/50 ring-1 ring-primary/30"),title:Q.path,children:[s.jsx(Zn,{filePath:Q.path,extension:Q.extension,className:"h-8 w-8"}),s.jsx("span",{className:"w-full truncate text-center typography-small text-muted-foreground",children:Q.name})]},Q.path))}),t[19]=T,t[20]=S,t[21]=g,t[22]=n,t[23]=e,t[24]=R):R=t[24];const z=R;let B;t[25]!==h||t[26]!==d||t[27]!==i||t[28]!==m||t[29]!==n||t[30]!==a||t[31]!==r||t[32]!==e?(B=()=>{if(!n)return null;if(m)return s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx(P,{name:"loader-4",className:"h-6 w-6 animate-spin text-muted-foreground"})});if(h)return s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("p",{className:"typography-meta text-destructive",children:e("creative.preview.notFound")})});const Q=bf(n),ne=WA(Q),G=_A(Q),le=UA(Q);return s.jsxs("div",{className:"border-b border-border/40",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",children:[s.jsx("span",{className:"typography-small font-medium truncate flex-1",children:n.split("/").pop()}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",onClick:()=>a(!i),className:ce("flex h-6 w-6 items-center justify-center rounded-md transition-colors",i?"bg-interactive-selection/70 text-foreground":"text-muted-foreground hover:text-foreground hover:bg-interactive-hover/40"),title:e("layout.rightSidebar.previewInfo"),children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:()=>r(null),className:"flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/40 transition-colors",title:"Close preview",children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx("div",{className:"flex items-center justify-center p-3 max-h-[40vh] overflow-hidden",children:ne?s.jsx("img",{src:`/api/fs/raw?path=${encodeURIComponent(n)}`,alt:n.split("/").pop()??"",className:"max-h-full max-w-full object-contain rounded-md"}):G?s.jsx("video",{src:`/api/fs/raw?path=${encodeURIComponent(n)}`,controls:!0,className:"max-h-full max-w-full rounded-md"}):le?s.jsxs("div",{className:"flex flex-col items-center gap-3 w-full max-w-sm",children:[s.jsx(P,{name:"music",className:"h-10 w-10 text-muted-foreground"}),s.jsx("audio",{src:`/api/fs/raw?path=${encodeURIComponent(n)}`,controls:!0,className:"w-full"})]}):s.jsxs("div",{className:"flex flex-col items-center gap-2 text-muted-foreground py-4",children:[s.jsx(P,{name:"file",className:"h-12 w-12"}),s.jsx("span",{className:"typography-meta",children:Q.toUpperCase()})]})}),i&&d&&s.jsxs("div",{className:"border-t border-border/40 bg-sidebar p-3 overflow-y-auto",children:[s.jsx("h4",{className:"typography-meta font-medium mb-2",children:e("creative.preview.info.title")}),s.jsxs("dl",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.name")}),s.jsx("dd",{className:"typography-meta text-right max-w-[60%] truncate",children:d.name})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.path")}),s.jsx("dd",{className:"typography-meta text-right max-w-[60%] truncate",title:d.path,children:d.path})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.size")}),s.jsx("dd",{className:"typography-meta text-right",children:VA(d.size)})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.type")}),s.jsx("dd",{className:"typography-meta text-right",children:d.type})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.modified")}),s.jsx("dd",{className:"typography-meta text-right",children:d.modified})]})]})]})]})},t[25]=h,t[26]=d,t[27]=i,t[28]=m,t[29]=n,t[30]=a,t[31]=r,t[32]=e,t[33]=B):B=t[33];const V=B;let $;t[34]!==A?($=A(),t[34]=A,t[35]=$):$=t[35];let _;t[36]!==V?(_=V(),t[36]=V,t[37]=_):_=t[37];let X;t[38]!==z?(X=z(),t[38]=z,t[39]=X):X=t[39];let O;t[40]!==_||t[41]!==X?(O=s.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[_,X]}),t[40]=_,t[41]=X,t[42]=O):O=t[42];let J;return t[43]!==$||t[44]!==O?(J=s.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:[$,O]}),t[43]=$,t[44]=O,t[45]=J):J=t[45],J};function qA(t){return t.selectedMediaFilePath}function YA(t){return t.setSelectedMediaFilePath}function QA(t){return t.isPreviewInfoOpen}function JA(t){return t.setPreviewInfoOpen}function XA(t){if(!t.ok)throw new Error("Not found");return t.json()}const ZA=()=>{const t=at.c(29),{t:e}=ut(),n=Ie(eD),r=Ie(tD);let i;t[0]!==e?(i=e("layout.rightSidebar.media"),t[0]=e,t[1]=i):i=t[1];let a;t[2]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(P,{name:"folder-3",className:"h-3.5 w-3.5"}),t[2]=a):a=t[2];let l;t[3]!==i?(l={id:"media",label:i,icon:a},t[3]=i,t[4]=l):l=t[4];let c;t[5]!==e?(c=e("layout.rightSidebar.preview"),t[5]=e,t[6]=c):c=t[6];let d;t[7]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(P,{name:"eye",className:"h-3.5 w-3.5"}),t[7]=d):d=t[7];let p;t[8]!==c?(p={id:"preview",label:c,icon:d},t[8]=c,t[9]=p):p=t[9];let m;t[10]!==l||t[11]!==p?(m=[l,p],t[10]=l,t[11]=p,t[12]=m):m=t[12];const u=m;let h;t[13]!==r?(h=w=>r(w),t[13]=r,t[14]=h):h=t[14];let x;t[15]!==n||t[16]!==h||t[17]!==u?(x=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Cr,{items:u,activeId:n,onSelect:h,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[15]=n,t[16]=h,t[17]=u,t[18]=x):x=t[18];let f;t[19]!==n?(f=n==="media"&&s.jsx(OA,{}),t[19]=n,t[20]=f):f=t[20];let v;t[21]!==n?(v=n==="preview"&&s.jsx(GA,{}),t[21]=n,t[22]=v):v=t[22];let y;t[23]!==v||t[24]!==f?(y=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[f,v]}),t[23]=v,t[24]=f,t[25]=y):y=t[25];let g;return t[26]!==y||t[27]!==x?(g=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[x,y]}),t[26]=y,t[27]=x,t[28]=g):g=t[28],g};function eD(t){return t.creativeRightSidebarTab}function tD(t){return t.setCreativeRightSidebarTab}const sD=()=>{const t=at.c(13),[e,n]=Be.useState(!1);let r,i;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(gn())},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),Be.useEffect(r,i);let a;t[2]!==e?(a=async h=>e?await Vy(h):{success:!0,path:h},t[2]=e,t[3]=a):a=t[3];const l=a;let c;t[4]!==e?(c=async h=>e?await _y():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async h=>e?await Uy():{success:!0},t[6]=e,t[7]=p):p=t[7];const m=p;let u;return t[8]!==e||t[9]!==l||t[10]!==d||t[11]!==m?(u={isDesktop:e,requestAccess:l,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=l,t[10]=d,t[11]=m,t[12]=u):u=t[12],u},nD=t=>t==="/",Al=t=>t.replace(/\\/g,"/"),ru=t=>{if(!t||nD(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},ma=t=>t.endsWith("/"),rD=t=>{const e=t.trim();return!e||ma(e)?e:`${e}/`},iu=t=>t.lastIndexOf("/"),_g=t=>{if(ma(t))return t;const e=iu(t);return e<0?t:t.slice(0,e+1)},iD=t=>{const e=iu(t);return t.slice(e+1)},Ug=t=>{const e=ru(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=iu(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},aD=t=>ma(t)&&Ug(t)!==null,yf=(t,e)=>`${_g(t)}${e}/`,Zi=t=>{if(!t)return null;const e=ru(Al(t.trim()));return e?e.toLowerCase():null},vf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},oD=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,_c=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},lD=async()=>{try{const t=await fetch("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(t.ok){const e=await t.json();if(typeof e.home=="string"&&e.home.trim().length>0)return Al(e.home.trim())}}catch{}return Zs.getFilesystemHome().catch(()=>null)},cD=({open:t,onOpenChange:e})=>{const{t:n}=ut(),r=$s(Te=>Te.homeDirectory),i=As(Te=>Te.projects),a=As(Te=>Te.addProject),l=Qn(Te=>Te.profiles),c=Qn(Te=>Te.globalIdentity),d=Qn(Te=>Te.defaultGitIdentityId),p=Qn(Te=>Te.loadProfiles),m=Qn(Te=>Te.loadGlobalIdentity),u=Qn(Te=>Te.loadDefaultGitIdentityId),h=$l(),{isDesktop:x,requestAccess:f,startAccessing:v}=sD(),{isMobile:y}=rn(),g=o.useRef(null),w=o.useRef(null),b=o.useRef(new Map),[k,I]=o.useState(""),[j,N]=o.useState("~/"),[D,E]=o.useState([]),[T,C]=o.useState(!1),[S,M]=o.useState(!1),[A,R]=o.useState(0),[z,B]=o.useState(!1),[V,$]=o.useState(!1),[_,X]=o.useState(0),[O,J]=o.useState(!1),[Q,ne]=o.useState(""),[G,le]=o.useState(null),[oe,F]=o.useState(!1),[U,W]=o.useState(""),[te,K]=o.useState(!1),ae=k||r,ve=o.useMemo(()=>new Set(i.map(Te=>Zi(Te.path)).filter(Te=>!!Te)),[i]);o.useEffect(()=>{if(!t)return;N("~/"),E([]),R(0),B(!1),$(!1),J(!1),ne(""),le(null),F(!1),W(""),K(!1),requestAnimationFrame(()=>_c(g.current));let Te=!1;return(async()=>{const Ze=await lD();Te||(I(Ze||r||""),requestAnimationFrame(()=>_c(g.current)))})(),()=>{Te=!0}},[r,t]),o.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const re=o.useMemo(()=>{const Te=new Map;c&&Te.set(c.id,c);for(const We of l)Te.set(We.id,We);return Array.from(Te.values())},[l,c]);o.useEffect(()=>{if(!t||!O||G!==null)return;const Te=typeof d=="string"?d.trim():"";if(Te&&re.some(Ze=>Ze.id===Te)){le(Te);return}const We=re.find(Ze=>Ze.authType==="ssh"||Ze.sshKey);We&&le(We.id)},[re,d,O,t,G]);const be=o.useMemo(()=>re.find(Te=>Te.id===G)??null,[re,G]),pe=o.useMemo(()=>_g(j),[j]),ye=o.useMemo(()=>ma(j)?"":iD(j),[j]),ie=o.useMemo(()=>ae?vf(pe,ae):"",[pe,ae]);o.useEffect(()=>{if(!t||!ie){E([]);return}let Te=!1;return C(!0),M(!1),Zs.listLocalDirectory(ie).then(We=>{if(Te)return;M(!1);const Ze=We.filter(Qe=>Qe.isDirectory).map(Qe=>({name:Qe.name,path:Al(Qe.path)})).sort((Qe,he)=>Qe.name.localeCompare(he.name));E(Ze)}).catch(()=>{Te||(E([]),M(!0))}).finally(()=>{Te||C(!1)}),()=>{Te=!0}},[ie,t]);const ue=o.useMemo(()=>{const Te=ye.toLowerCase(),We=h||ye.startsWith(".");return D.filter(Ze=>Ze.name.toLowerCase().startsWith(Te)&&(We||!Ze.name.startsWith(".")))},[ye,D,h]),se=o.useMemo(()=>{const Te=[];aD(j)&&Te.push({type:"up",value:"browse:up",name:"..",path:Ug(j)});for(const We of ue){const Ze=Zi(We.path);Te.push({type:"directory",value:`browse:${We.path}`,name:We.name,path:We.path,disabled:!!(Ze&&ve.has(Ze))})}return Te},[ve,ue,j]);o.useEffect(()=>{R(0)},[j,se.length]);const Ne=o.useMemo(()=>ae?ru(vf(j,ae)):"",[ae,j]),Ce=Zi(Ne),je=!!(Ce&&ve.has(Ce)),we=o.useMemo(()=>ye?ue.find(Te=>Te.name===ye)??null:null,[ye,ue]),ke=!!(Ne&&!je&&(ma(j)&&S||!ma(j)&&ye.trim().length>0&&we===null)),xe=!z&&!V&&!je&&!!Ne,me=xe&&Q.trim().length>0,Me=se[A]??null,Ue=!!(Me&&(Me.type==="up"||Me.type==="directory"&&!Me.disabled)),q=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Se=n(je?"directoryExplorerDialog.actions.alreadyAdded":O?z?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":z?"directoryExplorerDialog.actions.adding":ke?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const Te=w.current;if(!Te)return;const We=()=>X(Math.ceil(Te.getBoundingClientRect().width));if(We(),typeof ResizeObserver>"u")return;const Ze=new ResizeObserver(We);return Ze.observe(Te),()=>Ze.disconnect()},[Se]),o.useLayoutEffect(()=>{const Te=g.current;Te&&(Te.scrollLeft=Te.scrollWidth)},[_,j]),o.useLayoutEffect(()=>{t&&_c(g.current)},[t]),o.useLayoutEffect(()=>{const Te=se[A];Te&&b.current.get(Te.value)?.scrollIntoView({block:"nearest"})},[A,se]);const $e=o.useCallback(()=>{e(!1)},[e]),Pe=o.useCallback(async Te=>{if(!Te||z)return;const We=Zi(Te);if(We&&ve.has(We))return;let Ze=Te;B(!0);try{const Qe=!O&&ke&&Zi(Te)===Zi(Ne);if(O){const Ge=Q.trim();if(!Ge){H.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ze=(await Zs.cloneRepository({remoteUrl:Ge,destinationPath:Te,gitIdentityId:be?.id??null})).path}else Qe&&await Zs.createDirectory(Te,{allowOutsideWorkspace:!0,initializeTemplate:!0});if(!a(Ze)){H.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}$e()}catch(Qe){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Qe instanceof Error?Qe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{B(!1)}},[a,ve,Q,$e,O,z,be?.id,ke,Ne,n]),fe=o.useCallback(Te=>{N(rD(Te))},[]),L=o.useCallback(Te=>{N(yf(j,Te.name))},[j]),Z=o.useCallback(Te=>{if(Te){if(Te.type==="up"){Te.path&&fe(Te.path);return}Te.disabled||L(Te)}},[fe,L]),Y=o.useCallback(async()=>{if(!(!x||V)){$(!0);try{const Te=await f(Ne);if(!Te.success||!Te.path){Te.error&&Te.error!=="Directory selection cancelled"&&H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te.error});return}const We=await v(Te.path);if(!We.success){H.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:We.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Pe(Te.path)}catch(Te){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te instanceof Error?Te.message:n("directoryExplorerDialog.toast.unknownError")})}finally{$(!1)}}},[Pe,x,V,f,v,n,Ne]),Ee=o.useCallback(Te=>{if(Te.key==="ArrowDown"){Te.preventDefault(),R(We=>Math.min(se.length-1,We+1));return}if(Te.key==="ArrowUp"){Te.preventDefault(),R(We=>Math.max(0,We-1));return}if(Te.key==="Enter"){if(Te.preventDefault(),oD(Te)){Pe(Ne);return}Ue&&Z(Me);return}Te.key==="Backspace"&&j===""&&(Te.preventDefault(),$e())},[Z,Pe,$e,Ue,Me,j,se.length,Ne]),Ae=o.useCallback(async()=>{const Te=U.trim();if(!(!Te||te)){K(!0);try{const We=`${ie}${Te}`;await Zs.createDirectory(We,{allowOutsideWorkspace:!0,initializeTemplate:!0}),H.success(n("directoryExplorerDialog.toast.folderCreated")),N(yf(j,Te)),F(!1),W("")}catch(We){H.error(n("directoryExplorerDialog.toast.failedToCreateFolder"),{description:We instanceof Error?We.message:n("directoryExplorerDialog.toast.unknownError")})}finally{K(!1)}}},[U,te,ie,j,n]),Je=o.useCallback(Te=>{Te.stopPropagation(),Te.key==="Enter"?(Te.preventDefault(),Ae()):Te.key==="Escape"&&(Te.preventDefault(),F(!1),W(""))},[Ae]),de=s.jsxs("button",{type:"button",onClick:()=>Qo(!h),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[h?s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),ze=s.jsxs("div",{className:"px-2.5 py-1.5",children:[O?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Bt,{value:Q,onChange:Te=>ne(Te.target.value),placeholder:n("directoryExplorerDialog.clone.remoteUrlPlaceholder"),className:"min-w-0 flex-1 border-border/60 bg-[var(--surface-elevated)] font-mono typography-ui-label shadow-none",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),s.jsx($h,{activeProfile:be,identities:re,onSelect:Te=>le(Te.id),isApplying:z,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(P,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(Bt,{ref:g,value:j,onChange:Te=>N(Al(Te.target.value)),onKeyDown:Ee,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!y&&_>0?{paddingRight:`${_+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),y?null:s.jsx(ge,{ref:w,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:O?!me:!xe,onMouseDown:Te=>Te.preventDefault(),onClick:()=>{Pe(Ne)},title:Se,children:Se})]})]}),rt=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsxs("div",{className:"flex items-center justify-between px-2 pb-1 pt-0.5",children:[s.jsx("div",{className:"typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),!O&&!oe&&s.jsxs("button",{type:"button",onClick:()=>{F(!0),W(""),K(!1)},className:"flex items-center gap-1 rounded px-1.5 py-0.5 typography-meta text-primary hover:bg-primary/10 transition-colors",children:[s.jsx(P,{name:"folder-add",className:"h-3.5 w-3.5"}),s.jsx("span",{children:n("directoryExplorerDialog.actions.newFolder")})]})]}),T?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):se.length===0&&!oe?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):s.jsxs("div",{className:"space-y-0.5",children:[oe&&s.jsxs("div",{className:"flex w-full items-center gap-2 rounded-lg px-2 py-1 border border-primary/40 bg-interactive-hover/30",children:[s.jsx(P,{name:"folder-add",className:"h-4 w-4 flex-shrink-0 text-primary"}),s.jsx("input",{type:"text",value:U,onChange:Te=>W(Te.target.value),onKeyDown:Je,placeholder:n("directoryExplorerDialog.newFolder.placeholder"),className:"min-w-0 flex-1 bg-transparent border-none outline-none font-mono typography-ui-label text-foreground placeholder:text-muted-foreground/60",autoFocus:!0,disabled:te}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",disabled:te||!U.trim(),onClick:Ae,title:n("directoryExplorerDialog.newFolder.confirm"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-primary",children:s.jsx(P,{name:"check",className:"h-4 w-4"})}),s.jsx("button",{type:"button",disabled:te,onClick:()=>{F(!1),W("")},title:n("directoryExplorerDialog.newFolder.cancel"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-muted-foreground",children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]})]}),se.map((Te,We)=>{const Ze=We===A;return s.jsxs("button",{ref:Qe=>{Qe?b.current.set(Te.value,Qe):b.current.delete(Te.value)},type:"button",disabled:Te.type==="directory"&&Te.disabled,onMouseEnter:()=>R(We),onMouseDown:Qe=>Qe.preventDefault(),onClick:()=>Z(Te),className:ce("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ze&&"bg-interactive-selection text-interactive-selection-foreground",!Ze&&"hover:bg-interactive-hover/50",Te.type==="directory"&&Te.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Te.type==="up"?s.jsx(P,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(P,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Te.name})}),Te.type==="directory"&&Te.disabled?s.jsx("span",{className:"rounded-full border border-border/60 px-2 py-0.5 typography-meta text-muted-foreground",children:n("directoryExplorerDialog.browse.addedBadge")}):null]},Te.value)})]})]})}),Re=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[ze,rt]}),Xe=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(P,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(P,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(P,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:q}),s.jsx(P,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),qe=()=>s.jsxs(s.Fragment,{children:[y?null:Xe,s.jsxs("div",{className:ce("flex w-full flex-row justify-end gap-2 sm:w-auto",y&&"justify-stretch"),children:[x?s.jsx(ge,{variant:"ghost",size:"xs",onClick:Y,disabled:z||V||O,children:n(V?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(ge,{variant:"ghost",size:"xs",onClick:()=>J(Te=>!Te),disabled:z||V,className:ce(y&&"flex-1"),children:n(O?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),y?s.jsx(ge,{size:"xs",onClick:()=>{Pe(Ne)},disabled:O?!me:!xe,className:"flex-1",children:Se}):null]})]});return y?s.jsx($r,{open:t,onClose:$e,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:s.jsx("div",{className:"flex flex-col gap-2",children:qe()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:de}),Re]})}):s.jsx(hs,{open:t,onOpenChange:e,children:s.jsxs(fs,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(bs,{className:"px-5 pb-2 pt-5",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx(gs,{children:n("directoryExplorerDialog.title")}),s.jsx(Is,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),de]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:Re}),s.jsx(Vs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:qe()})]})})},Ci=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Fr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},dD=()=>{const{t}=ut(),[e,n]=o.useState(!1),[r,i]=o.useState(!1),[a,l]=o.useState(null),[c,d]=o.useState([]),[p,m]=o.useState(!1),[u,h]=o.useState(!1),[x,f]=o.useState(!1),[v,y]=o.useState(!1),[g,w]=o.useState(new Set),b=Ot(se=>se.getWorktreeMetadata),k=Ot(se=>se.newSessionDraft),I=Ot(se=>se.setNewSessionDraftTarget),j=Ot(se=>se.setDraftBootstrapPendingDirectory),N=Wy,D=Gy,E=Ot(se=>se.deleteSessions),T=Ot(se=>se.archiveSessions),C=Ie(se=>se.showDeletionDialog),S=Ie(se=>se.setShowDeletionDialog),M=$s(se=>se.currentDirectory),A=$s(se=>se.homeDirectory),R=$s(se=>se.isHomeReady),z=As(se=>se.projects),B=As(se=>se.activeProjectId),{isMobile:V,isTablet:$,hasTouchInput:_}=rn(),X=V||$||_,O=o.useMemo(()=>{const Ne=(B?z.find(Ce=>Ce.id===B)??null:null)?.path??M;return Fr(Ne)},[B,M,z]),J=o.useCallback(se=>{const Ce=Fr(se.projectDirectory)||O;return{id:(z.find(we=>Fr(we.path)===Ce)??null)?.id??`path:${Ce}`,path:Ce}},[O,z]),Q=v&&g.size>0,ne=o.useMemo(()=>{const se=a?.worktree;return se&&typeof se.branch=="string"&&se.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Ne})=>typeof Ne.branch=="string"&&Ne.branch.trim().length>0)},[a?.worktree,c]),G=a?.mode==="worktree",le=G,oe=x||!G||!ne,F=x||!G;o.useEffect(()=>{r||!R||z.length>0||(i(!0),n(!0))},[r,R,z.length]);const U=o.useCallback(se=>{l({sessions:se.sessions,dateLabel:se.dateLabel,mode:se.mode??"session",worktree:se.worktree??null})},[]),W=o.useCallback(()=>{l(null),d([]),m(!1),h(!1),f(!1),y(!1),w(new Set)},[]),te=o.useCallback(async se=>{if(se.sessions.length===0)return;if(se.sessions.length===1){const we=se.sessions[0];await N(we.id)?H.success(t("sessions.sidebar.session.delete.success")):H.error(t("sessions.sidebar.session.delete.error"));return}const Ne=se.sessions.map(we=>we.id),{deletedIds:Ce,failedIds:je}=await E(Ne);if(Ce.length>0){const we=je.length>0?je.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:je.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:je.length}):se.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:se.dateLabel}):void 0;H.success(Ce.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ce.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ce.length}),{description:Ci(we)})}je.length>0&&H.error(je.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:je.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:je.length}),{description:Ci(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[N,E,t]);o.useEffect(()=>Sr.onDeleteRequest(se=>{if(!C&&(se.mode??"session")==="session"){te(se);return}U(se)}),[U,C,te]),o.useEffect(()=>Sr.onDirectoryRequest(()=>{n(!0)}),[]),o.useEffect(()=>{if(!a){d([]),m(!1),h(!1),y(!1),w(new Set);return}const se=a.sessions.map(je=>{const we=b(je.id);return we?{session:je,metadata:we}:null}).filter(je=>!!je);d(se),m(!1),y(!1),w(new Set);const Ne=new Map;if(a.worktree?.path&&Ne.set(Fr(a.worktree.path),a.worktree),se.forEach(({metadata:je})=>{je.path&&Ne.set(Fr(je.path),je)}),Ne.size===0){y(!0);return}let Ce=!1;return(async()=>{const je=new Map,we=new Set;await Promise.all(Array.from(Ne.entries()).map(async([ke,xe])=>{try{const me=await Ky(xe.path);je.set(ke,me),me?.isDirty&&we.add(ke)}catch{xe.status&&(je.set(ke,xe.status),xe.status.isDirty&&we.add(ke))}})).catch(ke=>{console.warn("Failed to inspect worktree status before deletion:",ke)}),!Ce&&(w(we),y(!0),l(ke=>{if(!ke?.worktree?.path)return ke;const xe=Fr(ke.worktree.path),me=je.get(xe);if(!me)return ke;const Me=ke.worktree.status;return Me?.isDirty===me.isDirty&&Me?.ahead===me.ahead&&Me?.behind===me.behind&&Me?.upstream===me.upstream?ke:{...ke,worktree:{...ke.worktree,status:me}}}),d(ke=>ke.map(xe=>{const me=Fr(xe.metadata.path),Me=je.get(me);return Me?{session:xe.session,metadata:{...xe.metadata,status:Me}}:xe})))})(),()=>{Ce=!0}},[a,b]),o.useEffect(()=>{ne||m(!1)},[ne]);const K=o.useCallback(async(se,Ne)=>{const Ce=p&&ne,je=J(se),we=Fr(se.path),ke=Fr(je.path);try{await Hy(je,se,{deleteRemoteBranch:Ce,deleteLocalBranch:Ne});const xe=Fr(k?.directoryOverride);return k?.open&&we&&xe===we&&ke&&(j(null),I({projectId:je.id,directoryOverride:ke},{force:!0})),Fr(M)===we&&ke&&$s.getState().setDirectory(ke,{showOverlay:!1}),!0}catch(xe){return H.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Ci(xe instanceof Error?xe.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ne,M,p,J,k?.directoryOverride,k?.open,j,I,t]),ae=o.useCallback(async()=>{if(a){f(!0);try{const se=le,Ne=se&&p,Ce=se&&u;if(a.sessions.length===0&&G&&a.worktree){if(!await K(a.worktree,Ce)){W();return}const ke=t(p&&ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");H.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Ci(ke)}),W();return}if(a.sessions.length===1){const je=a.sessions[0];if(!(G?await D(je.id):await N(je.id,{archiveWorktree:!1,deleteRemoteBranch:Ne,deleteLocalBranch:Ce}))){H.error(t(G?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),f(!1);return}const ke=!G&&se?t(Ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;H.success(t(G?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Ci(ke),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const je=a.sessions.map(xe=>xe.id);let we=[],ke=[];if(G){const xe=await T(je);we=xe.archivedIds,ke=xe.failedIds}else{const xe=await E(je);we=xe.deletedIds,ke=xe.failedIds}if(G&&a.worktree&&ke.length===0&&await K(a.worktree,Ce),we.length>0){const xe=!G&&se?t(Ne?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Me=[ke.length>0?G?ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:ke.length}):ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ke.length}):a.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:a.dateLabel}):void 0,xe].filter(Boolean).join(" ");H.success(G?we.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:we.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:we.length}):we.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:we.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:we.length}),{description:Ci(Me||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ke.length>0&&(H.error(G?ke.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:ke.length}):ke.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ke.length}),{description:Ci(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),we.length===0)){f(!1);return}}G&&a.sessions.length===1&&a.worktree&&await K(a.worktree,Ce),W()}finally{f(!1)}}},[a,p,u,N,E,D,T,W,le,G,ne,K,t]),ve=a?.worktree??c[0]?.metadata??null,re=a?a.mode==="worktree"?a.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):a.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:a.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:a.sessions.length}):a.sessions.length===1?a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:a.sessions.length,dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:a.sessions.length}):"",be=a?s.jsxs("div",{className:ce(G?"space-y-3":"space-y-2"),children:[a.sessions.length>0&&s.jsxs("div",{className:ce(G?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[G&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:a.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:a.sessions.length})]}),s.jsxs("ul",{className:ce(G?"mt-2 space-y-1":"space-y-0.5"),children:[a.sessions.slice(0,5).map(se=>s.jsxs("li",{className:ce(G?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:ce(!G&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:se.title||t("sessions.sidebar.session.untitled")})]},se.id)),a.sessions.length>5&&s.jsx("li",{className:ce(G?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:a.sessions.length-5})})]})]}),G?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),ve?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ve.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ve?ro(ve.path,A):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),Q&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,pe=G?ne?s.jsxs("button",{type:"button",onClick:()=>{oe||m(se=>!se)},disabled:oe,className:ce("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",oe?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,ye=G?s.jsxs("button",{type:"button",onClick:()=>{F||h(se=>!se)},disabled:F,className:ce("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",F?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ie=G?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[ye,pe]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{variant:"ghost",onClick:W,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ge,{variant:"destructive",onClick:ae,disabled:x,children:t(x?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>S(!C),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!C,children:[C?s.jsx(P,{name:"checkbox-blank",className:"size-4"}):s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{variant:"ghost",onClick:W,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ge,{variant:"destructive",onClick:ae,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ue=G?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[X?s.jsx($r,{open:!!a,onClose:()=>{x||W()},title:ue,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ie}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[re&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:re}),be]})}):s.jsx(hs,{open:!!a,onOpenChange:se=>{if(!se){if(x)return;W()}},children:s.jsxs(fs,{className:ce(G?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(bs,{children:[s.jsxs(gs,{className:ce(G&&"flex items-center gap-2"),children:[G&&s.jsx(P,{name:"delete-bin",className:"h-5 w-5"}),ue]}),re&&s.jsx(Is,{children:re})]}),s.jsx("div",{className:ce(G&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:be}),s.jsx(Vs,{className:"mt-2 gap-2 pt-1 pb-1",children:ie})]})}),s.jsx(cD,{open:e,onOpenChange:n})]})},Cd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),uD=(t,e)=>{const n=Cd(t),r=Cd(e);return`${n}-${r}`.substring(0,60)},wf=(t,e)=>`${t}/${e}`,mD=()=>{const t=As.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(i=>i.id===e);if(n?.path)return{id:n.id,path:n.path};const r=$s.getState().currentDirectory??null;if(r&&r.trim().length>0){const i=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${i}`,path:i}}return null},Uc=gr()(Na(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:i,agent:a,files:l,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r)return t({error:"Prompt is required"}),null;if(i.length<1)return t({error:"Select at least 1 model"}),null;if(i.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=mD();if(!d)return t({error:"Select a project",isLoading:!1}),null;const p=d.path,u=await nh(p)&&e.isolateRuns!==!1,h=Cd(n),x=u?await fo(p):void 0,f=u?await qy(p):null,v=[],y=c?.filter(N=>N.trim().length>0)??[],g=new Map;for(const N of i){const D=`${N.providerID}:${N.modelID}`;g.set(D,(g.get(D)||0)+1)}const w=new Map;for(const N of i){const D=`${N.providerID}:${N.modelID}`,E=g.get(D)||1,T=(w.get(D)||0)+1;w.set(D,T);const C=uD(N.providerID,N.modelID),S=E>1?wf(h,`${C}/${T}`):wf(h,C);try{const M=E>1?`${h}/${N.providerID}/${N.modelID}/${T}`:`${h}/${N.providerID}/${N.modelID}`;if(!u){const B=await Zs.withDirectory(p,()=>Zs.createSession({title:M}));v.push({sessionId:B.id,worktreePath:p,providerID:N.providerID,modelID:N.modelID,variant:N.variant});continue}const A=await Yy(d,{preferredName:S,mode:"new",branchName:S,worktreeName:S,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:y},{resolvedRootTrackingRemote:f}),R={...A,createdFromBranch:x,kind:"standard"},z=await Zs.withDirectory(A.path,()=>Zs.createSession({title:M}));Ot.getState().setWorktreeMetadata(z.id,R),v.push({sessionId:z.id,worktreePath:A.path,providerID:N.providerID,modelID:N.modelID,variant:N.variant})}catch(M){console.warn("[MultiRun] Failed to create session:",M)}}const b=c?.filter(N=>N.trim().length>0)??[];b.length>0&&rh(d,b).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const k=v.map(N=>N.sessionId),I=v[0]?.sessionId??null;if(k.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const j=l?.map(N=>({type:"file",mime:N.mime,filename:N.filename,url:N.url}));return(async()=>{try{await Promise.allSettled(v.map(async N=>{try{await Zs.withDirectory(N.worktreePath,()=>Zs.sendMessage({id:N.sessionId,providerID:N.providerID,modelID:N.modelID,variant:N.variant,text:r,agent:a,files:j}))}catch(D){console.warn("[MultiRun] Failed to start run:",D)}}))}catch(N){console.warn("[MultiRun] Failed to start runs:",N)}})(),t({isLoading:!1}),{groupSlug:h,sessionIds:k,firstSessionId:I}}catch(d){return t({error:d instanceof Error?d.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),pD="oc:lastWorktreeSourceBranch";function Wg(t){const e=at.c(30),{git:n}=Pn(),r=Rd(t),i=Ed(t),a=Fd(t),l=ch(t),c=tn(bD),d=tn(xD);let p,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==i||e[4]!==a?(p=()=>{!t||!n||i!==null||a||d(t,n,{silent:!0})},m=[t,n,d,i,a],e[0]=t,e[1]=d,e[2]=n,e[3]=i,e[4]=a,e[5]=p,e[6]=m):(p=e[5],m=e[6]),o.useEffect(p,m);let u;e[7]!==r?.all||e[8]!==t||e[9]!==c||e[10]!==n||e[11]!==i?(u=()=>{!t||!n||i===!0&&(r?.all||c(t,n))},e[7]=r?.all,e[8]=t,e[9]=c,e[10]=n,e[11]=i,e[12]=u):u=e[12];const h=r?.all;let x;e[13]!==t||e[14]!==c||e[15]!==n||e[16]!==i||e[17]!==h?(x=[t,n,i,h,c],e[13]=t,e[14]=c,e[15]=n,e[16]=i,e[17]=h,e[18]=x):x=e[18],o.useEffect(u,x);const f=a||i===!0&&l;let v;e:{if(!r?.all){let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[19]=N):N=e[19],v=N;break e}let j;e[20]!==r.all?(j=r.all.filter(gD).sort(),e[20]=r.all,e[21]=j):j=e[21],v=j}const y=v;let g;e:{if(!r?.all){let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[22]=N):N=e[22],g=N;break e}let j;e[23]!==r.all?(j=r.all.filter(hD).map(fD).sort(),e[23]=r.all,e[24]=j):j=e[24],g=j}const w=g;let b;e:{if(!t){b=null;break e}if(i!==null){b=i;break e}if(f){b=null;break e}b=r?.all?!0:null}const k=b;let I;return e[25]!==k||e[26]!==f||e[27]!==y||e[28]!==w?(I={localBranches:y,remoteBranches:w,isLoading:f,isGitRepository:k},e[25]=k,e[26]=f,e[27]=y,e[28]=w,e[29]=I):I=e[29],I}function fD(t){return t.replace(/^remotes\//,"")}function hD(t){return t.startsWith("remotes/")}function gD(t){return!t.startsWith("remotes/")}function xD(t){return t.fetchStatus}function bD(t){return t.fetchBranches}const yD=({directory:t,value:e,onChange:n,className:r,disabled:i,id:a})=>{const{t:l}=ut(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=Wg(t),u=o.useMemo(()=>[...c,...d.map(x=>`remotes/${x}`)],[c,d]);o.useEffect(()=>{if(i||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const f=t?await fo(t).catch(()=>null):null,v=localStorage.getItem(pD);v&&u.includes(v)?n(v):f&&u.includes(f)?n(f):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,i,p,n,e]);const h=i||!m||p;return s.jsxs("div",{children:[s.jsxs(is,{value:e,onValueChange:n,disabled:h,children:[s.jsx(as,{id:a,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(us,{placeholder:l(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(os,{className:"max-h-[280px] max-w-[320px]",children:p?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.loadingBranches")}):c.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[c.length>0&&s.jsxs(Xc,{children:[s.jsx(Vu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),c.map(x=>s.jsx(Ft,{value:x,className:"whitespace-normal break-all",children:x},x))]}),c.length>0&&d.length>0&&s.jsx(Qy,{}),d.length>0&&s.jsxs(Xc,{children:[s.jsx(Vu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),d.map(x=>s.jsx(Ft,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:l("multiRun.branchSelector.status.notInGitRepository")})]})},vD=10*1024*1024,Wc=5,Ko=t=>{const e=at.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let i;return e[1]!==n?(i=s.jsxs(Pt,{children:[r,s.jsx(Dt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=i):i=e[2],i},ea=t=>{const e=at.c(9),{htmlFor:n,required:r,children:i,info:a}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let c;e[2]!==i||e[3]!==n||e[4]!==l?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,l]}),e[2]=i,e[3]=n,e[4]=l,e[5]=c):c=e[5];const d=a&&a;let p;return e[6]!==c||e[7]!==d?(p=s.jsxs("div",{className:"flex items-center gap-1.5",children:[c,d]}),e[6]=c,e[7]=d,e[8]=p):p=e[8],p},wD=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:i}=ut(),[a,l]=o.useState(""),[c,d]=o.useState(()=>t??""),[p,m]=o.useState([]),[u,h]=o.useState(""),[x,f]=o.useState([]),[v,y]=o.useState(!1),[g,w]=o.useState([]),[b,k]=o.useState(!1),[I,j]=o.useState(!1),[N,D]=o.useState(!0),[E,T]=o.useState(!1),[C,S]=o.useState(""),[M,A]=o.useState(!1),[R,z]=o.useState(""),B=o.useRef(null),V=o.useRef(null),$=o.useRef(null),_=o.useRef(null),X=$s(Re=>Re.currentDirectory??null),O=$s(Re=>Re.homeDirectory??null),J=o.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Re=="string"&&Re.trim().length>0?Re.trim():null},[]),Q=As(Re=>Re.activeProjectId),ne=As(Re=>Re.setActiveProjectIdOnly),G=As(Re=>Re.projects),[le,oe]=o.useState(()=>Q??null);o.useEffect(()=>{if(Q){oe(Q);return}!le&&G.length>0&&oe(G[0].id)},[Q,G,le]);const F=o.useMemo(()=>le?G.find(Re=>Re.id===le)??null:null,[G,le]),U=F?.path??X,W=o.useCallback(Re=>{oe(Re),Re!==Q&&ne(Re)},[Q,ne]),{currentTheme:te}=Ar(),K=o.useCallback(Re=>{const Xe=Re.label?.trim()||Vi(Re.path,O),qe=xo({id:Re.id,iconImage:Re.iconImage??null},{themeVariant:te.metadata.variant,iconColor:te.colors.surface.foreground}),Te=Re.icon?Vl[Re.icon]:null,We=Re.color?bo[Re.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[qe?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Re.iconBackground?{backgroundColor:Re.iconBackground}:void 0,children:s.jsx("img",{src:qe,alt:"",className:"h-full w-full object-contain",draggable:!1})}):Te?s.jsx(P,{name:Te,className:"h-3.5 w-3.5 shrink-0",style:We?{color:We}:void 0}):s.jsx(P,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:We?{color:We}:void 0}),s.jsx("span",{className:"truncate",children:Xe})]})},[O,te.metadata.variant,te.colors.surface.foreground]),ae=o.useMemo(()=>{if(F?.path)return{id:F.id,path:F.path};const Re=X??J;return Re?{id:`path:${Re}`,path:Re}:null},[F,X,J]),[ve,re]=o.useState(()=>typeof window>"u"?!1:gn()),be=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),pe=El();o.useEffect(()=>{typeof window>"u"||re(gn())},[]);const ye=o.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__APP_MACOS_MAJOR__;if(typeof Re=="number"&&Number.isFinite(Re)&&Re>0)return Re;if(typeof navigator>"u")return null;const Xe=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Xe)return null;const qe=Number.parseInt(Xe[1],10),Te=Number.parseInt(Xe[2],10);return Number.isNaN(qe)?null:qe===10?Te:qe},[]),ie=o.useMemo(()=>ve&&be||pe?"pl-[5.5rem]":"pl-3",[ve,be,pe]),ue=o.useMemo(()=>!ve||!be||ye===null?"":ye>=26?"h-12":ye<=15?"h-14":"",[ve,be,ye]),se=o.useCallback(async Re=>{Re.target.closest("button, a, input, select, textarea")||Re.button===0&&ve&&await fh()},[ve]);o.useEffect(()=>{if(!n)return;const Re=Xe=>{Xe.key==="Escape"&&(Xe.preventDefault(),Xe.stopPropagation(),n())};return window.addEventListener("keydown",Re,!0),()=>window.removeEventListener("keydown",Re,!0)},[n]);const[Ne,Ce]=o.useState(""),{isLoading:je,isGitRepository:we}=Wg(U),ke=o.useRef(!1),xe=we===!0,me=xe&&N;o.useEffect(()=>{if(we===!1){ke.current=!0,D(!1);return}we===!0&&ke.current&&(ke.current=!1,D(!0))},[we]);const Me=Uc(Re=>Re.createMultiRun),Ue=Uc(Re=>Re.error),q=Uc(Re=>Re.clearError);o.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Re=>Re.trim().length>0?Re:t)},[t]),o.useEffect(()=>{if(!ae)return;let Re=!1;return j(!0),(async()=>{try{const Xe=await zd(ae);Re||w(Xe)}catch{}finally{Re||j(!1)}})(),()=>{Re=!0}},[ae]);const Se=Re=>{p.length>=Wc||(m(Xe=>[...Xe,Re]),q())},$e=Re=>{m(Xe=>Xe.filter((qe,Te)=>Te!==Re)),q()},Pe=o.useCallback((Re,Xe)=>{m(qe=>qe.map((Te,We)=>We===Re?Xe:Te))},[]),fe=async Re=>{const Xe=Re.target.files;if(!Xe)return;let qe=0;for(let Te=0;Te<Xe.length;Te++){const We=Xe[Te];if(We.size>vD){H.error(i("multirun.launcher.toast.fileTooLarge",{fileName:We.name}));continue}try{const Ze=await new Promise((he,Ge)=>{const Ve=new FileReader;Ve.onload=()=>he(Ve.result),Ve.onerror=Ge,Ve.readAsDataURL(We)}),Qe={id:Il(),filename:We.name,mimeType:We.type||"application/octet-stream",size:We.size,dataUrl:Ze};f(he=>[...he,Qe]),qe++}catch(Ze){console.error("File attach failed",Ze),H.error(i("multirun.launcher.toast.attachFailed",{fileName:We.name}))}}qe>0&&H.success(qe===1?i("multirun.launcher.toast.attachedSingle",{count:qe}):i("multirun.launcher.toast.attachedPlural",{count:qe})),B.current&&(B.current.value="")},L=Re=>{f(Xe=>Xe.filter(qe=>qe.id!==Re))},Z=o.useCallback((Re,Xe)=>{if(Re.startsWith("/")){const We=Re.indexOf(" "),Ze=Re.indexOf(`
|
|
224
|
+
`),Qe=Math.min(We===-1?Re.length:We,Ze===-1?Re.length:Ze);if(Xe<=Qe&&We===-1){z(Re.substring(1,Qe)),A(!0),T(!1);return}}A(!1);const qe=Re.substring(0,Xe),Te=qe.lastIndexOf("@");if(Te!==-1){const We=Te>0?qe[Te-1]:null,Ze=qe.substring(Te+1);(!We||/\s/.test(We))&&!Ze.includes(" ")&&!Ze.includes(`
|
|
225
|
+
`)?(S(Ze),T(!0)):T(!1);return}T(!1)},[]),Y=o.useCallback(Re=>{if(M&&_.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")){Re.preventDefault(),_.current.handleKeyDown(Re.key);return}E&&$.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")&&(Re.preventDefault(),$.current.handleKeyDown(Re.key))},[M,E]),Ee=o.useCallback(Re=>{const qe=V.current?.selectionStart??c.length,We=c.substring(0,qe).lastIndexOf("@"),Ze=Re.relativePath&&Re.relativePath.trim().length>0?Re.relativePath.trim():Re.path||Re.name,Qe=We!==-1?We:qe,he=`${c.substring(0,Qe)}@${Ze} ${c.substring(qe)}`,Ge=Qe+Ze.length+2;d(he),T(!1),S(""),requestAnimationFrame(()=>{const Ve=V.current;Ve&&(Ve.selectionStart=Ge,Ve.selectionEnd=Ge,Ve.focus()),Z(he,Ge)})},[c,Z]),Ae=o.useCallback(Re=>{const qe=V.current?.selectionStart??c.length,We=c.substring(0,qe).lastIndexOf("@"),Ze=We!==-1?We:qe,Qe=`${c.substring(0,Ze)}@${Re} ${c.substring(qe)}`,he=Ze+Re.length+2;d(Qe),T(!1),S(""),requestAnimationFrame(()=>{const Ge=V.current;Ge&&(Ge.selectionStart=he,Ge.selectionEnd=he,Ge.focus()),Z(Qe,he)})},[c,Z]),Je=o.useCallback(Re=>{const Xe=`/${Re.name} `;d(Xe),A(!1),z(""),requestAnimationFrame(()=>{const qe=V.current;qe&&(qe.focus(),qe.selectionStart=qe.value.length,qe.selectionEnd=qe.value.length),Z(Xe,Xe.length)})},[Z]),de=async Re=>{if(Re.preventDefault(),!!c.trim()&&!(p.length<2)){y(!0),q();try{le&&le!==Q&&ne(le);const Xe=p.map(({instanceId:Qe,...he})=>he),qe=x.map(Qe=>({mime:Qe.mimeType,filename:Qe.filename,url:Qe.dataUrl})),Te=g.filter(Qe=>Qe.trim().length>0),We={name:a.trim(),prompt:c.trim(),models:Xe,agent:u||void 0,worktreeBaseBranch:me?Ne:void 0,isolateRuns:me,files:qe.length>0?qe:void 0,setupCommands:Te.length>0?Te:void 0},Ze=await Me(We);Ze&&(Ze.firstSessionId&&Ot.getState().setCurrentSession(Ze.firstSessionId),e?.())}finally{y(!1)}}},ze=!!(a.trim()&&c.trim()&&p.length>=2&&U&&!je&&(we===!1||!me||Ne)),rt=g.filter(Re=>Re.trim()).length;return s.jsxs("form",{onSubmit:de,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:se,className:ce("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",ie,ue),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:i("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(P,{name:"close",className:"h-5 w-5"})})}),s.jsx(Dt,{children:s.jsx("p",{children:i("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(po,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"multirun-project",required:!0,children:i("multirun.launcher.project.label")}),G.length>0?s.jsxs(is,{value:le??void 0,onValueChange:W,children:[s.jsx(as,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:F?s.jsx(us,{children:K(F)}):s.jsx(us,{placeholder:i("multirun.launcher.project.placeholder")})}),s.jsx(os,{fitContent:!0,children:G.map(Re=>s.jsx(Ft,{value:Re.id,className:"max-w-[24rem]",children:K(Re)},Re.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:i("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"group-name",required:!0,info:s.jsx(Ko,{children:i("multirun.launcher.groupName.info")}),children:i("multirun.launcher.groupName.label")}),s.jsx(Bt,{id:"group-name",value:a,onChange:Re=>l(Re.target.value),placeholder:i("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Ko,{children:i("multirun.launcher.baseBranch.info")}),children:i("multirun.launcher.baseBranch.label")}),s.jsx(yD,{directory:U,value:Ne,onChange:Ce,disabled:!me,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(ds,{checked:N,onChange:D,disabled:!xe,ariaLabel:i("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:i("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"multirun-agent",info:s.jsx(Ko,{children:i("multirun.launcher.agent.info")}),children:i("multirun.launcher.agent.label")}),s.jsx(Lg,{value:u,onChange:h,id:"multirun-agent"})]})]}),s.jsxs(fr,{open:b,onOpenChange:k,children:[s.jsxs(Pr,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(P,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:i("multirun.launcher.setupCommands.label")}),rt>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:rt}),s.jsx(P,{name:"arrow-down-s",className:ce("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",b&&"rotate-180")})]}),s.jsx(hr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:I?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:i("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[g.map((Re,Xe)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Bt,{value:Re,onChange:qe=>{const Te=[...g];Te[Xe]=qe.target.value,w(Te)},placeholder:i("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const qe=g.filter((Te,We)=>We!==Xe);w(qe)},className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]},`${Re}-${Xe}`)),s.jsxs("button",{type:"button",onClick:()=>w([...g,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(P,{name:"add",className:"h-3 w-3"}),i("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(ea,{htmlFor:"prompt",required:!0,children:i("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(hn,{id:"prompt",ref:V,value:c,onChange:Re=>{const Xe=Re.target.value;d(Xe);const qe=Re.target.selectionStart??Xe.length;Z(Xe,qe)},onKeyDown:Y,placeholder:i("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),M?s.jsx(dh,{ref:_,searchQuery:R,onCommandSelect:Je,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,E?s.jsx(uh,{ref:$,searchQuery:C,onFileSelect:Ee,onAgentSelect:Ae,onClose:()=>T(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:B,type:"file",multiple:!0,className:"hidden",onChange:fe,accept:"*/*"}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>B.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(P,{name:"attachment-2",className:"h-3 w-3"}),i("multirun.launcher.attachments.attach")]})}),s.jsx(Dt,{children:i("multirun.launcher.attachments.tooltip")})]}),x.map(Re=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[Re.mimeType.startsWith("image/")?s.jsx(P,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(P,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Re.filename,children:Re.filename}),s.jsx("button",{type:"button",onClick:()=>L(Re.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(P,{name:"close",className:"h-3 w-3"})})]},Re.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(ea,{required:!0,info:s.jsx(Ko,{children:i("multirun.launcher.models.info",{max:Wc})}),children:i("multirun.launcher.models.label")}),s.jsx($g,{selectedModels:p,onAdd:Se,onRemove:$e,onUpdate:Pe,minModels:2,maxModels:Wc})]}),Ue&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:Ue})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!me&&we!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(P,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:i("multirun.launcher.project.gitRequired")})]}):null,s.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:n,children:i("multirun.launcher.actions.cancel")}),s.jsx(ge,{type:"submit",size:"sm",disabled:!ze||v,children:v?i("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:i("multirun.launcher.actions.startWithModelCount",{count:p.length})})})]})})]})},jD=()=>typeof window>"u"?0:window.visualViewport?.height??window.innerHeight,ND=()=>{const t=at.c(2),[e,n]=o.useState(SD),r=o.useRef(null);let i,a;return t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{if(typeof window>"u"||!window.visualViewport)return;const l=()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null;const d=window.visualViewport.height,p=Math.max(0,window.innerHeight-d);n(m=>m.height===d&&m.keyboardHeight===p?m:{height:d,keyboardHeight:p})}))};return window.visualViewport.addEventListener("resize",l),window.visualViewport.addEventListener("scroll",l,{passive:!0}),l(),()=>{r.current!==null&&cancelAnimationFrame(r.current),window.visualViewport?.removeEventListener("resize",l),window.visualViewport?.removeEventListener("scroll",l)}},a=[],t[0]=i,t[1]=a):(i=t[0],a=t[1]),o.useEffect(i,a),e};function SD(){return{height:jD(),keyboardHeight:0}}class kD extends o.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(hh,{className:"w-full max-w-md",children:[s.jsx(Jy,{className:"text-center",children:s.jsxs(Xy,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(P,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Zy,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(ge,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(P,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function CD(t){const e=at.c(22),{t:n}=ut();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let i;e[2]!==n?(i=n("chat.errorBoundary.description"),e[2]=n,e[3]=i):i=e[3];let a;e[4]!==n?(a=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=a):a=e[5];let l;e[6]!==n?(l=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=l):l=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let p;e[12]!==r||e[13]!==i||e[14]!==a||e[15]!==l||e[16]!==c||e[17]!==d?(p={title:r,description:i,sessionLabel:a,detailsSummary:l,resetAction:c,persistentHint:d},e[12]=r,e[13]=i,e[14]=a,e[15]=l,e[16]=c,e[17]=d,e[18]=p):p=e[18];let m;return e[19]!==t||e[20]!==p?(m=s.jsx(kD,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const Pd=t=>{const e=at.c(5),{readOnly:n}=t,r=n===void 0?!1:n,a=Ot(PD)||void 0;let l;e[0]!==r?(l=s.jsx(ev,{readOnly:r}),e[0]=r,e[1]=l):l=e[1];let c;return e[2]!==a||e[3]!==l?(c=s.jsx(CD,{sessionId:a,children:l}),e[2]=a,e[3]=l,e[4]=c):c=e[4],c};function PD(t){return t.currentSessionId}const ID=si(()=>kr(()=>Promise.resolve().then(()=>G2),void 0).then(t=>({default:t.PlanView}))),jf=si(()=>kr(()=>Promise.resolve().then(()=>sN),void 0).then(t=>({default:t.GitView}))),AD=si(()=>kr(()=>Promise.resolve().then(()=>f2),void 0).then(t=>({default:t.DiffView}))),Nf=si(()=>kr(()=>import("./TerminalView-DrZ-i3Dr.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),DD=si(()=>kr(()=>Promise.resolve().then(()=>V2),void 0).then(t=>({default:t.FilesView}))),TD=si(()=>kr(()=>Promise.resolve().then(()=>HC),void 0).then(t=>({default:t.SettingsView}))),MD=si(()=>kr(()=>import("./SettingsWindow-coz__Ykw.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),ED=si(()=>kr(()=>import("./MultiRunWindow-Bo7THayo.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),Ho=85,RD=250,FD=500,LD=400,OD=860,$D=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},BD=()=>{const{t}=ut(),e=1140,n=1220,r=640,i=700,a=Ie(F=>F.isSidebarOpen),l=Ie(F=>F.isCreativeMode),c=Ie(F=>F.isRightSidebarOpen),d=Ie(F=>F.isBottomTerminalOpen),p=Ie(F=>F.setRightSidebarOpen),m=Ie(F=>F.setBottomTerminalOpen),u=Ie(F=>F.activeMainTab),h=Ie(F=>F.setIsMobile),x=Ie(F=>F.isSessionSwitcherOpen),f=Ie(F=>F.isSettingsDialogOpen),v=Ie(F=>F.setSettingsDialogOpen),y=Ie(F=>F.isMultiRunLauncherOpen),g=Ie(F=>F.setMultiRunLauncherOpen),w=Ie(F=>F.multiRunLauncherPrefillPrompt),{isMobile:b,isTablet:k}=rn(),I=ND(),j=o.useMemo(()=>gn(),[]),N=Ie(F=>F.sidebarWidth),D=Ie(F=>F.rightSidebarWidth),[E,T]=o.useState(null),C=Ir()??"",S=o.useMemo(()=>$D(C),[C]),M=Ie(F=>{if(!S)return!1;const U=F.contextPanelByDirectory[S],W=U?.tabs??[],te=W.find(K=>K.id===U?.activeTabId)??W[W.length-1];return!!(U?.isOpen&&te)}),A=Ie(F=>F.setSidebarOpen),R=o.useRef(!1),z=o.useRef(!1),B=o.useRef(!1),[V,$]=o.useState(!1),_=o.useRef(!1),X=gu(0),O=Be.useRef(0),J=gu(0),Q=Be.useRef(0);Be.useEffect(()=>{b&&(O.current=window.innerWidth*(Ho/100),Q.current=window.innerWidth*(Ho/100))},[b]),Be.useEffect(()=>{if(!b)return;const F=V?0:-O.current;xu(X,F,{type:"spring",stiffness:400,damping:35,mass:.8})},[V,b,X]),Be.useEffect(()=>{if(!b)return;_.current=c;const F=c?0:Q.current;xu(J,F,{type:"spring",stiffness:400,damping:35,mass:.8})},[b,c,J]),Be.useEffect(()=>{b&&$(x)},[x,b]),Be.useEffect(()=>{!b||!f||($(!1),x&&Ie.getState().setSessionSwitcherOpen(!1),c&&p(!1))},[b,f,x,c,p]),Be.useEffect(()=>{b&&(_.current=c)},[c,b]),o.useEffect(()=>{Ie.getState().isMobile!==b&&h(b)},[b,h]),o.useEffect(()=>{if(typeof window>"u")return;let F;const U=()=>{F!==void 0&&window.clearTimeout(F),F=window.setTimeout(()=>{Ie.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",U),()=>{window.removeEventListener("resize",U),F!==void 0&&window.clearTimeout(F)}},[]),o.useEffect(()=>{if(M){Ie.getState().isSidebarOpen&&(A(!1),B.current=!0);return}B.current&&(A(!0),B.current=!1)},[M,A]),o.useEffect(()=>{if(typeof window>"u")return;let F;const U=()=>{const te=Ie.getState(),K=window.innerWidth,ae=window.innerHeight;if(!b&&!k){const ve=K<e,re=K>=n;ve?te.isRightSidebarOpen&&(p(!1),R.current=!0):re&&R.current&&(p(!0),R.current=!1);const be=ae<r,pe=ae>=i;be?te.isBottomTerminalOpen&&(m(!1),z.current=!0):pe&&z.current&&(m(!0),z.current=!1)}},W=()=>{F!==void 0&&window.clearTimeout(F),F=window.setTimeout(()=>{U()},100)};return U(),window.addEventListener("resize",W),()=>{window.removeEventListener("resize",W),F!==void 0&&window.clearTimeout(F)}},[b,k,m,p]),o.useEffect(()=>{if(typeof window>"u")return;const F=Ie.subscribe((U,W)=>{const te=window.innerWidth,K=window.innerHeight,ae=te>=n,ve=K>=i;U.isRightSidebarOpen!==W.isRightSidebarOpen&&ae&&(R.current=!1),U.isBottomTerminalOpen!==W.isBottomTerminalOpen&&ve&&(z.current=!1)});return()=>{F()}},[b,k,m,p]);const ne=o.useMemo(()=>{switch(u){case"plan":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(ID,{})});case"git":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(jf,{})});case"diff":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(AD,{})});case"terminal":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Nf,{})});case"files":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(DD,{})});default:return null}},[u]),G=u==="chat",le=o.useMemo(()=>Math.min(FD,Math.max(RD,N||rd)),[N]),oe=o.useMemo(()=>Math.min(OD,Math.max(LD,D||Th)),[D]);return s.jsx(_j,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:ce("main-content-safe-area",b?"flex flex-col":"flex h-[100dvh]","bg-background"),style:b&&I.height>0?{height:I.height}:void 0,children:[s.jsx(GC,{}),s.jsx(R4,{}),s.jsx($4,{}),s.jsx(dD,{}),b?s.jsxs(tv,{value:{leftDrawerOpen:V,rightDrawerOpen:c,toggleLeftDrawer:()=>{c&&p(!1),$(!V)},toggleRightDrawer:()=>{V&&$(!1),p(!c)},leftDrawerX:X,rightDrawerX:J,leftDrawerWidth:O,rightDrawerWidth:Q,setMobileLeftDrawerOpen:$,setRightSidebarOpen:p},children:[!f&&s.jsx(om,{onToggleLeftDrawer:()=>{c&&p(!1),$(!V)},onToggleRightDrawer:()=>{V&&$(!1),p(!c)},leftDrawerOpen:V,rightDrawerOpen:c}),s.jsx(Jl.button,{type:"button",initial:!1,animate:{opacity:V||c?1:0,pointerEvents:V||c?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{$(!1),p(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Jl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(O.current||window.innerWidth*.85),right:0},style:{width:`${Ho}%`,x:X},onDragEnd:(F,U)=>{const W=O.current||window.innerWidth*.85,te=W*.3,K=500,ae=X.get(),ve=U.offset.x<-te||U.velocity.x<-K,re=U.offset.x>te||U.velocity.x>K;ve?(X.set(-W),$(!1)):re?(X.set(0),$(!0)):ae>-W/2?X.set(0):X.set(-W)},className:ce("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!V,children:s.jsx("div",{"data-page-scroll-lock":"true",className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(xf,{mobileVariant:!0})})})})}),s.jsx(Jl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:Q.current||window.innerWidth*.85},style:{width:`${Ho}%`,x:J},onDragEnd:(F,U)=>{const W=Q.current||window.innerWidth*.85,te=W*.3,K=500,ae=J.get(),ve=U.offset.x>te||U.velocity.x>K,re=U.offset.x<-te||U.velocity.x<-K;ve?(J.set(W),p(!1)):re?(J.set(0),p(!0)):ae<W/2?J.set(0):J.set(W)},className:ce("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!c,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(jf,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:ce("flex flex-1 overflow-hidden relative",f&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ce("absolute inset-0",!G&&"invisible"),children:s.jsx(Xs,{children:s.jsx(Pd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:ne})}),y&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Xs,{children:s.jsx(wD,{initialPrompt:w,onCreated:()=>g(!1),onCancel:()=>g(!1)})})})]})}),f&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Xs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(TD,{onClose:()=>v(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:ce("absolute inset-0 flex overflow-hidden","bg-sidebar"),"data-page-scroll-lock":"true",children:[a?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${le}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${le}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}})]}):null,c?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${oe}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${oe}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}})]}):null,s.jsx(t1,{isOpen:a,isMobile:b,className:"border-0",children:s.jsx(xf,{})}),s.jsxs("div",{className:ce("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",a&&"border-l border-border/50 rounded-tl-[10px] rounded-bl-[10px]",c&&"border-r border-border/50 rounded-tr-[10px] rounded-br-[10px]"),"data-page-scroll-lock":"true",children:[s.jsx(om,{desktopRightSidebarActionsHost:E}),s.jsx("div",{className:ce("flex flex-1 min-h-0 overflow-hidden",a||G?"":"border-l border-border/50",c?"":"border-r border-border/50"),"data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ce("absolute inset-0",!G&&"invisible"),children:s.jsx(Xs,{children:s.jsx(Pd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:ne})})]}),s.jsx(ES,{})]})}),s.jsx(Qw,{isOpen:d,isMobile:b,children:d?s.jsx(Xs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Nf,{})})}):null})]}),s.jsx(s1,{isOpen:c,className:"border-0",onTopActionsHostChange:T,children:s.jsx(Xs,{children:l?s.jsx(ZA,{}):s.jsx(LN,{})})})]})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(MD,{open:f,onOpenChange:v})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(ED,{open:y,onOpenChange:g,initialPrompt:w})})]})]})})},zD=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},dr=t=>{const e=at.c(8),{label:n,value:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=i):i=e[0];let a;e[1]!==n?(a=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=a):a=e[2];let l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let c;return e[5]!==a||e[6]!==l?(c=s.jsxs("div",{className:"rounded-md p-2",style:i,children:[a,l]}),e[5]=a,e[6]=l,e[7]=c):c=e[7],c},Sf=t=>{const e=at.c(43),{title:n,snapshot:r,emptyLabel:i}=t,{t:a}=ut();let l;if(e[0]!==i||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==a||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(UD,0),e[8]=r.entries,e[9]=d):d=e[9];const p=d;let m;e[10]!==n?(m=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=m):m=e[11];let u;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==a?(u=r.startedAt?zD(r.durationMs):a("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=a,e[15]=u):u=e[15];let h;e[16]!==u?(h=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=h):h=e[17];let x;e[18]!==m||e[19]!==h?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,h]}),e[18]=m,e[19]=h,e[20]=x):x=e[20];let f;e[21]!==a?(f=a("memoryDebugPanel.metric.metrics"),e[21]=a,e[22]=f):f=e[22];let v;e[23]!==r.entries.length||e[24]!==f?(v=s.jsx(dr,{label:f,value:r.entries.length}),e[23]=r.entries.length,e[24]=f,e[25]=v):v=e[25];let y;e[26]!==a?(y=a("memoryDebugPanel.metric.samples"),e[26]=a,e[27]=y):y=e[27];let g;e[28]!==y||e[29]!==p?(g=s.jsx(dr,{label:y,value:p}),e[28]=y,e[29]=p,e[30]=g):g=e[30];let w;e[31]!==a?(w=a("memoryDebugPanel.metric.lastUpdate"),e[31]=a,e[32]=w):w=e[32];let b;e[33]!==r.lastUpdatedAt||e[34]!==a?(b=r.lastUpdatedAt?a("memoryDebugPanel.common.live"):a("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=a,e[35]=b):b=e[35];let k;e[36]!==w||e[37]!==b?(k=s.jsx(dr,{label:w,value:b}),e[36]=w,e[37]=b,e[38]=k):k=e[38];let I;e[39]!==g||e[40]!==k||e[41]!==v?(I=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,g,k]}),e[39]=g,e[40]=k,e[41]=v,e[42]=I):I=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,I,c.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:i}):s.jsx(Cs,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:a("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:a("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:a("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:a("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=i,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=a,e[6]=n,e[7]=l}else l=e[7];return l},VD=t=>{const e=at.c(101),{onClose:n}=t,{t:r}=ut(),[i,a]=o.useState("memory"),[l,c]=o.useState("idle"),d=Ot(WD),p=ph(KD),m=zl(),u=th(HD),h=mr(GD),[x,f]=o.useState(qD),[v,y]=o.useState(YD);let g;e[0]!==x.entries?(g=new Map,x.entries.forEach(Ce=>{g.set(Ce.metric,Ce.count)}),e[0]=x.entries,e[1]=g):g=e[1];let w;e[2]!==g?(w=g.get("ui.message_list.render")??0,e[2]=g,e[3]=w):w=e[3];let b;e[4]!==g?(b=g.get("ui.message_list.render.streaming")??0,e[4]=g,e[5]=b):b=e[5];let k;e[6]!==g?(k=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=k):k=e[7];let I;e[8]!==g?(I=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=I):I=e[9];let j;e[10]!==g?(j=g.get("ui.chat_message.render.static_during_stream")??0,e[10]=g,e[11]=j):j=e[11];let N;e[12]!==g?(N=g.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=g,e[13]=N):N=e[13];let D;e[14]!==w||e[15]!==b||e[16]!==k||e[17]!==I||e[18]!==j||e[19]!==N?(D={messageListRender:w,messageListRenderStreaming:b,chatMessageRender:k,chatMessageRenderStreaming:I,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:N},e[14]=w,e[15]=b,e[16]=k,e[17]=I,e[18]=j,e[19]=N,e[20]=D):D=e[20];const E=D;let T,C;e[21]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const Ce=()=>{f(Jo()),y(Xo())};Ce();const je=window.setInterval(Ce,500);return()=>window.clearInterval(je)},C=[],e[21]=T,e[22]=C):(T=e[21],C=e[22]),o.useEffect(T,C);let S,M;e[23]!==l?(S=()=>{if(l==="idle")return;const Ce=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Ce)},M=[l],e[23]=l,e[24]=S,e[25]=M):(S=e[24],M=e[25]),o.useEffect(S,M);let A=0,R;if(e[26]!==u?(R=Object.keys(u),e[26]=u,e[27]=R):R=e[27],e[28]!==u||e[29]!==R||e[30]!==A){for(const Ce of R)A=A+(u[Ce]?.length??0);e[28]=u,e[29]=R,e[30]=A,e[31]=A}else A=e[31];const z=A;let B;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Ce;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Ce=je=>{const we=u[je.id]?.length||0,ke=p.get(je.id);return{id:je.id,title:je.title||r("memoryDebugPanel.common.untitled"),messageCount:we,isStreaming:ke?.isStreaming||!1,isZombie:ke?.isZombie||!1,backgroundCount:ke?.backgroundMessageCount||0,lastAccessed:ke?.lastAccessedAt||0,isCurrent:je.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=Ce):Ce=e[42],B=m.map(Ce).sort(QD),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=B}else B=e[37];const V=B;let $;e[43]!==u?($=Object.keys(u),e[43]=u,e[44]=$):$=e[44];const _=$.length;let X;e[45]===Symbol.for("react.memo_cache_sentinel")?(X=async()=>{try{const Ce={generatedAt:new Date().toISOString(),ui:Jo(),vscode:Xo()};await navigator.clipboard.writeText(JSON.stringify(Ce,null,2)),c("copied")}catch{c("error")}},e[45]=X):X=e[45];const O=X;let J;e[46]===Symbol.for("react.memo_cache_sentinel")?(J={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=J):J=e[46];let Q;e[47]!==i?(Q=i==="memory"?s.jsx(P,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(P,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=i,e[48]=Q):Q=e[48];let ne;e[49]!==r?(ne=r("memoryDebugPanel.title"),e[49]=r,e[50]=ne):ne=e[50];let G;e[51]!==ne?(G=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ne}),e[51]=ne,e[52]=G):G=e[52];let le;e[53]!==Q||e[54]!==G?(le=s.jsxs("div",{className:"flex items-center gap-2",children:[Q,G]}),e[53]=Q,e[54]=G,e[55]=le):le=e[55];let oe;e[56]!==i?(oe=i==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ge,{size:"xs",variant:"ghost",onClick:O,children:s.jsx(P,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ge,{size:"xs",variant:"ghost",onClick:()=>{nv(),f(Jo()),y(Xo())},children:s.jsx(P,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=i,e[57]=oe):oe=e[57];let F;e[58]!==n?(F=n?s.jsx(ge,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(P,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=F):F=e[59];let U;e[60]!==oe||e[61]!==F?(U=s.jsxs("div",{className:"flex items-center gap-1",children:[oe,F]}),e[60]=oe,e[61]=F,e[62]=U):U=e[62];let W;e[63]!==le||e[64]!==U?(W=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[le,U]}),e[63]=le,e[64]=U,e[65]=W):W=e[65];let te;e[66]===Symbol.for("react.memo_cache_sentinel")?(te={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=te):te=e[66];const K=i==="memory"?"secondary":"ghost";let ae;e[67]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>a("memory"),e[67]=ae):ae=e[67];let ve;e[68]!==r?(ve=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=ve):ve=e[69];let re;e[70]!==K||e[71]!==ve?(re=s.jsx(ge,{size:"sm",variant:K,className:"flex-1",onClick:ae,children:ve}),e[70]=K,e[71]=ve,e[72]=re):re=e[72];const be=i==="streaming"?"secondary":"ghost";let pe;e[73]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>a("streaming"),e[73]=pe):pe=e[73];let ye;e[74]!==r?(ye=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=ye):ye=e[75];let ie;e[76]!==be||e[77]!==ye?(ie=s.jsx(ge,{size:"sm",variant:be,className:"flex-1",onClick:pe,children:ye}),e[76]=be,e[77]=ye,e[78]=ie):ie=e[78];let ue;e[79]!==re||e[80]!==ie?(ue=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:te,children:[re,ie]}),e[79]=re,e[80]=ie,e[81]=ue):ue=e[81];let se;e[82]!==i||e[83]!==_||e[84]!==l||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==V||e[89]!==m||e[90]!==E||e[91]!==x||e[92]!==r||e[93]!==h||e[94]!==z||e[95]!==v?(se=i==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(dr,{label:r("memoryDebugPanel.metric.totalMessages"),value:z}),s.jsx(dr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${_} / ${_u.MAX_SESSIONS}`})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:sv()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:_u.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:h})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(Cs,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(Ce=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ce.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Ce.title}),Ce.isStreaming?s.jsx(P,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ce.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Ce.messageCount})}),Ce.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ce.backgroundCount]}):null]})]},Ce.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(JD),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Dt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ge,{size:"xs",variant:"outline",onClick:O,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(dr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:E.messageListRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:E.messageListRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:E.chatMessageRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:E.chatMessageRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:E.chatMessageRenderStaticDuringStream}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:E.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Sf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(Sf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=i,e[83]=_,e[84]=l,e[85]=d,e[86]=u,e[87]=p,e[88]=V,e[89]=m,e[90]=E,e[91]=x,e[92]=r,e[93]=h,e[94]=z,e[95]=v,e[96]=se):se=e[96];let Ne;return e[97]!==W||e[98]!==ue||e[99]!==se?(Ne=s.jsxs(hh,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:J,children:[W,ue,se]}),e[97]=W,e[98]=ue,e[99]=se,e[100]=Ne):Ne=e[100],Ne},_D=VD;function UD(t,e){return t+e.count}function WD(t){return t.currentSessionId}function KD(t){return t.sessionMemoryState}function HD(t){return t.message}function GD(t){return t.totalRequestCount}function qD(){return Jo()}function YD(){return Xo()}function QD(t,e){return e.lastAccessed-t.lastAccessed}function JD(t){return{id:t.id,title:t.title}}const XD=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},ZD=async()=>{const t=XD()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},kf="vinci:menu-action",e6=t=>{const e=Ot(x=>x.openNewSessionDraft),n=Ie(x=>x.toggleCommandPalette),r=Ie(x=>x.setCommandPaletteOpen),i=Ie(x=>x.toggleHelpDialog),a=Ie(x=>x.toggleSidebar),l=Ie(x=>x.setSessionSwitcherOpen),c=Ie(x=>x.setActiveMainTab),d=Ie(x=>x.setSettingsDialogOpen),p=Ie(x=>x.setAboutDialogOpen),{setThemeMode:m}=Ar(),u=o.useCallback(()=>{Sr.requestDirectoryDialog()},[]),h=o.useCallback(x=>{switch(x){case"about":p(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),l(!1),e();break;case"new-worktree-session":c("chat"),l(!1),oh();break;case"change-workspace":u();break;case"open-git-tab":{const{activeMainTab:f}=Ie.getState();c(f==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:f}=Ie.getState();c(f==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:f}=Ie.getState();c(f==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:f}=Ie.getState();c(f==="terminal"?"chat":"terminal");break}case"copy":{const f=new Event("vinci:copy",{cancelable:!0});!window.dispatchEvent(f)||ZD();break}case"theme-light":m("light");break;case"theme-dark":m("dark");break;case"theme-system":m("system");break;case"toggle-sidebar":a();break;case"toggle-memory-debug":t?.();break;case"help-dialog":i();break;case"download-logs":{rv().catch(()=>{H.error("Failed to collect OpenCode status")});break}}},[u,t,e,p,c,l,r,d,m,n,i,a]);o.useEffect(()=>{const x=f=>{const v=f.detail;v&&h(v)};return window.addEventListener(kf,x),()=>{window.removeEventListener(kf,x)}},[h]),o.useEffect(()=>{if(typeof window>"u")return;const f=window.__TAURI__?.event?.listen;if(typeof f!="function")return;let v=null;return f("vinci:menu-action",y=>{const g=y?.payload;typeof g=="string"&&h(g)}).then(y=>{v=y}).catch(()=>{}),()=>{(async()=>{try{const g=v?.();g instanceof Promise&&await g}catch{}})()}},[h])},t6=["chat","git","diff","terminal","files"],s6=["settings","agents","commands","skills","providers","usage","git-identities"],Nr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Cf(t){const e=n6();return{sessionId:r6(e),tab:i6(e),settingsPath:a6(e),diffFile:o6(e)}}function n6(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function r6(t){const e=t.get(Nr.SESSION);return!e||e.trim().length===0?null:e.trim()}function i6(t){const e=t.get(Nr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return t6.includes(n)?n:null}function a6(t){const e=t.get(Nr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="vinci"||n==="general"||n==="preferences"?"home":(s6.includes(n),n)}function o6(t){const e=t.get(Nr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Pf(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(Nr.SESSION)||t.has(Nr.TAB)||t.has(Nr.SETTINGS)||t.has(Nr.FILE)}catch{return!1}}const l6="chat";function Kg(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(Nr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(Nr.SETTINGS,n),e}return t.tab!==l6&&e.set(Nr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(Nr.FILE,t.diffFile),e}function c6(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function d6(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Kg(t),r=[...e.entries()].sort((a,l)=>a[0].localeCompare(l[0])),i=[...n.entries()].sort((a,l)=>a[0].localeCompare(l[0]));if(r.length!==i.length)return!1;for(let a=0;a<r.length;a++)if(r[a][0]!==i[a][0]||r[a][1]!==i[a][1])return!1;return!0}catch{return!0}}function u6(t,e={}){if(!(typeof window>"u")&&!m6()&&!(!e.force&&d6(t)))try{const n=Kg(t),r=c6(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function m6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function p6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function f6(){const t=o.useMemo(()=>p6(),[]),e=o.useRef(!1),n=o.useRef(!1),r=Ot(u=>u.setCurrentSession),i=Ie(u=>u.setActiveMainTab),a=Ie(u=>u.setSettingsDialogOpen),l=Ie(u=>u.setSettingsPage),c=Ie(u=>u.navigateToDiff),d=o.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const h=Ot.getState().currentSessionId;u.sessionId!==h&&await r(u.sessionId)}if(u.settingsPath){l(lg(u.settingsPath)),a(!0);return}Ie.getState().isSettingsDialogOpen&&a(!1),u.tab&&i(u.tab),u.diffFile&&(u.tab==="diff"||!u.tab)&&c(u.diffFile)}finally{n.current=!1}}},[r,i,a,l,c]),p=o.useCallback(()=>{const u=Ot.getState(),h=Ie.getState();return{sessionId:u.currentSessionId,tab:h.activeMainTab,isSettingsOpen:h.isSettingsDialogOpen,settingsPath:h.settingsPage,diffFile:h.pendingDiffFile}},[]),m=o.useCallback((u={})=>{if(t||n.current)return;const h=p();u6(h,u)},[t,p]);o.useEffect(()=>{if(e.current||(e.current=!0,!Pf()))return;const u=Cf();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),o.useEffect(()=>{if(t)return;let u=Ot.getState().currentSessionId;return Ot.subscribe(x=>{const f=x.currentSessionId;f===u||n.current||(u=f,m())})},[t,m]),o.useEffect(()=>{if(t)return;let u=Ie.getState().activeMainTab,h=Ie.getState().isSettingsDialogOpen,x=Ie.getState().settingsPage,f=Ie.getState().pendingDiffFile;return Ie.subscribe(y=>{if(n.current)return;const g=y.activeMainTab!==u,w=y.isSettingsDialogOpen!==h,b=y.settingsPage!==x,k=y.pendingDiffFile!==f&&y.activeMainTab==="diff";u=y.activeMainTab,h=y.isSettingsDialogOpen,x=y.settingsPage,f=y.pendingDiffFile,(g||w||b||k)&&m()})},[t,m]),o.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const h=Cf();if(Pf())d(h);else{const x=Ie.getState();x.isSettingsDialogOpen&&a(!1),x.activeMainTab!=="chat"&&i("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,i,a])}const If="pwa-install-toast-shown",h6=()=>{const t=at.c(6),{browserTab:e}=wg(),{t:n}=ut(),r=o.useRef(n);let i,a;t[0]!==n?(i=()=>{r.current=n},a=[n],t[0]=n,t[1]=i,t[2]=a):(i=t[1],a=t[2]),o.useEffect(i,a);let l,c;t[3]!==e?(l=()=>{if(typeof window>"u"||!Li()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(H.dismiss(p),p=null)},u=async()=>{if(!d)return;const f=d;d=null,m(),await f.prompt();const{outcome:v}=await f.userChoice;v==="accepted"&&H.success(r.current("pwa.installPrompt.started"))},h=f=>{const v=f;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const y=_f();y.getItem(If)!=="true"&&p===null&&(y.setItem(If,"true"),p=H.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}}}))},x=()=>{d=null,m(),H.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",h),window.addEventListener("appinstalled",x),()=>{m(),window.removeEventListener("beforeinstallprompt",h),window.removeEventListener("appinstalled",x)}},c=[e],t[3]=e,t[4]=l,t[5]=c):(l=t[4],c=t[5]),o.useEffect(l,c)},g6=["local","remote",null],x6=["ok","not-configured","unreachable","wrong-service","missing"];function Hg(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!g6.includes(n)))return{valid:!1};if(typeof r!="string"||!x6.includes(r))return{valid:!1};if(n==="remote"||n==="local"){if(r==="ok"&&n==="local")return{valid:!0,outcome:{target:"local",status:"ok"}};if(r==="ok"&&n==="remote")return typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"ok",hostId:e.hostId,url:e.url}};if(r==="unreachable")return n==="local"?{valid:!0,outcome:{target:"local",status:"unreachable"}}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"unreachable",hostId:e.hostId,url:e.url}};if(r==="wrong-service")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"wrong-service",hostId:e.hostId,url:e.url}};if(r==="missing")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"missing",hostId:e.hostId}}}if(n===null){if(r==="not-configured")return{valid:!0,outcome:{target:null,status:"not-configured"}};if(r==="missing")return{valid:!1}}return{valid:!1}}function Af(t){if(!t.isDesktopShell)return null;const e=t.bootOutcome;if(!e)return null;if(e.status==="ok"){if(e.target==="local")return{screen:"main"};if(e.target==="remote")return{screen:"main",hostId:e.hostId,url:e.url}}if(e.target===null&&e.status==="not-configured")return{screen:"chooser"};if(e.target==="local"&&e.status==="unreachable")return{screen:"recovery",variant:"local-unavailable"};if(e.target==="remote"){if(e.status==="unreachable")return{screen:"recovery",variant:"remote-unreachable",hostId:e.hostId,url:e.url};if(e.status==="wrong-service")return{screen:"recovery",variant:"remote-wrong-service",hostId:e.hostId,url:e.url};if(e.status==="missing")return{screen:"recovery",variant:"remote-missing",hostId:e.hostId}}return null}function b6(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function y6(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function Df(){if(Id()!=="valid")return null;const e=window.__APP_DESKTOP_BOOT_OUTCOME__,n=Hg(e);return n.valid?n.outcome:null}function Id(){if(typeof window>"u")return"not-injected";const t=window.__APP_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Hg(t).valid?"valid":"malformed"}const v6=()=>{const t=at.c(5),[e,n]=o.useState(w6),{isUpdating:r,message:i}=e;let a,l;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>av(n),l=[],t[0]=a,t[1]=l):(a=t[0],l=t[1]),o.useEffect(a,l),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx($d,{width:80,height:80}),t[2]=c):c=t[2];let d;return t[3]!==i?(d=s.jsxs("div",{className:"fixed inset-0 z-[9999] flex flex-col items-center justify-center gap-6 bg-background/90",children:[c,s.jsx("p",{className:"typography-body text-muted-foreground",children:i})]}),t[3]=i,t[4]=d):d=t[4],d};function w6(){return iv()}const j6=({open:t,onOpenChange:e})=>{const{t:n}=ut(),[r,i]=o.useState(null),[a,l]=o.useState(null),[c,d]=o.useState(!1),[p,m]=o.useState(!1),[u,h]=o.useState(null),[x,f]=o.useState(!1),v=o.useCallback(async()=>{if(!c){d(!0),m(!1);try{if(!u){H.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const g=await Uu.copyTextToClipboard(u);g.ok?(m(!0),H.success(n("aboutDialog.toast.diagnosticsCopied"))):H.error(n("aboutDialog.toast.copyFailed"),{description:g.error})}catch(g){H.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",g)}finally{d(!1)}}},[u,c,n]);o.useEffect(()=>{if(!t)return;(async()=>{try{const w=await fetch("/api/system/info");if(w.ok){const b=await w.json();if(typeof b.vinciVersion=="string"&&b.vinciVersion.trim()){i(b.vinciVersion);return}}}catch{}i(await ov())})()},[t]),o.useEffect(()=>{if(!t)return;let g=!1;return(async()=>{try{const b=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!b.ok)return;const k=await b.json().catch(()=>null),I=typeof k?.currentVersion=="string"?k.currentVersion.trim():"";!g&&I&&l(I)}catch{}})(),()=>{g=!0}},[t]),o.useEffect(()=>{if(!t){h(null),f(!1);return}let g=!1;return f(!0),Uu.buildDiagnosticsReport().then(w=>{g||h(w)}).catch(w=>{g||(console.error("Failed to prepare diagnostics:",w),h(null))}).finally(()=>{g||f(!1)}),()=>{g=!0}},[t]);const y=r;return s.jsx(hs,{open:t,onOpenChange:e,children:s.jsx(fs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx($d,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Vinci"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[y&&s.jsx("p",{children:n("aboutDialog.vinciVersionLabel",{version:y})}),a&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:a})})]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:v,disabled:c||x||!u,className:ce("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(p?"aboutDialog.actions.diagnosticsCopied":x?"aboutDialog.actions.preparingDiagnostics":"aboutDialog.actions.copyDiagnostics")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("aboutDialog.diagnosticsDescription")})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[s.jsxs("a",{href:"https://github.com/jaygupta17/vinci",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/eSSmgeX8Q",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/guptajay17",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@guptajay17"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},Kc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},N6=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to Vinci and click Authorize again.":n},S6=()=>{const t=yn(a=>a.completeAuth),[e,n]=o.useState("working"),[r,i]=o.useState("Completing MCP authorization...");return o.useEffect(()=>{if(typeof window>"u"){n("error"),i("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),l=Kc(a,"code"),c=pg(a),d=Zd(a),p=Kc(a,"error"),m=Kc(a,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),i(m??p);return}(async()=>{try{if(!l)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");let u=c;if(!u&&d){const h=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(h.ok){const x=await h.json().catch(()=>null);x?.name?.trim()&&(u={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!u?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");await t(u.name,l,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),i("Authorization completed. You can close this tab and return to Vinci.")}catch(u){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),i(N6(u,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(ge,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to Vinci"})})]})})},Go="opencode-update-available",qo="opencode-upgrade-progress",k6=5e3,C6=[1e4,6e4],Gg=()=>{const{t}=ut(),e=Ie(l=>l.showOpenCodeUpdateNotifications),n=Be.useRef(new Set),r=Be.useRef(!1);Be.useEffect(()=>{e||H.dismiss(Go)},[e]);const i=Be.useCallback(()=>{H.dismiss(qo),Fi({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),a=Be.useCallback(async()=>{if(!r.current){r.current=!0,H.dismiss(Go),H.message(t("opencodeUpdate.toast.upgrading.title"),{id:qo,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(P,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const l=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),c=await l.json().catch(()=>null);if(!l.ok||c?.success===!1)throw new Error(c?.error||l.statusText||t("opencodeUpdate.toast.failed.description"));H.success(t("opencodeUpdate.toast.updated.title"),{id:qo,description:c?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:c.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(P,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:i}})}catch(l){H.error(t("opencodeUpdate.toast.failed.title"),{id:qo,description:l instanceof Error?l.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[i,t]);return Be.useEffect(()=>{const l=u=>{if(!Ie.getState().showOpenCodeUpdateNotifications){H.dismiss(Go);return}u&&(n.current.has(u)||(n.current.add(u),H.info(t("opencodeUpdate.toast.available.title"),{id:Go,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:a}})))},c=u=>{const h=typeof u.detail?.version=="string"?String(u.detail.version).trim():"";l(h)};let d=!1;const p=[],m=async u=>{try{const h=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!h.ok)throw new Error(h.statusText||"OpenCode upgrade status check failed");const x=await h.json().catch(()=>null),f=typeof x?.latestVersion=="string"?x.latestVersion.trim():"";!d&&x?.available===!0&&f&&l(f)}catch{const h=C6[u];!d&&h!==void 0&&p.push(setTimeout(()=>{m(u+1)},h))}};return e&&p.push(setTimeout(()=>{m(0)},k6)),window.addEventListener("vinci:opencode-update-available",c),()=>{d=!0;for(const u of p)clearTimeout(u);window.removeEventListener("vinci:opencode-update-available",c)}},[a,e,t]),null},Tf=si(()=>kr(()=>import("./OnboardingScreen-BDqmzTVR.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),P6=()=>{const t=at.c(3),e=Ie(E6),n=Ie(R6);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(j6,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},I6=t=>{const e=at.c(21),{onRetry:n,isRetrying:r}=t,{t:i}=ut();let a;e[0]!==i?(a=i("startup.initRecovery.title"),e[0]=i,e[1]=a):a=e[1];let l;e[2]!==a?(l=s.jsx("h1",{className:"typography-title text-foreground",children:a}),e[2]=a,e[3]=l):l=e[3];let c;e[4]!==i?(c=i("startup.initRecovery.description"),e[4]=i,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==l||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,d]}),e[8]=l,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==i?(m=i(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=i,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(ge,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let h;return e[18]!==p||e[19]!==u?(h=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[p,u]})}),e[18]=p,e[19]=u,e[20]=h):h=e[20],h},Mf=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",A6=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),i=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:i,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},D6=()=>typeof window>"u"?!1:window.location.pathname===mg,T6=t=>{const e=at.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=t,a=$s(F6),l=Ot(L6),c=Ot(O6),d=_d(),p=o.useRef(null);let m;e[0]!==n.directory?(m=Mf(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let h;e[2]!==a?(h=Mf(a),e[2]=a,e[3]=h):h=e[3];const x=h;let f,v;if(e[4]!==x||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==c||e[11]!==d?(f=()=>{if(r||u&&x!==u)return;const I=`${u}
|
|
226
|
+
${n.sessionId}`;p.current===I&&l===n.sessionId||(p.current=I,c(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},v=[x,l,n.directory,n.sessionId,u,r,c,d],e[4]=x,e[5]=l,e[6]=n.directory,e[7]=n.sessionId,e[8]=u,e[9]=r,e[10]=c,e[11]=d,e[12]=f,e[13]=v):(f=e[12],v=e[13]),o.useEffect(f,v),u&&x!==u)return null;let y;e[14]!==i?(y=s.jsx(gh,{embeddedBackgroundWorkEnabled:i}),e[14]=i,e[15]=y):y=e[15];let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Gg,{}),e[16]=g):g=e[16];let w;e[17]!==n.readOnly?(w=s.jsx(Pd,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=w):w=e[18];let b;e[19]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(xh,{}),e[19]=b):b=e[19];let k;return e[20]!==y||e[21]!==w?(k=s.jsxs(s.Fragment,{children:[y,g,w,b]}),e[20]=y,e[21]=w,e[22]=k):k=e[22],k};function M6({apis:t}){console.log("[App] Rendering with apis:",!!t,"keys:",Object.keys(t||{}));const e=xt(F=>F.initializeApp),n=xt(F=>F.isInitialized),r=xt(F=>F.isConnected),i=xt(F=>F.providers.length),a=xt(F=>F.agents.length),l=xt(F=>F.loadProviders),c=xt(F=>F.loadAgents),d=Ot(F=>F.error),p=Ot(F=>F.clearError),m=$s(F=>F.currentDirectory),u=$s(F=>F.setDirectory),h=$s(F=>F.isSwitchingDirectory),[x,f]=o.useState(!1),v=Hn(F=>F.refreshStatus),[y,g]=o.useState(()=>t.runtime.isVSCode),[w,b]=o.useState(!0),[k,I]=o.useState(!1),[j,N]=o.useState(0),[D,E]=o.useState(!1),T=Ie(F=>F.wideChatLayoutEnabled),C=Ie(F=>F.mobileKeyboardMode),S=o.useMemo(()=>gn(),[]),M=Td(F=>F.setPlanModeEnabled),[A,R]=o.useState(()=>Id()),[z,B]=o.useState(()=>{const F=Df();return F!==null?Af({isDesktopShell:!0,bootOutcome:F}):null}),V=o.useRef(!1),$=o.useMemo(()=>A6(),[]),_=!$||w,X=o.useMemo(()=>D6(),[]);o.useEffect(()=>(Wu(x),()=>{Wu(!1)}),[x]),o.useEffect(()=>{lv(C)},[C]),o.useEffect(()=>{g(t.runtime.isVSCode)},[t.runtime.isVSCode]),o.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",T),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[T]),o.useEffect(()=>(Ku(t),()=>Ku(null)),[t]),o.useEffect(()=>{$||v(t.github,{force:!0})},[t.github,$,v]),cv();const O=A==="valid",J=z?.screen==="main";o.useEffect(()=>{if(!b6({isDesktopShell:S,isInitialized:n,bootOutcomeKnown:O,bootViewIsMain:J}))return;const F=setTimeout(()=>{const U=document.getElementById("initial-loading");U&&(U.classList.add("fade-out"),setTimeout(()=>{U.remove()},300))},150);return()=>clearTimeout(F)},[S,n,O,J]),o.useEffect(()=>{if(!S||A!=="malformed")return;const F=document.getElementById("initial-loading");F&&(F.textContent="Desktop startup failed — please restart the app.")},[S,A]),o.useEffect(()=>{if(S)return;const F=setTimeout(()=>{const U=document.getElementById("initial-loading");U&&!n&&(U.classList.add("fade-out"),setTimeout(()=>{U.remove()},300))},5e3);return()=>clearTimeout(F)},[S,n]),o.useEffect(()=>{let F=!1;return(async()=>{const W=await fetch("/health",{method:"GET"}).catch(()=>null);if(!W||!W.ok||F)return;const te=await W.json().catch(()=>null);if(!te||F)return;const K=te.planModeExperimentalEnabled;M(K===!0||K===1||K==="1"||K==="true")})(),()=>{F=!0}},[M]),o.useEffect(()=>{y||e()},[e,y]),o.useEffect(()=>{if(y||n)return;let F=!0,U,W=0;const te=10,K=1e3,ae=async()=>{if(!F)return;if(W>=te){I(!0);return}const ve=xt.getState();if(ve.isInitialized){I(!1);return}W+=1,await ve.initializeApp();const re=xt.getState();if(!F)return;if(re.isInitialized){I(!1);return}if(W>=te){I(!0);return}const be=Math.min(K*Math.pow(2,W-1),16e3);U=setTimeout(ae,be)};return U=setTimeout(ae,K),()=>{F=!1,U&&clearTimeout(U)}},[j,n,y]),o.useEffect(()=>{n&&I(!1)},[n]),o.useEffect(()=>{if(!k)return;const F=document.getElementById("initial-loading");F&&(F.classList.add("fade-out"),setTimeout(()=>{F.remove()},300))},[k]),o.useEffect(()=>{if(y||!r||i>0&&a>0)return;let F=!0,U=0;const W=15,te=async()=>{const ae=xt.getState();if(!(ae.providers.length>0&&ae.agents.length>0))try{ae.providers.length===0&&await l(),xt.getState().agents.length===0&&await c()}catch{}};te();const K=setInterval(()=>{if(F){if(++U>=W){clearInterval(K);return}te()}},2e3);return()=>{F=!1,clearInterval(K)}},[r,y,c,l,i,a]),o.useEffect(()=>{h||y||r&&Zs.setDirectory(m)},[m,h,r,y]),o.useEffect(()=>{if(!$||typeof window>"u")return;const F=te=>{const K=te?.visible===!0;b(K)},U=te=>{if(te.origin!==window.location.origin)return;const K=te.data;K?.type==="vinci:embedded-visibility"&&F(K.payload)},W=window;return W.__vinciSetEmbeddedVisibility=F,window.addEventListener("message",U),()=>{window.removeEventListener("message",U),W.__vinciSetEmbeddedVisibility===F&&delete W.__vinciSetEmbeddedVisibility}},[$]),o.useEffect(()=>{!$?.directory||y||m!==$.directory&&u($.directory,{showOverlay:!1})},[m,$,y,u]),o.useEffect(()=>{if(!$||typeof window>"u")return;const F=U=>{U.storageArea===window.localStorage&&U.key==="ui-store"&&Ie.persist.rehydrate()};return window.addEventListener("storage",F),()=>{window.removeEventListener("storage",F)}},[$]),o.useEffect(()=>{if(typeof window>"u")return;const F=U=>{const W=U.detail,te=typeof W?.sessionId=="string"?W.sessionId.trim():"";if(!te)return;const K=typeof W?.directory=="string"&&W.directory.trim().length>0?W.directory.trim():null;Ie.getState().setActiveMainTab("chat"),Ot.getState().setCurrentSession(te,K)};return window.addEventListener("vinci:open-session",F),()=>window.removeEventListener("vinci:open-session",F)},[]),o.useEffect(()=>{if(typeof window>"u")return;const F=U=>{const W=U.detail,te=typeof W?.directory=="string"&&W.directory.trim().length>0?W.directory.trim():null,K=typeof W?.projectId=="string"&&W.projectId.trim().length>0?W.projectId.trim():null;Ie.getState().setActiveMainTab("chat"),Ie.getState().setSessionSwitcherOpen(!1),Ot.getState().openNewSessionDraft({selectedProjectId:K,directoryOverride:te,preserveDirectoryOverride:!!te})};return window.addEventListener("vinci:open-draft-session",F),()=>window.removeEventListener("vinci:open-draft-session",F)},[]),o.useEffect(()=>{if(typeof window>"u")return;const F=U=>{const W=U.detail,te=typeof W?.projectPath=="string"?W.projectPath.trim():"";if(!te)return;const K=As.getState(),ae=K.projects.find(ve=>ve.path===te);ae?K.setActiveProject(ae.id):K.addProject(te)};return window.addEventListener("vinci:open-project",F),()=>window.removeEventListener("vinci:open-project",F)},[]),o.useEffect(()=>{typeof window>"u"||!n||h||V.current||(V.current=!0,window.__vinciAppReady=!0,window.dispatchEvent(new Event("vinci:app-ready")))},[n,h]),dv({enabled:_}),h6(),uv(),f6();const Q=o.useCallback(()=>{f(F=>!F)},[]);e6(Q),o.useEffect(()=>{if($)return;const F=U=>{Md(U)&&U.shiftKey&&!U.altKey&&(U.code==="KeyD"||U.key.toLowerCase()==="d")&&(U.preventDefault(),f(te=>!te))};return window.addEventListener("keydown",F,!0),()=>window.removeEventListener("keydown",F,!0)},[$]),o.useEffect(()=>{$||d&&setTimeout(()=>p(),5e3)},[p,$,d]),o.useEffect(()=>{if(!S||A!=="not-injected")return;let F=!1,U=0;const W=200,te=2e3,K=50,ae=()=>{if(F)return;U++;const ve=Id();if(ve!=="not-injected"){if(F=!0,R(ve),ve==="valid"){const be=Df();be&&B(Af({isDesktopShell:!0,bootOutcome:be}))}return}const re=Math.min(W*Math.pow(1.1,U),te);if(U>=K){const be=document.getElementById("initial-loading");be&&!be.textContent?.includes("taking longer")&&(be.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ae,re)};return window.setTimeout(ae,W),()=>{F=!0}},[S,A]);const ne=o.useCallback(async()=>{if(y6({isTauriShell:pa(),isDesktopLocalOriginActive:Bi()})){await ih();return}window.location.reload()},[]),G=o.useCallback(async()=>{if(!D){I(!1),E(!0);try{await xt.getState().initializeApp()}finally{E(!1)}xt.getState().isInitialized||N(F=>F+1)}},[D]),le=F=>{if(F.screen==="recovery")return F.variant};if(S&&z&&z.screen!=="main"){if(z.screen==="chooser")return s.jsx(Xs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Tf,{mode:"first-launch",onCliAvailable:ne,onChooseRemote:()=>{}})})})});const F=le(z),U=z.screen==="recovery"&&"url"in z?z.url:void 0;return s.jsx(Xs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Tf,{mode:"recovery",recoveryVariant:F,recoveryHostUrl:U,recoveryHostLabel:void 0,onCliAvailable:ne})})})})}if($)return s.jsx(Xs,{children:s.jsx(Hu,{sdk:Zs.getSdkClient(),directory:m||"",children:s.jsx(Gu,{apis:t,children:s.jsx(qu,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(T6,{embeddedSessionChat:$,isVSCodeRuntime:y,embeddedBackgroundWorkEnabled:_})})})})})});if(X)return s.jsx(Xs,{children:s.jsx(S6,{})});if(k&&!n&&!y&&!$)return s.jsx(Xs,{children:s.jsx(I6,{onRetry:()=>{G()},isRetrying:D})});const oe=!n&&!S;return s.jsx(Xs,{children:s.jsx(Hu,{sdk:Zs.getSdkClient(),directory:m||"",children:s.jsx(Gu,{apis:t,children:s.jsx(E1,{children:s.jsx(mv,{children:s.jsx(qu,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:S?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(gh,{embeddedBackgroundWorkEnabled:_}),s.jsx(Gg,{}),s.jsx(BD,{}),s.jsx(xh,{}),!oe&&s.jsxs(s.Fragment,{children:[s.jsx(v6,{}),s.jsx(P6,{}),x&&s.jsx(_D,{onClose:()=>f(!1)})]})]})})})})})})})}function E6(t){return t.isAboutDialogOpen}function R6(t){return t.setAboutDialogOpen}function F6(t){return t.currentDirectory}function L6(t){return t.currentSessionId}function O6(t){return t.setCurrentSession}const au=typeof window<"u"&&window.__VINCI_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();console.log("[ui-main] Runtime APIs loaded:",!!au);console.log("[ui-main] Runtime keys:",Object.keys(au||{}));pv();fv().then(()=>{Promise.all([hv(),gv()]).catch(t=>{console.error("[main] settings init failed:",t)}),xv(),bv(),yv()}).catch(t=>{console.error("[main] appearance init failed:",t)});const qg=document.getElementById("root");if(!qg)throw new Error("Root element not found");Fx.createRoot(qg).render(s.jsx(Be.StrictMode,{children:s.jsx(vv,{children:s.jsx(wv,{children:s.jsx(jv,{children:s.jsx(Nv,{children:s.jsx(M6,{apis:au})})})})})}));const H6=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{wD as M,Zo as P,OC as S,Cr as a,H6 as m,on as u};
|