@surething/cockpit 1.0.205 → 1.0.206
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/.next-prod/BUILD_ID +1 -1
- package/.next-prod/app-path-routes-manifest.json +25 -25
- package/.next-prod/build-manifest.json +3 -3
- package/.next-prod/prerender-manifest.json +3 -3
- package/.next-prod/react-loadable-manifest.json +3 -3
- package/.next-prod/required-server-files.js +12 -0
- package/.next-prod/required-server-files.json +12 -0
- package/.next-prod/server/app/_global-error/page.js.nft.json +1 -1
- package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_global-error.html +1 -1
- package/.next-prod/server/app/_global-error.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found/page.js +2 -2
- package/.next-prod/server/app/_not-found/page.js.nft.json +1 -1
- package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_not-found.html +2 -2
- package/.next-prod/server/app/_not-found.rsc +4 -3
- package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +4 -3
- package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +4 -3
- package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +3 -2
- package/.next-prod/server/app/api/bash/route.js +1 -1
- package/.next-prod/server/app/api/bash/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/codex/route.js +3 -3
- package/.next-prod/server/app/api/chat/codex/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/deepseek/route.js +6 -6
- package/.next-prod/server/app/api/chat/deepseek/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/kimi/route.js +3 -3
- package/.next-prod/server/app/api/chat/kimi/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/ollama/route.js +7 -7
- package/.next-prod/server/app/api/chat/ollama/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/route.js +3 -3
- package/.next-prod/server/app/api/chat/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/claude-stats/route.js +1 -1
- package/.next-prod/server/app/api/claude-stats/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/commands/route.js +1 -1
- package/.next-prod/server/app/api/commands/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/comments/route.js +1 -1
- package/.next-prod/server/app/api/comments/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/columns/route.js +4 -4
- package/.next-prod/server/app/api/db/columns/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/connect/route.js +1 -1
- package/.next-prod/server/app/api/db/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/disconnect/route.js +1 -1
- package/.next-prod/server/app/api/db/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/export/route.js +1 -1
- package/.next-prod/server/app/api/db/export/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/query/route.js +1 -1
- package/.next-prod/server/app/api/db/query/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/schemas/route.js +2 -2
- package/.next-prod/server/app/api/db/schemas/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/extension/version/route.js +1 -1
- package/.next-prod/server/app/api/extension/version/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/file/route.js +1 -1
- package/.next-prod/server/app/api/file/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/blame/route.js +1 -1
- package/.next-prod/server/app/api/files/blame/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/clipboard/route.js +1 -1
- package/.next-prod/server/app/api/files/clipboard/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/copy/route.js +1 -1
- package/.next-prod/server/app/api/files/copy/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/delete/route.js +1 -1
- package/.next-prod/server/app/api/files/delete/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/expanded/route.js +1 -1
- package/.next-prod/server/app/api/files/expanded/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/index/route.js +1 -1
- package/.next-prod/server/app/api/files/index/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/init/route.js +1 -1
- package/.next-prod/server/app/api/files/init/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/paste/route.js +1 -1
- package/.next-prod/server/app/api/files/paste/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/read/route.js +1 -1
- package/.next-prod/server/app/api/files/read/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/readdir/route.js +1 -1
- package/.next-prod/server/app/api/files/readdir/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/recent/route.js +1 -1
- package/.next-prod/server/app/api/files/recent/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/save/route.js +1 -1
- package/.next-prod/server/app/api/files/save/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/search/route.js +1 -1
- package/.next-prod/server/app/api/files/search/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/stat/route.js +1 -1
- package/.next-prod/server/app/api/files/stat/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/text/route.js +1 -1
- package/.next-prod/server/app/api/files/text/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/branch-diff/route.js +1 -1
- package/.next-prod/server/app/api/git/branch-diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/branches/route.js +1 -1
- package/.next-prod/server/app/api/git/branches/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/commit-diff/route.js +1 -1
- package/.next-prod/server/app/api/git/commit-diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/commits/route.js +1 -1
- package/.next-prod/server/app/api/git/commits/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/diff/route.js +1 -1
- package/.next-prod/server/app/api/git/diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/discard/route.js +1 -1
- package/.next-prod/server/app/api/git/discard/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/stage/route.js +1 -1
- package/.next-prod/server/app/api/git/stage/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/status/route.js +1 -1
- package/.next-prod/server/app/api/git/status/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/unstage/route.js +1 -1
- package/.next-prod/server/app/api/git/unstage/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/worktree/route.js +1 -1
- package/.next-prod/server/app/api/git/worktree/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/global-state/route.js +1 -1
- package/.next-prod/server/app/api/global-state/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/jupyter/load/route.js +1 -1
- package/.next-prod/server/app/api/jupyter/load/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/jupyter/save/route.js +1 -1
- package/.next-prod/server/app/api/jupyter/save/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/jupyter/shutdown/route.js +1 -1
- package/.next-prod/server/app/api/jupyter/shutdown/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/definition/route.js +1 -1
- package/.next-prod/server/app/api/lsp/definition/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/hover/route.js +1 -1
- package/.next-prod/server/app/api/lsp/hover/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/references/route.js +1 -1
- package/.next-prod/server/app/api/lsp/references/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/status/route.js +1 -1
- package/.next-prod/server/app/api/lsp/status/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/warmup/route.js +1 -1
- package/.next-prod/server/app/api/lsp/warmup/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/columns/route.js +4 -4
- package/.next-prod/server/app/api/mysql/columns/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/connect/route.js +1 -1
- package/.next-prod/server/app/api/mysql/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/disconnect/route.js +1 -1
- package/.next-prod/server/app/api/mysql/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/export/route.js +1 -1
- package/.next-prod/server/app/api/mysql/export/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/query/route.js +1 -1
- package/.next-prod/server/app/api/mysql/query/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/schemas/route.js +2 -2
- package/.next-prod/server/app/api/mysql/schemas/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/connect/route.js +1 -1
- package/.next-prod/server/app/api/neo4j/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/disconnect/route.js +1 -1
- package/.next-prod/server/app/api/neo4j/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/query/route.js +1 -1
- package/.next-prod/server/app/api/neo4j/query/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/schema/route.js +1 -1
- package/.next-prod/server/app/api/neo4j/schema/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/note/route.js +1 -1
- package/.next-prod/server/app/api/note/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/ollama/models/route.js +1 -1
- package/.next-prod/server/app/api/ollama/models/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/ollama/start/route.js +1 -1
- package/.next-prod/server/app/api/ollama/start/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/open-cursor/route.js +1 -1
- package/.next-prod/server/app/api/open-cursor/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/open-vscode/route.js +1 -1
- package/.next-prod/server/app/api/open-vscode/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/pick-folder/route.js +1 -1
- package/.next-prod/server/app/api/pick-folder/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/pinned-sessions/route.js +1 -1
- package/.next-prod/server/app/api/pinned-sessions/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/project-settings/route.js +1 -1
- package/.next-prod/server/app/api/project-settings/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/project-state/route.js +1 -1
- package/.next-prod/server/app/api/project-state/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/file/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/file/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/file-functions/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/file-functions/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/search/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/search/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projects/route.js +1 -1
- package/.next-prod/server/app/api/projects/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/command/route.js +1 -1
- package/.next-prod/server/app/api/redis/command/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/connect/route.js +1 -1
- package/.next-prod/server/app/api/redis/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/delete/route.js +1 -1
- package/.next-prod/server/app/api/redis/delete/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/disconnect/route.js +1 -1
- package/.next-prod/server/app/api/redis/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/get/route.js +1 -1
- package/.next-prod/server/app/api/redis/get/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/keys/route.js +1 -1
- package/.next-prod/server/app/api/redis/keys/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/set/route.js +1 -1
- package/.next-prod/server/app/api/redis/set/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/[id]/comments/route.js +1 -1
- package/.next-prod/server/app/api/review/[id]/comments/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/[id]/replies/route.js +1 -1
- package/.next-prod/server/app/api/review/[id]/replies/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/[id]/route.js +1 -1
- package/.next-prod/server/app/api/review/[id]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/identify/route.js +1 -1
- package/.next-prod/server/app/api/review/identify/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/order/route.js +1 -1
- package/.next-prod/server/app/api/review/order/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/route.js +1 -1
- package/.next-prod/server/app/api/review/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/share-info/route.js +1 -1
- package/.next-prod/server/app/api/review/share-info/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/users/route.js +1 -1
- package/.next-prod/server/app/api/review/users/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/scheduled-tasks/route.js +1 -1
- package/.next-prod/server/app/api/scheduled-tasks/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/services/config/route.js +1 -1
- package/.next-prod/server/app/api/services/config/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/services/scripts/route.js +1 -1
- package/.next-prod/server/app/api/services/scripts/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/fork/route.js +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/fork/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/history/route.js +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/history/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/session-by-path/route.js +1 -1
- package/.next-prod/server/app/api/session-by-path/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js +1 -1
- package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/sessions/projects/route.js +1 -1
- package/.next-prod/server/app/api/sessions/projects/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/sessions/route.js +1 -1
- package/.next-prod/server/app/api/sessions/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/settings/route.js +1 -1
- package/.next-prod/server/app/api/settings/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/skills/[id]/route.js +1 -1
- package/.next-prod/server/app/api/skills/[id]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/skills/content/route.js +1 -1
- package/.next-prod/server/app/api/skills/content/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/skills/route.js +1 -1
- package/.next-prod/server/app/api/skills/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/aliases/route.js +1 -1
- package/.next-prod/server/app/api/terminal/aliases/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/autocomplete/route.js +1 -1
- package/.next-prod/server/app/api/terminal/autocomplete/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/bubble-order/route.js +1 -1
- package/.next-prod/server/app/api/terminal/bubble-order/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/env/route.js +1 -1
- package/.next-prod/server/app/api/terminal/env/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/history/route.js +1 -1
- package/.next-prod/server/app/api/terminal/history/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/version/route.js +1 -1
- package/.next-prod/server/app/api/version/route.js.nft.json +1 -1
- package/.next-prod/server/app/favicon.ico/route.js.nft.json +1 -1
- package/.next-prod/server/app/manifest.webmanifest/route.js.nft.json +1 -1
- package/.next-prod/server/app/page.js +2 -99
- package/.next-prod/server/app/page.js.nft.json +1 -1
- package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/project/page.js +2 -30
- package/.next-prod/server/app/project/page.js.nft.json +1 -1
- package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/review/[id]/page.js +2 -2
- package/.next-prod/server/app/review/[id]/page.js.nft.json +1 -1
- package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app-paths-manifest.json +25 -25
- package/.next-prod/server/chunks/240.js +1 -0
- package/.next-prod/server/chunks/{4098.js → 5466.js} +1 -1
- package/.next-prod/server/chunks/554.js +101 -0
- package/.next-prod/server/chunks/{4272.js → 6007.js} +2 -2
- package/.next-prod/server/chunks/7264.js +5 -0
- package/.next-prod/server/chunks/8750.js +1 -0
- package/.next-prod/server/chunks/{4490.js → 8764.js} +1 -1
- package/.next-prod/server/chunks/900.js +1 -0
- package/.next-prod/server/chunks/9255.js +1 -0
- package/.next-prod/server/chunks/9658.js +59 -0
- package/.next-prod/server/chunks/987.js +139 -0
- package/.next-prod/server/functions-config-manifest.json +1 -26
- package/.next-prod/server/middleware-build-manifest.js +1 -1
- package/.next-prod/server/middleware-react-loadable-manifest.js +1 -1
- package/.next-prod/server/pages/404.html +2 -2
- package/.next-prod/server/pages/500.html +1 -1
- package/.next-prod/server/server-reference-manifest.json +1 -1
- package/.next-prod/static/chunks/{700.8d53bb1a328c3f97.js → 1959.b9473117faf354bf.js} +1 -1
- package/.next-prod/static/chunks/5204-c8293184aa55cdd5.js +23 -0
- package/.next-prod/static/chunks/5660-9ffe0abe675caac1.js +29 -0
- package/.next-prod/static/chunks/6028-1d6ced1439a3f01f.js +1 -0
- package/.next-prod/static/chunks/6345-6b34b0528ff833a1.js +14 -0
- package/.next-prod/static/chunks/app/layout-421143dba2c69478.js +1 -0
- package/.next-prod/static/chunks/app/page-db32ebfdf1ac9174.js +1 -0
- package/.next-prod/static/chunks/app/project/page-db32ebfdf1ac9174.js +1 -0
- package/.next-prod/static/chunks/app/review/[id]/page-05cd4cb51babd64c.js +1 -0
- package/.next-prod/static/chunks/webpack-bb0c02e3a9602d78.js +1 -0
- package/.next-prod/static/css/a7974d62fe853925.css +1 -0
- package/.next-prod/trace +12 -12
- package/.next-prod/trace-build +1 -1
- package/dist/{chunk-5NL2LMKP.mjs → chunk-HIRLDMCH.mjs} +24 -140
- package/dist/chunk-RSHKDWJM.mjs +136 -0
- package/dist/chunk-VCZEGP64.mjs +984 -0
- package/dist/scheduledTasks.mjs +6 -4
- package/dist/server-K6XWP7DX.mjs +69 -0
- package/dist/wsServer.mjs +60 -482
- package/next.config.mjs +15 -0
- package/package.json +15 -17
- package/server.mjs +1 -1
- package/.next-prod/server/chunks/2338.js +0 -1
- package/.next-prod/server/chunks/3353.js +0 -1
- package/.next-prod/server/chunks/3863.js +0 -1
- package/.next-prod/server/chunks/4732.js +0 -1
- package/.next-prod/server/chunks/4793.js +0 -1
- package/.next-prod/server/chunks/5147.js +0 -1
- package/.next-prod/server/chunks/5394.js +0 -1
- package/.next-prod/server/chunks/6043.js +0 -4
- package/.next-prod/server/chunks/7051.js +0 -1
- package/.next-prod/server/chunks/7514.js +0 -31
- package/.next-prod/server/chunks/8491.js +0 -5
- package/.next-prod/server/chunks/9298.js +0 -139
- package/.next-prod/static/chunks/1705-906aa28943dbc391.js +0 -4
- package/.next-prod/static/chunks/3530-42727255f967251e.js +0 -14
- package/.next-prod/static/chunks/3579-51f0ad7204c67e22.js +0 -1
- package/.next-prod/static/chunks/3643-fe2ac2f1accd0649.js +0 -1
- package/.next-prod/static/chunks/3743-1f5d8cfd9d92ad97.js +0 -4
- package/.next-prod/static/chunks/4186-2bbbcdf03b3c15f5.js +0 -17
- package/.next-prod/static/chunks/9062-8d92cbc176f388a0.js +0 -1
- package/.next-prod/static/chunks/9114-0d2717c9c2752d0f.js +0 -1
- package/.next-prod/static/chunks/app/layout-e091cf70aaec617b.js +0 -1
- package/.next-prod/static/chunks/app/page-c9a30c88afc0a0c5.js +0 -1
- package/.next-prod/static/chunks/app/project/page-bd8c46d229676a01.js +0 -29
- package/.next-prod/static/chunks/app/review/[id]/page-f8bb4748e9a94a0f.js +0 -1
- package/.next-prod/static/chunks/webpack-c6cffb10a569677a.js +0 -1
- package/.next-prod/static/css/23784ace5d9f83d5.css +0 -1
- package/dist/JupyterKernelManager-VBKKSRVJ.mjs +0 -269
- /package/.next-prod/static/{T6-Nq3sO9DxU5E0rsM6aX → VAwjvIwxO_lfKwd6A4ptI}/_buildManifest.js +0 -0
- /package/.next-prod/static/{T6-Nq3sO9DxU5E0rsM6aX → VAwjvIwxO_lfKwd6A4ptI}/_ssgManifest.js +0 -0
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6500],{30265:(e,t,r)=>{"use strict";r.d(t,{TabManager:()=>n7});var n=r(95155),s=r(12115),o=r(79114);function a({isOpen:e,onClose:t,cwd:r,onSelectSession:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[u,m]=(0,s.useState)(!1),[h,x]=(0,s.useState)(null),[f,p]=(0,s.useState)(""),g=(0,s.useRef)(null),b=(0,s.useCallback)(async()=>{if(r){m(!0),x(null);try{let e=r.replace(/\//g,"-"),t=await fetch(`/api/sessions/projects/${encodeURIComponent(e)}`);if(!t.ok)throw Error("Failed to load sessions");let n=await t.json();d(n)}catch(e){x(e instanceof Error?e.message:"Unknown error")}finally{m(!1)}}},[r]);(0,s.useEffect)(()=>{e&&(b(),setTimeout(()=>{g.current?.focus()},100))},[e,b]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let v=c.filter(e=>{if(!f)return!0;let t=f.toLowerCase();return e.title.toLowerCase().includes(t)||e.firstMessages.some(e=>e.toLowerCase().includes(t))||e.lastMessages.some(e=>e.toLowerCase().includes(t))});return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-6xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("sessions.sessionList")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:r,children:r})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsx)("input",{ref:g,type:"text",placeholder:i("sessions.searchSessions"),value:f,onChange:e=>p(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[u&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:i("sessions.loadingSessions")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:h})}),!u&&!h&&0===v.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:i(f?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!u&&!h&&v.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:v.map(e=>(0,n.jsxs)("div",{onClick:()=>{let n;return n=(e.path.split("/").pop()||"").replace(".jsonl",""),void(l?(l(n,e.title),t()):window.parent.postMessage({type:"OPEN_PROJECT",cwd:r,sessionId:n},"*"))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[e.engine&&"claude"!==e.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===e.engine?"bg-orange-500/15 text-orange-11":"ollama"===e.engine?"bg-blue-500/15 text-blue-11":"codex"===e.engine?"bg-green-500/15 text-green-11":"kimi"===e.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:e.title,children:e.title})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[e.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),e.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},e.path))})]})]})]}):null}var l=r(47650),i=r(44810),c=r(64702),d=r(71063),u=r(10222),m=r(57842),h=r(1531),x=r(91694);function f(e,t){let r=e.split("\n"),n=t.split("\n"),s=[],o=r.length,a=n.length,l=Array(o+1).fill(null).map(()=>Array(a+1).fill(0));for(let e=1;e<=o;e++)for(let t=1;t<=a;t++)r[e-1]===n[t-1]?l[e][t]=l[e-1][t-1]+1:l[e][t]=Math.max(l[e-1][t],l[e][t-1]);let i=o,c=a,d=[];for(;i>0||c>0;)i>0&&c>0&&r[i-1]===n[c-1]?(d.push({type:"unchanged",content:r[i-1],oldLineNum:i,newLineNum:c}),i--,c--):c>0&&(0===i||l[i][c-1]>=l[i-1][c])?(d.push({type:"added",content:n[c-1],newLineNum:c}),c--):(d.push({type:"removed",content:r[i-1],oldLineNum:i}),i--);for(;d.length>0;)s.push(d.pop());return s}var p=r(38093),g=r(82085),b=r(23193);function v({lines:e,containerRef:t}){let r=(0,s.useRef)(null),[o,a]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{let{scrollTop:t,scrollHeight:n,clientHeight:s}=e,o=r.current?.clientHeight||0;if(n<=s)a({top:0,height:o});else{let e=o/n;a({top:t*e,height:s*e})}};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),()=>{e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}},[t]),0===e.length)return null;let l=100/e.length;return(0,n.jsxs)("div",{ref:r,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let n=t.current,s=r.current;if(!n||!s)return;let o=s.getBoundingClientRect(),a=(e.clientY-o.top)/o.height*n.scrollHeight-n.clientHeight/2;n.scrollTo({top:Math.max(0,a),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,n.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*l}%`,height:`${Math.max(l,.5)}%`,minHeight:"2px"}},t)),(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${o.top}px`,height:`${Math.max(o.height,10)}px`}})]})}var j=r(74567),y=r(84392);function w(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}let k=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:r,onAddComment:o,onSendToAI:a,onSearch:l,isChatLoading:i}){let[c,d]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>d(e=>e+1)},[t]);let u=(0,s.useMemo)(()=>e.current,[c]);return(0,n.jsx)(j.w,{x:u?.x??0,y:u?.y??0,visible:!!u,container:r,onAddComment:o,onSendToAI:a,onSearch:l,isChatLoading:i})});function N({oldContent:e,newContent:t,filePath:r,isNew:a=!1,isDeleted:i=!1,cwd:j,enableComments:C=!1,onPreview:S,previewLabel:L,onContentSearch:M,targetLine:E,compact:$=!1,symbols:T}){let{t:R}=(0,o.Bd)(),P=L??R("common.preview"),I=(0,s.useMemo)(()=>f(e,t),[e,t]),B=(0,s.useRef)(null),F=(0,s.useRef)(null),D=(0,s.useRef)(null),O=(0,s.useRef)(!1),[A,_]=(0,s.useState)(!1),W=(0,m.iN)(),q=(0,h.nH)(),z=C&&!!j,{comments:H,addComment:U,updateComment:V,deleteComment:K,refresh:J}=(0,d._)({cwd:j||"",filePath:r}),[Q,Y]=(0,s.useState)(null),X=(0,s.useRef)(null),G=(0,s.useRef)(()=>{}),[Z,ee]=(0,s.useState)(null),[et,er]=(0,s.useState)(null);(0,s.useEffect)(()=>{_(!0)},[]);let en=(0,s.useMemo)(()=>{let e=new Set;for(let t of H)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[H]),es=(0,s.useMemo)(()=>{let e=new Map;for(let t of H){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[H]);(0,s.useEffect)(()=>{if(!z)return;let e=D.current,t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,X.current&&(X.current=null,G.current())},o=e=>{t=!1;let s=e.target;if(s.closest?.(".floating-toolbar"))return;let o=Math.abs(e.clientX-r)>5||Math.abs(e.clientY-n)>5,a=window.getSelection();if(!a||a.isCollapsed||!a.toString().trim()||!o){X.current&&(X.current=null,G.current());return}let l=a.getRangeAt(0),i=D.current;if(!i||!i.contains(l.commonAncestorContainer))return;let c=e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;for(;t&&t!==i;){let e=t.closest("[data-new-line]");if(e)return parseInt(e.getAttribute("data-new-line")||"0",10);t=t.parentElement}return null},d=c(l.startContainer),u=c(l.endContainer);if(d&&u){let t=Math.min(d,u),r=Math.max(d,u),n=[],s=0;for(let e of I)("unchanged"===e.type||"added"===e.type)&&++s>=t&&s<=r&&n.push(e.content);let o=n.join("\n");X.current={x:e.clientX,y:e.clientY,range:{start:t,end:r},codeContent:o},G.current()}},a=()=>{if(t||!X.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(X.current=null,G.current())};return e?.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",a),()=>{e?.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",a)}},[z,I]);let eo=(0,s.useCallback)((e,t)=>{t.stopPropagation(),Y({comment:e,x:t.clientX,y:t.clientY}),X.current=null,G.current(),ee(null),er(null)},[]),ea=(0,s.useCallback)(()=>{let e=X.current;e&&(ee({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),X.current=null,G.current())},[]),el=(0,s.useCallback)(()=>{let e=X.current;e&&(er({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),X.current=null,G.current())},[]),ei=(0,s.useCallback)(()=>{let e=X.current;if(!e||!M)return;let t=e.codeContent.trim();X.current=null,G.current(),t&&M(t)},[M]),ec=(0,s.useCallback)(async e=>{if(et&&q&&j)try{let t=await (0,u.$3)(j),n=[];for(let e of t)n.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});n.push({filePath:r,startLine:et.range.start,endLine:et.range.end,codeContent:et.codeContent});let s=(0,u.Gw)(n,e);q.sendMessage(s),await (0,u.RP)(j),J(),er(null)}catch(e){console.error("Failed to send to AI:",e)}},[et,q,r,j,J]),ed=(0,s.useCallback)(async e=>{Z&&(await U(Z.range.start,Z.range.end,e),ee(null))},[Z,U]);(0,s.useEffect)(()=>{let e=F.current,t=D.current;if(!e||!t)return;let r=(e,t)=>{O.current||(O.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{O.current=!1}))},n=()=>r(e,t),s=()=>r(t,e);return e.addEventListener("scroll",n),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",n),t.removeEventListener("scroll",s)}},[]);let{leftLines:eu,rightLines:em}=(0,s.useMemo)(()=>{let e=[],t=[],r=0,n=0;for(let s=0;s<I.length;s++){let o=I[s];if("unchanged"===o.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});r++,n++,e.push({lineNum:r,content:o.content,type:"unchanged",originalIdx:s}),t.push({lineNum:n,content:o.content,type:"unchanged",originalIdx:s})}else"removed"===o.type?(r++,e.push({lineNum:r,content:o.content,type:"removed",originalIdx:s})):"added"===o.type&&(n++,t.push({lineNum:n,content:o.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[I]),eh=(0,s.useMemo)(()=>I.map(e=>e.content),[I]),ex=(0,g.C)(eh,r),[ef,ep]=(0,s.useState)(()=>new Map);(0,s.useEffect)(()=>{ep(new Map)},[eu,em]);let eg=(0,s.useMemo)(()=>T??[],[T]),{rows:eb,gaps:ev}=(0,s.useMemo)(()=>$?function(e,t,r,n=[]){let s=e.length,o=r=>"unchanged"!==e[r].type||"unchanged"!==t[r].type,a=new Set;for(let e=0;e<s;e++){if(!o(e))continue;let t=Math.max(0,e-3),r=Math.min(s-1,e+3);for(let e=t;e<=r;e++)a.add(e)}let l=[];for(let e=0;e<s;e++){if(a.has(e))continue;let t=e;for(;e<s&&!a.has(e);)e++;l.push({id:l.length,startIdx:t,endIdx:e-1}),e--}for(let e of l){let t=r.get(e.id)??{topRevealed:0,bottomRevealed:0},n=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,n)),o=Math.max(0,Math.min(t.bottomRevealed,n-s));for(let t=e.startIdx;t<e.startIdx+s;t++)a.add(t);for(let t=e.endIdx-o+1;t<=e.endIdx;t++)a.add(t)}let i=[];for(let e=0;e<s;e++){let r;if(a.has(e)){i.push({kind:"diff",idx:e});continue}let o=e;for(;e<s&&!a.has(e);)e++;let c=e-1;e--;let d=l.find(e=>e.startIdx<=o&&c<=e.endIdx);if(!d)continue;let u=c-o+1,m=Math.min(20,u);if(n.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){r=function(e,t){let r=null;for(let n of e)n.startLine<=t&&t<=n.endLine&&(!r||n.endLine-n.startLine<r.endLine-r.startLine)&&(r=n);return r}(n,s)??void 0;break}}i.push({kind:"gap-expand",gapId:d.id,direction:"up",revealCount:m}),i.push({kind:"gap-label",gapId:d.id,hiddenCount:u,enclosingFn:r}),i.push({kind:"gap-expand",gapId:d.id,direction:"down",revealCount:m})}return{rows:i,gaps:l}}(eu,em,ef,eg):{rows:eu.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[$,eu,eu,em,ef,eg]),ej=(0,s.useCallback)((e,t)=>{let r=ev.find(t=>t.id===e);r&&ep(n=>{let s=n.get(e)??{topRevealed:0,bottomRevealed:0},o=r.endIdx-r.startIdx+1-s.topRevealed-s.bottomRevealed;if(o<=0)return n;let a=Math.min(20,o),l="up"===t?{...s,topRevealed:s.topRevealed+a}:{...s,bottomRevealed:s.bottomRevealed+a};return new Map(n).set(e,l)})},[ev]),ey=(0,s.useCallback)(e=>{for(let t of ev)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[ev]),ew=(0,s.useCallback)(e=>eb[e]?.kind==="gap-label"?28:20,[eb]),ek=(0,c.Te)({count:eb.length,getScrollElement:()=>B.current,estimateSize:ew,overscan:20}),eN=a?"w-1/4":i?"w-3/4":"w-1/2",eC=a?"w-3/4":i?"w-1/4":"w-1/2",eS=(0,s.useMemo)(()=>eb.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=eu[e.idx],r=em[e.idx];return"removed"===t.type?{type:"removed"}:r?.type==="added"?{type:"added"}:{type:"unchanged"}}),[eb,eu,em]),eL=ek.getTotalSize(),eM=ek.getVirtualItems();return(0,s.useEffect)(()=>{if(!E)return;let e=("after"===E.side?em:eu).findIndex(e=>e.lineNum===E.line);if(-1===e)return;let t=eb.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=ey(e);if(null!==t){let e=ev.find(e=>e.id===t);if(!e)return;let r=e.endIdx-e.startIdx+1;ep(e=>{let n=e.get(t)??{topRevealed:0,bottomRevealed:0};if(n.topRevealed+n.bottomRevealed>=r)return e;let s=new Map(e);return s.set(t,{topRevealed:r,bottomRevealed:0}),s})}return}let r=requestAnimationFrame(()=>{ek.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(r)},[E,eu,em,eb]),(0,n.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,n.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,n.jsx)("div",{className:`${eN} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:a?"(New File)":i?"Deleted":"Old"}),(0,n.jsxs)("div",{className:`${eC} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,n.jsx)("span",{className:"block text-center",children:i?"(Deleted)":"New"}),(0,n.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[S&&(0,n.jsx)("button",{onClick:S,className:"text-muted-foreground hover:text-foreground transition-colors",children:P}),!i&&t&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,p.oR)(R("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:R("common.copy")})]})]}),(0,n.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,n.jsx)("div",{ref:B,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,n.jsxs)("div",{className:"flex",style:{height:`${eL}px`},children:[(0,n.jsx)("div",{ref:F,className:`${eN} overflow-x-auto border-r border-border`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eM.map(e=>{let t=eb[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let r="gap-label"===t.kind;return(0,n.jsx)("div",{ref:ek.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:r?"bg-accent border-y border-border":""},e.key)}let r=eu[t.idx];return(0,n.jsxs)("div",{ref:ek.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===r.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:r.lineNum||""}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r.originalIdx>=0&&ex[r.originalIdx]||(0,b.ZD)(r.content||" ")}})]},e.key)})})}),(0,n.jsx)("div",{ref:D,className:`${eC} overflow-x-auto`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eM.map(e=>{let t=eb[e.index];if("gap-expand"===t.kind)return(0,n.jsx)("button",{ref:ek.measureElement,"data-index":e.index,type:"button",onClick:()=>ej(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,n.jsx)("span",{className:"select-none",children:R("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,n.jsxs)("div",{ref:ek.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:R("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,n.jsx)("span",{className:"truncate min-w-0 font-medium",title:w(t.enclosingFn),children:w(t.enclosingFn)})]})]},e.key);let r=em[t.idx],s=r?.lineNum||0,o=s>0&&en.has(s),a=es.get(s),l=a?.[0],i=Z&&s>=Z.range.start&&s<=Z.range.end,c=et&&s>=et.range.start&&s<=et.range.end,d=i||c;return(0,n.jsxs)("div",{ref:ek.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${d?"bg-blue-9/20":o?"bg-amber-9/10":r?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${d?"bg-blue-9/30":""}`,style:{width:z?"52px":"40px"},children:[z&&s>0&&o&&l&&(0,n.jsx)("button",{onClick:e=>eo(l,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:R("codeViewer.nComments",{count:a?.length}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),z&&s>0&&!o&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r?.originalIdx>=0&&ex[r.originalIdx]||(0,b.ZD)(r?.content||" ")}})]},e.key)})})})]})}),(0,n.jsx)(v,{lines:eS,containerRef:B})]}),A&&W&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(k,{floatingToolbarRef:X,bumpRef:G,container:W,onAddComment:ea,onSendToAI:el,onSearch:M?ei:void 0,isChatLoading:q?.isLoading??!1}),Z&&(0,n.jsx)(x.t,{x:Z.x,y:Z.y,range:Z.range,codeContent:Z.codeContent,container:W,onSubmit:ed,onClose:()=>ee(null)}),et&&(0,n.jsx)(x.G,{x:et.x,y:et.y,range:et.range,container:W,onSubmit:ec,onClose:()=>er(null)}),Q&&(0,n.jsx)(y.t,{x:Q.x,y:Q.y,comment:Q.comment,container:W,onClose:()=>Y(null),onUpdateComment:V,onDeleteComment:K})]}),W)]})}function C({oldContent:e,newContent:t,filePath:r}){let o=(0,s.useMemo)(()=>f(e,t),[e,t]),a=(0,s.useRef)(null),l=(0,s.useMemo)(()=>o.map(e=>e.content),[o]),i=(0,g.C)(l,r),d=(0,c.Te)({count:o.length,getScrollElement:()=>a.current,estimateSize:()=>20,overscan:20});return(0,n.jsx)("div",{ref:a,className:"font-mono text-sm overflow-auto h-full",children:(0,n.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.getVirtualItems().map(e=>{let t=o[e.index];return(0,n.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,n.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,n.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:i[e.index]||(0,b.ZD)(t.content||" ")}})]},e.key)})})})}let S={ts:"#3178c6",tsx:"#3178c6",js:"#f1e05a",jsx:"#61dafb",mjs:"#f1e05a",cjs:"#f1e05a",html:"#e44d26",css:"#563d7c",scss:"#cd6799",sass:"#cd6799",less:"#1d365d",vue:"#41b883",svelte:"#ff3e00",json:"#cbcb41",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4121",xml:"#e37933",env:"#ecd53f",md:"#519aba",mdx:"#519aba",txt:"#89898a",py:"#3572a5",go:"#00add8",rs:"#dea584",java:"#b07219",kt:"#a97bff",kts:"#a97bff",c:"#555555",h:"#555555",cpp:"#f34b7d",hpp:"#f34b7d",rb:"#701516",php:"#4f5d95",sh:"#89e051",bash:"#89e051",zsh:"#89e051",png:"#a074c4",jpg:"#a074c4",jpeg:"#a074c4",gif:"#a074c4",svg:"#ffb13b",webp:"#a074c4",ico:"#a074c4",lock:"#89898a",gitignore:"#f14e32",dockerfile:"#2496ed",sql:"#e38c00",graphql:"#e535ab",gql:"#e535ab",default:"#8a8a8a"},L={"package.json":"#cb3837","package-lock.json":"#cb3837","tsconfig.json":"#3178c6","jsconfig.json":"#f1e05a",".gitignore":"#f14e32",".eslintrc":"#4b32c3",".eslintrc.js":"#4b32c3",".eslintrc.json":"#4b32c3",".prettierrc":"#56b3b4",dockerfile:"#2496ed",".env":"#ecd53f",".env.local":"#ecd53f",".env.development":"#ecd53f",".env.production":"#ecd53f","readme.md":"#519aba",license:"#d4af37",makefile:"#6d8086","cargo.toml":"#dea584","go.mod":"#00add8","go.sum":"#00add8","requirements.txt":"#3572a5","yarn.lock":"#2c8ebb","pnpm-lock.yaml":"#f9ad00","vite.config.ts":"#646cff","vite.config.js":"#646cff","next.config.js":"#000000","next.config.mjs":"#000000","tailwind.config.js":"#38bdf8","tailwind.config.ts":"#38bdf8"};function M({name:e,className:t="",size:r=16}){let s,o=L[s=e.toLowerCase()]?L[s]:S[e.split(".").pop()?.toLowerCase()||""]||S.default,a=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M7 10h10M12 10v8",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):["js","jsx","mjs","cjs"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M10 10v6c0 1-1 2-2 2M14 10v4c0 2 4 2 4 0v-4",stroke:"#323330",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):"jsx"===a||"tsx"===a&&e.includes("component")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(60 12 12)"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(120 12 12)"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2",fill:"#61dafb"})]}):"json"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 4C4 4 4 6 4 8v2c0 1-1 2-2 2 1 0 2 1 2 2v2c0 2 0 4 2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M18 4c2 0 2 2 2 4v2c0 1 1 2 2 2-1 0-2 1-2 2v2c0 2 0 4-2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5",fill:o})]}):["md","mdx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M5 15V9l3 4 3-4v6M17 12l-2-3v6M17 12l2-3v6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["py","pyi","pyx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M12 4c-4 0-4 2-4 3v2h5v1H6c-2 0-3 2-3 4s1 4 3 4h2v-2c0-2 1-3 3-3h4c1 0 2-1 2-2V7c0-2-2-3-5-3z",fill:"#3572a5"}),(0,n.jsx)("path",{d:"M12 20c4 0 4-2 4-3v-2h-5v-1h7c2 0 3-2 3-4s-1-4-3-4h-2v2c0 2-1 3-3 3h-4c-1 0-2 1-2 2v4c0 2 2 3 5 3z",fill:"#ffd43b"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"1",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"17",r:"1",fill:"white"})]}):"go"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6",fill:o}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"0.7",fill:"#333"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"0.7",fill:"#333"})]}):"rs"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:o,strokeWidth:"2",fill:"none"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:o}),(0,n.jsx)("path",{d:"M12 3v3M12 18v3M3 12h3M18 12h3",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):["png","jpg","jpeg","gif","webp","ico","bmp"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"9",r:"2",fill:o}),(0,n.jsx)("path",{d:"M3 16l5-5 3 3 4-4 6 6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"svg"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 12 Q12 6 17 12 Q12 18 7 12",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"html"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M8 7h8l-.5 6-3.5 1-3.5-1-.2-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["css","scss","sass","less"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M15 8H9l.3 3h5.2l-.4 4-2.1.7-2.1-.7-.1-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["yaml","yml"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 8l3 4v5M17 8l-3 4v5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["sh","bash","zsh","fish"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",fill:"#1e1e1e",stroke:"#555",strokeWidth:"1"}),(0,n.jsx)("path",{d:"M6 9l3 3-3 3M12 15h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"gitignore"===a||".gitignore"===e.toLowerCase()?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",fill:o}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:"white"}),(0,n.jsx)("path",{d:"M12 6v3M12 15v3M6 12h3M15 12h3",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):"dockerfile"===a||"dockerfile"===e.toLowerCase()||e.toLowerCase().startsWith("dockerfile")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M3 12h3v3H3zM7 12h3v3H7zM11 12h3v3h-3zM7 8h3v3H7zM11 8h3v3h-3zM11 4h3v3h-3zM15 12h3v3h-3z",fill:o}),(0,n.jsx)("path",{d:"M21 13c-1-2-3-2-4-2h-1c0-1 0-2-2-3h-1v1c0 1-1 2-2 2H3c-1 3 0 6 2 8s5 3 9 3c5 0 8-2 10-6",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"env"===a||e.startsWith(".env")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"8",r:"2",fill:o}),(0,n.jsx)("path",{d:"M12 8h6M8 12h8M8 16h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round"})]}):"sql"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"7",rx:"8",ry:"3",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"vue"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M2 4h4l6 10 6-10h4L12 22 2 4z",fill:o}),(0,n.jsx)("path",{d:"M6 4h4l2 4 2-4h4l-6 10L6 4z",fill:"#35495e"})]}):(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 3h8l5 5v13H6V3z",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M14 3v5h5",stroke:o,strokeWidth:"1.5",fill:"none"})]})}function E({status:e}){let{label:t,className:r}={added:{label:"A",className:"text-green-11"},untracked:{label:"A",className:"text-green-11"},modified:{label:"M",className:"text-amber-11"},deleted:{label:"D",className:"text-red-11"},renamed:{label:"R",className:"text-brand"}}[e]||{label:"?",className:"text-muted-foreground"};return(0,n.jsx)("span",{className:`text-xs font-bold ${r}`,children:t})}let $=s.memo(function e({node:t,level:r,selectedPath:o,expandedPaths:a,onSelect:l,onToggle:i,onContextMenu:c,showChanges:d=!1,renderActions:u}){let m=o===t.path,h=a.has(t.path),x=(0,s.useCallback)(()=>{t.isDirectory?i(t.path):l(t)},[t,l,i]),f=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(e,t.path,t.isDirectory)},[t.path,t.isDirectory,c]);return t.isDirectory?(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*r+8}px`},onClick:x,onContextMenu:f,children:[(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:h?"▼":"▶"}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),u&&u(t)]}),h&&t.children.map(t=>(0,n.jsx)(e,{node:t,level:r+1,selectedPath:o,expandedPaths:a,onSelect:l,onToggle:i,onContextMenu:c,showChanges:d,renderActions:u},t.path))]}):(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${m?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*r+8}px`},onClick:x,onContextMenu:f,children:[(0,n.jsx)(M,{name:t.name,size:16,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:`text-sm flex-1 truncate ${m?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,n.jsx)(E,{status:t.status}),d&&void 0!==t.additions&&void 0!==t.deletions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["+",t.additions]}),(0,n.jsxs)("span",{className:"text-xs text-red-11",children:["-",t.deletions]})]}),u&&u(t)]})});function T({files:e,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:a,cwd:l,showChanges:i=!1,renderActions:c,emptyMessage:d,className:u}){let{t:h}=(0,o.Bd)(),x=d??h("gitFileTree.noFiles"),{contextMenu:f,showContextMenu:p,hideContextMenu:g}=(0,m.Ee)();return 0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:x}):(0,n.jsxs)("div",{className:u||"py-1",children:[e.map(e=>(0,n.jsx)($,{node:e,level:0,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:a,onContextMenu:p,showChanges:i,renderActions:c},e.path)),f&&(0,n.jsx)(m.ft,{x:f.x,y:f.y,path:f.path,cwd:l,isDirectory:f.isDirectory,onClose:g})]})}function R(e){let t=[];for(let r of e){let e=r.path.split("/"),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,a=e.slice(0,t+1).join("/"),l=n.find(e=>e.name===s);l||(l={name:s,path:a,isDirectory:!o,children:[],...o&&{status:r.status,additions:r.additions,deletions:r.deletions,oldPath:r.oldPath,file:r}},n.push(l)),o||(n=l.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>r(e.children))};return r(t),t}function P(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),r(n.children))};return r(e),t}function I(e){let t=[],r=e=>{if(e.isDirectory)for(let t of e.children)r(t);else t.push(e)};return r(e),t}var B=r(87918);function F(e){try{let t=JSON.parse(e);return z(t,0)}catch{return e}}let D="#79c0ff",O="#a5d6ff",A="#ff7b72",_="#8b949e",W=(e,t)=>s.createElement("span",{style:{color:e}},t);function q({label:e,labelColor:t,value:r,indent:n}){let[o,a]=s.useState(!1),[l,i]=s.useState({x:0,y:0}),c="string"==typeof r&&r.replace(/\\n/g,"\n").split("\n").length>3,d={onMouseDown:e=>{i({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-l.x,r=e.clientY-l.y;t*t+r*r>25||(e.stopPropagation(),a(e=>!e))},style:{cursor:"pointer"}};if(c&&o&&"string"==typeof r){let n=r.replace(/\\n/g,"\n").split("\n")[0],o=r.replace(/\\n/g,"\n").split("\n").length;return s.createElement("span",d,W(t,e),W(_,": "),W(O,n),W("#6e7681",` ${B.A.t("toolCall.foldedLines",{count:o})}`))}let u=s.createElement(s.Fragment,null,W(t,e),W(_,": "),z(r,n));return c?s.createElement("span",d,u):u}function z(e,t){let r=" ".repeat(t);if(null===e)return W(A,"null");if(void 0===e)return W(A,"undefined");if("string"==typeof e)return W(O,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+r));if("number"==typeof e)return W("#79c0ff",String(e));if("boolean"==typeof e)return W(A,String(e));if(Array.isArray(e))return 0===e.length?W(_,"[]"):s.createElement(s.Fragment,null,W(_,"["),"\n",...e.map((n,o)=>s.createElement("span",{key:o},r+" ",s.createElement(q,{label:`[${o}]`,labelColor:D,value:n,indent:t+1}),o<e.length-1?s.createElement(s.Fragment,null,W(_,","),"\n"):"\n")),r,W(_,"]"));if("object"==typeof e){let n=Object.entries(e);return 0===n.length?W(_,"{}"):s.createElement(s.Fragment,null,W(_,"{"),"\n",...n.map(([e,o],a)=>s.createElement("span",{key:e},r+" ",s.createElement(q,{label:e,labelColor:D,value:o,indent:t+1}),a<n.length-1?s.createElement(s.Fragment,null,W(_,","),"\n"):"\n")),r,W(_,"}"))}return String(e)}let H=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function U(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return H.has(t)}function V(e){return e.toLowerCase().endsWith(".md")}let K="json-search-highlight-style";function J(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[a,l]=(0,s.useState)(!1),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(0),m=(0,s.useRef)(null),h=(0,s.useRef)([]),x=(0,s.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),h.current=[];let r=e.current;if(!r||!n){c(0),u(0);return}!function(){if(document.getElementById(K))return;let e=document.createElement("style");e.id=K,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let s=r.textContent||"",o=a?n:n.toLowerCase(),l=a?s:s.toLowerCase(),i=[],d=0;for(;d<l.length;){let e=l.indexOf(o,d);if(-1===e)break;i.push([e,e+o.length]),d=e+1}if(0===i.length){c(0),u(0);return}let m=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),x=0,f=0,p=[],g=null,b=0;for(;(t=m.nextNode())&&f<i.length;){let e=t.textContent?.length||0,r=x,n=x+e;for(;f<i.length;){let[e,s]=i[f];if(e>=n)break;if(!g)if(e>=r)(g=document.createRange()).setStart(t,e-r),b=s;else break;if(b<=n)g.setEnd(t,b-r),p.push(g),g=null,f++;else break}x=n}h.current=p,c(p.length),u(e=>p.length>0?Math.min(e,p.length-1):0),CSS.highlights&&p.length>0&&CSS.highlights.set("json-search",new Highlight(...p))},[e,n,a]),f=(0,s.useCallback)((e,t)=>{let r=e.getBoundingClientRect();(t.top<r.top||t.bottom>r.bottom)&&(e.scrollTop+=t.top-r.top-r.height/2+t.height/2)},[]),p=(0,s.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let r=h.current[t];if(!r||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(r));let n=r.getBoundingClientRect(),s=e.current?.parentElement;s&&f(s,n)},[e,f]);(0,s.useEffect)(()=>{queueMicrotask(()=>x())},[x]),(0,s.useEffect)(()=>{p(d)},[d,i,p]),(0,s.useEffect)(()=>{let t=e.current;if(!t||!n)return;let r=new MutationObserver(()=>x());return r.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>r.disconnect()},[e,n,x]),(0,s.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),h.current=[])},[t]),(0,s.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let g=(0,s.useCallback)(()=>{0!==i&&u(e=>(e+1)%i)},[i]),b=(0,s.useCallback)(()=>{0!==i&&u(e=>(e-1+i)%i)},[i]),v=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>m.current?.focus(),0)},[]),j=(0,s.useCallback)(()=>{r(!1),o(""),u(0)},[]),y=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?b():g()),"Escape"===e.key&&(e.preventDefault(),j())},[g,b,j]);return{isVisible:t,query:n,setQuery:o,caseSensitive:a,setCaseSensitive:l,matchCount:i,currentIndex:d,searchInputRef:m,open:v,close:j,goToNext:g,goToPrev:b,handleKeyDown:y}}function Q({search:e}){return e.isVisible?s.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},s.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:B.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),s.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:B.A.t("codeViewer.caseSensitive")},"Aa"),s.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:B.A.t("common.noMatch")),s.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:B.A.t("common.previous")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),s.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:B.A.t("common.next")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),s.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:B.A.t("common.close")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}function Y({isOpen:e,onClose:t,commit:r,cwd:a,embedded:l=!1,initialFilePath:i,onContentSearch:c}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)([]),[h,x]=(0,s.useState)([]),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),M=(0,s.useRef)(null),E=J(M);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&S){e.preventDefault(),E.open();return}if("Escape"===e.key){if(E.isVisible)return void E.close();if(S)return void L(null);t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,S,E]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{m([]),x([]),b(null),j(null),w(!0)}),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(a)}&hash=${r.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];m(t);let n=R(t);if(x(n),p(new Set(P(n))),i&&t.length>0){let e=t.find(e=>e.path===i);e&&setTimeout(()=>{b(e),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(a)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error)},0)}}).catch(console.error).finally(()=>w(!1)))},[e,r,a,i]);let $=(0,s.useCallback)(e=>{r&&(b(e),C(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(a)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>C(!1)))},[a,r]),I=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),B=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,a,l;return e=new Date(r.date),t=new Date,n=e.getFullYear()===t.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${a}:${l}`:`${e.getFullYear()}-${s}-${o} ${a}:${l}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]);if(!e||!r)return null;let D=(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border bg-secondary flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-2",children:r.subject}),r.body&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground whitespace-pre-wrap mb-3 max-h-32 overflow-y-auto border-l-2 border-border pl-3",children:r.body}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.hash")}),(0,n.jsx)("span",{className:"font-mono bg-accent px-1.5 py-0.5 rounded",children:r.hash})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.author")}),(0,n.jsx)("span",{children:r.author}),(0,n.jsxs)("span",{className:"text-slate-9",children:["<",r.authorEmail,">"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.date")}),(0,n.jsx)("span",{children:B}),r.relativeDate&&(0,n.jsxs)("span",{className:"text-slate-9",children:["(",r.relativeDate,")"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.files")}),(0,n.jsx)("span",{children:d("commitDetail.nChanges",{count:u.length})})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto overflow-x-hidden",children:y?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:d("commitDetail.loadingFiles")}):(0,n.jsx)(T,{files:h,selectedPath:g?.path||null,expandedPaths:f,onSelect:e=>e.file&&$(e.file),onToggle:I,cwd:a,showChanges:!0,emptyMessage:d("commitDetail.noFileChanges"),className:"py-1"})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:k?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:d("commitDetail.loadingDiff")}):v?(0,n.jsx)(N,{oldContent:v.oldContent,newContent:v.newContent,filePath:v.filePath,isNew:v.isNew,isDeleted:v.isDeleted,cwd:a,enableComments:!0,onPreview:!v.isDeleted&&v.filePath.endsWith(".json")?()=>L({content:v.newContent,filePath:v.filePath}):void 0,previewLabel:d("common.readable"),onContentSearch:c}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:d("commitDetail.selectFileToView")})})]})]}),O=S&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>L(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:S.filePath}),(0,n.jsx)("button",{onClick:()=>L(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(Q,{search:E}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:M,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:F(S.content)})})]})});return l?(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-2 right-2 z-10 p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",title:d("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),D,O]}):(0,n.jsx)("div",{className:"fixed inset-0 z-[60] bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:d("commitDetail.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),D,O]})})}let X={M:{text:"text-amber-11",bg:"bg-amber-9/20"},A:{text:"text-green-11",bg:"bg-green-9/20"},D:{text:"text-red-11",bg:"bg-red-9/20"},"?":{text:"text-slate-9",bg:"bg-slate-9/20"},R:{text:"text-blue-11",bg:"bg-blue-9/20"}},G=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:a,onToggle:l,onContextMenu:i,renderActions:c}){let{node:d,level:u,gitStatus:m,hasChangedChildren:h}=e,x=m?X[m]:null,f=(0,s.useCallback)(()=>{d.isDirectory?l(d.path):a(d.path)},[d.isDirectory,d.path,a,l]),p=(0,s.useCallback)(e=>{i(e,d.path,d.isDirectory)},[d.path,d.isDirectory,i]),g=!d.isDirectory&&(".env"===d.name||d.name.startsWith(".env.")),b=m?x.text:h?"text-amber-11":g?"text-yellow-600 dark:text-yellow-500":t&&!d.isDirectory?"text-brand":"text-foreground";return(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 cursor-pointer hover:bg-accent ${t?"bg-brand/10":""}`,style:{paddingLeft:`${12*u+8}px`},onClick:f,onContextMenu:p,children:[d.isDirectory?o?(0,n.jsxs)("svg",{className:"w-4 h-4 flex-shrink-0 text-muted-foreground animate-spin",viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.3"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 0 0-6-6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):(0,n.jsx)("svg",{className:`w-4 h-4 flex-shrink-0 text-muted-foreground transition-transform ${r?"rotate-90":""}`,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M6 4 L10 8 L6 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)(M,{name:d.name,size:16,className:"flex-shrink-0 ml-4"}),(0,n.jsx)("span",{className:`text-sm truncate flex-1 ${b}`,"data-tooltip":d.isSymlink&&d.symlinkTarget?`${d.path} → ${d.symlinkTarget}`:d.path,children:d.name}),d.isSymlink&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:"→"}),m&&(0,n.jsx)("span",{className:`text-xs font-mono px-1 rounded ${x.text} ${x.bg} flex-shrink-0`,children:m}),d.isDirectory&&h&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),c?.(d)]})});function Z({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:a=null,loadingDirs:l,onSelect:i,onToggle:d,cwd:u,shouldScrollToSelected:h=!1,onScrolledToSelected:x,className:f,renderActions:p,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y}){let w=(0,s.useRef)(null),{contextMenu:k,showContextMenu:N,hideContextMenu:C}=(0,m.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let a=[];for(let l of t){if(null!==n&&!n.has(l.path))continue;let t=s?.get(l.path),i=l.isDirectory?function(e,t){if(!t)return!1;let r=e+"/";for(let e of t.keys())if(e.startsWith(r))return!0;return!1}(l.path,s):void 0;a.push({node:l,level:o,gitStatus:t,hasChangedChildren:i}),l.isDirectory&&l.children&&r.has(l.path)&&a.push(...e(l.children,r,n,s,o+1))}return a})(e,r,o,a),[e,r,o,a]),L=(0,c.Te)({count:S.length,getScrollElement:()=>w.current,estimateSize:()=>26,overscan:10}),M=(0,s.useRef)(x);return(M.current=x,(0,s.useEffect)(()=>{if(h&&t&&S.length>0){let e=S.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{L.scrollToIndex(e,{align:"center"}),M.current?.()},150);return()=>clearTimeout(t)}}},[h,t,S,L]),0===S.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:w,className:f||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${L.getTotalSize()}px`,width:"100%",position:"relative"},children:L.getVirtualItems().map(e=>{let s=S[e.index];return(0,n.jsx)("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},children:(0,n.jsx)(G,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:l?.has(s.node.path),onSelect:i,onToggle:d,onContextMenu:N,renderActions:p})},s.node.path)})}),k&&(0,n.jsx)(m.ft,{x:k.x,y:k.y,path:k.path,cwd:u,isDirectory:k.isDirectory,onClose:C,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y})]})}var ee=r(89662),et=r(578),er=r(14978),en=r(95766),es=r(94002);function eo({content:e,sourceFile:t}){let r,a,l,i,c,{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(!0),[f,g]=(0,s.useState)(!1);(0,s.useEffect)(()=>{if(!t)return void x(!1);let e=!1;return fetch("/api/review").then(e=>e.ok?e.json():Promise.reject()).then(r=>{if(e)return;let n=r.reviews.find(e=>e.sourceFile===t);m(n?{id:n.id,active:n.active,updatedAt:n.updatedAt}:null)}).catch(()=>{}).finally(()=>{e||x(!1)}),()=>{e=!0}},[t]);let b=u?.active===!0,v=(0,s.useCallback)(async()=>{g(!0);try{let r=t.split("/").pop()||t,n=await fetch("/api/review",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:r,content:e,sourceFile:t})});if(!n.ok)throw Error("Failed");let s=(await n.json()).review;m({id:s.id,active:!0,updatedAt:s.updatedAt||s.createdAt});try{let e=await fetch("/api/review/share-info"),t=await e.json(),r=t.shareBase?`${t.shareBase}/review/${s.id}`:`${window.location.origin}/review/${s.id}`;await navigator.clipboard.writeText(r)}catch{}(0,p.oR)(s.existing?d("toast.reviewUpdated"):d("toast.reviewCreated"),"success")}catch{(0,p.oR)(d("toast.reviewCreateFailed"),"error")}finally{g(!1)}},[e,t]),j=(0,s.useCallback)(async()=>{if(u){g(!0);try{if(!(await fetch(`/api/review/${u.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({active:!1})})).ok)throw Error("Failed");m(e=>e?{...e,active:!1}:null),(0,p.oR)(d("toast.sharingClosed"),"success")}catch{(0,p.oR)(d("toast.sharingCloseFailed"),"error")}finally{g(!1)}}},[u]),y=(0,s.useCallback)(()=>{f||(b?j():v())},[f,b,v,j]),w=(0,s.useCallback)(()=>{u&&window.open(`${window.location.origin}/review/${u.id}`,"_blank")},[u]);return h?null:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:y,disabled:f,className:`relative inline-flex h-4 w-7 items-center rounded-full transition-colors ${f?"opacity-50 cursor-wait":"cursor-pointer"} ${b?"bg-green-500":"bg-muted-foreground/30"}`,title:b?d("review.closeSharing"):d("review.enableSharing"),children:(0,n.jsx)("span",{className:`inline-block h-3 w-3 rounded-full bg-white transition-transform ${b?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsx)("span",{className:`text-[11px] ${b?"text-green-600 dark:text-green-400":"text-muted-foreground"}`,children:b?d("review.sharing"):d("review.notShared")}),u&&u.updatedAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground",children:(a=String((r=new Date(u.updatedAt)).getMonth()+1).padStart(2,"0"),l=String(r.getDate()).padStart(2,"0"),i=String(r.getHours()).padStart(2,"0"),c=String(r.getMinutes()).padStart(2,"0"),`${a}-${l} ${i}:${c}`)}),(0,n.jsx)("button",{onClick:w,className:"text-[11px] text-brand hover:underline",children:d("review.view")})]})]})}function ea(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let r=t.closest("[data-source-start]");if(!r)return null;let n=r.getAttribute("data-source-start"),s=r.getAttribute("data-source-end");return n&&s?{start:parseInt(n,10),end:parseInt(s,10)}:null}let el=[en.W];function ei({content:e,filePath:t,cwd:r,onClose:a,sourceFile:i}){let c=i||(r&&t.startsWith(r)?t.slice(r.endsWith("/")?r.length:r.length+1):t),{t:f}=(0,o.Bd)(),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(()=>{}),v=(0,m.iN)(),w=(0,h.nH)(),{comments:k,addComment:N,updateComment:C,deleteComment:S,refresh:L}=(0,d._)({cwd:r,filePath:t}),[M,E]=(0,s.useState)(!1),[$,T]=(0,s.useState)(null),[R,P]=(0,s.useState)(null),[I,B]=(0,s.useState)(null),F=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>E(!0))},[]),(0,s.useEffect)(()=>{let e=p.current;if(!e)return;let t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,g.current&&(g.current=null,b.current())},o=s=>{t=!1;let o=s.target;if(o.closest?.(".floating-toolbar")||o.closest?.("[data-comment-card]"))return;let a=Math.abs(s.clientX-r)>5||Math.abs(s.clientY-n)>5,l=window.getSelection();if(!l||l.isCollapsed){g.current=null,b.current();return}let i=l.toString();if(!i.trim()||!a){g.current=null,b.current();return}let c=l.getRangeAt(0);if(!e.contains(c.commonAncestorContainer))return;let d=ea(c.startContainer),u=ea(c.endContainer);if(d&&u){let e=Math.min(d.start,u.start),t=Math.max(d.end,u.end);g.current={x:s.clientX,y:s.clientY,range:{start:e,end:t},selectedText:i},b.current()}},a=()=>{if(t||!g.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(g.current=null,b.current())};return e.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",a),()=>{e.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",a)}},[]);let D=(0,s.useCallback)(()=>{let e=g.current;e&&(T({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),O=(0,s.useCallback)(()=>{let e=g.current;e&&(P({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),A=(0,s.useCallback)(async e=>{$&&(await N($.range.start,$.range.end,e),T(null))},[$,N]),_=(0,s.useCallback)(async e=>{if(R&&w)try{let n=await (0,u.$3)(r),s=[];for(let e of n)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});let o=Math.max(0,R.range.start-1),a=Math.min(F.length,R.range.end),l=F.slice(o,a).join("\n");s.push({filePath:t,startLine:R.range.start,endLine:R.range.end,codeContent:l});let i=(0,u.Gw)(s,e);w.sendMessage(i),await (0,u.RP)(r),L(),P(null)}catch(e){console.error("Failed to send to AI:",e)}},[R,w,t,r,F,L]),W=(0,s.useMemo)(()=>{if(0===k.length)return[];let e=new Map;for(let t of k){let r=`${t.startLine}-${t.endLine}`;e.has(r)||e.set(r,[]),e.get(r).push(t)}return Array.from(e.entries()).map(([e,t])=>({key:e,startLine:t[0].startLine,endLine:t[0].endLine,comments:t}))},[k]),[q,z]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===W.length||!p.current)return void queueMicrotask(()=>z([]));let e=setTimeout(()=>{let e=p.current;if(!e)return;let t=[],r=e.querySelectorAll("[data-source-start]");for(let n of W){let s=null,o=1/0;for(let e of r){let t=parseInt(e.getAttribute("data-source-start"),10),r=parseInt(e.getAttribute("data-source-end"),10);if(t<=n.startLine&&r>=n.endLine){let n=r-t;n<o&&(o=n,s=e)}}if(s){let r=e.getBoundingClientRect(),o=s.getBoundingClientRect();t.push({key:n.key,top:o.top-r.top+e.scrollTop,comments:n.comments})}}z(t)},100);return()=>clearTimeout(e)},[W,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(R){P(null),e.stopPropagation();return}if($){T(null),e.stopPropagation();return}if(g.current){g.current=null,b.current(),e.stopPropagation();return}if(I){B(null),e.stopPropagation();return}a()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[R,$,I,a]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:t}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(eo,{content:e,sourceFile:c}),(0,n.jsx)("button",{onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(es.l,{content:e,containerRef:p}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:p,children:[(0,n.jsx)("div",{className:"p-6",children:(0,n.jsx)(er.T,{content:e,rehypePlugins:el})}),q.map(({key:e,top:t,comments:r})=>(0,n.jsx)("div",{className:"absolute right-3 cursor-pointer z-10",style:{top:t},onClick:e=>{e.stopPropagation(),B({comment:r[0],x:e.clientX,y:e.clientY})},children:(0,n.jsx)("div",{className:"w-5 h-5 rounded-full bg-amber-500/80 text-white text-xs flex items-center justify-center shadow-sm hover:bg-amber-500 transition-colors",children:r.length})},e))]})]}),M&&v&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.f,{floatingToolbarRef:g,bumpRef:b,container:v,onAddComment:D,onSendToAI:O,isChatLoading:w?.isLoading}),$&&(0,n.jsx)(x.t,{x:$.x,y:$.y,range:$.range,codeContent:$.codeContent,container:v,onSubmit:A,onClose:()=>T(null)}),R&&(0,n.jsx)(x.G,{x:R.x,y:R.y,range:R.range,filePath:t,codeContent:R.codeContent,container:v,onSubmit:_,onClose:()=>P(null),isChatLoading:w?.isLoading}),I&&(0,n.jsx)(y.t,{x:I.x,y:I.y,comment:I.comment,container:v,onClose:()=>B(null),onUpdateComment:C,onDeleteComment:S})]}),v)]})}function ec({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),a=o>=0?e.slice(0,o+1):"",l=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],a="",l=!1;for(let s=0;s<e.length;s++){let i=t+s,c=r.has(i);c!==l&&a&&(o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-${s}`):(0,n.jsx)("span",{children:a},`${t}-${s}`)),a=""),l=c,a+=e[s]}return a&&o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-end`):(0,n.jsx)("span",{children:a},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[a&&i(a,0,"text-muted-foreground"),i(l,a.length,"text-foreground")]})}function ed({files:e,fileIndex:t,recentFiles:r,onSelectFile:a,onClose:l}){let{t:c}=(0,o.Bd)(),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(0),x=(0,s.useRef)(null),f=(0,s.useRef)(null),p=(0,s.useMemo)(()=>{let r,n;return t??(r=[],(n=e=>{for(let t of e)t.isDirectory&&t.children?n(t.children):t.isDirectory||r.push(t.path)})(e),r)},[t,e]),g=(0,s.useMemo)(()=>{if(!d.trim()){let e=new Set(r);return[...r.map(e=>({path:e,score:0,matchedIndices:[]})),...p.filter(t=>!e.has(t)).slice(0,50).map(e=>({path:e,score:0,matchedIndices:[]}))]}let e=[];for(let t of p){let n=function(e,t){let r=e.toLowerCase(),n=t.toLowerCase(),s=[],o=0,a=0,l=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),l===i-1&&(a+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(a+=10),i>e.lastIndexOf("/")&&(a+=3),e[i]===t[o]&&(a+=1),l=i,o++);return o<n.length?null:(a-=.1*e.length,{path:e,score:a,matchedIndices:s})}(t,d.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[d,p,r]),b=(0,s.useCallback)(e=>{u(e),h(0)},[]);(0,s.useEffect)(()=>{x.current?.focus()},[]),(0,s.useEffect)(()=>{if(f.current){let e=f.current.children[m];e?.scrollIntoView({block:"nearest"})}},[m]);let v=(0,s.useCallback)(e=>{a(e),l()},[a,l]),j=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing)switch(e.key){case"ArrowDown":e.preventDefault(),h(e=>Math.min(e+1,g.length-1));break;case"ArrowUp":e.preventDefault(),h(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),g[m]&&v(g[m].path);break;case"Escape":e.preventDefault(),l()}},[g,m,v,l]);return(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:l,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-2xl overflow-hidden flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,n.jsx)("input",{ref:x,value:d,onChange:e=>b(e.target.value),onKeyDown:j,placeholder:c("quickFileOpen.placeholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",autoCorrect:"off",spellCheck:"false"}),(0,n.jsx)("kbd",{className:"text-[10px] text-muted-foreground px-1.5 py-0.5 rounded border border-border bg-secondary",children:"ESC"})]}),(0,n.jsx)("div",{ref:f,className:"flex-1 overflow-y-auto py-1",children:0===g.length?(0,n.jsx)("div",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:c("quickFileOpen.noMatch")}):g.map((e,t)=>(0,n.jsxs)("div",{className:`px-3 py-1.5 flex items-center gap-2 cursor-pointer transition-colors ${t===m?"bg-brand/15 text-foreground":"hover:bg-accent text-foreground"}`,"data-tooltip":e.path,onClick:()=>v(e.path),children:[(0,n.jsx)(M,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(ec,{path:e.path,matchedIndices:e.matchedIndices}),!d.trim()&&r.includes(e.path)&&(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground px-1.5 py-0.5 rounded bg-secondary flex-shrink-0",children:c("quickFileOpen.recent")})]},e.path))}),(0,n.jsxs)("div",{className:"px-3 py-1.5 border-t border-border flex items-center gap-3 text-[10px] text-muted-foreground",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"↑↓"})," ",c("quickFileOpen.selectHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Enter"})," ",c("quickFileOpen.openHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Esc"})," ",c("quickFileOpen.closeHint")]})]})]})})})}var eu=r(22552);function em(){let[e,t]=(0,s.useState)(()=>"u"<typeof document||"visible"===document.visibilityState);return(0,s.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{e.data?.type==="IFRAME_VISIBILITY"&&t(!!e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e}var eh=r(61878),ex=r(33210),ef=r(48368),ep=r(91958),eg=r(45916),eb=r(31794),ev=r(69048),ej=r(97567),ey=r(68806),ew=r(52475);function ek({kind:e,qname:t,className:r}){let s=`${(function(e,t){if("__file__"===t||"__preamble__"===t||t&&t.startsWith("__heading_"))return"text-muted-foreground/60";switch(e){case"function":case"method":return"text-violet-11";case"class":return"text-amber-11";case"interface":return"text-blue-11";default:return"text-muted-foreground/60"}})(e,t)} ${r??""}`.trim();if("__file__"===t)return(0,n.jsx)(ef.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(eg.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(eb.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(ev.A,{className:s});case"class":return(0,n.jsx)(ej.A,{className:s});case"interface":return(0,n.jsx)(ey.A,{className:s});default:return(0,n.jsx)(ew.A,{className:s})}}let eN=new Map,eC=new Map;async function eS(e,t,r=!1){let n=`${e}::${t}`;if(r)!function(e){if(!e){eN.clear(),eC.clear();return}let t=`${e}::`;for(let e of eN.keys())e.startsWith(t)&&eN.delete(e);for(let e of eC.keys())e.startsWith(t)&&eC.delete(e)}(e);else{let e=eN.get(n);if(e)return e;let t=eC.get(n);if(t)return t}let s=(async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","1");let o=await fetch(`/api/projectGraph/file-functions?${s}`);if(404===o.status)return"not-found";if(!o.ok)throw Error((await o.json().catch(()=>({error:`HTTP ${o.status}`}))).error||`HTTP ${o.status}`);let a=await o.json();return eN.set(n,a),a})().finally(()=>eC.delete(n));return eC.set(n,s),s}function eL(e,t){let[r,n]=(0,s.useState)({state:"idle"}),o=(0,s.useRef)(!0);(0,s.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let a=(0,s.useCallback)((e,t,r)=>{n({state:"loading"}),eS(e,t,r).then(e=>{o.current&&("not-found"===e?n({state:"notFound"}):n({state:"ready",data:e}))}).catch(e=>{o.current&&n({state:"error",message:e.message})})},[]);return(0,s.useEffect)(()=>{e&&t?a(e,t,!1):n({state:"idle"})},[e,t,a]),{state:r,refresh:(0,s.useCallback)(()=>{e&&t&&a(e,t,!0)},[e,t,a])}}var eM=r(72816),eE=r(50538),e$=r(80777);function eT({entries:e,onSelect:t,onClear:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-l border-border flex flex-col","data-testid":"function-history-drawer",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border flex items-center justify-between gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground font-mono min-w-0",children:[(0,n.jsx)(eE.A,{className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:0===e.length?s("blockViewer.history.title"):`${s("blockViewer.history.title")} \xb7 ${e.length}/15`})]}),e.length>0&&(0,n.jsx)(e$.m,{content:s("blockViewer.history.clear"),children:(0,n.jsx)("button",{onClick:r,className:"flex-shrink-0 text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-secondary",children:(0,n.jsx)(ex.A,{className:"w-3 h-3"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===e.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:s("blockViewer.history.empty")}):e.map((e,r)=>{var s;let o;return(0,n.jsx)(e$.m,{content:`${e.qname} \xb7 ${e.filePath}`,children:(0,n.jsxs)("button",{onClick:()=>t(e),className:"w-full text-left px-2 py-1.5 border-b border-border/50 hover:bg-secondary/60 transition-colors group flex items-start gap-1.5",children:[(0,n.jsx)(ek,{kind:e.kind??"unknown",qname:e.qname,className:"w-3 h-3 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-mono font-medium truncate",children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:[(o=(s=e.filePath).lastIndexOf("/"))>=0?s.slice(o+1):s,e.kind&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.kind]})]})]})]})},`${e.filePath}::${e.qname}::${r}`)})})]})}function eR(e,t){let r=e.filter(e=>e.filePath!==t.filePath||e.qname!==t.qname),n=[t,...r];return n.length>15?n.slice(0,15):n}let eP=new Set(["function","class","method"]);function eI(e){return eP.has(e.kind)}function eB({functions:e,currentQname:t,onSelect:r}){let{t:a}=(0,o.Bd)(),l=(0,s.useMemo)(()=>e.filter(eI),[e]);return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-r border-border flex flex-col","data-testid":"file-toc-section",children:[(0,n.jsx)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border text-xs text-muted-foreground font-mono truncate",children:0===l.length?a("blockViewer.toc.title"):`${a("blockViewer.toc.title")} \xb7 ${l.length}`}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===l.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:a("blockViewer.toc.empty")}):l.map(e=>{let s=t===e.qualifiedName;return(0,n.jsx)(e$.m,{content:`${e.qualifiedName} \xb7 L${e.startLine}`,children:(0,n.jsxs)("button",{onClick:()=>r(e.qualifiedName,e.startLine),className:`w-full text-left px-2 py-1 transition-colors flex items-center gap-1.5 min-w-0 ${s?"bg-brand/15 hover:bg-brand/20":"hover:bg-secondary/60"}`,children:[(0,n.jsx)(ek,{kind:e.kind,qname:e.qualifiedName,className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs font-mono truncate ${s?"font-semibold text-brand":""}`,children:e.name})]})},e.qualifiedName)})})]})}function eF(e,t,r){if(!document.contains(e))return null;let n=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!n)return null;let s=n.closest("[data-line]");if(!s||!t.contains(s)||r&&!s.closest(r))return null;let o=s.getAttribute("data-line");if(!o)return null;let a=parseInt(o,10);return Number.isFinite(a)?a:null}var eD=r(96035);function eO({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,onCommentClick:a}){let l=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=l.get(n.endLine);e?e.push(n):l.set(n.endLine,[n])}return 0===l.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(l.entries()).map(([e,r])=>{let l=o+(e-t)*s,i=r[0],c=r.length-1;return(0,n.jsx)(e$.m,{content:1===r.length?i.content:`${r.length} comments — click to view`,children:(0,n.jsxs)("button",{onClick:e=>a(i,e),className:"pointer-events-auto absolute right-1 w-4 h-4 rounded-full bg-amber-9/70 hover:bg-amber-11 text-white flex items-center justify-center shadow-sm transition-colors",style:{top:`${l+s/2-8}px`},children:[(0,n.jsx)(eD.A,{className:"w-2.5 h-2.5"}),c>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 bg-amber-11 text-white rounded-full text-[8px] leading-none w-3 h-3 flex items-center justify-center",children:c+1})]})},e)})})}function eA(e,t){for(let r=0;r<e.blocks.length;r++){let n=e.blocks[r];if(t>=n.startLine&&t<=n.endLine)return e.prefix[r]+(t-n.startLine)}return null}function e_({addedLines:e,blockRanges:t,viewportRange:r,onJumpToLine:o}){let a,l=(0,s.useRef)(null),i=(0,s.useMemo)(()=>(function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[0];for(let e of t){let t=Math.max(0,e.endLine-e.startLine+1);r.push(r[r.length-1]+t)}return{blocks:t,prefix:r,total:r[r.length-1]}})(t),[t]),c=(0,s.useMemo)(()=>{if(i.total<=0||0===e.size)return[];let t=[];for(let r of e){let e=i.blocks.find(e=>r>=e.startLine&&r<=e.endLine);e&&t.push({line:r,qname:e.qname})}t.sort((e,t)=>e.line-t.line);let r=[],n=null;for(let e of t)n&&e.line===n.end+1&&e.qname===n.qname?n.end=e.line:(n&&r.push(n),n={start:e.line,end:e.line,qname:e.qname});return n&&r.push(n),r},[e,i]);if(i.total<=0)return null;let d=(e,t)=>{let r=eA(i,e),n=eA(i,t);return null===r||null===n?null:{top:r/i.total*100,heightPct:(n-r+1)/i.total*100}};return(0,n.jsxs)("div",{ref:l,onClick:e=>{let t=l.current;if(!t)return;let r=t.getBoundingClientRect();if(r.height<=0)return;let n=function(e,t){if(e.total<=0)return null;let r=Math.max(0,Math.min(e.total-1,t));for(let t=0;t<e.blocks.length;t++){let n=e.prefix[t],s=e.prefix[t+1];if(r>=n&&r<s){let s=e.blocks[t];return{qname:s.qname,line:s.startLine+Math.round(r-n)}}}return null}(i,(e.clientY-r.top)/r.height*i.total);if(!n)return;let s=n.line,a=c.find(e=>e.qname===n.qname&&s>=e.start&&s<=e.end);if(a)return void o(a.qname,s);if(c.length>0){let e=Math.max(2,Math.round(.05*i.total)),t=eA(i,s);if(null!==t){let r=null,n=1/0;for(let e of c){let s=eA(i,e.start),o=eA(i,e.end);if(null===s||null===o)continue;let a=t<s?s-t:t>o?t-o:0;a<n&&(r=e,n=a)}if(r&&n<=e){let e=s<r.start?r.start:s>r.end?r.end:s;o(r.qname,e);return}}}let d=i.blocks.find(e=>e.qname===n.qname);d&&o(d.qname,d.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[c.map(e=>{let t=d(e.start,e.end);return t?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-green-9 pointer-events-none",style:{top:`${t.top}%`,height:`${t.heightPct}%`,minHeight:"2px"}},`run:${e.qname}:${e.start}-${e.end}`):null}),r&&r.end>=r.start&&((a=d(r.start,r.end))?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border pointer-events-none",style:{top:`${a.top}%`,height:`${Math.max(1.2,a.heightPct)}%`}}):null)]})}function eW(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function eq({symbol:e,fileSource:t,hasChange:r,onHighlighted:o,comments:a,onCommentClick:l,addedLines:i}){let{resolvedTheme:c}=(0,eM.D)(),d=(0,s.useMemo)(()=>(0,b.sQ)(e.filePath),[e.filePath]),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!t)return void m(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,b.kS)()).codeToTokens(n,{lang:d,theme:"dark"===c?"github-dark":"github-light"}).tokens.map((t,r)=>{let n=e.startLine+r,s=i?.has(n)??!1;return`<div class="flex${s?" bg-green-9/15":""}" style="min-width:max-content" data-line="${n}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${n}</span><span class="whitespace-pre">${(0,b.b8)(t)}</span></div>`}).join("");r||(m(s),x(null))}catch(e){r||x(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,d,c,e.filePath,i]),(0,s.useEffect)(()=>{(null!==u||null!==h)&&o(e.qualifiedName)},[u,h,e.qualifiedName,o]),(0,n.jsxs)("div",{className:"flex-1 min-w-0 bg-card border border-border rounded overflow-hidden relative",children:[(0,n.jsxs)("div",{"data-block-header":!0,className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border bg-secondary/40 text-xs",children:[(0,n.jsx)(ek,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsxs)("span",{className:"font-mono truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),void 0!==e.params&&(0,n.jsxs)("span",{className:"text-muted-foreground/80",children:["(",e.params.join(", "),")"]})]}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 flex-shrink-0",children:[e.kind," \xb7 L",e.startLine,"-",e.endLine]}),(0,n.jsx)("span",{className:"flex-1"}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 w-2 h-2 rounded-full bg-amber-11","data-tooltip":"File has uncommitted change"})]}),(0,n.jsxs)("div",{"data-block-body":!0,className:"text-[11px] font-mono px-2 py-2 overflow-auto",style:{lineHeight:`${eH}px`},children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),h&&(0,n.jsx)("span",{className:"text-red-11",children:h}),u&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:u}})]}),a&&a.length>0&&l&&(0,n.jsx)(eO,{comments:a,startLine:e.startLine,endLine:e.endLine,lineHeight:eH,bodyTopOffset:eU+eV,onCommentClick:l})]})}function ez({side:e,pin:t,accent:r,onClick:s}){let o,a,l,i,c,d,u,m=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="ext",l="text-muted-foreground/60",i=t.name,c=t.packageSpec,d="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="method",l="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,c=null,d="method (unresolved)",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):"self"===t.kind?(o="bg-secondary/40 border-border hover:border-muted-foreground",a="self",l="text-muted-foreground/70",i=t.external.name,c=null,d="same-file",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):(o="in"===e?"bg-amber-9/15 border-amber-9/40 hover:border-amber-11":"bg-green-9/15 border-green-9/40 hover:border-green-11",a=e,l="in"===e?"text-amber-11":"text-green-11",i=t.external.name,c=eW(t.external.filePath),d="in"===e?"caller":"callee",u=t.external.filePath);let h=r&&"ext"!==t.kind&&"method"!==t.kind?" ring-1 ring-amber-9/70 ring-offset-0":"";return(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),s()},className:`${o}${h} w-full text-left border rounded px-1.5 py-0.5 text-[10px] font-mono cursor-pointer transition-colors flex items-center gap-1.5`,"data-tooltip":`${d}${u?" \xb7 "+u:""}`,children:[(0,n.jsx)("span",{className:`${l} text-[9px] uppercase tracking-wider font-semibold flex-shrink-0`,children:a}),(0,n.jsxs)("span",{className:"truncate flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:i}),c&&(0,n.jsx)("span",{className:"text-muted-foreground/70 ml-1",children:c}),m>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60 ml-1",children:["\xb7",m,"\xd7"]})]})]})}let eH=18,eU=29,eV=8;function eK(e,t){switch(t.kind){case"cross":return`${e}:x:${t.external.filePath}::${t.external.qualifiedName}`;case"self":return`${e}:s:${t.external.filePath}::${t.external.qualifiedName}`;case"ext":return`${e}:e:${t.packageSpec}::${t.name}`;case"method":return`${e}:m:${t.receiverName}::${t.methodName}`}}function eJ(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function eQ(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function eY({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:a,onHighlighted:l,comments:i,onCommentClick:c,accentQnames:d,addedLines:u}){let m=function(e,t){if(0===e.length)return[];let r=e.map((e,r)=>{var n,s;return{i:r,line:(n=e.lines[0]??t.startLine,s=t.startLine,Math.max(s,Math.min(t.endLine,n)))}});r.sort((e,t)=>e.line-t.line||e.i-t.i);let n=Array(e.length).fill(0),s=-1/0;for(let{i:e,line:o}of r){let r=Math.max(eU+eV+(o-t.startLine)*eH,s);n[e]=r,s=r+22}return n}(o,e);return(0,n.jsxs)("div",{"data-block-qname":e.qualifiedName,"data-start-line":e.startLine,"data-end-line":e.endLine,className:"flex gap-2 items-stretch scroll-mt-2",children:[(0,n.jsx)("div",{className:"w-44 flex-shrink-0 flex flex-col gap-1 pt-1",children:0===s.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5",children:"no callers"}):s.map(t=>(0,n.jsx)(ez,{side:"in",pin:t,accent:eJ(t,d),onClick:()=>a(t,e)},eK("in",t)))}),(0,n.jsx)(eq,{symbol:e,fileSource:t,hasChange:r,onHighlighted:l,comments:i,onCommentClick:c,addedLines:u}),(0,n.jsx)("div",{className:"w-44 flex-shrink-0 relative",children:0===o.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5 pt-1",children:"no callees"}):o.map((t,r)=>(0,n.jsx)("div",{className:"absolute left-0 right-0",style:{top:`${m[r]}px`},children:(0,n.jsx)(ez,{side:"out",pin:t,accent:eJ(t,d),onClick:()=>a(t,e)})},eK("out",t)))})]})}function eX({cwd:e,onSelect:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(""),[c,d]=(0,s.useState)({files:[],symbols:[]}),[u,m]=(0,s.useState)(0),[h,x]=(0,s.useState)(!1),f=(0,s.useMemo)(()=>[...c.files,...c.symbols],[c]);(0,s.useEffect)(()=>{let t=l.trim();if(!t)return void d({files:[],symbols:[]});x(!0);let r=setTimeout(async()=>{try{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await fetch(`/api/projectGraph/search?${r}`);if(n.ok){let e=await n.json();d(e),m(0)}}finally{x(!1)}},120);return()=>clearTimeout(r)},[l,e]);let p=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==f.length){if("ArrowDown"===e.key)e.preventDefault(),m(e=>Math.min(e+1,f.length-1));else if("ArrowUp"===e.key)e.preventDefault(),m(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=f[u];r&&t(r)}}},[f,u,r,t]);return(0,n.jsx)("div",{className:"absolute inset-0 bg-background/40 z-20 flex items-start justify-center pt-24",onClick:r,children:(0,n.jsxs)("div",{className:"w-[480px] max-w-[80%] bg-card border border-border rounded shadow-2xl overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)(eh.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:l,onChange:e=>i(e.target.value),onKeyDown:p,placeholder:a("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),h&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"…"}),(0,n.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===f.length&&l&&!h&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("blockViewer.search.noResults","No matches")}),(0,n.jsx)(eG,{label:a("blockViewer.search.files","Files"),hits:c.files,startIdx:0,activeIdx:u,onSelect:t,setActive:m}),(0,n.jsx)(eG,{label:a("blockViewer.search.symbols","Symbols"),hits:c.symbols,startIdx:c.files.length,activeIdx:u,onSelect:t,setActive:m})]})]})})}function eG({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:a}){return 0===t.length?null:(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-secondary/40",children:e}),t.map((e,t)=>{let l=r+t,i=l===s;return(0,n.jsxs)("button",{onMouseEnter:()=>a(l),onClick:()=>o(e),className:`w-full text-left px-3 py-1.5 text-xs flex items-start gap-2 ${i?"bg-secondary":"hover:bg-secondary/60"}`,children:["file"===e.target.kind?(0,n.jsx)(ef.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(ek,{kind:e.target.symbolKind,qname:e.target.qualifiedName,className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),e.hint&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground truncate",children:e.hint})]})]},`${e.type}:${e.label}:${t}`)})]})}function eZ({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:a,enableComments:l=!1,onContentSearch:i,onFocalChange:c,qnameFilter:m,qnameFilterFile:f,accentQnames:p,accentFile:g,addedLines:b,addedLinesFile:v,headerExtraLeft:w,headerExtraRight:k}){let{t:N}=(0,o.Bd)(),[C,S]=(0,s.useState)(null),L=C??t??null;(0,s.useEffect)(()=>{S(null)},[t]),(0,s.useEffect)(()=>{c?.(L)},[L,c]);let{state:M,refresh:E}=eL(e,L),[$,T]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!L)return void T(null);let t=!1;return T(null),(async()=>{try{let r=new URLSearchParams({cwd:e,path:L}),n=await fetch(`/api/files/text?${r}`);if(!n.ok)return;let s=await n.json();t||T({content:s.content,mtimeMs:s.mtimeMs})}catch(e){console.error("[BlockViewer] failed to load file source for",L,e)}})(),()=>{t=!0}},[e,L]);let R=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!$||"ready"!==M.state)return;let e=M.data.mtimeMs;!e||$.mtimeMs<=e||R.current!==$.mtimeMs&&(R.current=$.mtimeMs,E())},[$,M,E]);let[P,I]=(0,s.useState)([]),[B,F]=(0,s.useState)(!1),[D,O]=(0,s.useState)(null),A=(0,s.useRef)(0),_=(0,s.useRef)(0),[W,q]=(0,s.useState)(()=>new Set),z="ready"===M.state?M.data.filePath:null;(0,s.useEffect)(()=>{q(new Set)},[z]);let H=(0,s.useCallback)(e=>{q(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),F(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let U=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;A.current+=1,O({filePath:e,qname:"__imports__",nonce:A.current});return}let r=eQ(t),n=eQ(e.external);I(e=>eR(eR(e,r),n)),S(n.filePath),A.current+=1,O({filePath:n.filePath,qname:n.qname,nonce:A.current})},[]),V=(0,s.useCallback)(e=>{S(e.filePath),A.current+=1,O({filePath:e.filePath,qname:e.qname,nonce:A.current})},[]),K=(0,s.useCallback)(e=>{F(!1),S(e.target.filePath),"symbol"===e.target.kind&&(A.current+=1,O({filePath:e.target.filePath,qname:e.target.qualifiedName,line:e.target.line,nonce:A.current}))},[]),J=(0,s.useCallback)((e,t)=>{L&&(A.current+=1,O({filePath:L,qname:e,line:t,nonce:A.current}))},[L]),[Q,Y]=(0,s.useState)(null),[X,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!Q)return;let e=null,t=()=>{e=null;let t=Q.getBoundingClientRect();if(t.height<=0)return;let r=Q.querySelectorAll("[data-block-qname]"),n=1/0,s=-1/0;r.forEach(e=>{let r=e.dataset.startLine,o=e.dataset.endLine;if(!r||!o)return;let a=Number(r),l=Number(o);if(!Number.isFinite(a)||!Number.isFinite(l))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let c=Math.max(0,t.top-i.top),d=Math.min(i.height,t.bottom-i.top),u=l-a+1,m=Math.floor(c/i.height*u),h=Math.ceil(d/i.height*u)-1,x=a+Math.max(0,m),f=a+Math.min(u-1,Math.max(0,h));x<n&&(n=x),f>s&&(s=f)}),n===1/0||s===-1/0?G(null):G(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),Q.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(Q);let s=new MutationObserver(r);return s.observe(Q,{childList:!0,subtree:!0}),()=>{Q.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[Q]);let Z=(0,s.useMemo)(()=>{if("ready"!==M.state||!X)return null;let e=M.data.functions;if(0===e.length)return null;let t=(X.start+X.end)/2;for(let r of e)if(r.startLine<=t&&t<=r.endLine)return r.qualifiedName;let r=null;for(let t of e)t.startLine<=X.start&&(!r||t.startLine>r.startLine)&&(r=t);return r?.qualifiedName??null},[M,X]),ee=l&&!!e&&!!L,et=(0,h.nH)(),{comments:er,addComment:en,updateComment:es,deleteComment:eo,refresh:ea}=(0,d._)({cwd:e,filePath:L??""}),[el,ei]=(0,s.useState)(null),{toolbar:ec,clearToolbar:ed}=function({enabled:e,container:t,bodyScope:r}){let[n,o]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!e||!t)return;let n=!1,s=0,a=0,l=e=>{n=!0,s=e.clientX,a=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||o(e=>e?null:e)},i=e=>{n=!1;let l=e.target;if(l?.closest?.(".floating-toolbar"))return;let i=Math.abs(e.clientX-s)>5||Math.abs(e.clientY-a)>5,c=window.getSelection();if(!c||c.isCollapsed||!c.toString().trim()||!i)return void o(e=>e?null:e);let d=c.getRangeAt(0);if(!t.contains(d.commonAncestorContainer))return void o(e=>e?null:e);let u=eF(d.startContainer,t,r),m=eF(d.endContainer,t,r);if(null==u||null==m)return void o(e=>e?null:e);let h=Math.min(u,m),x=Math.max(u,m);o({x:e.clientX,y:e.clientY,range:{start:h,end:x},selectedText:c.toString()})},c=()=>{if(n)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||o(e=>e?null:e)};return t.addEventListener("mousedown",l),document.addEventListener("mouseup",i),document.addEventListener("selectionchange",c),()=>{t.removeEventListener("mousedown",l),document.removeEventListener("mouseup",i),document.removeEventListener("selectionchange",c)}},[e,t,r]),{toolbar:n,clearToolbar:()=>o(null)}}({enabled:ee,container:el}),[eu,em]=(0,s.useState)(null),[eh,ex]=(0,s.useState)(null),[ef,ep]=(0,s.useState)(null),eg=(0,s.useCallback)(()=>{ec&&(em({x:ec.x,y:ec.y,range:ec.range,codeContent:ec.selectedText}),ed())},[ec,ed]),eb=(0,s.useCallback)(()=>{ec&&(ex({x:ec.x,y:ec.y,range:ec.range,codeContent:ec.selectedText}),ed())},[ec,ed]),ev=(0,s.useCallback)(()=>{if(!ec||!i)return;let e=ec.selectedText.trim();ed(),e&&i(e)},[ec,i,ed]),ej=(0,s.useCallback)(async e=>{eu&&(await en(eu.range.start,eu.range.end,e,eu.codeContent),em(null))},[eu,en]),ey=(0,s.useCallback)(async t=>{if(eh&&et&&e&&L)try{let r=(await (0,u.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:L,startLine:eh.range.start,endLine:eh.range.end,codeContent:eh.codeContent});let n=(0,u.Gw)(r,t);et.sendMessage(n),await (0,u.RP)(e),ea(),ex(null)}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[eh,et,e,L,ea]),ew=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ep({comment:e,x:t.clientX,y:t.clientY}),ed(),em(null),ex(null)},[ed]);if((0,s.useEffect)(()=>{let e;if(!D||_.current>=D.nonce||"ready"!==M.state||!$||M.data.filePath!==D.filePath)return;if(f&&f===M.data.filePath&&m){let t=0;for(let e of M.data.functions)m.has(e.qualifiedName)&&t++;e=Math.max(1,t)}else e=Math.max(1,M.data.functions.length);if(W.size<e)return;_.current=D.nonce;let t=null,r=requestAnimationFrame(()=>{let e=D.qname.indexOf(">"),r=e>=0?D.qname.slice(0,e):D.qname,n=document.querySelector(`[data-block-qname="${CSS.escape(r)}"]`);if(!n)return;if("number"==typeof D.line){let e=n.querySelector(`[data-line="${D.line}"]`);if(e instanceof HTMLElement){e.scrollIntoView({behavior:"instant",block:"center"}),e.classList.remove("line-flash"),e.offsetWidth,e.classList.add("line-flash"),t=window.setTimeout(()=>{e.classList.remove("line-flash")},1700);return}}n.scrollIntoView({behavior:"instant",block:"start"});let s=n.querySelector("[data-block-header]");s instanceof HTMLElement&&(s.classList.remove("block-flash"),s.offsetWidth,s.classList.add("block-flash"),t=window.setTimeout(()=>{s.classList.remove("block-flash")},1700))});return()=>{cancelAnimationFrame(r),null!==t&&window.clearTimeout(t)}},[D,M,$,W,m,f]),!L)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:null,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-sm text-muted-foreground gap-2 px-4 text-center",children:[(0,n.jsx)("span",{children:N("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:N("blockViewer.empty.hint","or press ⌘K to search.")})]}),B&&(0,n.jsx)(eX,{cwd:e,onSelect:K,onClose:()=>F(!1)})]});if("idle"===M.state||"loading"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N("blockViewer.fileMode.loading","Loading…")})]});if("notFound"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:N("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),B&&(0,n.jsx)(eX,{cwd:e,onSelect:K,onClose:()=>F(!1)})]});if("error"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-sm",children:[(0,n.jsx)("span",{className:"text-red-11",children:M.message}),(0,n.jsx)("button",{onClick:E,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:N("blockViewer.retry","Retry")})]})]});let ek=M.data,eN=ek.functions;if(0===eN.length&&$){let e=Math.max(1,$.content.split("\n").length);eN=[{filePath:ek.filePath,qualifiedName:"__file__",name:eW(ek.filePath),kind:"unknown",startLine:1,endLine:e}]}let eC=f&&f===ek.filePath,eS=g&&g===ek.filePath,eM=v&&v===ek.filePath;eC&&m&&(eN=eN.filter(e=>m.has(e.qualifiedName)));let eE=eS?p:void 0,e$=eM?b:void 0,eP=e0(ek.upstreamCalls),eI=e0(ek.downstreamCalls),eD=new Map(eN.map(e=>[e.qualifiedName,e])),eO=new Map,eA=new Map;for(let e of ek.intraCalls){let t=eD.get(e.to),r=eD.get(e.from);if(t){let r=eO.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):eO.set(e.from,[n])}if(r){let t=eA.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):eA.set(e.to,[n])}}let eq=new Map;for(let e of ek.externalCalls??[]){let t=eq.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):eq.set(e.focalQname,[r])}let ez=new Map;for(let e of ek.methodCalls??[]){let t=ez.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):ez.set(e.focalQname,[r])}let eH=r.has(ek.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:ek.fileCount,functionCount:ek.functions.length,upstreamCount:ek.upstreamCalls.length,downstreamCount:ek.downstreamCalls.length,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{ref:ei,className:"flex-1 relative min-h-0 flex",children:[(0,n.jsx)(eB,{functions:eN,currentQname:Z,onSelect:J}),(0,n.jsx)("div",{ref:Y,className:"flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:eN.map(e=>{let t,r,s,o,a,l;return(0,n.jsx)(eY,{symbol:e,fileSource:$?.content??null,hasChange:eH,upstream:(t=eP.get(e.qualifiedName),r=eA.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=eI.get(e.qualifiedName),o=eO.get(e.qualifiedName),a=ez.get(e.qualifiedName),l=eq.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...a??[],...l??[]]),onPinClick:U,onHighlighted:H,comments:ee?er:void 0,onCommentClick:ee?ew:void 0,accentQnames:eE,addedLines:e$},e.qualifiedName)})})}),ee&&ec&&el&&(0,n.jsx)(j.w,{x:ec.x,y:ec.y,visible:!0,container:el,onAddComment:eg,onSendToAI:eb,onSearch:i?ev:void 0,isChatLoading:et?.isLoading}),ee&&eu&&(0,n.jsx)(x.t,{x:eu.x,y:eu.y,range:eu.range,codeContent:eu.codeContent,container:el,onSubmit:ej,onClose:()=>em(null)}),ee&&eh&&L&&(0,n.jsx)(x.G,{x:eh.x,y:eh.y,range:eh.range,filePath:L,codeContent:eh.codeContent,container:el,onSubmit:ey,onClose:()=>ex(null),isChatLoading:et?.isLoading}),ee&&ef&&(0,n.jsx)(y.t,{x:ef.x,y:ef.y,comment:ef.comment,container:el,onClose:()=>ep(null),onUpdateComment:es,onDeleteComment:eo}),e$&&e$.size>0&&eN.length>0&&(0,n.jsx)(e_,{addedLines:e$,blockRanges:eN.map(e=>({qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine})),viewportRange:X,onJumpToLine:J}),(0,n.jsx)(eT,{entries:P,onSelect:V,onClear:()=>I([])}),B&&(0,n.jsx)(eX,{cwd:e,onSelect:K,onClose:()=>F(!1)})]})]})}function e0(e){let t=new Map;for(let r of e){let e=t.get(r.focalQname);if(!e){t.set(r.focalQname,[r]);continue}e.some(e=>e.external.filePath===r.external.filePath&&e.external.qualifiedName===r.external.qualifiedName)||e.push(r)}return t}function e1({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:a,onSwitchToCode:l,onSearch:i,onRefresh:c,refreshDisabled:d,extraLeft:u,extraRight:m}){let{t:h}=(0,o.Bd)(),x={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:a??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between bg-secondary/30 gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 text-xs text-muted-foreground font-mono",children:[(0,n.jsx)("span",{className:"truncate min-w-0",children:e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-foreground",children:e}),"number"==typeof r&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",r," blocks"]}),"number"==typeof s&&"number"==typeof a&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",a," out"]})]}):(0,n.jsx)("span",{children:null!==t?`${t} files`:"…"})}),u&&(0,n.jsx)("span",{className:"flex items-center gap-1 flex-shrink-0",children:u(x)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[m&&(0,n.jsx)("span",{className:"flex items-center gap-1",children:m(x)}),(0,n.jsxs)("button",{onClick:i,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground flex items-center gap-1","data-tooltip":h("blockViewer.search.tooltip","Search (⌘K)"),children:[(0,n.jsx)(eh.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:c,disabled:d,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent","data-tooltip":h("blockViewer.refresh","Rebuild project graph"),children:(0,n.jsx)(ep.A,{className:"w-3 h-3"})}),l&&(0,n.jsx)("button",{onClick:l,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:"Code"})]})]})}function e2(e){let t=0xdeadbeef,r=0x41c6ce57;for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);t=Math.imul(t^s,0x9e3779b1),r=Math.imul(r^s,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35),(0x100000000*(2097151&(r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)>>>0).toString(16)}function e5(e){return e.replace(/\s+/g," ").trim()}function e4(e,t){return e?`${e}>${t}`:t}function e3(e){let t=e.childForFieldName("name");if(t)return t.text;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r&&("identifier"===r.type||"type_identifier"===r.type||"property_identifier"===r.type))return r.text}return"<anonymous>"}function e6(e,t,r,n,s=[],o){return{qualifiedName:e4(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e2(e5(e.text)),children:s,params:o}}function e8(e){let t=e.childForFieldName("parameter");if(t)return[t.text];let r=e.childForFieldName("parameters");if(!r)return;let n=[];for(let e=0;e<r.namedChildCount;e++){let t=r.namedChild(e);t&&n.push(function e(t){switch(t.type){case"required_parameter":case"optional_parameter":{let r=t.childForFieldName("pattern");return r?e(r):t.text}case"assignment_pattern":{let r=t.childForFieldName("left");return r?e(r):t.text}case"default_parameter":case"typed_default_parameter":{let e=t.childForFieldName("name");return e?e.text:t.text}case"typed_parameter":for(let e=0;e<t.namedChildCount;e++){let r=t.namedChild(e);if(r?.type==="identifier")return r.text}return t.text;default:return t.text}}(t))}return n}function e9(e){let t=e.split("/").pop()?.toLowerCase()??"";switch(t.includes(".")?t.split(".").pop():""){case"ts":return"typescript";case"tsx":case"jsx":return"tsx";case"js":case"mjs":case"cjs":return"javascript";case"py":case"pyi":return"python";case"go":return"go";case"rs":return"rust";default:return null}}var e7=r(14066);let te="/tree-sitter",tt=null,tr=new Map;async function tn(e){let t,r=await (!(t=tr.get(e))&&(t=(async()=>(await (!tt&&(tt=e7.iX.init({locateFile:e=>`${te}/${e}`})),tt),e7.TM.load(`${te}/tree-sitter-${e}.wasm`)))(),tr.set(e,t)),t),n=new e7.iX;return n.setLanguage(r),n}function ts(e){return e.qualifiedName.startsWith("__code_")||e.qualifiedName.startsWith("__heading_")}function to(e){return!ts(e)&&"__file__"!==e.qualifiedName}async function ta(e,t){if(!e)return[];let r=e9(t);if(!r)return null;let n=(await tn(r)).parse(e);if(!n)return null;try{return function(e){let t=[],r=function(e){let t=[],r=-1,n=-1;for(let s=0;s<e.namedChildCount;s++){let o=e.namedChild(s);if(o){if("import_statement"===o.type||"export_statement"===o.type&&null!==o.childForFieldName("source")||"import_from_statement"===o.type||"future_import_statement"===o.type)t.push(o),r<0&&(r=o.startPosition.row+1),n=o.endPosition.row+1;else if(r>=0)break}}return r<0?null:{qualifiedName:"__imports__",name:"imports",kind:"unknown",startLine:r,endLine:n,contentHash:e2(e5(t.map(e=>e.text).join("\n"))),children:[]}}(e);r&&t.push(r);for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);n&&t.push(...function e(t,r,n=!1){switch(t.type){case"export_statement":case"export_default_declaration":{let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);o&&n.push(...e(o,r,!0))}return n}case"function_declaration":case"generator_function_declaration":case"function_definition":return[e6(t,e3(t),"function",r,[],e8(t))];case"class_declaration":case"abstract_class_declaration":{let e=e3(t),n=e4(r,e),s=function(e,t){if(!e)return[];let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(s){if("method_definition"===s.type)r.push(e6(s,e3(s),"method",t,[],e8(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(e6(s,e3(s),"method",t,[],e8(e)))}}}return r}(t.childForFieldName("body"),n);return[e6(t,e,"class",r,s)]}case"interface_declaration":return[e6(t,e3(t),"interface",r)];case"type_alias_declaration":return[e6(t,e3(t),"type",r)];case"enum_declaration":return[e6(t,e3(t),"enum",r)];case"lexical_declaration":case"variable_declaration":return function(e,t){let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s||"variable_declarator"!==s.type)continue;let o=s.childForFieldName("name"),a=s.childForFieldName("value");if(!o)continue;let l=o.text,i=a&&("arrow_function"===a.type||"function_expression"===a.type),c=i&&a?e8(a):void 0;if(r.push(e6(e,l,i?"function":"const",t,[],c)),a&&"object"===a.type&&!i){let e=t?`${t}>${l}`:l;for(let t=0;t<a.namedChildCount;t++){let n=a.namedChild(t);if(n){if("pair"===n.type){let t=n.childForFieldName("key"),s=n.childForFieldName("value");if(!t||!s||"property_identifier"!==t.type&&"identifier"!==t.type||"arrow_function"!==s.type&&"function_expression"!==s.type)continue;r.push(e6(n,t.text,"method",e,[],e8(s)))}else if("method_definition"===n.type){let t=e3(n);t&&r.push(e6(n,t,"method",e,[],e8(n)))}}}}}return r}(t,r);case"class_definition":{let e=e3(t),n=e4(r,e),s=function e(t,r){if(!t)return[];let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);if(o){if("function_definition"===o.type)n.push(e6(o,e3(o),"method",r,[],e8(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...e6(t,e3(t),"method",r,[],e8(t)),startLine:o.startPosition.row+1,contentHash:e2(e5(o.text))});else if(t?.type==="class_definition"){let s=e3(t),a=e4(r,s),l=e(t.childForFieldName("body"),a);n.push({...e6(t,s,"class",r,l),startLine:o.startPosition.row+1,contentHash:e2(e5(o.text))})}}else if("class_definition"===o.type){let t=e3(o),s=e4(r,t),a=e(o.childForFieldName("body"),s);n.push(e6(o,t,"class",r,a))}}}return n}(t.childForFieldName("body"),n);return[e6(t,e,"class",r,s)]}case"decorated_definition":{let n=t.childForFieldName("definition");if(!n)return[];return e(n,r,!1).map(e=>({...e,startLine:t.startPosition.row+1,contentHash:e2(e5(t.text))}))}case"expression_statement":{let e=[];for(let n=0;n<t.namedChildCount;n++){let s=t.namedChild(n);if(s?.type==="assignment"){let n=function(e,t,r){let n=t.childForFieldName("left");if(!n||"identifier"!==n.type)return null;let s=n.text;return{qualifiedName:e4(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e2(e5(e.text)),children:[]}}(t,s,r);n&&e.push(n)}}return e.push(...function(e,t){let r=null;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(n){if("call_expression"===n.type){r=n;break}if("await_expression"===n.type){for(let e=0;e<n.namedChildCount;e++){let t=n.namedChild(e);if(t?.type==="call_expression"){r=t;break}}break}}}if(!r)return[];let n=r.childForFieldName("function"),s=r.childForFieldName("arguments");if(!n||!s)return[];let o=null,a=[];for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t){if(null===o&&("string"===t.type||"template_string"===t.type)){let e=t.text;o=e.length>=2&&/^["'`]/.test(e)?e.slice(1,-1):e}("arrow_function"===t.type||"function_expression"===t.type)&&a.push(t)}}if(0===a.length||!o)return[];let l=function e(t){if("identifier"===t.type)return t.text;if("member_expression"===t.type){let e=t.childForFieldName("property");return e?.text??""}if("call_expression"===t.type){let r=t.childForFieldName("function");return r?e(r):""}return""}(n),i=l?`${l} ${o}`:o;return a.map((e,r)=>e6(e,a.length>1?`${i} #${r+1}`:i,"function",t,[],e8(e)))}(t,r)),e}default:return[]}}(n,void 0,!1))}return t.push(...function(e,t){let r=e.text.split("\n"),n=r.length;if(0===n)return[];let s=new Uint8Array(n+2);for(let e of t){let t=Math.max(1,e.startLine),r=Math.min(n,e.endLine);for(let e=t;e<=r;e++)s[e]=1}let o=[],a=(e,t)=>{let n=!1;for(let s=e;s<=t;s++){let e=r[s-1];if(e&&e.trim().length>0){n=!0;break}}if(!n)return;let s=r.slice(e-1,t).join("\n");o.push({qualifiedName:`__code_${e}_${t}__`,name:"code",kind:"unknown",startLine:e,endLine:t,contentHash:e2(e5(s)),children:[]})},l=-1;for(let e=1;e<=n;e++)s[e]?l>=0&&(a(l,e-1),l=-1):l<0&&(l=e);return l>=0&&a(l,n),o}(e,t)),t}(n.rootNode)}finally{n.delete()}}async function tl(e,t,r,n,s){let o=new Set;if(e!==t)for(let r of f(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum&&o.add(r.newLineNum);if(!e9(r))return{addedLines:o};let[a,l]=await Promise.all([ta(n?"":e,r),ta(s?"":t,r)]),i=l??[],c=function(e,t){let r=new Map;for(let t of e)r.set(t.qualifiedName,t);let n=new Map;for(let e of t)n.set(e.qualifiedName,e);let s=[];for(let e of t){let t=r.get(e.qualifiedName);t?t.contentHash!==e.contentHash&&s.push({id:`mod:${e.qualifiedName}`,changeKind:"modified",qname:e.qualifiedName}):s.push({id:`add:${e.qualifiedName}`,changeKind:"added",qname:e.qualifiedName})}for(let t of e)n.has(t.qualifiedName)||s.push({id:`del:${t.qualifiedName}`,changeKind:"deleted",qname:t.qualifiedName});return s}((a??[]).filter(to),i.filter(to)),d=new Set;for(let e of c)"deleted"!==e.changeKind&&d.add(e.qname);for(let e of function(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(ts(n)){for(let e of t)if(e>=n.startLine&&e<=n.endLine){r.push(n.qualifiedName);break}}return r}(i,o))d.add(e);return{changedQnames:d,addedLines:o}}function ti({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:a=!1,isDeleted:l=!1,changedFiles:i,fileGitStatusMap:c,enableComments:d=!1,onContentSearch:u,headerExtraLeft:m,headerExtraRight:h}){let[x,f]=(0,s.useState)(t);(0,s.useEffect)(()=>{f(t)},[t]);let[p,g]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return g(null),(async()=>{try{let s=await tc(x,t,r,o,a,l,i,c,e);if(n||!s)return;let d=await tl(s.oldContent,s.newContent,x,s.isNew,s.isDeleted);if(n)return;g(d)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[x,t,r,o,a,l,i,c,e]),(0,n.jsx)(eZ,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:d,qnameFilter:p?.changedQnames,qnameFilterFile:x,accentQnames:p?.changedQnames,accentFile:x,addedLines:p?.addedLines,addedLinesFile:x,onFocalChange:e=>e&&f(e),onContentSearch:u,headerExtraLeft:m,headerExtraRight:h})}async function tc(e,t,r,n,s,o,a,l,i){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!a.has(e))return null;let c=l?.get(e);if(!c)return null;let d=new URLSearchParams({cwd:i,file:e,type:c}),u=await fetch(`/api/git/diff?${d}`);if(!u.ok)return null;let m=await u.json();return{oldContent:m.oldContent,newContent:m.newContent,isNew:m.isNew??!1,isDeleted:m.isDeleted??!1}}function td(e){let{refreshKey:t,className:r="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:a}=e,l="absPath"in e&&"string"==typeof e.absPath,i=l?void 0:e.cwd,c=l?void 0:e.path,d=l?e.absPath:void 0,[u,m]=(0,s.useState)({kind:"loading"}),h=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++h.current;return m({kind:"loading"}),(async()=>{if(l){if(e!==h.current)return;m({kind:"ready",etag:null,size:0});return}try{let t=`/api/files/stat?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}`,r=await fetch(t,{cache:"no-store"});if(e!==h.current)return;if(!r.ok)return void m({kind:"error",message:`stat failed (${r.status})`});let n=await r.json();if(e!==h.current)return;if(!n.exists)return void m({kind:"missing"});if("too-large"===n.category)return void m({kind:"too-large",size:n.size??0});if("image"!==n.category)return void m({kind:"error",message:`Not an image (${n.category})`});let s=n.etag||`t-${n.mtimeMs??Date.now()}`;m({kind:"ready",etag:s,size:n.size??0})}catch(t){if(e!==h.current)return;m({kind:"error",message:t instanceof Error?t.message:"Unknown error"})}})(),()=>{h.current++}},[l,i,c,d,t]),"loading"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(u.size/1024/1024)," MB)"]})});if("error"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:u.message})});let x=l?`/api/file?path=${encodeURIComponent(d)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}&v=${encodeURIComponent(u.etag)}`;return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("img",{src:x,alt:a??(c||d),className:o})})}function tu({cwd:e,selected:t,diff:r,showMarkdownPreview:a,setShowMarkdownPreview:l,changedFiles:i,fileGitStatusMap:c,onContentSearch:d,locateInTree:u,jsonPreview:m,setJsonPreview:h,jsonPreviewSearch:x,jsonPreviewPreRef:f}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)("file"),[j,y]=(0,s.useState)("compact"),w=t.file.path,k=(0,et.u)(w),{state:C}=eL(e,w),S=(0,s.useMemo)(()=>{if("ready"===C.state)return C.data.functions.filter(eI).map(e=>({name:e.name,startLine:e.startLine,endLine:e.endLine,params:e.params}))},[C]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[k||"map"!==b?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:w}),(0,n.jsx)(e$.m,{content:g("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${w}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(e$.m,{content:g("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(w)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${"staged"===t.type?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===t.type?g("fileBrowser.staged"):g("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"}),!k&&"file"===b&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["compact","full"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e)},className:`px-2 py-0.5 text-xs transition-colors ${j===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("compact"===e?"diffViewer.compact":"diffViewer.full")},e))}),!k&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-xs transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:k?(0,n.jsx)(td,{cwd:e,path:w,className:"p-4 flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:w}):(0,n.jsx)(N,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,compact:"compact"===j,symbols:S,onPreview:!r.isDeleted&&V(w)?()=>l(!0):!r.isDeleted&&w.endsWith(".json")?()=>h({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:w.endsWith(".json")?g("common.readable"):g("common.preview"),onContentSearch:d})})]}):(0,n.jsx)(ti,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:c,enableComments:!0,onContentSearch:d,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=c.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e$.m,{content:g("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(e$.m,{content:g("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),r&&(0,n.jsx)("span",{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 ${"staged"===r?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===r?g("fileBrowser.staged"):g("fileBrowser.unstaged")})]})},headerExtraRight:()=>(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})}),a&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>l(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ei,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>l(!1)})})}),m&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>h(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:m.filePath}),(0,n.jsx)("button",{onClick:()=>h(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(Q,{search:x}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:f,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:F(m.content)})})]})})]})}function tm({branches:e,selectedBranch:t,onSelect:r,isLoading:a,pinnedBranches:l=[]}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(""),h=(0,s.useRef)(null),x=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{h.current&&!h.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{c&&x.current&&x.current.focus()},[c]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=l.filter(e=>p.has(e)&&e.toLowerCase().includes(f)),b=new Set(g),v=e?.local.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],j=e?.remote.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],y=e=>{r(e),d(!1),m("")};return(0,n.jsxs)("div",{className:"relative",ref:h,children:[(0,n.jsxs)("button",{onClick:()=>d(!c),disabled:a,className:"w-full px-3 py-1.5 text-sm border border-border rounded bg-card text-foreground text-left flex items-center justify-between hover:border-slate-6 dark:hover:border-slate-6 transition-colors",children:[(0,n.jsxs)("span",{className:"truncate flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t||i("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",i("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-slate-9 transition-transform ${c?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lg max-h-80 flex flex-col",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:x,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:i("git.searchBranch"),className:"w-full px-2 py-1 text-sm border border-border rounded bg-secondary text-foreground placeholder-slate-9"})}),(0,n.jsxs)("div",{className:"overflow-y-auto flex-1",children:[g.length>0&&g.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},`pinned-${r}`)),v.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.localBranches")}),v.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},r))]}),j.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.remoteBranches")}),j.map(e=>(0,n.jsxs)("div",{onClick:()=>y(e),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${e===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:e}),e===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},e))]}),0===g.length&&0===v.length&&0===j.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("git.noMatchingBranches")})]})]})]})}function th(e){let t=e.split(".").pop()?.toLowerCase();return t?["ts","tsx","js","jsx","mjs","cjs"].includes(t)?"typescript":["py","pyi"].includes(t)?"python":null:null}function tx(e){return e.replace(/^\([^)]+\)\s*/,"")}let tf=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:a,container:l,onMouseEnter:i,onMouseLeave:c,onFindReferences:d,onSearch:u},m){let{t:h}=(0,o.Bd)(),x=(0,s.useRef)(null);(0,s.useImperativeHandle)(m,()=>x.current,[]);let f=l.getBoundingClientRect(),p=r-f.left,g=a-f.top,b=(0,s.useMemo)(()=>tx(e),[e]),v=(0,s.useMemo)(()=>(function(e){let t,r=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b/g,s=[],o=0,a=0,l=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b|"[^"]*"|'[^']*'|\b\d+\b/g;for(;null!==(t=l.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},a++));let l=t[0];/^["']/.test(l)?s.push((0,n.jsx)("span",{className:"text-green-400",children:l},a++)):/^\d+$/.test(l)?s.push((0,n.jsx)("span",{className:"text-orange-300",children:l},a++)):r.test(l)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-pink-400",children:l},a++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:l},a++)),o=t.index+l.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},a++)),s})(b),[b]);return(0,s.useEffect)(()=>{if(!x.current)return;let e=x.current,t=l.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=a-t.top;s+n.width>t.width-8&&(s=t.width-n.width-8),s<8&&(s=8),o+n.height>t.height-8&&(o=o-n.height-24),e.style.left=`${s}px`,e.style.top=`${o}px`},[r,a,l]),(0,n.jsxs)("div",{ref:x,className:"absolute z-[200] max-w-lg bg-card border border-border rounded-lg shadow-xl px-3 py-2 pointer-events-none",style:{left:p,top:g},children:[(0,n.jsx)("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all leading-relaxed",children:v}),t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground whitespace-pre-wrap",children:t})]}),(d||u)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1.5"}),(0,n.jsxs)("div",{className:"flex items-center gap-3 pointer-events-auto",onMouseEnter:i,onMouseLeave:c,children:[d&&(0,n.jsx)("button",{onClick:d,className:"text-[11px] text-brand hover:underline cursor-pointer",children:h("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(function(e){let t=tx(e),r=t.match(/^(?:function|const|let|var|class|interface|type|enum|async function)\s+([a-zA-Z_$][\w$]*)/);if(r)return r[1];let n=e.match(/\([^)]+\)\s+(?:[\w$]+\.)*([a-zA-Z_$][\w$]*)/);if(n)return n[1];let s=t.match(/([a-zA-Z_$][\w$]*)/);return s?s[1]:t.split(/[(\s:]/)[0]}(e)),className:"text-[11px] text-brand hover:underline cursor-pointer",children:h("hoverTooltip.search")})]})]})]})});function tp({references:e,loading:t,onSelect:r,onClose:a}){let{t:l}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)();if(t!==a.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let a=(0,b.sQ)(r.file);if("text"!==a)try{let e=n.codeToTokens(r.lineText,{lang:a,theme:s}),l=(0,b.b8)(e.tokens[0]||[]);l&&o.set(t,l)}catch{}}t===a.current&&r(o)})()},[e,n]),t}(e),c=[],d=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=d.get(r.file);void 0===n&&(n=c.length,d.set(r.file,n),c.push({file:r.file,items:[]})),c[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[l("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.notFound")}):c.map(({file:e,items:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e}),t.map(({ref:e,idx:t})=>(0,n.jsxs)("button",{onClick:()=>r(e),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:e.line}),i.has(t)?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:i.get(t)}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:e.lineText||""})]},`${e.line}-${e.column}-${t}`))]},e))})]})}function tg({results:e,loading:t,totalMatches:r,onSelect:a,onClose:l}){let{t:i}=(0,o.Bd)(),c=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)(),o=new Map;for(let t of e){let e=(0,b.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let a=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),l=(0,b.b8)(t.tokens[0]||[]);l&&o.set(a,l)}catch{}}}t===a.current&&r(o)})()},[e,n]),t}(e);return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[i("searchResults.title")," ",!t&&i("searchResults.nMatches",{count:r})]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:i("searchResults.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:i("searchResults.noResults")}):e.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e.path}),e.matches.map((t,r)=>{let s=`${e.path}:${t.lineNumber}`,o=c.get(s);return(0,n.jsxs)("button",{onClick:()=>a(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:t.lineNumber}),o?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:t.content||""})]},`${t.lineNumber}-${r}`)})]},e.path))})]})}let tb=["agent","explorer","console"],tv={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},tj=(0,s.createContext)(null);function ty(){let e=(0,s.useContext)(tj);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function tw({activeView:e,onViewChange:t,children:r}){let o=(0,s.useRef)(null),a=(0,s.useRef)(!1),l=(0,s.useRef)(0),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(!1),m=tb.indexOf(e),h=tb.length-1;(0,s.useEffect)(()=>{l.current=0,queueMicrotask(()=>c(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){let r=e.target;if("IFRAME"===r.tagName||function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth>e.clientWidth)return!0;e=e.parentElement}return!1}(r))return;e.preventDefault(),e.stopPropagation(),a.current&&(a.current=!1);let n=window.innerWidth,s=l.current-6*e.deltaX;!(m>0)&&s>0&&(s=0),!(m<h)&&s<0&&(s=0),l.current=s=Math.max(-n,Math.min(n,s)),c(s),u(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{let e=l.current,r=.12*n;u(!1),a.current=!0;let s=m;e<-r&&m<h?s=m+1:e>r&&m>0&&(s=m-1),l.current=0,c(0),s!==m&&t(tb[s]),setTimeout(()=>{a.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[m,h,t]);let[x,f]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>f(!0))},[]);let p={activeView:e,onViewChange:t,dragOffset:(()=>{if(!x)return 0;let e=window.innerWidth;return e?i/e:0})(),isDragging:x&&d};return(0,n.jsx)(tj.Provider,{value:p,children:r})}function tk({children:e}){let t,r,{activeView:o,dragOffset:a,isDragging:l}=ty(),i=(0,s.useRef)(null),c=(0,s.useRef)(null),d=tb.indexOf(o),u=tb.length;return(0,s.useEffect)(()=>{let e=i.current;if(!e)return;let t=()=>{0!==e.scrollLeft&&(e.scrollLeft=0)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,n.jsx)("div",{ref:i,className:"flex-1 overflow-hidden relative",style:{overscrollBehaviorX:"none"},children:(0,n.jsx)("div",{ref:c,className:l?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*tb.length}%`,transform:(t=a/u*100,r=-(100/u*d)+(Number.isFinite(t)?t:0),`translateX(${r}%)`)},children:e})})}function tN(){let{activeView:e,onViewChange:t,dragOffset:r,isDragging:o}=ty(),a=(0,s.useRef)(null),l=(0,s.useRef)([]),[i,c]=(0,s.useState)({left:0,width:0}),d=tb.indexOf(e),u=()=>{if(!a.current||0===l.current.length)return{left:0,width:0};let e=a.current.getBoundingClientRect(),t=l.current.filter(Boolean);if(t.length!==tb.length)return{left:0,width:0};let n=Number.isFinite(r)?r:0,s=Math.max(0,Math.min(tb.length-1,d-n)),o=Math.floor(s),i=Math.ceil(s),c=s-o,u=t[o],m=t[i];if(!u||!m)return{left:0,width:0};let h=u.getBoundingClientRect(),x=m.getBoundingClientRect();return{left:h.left+(x.left-h.left)*c-e.left,width:h.width+(x.width-h.width)*c}};(0,s.useEffect)(()=>{queueMicrotask(()=>c(u()))},[d,r]),(0,s.useEffect)(()=>{let e=()=>{c(u())};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[d,r]);let m=Number.isFinite(r)?r:0,h=Math.round(Math.max(0,Math.min(tb.length-1,d-m)));return(0,n.jsxs)("div",{ref:a,className:"relative flex gap-4",children:[tb.map((e,r)=>(0,n.jsx)("button",{ref:e=>{l.current[r]=e},onClick:()=>t(e),className:`px-4 py-1 text-sm font-medium transition-colors ${h===r?"text-brand":"text-muted-foreground hover:text-foreground"}`,children:tv[e]},e)),(0,n.jsx)("div",{className:`absolute bottom-0 h-0.5 bg-brand ${o?"":"transition-all duration-100 ease-out"}`,style:{left:i.left,width:i.width}})]})}function tC({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:a,initialSearchQuery:c,searchQueryTrigger:d}){var u;let h,x,f,g,b,v,{t:j}=(0,o.Bd)(),{activeView:y}=ty(),[w,k]=(0,s.useState)(r),[C,S]=(0,s.useState)("code"),L=(0,s.useRef)(null),M=(0,s.useRef)(!1),[E,$]=(0,s.useState)(null),[D,O]=(0,s.useState)(null),[A,_]=(0,s.useState)(!1),W=(0,s.useRef)(1),q=(0,s.useRef)(null),[z,H]=(0,s.useState)(null),U=(0,s.useRef)(null),[K,X]=(0,s.useState)({isDirty:!1,isSaving:!1}),[G,er]=(0,s.useState)(!1),[en,es]=(0,s.useState)(!1),[eo,ea]=(0,s.useState)(null),el=(0,s.useRef)(null),ec=J(el),eh=(0,s.useRef)(null),ex=J(eh),ef=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);try{let r=await fetch("/api/lsp/definition",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:n,column:s})});return(await r.json()).definitions||[]}catch(e){return console.error("[useLSP] definition error:",e),[]}finally{r(!1)}},[e]),loading:t}}(t),ep=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),a=(0,s.useRef)(0),l=(0,s.useRef)(!1),i=(0,s.useRef)(null),c=(0,s.useRef)({x:0,y:0}),d=(0,s.useCallback)(e=>{i.current=e},[]);(0,s.useEffect)(()=>{let e=e=>{c.current.x=e.clientX,c.current.y=e.clientY};return document.addEventListener("mousemove",e),()=>document.removeEventListener("mousemove",e)},[]);let u=(0,s.useRef)(!1),m=(0,s.useRef)(null),h=(0,s.useCallback)(()=>{let e=i.current;e&&u.current&&(e.style.pointerEvents="none"),u.current=!1,m.current&&(i.current?.removeEventListener("mouseleave",m.current),m.current=null)},[]),x=(0,s.useCallback)(()=>{let e=i.current;if(!e||u.current)return;u.current=!0,l.current=!0,e.style.pointerEvents="auto";let t=()=>{l.current=!1,h(),a.current++,r(null)};m.current=t,e.addEventListener("mouseleave",t)},[h]),f=(0,s.useCallback)((t,s,l,i)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let c=++a.current;n.current=setTimeout(async()=>{try{let n=await fetch("/api/lsp/hover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:s,column:l})}),o=await n.json();if(c!==a.current)return;o.hover&&o.hover.displayString&&r({...o.hover,x:i.x,y:i.y,filePath:t,line:s,column:l})}catch{}},300)},[e]),p=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),a.current++,o.current=setTimeout(function(){if(l.current)return;let e=i.current;if(e){let t=e.getBoundingClientRect(),{x:r,y:n}=c.current;if(r>=t.left&&r<=t.right&&n>=t.top&&n<=t.bottom)return void x()}r(null)},150)},[x]),g=(0,s.useCallback)(()=>{l.current=!0,o.current&&clearTimeout(o.current)},[]),b=(0,s.useCallback)(()=>{l.current=!1,a.current++,r(null)},[]),v=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),l.current=!1,h(),a.current++,r(null)},[h]);return(0,s.useEffect)(()=>{t||h()},[t,h]),{hoverInfo:t,onTokenMouseEnter:f,onTokenMouseLeave:p,onCardMouseEnter:g,onCardMouseLeave:b,clearHover:v,setTooltipEl:d}}(t),eg=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)(!1);return{references:t,loading:n,visible:a,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),l(!0);try{let o=await fetch("/api/lsp/references",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:n,column:s})}),a=await o.json();r(a.references||[])}catch(e){console.error("[useLSP] references error:",e),r([])}finally{o(!1)}},[e]),closeReferences:(0,s.useCallback)(()=>{l(!1),r([])},[])}}(t),eb=(h=(0,s.useRef)([]),x=(0,s.useRef)([]),f=(0,s.useCallback)(e=>{h.current.push(e),h.current.length>50&&(h.current=h.current.slice(-50)),x.current=[]},[]),g=(0,s.useCallback)(e=>{if(0===h.current.length)return null;let t=h.current.pop();return x.current.push(e),x.current.length>50&&(x.current=x.current.slice(-50)),t},[]),b=(0,s.useCallback)(e=>{if(0===x.current.length)return null;let t=x.current.pop();return h.current.push(e),h.current.length>50&&(h.current=h.current.slice(-50)),t},[]),{push:f,goBack:g,goForward:b,canGoBack:(0,s.useCallback)(()=>h.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>x.current.length>0,[])}),ev=em(),ej=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[a,l]=(0,s.useState)(new Set),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(null),[x,f]=(0,s.useState)(new Set),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(""),[j,y]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(!1),[M,E]=(0,s.useState)(null),$=(0,s.useRef)(null),[T,R]=(0,s.useState)(!1),[P,I]=(0,s.useState)(null),[B,F]=(0,s.useState)("center"),[D,O]=(0,s.useState)(null),[A,_]=(0,s.useState)(null),[W,q]=(0,s.useState)(!1),[z,H]=(0,s.useState)([]),[U,V]=(0,s.useState)(!1),[K,J]=(0,s.useState)(null),[Q,Y]=(0,s.useState)(null),[X,G]=(0,s.useState)(!1),[Z,ee]=(0,s.useState)(!1),er=(0,s.useMemo)(()=>i.map(e=>e.path).filter(Boolean),[i]),en=(0,s.useMemo)(()=>(0,et.v3)(er),[er]),es=(0,s.useMemo)(()=>new Set((0,et.tW)(en)),[en]),eo=(0,s.useMemo)(()=>b?n?(0,et.KH)(n,b,j):(0,et.q3)(t,b,j):null,[t,n,b,j]);(0,s.useEffect)(()=>{if(!eo||0===eo.size)return void g(null);let e=new Set;if(n){let t=new Set(n);for(let r of eo)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&eo.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}g(e)},[eo,t,n]);let ea=p??x,el=(0,s.useRef)(null),ei=(0,s.useCallback)(t=>{el.current&&clearTimeout(el.current),el.current=setTimeout(async()=>{try{await fetch("/api/files/expanded",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,paths:Array.from(t)})})}catch(e){console.error("Error saving expanded paths:",e)}},500)},[e]),ec=(0,s.useCallback)(async()=>{C(!0),E(null);try{let t=await fetch(`/api/files/init?cwd=${encodeURIComponent(e)}`),n=await t.json();n.error?E(n.error):(r(n.files||[]),n.expandedPaths&&Array.isArray(n.expandedPaths)&&f(new Set(n.expandedPaths)))}catch(e){console.error("Error loading files:",e),E("Failed to load files")}finally{C(!1)}},[e]),ed=(0,s.useCallback)(async()=>{try{let t=await fetch(`/api/files/index?cwd=${encodeURIComponent(e)}`),r=await t.json();r.paths&&o(r.paths)}catch(e){console.error("Error loading file index:",e)}},[e]),eu=(0,s.useCallback)(async t=>{l(e=>new Set([...e,t]));try{let n=await fetch(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),s=await n.json();s.children&&r(e=>{if(!t){let t=new Map(e.map(e=>[e.path,e]));return s.children.map(e=>{let r=t.get(e.path);return r?.children&&e.isDirectory?{...e,children:r.children}:e})}let r=structuredClone(e),n=(0,et.MB)(r,t);return n&&(n.children=s.children),r})}catch(e){console.error("Error loading directory:",e)}finally{l(e=>{let r=new Set(e);return r.delete(t),r})}},[e]),em=(0,s.useRef)(a);em.current=a,(0,s.useEffect)(()=>{for(let e of p??x){let r=(0,et.MB)(t,e);r&&r.isDirectory&&!r.children&&!em.current.has(e)&&eu(e)}},[t,x,p,eu]);let eh=(0,s.useCallback)(async()=>{try{let t=await fetch(`/api/files/recent?cwd=${encodeURIComponent(e)}`),r=await t.json();c(r.files||[])}catch(e){console.error("Error loading recent files:",e)}},[e]),ex=(0,s.useCallback)(async t=>{c(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)});try{await fetch("/api/files/recent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,file:t})})}catch(e){console.error("Error adding to recent files:",e)}},[e]),ef=(0,s.useCallback)((t,r,n,s)=>{c(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),fetch("/api/files/recent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,file:t,scrollLine:r,cursorLine:n,cursorCol:s})}).catch(()=>{})},[e]),ep=(0,s.useCallback)(e=>i.find(t=>t.path===e),[i]),eg=(0,s.useCallback)(async t=>{let r=t||d;if(r){V(!0),J(null);try{let t=await fetch(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(r)}`),n=await t.json();n.error?J(n.error):H(n.blame||[])}catch(e){console.error("Error loading blame:",e),J("Failed to load blame info")}finally{V(!1)}}},[e,d]),eb=(0,s.useCallback)(async t=>{L(!0),h(null),q(!1),H([]),J(null),Y(null);try{let r=await fetch(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),n=await r.json();if(!r.ok)return void h({type:"error",message:n?.error||"Failed to stat file"});if(!n.exists)return void h({type:"error",message:"File not found"});if("dir"===n.kind)return void h({type:"error",message:"Path is a directory"});switch(n.category){case"image":h({type:"image",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}});break;case"binary":h({type:"binary",message:"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break;case"too-large":h({type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs});break;default:{let r=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"});if(409===r.status){let e=await r.json().catch(()=>({}));h({type:"binary",message:e?.error||"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break}if(!r.ok){let e=await r.json().catch(()=>({}));h({type:"error",message:e?.error||"Failed to load file"});break}let s=await r.json();h({type:"text",content:s.content,size:s.size,mtime:s.mtimeMs,...s.isSymlink?{isSymlink:!0,symlinkTarget:s.symlinkTarget}:{}})}}ex(t),eg(t)}catch(e){console.error("Error loading file content:",e),h({type:"error",message:"Failed to load file"})}finally{L(!1)}},[e,ex,eg]),ev=(0,s.useCallback)(()=>{W?q(!1):(q(!0),0===z.length&&eg())},[W,z.length,eg]),ej=(0,s.useCallback)((e,t)=>{if(!e)return;if(u(e),I(t??null),null==t){let t=i.find(t=>t.path===e);t?.scrollLine?(I(t.scrollLine),F("start"),O(t.cursorLine??null),_(t.cursorCol??null)):(F("center"),O(null),_(null))}else F("center"),O(null),_(null);eb(e);let r=e.split("/");if(r.length>1){let e=[];for(let t=1;t<r.length;t++)e.push(r.slice(0,t).join("/"));f(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&ei(r),n?r:t})}},[eb,ei,i]),ey=(0,s.useCallback)(e=>{if(p)g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!x.has(e);if(f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),ei(r),r}),r){let r=(0,et.MB)(t,e);r&&r.isDirectory&&!r.children&&eu(e)}}},[p,ei,x,t,eu]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:a,expandedPaths:x,setExpandedPaths:f,searchTreeExpandedPaths:p,setSearchTreeExpandedPaths:g,effectiveExpandedPaths:ea,searchQuery:b,setSearchQuery:v,searchExactMatch:j,setSearchDirExact:y,matchedPaths:eo,creatingItem:w,setCreatingItem:k,isLoadingFiles:N,fileError:M,searchInputRef:$,shouldScrollToSelected:T,setShouldScrollToSelected:R,targetLineNumber:P,setTargetLineNumber:I,targetScrollAlign:B,setTargetScrollAlign:F,initialCursorLine:D,initialCursorCol:A,setInitialCursorLine:O,setInitialCursorCol:_,selectedPath:d,setSelectedPath:u,fileContent:m,setFileContent:h,isLoadingContent:S,recentFiles:i,recentFilePaths:er,setRecentFiles:c,recentFilesTree:en,recentTreeDirPaths:es,showBlame:W,setShowBlame:q,blameLines:z,isLoadingBlame:U,blameError:K,blameSelectedCommit:Q,setBlameSelectedCommit:Y,showMarkdownPreview:X,setShowMarkdownPreview:G,showEditor:Z,setShowEditor:ee,saveExpandedPaths:ei,loadFiles:ec,loadFileIndex:ed,loadDirectory:eu,loadRecentFiles:eh,addToRecentFiles:ex,updateRecentFilePosition:ef,getRecentFilePosition:ep,loadFileContent:eb,loadBlame:eg,handleToggleBlame:ev,handleSelectFile:ej,handleToggle:ey}}({cwd:t});u=ej.selectedPath,v=(0,s.useRef)(null),(0,s.useEffect)(()=>{!u||u===v.current||th(u)&&(v.current=u,fetch("/api/lsp/warmup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,filePath:u})}).catch(()=>{}))},[t,u]);let ey=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,a]=(0,s.useState)([]),[l,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),[u,m]=(0,s.useState)(new Set),[h,x]=(0,s.useState)({caseSensitive:!1,wholeWord:!1,regex:!1,fileType:""}),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useCallback)(async r=>{let n=r.trim();if(!n){a([]),p(null);return}if(n.length<2)return void d(B.A.t("fileBrowser.searchMinChars"));i(!0),d(null);try{let n=new URLSearchParams({cwd:e,q:r,caseSensitive:String(h.caseSensitive),wholeWord:String(h.wholeWord),regex:String(h.regex),fileType:h.fileType}),s=await fetch(`/api/files/search?${n}`),o=await s.json();if(o.error)throw Error(o.error);a(o.results),p({totalFiles:o.totalFiles,totalMatches:o.totalMatches,truncated:o.truncated});let l=new Set(o.results.map(e=>e.path));m(l),o.results.length>0&&t?.()}catch(e){d(e instanceof Error?e.message:"Search failed"),a([])}finally{i(!1)}},[e,h,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:l,searchError:c,searchExpandedPaths:u,searchOptions:h,setSearchOptions:x,searchStats:f,contentSearchInputRef:g,performContentSearch:b,handleSearchToggle:(0,s.useCallback)(e=>{m(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>er(!0)}),ew=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[c,d]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(!1),[f,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)([]),[j,y]=(0,s.useState)([]),w=(0,s.useMemo)(()=>{let e=new Set([...P(b),...P(j)]);for(let t of f)e.delete(t);return e},[b,j,f]),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(0),L=(0,s.useCallback)(async()=>{a(!0),i(null);try{let t=`/api/git/status?cwd=${encodeURIComponent(e)}`,r=await fetch(t);if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to fetch git status")}let s=await r.json();n(s);let o=R(s.staged),a=R(s.unstaged);v(o),y(a)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{a(!1)}},[e]),M=(0,s.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),E=(0,s.useCallback)((e,r)=>{d({file:e,type:r}),t(e.path)},[t]),$=(0,s.useCallback)(async t=>{try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t]})})).ok)throw Error("Failed to stage file");await L(),(0,p.oR)(B.A.t("toast.staged"),"success")}catch(e){console.error("Error staging file:",e),(0,p.oR)(B.A.t("toast.stageFailed"),"error")}},[e,L]),T=(0,s.useCallback)(async t=>{try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t]})})).ok)throw Error("Failed to unstage file");await L(),(0,p.oR)(B.A.t("toast.unstaged"),"success")}catch(e){console.error("Error unstaging file:",e),(0,p.oR)(B.A.t("toast.unstageFailed"),"error")}},[e,L]),I=(0,s.useCallback)(async t=>{if(0!==t.length)try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t})})).ok)throw Error("Failed to stage files");await L(),(0,p.oR)(B.A.t("toast.stagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error staging files:",e),(0,p.oR)(B.A.t("toast.stageFailed"),"error")}},[e,L]),F=(0,s.useCallback)(async t=>{if(0!==t.length)try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t})})).ok)throw Error("Failed to unstage files");await L(),(0,p.oR)(B.A.t("toast.unstagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error unstaging files:",e),(0,p.oR)(B.A.t("toast.unstageFailed"),"error")}},[e,L]),D=(0,s.useCallback)(async t=>{if(0!==t.length)try{let r=t.filter(e=>"untracked"===e.status).map(e=>e.path),n=t.filter(e=>"untracked"!==e.status).map(e=>e.path);if(r.length>0&&!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r,isUntracked:!0})})).ok)throw Error("Failed to discard untracked files");if(n.length>0&&!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:n,isUntracked:!1})})).ok)throw Error("Failed to discard tracked files");await L(),(0,p.oR)(B.A.t("toast.discardedNFiles",{count:t.length}),"success")}catch(e){console.error("Error discarding files:",e),(0,p.oR)(B.A.t("toast.discardFailed"),"error")}},[e,L]),O=(0,s.useCallback)(async()=>{if(r?.unstaged.length)try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r.unstaged.map(e=>e.path)})})).ok)throw Error("Failed to stage all files");await L(),(0,p.oR)(B.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error staging all files:",e),(0,p.oR)(B.A.t("toast.stageFailed"),"error")}},[e,r,L]),A=(0,s.useCallback)(async()=>{if(r?.staged.length)try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r.staged.map(e=>e.path)})})).ok)throw Error("Failed to unstage all files");await L(),(0,p.oR)(B.A.t("toast.unstagedNFiles",{count:r.staged.length}),"success")}catch(e){console.error("Error unstaging all files:",e),(0,p.oR)(B.A.t("toast.unstageFailed"),"error")}},[e,r,L]),_=(0,s.useCallback)(async t=>{try{let r="untracked"===t.status;if(!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t.path],isUntracked:r})})).ok)throw Error("Failed to discard file");await L(),(0,p.oR)(r?B.A.t("toast.deletedFile"):B.A.t("toast.discardedChanges"),"success")}catch(e){console.error("Error discarding file:",e),(0,p.oR)(B.A.t("toast.discardFailed"),"error")}},[e,L]),W=(0,s.useCallback)(async()=>{if(r?.unstaged.length&&await (0,p.lJ)(B.A.t("git.discardAllConfirm",{count:r.unstaged.length}),{danger:!0}))try{let t=r.unstaged.filter(e=>"untracked"===e.status).map(e=>e.path),n=r.unstaged.filter(e=>"untracked"!==e.status).map(e=>e.path);n.length>0&&await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:n,isUntracked:!1})}),t.length>0&&await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t,isUntracked:!0})}),await L(),(0,p.oR)(B.A.t("toast.discardedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error discarding all:",e),(0,p.oR)(B.A.t("toast.discardFailed"),"error")}},[e,r,L]);return(0,s.useEffect)(()=>{c?(async()=>{x(!0);try{let t=new URLSearchParams({file:c.file.path,type:c.type});t.set("cwd",e);let r=await fetch(`/api/git/diff?${t}`);if(!r.ok)throw Error("Failed to fetch diff");let n=await r.json();m(n)}catch(e){console.error("Error fetching diff:",e)}finally{x(!1)}})():m(null)},[c,e,C]),{status:r,setStatus:n,statusLoading:o,statusError:l,statusSelectedFile:c,statusDiff:u,statusDiffLoading:h,statusExpandedPaths:w,stagedTree:b,setStagedTree:v,unstagedTree:j,setUnstagedTree:y,showStatusDiffPreview:k,setShowStatusDiffPreview:N,fetchStatus:L,handleStatusToggle:M,handleStatusFileSelect:E,handleStage:$,handleUnstage:T,handleStageFiles:I,handleUnstageFiles:F,handleDiscardFiles:D,handleStageAll:O,handleUnstageAll:A,handleDiscardFile:_,handleDiscardAll:W,refreshDiff:(0,s.useCallback)(()=>S(e=>e+1),[])}}({cwd:t,addToRecentFiles:ej.addToRecentFiles}),ek=(0,s.useMemo)(()=>{let e=new Set;if(ew.status){for(let t of ew.status.staged)e.add(t.path);for(let t of ew.status.unstaged)e.add(t.path)}return e},[ew.status]),eN=(0,s.useMemo)(()=>{let e=new Map;if(ew.status){for(let t of ew.status.staged)e.set(t.path,"staged");for(let t of ew.status.unstaged)e.set(t.path,"unstaged")}return e},[ew.status]),eC=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(""),[l,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(null),[u,m]=(0,s.useState)([]),[h,x]=(0,s.useState)([]),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)(!0),[E,$]=(0,s.useState)(!1),[T,I]=(0,s.useState)(!1),[F,D]=(0,s.useState)(null),O=(0,s.useRef)(null),[A,_]=(0,s.useState)(null),[W,q]=(0,s.useState)(!1),[z,H]=(0,s.useState)(""),[U,V]=(0,s.useState)(""),[K,J]=(0,s.useState)([]),[Q,Y]=(0,s.useState)([]),[X,G]=(0,s.useState)(new Set),[Z,ee]=(0,s.useState)(null),[er,en]=(0,s.useState)(null),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)(!1),ei=(0,s.useCallback)(()=>{w(!0),D(null),fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{e.error?(D("Failed to get branches"===e.error?B.A.t("git.notGitRepo"):e.error),n(null)):e.local&&e.current?(n(e),a(e.current),e.upstream&&H(e.upstream)):(D(B.A.t("git.cannotGetBranches")),n(null))}).catch(e=>{console.error(e),D(B.A.t("git.getBranchesFailed")),n(null)}).finally(()=>w(!1))},[e]),ec=(0,s.useCallback)(t=>{N(!0),d(null),m([]),x([]),b(null),j(null),M(!0),fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${et.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];i(t),M(t.length>=et.B_)}).catch(console.error).finally(()=>N(!1))},[e]),ed=(0,s.useCallback)(()=>{if(C||!L||!o)return;S(!0);let t=l.length;fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(o)}&limit=${et.B_}&offset=${t}`).then(e=>e.json()).then(e=>{let t=e.commits||[];t.length>0&&i(e=>[...e,...t]),M(t.length>=et.B_)}).catch(console.error).finally(()=>S(!1))},[e,o,l.length,C,L]),eu=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&ed()},[ed]),em=(0,s.useCallback)(t=>{d(t),b(null),j(null),$(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${t.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];m(t);let r=R(t);x(r),p(new Set(P(r)))}).catch(console.error).finally(()=>$(!1))},[e]),eh=(0,s.useCallback)(r=>{c&&(b(r),t(r.path),I(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${c.hash}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>I(!1)))},[e,c,t]),ex=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ef=(0,s.useCallback)(t=>{eo(!0),ee(null),en(null),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{let t=e.files||[];J(t);let r=R(t);Y(r),G(new Set(P(r)))}).catch(console.error).finally(()=>eo(!1))},[e]),ep=(0,s.useCallback)(r=>{ee(r),t(r.path),el(!0),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(U)}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>en(e)).catch(console.error).finally(()=>el(!1))},[e,U,t]),eg=(0,s.useCallback)(e=>{G(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eb=(0,s.useCallback)(e=>{if(q(e),e){let e="origin/main";V(e),ef(e)}else J([]),Y([]),ee(null),en(null),V("")},[z,ef]);return{branches:r,selectedBranch:o,setSelectedBranch:a,commits:l,setCommits:i,selectedCommit:c,setSelectedCommit:d,historyFiles:u,historyFileTree:h,historyExpandedPaths:f,historySelectedFile:g,historyFileDiff:v,isLoadingBranches:y,isLoadingCommits:k,isLoadingMore:C,hasMoreCommits:L,setHasMoreCommits:M,isLoadingHistoryFiles:E,isLoadingHistoryDiff:T,historyError:F,commitListRef:O,tooltipPos:A,loadBranches:ei,loadCommits:ec,loadMoreCommits:ed,handleCommitListScroll:eu,handleSelectCommit:em,handleSelectHistoryFile:eh,handleHistoryToggle:ex,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{_({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{_(null)},[]),compareMode:W,toggleCompareMode:eb,compareBaseBranch:U,setCompareBaseBranch:V,upstreamBranch:z,compareFiles:K,compareFileTree:Q,compareExpandedPaths:X,compareSelectedFile:Z,compareFileDiff:er,isLoadingCompareFiles:es,isLoadingCompareDiff:ea,handleSelectCompareFile:ep,handleCompareToggle:eg,loadCompareFiles:ef}}({cwd:t,addToRecentFiles:ej.addToRecentFiles}),eS=(0,s.useCallback)(e=>{ej.setFileContent(t=>t?.type==="text"?{...t,content:e}:t)},[ej]),eL=(0,s.useCallback)(e=>{ej.setShowEditor(!0)},[ej]),eM=(0,s.useCallback)(async()=>{if(ej.fileContent&&"text"===ej.fileContent.type&&ej.fileContent.content)try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:ej.selectedPath,content:ej.fileContent.content})});if(!e.ok)throw Error("Failed to save file");let r=await e.json();r.mtime&&ej.setFileContent(e=>e?.type==="text"?{...e,mtime:r.mtime}:e),(0,p.oR)(j("toast.savedSuccess"),"success")}catch{(0,p.oR)(j("toast.saveFailed"),"error")}},[t,ej]),eE=(0,s.useCallback)(()=>{if(!ej.selectedPath)return;let e=W.current,t=q.current;e>0&&ej.updateRecentFilePosition(ej.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[ej]),e$=(0,s.useCallback)((e,t)=>{e!==ej.selectedPath&&eE(),ej.handleSelectFile(e,t)},[ej,eE]),eT=(0,s.useMemo)(()=>{let e=ey.contentSearchResults;if(0===e.length)return{files:[],expandDirs:new Set,matchMap:new Map};let t=new Map,r=[];for(let n of e)t.set(n.path,n),r.push(n.path);let n=(0,et.v3)(r),s=new Set((0,et.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[ey.contentSearchResults]),[eR,eP]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{eP(eT.expandDirs)},[eT.expandDirs]);let eI=(0,s.useCallback)(e=>{eP(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eB=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=eT.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[eT.matchMap]),eF=G&&ey.contentSearchResults.length>0,eD=!!ej.selectedPath&&null!==th(ej.selectedPath),eO=(0,s.useCallback)(async(e,r)=>{if(!ej.selectedPath||!eD)return;let n=await ef.goToDefinition(ej.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",a=s.file.startsWith(o)?s.file.slice(o.length):s.file;eb.push({filePath:ej.selectedPath,lineNumber:W.current}),a===ej.selectedPath?ej.setTargetLineNumber(s.line):e$(a,s.line)},[ej,t,eD,ef,eb]),eA=(0,s.useCallback)((e,t,r)=>{ej.selectedPath&&eD&&ep.onTokenMouseEnter(ej.selectedPath,e,t,r)},[ej.selectedPath,eD,ep]),e_=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;ej.selectedPath&&eb.push({filePath:ej.selectedPath,lineNumber:W.current}),n===ej.selectedPath?ej.setTargetLineNumber(e.line):e$(n,e.line)},[ej,t,eb]),eW=(0,s.useMemo)(()=>{if(!ew.status)return null;let e=new Map,t=e=>{switch(e){case"modified":default:return"M";case"added":return"A";case"deleted":return"D";case"renamed":return"R";case"untracked":return"?"}};for(let r of ew.status.staged)e.set(r.path,t(r.status));for(let r of ew.status.unstaged)e.set(r.path,t(r.status));return e},[ew.status]);(0,s.useEffect)(()=>{$(L.current)},[]),(0,s.useEffect)(()=>{k(r)},[r,a]),(0,s.useEffect)(()=>{c&&(k("search"),ey.setContentSearchQuery(c),ey.performContentSearch(c))},[d]);let eq=(0,s.useCallback)(e=>{k(e),ej.setBlameSelectedCommit(null),"history"===e&&eC.selectedBranch&&eC.loadCommits(eC.selectedBranch)},[ej,eC.selectedBranch,eC.loadCommits]),ez=(0,s.useCallback)(()=>{if(!ej.selectedPath)return;let e={filePath:ej.selectedPath,lineNumber:W.current},t=eb.goBack(e);t&&(t.filePath===ej.selectedPath?ej.setTargetLineNumber(t.lineNumber):e$(t.filePath,t.lineNumber))},[ej,eb]),eH=(0,s.useCallback)(()=>{if(!ej.selectedPath)return;let e={filePath:ej.selectedPath,lineNumber:W.current},t=eb.goForward(e);t&&(t.filePath===ej.selectedPath?ej.setTargetLineNumber(t.lineNumber):e$(t.filePath,t.lineNumber))},[ej,eb]),eU=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;try{await fetch("/api/files/clipboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:e})}),(0,p.oR)(j("toast.copiedName",{name:r}),"success")}catch{(0,p.oR)(j("toast.copyFailed"),"error")}},[t]),eV=(0,s.useCallback)(async e=>{try{let r=await fetch("/api/files/clipboard"),n=await r.json();if(!n.path)return void(0,p.oR)(j("toast.noFileToPaste"),"info");let s=await fetch("/api/files/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,targetDir:e,sourceAbsPath:n.path})}),o=await s.json();s.ok?((0,p.oR)(j("toast.pastedFile",{name:o.newName}),"success"),ej.loadDirectory(e),ej.loadFileIndex()):(0,p.oR)(o.error||j("toast.pasteFailed"),"error")}catch{(0,p.oR)(j("toast.pasteFailed"),"error")}},[t,ej]),eK=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===y;if(r&&t.ctrlKey&&!t.metaKey&&"Minus"===t.code){t.preventDefault(),t.shiftKey?eH():ez();return}if(r&&(t.metaKey||t.ctrlKey)&&"p"===t.key){t.preventDefault(),_(e=>!e);return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===w||"recent"===w)&&ej.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),eU(ej.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===w||"recent"===w)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),eV((0,et.S7)(ej.selectedPath,ej.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(eo){t.preventDefault(),ex.open();return}if(en&&ej.selectedPath?.endsWith(".json")){t.preventDefault(),ec.open();return}}if(r&&"Escape"===t.key){if(A)return void _(!1);if(ex.isVisible)return void ex.close();if(ec.isVisible)return void ec.close();if(eo)return void ea(null);let t=Date.now();if(t-eK.current<3e3)return;eK.current=t,eg.visible?eg.closeReferences():G?er(!1):ej.blameSelectedCommit?ej.setBlameSelectedCommit(null):ej.showBlame?ej.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,ej.showBlame,ej.blameSelectedCommit,ej,A,eg.visible,eg.closeReferences,G,ez,eH,en,ec,eo,ex,w,eU,eV,y]),(0,s.useEffect)(()=>{ej.loadFiles(),ej.loadFileIndex(),ej.loadRecentFiles(),ew.fetchStatus(),eC.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{ew.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[ew.fetchStatus]);let eJ=(0,s.useRef)(ev);(0,s.useEffect)(()=>{ev&&!eJ.current&&(ej.loadFiles(),ej.loadFileIndex(),ej.loadRecentFiles(),ew.fetchStatus(),eC.loadBranches()),eJ.current=ev},[ev]),(0,s.useEffect)(()=>{eC.selectedBranch&&eC.loadCommits(eC.selectedBranch)},[eC.selectedBranch,eC.loadCommits]);let eQ=(0,s.useRef)(w);(0,s.useEffect)(()=>{let e=eQ.current;if(eQ.current=w,("tree"===w||"recent"===w)&&ej.recentFiles.length>0){let t=ej.recentFiles[0].path;ej.selectedPath&&("status"!==e&&"history"!==e||ej.selectedPath===t)||(ej.setShouldScrollToSelected(!0),e$(t))}},[w,ej.recentFiles,ej.selectedPath,e$,ej]);let eY=(0,s.useRef)(eC.selectedBranch);eY.current=eC.selectedBranch;let eX=(0,s.useRef)(ej.selectedPath);eX.current=ej.selectedPath;let eG=(0,s.useRef)(ej.fileContent?.type);eG.current=ej.fileContent?.type;let e0=(0,s.useCallback)(async e=>{try{let{data:r}=e;if(!r)return;let n=r.some(e=>"git"===e.type),s=r.some(e=>"file"===e.type),o=[];if((s||n)&&(o.push(fetch(`/api/files/init?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.error||ej.setFiles(e.files||[])})),o.push(fetch(`/api/files/index?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.paths&&ej.setFileIndex(e.paths)})),o.push(fetch(`/api/files/recent?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{ej.setRecentFiles(e.files||[])}))),n||s){o.push(fetch(`/api/git/status?cwd=${encodeURIComponent(t)}`).then(e=>{if(e.ok)return e.json().then(e=>{ew.setStatus(e);let t=R(e.staged),r=R(e.unstaged);ew.setStagedTree(t),ew.setUnstagedTree(r)})})),ew.refreshDiff(),n&&eC.loadBranches();let e=eY.current;e&&o.push(fetch(`/api/git/commits?cwd=${encodeURIComponent(t)}&branch=${encodeURIComponent(e)}&limit=${et.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];eC.setCommits(t),eC.setHasMoreCommits(t.length>=et.B_)}))}let a=eX.current,l=eG.current;a&&"text"===l&&o.push(fetch(`/api/files/text?cwd=${encodeURIComponent(t)}&path=${encodeURIComponent(a)}`).then(e=>e.ok?e.json():null).then(e=>{e&&"string"==typeof e.content&&ej.setFileContent({type:"text",content:e.content,size:e.size,mtime:e.mtimeMs,...e.isSymlink?{isSymlink:!0,symlinkTarget:e.symlinkTarget}:{}})})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,eu.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:e0,enabled:ev});let e1=(0,s.useCallback)(e=>{let t=e.split("/");if(t.length>1){let e=[];for(let r=1;r<t.length;r++)e.push(t.slice(0,r).join("/"));ej.setExpandedPaths(t=>{let r=new Set(t);for(let t of e)r.add(t);return ej.saveExpandedPaths(r),r})}ej.setSelectedPath(e),ej.setShouldScrollToSelected(!0),k("tree")},[ej]);return(0,n.jsxs)(m.SU,{container:E,children:[(0,n.jsxs)("div",{ref:L,className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsxs)("div",{className:"w-80 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex border-b border-border",children:[(0,n.jsx)("button",{onClick:()=>eq("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>eq("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>eq("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>eq("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>eq("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.historyTab")})]}),"tree"===w&&(0,n.jsxs)("div",{className:"p-2 border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:ej.searchInputRef,type:"text",value:ej.searchQuery,onChange:e=>ej.setSearchQuery(e.target.value),placeholder:j("fileBrowser.searchFiles"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),ej.searchQuery&&(0,n.jsx)("button",{onClick:()=>ej.setSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:j("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>ej.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${ej.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:ej.searchExactMatch?j("fileBrowser.exactMatchOn"):j("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>ej.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("fileBrowser.refreshTree"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:()=>ej.searchTreeExpandedPaths?ej.setSearchTreeExpandedPaths(new Set):ej.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("fileBrowser.collapseAll"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})]})]}),"search"===w&&(0,n.jsxs)("div",{className:"p-2 border-b border-border space-y-2",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:ey.contentSearchInputRef,type:"text",value:ey.contentSearchQuery,onChange:e=>ey.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ey.performContentSearch(ey.contentSearchQuery)},placeholder:j("fileBrowser.searchFileContent"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),ey.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>ey.setContentSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:j("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>ey.performContentSearch(ey.contentSearchQuery),disabled:ey.isSearching||!ey.contentSearchQuery.trim(),className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",children:ey.isSearching?"...":j("common.search")})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 text-xs",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ey.searchOptions.caseSensitive,onChange:e=>ey.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:j("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ey.searchOptions.wholeWord,onChange:e=>ey.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:j("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ey.searchOptions.regex,onChange:e=>ey.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:j("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:ey.searchOptions.fileType,onChange:e=>ey.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:j("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9"})]})]}),"history"===w&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:eC.compareMode?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-3 py-1.5 text-sm border border-border rounded bg-secondary text-foreground flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),(0,n.jsx)("span",{className:"truncate",children:eC.branches?.current||"HEAD"}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:"HEAD"})]}),(0,n.jsx)("button",{onClick:()=>eC.toggleCompareMode(!1),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors bg-brand text-white",title:j("fileBrowser.compareModeOff"),children:j("fileBrowser.compareMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0 pl-1",children:"vs"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(tm,{branches:eC.branches,selectedBranch:eC.compareBaseBranch,onSelect:e=>{eC.setCompareBaseBranch(e),eC.loadCompareFiles(e)},isLoading:eC.isLoadingBranches,pinnedBranches:["origin/main",...eC.upstreamBranch&&"origin/main"!==eC.upstreamBranch?[eC.upstreamBranch]:[]]})})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(tm,{branches:eC.branches,selectedBranch:eC.selectedBranch,onSelect:e=>{eC.setSelectedBranch(e)},isLoading:eC.isLoadingBranches,pinnedBranches:["origin/main",...eC.upstreamBranch&&"origin/main"!==eC.upstreamBranch?[eC.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>eC.toggleCompareMode(!0),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors text-muted-foreground hover:text-foreground hover:bg-accent border border-border",title:j("fileBrowser.compareModeOn"),children:j("fileBrowser.compareMode")})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,n.jsxs)("div",{className:`flex-1 flex flex-col min-h-0 ${"tree"===w?"":"hidden"}`,children:[ej.creatingItem&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b border-border bg-secondary flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:ej.creatingItem.parentPath?j("fileBrowser.createFileIn",{path:ej.creatingItem.parentPath}):j("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:j("fileBrowser.fileName"),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring",onCompositionStart:()=>{M.current=!0},onCompositionEnd:()=>{M.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(M.current)return;let r=e.target.value.trim();if(!r)return;let n=ej.creatingItem.parentPath,s=n?`${n}/${r}`:r;try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:s,content:""})});if(e.ok)(0,p.oR)(j("toast.createdFile",{name:r}),"success"),ej.setCreatingItem(null),ej.loadDirectory(n),ej.loadFileIndex(),n&&ej.setExpandedPaths(e=>new Set([...e,n])),e$(s);else{let t=await e.json();(0,p.oR)(t.error||j("toast.createFailed"),"error")}}catch(e){(0,p.oR)(j("toast.createFailed"),"error")}}else"Escape"===e.key&&ej.setCreatingItem(null)},onBlur:()=>ej.setCreatingItem(null)})]}),ej.isLoadingFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("common.loading")}):ej.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ej.fileError}):(0,n.jsx)(Z,{files:ej.files,selectedPath:ej.selectedPath,expandedPaths:ej.effectiveExpandedPaths,matchedPaths:ej.matchedPaths,gitStatusMap:eW,loadingDirs:ej.loadingDirs,onSelect:e=>{ej.setShouldScrollToSelected(!1),e$(e)},onToggle:ej.handleToggle,cwd:t,shouldScrollToSelected:ej.shouldScrollToSelected,onScrolledToSelected:()=>ej.setShouldScrollToSelected(!1),onCreateFile:e=>ej.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>O({path:e,isDirectory:t,name:r}),onRefresh:()=>ej.loadFiles(),onCopyFile:eU,onPaste:eV})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===w?"":"hidden"}`,children:ey.isSearching?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ey.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ey.searchError}):0===ey.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ey.contentSearchQuery?j("fileBrowser.noContentSearchResults"):j("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[ey.searchStats&&(0,n.jsxs)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-secondary border-b border-border flex-shrink-0",children:[j("fileBrowser.nFilesNMatches",{files:ey.searchStats.totalFiles,matches:ey.searchStats.totalMatches}),ey.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",j("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(Z,{files:eT.files,selectedPath:ej.selectedPath,expandedPaths:eR,onSelect:e=>{let t=eT.matchMap.get(e);e$(e,t?.matches[0]?.lineNumber),G||er(!0)},onToggle:eI,cwd:t,renderActions:eB,className:"flex-1 overflow-y-auto py-1 min-w-max"})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"recent"===w?"":"hidden"}`,children:0===ej.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.noRecentFiles")}):(0,n.jsx)(Z,{files:ej.recentFilesTree,selectedPath:ej.selectedPath,expandedPaths:ej.recentTreeDirPaths,onSelect:e$,onToggle:et.tE,cwd:t})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===w?"":"hidden"}`,children:ew.statusLoading?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ew.statusError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center p-4",children:(0,n.jsx)("span",{className:"text-red-11 text-sm",children:ew.statusError})}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:j("fileBrowser.stagingArea",{count:ew.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>ew.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("fileBrowser.refreshChanges"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),(ew.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:ew.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:j("fileBrowser.unstageAll")})]}),(0,n.jsx)(T,{files:ew.stagedTree,selectedPath:ew.statusSelectedFile?.type==="staged"?ew.statusSelectedFile.file.path:null,expandedPaths:ew.statusExpandedPaths,onSelect:e=>e.file&&ew.handleStatusFileSelect(e.file,"staged"),onToggle:ew.handleStatusToggle,cwd:t,emptyMessage:j("fileBrowser.noStagedFiles"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=I(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ew.handleUnstageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:j("fileBrowser.unstageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}return(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ew.handleUnstage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:j("fileBrowser.unstageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:j("fileBrowser.workspace",{count:ew.status?.unstaged.length||0})}),(ew.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:ew.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:j("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:ew.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:j("fileBrowser.stageAll")})]})]}),(0,n.jsx)(T,{files:ew.unstagedTree,selectedPath:ew.statusSelectedFile?.type==="unstaged"?ew.statusSelectedFile.file.path:null,expandedPaths:ew.statusExpandedPaths,onSelect:e=>e.file&&ew.handleStatusFileSelect(e.file,"unstaged"),onToggle:ew.handleStatusToggle,cwd:t,emptyMessage:j("fileBrowser.noUnstagedChanges"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=I(e);if(0===t.length)return null;let r=t.map(e=>e.file).filter(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ew.handleDiscardFiles(r)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:j("fileBrowser.discardNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ew.handleStageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:j("fileBrowser.stageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]})}return e.file?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ew.handleDiscardFile(e.file)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:j("fileBrowser.discardChanges"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ew.handleStage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:j("fileBrowser.stageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]}):null}})]})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"history"===w?"":"hidden"}`,children:eC.historyError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-muted-foreground",children:eC.historyError})]})}):eC.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:eC.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.loadingDiff")}):0===eC.compareFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.noDiffFiles")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:j("fileBrowser.nFilesChanged",{count:eC.compareFiles.length,branch:eC.compareBaseBranch})})}),(0,n.jsx)(T,{files:eC.compareFileTree,expandedPaths:eC.compareExpandedPaths,onToggle:eC.handleCompareToggle,selectedPath:eC.compareSelectedFile?.path||null,onSelect:e=>{e.file&&eC.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0})]})}):(0,n.jsx)("div",{ref:eC.commitListRef,className:"flex-1 overflow-y-auto",onScroll:eC.handleCommitListScroll,children:eC.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.loadingCommits")}):0===eC.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[eC.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>eC.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${eC.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-slate-9",title:e.date,children:[e.relativeDate," \xb7 ",(0,et.r6)(e.date)]})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.author})]},e.hash)),eC.isLoadingMore&&(0,n.jsx)("div",{className:"p-3 text-center",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),!eC.hasMoreCommits&&eC.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-slate-9",children:j("fileBrowser.allLoaded",{count:eC.commits.length})})]})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[("tree"===w||"search"===w||"recent"===w)&&(ej.blameSelectedCommit?(0,n.jsx)(Y,{isOpen:!0,onClose:()=>ej.setBlameSelectedCommit(null),commit:ej.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:ej.selectedPath||void 0,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):"map"===C?(0,n.jsx)(eZ,{cwd:t,highlightedFilePath:ej.selectedPath,changedFiles:ek,onSwitchToCode:()=>S("code"),enableComments:!0,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)},headerExtraLeft:({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,p.oR)(j("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),e1(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]})}):ej.selectedPath?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex-shrink-0 flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",children:ej.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${ej.selectedPath}`),(0,p.oR)(j("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),e1(ej.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:ej.showEditor?(0,n.jsxs)(n.Fragment,{children:[K.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:j("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>U.current?.save(),disabled:!K.isDirty||K.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${K.isDirty&&!K.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:K.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):j("common.save")}),(0,n.jsx)("button",{onClick:()=>U.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.closeEdit"),children:j("fileBrowser.closeBtn")})]}):(0,n.jsxs)(n.Fragment,{children:[ej.fileContent?.type==="text"&&ej.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(ej.fileContent.content),(0,p.oR)(j("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.copyFileContent"),children:j("common.copy")}),ej.selectedPath?.endsWith(".json")&&ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>es(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${en?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:j("fileBrowser.toggleJsonReadable"),children:j("common.readable")}),ej.fileContent?.type==="text"&&V(ej.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ej.setShowMarkdownPreview(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.previewMarkdown"),children:j("common.preview")}),ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:ej.handleToggleBlame,disabled:ej.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${ej.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-accent"} disabled:opacity-50`,title:j("fileBrowser.viewBlame"),children:ej.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>S("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("blockViewer.viewerToggle.toBlock"),children:j("common.codeMap")}),ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>ej.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.editFile"),children:j("common.edit")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:ej.isLoadingContent?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ej.fileContent?"text"===ej.fileContent.type&&"string"==typeof ej.fileContent.content?ej.showBlame&&ej.blameError?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-red-11",children:ej.blameError}),(0,n.jsx)("button",{onClick:()=>ej.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:j("fileBrowser.backToPreview")})]})}):ej.showBlame&&0===ej.blameLines.length&&ej.isLoadingBlame?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):en&&ej.selectedPath?.endsWith(".json")?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[#0d1117]",children:[(0,n.jsx)(Q,{search:ec}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:el,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:F(ej.fileContent.content)})})]}):(0,n.jsx)(ee.Cv,{ref:U,content:ej.fileContent.content,filePath:ej.selectedPath,cwd:t,enableComments:!0,scrollToLine:z??ej.targetLineNumber,scrollToLineAlign:null!=z?"start":ej.targetScrollAlign,onScrollToLineComplete:()=>{H(null),ej.setTargetLineNumber(null)},highlightKeyword:"search"===w?ey.contentSearchQuery:null,visibleLineRef:W,viStateRef:q,initialCursorLine:ej.initialCursorLine,initialCursorCol:ej.initialCursorCol,onInitialCursorSet:()=>{ej.setInitialCursorLine(null),ej.setInitialCursorCol(null)},onCmdClick:eD?eO:void 0,onTokenHover:eD?eA:void 0,onTokenHoverLeave:eD?ep.onTokenMouseLeave:void 0,onTokenHoverCancel:eD?ep.clearHover:void 0,blameLines:ej.showBlame&&ej.blameLines.length>0?ej.blameLines:void 0,inlineBlameLines:ej.blameLines.length>0?ej.blameLines:void 0,onSelectCommit:ej.setBlameSelectedCommit,editable:ej.showEditor,initialMtime:ej.fileContent.mtime,onEditorClose:e=>{ej.setShowEditor(!1),H(e)},onSaved:()=>{let e=W.current??1;ej.loadFileContent(ej.selectedPath),ej.setShowEditor(!1),H(e)},onEditorStateChange:X,viMode:!0,onContentMutate:eS,onEnterInsertMode:eL,onViSave:eM,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):"image"===ej.fileContent.type&&ej.selectedPath?(0,n.jsx)(td,{cwd:t,path:ej.selectedPath,refreshKey:ej.fileContent.mtime,alt:ej.selectedPath}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("p",{children:ej.fileContent.message||j("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:j("fileBrowser.selectFileToPreview")})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("p",{children:j("fileBrowser.selectFileToPreview")})]})})),"status"===w&&(ew.statusSelectedFile&&ew.statusDiff?(0,n.jsx)(tu,{cwd:t,selected:ew.statusSelectedFile,diff:ew.statusDiff,showMarkdownPreview:ew.showStatusDiffPreview,setShowMarkdownPreview:ew.setShowStatusDiffPreview,changedFiles:ek,fileGitStatusMap:eN,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)},locateInTree:e1,jsonPreview:eo,setJsonPreview:ea,jsonPreviewSearch:ex,jsonPreviewPreRef:eh}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:j("fileBrowser.selectFileToViewDiff")})})),"history"===w&&!eC.historyError&&(eC.compareMode?eC.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:j("fileBrowser.loadingDiffContent")}):eC.compareFileDiff?(0,n.jsx)(N,{oldContent:eC.compareFileDiff.oldContent,newContent:eC.compareFileDiff.newContent,filePath:eC.compareFileDiff.filePath,isNew:eC.compareFileDiff.isNew,isDeleted:eC.compareFileDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eC.compareFileDiff.isDeleted&&eC.compareFileDiff.filePath.endsWith(".json")?()=>ea({content:eC.compareFileDiff.newContent,filePath:eC.compareFileDiff.filePath}):void 0,previewLabel:j("common.readable"),onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:eC.compareFiles.length>0?j("fileBrowser.selectFileToViewDiff"):j("fileBrowser.clickCompareToLoad")})}):eC.selectedCommit?(0,n.jsx)(Y,{isOpen:!0,onClose:()=>eC.setSelectedCommit(null),commit:eC.selectedCommit,cwd:t,embedded:!0,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:j("fileBrowser.selectCommitToView")})}))]})]}),ej.showMarkdownPreview&&ej.fileContent?.type==="text"&&ej.selectedPath&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>ej.setShowMarkdownPreview(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ei,{content:ej.fileContent.content||"",filePath:ej.selectedPath,cwd:t,onClose:()=>ej.setShowMarkdownPreview(!1)})})}),A&&(0,n.jsx)(ed,{files:ej.files,fileIndex:ej.fileIndex,recentFiles:ej.recentFilePaths,onSelectFile:e=>{e$(e),ej.setShouldScrollToSelected(!0),k("tree")},onClose:()=>_(!1)}),(eF||eg.visible)&&(0,n.jsxs)("div",{className:`flex ${eg.visible&&eF?"":"flex-col"}`,children:[eF&&(0,n.jsx)("div",{className:eg.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(tg,{results:ey.contentSearchResults,loading:ey.isSearching,totalMatches:ey.searchStats?.totalMatches??0,onSelect:(e,t)=>{ej.selectedPath&&eb.push({filePath:ej.selectedPath,lineNumber:W.current}),e$(e,t)},onClose:()=>er(!1)})}),eg.visible&&(0,n.jsx)("div",{className:eF?"flex-1 min-w-0":"",children:(0,n.jsx)(tp,{references:eg.references,loading:eg.loading,onSelect:e_,onClose:eg.closeReferences})})]})]}),D&&(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50",onClick:()=>O(null),children:(0,n.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-xl p-4 max-w-sm w-full mx-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-2",children:j("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:j("fileBrowser.confirmDeleteMessage",{name:D.name}).split(/<\/?file>/g).map((e,t)=>1===t?(0,n.jsx)("span",{className:"font-mono text-foreground",children:e},t):e)}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>O(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-accent transition-colors",children:j("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=D;O(null);try{let n=await fetch("/api/files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:e})});if(n.ok){(0,p.oR)(j("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";ej.loadDirectory(t),ej.loadFileIndex(),ej.selectedPath===e&&e$("")}else{let e=await n.json();(0,p.oR)(e.error||j("toast.deleteFailed"),"error")}}catch{(0,p.oR)(j("toast.deleteFailed"),"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:j("common.delete")})]})]})})}),ep.hoverInfo&&E&&(0,l.createPortal)((0,n.jsx)(tf,{ref:ep.setTooltipEl,displayString:ep.hoverInfo.displayString,documentation:ep.hoverInfo.documentation,x:ep.hoverInfo.x,y:ep.hoverInfo.y,container:E,onMouseEnter:ep.onCardMouseEnter,onMouseLeave:ep.onCardMouseLeave,onFindReferences:()=>{let{filePath:e,line:t,column:r}=ep.hoverInfo;ep.clearHover(),eg.findReferences(e,t,r)},onSearch:e=>{ep.clearHover(),k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}),E)]})}function tS({isOpen:e,onClose:t,cwd:r}){let a,{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(null),[x,f]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,N]=(0,s.useState)(""),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)([]),[E,$]=(0,s.useState)(""),[T,R]=(0,s.useState)(!1),P=(0,s.useCallback)(async()=>{f(!0);try{let e=await fetch(`/api/git/worktree?cwd=${encodeURIComponent(r)}`);if(e.ok){let t=await e.json();c(t.worktrees),u(t.nextPath),h(t.nextRandomWord),t.gitUserName&&N(t.gitUserName)}}catch(e){console.error("Failed to load worktrees:",e),(0,p.oR)(l("toast.worktreeLoadFailed"),"error")}finally{f(!1)}},[r]),I=(0,s.useCallback)(e=>{let{local:t,remote:r}=e;return r.includes("origin/main")?"origin/main":r.includes("origin/master")?"origin/master":t.includes("main")?"main":t.includes("master")?"master":r.length>0?r[0]:t.length>0?t[0]:"main"},[]);(0,s.useEffect)(()=>{e&&(P(),j(null))},[e,P]);let B=async()=>{if(!d)return;let e="origin/main";try{let t=await fetch(`/api/git/branches?cwd=${encodeURIComponent(r)}`);if(t.ok){let r=await t.json();e=I(r)}}catch{}let t=m||function(){let e="bcdfghjklmnprstvwz",t=["a","e","i","o","u","ai","au","ea","ee","ia","io","oa","oo","ou","ui"],r="";for(let n=0;n<2;n++)r+=e[Math.floor(Math.random()*e.length)],r+=t[Math.floor(Math.random()*t.length)];return r}(),n=k?`${k}/${t}`:t;b(!0);try{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add",cwd:r,path:d,newBranch:n,baseBranch:e})});if(t.ok)(0,p.oR)(l("toast.worktreeCreateSuccess",{name:n}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||l("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(l("toast.worktreeCreateFailed"),"error")}finally{b(!1)}},F=async()=>{R(!0),$(""),S(!0);try{let e=await fetch(`/api/git/branches?cwd=${encodeURIComponent(r)}`);if(e.ok){let t=await e.json(),r=new Set(i.map(e=>e.branch).filter(Boolean)),n=[...t.local.filter(e=>!r.has(e)),...t.remote.filter(e=>!r.has(e)&&!t.local.includes(e.replace(/^origin\//,"")))];M(n)}}catch{(0,p.oR)(l("toast.loadBranchFailed"),"error")}finally{R(!1)}},D=async e=>{if(d){S(!1),b(!0);try{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add",cwd:r,path:d,branch:e})});if(t.ok)(0,p.oR)(l("toast.worktreeCreateSuccess",{name:e}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||l("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(l("toast.worktreeCreateFailed"),"error")}finally{b(!1)}}},O=async()=>{if(v){w(!0);try{let e=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"remove",cwd:r,path:v.path})});if(e.ok)(0,p.oR)(l("toast.worktreeDeleted"),"success"),j(null),P();else{let t=await e.json();(0,p.oR)(t.error||l("toast.worktreeDeleteFailed"),"error")}}catch(e){console.error("Failed to delete worktree:",e),(0,p.oR)(l("toast.worktreeDeleteFailed"),"error")}finally{w(!1)}}},A=async e=>{let t=e.isLocked?"unlock":"lock";try{let n=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,cwd:r,path:e.path})});if(n.ok)(0,p.oR)(e.isLocked?l("toast.worktreeUnlocked"):l("toast.worktreeLocked"),"success"),P();else{let e=await n.json();(0,p.oR)(e.error||l("toast.operationFailed"),"error")}}catch(e){console.error("Failed to toggle lock:",e),(0,p.oR)(l("toast.operationFailed"),"error")}};return e?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[480px] max-h-[80vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:"Git Worktrees"}),(0,n.jsx)("button",{onClick:t,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:l("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:x?(0,n.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):(0,n.jsx)("div",{className:"space-y-2",children:i.map(e=>{let s=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${s?"border-brand bg-brand/5":"border-border hover:bg-accent cursor-pointer"}`,onClick:()=>{e.path!==r&&(window.parent.postMessage({type:"OPEN_PROJECT",cwd:e.path},"*"),t())},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${s?"bg-brand":"bg-muted-foreground/30"}`}),(0,n.jsx)("span",{className:"font-medium text-foreground truncate",children:e.branch||(e.isDetached?"detached":"unknown")}),e.isLocked&&(0,n.jsx)("span",{className:"text-amber-11",title:l("git.worktree.locked"),children:"\uD83D\uDD12"}),s&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",l("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),A(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?l("git.worktree.unlock"):l("git.worktree.lock"),children:e.isLocked?(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"})}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),j(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",title:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})})]}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate pl-4",children:e.path}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),C&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-3 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)("input",{value:E,onChange:e=>$(e.target.value),placeholder:l("git.worktree.searchBranch"),className:"flex-1 bg-secondary text-sm text-foreground rounded px-2.5 py-1.5 outline-none placeholder:text-muted-foreground",autoFocus:!0,autoComplete:"off",spellCheck:"false"}),(0,n.jsx)("button",{onClick:()=>S(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:l("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:T?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("common.loading")}):0===(a=L.filter(e=>e.toLowerCase().includes(E.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("git.worktree.noBranches")}):a.map(e=>(0,n.jsx)("button",{onClick:()=>D(e),className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate",children:(0,n.jsx)("span",{className:`${e.startsWith("origin/")?"text-muted-foreground":"text-foreground"}`,children:e})},e))})]}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:l("git.worktree.count",{count:i.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:F,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-secondary text-foreground hover:bg-accent":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:l("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:B,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:g?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):l("git.worktree.addWorktree")})]})]}),v&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-black/50 rounded-lg",onClick:()=>j(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[360px] p-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-3",children:l("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:l("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:l("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:v.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:l("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:v.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>j(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:O,disabled:y,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:y?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):l("common.delete")})]})]})})]})}):null}var tL=r(67635),tM=r(73300),tE=r(20986),t$=r(9921),tT=r(66088),tR=r(42790);function tP(e){let t=function(e){let t=0xffffffff;for(let r=0;r<e.length;r++){t^=e.charCodeAt(r);for(let e=0;e<8;e++)t=t>>>1^(1&t?0xedb88320:0)}return(0xffffffff^t)>>>0}(e),r="",n=t;for(let e=0;e<4;e++)r+=String.fromCharCode(97+n%26),n=Math.floor(n/26);return r}let tI=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:a}){let{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)(async n=>{if(n.stopPropagation(),i)await a(),c(!1),(0,p.oR)(l("toast.disconnected",{id:e}));else{await r(),c(!0);let n=`${"3456"===window.location.port?"cock-dev":"cock"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,p.oR)(l("toast.copiedCommand",{command:n}))}},[i,e,t,r,a,l]);return(0,n.jsxs)("button",{onClick:d,className:"inline-flex items-center gap-1 text-[10px] font-mono leading-none px-1.5 py-0.5 rounded flex-shrink-0 transition-colors bg-muted/60 hover:bg-muted text-muted-foreground",title:i?l("shortIdBadge.clickToDisconnect"):l("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${i?"bg-green-500":"bg-muted-foreground/40"}`}),e]})});var tB=r(72588);let tF=(0,s.lazy)(()=>Promise.all([r.e(3888),r.e(700)]).then(r.bind(r,80700)).then(e=>({default:e.XtermRenderer}))),tD={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},tO=/\x1b\[[0-9;]*m/g;function tA({output:e,query:t,mode:r,currentIdx:o,matchListRef:a}){let l=(0,s.useRef)(null);l.current||(l.current=new tR.v,l.current.use_classes=!0);let i=e.split("\n"),c=t.toLowerCase(),d=0;return a.current=[],(0,n.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap break-words select-text",children:i.map((e,t)=>{let s=e.replace(tO,""),i=s.toLowerCase().includes(c);if("filter"===r&&!i)return null;if(!i){let r=l.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],m=0,h=s.toLowerCase(),x=0;for(;x<h.length;){let e=h.indexOf(c,x);if(-1===e)break;e>m&&u.push((0,n.jsx)("span",{children:s.slice(m,e)},`t${m}`));let t=d++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{a.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+c.length)},`m${e}`)),x=m=e+c.length}return m<s.length&&u.push((0,n.jsx)("span",{children:s.slice(m)},`t${m}`)),(0,n.jsx)("div",{children:u},t)})})}let t_=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:a,output:l,exitCode:i,isRunning:c,selected:d,onSelect:u,onInterrupt:m,onStdin:h,onDelete:x,onRerun:f,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,onPtyResize:y,onToggleMaximize:w,maximized:k,expandedHeight:N,bubbleContentHeight:C,onTitleMouseDown:S}){let{t:L}=(0,o.Bd)(),M=(0,s.useRef)(null),E=(0,s.useRef)(null),$=(0,s.useRef)(!0),T=(0,s.useRef)(null),R=(0,s.useRef)(null),P=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(g),I=e&&t?tP(t+e):void 0,[B,F]=(0,s.useState)(!1),[D,O]=(0,s.useState)(""),A=(0,s.useRef)(null),_=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>A.current?v(e,A.current.write):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[v,e]),(0,s.useEffect)(()=>{if(!j||!e)return;let t=()=>A.current?j(e,A.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]);let[W,q]=(0,s.useState)(!1),[z,H]=(0,s.useState)(""),[U,V]=(0,s.useState)("search"),[K,J]=(0,s.useState)(0),Q=(0,s.useRef)([]),Y=(0,s.useRef)(null),X=(0,s.useRef)(0);(0,s.useEffect)(()=>{Y.current||(Y.current=new tR.v,Y.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=E.current;if(e&&Y.current){if(l.length<X.current&&(Y.current=new tR.v,Y.current.use_classes=!0,X.current=0,e.innerHTML=""),l.length>X.current){let t=l.slice(X.current),r=Y.current.ansi_to_html(t);X.current=l.length,e.insertAdjacentHTML("beforeend",r)}if(M.current){let e=M.current.scrollHeight>M.current.clientHeight;F(e),e&&(M.current.scrollTop=M.current.scrollHeight)}}},[l]),(0,s.useEffect)(()=>(c&&$.current&&M.current&&(null!==T.current&&cancelAnimationFrame(T.current),T.current=requestAnimationFrame(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight),T.current=null})),()=>{null!==T.current&&cancelAnimationFrame(T.current)}),[l,c]),(0,s.useEffect)(()=>{if(!k)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),w?.())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[k,w]);let G=l?l.split("\n").length:0,Z=(0,s.useCallback)(()=>{q(!0),requestAnimationFrame(()=>_.current?.focus())},[]),ee=(0,s.useCallback)(()=>{q(!1),H(""),J(0),A.current?.clearSearch()},[]),et=(0,s.useCallback)(e=>{e.trim()&&(b?A.current?.findNext(e):J(e=>{let t=e+1,r=Q.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(Q.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[b]),er=(0,s.useCallback)(e=>{e.trim()&&(b?A.current?.findPrevious(e):J(e=>{let t=e-1;if(t>=0)return Q.current[t]?.scrollIntoView({block:"nearest"}),t;let r=Q.current.length-1;return r>=0&&Q.current[r]?.scrollIntoView({block:"nearest"}),Math.max(r,0)}))},[b]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),Z();return}if("Escape"===e.key&&W){e.preventDefault(),e.stopPropagation(),ee();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,W,Z,ee]);let en=k&&N?N-41:C??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground dark:text-slate-11 relative overflow-hidden border transition-colors cursor-pointer ${k?"rounded-none border-0":"rounded-2xl rounded-bl-md rounded-br-md"} ${k?"":d?"border-brand":"border-brand/30"}`,onClick:u,children:[k?(0,n.jsxs)("div",{onDoubleClick:()=>w?.(),className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41,flexShrink:0},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded bg-muted text-muted-foreground",children:">_"}),(0,n.jsx)("span",{className:"flex-1 text-xs text-muted-foreground truncate font-mono",children:a}),c&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse"}),L("console.runningText")]}),c&&m&&(0,n.jsx)("button",{onClick:m,className:"text-xs px-3 py-1 rounded-md font-medium bg-destructive text-destructive-foreground transition-all duration-150 hover:bg-destructive/80 hover:shadow-md active:scale-95 active:bg-destructive/70 cursor-pointer select-none",children:"Ctrl+C"}),(0,n.jsx)("button",{onClick:()=>w?.(),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.restoreTooltip",{modKey:(0,tB.Mu)()}),children:(0,n.jsx)(ex.A,{className:"w-4 h-4"})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>S?.(),onDoubleClick:e=>{e.stopPropagation(),w?.()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing ${d?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:">_"}),I&&e&&t&&(0,n.jsx)(tI,{shortId:I,type:"terminal",onRegister:()=>{fetch("/api/terminal/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tabId:t,commandId:e,command:a,projectCwd:r})}).catch(()=>{})},onUnregister:()=>{fetch("/api/terminal/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandId:e})}).catch(()=>{})}}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:a}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(a),(0,p.oR)(L("toast.copiedCmd"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyCommand"),children:(0,n.jsx)(tL.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),B&&!c&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:L("console.totalLines",{count:G})}),l&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=l.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,p.oR)(L("toast.copiedOutput"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyOutput"),children:(0,n.jsx)(tM.A,{className:"w-3.5 h-3.5"})}),f&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),f()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.rerun"),children:(0,n.jsx)(tE.A,{className:"w-3.5 h-3.5"})}),x&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:L("console.deleteRecord"),children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),W&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card",style:{flexShrink:0},children:[(0,n.jsx)(eh.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:_,value:z,onChange:e=>{let t=e.target.value;H(t),J(0),b&&(t.trim()?A.current?.findNext(t):A.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?er(z):et(z))},placeholder:L("console.searchPlaceholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}),!b&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>V("search"),className:`px-1.5 py-0.5 rounded transition-colors ${"search"===U?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:L("console.searchMode")}),(0,n.jsx)("button",{onClick:()=>V("filter"),className:`px-1.5 py-0.5 rounded transition-colors ${"filter"===U?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:L("console.filterMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>er(z),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.prevShiftEnter"),children:(0,n.jsx)(t$.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>et(z),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.nextEnter"),children:(0,n.jsx)(tT.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:ee,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),b?(0,n.jsx)("div",{style:{height:en,overflow:"hidden"},children:(0,n.jsx)(s.Suspense,{fallback:(0,n.jsx)("div",{className:"px-4 py-2 text-xs text-muted-foreground",style:{height:en},children:L("console.loadingTerminal")}),children:(0,n.jsx)(tF,{ref:A,output:l,isRunning:c,onInput:h,onResize:y,maximized:k,height:en,directWrite:!!v})})}):(0,n.jsx)("div",{ref:M,className:"overflow-auto px-4 py-2",style:{height:en},onScroll:()=>{if(M.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=M.current;$.current=t-e-r<50}},children:W&&z.trim()?(0,n.jsx)(tA,{output:l,query:z,mode:U,currentIdx:K,matchListRef:Q}):(0,n.jsx)("pre",{ref:E,className:"text-sm font-mono whitespace-pre-wrap break-words select-text"})}),c&&!k&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse flex-shrink-0"}),b?(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-1",children:L("console.clickToInput")}):h?(0,n.jsx)("input",{ref:R,value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=tD[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),h(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),h(D+"\n"),O("")),"Tab"===e.key&&(e.preventDefault(),h(" "))},placeholder:L("console.stdinPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-xs font-mono text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}):(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:L("console.runningText")}),m&&(0,n.jsx)("button",{onClick:m,className:"flex-shrink-0 text-xs text-destructive hover:brightness-125 transition-colors cursor-pointer select-none",children:"Ctrl+C"}),P&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:P})]}),!c&&void 0!==i&&!k&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${0===i?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:L("console.exitCode",{code:i})}),(0,n.jsx)("span",{className:"flex-1"}),P&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:P})]})]})})});var tW=r(68459),tq=r(51914);function tz({cwd:e,tabId:t,onClose:r,onSave:a}){let{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)({}),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(""),[x,f]=(0,s.useState)(!0),p=(0,s.useCallback)(async()=>{f(!0);try{let r=new URLSearchParams({cwd:e});t&&r.set("tabId",t);let n=await fetch(`/api/terminal/env?${r}`);if(n.ok){let e=await n.json();c(e.env||{})}}catch(e){console.error("Failed to load env:",e)}finally{f(!1)}},[e,t]);(0,s.useEffect)(()=>{p()},[p]);let g=()=>{d.trim()&&(c(e=>({...e,[d.trim()]:m})),u(""),h(""))},b=async()=>{try{(await fetch("/api/terminal/env",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:t,env:i})})).ok&&(a(i),r())}catch(e){console.error("Failed to save env:",e)}};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-lg font-semibold",children:l("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?l("envManager.tabScope"):l("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(ex.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:x?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:l("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(i).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"flex-1 px-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void c(t=>({...t,[e]:r}))},placeholder:l("envManager.valuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>{c(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors",children:(0,n.jsx)(tW.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:l("envManager.varNamePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>h(e.target.value),placeholder:l("envManager.varValuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("button",{onClick:g,disabled:!d.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(tq.A,{className:"w-4 h-4"})})]}),0===Object.keys(i).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:l("envManager.noVars")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:b,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:l("common.save")})]})]})})}var tH=r(10762);function tU({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)({}),[i,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(!0),x=(0,s.useCallback)(async()=>{h(!0);try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();l(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}finally{h(!1)}},[]);(0,s.useEffect)(()=>{x()},[x]);let f=()=>{i.trim()&&d.trim()&&(l(e=>({...e,[i.trim()]:d.trim()})),c(""),u(""))},p=async()=>{try{(await fetch("/api/terminal/aliases",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({aliases:a})})).ok&&(t(a),e())}catch(e){console.error("Failed to save aliases:",e)}};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[(0,n.jsx)(tH.A,{className:"w-5 h-5"}),r("aliasManager.title")]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:r("aliasManager.description")})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(ex.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:r("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(a).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2 group",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"})]}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void l(t=>({...t,[e]:r}))},placeholder:r("aliasManager.fullCommandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"})]}),(0,n.jsx)("button",{onClick:()=>{l(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors opacity-0 group-hover:opacity-100",children:(0,n.jsx)(tW.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:r("aliasManager.aliasPlaceholder"),className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),f())}})]}),(0,n.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:r("aliasManager.commandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),f())}})]}),(0,n.jsx)("button",{onClick:f,disabled:!i.trim()||!d.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(tq.A,{className:"w-4 h-4"})})]}),(0,n.jsxs)("div",{className:"mt-4 p-3 bg-accent rounded-lg",children:[(0,n.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(0,n.jsx)("strong",{children:r("aliasManager.usage")}),r("aliasManager.usageDesc")]}),(0,n.jsxs)("div",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ ll"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"ls -la"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ gs"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"git status"})]})]})]}),0===Object.keys(a).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:r("aliasManager.noAliases")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:e,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:p,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:r("common.save")})]})]})})}var tV=r(53961),tK=r(15813),tJ=r(37595),tQ=r(49698),tY=r(20232);let tX=null,tG="",tZ=0,t0=null,t1=!1,t2=new Map,t5=null,t4=null;function t3(e){let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ping"===r)return;if("running"===r){t5&&(t5(t.commands),t5=null);return}let n=t.commandId;if(!n)return;let s=t2.get(n);if(s){if("error"===r)s.onError(t.error);else{let{commandId:e,type:n,...o}=t;s.onData(r,o)}("exit"===r||"error"===r)&&t2.delete(n)}}function t6(e){tX?.readyState===WebSocket.OPEN&&tX.send(JSON.stringify(e))}function t8(e){let t,r=(t="https:"===window.location.protocol?"wss:":"ws:",`${t}//${window.location.host}/ws/terminal?projectCwd=${encodeURIComponent(e)}`);tG===r&&tX||(ro(),t1=!1,tG=r,function e(){if(t1||!tG)return;let t=new WebSocket(tG);tX=t,t.onopen=()=>{for(let e of(tZ=0,t2.keys()))t.send(JSON.stringify({type:"attach",commandId:e}))},t.onmessage=t3,t.onclose=()=>{if(tX!==t||(tX=null,t1))return;t0&&clearTimeout(t0);let r=Math.min(1e3*Math.pow(1.5,tZ),1e4);tZ++,t0=setTimeout(e,r)},t.onerror=()=>{}}())}function t9(){return new Promise((e,t)=>{if(tX?.readyState===WebSocket.OPEN)return void e();let r=setInterval(()=>{tX?.readyState===WebSocket.OPEN&&(clearInterval(r),clearTimeout(n),e())},50),n=setTimeout(()=>{clearInterval(r),t(Error("WebSocket connection timeout"))},5e3)})}async function t7(e){let{cwd:t,command:r,commandId:n,tabId:s,projectCwd:o,env:a,usePty:l,cols:i,rows:c,onData:d,onError:u}=e;t8(o);try{await t9()}catch{u("WebSocket connection failed");return}t2.delete(n),t2.set(n,{onData:d,onError:u}),t6({type:"exec",commandId:n,command:r,cwd:t,tabId:s,env:a,...l?{usePty:!0}:{},...i?{cols:i,rows:c}:{}})}async function re(e){let{commandId:t,projectCwd:r,onData:n,onError:s}=e;t8(r);try{await t9()}catch{s("WebSocket connection failed");return}t2.set(t,{onData:n,onError:s}),t6({type:"attach",commandId:t})}function rt(e,t){t6({type:"stdin",commandId:e,data:t})}function rr(e,t,r){t6({type:"resize",commandId:e,cols:t,rows:r})}function rn(e){t6({type:"interrupt",pid:e})}async function rs(e){try{t8(e);try{await t9()}catch{return[]}return await new Promise(e=>{t5=t=>{e(t)},t6({type:"running"}),setTimeout(()=>{t5&&(t5=null,e([]))},3e3)})}finally{t4=null}}function ro(){if(t1=!0,t0&&(clearTimeout(t0),t0=null),tX){let e=tX;tX=null,e.close()}t2.clear(),t5&&(t5([]),t5=null),t4=null,tG="",tZ=0}let ra=new Map;function rl(e){ra.set(e.type,e)}function ri(e){return ra.get(e)}function rc(e){for(let t of ra.values())if(t.match(e))return t;return null}var rd=r(10611);function ru(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.set("_cockpit","1"),t.toString()}catch{let t=e.includes("?")?"&":"?";return`${e}${t}_cockpit=1`}}function rm(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.delete("_cockpit"),t.toString()}catch{return e.replace(/[?&]_cockpit=1/,"")}}async function rh(e){let t=(0,rd.f)()?.id??null;return!!t&&new Promise(r=>{try{let n=globalThis.chrome?.runtime;if(!n?.sendMessage)return void r(!1);let s=setTimeout(()=>r(!1),2e3);n.sendMessage(t,{type:"prepare-iframe",url:e},e=>{clearTimeout(s),r(e?.ok??!1)})}catch{r(!1)}})}function rx(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function rf({url:e,id:t,selected:r,maximized:a,expandedHeight:l,bubbleContentHeight:i,onSelect:c,onClose:d,onToggleMaximize:u,onNewTab:m,timestamp:h,onTitleMouseDown:x,initialSleeping:f,onSleep:g,onWake:b}){let{t:v}=(0,o.Bd)(),[j,y]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[N,C]=(0,s.useState)(e),[S,L]=(0,s.useState)(null),[M,E]=(0,s.useState)(f??!1),$=(0,s.useRef)(null),T=(0,s.useRef)(null),R=(0,s.useRef)(null);(0,s.useEffect)(()=>{C(e)},[e]);let P=(0,s.useRef)(!0),I=(0,s.useCallback)(()=>{M||(E(!0),L(null),g?.(t))},[M,t,g]),B=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null)},[]),{shortId:F,connected:D,connect:O,disconnect:A}=function(e,t,r){let n=(0,s.useMemo)(()=>tP(e),[e]),[o,a]=(0,s.useState)(!1),l=(0,s.useRef)(null),i=(0,s.useRef)([]),c=(0,s.useRef)(null),d=(0,s.useRef)(!1),u=(0,s.useRef)(r);(0,s.useEffect)(()=>{u.current=r});let m=(0,s.useRef)([]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="cockpit:cmd-result"){let{reqId:t,ok:r,data:n,error:s}=e.data,o=l.current;o&&o.readyState===WebSocket.OPEN&&o.send(JSON.stringify({type:"browser:cmd-result",reqId:t,ok:r,data:n,error:s}));return}if(e.data?.type==="cockpit:prepare-screenshot"){let r=t.current;if(!r?.contentWindow)return;let n=new URLSearchParams(window.location.search).get("cwd")||"";window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!0}})),window.parent.postMessage({type:"SCREENSHOT_PREPARE",cwd:n},"*"),requestAnimationFrame(()=>requestAnimationFrame(()=>requestAnimationFrame(()=>{setTimeout(()=>{let t=r.getBoundingClientRect(),n=window.devicePixelRatio||1,s=t.x,o=t.y;try{let e=window;for(;e!==e.top;){let t=e.frameElement;if(t){let e=t.getBoundingClientRect();s+=e.x,o+=e.y}e=e.parent}}catch{}r.contentWindow?.postMessage({type:"cockpit:screenshot-bounds",reqId:e.data.reqId,bounds:{x:Math.round(s*n),y:Math.round(o*n),width:Math.round(t.width*n),height:Math.round(t.height*n),dpr:n}},"*")},150)})));return}if(e.data?.type==="cockpit:screenshot-done"){window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!1}})),window.parent.postMessage({type:"SCREENSHOT_DONE"},"*");return}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let h=(0,s.useCallback)(e=>{let r=t.current;if(!r?.contentWindow){let t=l.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"browser:cmd-result",reqId:e.reqId,ok:!1,error:"iframe not available (page may be sleeping)"}));return}r.contentWindow.postMessage({type:"cockpit:cmd",reqId:e.reqId,action:e.action,params:e.params},"*")},[t]);(0,s.useEffect)(()=>{if(!o)return;let r=!1;return d.current=!0,!function n(){if(r||!d.current)return;let s="https:"===window.location.protocol?"wss:":"ws:",o=new WebSocket(`${s}//${window.location.host}/ws/browser?fullId=${encodeURIComponent(e)}`);l.current=o,o.onopen=()=>{for(let e of m.current)e();if(m.current=[],i.current.length>0){for(let e of i.current)h(e);i.current=[]}},o.onmessage=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("browser:cmd"===r.type){let e=r;t.current?.contentWindow&&u.current?h(e):i.current.push(e)}},o.onclose=()=>{l.current=null,!r&&d.current&&(c.current=setTimeout(n,3e3))},o.onerror=()=>o.close()}(),()=>{r=!0,d.current=!1,c.current&&clearTimeout(c.current),l.current&&(l.current.close(),l.current=null),m.current=[]}},[o,e,t,h]),(0,s.useEffect)(()=>{if(r&&i.current.length>0){for(let e of i.current)h(e);i.current=[]}},[r,h]);let x=(0,s.useCallback)(()=>o&&l.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{m.current.push(e),o||a(!0)}),[o]);return{shortId:n,connected:o,connect:x,disconnect:(0,s.useCallback)(()=>{a(!1)},[])}}(t,R,!!S&&!M&&!j),_=(0,s.useRef)(D);_.current=D,(0,s.useEffect)(()=>{let e=T.current;if(!e||M)return;let t=new IntersectionObserver(([e])=>{P.current=e.isIntersecting,e.isIntersecting||_.current?B():($.current&&clearTimeout($.current),$.current=setTimeout(I,3e5))});return t.observe(e),()=>t.disconnect()},[M,I,B]),(0,s.useEffect)(()=>{M?A():D?B():P.current||($.current&&clearTimeout($.current),$.current=setTimeout(I,3e5))},[D,M,A,B,I]),(0,s.useEffect)(()=>{f&&L(null)},[]);let W=(0,s.useCallback)(()=>{E(!1),b?.(t);let r=ru(e);rx(e)?L(r):rh(e).then(()=>L(r))},[e,t,b]);(0,s.useEffect)(()=>{if(!e||M){e||L(null);return}let t=ru(e);if(rx(e))return void L(t);let r=!1;return rh(e).then(()=>{r||L(t)}),()=>{r=!0}},[e,M]);let q=(0,s.useCallback)(()=>y(!1),[]);(0,s.useEffect)(()=>{let e=T.current;if(!e)return;let t=null,r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e){t=r;break}r=r.parentElement}if(!t)return;let n="",s=0,o=!1,a=()=>{o&&t&&(t.scrollTop=s)},l=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",a)},i=()=>{o=!1,t.removeEventListener("scroll",a),t.style.overflow=n};return e.addEventListener("mouseenter",l),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",l),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",a),o&&(t.style.overflow=n)}},[]),(0,s.useEffect)(()=>{let e=e=>{if(!e.data||"string"!=typeof e.data.type||!e.data.type.startsWith("cockpit:"))return;let r=T.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?m?.(rm(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&C(rm(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,m]);let z=(0,s.useCallback)(()=>{y(!1),k(v("browser.pageLoadFailed"))},[]),H=(0,s.useCallback)(()=>{if(M)return void W();let e=T.current?.querySelector("iframe");if(e&&S){y(!0),k(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[M,W,S]);(0,s.useEffect)(()=>{e&&!M&&(y(!0),k(null))},[e,M]);let U=(0,s.useCallback)(()=>{N&&window.open(N,"_blank")},[N]);(0,s.useEffect)(()=>{if(!r&&!a)return;let e=e=>{"Escape"===e.key&&a&&(e.stopPropagation(),u()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),u())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[a,r,u]);let V=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e}}(N),K=a&&l?l-41:i??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
|
|
2
|
-
relative transition-colors cursor-pointer
|
|
3
|
-
${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
|
|
4
|
-
${a?"":r?"border-brand":"border-brand/30"}`,onClick:a?void 0:c,children:[a?(0,n.jsxs)("div",{onDoubleClick:u,className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})}),F&&(0,n.jsx)(tI,{shortId:F,type:"browser",onRegister:()=>O(),onUnregister:async()=>{A(),await fetch("/api/browser/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:F})}).catch(()=>{})}}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate font-mono",children:N||v("browser.blankPage")}),N&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(N),(0,p.oR)(v("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("browser.copyUrl"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("span",{className:"flex-1"}),j&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),(0,n.jsx)("button",{onClick:H,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:U,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("browser.openInNewWindow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:u,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("browser.exitMaximize",{modKey:(0,tB.Mu)()}),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>x?.(),onDoubleClick:e=>{e.stopPropagation(),u()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing
|
|
5
|
-
${r?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-3 h-3 inline-block",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})}),F&&(0,n.jsx)(tI,{shortId:F,type:"browser",onRegister:()=>O(),onUnregister:async()=>{A(),await fetch("/api/browser/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:F})}).catch(()=>{})}}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:N||v("browser.blankPage")}),N&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(N),(0,p.oR)(v("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("browser.copyUrl"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("span",{className:"flex-1"}),j&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),U()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("browser.openInNewWindow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),H()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:v("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{ref:T,className:"w-full",style:{height:K},children:M?(0,n.jsxs)("div",{className:"relative overflow-hidden cursor-pointer group h-full",onClick:e=>{e.stopPropagation(),H()},children:[(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-muted/30",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-2 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground/60",children:V})]}),(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-black/60 text-white text-xs",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),v("browser.clickToWake")]})})]}):e?w?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center text-muted-foreground p-6 h-full",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-3 text-red-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-xs",children:w}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),H()},className:"mt-2 px-3 py-1 text-xs bg-secondary text-foreground rounded hover:bg-accent transition-colors",children:v("common.retry")})]}):(0,n.jsxs)("div",{className:"relative overflow-hidden h-full",style:{contain:"strict"},children:[j&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-white/80 dark:bg-slate-900/80 z-10",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),S?(0,n.jsx)("iframe",{ref:R,src:S,className:"border-0",allow:"clipboard-write; clipboard-read",style:a?{width:"100%",height:"100%"}:{position:"absolute",top:0,left:0,width:"200%",height:"200%",transform:"scale(0.5)",transformOrigin:"top left"},onLoad:q,onError:z,title:`Browser: ${V}`,"data-browser-id":t}):(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center text-muted-foreground h-full",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-2 text-slate-300 dark:text-slate-700",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})}),(0,n.jsx)("p",{className:"text-xs",children:v("browser.blankPage")})]})}),!a&&e&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${M?"bg-yellow-500":j?"bg-brand animate-pulse":w?"bg-red-500":"bg-green-500"}`}),(0,n.jsx)("span",{className:"truncate",children:M?v("browser.sleeping"):j?v("browser.loadingPage"):w?v("browser.loadFailed"):V}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(h)})]})]})})}rl({type:"browser",idPrefix:"browser",match(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")},parse:e=>({url:e.trim()}),fromHistory:e=>({url:e.url}),toHistory:e=>({url:e.url}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d,extra:u}){return(0,n.jsx)(rf,{id:e.id,url:e.url,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d,onNewTab:u?.addBrowserItem,initialSleeping:u?.initialSleeping,onSleep:u?.onSleep,onWake:u?.onWake})}});let rp=[{value:"=",label:"="},{value:"!=",label:"≠"},{value:">",label:">"},{value:"<",label:"<"},{value:">=",label:"≥"},{value:"<=",label:"≤"},{value:"LIKE",label:"LIKE"},{value:"NOT LIKE",label:"NOT LIKE"},{value:"IN",label:"IN"},{value:"IS NULL",label:"IS NULL"},{value:"IS NOT NULL",label:"IS NOT NULL"}];function rg(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}function rb(e){return`"${e.replace(/"/g,'""')}"`}function rv(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function rj({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),l=(0,s.useRef)(null),c=(0,s.useRef)(null),d=(0,s.useRef)(!1),u=(0,i.F2)(),m=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d.current||r(!1)},80)},[]),h=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),d.current=!1,c.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=u?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.width??window.innerWidth,c=n?.height??window.innerHeight,d=t.left-s,m=t.top-o,h=t.bottom-o,x=Math.min(600,i-d-8),f=m-8,p=c-h-8,g=f>p&&f>80;a({x:x<200?Math.max(8,i-600-8):d,y:g?m-4:h+4,maxW:x<200?Math.min(600,i-16):x,maxH:Math.max(60,g?f-4:p-4),above:g}),r(!0)},350)},[u]),x=(0,s.useCallback)(()=>{m()},[m]),f=(0,s.useCallback)(()=>{d.current=!0,c.current&&clearTimeout(c.current)},[]),p=(0,s.useCallback)(()=>{d.current=!1,m()},[m]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:h,onMouseLeave:x,children:[e,t&&(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lg whitespace-pre-wrap break-all select-text cursor-text",style:{left:o.x,top:o.y,maxWidth:o.maxW,maxHeight:o.maxH,transform:o.above?"translateY(-100%)":void 0},onMouseEnter:f,onMouseLeave:p,children:function(e){try{let t=JSON.parse(e);if("object"==typeof t&&null!==t)return JSON.stringify(t,null,2)}catch{}return e}(e)})})]})}async function ry(e,t){let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json();if(!r.ok)throw Error(n.error||`HTTP ${r.status}`);return n}async function rw(e,t){let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(s.error||`HTTP ${n.status}`);return s}function rk({id:e,connectionString:t,displayName:r,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:c,onSelect:d,onClose:u,onToggleMaximize:m,timestamp:h,onTitleMouseDown:x}){let{t:f}=(0,o.Bd)(),{showToast:g}=(0,p.dj)(),[b,v]=(0,s.useState)("connecting"),[j,y]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[N,C]=(0,s.useState)("public"),[S,L]=(0,s.useState)([]),[M,E]=(0,s.useState)(null),[$,T]=(0,s.useState)("table"),[R,P]=(0,s.useState)("data"),[I,B]=(0,s.useState)([]),[F,D]=(0,s.useState)([]),[O,A]=(0,s.useState)([]),[_,W]=(0,s.useState)([]),[q,z]=(0,s.useState)(null),[H,U]=(0,s.useState)(0),[V,K]=(0,s.useState)(!1),[J,Q]=(0,s.useState)(0),[Y,X]=(0,s.useState)(new Set),[G,Z]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)({}),[ei,ec]=(0,s.useState)({}),[ed,eu]=(0,s.useState)(null),[em,eh]=(0,s.useState)(""),[ex,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ey=(0,s.useCallback)(async()=>{v("connecting"),y("");try{let r=await ry("/api/db/connect",{id:e,connectionString:t});k(r.schemas||[]),r.schemas?.length>0&&!r.schemas.includes("public")&&C(r.schemas[0]),v("connected")}catch(e){y(e instanceof Error?e.message:String(e)),v("error")}},[e,t]);(0,s.useEffect)(()=>{ey()},[ey]);let ew=(0,s.useCallback)(async()=>{if("connected"===b)try{let r=await rw("/api/db/schemas",{id:e,connectionString:t,schema:N});L(r.tables||[])}catch{}},[e,t,N,b]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async(r,n,s,o)=>{K(!0);let a=s??ei,l=void 0!==o?o:ed;try{let s=`${rb(N)}.${rb(r)}`,{where:o,params:i}=function(e){let t=[],r=[],n=1;for(let[s,o]of Object.entries(e)){if(!o.enabled)continue;let e=rb(s);if("IS NULL"===o.op)t.push(`${e} IS NULL`);else if("IS NOT NULL"===o.op)t.push(`${e} IS NOT NULL`);else if("IN"===o.op){let s=o.value.split(",").map(e=>e.trim()).filter(Boolean);if(0===s.length)continue;let a=s.map(e=>(r.push(e),`$${n++}`));t.push(`${e}::text IN (${a.join(", ")})`)}else"LIKE"===o.op||o.op,t.push(`${e}::text ${o.op} $${n++}`),r.push(o.value)}return{where:t.length>0?` WHERE ${t.join(" AND ")}`:"",params:r}}(a),c=l?` ORDER BY ${rb(l.column)} ${l.dir}`:"",d=`SELECT * FROM ${s}${o}${c} LIMIT 50 OFFSET ${50*n}`,u=await ry("/api/db/query",{id:e,connectionString:t,sql:d,params:i});z(u);let m=`SELECT count(*)::int AS cnt FROM ${s}${o}`,h=await ry("/api/db/query",{id:e,connectionString:t,sql:m,params:i});Q(h.rows?.[0]?.cnt??0)}catch{}K(!1)},[e,t,N,ei,ed]),eN=(0,s.useCallback)(async r=>{E(r),U(0),et(null),eo(!1),X(new Set),Z(!1),ec({}),eu(null);try{let n=await rw("/api/db/columns",{id:e,connectionString:t,schema:N,table:r});B(n.columns||[]),D(n.primaryKeys||[]),A(n.foreignKeys||[]),W(n.indexes||[])}catch{}ek(r,0,{},null)},[e,t,N,ek]),eC=(0,s.useCallback)(async()=>{if(em.trim()){ev(!0),eg(""),ef(null);try{let r=await ry("/api/db/query",{id:e,connectionString:t,sql:em});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,em]),eS=(0,s.useCallback)(async()=>{if(null===ee||!q||!M)return;let r=q.rows[ee],n=[],s=[],o=1;for(let e of I)void 0!==er[e.name]&&er[e.name]!==rv(r[e.name]??"")&&(n.push(`${rb(e.name)} = $${o}`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]),o++);if(0===n.length)return void et(null);let a=F.length>0?F:I.map(e=>e.name),l=[];for(let e of a)null===r[e]||void 0===r[e]?l.push(`${rb(e)} IS NULL`):(l.push(`${rb(e)} = $${o}`),s.push(r[e]),o++);let i=`UPDATE ${rb(N)}.${rb(M)} SET ${n.join(", ")} WHERE ${l.join(" AND ")}`;try{await ry("/api/db/query",{id:e,connectionString:t,sql:i,params:s}),et(null),ek(M,H,ei,ed)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,q,M,I,F,er,e,t,N,ek,H,ei,ed]),eL=(0,s.useCallback)(async()=>{if(!M)return;let r=[],n=[],s=[],o=1;for(let e of I)void 0!==ea[e.name]&&""!==ea[e.name]&&(r.push(rb(e.name)),n.push(ea[e.name]),s.push(`$${o}`),o++);if(0===r.length)return;let a=`INSERT INTO ${rb(N)}.${rb(M)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await ry("/api/db/query",{id:e,connectionString:t,sql:a,params:n}),eo(!1),el({}),ek(M,H,ei,ed)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[M,I,ea,e,t,N,ek,H,ei,ed]),eM=(0,s.useCallback)(async()=>{if(0===Y.size||!q||!M)return;let r=F.length>0?F:I.map(e=>e.name),n=0;for(let s of Array.from(Y).sort((e,t)=>t-e)){let o=q.rows[s];if(!o)continue;let a=[],l=[],i=1;for(let e of r)null===o[e]||void 0===o[e]?a.push(`${rb(e)} IS NULL`):(a.push(`${rb(e)} = $${i}`),l.push(o[e]),i++);let c=`DELETE FROM ${rb(N)}.${rb(M)} WHERE ctid = (SELECT ctid FROM ${rb(N)}.${rb(M)} WHERE ${a.join(" AND ")} LIMIT 1)`;try{await ry("/api/db/query",{id:e,connectionString:t,sql:c,params:l})}catch{n++}}X(new Set),Z(!1),ek(M,H,ei,ed),n>0&&alert(f("database.deleteRowsFailed",{count:n}))},[Y,q,M,F,I,e,t,N,ek,H,ei,ed]),eE=(0,s.useCallback)(async r=>{if(!M)return;if(Y.size>0&&q){let e,t=q.fields.map(e=>e.name),n=Array.from(Y).sort((e,t)=>e-t).map(e=>q.rows[e]).filter(Boolean);if("json"===r)e=JSON.stringify(n,null,2);else{let r=[t.join(",")];for(let e of n)r.push(t.map(t=>{let r=e[t];if(null==r)return"";let n="object"==typeof r?JSON.stringify(r):String(r);return n.includes(",")||n.includes('"')||n.includes("\n")?`"${n.replace(/"/g,'""')}"`:n}).join(","));e=r.join("\n")}navigator.clipboard.writeText(e);return}let n=`SELECT * FROM ${rb(N)}.${rb(M)}`;try{let s=await fetch("/api/db/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,connectionString:t,sql:n,format:r})});if(!s.ok)throw Error("Export failed");let o=await s.blob(),a=URL.createObjectURL(o),l=document.createElement("a");l.href=a,l.download=`${M}.${r}`,l.click(),URL.revokeObjectURL(a)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[M,e,t,N,Y,q]),e$=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),eT=Math.max(1,Math.ceil(J/50)),eR=(0,s.useCallback)(e=>{M&&(U(e),ek(M,e,ei,ed))},[M,ek,ei,ed]),eP=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ec(r),U(0),X(new Set),M&&ek(M,0,r,ed)},[ei,ed,M,ek]),eI=(0,s.useCallback)(()=>{ec({}),U(0),X(new Set),M&&ek(M,0,{},ed)},[ed,M,ek]),eB=(0,s.useCallback)(e=>{eu(e),U(0),X(new Set),M&&ek(M,0,ei,e)},[ei,M,ek]);return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
|
|
6
|
-
relative transition-colors cursor-pointer
|
|
7
|
-
${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
|
|
8
|
-
${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:d,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:x,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDC18"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===b&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===b&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:f("database.connectionFailed")}),"connected"===b&&(0,n.jsx)("span",{className:"text-[10px] text-emerald-500 flex-shrink-0",children:f("database.connected")}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rg(h)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?f("browser.exitMaximize",{modKey:(0,tB.Mu)()}):f("browser.maximize",{modKey:(0,tB.Mu)()}),children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&i?i-41:c??360},className:"flex overflow-hidden",children:["connecting"===b&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),f("database.connecting")]}),"error"===b&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:j}),(0,n.jsx)("button",{onClick:ey,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:f("common.retry")})]}),"connected"===b&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[w.length>1?(0,n.jsx)("select",{value:N,onChange:e=>{C(e.target.value),E(null)},className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1",children:w.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}):(0,n.jsx)("span",{className:"flex-1 min-w-0 text-xs text-muted-foreground truncate",children:N}),(0,n.jsx)("button",{onClick:ew,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent active:bg-accent/50 transition-colors",title:f("database.refreshTableList"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsx)("div",{className:"flex items-center border-b border-border",children:["table","view"].map(e=>(0,n.jsx)("button",{onClick:()=>T(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${$===e?"text-brand border-b border-brand":"text-muted-foreground hover:text-foreground"}`,children:{table:f("database.filterTable"),view:f("database.filterView")}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[S.filter(e=>"table"===$?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>eN(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${M===e.name?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground",children:"view"===e.type?"V":"T"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:(0,n.jsx)(rj,{text:e.name})}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.rowEstimate>0?`~${e.rowEstimate}`:""})]},e.name)),0===S.length&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:f("database.noTables")})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["structure","data","sql"].map(e=>(0,n.jsx)("button",{onClick:()=>P(e),className:`px-3 py-1.5 text-xs transition-colors ${R===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{structure:f("database.tabStructure"),data:f("database.tabData"),sql:"SQL"}[e]},e)),M&&"data"===R&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[Object.values(ei).some(e=>e.enabled)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-brand",children:f("database.filterActive",{count:Object.values(ei).filter(e=>e.enabled).length})}),(0,n.jsx)("button",{onClick:eI,className:"px-1 py-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors",title:f("database.clearAllFilters"),children:"✕"}),(0,n.jsx)("span",{className:"text-border",children:"|"})]}),Y.size>0&&!G&&(0,n.jsx)("button",{onClick:()=>Z(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:f("database.deleteNRows",{count:Y.size})}),G&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-destructive",children:f("database.confirmDeleteRows")}),(0,n.jsx)("button",{onClick:eM,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:f("common.confirm")}),(0,n.jsx)("button",{onClick:()=>Z(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:f("common.cancel")})]}),(0,n.jsx)("button",{onClick:()=>eE("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Y.size>0?f("database.copyCsvSelected"):f("database.copyCsvAll"),children:Y.size>0?f("database.copyCSV"):f("database.CSV")}),(0,n.jsx)("button",{onClick:()=>eE("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Y.size>0?f("database.copyJsonSelected"):f("database.copyJsonAll"),children:Y.size>0?f("database.copyJSON"):f("database.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:M||"sql"===R?"structure"===R?(0,n.jsx)(rN,{columns:I,primaryKeys:F,foreignKeys:O,indexes:_}):"data"===R?(0,n.jsx)(rS,{result:q,loading:V,columns:I,page:H,totalPages:eT,totalRows:J,onPageChange:eR,filters:ei,sort:ed,onFilterChange:eP,onSortChange:eB,selectedRows:Y,onSelectedRowsChange:e=>{X(e),Z(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!q)return;let t=q.rows[e],r={};for(let e of I)r[e.name]=null==t[e.name]?"":rv(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:ea,onStartAdd:()=>{eo(!0),el({})},onNewRowChange:(e,t)=>el(r=>({...r,[e]:t})),onSaveNewRow:eL,onCancelAdd:()=>{eo(!1),el({})},onCellCopy:e=>{navigator.clipboard.writeText(e),g(f("common.copied"))}}):(0,n.jsx)(rL,{sqlInput:em,onSqlChange:eh,onExecute:eC,onKeyDown:e$,result:ex,error:ep,loading:eb,sqlRef:ej,onCellCopy:e=>{navigator.clipboard.writeText(e),g(f("common.copied"))}}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:f("database.selectTable")})})]})]})]}),!l&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===b?"bg-green-500":"error"===b?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:f("common.connecting"),connected:f("common.connected"),error:f("common.connectionFailed")}[b]}),"connected"===b&&M&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:M}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rg(h)})]})]})})}function rN({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:a}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:a("database.selectTableToView")}):(0,n.jsxs)("div",{className:"p-2 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("database.columns")}),(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"text-left text-muted-foreground border-b border-border",children:[(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colDefault")})]})}),(0,n.jsx)("tbody",{children:e.map(e=>(0,n.jsxs)("tr",{className:"border-b border-border/50 hover:bg-accent/50",children:[(0,n.jsxs)("td",{className:"px-1.5 py-1 font-mono",children:[e.isPrimaryKey&&(0,n.jsx)("span",{className:"text-amber-500 mr-1",title:a("database.primaryKey"),children:"\uD83D\uDD11"}),e.name]}),(0,n.jsxs)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono",children:[e.type,e.maxLength?`(${e.maxLength})`:""]}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground",children:e.nullable?"YES":"NO"}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono truncate max-w-[120px]",children:e.default||""})]},e.name))})]})]}),r.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("database.foreignKeys")}),(0,n.jsx)("div",{className:"space-y-0.5",children:r.map((e,t)=>(0,n.jsxs)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground",children:[e.column," → ",e.refSchema,".",e.refTable,".",e.refColumn]},t))})]}),s.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("database.indexes")}),(0,n.jsx)("div",{className:"space-y-0.5",children:s.map(e=>(0,n.jsx)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground truncate",title:e.definition,children:e.name},e.name))})]})]})}function rC({filter:e,onApply:t,onClear:r,onToggle:a,onClose:l,colName:c,anchorRect:d}){let{t:u}=(0,o.Bd)(),[m,h]=(0,s.useState)(e?.op||"="),[x,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null),g=(0,i.F2)();(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&l()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[l]);let b="IS NULL"!==m&&"IS NOT NULL"!==m,v=()=>{(!b||x.trim())&&t({op:m,value:x.trim(),enabled:!0})},j=g?.getBoundingClientRect(),y=j?.left??0,w=j?.top??0,k=j?.width??window.innerWidth,N=d.left-y;N+220>k-8&&(N=k-220-8),N<8&&(N=8);let C=d.bottom+2-w;return(0,n.jsx)(i.ZL,{children:(0,n.jsxs)("div",{ref:p,className:"fixed z-[9998] w-[220px] bg-popover border border-border rounded-md shadow-lg p-2 space-y-2",style:{left:N,top:C},onClick:e=>e.stopPropagation(),children:[e&&(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:e=>a(e.target.checked),className:"w-3 h-3 accent-brand"}),u("database.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:c})]}),(0,n.jsx)("select",{value:m,onChange:e=>h(e.target.value),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 focus:outline-none focus:ring-1 focus:ring-ring",children:rp.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),b&&(0,n.jsx)("input",{type:"text",value:x,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v())},placeholder:u("IN"===m?"database.commaValues":"LIKE"===m?"database.likePattern":"database.valuePlaceholder"),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:v,disabled:b&&!x.trim(),className:"flex-1 px-2 py-1 text-[10px] bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-40 transition-colors",children:u("database.apply")}),e&&(0,n.jsx)("button",{onClick:r,className:"flex-1 px-2 py-1 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground transition-colors",children:u("database.clearFilter")})]})]})})}function rS({result:e,loading:t,columns:r,page:a,totalPages:l,totalRows:i,onPageChange:c,filters:d,sort:u,onFilterChange:m,onSortChange:h,selectedRows:x,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:y,isAddingRow:w,newRowValues:k,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:L,onCellCopy:M}){let{t:E}=(0,o.Bd)(),[$,T]=(0,s.useState)(null),[R,P]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==$?(e.stopPropagation(),T(null)):null!==p?(e.stopPropagation(),y()):w&&(e.stopPropagation(),L()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[$,p,w,y,L]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:E("database.selectTableForData")});let I=e?.fields||[],B=e?.rows||[],F={};for(let e of r)F[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let D=B.length>0&&x.size===B.length,O=x.size>0&&!D;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",children:[t&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 flex items-center justify-center z-10",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[2]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-1 py-1 border-b border-border w-8 text-center",children:(0,n.jsx)("input",{type:"checkbox",checked:D,ref:e=>{e&&(e.indeterminate=O)},onChange:()=>{D?f(new Set):f(new Set(B.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(e=>{let t=u?.column===e.name?u.dir:null,r=d[e.name],s=r?.enabled;return(0,n.jsxs)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono relative",children:[(0,n.jsxs)("span",{className:"cursor-pointer select-none hover:text-foreground transition-colors",onClick:()=>{var t;return t=e.name,void(u?.column===t?"ASC"===u.dir?h({column:t,dir:"DESC"}):h(null):h({column:t,dir:"ASC"}))},children:[e.name,F[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:F[e.name]}),"ASC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↑"}),"DESC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↓"})]}),(0,n.jsx)("button",{onClick:t=>{if(t.stopPropagation(),$===e.name)return void T(null);let r=t.currentTarget.closest("th").getBoundingClientRect();P({left:r.left,bottom:r.bottom}),T(e.name)},className:`ml-1 inline-flex items-center transition-colors ${s?"text-brand":"text-muted-foreground/40 hover:text-muted-foreground"}`,children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 16 16",fill:"currentColor",children:(0,n.jsx)("path",{d:"M1 2h14l-5.5 6.5V14l-3-2v-3.5z"})})}),$===e.name&&(0,n.jsx)(rC,{filter:r||null,onApply:t=>{m(e.name,t),T(null)},onClear:()=>{m(e.name,null),T(null)},onToggle:t=>{r&&m(e.name,{...r,enabled:t})},onClose:()=>T(null),colName:e.name,anchorRect:R})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[w&&(0,n.jsxs)("tr",{className:"bg-emerald-500/5",children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border text-center",children:(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:S,className:"text-[10px] text-emerald-500 hover:text-emerald-400",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:L,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]})}),I.map(e=>(0,n.jsx)("td",{className:"px-0.5 py-0.5 border-b border-border",children:(0,n.jsx)("input",{type:"text",value:k[e.name]??"",onChange:t=>C(e.name,t.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]",placeholder:"NULL"})},e.name))]}),B.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-accent/50 ${x.has(t)?"bg-brand/5":""} ${p===t?"bg-blue-500/5":""}`,children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border/50 text-center",children:p===t?(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:j,className:"text-[10px] text-emerald-500 hover:text-emerald-400",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:y,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:x.has(t),onChange:()=>{let e;(e=new Set(x)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(r=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onDoubleClick:()=>{null===p&&b(t)},onContextMenu:t=>{t.preventDefault(),M(rv(e[r.name]))},children:p===t?(0,n.jsx)("input",{type:"text",value:g[r.name]??"",onChange:e=>v(r.name,e.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]"}):null===e[r.name]||void 0===e[r.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rj,{text:rv(e[r.name])})},r.name))]},t))]})]}),0===B.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:E("common.noData")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 border-t border-border text-[10px] text-muted-foreground bg-card/30 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:N,disabled:w,className:"px-1.5 py-0.5 text-[10px] text-emerald-500 hover:text-emerald-400 disabled:opacity-30",children:E("database.addRow")}),(0,n.jsx)("span",{children:E("database.totalRows",{count:i})}),e?.duration!==void 0&&(0,n.jsxs)("span",{children:[e.duration,"ms"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>c(a-1),disabled:0===a,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[a+1," / ",l]}),(0,n.jsx)("button",{onClick:()=>c(a+1),disabled:a>=l-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function rL({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:a,error:l,loading:i,sqlRef:c,onCellCopy:d}){let{t:u}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 p-2 border-b border-border",children:[(0,n.jsx)("textarea",{ref:c,value:e,onChange:e=>t(e.target.value),onKeyDown:s,placeholder:u("database.sqlPlaceholder",{modKey:(0,tB.Mu)()}),className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("button",{onClick:r,disabled:i||!e.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:u(i?"database.executing":"database.execute")}),a?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[a.command&&!a.fields?u("database.rowsAffected",{command:a.command,count:a.rowCount,duration:a.duration}):u("database.queryRows",{count:a.rows?.length??0,duration:a.duration}),a.truncated&&` ${u("database.resultTruncated")}`]})]})]}),l&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:l}),a?.fields&&a.rows&&(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:a.fields.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e.name},e.name))})}),(0,n.jsx)("tbody",{children:a.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:a.fields.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onContextMenu:r=>{r.preventDefault(),d(rv(e[t.name]))},children:null===e[t.name]||void 0===e[t.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rj,{text:rv(e[t.name])})},t.name))},t))})]})})]})}rl({type:"database",idPrefix:"db",match(e){let t=e.trim().toLowerCase();return t.startsWith("postgresql://")||t.startsWith("postgres://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"postgres";r=`${n}@${e.hostname}${e.port?":"+e.port:""}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(rk,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/db/disconnect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})})}catch{}}});var rM=r(91334),rE=r(38194),r$=r(88522);let rT=new tR.v;function rR(e){return e?Array.isArray(e)?e.join(""):e:""}function rP(e,t){return e&&e[t]?rR(e[t]):""}rT.use_classes=!0;let rI=(0,s.memo)(function({output:e}){if("stream"===e.output_type){let t=rR(e.text);if(!t)return null;let r=rT.ansi_to_html(t);return(0,n.jsx)("pre",{className:`text-xs leading-relaxed whitespace-pre-wrap break-all px-3 py-1 ${"stderr"===e.name?"text-amber-500":"text-foreground"}`,dangerouslySetInnerHTML:{__html:r}})}if("error"===e.output_type){let t=(e.traceback||[]).join("\n"),r=rT.ansi_to_html(t);return(0,n.jsx)("pre",{className:"text-xs leading-relaxed whitespace-pre-wrap break-all px-3 py-1 text-red-400 bg-red-500/5 rounded",dangerouslySetInnerHTML:{__html:r}})}if("execute_result"===e.output_type||"display_data"===e.output_type||"update_display_data"===e.output_type){let t=e.data;if(!t)return null;let r=rP(t,"image/png"),s=rP(t,"image/jpeg"),o=rP(t,"image/svg+xml"),a=rP(t,"text/html"),l=rP(t,"text/markdown"),i=rP(t,"text/latex"),c=rP(t,"text/plain");if(r)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)("img",{src:`data:image/png;base64,${r}`,alt:"output",className:"max-w-full"})});if(s)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)("img",{src:`data:image/jpeg;base64,${s}`,alt:"output",className:"max-w-full"})});if(o)return(0,n.jsx)("div",{className:"px-3 py-1",dangerouslySetInnerHTML:{__html:o}});if(a)return(0,n.jsx)("div",{className:"px-3 py-1 overflow-x-auto notebook-html-output",dangerouslySetInnerHTML:{__html:a}});if(l)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)(er.T,{content:l})});if(i)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)(er.T,{content:`$$${i}$$`})});if(c)return(0,n.jsx)("pre",{className:"text-xs leading-relaxed whitespace-pre-wrap break-all px-3 py-1 text-foreground",children:c})}return null}),rB=(0,s.memo)(function({cell:e,isActive:t,isEditing:r,onSelect:o,onEdit:a,onStopEdit:l,onSourceChange:i,onRun:c,onDelete:d,onMoveUp:u,onMoveDown:m,onToggleType:h,isFirst:x,isLast:f}){let{resolvedTheme:p}=(0,eM.D)(),g=(0,s.useRef)(null),[b,v]=(0,s.useState)(e.source),j=(0,s.useCallback)(()=>{v(e.source),a()},[e.source,a]);(0,s.useEffect)(()=>{if(r&&g.current){g.current.focus();let e=g.current.value.length;g.current.setSelectionRange(e,e)}},[r]);let y=(0,s.useCallback)(()=>{let e=g.current;e&&(e.style.height="auto",e.style.height=e.scrollHeight+"px")},[]);(0,s.useEffect)(()=>{r&&y()},[r,b,y]);let w=(0,s.useCallback)(e=>{v(e.target.value),y()},[y]),k=(0,s.useCallback)(()=>{b!==e.source&&i(b),l()},[b,e.source,i,l]),N=(0,s.useCallback)(t=>{if("Enter"===t.key&&t.shiftKey)t.preventDefault(),b!==e.source&&i(b),c();else if("Enter"===t.key&&(t.metaKey||t.ctrlKey))t.preventDefault(),b!==e.source&&i(b),c();else if("Escape"===t.key)t.preventDefault(),k();else if("Tab"===t.key){t.preventDefault();let e=g.current;if(e){let t=e.selectionStart,r=e.selectionEnd;v(b.substring(0,t)+" "+b.substring(r)),requestAnimationFrame(()=>{e.selectionStart=e.selectionEnd=t+4})}}},[b,e.source,i,c,k]),C=e.isExecuting?"*":e.execution_count??" ",S="code"===e.cell_type?"Code":"markdown"===e.cell_type?"Md":"Raw";return(0,n.jsxs)("div",{className:`group relative border rounded-lg transition-colors ${t?"border-brand/50 bg-brand/5":"border-border/50 hover:border-border"}`,onClick:o,children:[(0,n.jsxs)("div",{className:`absolute -top-3 left-2 flex items-center gap-0.5 text-[10px] z-10 bg-surface-secondary rounded px-1 py-0.5 border border-border/50 transition-opacity ${t?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:[(0,n.jsx)("button",{onClick:c,className:"px-1 hover:text-brand",title:"Run (Shift+Enter)",children:e.isExecuting?"⬛":"▶"}),(0,n.jsx)("button",{onClick:h,className:"px-1 hover:text-brand",title:"Toggle type",children:S}),!x&&(0,n.jsx)("button",{onClick:u,className:"px-1 hover:text-brand",title:"Move up",children:"↑"}),!f&&(0,n.jsx)("button",{onClick:m,className:"px-1 hover:text-brand",title:"Move down",children:"↓"}),(0,n.jsx)("button",{onClick:d,className:"px-1 hover:text-red-400",title:"Delete",children:"\xd7"})]}),(0,n.jsxs)("div",{className:"flex",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-10 text-center py-2 text-[10px] text-muted-foreground select-none cursor-pointer border-r border-border/30",onClick:e=>{e.stopPropagation(),c()},title:"code"===e.cell_type?"Click to run":void 0,children:"code"===e.cell_type?(0,n.jsxs)("span",{className:e.isExecuting?"text-brand animate-pulse":"",children:["[",C,"]"]}):(0,n.jsx)("span",{className:"text-muted-foreground/50",children:S})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"cursor-text",onDoubleClick:e=>{e.stopPropagation(),j()},children:r?(0,n.jsx)("textarea",{ref:g,value:b,onChange:w,onBlur:k,onKeyDown:N,className:"w-full bg-transparent text-xs font-mono leading-relaxed px-3 py-2 resize-none outline-none text-foreground",spellCheck:!1,style:{minHeight:"1.5rem"}}):"code"===e.cell_type?(0,n.jsx)("div",{className:"text-xs [&_pre]:!m-0 [&_pre]:!p-2 [&_pre]:!bg-transparent [&_code]:!bg-transparent",children:(0,n.jsx)(rM.A,{language:"python",style:"dark"===p?rE.A:r$.A,customStyle:{margin:0,padding:"8px 12px",background:"transparent",fontSize:"12px"},wrapLongLines:!0,children:e.source||" "})}):"markdown"===e.cell_type?e.source.trim()?(0,n.jsx)("div",{className:"px-3 py-2 text-sm prose prose-sm dark:prose-invert max-w-none",children:(0,n.jsx)(er.T,{content:e.source})}):(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground italic",children:"Empty markdown cell"}):(0,n.jsx)("pre",{className:"text-xs font-mono px-3 py-2 text-muted-foreground whitespace-pre-wrap",children:e.source||" "})}),e.outputs.length>0&&(0,n.jsx)("div",{className:"border-t border-border/30",children:e.outputs.map((e,t)=>(0,n.jsx)(rI,{output:e},t))})]})]})]})});function rF({id:e,filePath:t,displayName:r,cwd:o,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:c,timestamp:d,onSelect:u,onClose:m,onToggleMaximize:h,onTitleMouseDown:x}){let{showToast:f}=(0,p.dj)(),[g,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(!0),[y,w]=(0,s.useState)(null),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)(null),[E,$]=(0,s.useState)(null),[T,R]=(0,s.useState)("disconnected"),[P,I]=(0,s.useState)(null),B=(0,s.useRef)(null),F=(0,s.useRef)(new Map),D=(0,s.useRef)(null),O=(0,s.useRef)(g);O.current=g;let A=(0,s.useCallback)(async()=>{j(!0),w(null);try{let e=await fetch("/api/jupyter/load",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:t,cwd:o})}),r=await e.json();if(!e.ok)throw Error(r.error||"Failed to load notebook");b(r.cells.map((e,t)=>({...e,index:t,isExecuting:!1}))),N(!1)}catch(e){w(e.message)}finally{j(!1)}},[t,o]);(0,s.useEffect)(()=>{A()},[A]);let _=(0,s.useCallback)(async()=>{if(!C){S(!0);try{let e=await fetch("/api/jupyter/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:t,cwd:o,cells:g.map(e=>({cell_type:e.cell_type,source:e.source,outputs:e.outputs,execution_count:e.execution_count,metadata:e.metadata}))})}),r=await e.json();if(!e.ok)throw Error(r.error||"Failed to save");N(!1),f("Saved","success")}catch(e){f(e.message,"error")}finally{S(!1)}}},[t,o,g,C,f]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),_())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[_]);let W=(0,s.useCallback)(()=>{if(B.current&&B.current.readyState<=1)return;R("starting"),I(null);let t="https:"===window.location.protocol?"wss:":"ws:",r=new WebSocket(`${t}//${window.location.host}/ws/jupyter?bubbleId=${encodeURIComponent(e)}&cwd=${encodeURIComponent(o)}`);B.current=r,r.onopen=()=>{},r.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ready"===r)R("idle"),I(null);else if("status"===r){let e=t.execution_state;"idle"===e?R("idle"):"busy"===e&&R("busy")}else if("output"===r){let e=t.msg_id,r=t.msg_type,n=t.content,s=F.current.get(e);if(void 0===s)return;b(e=>e.map((e,t)=>{if(t!==s)return e;let o={output_type:"execute_result"===r?"execute_result":"display_data"===r?"display_data":"update_display_data"===r?"update_display_data":"stream"===r?"stream":"error"===r?"error":"display_data"};return"stream"===r?(o.name=n.name,o.text=n.text):"error"===r?(o.ename=n.ename,o.evalue=n.evalue,o.traceback=n.traceback):(o.data=n.data,o.metadata=n.metadata,"execute_result"===r&&(o.execution_count=n.execution_count)),{...e,outputs:[...e.outputs,o]}}))}else if("kernel_error"===r)R("error"),I(t.message);else if("kernel_died"===r){for(let[,e]of(R("dead"),I("Kernel died"),F.current))b(t=>t.map((t,r)=>r===e?{...t,isExecuting:!1}:t));F.current.clear()}},r.onclose=()=>{"error"!==T&&"dead"!==T&&R("disconnected")},r.onerror=()=>{R("error")}},[e,o,T]);(0,s.useEffect)(()=>()=>{B.current?.close()},[]);let q=(0,s.useRef)(null),z=(0,s.useCallback)(e=>{let t=O.current[e];if(!t||"code"!==t.cell_type)return;if(!B.current||B.current.readyState!==WebSocket.OPEN){W();let t=setInterval(()=>{B.current?.readyState===WebSocket.OPEN&&(clearInterval(t),q.current?.(e))},200);setTimeout(()=>clearInterval(t),15e3);return}let r=`cell-${e}-${Date.now()}`;F.current.set(r,e),b(t=>t.map((t,r)=>r===e?{...t,outputs:[],isExecuting:!0,execution_count:null}:t)),B.current.send(JSON.stringify({type:"execute",msg_id:r,code:t.source})),setTimeout(()=>{F.current.has(r)&&(F.current.delete(r),b(t=>t.map((t,r)=>r===e?{...t,isExecuting:!1}:t)))},3e5)},[W]);q.current=z,(0,s.useEffect)(()=>{let e=B.current;if(!e)return;let t=e=>{let t=F.current.get(e);void 0!==t&&(F.current.delete(e),b(e=>e.map((e,r)=>{if(r!==t)return e;let n=e.outputs.find(e=>"execute_result"===e.output_type);return{...e,isExecuting:!1,execution_count:n?.execution_count??e.execution_count}})))},r=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("status"===r.type&&"idle"===r.execution_state)for(let[e]of F.current)t(e)};return e.addEventListener("message",r),()=>{e.removeEventListener("message",r)}},[T]);let H=(0,s.useCallback)(()=>{let e=[...g.map((e,t)=>({cell:e,index:t})).filter(e=>"code"===e.cell.cell_type)],t=()=>{if(0===e.length)return;let{index:r}=e.shift();z(r);let n=setInterval(()=>{let e=O.current[r];e&&!e.isExecuting&&(clearInterval(n),t())},200)};t()},[g,z]),U=(0,s.useCallback)(()=>{B.current?.send(JSON.stringify({type:"interrupt"}))},[]),V=(0,s.useCallback)((e,t)=>{b(r=>r.map((r,n)=>n===e?{...r,source:t}:r)),N(!0)},[]),K=(0,s.useCallback)(e=>{b(t=>t.filter((t,r)=>r!==e)),N(!0),L===e&&M(null)},[L]),J=(0,s.useCallback)((e,t)=>{b(r=>{let n=[...r],s="up"===t?e-1:e+1;return s<0||s>=n.length?r:([n[e],n[s]]=[n[s],n[e]],n)}),N(!0),M("up"===t?e-1:e+1)},[]),Q=(0,s.useCallback)(e=>{b(t=>t.map((t,r)=>{if(r!==e)return t;let n="code"===t.cell_type?"markdown":"markdown"===t.cell_type?"raw":"code";return{...t,cell_type:n,outputs:"code"===n?t.outputs:[]}})),N(!0)},[]),Y=(0,s.useCallback)((e,t)=>{let r={index:0,cell_type:e,source:"",outputs:[],execution_count:null,metadata:{},isExecuting:!1};b(e=>{let n=[...e],s=void 0!==t?t+1:n.length;return n.splice(s,0,r),n}),N(!0);let n=void 0!==t?t+1:g.length;M(n),$(n)},[g.length]),X=(0,s.useMemo)(()=>{switch(T){case"idle":return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 inline-block",title:"Kernel idle"});case"busy":return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-amber-500 animate-pulse inline-block",title:"Kernel busy"});case"starting":return(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin inline-block",title:"Starting kernel"});case"error":return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-red-500 inline-block",title:P||"Kernel error"});case"dead":return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-red-500 inline-block",title:"Kernel died"});default:return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-gray-500 inline-block",title:"Disconnected"})}},[T,P]);return(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
|
|
9
|
-
relative transition-colors cursor-pointer
|
|
10
|
-
${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
|
|
11
|
-
${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:u,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:h,onMouseDown:x,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDCD3"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),X,k&&(0,n.jsx)("span",{className:"text-[10px] text-amber-500 flex-shrink-0",children:"unsaved"}),(0,n.jsx)("span",{className:"flex-1"}),d&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(d)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?`Exit maximize (${(0,tB.Mu)()}+M)`:`Maximize (${(0,tB.Mu)()}+M)`,children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:"Close",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 px-3 py-1 border-b border-border/50 bg-surface-secondary/50 text-[11px]",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),H()},className:"px-1.5 py-0.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",title:"Run All",children:"▶ All"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),U()},className:"px-1.5 py-0.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",title:"Interrupt",disabled:"busy"!==T,children:"⬛ Stop"}),(0,n.jsx)("div",{className:"w-px h-3 bg-border/50 mx-1"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Y("code",L??g.length-1)},className:"px-1.5 py-0.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",title:"Add code cell",children:"+ Code"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Y("markdown",L??g.length-1)},className:"px-1.5 py-0.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",title:"Add markdown cell",children:"+ Md"}),(0,n.jsx)("div",{className:"w-px h-3 bg-border/50 mx-1"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),_()},className:`px-1.5 py-0.5 rounded hover:bg-accent transition-colors ${k?"text-brand":"text-muted-foreground hover:text-foreground"}`,title:`Save (${(0,tB.Mu)()}+S)`,disabled:C,children:C?"Saving...":"Save"}),(0,n.jsx)("span",{className:"flex-1"}),P&&(0,n.jsx)("span",{className:"text-[10px] text-red-400 truncate max-w-[50%]",title:P,children:P}),"dead"===T&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),W()},className:"px-1.5 py-0.5 rounded text-brand hover:bg-accent transition-colors",children:"Restart"})]}),(0,n.jsx)("div",{ref:D,className:"overflow-y-auto",style:{height:(l&&i?i-41:c??360)-30},children:v?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground text-sm",children:"Loading notebook..."}):y?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-32 gap-2",children:[(0,n.jsx)("span",{className:"text-red-400 text-sm",children:y}),(0,n.jsx)("button",{onClick:A,className:"text-xs text-brand hover:underline",children:"Retry"})]}):0===g.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-32 gap-2 text-muted-foreground text-sm",children:[(0,n.jsx)("span",{children:"Empty notebook"}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>Y("code"),className:"text-xs text-brand hover:underline",children:"+ Code cell"}),(0,n.jsx)("button",{onClick:()=>Y("markdown"),className:"text-xs text-brand hover:underline",children:"+ Markdown cell"})]})]}):(0,n.jsxs)("div",{className:"flex flex-col gap-1 p-2",children:[g.map((e,t)=>(0,n.jsx)(rB,{cell:e,isActive:L===t,isEditing:E===t,onSelect:()=>M(t),onEdit:()=>{M(t),$(t)},onStopEdit:()=>$(null),onSourceChange:e=>V(t,e),onRun:()=>{"code"===e.cell_type&&z(t),t<g.length-1&&M(t+1)},onDelete:()=>K(t),onMoveUp:()=>J(t,"up"),onMoveDown:()=>J(t,"down"),onToggleType:()=>Q(t),isFirst:0===t,isLast:t===g.length-1},`${t}-${e.cell_type}`)),(0,n.jsxs)("div",{className:"flex justify-center gap-2 py-2 opacity-0 hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:()=>Y("code",g.length-1),className:"text-[10px] text-muted-foreground hover:text-foreground px-2 py-0.5 rounded border border-border/50 hover:border-border transition-colors",children:"+ Code"}),(0,n.jsx)("button",{onClick:()=>Y("markdown",g.length-1),className:"text-[10px] text-muted-foreground hover:text-foreground px-2 py-0.5 rounded border border-border/50 hover:border-border transition-colors",children:"+ Markdown"})]})]})})]})}rl({type:"jupyter",idPrefix:"nb",match:e=>e.trim().endsWith(".ipynb"),parse(e){let t=e.trim(),r=t.split("/"),n=r[r.length-1]||t;return{filePath:t,displayName:n,cwd:""}},fromHistory:e=>({filePath:e.filePath,displayName:e.displayName||"",cwd:e.cwd||""}),toHistory:e=>({filePath:e.filePath,displayName:e.displayName,cwd:e.cwd}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(rF,{id:e.id,filePath:e.filePath,displayName:e.displayName,cwd:e.cwd,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/jupyter/shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({bubbleId:e.id})})}catch{}}});let rD=[{value:"=",label:"="},{value:"!=",label:"!="},{value:">",label:">"},{value:"<",label:"<"},{value:">=",label:">="},{value:"<=",label:"<="},{value:"LIKE",label:"LIKE"},{value:"NOT LIKE",label:"NOT LIKE"},{value:"IN",label:"IN"},{value:"IS NULL",label:"IS NULL"},{value:"IS NOT NULL",label:"IS NOT NULL"}];function rO(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}function rA(e){return`\`${e.replace(/`/g,"``")}\``}function r_(e){try{let t=e.match(/\/\/[^/]+\/([^?]+)/);if(t)return t[1]}catch{}return""}function rW(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function rq({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),l=(0,s.useRef)(null),c=(0,s.useRef)(null),d=(0,s.useRef)(!1),u=(0,i.F2)(),m=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d.current||r(!1)},80)},[]),h=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),d.current=!1,c.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=u?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.width??window.innerWidth,c=n?.height??window.innerHeight,d=t.left-s,m=t.top-o,h=t.bottom-o,x=Math.min(600,i-d-8),f=m-8,p=c-h-8,g=f>p&&f>80;a({x:x<200?Math.max(8,i-600-8):d,y:g?m-4:h+4,maxW:x<200?Math.min(600,i-16):x,maxH:Math.max(60,g?f-4:p-4),above:g}),r(!0)},350)},[u]),x=(0,s.useCallback)(()=>{m()},[m]),f=(0,s.useCallback)(()=>{d.current=!0,c.current&&clearTimeout(c.current)},[]),p=(0,s.useCallback)(()=>{d.current=!1,m()},[m]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:h,onMouseLeave:x,children:[e,t&&(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lg whitespace-pre-wrap break-all select-text cursor-text",style:{left:o.x,top:o.y,maxWidth:o.maxW,maxHeight:o.maxH,transform:o.above?"translateY(-100%)":void 0},onMouseEnter:f,onMouseLeave:p,children:function(e){try{let t=JSON.parse(e);if("object"==typeof t&&null!==t)return JSON.stringify(t,null,2)}catch{}return e}(e)})})]})}async function rz(e,t){let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json();if(!r.ok)throw Error(n.error||`HTTP ${r.status}`);return n}async function rH(e,t){let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(s.error||`HTTP ${n.status}`);return s}function rU({id:e,connectionString:t,displayName:r,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:c,onSelect:d,onClose:u,onToggleMaximize:m,timestamp:h,onTitleMouseDown:x}){let{t:f}=(0,o.Bd)(),{showToast:g}=(0,p.dj)(),[b,v]=(0,s.useState)("connecting"),[j,y]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[N,C]=(0,s.useState)(()=>r_(t)),[S,L]=(0,s.useState)([]),[M,E]=(0,s.useState)(null),[$,T]=(0,s.useState)("table"),[R,P]=(0,s.useState)("data"),[I,B]=(0,s.useState)([]),[F,D]=(0,s.useState)([]),[O,A]=(0,s.useState)([]),[_,W]=(0,s.useState)([]),[q,z]=(0,s.useState)(null),[H,U]=(0,s.useState)(0),[V,K]=(0,s.useState)(!1),[J,Q]=(0,s.useState)(0),[Y,X]=(0,s.useState)(new Set),[G,Z]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)({}),[ei,ec]=(0,s.useState)({}),[ed,eu]=(0,s.useState)(null),[em,eh]=(0,s.useState)(""),[ex,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ey=(0,s.useCallback)(async()=>{v("connecting"),y("");try{let r=await rz("/api/mysql/connect",{id:e,connectionString:t});k(r.schemas||[]);let n=r_(t);r.schemas?.length>0&&n&&r.schemas.includes(n)?C(n):r.schemas?.length>0&&C(r.schemas[0]),v("connected")}catch(e){y(e instanceof Error?e.message:String(e)),v("error")}},[e,t]);(0,s.useEffect)(()=>{ey()},[ey]);let ew=(0,s.useCallback)(async()=>{if("connected"===b)try{let r=await rH("/api/mysql/schemas",{id:e,connectionString:t,schema:N});L(r.tables||[])}catch{}},[e,t,N,b]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async(r,n,s,o)=>{K(!0);let a=s??ei,l=void 0!==o?o:ed;try{let s=`${rA(N)}.${rA(r)}`,{where:o,params:i}=function(e){let t=[],r=[];for(let[n,s]of Object.entries(e)){if(!s.enabled)continue;let e=rA(n);if("IS NULL"===s.op)t.push(`${e} IS NULL`);else if("IS NOT NULL"===s.op)t.push(`${e} IS NOT NULL`);else if("IN"===s.op){let n=s.value.split(",").map(e=>e.trim()).filter(Boolean);if(0===n.length)continue;let o=n.map(e=>(r.push(e),"?"));t.push(`${e} IN (${o.join(", ")})`)}else"LIKE"===s.op||s.op,t.push(`${e} ${s.op} ?`),r.push(s.value)}return{where:t.length>0?` WHERE ${t.join(" AND ")}`:"",params:r}}(a),c=l?` ORDER BY ${rA(l.column)} ${l.dir}`:"",d=`SELECT * FROM ${s}${o}${c} LIMIT 50 OFFSET ${50*n}`,u=await rz("/api/mysql/query",{id:e,connectionString:t,sql:d,params:i});z(u);let m=`SELECT count(*) AS cnt FROM ${s}${o}`,h=await rz("/api/mysql/query",{id:e,connectionString:t,sql:m,params:i});Q(h.rows?.[0]?.cnt??0)}catch{}K(!1)},[e,t,N,ei,ed]),eN=(0,s.useCallback)(async r=>{E(r),U(0),et(null),eo(!1),X(new Set),Z(!1),ec({}),eu(null);try{let n=await rH("/api/mysql/columns",{id:e,connectionString:t,schema:N,table:r});B(n.columns||[]),D(n.primaryKeys||[]),A(n.foreignKeys||[]),W(n.indexes||[])}catch{}ek(r,0,{},null)},[e,t,N,ek]),eC=(0,s.useCallback)(async()=>{if(em.trim()){ev(!0),eg(""),ef(null);try{let r=await rz("/api/mysql/query",{id:e,connectionString:t,sql:em});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,em]),eS=(0,s.useCallback)(async()=>{if(null===ee||!q||!M)return;let r=q.rows[ee],n=[],s=[];for(let e of I)void 0!==er[e.name]&&er[e.name]!==rW(r[e.name]??"")&&(n.push(`${rA(e.name)} = ?`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]));if(0===n.length)return void et(null);let o=F.length>0?F:I.map(e=>e.name),a=[];for(let e of o)null===r[e]||void 0===r[e]?a.push(`${rA(e)} IS NULL`):(a.push(`${rA(e)} = ?`),s.push(r[e]));let l=`UPDATE ${rA(N)}.${rA(M)} SET ${n.join(", ")} WHERE ${a.join(" AND ")}`;try{await rz("/api/mysql/query",{id:e,connectionString:t,sql:l,params:s}),et(null),ek(M,H,ei,ed)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,q,M,I,F,er,e,t,N,ek,H,ei,ed]),eL=(0,s.useCallback)(async()=>{if(!M)return;let r=[],n=[],s=[];for(let e of I)void 0!==ea[e.name]&&""!==ea[e.name]&&(r.push(rA(e.name)),n.push(ea[e.name]),s.push("?"));if(0===r.length)return;let o=`INSERT INTO ${rA(N)}.${rA(M)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await rz("/api/mysql/query",{id:e,connectionString:t,sql:o,params:n}),eo(!1),el({}),ek(M,H,ei,ed)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[M,I,ea,e,t,N,ek,H,ei,ed]),eM=(0,s.useCallback)(async()=>{if(0===Y.size||!q||!M)return;let r=F.length>0?F:I.map(e=>e.name),n=0;for(let s of Array.from(Y).sort((e,t)=>t-e)){let o=q.rows[s];if(!o)continue;let a=[],l=[];for(let e of r)null===o[e]||void 0===o[e]?a.push(`${rA(e)} IS NULL`):(a.push(`${rA(e)} = ?`),l.push(o[e]));let i=`DELETE FROM ${rA(N)}.${rA(M)} WHERE ${a.join(" AND ")} LIMIT 1`;try{await rz("/api/mysql/query",{id:e,connectionString:t,sql:i,params:l})}catch{n++}}X(new Set),Z(!1),ek(M,H,ei,ed),n>0&&alert(f("mysql.deleteRowsFailed",{count:n}))},[Y,q,M,F,I,e,t,N,ek,H,ei,ed]),eE=(0,s.useCallback)(async r=>{if(!M)return;if(Y.size>0&&q){let e,t=q.fields.map(e=>e.name),n=Array.from(Y).sort((e,t)=>e-t).map(e=>q.rows[e]).filter(Boolean);if("json"===r)e=JSON.stringify(n,null,2);else{let r=[t.join(",")];for(let e of n)r.push(t.map(t=>{let r=e[t];if(null==r)return"";let n="object"==typeof r?JSON.stringify(r):String(r);return n.includes(",")||n.includes('"')||n.includes("\n")?`"${n.replace(/"/g,'""')}"`:n}).join(","));e=r.join("\n")}navigator.clipboard.writeText(e);return}let n=`SELECT * FROM ${rA(N)}.${rA(M)}`;try{let s=await fetch("/api/mysql/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,connectionString:t,sql:n,format:r})});if(!s.ok)throw Error("Export failed");let o=await s.blob(),a=URL.createObjectURL(o),l=document.createElement("a");l.href=a,l.download=`${M}.${r}`,l.click(),URL.revokeObjectURL(a)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[M,e,t,N,Y,q]),e$=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),eT=Math.max(1,Math.ceil(J/50)),eR=(0,s.useCallback)(e=>{M&&(U(e),ek(M,e,ei,ed))},[M,ek,ei,ed]),eP=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ec(r),U(0),X(new Set),M&&ek(M,0,r,ed)},[ei,ed,M,ek]),eI=(0,s.useCallback)(()=>{ec({}),U(0),X(new Set),M&&ek(M,0,{},ed)},[ed,M,ek]),eB=(0,s.useCallback)(e=>{eu(e),U(0),X(new Set),M&&ek(M,0,ei,e)},[ei,M,ek]);return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
|
|
12
|
-
relative transition-colors cursor-pointer
|
|
13
|
-
${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
|
|
14
|
-
${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:d,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:x,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDC2C"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===b&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===b&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:f("mysql.connectionFailed")}),"connected"===b&&(0,n.jsx)("span",{className:"text-[10px] text-emerald-500 flex-shrink-0",children:f("mysql.connected")}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rO(h)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?f("browser.exitMaximize",{modKey:(0,tB.Mu)()}):f("browser.maximize",{modKey:(0,tB.Mu)()}),children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&i?i-41:c??360},className:"flex overflow-hidden",children:["connecting"===b&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),f("mysql.connecting")]}),"error"===b&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:j}),(0,n.jsx)("button",{onClick:ey,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:f("common.retry")})]}),"connected"===b&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[w.length>1?(0,n.jsx)("select",{value:N,onChange:e=>{C(e.target.value),E(null)},className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1",children:w.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}):(0,n.jsx)("span",{className:"flex-1 min-w-0 text-xs text-muted-foreground truncate",children:N}),(0,n.jsx)("button",{onClick:ew,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent active:bg-accent/50 transition-colors",title:f("mysql.refreshTableList"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsx)("div",{className:"flex items-center border-b border-border",children:["table","view"].map(e=>(0,n.jsx)("button",{onClick:()=>T(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${$===e?"text-brand border-b border-brand":"text-muted-foreground hover:text-foreground"}`,children:{table:f("mysql.filterTable"),view:f("mysql.filterView")}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[S.filter(e=>"table"===$?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>eN(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${M===e.name?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground",children:"view"===e.type?"V":"T"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:(0,n.jsx)(rq,{text:e.name})}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.rowEstimate>0?`~${e.rowEstimate}`:""})]},e.name)),0===S.length&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:f("mysql.noTables")})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["structure","data","sql"].map(e=>(0,n.jsx)("button",{onClick:()=>P(e),className:`px-3 py-1.5 text-xs transition-colors ${R===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{structure:f("mysql.tabStructure"),data:f("mysql.tabData"),sql:"SQL"}[e]},e)),M&&"data"===R&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[Object.values(ei).some(e=>e.enabled)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-brand",children:f("mysql.filterActive",{count:Object.values(ei).filter(e=>e.enabled).length})}),(0,n.jsx)("button",{onClick:eI,className:"px-1 py-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors",title:f("mysql.clearAllFilters"),children:"✕"}),(0,n.jsx)("span",{className:"text-border",children:"|"})]}),Y.size>0&&!G&&(0,n.jsx)("button",{onClick:()=>Z(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:f("mysql.deleteNRows",{count:Y.size})}),G&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-destructive",children:f("mysql.confirmDeleteRows")}),(0,n.jsx)("button",{onClick:eM,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:f("common.confirm")}),(0,n.jsx)("button",{onClick:()=>Z(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:f("common.cancel")})]}),(0,n.jsx)("button",{onClick:()=>eE("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Y.size>0?f("mysql.copyCsvSelected"):f("mysql.copyCsvAll"),children:Y.size>0?f("mysql.copyCSV"):f("mysql.CSV")}),(0,n.jsx)("button",{onClick:()=>eE("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Y.size>0?f("mysql.copyJsonSelected"):f("mysql.copyJsonAll"),children:Y.size>0?f("mysql.copyJSON"):f("mysql.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:M||"sql"===R?"structure"===R?(0,n.jsx)(rV,{columns:I,primaryKeys:F,foreignKeys:O,indexes:_}):"data"===R?(0,n.jsx)(rJ,{result:q,loading:V,columns:I,page:H,totalPages:eT,totalRows:J,onPageChange:eR,filters:ei,sort:ed,onFilterChange:eP,onSortChange:eB,selectedRows:Y,onSelectedRowsChange:e=>{X(e),Z(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!q)return;let t=q.rows[e],r={};for(let e of I)r[e.name]=null==t[e.name]?"":rW(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:ea,onStartAdd:()=>{eo(!0),el({})},onNewRowChange:(e,t)=>el(r=>({...r,[e]:t})),onSaveNewRow:eL,onCancelAdd:()=>{eo(!1),el({})},onCellCopy:e=>{navigator.clipboard.writeText(e),g(f("common.copied"))}}):(0,n.jsx)(rQ,{sqlInput:em,onSqlChange:eh,onExecute:eC,onKeyDown:e$,result:ex,error:ep,loading:eb,sqlRef:ej,onCellCopy:e=>{navigator.clipboard.writeText(e),g(f("common.copied"))}}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:f("mysql.selectTable")})})]})]})]}),!l&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===b?"bg-green-500":"error"===b?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:f("common.connecting"),connected:f("common.connected"),error:f("common.connectionFailed")}[b]}),"connected"===b&&M&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:M}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rO(h)})]})]})})}function rV({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:a}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:a("mysql.selectTableToView")}):(0,n.jsxs)("div",{className:"p-2 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("mysql.columns")}),(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"text-left text-muted-foreground border-b border-border",children:[(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colDefault")})]})}),(0,n.jsx)("tbody",{children:e.map(e=>(0,n.jsxs)("tr",{className:"border-b border-border/50 hover:bg-accent/50",children:[(0,n.jsxs)("td",{className:"px-1.5 py-1 font-mono",children:[e.isPrimaryKey&&(0,n.jsx)("span",{className:"text-amber-500 mr-1",title:a("mysql.primaryKey"),children:"\uD83D\uDD11"}),e.name]}),(0,n.jsxs)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono",children:[e.type,e.maxLength?`(${e.maxLength})`:""]}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground",children:e.nullable?"YES":"NO"}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono truncate max-w-[120px]",children:e.default||""})]},e.name))})]})]}),r.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("mysql.foreignKeys")}),(0,n.jsx)("div",{className:"space-y-0.5",children:r.map((e,t)=>(0,n.jsxs)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground",children:[e.column," → ",e.refSchema,".",e.refTable,".",e.refColumn]},t))})]}),s.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("mysql.indexes")}),(0,n.jsx)("div",{className:"space-y-0.5",children:s.map(e=>(0,n.jsx)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground truncate",title:e.definition,children:e.name},e.name))})]})]})}function rK({filter:e,onApply:t,onClear:r,onToggle:a,onClose:l,colName:c,anchorRect:d}){let{t:u}=(0,o.Bd)(),[m,h]=(0,s.useState)(e?.op||"="),[x,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null),g=(0,i.F2)();(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&l()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[l]);let b="IS NULL"!==m&&"IS NOT NULL"!==m,v=()=>{(!b||x.trim())&&t({op:m,value:x.trim(),enabled:!0})},j=g?.getBoundingClientRect(),y=j?.left??0,w=j?.top??0,k=j?.width??window.innerWidth,N=d.left-y;N+220>k-8&&(N=k-220-8),N<8&&(N=8);let C=d.bottom+2-w;return(0,n.jsx)(i.ZL,{children:(0,n.jsxs)("div",{ref:p,className:"fixed z-[9998] w-[220px] bg-popover border border-border rounded-md shadow-lg p-2 space-y-2",style:{left:N,top:C},onClick:e=>e.stopPropagation(),children:[e&&(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:e=>a(e.target.checked),className:"w-3 h-3 accent-brand"}),u("mysql.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:c})]}),(0,n.jsx)("select",{value:m,onChange:e=>h(e.target.value),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 focus:outline-none focus:ring-1 focus:ring-ring",children:rD.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),b&&(0,n.jsx)("input",{type:"text",value:x,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v())},placeholder:u("IN"===m?"mysql.commaValues":"LIKE"===m?"mysql.likePattern":"mysql.valuePlaceholder"),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:v,disabled:b&&!x.trim(),className:"flex-1 px-2 py-1 text-[10px] bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-40 transition-colors",children:u("mysql.apply")}),e&&(0,n.jsx)("button",{onClick:r,className:"flex-1 px-2 py-1 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground transition-colors",children:u("mysql.clearFilter")})]})]})})}function rJ({result:e,loading:t,columns:r,page:a,totalPages:l,totalRows:i,onPageChange:c,filters:d,sort:u,onFilterChange:m,onSortChange:h,selectedRows:x,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:y,isAddingRow:w,newRowValues:k,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:L,onCellCopy:M}){let{t:E}=(0,o.Bd)(),[$,T]=(0,s.useState)(null),[R,P]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==$?(e.stopPropagation(),T(null)):null!==p?(e.stopPropagation(),y()):w&&(e.stopPropagation(),L()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[$,p,w,y,L]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:E("mysql.selectTableForData")});let I=e?.fields||[],B=e?.rows||[],F={};for(let e of r)F[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let D=B.length>0&&x.size===B.length,O=x.size>0&&!D;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",children:[t&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 flex items-center justify-center z-10",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[2]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-1 py-1 border-b border-border w-8 text-center",children:(0,n.jsx)("input",{type:"checkbox",checked:D,ref:e=>{e&&(e.indeterminate=O)},onChange:()=>{D?f(new Set):f(new Set(B.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(e=>{let t=u?.column===e.name?u.dir:null,r=d[e.name],s=r?.enabled;return(0,n.jsxs)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono relative",children:[(0,n.jsxs)("span",{className:"cursor-pointer select-none hover:text-foreground transition-colors",onClick:()=>{var t;return t=e.name,void(u?.column===t?"ASC"===u.dir?h({column:t,dir:"DESC"}):h(null):h({column:t,dir:"ASC"}))},children:[e.name,F[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:F[e.name]}),"ASC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↑"}),"DESC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↓"})]}),(0,n.jsx)("button",{onClick:t=>{if(t.stopPropagation(),$===e.name)return void T(null);let r=t.currentTarget.closest("th").getBoundingClientRect();P({left:r.left,bottom:r.bottom}),T(e.name)},className:`ml-1 inline-flex items-center transition-colors ${s?"text-brand":"text-muted-foreground/40 hover:text-muted-foreground"}`,children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 16 16",fill:"currentColor",children:(0,n.jsx)("path",{d:"M1 2h14l-5.5 6.5V14l-3-2v-3.5z"})})}),$===e.name&&(0,n.jsx)(rK,{filter:r||null,onApply:t=>{m(e.name,t),T(null)},onClear:()=>{m(e.name,null),T(null)},onToggle:t=>{r&&m(e.name,{...r,enabled:t})},onClose:()=>T(null),colName:e.name,anchorRect:R})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[w&&(0,n.jsxs)("tr",{className:"bg-emerald-500/5",children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border text-center",children:(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:S,className:"text-[10px] text-emerald-500 hover:text-emerald-400",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:L,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]})}),I.map(e=>(0,n.jsx)("td",{className:"px-0.5 py-0.5 border-b border-border",children:(0,n.jsx)("input",{type:"text",value:k[e.name]??"",onChange:t=>C(e.name,t.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]",placeholder:"NULL"})},e.name))]}),B.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-accent/50 ${x.has(t)?"bg-brand/5":""} ${p===t?"bg-blue-500/5":""}`,children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border/50 text-center",children:p===t?(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:j,className:"text-[10px] text-emerald-500 hover:text-emerald-400",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:y,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:x.has(t),onChange:()=>{let e;(e=new Set(x)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(r=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onDoubleClick:()=>{null===p&&b(t)},onContextMenu:t=>{t.preventDefault(),M(rW(e[r.name]))},children:p===t?(0,n.jsx)("input",{type:"text",value:g[r.name]??"",onChange:e=>v(r.name,e.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]"}):null===e[r.name]||void 0===e[r.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rq,{text:rW(e[r.name])})},r.name))]},t))]})]}),0===B.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:E("common.noData")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 border-t border-border text-[10px] text-muted-foreground bg-card/30 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:N,disabled:w,className:"px-1.5 py-0.5 text-[10px] text-emerald-500 hover:text-emerald-400 disabled:opacity-30",children:E("mysql.addRow")}),(0,n.jsx)("span",{children:E("mysql.totalRows",{count:i})}),e?.duration!==void 0&&(0,n.jsxs)("span",{children:[e.duration,"ms"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>c(a-1),disabled:0===a,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[a+1," / ",l]}),(0,n.jsx)("button",{onClick:()=>c(a+1),disabled:a>=l-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function rQ({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:a,error:l,loading:i,sqlRef:c,onCellCopy:d}){let{t:u}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 p-2 border-b border-border",children:[(0,n.jsx)("textarea",{ref:c,value:e,onChange:e=>t(e.target.value),onKeyDown:s,placeholder:u("mysql.sqlPlaceholder",{modKey:(0,tB.Mu)()}),className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("button",{onClick:r,disabled:i||!e.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:u(i?"mysql.executing":"mysql.execute")}),a?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[a.command&&!a.fields?u("mysql.rowsAffected",{command:a.command,count:a.rowCount,duration:a.duration}):u("mysql.queryRows",{count:a.rows?.length??0,duration:a.duration}),a.truncated&&` ${u("mysql.resultTruncated")}`]})]})]}),l&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:l}),a?.fields&&a.rows&&(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:a.fields.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e.name},e.name))})}),(0,n.jsx)("tbody",{children:a.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:a.fields.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onContextMenu:r=>{r.preventDefault(),d(rW(e[t.name]))},children:null===e[t.name]||void 0===e[t.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rq,{text:rW(e[t.name])})},t.name))},t))})]})})]})}async function rY(e,t){let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json();if(!r.ok)throw Error(n.error||`HTTP ${r.status}`);return n}rl({type:"mysql",idPrefix:"mysql",match:e=>e.trim().toLowerCase().startsWith("mysql://"),parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"mysql";r=`${n}@${e.hostname}${e.port?":"+e.port:""}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(rU,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/mysql/disconnect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})})}catch{}}});let rX={string:{label:"S",color:"text-emerald-500 bg-emerald-500/10"},hash:{label:"H",color:"text-blue-500 bg-blue-500/10"},list:{label:"L",color:"text-orange-500 bg-orange-500/10"},set:{label:"SET",color:"text-teal-500 bg-teal-500/10"},zset:{label:"Z",color:"text-purple-500 bg-purple-500/10"},stream:{label:"STR",color:"text-pink-500 bg-pink-500/10"}};function rG({type:e}){let t=rX[e]||{label:"?",color:"text-muted-foreground bg-muted"};return(0,n.jsx)("span",{className:`inline-block text-[9px] font-mono font-bold leading-none px-1 py-0.5 rounded flex-shrink-0 ${t.color}`,children:t.label})}function rZ({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,above:!0}),l=(0,s.useRef)(null),c=(0,s.useRef)(null),d=(0,i.F2)(),u=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=d?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.height??window.innerHeight,c=t.top-o,u=t.bottom-o,m=c>i/2;a({x:t.left-s,y:m?c-4:u+4,above:m}),r(!0)},350)},[d]),m=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),r(!1)},[]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:u,onMouseLeave:m,children:[e,t&&(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] max-w-[500px] max-h-[200px] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lg whitespace-pre-wrap break-all select-text",style:{left:o.x,top:o.y,transform:o.above?"translateY(-100%)":void 0},children:e})})]})}function r0({id:e,connectionString:t,displayName:r,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:c,onSelect:d,onClose:u,onToggleMaximize:m,timestamp:h,onTitleMouseDown:x}){var f;let{t:g}=(0,o.Bd)(),{showToast:b}=(0,p.dj)(),[v,j]=(0,s.useState)("connecting"),[y,w]=(0,s.useState)(""),[k,N]=(0,s.useState)(null),[C,S]=(0,s.useState)([]),[L,M]=(0,s.useState)("0"),[E,$]=(0,s.useState)(!1),[T,R]=(0,s.useState)("*"),[P,I]=(0,s.useState)(!1),[B,F]=(0,s.useState)(null),[D,O]=(0,s.useState)(null),[A,_]=(0,s.useState)(!1),[W,q]=(0,s.useState)(null),[z,H]=(0,s.useState)(!1),[U,V]=(0,s.useState)("data"),[K,J]=(0,s.useState)(""),[Q,Y]=(0,s.useState)(""),[X,G]=(0,s.useState)([]),[Z,ee]=(0,s.useState)(!1),et=(0,s.useRef)(null),er=(0,s.useRef)(null),en=(0,s.useCallback)(async()=>{j("connecting"),w("");try{let r=await rY("/api/redis/connect",{id:e,connectionString:t});N(r),j("connected")}catch(e){w(e instanceof Error?e.message:String(e)),j("error")}},[e,t]);(0,s.useEffect)(()=>{en()},[en]);let es=(0,s.useCallback)(async(r,n,s)=>{I(!0);try{let o=await rY("/api/redis/keys",{id:e,connectionString:t,pattern:r,cursor:n,count:200});S(e=>s?[...e,...o.keys]:o.keys),M(o.cursor),$(o.hasMore)}catch{}I(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===v&&es(T,"0",!1)},[v]);let eo=(0,s.useCallback)(()=>{F(null),O(null),es(T,"0",!1)},[T,es]),ea=(0,s.useCallback)(async r=>{F(r),_(!0),q(null),H(!1);try{let n=await rY("/api/redis/get",{id:e,connectionString:t,key:r});O(n)}catch(e){O(null),b(e instanceof Error?e.message:g("redis.loadFailed"))}_(!1)},[e,t,b]),el=(0,s.useCallback)(async()=>{if(B)try{await rY("/api/redis/delete",{id:e,connectionString:t,keys:[B]}),F(null),O(null),H(!1),es(T,"0",!1)}catch(e){b(e instanceof Error?e.message:g("redis.deleteFailed"))}},[B,e,t,T,es,b]),ei=(0,s.useCallback)(async()=>{if(B&&null!==W)try{await rY("/api/redis/set",{id:e,connectionString:t,key:B,value:W,type:"string"}),q(null),ea(B),b(g("common.saved"))}catch(e){b(e instanceof Error?e.message:g("redis.saveFailed"))}},[B,W,e,t,ea,b]),ec=(0,s.useCallback)(async()=>{try{let r=await rY("/api/redis/command",{id:e,connectionString:t,command:"INFO"});J("string"==typeof r.result?r.result:String(r.result))}catch{}},[e,t]);(0,s.useEffect)(()=>{"connected"===v&&"info"===U&&ec()},[v,U,ec]);let ed=(0,s.useCallback)(async()=>{let r,n=Q.trim();if(!n)return;ee(!0),Y("");let s=[],o=/(?:"([^"]*)")|(?:'([^']*)')|(\S+)/g;for(;null!==(r=o.exec(n));)s.push(r[1]??r[2]??r[3]);let a=s[0]||"",l=s.slice(1);try{let r=await rY("/api/redis/command",{id:e,connectionString:t,command:a,args:l});G(e=>[...e,{command:n,result:r.result,duration:r.duration,isError:!1}])}catch(e){G(t=>[...t,{command:n,result:e instanceof Error?e.message:String(e),duration:0,isError:!0}])}ee(!1)},[Q,e,t]);return(0,s.useEffect)(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[X]),(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
|
|
15
|
-
relative transition-colors cursor-pointer
|
|
16
|
-
${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
|
|
17
|
-
${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:d,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:x,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"♦"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===v&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===v&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:g("common.connectionFailed")}),"connected"===v&&k&&(0,n.jsxs)("span",{className:"text-[10px] text-red-500 flex-shrink-0",children:["v",k.version," \xb7 ",k.dbSize," keys \xb7 ",k.memory]}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(h)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?g("browser.exitMaximize",{modKey:(0,tB.Mu)()}):g("browser.maximize",{modKey:(0,tB.Mu)()}),children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:g("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&i?i-41:c??360},className:"flex overflow-hidden",children:["connecting"===v&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),g("common.connecting"),"..."]}),"error"===v&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:y}),(0,n.jsx)("button",{onClick:en,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:g("common.retry")})]}),"connected"===v&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:T,onChange:e=>R(e.target.value),onKeyDown:e=>{"Enter"===e.key&&eo()},placeholder:g("redis.scanPlaceholder"),className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("button",{onClick:eo,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent active:bg-accent/50 transition-colors",title:g("redis.scanSearch"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"6.5",cy:"6.5",r:"4.5"}),(0,n.jsx)("path",{d:"M10 10l4 4"})]})}),(0,n.jsx)("button",{onClick:()=>es(T,"0",!1),className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent active:bg-accent/50 transition-colors",title:g("common.refresh"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[C.map(e=>(0,n.jsxs)("div",{onClick:()=>ea(e.key),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer transition-colors ${B===e.key?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)(rG,{type:e.type}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:(0,n.jsx)(rZ,{text:e.key})})]},e.key)),0===C.length&&!P&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:g("redis.noKeys")}),P&&(0,n.jsx)("div",{className:"p-2 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"})}),E&&!P&&(0,n.jsx)("button",{onClick:()=>es(T,L,!0),className:"w-full py-1.5 text-[10px] text-brand hover:text-brand/80 transition-colors",children:g("redis.loadMore")})]}),(0,n.jsxs)("div",{className:"px-2 py-1 border-t border-border text-[10px] text-muted-foreground",children:[C.length," keys",E?"+":"",k?` / ${k.dbSize} total`:""]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["data","info","cli"].map(e=>(0,n.jsx)("button",{onClick:()=>V(e),className:`px-3 py-1.5 text-xs transition-colors ${U===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{data:g("redis.tabData"),info:g("redis.tabInfo"),cli:"CLI"}[e]},e)),B&&"data"===U&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[D&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:["TTL: ",function(e,t){if(-1===e)return t("redis.neverExpires");if(-2===e)return t("redis.expired");if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m${e%60>0?` ${e%60}s`:""}`;let r=Math.floor(e/3600),n=Math.floor(e%3600/60);return`${r}h${n>0?` ${n}m`:""}`}(D.ttl,g),null!==D.size?` \xb7 ${null==(f=D.size)?"":f<1024?`${f} B`:f<1048576?`${(f/1024).toFixed(1)} KB`:`${(f/1048576).toFixed(1)} MB`}`:""]}),z?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-[10px] text-destructive",children:[g("common.confirm"),"?"]}),(0,n.jsx)("button",{onClick:el,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:g("common.confirm")}),(0,n.jsx)("button",{onClick:()=>H(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:g("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>H(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:g("common.delete")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:"data"===U?(0,n.jsx)(r1,{selectedKey:B,keyValue:D,keyLoading:A,editingValue:W,onStartEdit:e=>q(e),onEditChange:q,onSaveEdit:ei,onCancelEdit:()=>q(null),onCellCopy:e=>{navigator.clipboard.writeText(e),b(g("common.copied"))}}):"info"===U?(0,n.jsx)(r2,{infoText:K,onRefresh:ec}):(0,n.jsx)(r5,{cliInput:Q,onInputChange:Y,onExecute:ed,history:X,loading:Z,endRef:et,inputRef:er})})]})]})]})]})})}function r1({selectedKey:e,keyValue:t,keyLoading:r,editingValue:s,onStartEdit:a,onEditChange:l,onSaveEdit:i,onCancelEdit:c,onCellCopy:d}){let{t:u}=(0,o.Bd)();if(!e)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.selectKey")});if(r)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if(!t)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.keyNotExist")});let{type:m,value:h}=t;if("string"===m){let t=String(h??""),r=null!==s;return(0,n.jsxs)("div",{className:"p-3 h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)(rG,{type:"string"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsx)("span",{className:"flex-1"}),r?(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("button",{onClick:i,className:"px-2 py-0.5 text-[10px] text-white bg-brand rounded hover:bg-brand/90",children:u("common.save")}),(0,n.jsx)("button",{onClick:c,className:"px-2 py-0.5 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground",children:u("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>a(t),className:"px-2 py-0.5 text-[10px] text-brand hover:text-brand/80 bg-brand/10 rounded transition-colors",children:u("common.edit")})]}),r?(0,n.jsx)("textarea",{value:s,onChange:e=>l(e.target.value),className:"flex-1 w-full px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-none focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}):(0,n.jsx)("pre",{className:"flex-1 overflow-auto text-xs font-mono bg-muted/30 rounded p-2 whitespace-pre-wrap break-all select-text cursor-text",onContextMenu:e=>{e.preventDefault(),d(t)},children:t})]})}if("hash"===m){let t=Object.entries(h||{});return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rG,{type:"hash"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[t.length," fields"]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-1/3",children:"Field"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Value"})]})}),(0,n.jsx)("tbody",{children:t.map(([e,t])=>(0,n.jsxs)("tr",{className:"hover:bg-accent/50",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[150px]",onContextMenu:t=>{t.preventDefault(),d(e)},children:(0,n.jsx)(rZ,{text:e})}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:e=>{e.preventDefault(),d(t)},children:(0,n.jsx)(rZ,{text:t})})]},e))})]})})]})}if("list"===m){let t=h?.items||[],r=h?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rG,{type:"list"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nItems",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-16",children:"#"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Value"})]})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsxs)("tr",{className:"hover:bg-accent/50",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 text-muted-foreground",children:t}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:t=>{t.preventDefault(),d(e)},children:(0,n.jsx)(rZ,{text:e})})]},t))})]})})]})}if("set"===m){let t=h?.items||[],r=h?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rG,{type:"set"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nMembers",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Member"})})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[400px]",onContextMenu:t=>{t.preventDefault(),d(e)},children:(0,n.jsx)(rZ,{text:e})})},t))})]})})]})}if("zset"===m){let t=h?.items||[],r=h?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rG,{type:"zset"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nMembers",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Member"}),(0,n.jsx)("th",{className:"px-2 py-1 text-right text-muted-foreground font-medium border-b border-border w-28",children:"Score"})]})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsxs)("tr",{className:"hover:bg-accent/50",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:t=>{t.preventDefault(),d(e.member)},children:(0,n.jsx)(rZ,{text:e.member})}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono text-right text-muted-foreground",children:e.score})]},t))})]})})]})}if("stream"===m){let t=h?.entries||[],r=h?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rG,{type:"stream"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nEntries",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-40",children:"ID"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Fields"})]})}),(0,n.jsx)("tbody",{children:t.map(([e,t])=>{let r=[];for(let e=0;e<t.length;e+=2)r.push(`${t[e]}: ${t[e+1]}`);return(0,n.jsxs)("tr",{className:"hover:bg-accent/50",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono text-muted-foreground",children:e}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",children:(0,n.jsx)(rZ,{text:r.join(", ")})})]},e)})})]})})]})}return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.unsupportedType",{type:m})})}function r2({infoText:e,onRefresh:t}){let{t:r}=(0,o.Bd)();if(!e)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})});let s=[],a=null;for(let t of e.split("\n")){let e=t.trim();if(e){if(e.startsWith("#"))a={title:e.replace(/^#\s*/,""),items:[]},s.push(a);else if(a&&e.includes(":")){let t=e.indexOf(":");a.items.push({key:e.slice(0,t),value:e.slice(t+1)})}}}return(0,n.jsxs)("div",{className:"p-2 space-y-3 overflow-auto h-full",children:[(0,n.jsx)("div",{className:"flex justify-end",children:(0,n.jsx)("button",{onClick:t,className:"px-2 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:r("common.refresh")})}),s.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1 font-medium",children:e.title}),(0,n.jsx)("div",{className:"space-y-0",children:e.items.map(({key:e,value:t})=>(0,n.jsxs)("div",{className:"flex items-start gap-2 px-1.5 py-0.5 text-xs hover:bg-accent/50 rounded",children:[(0,n.jsx)("span",{className:"text-muted-foreground font-mono flex-shrink-0 w-48 truncate",children:e}),(0,n.jsx)("span",{className:"font-mono text-foreground break-all",children:t})]},e))})]},e.title))]})}function r5({cliInput:e,onInputChange:t,onExecute:r,history:s,loading:a,endRef:l,inputRef:i}){let{t:c}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto p-2 font-mono text-xs space-y-2",onClick:()=>i.current?.focus(),children:[0===s.length&&(0,n.jsx)("div",{className:"text-muted-foreground text-center py-4",children:c("redis.cliHint")}),s.map((e,t)=>(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"text-brand",children:[(0,n.jsx)("span",{className:"text-muted-foreground mr-1",children:">"}),e.command,e.duration>0&&(0,n.jsxs)("span",{className:"text-muted-foreground/50 ml-2",children:["(",e.duration,"ms)"]})]}),(0,n.jsx)("pre",{className:`whitespace-pre-wrap break-all mt-0.5 ${e.isError?"text-destructive":"text-foreground"}`,children:e.isError?`(error) ${e.result}`:function e(t,r=0){let n=" ".repeat(r);return null===t?`${n}(nil)`:"number"==typeof t?`${n}(integer) ${t}`:"string"==typeof t?`${n}"${t}"`:Array.isArray(t)?0===t.length?`${n}(empty array)`:t.map((t,r)=>`${n}${r+1}) ${e(t,0)}`).join("\n"):`${n}${String(t)}`}(e.result)})]},t)),(0,n.jsx)("div",{ref:l})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1.5 border-t border-border bg-card/30 flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-xs text-brand font-mono flex-shrink-0",children:">"}),(0,n.jsx)("input",{ref:i,type:"text",value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{"Enter"!==e.key||a||r()},placeholder:c("redis.cliPlaceholder"),className:"flex-1 min-w-0 text-xs font-mono bg-transparent border-0 focus:outline-none",autoComplete:"off",spellCheck:!1,disabled:a}),a&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"})]})]})}rl({type:"redis",idPrefix:"redis",match(e){let t=e.trim().toLowerCase();return t.startsWith("redis://")||t.startsWith("rediss://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"0";r=`db${n}@${e.hostname}${e.port?":"+e.port:":6379"}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(r0,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/redis/disconnect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})})}catch{}}});let r4=["#4C8BF5","#E74C3C","#2ECC71","#F39C12","#9B59B6","#1ABC9C","#E67E22","#3498DB","#E91E63","#00BCD4"];function r3(e,t){return r4[t.indexOf(e)%r4.length]}async function r6(e,t){let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json();if(!r.ok)throw Error(n.error||`HTTP ${r.status}`);return n}function r8(e){if(!e)return"";let t=new Date(e);return isNaN(t.getTime())?"":`${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function r9({nodes:e,rels:t,allLabels:r}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),l=(0,s.useRef)([]),i=(0,s.useRef)(0),c=(0,s.useRef)(null),d=(0,s.useRef)({w:0,h:0}),u=(0,s.useRef)(new Map),[m,h]=(0,s.useState)(null),x=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=o.current;if(!e)return;let t=new ResizeObserver(e=>{let{width:t,height:r}=e[0].contentRect,n=d.current;if(t===n.w&&r===n.h)return;if(n.w>0&&n.h>0&&l.current.length>0){let e=t/n.w,s=r/n.h;l.current.forEach(t=>{t.x=(t.x||0)*e,t.y=(t.y||0)*s})}d.current={w:t,h:r};let s=a.current;s&&(s.width=t,s.height=r)});return t.observe(e),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{let{w:t,h:r}=d.current,n=t||o.current?.clientWidth||600,s=r||o.current?.clientHeight||400;0===t&&(d.current={w:n,h:s}),l.current=e.map((t,r)=>({...t,x:t.x??n/2+Math.cos(2*r*Math.PI/e.length)*Math.min(n,s)*.3,y:t.y??s/2+Math.sin(2*r*Math.PI/e.length)*Math.min(n,s)*.3,vx:0,vy:0})),u.current=new Map(l.current.map(e=>[e.id,e]))},[e]),(0,s.useEffect)(()=>{let e=u.current;return i.current=requestAnimationFrame(function n(){let{w:s,h:o}=d.current;if(0===s||0===o){i.current=requestAnimationFrame(n);return}let u=l.current;u.forEach(e=>{e.vx=(e.vx||0)+(s/2-(e.x||0))*.001,e.vy=(e.vy||0)+(o/2-(e.y||0))*.001});for(let e=0;e<u.length;e++)for(let t=e+1;t<u.length;t++){let r=(u[e].x||0)-(u[t].x||0),n=(u[e].y||0)-(u[t].y||0),s=Math.sqrt(r*r+n*n)||1,o=2e3/(s*s),a=r/s*o,l=n/s*o;u[e].vx+=a,u[t].vx-=a,u[e].vy+=l,u[t].vy-=l}t.forEach(t=>{let r=e.get(t.startId),n=e.get(t.endId);if(!r||!n)return;let s=(n.x||0)-(r.x||0),o=(n.y||0)-(r.y||0),a=Math.sqrt(s*s+o*o)||1,l=(a-100)*.01,i=s/a*l,c=o/a*l;r.vx+=i,n.vx-=i,r.vy+=c,n.vy-=c}),u.forEach(e=>{c.current?.nodeId!==e.id&&(e.vx=.6*(e.vx||0),e.vy=.6*(e.vy||0),e.x=Math.max(20,Math.min(s-20,(e.x||0)+.1*(e.vx||0))),e.y=Math.max(20,Math.min(o-20,(e.y||0)+.1*(e.vy||0))))});let m=a.current?.getContext("2d");m&&(m.clearRect(0,0,s,o),m.lineWidth=1.5,t.forEach(t=>{let r=e.get(t.startId),n=e.get(t.endId);if(!r||!n)return;m.strokeStyle="#666",m.beginPath(),m.moveTo(r.x,r.y),m.lineTo(n.x,n.y),m.stroke();let s=Math.atan2(n.y-r.y,n.x-r.x),o=n.x-24*Math.cos(s),a=n.y-24*Math.sin(s);m.fillStyle="#666",m.beginPath(),m.moveTo(o,a),m.lineTo(o-8*Math.cos(s-.3),a-8*Math.sin(s-.3)),m.lineTo(o-8*Math.cos(s+.3),a-8*Math.sin(s+.3)),m.closePath(),m.fill(),m.font="9px system-ui",m.fillStyle="#999",m.textAlign="center",m.fillText(t.type,(r.x+n.x)/2,(r.y+n.y)/2-4)}),u.forEach(e=>{let t=e.labels[0]||"",n=t?r3(t,r):"#888";m.beginPath(),m.arc(e.x,e.y,20,0,2*Math.PI),m.fillStyle=n,m.fill();let s=x.current?.id===e.id;m.strokeStyle=s?"#fff":"rgba(255,255,255,0.3)",m.lineWidth=s?2.5:1,m.stroke(),m.font="10px system-ui",m.fillStyle="#fff",m.textAlign="center",m.textBaseline="middle";let o=String(e.properties.name||e.properties.title||e.properties.id||t||e.id);m.fillText(o.length>8?o.slice(0,7)+"…":o,e.x,e.y)}),i.current=requestAnimationFrame(n))}),()=>cancelAnimationFrame(i.current)},[e,t,r]);let f=(0,s.useCallback)(e=>{let t=a.current?.getBoundingClientRect();if(!t)return null;let r=e.clientX-t.left,n=e.clientY-t.top;return l.current.find(e=>{let t=(e.x||0)-r,s=(e.y||0)-n;return t*t+s*s<400})||null},[]);return(0,n.jsxs)("div",{ref:o,className:"relative w-full h-full",children:[(0,n.jsx)("canvas",{ref:a,className:"cursor-grab active:cursor-grabbing absolute inset-0",onMouseDown:e=>{let t=f(e);if(t){let r=a.current.getBoundingClientRect();c.current={nodeId:t.id,offsetX:e.clientX-r.left-(t.x||0),offsetY:e.clientY-r.top-(t.y||0)}}},onMouseMove:e=>{if(c.current){let t=a.current.getBoundingClientRect(),r=l.current.find(e=>e.id===c.current.nodeId);r&&(r.x=e.clientX-t.left-c.current.offsetX,r.y=e.clientY-t.top-c.current.offsetY,r.vx=0,r.vy=0)}else{let t=f(e);x.current=t,h(t)}},onMouseUp:()=>{c.current=null},onMouseLeave:()=>{c.current=null,x.current=null,h(null)}}),m&&!c.current&&(0,n.jsxs)("div",{className:"absolute top-2 left-2 bg-popover text-popover-foreground border border-border rounded px-2 py-1 text-xs max-w-[300px] pointer-events-none",children:[(0,n.jsxs)("div",{className:"font-medium",children:[m.labels.join(", ")," #",String(m.id)]}),Object.entries(m.properties).slice(0,8).map(([e,t])=>(0,n.jsxs)("div",{className:"truncate",children:[(0,n.jsxs)("span",{className:"text-muted-foreground",children:[e,":"]})," ",String(t)]},e))]})]})}function r7({id:e,connectionString:t,displayName:r,selected:o,maximized:a,expandedHeight:l,bubbleContentHeight:i,onSelect:c,onClose:d,onToggleMaximize:u,timestamp:m,onTitleMouseDown:h}){let[x,f]=(0,s.useState)("connecting"),[p,g]=(0,s.useState)(""),[b,v]=(0,s.useState)(null),[j,y]=(0,s.useState)(null),[w,k]=(0,s.useState)(!1),[N,C]=(0,s.useState)("labels"),[S,L]=(0,s.useState)(""),[M,E]=(0,s.useState)(null),[$,T]=(0,s.useState)(!1),[R,P]=(0,s.useState)(""),I=(0,s.useRef)(null),[B,F]=(0,s.useState)([]),[D,O]=(0,s.useState)([]),[A,_]=(0,s.useState)("schema"),W=(0,s.useCallback)(async()=>{f("connecting");try{let r=await r6("/api/neo4j/connect",{id:e,connectionString:t});v(r),f("connected")}catch(e){g(e instanceof Error?e.message:String(e)),f("error")}},[e,t]);(0,s.useEffect)(()=>{W()},[W]);let q=(0,s.useCallback)(async()=>{k(!0);try{let r=await r6("/api/neo4j/schema",{id:e,connectionString:t});y(r)}catch{}k(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===x&&q()},[x,q]);let z=(0,s.useCallback)(async r=>{let n=r||S.trim();if(n){T(!0),P("");try{var s;let r,o,a=await r6("/api/neo4j/query",{id:e,connectionString:t,cypher:n});E(a);let{nodes:l,rels:i}=(s=a.records,r=new Map,o=[],s.forEach(e=>Object.values(e).forEach(function e(t){if(t&&"object"==typeof t)if("node"===t._type){let e=t._id;r.has(e)||r.set(e,{id:e,labels:t._labels||[],properties:Object.fromEntries(Object.entries(t).filter(([e])=>!e.startsWith("_")))})}else if("relationship"===t._type)o.push({id:t._id,type:t._relType,startId:t._start,endId:t._end,properties:Object.fromEntries(Object.entries(t).filter(([e])=>!e.startsWith("_")))});else if("path"===t._type){let r=t.segments;r?.forEach(t=>{e(t.start),e(t.relationship),e(t.end)})}else Array.isArray(t)&&t.forEach(e)})),{nodes:Array.from(r.values()),rels:o});l.length>0&&(F(l),O(i))}catch(e){P(e instanceof Error?e.message:String(e))}T(!1)}},[e,t,S]),H=(0,s.useCallback)(e=>{let t=`MATCH (n:\`${e}\`) RETURN n LIMIT 25`;L(t),_("cypher"),z(t)},[z]),U=(0,s.useCallback)(e=>{let t=`MATCH (a)-[r:\`${e}\`]->(b) RETURN a, r, b LIMIT 25`;L(t),_("graph"),z(t)},[z]);return(0,n.jsx)("div",{className:"flex flex-col items-start",onClick:c,children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground relative transition-colors ${o?"ring-1 ring-ring":""} rounded-lg overflow-hidden`,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:u,onMouseDown:h,className:"flex items-center gap-2 px-4 py-1.5 border-b border-border cursor-grab active:cursor-grabbing select-none",children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"⬡"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===x&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"connected"===x&&(0,n.jsx)("span",{className:"text-[10px] text-emerald-500 flex-shrink-0",children:"Connected"}),"error"===x&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:"Error"}),m&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:r8(m)}),"connected"===x&&b&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:["v",b.version," \xb7 ",b.nodeCount.toLocaleString(),"n \xb7 ",b.relationshipCount.toLocaleString(),"r"]}),(0,n.jsx)("span",{className:"flex-1"}),"connected"===x&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),q(),W()},disabled:w,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0 disabled:opacity-40",title:"Refresh",children:(0,n.jsx)("svg",{className:`w-3.5 h-3.5 ${w?"animate-spin":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a?(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 9V4.5M9 9H4.5M9 9L3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5l5.25 5.25"}):(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:a&&l?l-41:i??360},className:"flex flex-col overflow-hidden",children:["connecting"===x&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Connecting..."]}),"error"===x&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-xs p-4 gap-2",children:[(0,n.jsx)("p",{className:"text-destructive",children:p}),(0,n.jsx)("button",{onClick:W,className:"px-3 py-1 rounded text-xs bg-brand text-white hover:bg-brand/90 transition-colors",children:"Retry"})]}),"connected"===x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:["schema","cypher","graph"].map(e=>(0,n.jsx)("button",{onClick:()=>_(e),className:`px-3 py-1.5 text-xs transition-colors ${A===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{schema:"Schema",cypher:"Cypher",graph:"Graph"}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex",children:["schema"===A&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-40 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:(0,n.jsx)("div",{className:"flex-1 overflow-y-auto text-xs",children:[{key:"labels",label:"Labels",count:j?.labels.length},{key:"relationships",label:"Relationships",count:j?.relationshipTypes.length},{key:"properties",label:"Properties",count:j?.propertyKeys.length},{key:"indexes",label:"Indexes",count:j?.indexes.length},{key:"constraints",label:"Constraints",count:j?.constraints.length}].map(e=>(0,n.jsxs)("div",{onClick:()=>C(e.key),className:`flex items-center gap-1.5 px-2 py-1.5 cursor-pointer truncate transition-colors ${N===e.key?"bg-brand/10 text-brand":"hover:bg-white/10 text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:e.label}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count??0})]},e.key))})}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[w&&(0,n.jsxs)("div",{className:"flex items-center justify-center p-4 gap-2 text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"})," Loading..."]}),!w&&"labels"===N&&j?.labels.map(e=>(0,n.jsxs)("div",{onClick:()=>H(e.name),className:"flex items-center gap-1.5 px-2 py-1 cursor-pointer hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:r3(e.name,j.labels.map(e=>e.name))}}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count.toLocaleString()})]},e.name)),!w&&"relationships"===N&&j?.relationshipTypes.map(e=>(0,n.jsxs)("div",{onClick:()=>U(e.name),className:"flex items-center gap-1.5 px-2 py-1 cursor-pointer hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:"→"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count.toLocaleString()})]},e.name)),!w&&"properties"===N&&j?.propertyKeys.map(e=>(0,n.jsx)("div",{className:"px-2 py-1 font-mono text-muted-foreground hover:bg-brand/10 transition-colors",children:e},e)),!w&&"indexes"===N&&j?.indexes.map(e=>(0,n.jsxs)("div",{className:"px-2 py-1 border-b border-border/50 hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("div",{className:"font-mono text-foreground",children:e.name}),(0,n.jsxs)("div",{className:"text-muted-foreground",children:[e.type," \xb7 ",e.labelsOrTypes?.join(", ")," \xb7 (",e.properties?.join(", "),") \xb7 ",e.state]})]},e.name)),!w&&"constraints"===N&&j?.constraints.map(e=>(0,n.jsxs)("div",{className:"px-2 py-1 border-b border-border/50 hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("div",{className:"font-mono text-foreground",children:e.name}),(0,n.jsxs)("div",{className:"text-muted-foreground",children:[e.type," \xb7 ",e.labelsOrTypes?.join(", ")," \xb7 (",e.properties?.join(", "),")"]})]},e.name))]})]}),"cypher"===A&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("textarea",{ref:I,value:S,onChange:e=>L(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),z())},placeholder:`Enter Cypher query (${(0,tB.Mu)()}+Enter to run)`,className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center justify-between mt-1",children:[(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[(0,tB.Mu)(),"+Enter to execute"]}),(0,n.jsx)("button",{onClick:()=>z(),disabled:$||!S.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:$?"Running...":"Execute"})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[R&&(0,n.jsx)("div",{className:"p-2 text-xs text-destructive",children:R}),M&&!R&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-2 py-1 text-[10px] text-muted-foreground border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("span",{children:[M.records.length," rows"]}),(0,n.jsxs)("span",{children:[M.duration,"ms"]}),Object.entries(M.counters).filter(([,e])=>e>0).map(([e,t])=>(0,n.jsxs)("span",{children:[e,": ",t]},e))]}),M.records.length>0&&(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:M.keys.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e},e))})}),(0,n.jsx)("tbody",{children:M.records.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:M.keys.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",children:null===e[t]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):function(e){if(null==e)return"null";if("object"==typeof e){if("node"===e._type){let t=e._labels?.[0]||"",r=e.name||e.title||e.id||"";return`(${t}${r?": "+r:""})`}return"relationship"===e._type?`[${e._relType}]`:JSON.stringify(e)}return String(e)}(e[t])},t))},t))})]})]})]})]}),"graph"===A&&(0,n.jsx)("div",{className:"flex-1 relative",children:0===B.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-xs text-muted-foreground gap-2",children:[(0,n.jsx)("p",{children:"Run a Cypher query that returns nodes to visualize"}),(0,n.jsx)("button",{onClick:()=>{let e="MATCH (a)-[r]->(b) RETURN a, r, b LIMIT 50";L(e),z(e)},className:"px-3 py-1 rounded text-xs bg-brand text-white hover:bg-brand/90 transition-colors",children:"Load sample graph"})]}):(0,n.jsx)(r9,{nodes:B,rels:D,allLabels:j?.labels.map(e=>e.name)||[]})})]})]})]}),!a&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===x?"bg-green-500":"error"===x?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:"Connecting",connected:"Connected",error:"Error"}[x]}),"connected"===x&&b&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:b.edition}),(0,n.jsx)("span",{className:"flex-1"}),m&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:r8(m)})]})]})})}function ne(){return`cmd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}rl({type:"neo4j",idPrefix:"neo4j",match(e){let t=e.trim().toLowerCase();return t.startsWith("neo4j://")||t.startsWith("neo4j+s://")||t.startsWith("bolt://")||t.startsWith("bolt+s://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t);r=`${e.hostname}${e.port?":"+e.port:":7687"}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(r7,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/neo4j/disconnect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})})}catch{}}});let nt=new Set(["zsh","bash","sh","fish","nu","python","python3","node","irb","lua","vim","nvim","vi","nano","emacs","top","htop","less","man"]);function nr({onAdd:e,onCancel:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(""),[i,c]=(0,s.useState)("");return(0,n.jsxs)("div",{className:"flex gap-1 mb-1",children:[(0,n.jsx)("input",{type:"text",value:a,onChange:e=>l(e.target.value),placeholder:r("console.namePlaceholder"),className:"w-24 flex-shrink-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0,onKeyDown:e=>{"Escape"===e.key&&t()}}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:r("console.commandPlaceholder"),className:"flex-1 min-w-0 px-2 py-1 text-xs font-mono rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring",onKeyDown:r=>{"Enter"!==r.key||r.nativeEvent.isComposing?"Escape"===r.key&&t():(r.preventDefault(),r.stopPropagation(),a.trim()&&i.trim()&&e(a.trim(),i.trim()))}})]})}function nn({label:e,commands:t,isAdding:r,onStartAdd:s,onAdd:a,onCancelAdd:l,onDelete:i,onExecute:c}){let{t:d}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),(0,n.jsx)("button",{type:"button",onClick:s,className:"p-0.5 text-muted-foreground hover:text-foreground rounded",children:(0,n.jsx)(tq.A,{className:"w-3.5 h-3.5"})})]}),r&&(0,n.jsx)(nr,{onAdd:(e,t)=>a(e,t),onCancel:l}),0===t.length&&!r&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:d("console.noCustomCommands")}),t.map((e,t)=>(0,n.jsx)(e$.m,{content:e.command,children:(0,n.jsxs)("div",{className:"flex items-center group min-w-0",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>c(e.command),className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-accent transition-colors",children:[(0,n.jsx)(tY.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]}),(0,n.jsx)("button",{type:"button",onClick:()=>i(t),className:"p-1 text-muted-foreground hover:text-destructive rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:(0,n.jsx)(ex.A,{className:"w-3 h-3"})})]})},t))]})}function ns({cwd:e,show:t,onClose:r,onExecute:a,onAddPluginItem:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[u,m]=(0,s.useState)([]),[h,x]=(0,s.useState)(null),f=(0,s.useRef)(null),p=(0,s.useCallback)(async()=>{try{let[t,r]=await Promise.all([fetch("/api/services/config?scope=global"),fetch(`/api/services/config?cwd=${encodeURIComponent(e)}`)]);if(t.ok){let e=await t.json();d(e.customCommands||[])}if(r.ok){let e=await r.json();m(e.customCommands||[])}}catch(e){console.error("Failed to load commands:",e)}},[e]);(0,s.useEffect)(()=>{t&&queueMicrotask(()=>p())},[t,p]),(0,s.useEffect)(()=>{if(!t)return;let e=e=>{f.current&&!f.current.contains(e.target)&&(r(),x(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]);let g=(0,s.useCallback)(async e=>{d(e);try{await fetch("/api/services/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:"global",customCommands:e})})}catch(e){console.error("Failed to save global commands:",e)}},[]),b=(0,s.useCallback)(async t=>{m(t);try{await fetch("/api/services/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,customCommands:t})})}catch(e){console.error("Failed to save project commands:",e)}},[e]),v=(0,s.useCallback)(e=>{r();let t=rc(e);t?l?.(t.type,e.trim()):a(e)},[r,a,l]);return t?(0,n.jsxs)("div",{ref:f,className:"absolute bottom-full left-0 mb-2 w-72 bg-popover border border-border rounded-lg shadow-lg z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(nn,{label:i("console.globalCommands"),commands:c,isAdding:"global"===h,onStartAdd:()=>x("global"),onAdd:(e,t)=>{g([...c,{name:e,command:t}]),x(null)},onCancelAdd:()=>x(null),onDelete:e=>g(c.filter((t,r)=>r!==e)),onExecute:v}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(nn,{label:i("console.projectCommands"),commands:u,isAdding:"project"===h,onStartAdd:()=>x("project"),onAdd:(e,t)=>{b([...u,{name:e,command:t}]),x(null)},onCancelAdd:()=>x(null),onDelete:e=>b(u.filter((t,r)=>r!==e)),onExecute:v})]}):null}function no({cwd:e,currentCwd:t,commandHistoryRef:r,gridLayout:a,onGridLayoutChange:l,onExecute:i,onAddPluginItem:c,onShowEnvManager:d,onOpenZsh:u,onOpenNote:m}){let{t:h}=(0,o.Bd)(),[x,f]=(0,s.useState)(""),[p,g]=(0,s.useState)(-1),[b,v]=(0,s.useState)(""),[j,y]=(0,s.useState)([]),[w,k]=(0,s.useState)(0),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(!1),[M,E]=(0,s.useState)([]),[$,T]=(0,s.useState)(!1),[R,P]=(0,s.useState)(0),I=(0,s.useRef)(null),B=(0,s.useRef)(null),F=(0,s.useRef)(!1),{projectCommands:D,globalCommands:O,expandCustomCommand:A,loadQuickCommands:_}=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)([]),a=(0,s.useCallback)(async()=>{try{let[t,n]=await Promise.all([fetch(`/api/services/config?cwd=${encodeURIComponent(e)}`),fetch("/api/services/config?scope=global")]);if(t.ok){let e=await t.json();r(e.customCommands||[])}if(n.ok){let e=await n.json();o(e.customCommands||[])}}catch{}},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>a())},[a]);let l=[...t,...n],i=(0,s.useCallback)(e=>{let r=e.trim().split(/\s+/),s=r[0];if(!s.startsWith("/")||s.length<=1)return null;let o=s.slice(1),a=t.find(e=>e.name===o)??n.find(e=>e.name===o);return a?a.command+(r.length>1?" "+r.slice(1).join(" "):""):null},[t,n]);return{quickCustomCommands:l,projectCommands:t,globalCommands:n,expandCustomCommand:i,loadQuickCommands:a}}(e);(0,s.useEffect)(()=>{I.current?.focus()},[]),(0,s.useEffect)(()=>{if(x.startsWith("/")){let e=x.slice(1).toLowerCase(),t=[...D.filter(t=>t.name.toLowerCase().startsWith(e)).map(e=>({...e,scope:"project"})),...O.filter(t=>t.name.toLowerCase().startsWith(e)).map(e=>({...e,scope:"global"}))];queueMicrotask(()=>{E(t),T(t.length>0),P(0)})}else queueMicrotask(()=>T(!1))},[x,D,O]),(0,s.useEffect)(()=>{if($&&B.current){let e=B.current.children[R];e?.scrollIntoView({block:"nearest"})}},[R,$]);let W=(0,s.useCallback)(e=>{T(!1);let t=e.command,r=rc(t);r?c?.(r.type,t.trim()):i(t),f("")},[i,c]),q=(0,s.useCallback)(e=>{if(e.preventDefault(),F.current||!x.trim())return;let t=A(x)??x,r=rc(t);r?c?.(r.type,t.trim()):i(t),f(""),g(-1),v("")},[x,i,c,A]),z=(0,s.useCallback)(async()=>{if(!I.current)return;let e=I.current.selectionStart||0;try{let r=await fetch("/api/terminal/autocomplete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,input:x,cursorPosition:e})});if(r.ok){let e=await r.json();if(e.suggestions&&e.suggestions.length>0&&(y(e.suggestions),k(0),C(!0),1===e.suggestions.length)){let t=x.substring(0,e.replaceStart),r=x.substring(e.replaceEnd),n=t+e.suggestions[0]+r;f(n),C(!1),setTimeout(()=>{if(I.current){let t=e.replaceStart+e.suggestions[0].length;I.current.setSelectionRange(t,t)}},0)}}}catch(e){console.error("Autocomplete error:",e)}},[t,x]),H=(0,s.useCallback)(e=>{if(!I.current)return;let t=I.current.selectionStart||0,r=x.substring(0,t),n=x.substring(t),s=r.split(/\s+/),o=t-(s[s.length-1]||"").length;f(x.substring(0,o)+e+n),C(!1),setTimeout(()=>{if(I.current){let t=o+e.length;I.current.setSelectionRange(t,t)}},0)},[x]),U=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing)return;if($&&M.length>0){if("ArrowUp"===e.key){e.preventDefault(),P(e=>(e-1+M.length)%M.length);return}if("ArrowDown"===e.key){e.preventDefault(),P(e=>(e+1)%M.length);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),W(M[R]);return}if("Escape"===e.key){e.preventDefault(),T(!1);return}}if("Tab"===e.key){if(e.preventDefault(),N&&j.length>0){let e=(w+1)%j.length;k(e),H(j[e])}else z();return}if("Escape"===e.key&&N){e.preventDefault(),C(!1);return}let t=r.current;if(t&&0!==t.length){if("ArrowUp"===e.key){e.preventDefault(),-1===p&&v(x);let r=-1===p?t.length-1:Math.max(0,p-1);g(r),f(t[r])}else if("ArrowDown"===e.key){if(e.preventDefault(),-1===p)return;let r=p+1;r>=t.length?(g(-1),f(b)):(g(r),f(t[r]))}}},[p,x,b,N,j,w,z,H,$,M,R,W,r]);return(0,n.jsx)("div",{className:"border-t border-border p-4",children:(0,n.jsxs)("form",{onSubmit:q,className:"relative flex gap-2 items-center",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{S||_(),L(!S)},className:`p-2 rounded-lg transition-all ${S?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:h("console.quickCommands"),children:(0,n.jsx)(tV.A,{className:"w-4 h-4"})}),(0,n.jsx)(ns,{cwd:e,show:S,onClose:()=>L(!1),onExecute:i,onAddPluginItem:c})]}),m&&(0,n.jsx)("button",{type:"button",onClick:m,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:h("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsx)("button",{type:"button",onClick:()=>l(!a),className:`p-2 rounded-lg transition-all ${a?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:a?h("console.singleColumn"):h("console.dualColumn"),children:a?(0,n.jsx)(tK.A,{className:"w-4 h-4"}):(0,n.jsx)(tJ.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{type:"button",onClick:d,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:h("console.envVars"),children:(0,n.jsx)(tQ.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{type:"button",onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:h("console.launchZsh"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}),(0,n.jsx)("input",{ref:I,type:"text",value:x,onChange:e=>{f(e.target.value),-1!==p&&(g(-1),v("")),C(!1)},onKeyDown:U,onCompositionStart:()=>{F.current=!0},onCompositionEnd:()=>{F.current=!1},placeholder:h("console.inputPlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm focus:outline-none focus:ring-2 focus:ring-ring font-mono"}),$&&M.length>0&&(0,n.jsx)("div",{ref:B,className:"absolute bottom-full left-0 right-0 mb-1 max-h-64 overflow-y-auto bg-popover border border-border rounded-lg shadow-lg z-50",children:M.map((e,t)=>(0,n.jsxs)("div",{onClick:()=>W(e),className:`flex items-center gap-3 px-3 py-1.5 cursor-pointer text-sm ${t===R?"bg-brand/10":"hover:bg-accent"}`,children:[(0,n.jsxs)("span",{className:"font-mono font-medium text-foreground",children:["/",e.name]}),(0,n.jsx)("span",{className:"flex-1 text-muted-foreground truncate",children:e.command}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/60 flex-shrink-0",children:"project"===e.scope?h("console.scopeProject"):h("console.scopeGlobal")})]},`${e.scope}-${e.name}`))}),N&&j.length>1&&(0,n.jsxs)("div",{className:"absolute bottom-full left-0 mb-1 bg-popover border border-border rounded-lg shadow-lg max-h-48 overflow-y-auto z-50",children:[(0,n.jsx)("div",{className:"py-1",children:j.map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>H(e),className:`w-full px-3 py-1.5 text-left text-sm font-mono hover:bg-accent transition-colors ${t===w?"bg-accent":""}`,children:e},t))}),(0,n.jsx)("div",{className:"border-t border-border px-3 py-1 text-xs text-muted-foreground",children:h("console.tabSwitchEscClose")})]})]})})}function na({showTop:e,showBottom:t,onScrollTop:r,onScrollBottom:s}){let{t:a}=(0,o.Bd)();return(0,n.jsxs)(n.Fragment,{children:[e&&(0,n.jsx)("button",{onClick:r,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95 z-10",title:a("chat.jumpToStart"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),t&&(0,n.jsx)("button",{onClick:s,className:"absolute bottom-20 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95 z-10",title:a("chat.jumpToLatest"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]})}function nl({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a,onOpenNote:l}){let{t:i}=(0,o.Bd)(),{consoleItems:c,scrollRef:d,selectedCommandId:u,setSelectedCommandId:m,interruptCommand:h,sendStdin:x,deleteCommand:f,rerunCommand:p,ptySizeRef:g,resizePty:b,executeCommand:v,addPluginItem:j,closePluginItem:y,sleepingBubbles:w,handleBubbleSleep:k,handleBubbleWake:N,scrollToBottom:C,currentCwd:S,commandHistoryRef:L,setCustomEnv:M,setAliases:E,saveBubbleOrder:$,hasMoreHistory:T,loadHistory:R,currentPage:P,isLoadingHistory:I,subscribePtyOutput:B,subscribePtyReset:F}=function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:n}){let[o,a]=(0,s.useState)([]),[l,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(new Set),[u,m]=(0,s.useState)(t||e),[h,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(0),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)({}),[k,N]=(0,s.useState)({}),[C,S]=(0,s.useState)(null),L=(0,s.useRef)(null),M=(0,s.useRef)(new Map),E=(0,s.useRef)(new Map),$=(0,s.useRef)(new Set),T=(0,s.useRef)([]),R=(0,s.useRef)(new Map),P=(0,s.useRef)(new Map),I=(0,s.useRef)(new Map),B=(0,s.useRef)(null),F=(0,s.useRef)(null),D=(0,s.useRef)([]),O=(0,s.useRef)(null);(0,s.useEffect)(()=>{n?.(e)},[]);let A=(0,s.useCallback)(()=>{if(M.current.size>0){let e=new Map(M.current);M.current.clear(),a(t=>t.map(t=>{let r=e.get(t.id);return void 0!==r?{...t,output:r}:t}))}L.current=null},[]),_=(0,s.useCallback)((e,t)=>{if($.current.has(e)){let r=P.current.get(e);if(r&&r.size>0)for(let e of r)e(t);else I.current.has(e)||I.current.set(e,[]),I.current.get(e).push(t);return}let r=(E.current.get(e)||"")+t;if(r.length>2097152){let t=function(e){let t=e.slice(-2097152),r=0;if(t.length>0){let e=t.charCodeAt(0);e>=56320&&e<=57343&&(r=1)}let n=Math.min(t.length,64);for(let e=r;e<n;e++){let n=t.charCodeAt(e);if(27===n){r=e;break}if((!(n>=48)||!(n<=63))&&59!==n&&63!==n&&32!==n){n>=64&&n<=126&&(r=e+1);break}}return r>0?t.slice(r):t}(r);E.current.set(e,t),M.current.set(e,t)}else E.current.set(e,r),M.current.set(e,r);null===L.current&&(L.current=requestAnimationFrame(A))},[A]),W=(0,s.useCallback)((e,t=!1)=>{E.current.delete(e),$.current.delete(e),M.current.delete(e),I.current.delete(e),t||(P.current.delete(e),z.current.delete(e))},[]),q=(0,s.useCallback)((e,t)=>{P.current.has(e)||P.current.set(e,new Set),P.current.get(e).add(t);let r=I.current.get(e);if(r&&r.length>0){for(let e of r)t(e);I.current.delete(e)}return()=>{P.current.get(e)?.delete(t)}},[]),z=(0,s.useRef)(new Map),H=(0,s.useCallback)((e,t)=>(z.current.has(e)||z.current.set(e,new Set),z.current.get(e).add(t),()=>{z.current.get(e)?.delete(t)}),[]),U=(0,s.useCallback)(e=>(null!==L.current&&(cancelAnimationFrame(L.current),L.current=null),A(),E.current.get(e)||""),[A]),V=(0,s.useCallback)(()=>{O.current&&(O.current.scrollTop=O.current.scrollHeight)},[]),K=(0,s.useCallback)(async(t=0)=>{if(r){x(!0);try{let n=await fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&page=${t}&pageSize=100`);if(n.ok){let e=await n.json(),r=[],s=[],o=new Set;for(let t of e.entries){let e=ri(t.type);if(e){let r=e.fromHistory(t);s.push({id:t.id,_type:t.type,timestamp:t.timestamp,...r}),t.sleeping&&o.add(t.id)}else{if(t.running)continue;r.push({id:t.id.includes("-")&&3===t.id.split("-").length?t.id:ne(),command:t.command,output:t.output,exitCode:t.exitCode,isRunning:!1,timestamp:t.timestamp,cwd:t.cwd,usePty:t.usePty})}}0===t?(a(r),i(s),o.size>0&&d(o)):(a(e=>{let t=new Set(e.map(e=>e.id)),n=r.filter(e=>!t.has(e.id));return[...e,...n]}),i(e=>{let t=new Set(e.map(e=>e.id)),r=s.filter(e=>!t.has(e.id));return[...e,...r]})),p(e.hasMore),b(t)}}catch(e){console.error("Failed to load history:",e)}finally{x(!1)}}},[e,r]),J=(0,s.useCallback)(async t=>{if(r)try{await fetch("/api/terminal/history",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,entry:{id:t.id,command:t.command,output:t.output,exitCode:t.exitCode,timestamp:t.timestamp,cwd:u}})})}catch(e){console.error("Failed to save cd history:",e)}},[e,r,u]),Q=(0,s.useCallback)(async t=>{try{let n=await (t4||(t4=rs(e)));if(t.current)return;for(let s of n){if(r&&s.tabId!==r)continue;if(t.current)break;let n=s.commandId;a(e=>e.find(e=>e.id===n)?e.map(e=>e.id===n?{...e,isRunning:!0,exitCode:void 0,pid:s.pid,...s.usePty?{usePty:!0}:{}}:e):[...e,{id:n,command:s.command,output:"",isRunning:!0,pid:s.pid,timestamp:s.timestamp,cwd:s.cwd,...s.usePty?{usePty:!0}:{}}]),E.current.set(n,""),s.usePty&&$.current.add(n),await re({commandId:n,projectCwd:e,onData:(e,t)=>{if("pid"===e);else if("stdout"===e||"stderr"===e)_(n,t.data);else if("exit"===e){let e=U(n);W(n),a(r=>r.map(r=>r.id===n?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:()=>{a(e=>e.map(e=>e.id===n&&e.isRunning?{...e,isRunning:!1}:e))}})}}catch{}},[e,r,_,U,W]),Y=(0,s.useCallback)(async t=>{let s,o=t.trim().split(/\s+/),l=o[0],i=t;k[l]&&(i=k[l]+(o.length>1?" "+o.slice(1).join(" "):""));let c=rc(i);if(c)return void F.current?.(c.type,i.trim());let d=ne(),h=new Date().toISOString(),x=(s=i.trim().split(/\s+/)[0],nt.has(s)),f={id:d,command:t,output:i!==t?`→ ${i}
|
|
18
|
-
`:"",isRunning:!0,timestamp:h,cwd:u,...x?{usePty:!0}:{}};if(a(e=>e.some(e=>e.id===d)?e:[...e,f]),j(d),E.current.set(d,f.output),x&&$.current.add(d),setTimeout(V,100),i.trim().startsWith("cd ")){let e=i.trim().substring(3).trim(),t=u;e.startsWith("/")?t=e:".."===e?t=u.split("/").slice(0,-1).join("/")||"/":"."!==e&&(t=`${u}/${e}`.replace(/\/+/g,"/")),m(t),n?.(t),a(e=>e.map(e=>{if(e.id===d){let r={...e,output:`Changed directory to: ${t}`,exitCode:0,isRunning:!1};return J(r),r}return e}));return}try{await t7({cwd:u,command:i,commandId:d,tabId:r||"",projectCwd:e,env:y,usePty:x,onData:(e,t)=>{if("pid"===e)a(e=>e.map(e=>e.id===d?{...e,pid:t.pid}:e));else if("stdout"===e||"stderr"===e)_(d,t.data);else if("exit"===e){let e=U(d);W(d),a(r=>r.map(r=>r.id===d?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:e=>{let t=U(d);W(d),a(r=>r.map(r=>r.id===d?{...r,output:t+`
|
|
19
|
-
Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:r))}})}catch(t){let e=U(d);W(d),a(r=>r.map(r=>r.id===d?{...r,output:e+`
|
|
20
|
-
Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[k,u,y,r,e,_,U,W,V,n,J]),X=(0,s.useCallback)(e=>{let t=o.find(t=>t.id===e);t?.isRunning&&t.pid&&rn(t.pid)},[o]),G=(0,s.useCallback)(async t=>{let n=o.find(e=>e.id===t);if(!n)return;n.isRunning&&n.pid&&(rn(n.pid),await new Promise(e=>setTimeout(e,200)));let s=n.command.trim().split(/\s+/),l=s[0],i=n.command;k[l]&&(i=k[l]+(s.length>1?" "+s.slice(1).join(" "):""));let c=n.usePty||!1;if(c){let e=z.current.get(t);if(e)for(let t of e)t()}W(t,c);let d=i!==n.command?`→ ${i}
|
|
21
|
-
`:"";c||E.current.set(t,d),c&&$.current.add(t),a(e=>e.map(e=>e.id===t?{...e,output:c?"":d,exitCode:void 0,isRunning:!0,pid:void 0}:e));let m=R.current.get(t);try{await t7({cwd:n.cwd||u,command:i,commandId:t,tabId:r||"",projectCwd:e,env:y,usePty:c,...c&&m?{cols:m.cols,rows:m.rows}:{},onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid}:e));else if("stdout"===e||"stderr"===e)_(t,r.data);else if("exit"===e){let e=U(t);W(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:e=>{let r=U(t);W(t),a(n=>n.map(n=>n.id===t?{...n,output:r+`
|
|
22
|
-
Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=U(t);W(t),a(n=>n.map(n=>n.id===t?{...n,output:e+`
|
|
23
|
-
Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,k,u,y,r,e,_,U,W]),Z=(0,s.useCallback)(async t=>{if(a(e=>e.filter(e=>e.id!==t)),W(t),r)try{await fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&commandId=${encodeURIComponent(t)}`,{method:"DELETE"})}catch(e){console.error("Failed to delete command:",e)}},[e,r,W]),ee=(0,s.useCallback)((t,n,s)=>{var o;let a=ri(t);if(!a)return;let l=a.parse(n);"cwd"in l&&!l.cwd&&(l.cwd=u);let c={id:(o=a.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...l};if(i(e=>[...e,c]),j(c.id),setTimeout(V,100),s){let t=C&&C.length>0?[...C]:D.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,c.id):t.push(c.id),S(t),r&&fetch("/api/terminal/bubble-order",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,order:t})}).catch(()=>{})}if(r){let n=a.toHistory(c);fetch("/api/terminal/history",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,entry:{type:t,id:c.id,timestamp:c.timestamp,...n}})}).catch(e=>console.error(`Failed to save ${t} item:`,e))}},[V,e,r,C]),et=(0,s.useCallback)(async t=>{let n=l.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),j(e=>e===t?null:e),d(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=ri(n._type);e?.onClose?.(n)}r&&fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&commandId=${encodeURIComponent(t)}`,{method:"DELETE"}).catch(e=>console.error("Failed to delete plugin item:",e))},[l,e,r]);F.current=ee,B.current=Y;let er=(0,s.useCallback)((t,n)=>{r&&fetch("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,id:t,fields:{sleeping:n}})}).catch(()=>{})},[e,r]),en=(0,s.useCallback)(e=>{d(t=>new Set(t).add(e)),er(e,!0)},[er]),es=(0,s.useCallback)(e=>{d(t=>{let r=new Set(t);return r.delete(e),r}),er(e,!1)},[er]),eo=(0,s.useCallback)(async t=>{if(S(t),r)try{await fetch("/api/terminal/bubble-order",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,order:t})})}catch{}},[e,r]),ea=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...l.map(e=>({type:e._type,data:e}))];if(!C||0===C.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(C.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,l,C]);D.current=ea,(0,s.useEffect)(()=>{T.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let el=async()=>{try{let t=new URLSearchParams({cwd:e});r&&t.set("tabId",r);let n=await fetch(`/api/terminal/env?${t}`);if(n.ok){let e=await n.json();w(e.env||{})}}catch(e){console.error("Failed to load env:",e)}},ei=async()=>{try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();N(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}},ec=async()=>{if(r)try{let t=await fetch(`/api/terminal/bubble-order?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}`);if(t.ok){let e=await t.json();e.order&&e.order.length>0&&S(e.order)}}catch{}};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await K(0),e.current||await Q(e)})(),el(),ei(),ec(),()=>{e.current=!0}},[K,Q]),(0,s.useEffect)(()=>()=>{null!==L.current&&cancelAnimationFrame(L.current)},[]),(0,s.useEffect)(()=>()=>{ro()},[]),{commands:o,pluginItems:l,sleepingBubbles:c,consoleItems:ea,currentCwd:u,selectedCommandId:v,setSelectedCommandId:j,customEnv:y,setCustomEnv:w,aliases:k,setAliases:N,isLoadingHistory:h,hasMoreHistory:f,currentPage:g,scrollRef:O,commandHistoryRef:T,ptySizeRef:R,executeCommandRef:B,executeCommand:Y,interruptCommand:X,rerunCommand:G,deleteCommand:Z,addPluginItem:ee,closePluginItem:et,handleBubbleSleep:en,handleBubbleWake:es,loadHistory:K,scrollToBottom:V,saveBubbleOrder:eo,sendStdin:rt,resizePty:rr,subscribePtyOutput:q,subscribePtyReset:H}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[D,O]=(0,s.useState)(null),[A,_]=(0,s.useState)(0),[W,q]=(0,s.useState)(0),[z,H]=(0,s.useState)(!0),[U,V]=(0,s.useState)(!1),[K,J]=(0,s.useState)(!1),[Q,Y]=(0,s.useState)(!1),[X,G]=(0,s.useState)(!1),Z=(0,s.useRef)(null),ee=(0,s.useRef)(null),et=(0,s.useRef)(null),er=(0,s.useRef)(!1),en=(0,s.useRef)(null),es=(0,s.useRef)(null),eo=(0,s.useRef)([]);(0,s.useEffect)(()=>{eo.current=c},[c]);let ea=(0,s.useCallback)(()=>{let e=d.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[d]),el=(0,s.useCallback)(()=>{let e=d.current;return!e||e.scrollTop<50},[d]),ei=(0,s.useCallback)(()=>{Y(!el()),G(!ea())},[ea,el]),ec=(0,s.useCallback)(()=>{ee.current?.scrollIntoView({behavior:"smooth"})},[]),ed=async()=>{try{let t=await fetch(`/api/project-settings?cwd=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json();e.settings?.gridLayout!==void 0&&H(e.settings.gridLayout)}}catch(e){console.error("Failed to load project settings:",e)}},eu=async t=>{try{await fetch("/api/project-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,settings:t})})}catch(e){console.error("Failed to save project settings:",e)}};(0,s.useEffect)(()=>{queueMicrotask(()=>ed())},[]);let em=(0,s.useCallback)(()=>{er.current=!0},[]),eh=(0,s.useCallback)((e,t)=>{if(!er.current)return void e.preventDefault();er.current=!1,en.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:var(--card);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),ex=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",es.current=t},[]),ef=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ep=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),eg=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),eb=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=en.current,r=es.current;if(en.current=null,es.current=null,!t||!r||t===r)return;let n=eo.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let a=[...n];a[s]=r,a[o]=t,$(a)},[$]),ev=(0,s.useCallback)(e=>{O(t=>t===e?null:e)},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),u&&ev(u))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[u,ev]),(0,s.useEffect)(()=>{let e=d.current;if(!e)return;let t=new ResizeObserver(([e])=>{q(e.contentRect.height)});return t.observe(e),q(e.clientHeight),()=>t.disconnect()},[d]),(0,s.useEffect)(()=>{let e=d.current;if(e)return D?_(e.clientHeight):(e.style.overflow="",_(0)),()=>{e&&(e.style.overflow="")}},[D,d]),(0,s.useEffect)(()=>{let e=d.current;if(!e||!D||!A)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${D}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[D,A,d]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&v(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[v]);let ej=W>0?Math.floor((W-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:Z,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:d,onScroll:ei,className:`flex-1 overflow-y-auto ${D?"":"py-4 px-4"}`,children:0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:i("console.enterCommandOrUrl")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:ee}),T&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>R(P+1),disabled:I,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors disabled:opacity-50",children:i(I?"console.loadingMore":"console.loadMoreHistory")})}),(0,n.jsx)("div",{className:D?"flex flex-col gap-3":z?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:c.map(t=>{let s={draggable:!0,onDragStart:e=>eh(e,t.data.id),onDragOver:e=>ex(e,t.data.id),onDragEnter:ef,onDragLeave:ep,onDrop:eg,onDragEnd:eb};if("command"===t.type){let o=t.data;return(0,n.jsx)("div",{"data-bubble-id":o.id,className:"group/cmd rounded-lg transition-shadow",...s,children:(0,n.jsx)(t_,{commandId:o.id,tabId:r,projectCwd:e,command:o.command,output:o.output,exitCode:o.exitCode,isRunning:o.isRunning,selected:u===o.id,onSelect:()=>{m(o.id)},onInterrupt:o.isRunning?()=>h(o.id):void 0,onStdin:o.isRunning?e=>x(o.id,e):void 0,onDelete:()=>{o.isRunning&&o.pid&&rn(o.pid),f(o.id)},onRerun:()=>p(o.id),timestamp:o.timestamp,usePty:o.usePty,subscribePtyOutput:o.usePty?B:void 0,subscribePtyReset:o.usePty?F:void 0,onPtyResize:(e,t)=>{g.current.set(o.id,{cols:e,rows:t}),b(o.id,e,t)},onToggleMaximize:()=>ev(o.id),maximized:D===o.id,expandedHeight:A,bubbleContentHeight:ej,onTitleMouseDown:em})},o.id)}let o=ri(t.type);if(!o)return null;let a=o.Component,l=t.data;return(0,n.jsx)("div",{"data-bubble-id":l.id,className:"rounded-lg transition-shadow",...s,children:(0,n.jsx)(a,{item:l,selected:u===l.id,maximized:D===l.id,expandedHeight:A,bubbleContentHeight:ej,timestamp:l.timestamp,onSelect:()=>{m(l.id)},onClose:()=>y(l.id),onToggleMaximize:()=>ev(l.id),onTitleMouseDown:em,extra:{addBrowserItem:(e,t)=>j("browser",e,t),initialSleeping:w.has(l.id),onSleep:k,onWake:N}})},l.id)})}),(0,n.jsx)("div",{ref:et})]})}),!D&&c.length>0&&(0,n.jsx)(na,{showTop:Q,showBottom:X,onScrollTop:ec,onScrollBottom:C}),(0,n.jsx)(no,{cwd:e,currentCwd:S,commandHistoryRef:L,gridLayout:z,onGridLayoutChange:e=>{H(e),eu({gridLayout:e})},onExecute:v,onAddPluginItem:j,onShowEnvManager:()=>V(!0),onOpenZsh:()=>v("zsh"),onOpenNote:l}),U&&(0,n.jsx)(tz,{cwd:e,tabId:r,onClose:()=>V(!1),onSave:e=>M(e)}),K&&(0,n.jsx)(tU,{onClose:()=>J(!1),onSave:e=>E(e)})]})}var ni=r(24750);let nc="review-last-viewed";function nd(){try{return JSON.parse(localStorage.getItem(nc)||"{}")}catch{return{}}}function nu(e,t){if(!e.lastCommentAt)return!1;let r=t[e.id];return!r||e.lastCommentAt>r}function nm({cwd:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)({}),[f,p]=(0,s.useState)({open:!1,comments:[],title:"",userNameMap:{}}),g=(0,s.useRef)(null),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null);(0,s.useEffect)(()=>{queueMicrotask(()=>x(nd()))},[]),(0,s.useEffect)(()=>{if(!r)return;let e=e=>{g.current&&!g.current.contains(e.target)&&a(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let y=(0,s.useCallback)(async()=>{d(!0);try{let e=await fetch("/api/review");if(e.ok){let t=await e.json();i(t.reviews||[])}}catch{}d(!1)},[]);(0,s.useEffect)(()=>{r&&queueMicrotask(()=>y())},[r,y]);let w=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"review"===e.type)&&y()},[y]);(0,eu.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"/")}`,onMessage:w,enabled:!!e}),(0,s.useEffect)(()=>{queueMicrotask(()=>y())},[y]);let k=(0,s.useMemo)(()=>l.filter(e=>e.active),[l]),N=(0,s.useMemo)(()=>k.some(e=>nu(e,h)),[k,h]),C=(0,s.useCallback)(e=>{let t;(t=nd())[e]=Date.now(),localStorage.setItem(nc,JSON.stringify(t)),x(nd()),window.open(`${window.location.origin}/review/${e}`,"_blank")},[]),S=(0,s.useCallback)(async(e,t)=>{e.stopPropagation();try{let[e,r]=await Promise.all([fetch(`/api/review/${t}`),fetch("/api/review/users")]);if(!e.ok)return;let{review:n}=await e.json(),s={};if(r.ok){let{users:e}=await r.json();for(let[t,r]of Object.entries(e))s[t]=r.name}p({open:!0,comments:n.comments||[],title:n.title,userNameMap:s})}catch{}},[]),L=(0,s.useCallback)((e,t)=>{b.current=t,e.dataTransfer.effectAllowed="move";let r=e.currentTarget;requestAnimationFrame(()=>r.classList.add("opacity-30"))},[]),M=(0,s.useCallback)(e=>{b.current=null,j(null),e.currentTarget instanceof HTMLElement&&e.currentTarget.classList.remove("opacity-30")},[]),E=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",b.current&&b.current!==t&&j(t)},[]),$=(0,s.useCallback)((e,t)=>{e.preventDefault(),j(null);let r=b.current;b.current=null,r&&r!==t&&i(e=>{let n=[...e],s=n.findIndex(e=>e.id===r),o=n.findIndex(e=>e.id===t);if(-1===s||-1===o)return e;let[a]=n.splice(s,1);return n.splice(o,0,a),fetch("/api/review/order",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:n.map(e=>e.id)})}).catch(()=>{}),n})},[]);return(0,n.jsxs)("div",{ref:g,className:"relative",children:[(0,n.jsxs)("button",{onClick:()=>a(e=>!e),className:`relative p-2 rounded-lg transition-colors ${r?"text-foreground bg-accent":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:t("review.reviewManagement"),children:[(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})}),N&&(0,n.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]}),r&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 w-64 bg-popover border border-border rounded-lg shadow-xl z-50 overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:t("review.allReviews")}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground/60 ml-1.5",children:k.length})]}),(0,n.jsx)("button",{onClick:y,className:"p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",title:t("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),(0,n.jsx)("div",{className:"max-h-80 overflow-y-auto",children:c&&0===l.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-muted-foreground/50 text-center",children:t("common.loading")}):0===k.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-muted-foreground/50 text-center",children:t("review.noOpenReviews")}):k.map(e=>{let r,s,o,a,l,i=nu(e,h);return(0,n.jsxs)("div",{draggable:!0,onDragStart:t=>L(t,e.id),onDragEnd:M,onDragOver:t=>E(t,e.id),onDrop:t=>$(t,e.id),onMouseEnter:t=>{let r=t.currentTarget.getBoundingClientRect();m({id:e.id,text:e.title,top:r.top+r.height/2,left:r.left})},onMouseLeave:()=>m(t=>t?.id===e.id?null:t),onClick:()=>C(e.id),className:`group px-3 py-2 cursor-pointer border-b transition-colors ${v===e.id?"border-b-brand border-t border-t-transparent":"border-b-border/50"} hover:bg-accent/30`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${i?"bg-red-500":"bg-green-500"}`}),(0,n.jsx)("span",{className:`text-xs truncate flex-1 ${i?"font-medium text-foreground":""}`,children:e.title}),e.commentCount>0&&(0,n.jsx)("button",{onClick:t=>S(t,e.id),className:"flex-shrink-0 p-0.5 rounded text-muted-foreground/0 group-hover:text-muted-foreground/60 hover:!text-brand hover:!bg-brand/10 transition-colors",title:t("review.viewComments"),children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground/50 mt-0.5 pl-3",children:[(0,n.jsx)("span",{children:(s=String((r=new Date(e.updatedAt||e.createdAt)).getMonth()+1).padStart(2,"0"),o=String(r.getDate()).padStart(2,"0"),a=String(r.getHours()).padStart(2,"0"),l=String(r.getMinutes()).padStart(2,"0"),`${s}-${o} ${a}:${l}`)}),e.commentCount>0&&(0,n.jsx)("span",{children:t("review.nComments",{count:e.commentCount})})]})]},e.id)})})]}),u&&r&&(0,n.jsx)("div",{className:"fixed z-[60] px-2 py-1 text-xs bg-popover text-popover-foreground border border-border rounded shadow-md whitespace-nowrap pointer-events-none",style:{top:u.top,left:u.left-8,transform:"translate(-100%, -50%)"},children:u.text}),(0,n.jsx)(ni._,{isOpen:f.open,onClose:()=>p(e=>({...e,open:!1})),comments:f.comments,reviewTitle:f.title,userNameMap:f.userNameMap})]})}function nh({cwd:e,currentBranch:t,onSwitched:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)([]),[u,m]=(0,s.useState)(!1),[h,x]=(0,s.useState)(!1),[f,g]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useCallback)(async()=>{m(!0);try{let t=await fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json(),r=[...e.local||[],...(e.remote||[]).filter(t=>!e.local.includes(t.replace(/^origin\//,"")))];d(r)}}catch{(0,p.oR)(a("toast.loadBranchFailed"),"error")}finally{m(!1)}},[e]),y=(0,s.useCallback)(()=>{i(!0),g(""),j()},[j]),w=(0,s.useCallback)(()=>{i(!1)},[]);(0,s.useEffect)(()=>{if(!l)return;let e=e=>{b.current&&!b.current.contains(e.target)&&w()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l,w]),(0,s.useEffect)(()=>{l&&setTimeout(()=>v.current?.focus(),50)},[l]);let k=async t=>{x(!0);try{let n=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"checkout",cwd:e,path:e,branch:t})});if(n.ok){let e=t.replace(/^origin\//,"");(0,p.oR)(a("toast.switchedToBranch",{branch:e}),"success"),w(),r()}else{let e=await n.json();(0,p.oR)(e.error||a("toast.switchBranchFailed"),"error")}}catch{(0,p.oR)(a("toast.switchBranchFailed"),"error")}finally{x(!1)}},N=c.filter(e=>e!==t&&e.toLowerCase().includes(f.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:b,children:[(0,n.jsx)("button",{onClick:l?w:y,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:a("git.switchBranch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})})}),l&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lg z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:v,type:"text",value:f,onChange:e=>g(e.target.value),placeholder:a("git.searchBranch"),className:"w-full px-2.5 py-1.5 text-sm bg-muted rounded border-none outline-none placeholder:text-muted-foreground",onKeyDown:e=>{"Escape"===e.key&&w()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:u?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:a("common.loading")}):0===N.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:f?a("git.noMatchingBranches"):a("git.noBranches")}):N.map(e=>(0,n.jsx)("button",{onClick:()=>k(e),disabled:h,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function nx({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:a,onOpenProjectSessions:l,onOpenAliasManager:i,onBranchSwitched:c}){let{t:d}=(0,o.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6 cursor-pointer",title:d("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,p.oR)(d("toast.copiedPageUrl"),"success")})}}),e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,p.oR)(d("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:d("tabManagerTopBar.copyDirPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}):(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"})]}),r&&e&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("button",{onClick:a,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"Git Worktrees",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 17h8m0 0l-4-4m4 4l-4 4M3 7v6a4 4 0 004 4h5"})}),(0,n.jsx)("span",{className:"text-sm",children:s||"main"})]}),(0,n.jsx)(nh,{cwd:e,currentBranch:s,onSwitched:()=>c?.()})]})]}),(0,n.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2",children:(0,n.jsx)(tN,{})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(nm,{cwd:e}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.refreshProject"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),e&&(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:async()=>{if(t?.cwd)try{await fetch("/api/open-vscode",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd})})}catch{}},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M17.583 2.213L12 7.393 6.417 2.213 1 6.17v11.66l5.417 3.957L12 16.607l5.583 5.18L23 17.83V6.17l-5.417-3.957zM6.417 17.83L3 15.33V8.67l3.417-2.5v11.66zm11.166 0V6.17L21 8.67v6.66l-3.417 2.5z"})})}),(0,n.jsx)("button",{onClick:async()=>{if(t?.cwd)try{await fetch("/api/open-cursor",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd})})}catch{}},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.openInCursor"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4.5 2L20.5 12L4.5 22V2Z"})})}),t?.sessionId&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t.sessionId}`;navigator.clipboard.writeText(e).then(()=>{(0,p.oR)(d("toast.copiedCommand",{command:e}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("chat.copyCommandTooltip",{sessionId:t.sessionId}),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.aliasesGlobal"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12h-6m-4 0a8 8 0 1116 0 8 8 0 01-16 0zm4 0h.01"})})}),(0,n.jsx)("button",{onClick:()=>window.parent.postMessage({type:"OPEN_TOKEN_STATS"},"*"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.tokenStats"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})}),(0,n.jsx)("button",{onClick:()=>window.open("https://surething.io?from=cockpit","_blank"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}function nf({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function np({onNewTab:e,onNewClaude2Tab:t,onNewCodexTab:r,onNewKimiTab:o,onNewOllamaTab:a,onNewDeepseekTab:l}){let[c,d]=(0,s.useState)(!1),u=(0,s.useRef)(null),m=(0,s.useRef)(null),[h,x]=(0,s.useState)({top:0,right:0}),f=(0,i.F2)();(0,s.useEffect)(()=>{if(!c)return;let e=e=>{m.current&&!m.current.contains(e.target)&&u.current&&!u.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c]);let p=n=>{d(!1),"claude2"===n?t?.():"codex"===n?r?.():"kimi"===n?o?.():"ollama"===n?a?.():"deepseek"===n?l?.():e()};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:u,onClick:()=>{if(!c&&u.current){let e=u.current.getBoundingClientRect(),t=f?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;x({top:e.bottom+4-n,right:s-(e.right-r)})}d(e=>!e)},className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"New tab",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),c&&(0,n.jsx)(i.ZL,{children:(0,n.jsxs)("div",{ref:m,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[140px]",style:{top:h.top,right:h.right},children:[(0,n.jsxs)("button",{onClick:()=>p("claude"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}),"Claude Code"]}),(0,n.jsxs)("button",{onClick:()=>p("claude2"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-orange-500 flex-shrink-0"}),"Claude 2"]}),(0,n.jsxs)("button",{onClick:()=>p("codex"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 flex-shrink-0"}),"OpenAI Codex"]}),(0,n.jsxs)("button",{onClick:()=>p("deepseek"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0"}),"Deepseek"]}),(0,n.jsxs)("button",{onClick:()=>p("kimi"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500 flex-shrink-0"}),"Kimi"]}),(0,n.jsxs)("button",{onClick:()=>p("ollama"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-violet-500 flex-shrink-0"}),"Ollama"]})]})})]})}function ng({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:a,isPinned:l,onTogglePin:i,onSwitchTab:c,onCloseTab:d,onNewTab:u,onNewClaude2Tab:m,onNewCodexTab:h,onNewKimiTab:x,onNewOllamaTab:f,onNewDeepseekTab:p,onDragStart:g,onDragOver:b,onDrop:v,onDragEnd:j}){let{t:y}=(0,o.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((o,u)=>(0,n.jsx)(e$.m,{content:o.title,delay:200,className:"flex-1 min-w-16 max-w-32",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>g(u),onDragOver:e=>b(e,u),onDrop:()=>v(u),onDragEnd:j,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg transition-colors ${o.id===t?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary"} ${s===u?"opacity-50":""} ${a===u?"border-l-2 border-brand":""}`,onClick:()=>c(o.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(nf,{number:u+1,isActive:o.id===t}),o.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!o.isLoading&&r.has(o.id)&&o.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),i&&l?.(o.id)&&!o.isLoading&&!(r.has(o.id)&&o.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i(o.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:y("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),i&&!l?.(o.id)&&!o.isLoading&&!(r.has(o.id)&&o.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i(o.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:y("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:o.title}),"claude2"===o.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-orange-500/15 text-orange-400 font-medium leading-relaxed",children:"C2"}),"codex"===o.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-emerald-500/15 text-emerald-400 font-medium leading-relaxed",children:"CX"}),"kimi"===o.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-blue-500/15 text-blue-400 font-medium leading-relaxed",children:"KM"}),"ollama"===o.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-violet-500/15 text-violet-400 font-medium leading-relaxed",children:"OL"}),"deepseek"===o.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-sky-500/15 text-sky-400 font-medium leading-relaxed",children:"DS"}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(o.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:y("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},o.id)),(0,n.jsx)(np,{onNewTab:u,onNewClaude2Tab:m,onNewCodexTab:h,onNewKimiTab:x,onNewOllamaTab:f,onNewDeepseekTab:p})]})})}var nb=r(12651),nv=r(81165),nj=r(16950),ny=r(11019),nw=r(12612);function nk({filePath:e}){let[t,r]=(0,s.useState)(null),[o,a]=(0,s.useState)(!0),[l,i]=(0,s.useState)(null),c=(0,s.useRef)(!1),d=V(e),u=U(e);return((0,s.useEffect)(()=>{u?a(!1):c.current||(c.current=!0,(async()=>{a(!0),i(null);try{let t=await fetch(`/api/file?path=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Failed to load file: ${t.statusText}`);let n=await t.json();r(n.content)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{a(!1),c.current=!1}})())},[e,u]),l)?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:l})}):o?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"Loading..."})}):U(e)?(0,n.jsx)(td,{absPath:e,className:"flex items-center justify-center h-full overflow-auto",imgClassName:"max-w-full max-h-full object-contain",alt:e.split("/").pop()||"image"}):t?d?(0,n.jsx)(nC,{content:t}):(0,n.jsx)(ee.Cv,{content:t,filePath:e,showLineNumbers:!0,showSearch:!0,className:"h-full"}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"No content"})})}let nN=[en.W];function nC({content:e}){let t=(0,s.useRef)(null);return(0,n.jsxs)("div",{className:"h-full flex",children:[(0,n.jsx)(es.l,{content:e,containerRef:t}),(0,n.jsx)("div",{ref:t,className:"flex-1 overflow-auto p-4",children:(0,n.jsx)(er.T,{content:e,rehypePlugins:nN})})]})}function nS({title:e,content:t,toolName:r,onClose:a}){let{t:l}=(0,o.Bd)(),c=function(e){try{return JSON.parse(e),!0}catch{return!1}}(t),d=function(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path&&"string"==typeof t.old_string&&"string"==typeof t.new_string)return t}catch{}return null}(t),u=function(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path)return t.file_path}catch{let t=e.trim();if(t.startsWith("/")&&!t.includes("\n")&&t.length<500)return t}return null}(t),m=!!d,h=!!u,[x,f]=(0,s.useState)(("Read"===r||"Write"===r)&&h?"file":m?"diff-unified":c?"readable":"json"),g=(0,s.useRef)(null),b=J(g);(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&"readable"===x&&c){e.preventDefault(),b.open();return}if("Escape"===e.key){if(b.isVisible)return void b.close();document.activeElement instanceof HTMLElement&&document.activeElement.blur(),a()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a,x,c,b]);let v=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:a,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:e}),u&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(u),(0,p.oR)(l("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:l("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[c&&(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[m&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>f("diff-split"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-split"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:l("diffViewer.sideBySide"),children:"Split"}),(0,n.jsx)("button",{onClick:()=>f("diff-unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-unified"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:l("diffViewer.unified"),children:"Unified"})]}),h&&(0,n.jsx)("button",{onClick:()=>f("file"),className:`px-2 py-1 text-xs rounded transition-colors ${"file"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:l("diffViewer.previewFile"),children:"File"}),(0,n.jsx)("button",{onClick:()=>f("readable"),className:`px-2 py-1 text-xs rounded transition-colors ${"readable"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:l("common.readable")}),(0,n.jsx)("button",{onClick:()=>f("json"),className:`px-2 py-1 text-xs rounded transition-colors ${"json"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"JSON"})]}),(0,n.jsx)("button",{onClick:a,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto p-4",children:"file"===x&&u?(0,n.jsx)(nk,{filePath:u}):"diff-unified"===x&&d?(0,n.jsx)(C,{oldContent:d.old_string,newContent:d.new_string,filePath:d.file_path}):"diff-split"===x&&d?(0,n.jsx)(N,{oldContent:d.old_string,newContent:d.new_string,filePath:d.file_path}):"readable"===x&&c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Q,{search:b}),(0,n.jsx)("pre",{ref:g,className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:F(t)})]}):(0,n.jsx)("pre",{className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:c?function(e){try{let t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}(t):t})})]})});return(0,n.jsx)(i.ZL,{children:v})}let nL={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D"};function nM({toolCall:e,cwd:t}){let r,{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),u=nL[e.name]||"\uD83D\uDD27",m=(r=e.input,"Bash"===e.name&&r.command&&"string"==typeof r.command?r.command:"Glob"===e.name&&r.pattern&&"string"==typeof r.pattern||"Grep"===e.name&&r.pattern&&"string"==typeof r.pattern?r.pattern:r.file_path&&"string"==typeof r.file_path?r.file_path:r.path&&"string"==typeof r.path?r.path:null),h="Glob"===e.name||"Grep"===e.name||"Bash"===e.name,x=m?h?m:(e=>{if(t&&e.startsWith(t)){let r=e.slice(t.length);return r.startsWith("/")?r.slice(1):r}let r=e.split("/");return r.length>2?".../"+r.slice(-2).join("/"):e})(m):null,f=t=>{let r="input"===t?a("toolCall.inputParams"):a("toolCall.resultLabel"),n="input"===t?JSON.stringify(e.input,null,2):"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2);d({title:`${e.name}${x?` ${x}`:""} - ${r}`,content:n,toolName:e.name})};return(0,n.jsxs)("div",{className:"my-2 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,n.jsxs)("button",{onClick:()=>i(!l),className:"w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,n.jsx)("span",{className:"text-base",children:u}),(0,n.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:e.name}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:m||"",children:x}),(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),m&&(navigator.clipboard.writeText(m),(0,p.oR)(a("common.copiedPath")))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),m&&(navigator.clipboard.writeText(m),(0,p.oR)(a("common.copiedPath"))))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0 cursor-pointer",title:a("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[l&&!e.isLoading&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f("input")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f("input"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("toolCall.inputParamsTitle"),children:a("toolCall.input")}),e.result&&(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f("result")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f("result"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("toolCall.resultTitle"),children:a("toolCall.result")})]}),e.isLoading?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:l?"▲":"▼"})]})]}),l&&(0,n.jsxs)("div",{className:"border-t border-border",children:[(0,n.jsxs)("div",{className:"px-3 py-2",children:[(0,n.jsx)("div",{className:"mb-1",children:(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.inputParams"),":"]})}),(0,n.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:JSON.stringify(e.input,null,2)})]}),e.result&&(0,n.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,n.jsx)("div",{className:"mb-1",children:(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.resultLabel"),":"]})}),(0,n.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2)})]})]}),c&&(0,n.jsx)(nS,{title:c.title,content:c.content,toolName:c.toolName,onClose:()=>d(null)})]})}var nE=r(21362);function n$(e,t){if(t&&e.startsWith(t)){let r=e.slice(t.length);return r.startsWith("/")?r.slice(1):r}return e}function nT({node:e,selectedUid:t,onSelect:r,depth:o=0}){let[a,l]=(0,s.useState)(!0);if(e.isFile&&e.change){let s=t===e.change.uid;return(0,n.jsxs)("button",{onClick:()=>r(e.change),className:`w-full flex items-center gap-1.5 px-2 py-1 text-xs text-left rounded transition-colors ${s?"bg-brand/15 text-brand":"text-foreground hover:bg-accent"}`,style:{paddingLeft:`${12*o+8}px`},"data-tooltip":e.fullPath,children:[(0,n.jsx)(ef.A,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-60"}),(0,n.jsx)("span",{className:"truncate",children:e.name}),(0,n.jsx)("span",{className:`ml-auto text-[10px] flex-shrink-0 ${"write"===e.change.type?"text-green-500":"text-yellow-500"}`,children:"write"===e.change.type?"new":"edit"})]})}return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{onClick:()=>l(!a),className:"w-full flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:text-foreground transition-colors",style:{paddingLeft:`${12*o+8}px`},children:[a?(0,n.jsx)(tT.A,{className:"w-3 h-3"}):(0,n.jsx)(nE.A,{className:"w-3 h-3"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]}),a&&e.children.map((e,s)=>(0,n.jsx)(nT,{node:e,selectedUid:t,onSelect:r,depth:o+1},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${s}`))]})}function nR({toolCalls:e,cwd:t,onClose:r}){let{t:a}=(0,o.Bd)(),l=(0,s.useMemo)(()=>(function(e,t){let r=[],n=0;for(let s of e)if("Edit"===s.name){let e=s.input;e.file_path&&"string"==typeof e.old_string&&"string"==typeof e.new_string&&r.push({filePath:n$(e.file_path,t),uid:`change-${n++}`,type:"edit",old_string:e.old_string,new_string:e.new_string})}else if("Write"===s.name){let e=s.input;e.file_path&&"string"==typeof e.content&&r.push({filePath:n$(e.file_path,t),uid:`change-${n++}`,type:"write",old_string:"",new_string:e.content})}return r})(e,t),[e,t]),c=(0,s.useMemo)(()=>(function e(t){return t.map(t=>{if(!t.isFile&&1===t.children.length&&!t.children[0].isFile){let r=t.children[0];return{...r,name:t.name+"/"+r.name,children:e(r.children)}}return{...t,children:e(t.children)}})})(function(e){let t=[];for(let r of e){let e=r.filePath.split("/").filter(Boolean),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,a=e.slice(0,t+1).join("/");if(o){let e={name:s,fullPath:a,isFile:!0,children:[],change:r};n.push(e)}else{let e=n.find(e=>e.name===s&&!e.isFile);e||(e={name:s,fullPath:a,isFile:!1,children:[]},n.push(e)),n=e.children}}}return t}(l)),[l]),[d,u]=(0,s.useState)(l[0]||null),[m,h]=(0,s.useState)("unified"),x=(0,s.useRef)(null);if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r]),0===l.length)return null;let f=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:r,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:a("diffViewer.fileChanges",{count:l.length})})}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[(0,n.jsx)("button",{onClick:()=>h("unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"unified"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Unified"}),(0,n.jsx)("button",{onClick:()=>h("split"),className:`px-2 py-1 text-xs rounded transition-colors ${"split"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Split"})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)(ex.A,{className:"w-5 h-5"})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{ref:x,className:"w-56 flex-shrink-0 border-r border-border overflow-y-auto py-2",children:c.map((e,t)=>(0,n.jsx)(nT,{node:e,selectedUid:d?.uid||"",onSelect:u},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${t}`))}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:d?"unified"===m?(0,n.jsx)(C,{oldContent:d.old_string,newContent:d.new_string,filePath:d.filePath}):(0,n.jsx)(N,{oldContent:d.old_string,newContent:d.new_string,filePath:d.filePath,isNew:"write"===d.type}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:a("diffViewer.selectFileToView")})})]})]})});return(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(i.ZL,{children:f})})}var nP=r(58515),nI=r(36201),nB=r(55804),nF=r(37618);function nD(e){let t=e.input?.questions||[],r=e.input?.answers||{},n={};if(e.result)try{let t=JSON.parse(e.result);t?.answers&&(n=t.answers)}catch{}return{questions:t,answers:{...r,...n}}}function nO(e,t){return`${e}-${t}`}function nA({toolCalls:e,onClose:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)({}),[c,d]=(0,s.useState)({}),[u,m]=(0,s.useState)({}),[h,x]=(0,s.useState)({});(0,s.useEffect)(()=>{let t={};e.forEach((e,r)=>{let{questions:n,answers:s}=nD(e);n.forEach((e,n)=>{let o=s[e.question];if(o){let s=nO(r,n);t[s]=o,e.options.some(e=>e.label===o)||(d(e=>({...e,[s]:!0})),m(e=>({...e,[s]:o})))}})}),queueMicrotask(()=>l(t))},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let f=e.reduce((e,t)=>{let{questions:r}=nD(t);return e+r.length},0),g=Object.values(h).filter(Boolean).length,b=(0,s.useCallback)((e,t)=>{l(r=>({...r,[e]:t})),d(t=>({...t,[e]:!1}))},[]),v=(0,s.useCallback)(e=>{d(t=>{let r=!t[e];if(r){let t=u[e]||"";t&&l(r=>({...r,[e]:t}))}return{...t,[e]:r}})},[u]),j=(0,s.useCallback)((e,t)=>{m(r=>({...r,[e]:t})),t&&l(r=>({...r,[e]:t}))},[]),y=(0,s.useCallback)(e=>{x(t=>({...t,[e]:!t[e]}))},[]),w=(0,s.useCallback)(()=>{let t=g>0,n=[];e.forEach((e,s)=>{let{questions:o}=nD(e);o.forEach((e,o)=>{let l=nO(s,o);if(t&&!h[l])return;let i=a[l];n.push(`Q: ${e.question}`),n.push(`A: ${i||r("askQuestion.notSelected")}`),n.push("")})}),navigator.clipboard.writeText(n.join("\n").trim()),(0,p.oR)(t?r("toast.copiedQA",{count:g}):r("toast.copiedAllQA"))},[e,a,h,g,r]),k=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:r("askQuestion.title")}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[r("askQuestion.nQuestions",{count:f}),g>0&&` \xb7 ${r("askQuestion.checkedN",{count:g})}`]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:w,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:g>0?r("askQuestion.copyChecked",{count:g}):r("askQuestion.copyAll"),children:(0,n.jsx)(tL.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)(ex.A,{className:"w-5 h-5"})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:e.map((t,s)=>{let{questions:o}=nD(t);return o.map((t,l)=>{let i=nO(s,l),d=a[i],m=c[i]||!1,x=h[i]||!1;return(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("button",{onClick:()=>y(i),className:"mt-0.5 flex-shrink-0 p-0.5 rounded hover:bg-accent transition-colors",title:r("askQuestion.checkToCopy"),children:x?(0,n.jsx)(nP.A,{className:"w-4 h-4 text-brand"}):(0,n.jsx)(nI.A,{className:"w-4 h-4 text-muted-foreground"})}),t.header&&(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-brand/10 text-brand flex-shrink-0 mt-0.5",children:t.header}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.question})]}),(0,n.jsxs)("div",{className:"space-y-1 ml-7",children:[t.options.map((e,t)=>{let r=d===e.label&&!m;return(0,n.jsxs)("button",{onClick:()=>b(i,e.label),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${r?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,n.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:r?(0,n.jsx)(nB.A,{className:"w-3.5 h-3.5 text-brand"}):(0,n.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:`text-sm ${r?"text-foreground font-medium":"text-foreground"}`,children:e.label}),e.description&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]})]},t)}),(0,n.jsxs)("button",{onClick:()=>v(i),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${m?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,n.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:m?(0,n.jsx)(nB.A,{className:"w-3.5 h-3.5 text-brand"}):(0,n.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(nF.A,{className:"w-3.5 h-3.5 text-muted-foreground"}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:r("askQuestion.custom")})]})]}),m&&(0,n.jsx)("div",{className:"ml-6 mt-1",children:(0,n.jsx)("input",{type:"text",autoFocus:!0,value:u[i]||"",onChange:e=>j(i,e.target.value),placeholder:r("askQuestion.customPlaceholder"),className:"w-full px-3 py-1.5 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-brand text-foreground placeholder:text-muted-foreground"})})]}),(s!==e.length-1||l!==o.length-1)&&(0,n.jsx)("div",{className:"border-b border-border/50 mt-3"})]},i)})})})]})});return(0,n.jsx)(i.ZL,{children:k})}function n_({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,n.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,n.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:r("chat.imagePreview"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(i.ZL,{children:s})}function nW({filePath:e,content:t,cwd:r,onClose:o}){let[a,l]=(0,s.useState)(null);return(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,n.jsx)("div",{ref:l,className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col relative",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(m.SU,{container:a,children:(0,n.jsx)(ei,{content:t,filePath:e,cwd:r,onClose:o})})})})})}let nq=(0,s.memo)(function({message:e,cwd:t,sessionId:r,onFork:a}){let l,i,c,d,{t:u}=(0,o.Bd)(),[m,h]=(0,s.useState)(null),[x,f]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),y="user"===e.role,w=e.images&&e.images.length>0,k=e.toolCalls?.length||0,N=k>1,C=!!r&&!!t&&!!a,S=(0,s.useMemo)(()=>e.toolCalls?.some(e=>"Edit"===e.name||"Write"===e.name)||!1,[e.toolCalls]),L=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("TodoWrite"===e.toolCalls[t].name)return e.toolCalls[t];return null},[e.toolCalls]),M=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),E=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=new Set,r=[];for(let n of e.toolCalls)if("Read"===n.name||"Edit"===n.name||"Write"===n.name){let e=n.input.file_path;e&&e.toLowerCase().endsWith(".md")&&!t.has(e)&&(t.add(e),r.push(e))}return r},[e.toolCalls]),$=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=[];for(let r of e.toolCalls){let e=r.input?.thought;if(e&&"string"==typeof e){let n=e.match(/PREVIOUS:\s*(.*?)\s*→\s*THIS:\s*(.*?)\s*→\s*EXPECT:\s*(.*)/i);n?t.push({previous:n[1].trim(),current:n[2].trim(),expect:n[3].trim(),raw:e,toolName:r.name}):t.push({previous:"",current:e,expect:"",raw:e,toolName:r.name})}}return t},[e.toolCalls]),[T,R]=(0,s.useState)(null),[P,I]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!T)return void queueMicrotask(()=>I(null));let e=!1;return fetch(`/api/file?path=${encodeURIComponent(T)}`).then(e=>e.ok?e.json():Promise.reject()).then(t=>{e||I(t.content)}).catch(()=>{e||((0,p.oR)(u("toast.readFileFailed"),"error"),R(null))}),()=>{e=!0}},[T]);let B=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,p.oR)(u("toast.copiedMessage")))},F=()=>{C&&a(e.id)},D=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(e.timestamp);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:`flex flex-col ${y?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[D&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:D}),(0,n.jsxs)("div",{className:`flex ${y?"justify-end":"justify-start"} w-full`,children:[y&&(0,n.jsxs)("div",{className:"self-start mt-2 mr-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,n.jsx)("button",{onClick:B,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.copyMessage"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),C&&(0,n.jsx)("button",{onClick:F,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.forkSession"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,n.jsx)("path",{d:"M12 12v3"})]})})]}),(0,n.jsxs)("div",{className:`max-w-[80%] ${y?"bg-accent text-foreground border border-brand rounded-2xl rounded-br-md":"bg-accent text-foreground dark:text-slate-11 rounded-2xl rounded-bl-md"} px-4 py-2`,children:[w&&(0,n.jsx)("div",{className:`flex flex-wrap gap-2 ${e.content?"mb-2":""}`,children:e.images.map((e,t)=>(0,n.jsx)("div",{className:"relative w-16 h-16 rounded-lg overflow-hidden border border-white/20 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>h(e),children:(0,n.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:u("chat.imageN",{index:t+1}),className:"w-full h-full object-cover"})},t))}),e.content&&(0,n.jsxs)("div",{className:"break-words",children:[(0,n.jsx)(er.T,{content:e.content,isUser:y,isStreaming:e.isStreaming,enableMath:!1}),e.isStreaming&&(0,n.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]}),L&&(c=(i=Array.isArray(l=L.input?.todos)?l:[]).filter(e=>"completed"===e.status).length,d=i.length,(0,n.jsx)("div",{className:`${e.content||w?"mt-2":""}`,children:(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,n.jsx)("div",{className:"flex-1 h-1 bg-secondary rounded-full overflow-hidden",children:(0,n.jsx)("div",{className:"h-full bg-green-500 rounded-full transition-all duration-300",style:{width:`${d>0?c/d*100:0}%`}})}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[c,"/",d]})]}),i.map((e,t)=>(0,n.jsxs)("div",{className:`flex items-center gap-1.5 ${"completed"===e.status?"opacity-50":""}`,children:["completed"===e.status?(0,n.jsx)(nb.A,{className:"w-3 h-3 text-green-500 flex-shrink-0"}):"in_progress"===e.status?(0,n.jsx)(nv.A,{className:"w-3 h-3 text-brand flex-shrink-0 animate-spin"}):(0,n.jsx)(nj.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs truncate ${"completed"===e.status?"text-muted-foreground":"text-foreground"}`,children:"in_progress"===e.status&&e.activeForm?e.activeForm:e.content})]},t))]})})),E.length>0&&(0,n.jsx)("div",{className:`${e.content||w||L?"mt-2":""}`,children:(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-0.5",children:E.map(e=>(0,n.jsxs)("button",{onClick:()=>R(e),className:"flex items-center gap-1.5 w-full text-left hover:bg-accent rounded px-1 py-0.5 transition-colors group/md",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover/md:text-foreground truncate",children:e.split("/").pop()})]},e))})}),$.length>0&&(0,n.jsx)("div",{className:`${e.content||w||L||E.length>0?"mt-2":""}`,children:(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50",children:(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"border-b border-border text-muted-foreground",children:[(0,n.jsx)("th",{className:"px-2 py-1.5 text-left font-medium w-[60px]",children:"Tool"}),(0,n.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Previous"}),(0,n.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Action"}),(0,n.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Expect"})]})}),(0,n.jsx)("tbody",{children:$.map((e,t)=>(0,n.jsxs)("tr",{className:t<$.length-1?"border-b border-border/50":"",children:[(0,n.jsx)("td",{className:"px-2 py-1 text-muted-foreground font-mono",children:e.toolName}),(0,n.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.previous||"—"}),(0,n.jsx)("td",{className:"px-2 py-1 text-foreground",children:e.current}),(0,n.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.expect||"—"})]},t))})]})})}),e.toolCalls&&e.toolCalls.length>0&&(0,n.jsx)("div",{className:`${e.content||w?"mt-2":""}`,children:N?(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center",children:[(0,n.jsxs)("button",{onClick:()=>f(!x),className:"flex-1 px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,n.jsx)("span",{className:"text-lg",children:"\uD83D\uDD27"}),(0,n.jsx)("span",{className:"font-medium text-foreground",children:u("chat.toolCalls",{count:k})}),(0,n.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:x?u("chat.collapse"):u("chat.expand")})]}),M.length>0&&(0,n.jsx)("button",{onClick:()=>j(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:u("chat.viewQuestions"),children:(0,n.jsx)(ny.A,{className:"w-4 h-4"})}),S&&(0,n.jsx)("button",{onClick:()=>b(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:u("chat.viewAllFileChanges"),children:(0,n.jsx)(nw.A,{className:"w-4 h-4"})})]}),x&&(0,n.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:e.toolCalls.map((e,r)=>(0,n.jsx)(nM,{toolCall:e,cwd:t},`${e.id}-${r}`))})]}):e.toolCalls.map((e,r)=>(0,n.jsx)(nM,{toolCall:e,cwd:t},`${e.id}-${r}`))})]}),!y&&(0,n.jsxs)("div",{className:"self-start mt-2 ml-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,n.jsx)("button",{onClick:B,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.copyMessage"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),C&&(0,n.jsx)("button",{onClick:F,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.forkSession"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,n.jsx)("path",{d:"M12 12v3"})]})})]})]})]}),m&&(0,n.jsx)(n_,{image:m,onClose:()=>h(null)}),g&&e.toolCalls&&(0,n.jsx)(nR,{toolCalls:e.toolCalls,cwd:t,onClose:()=>b(!1)}),v&&M.length>0&&(0,n.jsx)(nA,{toolCalls:M,onClose:()=>j(!1)}),T&&null!==P&&(0,n.jsx)(nW,{filePath:T,content:P,cwd:t||"",onClose:()=>R(null)})]})}),nz=(0,s.forwardRef)(function({messages:e,isLoading:t,cwd:r,sessionId:a,engine:l,apiRetryInfo:i,hasMoreHistory:c,isLoadingMore:m,onLoadMore:f,onFork:p,isActive:g=!0,onContentSearch:b},v){let{t:y}=(0,o.Bd)(),w=(0,s.useRef)(null),k=(0,s.useRef)(null),N=(0,s.useRef)(null),C=(0,s.useRef)(null),[S,L]=(0,s.useState)(null),[M,E]=(0,s.useState)(!0),[$,T]=(0,s.useState)(!1),[R,P]=(0,s.useState)(!1);(0,s.useEffect)(()=>{L(C.current)},[]);let{isSearchVisible:I,searchQuery:B,setSearchQuery:F,matches:D,currentMatchIndex:O,goToNextMatch:A,goToPrevMatch:_,closeSearch:W,searchInputRef:q,handleSearchKeyDown:z}=function(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[a,l]=(0,s.useState)([]),[i,c]=(0,s.useState)(0),d=(0,s.useRef)(null),u=(0,s.useRef)([]),m=(0,s.useCallback)(()=>{let t=e.current;t&&(t.querySelectorAll("mark.chat-search-match, mark.chat-search-current").forEach(e=>{let t=e.parentNode;t&&(t.replaceChild(document.createTextNode(e.textContent||""),e),t.normalize())}),u.current=[])},[e]),h=(0,s.useCallback)(t=>{if(m(),!t||!e.current){l([]),c(0);return}let r=[],n=[],s=t.toLowerCase();e.current.querySelectorAll("[data-message-id]").forEach(e=>{let o,a=e.getAttribute("data-message-id")||"",l=0,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),c=[];for(;o=i.nextNode();)c.push(o);for(let e of c){let o=(e.textContent||"").toLowerCase(),i=0,c=[];for(;;){let e=o.indexOf(s,i);if(-1===e)break;c.push({start:e,end:e+t.length}),i=e+1}if(0!==c.length)for(let t=c.length-1;t>=0;t--){let s=c[t];e.splitText(s.end);let o=e.splitText(s.start),i=document.createElement("mark");i.className="chat-search-match",i.textContent=o.textContent,o.parentNode.replaceChild(i,o),r.push({messageId:a,markIndex:l}),n.push(i),l++}}}),r.reverse(),n.reverse(),u.current=n,l(r),c(r.length>0?0:-1)},[e,m]);(0,s.useEffect)(()=>{queueMicrotask(()=>h(n))},[n,h]),(0,s.useEffect)(()=>{let e=u.current;e.forEach((e,t)=>{e.className=t===i?"chat-search-current":"chat-search-match"}),i>=0&&i<e.length&&e[i].scrollIntoView({behavior:"smooth",block:"center"})},[i,a]);let x=(0,s.useCallback)(()=>{0!==a.length&&c(e=>(e+1)%a.length)},[a.length]),f=(0,s.useCallback)(()=>{0!==a.length&&c(e=>(e-1+a.length)%a.length)},[a.length]),p=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>d.current?.focus(),0)},[]),g=(0,s.useCallback)(()=>{r(!1),o(""),m(),l([]),c(0)},[m]),b=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?f():x()),"Escape"===e.key&&g()},[x,f,g]);return(0,s.useEffect)(()=>{let t=e.current;if(!t)return;let r=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),e.stopPropagation(),p())};return t.addEventListener("keydown",r),()=>t.removeEventListener("keydown",r)},[e,p]),{isSearchVisible:t,searchQuery:n,setSearchQuery:o,matches:a,currentMatchIndex:i,goToNextMatch:x,goToPrevMatch:f,openSearch:p,closeSearch:g,searchInputRef:d,handleSearchKeyDown:b}}(C),H=(0,h.nH)(),U=(0,s.useRef)(null),V=(0,s.useRef)(()=>{}),{addComment:K,refresh:J}=(0,d._)({cwd:r||"",filePath:u.Un}),[Q,Y]=(0,s.useState)(null),[X,G]=(0,s.useState)(null),Z=(0,s.useCallback)(e=>{if(Q||X)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){U.current=null,V.current();return}let r=t.toString().trim();if(!r){U.current=null,V.current();return}let n=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(n?.closest('[data-role="user"]')){U.current=null,V.current();return}U.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:r},V.current()},[Q,X]),ee=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&U.current&&(U.current=null,V.current())},[]),et=(0,s.useCallback)(()=>{let e=U.current;e&&(Y({x:e.x,y:e.y,text:e.selectedText}),U.current=null,V.current(),window.getSelection()?.removeAllRanges())},[]),er=(0,s.useCallback)(()=>{let e=U.current;e&&(G({x:e.x,y:e.y,text:e.selectedText}),U.current=null,V.current(),window.getSelection()?.removeAllRanges())},[]),en=(0,s.useCallback)(()=>{let e=U.current;if(!e||!b)return;let t=e.selectedText.trim();U.current=null,V.current(),window.getSelection()?.removeAllRanges(),t&&b(t)},[b]),es=(0,s.useCallback)(async e=>{Q&&(await K(0,0,e,Q.text),Y(null))},[Q,K]),eo=(0,s.useCallback)(async e=>{if(X&&H&&r)try{let t=(await (0,u.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));t.push({filePath:u.Un,startLine:0,endLine:0,codeContent:X.text});let n=(0,u.Gw)(t,e);H.sendMessage(n),await (0,u.RP)(r),J(),G(null)}catch(e){console.error("Failed to send to AI:",e)}},[X,H,r,J]),ea=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},[e]),el=(0,s.useRef)(0),ei=(0,s.useRef)(!1),ec=(0,s.useCallback)(()=>{let e=N.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[]),ed=(0,s.useCallback)(()=>{let e=N.current;return!e||e.scrollTop<50},[]),eu=(0,s.useCallback)(()=>{let e=ec(),t=ed();if(E(e),T(!t),P(!e),t&&c&&!m&&f){let e=N.current;e&&(el.current=e.scrollHeight,ei.current=!0),f()}},[ec,ed,c,m,f]),em=(0,s.useCallback)(()=>{k.current?.scrollIntoView({behavior:"smooth"})},[]),eh=(0,s.useCallback)(()=>{w.current?.scrollIntoView({behavior:"smooth"})},[]),ex=(0,s.useCallback)(e=>{let t=N.current;if(!t)return;let r=t.querySelector(`[data-message-id="${e}"]`);r&&(r.scrollIntoView({behavior:"smooth",block:"center"}),r.classList.add("ring-2","ring-brand","ring-offset-2"),setTimeout(()=>{r.classList.remove("ring-2","ring-brand","ring-offset-2")},2e3))},[]);(0,s.useImperativeHandle)(v,()=>({scrollToMessage:ex}),[ex]);let ef=(0,s.useRef)(0),ep=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let t=ef.current,r=e.length;ef.current=r,!ep.current&&M&&r>t&&w.current?.scrollIntoView({behavior:"smooth"})},[e,M]),(0,s.useEffect)(()=>{M&&t&&w.current?.scrollIntoView({behavior:"smooth"})},[t,M]),(0,s.useEffect)(()=>{if(ei.current&&!m){let e=N.current;if(e){let t=e.scrollHeight-el.current;e.scrollTop=t,ei.current=!1}}},[e,m]);let eg=(0,s.useRef)(!1);return(0,s.useEffect)(()=>{g&&eg.current&&e.length>0&&(eg.current=!1,w.current?.scrollIntoView({behavior:"instant"}))},[g,e.length]),(0,s.useEffect)(()=>{ep.current&&e.length>0&&(ep.current=!1,g?w.current?.scrollIntoView({behavior:"instant"}):eg.current=!0)},[e.length,g]),(0,n.jsxs)("div",{ref:C,className:"relative flex-1 min-h-0 overflow-hidden flex flex-col outline-none",tabIndex:-1,onMouseUp:Z,onMouseDown:ee,children:[I&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("input",{ref:q,type:"text",value:B,onChange:e=>F(e.target.value),onKeyDown:z,placeholder:y("codeViewer.searchChat"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:D.length>0?`${O+1}/${D.length}`:y("common.noMatch")}),(0,n.jsx)("button",{onClick:_,disabled:0===D.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:y("codeViewer.prevShiftEnter"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,n.jsx)("button",{onClick:A,disabled:0===D.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:y("codeViewer.nextEnter"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,n.jsx)("button",{onClick:W,className:"p-1 rounded hover:bg-accent",title:y("codeViewer.closeEsc"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{ref:N,onScroll:eu,className:"relative flex-1 min-h-0 overflow-y-auto p-4",children:0!==e.length||t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:k}),c&&(0,n.jsx)("div",{className:"flex justify-center py-3",children:m?(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,n.jsx)("span",{children:y("chat.loadMoreHistory")})]}):(0,n.jsx)("button",{onClick:f,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:y("chat.scrollUpForMore")})}),ea.map(e=>(0,n.jsx)("div",{"data-message-id":e.id,className:"transition-[box-shadow] duration-300",children:(0,n.jsx)(nq,{message:e,cwd:r,sessionId:a,onFork:p})},e.id)),t&&(0,n.jsx)("div",{className:"flex justify-start mb-4",children:(0,n.jsxs)("div",{className:"bg-accent rounded-2xl rounded-bl-md px-4 py-3 max-w-[90%]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-5 h-5 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,n.jsx)("span",{className:"text-sm",children:"claude2"===l?"Claude 2 is thinking...":"codex"===l?"Codex is thinking...":"kimi"===l?"Kimi is thinking...":"ollama"===l?"Ollama is thinking...":"deepseek"===l?"Deepseek is thinking...":y("chat.claudeThinking")})]}),i&&(0,n.jsxs)("div",{className:"mt-2 flex items-start gap-2 text-xs text-amber-400 border-t border-border/50 pt-2",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{children:["Retrying API call (attempt ",i.attempt,i.maxRetries>0?`/${i.maxRetries}`:"",i.delayMs>0?`, delay ${(i.delayMs/1e3).toFixed(1)}s`:"",")"]}),(i.errorStatus||i.error)&&(0,n.jsxs)("div",{className:"text-muted-foreground/80 break-words",children:[i.errorStatus?`${i.errorStatus}`:"",i.errorStatus&&i.error?" \xb7 ":"",i.error||""]})]})]})]})}),(0,n.jsx)("div",{ref:w})]}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-slate-9",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCAC"}),(0,n.jsx)("div",{children:y("chat.startConversation")})]})})}),$&&e.length>0&&(0,n.jsx)("button",{onClick:em,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:y("chat.jumpToStart"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),R&&e.length>0&&(0,n.jsx)("button",{onClick:eh,className:"absolute bottom-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:y("chat.jumpToLatest"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),S&&(0,n.jsx)(j.f,{floatingToolbarRef:U,bumpRef:V,container:S,onAddComment:et,onSendToAI:er,onSearch:b?en:void 0,isChatLoading:H?.isLoading}),Q&&S&&(0,n.jsx)(x.t,{x:Q.x,y:Q.y,range:{start:0,end:0},codeContent:Q.text,container:S,onSubmit:es,onClose:()=>Y(null)}),X&&S&&(0,n.jsx)(x.G,{x:X.x,y:X.y,range:{start:0,end:0},codeContent:X.text,container:S,onSubmit:eo,onClose:()=>G(null),isChatLoading:H?.isLoading})]})});function nH({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-full max-h-[90vh] object-contain rounded-lg",onClick:e=>e.stopPropagation()}),(0,n.jsx)("button",{onClick:t,className:"absolute -top-3 -right-3 w-8 h-8 bg-card text-foreground hover:text-foreground rounded-full shadow-lg flex items-center justify-center transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})});return(0,n.jsx)(i.ZL,{children:s})}function nU({images:e,onRemove:t,disabled:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 bg-secondary border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:a("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:a("imagePreview.deleteImage"),children:"✕"})]},e.id))}),l&&(0,n.jsx)(nH,{image:l,onClose:()=>i(null)})]})}var nV=r(28147),nK=r(74446);let nJ=(0,s.memo)(function({onSend:e,disabled:t,cwd:r,engine:a,onShowGitStatus:l,onShowComments:i,onShowUserMessages:c,onOpenNote:d,onCreateScheduledTask:u}){let{t:m}=(0,o.Bd)(),[h,x]=(0,s.useState)(""),[f,g]=(0,s.useState)([]),[b,v]=(0,s.useState)([]),[j,y]=(0,s.useState)([]),[w,k]=(0,s.useState)(!1),[N,C]=(0,s.useState)(0),[S,L]=(0,s.useState)(!1),M=(0,s.useRef)(null),E=(0,s.useRef)(null),$=(0,s.useCallback)(()=>{let e=M.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{$()},[h,$]),(0,s.useEffect)(()=>{(async()=>{try{let e=r?`/api/commands?cwd=${encodeURIComponent(r)}`:"/api/commands",t=await fetch(e);if(t.ok){let e=await t.json();v(e)}}catch(e){console.error("Failed to load commands:",e)}})()},[r]);let T=(0,s.useCallback)(async()=>{try{let e=await fetch("/api/skills");if(e.ok){let t=(await e.json()).filter(e=>e.valid&&!!e.name).map(e=>({name:`/${e.name}`,description:e.description||"",source:"skill",skillPath:e.path,argumentHint:e.argumentHint}));y(t)}}catch(e){console.error("Failed to load skills:",e)}},[]);(0,s.useEffect)(()=>(T(),(0,nK.U)(T)),[T]);let R=(0,s.useMemo)(()=>{if(!h.startsWith("/"))return[];let e=h.toLowerCase(),t=t=>t.name.toLowerCase().startsWith(e);return[...b.filter(t),...j.filter(t)]},[h,b,j]),P=!S&&h.startsWith("/")&&R.length>0,I=(0,s.useRef)(h);(0,s.useLayoutEffect)(()=>{I.current!==h&&(queueMicrotask(()=>C(0)),S&&queueMicrotask(()=>L(!1)),I.current=h)},[h,S]),(0,s.useLayoutEffect)(()=>{if(P&&E.current){let e=E.current.children[N];e&&e.scrollIntoView({block:"nearest"})}},[N,P]);let B=(0,s.useCallback)(()=>{let r=h.trim();if((r||f.length>0)&&!t){let t=r;if(r.startsWith("/")&&j.length>0)for(let e of[...j].sort((e,t)=>t.name.length-e.name.length)){if(!e.skillPath)continue;if(r===e.name){t=`${m("chat.skillExpansionPrompt")}
|
|
24
|
-
${e.skillPath}`;break}let n=`${e.name} `;if(r.startsWith(n)){let s=r.slice(n.length).trimStart();t=`${m("chat.skillExpansionPrompt")}
|
|
25
|
-
${e.skillPath}
|
|
26
|
-
|
|
27
|
-
${s}`;break}}e(t,f.length>0?f:void 0),x(""),g([]),M.current&&(M.current.style.height="auto")}},[h,f,t,e,j,m]),F=(0,s.useCallback)(e=>{x(e.name+" "),M.current?.focus()},[]),D=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing){if(P&&R.length>0){if("ArrowDown"===e.key){e.preventDefault(),C(e=>(e+1)%R.length);return}if("ArrowUp"===e.key){e.preventDefault(),C(e=>(e-1+R.length)%R.length);return}if("Enter"===e.key){e.preventDefault(),F(R[N]);return}if("Escape"===e.key){e.preventDefault(),L(!0);return}if("Tab"===e.key){e.preventDefault(),F(R[N]);return}}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),B())}},[P,R,N,F,B]),O=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(m("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};g(e=>[...e,s])},s.readAsDataURL(r)}}},[m]),A=(0,s.useCallback)(e=>{g(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nU,{images:f,onRemove:A,disabled:t}),P&&R.length>0&&(0,n.jsx)("div",{ref:E,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64 overflow-y-auto bg-card border border-border rounded-lg shadow-lg",children:R.map((e,t)=>{let r=t>0?R[t-1]:null,s="skill"===e.source&&(!r||"skill"!==r.source),o="skill"!==e.source&&0===t;return(0,n.jsxs)("div",{children:[o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),s&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),(0,n.jsxs)("div",{onClick:()=>F(e),className:`px-4 py-2 cursor-pointer ${t===N?"bg-brand/10":"hover:bg-accent"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:e.name}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"global":return"bg-green-9/15 text-green-11 dark:bg-green-9/25 dark:text-green-11";case"project":return"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25 dark:text-amber-11";case"skill":return"bg-purple-9/15 text-purple-11 dark:bg-purple-9/25 dark:text-purple-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return m("common.builtin");case"global":return m("common.global");case"project":return m("common.project");case"skill":return"Skill"}})(e.source)})]}),"skill"===e.source&&e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 pl-0 truncate",children:e.argumentHint})]})]},e.name)})}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[(0,n.jsx)("button",{onClick:async()=>{try{(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,files:["."]})})).ok?((0,p.oR)(m("toast.stagedAllFiles"),"success"),window.dispatchEvent(new CustomEvent("git-status-changed"))):(0,p.oR)(m("toast.stageFailed"),"error")}catch(e){console.error("Error staging files:",e),(0,p.oR)(m("toast.stageFailed"),"error")}},className:"p-2 text-green-11 hover:text-green-10 hover:bg-green-9/10 active:bg-green-9/20 active:scale-95 rounded-lg transition-all",title:m("chat.stageAll"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),l&&(0,n.jsx)("button",{onClick:l,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:m("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),i&&(0,n.jsx)("button",{onClick:i,className:"p-2 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95 rounded-lg transition-all",title:m("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),c&&(0,n.jsx)("button",{onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:m("chat.userMessages"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),d&&(0,n.jsx)("button",{onClick:d,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:m("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),u&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>k(!w),className:`p-2 rounded-lg transition-all ${w?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:m("chat.scheduledTasks"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]})}),w&&(0,n.jsx)(nV.E,{onClose:()=>k(!1),onCreate:u})]}),(0,n.jsx)("textarea",{ref:M,value:h,onChange:e=>x(e.target.value),onKeyDown:D,onPaste:O,placeholder:t?m("chat.placeholderDisabled"):m("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground placeholder-slate-9"})]})]})});var nQ=r(97440),nY=r(31914);function nX(e){if(0===e.length)return"";let t=[B.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===u.Un),n=e.filter(e=>e.filePath!==u.Un);for(let e of(n.length>0&&n.forEach((e,r)=>{t.push(`[${r+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(B.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function nG({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[m,h]=(0,s.useState)(!1),[x,f]=(0,s.useState)(null),[g,b]=(0,s.useState)(!1),v=(0,s.useCallback)(async()=>{if(r){h(!0);try{let e=await fetch(`/api/comments?cwd=${encodeURIComponent(r)}&all=true`);if(e.ok){let t=await e.json();d(t.comments||[])}}catch(e){console.error("Failed to load comments:",e)}finally{h(!1)}}},[r]);(0,s.useEffect)(()=>{e&&v()},[e,v]);let j=async e=>{try{(await fetch(`/api/comments?cwd=${encodeURIComponent(r)}&id=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&(d(t=>t.filter(t=>t.id!==e)),(0,u.Cm)())}catch(e){console.error("Failed to delete comment:",e)}},y=async e=>{f(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await fetch(`/api/files/text?cwd=${encodeURIComponent(r)}&path=${encodeURIComponent(e.filePath)}`);if(!n.ok)throw Error("Failed to read file");t=((await n.json()).content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=nX([n]);await navigator.clipboard.writeText(s),(0,p.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{f(null)}},w=async()=>{if(0!==c.length){b(!0);try{let e=await (0,u.$3)(r),t=nX(e);await navigator.clipboard.writeText(t),(0,p.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{b(!1)}}},k=c.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let N=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-xl flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:l("comments.allComments")}),c.length>0&&(0,n.jsx)("button",{onClick:w,disabled:g,className:"p-1 rounded hover:bg-accent text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:g?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:l("common.loading")}):0===c.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:l("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(k).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===u.Un?l("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",l("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-accent/50 cursor-pointer group",onClick:()=>a?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand font-mono",children:[l("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",l("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:l("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e)},disabled:x===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground transition-opacity disabled:opacity-50",title:l("common.copy"),children:x===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),j(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground hover:text-red-9 transition-opacity",title:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border bg-secondary flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:l("comments.totalComments",{count:c.length})}),(0,n.jsx)("button",{onClick:async()=>{0===c.length||await (0,u.RP)(r)&&d([])},disabled:0===c.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:l("comments.clearAll")})]})]})});return(0,n.jsx)(i.ZL,{children:N})}function nZ({isOpen:e,onClose:t,messages:r,onSelectMessage:a}){let{t:l}=(0,o.Bd)();if((0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t]),!e)return null;let c=r.filter(e=>"user"===e.role),d=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-lg max-h-[70vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:l("userMessages.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:l("userMessages.noMessages")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:c.map((e,r)=>{let s,o,l,i=(s=e.id.match(/^user-(\d+)/))?parseInt(s[1],10):null,c=i?(o=new Date(i),l=new Date,o.toDateString()===l.toDateString()?o.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):o.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})):"";return(0,n.jsx)("button",{onClick:()=>{a(e.id),t()},className:"w-full px-4 py-3 text-left hover:bg-accent transition-colors",children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[r+1,"."]}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("p",{className:"text-sm text-foreground break-words",children:function(e,t=50){let r=e.replace(/\s+/g," ").trim();return r.length<=t?r:r.slice(0,t)+"..."}(e.content)})}),c&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:c})]})},e.id)})})})]})});return(0,n.jsx)(i.ZL,{children:d})}function n0({cwd:e,sessionId:t,onOpenProjectSessions:r,onOpenSessionBrowser:a,onOpenSettings:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Session: ",t.slice(0,8),"..."]}),e&&(0,n.jsx)("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),t&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t}`;navigator.clipboard.writeText(e).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-500 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:c?i("chat.copiedCommandTooltip"):i("chat.copyCommandTooltip",{sessionId:t}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function n1({tokenUsage:e,rateLimitInfo:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{if(!t?.resetsAt)return;let e=setInterval(()=>l(Date.now()),3e4);return()=>clearInterval(e)},[t?.resetsAt]);let i=t?.status==="rejected"?"text-red-500":t?.status==="allowed_warning"?"text-yellow-500":"text-muted-foreground",c=t?.status==="rejected"?r("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?r("chat.rateLimitWarning","Approaching Limit"):null,d=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-a;if(t<=0)return"";let r=Math.ceil(t/6e4);if(r<60)return`${r}m`;let n=Math.floor(r/60),s=r%60;return s>0?`${n}h${s}m`:`${n}h`},u=e=>e?e.replace(/_/g," "):"";return(0,n.jsx)("div",{className:"px-4 py-1.5 border-t border-border bg-secondary",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&c&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${i}`,title:[t.rateLimitType&&`Type: ${u(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${d(t.resetsAt)}`,t.isUsingOverage&&"Using overage"].filter(Boolean).join(" \xb7 "),children:["rejected"===t.status?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:c}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${d(t.resetsAt)}`]})]}),t&&!c&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5",title:[t.rateLimitType&&u(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${d(t.resetsAt)}`].filter(Boolean).join(" \xb7 "),children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),null!=t.utilization?(0,n.jsxs)("span",{children:[(100*t.utilization).toFixed(0),"%"]}):(0,n.jsx)("span",{children:d(t.resetsAt)})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsxs)("span",{children:[r("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens).toLocaleString()})]})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[r("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}function n2({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(!1),f=(0,s.useRef)(null),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({top:0,left:0}),v=(0,i.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{p.current&&!p.current.contains(e.target)&&f.current&&!f.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let j=(0,s.useCallback)(async()=>{d(!0),m(null);try{let e=await fetch("/api/ollama/models");if(503===e.status){x(!0);let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json();if(404===e.status){m(t.message||"Ollama is not installed"),x(!1);return}if(!e.ok){m("Failed to start Ollama"),x(!1);return}x(!1);let r=await fetch("/api/ollama/models");if(!r.ok)return void m("Ollama started but cannot fetch models");let n=await r.json();l(n.models||[])}else if(e.ok){let t=await e.json();l(t.models||[])}else m("Failed to fetch models")}catch{m("Connection error")}finally{d(!1)}},[]),y=e?e.replace(/:latest$/,""):"Select model",w=r?(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{ref:p,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[200px] max-h-[300px] overflow-y-auto",style:{top:g.top,left:g.left},children:c||h?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),h?"Starting Ollama...":"Loading models..."]}):u?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-400",children:u}):0===a.length?(0,n.jsxs)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No models found. Run ",(0,n.jsx)("code",{className:"bg-secondary px-1 rounded",children:"ollama pull <model>"})]}):a.map(r=>{var s;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center justify-between gap-2 px-3 py-1.5 text-xs hover:bg-brand/10 transition-colors ${r.name===e?"text-brand":"text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:r.parameter_size||((s=r.size)<1e9?`${(s/1e6).toFixed(0)}M`:`${(s/1e9).toFixed(1)}G`)})]},r.name)})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,onClick:()=>{if(!r){if(f.current){let e=f.current.getBoundingClientRect(),t=v?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;b({top:e.bottom+4-n,left:e.left-r})}j()}o(e=>!e)},className:"flex items-center gap-1 px-2 py-0.5 text-[11px] rounded bg-violet-500/15 text-violet-400 hover:bg-violet-500/25 transition-colors",title:"Switch Ollama model",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-violet-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate max-w-[120px]",children:y}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),w]})}let n5=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function n4({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)(""),[c,d]=(0,s.useState)(""),[u,m]=(0,s.useState)(!1),[h,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),y=(0,s.useRef)(null),[w,k]=(0,s.useState)({top:0,left:0}),N=(0,i.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{j.current&&!j.current.contains(e.target)&&v.current&&!v.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let C=(0,s.useCallback)(async()=>{x(!0),b(null);try{let r=await fetch("/api/settings");if(!r.ok)return void b("Failed to load settings");let n=await r.json(),s=n?.engines?.deepseek?.apiKey||"";l(s),d(""),m(!1);let o=n?.engines?.deepseek?.model;!e&&o&&n5.some(e=>e.value===o)&&t(o)}catch{b("Connection error")}finally{x(!1)}},[e,t]),S=(0,s.useCallback)(async e=>{let t=(await fetch("/api/settings").then(e=>e.ok?e.json():{}).catch(()=>({}))).engines||{},r={...t,deepseek:{...t.deepseek||{},...e}};if(!(await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({engines:r})})).ok)throw Error("Failed to save settings")},[]),L=async()=>{let e=c.trim();if(e){p(!0),b(null);try{await S({apiKey:e}),l(e),d(""),m(!1)}catch(e){b(e instanceof Error?e.message:"Save failed")}finally{p(!1)}}},M=async()=>{p(!0),b(null);try{await S({apiKey:""}),l(""),d(""),m(!1)}catch(e){b(e instanceof Error?e.message:"Clear failed")}finally{p(!1)}},E=async e=>{t(e);try{await S({model:e})}catch{}},$=!!a,T=$?e||"deepseek-v4-flash":"Set API key",R=$?"text-sky-400":"text-amber-400",P=r?(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{ref:j,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-2 min-w-[280px]",style:{top:w.top,left:w.left},children:h?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"API Key"}),$&&!u?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:a?a.length<=8?a.replace(/./g,"•"):`${a.slice(0,3)}${"•".repeat(Math.max(4,a.length-7))}${a.slice(-4)}`:""}),(0,n.jsx)("button",{onClick:()=>{m(!0),d(""),setTimeout(()=>y.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-accent text-foreground transition-colors",disabled:f,children:"Edit"}),(0,n.jsx)("button",{onClick:M,className:"text-[11px] px-2 py-1 rounded text-red-400 hover:bg-red-500/10 transition-colors",disabled:f,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:y,type:"password",value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"===e.key&&L()},placeholder:"sk-...",className:"flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:border-sky-500 focus:outline-none font-mono",autoFocus:!0}),(0,n.jsx)("button",{onClick:L,disabled:f||!c.trim(),className:"text-[11px] px-2 py-1 rounded bg-sky-500/20 hover:bg-sky-500/30 text-sky-300 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:f?"Saving...":"Save"}),$&&(0,n.jsx)("button",{onClick:()=>{m(!1),d("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),g&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-400",children:g})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Model"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:n5.map(t=>{let r=(e||"deepseek-v4-flash")===t.value;return(0,n.jsxs)("button",{onClick:()=>E(t.value),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?"bg-sky-500/15 text-sky-300":"text-foreground hover:bg-accent"}`,children:[(0,n.jsx)("span",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${r?"border-sky-400":"border-muted-foreground"}`,children:r&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-sky-400"})}),(0,n.jsx)("span",{children:t.label})]},t.value)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:v,onClick:()=>{if(!r){if(v.current){let e=v.current.getBoundingClientRect(),t=N?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;k({top:e.bottom+4-n,left:e.left-r})}C()}o(e=>!e)},className:"flex items-center gap-1 px-2 py-0.5 text-[11px] rounded bg-sky-500/15 hover:bg-sky-500/25 transition-colors",title:"Configure Deepseek",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-sky-500 flex-shrink-0"}),(0,n.jsx)("span",{className:`truncate max-w-[160px] ${R}`,children:T}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0 text-sky-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),P]})}function n3({tabId:e,initialCwd:t,initialSessionId:r,engine:l,ollamaModel:i,onOllamaModelChange:c,deepseekModel:d,onDeepseekModelChange:u,hideHeader:m,hideSidebar:x,isActive:f=!0,onLoadingChange:p,onSessionIdChange:g,onTitleChange:b,onShowGitStatus:v,onOpenNote:j,onCreateScheduledTask:y,onOpenSession:w,onContentSearch:k}){let{t:N}=(0,o.Bd)(),C=(0,h.nH)(),[S,L]=(0,s.useState)([]),[M,E]=(0,s.useState)(null),[$,T]=(0,s.useState)(!1),[R,P]=(0,s.useState)(!1),[I,F]=(0,s.useState)(!1),[D,O]=(0,s.useState)(!1),[A,_]=(0,s.useState)(!1),[W,q]=(0,s.useState)(!1),[z,H]=(0,s.useState)(null),U=(0,s.useRef)(null),V=(0,s.useRef)(null),K=(0,s.useCallback)(async e=>{if(t)try{let r=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,sessionId:e})});if(r.ok){let e=await r.json();e.title&&b?.(e.title)}}catch(e){console.error("Failed to fetch session title:",e)}},[t,b]),{isLoading:J,tokenUsage:Q,rateLimitInfo:Y,apiRetryInfo:X,handleSend:G,handleStop:Z}=function(e,{sessionId:t,cwd:r,engine:n,ollamaModel:o,deepseekModel:a,onSessionId:l,onFetchTitle:i}){let[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(null),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(t);b.current=t;let v=(0,s.useRef)(null),j=(0,s.useRef)(null),y=(0,s.useCallback)(()=>{let t=v.current;if(t&&t.text){let{messageId:r,text:n}=t;e(e=>e.map(e=>e.id===r?{...e,content:(e.content||"")+n}:e)),v.current={messageId:r,text:""}}j.current=null},[e]),w=(0,s.useCallback)(()=>{g.current&&(g.current.abort(),g.current=null)},[]),k=(0,s.useCallback)((t,s)=>{let o=t.type;if("system"===o&&"init"===t.subtype){let e=t.session_id;l(e),b.current=e,p(null);return}if("system"===o&&"api_retry"===t.subtype)return void p({attempt:t.attempt??0,maxRetries:t.max_retries??0,delayMs:t.retry_delay_ms??0,errorStatus:t.error_status,error:t.error});if("rate_limit_event"===o){let e=t.rate_limit_info;e&&x({status:e.status||"allowed",resetsAt:e.resetsAt,rateLimitType:e.rateLimitType,utilization:e.utilization,overageStatus:e.overageStatus,overageDisabledReason:e.overageDisabledReason,isUsingOverage:e.isUsingOverage,surpassedThreshold:e.surpassedThreshold});return}if("stream_event"===o){p(e=>e?null:e);let e=t.event;if(e?.type==="content_block_delta"&&e.delta?.type==="text_delta"){let t=e.delta.text||"";v.current&&v.current.messageId===s?v.current.text+=t:v.current={messageId:s,text:t},j.current||(j.current=setTimeout(y,50))}return}if("assistant"===o){let r=t.message;if(r?.content){if("codex"===n||"kimi"===n||"ollama"===n){let t=r.content.filter(e=>"text"===e.type&&e.text).map(e=>e.text);if(t.length>0){let r=t.join("");e(e=>e.map(e=>e.id===s?{...e,content:(e.content||"")+r}:e))}}for(let t of r.content)if("name"in t&&t.name){let r={id:t.id||`tool-${Date.now()}`,name:t.name,input:t.input||{},isLoading:!0};e(e=>e.map(e=>e.id!==s||e.toolCalls?.some(e=>e.id===r.id)?e:{...e,toolCalls:[...e.toolCalls||[],r]}))}}}if("user"===o){let r=t.message;if(r?.content){for(let t of r.content)if("tool_use_id"in t&&t.tool_use_id){let r=t.tool_use_id,n="string"==typeof t.content?t.content:JSON.stringify(t.content);e(e=>e.map(e=>e.id===s?{...e,toolCalls:e.toolCalls?.map(e=>e.id===r?{...e,result:n,isLoading:!1}:e)}:e))}}}if("result"===o){p(null),j.current&&(clearTimeout(j.current),j.current=null),y();let n=b.current;n&&r&&e(e=>(2===e.length&&i(n),e));let o=t.usage,a=t.total_cost_usd;o&&m({inputTokens:o.input_tokens||0,outputTokens:o.output_tokens||0,cacheCreationInputTokens:o.cache_creation_input_tokens||0,cacheReadInputTokens:o.cache_read_input_tokens||0,totalCostUsd:a||0}),e(e=>e.map(e=>e.id===s?{...e,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e))}},[e,y,l,i,r,n]),N=(0,s.useCallback)(async(t,s)=>{let l=s?.map(e=>({type:"base64",media_type:e.media_type,data:e.data})),i={id:`user-${Date.now()}`,role:"user",content:t,images:l};e(e=>[...e,i]),d(!0),p(null);let c=`assistant-${Date.now()}`,u={id:c,role:"assistant",content:"",toolCalls:[],isStreaming:!0};e(e=>[...e,u]),g.current=new AbortController;try{if("ollama"===n&&!o)throw Error("Please select an Ollama model first (click the model picker above)");let e="codex"===n?"/api/chat/codex":"kimi"===n?"/api/chat/kimi":"ollama"===n?"/api/chat/ollama":"deepseek"===n?"/api/chat/deepseek":"/api/chat",s=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:t,sessionId:b.current,images:l,cwd:r,language:B.A.language,..."ollama"===n&&o&&{model:o},..."deepseek"===n&&a&&{model:a},..."claude2"===n&&{engine:"claude2"}}),signal:g.current.signal});if(400===s.status&&"deepseek"===n){let e=await s.json().catch(()=>null);throw Error(e?.error||"Deepseek request failed")}if(!s.ok)throw Error(B.A.t("chat.requestFailed"));let i=s.body?.getReader();if(!i)throw Error(B.A.t("chat.cannotReadStream"));let d=new TextDecoder,u="";for(;;){let{done:e,value:t}=await i.read();if(e)break;let r=(u+=d.decode(t,{stream:!0})).split("\n");for(let e of(u=r.pop()||"",r))if(e.startsWith("data: ")){let t=e.slice(6);if("[DONE]"===t)continue;try{let e=JSON.parse(t);k(e,c)}catch{}}}}catch(t){if(t instanceof Error&&"AbortError"===t.name);else{console.error("Chat error:",t);let r=t instanceof Error?t.message:B.A.t("chat.errorRetry");e(e=>e.map(e=>e.id===c?{...e,content:r,isStreaming:!1}:e))}}finally{g.current=null,d(!1),e(e=>e.map(e=>e.id===c?{...e,isStreaming:!1}:e))}},[r,n,o,a,e,k]);return{isLoading:c,tokenUsage:u,rateLimitInfo:h,apiRetryInfo:f,handleSend:N,handleStop:w,abortControllerRef:g}}(L,{sessionId:M,cwd:t,engine:l,ollamaModel:i,deepseekModel:d,onSessionId:E,onFetchTitle:K}),ee=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void G(e,r);let o=e.split("\n").slice(1).join("\n").trim();try{let e=await fetch("/api/bash",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({command:s,cwd:t})}),n=await e.json(),a=[n.stdout,n.stderr].filter(Boolean).join("\n")||"(no output)",l=n.exitCode?` (exit code: ${n.exitCode})`:"",i=N("chat.executedCommand",{command:s,exitInfo:l,output:a});o&&(i+=`
|
|
28
|
-
|
|
29
|
-
${o}`),G(i,r)}catch(e){G(N("chat.executedCommandFailed",{command:s,error:e}),r)}return}G(e,r)},[G,t,N]),{isLoadingHistory:et,isLoadingMore:er,hasMoreHistory:en,loadMoreHistory:es,loadHistoryByCwdAndSessionId:eo}=function(e,t,r,{cwd:n,initialSessionId:o,onSessionId:a,onTitleChange:l,onTokenUsage:i}){let[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[h,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(void 0),[g,b]=(0,s.useState)(0),v=(0,s.useRef)(l);v.current=l;let j=(0,s.useRef)(i);j.current=i;let y=(0,s.useRef)(void 0),w=(0,s.useRef)(0),k=(0,s.useCallback)(async(e,r,n=!1,s,o)=>{if(n){let e=Date.now();if(e-w.current<5e3)return;w.current=e}n||d(!0);try{let l={cwd:e,sessionId:r,limit:s,beforeTurnIndex:o};n&&y.current&&(l.ifFingerprint=y.current);let i=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(i.ok){let e=await i.json();if(e.notModified)return;e.fingerprint&&(y.current=e.fingerprint),void 0!==e.totalTurns&&b(e.totalTurns),void 0!==e.hasMore&&x(e.hasMore),e.messages&&e.messages.length>0&&(n?t(t=>{let r=e.messages;if(t.length===r.length&&t.length>0&&t[t.length-1].content===r[r.length-1].content)return t;let n=0;for(let e=0;e<Math.min(t.length,r.length)&&t[e].id===r[e].id&&t[e].content===r[e].content;e++)n=e+1;return n===t.length&&n<r.length?[...t,...r.slice(n)]:r}):t(e.messages)),e.sessionId&&a(e.sessionId),e.title&&v.current?.(e.title),e.usage&&j.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{n||d(!1)}},[t,a]),N=(0,s.useCallback)(async()=>{if(n&&r&&!u&&h){m(!0);try{let s=void 0!==f?f:g-Math.ceil(e.filter(e=>"user"===e.role).length),o=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,sessionId:r,limit:10,beforeTurnIndex:s>0?s:void 0})});if(o.ok){let e=await o.json();if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let r=e.messages.filter(e=>"user"===e.role).length;p(s-r)}void 0!==e.hasMore&&x(e.hasMore),e.fingerprint&&(y.current=e.fingerprint)}}catch(e){console.error("Failed to load more history:",e)}finally{m(!1)}}},[n,r,u,h,f,g,e,t]),C=(0,s.useCallback)(async e=>{d(!0);try{let r=await fetch(`/api/session/${e}/history`);if(r.ok){let e=await r.json();e.messages&&e.messages.length>0&&t(e.messages)}}catch(e){console.error("Failed to load history:",e)}finally{d(!1)}},[t]);return(0,s.useEffect)(()=>{n&&o&&k(n,o,!1,10)},[]),{isLoadingHistory:c,isLoadingMore:u,hasMoreHistory:h,loadMoreHistory:N,loadHistory:C,loadHistoryByCwdAndSessionId:k}}(S,L,M,{cwd:t,initialSessionId:r,onSessionId:E,onTitleChange:b,onTokenUsage:H}),ea=(0,s.useRef)(f);(0,s.useEffect)(()=>{f&&!ea.current&&M&&t&&!J&&eo(t,M,!0,10),ea.current=f},[f,M,t,J,eo]);let el=Q||z;(0,s.useEffect)(()=>{M&&g?.(M)},[M,g]);let ei=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(p?.(J),ei.current&&!J&&t&&M){let e;for(let t=S.length-1;t>=0;t--)if("user"===S[t].role&&S[t].content){e=S[t].content.slice(0,100);break}window.parent.postMessage({type:"SESSION_COMPLETE",cwd:t,sessionId:M,lastUserMessage:e},"*")}ei.current=J},[J,p,t]),(0,s.useEffect)(()=>{f&&C?.setIsLoading(J)},[J,f,C]),(0,s.useEffect)(()=>{if(e&&C)return C.registerChat(e=>{V.current?.(e)},e),()=>{C.unregisterChat(e)}},[e,C]),(0,s.useEffect)(()=>{e&&f&&C&&C.setActiveTab(e)},[e,f,C]),(0,s.useEffect)(()=>{V.current=ee},[ee]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&$&&J&&Z()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[$,J,Z]);let ec=(0,s.useCallback)(async e=>{if(t&&M)try{let r=await fetch(`/api/session/${M}/fork`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,fromMessageUuid:e})});if(r.ok){let e=await r.json();w?w(e.newSessionId,"Fork"):window.parent.postMessage({type:"OPEN_PROJECT",cwd:t,sessionId:e.newSessionId},"*")}else console.error("Fork failed:",await r.text())}catch(e){console.error("Fork error:",e)}},[t,M,w]),ed=(0,s.useCallback)(()=>{_(!0)},[]),eu=(0,s.useCallback)(()=>{q(!0)},[]),em=(0,s.useMemo)(()=>{if(y&&t&&e&&M)return r=>{y({...r,cwd:t,tabId:e,sessionId:M})}},[y,t,e,M]);return(0,n.jsxs)("div",{className:`flex ${m&&x?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),children:[!m&&(0,n.jsx)(n0,{cwd:t,sessionId:M,onOpenProjectSessions:()=>F(!0),onOpenSessionBrowser:()=>P(!0),onOpenSettings:()=>O(!0)}),"ollama"===l&&c&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(n2,{currentModel:i,onModelChange:c})}),"deepseek"===l&&u&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(n4,{currentModel:d,onModelChange:u})}),et?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:N("sessions.loadingHistory")})}):(0,n.jsx)(nz,{ref:U,messages:S,isLoading:J,cwd:t,sessionId:M,engine:l,apiRetryInfo:X,hasMoreHistory:en,isLoadingMore:er,onLoadMore:es,onFork:ec,isActive:f,onContentSearch:k}),el&&(0,n.jsx)(n1,{tokenUsage:el,rateLimitInfo:Y}),(0,n.jsx)(nJ,{onSend:ee,disabled:J,cwd:t,engine:l,onShowGitStatus:v,onShowComments:t?ed:void 0,onShowUserMessages:eu,onOpenNote:j,onCreateScheduledTask:em})]}),!m&&(0,n.jsx)(nQ.r,{isOpen:R,onClose:()=>P(!1)}),!m&&t&&(0,n.jsx)(a,{isOpen:I,onClose:()=>F(!1),cwd:t}),!m&&(0,n.jsx)(nY.b,{isOpen:D,onClose:()=>O(!1)}),t&&(0,n.jsx)(nG,{isOpen:A,onClose:()=>_(!1),cwd:t}),(0,n.jsx)(nZ,{isOpen:W,onClose:()=>q(!1),messages:S,onSelectMessage:e=>{U.current?.scrollToMessage(e)}})]})}function n6({tabId:e,cwd:t,sessionId:r,engine:o,ollamaModel:a,onOllamaModelChange:l,deepseekModel:i,onDeepseekModelChange:c,isActive:d,onStateChange:u,onShowGitStatus:m,onOpenNote:h,onCreateScheduledTask:x,onOpenSession:f,onContentSearch:p}){let g=(0,s.useCallback)(t=>{u(e,{isLoading:t})},[e,u]),b=(0,s.useCallback)(t=>{u(e,{sessionId:t})},[e,u]),v=(0,s.useCallback)(t=>{u(e,{title:t})},[e,u]),j=(0,s.useCallback)(t=>{l?.(e,t)},[e,l]),y=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]);return(0,n.jsx)(n3,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,ollamaModel:a,onOllamaModelChange:j,deepseekModel:i,onDeepseekModelChange:y,hideHeader:!0,hideSidebar:!0,isActive:d,onLoadingChange:g,onSessionIdChange:b,onTitleChange:v,onShowGitStatus:m,onOpenNote:h,onCreateScheduledTask:x,onOpenSession:f,onContentSearch:p})}var n8=r(36998),n9=r(18658);function n7({initialCwd:e,initialSessionId:t}){let{t:r}=(0,o.Bd)(),[l,c]=(0,s.useState)("agent"),{tabs:d,activeTabId:u,activeTab:m,unreadTabs:x,dragTabIndex:f,dragOverTabIndex:p,closeTab:g,switchTab:b,handleSelectSession:v,handleNewTab:j,handleNewClaude2Tab:y,handleNewCodexTab:w,handleNewKimiTab:k,handleNewOllamaTab:N,handleNewDeepseekTab:C,handleOpenSession:S,updateTabState:L,updateTabOllamaModel:M,updateTabDeepseekModel:E,handleTabDragStart:$,handleTabDragOver:T,handleTabDrop:R,handleTabDragEnd:P}=function({initialCwd:e,initialSessionId:t,activeView:r}){let n=(0,s.useRef)(!1),o=(0,s.useRef)(!0),a=(0,s.useRef)(r);(0,s.useEffect)(()=>{a.current=r},[r]);let l=em(),i=(0,s.useRef)(l);(0,s.useEffect)(()=>{i.current=l},[l]);let[c,d]=(0,s.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),[u,m]=(0,s.useState)(c[0].id),[h,x]=(0,s.useState)(new Set),f=(0,s.useRef)(c);(0,s.useEffect)(()=>{f.current=c},[c]);let p=(0,s.useCallback)((t,r)=>{e&&t&&fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r})}).catch(()=>{})},[e]),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null);(0,s.useEffect)(()=>{!e||n.current||(n.current=!0,(async()=>{try{let r=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(r.ok){let n=await r.json(),s=n.sessions||[],a=n.activeSessionId,l=n.engines||{},i=n.ollamaModels||{},c=n.deepseekModels||{},u=[...s];if(t&&!u.includes(t)&&(u=[t,...u]),u.length>0){let r=u.map((t,r)=>({id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:l[t]||void 0,ollamaModel:i[t]||void 0,deepseekModel:c[t]||void 0})),n=t||a,s=n?u.indexOf(n):-1;s<0&&(s=0);let h=r[s].id;d(r),m(h),setTimeout(()=>{o.current=!1},0)}else o.current=!1}}catch(e){console.error("Failed to load sessions:",e),o.current=!1}})())},[e,t]),(0,s.useEffect)(()=>{if(o.current||!e)return;let t=c.map(e=>e.sessionId).filter(e=>!!e),r=c.find(e=>e.id===u),n=r?.sessionId,s={},a={},l={};for(let e of c)e.sessionId&&e.engine&&(s[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(a[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(l[e.sessionId]=e.deepseekModel);fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessions:t,activeSessionId:n,engines:s,ollamaModels:a,deepseekModels:l})}).catch(e=>{console.error("Failed to save sessions:",e)})},[c,u,e]),(0,s.useEffect)(()=>{if(o.current||!e)return;let t=c.find(e=>e.id===u);t?.sessionId&&window.parent.postMessage({type:"SESSION_CHANGE",cwd:e,sessionId:t.sessionId},"*")},[u,c,e]);let y=(0,s.useCallback)((e,t,r,n,s,o)=>{let a={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat"),engine:n,ollamaModel:s,deepseekModel:o};d(e=>{let t=e.findIndex(e=>e.id===u);if(-1===t)return[...e,a];let r=[...e];return r.splice(t+1,0,a),r}),m(a.id)},[u]),w=(0,s.useCallback)(t=>{d(r=>{let n=r.filter(e=>e.id!==t);if(t===u&&n.length>0&&m(n[n.length-1].id),0===n.length){let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};return m(t.id),[t]}return n})},[u,e]),k=(0,s.useCallback)((t,r)=>{let n=c.find(e=>e.sessionId===t);n?m(n.id):y(e,t,r)},[c,e,y]),N=(0,s.useCallback)(()=>{y(e)},[e,y]),C=(0,s.useCallback)(()=>{y(e,void 0,"New Claude 2 Chat","claude2")},[e,y]),S=(0,s.useCallback)(()=>{y(e,void 0,"New Codex Chat","codex")},[e,y]),L=(0,s.useCallback)(()=>{y(e,void 0,"New Kimi Chat","kimi")},[e,y]),M=(0,s.useCallback)(t=>{y(e,void 0,t?`New Ollama (${t})`:"New Ollama Chat","ollama",t)},[e,y]),E=(0,s.useCallback)((e,t)=>{d(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),$=(0,s.useCallback)(()=>{y(e,void 0,"New Deepseek Chat","deepseek",void 0,"deepseek-v4-flash")},[e,y]),T=(0,s.useCallback)((e,t)=>{d(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),R=(0,s.useCallback)((t,r)=>{y(e,t,r)},[e,y]),P=(0,s.useCallback)((e,t)=>{d(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!a.current||"agent"===a.current;if(e===u&&r&&i.current){let e=n.sessionId||t.sessionId;e&&p(e,"normal")}else x(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[u,p]);(0,s.useEffect)(()=>{(!r||"agent"===r)&&l&&x(e=>{if(!e.has(u))return e;let t=new Set(e);t.delete(u);let r=f.current.find(e=>e.id===u);return r?.sessionId&&(p(r.sessionId,"normal"),fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:r.sessionId}})}).catch(()=>{})),t})},[r,u,l,p]);let I=(0,s.useCallback)(e=>{m(e),x(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=f.current.find(t=>t.id===e);return n?.sessionId&&(p(n.sessionId,"normal"),fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:n.sessionId}})}).catch(()=>{})),r})},[p]),B=(0,s.useCallback)(e=>{b(e)},[]),F=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==g&&g!==t&&j(t)},[g]),D=(0,s.useCallback)(e=>{null!==g&&g!==e&&d(t=>{let r=[...t],[n]=r.splice(g,1);return r.splice(e,0,n),r}),b(null),j(null)},[g]),O=(0,s.useCallback)(()=>{b(null),j(null)},[]),A=c.find(e=>e.id===u);return{tabs:c,activeTabId:u,activeTab:A,unreadTabs:h,dragTabIndex:g,dragOverTabIndex:v,addTab:y,closeTab:w,switchTab:I,handleSelectSession:k,handleNewTab:N,handleNewClaude2Tab:C,handleNewCodexTab:S,handleNewKimiTab:L,handleNewOllamaTab:M,handleNewDeepseekTab:$,handleOpenSession:R,updateTabState:P,updateTabOllamaModel:E,updateTabDeepseekModel:T,handleTabDragStart:B,handleTabDragOver:F,handleTabDrop:D,handleTabDragEnd:O}}({initialCwd:e,initialSessionId:t,activeView:l}),{isPinned:I,pinSession:B,unpinSession:F}=(0,n8.P)(),{createTask:D}=(0,n9.n)(),O=(0,s.useCallback)(e=>{let t=d.find(t=>t.id===e);return!!t?.sessionId&&I(t.sessionId)},[d,I]),A=(0,s.useCallback)(t=>{let r=d.find(e=>e.id===t);r?.sessionId&&(I(r.sessionId)?F(r.sessionId):B(r.sessionId,r.cwd||e||"",r.title))},[d,I,B,F,e]),[_,W]=(0,s.useState)(!1),[q,z]=(0,s.useState)(!1),[H,U]=(0,s.useState)(!1),[V,K]=(0,s.useState)(null),[J,Q]=(0,s.useState)(!1),[Y,X]=(0,s.useState)("tree"),[G,Z]=(0,s.useState)(0),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)(0);(0,s.useEffect)(()=>{e&&fetch(`/api/project-settings?cwd=${encodeURIComponent(e)}`).then(e=>e.ok?e.json():null).then(e=>{e?.settings?.activeView&&c(e.settings.activeView)}).catch(()=>{})},[e]);let[es,eo]=(0,s.useState)(!1),ea=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(ea.current=l,c("console"),eo(!0)):(eo(!1),ea.current&&"console"!==ea.current&&c(ea.current),ea.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[l]);let el=(0,s.useCallback)(t=>{c(t),e&&(fetch("/api/project-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,settings:{activeView:t}})}).catch(()=>{}),window.parent.postMessage({type:"VIEW_CHANGE",cwd:e,view:t},"*"))},[e]),ei=(0,s.useCallback)(async()=>{if(e)try{let t=await fetch(`/api/git/worktree?cwd=${encodeURIComponent(e)}`);if(t.ok){let r=await t.json();if(Q(r.isGitRepo),r.isGitRepo&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&K(t.branch)}}}catch(e){console.error("Failed to load git info:",e)}},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>ei())},[ei]);let ec=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"git"===e.type)&&ei()},[ei]);(0,eu.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:ec,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),el("agent")):"2"===e.key?(e.preventDefault(),el("explorer")):"3"===e.key&&(e.preventDefault(),el("console")))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){v(r),n&&el("agent");let t=d.find(e=>e.sessionId===r);e&&!t?.isLoading&&fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:r,status:"normal"})}).catch(()=>{})}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[v,el,e,d]);let ed=(0,s.useCallback)(()=>{X("status"),Z(e=>e+1),el("explorer")},[el]),eh=(0,s.useCallback)(e=>{et(e),en(e=>e+1),el("explorer")},[el]),ex=(0,s.useCallback)(()=>{e&&window.parent.postMessage({type:"OPEN_NOTE",cwd:e},"*")},[e]);return(0,n.jsx)(h.k_,{children:(0,n.jsx)(tw,{activeView:l,onViewChange:el,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(nx,{initialCwd:e,activeTab:m,isGitRepo:J,currentBranch:V,onOpenWorktree:()=>z(!0),onOpenProjectSessions:()=>W(!0),onOpenAliasManager:()=>U(!0),onBranchSwitched:ei}),es&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),r("console.screenshotting")]}),e?(0,n.jsxs)(tk,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(i.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(ng,{tabs:d,activeTabId:u,unreadTabs:x,dragTabIndex:f,dragOverTabIndex:p,isPinned:O,onTogglePin:A,onSwitchTab:b,onCloseTab:g,onNewTab:j,onNewClaude2Tab:y,onNewCodexTab:w,onNewKimiTab:k,onNewOllamaTab:N,onNewDeepseekTab:C,onDragStart:$,onDragOver:T,onDrop:R,onDragEnd:P}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:d.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===u?"block":"hidden"}`,children:(0,n.jsx)(n6,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:M,deepseekModel:e.deepseekModel,onDeepseekModelChange:E,isActive:e.id===u&&"agent"===l,onStateChange:L,onShowGitStatus:ed,onContentSearch:eh,onOpenNote:ex,onCreateScheduledTask:D,onOpenSession:S})},e.id))})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(i.a9,{children:(0,n.jsx)(tC,{onClose:()=>el("agent"),cwd:e,initialTab:Y,tabSwitchTrigger:G,initialSearchQuery:ee,searchQueryTrigger:er})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(i.a9,{children:(0,n.jsx)(nl,{cwd:e,tabId:"default",onOpenNote:ex})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(ng,{tabs:d,activeTabId:u,unreadTabs:x,dragTabIndex:f,dragOverTabIndex:p,isPinned:O,onTogglePin:A,onSwitchTab:b,onCloseTab:g,onNewTab:j,onNewClaude2Tab:y,onNewCodexTab:w,onNewKimiTab:k,onNewDeepseekTab:C,onDragStart:$,onDragOver:T,onDrop:R,onDragEnd:P}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:d.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===u?"block":"hidden"}`,children:(0,n.jsx)(n6,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:M,deepseekModel:e.deepseekModel,onDeepseekModelChange:E,isActive:e.id===u,onStateChange:L,onCreateScheduledTask:D,onOpenSession:S})},e.id))})]})]}),e&&(0,n.jsx)(a,{isOpen:_,onClose:()=>W(!1),cwd:e,onSelectSession:v}),e&&J&&(0,n.jsx)(tS,{isOpen:q,onClose:()=>z(!1),cwd:e}),H&&(0,n.jsx)(tU,{onClose:()=>U(!1),onSave:()=>U(!1)})]})})})}},60499:(e,t,r)=>{Promise.resolve().then(r.bind(r,30265))}},e=>{e.O(0,[8653,7330,9114,3643,3743,1705,3530,3579,9062,8441,3794,7358],()=>e(e.s=60499)),_N_E=e.O()}]);
|