denchclaw 2.2.0 → 2.2.2
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/apps/web/.next/standalone/apps/web/.next/BUILD_ID +1 -1
- package/apps/web/.next/standalone/apps/web/.next/app-build-manifest.json +185 -178
- package/apps/web/.next/standalone/apps/web/.next/app-path-routes-manifest.json +35 -34
- package/apps/web/.next/standalone/apps/web/.next/build-manifest.json +5 -5
- package/apps/web/.next/standalone/apps/web/.next/react-loadable-manifest.json +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/apps/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/apps/serve/[...path]/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/active/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/stop/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/stream/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/subagents/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/jobs/[jobId]/runs/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/jobs/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/runs/[sessionId]/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/runs/search-transcript/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/feedback/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/memories/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/profiles/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/profiles/switch/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/sessions/[sessionId]/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/skills/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/terminal/port/route.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/terminal/port/route.js.nft.json +1 -0
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/terminal/port/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/[id]/messages/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/[id]/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/assets/[...path]/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/browse/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/browse-file/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/context/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/copy/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/db/introspect/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/db/query/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/delete/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/file/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/init/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/list/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/mkdir/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/move/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/display-field/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/[id]/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/bulk-delete/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/options/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/fields/[fieldId]/enum-rename/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/fields/[fieldId]/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/fields/reorder/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/views/route.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/views/route.js.nft.json +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/views/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/open-file/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/path-info/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/query/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/raw-file/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/rename/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/reports/execute/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/search-index/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/suggest-files/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/switch/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/thumbnail/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/tree/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/upload/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/virtual-file/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/watch/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/write-binary/route_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/page.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/page_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app/workspace/page_client-reference-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/app-paths-manifest.json +35 -34
- package/apps/web/.next/standalone/apps/web/.next/server/chunks/1150.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/server/chunks/8899.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/functions-config-manifest.json +22 -22
- package/apps/web/.next/standalone/apps/web/.next/server/middleware-build-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/apps/web/.next/standalone/apps/web/.next/server/pages/500.html +1 -1
- package/apps/web/.next/standalone/apps/web/.next/static/GMcg5LmEckjlPN9JnIiUs/_buildManifest.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/7858.a92307f116e7eb08.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/apps/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/apps/serve/[...path]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/active/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/stop/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/stream/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/subagents/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/cron/jobs/[jobId]/runs/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/cron/jobs/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/cron/runs/[sessionId]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/cron/runs/search-transcript/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/feedback/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/memories/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/profiles/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/profiles/switch/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/sessions/[sessionId]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/sessions/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/skills/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/terminal/port/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/web-sessions/[id]/messages/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/web-sessions/[id]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/web-sessions/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/assets/[...path]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/browse/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/browse-file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/context/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/copy/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/db/introspect/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/db/query/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/delete/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/init/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/list/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/mkdir/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/move/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/display-field/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/[id]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/bulk-delete/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/options/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/[fieldId]/enum-rename/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/[fieldId]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/reorder/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/views/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/open-file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/path-info/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/query/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/raw-file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/rename/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/reports/execute/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/search-index/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/suggest-files/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/switch/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/thumbnail/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/tree/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/upload/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/virtual-file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/watch/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/write-binary/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/{page-890b7921644e2001.js → page-ea3ef779d7901b04.js} +1 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/{webpack-b4ff13c7886e10c9.js → webpack-11b130b100839707.js} +1 -1
- package/apps/web/.next/standalone/package.json +1 -1
- package/apps/web/.next/static/GMcg5LmEckjlPN9JnIiUs/_buildManifest.js +1 -0
- package/apps/web/.next/static/chunks/7858.a92307f116e7eb08.js +1 -0
- package/apps/web/.next/static/chunks/app/api/apps/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/apps/serve/[...path]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/chat/active/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/chat/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/chat/stop/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/chat/stream/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/chat/subagents/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/cron/jobs/[jobId]/runs/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/cron/jobs/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/cron/runs/[sessionId]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/cron/runs/search-transcript/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/feedback/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/memories/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/profiles/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/profiles/switch/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/sessions/[sessionId]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/sessions/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/skills/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/terminal/port/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/web-sessions/[id]/messages/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/web-sessions/[id]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/web-sessions/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/assets/[...path]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/browse/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/browse-file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/context/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/copy/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/db/introspect/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/db/query/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/delete/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/init/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/list/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/mkdir/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/move/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/display-field/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/[id]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/bulk-delete/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/options/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/[fieldId]/enum-rename/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/[fieldId]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/reorder/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/views/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/open-file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/path-info/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/query/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/raw-file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/rename/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/reports/execute/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/search-index/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/suggest-files/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/switch/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/thumbnail/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/tree/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/upload/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/virtual-file/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/watch/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/api/workspace/write-binary/route-6294b5f2b139fc07.js +1 -0
- package/apps/web/.next/static/chunks/app/{page-890b7921644e2001.js → page-ea3ef779d7901b04.js} +1 -1
- package/apps/web/.next/static/chunks/{webpack-b4ff13c7886e10c9.js → webpack-11b130b100839707.js} +1 -1
- package/package.json +1 -1
- package/apps/web/.next/standalone/apps/web/.next/static/8TiFtXeWNbJK3kK2Uw7Dl/_buildManifest.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/7858.c5e365bb10ae46df.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/apps/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/apps/serve/[...path]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/active/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/stop/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/stream/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/chat/subagents/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/cron/jobs/[jobId]/runs/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/cron/jobs/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/cron/runs/[sessionId]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/cron/runs/search-transcript/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/feedback/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/memories/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/profiles/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/profiles/switch/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/sessions/[sessionId]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/sessions/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/skills/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/web-sessions/[id]/messages/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/web-sessions/[id]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/web-sessions/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/assets/[...path]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/browse/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/browse-file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/context/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/copy/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/db/introspect/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/db/query/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/delete/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/init/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/list/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/mkdir/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/move/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/display-field/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/[id]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/bulk-delete/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/options/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/[fieldId]/enum-rename/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/[fieldId]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/reorder/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/views/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/open-file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/path-info/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/query/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/raw-file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/rename/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/reports/execute/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/search-index/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/suggest-files/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/switch/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/thumbnail/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/tree/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/upload/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/virtual-file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/watch/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/api/workspace/write-binary/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/8TiFtXeWNbJK3kK2Uw7Dl/_buildManifest.js +0 -1
- package/apps/web/.next/static/chunks/7858.c5e365bb10ae46df.js +0 -1
- package/apps/web/.next/static/chunks/app/api/apps/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/apps/serve/[...path]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/chat/active/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/chat/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/chat/stop/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/chat/stream/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/chat/subagents/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/cron/jobs/[jobId]/runs/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/cron/jobs/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/cron/runs/[sessionId]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/cron/runs/search-transcript/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/feedback/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/memories/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/profiles/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/profiles/switch/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/sessions/[sessionId]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/sessions/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/skills/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/web-sessions/[id]/messages/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/web-sessions/[id]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/web-sessions/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/assets/[...path]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/browse/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/browse-file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/context/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/copy/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/db/introspect/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/db/query/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/delete/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/init/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/list/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/mkdir/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/move/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/display-field/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/[id]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/bulk-delete/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/options/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/entries/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/[fieldId]/enum-rename/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/[fieldId]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/fields/reorder/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/objects/[name]/views/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/open-file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/path-info/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/query/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/raw-file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/rename/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/reports/execute/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/search-index/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/suggest-files/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/switch/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/thumbnail/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/tree/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/upload/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/virtual-file/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/watch/route-92144e0c11c84d4d.js +0 -1
- package/apps/web/.next/static/chunks/app/api/workspace/write-binary/route-92144e0c11c84d4d.js +0 -1
- /package/apps/web/.next/standalone/apps/web/.next/static/{8TiFtXeWNbJK3kK2Uw7Dl → GMcg5LmEckjlPN9JnIiUs}/_ssgManifest.js +0 -0
- /package/apps/web/.next/static/{8TiFtXeWNbJK3kK2Uw7Dl → GMcg5LmEckjlPN9JnIiUs}/_ssgManifest.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{395:(e,t,r)=>{"use strict";r.d(t,{V:()=>a});var n=r(80534),o=r(74166),l=r(65163);function a(e){let{name:t="braille",children:r,className:a,style:s}=e,[i,c]=(0,o.useState)(0),d=l.Mb[t];return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>(e+1)%d.frames.length),d.interval);return()=>clearInterval(e)},[t,d.frames.length,d.interval]),(0,n.jsxs)("span",{className:a,style:{fontFamily:"monospace",...s},children:[d.frames[i],null!=r&&(0,n.jsxs)(n.Fragment,{children:[" ",r]})]})}},4582:()=>{},7713:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>ia});var n=r(80534),o=r(74166),l=r(99197),a=r(87694),s=r(17763);function i(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.5},children:[(0,n.jsx)("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function c(e){let{x:t,y:r,target:l,onAction:a,onClose:c}=e,d=(0,o.useRef)(null),u=function(e){let t="empty"!==e.kind&&e.isSystem;return"file"===e.kind?[{action:"open",label:"Open"},{separator:!0},{action:"rename",label:"Rename",shortcut:"Enter",disabled:t},{action:"duplicate",label:"Duplicate",shortcut:"⌘D",disabled:t},{action:"copy",label:"Copy Path",shortcut:"⌘C"},{separator:!0},{action:"getInfo",label:"Get Info",shortcut:"⌘I"},{separator:!0},{action:"delete",label:"Move to Trash",shortcut:"⌘⌫",disabled:t,danger:!0}]:"folder"===e.kind?[{action:"open",label:"Open"},{separator:!0},{action:"newFile",label:"New File",shortcut:"⌘N",disabled:t},{action:"newFolder",label:"New Folder",shortcut:"⇧⌘N",disabled:t},{separator:!0},{action:"rename",label:"Rename",shortcut:"Enter",disabled:t},{action:"duplicate",label:"Duplicate",shortcut:"⌘D",disabled:t},{action:"copy",label:"Copy Path",shortcut:"⌘C"},{separator:!0},{action:"getInfo",label:"Get Info",shortcut:"⌘I"},{separator:!0},{action:"delete",label:"Move to Trash",shortcut:"⌘⌫",disabled:t,danger:!0}]:[{action:"newFile",label:"New File",shortcut:"⌘N"},{action:"newFolder",label:"New Folder",shortcut:"⇧⌘N"},{separator:!0},{action:"paste",label:"Paste",shortcut:"⌘V",disabled:!0}]}(l),x="empty"!==l.kind&&l.isSystem,h=(0,o.useRef)({x:t,y:r});(0,o.useEffect)(()=>{let e=d.current;if(!e)return;let n=e.getBoundingClientRect(),o=window.innerWidth,l=window.innerHeight,a=t,s=r;a+n.width>o-8&&(a=o-n.width-8),s+n.height>l-8&&(s=l-n.height-8),a<8&&(a=8),s<8&&(s=8),h.current={x:a,y:s},e.style.left="".concat(a,"px"),e.style.top="".concat(s,"px")},[t,r]),(0,o.useEffect)(()=>{function e(e){d.current&&!d.current.contains(e.target)&&c()}function t(e){"Escape"===e.key&&c()}function r(){c()}return document.addEventListener("mousedown",e,!0),document.addEventListener("keydown",t,!0),window.addEventListener("scroll",r,!0),()=>{document.removeEventListener("mousedown",e,!0),document.removeEventListener("keydown",t,!0),window.removeEventListener("scroll",r,!0)}},[c]);let p=(0,o.useCallback)((e,t)=>{t||(a(e),c())},[a,c]);return(0,s.createPortal)((0,n.jsxs)("div",{ref:d,className:"fixed z-[9999] min-w-[200px] py-1 rounded-lg shadow-xl border",style:{left:t,top:r,background:"var(--color-surface)",borderColor:"var(--color-border)",backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",animation:"contextMenuFadeIn 100ms ease-out"},role:"menu",children:[x&&(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-[11px]",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(i,{}),(0,n.jsx)("span",{children:"System file (locked)"})]}),u.map((e,t)=>{if("separator"in e&&e.separator)return(0,n.jsx)("div",{className:"my-1 mx-2 border-t",style:{borderColor:"var(--color-border)"}},"sep-".concat(t));let r=e.disabled;return(0,n.jsxs)("button",{type:"button",role:"menuitem",disabled:r,className:"w-full flex items-center gap-2 px-3 py-1.5 text-[13px] text-left transition-colors",style:{color:r?"var(--color-text-muted)":e.danger?"#ef4444":"var(--color-text)",opacity:r?.5:1,cursor:r?"default":"pointer"},onMouseEnter:t=>{r||(t.currentTarget.style.background=e.danger?"rgba(239, 68, 68, 0.1)":"var(--color-surface-hover)")},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},onClick:()=>p(e.action,r),children:[e.icon,(0,n.jsx)("span",{className:"flex-1",children:e.label}),r&&x&&(0,n.jsx)(i,{}),e.shortcut&&(0,n.jsx)("span",{className:"text-[11px] ml-4",style:{color:"var(--color-text-muted)"},children:e.shortcut})]},e.action)}),(0,n.jsx)("style",{children:"\n @keyframes contextMenuFadeIn {\n from { opacity: 0; transform: scale(0.96); }\n to { opacity: 1; transform: scale(1); }\n }\n "})]}),document.body)}function d(e){let{currentName:t,onCommit:r,onCancel:l}=e,[a,s]=(0,o.useState)(t),[i,c]=(0,o.useState)(!1),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=d.current;if(!e)return;e.focus();let r=t.lastIndexOf(".");r>0?e.setSelectionRange(0,r):e.select()},[t]);let u=(0,o.useCallback)(e=>{let t=e.trim();return!(!t||t.includes("/")||t.includes("\\"))},[]),x=(0,o.useCallback)(()=>{let e=a.trim();if(!u(e)){c(!0),setTimeout(()=>c(!1),500);return}if(e===t)return void l();r(e)},[a,t,u,r,l]),h=(0,o.useCallback)(e=>{e.stopPropagation(),"Enter"===e.key?(e.preventDefault(),x()):"Escape"===e.key&&(e.preventDefault(),l())},[x,l]);return(0,n.jsx)("input",{ref:d,type:"text",value:a,onChange:e=>{s(e.target.value),c(!1)},onBlur:x,onKeyDown:h,className:"flex-1 text-sm rounded px-1 py-0 outline-none min-w-0",style:{background:"var(--color-bg)",color:"var(--color-text)",border:i?"1px solid #ef4444":"1px solid var(--color-accent)",animation:i?"renameShake 300ms ease":void 0},onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation()})}let u=new Set(["Chats","Skills","Memories"]);function x(e){return!!e.virtual||e.path.startsWith("~")}let h=[/^\.object\.yaml$/,/\.wal$/,/\.tmp$/],p=[/^workspace\.duckdb/,/^workspace_context\.yaml$/];function m(e){var t;let r=null!=(t=e.split("/").pop())?t:"";return!!h.some(e=>e.test(r))||!e.includes("/")&&p.some(e=>e.test(r))}function f(e){let{open:t}=e;return(0,n.jsx)("img",{src:t?"/icons/folder-open.png":"/icons/folder.png",alt:"",width:16,height:16,draggable:!1,style:{flexShrink:0}})}function v(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]})}function g(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"6",height:"14",x:"2",y:"5",rx:"1"}),(0,n.jsx)("rect",{width:"6",height:"10",x:"9",y:"5",rx:"1"}),(0,n.jsx)("rect",{width:"6",height:"16",x:"16",y:"3",rx:"1"})]})}function y(){return(0,n.jsx)("img",{src:"/icons/document.png",alt:"",width:16,height:16,draggable:!1,style:{flexShrink:0,filter:"drop-shadow(0 0.5px 1.5px rgba(0,0,0,0.2))"}})}function b(){return(0,n.jsx)("img",{src:"/icons/document.png",alt:"",width:16,height:16,draggable:!1,style:{flexShrink:0,filter:"drop-shadow(0 0.5px 1.5px rgba(0,0,0,0.2))"}})}function j(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]})}function k(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",x2:"12",y1:"20",y2:"10"}),(0,n.jsx)("line",{x1:"18",x2:"18",y1:"20",y2:"4"}),(0,n.jsx)("line",{x1:"6",x2:"6",y1:"20",y2:"14"})]})}function w(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function N(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#6366f1",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]})}function C(){return(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.4},children:[(0,n.jsx)("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function S(){return(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.55},children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}function M(e){let{open:t}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:t?"rotate(90deg)":"rotate(0deg)",transition:"transform 150ms ease"},children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}function L(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"})]})}function T(e){let{node:t,open:r}=e;if(t.path.startsWith("~chats/")||"~chats"===t.path)return(0,n.jsx)(w,{});switch(t.type){case"object":return"kanban"===t.defaultView?(0,n.jsx)(g,{}):(0,n.jsx)(v,{});case"document":return(0,n.jsx)(y,{});case"folder":return(0,n.jsx)(f,{open:r});case"database":return(0,n.jsx)(j,{});case"report":return(0,n.jsx)(k,{});case"app":{var o,l;let e=null!=(l=null==(o=t.appManifest)?void 0:o.icon)?l:t.icon;if(e&&(e.endsWith(".png")||e.endsWith(".svg")||e.endsWith(".jpg")||e.endsWith(".jpeg")||e.endsWith(".webp")))return(0,n.jsx)("img",{src:"/api/apps/serve/".concat(t.path,"/").concat(e),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",style:{objectFit:"cover"}});return(0,n.jsx)(N,{})}default:return(0,n.jsx)(b,{})}}function D(e){switch(e.type){case"object":return"var(--color-accent)";case"document":return"#60a5fa";case"database":return"#c084fc";case"report":return"#22c55e";case"app":return"#6366f1";default:return"var(--color-text-muted)"}}async function E(e,t){return(await fetch("/api/workspace/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,newName:t})})).json()}async function R(e){return(await fetch("/api/workspace/file",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})).json()}async function W(e,t){return(await fetch("/api/workspace/move",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourcePath:e,destinationDir:t})})).json()}async function I(e){return(await fetch("/api/workspace/copy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})).json()}async function B(e){return(await fetch("/api/workspace/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})).json()}async function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,content:t})})).json()}function A(e){let{message:t,onConfirm:r,onCancel:l}=e;return(0,o.useEffect)(()=>{function e(e){"Escape"===e.key&&l(),"Enter"===e.key&&r()}return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r,l]),(0,n.jsx)("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)"},children:(0,n.jsxs)("div",{className:"rounded-xl p-5 max-w-sm w-full shadow-2xl border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[(0,n.jsx)("p",{className:"text-sm mb-4",style:{color:"var(--color-text)"},children:t}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:l,className:"px-3 py-1.5 rounded-md text-sm",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:r,className:"px-3 py-1.5 rounded-md text-sm text-white",style:{background:"#ef4444"},children:"Delete"})]})]})})}function P(e){let{kind:t,parentPath:r,onSubmit:l,onCancel:a}=e,[s,i]=(0,o.useState)("file"===t?"untitled.md":"new-folder"),c=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let e=c.current;if(e)if(e.focus(),"file"===t){let t=s.lastIndexOf(".");e.setSelectionRange(0,t>0?t:s.length)}else e.select()},[]),(0,n.jsx)("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)"},children:(0,n.jsxs)("div",{className:"rounded-xl p-5 max-w-sm w-full shadow-2xl border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[(0,n.jsxs)("p",{className:"text-sm mb-3 font-medium",style:{color:"var(--color-text)"},children:["New ",t," in ",(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:r||"/"})]}),(0,n.jsx)("input",{ref:c,type:"text",value:s,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&l(s.trim()),"Escape"===e.key&&a()},className:"w-full px-3 py-2 rounded-md text-sm outline-none border",style:{background:"var(--color-bg)",color:"var(--color-text)",borderColor:"var(--color-border)"}}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-3",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 rounded-md text-sm",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l(s.trim()),className:"px-3 py-1.5 rounded-md text-sm text-white",style:{background:"var(--color-accent)"},children:"Create"})]})]})})}function _(e){let{node:t,depth:r,activePath:l,selectedPath:s,onSelect:i,onNodeSelect:c,expandedPaths:u,onToggleExpand:h,renamingPath:p,onStartRename:f,onCommitRename:v,onCancelRename:g,onContextMenu:y,compact:b,dragOverPath:j,workspaceRoot:k}=e,w=!!k&&t.path===k,N=t.children&&t.children.length>0,E=!w&&"app"!==t.type&&(N||"folder"===t.type||"object"===t.type),R=!w&&u.has(t.path),W=l===t.path,I=s===t.path,B=p===t.path,F=m(t.path),A=x(t),P=F||A||w,z=j===t.path&&E,{attributes:O,listeners:U,setNodeRef:H,isDragging:V}=(0,a.PM)({id:"drag-".concat(t.path),data:{node:t},disabled:P}),{setNodeRef:J,isOver:K}=(0,a.zM)({id:"drop-".concat(t.path),data:{node:t},disabled:!E||A}),q=(0,o.useCallback)(()=>{c(t.path),i(t),E&&h(t.path)},[t,E,i,c,h]),G=(0,o.useCallback)(()=>{P||f(t.path)},[t.path,P,f]),$=(0,o.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(t.path),y(e,t)},[t,c,y]),Z=(0,o.useCallback)(e=>{H(e),J(e)},[H,J]),Y=(K||z)&&E;return(0,n.jsxs)("div",{style:{opacity:V?.4:1},children:[(0,n.jsxs)("div",{ref:Z,...O,...U,role:"treeitem",tabIndex:-1,draggable:!P,onDragStart:e=>{e.dataTransfer.setData("application/x-file-mention",JSON.stringify({name:t.name,path:t.path})),e.dataTransfer.setData("text/plain",t.path),e.dataTransfer.effectAllowed="copy"},onClick:q,onDoubleClick:G,onContextMenu:$,className:"w-full flex items-center gap-1.5 py-1 px-2 rounded-md text-left text-sm transition-colors duration-100 cursor-pointer select-none",style:{paddingLeft:"".concat(16*r+8,"px"),background:w||Y?"var(--color-accent-light)":I||W?"var(--color-surface-hover)":"transparent",color:w?"var(--color-accent)":W||I?"var(--color-text)":"var(--color-text-muted)",outline:w?"1.5px solid var(--color-accent)":Y?"1px dashed var(--color-accent)":"none",outlineOffset:"-1px",borderRadius:w?"8px":"6px",marginTop:w?"2px":void 0,marginBottom:w?"2px":void 0},onMouseEnter:e=>{w?e.currentTarget.style.opacity="0.8":W||I||Y||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{w?e.currentTarget.style.opacity="1":W||I||Y||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{className:"flex-shrink-0 w-4 h-4 flex items-center justify-center",style:{opacity:+!!E,cursor:E?"pointer":void 0},onClick:E?e=>{e.stopPropagation(),h(t.path)}:void 0,children:E&&(0,n.jsx)(M,{open:R})}),(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",style:{color:w?"var(--color-accent)":D(t)},children:w?(0,n.jsx)(L,{}):(0,n.jsx)(T,{node:t,open:R})}),B?(0,n.jsx)(d,{currentName:t.name,onCommit:v,onCancel:g}):(0,n.jsx)("span",{className:"truncate flex-1",children:t.name}),w&&(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0 font-medium",style:{background:"var(--color-accent)",color:"white"},children:"workspace"}),"app"===t.type&&(0,n.jsx)("span",{className:"text-[9px] px-1.5 py-[1px] rounded flex-shrink-0 font-medium",style:{background:"#6366f118",color:"#6366f1"},children:"APP"}),P&&!w&&!b&&(0,n.jsx)("span",{className:"flex-shrink-0 ml-1",children:(0,n.jsx)(C,{})}),t.symlink&&!b&&(0,n.jsx)("span",{className:"flex-shrink-0 ml-0.5",title:"Symbolic link",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(S,{})}),"object"===t.type&&(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",style:{background:"var(--color-accent-light)",color:"var(--color-accent)"},children:"kanban"===t.defaultView?"board":"table"})]}),R&&N&&(0,n.jsx)("div",{className:"relative",style:{borderLeft:r>0?"1px solid var(--color-border)":"none",marginLeft:"".concat(16*r+16,"px")},children:t.children.map(e=>(0,n.jsx)(_,{node:e,depth:r+1,activePath:l,selectedPath:s,onSelect:i,onNodeSelect:c,expandedPaths:u,onToggleExpand:h,renamingPath:p,onStartRename:f,onCommitRename:v,onCancelRename:g,onContextMenu:y,compact:b,dragOverPath:j,workspaceRoot:k},e.path))})]})}function z(e){let{isDragging:t}=e,{setNodeRef:r,isOver:o}=(0,a.zM)({id:"drop-__root__",data:{rootDrop:!0}}),l=o&&t;return(0,n.jsx)("div",{ref:r,className:"flex-1 min-h-[48px]",style:{margin:t?"4px 8px":void 0,borderRadius:"6px",border:l?"1.5px dashed var(--color-accent)":t?"1.5px dashed var(--color-border)":"1.5px dashed transparent",background:l?"var(--color-accent-light)":"transparent",transition:"all 150ms ease",display:"flex",alignItems:"center",justifyContent:"center"},children:t&&(0,n.jsx)("span",{className:"text-[11px] select-none",style:{color:l?"var(--color-accent)":"var(--color-text-muted)",opacity:l?1:.6},children:"Drop here to move to root"})})}function O(e){let{node:t}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm shadow-lg border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text)",pointerEvents:"none"},children:[(0,n.jsx)("span",{style:{color:D(t)},children:(0,n.jsx)(T,{node:t})}),(0,n.jsx)("span",{children:t.name})]})}function U(e){let t=e.split("/");return t.pop(),t.join("/")||"."}let H="denchclaw-tree-expanded";function V(e){let{tree:t,activePath:r,onSelect:l,onRefresh:s,compact:i,parentDir:d,onNavigateUp:h,browseDir:p,workspaceRoot:v,onExternalDrop:g}=e,[y,b]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(H);if(e){let t=JSON.parse(e);if(Array.isArray(t))return new Set(t)}}catch(e){}return new Set})()),[j,k]=(0,o.useState)(null),[w,N]=(0,o.useState)(null),[C,S]=(0,o.useState)(null),[M,L]=(0,o.useState)(null),T=(0,o.useRef)({x:0,y:0}),D=(0,o.useRef)(null),V=(0,o.useCallback)(()=>{let e=e=>{T.current={x:e.clientX,y:e.clientY};let t=document.elementFromPoint(e.clientX,e.clientY),r=null==t?void 0:t.closest("[data-chat-drop-target]"),n=document.querySelector("[data-drag-hover]");r&&!r.hasAttribute("data-drag-hover")&&r.setAttribute("data-drag-hover",""),n&&n!==r&&n.removeAttribute("data-drag-hover")};D.current=e,window.addEventListener("pointermove",e,!0)},[]),J=(0,o.useCallback)(()=>{var e;D.current&&(window.removeEventListener("pointermove",D.current,!0),D.current=null),null==(e=document.querySelector("[data-drag-hover]"))||e.removeAttribute("data-drag-hover")},[]);(0,o.useEffect)(()=>J,[J]);let[K,q]=(0,o.useState)(null),[G,$]=(0,o.useState)(null),[Z,Y]=(0,o.useState)(null),Q=(0,o.useRef)(null),X=(0,o.useRef)(null),ee=(0,o.useRef)(null);(0,o.useEffect)(()=>{try{window.localStorage.setItem(H,JSON.stringify([...y]))}catch(e){}},[y]);let et=(0,o.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),er=(0,a.FR)((0,a.MS)(a.AN,{activationConstraint:{distance:8}})),en=(0,o.useCallback)(e=>{let t=e.active.data.current;(null==t?void 0:t.node)&&(L(t.node),V())},[V]),eo=(0,o.useCallback)(e=>{var t;let r=null==(t=e.over)?void 0:t.data.current;if(null==r?void 0:r.rootDrop)"__root__"!==ee.current&&(X.current&&clearTimeout(X.current),ee.current="__root__"),S("__root__");else if(null==r?void 0:r.node){let e=r.node.path;S(e),ee.current!==e&&(X.current&&clearTimeout(X.current),ee.current=e,("folder"===r.node.type||"object"===r.node.type)&&(X.current=setTimeout(()=>{ee.current===e&&b(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},300)))}else X.current&&clearTimeout(X.current),ee.current=null,S(null)},[]),el=(0,o.useCallback)(async e=>{var t;L(null),S(null),X.current&&clearTimeout(X.current),ee.current=null,J();let r=e.active.data.current;if(!(null==r?void 0:r.node))return;let n=r.node;if(g){let{x:e,y:t}=T.current,r=document.elementFromPoint(e,t);if(null==r?void 0:r.closest("[data-chat-drop-target]"))return void g(n)}let o=null==(t=e.over)?void 0:t.data.current;if(null==o?void 0:o.rootDrop){if("."===U(n.path))return;(await W(n.path,".")).ok&&s();return}if(!(null==o?void 0:o.node))return;let l=o.node;!("folder"!==l.type&&"object"!==l.type||l.path===n.path||l.path.startsWith(n.path+"/"))&&U(n.path)!==l.path&&(await W(n.path,l.path)).ok&&s()},[s,g,J]),ea=(0,o.useCallback)(()=>{L(null),S(null),X.current&&clearTimeout(X.current),ee.current=null,J()},[J]),es=(0,o.useCallback)((e,t)=>{let r=m(t.path)||x(t),n="folder"===t.type||"object"===t.type;q({x:e.clientX,y:e.clientY,target:{kind:n?"folder":"file",path:t.path,name:t.name,isSystem:r}})},[]),ei=(0,o.useCallback)(e=>{e.preventDefault(),q({x:e.clientX,y:e.clientY,target:{kind:"empty"}})},[]),ec=(0,o.useCallback)(async e=>{let r=null==K?void 0:K.target;if(r)switch(e){case"open":if("empty"!==r.kind){let e=function e(t,r){for(let n of t){if(n.path===r)return n;if(n.children){let t=e(n.children,r);if(t)return t}}return null}(t,r.path);e&&l(e)}break;case"rename":"empty"!==r.kind&&N(r.path);break;case"duplicate":"empty"!==r.kind&&(await I(r.path),s());break;case"copy":case"getInfo":"empty"!==r.kind&&await navigator.clipboard.writeText(r.path);break;case"delete":"empty"!==r.kind&&$(r.path);break;case"newFile":Y({kind:"file",parentPath:"folder"===r.kind?r.path:"file"===r.kind?U(r.path):""});break;case"newFolder":Y({kind:"folder",parentPath:"folder"===r.kind?r.path:"file"===r.kind?U(r.path):""})}},[K,t,l,s]),ed=(0,o.useCallback)(async e=>{if(!w)return;if(u.has(e)){alert('"'.concat(e,'" is a reserved name and cannot be used.')),N(null);return}let t=await E(w,e);N(null),t.ok&&s()},[w,s]),eu=(0,o.useCallback)(()=>{N(null)},[]),ex=(0,o.useCallback)(async()=>{if(!G)return;let e=await R(G);$(null),e.ok&&s()},[G,s]),eh=(0,o.useCallback)(async e=>{if(!Z||!e)return;if(u.has(e))return void alert('"'.concat(e,'" is a reserved name and cannot be used.'));let t=Z.parentPath?"".concat(Z.parentPath,"/").concat(e):e;"folder"===Z.kind?await B(t):await F(t,""),Y(null),s(),b(e=>{let t=new Set(e);return t.add(Z.parentPath),t})},[Z,s]),ep=(0,o.useCallback)(e=>{if(w)return;let r=function(e,t){let r=[];return!function e(n){for(let o of n)r.push(o),o.children&&t.has(o.path)&&e(o.children)}(e),r}(t,y),n=r.findIndex(e=>e.path===j),o=n>=0?r[n]:null;switch(e.key){case"ArrowDown":{e.preventDefault();let t=n<r.length-1?r[n+1]:r[0];t&&k(t.path);break}case"ArrowUp":{e.preventDefault();let t=n>0?r[n-1]:r[r.length-1];t&&k(t.path);break}case"ArrowRight":e.preventDefault(),o&&("folder"===o.type||"object"===o.type)&&b(e=>new Set([...e,o.path]));break;case"ArrowLeft":e.preventDefault(),o&&y.has(o.path)&&b(e=>{let t=new Set(e);return t.delete(o.path),t});break;case"Enter":if(e.preventDefault(),o){let t=m(o.path)||x(o);e.shiftKey||t?l(o):N(o.path)}break;case"F2":e.preventDefault(),!o||m(o.path)||x(o)||N(o.path);break;case"Backspace":case"Delete":!o||m(o.path)||x(o)||(e.preventDefault(),$(o.path));break;default:if(e.metaKey||e.ctrlKey){if("c"===e.key&&o)e.preventDefault(),navigator.clipboard.writeText(o.path);else if("d"===e.key&&o&&!m(o.path))e.preventDefault(),I(o.path).then(()=>s());else if("n"===e.key){e.preventDefault();let t=o?"folder"===o.type||"object"===o.type?o.path:U(o.path):"";e.shiftKey?Y({kind:"folder",parentPath:t}):Y({kind:"file",parentPath:t})}}}},[t,y,j,w,l,s]);return 0===t.length?(0,n.jsxs)("div",{className:"px-4 py-6 text-center text-sm",style:{color:"var(--color-text-muted)"},onContextMenu:ei,children:["No files in workspace",K&&(0,n.jsx)(c,{x:K.x,y:K.y,target:K.target,onAction:ec,onClose:()=>q(null)}),Z&&(0,n.jsx)(P,{kind:Z.kind,parentPath:Z.parentPath,onSubmit:eh,onCancel:()=>Y(null)})]}):(0,n.jsxs)(a.Mp,{sensors:er,collisionDetection:a.fp,onDragStart:en,onDragOver:eo,onDragEnd:el,onDragCancel:ea,children:[(0,n.jsxs)("div",{ref:Q,className:"py-1 outline-none flex flex-col min-h-full",tabIndex:0,role:"tree",onKeyDown:ep,onContextMenu:ei,children:[null!=d&&h&&(0,n.jsxs)("div",{role:"treeitem",tabIndex:-1,onClick:h,className:"w-full flex items-center gap-1.5 py-1 px-2 rounded-md text-left text-sm transition-colors duration-100 cursor-pointer select-none",style:{paddingLeft:"8px",color:"var(--color-text-muted)",borderRadius:"6px"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{className:"flex-shrink-0 w-4 h-4 flex items-center justify-center",children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})})}),(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(f,{})}),(0,n.jsx)("span",{className:"truncate flex-1",children:".."})]}),t.map(e=>(0,n.jsx)(_,{node:e,depth:0,activePath:r,selectedPath:j,onSelect:l,onNodeSelect:k,expandedPaths:y,onToggleExpand:et,renamingPath:w,onStartRename:N,onCommitRename:ed,onCancelRename:eu,onContextMenu:es,compact:i,dragOverPath:C,workspaceRoot:v},e.path)),(0,n.jsx)(z,{isDragging:!!M})]}),(0,n.jsx)(a.Hd,{dropAnimation:null,style:{pointerEvents:"none"},children:M?(0,n.jsx)(O,{node:M}):null}),K&&(0,n.jsx)(c,{x:K.x,y:K.y,target:K.target,onAction:ec,onClose:()=>q(null)}),G&&(0,n.jsx)(A,{message:'Are you sure you want to delete "'.concat(G.split("/").pop(),'"? This action cannot be undone.'),onConfirm:ex,onCancel:()=>$(null)}),Z&&(0,n.jsx)(P,{kind:Z.kind,parentPath:Z.parentPath,onSubmit:eh,onCancel:()=>Y(null)}),(0,n.jsx)("style",{children:"\n @keyframes renameShake {\n 0%, 100% { transform: translateX(0); }\n 20%, 60% { transform: translateX(-3px); }\n 40%, 80% { transform: translateX(3px); }\n }\n"})]})}function J(e){return e.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Za-z]:[/\\]Users[/\\][^/\\]+/,"~")}function K(e){let{onWorkspaceSwitch:t,onWorkspaceDelete:r,onCreateWorkspace:l,activeWorkspaceHint:a,trigger:s}=e,[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(null),[x,h]=(0,o.useState)(!1),[p,m]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),[g,y]=(0,o.useState)(null),b=(0,o.useRef)(null),j=(0,o.useCallback)(async()=>{try{var e,t,r,n,o,l,a,s;let i=await fetch("/api/workspace/list"),d=await i.json(),x=(null!=(n=null!=(r=d.workspaces)?r:d.profiles)?n:[]).filter(e=>!!e.workspaceDir),h=null!=(l=null!=(o=d.activeWorkspace)?o:d.activeProfile)?l:null,p=h&&x.some(e=>e.name===h)?h:null!=(s=null!=(a=null==(e=x.find(e=>e.isActive))?void 0:e.name)?a:null==(t=x[0])?void 0:t.name)?s:null;c(x),u(p)}catch(e){}},[]);(0,o.useEffect)(()=>{j()},[j,a]),(0,o.useEffect)(()=>{function e(e){b.current&&!b.current.contains(e.target)&&h(!1)}if(x)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[x]);let k=async e=>{if(e===d)return void h(!1);y(null),m(!0);try{var r,n,o;let l=await fetch("/api/workspace/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workspace:e})});if(l.ok){let e=await l.json();u(null!=(n=null!=(r=e.activeWorkspace)?r:e.activeProfile)?n:null),null==t||t(),j()}else{let e=await l.json().catch(()=>({}));y(null!=(o=e.error)?o:"Failed to switch workspace.")}}catch(e){y("Failed to switch workspace.")}finally{m(!1),h(!1)}},w=async e=>{let n=i.find(t=>t.name===e);if((null==n?void 0:n.workspaceDir)&&window.confirm('Delete workspace "'.concat(e,'"?\n\nThis permanently removes:\n').concat(J(n.workspaceDir),"\n\nThis cannot be undone."))){y(null),v(e);try{let n=await fetch("/api/workspace/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workspace:e})});if(!n.ok){var o;let t=await n.json().catch(()=>({}));y(null!=(o=t.error)?o:"Failed to delete workspace '".concat(e,"'."));return}e===d&&(null==t||t()),null==r||r(e),await j()}catch(t){y("Failed to delete workspace '".concat(e,"'."))}finally{v(null)}}},N=i.length>0,C=()=>{N&&h(e=>!e)};return s||N?(0,n.jsxs)("div",{className:"relative ".concat(s?"flex-1 min-w-0":""),ref:b,children:[s?s({isOpen:x,onClick:C,activeWorkspace:d,switching:p}):(0,n.jsxs)("button",{onClick:C,disabled:p,className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-xs transition-colors hover:bg-[var(--color-surface-hover)] disabled:opacity-50",style:{color:"var(--color-text-secondary)"},title:"Switch workspace",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})}),(0,n.jsx)("span",{className:"truncate max-w-[120px]",children:null!=d?d:"No workspace"}),(0,n.jsx)("svg",{className:"w-3 h-3 transition-transform ".concat(x?"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"})})]}),N&&x&&(0,n.jsxs)("div",{className:"absolute left-0 top-full mt-1 w-64 rounded-lg overflow-hidden z-50",style:{background:"var(--color-surface-raised)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-lg)"},children:[(0,n.jsx)("div",{className:"px-3 py-2 text-xs font-medium",style:{color:"var(--color-text-muted)",borderBottom:"1px solid var(--color-border)"},children:"Workspaces"}),(0,n.jsx)("div",{className:"py-1 max-h-64 overflow-y-auto",children:i.map(e=>{let t=e.name===d;return(0,n.jsxs)("div",{className:"flex items-center gap-1 px-1.5 py-0.5",children:[(0,n.jsxs)("button",{onClick:()=>void k(e.name),disabled:p||!!f,className:"flex-1 min-w-0 flex items-center gap-2 px-1.5 py-1.5 rounded text-left text-sm transition-colors hover:bg-[var(--color-surface-hover)] disabled:opacity-50",style:{color:"var(--color-text)"},children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:t?"var(--color-success)":"transparent",border:t?"none":"1px solid var(--color-border-strong)"}}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"flex items-center gap-1.5",children:(0,n.jsx)("span",{className:"truncate font-medium",children:e.name})}),(0,n.jsx)("div",{className:"text-xs truncate mt-0.5",style:{color:"var(--color-text-muted)"},children:e.workspaceDir?J(e.workspaceDir):"No workspace yet"})]}),t&&(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded",style:{background:"var(--color-accent-light)",color:"var(--color-accent)"},children:"Active"})]}),e.workspaceDir&&(0,n.jsx)("button",{onClick:()=>void w(e.name),disabled:p||!!f,title:"Delete workspace ".concat(e.name),className:"p-1.5 rounded transition-colors hover:bg-[var(--color-surface-hover)] disabled:opacity-50",style:{color:f===e.name?"var(--color-text-muted)":"var(--color-error)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M8 6V4h8v2"}),(0,n.jsx)("path",{d:"M19 6l-1 14H6L5 6"}),(0,n.jsx)("path",{d:"M10 11v6"}),(0,n.jsx)("path",{d:"M14 11v6"})]})})]},e.name)})}),g&&(0,n.jsx)("p",{className:"mx-3 mb-2 mt-1 rounded px-2 py-1 text-xs",style:{background:"rgba(220, 38, 38, 0.08)",color:"var(--color-error)"},children:g}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--color-border)"},children:(0,n.jsxs)("button",{onClick:()=>{h(!1),null==l||l()},className:"w-full flex items-center gap-2 px-3 py-2.5 text-sm transition-colors hover:bg-[var(--color-surface-hover)]",style:{color:"var(--color-accent)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]}),"New Workspace"]})})]})]}):null}function q(e){let{isOpen:t,onClose:r,onCreated:l}=e,[a,s]=(0,o.useState)(""),[i,c]=(0,o.useState)(!0),[d,u]=(0,o.useState)(!1),[x,h]=(0,o.useState)(null),[p,m]=(0,o.useState)(null),f=(0,o.useRef)(null),v=(0,o.useRef)(null);(0,o.useEffect)(()=>{t&&(s(""),h(null),m(null),setTimeout(()=>{var e;return null==(e=f.current)?void 0:e.focus()},100))},[t]),(0,o.useEffect)(()=>{function e(e){"Escape"===e.key&&r()}if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,r]);let g=async()=>{let e=a.trim();if(!e)return void h("Please enter a workspace name.");if(!/^[a-zA-Z0-9_-]+$/.test(e))return void h("Name must use only letters, numbers, hyphens, or underscores.");u(!0),h(null);try{var t;let r=await fetch("/api/workspace/init",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workspace:e,seedBootstrap:i})}),n=await r.json();if(!r.ok)return void h(n.error||"Failed to create workspace.");m({workspaceDir:n.workspaceDir,seededFiles:null!=(t=n.seededFiles)?t:[]}),null==l||l()}catch(e){h(e.message)}finally{u(!1)}};return t?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)"},onClick:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{ref:v,className:"w-full max-w-md rounded-xl overflow-hidden",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-xl)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("h2",{className:"text-base font-semibold",style:{color:"var(--color-text)"},children:"New Workspace"}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]}),(0,n.jsx)("div",{className:"px-5 py-4 space-y-4",children:p?(0,n.jsxs)("div",{className:"text-center py-4",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center mx-auto mb-3",style:{background:"rgba(22, 163, 74, 0.1)"},children:(0,n.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"#16a34a",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})})}),(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"Workspace created"}),(0,n.jsx)("code",{className:"text-xs px-2 py-1 rounded mt-2 inline-block",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:p.workspaceDir.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Za-z]:[/\\]Users[/\\][^/\\]+/,"~")}),p.seededFiles.length>0&&(0,n.jsxs)("p",{className:"text-xs mt-2",style:{color:"var(--color-text-muted)"},children:["Seeded: ",p.seededFiles.join(", ")]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium mb-1.5",style:{color:"var(--color-text-secondary)"},children:"Workspace name"}),(0,n.jsx)("input",{ref:f,type:"text",value:a,onChange:e=>{s(e.target.value),h(null)},onKeyDown:e=>{"Enter"!==e.key||d||g()},placeholder:"e.g. work, personal, project-x",className:"w-full px-3 py-2 text-sm rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--color-accent)]",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),(0,n.jsxs)("p",{className:"text-xs mt-1",style:{color:"var(--color-text-muted)"},children:["This creates a workspace under ~/.openclaw-dench/workspace-","{name}","."]})]}),(0,n.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer hidden",children:[(0,n.jsx)("input",{type:"checkbox",checked:i,onChange:e=>c(e.target.checked),className:"rounded",style:{accentColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-secondary)"},children:"Seed bootstrap files and workspace database"})]}),x&&(0,n.jsx)("p",{className:"text-sm px-3 py-2 rounded-lg",style:{background:"rgba(220, 38, 38, 0.08)",color:"var(--color-error)"},children:x})]})}),(0,n.jsx)("div",{className:"flex items-center justify-end gap-2 px-5 py-3",style:{borderTop:"1px solid var(--color-border)"},children:p?(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 text-sm font-medium rounded-lg transition-colors",style:{background:"var(--color-accent)",color:"#fff"},children:"Done"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 text-sm rounded-lg transition-colors hover:bg-[var(--color-surface-hover)]",style:{color:"var(--color-text-secondary)"},children:"Cancel"}),(0,n.jsx)("button",{onClick:()=>void g(),disabled:d||!a.trim(),className:"px-4 py-2 text-sm font-medium rounded-lg transition-colors disabled:opacity-50",style:{background:"var(--color-accent)",color:"#fff"},children:d?"Creating...":"Create Workspace"})]})})]})}):null}var G=r(395);function $(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),(0,n.jsx)("polyline",{points:"9 22 9 12 15 12 15 22"})]})}function Z(){return(0,n.jsx)("img",{src:"/icons/folder-open.png",alt:"",width:20,height:20,draggable:!1,style:{flexShrink:0}})}function Y(){let[e,t]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{t(document.documentElement.classList.contains("dark"))},[]),(0,n.jsx)("button",{type:"button",onClick:()=>{let r=!e;t(r),r?(document.documentElement.classList.add("dark"),localStorage.setItem("theme","dark")):(document.documentElement.classList.remove("dark"),localStorage.setItem("theme","light"))},className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:e?"Switch to light mode":"Switch to dark mode",children:e?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M12 2v2"}),(0,n.jsx)("path",{d:"M12 20v2"}),(0,n.jsx)("path",{d:"m4.93 4.93 1.41 1.41"}),(0,n.jsx)("path",{d:"m17.66 17.66 1.41 1.41"}),(0,n.jsx)("path",{d:"M2 12h2"}),(0,n.jsx)("path",{d:"M20 12h2"}),(0,n.jsx)("path",{d:"m6.34 17.66-1.41 1.41"}),(0,n.jsx)("path",{d:"m19.07 4.93-1.41 1.41"})]}):(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})})}function Q(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]})}function X(){return(0,n.jsx)("img",{src:"/icons/folder.png",alt:"",width:14,height:14,draggable:!1,style:{flexShrink:0}})}function ee(){return(0,n.jsx)("img",{src:"/icons/document.png",alt:"",width:14,height:14,draggable:!1,style:{flexShrink:0,filter:"drop-shadow(0 0.5px 1.5px rgba(0,0,0,0.2))"}})}function et(){return(0,n.jsx)("img",{src:"/icons/document.png",alt:"",width:14,height:14,draggable:!1,style:{flexShrink:0,filter:"drop-shadow(0 0.5px 1.5px rgba(0,0,0,0.2))"}})}function er(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]})}function en(e){let{type:t}=e;switch(t){case"folder":return(0,n.jsx)(X,{});case"document":return(0,n.jsx)(et,{});case"database":return(0,n.jsx)(er,{});default:return(0,n.jsx)(ee,{})}}function eo(e){let{onSelect:t}=e,[r,l]=(0,o.useState)(""),[a,s]=(0,o.useState)([]),[i,c]=(0,o.useState)(!1),[d,u]=(0,o.useState)(!1),[x,h]=(0,o.useState)(0),p=(0,o.useRef)(null),m=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!r.trim()){s([]),c(!1);return}u(!0);let e=setTimeout(async()=>{try{var e;let t=await fetch("/api/workspace/suggest-files?q=".concat(encodeURIComponent(r.trim()))),n=await t.json();s(null!=(e=n.items)?e:[]),c(!0),h(0)}catch(e){s([])}finally{u(!1)}},150);return()=>clearTimeout(e)},[r]),(0,o.useEffect)(()=>{function e(e){m.current&&!m.current.contains(e.target)&&c(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let f=(0,o.useCallback)(e=>{var r,n;"ArrowDown"===e.key?(e.preventDefault(),h(e=>Math.min(e+1,a.length-1))):"ArrowUp"===e.key?(e.preventDefault(),h(e=>Math.max(e-1,0))):"Enter"===e.key&&a[x]?(e.preventDefault(),t(a[x]),l(""),c(!1),null==(r=p.current)||r.blur()):"Escape"===e.key&&(c(!1),l(""),null==(n=p.current)||n.blur())},[a,x,t]),v=(0,o.useCallback)(e=>{t(e),l(""),c(!1)},[t]);return(0,n.jsxs)("div",{ref:m,className:"relative px-3 pt-2 pb-1",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 pointer-events-none",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(Q,{})}),(0,n.jsx)("input",{ref:p,type:"text",value:r,onChange:e=>l(e.target.value),onKeyDown:f,onFocus:()=>{a.length>0&&c(!0)},placeholder:"Search files...",className:"w-full pl-8 pr-3 py-1.5 rounded-lg text-xs outline-none transition-colors",style:{background:"var(--color-bg)",color:"var(--color-text)",border:"1px solid var(--color-border)"}}),d&&(0,n.jsx)("span",{className:"absolute right-2.5 top-1/2 -translate-y-1/2",children:(0,n.jsx)(G.V,{name:"braille",className:"text-sm",style:{color:"var(--color-text-muted)"}})})]}),i&&a.length>0&&(0,n.jsx)("div",{className:"absolute left-3 right-3 mt-1 rounded-lg shadow-lg border overflow-hidden z-50 max-h-[300px] overflow-y-auto",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:a.map((e,t)=>(0,n.jsxs)("button",{type:"button",onClick:()=>v(e),className:"w-full flex items-center gap-2 px-3 py-2 text-left text-xs cursor-pointer transition-colors",style:{background:t===x?"var(--color-surface-hover)":"transparent",color:"var(--color-text)"},onMouseEnter:()=>h(t),children:[(0,n.jsx)("span",{className:"flex-shrink-0",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(en,{type:e.type})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"truncate font-medium",children:e.name}),(0,n.jsx)("div",{className:"truncate",style:{color:"var(--color-text-muted)",fontSize:"10px"},children:e.path.split("/").slice(0,-1).join("/")})]}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0 capitalize",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:e.type})]},e.path))}),i&&r.trim()&&!d&&0===a.length&&(0,n.jsx)("div",{className:"absolute left-3 right-3 mt-1 rounded-lg shadow-lg border z-50 px-3 py-3 text-center",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No files found"})})]})}function el(e){let{tree:t,activePath:r,onSelect:l,onRefresh:a,orgName:s,loading:i,browseDir:c,parentDir:d,onNavigateUp:u,onGoHome:x,onFileSearchSelect:h,workspaceRoot:p,onGoToChat:m,onExternalDrop:f,mobile:v,onClose:g,showHidden:y,onToggleHidden:b,width:j,onCollapse:k,activeWorkspace:w,onWorkspaceChanged:N}=e,C=null!=c,S=v?"280px":null!=j?j:260,[M,L]=(0,o.useState)(!1),T=(0,n.jsxs)("aside",{className:"flex flex-col h-screen shrink-0 ".concat(v?"drawer-left":"border-r"),style:{width:"number"==typeof S?"".concat(S,"px"):S,minWidth:"number"==typeof S?"".concat(S,"px"):S,background:"var(--color-sidebar-bg)",borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[C?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:(0,n.jsx)(Z,{})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},title:c,children:"/"===c?"/":c.split("/").pop()||c}),(0,n.jsx)("div",{className:"text-[11px] truncate",style:{color:"var(--color-text-muted)"},title:c,children:c})]}),x&&(0,n.jsx)("button",{type:"button",onClick:x,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Return to workspace",children:(0,n.jsx)($,{})})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>void(null==m||m()),className:"w-7 h-7 rounded-lg flex items-center justify-center shrink-0 cursor-pointer transition-colors hover:bg-stone-200 dark:hover:bg-stone-700",style:{background:"transparent",color:"var(--color-text-muted)"},title:"All Chats",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),(0,n.jsx)("polyline",{points:"9 22 9 12 15 12 15 22"})]})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-1.5",children:[(0,n.jsx)("div",{className:"text-[13px] font-semibold truncate text-stone-700 dark:text-stone-200",children:s||"Workspace"}),(0,n.jsx)("div",{className:"mt-1",children:(0,n.jsx)(K,{activeWorkspaceHint:null!=w?w:null,onWorkspaceSwitch:()=>{null==N||N()},onWorkspaceDelete:()=>{null==N||N()},onCreateWorkspace:()=>{L(!0)},trigger:e=>{let{onClick:t,activeWorkspace:r,switching:o}=e;return(0,n.jsxs)("button",{type:"button",onClick:t,disabled:o,className:"text-[11px] flex items-center gap-1 truncate w-full transition-colors",style:{color:"var(--color-text-muted)"},title:"Switch workspace",children:[(0,n.jsx)("span",{children:"Workspace"}),(0,n.jsx)("span",{className:"px-1 py-0.5 rounded text-[10px] shrink-0 bg-stone-200 text-stone-600 dark:bg-stone-700 dark:text-stone-300",children:r||"-"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}})})]})]}),k&&(0,n.jsx)("button",{type:"button",onClick:k,className:"p-1 rounded-md shrink-0 transition-colors hover:bg-stone-200 dark:hover:bg-stone-700",style:{color:"var(--color-text-muted)"},title:"Hide sidebar (⌘B)",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M9 3v18"})]})})]}),h&&(0,n.jsx)(eo,{onSelect:h}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-1",children:i?(0,n.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})}):(0,n.jsx)(V,{tree:t,activePath:r,onSelect:l,onRefresh:a,parentDir:d,onNavigateUp:u,browseDir:c,workspaceRoot:p,onExternalDrop:f})}),(0,n.jsxs)("div",{className:"px-3 py-2.5 border-t flex items-center justify-between",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("a",{href:"https://denchclaw.com",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 px-2 py-1.5 rounded-lg text-sm",style:{color:"var(--color-text-muted)"},children:"denchclaw.com"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[b&&(0,n.jsx)("button",{type:"button",onClick:b,className:"p-1.5 rounded-lg transition-colors",style:{color:y?"var(--color-accent)":"var(--color-text-muted)"},title:y?"Hide dotfiles":"Show dotfiles",children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}),(0,n.jsx)("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),(0,n.jsx)("path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}),(0,n.jsx)("path",{d:"m2 2 20 20"})]})})}),(0,n.jsx)(Y,{})]})]})]});return v?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"drawer-backdrop",onClick:()=>void(null==g||g()),children:(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),className:"fixed inset-y-0 left-0 z-50",children:T})}),(0,n.jsx)(q,{isOpen:M,onClose:()=>L(!1),onCreated:()=>{null==N||N()}})]}):(0,n.jsxs)(n.Fragment,{children:[T,(0,n.jsx)(q,{isOpen:M,onClose:()=>L(!1),onCreated:()=>{null==N||N()}})]})}var ea=r(50890),es=r(76552),ei=r(42282),ec=r(24285),ed=r(98832);function eu(e,t,r){return(0,ed.IL)(e.getValue(t),r).passed}function ex(e){let{id:t,children:r,style:o,className:l}=e,{attributes:a,listeners:s,setNodeRef:i,transform:c,transition:d,isDragging:u}=(0,ei.gl)({id:t}),x={...o,transform:ec.Ks.Translate.toString(c),transition:d,opacity:u?.5:1,cursor:"grab"};return(0,n.jsx)("th",{ref:i,style:x,className:l,...a,...s,children:r})}function eh(e){let{direction:t}=e;return t?(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:"asc"===t?(0,n.jsx)("path",{d:"m5 12 7-7 7 7"}):(0,n.jsx)("path",{d:"m19 12-7 7-7-7"})}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.25},children:[(0,n.jsx)("path",{d:"m7 15 5 5 5-5"}),(0,n.jsx)("path",{d:"m7 9 5-5 5 5"})]})}function ep(e){let{columns:t,data:r,loading:l=!1,searchPlaceholder:s="Search...",enableGlobalFilter:i=!0,enableSorting:c=!0,enableRowSelection:d=!1,rowSelection:u,onRowSelectionChange:x,bulkActions:h,enableColumnReordering:p=!1,onColumnReorder:m,initialColumnVisibility:f,onColumnVisibilityChanged:v,pageSize:g=100,onRefresh:y,onAdd:b,addButtonLabel:j="+ Add",onRowClick:k,rowActions:w,toolbarExtra:N,title:C,titleIcon:S,stickyFirstColumn:M=!0,serverPagination:L,onServerSearch:T}=e,[D,E]=(0,o.useState)([]),[R,W]=(0,o.useState)(""),[I,B]=(0,o.useState)([]),[F,A]=(0,o.useState)(null!=f?f:{});(0,o.useEffect)(()=>{A(null!=f?f:{})},[f]);let[P,_]=(0,o.useState)({}),[z,O]=(0,o.useState)(!1),[U,H]=(0,o.useState)(M),[V,J]=(0,o.useState)(!1),[K,q]=(0,o.useState)({pageIndex:0,pageSize:g}),G=(0,o.useRef)(null),$=(0,o.useRef)(null),Z=void 0!==u?u:P,Y=(0,o.useCallback)(e=>"id"in e&&"string"==typeof e.id?e.id:"accessorKey"in e&&"string"==typeof e.accessorKey?e.accessorKey:"",[]),Q=(0,o.useCallback)(e=>{let t=e.map(Y),r=[];return d&&r.push("select"),r.push(...t),w&&r.push("actions"),r},[Y,d,w]),[X,ee]=(0,o.useState)(()=>Q(t));(0,o.useEffect)(()=>{ee(Q(t))},[t,Q]);let et=(0,a.FR)((0,a.MS)(a.AN,{activationConstraint:{distance:5}})),er=(0,o.useCallback)(e=>{let{active:t,over:r}=e;r&&t.id!==r.id&&ee(e=>{let n=e.indexOf(t.id),o=e.indexOf(r.id),l=(0,ei.be)(e,n,o);return null==m||m(l),l})},[m]),en=(0,o.useCallback)(e=>{J(e.currentTarget.scrollLeft>0)},[]);(0,o.useEffect)(()=>{function e(e){G.current&&!G.current.contains(e.target)&&O(!1)}if(z)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[z]);let eo=d?{id:"select",header:e=>{let{table:t}=e;return(0,n.jsx)("input",{type:"checkbox",checked:t.getIsAllPageRowsSelected(),onChange:t.getToggleAllPageRowsSelectedHandler(),className:"w-3.5 h-3.5 rounded accent-[var(--color-accent)] cursor-pointer"})},cell:e=>{let{row:t}=e;return(0,n.jsx)("input",{type:"checkbox",checked:t.getIsSelected(),onChange:t.getToggleSelectedHandler(),onClick:e=>e.stopPropagation(),className:"w-3.5 h-3.5 rounded accent-[var(--color-accent)] cursor-pointer"})},size:40,enableSorting:!1,enableHiding:!1}:null,el=w?{id:"actions",header:()=>null,cell:e=>{let{row:t}=e;return(0,n.jsx)(ef,{row:t.original,actions:w(t.original)})},size:48,enableSorting:!1,enableHiding:!1}:null,ec=(0,o.useMemo)(()=>{let e=[];return eo&&e.push(eo),e.push(...t),el&&e.push(el),e},[t,eo,el]),ed=L?{pageIndex:L.page-1,pageSize:L.pageSize}:void 0,ep=(0,ea.N4)({data:r,columns:ec,state:{sorting:D,globalFilter:R,columnFilters:I,columnVisibility:F,rowSelection:Z,columnOrder:p?X:void 0,pagination:null!=ed?ed:K},onSortingChange:E,onGlobalFilterChange:W,onColumnFiltersChange:B,onColumnVisibilityChange:e=>{let t="function"==typeof e?e(F):e;A(t),null==v||v(t)},onRowSelectionChange:e=>{x?x(e):_(e)},onPaginationChange:L?e=>{let t="function"==typeof e?e(ed):e;t.pageSize!==L.pageSize?L.onPageSizeChange(t.pageSize):t.pageIndex!==L.page-1&&L.onPageChange(t.pageIndex+1)}:q,getCoreRowModel:(0,es.HT)(),getSortedRowModel:c?(0,es.h5)():void 0,getFilteredRowModel:L?void 0:(0,es.hM)(),getPaginationRowModel:L?void 0:(0,es.kW)(),...L?{manualPagination:!0,pageCount:Math.ceil(L.totalCount/L.pageSize)}:{},enableRowSelection:d,enableSorting:c,globalFilterFn:eu,columnResizeMode:"onChange"}),eg=Object.keys(Z).filter(e=>Z[e]).length,ey=ep.getVisibleFlatColumns().filter(e=>"select"!==e.id&&"actions"!==e.id);return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 flex-shrink-0 flex-wrap",style:{borderBottom:"1px solid var(--color-border)"},children:[C&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mr-2",children:[S,(0,n.jsx)("span",{className:"text-sm font-semibold",style:{color:"var(--color-text)"},children:C})]}),i&&(0,n.jsxs)("div",{className:"relative flex-1 min-w-[180px] max-w-[320px]",children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"absolute left-3 top-1/2 -translate-y-1/2",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]}),(0,n.jsx)("input",{type:"text",value:R,onChange:e=>{W(e.target.value),null==T||T(e.target.value)},placeholder:s,className:"w-full pl-9 pr-3 py-1.5 text-xs rounded-full outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"1px solid var(--color-border)"}}),R&&(0,n.jsx)("button",{type:"button",onClick:()=>{W(""),null==T||T("")},className:"absolute right-2.5 top-1/2 -translate-y-1/2",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]}),eg>0&&h&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("span",{className:"text-xs font-medium",style:{color:"var(--color-text-muted)"},children:[eg," selected"]}),h]}),(0,n.jsx)("div",{className:"flex-1"}),N,y&&(0,n.jsx)("button",{type:"button",onClick:y,className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"Refresh",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}),(0,n.jsx)("path",{d:"M21 3v5h-5"}),(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"}),(0,n.jsx)("path",{d:"M3 21v-5h5"})]})}),(0,n.jsxs)("div",{className:"relative",ref:G,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>O(e=>!e),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)",background:z?"var(--color-surface-hover)":"transparent"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M9 3v18"}),(0,n.jsx)("path",{d:"M15 3v18"})]}),"Columns"]}),z&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[200px] rounded-xl overflow-hidden py-1",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-lg)"},children:[(0,n.jsxs)("label",{className:"flex items-center gap-2 px-3 py-2 text-xs cursor-pointer",style:{color:"var(--color-text-muted)",borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:U,onChange:()=>H(e=>!e),className:"w-3.5 h-3.5 rounded accent-[var(--color-accent)]"}),"Freeze first column"]}),0===ey.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs",style:{color:"var(--color-text-muted)"},children:"No toggleable columns"}):ep.getAllLeafColumns().filter(e=>"select"!==e.id&&"actions"!==e.id&&e.getCanHide()).map(e=>{var t,r;return(0,n.jsxs)("label",{className:"flex items-center gap-2 px-3 py-1.5 text-xs cursor-pointer",style:{color:"var(--color-text)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:e.getIsVisible(),onChange:e.getToggleVisibilityHandler(),className:"w-3.5 h-3.5 rounded accent-[var(--color-accent)]"}),"string"==typeof e.columnDef.header?e.columnDef.header:String(null!=(r=null==(t=e.columnDef.meta)?void 0:t.label)?r:e.id)]},e.id)})]})]}),b&&(0,n.jsx)("button",{type:"button",onClick:b,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium",style:{background:"var(--color-accent)",color:"white"},children:j})]}),(0,n.jsx)("div",{ref:$,className:"flex-1 overflow-auto min-w-0",onScroll:en,children:l?(0,n.jsx)(ev,{columnCount:ec.length}):0===r.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:[(0,n.jsxs)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"}),(0,n.jsx)("path",{d:"M9 3v18"})]}),(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No data"})]}):(0,n.jsx)(a.Mp,{sensors:et,collisionDetection:a.fp,onDragEnd:er,children:(0,n.jsxs)("table",{className:"w-full text-sm",style:{borderCollapse:"separate",borderSpacing:0},children:[(0,n.jsx)("thead",{children:ep.getHeaderGroups().map(e=>(0,n.jsx)("tr",{children:(0,n.jsx)(ei.gB,{items:X,strategy:ei.m$,children:e.headers.map((e,t)=>{let r=t===+!!d,o=U&&r,l="select"===e.id,a="actions"===e.id,s=e.column.getCanSort(),i={borderColor:"var(--color-border)",background:"var(--color-surface)",position:"sticky",top:0,zIndex:o||l?31:30,...o?{left:40*!!d,boxShadow:V?"4px 0 8px -2px rgba(0,0,0,0.08)":"none"}:{},...l?{left:0,position:"sticky",zIndex:31,width:40}:{},width:e.getSize()},c=e.isPlaceholder?null:(0,ea.Kv)(e.column.columnDef.header,e.getContext());return!p||l||a?(0,n.jsx)("th",{style:i,className:"text-left px-3 py-2.5 font-medium text-xs uppercase tracking-wider whitespace-nowrap border-b select-none",children:(0,n.jsxs)("span",{className:"flex items-center gap-1 ".concat(s?"cursor-pointer":""),onClick:s?e.column.getToggleSortingHandler():void 0,style:{color:"var(--color-text-muted)"},children:[c,s&&(0,n.jsx)(eh,{direction:e.column.getIsSorted()})]})},e.id):(0,n.jsx)(ex,{id:e.id,style:i,className:"text-left px-3 py-2.5 font-medium text-xs uppercase tracking-wider whitespace-nowrap border-b select-none",children:(0,n.jsxs)("span",{className:"flex items-center gap-1 ".concat(s?"cursor-pointer":""),onClick:s?e.column.getToggleSortingHandler():void 0,children:[c,s&&(0,n.jsx)(eh,{direction:e.column.getIsSorted()})]})},e.id)})})},e.id))}),(0,n.jsx)("tbody",{children:ep.getRowModel().rows.map((e,t)=>{let r=e.getIsSelected();return(0,n.jsx)("tr",{className:"transition-colors duration-75 ".concat(k?"cursor-pointer":""),style:{background:r?"var(--color-accent-light)":t%2==0?"transparent":"var(--color-surface)"},onClick:()=>null==k?void 0:k(e.original,t),onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background=t%2==0?"transparent":"var(--color-surface)")},children:e.getVisibleCells().map((e,t)=>{let o=t===+!!d,l=U&&o,a="select"===e.column.id,s={borderColor:"var(--color-border)",...l?{position:"sticky",left:40*!!d,zIndex:20,background:r?"var(--color-accent-light)":"var(--color-bg)",boxShadow:V?"4px 0 8px -2px rgba(0,0,0,0.08)":"none"}:{},...a?{position:"sticky",left:0,zIndex:20,background:r?"var(--color-accent-light)":"var(--color-bg)",width:40}:{}};return(0,n.jsx)("td",{className:"px-3 py-2 border-b whitespace-nowrap",style:s,children:(0,ea.Kv)(e.column.columnDef.cell,e.getContext())},e.id)})},e.id)})})]})})}),!l&&r.length>0&&(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 text-xs flex-shrink-0",style:{borderTop:"1px solid var(--color-border)",color:"var(--color-text-muted)"},children:[(0,n.jsxs)("span",{children:[L?"Showing ".concat((L.page-1)*L.pageSize+1,"–").concat(Math.min(L.page*L.pageSize,L.totalCount)," of ").concat(L.totalCount," results"):"Showing ".concat(ep.getRowModel().rows.length," of ").concat(r.length," results"),eg>0&&" (".concat(eg," selected)")]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{children:"Rows per page"}),(0,n.jsx)("select",{value:L?L.pageSize:K.pageSize,onChange:e=>{let t=Number(e.target.value);L?L.onPageSizeChange(t):q(e=>({...e,pageSize:t,pageIndex:0}))},className:"px-1.5 py-0.5 rounded-md text-xs outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[20,50,100,250,500].map(e=>(0,n.jsx)("option",{value:e,children:e},e))}),(0,n.jsxs)("span",{children:["Page ",L?L.page:K.pageIndex+1," of ",ep.getPageCount()]}),(0,n.jsx)("div",{className:"flex gap-0.5",children:L?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(em,{onClick:()=>L.onPageChange(1),disabled:L.page<=1,label:"\xab"}),(0,n.jsx)(em,{onClick:()=>L.onPageChange(L.page-1),disabled:L.page<=1,label:"‹"}),(0,n.jsx)(em,{onClick:()=>L.onPageChange(L.page+1),disabled:L.page>=Math.ceil(L.totalCount/L.pageSize),label:"›"}),(0,n.jsx)(em,{onClick:()=>L.onPageChange(Math.ceil(L.totalCount/L.pageSize)),disabled:L.page>=Math.ceil(L.totalCount/L.pageSize),label:"\xbb"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(em,{onClick:()=>q(e=>({...e,pageIndex:0})),disabled:!ep.getCanPreviousPage(),label:"\xab"}),(0,n.jsx)(em,{onClick:()=>ep.previousPage(),disabled:!ep.getCanPreviousPage(),label:"‹"}),(0,n.jsx)(em,{onClick:()=>ep.nextPage(),disabled:!ep.getCanNextPage(),label:"›"}),(0,n.jsx)(em,{onClick:()=>q(e=>({...e,pageIndex:ep.getPageCount()-1})),disabled:!ep.getCanNextPage(),label:"\xbb"})]})})]})]})]})}function em(e){let{onClick:t,disabled:r,label:o}=e;return(0,n.jsx)("button",{type:"button",onClick:t,disabled:r,className:"w-6 h-6 rounded flex items-center justify-center text-xs disabled:opacity-30",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},dangerouslySetInnerHTML:{__html:o}})}function ef(e){let{row:t,actions:r}=e,[l,a]=(0,o.useState)(!1),s=(0,o.useRef)(null);return(0,o.useEffect)(()=>{function e(e){s.current&&!s.current.contains(e.target)&&a(!1)}if(l)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]),(0,n.jsxs)("div",{className:"relative",ref:s,children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),a(e=>!e)},className:"p-1 rounded-md",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"12",cy:"5",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"19",r:"1.5"})]})}),l&&(0,n.jsx)("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[140px] rounded-xl overflow-hidden py-1",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-lg)"},children:r.map((e,r)=>(0,n.jsxs)("button",{type:"button",onClick:r=>{var n;r.stopPropagation(),null==(n=e.onClick)||n.call(e,t),a(!1)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-left",style:{color:"destructive"===e.variant?"var(--color-error)":"var(--color-text)"},children:[e.icon,e.label]},r))})]})}function ev(e){let{columnCount:t}=e;return(0,n.jsx)("div",{className:"p-4 space-y-2",children:Array.from({length:12}).map((e,r)=>(0,n.jsx)("div",{className:"flex gap-3",children:Array.from({length:Math.min(t,6)}).map((e,t)=>(0,n.jsx)("div",{className:"h-8 rounded-lg animate-pulse flex-1",style:{background:"var(--color-surface-hover)",animationDelay:"".concat(50*t,"ms")}},t))},r))})}function eg(e){if(!e)return[];let t=e.trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]}function ey(e){let{relatedObjectName:t,value:r,multiple:l=!1,onChange:a,placeholder:s,variant:i="modal",autoFocus:c=!1}=e,[d,u]=(0,o.useState)(c),[x,h]=(0,o.useState)(""),[p,m]=(0,o.useState)([]),[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(()=>eg(r)),b=(0,o.useRef)(null),j=(0,o.useRef)(null),k=(0,o.useRef)(null);(0,o.useEffect)(()=>{y(eg(r))},[r]);let w=(0,o.useCallback)(async e=>{v(!0);try{let n=new URLSearchParams;e&&n.set("q",e);let o=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/options?").concat(n));if(o.ok){var r;let e=await o.json();m(null!=(r=e.options)?r:[])}}catch(e){}finally{v(!1)}},[t]);(0,o.useEffect)(()=>{d&&w(x)},[d]),(0,o.useEffect)(()=>{if(d)return k.current&&clearTimeout(k.current),k.current=setTimeout(()=>w(x),250),()=>{k.current&&clearTimeout(k.current)}},[x]),(0,o.useEffect)(()=>{d&&j.current&&j.current.focus()},[d]),(0,o.useEffect)(()=>{if(!d)return;let e=e=>{b.current&&!b.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let N=g.map(e=>{var t;let r=p.find(t=>t.id===e),n=null!=(t=null==r?void 0:r.label)?t:e;return{id:e,label:String(null!=n&&"object"==typeof n?JSON.stringify(n):null!=n?n:"")}}),C="inline"===i;return(0,n.jsxs)("div",{ref:b,className:"relative w-full",children:[(0,n.jsxs)("div",{onClick:()=>u(!d),className:"w-full flex items-center flex-wrap gap-1 cursor-pointer min-h-[1.5em] ".concat(C?"text-xs":"px-3 py-2 text-sm rounded-lg"),style:C?{}:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[N.length>0?N.map(e=>{let{id:t,label:r}=e;return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium",style:{background:"rgba(96, 165, 250, 0.1)",color:"#60a5fa",border:"1px solid rgba(96, 165, 250, 0.2)"},children:[(0,n.jsx)("span",{className:"truncate max-w-[160px]",children:String(null!=r?r:"")}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation();let r=g.filter(e=>e!==t);y(r),l?a(0===r.length?"":JSON.stringify(r)):a("")},className:"ml-0.5 hover:opacity-70",style:{color:"#60a5fa"},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]},t)}):(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:null!=s?s:"Select ".concat(t,"...")}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"ml-auto flex-shrink-0",style:{color:"var(--color-text-muted)",transform:d?"rotate(180deg)":void 0,transition:"transform 0.15s"},children:(0,n.jsx)("path",{d:"m6 9 6 6 6-6"})})]}),d&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full rounded-lg shadow-lg overflow-hidden",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",maxHeight:260},children:[(0,n.jsx)("div",{className:"p-2 border-b",style:{borderColor:"var(--color-border)"},children:(0,n.jsx)("input",{ref:j,type:"text",value:x,onChange:e=>h(e.target.value),placeholder:"Search ".concat(t,"..."),className:"w-full px-2.5 py-1.5 text-xs rounded-md outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},onKeyDown:e=>{"Escape"===e.key&&u(!1)}})}),(0,n.jsx)("div",{className:"overflow-y-auto",style:{maxHeight:200},children:f?(0,n.jsx)("div",{className:"px-3 py-4 text-center text-xs",style:{color:"var(--color-text-muted)"},children:"Loading..."}):0===p.length?(0,n.jsx)("div",{className:"px-3 py-4 text-center text-xs",style:{color:"var(--color-text-muted)"},children:x?"No matches found":"No entries"}):p.map(e=>{var t;let r=g.includes(e.id);return(0,n.jsxs)("button",{type:"button",onClick:()=>(e=>{if(l){let t=g.includes(e)?g.filter(t=>t!==e):[...g,e];y(t),a(0===t.length?"":JSON.stringify(t))}else y([e]),a(e),u(!1)})(e.id),className:"w-full text-left px-3 py-2 text-xs flex items-center gap-2 transition-colors",style:{background:r?"var(--color-accent-light, rgba(96, 165, 250, 0.08))":"transparent",color:"var(--color-text)"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--color-surface-hover, rgba(255,255,255,0.04))")},onMouseLeave:e=>{e.currentTarget.style.background=r?"var(--color-accent-light, rgba(96, 165, 250, 0.08))":"transparent"},children:[l&&(0,n.jsx)("span",{className:"w-3.5 h-3.5 rounded border flex items-center justify-center flex-shrink-0",style:{borderColor:r?"var(--color-accent)":"var(--color-border)",background:r?"var(--color-accent)":"transparent"},children:r&&(0,n.jsx)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})})}),!l&&r&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-accent)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})}),(0,n.jsx)("span",{className:"truncate",children:String(null!=e.label&&"object"==typeof e.label?JSON.stringify(e.label):null!=(t=e.label)?t:"")})]},e.id)})})]})]})}var eb=r(68840);let ej=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,ek=/^https?:\/\/\S+$/i,ew=/^\+?[0-9().\-\s]{7,}$/,eN=/^\d{4}-\d{2}-\d{2}$/,eC=/^\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}(?::?\d{2})?)?)?$/,eS=/^\d{1,2}\/\d{1,2}\/\d{2,4}$/,eM=/^([$\u20ac\u00a3\u00a5])\s*(-?\d[\d,]*(?:\.\d+)?)$/,eL=/^-?\d[\d,]*(?:\.\d+)?$/,eT=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","ico","tiff","tif"]),eD=new Set(["mp4","webm","mov","avi","mkv"]),eE=new Set(["mp3","wav","ogg","m4a","aac","flac"]),eR=new Set(["pdf"]),eW=new Set([...eT,...eD,...eE,...eR,"txt","md","json","yaml","yml","csv","sql","doc","docx","xls","xlsx","ppt","pptx","zip","tar","gz"]);function eI(e){var t,r,n,o;return null!=(o=null==(r=(null!=(n=null==(t=e.split("?")[0])?void 0:t.split("#")[0])?n:e).split(".").pop())?void 0:r.toLowerCase())?o:""}function eB(e){let t=eI(e);if(t){if(eT.has(t))return"image";if(eD.has(t))return"video";if(eE.has(t))return"audio";if(eR.has(t))return"pdf"}}function eF(e){return e.startsWith("/")||e.startsWith("~/")||/^[A-Za-z]:[\\/]/.test(e)}function eA(e){let t=(0,eb.lc)(e);if((null==t?void 0:t.kind)==="file")return t.path;let r=function(e){if(!e.startsWith("file://"))return null;try{let t=new URL(e);if("file:"!==t.protocol)return null;let r=decodeURIComponent(t.pathname);if(/^\/[A-Za-z]:\//.test(r))return r.slice(1);return r}catch(e){return null}}(e);if(r)return r;let n=e.trim();return!function(e){let t=e.trim();if(!t||t.includes("://")&&!t.startsWith("file://"))return!1;if(t.startsWith("./")||t.startsWith("../")||eF(t))return!0;let r=t.includes("/")||t.includes("\\"),n=eI(t);return r?n.length>0&&n.length<=8:eW.has(n)}(n)?null:n}function eP(e){let t=e.trim();if(!t)return null;if(t.startsWith("www."))return"https://".concat(t);if(!ek.test(t))return null;try{let e=new URL(t);if("http:"!==e.protocol&&"https:"!==e.protocol)return null;return e.toString()}catch(e){return null}}function e_(e){let t=e.trim();if(!ew.test(t)||t.replace(/\D/g,"").length<7)return null;let r=t.replace(/[^\d+]/g,"");return r?"tel:".concat(r):null}function ez(e){let t=e.replace(/,/g,"").trim();if(!t)return null;let r=Number(t);return Number.isFinite(r)?r:null}function eO(e){return new Intl.NumberFormat(void 0,{maximumFractionDigits:6}).format(e)}function eU(e,t){let r=function(e){switch(e){case"$":return"USD";case"€":return"EUR";case"\xa3":return"GBP";case"\xa5":return"JPY";default:return null}}(e);return r?new Intl.NumberFormat(void 0,{style:"currency",currency:r,maximumFractionDigits:2}).format(t):"".concat(e).concat(eO(t))}function eH(e){let t=function(e){let t,r=e.trim();if(eN.test(r)){let[e,t,n]=r.split("-").map(e=>Number(e)),o=new Date(e,(null!=t?t:1)-1,null!=n?n:1);return Number.isNaN(o.getTime())?null:o}if(!(eC.test(r)||eS.test(r)))return null;let n=new Date(((t=r).includes(" ")&&(t=t.replace(" ","T")),t=(t=(t=t.replace(/(\.\d{3})\d+(?=(?:Z|[+-]\d{2}(?::?\d{2})?)?$)/,"$1")).replace(/([+-]\d{2})$/,"$1:00")).replace(/([+-]\d{2})(\d{2})$/,"$1:$2")));return Number.isNaN(n.getTime())?null:n}(e);return t?{text:e.includes("T")||/\d{1,2}:\d{2}/.test(e)?new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t):new Intl.DateTimeFormat(void 0,{dateStyle:"medium"}).format(t),iso:t.toISOString()}:null}function eV(e){return e.startsWith("http://")||e.startsWith("https://")?e:eF(e)?"/api/workspace/browse-file?path=".concat(encodeURIComponent(e),"&raw=true"):"/api/workspace/raw-file?path=".concat(encodeURIComponent(e))}function eJ(e,t){let r=function(e){if(null==e)return"";if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return String(e);if("object"==typeof e)try{return JSON.stringify(e)}catch(e){}return""}(e);if(!r||0===r.trim().length)return{kind:"empty",raw:r,text:""};let n=(null!=t?t:"").trim().toLowerCase(),o=function(e,t){if("email"===t&&ej.test(e.trim())){let t=e.trim();return{kind:"link",raw:e,text:t,linkType:"email",href:"mailto:".concat(t)}}if("phone"===t){let t=e_(e);if(t)return{kind:"link",raw:e,text:e.trim(),linkType:"phone",href:t}}if("url"===t){let t=eP(e);if(t)return{kind:"link",raw:e,text:e.trim(),linkType:"url",href:t,mediaType:eB(t),embedUrl:t}}if("date"===t){let t=eH(e);if(t)return{kind:"date",raw:e,text:t.text,isoDate:t.iso}}if("number"===t){let t=e.trim().match(eM);if(t){var r,n;let o=ez(null!=(r=t[2])?r:"");if(null!=o)return{kind:"currency",raw:e,text:eU(null!=(n=t[1])?n:"$",o),numericValue:o}}let o=ez(e);if(null!=o)return{kind:"number",raw:e,text:eO(o),numericValue:o}}if("file"===t){let t=eA(e);if(t)return{kind:"link",raw:e,text:t,linkType:"file",href:(0,eb.bJ)(t),filePath:t,mediaType:eB(t),embedUrl:eV(t)}}return null}(r,n);return o||("richtext"===n||"relation"===n||"enum"===n||"user"===n?{kind:"text",raw:r,text:r}:function(e){let t=e.trim(),r=eA(t);if(r)return{kind:"link",raw:e,text:r,linkType:"file",href:(0,eb.bJ)(r),filePath:r,mediaType:eB(r),embedUrl:eV(r)};if(ej.test(t))return{kind:"link",raw:e,text:t,linkType:"email",href:"mailto:".concat(t)};let n=eP(t);if(n)return{kind:"link",raw:e,text:t,linkType:"url",href:n,mediaType:eB(n),embedUrl:n};let o=e_(t);if(o)return{kind:"link",raw:e,text:t,linkType:"phone",href:o};let l=eH(t);if(l)return{kind:"date",raw:e,text:l.text,isoDate:l.iso};let a=t.match(eM);if(a){var s,i;let t=ez(null!=(s=a[2])?s:"");if(null!=t)return{kind:"currency",raw:e,text:eU(null!=(i=a[1])?i:"$",t),numericValue:t}}if(eL.test(t)){let r=ez(t);if(null!=r)return{kind:"number",raw:e,text:eO(r),numericValue:r}}return{kind:"text",raw:e,text:e}}(r))}function eK(){return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"})}function eq(e){let{mediaType:t,url:r,label:o}=e;return"image"===t?(0,n.jsx)("div",{className:"mt-2 rounded-lg overflow-hidden border",style:{borderColor:"var(--color-border)"},children:(0,n.jsx)("img",{src:r,alt:o,className:"max-h-64 w-auto"})}):"video"===t?(0,n.jsx)("video",{src:r,controls:!0,className:"mt-2 w-full max-h-72 rounded-lg border",style:{borderColor:"var(--color-border)",background:"#000"}}):"audio"===t?(0,n.jsx)("audio",{src:r,controls:!0,className:"mt-2 w-full"}):(0,n.jsx)("iframe",{src:"".concat(r,"#toolbar=0&navpanes=0&scrollbar=1"),title:o,className:"mt-2 w-full h-72 rounded-lg border",style:{borderColor:"var(--color-border)",background:"white"}})}function eG(e){let{text:t,fieldType:r}=e,o=t.trim();if(!o)return(0,n.jsx)(n.Fragment,{children:t});let l=r&&"text"!==r&&"richtext"!==r?r:void 0,a=eJ(o,l);if("link"===a.kind&&a.href){if(!l&&"file"===a.linkType&&o.includes(" "))return(0,n.jsx)(n.Fragment,{children:a.text});let e="url"===a.linkType||"file"===a.linkType;return(0,n.jsx)("a",{href:a.href,...e?{target:"_blank",rel:"noopener noreferrer"}:{},className:"underline underline-offset-2",style:{color:"var(--color-accent)"},onClick:e=>e.stopPropagation(),children:a.text})}return"number"===a.kind||"currency"===a.kind?(0,n.jsx)("span",{className:"tabular-nums",children:a.text}):(0,n.jsx)(n.Fragment,{children:a.text})}function e$(e){let{value:t,fieldType:r,mode:l="table",className:a}=e,s=eJ(t,r),i="table"===l;if("empty"===s.kind)return(0,n.jsx)(eK,{});let c=s.text.replace(/\\r\\n/g,"\n").replace(/\\n/g,"\n").replace(/\\r/g,"\n");if(c.includes("\n")){let e=c.split("\n"),t=null!=a?a:i?"block max-w-[300px] line-clamp-3":"break-words";return(0,n.jsx)("span",{className:t,children:e.map((e,t)=>(0,n.jsxs)(o.Fragment,{children:[t>0&&(0,n.jsx)("br",{}),(0,n.jsx)(eG,{text:e,fieldType:r})]},t))})}let d=null!=a?a:i?"truncate block max-w-[300px]":"break-words";if("link"===s.kind&&s.href){let e="url"===s.linkType||"file"===s.linkType,t=!i&&!!s.embedUrl&&!!s.mediaType;return(0,n.jsxs)("div",{className:i?"truncate block max-w-[300px]":"w-full",children:[(0,n.jsx)("a",{href:s.href,...e?{target:"_blank",rel:"noopener noreferrer"}:{},className:"underline underline-offset-2 ".concat(i?"truncate block":""),style:{color:"var(--color-accent)"},onClick:e=>e.stopPropagation(),children:s.text}),t&&(0,n.jsx)(eq,{mediaType:s.mediaType,url:s.embedUrl,label:s.text})]})}return"number"===s.kind||"currency"===s.kind?(0,n.jsx)("span",{className:"tabular-nums ".concat(d),children:s.text}):(0,n.jsx)("span",{className:d,children:c})}function eZ(e){if(null==e)return[];if(Array.isArray(e))return e.map(String).filter(Boolean);let t=String(e).trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]}let eY=["created_at","Created","createdAt","created"],eQ=["updated_at","Updated","updatedAt","updated"];function eX(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):""}function e0(e){switch(e){case"number":return"number";case"date":return"date";case"email":return"email";case"phone":return"tel";case"url":return"url";default:return"text"}}function e1(e,t){for(let r of t){let t=e[r];if(null!=t&&""!==t)return t}}function e2(e){var t;let{value:r,enumValues:o,enumColors:l}=e,a=null!=(t=null==o?void 0:o.indexOf(r))?t:-1,s=a>=0&&l?l[a]:"#94a3b8";return(0,n.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium",style:{background:"".concat(s,"20"),color:s,border:"1px solid ".concat(s,"40")},children:r})}function e4(e){let{value:t}=e,r=!0===t||"true"===t||"1"===t||"yes"===t;return(0,n.jsx)("span",{style:{color:r?"var(--color-success)":"var(--color-text-muted)"},children:r?"Yes":"No"})}function e5(e){var t,r;let{value:o,members:l}=e,a=String(o),s=null==l?void 0:l.find(e=>e.id===a);return(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] font-medium flex-shrink-0",style:{background:"var(--color-accent)",color:"white"},children:(null!=(t=null==s?void 0:s.name)?t:a).charAt(0).toUpperCase()}),(0,n.jsx)("span",{className:"truncate",children:null!=(r=null==s?void 0:s.name)?r:a})]})}function e6(e){let{value:t,field:r,relationLabels:o,onNavigateObject:l,onNavigateEntry:a}=e,s=null==o?void 0:o[r.name],i=function(e){if(!e)return[];let t=e.trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]}(String(t));return 0===i.length?(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"}):(0,n.jsx)("span",{className:"flex items-center gap-1 flex-wrap",children:i.map(e=>{var t;return(0,n.jsx)("span",{onClick:t=>{if(r.related_object_name&&(a||l)){if(t.stopPropagation(),a)return void a(r.related_object_name,e);null==l||l(r.related_object_name)}},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium ".concat(r.related_object_name&&(a||l)?"cursor-pointer":""),style:{background:"var(--color-chip-document)",color:"var(--color-chip-document-text)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("span",{className:"truncate max-w-[180px]",children:null!=(t=null==s?void 0:s[e])?t:e})},e)})})}function e3(e){let{tag:t}=e,r=eJ(t),o="link"===r.kind&&r.href,l={background:"rgba(148, 163, 184, 0.12)",border:"1px solid var(--color-border)"};return o?(0,n.jsx)("a",{href:r.href,target:"url"===r.linkType||"file"===r.linkType?"_blank":void 0,rel:"url"===r.linkType||"file"===r.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium underline-offset-2 hover:underline",style:{...l,color:"var(--color-accent)"},children:r.text}):(0,n.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium",style:{...l,color:"var(--color-text-muted)"},children:t})}function e8(e){let{value:t}=e,r=eZ(t);return 0===r.length?(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"}):(0,n.jsxs)("span",{className:"flex items-center gap-1 flex-wrap",children:[r.slice(0,5).map(e=>(0,n.jsx)(e3,{tag:e},e)),r.length>5&&(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["+",r.length-5]})]})}function e7(e){let{value:t,onChange:r,autoFocus:l}=e,a=eZ(t),[s,i]=(0,o.useState)(""),c=(0,o.useRef)(null);(0,o.useEffect)(()=>{l&&c.current&&c.current.focus()},[l]);let d=e=>{let t=e.trim();!t||a.includes(t)||(r(JSON.stringify([...a,t])),i(""))},u=e=>{let t=a.filter(t=>t!==e);r(t.length>0?JSON.stringify(t):"")};return(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-wrap min-h-[1.5em]",children:[a.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-2 py-0.5 rounded-full text-xs font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[e,(0,n.jsx)("button",{type:"button",onClick:()=>u(e),className:"ml-0.5 hover:opacity-70",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]},e)),(0,n.jsx)("input",{ref:c,type:"text",value:s,onChange:e=>i(e.target.value),onKeyDown:e=>{("Enter"===e.key||","===e.key)&&s.trim()&&(e.preventDefault(),d(s)),"Backspace"===e.key&&!s&&a.length>0&&u(a[a.length-1])},onBlur:()=>{s.trim()&&d(s)},placeholder:0===a.length?"Type and press Enter...":"",className:"flex-1 min-w-[80px] text-xs outline-none bg-transparent",style:{color:"var(--color-text)"}})]})}function e9(e){let{links:t,sourceObjectName:r,onNavigateObject:o,onNavigateEntry:l}=e;if(!t||0===t.length)return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"});let a=t.slice(0,5),s=t.length-a.length;return(0,n.jsxs)("span",{className:"flex items-center gap-1 flex-wrap",children:[a.map(e=>(0,n.jsx)("span",{onClick:t=>{if(l||o){if(t.stopPropagation(),l)return void l(r,e.id);null==o||o(r)}},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium ".concat(l||o?"cursor-pointer":""),style:{background:"var(--color-chip-database)",color:"var(--color-chip-database-text)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("span",{className:"truncate max-w-[180px]",children:e.label})},e.id)),s>0&&(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["+",s]})]})}function te(e){let{value:t,entryId:r,fieldName:l,objectName:a,field:s,members:i,relationLabels:c,onNavigateObject:d,onNavigateEntry:u,onLocalValueChange:x,onSaved:h}=e,[p,m]=(0,o.useState)(!1),[f,v]=(0,o.useState)(eX(t)),g=(0,o.useRef)(null),y=(0,o.useRef)(null);(0,o.useEffect)(()=>{p||v(eX(t))},[t,p]),(0,o.useEffect)(()=>{p&&g.current&&g.current.focus()},[p]);let b=!["user"].includes(s.type),j="relation"===s.type&&!!s.related_object_name,k="tags"===s.type,w=(0,o.useCallback)(async e=>{null==x||x(e);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(a),"/entries/").concat(encodeURIComponent(r)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{[l]:e}})}),null==h||h()}catch(e){}},[a,r,l,x,h]),N=e=>{v(e),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>w(e),500)},C=()=>{y.current&&(clearTimeout(y.current),w(f)),m(!1)},S=e=>{"Enter"===e.key&&C(),"Escape"===e.key&&(m(!1),v(eX(t)))};if(!b)return"user"===s.type?(0,n.jsx)(e5,{value:t,members:i}):(0,n.jsx)("span",{className:"truncate block max-w-[300px]",children:eX(t)});if(p){let e;return j?(0,n.jsx)("div",{className:"-mx-3 -my-2 px-3 py-2",style:{background:"var(--color-bg)",boxShadow:"inset 0 0 0 2px var(--color-accent)"},children:(0,n.jsx)(ey,{relatedObjectName:s.related_object_name,value:eX(t),multiple:"many_to_many"===s.relationship_type,onChange:e=>{w(e),m(!1)},variant:"inline",autoFocus:!0})}):k?(0,n.jsx)("div",{className:"-mx-3 -my-2 px-3 py-2",style:{background:"var(--color-bg)",boxShadow:"inset 0 0 0 2px var(--color-accent)"},children:(0,n.jsx)(e7,{value:eX(t),onChange:e=>{w(e)},autoFocus:!0})}):(e="enum"===s.type&&s.enum_values?(0,n.jsxs)("select",{ref:g,value:f,onChange:e=>{N(e.target.value),m(!1)},onBlur:C,onKeyDown:S,className:"w-full text-xs outline-none bg-transparent",style:{color:"var(--color-text)"},children:[(0,n.jsx)("option",{value:"",children:"--"}),s.enum_values.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}):"boolean"===s.type?(0,n.jsxs)("select",{ref:g,value:f,onChange:e=>{N(e.target.value),m(!1)},onBlur:C,onKeyDown:S,className:"w-full text-xs outline-none bg-transparent",style:{color:"var(--color-text)"},children:[(0,n.jsx)("option",{value:"true",children:"Yes"}),(0,n.jsx)("option",{value:"false",children:"No"})]}):(0,n.jsx)("input",{ref:g,type:e0(s.type),value:f,onChange:e=>N(e.target.value),onBlur:C,onKeyDown:S,className:"w-full text-xs outline-none bg-transparent",style:{color:"var(--color-text)"}}),(0,n.jsx)("div",{className:"-mx-3 -my-2 px-3 py-2",style:{background:"var(--color-bg)",boxShadow:"inset 0 0 0 2px var(--color-accent)"},children:e}))}return j?(0,n.jsx)("div",{onDoubleClick:()=>m(!0),className:"cursor-cell min-h-[1.5em]",title:"Double-click to edit",children:(0,n.jsx)(e6,{value:t,field:s,relationLabels:c,onNavigateObject:d,onNavigateEntry:u})}):k?(0,n.jsx)("div",{onDoubleClick:()=>m(!0),className:"cursor-cell min-h-[1.5em]",title:"Double-click to edit",children:(0,n.jsx)(e8,{value:t})}):(0,n.jsx)("div",{onDoubleClick:()=>m(!0),className:"cursor-cell min-h-[1.5em]",title:"Double-click to edit",children:null==t||""===t?(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"}):"enum"===s.type?(0,n.jsx)(e2,{value:eX(t),enumValues:s.enum_values,enumColors:s.enum_colors}):"boolean"===s.type?(0,n.jsx)(e4,{value:t}):(0,n.jsx)(e$,{value:t,fieldType:s.type,mode:"table"})})}function tt(e){let{objectName:t,fields:r,entries:l,members:a,relationLabels:s,reverseRelations:i,onNavigateToObject:c,onNavigateToEntry:d,onEntryClick:u,onRefresh:x,columnVisibility:h,onColumnVisibilityChanged:p,serverPagination:m,onServerSearch:f}=e,[v,g]=(0,o.useState)({}),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(l);(0,o.useEffect)(()=>{k(l)},[l]);let w=(0,o.useCallback)((e,t,r)=>{k(n=>n.map(n=>{let o=n.entry_id;return String(null!=o&&"object"==typeof o?JSON.stringify(o):null!=o?o:"")!==e?n:{...n,[t]:r}}))},[]),N=(0,o.useMemo)(()=>i?i.filter(e=>Object.keys(e.entries).length>0):[],[i]),C=(0,o.useMemo)(()=>{let e=r.map((e,r)=>({id:e.id,accessorKey:e.name,meta:{label:e.name,fieldName:e.name},header:()=>(0,n.jsxs)("span",{className:"flex items-center gap-1",style:{color:"var(--color-text-muted)"},children:[e.name,"relation"===e.type&&e.related_object_name&&(0,n.jsxs)("span",{className:"text-[9px] font-normal normal-case tracking-normal opacity-60",children:["(",e.related_object_name,")"]})]}),cell:o=>{let l=o.row.original.entry_id,i=String(null!=l&&"object"==typeof l?JSON.stringify(l):null!=l?l:"");if(0===r&&u){let e=o.getValue(),t=null==e||""===e?"--":eX(e),r="--"===t;return(0,n.jsx)("span",{className:"font-semibold truncate block max-w-[300px] ".concat(r?"":"cursor-pointer hover:underline"),style:{color:r?"var(--color-text-muted)":"var(--color-accent)",opacity:r?.5:1},onClick:e=>{e.stopPropagation(),i&&!r&&u(i)},children:t})}return(0,n.jsx)(te,{value:o.getValue(),entryId:i,fieldName:e.name,objectName:t,field:e,members:a,relationLabels:s,onNavigateObject:c,onNavigateEntry:d,onLocalValueChange:t=>w(i,e.name,t),onSaved:x})},size:"richtext"===e.type?300:"relation"===e.type||"tags"===e.type?200:180,enableSorting:!0}));for(let t of(e.push({id:"created_at",accessorFn:e=>e1(e,eY),meta:{label:"Created",fieldName:"created_at"},header:()=>(0,n.jsx)("span",{className:"flex items-center gap-1",style:{color:"var(--color-text-muted)"},children:"Created"}),cell:e=>(0,n.jsx)(e$,{value:e.getValue(),fieldType:"date",mode:"table"}),size:190,enableSorting:!0}),e.push({id:"updated_at",accessorFn:e=>e1(e,eQ),meta:{label:"Updated",fieldName:"updated_at"},header:()=>(0,n.jsx)("span",{className:"flex items-center gap-1",style:{color:"var(--color-text-muted)"},children:"Updated"}),cell:e=>(0,n.jsx)(e$,{value:e.getValue(),fieldType:"date",mode:"table"}),size:190,enableSorting:!0}),N))e.push({id:"rev_".concat(t.sourceObjectName,"_").concat(t.fieldName),meta:{label:"".concat(t.sourceObjectName," (via ").concat(t.fieldName,")")},header:()=>(0,n.jsxs)("span",{className:"flex items-center gap-1.5",style:{color:"var(--color-text-muted)"},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.4},children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]}),(0,n.jsx)("span",{className:"capitalize",children:t.sourceObjectName}),(0,n.jsxs)("span",{className:"text-[9px] font-normal normal-case tracking-normal opacity-50",children:["via ",t.fieldName]})]}),cell:e=>{var r;let o=e.row.original.entry_id,l=String(null!=o&&"object"==typeof o?JSON.stringify(o):null!=o?o:""),a=null!=(r=t.entries[l])?r:[];return(0,n.jsx)(e9,{links:a,sourceObjectName:t.sourceObjectName,onNavigateObject:c,onNavigateEntry:d})},enableSorting:!1,size:200});return e},[r,N,t,a,s,c,d,x]),S=(0,o.useCallback)(()=>{b(!0)},[]),M=(0,o.useCallback)(async()=>{let e=Object.keys(v).filter(e=>v[e]).map(e=>{var t;return eX(null==(t=j[Number(e)])?void 0:t.entry_id)}).filter(Boolean);if(0!==e.length&&confirm("Delete ".concat(e.length," entries?")))try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/bulk-delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entryIds:e})}),g({}),null==x||x()}catch(e){}},[v,j,t,x]),L=(0,o.useCallback)(async e=>{let r=e.entry_id,n=String(null!=r&&"object"==typeof r?JSON.stringify(r):null!=r?r:"");if(n&&confirm("Delete this entry?"))try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(n)),{method:"DELETE"}),null==x||x()}catch(e){}},[t,x]),T=(0,o.useCallback)(e=>{let t=[];return u&&t.push({label:"View details",onClick:e=>{var t;let r=String(null!=(t=e.entry_id)?t:"");r&&u(r)},icon:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}),t.push({label:"Delete",variant:"destructive",onClick:L,icon:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})}),t},[u,L]),D=(0,o.useCallback)(async e=>{let n=new Set(r.map(e=>e.id)),o=e.filter(e=>n.has(e));try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/fields/reorder"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fieldOrder:o})})}catch(e){}},[t,r]),E=(0,n.jsxs)("button",{type:"button",onClick:()=>void M(),className:"flex items-center gap-1 px-2.5 py-1 rounded-lg text-xs font-medium",style:{background:"rgba(220, 38, 38, 0.08)",color:"var(--color-error)",border:"1px solid rgba(220, 38, 38, 0.2)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ep,{columns:C,data:j,enableSorting:!0,enableGlobalFilter:!0,enableRowSelection:!0,enableColumnReordering:!0,rowSelection:v,onRowSelectionChange:g,bulkActions:E,onColumnReorder:D,searchPlaceholder:"Search ".concat(t,"..."),onRefresh:x,onAdd:S,addButtonLabel:"+ Add",rowActions:T,stickyFirstColumn:!0,initialColumnVisibility:h,onColumnVisibilityChanged:p,serverPagination:m,onServerSearch:f}),y&&(0,n.jsx)(tr,{objectName:t,fields:r,members:a,onClose:()=>b(!1),onSaved:x})]})}function tr(e){let{objectName:t,fields:r,members:l,onClose:a,onSaved:s}=e,[i,c]=(0,o.useState)({}),[d,u]=(0,o.useState)(!1),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&a()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a]);let h=(e,t)=>{c(r=>({...r,[e]:t}))},p=async()=>{u(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:i})})).ok&&(null==s||s(),a())}catch(e){}finally{u(!1)}};return(0,n.jsx)("div",{ref:x,onClick:e=>{e.target===x.current&&a()},className:"fixed inset-0 z-50 flex items-start justify-center",style:{background:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)"},children:(0,n.jsxs)("div",{className:"relative mt-12 mb-12 w-full max-w-lg rounded-2xl overflow-hidden shadow-2xl flex flex-col",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",maxHeight:"calc(100vh - 6rem)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("h2",{className:"text-lg font-semibold capitalize",style:{color:"var(--color-text)"},children:["Add ",t]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]}),(0,n.jsx)("form",{onSubmit:e=>{e.preventDefault(),p()},className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:r.map(e=>{var t,r,o,a,s,c,d;let u="relation"===e.type,x="user"===e.type;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"block text-xs font-medium uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:[e.name,u&&e.related_object_name&&(0,n.jsxs)("span",{className:"normal-case tracking-normal font-normal opacity-60 ml-1",children:["(",e.related_object_name,")"]})]}),"tags"===e.type?(0,n.jsx)("div",{className:"w-full px-3 py-2 text-sm rounded-lg",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:(0,n.jsx)(e7,{value:null!=(t=i[e.name])?t:"",onChange:t=>h(e.name,t)})}):"enum"===e.type&&e.enum_values?(0,n.jsxs)("select",{value:null!=(r=i[e.name])?r:"",onChange:t=>h(e.name,t.target.value),className:"w-full px-3 py-2 text-sm rounded-lg outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("option",{value:"",children:"-- Select --"}),e.enum_values.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}):"boolean"===e.type?(0,n.jsxs)("select",{value:null!=(o=i[e.name])?o:"",onChange:t=>h(e.name,t.target.value),className:"w-full px-3 py-2 text-sm rounded-lg outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("option",{value:"",children:"-- Select --"}),(0,n.jsx)("option",{value:"true",children:"Yes"}),(0,n.jsx)("option",{value:"false",children:"No"})]}):"richtext"===e.type?(0,n.jsx)("textarea",{value:null!=(a=i[e.name])?a:"",onChange:t=>h(e.name,t.target.value),rows:3,className:"w-full px-3 py-2 text-sm rounded-lg outline-none resize-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},placeholder:e.name}):u&&e.related_object_name?(0,n.jsx)(ey,{relatedObjectName:e.related_object_name,value:null!=(s=i[e.name])?s:"",multiple:"many_to_many"===e.relationship_type,onChange:t=>h(e.name,t),placeholder:"Select ".concat(e.related_object_name,"...")}):x?(0,n.jsxs)("select",{value:null!=(c=i[e.name])?c:"",onChange:t=>h(e.name,t.target.value),className:"w-full px-3 py-2 text-sm rounded-lg outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("option",{value:"",children:"-- Select member --"}),null==l?void 0:l.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]}):(0,n.jsx)("input",{type:e0(e.type),value:null!=(d=i[e.name])?d:"",onChange:t=>h(e.name,t.target.value),className:"w-full px-3 py-2 text-sm rounded-lg outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},placeholder:e.name})]},e.id)})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-4 py-2 text-sm rounded-lg",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>void p(),disabled:d,className:"px-4 py-2 text-sm font-medium rounded-lg",style:{background:"var(--color-accent)",color:"white",opacity:d?.7:1},children:d?"Saving...":"Save"})]})]})})}function tn(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):""}function to(e){let{entry:t,fields:r,members:o,relationLabels:l,onEntryClick:s}=e,i=tn(t.entry_id)||"",{attributes:c,listeners:d,setNodeRef:u,isDragging:x}=(0,a.PM)({id:i,data:{entry:t}});return(0,n.jsx)("div",{ref:u,...d,...c,onClick:e=>{!x&&s&&(e.stopPropagation(),s(i))},className:"rounded-lg p-3 mb-2 transition-all duration-100 cursor-grab active:cursor-grabbing select-none",style:{background:"var(--color-surface)",border:"1px solid ".concat(x?"var(--color-accent)":"var(--color-border)"),opacity:x?.4:1,transform:x?"scale(1.02)":void 0},children:(0,n.jsx)(tl,{entry:t,fields:r,members:o,relationLabels:l})})}function tl(e){let{entry:t,fields:r,members:o,relationLabels:l}=e,a=function(e,t){var r;let n=t.find(e=>e.name.toLowerCase().includes("name")||e.name.toLowerCase().includes("title"));return n?tn(e[n.name])||"Untitled":tn(e[null==(r=t[0])?void 0:r.name])||"Untitled"}(t,r),s=r.filter(e=>"richtext"!==e.type&&null!==t[e.name]&&void 0!==t[e.name]&&""!==t[e.name]).slice(0,4),i=r.find(e=>e.name.toLowerCase().includes("name")||e.name.toLowerCase().includes("title"));return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"text-sm font-medium mb-1.5 truncate",style:{color:"var(--color-text)"},children:a}),(0,n.jsx)("div",{className:"space-y-1",children:s.filter(e=>e!==i).slice(0,3).map(e=>{let r=t[e.name];if(!r)return null;let a=tn(r);if("user"===e.type){let e=null==o?void 0:o.find(e=>e.id===a);e&&(a=e.name)}else if("relation"===e.type){let t=null==l?void 0:l[e.name];a=(function(e){if(!e)return[];let t=e.trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]})(a).map(e=>{var r;return null!=(r=null==t?void 0:t[e])?r:e}).join(", ")}let s="tags"===e.type?eZ(r):[];return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs",children:[(0,n.jsxs)("span",{style:{color:"var(--color-text-muted)"},children:[e.name,":"]}),"enum"===e.type?(0,n.jsx)(ta,{value:tn(r),enumValues:e.enum_values,enumColors:e.enum_colors}):"tags"===e.type?(0,n.jsxs)("span",{className:"flex items-center gap-0.5 flex-wrap",children:[s.slice(0,3).map(e=>{let t=eJ(e);return"link"===t.kind&&t.href?(0,n.jsx)("a",{href:t.href,target:"url"===t.linkType||"file"===t.linkType?"_blank":void 0,rel:"url"===t.linkType||"file"===t.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium hover:underline underline-offset-2",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)"},children:t.text},e):(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)"},children:e},e)}),s.length>3&&(0,n.jsxs)("span",{style:{color:"var(--color-text-muted)",opacity:.6},children:["+",s.length-3]})]}):"relation"===e.type?(0,n.jsxs)("span",{className:"truncate inline-flex items-center gap-0.5",style:{color:"#60a5fa"},children:[(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.5},children:[(0,n.jsx)("path",{d:"M7 7h10v10"}),(0,n.jsx)("path",{d:"M7 17 17 7"})]}),a]}):(0,n.jsx)("span",{className:"whitespace-pre-line line-clamp-2",style:{color:"var(--color-text)"},children:a})]},e.id)})})]})}function ta(e){var t;let{value:r,enumValues:o,enumColors:l}=e,a=null!=(t=null==o?void 0:o.indexOf(r))?t:-1,s=a>=0&&l?l[a]:"#94a3b8";return(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:"".concat(s,"20"),color:s},children:r})}function ts(e){let{columnName:t,color:r,items:l,cardFields:s,members:i,relationLabels:c,onEntryClick:d,isOver:u,groupFieldId:x,objectName:h,onRefresh:p}=e,{setNodeRef:m}=(0,a.zM)({id:"column:".concat(t)}),[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(t),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);(0,o.useEffect)(()=>{f&&k.current&&(k.current.focus(),k.current.select())},[f]);let w=(0,o.useCallback)(async()=>{let e=g.trim();if(!e||e===t||!x){v(!1),y(t);return}j(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(h),"/fields/").concat(encodeURIComponent(x),"/enum-rename"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldValue:t,newValue:e})})).ok?null==p||p():y(t)}catch(e){y(t)}finally{j(!1),v(!1)}},[g,t,x,h,p]);return(0,n.jsxs)("div",{ref:m,className:"flex-shrink-0 flex flex-col rounded-xl transition-colors duration-150",style:{width:"280px",background:u?"var(--color-surface)":"var(--color-bg)",border:"1px solid ".concat(u?"var(--color-accent)":"var(--color-border)")},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:r}}),f?(0,n.jsx)("input",{ref:k,value:g,onChange:e=>y(e.target.value),onBlur:w,onKeyDown:e=>{"Enter"===e.key&&w(),"Escape"===e.key&&(y(t),v(!1))},disabled:b,className:"text-sm font-medium flex-1 bg-transparent outline-none rounded px-1 -mx-1",style:{color:"var(--color-text)",border:"1px solid var(--color-accent)"}}):(0,n.jsx)("span",{className:"text-sm font-medium flex-1 cursor-text rounded px-1 -mx-1 hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)"},onDoubleClick:()=>{x&&(y(t),v(!0))},title:x?"Double-click to rename":void 0,children:t}),(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:l.length})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2",style:{minHeight:"80px"},children:0===l.length?(0,n.jsx)("div",{className:"flex items-center justify-center py-8 rounded-lg border border-dashed text-xs transition-colors",style:{borderColor:u?"var(--color-accent)":"var(--color-border)",color:u?"var(--color-accent)":"var(--color-text-muted)"},children:u?"Drop here":"No entries"}):l.map((e,t)=>(0,n.jsx)(to,{entry:e,fields:s,members:i,relationLabels:c,onEntryClick:d},tn(e.entry_id)||String(t)))})]})}function ti(e){var t;let{objectName:r,fields:l,entries:s,statuses:i,members:c,relationLabels:d,onEntryClick:u,onRefresh:x}=e,[h,p]=(0,o.useState)(null),[m,f]=(0,o.useState)(null),[v,g]=(0,o.useState)(s);(0,o.useEffect)(()=>{g(s)},[s]);let y=(0,a.FR)((0,a.MS)(a.AN,{activationConstraint:{distance:5}})),b=(0,o.useMemo)(()=>{var e;let t=l.find(e=>"enum"===e.type&&e.name.toLowerCase().includes("status"));return t||(null!=(e=l.find(e=>"enum"===e.type))?e:null)},[l]),j=(0,o.useMemo)(()=>{if(i.length>0)return i.map(e=>{var t;return{name:e.name,color:null!=(t=e.color)?t:"#94a3b8"}});if(null==b?void 0:b.enum_values)return b.enum_values.map((e,t)=>{var r,n;return{name:e,color:null!=(n=null==(r=b.enum_colors)?void 0:r[t])?n:"#94a3b8"}});let e=new Set;for(let t of v){let r=b?t[b.name]:void 0;r&&e.add(tn(r))}return Array.from(e).map(e=>({name:e,color:"#94a3b8"}))},[i,b,v]),k=(0,o.useMemo)(()=>{let e={};for(let t of j)e[t.name]=[];for(let t of(e._ungrouped=[],v)){let r=b?tn(t[b.name]):"";e[r]?e[r].push(t):e._ungrouped.push(t)}return e},[j,v,b]),w=l.filter(e=>e!==b),N=(0,o.useMemo)(()=>{var e;return h&&null!=(e=v.find(e=>String(e.entry_id)===h))?e:null},[h,v]),C=(0,o.useCallback)(e=>{p(String(e.active.id))},[]),S=(0,o.useCallback)(e=>{var t;let r=(null==(t=e.over)?void 0:t.id)?String(e.over.id):null;(null==r?void 0:r.startsWith("column:"))?f(r.replace("column:","")):f(null)},[]),M=(0,o.useCallback)(async e=>{p(null),f(null);let{active:t,over:n}=e;if(!n||!b)return;let o=String(n.id);if(!o.startsWith("column:"))return;let l=o.replace("column:",""),a=String(t.id),s=v.find(e=>String(e.entry_id)===a);if(!s)return;let i=tn(s[b.name]);if(i!==l){g(e=>e.map(e=>String(e.entry_id)===a?{...e,[b.name]:l}:e));try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(r),"/entries/").concat(encodeURIComponent(a)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{[b.name]:l}})})).ok?null==x||x():g(e=>e.map(e=>String(e.entry_id)===a?{...e,[b.name]:i}:e))}catch(e){g(e=>e.map(e=>String(e.entry_id)===a?{...e,[b.name]:i}:e))}}},[b,v,r,x]);return b?(0,n.jsxs)(a.Mp,{sensors:y,collisionDetection:a.y$,onDragStart:C,onDragOver:S,onDragEnd:M,children:[(0,n.jsxs)("div",{className:"flex gap-4 overflow-x-auto pb-4 px-1",style:{minHeight:"400px"},children:[j.map(e=>{var t;return(0,n.jsx)(ts,{columnName:e.name,color:e.color,items:null!=(t=k[e.name])?t:[],cardFields:w,members:c,relationLabels:d,onEntryClick:u,isOver:m===e.name,groupFieldId:b.id,objectName:r,onRefresh:x},e.name)}),(null==(t=k._ungrouped)?void 0:t.length)>0&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex flex-col rounded-xl",style:{width:"280px",background:"var(--color-bg)",border:"1px dashed var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text-muted)"},children:"Ungrouped"}),(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:k._ungrouped.length})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2",children:k._ungrouped.map((e,t)=>(0,n.jsx)(to,{entry:e,fields:w,members:c,relationLabels:d,onEntryClick:u},tn(e.entry_id)||String(t)))})]})]}),(0,n.jsx)(a.Hd,{dropAnimation:null,children:N?(0,n.jsx)("div",{className:"rounded-lg p-3 shadow-xl",style:{width:"260px",background:"var(--color-surface)",border:"1px solid var(--color-accent)",transform:"rotate(2deg)"},children:(0,n.jsx)(tl,{entry:N,fields:w,members:c,relationLabels:d})}):null})]}):(0,n.jsx)("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:(0,n.jsxs)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:["No enum field found for kanban grouping in"," ",(0,n.jsx)("span",{className:"font-medium",style:{color:"var(--color-text)"},children:r})]})})}var tc=r(70739),td=r(30489),tu=r(75885),tx=r(65316),th=r(1059),tp=r(38804),tm=r(45609),tf=r(98540),tv=r(14716),tg=r(92423),ty=r(3904),tb=r(67977),tj=r(39682),tk=r(99509),tw=r(89748),tN=r(25277),tC=r(67697),tS=r(77894),tM=r(74575),tL=r(76149),tT=r(49054),tD=r(67034),tE=r(12904),tR=r(84373),tW=r(65440),tI=r(75096);function tB(e){return null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):"object"==typeof e?JSON.stringify(e):""}function tF(e){return(0,td.GP)(e,"yyyy-MM-dd")}function tA(e){return e.toISOString()}function tP(e,t,r){switch(t){case"day":return 1===r?(0,tu.f)(e,1):(0,tx.e)(e,1);case"week":return 1===r?(0,th.J)(e,1):(0,tp.k)(e,1);case"month":return 1===r?(0,tm.P)(e,1):(0,tf.a)(e,1);case"year":return 1===r?(0,tv.e)(e,1):(0,tg.d)(e,1)}}function t_(e){var t;let{event:r,compact:o,onClick:l,draggable:a,onDragStart:s}=e,i=null!=(t=r.color)?t:"var(--color-accent)";return(0,n.jsxs)("button",{type:"button",draggable:a,onDragStart:s,onClick:e=>{e.stopPropagation(),null==l||l()},className:"text-left rounded px-1.5 truncate cursor-pointer transition-opacity hover:opacity-80 ".concat(o?"text-[10px] py-0":"text-[11px] py-0.5"),style:{backgroundColor:i,color:"#fff",border:"none",width:"100%",lineHeight:o?"16px":"18px"},title:r.title,children:[!o&&(0,n.jsx)("span",{className:"opacity-70 mr-1",children:(0,td.GP)(r.date,"HH:mm")}),r.title||"Untitled"]})}function tz(e){let{date:t,events:r,onEntryClick:l,onEntryDateChange:a}=e,[s,i]=(0,o.useState)(null),c=(0,o.useRef)(null),d=(0,tj.w)(t),u=(0,tk.p)(t),x=(0,ty.k)(d,{weekStartsOn:1}),h=(0,tb.$)(u,{weekStartsOn:1}),p=(0,tw.k)({start:x,end:h}),m=(0,o.useMemo)(()=>{let e=new Map;for(let t of r){let r=(0,td.GP)(t.date,"yyyy-MM-dd");if(e.has(r)||e.set(r,[]),e.get(r).push(t),t.endDate&&!(0,tN.r)(t.date,t.endDate))for(let r of(0,tw.k)({start:(0,tu.f)(t.date,1),end:t.endDate})){let n=(0,td.GP)(r,"yyyy-MM-dd");e.has(n)||e.set(n,[]),e.get(n).push(t)}}return e},[r]),f=(0,o.useCallback)(e=>{c.current=e},[]),v=(0,o.useCallback)((e,t)=>{e.preventDefault(),i(t)},[]),g=(0,o.useCallback)((e,t)=>{e.preventDefault(),i(null);let r=c.current;if(!r||!a||(0,tN.r)(r.date,t))return;let n=(0,tC.o)((0,tS.o)(t),(0,tS.o)(r.date)),o=(0,tM.z)(r.date,n),l={entryId:r.id,newDate:tF(o)};r.endDate&&(l.newEndDate=tF((0,tM.z)(r.endDate,n))),a(l),c.current=null},[a]),y=(0,o.useCallback)(()=>i(null),[]);return(0,n.jsxs)("div",{className:"w-full",children:[(0,n.jsx)("div",{className:"grid grid-cols-7 border-b",style:{borderColor:"var(--color-border)"},children:["Mon","Tue","Wed","Thu","Fri","Sat","Sun"].map(e=>(0,n.jsx)("div",{className:"text-center text-[11px] font-medium py-2",style:{color:"var(--color-text-muted)"},children:e},e))}),(0,n.jsx)("div",{className:"grid grid-cols-7",children:p.map(e=>{var r;let o=(0,td.GP)(e,"yyyy-MM-dd"),i=null!=(r=m.get(o))?r:[],c=(0,tL.t)(e,t),d=(0,tT.c)(e),u=s===o;return(0,n.jsxs)("div",{className:"min-h-[100px] border-b border-r p-1 transition-colors",style:{borderColor:"var(--color-border)",opacity:c?1:.4,background:u?"var(--color-accent-light, rgba(99,102,241,0.12))":d?"var(--color-surface-hover)":void 0},onDragOver:e=>v(e,o),onDragLeave:y,onDrop:t=>g(t,e),children:[(0,n.jsx)("div",{className:"text-[11px] mb-0.5 ".concat(d?"font-bold":""),style:{color:d?"var(--color-accent)":"var(--color-text-muted)"},children:(0,td.GP)(e,"d")}),(0,n.jsxs)("div",{className:"flex flex-col gap-0.5",children:[i.slice(0,3).map(e=>(0,n.jsx)(t_,{event:e,compact:!0,onClick:()=>null==l?void 0:l(e.id),draggable:!!a,onDragStart:()=>f(e)},e.id)),i.length>3&&(0,n.jsxs)("span",{className:"text-[10px] pl-1",style:{color:"var(--color-text-muted)"},children:["+",i.length-3," more"]})]})]},o)})})]})}function tO(e){var t;let{event:r,hourHeight:l,onEntryClick:a,onEntryDateChange:s}=e,i=(0,o.useRef)(null),[c,d]=(0,o.useState)(null),u=(0,o.useRef)({y:0,startMinute:0,duration:0}),x=(0,tD.O)(r.date)/60*l,h=r.endDate?Math.max((0,tC.o)(r.endDate,r.date),15):30,p=h/60*l,[m,f]=(0,o.useState)(0),[v,g]=(0,o.useState)(0),y=(0,o.useCallback)(e=>{s&&(e.preventDefault(),e.stopPropagation(),d("move"),u.current={y:e.clientY,startMinute:60*(0,tE.q)(r.date)+(0,tD.O)(r.date),duration:h},e.target.setPointerCapture(e.pointerId))},[s,r.date,h]),b=(0,o.useCallback)(e=>{s&&(e.preventDefault(),e.stopPropagation(),d("resize"),u.current={y:e.clientY,startMinute:0,duration:h},e.target.setPointerCapture(e.pointerId))},[s,h]),j=(0,o.useCallback)(e=>{if(!c)return;let t=e.clientY-u.current.y;"move"===c?f(t):g(t)},[c]),k=(0,o.useCallback)(e=>{if(!c||!s)return;let t=15*Math.round((e.clientY-u.current.y)/l*60/15);if("move"===c&&0!==t){let e=(0,tM.z)(r.date,t),n={entryId:r.id,newDate:tA(e)};r.endDate&&(n.newEndDate=tA((0,tM.z)(r.endDate,t))),s(n)}else if("resize"===c&&0!==t){var n;let e=(0,tM.z)(null!=(n=r.endDate)?n:(0,tM.z)(r.date,h),t);e>r.date&&s({entryId:r.id,newDate:tA(r.date),newEndDate:tA(e)})}d(null),f(0),g(0)},[c,s,r,l,h]),w=x+("move"===c?m:0),N=Math.max(p+("resize"===c?v:0),15);return(0,n.jsxs)("div",{ref:i,className:"absolute left-0.5 right-0.5 rounded px-1 text-[10px] truncate select-none",style:{top:w,height:Math.min(N,6*l),backgroundColor:null!=(t=r.color)?t:"var(--color-accent)",color:"#fff",lineHeight:"16px",zIndex:c?20:2,cursor:s?"move"===c?"grabbing":"grab":"pointer",opacity:c?.85:1,transition:c?"none":"top 0.15s, height 0.15s"},onPointerDown:y,onPointerMove:j,onPointerUp:k,onClick:e=>{c||(e.stopPropagation(),null==a||a(r.id))},title:r.title,children:[r.title||"Untitled",s&&(0,n.jsx)("div",{className:"absolute bottom-0 left-0 right-0 h-2 cursor-ns-resize",style:{borderRadius:"0 0 4px 4px"},onPointerDown:b})]})}function tU(e){let{date:t,events:r,onEntryClick:l,onEntryDateChange:a}=e,s=(0,ty.k)(t,{weekStartsOn:1}),i=(0,tw.k)({start:s,end:(0,tu.f)(s,6)}),c=Array.from({length:24},(e,t)=>t+0),d=(0,o.useMemo)(()=>{let e=new Map;for(let t of r){let r=(0,td.GP)(t.date,"yyyy-MM-dd");e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[r]);return(0,n.jsx)("div",{className:"w-full overflow-auto",style:{maxHeight:"calc(100vh - 280px)"},children:(0,n.jsxs)("div",{className:"grid",style:{gridTemplateColumns:"50px repeat(7, 1fr)"},children:[(0,n.jsx)("div",{className:"sticky top-0 z-10",style:{background:"var(--color-bg)"}}),i.map(e=>(0,n.jsxs)("div",{className:"sticky top-0 z-10 text-center py-2 border-b border-l text-[12px] font-medium",style:{borderColor:"var(--color-border)",background:"var(--color-bg)",color:(0,tT.c)(e)?"var(--color-accent)":"var(--color-text)"},children:[(0,n.jsx)("div",{children:(0,td.GP)(e,"EEE")}),(0,n.jsx)("div",{className:"text-lg ".concat((0,tT.c)(e)?"font-bold":""),children:(0,td.GP)(e,"d")})]},e.toISOString())),c.map(e=>(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"text-[10px] text-right pr-2 pt-0.5",style:{color:"var(--color-text-muted)",height:60},children:(0,td.GP)(new Date(2e3,0,1,e),"ha")},"label-".concat(e)),i.map(t=>{var r;let o=(0,td.GP)(t,"yyyy-MM-dd"),s=(null!=(r=d.get(o))?r:[]).filter(t=>(0,tE.q)(t.date)===e);return(0,n.jsx)("div",{className:"border-b border-l relative",style:{borderColor:"var(--color-border)",height:60},children:s.map(e=>(0,n.jsx)(tO,{event:e,hourHeight:60,onEntryClick:l,onEntryDateChange:a},e.id))},"".concat(o,"-").concat(e))})]}))]})})}function tH(e){let{date:t,events:r,onEntryClick:l,onEntryDateChange:a}=e,s=Array.from({length:24},(e,t)=>t+0),i=(0,o.useMemo)(()=>r.filter(e=>(0,tN.r)(e.date,t)),[r,t]);return(0,n.jsx)("div",{className:"w-full overflow-auto",style:{maxHeight:"calc(100vh - 280px)"},children:(0,n.jsx)("div",{className:"grid",style:{gridTemplateColumns:"60px 1fr"},children:s.map(e=>{let t=i.filter(t=>(0,tE.q)(t.date)===e);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"text-[11px] text-right pr-3 pt-0.5",style:{color:"var(--color-text-muted)",height:60},children:(0,td.GP)(new Date(2e3,0,1,e),"h:mm a")},"label-".concat(e)),(0,n.jsx)("div",{className:"border-b border-l relative",style:{borderColor:"var(--color-border)",height:60},children:t.map(e=>(0,n.jsx)(tO,{event:e,hourHeight:60,onEntryClick:l,onEntryDateChange:a},e.id))},"cell-".concat(e))]})})})})}function tV(e){let{date:t,events:r}=e,l=(0,tR.D)(t),a=(0,tW.Q)(t),s=(0,tI.i)({start:l,end:a}),i=(0,o.useMemo)(()=>{let e=new Map;for(let t of r){let r=t.date.getMonth();e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[r]);return(0,n.jsx)("div",{className:"grid grid-cols-3 md:grid-cols-4 gap-4 p-2",children:s.map(e=>{var t;let r=(0,tj.w)(e),o=(0,tk.p)(e),l=(0,ty.k)(r,{weekStartsOn:1}),a=(0,tb.$)(o,{weekStartsOn:1}),s=(0,tw.k)({start:l,end:a}),c=null!=(t=i.get(e.getMonth()))?t:[];return(0,n.jsxs)("div",{className:"rounded-lg border p-2",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"text-[12px] font-semibold mb-1",style:{color:"var(--color-text)"},children:(0,td.GP)(e,"MMMM")}),(0,n.jsxs)("div",{className:"grid grid-cols-7 gap-px",children:[["M","T","W","T","F","S","S"].map((e,t)=>(0,n.jsx)("div",{className:"text-[9px] text-center",style:{color:"var(--color-text-muted)"},children:e},t)),s.map(t=>{let r=(0,tL.t)(t,e),o=(0,tT.c)(t),l=c.some(e=>(0,tN.r)(e.date,t));return(0,n.jsxs)("div",{className:"text-[9px] text-center py-0.5 relative",style:{color:r?o?"var(--color-accent)":"var(--color-text)":"transparent",fontWeight:o?700:400},children:[(0,td.GP)(t,"d"),l&&r&&(0,n.jsx)("div",{className:"absolute bottom-0 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full",style:{backgroundColor:"var(--color-accent)"}})]},t.toISOString())})]}),c.length>0&&(0,n.jsxs)("div",{className:"mt-1 text-[10px]",style:{color:"var(--color-text-muted)"},children:[c.length," event",1!==c.length?"s":""]})]},e.toISOString())})})}function tJ(e){let{reason:t}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 gap-2",children:[(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"4",rx:"2"}),(0,n.jsx)("path",{d:"M16 2v4"}),(0,n.jsx)("path",{d:"M8 2v4"}),(0,n.jsx)("path",{d:"M3 10h18"})]}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"no-date-field"===t?"No date field configured for calendar view. Open view settings to select one.":"No events to display in this range."})]})}function tK(e){let{objectName:t,fields:r,entries:l,dateField:a,endDateField:s,mode:i,onModeChange:c,members:d,onEntryClick:u,onEntryDateChange:x}=e,[h,p]=(0,o.useState)(()=>new Date),m=(0,o.useMemo)(()=>(function(e,t,r,n){let o=[];for(let a of e){let e=tB(a[r]);if(e)try{var l;let r,s=(0,tc.H)(e);if(Number.isNaN(s.getTime()))continue;if(n){let e=tB(a[n]);if(e){let t=(0,tc.H)(e);Number.isNaN(t.getTime())||(r=t)}}o.push({id:tB(null!=(l=a.entry_id)?l:a.id),title:function(e,t){var r;let n=null!=(r=t.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?r:t.find(e=>"text"===e.type);return n?tB(e[n.name]):tB(e.id)}(a,t),date:s,endDate:r,entry:a,color:function(e,t){var r,n;let o=t.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_colors)?void 0:t.length)});if(!o)return;let l=tB(e[o.name]),a=null!=(n=null==(r=o.enum_values)?void 0:r.indexOf(l))?n:-1;return a>=0?o.enum_colors[a]:void 0}(a,t)})}catch(e){}}return o})(l,r,a,s),[l,r,a,s]),f=(0,o.useCallback)(()=>p(e=>tP(e,i,-1)),[i]),v=(0,o.useCallback)(()=>p(e=>tP(e,i,1)),[i]),g=(0,o.useCallback)(()=>p(new Date),[]);return a?(0,n.jsxs)("div",{className:"w-full",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3 px-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:f,className:"p-1.5 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})})}),(0,n.jsx)("button",{type:"button",onClick:v,className:"p-1.5 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}),(0,n.jsx)("button",{type:"button",onClick:g,className:"text-[12px] px-2.5 py-1 rounded-md border hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)",borderColor:"var(--color-border)"},children:"Today"}),(0,n.jsx)("h3",{className:"text-sm font-semibold ml-2",style:{color:"var(--color-text)"},children:function(e,t){switch(t){case"day":return(0,td.GP)(e,"EEEE, MMMM d, yyyy");case"week":{let t=(0,ty.k)(e,{weekStartsOn:1}),r=(0,tb.$)(e,{weekStartsOn:1});return"".concat((0,td.GP)(t,"MMM d")," - ").concat((0,td.GP)(r,"MMM d, yyyy"))}case"month":return(0,td.GP)(e,"MMMM yyyy");case"year":return(0,td.GP)(e,"yyyy")}}(h,i)})]}),(0,n.jsx)("div",{className:"flex rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)"},children:["day","week","month","year"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>c(e),className:"text-[11px] px-3 py-1 capitalize transition-colors",style:{background:e===i?"var(--color-accent)":"var(--color-surface)",color:e===i?"#fff":"var(--color-text-muted)",borderRight:"year"!==e?"1px solid var(--color-border)":void 0},children:e},e))})]}),(0,n.jsxs)("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)",background:"var(--color-bg)"},children:["month"===i&&(0,n.jsx)(tz,{date:h,events:m,onEntryClick:u,onEntryDateChange:x}),"week"===i&&(0,n.jsx)(tU,{date:h,events:m,onEntryClick:u,onEntryDateChange:x}),"day"===i&&(0,n.jsx)(tH,{date:h,events:m,onEntryClick:u,onEntryDateChange:x}),"year"===i&&(0,n.jsx)(tV,{date:h,events:m})]})]}):(0,n.jsx)(tJ,{reason:"no-date-field"})}var tq=r(35933),tG=r(22507),t$=r(88382),tZ=r(29788);let tY={day:{dayWidth:80,headerFormat:"MMM d"},week:{dayWidth:30,headerFormat:"MMM d"},month:{dayWidth:10,headerFormat:"MMM yyyy"},quarter:{dayWidth:4,headerFormat:"QQQ yyyy"}},tQ=["#3b82f6","#22c55e","#f59e0b","#ef4444","#8b5cf6","#06b6d4","#ec4899","#14b8a6","#f97316","#6366f1"];function tX(e){return null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):"object"==typeof e?JSON.stringify(e):""}function t0(e){return(0,td.GP)(e,"yyyy-MM-dd")}function t1(e){let{item:t,x:r,w:l,dayWidth:a,onEntryClick:s,onEntryDateChange:i}=e,[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)(0),[h,p]=(0,o.useState)(0),m=(0,o.useRef)(0),f=!!i,v=(0,o.useCallback)(e=>Math.round(e/a)*a,[a]),g=(0,o.useCallback)(e=>Math.round(e/a),[a]),y=(0,o.useCallback)((e,t)=>{f&&(e.preventDefault(),e.stopPropagation(),m.current=e.clientX,d(t),e.target.setPointerCapture(e.pointerId))},[f]),b=(0,o.useCallback)(e=>{if(!c)return;let t=v(e.clientX-m.current);"move"===c?x(t):"resize-left"===c?(x(t),p(-t)):p(t)},[c,v]),j=(0,o.useCallback)(e=>{if(!c||!i)return void d(null);let r=g(e.clientX-m.current);if(0===r&&"move"===c){d(null),x(0),p(0);return}let n=t.startDate,o=t.endDate;"move"===c?(n=(0,tu.f)(t.startDate,r),o=(0,tu.f)(t.endDate,r)):"resize-left"===c?(n=(0,tu.f)(t.startDate,r))>=o&&(n=(0,tu.f)(o,-1)):(o=(0,tu.f)(t.endDate,r))<=n&&(o=(0,tu.f)(n,1)),i({entryId:t.id,newStartDate:t0(n),newEndDate:t0(o)}),d(null),x(0),p(0)},[c,i,t,g]),k=Math.max(l+h,.5*a);return(0,n.jsxs)("div",{className:"absolute rounded flex items-center text-[11px] truncate select-none",style:{left:r+u,width:k,top:6,height:28,backgroundColor:t.color,color:"#fff",zIndex:c?20:2,cursor:f?"move"===c?"grabbing":"grab":"pointer",opacity:c?.85:1,transition:c?"none":"left 0.15s, width 0.15s"},onPointerDown:e=>y(e,"move"),onPointerMove:b,onPointerUp:j,onClick:e=>{c||(e.stopPropagation(),null==s||s(t.id))},title:"".concat(t.title,"\n").concat((0,td.GP)(t.startDate,"MMM d")," - ").concat((0,td.GP)(t.endDate,"MMM d")),children:[f&&(0,n.jsx)("div",{className:"absolute left-0 top-0 bottom-0 cursor-ew-resize hover:bg-white/20 rounded-l",style:{width:8},onPointerDown:e=>y(e,"resize-left")}),(0,n.jsx)("span",{className:"px-2 truncate flex-1",children:k>60?t.title||"Untitled":""}),f&&(0,n.jsx)("div",{className:"absolute right-0 top-0 bottom-0 cursor-ew-resize hover:bg-white/20 rounded-r",style:{width:8},onPointerDown:e=>y(e,"resize-right")})]})}function t2(e){let{reason:t}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 gap-2",children:[(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("path",{d:"M8 6h13"}),(0,n.jsx)("path",{d:"M8 12h13"}),(0,n.jsx)("path",{d:"M8 18h13"}),(0,n.jsx)("path",{d:"M3 6h.01"}),(0,n.jsx)("path",{d:"M3 12h.01"}),(0,n.jsx)("path",{d:"M3 18h.01"})]}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"no-fields"===t?"No date fields configured for timeline view. Open view settings to select start/end dates.":"No items with dates to display in this view."})]})}function t4(e){let{objectName:t,fields:r,entries:l,startDateField:a,endDateField:s,groupField:i,zoom:c,onZoomChange:d,members:u,onEntryClick:x,onEntryDateChange:h}=e,p=(0,o.useRef)(null),m=(0,o.useMemo)(()=>(function(e,t,r,n,o){let l=[];for(let s=0;s<e.length;s++){let i=e[s],c=tX(i[r]);if(c)try{var a;let e,r=(0,tc.H)(c);if(Number.isNaN(r.getTime()))continue;if(n){let t=tX(i[n]);if(t){let n=(0,tc.H)(t);e=Number.isNaN(n.getTime())?(0,tu.f)(r,1):n}else e=(0,tu.f)(r,1)}else e=(0,tu.f)(r,1);e<=r&&(e=(0,tu.f)(r,1)),l.push({id:tX(null!=(a=i.entry_id)?a:i.id),title:function(e,t){var r;let n=null!=(r=t.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?r:t.find(e=>"text"===e.type);return n?tX(e[n.name]):tX(e.id)}(i,t),startDate:r,endDate:e,group:o?tX(i[o]):void 0,color:function(e,t,r){let n=t.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_colors)?void 0:t.length)});if(n){var o,l;let t=tX(e[n.name]),r=null!=(l=null==(o=n.enum_values)?void 0:o.indexOf(t))?l:-1;if(r>=0&&n.enum_colors[r])return n.enum_colors[r]}return tQ[r%tQ.length]}(i,t,s),entry:i})}catch(e){}}return l.toSorted((e,t)=>e.startDate.getTime()-t.startDate.getTime())})(l,r,a,s,i),[l,r,a,s,i]),{start:f,end:v}=(0,o.useMemo)(()=>(function(e,t){if(0===e.length){let e=new Date;return{start:(0,tf.a)(e,1),end:(0,tm.P)(e,2)}}let r=(0,tq.j)(e.map(e=>e.startDate)),n=(0,tG.T)(e.map(e=>e.endDate)),o="day"===t?3:"week"===t?7:"month"===t?14:30;return{start:(0,tu.f)(r,-o),end:(0,tu.f)(n,o)}})(m,c),[m,c]),{dayWidth:g}=tY[c],y=((0,tZ.c)(v,f)+1)*g,b=(0,o.useMemo)(()=>(function(e,t,r){switch(r){case"day":return(0,tw.k)({start:e,end:t}).map(e=>({date:e,label:(0,td.GP)(e,"MMM d")}));case"week":return(0,t$.Y)({start:e,end:t},{weekStartsOn:1}).map(e=>({date:e,label:(0,td.GP)(e,"MMM d")}));case"month":return(0,tI.i)({start:e,end:t}).map(e=>({date:e,label:(0,td.GP)(e,"MMM yyyy")}));case"quarter":return(0,tI.i)({start:e,end:t}).filter(e=>e.getMonth()%3==0).map(e=>({date:e,label:(0,td.GP)(e,"QQQ yyyy")}))}})(f,v,c),[f,v,c]),j=(0,o.useMemo)(()=>{if(!i)return[{name:"",items:m}];let e=new Map;for(let t of m){let r=t.group||"Ungrouped";e.has(r)||e.set(r,[]),e.get(r).push(t)}return Array.from(e.entries()).map(e=>{let[t,r]=e;return{name:t,items:r}})},[m,i]),k=(0,o.useMemo)(()=>{let e=[];for(let t of j)for(let r of(i&&t.name&&e.push({type:"group",group:t.name}),t.items))e.push({type:"item",item:r});return e},[j,i]),w=(0,o.useCallback)(e=>(0,tZ.c)(e,f)*g,[f,g]);if((0,o.useEffect)(()=>{if(!p.current)return;let e=w(new Date);p.current.scrollLeft=Math.max(0,e-300)},[w]),!a)return(0,n.jsx)(t2,{reason:"no-fields"});if(0===m.length)return(0,n.jsx)(t2,{reason:"no-items"});let N=w((0,tS.o)(new Date));return(0,n.jsxs)("div",{className:"w-full",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3 px-1",children:[(0,n.jsxs)("div",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:[m.length," item",1!==m.length?"s":""]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:"Zoom:"}),(0,n.jsx)("div",{className:"flex rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)"},children:["day","week","month","quarter"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>d(e),className:"text-[11px] px-3 py-1 capitalize transition-colors",style:{background:e===c?"var(--color-accent)":"var(--color-surface)",color:e===c?"#fff":"var(--color-text-muted)",borderRight:"quarter"!==e?"1px solid var(--color-border)":void 0},children:e},e))})]})]}),(0,n.jsx)("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)",background:"var(--color-bg)"},children:(0,n.jsxs)("div",{className:"flex",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 border-r",style:{width:200,borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"border-b px-3 flex items-center text-[11px] font-medium",style:{height:50,borderColor:"var(--color-border)",color:"var(--color-text-muted)"},children:"Name"}),k.map((e,t)=>{var r;return(0,n.jsx)("div",{className:"px-3 flex items-center border-b truncate ".concat("group"===e.type?"text-[10px] font-semibold uppercase tracking-wider":"text-[12px] cursor-pointer hover:bg-[var(--color-surface-hover)]"),style:{height:40,borderColor:"var(--color-border)",color:"group"===e.type?"var(--color-text-muted)":"var(--color-text)",background:"group"===e.type?"var(--color-surface-hover)":void 0},onClick:()=>e.item&&(null==x?void 0:x(e.item.id)),children:"group"===e.type?e.group:(null==(r=e.item)?void 0:r.title)||"Untitled"},t)})]}),(0,n.jsx)("div",{ref:p,className:"flex-1 overflow-x-auto overflow-y-hidden",style:{maxHeight:"calc(100vh - 280px)"},children:(0,n.jsxs)("div",{style:{width:y,position:"relative"},children:[(0,n.jsx)("div",{className:"border-b flex",style:{height:50,borderColor:"var(--color-border)"},children:b.map((e,t)=>{let r=w(e.date),o=t<b.length-1?w(b[t+1].date):y;return(0,n.jsx)("div",{className:"absolute border-r flex items-end pb-1 px-2 text-[10px]",style:{left:r,width:o-r,height:50,borderColor:"var(--color-border)",color:"var(--color-text-muted)"},children:e.label},t)})}),k.map((e,t)=>(0,n.jsx)("div",{className:"relative border-b",style:{height:40,borderColor:"var(--color-border)",background:"group"===e.type?"var(--color-surface-hover)":void 0},children:e.item&&(()=>{let t=e.item,r=w(t.startDate),o=Math.max(w(t.endDate)-r,.5*g);return(0,n.jsx)(t1,{item:t,x:r,w:o,dayWidth:g,onEntryClick:x,onEntryDateChange:h})})()},t)),N>=0&&N<=y&&(0,n.jsx)("div",{className:"absolute top-0 bottom-0 pointer-events-none",style:{left:N,width:2,backgroundColor:"var(--color-accent)",opacity:.6,zIndex:10}})]})})]})})]})}function t5(e){return null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):"object"==typeof e?JSON.stringify(e):""}function t6(e){var t;let{entry:r,fields:l,titleField:a,coverField:s,onEntryClick:i}=e,c=t5(null!=(t=r.entry_id)?t:r.id),d=function(e,t,r){var n;if(r){let t=t5(e[r]);if(t)return t}let o=null!=(n=t.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?n:t.find(e=>"text"===e.type);return o?t5(e[o.name]):t5(e.id)}(r,l,a),u=(0,o.useMemo)(()=>l.filter(e=>e.name!==a&&e.name!==s).slice(0,4),[l,a,s]),x=l.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_values)?void 0:t.length)}),h=x?t5(r[x.name]):null,p=x&&h?function(e,t){var r;if(!e||!t.enum_values)return null;let n=t.enum_values.indexOf(e);return{text:e,color:n>=0&&(null==(r=t.enum_colors)?void 0:r[n])?t.enum_colors[n]:"#94a3b8"}}(h,x):null;return(0,n.jsxs)("button",{type:"button",onClick:()=>null==i?void 0:i(c),className:"text-left rounded-xl border p-4 hover:shadow-md transition-all cursor-pointer w-full group",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2 mb-2",children:[(0,n.jsx)("h4",{className:"text-[13px] font-semibold leading-tight line-clamp-2 group-hover:underline",style:{color:"var(--color-text)"},children:d||"Untitled"}),p&&(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0 whitespace-nowrap",style:{backgroundColor:p.color,color:"#fff"},children:p.text})]}),(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:u.map(e=>{let t=r[e.name];if(null==t||""===t5(t))return null;let o="tags"===e.type?eZ(t):[];return(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("span",{className:"text-[10px] flex-shrink-0 min-w-[60px]",style:{color:"var(--color-text-muted)"},children:e.name}),(0,n.jsx)("div",{className:"text-[12px] whitespace-pre-line line-clamp-2",style:{color:"var(--color-text)"},children:"tags"===e.type?(0,n.jsxs)("span",{className:"flex items-center gap-0.5 flex-wrap",children:[o.slice(0,3).map(e=>{let t=eJ(e);return"link"===t.kind&&t.href?(0,n.jsx)("a",{href:t.href,target:"url"===t.linkType||"file"===t.linkType?"_blank":void 0,rel:"url"===t.linkType||"file"===t.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium hover:underline underline-offset-2",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)"},children:t.text},e):(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)"},children:e},e)}),o.length>3&&(0,n.jsxs)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:["+",o.length-3]})]}):(0,n.jsx)(e$,{value:t,fieldType:e.type,mode:"table"})})]},e.id)})}),null!=r.created_at&&(0,n.jsx)("div",{className:"mt-3 text-[10px]",style:{color:"var(--color-text-muted)",opacity:.6},children:t5(r.created_at).slice(0,10)})]})}function t3(){return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 gap-2",children:[(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No entries to display in gallery view."})]})}function t8(e){let{objectName:t,fields:r,entries:o,titleField:l,coverField:a,members:s,relationLabels:i,onEntryClick:c}=e;return 0===o.length?(0,n.jsx)(t3,{}):(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3",children:o.map(e=>{var t;return(0,n.jsx)(t6,{entry:e,fields:r,titleField:l,coverField:a,onEntryClick:c},t5(null!=(t=e.entry_id)?t:e.id))})})}function t7(e){return null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):"object"==typeof e?JSON.stringify(e):""}function t9(e){var t,r;let{entry:l,fields:a,titleField:s,subtitleField:i,onEntryClick:c}=e,d=t7(null!=(t=l.entry_id)?t:l.id),u=function(e,t,r){var n;if(r){let t=t7(e[r]);if(t)return t}let o=null!=(n=t.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?n:t.find(e=>"text"===e.type);return o?t7(e[o.name]):t7(e.id)}(l,a,s),x=(0,o.useMemo)(()=>{if(i){let e=t7(l[i]);if(e)return e}let e=a.find(e=>"text"===e.type&&e.name!==s&&!/name|title/i.test(e.name));return e?t7(l[e.name]):void 0},[l,a,s,i]),h=a.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_values)?void 0:t.length)}),p=h?t7(l[h.name]):null,m=h&&p?function(e,t){var r;if(!e||!t.enum_values)return null;let n=t.enum_values.indexOf(e);return{text:e,color:n>=0&&(null==(r=t.enum_colors)?void 0:r[n])?t.enum_colors[n]:"#94a3b8"}}(p,h):null,f=a.find(e=>"tags"===e.type),v=f?eZ(l[f.name]):[],g=a.find(e=>"date"===e.type),y=g?t7(l[g.name]):null;return(0,n.jsxs)("button",{type:"button",onClick:()=>null==c?void 0:c(d),className:"w-full text-left flex items-center gap-3 px-4 py-3 border-b hover:bg-[var(--color-surface-hover)] transition-colors cursor-pointer group",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:null!=(r=null==m?void 0:m.color)?r:"var(--color-text-muted)",opacity:.6}}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-[13px] font-medium truncate group-hover:underline",style:{color:"var(--color-text)"},children:u||"Untitled"}),m&&(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{backgroundColor:m.color,color:"#fff"},children:m.text}),v.slice(0,3).map(e=>{let t=eJ(e);return"link"===t.kind&&t.href?(0,n.jsx)("a",{href:t.href,target:"url"===t.linkType||"file"===t.linkType?"_blank":void 0,rel:"url"===t.linkType||"file"===t.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0 hover:underline underline-offset-2",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)",border:"1px solid var(--color-border)"},children:t.text},e):(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:e},e)})]}),x&&(0,n.jsx)("div",{className:"text-[11px] whitespace-pre-line line-clamp-1 mt-0.5",style:{color:"var(--color-text-muted)"},children:x})]}),y&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0 tabular-nums",style:{color:"var(--color-text-muted)"},children:y.slice(0,10)})]})}function re(){return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 gap-2",children:[(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("path",{d:"M8 6h13"}),(0,n.jsx)("path",{d:"M8 12h13"}),(0,n.jsx)("path",{d:"M8 18h13"}),(0,n.jsx)("path",{d:"M3 6h.01"}),(0,n.jsx)("path",{d:"M3 12h.01"}),(0,n.jsx)("path",{d:"M3 18h.01"})]}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No entries to display in list view."})]})}function rt(e){let{objectName:t,fields:r,entries:o,titleField:l,subtitleField:a,members:s,onEntryClick:i}=e;return 0===o.length?(0,n.jsx)(re,{}):(0,n.jsx)("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:o.map(e=>{var t;return(0,n.jsx)(t9,{entry:e,fields:r,titleField:l,subtitleField:a,onEntryClick:i},t7(null!=(t=e.entry_id)?t:e.id))})})}let rr=["table","kanban","calendar","timeline","gallery","list"];function rn(e){return"string"==typeof e&&rr.includes(e)}function ro(e,t,r){return(null==e?void 0:e.view_type)&&rn(e.view_type)?e.view_type:t&&rn(t)?t:r&&rn(r)?r:"table"}function rl(e,t,r){var n,o,l,a,s,i,c,d,u,x,h,p;switch(t){case"kanbanField":return null!=(l=null==(n=r.find(e=>"enum"===e.type&&/status/i.test(e.name)))?void 0:n.name)?l:null==(o=r.find(e=>"enum"===e.type))?void 0:o.name;case"calendarDateField":case"timelineStartField":return null!=(i=null==(a=r.find(e=>"date"===e.type&&/due|start|begin/i.test(e.name)))?void 0:a.name)?i:null==(s=r.find(e=>"date"===e.type))?void 0:s.name;case"calendarEndDateField":case"timelineEndField":return null==(c=r.find(e=>"date"===e.type&&/end|finish|close/i.test(e.name)))?void 0:c.name;case"timelineGroupField":return null==(d=r.find(e=>"enum"===e.type))?void 0:d.name;case"galleryTitleField":case"listTitleField":return null!=(h=null==(u=r.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?void 0:u.name)?h:null==(x=r.find(e=>"text"===e.type))?void 0:x.name;case"galleryCoverField":default:return;case"listSubtitleField":return null==(p=r.find(e=>"text"===e.type&&!/name|title/i.test(e.name)))?void 0:p.name}}let ra=[{value:"is_empty",label:"is empty"},{value:"is_not_empty",label:"is not empty"}],rs=[{value:"contains",label:"contains"},{value:"not_contains",label:"does not contain"},{value:"equals",label:"equals"},{value:"not_equals",label:"does not equal"},{value:"starts_with",label:"starts with"},{value:"ends_with",label:"ends with"},...ra],ri=[{value:"eq",label:"="},{value:"neq",label:"≠"},{value:"gt",label:">"},{value:"gte",label:"≥"},{value:"lt",label:"<"},{value:"lte",label:"≤"},{value:"between",label:"between"},...ra],rc=[{value:"on",label:"is"},{value:"before",label:"before"},{value:"after",label:"after"},{value:"date_between",label:"between"},{value:"relative_past",label:"in the last"},{value:"relative_next",label:"in the next"},...ra],rd=[{value:"is",label:"is"},{value:"is_not",label:"is not"},{value:"is_any_of",label:"is any of"},{value:"is_none_of",label:"is none of"},...ra],ru=[{value:"is_true",label:"is true"},{value:"is_false",label:"is false"},...ra],rx=[{value:"has_any",label:"has any of"},{value:"has_none",label:"has none of"},{value:"has_all",label:"has all of"},...ra],rh=[{value:"contains",label:"contains"},{value:"not_contains",label:"does not contain"},...ra];function rp(e){switch(e){case"text":case"richtext":case"email":case"tags":default:return"contains";case"number":return"eq";case"date":return"relative_past";case"enum":return"is";case"boolean":return"is_true";case"relation":case"user":return"has_any"}}function rm(e){return"conjunction"in e&&"rules"in e}function rf(e){return btoa(JSON.stringify(e))}function rv(){return{id:"root",conjunction:"and",rules:[]}}function rg(e){var t,r;let n=e.field,o=e.operator,l=Array.isArray(e.value)?e.value.join(", "):String(null!=(t=e.value)?t:"");return"is_empty"===o?"".concat(n," is empty"):"is_not_empty"===o?"".concat(n," is not empty"):"is_true"===o?"".concat(n," is true"):"is_false"===o?"".concat(n," is false"):"between"===o||"date_between"===o?"".concat(n," between ").concat(l," and ").concat(e.valueTo):"relative_past"===o?"".concat(n," in the last ").concat(e.relativeAmount," ").concat(e.relativeUnit):"relative_next"===o?"".concat(n," in the next ").concat(e.relativeAmount," ").concat(e.relativeUnit):"".concat(n," ").concat(null!=(r=({contains:"contains",not_contains:"doesn't contain",equals:"=",not_equals:"≠",starts_with:"starts with",ends_with:"ends with",eq:"=",neq:"≠",gt:">",gte:"≥",lt:"<",lte:"≤",before:"before",after:"after",on:"is",is:"is",is_not:"is not",is_any_of:"is any of",is_none_of:"is none of",has_any:"has any of",has_none:"has none of",has_all:"has all of"})[o])?r:o," ").concat(l)}let ry={table:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("path",{d:"M3 12h18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})]})},label:"Table"},kanban:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"6",height:"14",x:"3",y:"5",rx:"1"}),(0,n.jsx)("rect",{width:"6",height:"10",x:"9",y:"9",rx:"1"}),(0,n.jsx)("rect",{width:"6",height:"16",x:"15",y:"3",rx:"1"})]})},label:"Board"},calendar:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"4",rx:"2"}),(0,n.jsx)("path",{d:"M16 2v4"}),(0,n.jsx)("path",{d:"M8 2v4"}),(0,n.jsx)("path",{d:"M3 10h18"})]})},label:"Calendar"},timeline:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h7"}),(0,n.jsx)("path",{d:"M6 12h10"}),(0,n.jsx)("path",{d:"M5 18h5"}),(0,n.jsx)("path",{d:"M14 6h7"}),(0,n.jsx)("path",{d:"M18 12h3"}),(0,n.jsx)("path",{d:"M12 18h9"})]})},label:"Timeline"},gallery:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]})},label:"Gallery"},list:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8 6h13"}),(0,n.jsx)("path",{d:"M8 12h13"}),(0,n.jsx)("path",{d:"M8 18h13"}),(0,n.jsx)("path",{d:"M3 6h.01"}),(0,n.jsx)("path",{d:"M3 12h.01"}),(0,n.jsx)("path",{d:"M3 18h.01"})]})},label:"List"}};function rb(e){let{value:t,onChange:r}=e;return(0,n.jsx)("div",{className:"flex items-center rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)"},children:rr.map(e=>{let o=ry[e],l=o.icon,a=e===t;return(0,n.jsxs)("button",{type:"button",onClick:()=>r(e),className:"flex items-center gap-1 px-2.5 py-1.5 text-[11px] transition-colors",style:{background:a?"var(--color-accent)":"var(--color-surface)",color:a?"#fff":"var(--color-text-muted)",borderRight:"list"!==e?"1px solid var(--color-border)":void 0},title:o.label,children:[(0,n.jsx)(l,{}),(0,n.jsx)("span",{className:"hidden sm:inline",children:o.label})]},e)})})}function rj(e){let{label:t,value:r,onChange:o,fields:l,filterType:a,allowEmpty:s}=e,i=a?Array.isArray(a)?a:[a]:null,c=i?l.filter(e=>i.includes(e.type)):l;return(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("label",{className:"text-[10px] font-medium",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsxs)("select",{value:null!=r?r:"",onChange:e=>o(e.target.value||void 0),className:"text-[12px] rounded-md border px-2 py-1.5 bg-transparent",style:{borderColor:"var(--color-border)",color:"var(--color-text)",background:"var(--color-surface)"},children:[s&&(0,n.jsx)("option",{value:"",children:"None"}),0===c.length&&(0,n.jsx)("option",{value:"",disabled:!0,children:"No matching fields"}),c.map(e=>(0,n.jsx)("option",{value:e.name,children:e.name},e.id))]})]})}function rk(e){let{label:t,value:r,options:o,onChange:l}=e;return(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("label",{className:"text-[10px] font-medium",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("div",{className:"flex rounded-md border overflow-hidden",style:{borderColor:"var(--color-border)"},children:o.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>l(e.value),className:"text-[11px] px-2.5 py-1 flex-1 transition-colors capitalize",style:{background:e.value===r?"var(--color-accent)":"var(--color-surface)",color:e.value===r?"#fff":"var(--color-text-muted)"},children:e.label},e.value))})]})}function rw(e){let{settings:t,fields:r,onSettingsChange:o}=e;return(0,n.jsx)(rj,{label:"Group by field",value:t.kanbanField,onChange:e=>o({...t,kanbanField:e}),fields:r,filterType:"enum"})}function rN(e){var t;let{settings:r,fields:o,onSettingsChange:l}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rj,{label:"Date field",value:r.calendarDateField,onChange:e=>l({...r,calendarDateField:e}),fields:o,filterType:"date"}),(0,n.jsx)(rj,{label:"End date field (optional)",value:r.calendarEndDateField,onChange:e=>l({...r,calendarEndDateField:e}),fields:o,filterType:"date",allowEmpty:!0}),(0,n.jsx)(rk,{label:"Default view",value:null!=(t=r.calendarMode)?t:"month",options:[{value:"day",label:"Day"},{value:"week",label:"Week"},{value:"month",label:"Month"},{value:"year",label:"Year"}],onChange:e=>l({...r,calendarMode:e})})]})}function rC(e){var t;let{settings:r,fields:o,onSettingsChange:l}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rj,{label:"Start date field",value:r.timelineStartField,onChange:e=>l({...r,timelineStartField:e}),fields:o,filterType:"date"}),(0,n.jsx)(rj,{label:"End date field",value:r.timelineEndField,onChange:e=>l({...r,timelineEndField:e}),fields:o,filterType:"date",allowEmpty:!0}),(0,n.jsx)(rj,{label:"Group by (optional)",value:r.timelineGroupField,onChange:e=>l({...r,timelineGroupField:e}),fields:o,filterType:"enum",allowEmpty:!0}),(0,n.jsx)(rk,{label:"Default zoom",value:null!=(t=r.timelineZoom)?t:"week",options:[{value:"day",label:"Day"},{value:"week",label:"Week"},{value:"month",label:"Month"},{value:"quarter",label:"Quarter"}],onChange:e=>l({...r,timelineZoom:e})})]})}function rS(e){let{settings:t,fields:r,onSettingsChange:o}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rj,{label:"Title field",value:t.galleryTitleField,onChange:e=>o({...t,galleryTitleField:e}),fields:r,filterType:"text"}),(0,n.jsx)(rj,{label:"Cover field (optional)",value:t.galleryCoverField,onChange:e=>o({...t,galleryCoverField:e}),fields:r,allowEmpty:!0})]})}function rM(e){let{settings:t,fields:r,onSettingsChange:o}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rj,{label:"Title field",value:t.listTitleField,onChange:e=>o({...t,listTitleField:e}),fields:r,filterType:"text"}),(0,n.jsx)(rj,{label:"Subtitle field (optional)",value:t.listSubtitleField,onChange:e=>o({...t,listSubtitleField:e}),fields:r,filterType:["text","email","richtext"],allowEmpty:!0})]})}function rL(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function rT(e){let{viewType:t,settings:r,fields:l,onSettingsChange:a}=e,[s,i]=(0,o.useState)(!1),c=(0,o.useRef)(null);return((0,o.useEffect)(()=>{if(!s)return;let e=e=>{c.current&&!c.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[s]),"table"===t)?null:(0,n.jsxs)("div",{className:"relative",ref:c,children:[(0,n.jsx)("button",{type:"button",onClick:()=>i(!s),className:"p-1.5 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text-muted)"},title:"View settings",children:(0,n.jsx)(rL,{})}),s&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-50 rounded-lg border shadow-lg p-3 min-w-[240px] flex flex-col gap-3",style:{borderColor:"var(--color-border)",background:"var(--color-surface)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,n.jsx)("div",{className:"text-[11px] font-semibold",style:{color:"var(--color-text)"},children:{table:"",kanban:"Board Settings",calendar:"Calendar Settings",timeline:"Timeline Settings",gallery:"Gallery Settings",list:"List Settings"}[t]}),"kanban"===t&&(0,n.jsx)(rw,{settings:r,fields:l,onSettingsChange:a}),"calendar"===t&&(0,n.jsx)(rN,{settings:r,fields:l,onSettingsChange:a}),"timeline"===t&&(0,n.jsx)(rC,{settings:r,fields:l,onSettingsChange:a}),"gallery"===t&&(0,n.jsx)(rS,{settings:r,fields:l,onSettingsChange:a}),"list"===t&&(0,n.jsx)(rM,{settings:r,fields:l,onSettingsChange:a})]})]})}var rD=r(24946);function rE(e){let t=[],r=0;for(let o of e.matchAll(/```report-json\s*\n([\s\S]*?)```/g)){var n;let l=e.slice(r,o.index);l.trim()&&t.push({type:"text",text:l});try{let e=JSON.parse(o[1]);e.panels&&Array.isArray(e.panels)?t.push({type:"report-artifact",config:e}):t.push({type:"text",text:o[0]})}catch(e){t.push({type:"text",text:o[0]})}r=(null!=(n=o.index)?n:0)+o[0].length}let o=e.slice(r);return o.trim()&&t.push({type:"text",text:o}),t}function rR(e){return e.includes("```report-json")}function rW(e){let t=[],r=0;for(let o of e.matchAll(/```diff\s*\n([\s\S]*?)```/g)){var n;let l=e.slice(r,o.index);l.trim()&&t.push({type:"text",text:l});let a=o[1].trimEnd();a?t.push({type:"diff-artifact",diff:a}):t.push({type:"text",text:o[0]}),r=(null!=(n=o.index)?n:0)+o[0].length}let o=e.slice(r);return o.trim()&&t.push({type:"text",text:o}),t}function rI(e){return e.includes("```diff")}function rB(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]})}function rF(e){let{expanded:t}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transition:"transform 150ms ease",transform:t?"rotate(90deg)":"rotate(0deg)"},children:(0,n.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function rA(e){let{file:t}=e,[r,l]=(0,o.useState)(!0),a=t.newPath&&"/dev/null"!==t.newPath?t.newPath:t.oldPath&&"/dev/null"!==t.oldPath?t.oldPath:"diff";return(0,n.jsxs)("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>l(!r),className:"flex items-center gap-2 w-full px-3 py-2 text-left",style:{background:"var(--color-surface)",borderBottom:r?"1px solid var(--color-border)":"none"},children:[(0,n.jsx)(rF,{expanded:r}),(0,n.jsx)(rB,{}),(0,n.jsx)("span",{className:"text-sm font-mono font-medium flex-1 truncate",style:{color:"var(--color-text)"},children:a}),t.additions>0&&(0,n.jsxs)("span",{className:"text-xs font-mono font-medium",style:{color:"var(--diff-add-badge)"},children:["+",t.additions]}),t.deletions>0&&(0,n.jsxs)("span",{className:"text-xs font-mono font-medium",style:{color:"var(--diff-del-badge)"},children:["-",t.deletions]})]}),r&&(0,n.jsx)("div",{className:"overflow-x-auto",style:{background:"var(--color-bg)"},children:(0,n.jsx)("table",{className:"w-full text-xs font-mono leading-5 border-collapse",style:{tabSize:4},children:(0,n.jsx)("tbody",{children:t.hunks.map((e,t)=>e.lines.map((e,r)=>{if("header"===e.type)return(0,n.jsx)("tr",{children:(0,n.jsx)("td",{colSpan:3,className:"px-3 py-1 select-none",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:e.content})},"".concat(t,"-").concat(r));let o="addition"===e.type?"var(--diff-add-bg)":"deletion"===e.type?"var(--diff-del-bg)":"transparent",l="addition"===e.type?"var(--diff-add-text)":"deletion"===e.type?"var(--diff-del-text)":"var(--color-text)",a="addition"===e.type?"+":"deletion"===e.type?"-":" ";return(0,n.jsxs)("tr",{style:{background:o},children:[(0,n.jsx)("td",{className:"select-none text-right pr-2 pl-3",style:{color:"var(--color-text-muted)",opacity:.5,width:"1%",whiteSpace:"nowrap",userSelect:"none"},children:"addition"!==e.type?e.oldLine:""}),(0,n.jsx)("td",{className:"select-none text-right pr-3",style:{color:"var(--color-text-muted)",opacity:.5,width:"1%",whiteSpace:"nowrap",userSelect:"none"},children:"deletion"!==e.type?e.newLine:""}),(0,n.jsxs)("td",{className:"pr-4",style:{color:l},children:[(0,n.jsx)("span",{className:"select-none inline-block w-4 text-center",style:{opacity:.6,userSelect:"none"},children:a}),e.content]})]},"".concat(t,"-").concat(r))}))})})})]})}function rP(e){let{diff:t}=e,r=(0,o.useMemo)(()=>(function(e){let t=[],r=e.split("\n"),n=null,o=null,l=0,a=0;for(let e=0;e<r.length;e++){let s=r[e];if(s.startsWith("--- ")){let o=r[e+1];if(null==o?void 0:o.startsWith("+++ ")){n={oldPath:s.replace(/^--- (a\/)?/,"").trim(),newPath:o.replace(/^\+\+\+ (b\/)?/,"").trim(),hunks:[],additions:0,deletions:0},t.push(n),e++;continue}}let i=s.match(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@(.*)/);if(i){l=parseInt(i[1],10),a=parseInt(i[2],10),o={header:s,lines:[{type:"header",content:s}]},n?n.hunks.push(o):(n={oldPath:"",newPath:"",hunks:[o],additions:0,deletions:0},t.push(n));continue}o&&n&&(s.startsWith("+")?(o.lines.push({type:"addition",content:s.slice(1),newLine:a}),n.additions++,a++):s.startsWith("-")?(o.lines.push({type:"deletion",content:s.slice(1),oldLine:l}),n.deletions++,l++):(s.startsWith(" ")||""===s)&&(o.lines.push({type:"context",content:s.slice(1)||"",oldLine:l,newLine:a}),l++,a++))}if(0===t.length&&e.trim()){let r=e.split("\n").map(e=>e.startsWith("+")?{type:"addition",content:e.slice(1)}:e.startsWith("-")?{type:"deletion",content:e.slice(1)}:{type:"context",content:e});t.push({oldPath:"",newPath:"",hunks:[{header:"",lines:r}],additions:r.filter(e=>"addition"===e.type).length,deletions:r.filter(e=>"deletion"===e.type).length})}return t})(t),[t]);return(0,n.jsx)("div",{className:"space-y-2 my-3",children:r.map((e,t)=>(0,n.jsx)(rA,{file:e},t))})}let r_=(0,rD.default)(()=>r.e(3867).then(r.bind(r,53867)).then(e=>e.MarkdownContent),{loadableGenerated:{webpack:()=>[53867]},ssr:!1,loading:()=>(0,n.jsxs)("div",{className:"animate-pulse space-y-3 py-4",children:[(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"80%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"60%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"70%"}})]})}),rz=(0,rD.default)(()=>r.e(5477).then(r.bind(r,45477)).then(e=>({default:e.ReportCard})),{loadableGenerated:{webpack:()=>[45477]},ssr:!1,loading:()=>(0,n.jsx)("div",{className:"h-48 rounded-xl animate-pulse my-4",style:{background:"var(--color-surface)"}})}),rO=(0,rD.default)(()=>Promise.all([r.e(4652),r.e(2597)]).then(r.bind(r,52597)).then(e=>({default:e.MarkdownEditor})),{loadableGenerated:{webpack:()=>[52597]},ssr:!1,loading:()=>(0,n.jsxs)("div",{className:"animate-pulse space-y-3 py-4 px-6",children:[(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"80%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"60%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"70%"}})]})});function rU(e){let{content:t,title:r,filePath:l,tree:a,onSave:s,onNavigate:i,searchFn:c}=e,[d,u]=(0,o.useState)(!!l),x=t.replace(/^---\s*\n[\s\S]*?\n---\s*\n/,""),h=x.match(/^#\s+(.+)/m),p=null!=r?r:null==h?void 0:h[1],m=p&&h?x.replace(/^#\s+.+\n?/,""):x;if(d&&l)return(0,n.jsx)("div",{className:"max-w-3xl mx-auto",children:(0,n.jsx)(rO,{content:x,rawContent:t,filePath:l,tree:null!=a?a:[],onSave:s,onNavigate:i,searchFn:c})});let f=rR(m)||rI(m),v=(0,o.useCallback)(e=>{if(!i)return;let t=e.target.closest("a");if(!t)return;let r=t.getAttribute("href");r&&(0,eb.m9)(r)&&(e.preventDefault(),e.stopPropagation(),i(r))},[i]);return(0,n.jsxs)("div",{className:"max-w-3xl mx-auto px-6 py-8",onClick:v,children:[(0,n.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[p&&(0,n.jsx)("h1",{className:"text-3xl font-bold mb-6 flex-1",style:{color:"var(--color-text)"},children:p}),l&&(0,n.jsxs)("button",{type:"button",onClick:()=>u(!0),className:"editor-mode-toggle flex-shrink-0 mt-1",title:"Edit this document",children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"}),(0,n.jsx)("path",{d:"m15 5 4 4"})]}),(0,n.jsx)("span",{children:"Edit"})]})]}),f?(0,n.jsx)(rH,{content:m}):(0,n.jsx)("div",{className:"workspace-prose",children:(0,n.jsx)(r_,{content:m})})]})}function rH(e){let{content:t}=e,r=rE(t),o=[];for(let e of r)if("text"===e.type&&rI(e.text))for(let t of rW(e.text))o.push(t);else o.push(e);return(0,n.jsx)("div",{className:"space-y-4",children:o.map((e,t)=>"report-artifact"===e.type?(0,n.jsx)("div",{className:"my-6",children:(0,n.jsx)(rz,{config:e.config})},t):"diff-artifact"===e.type?(0,n.jsx)("div",{className:"my-4",children:(0,n.jsx)(rP,{diff:e.diff})},t):(0,n.jsx)("div",{className:"workspace-prose",children:(0,n.jsx)(r_,{content:e.text})},t))})}let rV=new Set(["xlsx","xls","xlsb","xlsm","xltx","xltm","ods","fods","csv","tsv","numbers"]);function rJ(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return rV.has(n)}function rK(e){let{content:t,filename:r,type:o}=e,l=t.split("\n");return(0,n.jsxs)("div",{className:"max-w-4xl mx-auto px-6 py-8",children:[(0,n.jsx)(rq,{filename:r,label:o.toUpperCase()}),(0,n.jsx)("div",{className:"rounded-b-lg border overflow-x-auto",style:{background:"var(--color-bg)",borderColor:"var(--color-border)"},children:(0,n.jsx)("pre",{className:"text-sm leading-6",style:{margin:0},children:(0,n.jsx)("code",{children:l.map((e,t)=>(0,n.jsxs)("div",{className:"flex hover:bg-[var(--color-surface-hover)] transition-colors duration-75",children:[(0,n.jsx)("span",{className:"select-none text-right pr-4 pl-4 flex-shrink-0 tabular-nums",style:{color:"var(--color-text-muted)",opacity:.5,minWidth:"3rem",userSelect:"none"},children:t+1}),(0,n.jsx)("span",{className:"pr-4 flex-1",style:{color:"var(--color-text)"},children:"yaml"===o?(0,n.jsx)(rG,{line:e}):e||" "})]},t))})})})]})}function rq(e){let{filename:t,label:r,icon:o}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 rounded-t-lg border border-b-0",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[null!=o?o:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:t}),(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded ml-auto",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:r})]})}function rG(e){let{line:t}=e;if(t.trim().startsWith("#"))return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:t});let r=t.match(/^(\s*)([\w][\w_-]*)\s*(:)(.*)/);if(r){let[,e,t,o,l]=r;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:e}),(0,n.jsx)("span",{style:{color:"#60a5fa"},children:t}),(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:o}),(0,n.jsx)(r$,{value:l})]})}let o=t.match(/^(\s*)(-)(\s*)(.*)/);if(o){let[,e,t,r,l]=o;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:e}),(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:t}),(0,n.jsx)("span",{children:r}),(0,n.jsx)("span",{style:{color:"var(--color-text)"},children:l})]})}return(0,n.jsx)("span",{children:t||" "})}function r$(e){let{value:t}=e,r=t.trim();return r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'")?(0,n.jsxs)("span",{style:{color:"#a5d6a7"},children:[" ",r]}):"true"===r||"false"===r?(0,n.jsxs)("span",{style:{color:"#f59e0b"},children:[" ",r]}):/^-?\d+(\.\d+)?$/.test(r)?(0,n.jsxs)("span",{style:{color:"#c084fc"},children:[" ",r]}):"null"===r?(0,n.jsxs)("span",{style:{color:"var(--color-text-muted)",fontStyle:"italic"},children:[" ",r]}):(0,n.jsxs)("span",{style:{color:"var(--color-text)"},children:[" ",t]})}var rZ=r(81584),rY=r(13292);let rQ=new Set(["csv","tsv"]);function rX(e){var t,r;return null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:""}function r0(e){let t="",r=e;do t=String.fromCharCode(65+r%26)+t,r=Math.floor(r/26)-1;while(r>=0);return t}function r1(e){let{state:t,onClose:r,onInsertRowAbove:l,onInsertRowBelow:a,onInsertColLeft:s,onInsertColRight:i,onDeleteRow:c,onDeleteCol:d,onClearCells:u}=e,x=(0,o.useRef)(null);if((0,o.useEffect)(()=>{if(!t)return;let e=e=>{x.current&&!x.current.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]),!t)return null;let h={padding:"6px 12px",fontSize:"12px",cursor:"pointer",color:"var(--color-text)",borderRadius:"4px"};return(0,n.jsx)("div",{ref:x,style:{position:"fixed",top:t.y,left:t.x,zIndex:9999,background:"var(--color-surface-raised)",border:"1px solid var(--color-border)",borderRadius:"8px",padding:"4px",boxShadow:"var(--shadow-lg)",minWidth:"180px"},children:[{label:"Insert row above",action:l},{label:"Insert row below",action:a},{label:"Insert column left",action:s},{label:"Insert column right",action:i},{label:"Delete row",action:c,danger:!0},{label:"Delete column",action:d,danger:!0},{label:"Clear cells",action:u,danger:!0}].map((e,t)=>(0,n.jsxs)("div",{children:[4===t&&(0,n.jsx)("div",{style:{height:"1px",background:"var(--color-border)",margin:"4px 0"}}),(0,n.jsx)("button",{type:"button",onClick:()=>{e.action(),r()},style:{...h,color:e.danger?"var(--color-error)":"var(--color-text)",display:"block",width:"100%",textAlign:"left",background:"transparent",border:"none"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:e.label})]},t))})}function r2(e){let{data:t,onNavigate:r,onClose:l}=e,[a,s]=(0,o.useState)(""),[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(0),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;null==(e=x.current)||e.focus()},[]),(0,o.useEffect)(()=>{if(!a.trim()){c([]),u(0);return}let e=a.toLowerCase(),n=[];t.forEach((t,r)=>{null==t||t.forEach((t,o)=>{t&&String(t.value).toLowerCase().includes(e)&&n.push({row:r,column:o})})}),c(n),u(0),n.length>0&&r(n[0])},[a,t,r]);let h=(0,o.useCallback)(e=>{if(0===i.length)return;let t=(e%i.length+i.length)%i.length;u(t),r(i[t])},[i,r]);return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",background:"var(--color-surface)",borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]}),(0,n.jsx)("input",{ref:x,value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{"Escape"===e.key&&l(),"Enter"===e.key&&(e.preventDefault(),h(e.shiftKey?d-1:d+1))},placeholder:"Find in sheet...",style:{flex:1,background:"transparent",border:"none",outline:"none",fontSize:"12px",color:"var(--color-text)"}}),a&&(0,n.jsx)("span",{style:{fontSize:"11px",color:"var(--color-text-muted)",whiteSpace:"nowrap"},children:i.length>0?"".concat(d+1," of ").concat(i.length):"No results"}),(0,n.jsx)("button",{type:"button",onClick:()=>h(d-1),disabled:0===i.length,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px",color:"var(--color-text-muted)",opacity:0===i.length?.3:1},title:"Previous (Shift+Enter)",children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"m18 15-6-6-6 6"})})}),(0,n.jsx)("button",{type:"button",onClick:()=>h(d+1),disabled:0===i.length,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px",color:"var(--color-text-muted)",opacity:0===i.length?.3:1},title:"Next (Enter)",children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"m6 9 6 6 6-6"})})}),(0,n.jsx)("button",{type:"button",onClick:l,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px",color:"var(--color-text-muted)"},title:"Close (Esc)",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]})}function r4(e){let{onClick:t,title:r,disabled:o,children:l,accent:a}=e;return(0,n.jsx)("button",{type:"button",onClick:t,disabled:o,title:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",borderRadius:"6px",border:"none",background:a?"var(--color-accent)":"transparent",color:a?"#fff":"var(--color-text-muted)",cursor:o?"default":"pointer",opacity:o?.35:1,flexShrink:0,transition:"background 0.1s, color 0.1s"},onMouseEnter:e=>{o||a||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{a||(e.currentTarget.style.background="transparent")},children:l})}function r5(){return(0,n.jsx)("div",{style:{width:"1px",height:"18px",background:"var(--color-border)",margin:"0 4px",flexShrink:0}})}function r6(e){var t,r;let{url:l,filename:a,filePath:s,compact:i=!1}=e,[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)(0),[h,p]=(0,o.useState)(null),[m,f]=(0,o.useState)(!1),[v,g]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(null),[w,N]=(0,o.useState)(null),[C,S]=(0,o.useState)(null),[M,L]=(0,o.useState)(!1),T=(0,o.useRef)(null),[D,E]=(0,o.useState)([]),[R,W]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=!1;return d(null),x(0),p(null),f(!1),E([]),W([]),fetch(l).then(e=>{if(!e.ok)throw Error("Failed to load file (".concat(e.status,")"));return e.arrayBuffer()}).then(t=>{if(e)return;let r=(0,rY.LF)(t,{type:"array"}),n=r.SheetNames.map(e=>({name:e,data:function(e){let t=rY.Wp.sheet_to_json(e,{header:1,defval:""});if(0===t.length)return(0,rZ.JH)(1,1);let r=t.reduce((e,t)=>Math.max(e,t.length),0);return t.map(e=>{let t=[];for(let n=0;n<r;n++){let r=n<e.length?e[n]:"";t.push({value:null==r?"":r})}return t})}(r.Sheets[e])}));0===n.length&&n.push({name:"Sheet1",data:(0,rZ.JH)(50,26)}),d(n)}).catch(t=>{e||p(String(t))}),()=>{e=!0}},[l]);let I=null!=(r=null==c||null==(t=c[u])?void 0:t.data)?r:[],B=(0,o.useMemo)(()=>{let e=0;for(let t of I)t&&(e=Math.max(e,t.length));return e},[I]),F=(0,o.useMemo)(()=>Array.from({length:B},(e,t)=>r0(t)),[B]),A=(0,o.useCallback)(()=>{c&&(E(e=>[...e.slice(-49),{sheetIdx:u,data:c[u].data}]),W([]))},[c,u]),P=(0,o.useCallback)(e=>{d(t=>{if(!t)return t;let r=[...t];return r[u]={...r[u],data:e},r}),f(!0)},[u]),_=(0,o.useCallback)(e=>{A(),P(e)},[A,P]),z=(0,o.useCallback)(()=>{if(0===D.length||!c)return;let e=D[D.length-1];W(e=>[...e,{sheetIdx:u,data:c[u].data}]),E(e=>e.slice(0,-1)),d(t=>{if(!t)return t;let r=[...t];return r[e.sheetIdx]={...r[e.sheetIdx],data:e.data},r}),e.sheetIdx!==u&&x(e.sheetIdx)},[D,c,u]),O=(0,o.useCallback)(()=>{if(0===R.length||!c)return;let e=R[R.length-1];E(e=>[...e,{sheetIdx:u,data:c[u].data}]),W(e=>e.slice(0,-1)),d(t=>{if(!t)return t;let r=[...t];return r[e.sheetIdx]={...r[e.sheetIdx],data:e.data},r}),e.sheetIdx!==u&&x(e.sheetIdx)},[R,c,u]),U=(0,o.useCallback)(e=>{A();let t=Array.from({length:B},()=>({value:""})),r=[...I];r.splice(e,0,t),P(r)},[A,P,I,B]),H=(0,o.useCallback)(e=>{if(I.length<=1)return;A();let t=[...I];t.splice(e,1),P(t)},[A,P,I]),V=(0,o.useCallback)(e=>{A(),P(I.map(t=>{let r=[...null!=t?t:[]];return r.splice(e,0,{value:""}),r}))},[A,P,I]),J=(0,o.useCallback)(e=>{B<=1||(A(),P(I.map(t=>{let r=[...null!=t?t:[]];return r.splice(e,1),r})))},[A,P,I,B]),K=(0,o.useCallback)(()=>{if(!w)return;let e=w.toRange(I);if(!e)return;A();let t=I.map(e=>e?[...e]:[]);for(let r of e)t[r.row]&&(t[r.row][r.column]={value:""});P(t)},[w,I,A,P]),q=(0,o.useCallback)(async()=>{if(c&&!v){g(!0);try{if(rQ.has(rX(a))){let e="tsv"===rX(a)?" ":",",t=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:",";return e.map(e=>(null!=e?e:[]).map(e=>{let r=e?String(e.value):"";return r.includes(t)||r.includes('"')||r.includes("\n")?'"'.concat(r.replace(/"/g,'""'),'"'):r}).join(t)).join("\n")}(c[u].data,e);if(!(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s,content:t})})).ok)throw Error("Save failed")}else{let e=rY.Wp.book_new();for(let t of c)rY.Wp.book_append_sheet(e,function(e){let t=e.map(e=>(null!=e?e:[]).map(e=>e?e.value:""));return rY.Wp.aoa_to_sheet(t)}(t.data),t.name);let t=(0,rY.M9)(e,{type:"array",bookType:rX(a)});if(!(await fetch("/api/workspace/raw-file?path=".concat(encodeURIComponent(s)),{method:"POST",body:t})).ok)throw Error("Save failed")}f(!1),b(!0),setTimeout(()=>b(!1),1500)}catch(e){console.error("Spreadsheet save error:",e)}finally{g(!1)}}},[c,v,a,s,u]);(0,o.useEffect)(()=>{let e=e=>{let t=e.metaKey||e.ctrlKey;t&&"s"===e.key&&(e.preventDefault(),q()),t&&"z"===e.key&&!e.shiftKey&&(e.preventDefault(),z()),t&&"z"===e.key&&e.shiftKey&&(e.preventDefault(),O()),t&&"f"===e.key&&(e.preventDefault(),L(e=>!e))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[q,z,O]);let G=(0,o.useCallback)(e=>{e.preventDefault();let t=e.target.closest("td");if(!t)return;let r=t.closest("tr");if(!r)return;let n=r.closest("tbody");if(!n)return;let o=Array.from(n.children).indexOf(r),l=Array.from(r.children).indexOf(t)-1;o<0||l<0||S({x:e.clientX,y:e.clientY,row:o,col:l})},[]),$=(0,o.useCallback)(e=>{var t;k(e),null==(t=T.current)||t.activate(e),N(new rZ.MH(new rZ.m9(e,e)))},[]),Z=(0,o.useMemo)(()=>{var e;if(!j)return"";let t=null==(e=I[j.row])?void 0:e[j.column];return t?String(t.value):""},[j,I]),Y=(0,o.useCallback)(e=>{if(!j)return;A();let t=I.map(e=>e?[...e]:[]);t[j.row]||(t[j.row]=[]),t[j.row][j.column]={value:e},P(t)},[j,I,A,P]),Q=(0,o.useMemo)(()=>(function(e,t){if(!t)return null;let r=t.toRange(e);if(!r)return null;let n=0,o=0,l=0;for(let t of r){var a;let r=null==(a=e[t.row])?void 0:a[t.column];if(!r)continue;n++;let s=Number(r.value);""===r.value||isNaN(s)||(o++,l+=s)}return n<=1?null:{count:n,numericCount:o,sum:l,avg:o>0?l/o:0}})(I,w),[I,w]),X=rX(a).toUpperCase()||"SPREADSHEET";return h?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:"12px",padding:"24px"},children:[(0,n.jsx)(r3,{size:32}),(0,n.jsx)("p",{style:{color:"var(--color-text)",fontWeight:500,fontSize:"14px"},children:"Failed to load spreadsheet"}),(0,n.jsx)("p",{style:{color:"var(--color-text-muted)",fontSize:"12px"},children:h})]}):c?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%",background:"var(--color-bg)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:i?"6px 10px":"8px 16px",borderBottom:"1px solid var(--color-border)",background:"var(--color-surface)",flexShrink:0},children:[(0,n.jsx)(r3,{size:16}),(0,n.jsx)("span",{style:{fontSize:i?"12px":"13px",fontWeight:600,color:"var(--color-text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a}),(0,n.jsx)("span",{style:{fontSize:"10px",padding:"1px 6px",borderRadius:"4px",background:"var(--color-surface-hover)",color:"var(--color-text-muted)",fontWeight:500,flexShrink:0},children:X}),m&&(0,n.jsx)("span",{style:{fontSize:"10px",padding:"1px 6px",borderRadius:"4px",background:"var(--color-warning)",color:"#fff",fontWeight:500,flexShrink:0},children:"Unsaved"}),y&&(0,n.jsx)("span",{style:{fontSize:"10px",padding:"1px 6px",borderRadius:"4px",background:"var(--color-success)",color:"#fff",fontWeight:500,flexShrink:0},children:"Saved"}),(0,n.jsx)("div",{style:{flex:1}}),!i&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"2px"},children:[(0,n.jsx)(r4,{onClick:q,title:"Save (⌘S)",disabled:!m||v,accent:m,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}),(0,n.jsx)("path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}),(0,n.jsx)("path",{d:"M7 3v4a1 1 0 0 0 1 1h7"})]})}),(0,n.jsx)(r5,{}),(0,n.jsx)(r4,{onClick:z,title:"Undo (⌘Z)",disabled:0===D.length,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 7v6h6"}),(0,n.jsx)("path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"})]})}),(0,n.jsx)(r4,{onClick:O,title:"Redo (⌘⇧Z)",disabled:0===R.length,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 7v6h-6"}),(0,n.jsx)("path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"})]})}),(0,n.jsx)(r5,{}),(0,n.jsx)(r4,{onClick:()=>j&&U(j.row),title:"Insert row above",disabled:!j,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]})}),(0,n.jsx)(r4,{onClick:()=>j&&V(j.column),title:"Insert column left",disabled:!j,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("path",{d:"M12 8v8"}),(0,n.jsx)("path",{d:"M8 12h8"})]})}),(0,n.jsx)(r5,{}),(0,n.jsx)(r4,{onClick:()=>L(e=>!e),title:"Find (⌘F)",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]})})]}),i&&m&&(0,n.jsx)(r4,{onClick:q,title:"Save (⌘S)",disabled:v,accent:!0,children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}),(0,n.jsx)("path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}),(0,n.jsx)("path",{d:"M7 3v4a1 1 0 0 0 1 1h7"})]})})]}),!i&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"4px 16px",borderBottom:"1px solid var(--color-border)",background:"var(--color-surface)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--color-text-muted)",minWidth:"36px",textAlign:"center",padding:"2px 6px",borderRadius:"4px",background:"var(--color-surface-hover)",fontFamily:"monospace"},children:j?"".concat(r0(j.column)).concat(j.row+1):"\xa0"}),(0,n.jsx)("div",{style:{width:"1px",height:"18px",background:"var(--color-border)",flexShrink:0}}),(0,n.jsx)("span",{style:{fontSize:"11px",fontWeight:500,color:"var(--color-text-muted)",flexShrink:0},children:"fx"}),(0,n.jsx)("input",{type:"text",value:Z,onChange:e=>Y(e.target.value),placeholder:"Select a cell",style:{flex:1,background:"transparent",border:"none",outline:"none",fontSize:"12px",color:"var(--color-text)",fontFamily:"monospace"}})]}),M&&(0,n.jsx)(r2,{data:I,onNavigate:$,onClose:()=>L(!1)}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",position:"relative"},onContextMenu:G,children:(0,n.jsx)(rZ.Ay,{ref:T,data:I,onChange:_,columnLabels:F,onActivate:k,onSelect:N,darkMode:"undefined"!=typeof document&&document.documentElement.classList.contains("dark"),className:"spreadsheet-editor-grid"})}),(0,n.jsx)(r1,{state:C,onClose:()=>S(null),onInsertRowAbove:()=>C&&U(C.row),onInsertRowBelow:()=>C&&U(C.row+1),onInsertColLeft:()=>C&&V(C.col),onInsertColRight:()=>C&&V(C.col+1),onDeleteRow:()=>C&&H(C.row),onDeleteCol:()=>C&&J(C.col),onClearCells:K}),c.length>1&&(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:0,borderTop:"1px solid var(--color-border)",background:"var(--color-surface)",overflow:"auto",flexShrink:0},children:c.map((e,t)=>(0,n.jsxs)("button",{type:"button",onClick:()=>x(t),style:{padding:i?"4px 10px":"6px 16px",fontSize:i?"10px":"11px",fontWeight:t===u?600:400,color:t===u?"var(--color-text)":"var(--color-text-muted)",background:t===u?"var(--color-bg)":"transparent",border:"none",borderRight:"1px solid var(--color-border)",cursor:"pointer",whiteSpace:"nowrap",transition:"background 0.1s",position:"relative"},children:[e.name,t===u&&(0,n.jsx)("div",{style:{position:"absolute",top:0,left:0,right:0,height:"2px",background:"var(--color-accent)",borderRadius:"0 0 2px 2px"}})]},e.name))}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:i?"3px 10px":"4px 16px",borderTop:"1px solid var(--color-border)",background:"var(--color-surface)",fontSize:i?"10px":"11px",color:"var(--color-text-muted)",flexShrink:0,gap:"12px"},children:[(0,n.jsxs)("span",{children:[I.length," row",1!==I.length?"s":""," \xd7 ",B," col",1!==B?"s":"",c.length>1?" \xb7 ".concat(c.length," sheets"):""]}),Q&&(0,n.jsxs)("span",{style:{textAlign:"right"},children:["Count: ",Q.count,Q.numericCount>0&&(0,n.jsxs)(n.Fragment,{children:[" \xb7 ","Sum: ",Q.sum.toLocaleString()," \xb7 ","Avg: ",Q.avg.toLocaleString(void 0,{maximumFractionDigits:2})]})]})]})]}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:"12px"},children:[(0,n.jsx)("div",{className:"animate-spin",style:{width:"20px",height:"20px",border:"2px solid var(--color-border)",borderTopColor:"var(--color-accent)",borderRadius:"50%"}}),(0,n.jsx)("p",{style:{color:"var(--color-text-muted)",fontSize:"12px"},children:"Loading spreadsheet..."})]})}function r3(e){let{size:t=16}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"#22c55e",flexShrink:0},children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,n.jsx)("path",{d:"M8 13h2"}),(0,n.jsx)("path",{d:"M14 13h2"}),(0,n.jsx)("path",{d:"M8 17h2"}),(0,n.jsx)("path",{d:"M14 17h2"})]})}var r8=r(35778);let r7=null;function r9(e){let{filename:t,rawUrl:r,contentUrl:l}=e,[a,s]=(0,o.useState)("rendered"),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)(!1),x=(0,o.useCallback)(()=>{s("code"),null===i&&(u(!0),fetch(l).then(e=>e.json()).then(e=>c(e.content)).catch(()=>c("\x3c!-- Failed to load source --\x3e")).finally(()=>u(!1)))},[l,i]);return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-5 py-3 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)(nr,{}),(0,n.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:t}),(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"#f9731618",color:"#f97316",border:"1px solid #f9731630"},children:"HTML"}),(0,n.jsxs)("div",{className:"flex items-center ml-auto rounded-lg p-0.5",style:{background:"var(--color-surface-hover)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>s("rendered"),className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium transition-colors duration-100 cursor-pointer",style:{background:"rendered"===a?"var(--color-surface)":"transparent",color:"rendered"===a?"var(--color-text)":"var(--color-text-muted)",boxShadow:"rendered"===a?"0 1px 2px rgba(0,0,0,0.1)":"none"},children:[(0,n.jsx)(nn,{}),"Preview"]}),(0,n.jsxs)("button",{type:"button",onClick:x,className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium transition-colors duration-100 cursor-pointer",style:{background:"code"===a?"var(--color-surface)":"transparent",color:"code"===a?"var(--color-text)":"var(--color-text-muted)",boxShadow:"code"===a?"0 1px 2px rgba(0,0,0,0.1)":"none"},children:[(0,n.jsx)(no,{}),"Code"]})]}),(0,n.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md transition-colors duration-100",style:{color:"var(--color-text-muted)"},title:"Open in new tab",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nl,{})})]}),"rendered"===a?(0,n.jsx)(ne,{rawUrl:r}):d||null===i?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"w-6 h-6 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):(0,n.jsx)(nt,{content:i})]})}function ne(e){let{rawUrl:t}=e;return(0,n.jsx)("div",{className:"flex-1 overflow-hidden",style:{background:"white"},children:(0,n.jsx)("iframe",{src:t,className:"w-full h-full border-0",sandbox:"allow-same-origin allow-scripts allow-popups",title:"HTML preview",style:{minHeight:"calc(100vh - 120px)"}})})}function nt(e){let{content:t}=e,[r,l]=(0,o.useState)(null),a=(0,o.useMemo)(()=>t.split("\n").length,[t]);return(0,o.useEffect)(()=>{let e=!1;return(!r7&&(r7=(0,r8.O_)({themes:["github-dark","github-light"],langs:["html"]})),r7).then(r=>{e||l(r.codeToHtml(t,{lang:"html",themes:{dark:"github-dark",light:"github-light"}}))}),()=>{e=!0}},[t]),(0,n.jsx)("div",{className:"flex-1 overflow-auto",style:{background:"var(--color-surface)"},children:(0,n.jsxs)("div",{className:"max-w-4xl mx-auto px-6 py-8",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 rounded-t-lg border border-b-0",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[(0,n.jsx)(no,{}),(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"HTML"}),(0,n.jsxs)("span",{className:"text-xs ml-auto",style:{color:"var(--color-text-muted)"},children:[a," lines"]})]}),(0,n.jsx)("div",{className:"code-viewer-content rounded-b-lg border overflow-x-auto",style:{background:"var(--color-bg)",borderColor:"var(--color-border)"},children:r?(0,n.jsx)("div",{className:"code-viewer-highlighted",dangerouslySetInnerHTML:{__html:r}}):(0,n.jsx)("pre",{className:"text-sm leading-6",style:{margin:0},children:(0,n.jsx)("code",{children:t.split("\n").map((e,t)=>(0,n.jsxs)("div",{className:"flex hover:bg-[var(--color-surface-hover)] transition-colors duration-75",children:[(0,n.jsx)("span",{className:"select-none text-right pr-4 pl-4 flex-shrink-0 tabular-nums",style:{color:"var(--color-text-muted)",opacity:.5,minWidth:"3rem",userSelect:"none"},children:t+1}),(0,n.jsx)("span",{className:"pr-4 flex-1",style:{color:"var(--color-text)"},children:e||" "})]},t))})})})]})})}function nr(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f97316",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"}),(0,n.jsx)("line",{x1:"12",x2:"10",y1:"2",y2:"22"})]})}function nn(){return(0,n.jsxs)("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:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function no(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]})}function nl(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}function na(e,t){return"/api/apps/serve/".concat(e,"/").concat(t)}function ns(e){let{appPath:t,manifest:r}=e,l=(0,o.useRef)(null),[a,s]=(0,o.useState)(!0),[i,c]=(0,o.useState)(null),d=na(t,r.entry||"index.html"),u=(0,o.useCallback)(()=>{s(!0),c(null),l.current&&(l.current.src="".concat(d,"?_t=").concat(Date.now()))},[d]),x=(0,o.useCallback)(()=>{s(!1)},[]),h=(0,o.useCallback)(()=>{s(!1),c("Failed to load app")},[]);(0,o.useEffect)(()=>{let e=async e=>{if(!e.data||"dench:request"!==e.data.type)return;let{id:t,method:n,params:o}=e.data,a=l.current;if(!(null==a?void 0:a.contentWindow)||e.source!==a.contentWindow)return;let s=r.permissions||[];try{let e;if("app.getManifest"===n)e=r;else if("app.getTheme"===n)e=document.documentElement.classList.contains("dark")?"dark":"light";else if("db.query"===n&&s.includes("database")){let t=await fetch("/api/workspace/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:null==o?void 0:o.sql})});e=await t.json()}else if("db.execute"===n&&s.includes("database")){let t=await fetch("/api/workspace/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:null==o?void 0:o.sql})});e=await t.json()}else if("files.read"===n&&s.includes("files")){let t=await fetch("/api/workspace/file?path=".concat(encodeURIComponent(null==o?void 0:o.path)));e=await t.json()}else{if(!("files.list"===n&&s.includes("files")))return void a.contentWindow.postMessage({type:"dench:response",id:t,error:"Unknown method or insufficient permissions: ".concat(n)},"*");let r=await fetch("/api/workspace/tree?showHidden=0");e=await r.json()}a.contentWindow.postMessage({type:"dench:response",id:t,result:e},"*")}catch(e){var i;null==(i=a.contentWindow)||i.postMessage({type:"dench:response",id:t,error:e instanceof Error?e.message:"Unknown error"},"*")}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[r]);let p=r.icon&&(r.icon.endsWith(".png")||r.icon.endsWith(".svg")||r.icon.endsWith(".jpg")||r.icon.endsWith(".jpeg")||r.icon.endsWith(".webp"));return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-5 py-2.5 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[p?(0,n.jsx)("img",{src:na(t,r.icon),alt:"",width:20,height:20,className:"rounded flex-shrink-0",style:{objectFit:"cover"}}):(0,n.jsx)(ni,{}),(0,n.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:r.name}),r.version&&(0,n.jsxs)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"var(--color-accent-light)",color:"var(--color-accent)",border:"1px solid color-mix(in srgb, var(--color-accent) 20%, transparent)"},children:["v",r.version]}),(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"#6366f118",color:"#6366f1",border:"1px solid #6366f130"},children:"APP"}),(0,n.jsxs)("div",{className:"flex items-center gap-1 ml-auto",children:[(0,n.jsx)("button",{type:"button",onClick:u,className:"p-1.5 rounded-md transition-colors duration-100 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Reload app",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"}),(0,n.jsx)("path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"}),(0,n.jsx)("path",{d:"M16 16h5v5"})]})}),(0,n.jsx)("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md transition-colors duration-100",style:{color:"var(--color-text-muted)"},title:"Open in new tab",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden relative",style:{background:"white"},children:[a&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 z-10",style:{background:"var(--color-bg)"},children:[p?(0,n.jsx)("img",{src:na(t,r.icon),alt:"",width:48,height:48,className:"rounded-xl",style:{objectFit:"cover"}}):(0,n.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center",style:{background:"var(--color-accent-light)"},children:(0,n.jsx)(ni,{size:24})}),(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsxs)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["Loading ",r.name,"..."]})]}),i&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 z-10",style:{background:"var(--color-bg)"},children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center",style:{background:"color-mix(in srgb, var(--color-error) 10%, transparent)"},children:(0,n.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",x2:"9",y1:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",x2:"15",y1:"9",y2:"15"})]})}),(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:i}),(0,n.jsx)("button",{type:"button",onClick:u,className:"text-xs px-3 py-1.5 rounded-md cursor-pointer",style:{color:"var(--color-accent)",background:"var(--color-accent-light)"},children:"Try again"})]}),(0,n.jsx)("iframe",{ref:l,src:d,className:"w-full h-full border-0",sandbox:"allow-same-origin allow-scripts allow-popups allow-forms",title:r.name,onLoad:x,onError:h,style:{minHeight:"calc(100vh - 120px)"}})]})]})}function ni(e){let{size:t=18}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"#6366f1",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]})}var nc=r(47164);let nd={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",css:"css",scss:"scss",less:"less",html:"html",htm:"html",xml:"xml",svg:"xml",json:"json",jsonc:"json",yaml:"yaml",yml:"yaml",toml:"plaintext",md:"markdown",mdx:"markdown",sh:"shell",bash:"shell",zsh:"shell",fish:"shell",ps1:"powershell",sql:"sql",graphql:"graphql",gql:"graphql",dockerfile:"dockerfile",docker:"dockerfile",makefile:"plaintext",cmake:"plaintext",r:"r",lua:"lua",php:"php",vue:"html",svelte:"html",diff:"plaintext",patch:"plaintext",ini:"ini",env:"ini",tf:"plaintext",proto:"protobuf",zig:"plaintext",elixir:"plaintext",ex:"plaintext",erl:"plaintext",hs:"plaintext",scala:"scala",clj:"clojure",dart:"dart"};function nu(e){var t;let r=e.toLowerCase();return"dockerfile"===r||r.startsWith("dockerfile.")?"dockerfile":"makefile"===r||"gnumakefile"===r?"makefile":"cmakelists.txt"===r?"cmake":null!=(t=r.split(".").pop())?t:""}function nx(e){var t;return null!=(t=nd[nu(e)])?t:"plaintext"}let nh=!1;function np(){return"undefined"!=typeof document&&document.documentElement.classList.contains("dark")}function nm(e){let{content:t,filename:r,filePath:o,className:l}=e,a=nu(r);return"diff"===a||"patch"===a?(0,n.jsx)("div",{className:"max-w-4xl mx-auto px-6 py-8",children:(0,n.jsx)(rP,{diff:t})}):(0,n.jsx)(nf,{content:t,filename:r,filePath:o,className:l})}function nf(e){let{content:t,filename:r,filePath:l,className:a}=e,s=(0,o.useRef)(null),i=(0,o.useRef)(null),[c,d]=(0,o.useState)(np()?"denchclaw-dark":"denchclaw-light"),[u,x]=(0,o.useState)("clean"),[h,p]=(0,o.useState)({line:1,col:1}),m=(0,o.useRef)(null),f=(0,o.useRef)(t),v=nx(r),g=!!l;(0,o.useEffect)(()=>{f.current=t},[t]),(0,o.useEffect)(()=>{let e=document.documentElement,t=new MutationObserver(()=>d(np()?"denchclaw-dark":"denchclaw-light"));return t.observe(e,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let y=(0,o.useCallback)(async()=>{if(!l||!s.current)return;let e=s.current.getValue();x("saving");try{if(!(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:l,content:e})})).ok)throw Error("Save failed");f.current=e,x("saved"),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>x("clean"),2e3)}catch(e){x("error"),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>x("dirty"),3e3)}},[l]),b=(0,o.useCallback)((e,t)=>{s.current=e,i.current=t,nh||(nh=!0,t.editor.defineTheme("denchclaw-light",{base:"vs",inherit:!0,rules:[],colors:{"editor.background":"#ffffff","editor.foreground":"#1c1c1a","editor.lineHighlightBackground":"#f5f4f1","editor.selectionBackground":"#2563eb20","editor.inactiveSelectionBackground":"#2563eb10","editorLineNumber.foreground":"#8a8a82","editorLineNumber.activeForeground":"#44443e","editorIndentGuide.background":"#00000010","editorIndentGuide.activeBackground":"#00000020","editor.selectionHighlightBackground":"#2563eb12","editorCursor.foreground":"#2563eb","editorWhitespace.foreground":"#00000010","editorBracketMatch.background":"#2563eb15","editorBracketMatch.border":"#2563eb40","editorGutter.background":"#ffffff","editorWidget.background":"#ffffff","editorWidget.border":"#00000014","editorSuggestWidget.background":"#ffffff","editorSuggestWidget.border":"#00000014","editorSuggestWidget.selectedBackground":"#f5f4f1","editorHoverWidget.background":"#ffffff","editorHoverWidget.border":"#00000014","input.background":"#f5f5f4","input.border":"#00000014","input.foreground":"#1c1c1a","minimap.background":"#ffffff","scrollbarSlider.background":"#00000012","scrollbarSlider.hoverBackground":"#00000020","scrollbarSlider.activeBackground":"#0000002a"}}),t.editor.defineTheme("denchclaw-dark",{base:"vs-dark",inherit:!0,rules:[],colors:{"editor.background":"#0c0c0b","editor.foreground":"#ececea","editor.lineHighlightBackground":"#1e1e1c","editor.selectionBackground":"#3b82f630","editor.inactiveSelectionBackground":"#3b82f618","editorLineNumber.foreground":"#78776f","editorLineNumber.activeForeground":"#b8b8b0","editorIndentGuide.background":"#ffffff08","editorIndentGuide.activeBackground":"#ffffff14","editor.selectionHighlightBackground":"#3b82f618","editorCursor.foreground":"#3b82f6","editorWhitespace.foreground":"#ffffff08","editorBracketMatch.background":"#3b82f620","editorBracketMatch.border":"#3b82f650","editorGutter.background":"#0c0c0b","editorWidget.background":"#161615","editorWidget.border":"#ffffff14","editorSuggestWidget.background":"#161615","editorSuggestWidget.border":"#ffffff14","editorSuggestWidget.selectedBackground":"#1e1e1c","editorHoverWidget.background":"#161615","editorHoverWidget.border":"#ffffff14","input.background":"#1e1e1c","input.border":"#ffffff14","input.foreground":"#ececea","minimap.background":"#0c0c0b","scrollbarSlider.background":"#ffffff12","scrollbarSlider.hoverBackground":"#ffffff20","scrollbarSlider.activeBackground":"#ffffff2a"}})),t.editor.setTheme(np()?"denchclaw-dark":"denchclaw-light"),e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>{y()}),e.onDidChangeCursorPosition(e=>{p({line:e.position.lineNumber,col:e.position.column})}),e.onDidChangeModelContent(()=>{e.getValue()!==f.current?x("dirty"):x("clean")}),e.focus()},[y]);(0,o.useEffect)(()=>{i.current&&i.current.editor.setTheme(c)},[c]);let j=function(e){let t=nx(e);return"plaintext"===t?nu(e)||"TEXT":t}(r),k=t.split("\n").length;return(0,n.jsxs)("div",{className:"flex flex-col h-full ".concat(null!=a?a:""),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 flex-shrink-0",style:{background:"var(--color-surface)",borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",flexShrink:0},children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]}),(0,n.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:r}),"dirty"===u&&(0,n.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:"var(--color-text-muted)"},title:"Unsaved changes"}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("span",{className:"text-[11px] px-1.5 py-0.5 rounded font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:j.toUpperCase()}),(0,n.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:[k," lines"]}),(0,n.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:["Ln ",h.line,", Col ",h.col]}),g&&(0,n.jsxs)(n.Fragment,{children:["saving"===u&&(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:"Saving..."}),"saved"===u&&(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-success)"},children:"Saved"}),"error"===u&&(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-error)"},children:"Save failed"}),(0,n.jsx)("button",{type:"button",onClick:()=>void y(),disabled:"dirty"!==u,className:"text-[11px] px-2 py-0.5 rounded transition-colors",style:{background:"dirty"===u?"var(--color-accent)":"var(--color-surface-hover)",color:"dirty"===u?"#fff":"var(--color-text-muted)",cursor:"dirty"===u?"pointer":"default",opacity:"dirty"===u?1:.5},children:"Save"})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(nc.Ay,{defaultValue:t,language:v,theme:c,onMount:b,loading:(0,n.jsx)("div",{className:"flex items-center justify-center h-full",style:{background:"var(--color-bg)"},children:(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Loading editor..."})}),options:{readOnly:!g,fontSize:13,lineHeight:20,fontFamily:"'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Menlo, Monaco, 'Courier New', monospace",fontLigatures:!0,minimap:{enabled:!0,scale:1,showSlider:"mouseover"},scrollBeyondLastLine:!0,smoothScrolling:!0,cursorBlinking:"smooth",cursorSmoothCaretAnimation:"on",renderLineHighlight:"all",renderWhitespace:"selection",bracketPairColorization:{enabled:!0},guides:{bracketPairs:!0,indentation:!0,highlightActiveIndentation:!0},stickyScroll:{enabled:!0},folding:!0,foldingHighlight:!0,showFoldingControls:"mouseover",links:!0,wordWrap:"off",padding:{top:8,bottom:8},scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10,verticalSliderSize:10,horizontalSliderSize:10},overviewRulerBorder:!1,hideCursorInOverviewRuler:!0,automaticLayout:!0,tabSize:2,insertSpaces:!1,detectIndentation:!0,formatOnPaste:!1,formatOnType:!1,suggestOnTriggerCharacters:!0,quickSuggestions:!0,contextmenu:!0,mouseWheelZoom:!0,find:{addExtraSpaceOnTop:!1,autoFindInSelection:"multiline",seedSearchStringFromSelection:"selection"}}})})]})}let nv=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","ico","tiff","tif"]),ng=new Set(["mp4","webm","mov","avi","mkv"]),ny=new Set(["mp3","wav","ogg","m4a","aac","flac"]),nb=new Set(["pdf"]);function nj(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return nv.has(n)?"image":ng.has(n)?"video":ny.has(n)?"audio":nb.has(n)?"pdf":null}function nk(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]})}function nw(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}function nN(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65"}),(0,n.jsx)("line",{x1:"11",x2:"11",y1:"8",y2:"14"}),(0,n.jsx)("line",{x1:"8",x2:"14",y1:"11",y2:"11"})]})}function nC(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65"}),(0,n.jsx)("line",{x1:"8",x2:"14",y1:"11",y2:"11"})]})}function nS(e){switch(e){case"image":return"#60a5fa";case"video":return"#c084fc";case"audio":return"#f59e0b";case"pdf":return"#ef4444"}}function nM(e){let{url:t,filename:r,mediaType:o,filePath:l}=e;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-5 py-3 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)(nR,{mediaType:o}),(0,n.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:r}),(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"".concat(nS(o),"18"),color:nS(o),border:"1px solid ".concat(nS(o),"30")},children:function(e){switch(e){case"image":return"Image";case"video":return"Video";case"audio":return"Audio";case"pdf":return"PDF"}}(o)}),(0,n.jsxs)("div",{className:"flex items-center gap-1 ml-auto",children:[(0,n.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md transition-colors duration-100",style:{color:"var(--color-text-muted)"},title:"Open in new tab",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nw,{})}),(0,n.jsx)("a",{href:t,download:r,className:"p-1.5 rounded-md transition-colors duration-100",style:{color:"var(--color-text-muted)"},title:"Download",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nk,{})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto flex items-center justify-center p-6",style:{background:"var(--color-surface)"},children:["image"===o&&(0,n.jsx)(nL,{url:t,filename:r}),"video"===o&&(0,n.jsx)(nT,{url:t}),"audio"===o&&(0,n.jsx)(nD,{url:t,filename:r}),"pdf"===o&&(0,n.jsx)(nE,{url:t})]}),l&&(0,n.jsx)("div",{className:"px-5 py-2 border-t flex-shrink-0 flex items-center",style:{borderColor:"var(--color-border)"},children:(0,n.jsx)("span",{className:"text-[11px] truncate",style:{color:"var(--color-text-muted)",fontFamily:"'SF Mono', 'Fira Code', monospace"},children:l})})]})}function nL(e){let{url:t,filename:r}=e,[l,a]=(0,o.useState)(1),[s,i]=(0,o.useState)(!1),c=(0,o.useCallback)(()=>a(e=>Math.min(1.5*e,5)),[]),d=(0,o.useCallback)(()=>a(e=>Math.max(e/1.5,.25)),[]),u=(0,o.useCallback)(()=>a(1),[]);return s?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-3 py-12",children:[(0,n.jsx)("span",{className:"text-4xl",style:{opacity:.3},children:"\uD83D\uDDBC"}),(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Failed to load image"})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center gap-4 w-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{type:"button",onClick:d,className:"p-1.5 rounded-md transition-colors duration-100 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Zoom out",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nC,{})}),(0,n.jsxs)("button",{type:"button",onClick:u,className:"px-2 py-1 rounded-md text-[11px] tabular-nums transition-colors duration-100 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Reset zoom",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[Math.round(100*l),"%"]}),(0,n.jsx)("button",{type:"button",onClick:c,className:"p-1.5 rounded-md transition-colors duration-100 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Zoom in",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nN,{})})]}),(0,n.jsx)("div",{className:"overflow-auto max-w-full max-h-[calc(100vh-260px)] rounded-xl border",style:{borderColor:"var(--color-border)",backgroundImage:"linear-gradient(45deg, var(--color-surface-hover) 25%, transparent 25%), linear-gradient(-45deg, var(--color-surface-hover) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--color-surface-hover) 75%), linear-gradient(-45deg, transparent 75%, var(--color-surface-hover) 75%)",backgroundSize:"20px 20px",backgroundPosition:"0 0, 0 10px, 10px -10px, -10px 0px"},children:(0,n.jsx)("img",{src:t,alt:r,onError:()=>i(!0),style:{transform:"scale(".concat(l,")"),transformOrigin:"center center",transition:"transform 200ms ease",maxWidth:l<=1?"100%":"none",display:"block"},draggable:!1})})]})}function nT(e){let{url:t}=e;return(0,n.jsx)("div",{className:"w-full max-w-4xl",children:(0,n.jsx)("video",{src:t,controls:!0,className:"w-full rounded-xl border",style:{borderColor:"var(--color-border)",maxHeight:"calc(100vh - 220px)",background:"#000"}})})}function nD(e){let{url:t,filename:r}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center gap-6 py-8",children:[(0,n.jsx)("div",{className:"w-32 h-32 rounded-2xl flex items-center justify-center",style:{background:"linear-gradient(135deg, #f59e0b20, #f59e0b10)",border:"1px solid #f59e0b30"},children:(0,n.jsxs)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]})}),(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:r}),(0,n.jsx)("audio",{src:t,controls:!0,className:"w-full max-w-md"})]})}function nE(e){let{url:t}=e;return(0,n.jsx)("div",{className:"w-full h-full flex flex-col",children:(0,n.jsx)("iframe",{src:t,className:"w-full flex-1 rounded-xl border",style:{borderColor:"var(--color-border)",minHeight:"calc(100vh - 220px)",background:"white"},title:"PDF viewer"})})}function nR(e){let{mediaType:t}=e,r=nS(t);switch(t){case"image":return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,n.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,n.jsx)("path",{d:"M10 9H8"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"})]})}}function nW(e){let{size:t=16}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]})}function nI(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]})}function nB(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function nF(){return(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)("circle",{cx:"12",cy:"12",r:"1"})})}function nA(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"6 3 20 12 6 21 6 3"})})}function nP(e){let{direction:t}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:"left"===t?(0,n.jsx)("path",{d:"m15 18-6-6 6-6"}):(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}function n_(e){let{active:t,direction:r}=e;return(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:t?1:.25},children:"asc"===r?(0,n.jsx)("path",{d:"m5 12 7-7 7 7"}):(0,n.jsx)("path",{d:"m19 12-7 7-7-7"})})}function nz(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):""}function nO(e){let t=e.toUpperCase();return t.includes("INT")||t.includes("BIGINT")||t.includes("SMALLINT")||t.includes("TINYINT")||t.includes("HUGEINT")?{label:"int",color:"#c084fc"}:t.includes("FLOAT")||t.includes("DOUBLE")||t.includes("DECIMAL")||t.includes("NUMERIC")||t.includes("REAL")?{label:"float",color:"#c084fc"}:t.includes("BOOL")?{label:"bool",color:"#f59e0b"}:t.includes("VARCHAR")||t.includes("TEXT")||t.includes("STRING")||t.includes("CHAR")||"UUID"===t||"BLOB"===t?{label:t.includes("UUID")?"uuid":"text",color:"#22c55e"}:t.includes("TIMESTAMP")||t.includes("DATETIME")?{label:"timestamp",color:"#60a5fa"}:t.includes("DATE")?{label:"date",color:"#60a5fa"}:t.includes("TIME")?{label:"time",color:"#60a5fa"}:t.includes("JSON")?{label:"json",color:"#fb923c"}:{label:e.toLowerCase(),color:"var(--color-text-muted)"}}function nU(){return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-5 p-8",children:[(0,n.jsx)("div",{className:"w-16 h-16 rounded-2xl flex items-center justify-center",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},children:(0,n.jsx)(nW,{size:32})}),(0,n.jsxs)("div",{className:"text-center max-w-sm",children:[(0,n.jsx)("h3",{className:"text-sm font-medium mb-1",style:{color:"var(--color-text)"},children:"DuckDB is not installed"}),(0,n.jsx)("p",{className:"text-xs leading-relaxed",style:{color:"var(--color-text-muted)"},children:"The DuckDB CLI is required to view database files and workspace data. Click below to install it automatically."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{let e=new URLSearchParams(window.location.search);e.set("send","install duckdb"),window.location.href="/?".concat(e.toString())},className:"flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors cursor-pointer",style:{background:"var(--color-accent)",color:"white"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]}),"Install DuckDB"]})]})}function nH(e){let{dbPath:t,filename:r}=e,[l,a]=(0,o.useState)([]),[s,i]=(0,o.useState)(!0),[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)(!0),[h,p]=(0,o.useState)(null),[m,f]=(0,o.useState)([]),[v,g]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(0),[w,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(""),[M,L]=(0,o.useState)(null),[T,D]=(0,o.useState)(null),[E,R]=(0,o.useState)(!1),[W,I]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=!1;return async function(){i(!0),d(null);try{let o=await fetch("/api/workspace/db/introspect?path=".concat(encodeURIComponent(t)));if(!o.ok){let e=await o.json().catch(()=>({}));throw Error(e.error||"HTTP ".concat(o.status))}let l=await o.json();if(!e)if(!1===l.duckdb_available)x(!1);else{var r,n;a(null!=(n=l.tables)?n:[]),(null==(r=l.tables)?void 0:r.length)>0&&p(l.tables[0].table_name)}}catch(t){e||d(t instanceof Error?t.message:"Failed to introspect database")}finally{e||i(!1)}}(),()=>{e=!0}},[t]);let B=(0,o.useCallback)(async(e,r)=>{g(!0);try{var n;let o=e.replace(/"/g,'""'),l='SELECT * FROM "'.concat(o,'" LIMIT ').concat(100," OFFSET ").concat(r),a=await fetch("/api/workspace/db/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t,sql:l})});if(!a.ok)return void f([]);let s=await a.json();f(null!=(n=s.rows)?n:[])}catch(e){f([])}finally{g(!1)}},[t]);(0,o.useEffect)(()=>{h&&(b(null),B(h,100*j))},[h,j,B]);let F=(0,o.useCallback)(async()=>{if(C.trim()){R(!0),D(null),L(null);try{let r=await fetch("/api/workspace/db/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t,sql:C})}),n=await r.json();if(r.ok){var e;L(null!=(e=n.rows)?e:[])}else D(n.error||"HTTP ".concat(r.status))}catch(e){D(e instanceof Error?e.message:"Query failed")}finally{R(!1)}}},[t,C]),A=(0,o.useMemo)(()=>{var e;return null!=(e=l.find(e=>e.table_name===h))?e:null},[l,h]),P=(0,o.useMemo)(()=>{let e=w&&M?M:m;return y?[...e].toSorted((e,t)=>{let r=nz(e[y.column]),n=nz(t[y.column]),o=r.localeCompare(n,void 0,{numeric:!0});return"asc"===y.direction?o:-o}):e},[w,M,m,y]),_=e=>{b(t=>(null==t?void 0:t.column)===e?"asc"===t.direction?{column:e,direction:"desc"}:null:{column:e,direction:"asc"})},z=(0,o.useMemo)(()=>{let e=w&&M?M:m;return 0===e.length?[]:Object.keys(e[0])},[w,M,m]),O=(0,o.useMemo)(()=>{var e;let t=null==(e=r.split(".").pop())?void 0:e.toLowerCase();return"duckdb"===t?"DuckDB":"sqlite"===t||"sqlite3"===t?"SQLite":"postgres"===t?"PostgreSQL":"Database"},[r]);return s?(0,n.jsxs)("div",{className:"flex items-center justify-center h-full gap-3",children:[(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Loading database..."})]}):c?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-4 p-8",children:[(0,n.jsx)(nW,{size:48}),(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Failed to open database"}),(0,n.jsx)("p",{className:"text-xs px-3 py-2 rounded-lg max-w-md text-center",style:{background:"var(--color-surface)",color:"#f87171"},children:c})]}):u?(0,n.jsxs)("div",{className:"flex h-full",children:[(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 border-r flex flex-col overflow-hidden",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("div",{className:"px-3 py-3 border-b flex items-center gap-2",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:(0,n.jsx)(nW,{size:18})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-xs font-medium truncate",style:{color:"var(--color-text)"},children:r}),(0,n.jsxs)("div",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:[O," \xb7 ",l.length," table",1!==l.length?"s":""]})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto py-1",children:0===l.length?(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs",style:{color:"var(--color-text-muted)"},children:"No tables found"}):l.map(e=>{var t;let r=e.table_name.startsWith("v_"),o=h===e.table_name;return(0,n.jsxs)("button",{type:"button",onClick:()=>{p(e.table_name),k(0),N(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors duration-75 cursor-pointer",style:{background:o?"var(--color-surface-hover)":"transparent",color:o?"var(--color-text)":"var(--color-text-muted)"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{className:"flex-shrink-0",style:{color:r?"#60a5fa":"var(--color-accent)"},children:r?(0,n.jsx)(nB,{}):(0,n.jsx)(nI,{})}),(0,n.jsx)("span",{className:"truncate flex-1",children:e.table_name}),(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] tabular-nums",style:{color:"var(--color-text-muted)"},children:(t=e.estimated_row_count)>=1e6?"".concat((t/1e6).toFixed(1),"M"):t>=1e3?"".concat((t/1e3).toFixed(1),"K"):String(t)})]},e.table_name)})}),(0,n.jsx)("div",{className:"px-3 py-2 border-t",style:{borderColor:"var(--color-border)"},children:(0,n.jsxs)("button",{type:"button",onClick:()=>N(!w),className:"w-full flex items-center justify-center gap-1.5 py-1.5 rounded-md text-xs font-medium transition-colors duration-100 cursor-pointer",style:{background:w?"var(--color-accent-light)":"var(--color-surface-hover)",color:w?"var(--color-accent)":"var(--color-text-muted)",border:"1px solid ".concat(w?"var(--color-accent)":"var(--color-border)")},children:[(0,n.jsx)(nA,{}),"SQL Query"]})})]}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:w?(0,n.jsx)(nJ,{sqlInput:C,setSqlInput:S,queryResult:M,queryError:T,queryRunning:E,runQuery:F,dataColumns:z,sortedData:P,sort:y,onSort:_}):A?(0,n.jsx)(nV,{table:A,data:P,dataLoading:v,dataColumns:z,sort:y,onSort:_,page:j,pageSize:100,onPageChange:k,showSchema:W,onToggleSchema:()=>I(!W)}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Select a table to view its data"})})})]}):(0,n.jsx)(nU,{})}function nV(e){let{table:t,data:r,dataLoading:o,dataColumns:l,sort:a,onSort:s,page:i,pageSize:c,onPageChange:d,showSchema:u,onToggleSchema:x}=e,h=t.estimated_row_count,p=Math.max(1,Math.ceil(h/c));return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2.5 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:(0,n.jsx)(nI,{})}),(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:t.table_name}),(0,n.jsxs)("div",{className:"flex items-center gap-2 ml-auto",children:[(0,n.jsxs)("span",{className:"text-[10px] px-2 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[t.estimated_row_count.toLocaleString()," rows"]}),(0,n.jsxs)("span",{className:"text-[10px] px-2 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[t.column_count," columns"]}),(0,n.jsx)("button",{type:"button",onClick:x,className:"text-[10px] px-2 py-0.5 rounded-full cursor-pointer transition-colors duration-100",style:{background:u?"rgba(96, 165, 250, 0.15)":"var(--color-surface)",color:u?"#60a5fa":"var(--color-text-muted)",border:"1px solid ".concat(u?"#60a5fa":"var(--color-border)")},children:"Schema"})]})]}),u&&(0,n.jsx)("div",{className:"px-4 py-3 border-b overflow-x-auto flex-shrink-0",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:(0,n.jsx)("div",{className:"flex flex-wrap gap-x-6 gap-y-1.5",children:t.columns.map(e=>{let t=nO(e.type);return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs",children:[(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(nF,{})}),(0,n.jsx)("span",{className:"font-medium",style:{color:"var(--color-text)"},children:e.name}),(0,n.jsx)("span",{className:"px-1 py-px rounded text-[10px]",style:{background:"".concat(t.color,"18"),color:t.color},children:t.label}),e.is_nullable&&(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)",opacity:.5},children:"null"})]},e.name)})})}),(0,n.jsx)("div",{className:"flex-1 overflow-auto relative",children:o?(0,n.jsx)("div",{className:"flex items-center justify-center h-32",children:(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):0===r.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-20 gap-2",children:[(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.4},children:(0,n.jsx)(nI,{})}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No data"})]}):(0,n.jsx)(nK,{columns:l,rows:r,sort:a,onSort:s,schemaColumns:t.columns})}),h>c&&(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-t flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["Page ",i+1," of ",p]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{type:"button",disabled:0===i,onClick:()=>d(i-1),className:"p-1 rounded transition-colors duration-100 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(nP,{direction:"left"})}),(0,n.jsx)("button",{type:"button",disabled:i>=p-1,onClick:()=>d(i+1),className:"p-1 rounded transition-colors duration-100 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(nP,{direction:"right"})})]})]})]})}function nJ(e){let{sqlInput:t,setSqlInput:r,queryResult:o,queryError:l,queryRunning:a,runQuery:s,dataColumns:i,sortedData:c,sort:d,onSort:u}=e;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsx)("div",{className:"px-4 py-3 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("textarea",{value:t,onChange:e=>r(e.target.value),placeholder:"SELECT * FROM table_name LIMIT 100",className:"w-full text-xs rounded-lg px-3 py-2 resize-none outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)",fontFamily:"'SF Mono', 'Fira Code', 'JetBrains Mono', monospace",minHeight:"60px"},onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),s())}}),(0,n.jsx)("div",{className:"text-[10px] mt-1",style:{color:"var(--color-text-muted)"},children:"Press Cmd+Enter to run"})]}),(0,n.jsxs)("button",{type:"button",onClick:s,disabled:a||!t.trim(),className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"var(--color-accent)",color:"white"},children:[a?(0,n.jsx)("div",{className:"w-3.5 h-3.5 border-2 rounded-full animate-spin",style:{borderColor:"rgba(255,255,255,0.3)",borderTopColor:"white"}}):(0,n.jsx)(nA,{}),"Run"]})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[l&&(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("div",{className:"px-3 py-2 rounded-lg text-xs",style:{background:"rgba(248, 113, 113, 0.1)",color:"#f87171",border:"1px solid rgba(248, 113, 113, 0.2)"},children:l})}),null!==o&&0===o.length&&!l&&(0,n.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Query returned no results"})}),null!==o&&o.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-4 py-1.5",children:(0,n.jsxs)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:[o.length," row",1!==o.length?"s":""]})}),(0,n.jsx)(nK,{columns:i,rows:c,sort:d,onSort:u})]}),null===o&&!l&&(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:[(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.3},children:(0,n.jsx)(nA,{})}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Write a SQL query and press Run"})]})]})]})}function nK(e){let{columns:t,rows:r,sort:o,onSort:l,schemaColumns:a}=e;return(0,n.jsxs)("table",{className:"w-full text-xs",style:{borderCollapse:"separate",borderSpacing:0},children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"text-right px-2 py-2 font-normal whitespace-nowrap border-b sticky top-0 z-[1]",style:{color:"var(--color-text-muted)",borderColor:"var(--color-border)",background:"var(--color-surface)",width:"2.5rem",opacity:.5},children:"#"}),t.map(e=>{let t=null==a?void 0:a.find(t=>t.name===e),r=t?nO(t.type):null;return(0,n.jsx)("th",{className:"text-left px-3 py-2 font-medium whitespace-nowrap border-b cursor-pointer select-none sticky top-0 z-[1]",style:{color:"var(--color-text-muted)",borderColor:"var(--color-border)",background:"var(--color-surface)"},onClick:()=>l(e),children:(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[e,r&&(0,n.jsx)("span",{className:"text-[9px] px-1 rounded",style:{color:r.color,opacity:.6},children:r.label}),(0,n.jsx)(n_,{active:(null==o?void 0:o.column)===e,direction:(null==o?void 0:o.column)===e?o.direction:"asc"})]})},e)})]})}),(0,n.jsx)("tbody",{children:r.map((e,r)=>(0,n.jsxs)("tr",{className:"transition-colors duration-75 group",style:{background:r%2==0?"transparent":"var(--color-surface)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background=r%2==0?"transparent":"var(--color-surface)"},children:[(0,n.jsx)("td",{className:"text-right px-2 py-1.5 border-b tabular-nums",style:{color:"var(--color-text-muted)",borderColor:"var(--color-border)",opacity:.4},children:r+1}),t.map(t=>(0,n.jsx)("td",{className:"px-3 py-1.5 border-b whitespace-nowrap",style:{borderColor:"var(--color-border)",color:"var(--color-text)"},children:(0,n.jsx)(nq,{value:e[t]})},t))]},r))})]})}function nq(e){let{value:t}=e;if(null==t)return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.4,fontStyle:"italic"},children:"null"});if("boolean"==typeof t)return(0,n.jsx)("span",{style:{color:t?"#22c55e":"#f87171"},children:t?"true":"false"});if("number"==typeof t)return(0,n.jsx)("span",{className:"tabular-nums",children:t});let r=nz(t);return r.length>120?(0,n.jsxs)("span",{title:r,className:"cursor-help",children:[r.slice(0,120),(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:"..."})]}):(0,n.jsx)("span",{children:r})}var nG=r(69176),n$=r(87131),nZ=r(22856),nY=r(3087),nQ=r(86233),nX=r(79919),n0=r(34872),n1=r(8466),n2=r(83879),n4=r(14273),n5=r(54602),n6=r(95107),n3=r(95573),n8=r(75643),n7=r(97199),n9=r(52454),oe=r(47697),ot=r(45679),or=r(47325),on=r(68996),oo=r(77704);function ol(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return"docx"===n||"doc"===n}function oa(e){var t;return(null==(t=e.split(".").pop())?void 0:t.toLowerCase())==="txt"}function os(e){return e.trim()?e.split("\n").map(e=>"<p>".concat(e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")||"<br>","</p>")).join(""):"<p></p>"}function oi(e){var t,l,a,s,i,c;let{mode:d,initialHtml:u,filePath:x,onSave:h,compact:p}=e,[m,f]=(0,o.useState)(!1),[v,g]=(0,o.useState)("idle"),[y,b]=(0,o.useState)(!1),j=(0,o.useRef)(null),k=(0,o.useRef)(null),w=null!=(s=x.split("/").pop())?s:x,N="txt"===d,C=(0,nG.hG)({extensions:[nZ.A.configure({codeBlock:{HTMLAttributes:{class:"code-block"}}}),n3.A,ot.A,or.A,n7.xJ,n9.A,oe.Ay.configure({multicolor:!0}),n8.A.configure({types:["heading","paragraph"]}),nY.Ay.configure({inline:!1,allowBase64:!0,HTMLAttributes:{class:"editor-image"}}),nQ.Ay.configure({openOnClick:!1,autolink:!0,HTMLAttributes:{class:"editor-link",rel:"noopener"}}),nX.XI.configure({resizable:!1}),n0.A,n1.A,n2.h,n4.A,n5.A.configure({nested:!0}),n6.A.configure({placeholder:N?"Start typing...":"Start writing your document..."}),on.A],content:u,immediatelyRender:!1,onUpdate:()=>{b(!0),g("idle")}}),S=(0,o.useCallback)(async e=>{let t=new FormData;t.append("file",e);try{let e=await fetch("/api/workspace/upload",{method:"POST",body:t});if(!e.ok)return null;let r=await e.json();return"/api/workspace/assets/".concat(r.path.replace(/^assets\//,""))}catch(e){return null}},[]),M=(0,o.useCallback)(async e=>{if(C)for(let t of e){let e=await S(t);e&&C.chain().focus().setImage({src:e,alt:t.name}).run()}},[C,S]);(0,o.useEffect)(()=>{if(!C)return;let e=C.view.dom,t=e=>{var t,r;if(!(null==(r=e.dataTransfer)||null==(t=r.files)?void 0:t.length))return;let n=Array.from(e.dataTransfer.files).filter(e=>e.type.startsWith("image/"));0!==n.length&&(e.preventDefault(),e.stopPropagation(),M(n))},r=e=>{var t,r;(null==(r=e.dataTransfer)||null==(t=r.types)?void 0:t.includes("Files"))&&e.preventDefault()},n=e=>{if(!e.clipboardData)return;let t=Array.from(e.clipboardData.files).filter(e=>e.type.startsWith("image/"));t.length>0&&(e.preventDefault(),e.stopPropagation(),M(t))};return e.addEventListener("drop",t),e.addEventListener("dragover",r),e.addEventListener("paste",n),()=>{e.removeEventListener("drop",t),e.removeEventListener("dragover",r),e.removeEventListener("paste",n)}},[C,M]);let L=(0,o.useCallback)(async()=>{if(C&&!m){f(!0),g("idle");try{if(N){let e=C.getText();if(!(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:x,content:e})})).ok)throw Error("Save failed")}else{let e=C.getHTML(),{default:t}=await Promise.all([r.e(515),r.e(8732),r.e(5360),r.e(2457),r.e(4062)]).then(r.bind(r,77373)),n=await t(e,void 0,{table:{row:{cantSplit:!0}},footer:!0,pageNumber:!0}),o=new FormData;if(o.append("file",n),o.append("path",x),!(await fetch("/api/workspace/write-binary",{method:"POST",body:o})).ok)throw Error("Save failed")}g("saved"),b(!1),null==h||h(),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>g("idle"),2e3)}catch(e){g("error")}finally{f(!1)}}},[C,x,m,N,h]);if((0,o.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),L())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[L]),!C)return(0,n.jsxs)("div",{className:"animate-pulse space-y-3 py-4 px-6",children:[(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"80%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"60%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"70%"}})]});let T=null!=(i=null==(t=C.storage.characterCount)?void 0:t.words())?i:0,D=null!=(c=null==(l=C.storage.characterCount)?void 0:l.characters())?c:0;return(0,n.jsxs)("div",{className:"rich-doc-editor ".concat(p?"rich-doc-editor--compact":""),children:[(0,n.jsxs)("div",{className:"rich-doc-topbar",children:[(0,n.jsxs)("div",{className:"rich-doc-topbar-left",children:[(0,n.jsx)(oR,{mode:d}),(0,n.jsx)("span",{className:"rich-doc-filename",children:w}),y&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-unsaved",children:"Unsaved changes"}),"saved"===v&&!y&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-saved",children:"Saved"}),"error"===v&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-error",children:"Save failed"})]}),(0,n.jsxs)("div",{className:"rich-doc-topbar-right",children:[(0,n.jsxs)("span",{className:"editor-save-hint",children:["undefined"!=typeof navigator&&(null==(a=navigator.platform)?void 0:a.includes("Mac"))?"⌘":"Ctrl","+S"]}),(0,n.jsx)("button",{type:"button",onClick:()=>void L(),disabled:m||!y,className:"editor-save-button",children:m?"Saving...":"Save"})]})]}),!N&&(0,n.jsx)(oc,{editor:C,onUploadImages:M,imageInputRef:k}),N&&!p&&(0,n.jsxs)("div",{className:"editor-toolbar rich-doc-toolbar-minimal",children:[(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:!1,onClick:()=>C.chain().focus().undo().run(),title:"Undo",disabled:!C.can().undo(),children:(0,n.jsx)(op,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>C.chain().focus().redo().run(),title:"Redo",disabled:!C.can().redo(),children:(0,n.jsx)(om,{})})]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("span",{className:"rich-doc-txt-hint",children:"Plain text — formatting not preserved on save"})]}),!N&&(0,n.jsx)(n$.m,{editor:C,children:(0,n.jsxs)("div",{className:"bubble-menu",children:[(0,n.jsx)(oo.zM,{active:C.isActive("bold"),onClick:()=>C.chain().focus().toggleBold().run(),title:"Bold",children:(0,n.jsx)("strong",{children:"B"})}),(0,n.jsx)(oo.zM,{active:C.isActive("italic"),onClick:()=>C.chain().focus().toggleItalic().run(),title:"Italic",children:(0,n.jsx)("em",{children:"I"})}),(0,n.jsx)(oo.zM,{active:C.isActive("underline"),onClick:()=>C.chain().focus().toggleUnderline().run(),title:"Underline",children:(0,n.jsx)("span",{style:{textDecoration:"underline"},children:"U"})}),(0,n.jsx)(oo.zM,{active:C.isActive("strike"),onClick:()=>C.chain().focus().toggleStrike().run(),title:"Strikethrough",children:(0,n.jsx)("s",{children:"S"})}),(0,n.jsx)(oo.zM,{active:C.isActive("code"),onClick:()=>C.chain().focus().toggleCode().run(),title:"Inline code",children:"<>"}),(0,n.jsx)(oo.zM,{active:C.isActive("link"),onClick:()=>{if(C.isActive("link"))C.chain().focus().unsetLink().run();else{let e=window.prompt("URL:");e&&C.chain().focus().setLink({href:e}).run()}},title:"Link",children:(0,n.jsx)(oS,{size:14})})]})}),(0,n.jsx)("div",{className:"rich-doc-scroll",children:(0,n.jsx)("div",{className:"rich-doc-page ".concat(N?"rich-doc-page--txt":""),children:(0,n.jsx)(nG.$Z,{editor:C})})}),!p&&(0,n.jsxs)("div",{className:"rich-doc-statusbar",children:[(0,n.jsxs)("span",{children:[T.toLocaleString()," word",1!==T?"s":""]}),(0,n.jsx)("span",{className:"rich-doc-statusbar-sep"}),(0,n.jsxs)("span",{children:[D.toLocaleString()," character",1!==D?"s":""]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("span",{className:"rich-doc-statusbar-mode",children:"docx"===d?"DOCX":"TXT"})]}),(0,n.jsx)("input",{ref:k,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{var t;let r=Array.from(null!=(t=e.target.files)?t:[]);r.length>0&&M(r),e.target.value=""}})]})}function oc(e){var t;let{editor:r,onUploadImages:l,imageInputRef:a}=e,[s,i]=(0,o.useState)(!1),[c,d]=(0,o.useState)(!1),u=(0,o.useRef)(null),x=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&i(!1),x.current&&!x.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.jsxs)("div",{className:"editor-toolbar rich-doc-toolbar",children:[(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:!1,onClick:()=>r.chain().focus().undo().run(),title:"Undo",disabled:!r.can().undo(),children:(0,n.jsx)(op,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>r.chain().focus().redo().run(),title:"Redo",disabled:!r.can().redo(),children:(0,n.jsx)(om,{})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsx)(oo.$Q,{children:(0,n.jsx)(ou,{editor:r})}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive("bold"),onClick:()=>r.chain().focus().toggleBold().run(),title:"Bold (Cmd+B)",children:(0,n.jsx)("strong",{children:"B"})}),(0,n.jsx)(oo.IB,{active:r.isActive("italic"),onClick:()=>r.chain().focus().toggleItalic().run(),title:"Italic (Cmd+I)",children:(0,n.jsx)("em",{children:"I"})}),(0,n.jsx)(oo.IB,{active:r.isActive("underline"),onClick:()=>r.chain().focus().toggleUnderline().run(),title:"Underline (Cmd+U)",children:(0,n.jsx)("span",{style:{textDecoration:"underline"},children:"U"})}),(0,n.jsx)(oo.IB,{active:r.isActive("strike"),onClick:()=>r.chain().focus().toggleStrike().run(),title:"Strikethrough",children:(0,n.jsx)("s",{children:"S"})}),(0,n.jsx)(oo.IB,{active:r.isActive("superscript"),onClick:()=>r.chain().focus().toggleSuperscript().run(),title:"Superscript",children:(0,n.jsxs)("span",{children:["X",(0,n.jsx)("sup",{style:{fontSize:"0.6em"},children:"2"})]})}),(0,n.jsx)(oo.IB,{active:r.isActive("subscript"),onClick:()=>r.chain().focus().toggleSubscript().run(),title:"Subscript",children:(0,n.jsxs)("span",{children:["X",(0,n.jsx)("sub",{style:{fontSize:"0.6em"},children:"2"})]})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsxs)("div",{className:"relative",ref:u,children:[(0,n.jsx)(oo.IB,{active:s,onClick:()=>{i(!s),d(!1)},title:"Text color",children:(0,n.jsx)(oD,{color:null!=(t=r.getAttributes("textStyle").color)?t:"currentColor"})}),s&&(0,n.jsx)(oh,{onSelect:e=>{e?r.chain().focus().setColor(e).run():r.chain().focus().unsetColor().run(),i(!1)}})]}),(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsx)(oo.IB,{active:c,onClick:()=>{d(!c),i(!1)},title:"Highlight color",children:(0,n.jsx)(oE,{})}),c&&(0,n.jsx)(oh,{onSelect:e=>{e?r.chain().focus().toggleHighlight({color:e}).run():r.chain().focus().unsetHighlight().run(),d(!1)}})]})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive({textAlign:"left"}),onClick:()=>r.chain().focus().setTextAlign("left").run(),title:"Align left",children:(0,n.jsx)(of,{})}),(0,n.jsx)(oo.IB,{active:r.isActive({textAlign:"center"}),onClick:()=>r.chain().focus().setTextAlign("center").run(),title:"Align center",children:(0,n.jsx)(ov,{})}),(0,n.jsx)(oo.IB,{active:r.isActive({textAlign:"right"}),onClick:()=>r.chain().focus().setTextAlign("right").run(),title:"Align right",children:(0,n.jsx)(og,{})}),(0,n.jsx)(oo.IB,{active:r.isActive({textAlign:"justify"}),onClick:()=>r.chain().focus().setTextAlign("justify").run(),title:"Justify",children:(0,n.jsx)(oy,{})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive("bulletList"),onClick:()=>r.chain().focus().toggleBulletList().run(),title:"Bullet list",children:(0,n.jsx)(ob,{})}),(0,n.jsx)(oo.IB,{active:r.isActive("orderedList"),onClick:()=>r.chain().focus().toggleOrderedList().run(),title:"Ordered list",children:(0,n.jsx)(oj,{})}),(0,n.jsx)(oo.IB,{active:r.isActive("taskList"),onClick:()=>r.chain().focus().toggleTaskList().run(),title:"Task list",children:(0,n.jsx)(ok,{})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive("blockquote"),onClick:()=>r.chain().focus().toggleBlockquote().run(),title:"Blockquote",children:(0,n.jsx)(ow,{})}),(0,n.jsx)(oo.IB,{active:r.isActive("codeBlock"),onClick:()=>r.chain().focus().toggleCodeBlock().run(),title:"Code block",children:(0,n.jsx)(oN,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>r.chain().focus().setHorizontalRule().run(),title:"Horizontal rule",children:(0,n.jsx)(oC,{})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive("link"),onClick:()=>{if(r.isActive("link"))r.chain().focus().unsetLink().run();else{let e=window.prompt("Link URL:");e&&r.chain().focus().setLink({href:e}).run()}},title:"Insert link",children:(0,n.jsx)(oS,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>{if(l){var e;null==(e=a.current)||e.click()}else{let e=window.prompt("Image URL:");e&&r.chain().focus().setImage({src:e}).run()}},title:"Insert image",children:(0,n.jsx)(oM,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>r.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),title:"Insert table",children:(0,n.jsx)(oL,{})})]})]})}let od=[{label:"Normal text",level:0},{label:"Heading 1",level:1},{label:"Heading 2",level:2},{label:"Heading 3",level:3},{label:"Heading 4",level:4},{label:"Heading 5",level:5},{label:"Heading 6",level:6}];function ou(e){var t;let{editor:r}=e,[l,a]=(0,o.useState)(!1),s=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=e=>{s.current&&!s.current.contains(e.target)&&a(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let i=null!=(t=od.find(e=>e.level>0&&r.isActive("heading",{level:e.level})))?t:od[0];return(0,n.jsxs)("div",{className:"relative",ref:s,children:[(0,n.jsxs)("button",{type:"button",className:"rich-doc-style-dropdown",onClick:()=>a(!l),title:"Paragraph style",children:[(0,n.jsx)("span",{children:i.label}),(0,n.jsx)(oT,{})]}),l&&(0,n.jsx)("div",{className:"rich-doc-style-menu",children:od.map(e=>(0,n.jsx)("button",{type:"button",className:"rich-doc-style-option ".concat(e.level===i.level?"rich-doc-style-option--active":""),onClick:()=>{0===e.level?r.chain().focus().setParagraph().run():r.chain().focus().toggleHeading({level:e.level}).run(),a(!1)},children:(0,n.jsx)("span",{style:{fontSize:0===e.level?void 0:"".concat(Math.max(.75,1.4-.1*e.level),"rem"),fontWeight:e.level>0?600:400},children:e.label})},e.level))})]})}let ox=[null,"#000000","#434343","#666666","#999999","#b7b7b7","#cccccc","#d9d9d9","#efefef","#ffffff","#980000","#ff0000","#ff9900","#ffff00","#00ff00","#00ffff","#4a86e8","#0000ff","#9900ff","#ff00ff","#e6b8af","#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#c9daf8","#cfe2f3","#d9d2e9","#ead1dc","#dd7e6b","#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#a4c2f4","#9fc5e8","#b4a7d6","#d5a6bd","#cc4125","#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6d9eeb","#6fa8dc","#8e7cc3","#c27ba0"];function oh(e){let{onSelect:t}=e;return(0,n.jsx)("div",{className:"rich-doc-color-palette",children:ox.map(e=>(0,n.jsx)("button",{type:"button",className:"rich-doc-color-swatch",style:{background:null!=e?e:"transparent",border:e?"1px solid var(--color-border)":"2px dashed var(--color-border)"},onClick:()=>t(e),title:null!=e?e:"Remove color",children:!e&&(0,n.jsx)("span",{style:{fontSize:"10px",color:"var(--color-text-muted)"},children:"\xd7"})},null!=e?e:"none"))})}function op(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 7v6h6"}),(0,n.jsx)("path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"})]})}function om(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 7v6h-6"}),(0,n.jsx)("path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"})]})}function of(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"17",x2:"3",y1:"10",y2:"10"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"14",y2:"14"}),(0,n.jsx)("line",{x1:"17",x2:"3",y1:"18",y2:"18"})]})}function ov(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",x2:"6",y1:"10",y2:"10"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"14",y2:"14"}),(0,n.jsx)("line",{x1:"18",x2:"6",y1:"18",y2:"18"})]})}function og(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"21",x2:"7",y1:"10",y2:"10"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"14",y2:"14"}),(0,n.jsx)("line",{x1:"21",x2:"7",y1:"18",y2:"18"})]})}function oy(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"21",x2:"3",y1:"10",y2:"10"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"14",y2:"14"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"18",y2:"18"})]})}function ob(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"8",x2:"21",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"8",x2:"21",y1:"12",y2:"12"}),(0,n.jsx)("line",{x1:"8",x2:"21",y1:"18",y2:"18"}),(0,n.jsx)("line",{x1:"3",x2:"3.01",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"3",x2:"3.01",y1:"12",y2:"12"}),(0,n.jsx)("line",{x1:"3",x2:"3.01",y1:"18",y2:"18"})]})}function oj(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"10",x2:"21",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"10",x2:"21",y1:"12",y2:"12"}),(0,n.jsx)("line",{x1:"10",x2:"21",y1:"18",y2:"18"}),(0,n.jsx)("path",{d:"M4 6h1v4"}),(0,n.jsx)("path",{d:"M4 10h2"}),(0,n.jsx)("path",{d:"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"})]})}function ok(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"5",width:"6",height:"6",rx:"1"}),(0,n.jsx)("path",{d:"m3 17 2 2 4-4"}),(0,n.jsx)("line",{x1:"13",x2:"21",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"13",x2:"21",y1:"18",y2:"18"})]})}function ow(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V21z"}),(0,n.jsx)("path",{d:"M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3z"})]})}function oN(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]})}function oC(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("line",{x1:"2",x2:"22",y1:"12",y2:"12"})})}function oS(e){let{size:t=14}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),(0,n.jsx)("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}function oM(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]})}function oL(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]})}function oT(){return(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:"m6 9 6 6 6-6"})})}function oD(e){let{color:t}=e;return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M4 20h16",stroke:t,strokeWidth:"3"}),(0,n.jsx)("path",{d:"m8.5 3 3.5 11 3.5-11"})]})}function oE(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m9 11-6 6v3h9l3-3"}),(0,n.jsx)("path",{d:"m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"})]})}function oR(e){let{mode:t}=e;return"txt"===t?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("line",{x1:"8",x2:"16",y1:"13",y2:"13"}),(0,n.jsx)("line",{x1:"8",x2:"16",y1:"17",y2:"17"}),(0,n.jsx)("line",{x1:"8",x2:"10",y1:"9",y2:"9"})]}):(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#2b579a",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("line",{x1:"8",x2:"16",y1:"13",y2:"13"}),(0,n.jsx)("line",{x1:"8",x2:"16",y1:"17",y2:"17"}),(0,n.jsx)("line",{x1:"8",x2:"10",y1:"9",y2:"9"})]})}function oW(e){let{path:t,onNavigate:r}=e,o=t.startsWith("/"),l=t.split("/").filter(Boolean);return(0,n.jsxs)("nav",{className:"flex items-center gap-1 text-xs md:text-sm py-2 overflow-x-auto min-w-0",children:[(0,n.jsx)("button",{type:"button",onClick:()=>r(""),className:"px-1.5 py-0.5 rounded transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--color-text)",e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--color-text-muted)",e.currentTarget.style.background="transparent"},children:"All Chats"}),l.map((e,t)=>{let a=(o?"/":"")+l.slice(0,t+1).join("/"),s=t===l.length-1;return(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",opacity:.4},children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})}),s?(0,n.jsx)("span",{className:"px-1.5 py-0.5",style:{color:"var(--color-text)"},children:e.replace(/\.md$/,"")}):(0,n.jsx)("button",{type:"button",onClick:()=>r(a),className:"px-1.5 py-0.5 rounded transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--color-text)",e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--color-text-muted)",e.currentTarget.style.background="transparent"},children:e})]},a)})]})}var oI=r(77223),oB=r(90461),oF=r(13170),oA=r(33668),oP=r(86998),o_=r(2183),oz=r(66862),oO=r(7589);function oU(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return(0,oO.QP)((0,oz.$)(t))}function oH(e){let{...t}=e;return(0,n.jsx)(oI.i,{"data-slot":"dropdown-menu",...t})}function oV(e){let{className:t,...r}=e;return(0,n.jsx)(oB.c,{"data-slot":"dropdown-menu-trigger",className:oU("cursor-pointer outline-none ring-0 border-none",t),...r})}function oJ(e){let{align:t="start",alignOffset:r=0,side:o="bottom",sideOffset:l=4,className:a,...s}=e;return(0,n.jsx)(oF.g,{children:(0,n.jsx)(oA.y,{className:"isolate z-[100] outline-none",align:t,alignOffset:r,side:o,sideOffset:l,children:(0,n.jsx)(oP._,{"data-slot":"dropdown-menu-content",className:oU("bg-neutral-100/[0.67] border border-white backdrop-blur-md text-[var(--color-text)] z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] overflow-x-hidden overflow-y-auto rounded-3xl p-1 shadow-[0_0_25px_0_rgba(0,0,0,0.16)] outline-none","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...s})})})}function oK(e){let{className:t,inset:r,variant:o="default",onSelect:l,onClick:a,...s}=e;return(0,n.jsx)(o_.D,{"data-slot":"dropdown-menu-item","data-inset":r,"data-variant":o,className:oU("bg-transparent hover:bg-neutral-400/15 text-sm transition-all relative flex cursor-pointer items-center gap-2 rounded-full px-2 py-1.5 outline-none ring-0 border-none select-none","data-[variant=destructive]:text-[var(--color-error)] data-[variant=destructive]:hover:bg-[var(--color-error)]/10 data-[variant=destructive]:hover:text-[var(--color-error)]",r&&"pl-8","[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","data-disabled:pointer-events-none data-disabled:opacity-50",t),onClick:e=>{null==a||a(e),null==l||l()},...s})}function oq(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 12h14"}),(0,n.jsx)("path",{d:"M12 5v14"})]})}function oG(){return(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M16 3h5v5"}),(0,n.jsx)("path",{d:"m21 3-7 7"}),(0,n.jsx)("path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6"})]})}function o$(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function oZ(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1"})]})}function oY(e){let{sessions:t,activeSessionId:r,activeSessionTitle:l,streamingSessionIds:a,subagents:s,activeSubagentKey:i,onSelectSession:c,onNewSession:d,onSelectSubagent:u,onDeleteSession:x,onRenameSession:h,onCollapse:p,mobile:m,onClose:f,width:v,loading:g=!1}=e,[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(null),[w,N]=(0,o.useState)(""),C=(0,o.useCallback)(e=>{c(e),null==f||f()},[c,f]),S=(0,o.useCallback)(e=>{null==u||u(e),null==f||f()},[u,f]),M=(0,o.useCallback)(e=>{null==x||x(e)},[x]),L=(0,o.useCallback)((e,t)=>{k(e),N(t||"")},[]),T=(0,o.useCallback)(()=>{j&&w.trim()&&(null==h||h(j,w.trim())),k(null),N("")},[j,w,h]),D=(0,o.useMemo)(()=>{let e=new Map;if(!s)return e;for(let t of s){let r=e.get(t.parentSessionId);r||(r=[],e.set(t.parentSessionId,r)),r.push(t)}return e},[s]),E=function(e){let t=new Date,r=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),n=r-864e5,o=r-6048e5,l=r-2592e6,a=[],s=[],i=[],c=[],d=[];for(let t of e){let e=t.updatedAt;e>=r?a.push(t):e>=n?s.push(t):e>=o?i.push(t):e>=l?c.push(t):d.push(t)}let u=[];return a.length>0&&u.push({label:"Today",sessions:a}),s.length>0&&u.push({label:"Yesterday",sessions:s}),i.length>0&&u.push({label:"This Week",sessions:i}),c.length>0&&u.push({label:"This Month",sessions:c}),d.length>0&&u.push({label:"Older",sessions:d}),u}((0,o.useMemo)(()=>t.filter(e=>!e.id.includes(":subagent:")),[t])),R=m?"280px":null!=v?v:260,W=(0,n.jsx)("aside",{className:"flex flex-col h-full shrink-0 ".concat(m?"drawer-right":"border-l"),style:{width:"number"==typeof R?"".concat(R,"px"):R,minWidth:"number"==typeof R?"".concat(R,"px"):R,borderColor:"var(--color-border)",background:"var(--color-sidebar-bg)"},children:(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[(0,n.jsx)("div",{className:"absolute inset-0 overflow-y-auto",style:{paddingTop:40},children:g&&0===t.length?(0,n.jsxs)("div",{className:"px-4 py-8 flex flex-col items-center justify-center min-h-[120px]",children:[(0,n.jsx)(G.V,{name:"braille",className:"text-xl mb-2",style:{color:"var(--color-text-muted)"}}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading…"})]}):0===t.length?(0,n.jsxs)("div",{className:"px-4 py-8 text-center",children:[(0,n.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl flex items-center justify-center mb-3",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:(0,n.jsx)(o$,{})}),(0,n.jsxs)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["No conversations yet.",(0,n.jsx)("br",{}),"Start a new chat to begin."]})]}):(0,n.jsx)("div",{className:"px-2 py-1",children:E.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-2 pt-3 pb-1 text-[10px] font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:e.label}),e.sessions.map(e=>{var t;let o=e.id===r&&!i,l=e.id===y,s=null!=(t=null==a?void 0:a.has(e.id))&&t,c=D.get(e.id);return(0,n.jsxs)("div",{className:"group relative",onMouseEnter:()=>b(e.id),onMouseLeave:()=>b(null),children:[(0,n.jsxs)("div",{className:"flex items-stretch w-full rounded-lg",style:{background:o?"var(--color-chat-sidebar-active-bg)":l?"var(--color-surface-hover)":"transparent"},children:[j===e.id?(0,n.jsx)("form",{className:"flex-1 min-w-0 px-2 py-1.5",onSubmit:e=>{e.preventDefault(),T()},children:(0,n.jsx)("input",{type:"text",value:w,onChange:e=>N(e.target.value),onBlur:T,onKeyDown:e=>{"Escape"===e.key&&(k(null),N(""))},autoFocus:!0,className:"w-full text-xs font-medium px-1 py-0.5 rounded outline-none border",style:{color:"var(--color-text)",background:"var(--color-surface)",borderColor:"var(--color-border)"}})}):(0,n.jsxs)("button",{type:"button",onClick:()=>C(e.id),className:"flex-1 min-w-0 text-left px-2 py-2 rounded-l-lg transition-colors cursor-pointer",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[s&&(0,n.jsx)(G.V,{name:"braille",className:"text-[10px] flex-shrink-0",style:{color:"var(--color-chat-sidebar-muted)"}}),(0,n.jsx)("div",{className:"text-xs font-medium truncate",style:{color:o?"var(--color-chat-sidebar-active-text)":"var(--color-text)"},children:e.title||"Untitled chat"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",style:{paddingLeft:s?"calc(0.375rem + 6px)":void 0},children:[(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:function(e){let t=Math.floor((Date.now()-e)/1e3);if(t<60)return"just now";let r=Math.floor(t/60);if(r<60)return"".concat(r,"m ago");let n=Math.floor(r/60);if(n<24)return"".concat(n,"h ago");let o=Math.floor(n/24);if(o<30)return"".concat(o,"d ago");let l=Math.floor(o/30);return l<12?"".concat(l,"mo ago"):"".concat(Math.floor(l/12),"y ago")}(e.updatedAt)}),e.messageCount>0&&(0,n.jsxs)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:[e.messageCount," msg",1!==e.messageCount?"s":""]})]})]}),x&&(0,n.jsx)("div",{className:"shrink-0 flex items-center pr-1 transition-opacity ".concat(l?"opacity-100":"opacity-0"),children:(0,n.jsxs)(oH,{children:[(0,n.jsx)(oV,{onClick:e=>e.stopPropagation(),className:"flex items-center justify-center w-6 h-6 rounded-md",style:{color:"var(--color-text-muted)"},title:"More options","aria-label":"More options",children:(0,n.jsx)(oZ,{})}),(0,n.jsxs)(oJ,{align:"end",side:"bottom",children:[(0,n.jsxs)(oK,{onSelect:()=>L(e.id,e.title),children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"})}),"Rename"]}),(0,n.jsxs)(oK,{variant:"destructive",onSelect:()=>M(e.id),children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]})]})]})})]}),c&&c.length>0&&(0,n.jsx)("div",{className:"ml-4 border-l",style:{borderColor:"var(--color-border)"},children:c.map(e=>{let t=i===e.childSessionKey,r="running"===e.status,o=e.label||e.task,l=o.length>40?o.slice(0,40)+"...":o;return(0,n.jsx)("button",{type:"button",onClick:()=>S(e.childSessionKey),className:"w-full text-left pl-3 pr-2 py-1.5 rounded-r-lg transition-colors cursor-pointer",style:{background:t?"var(--color-chat-sidebar-active-bg)":"transparent"},children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[r&&(0,n.jsx)(G.V,{name:"braille",className:"text-[9px] flex-shrink-0",style:{color:"var(--color-chat-sidebar-muted)"}}),(0,n.jsx)(oG,{}),(0,n.jsx)("span",{className:"text-[11px] truncate",style:{color:t?"var(--color-chat-sidebar-active-text)":"var(--color-text-muted)"},children:l})]})},e.childSessionKey)})})]},e.id)})]},e.label))})}),(0,n.jsxs)("div",{className:"absolute top-0 left-0 right-0 z-10 flex items-center justify-between border-b px-4 py-2 backdrop-blur-md",style:{height:40,borderColor:"var(--color-border)",background:"color-mix(in srgb, var(--color-sidebar-bg) 80%, transparent)"},children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1 flex items-center gap-1.5",children:[p&&(0,n.jsx)("button",{type:"button",onClick:p,className:"p-1 rounded-md shrink-0 transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Hide chat sidebar (⌘⇧B)",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M15 3v18"})]})}),(0,n.jsx)("span",{className:"text-xs font-medium truncate block",style:{color:"var(--color-text)"},children:"Chats"})]}),(0,n.jsxs)("button",{type:"button",onClick:d,className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium transition-colors cursor-pointer shrink-0 ml-1.5",style:{color:"var(--color-chat-sidebar-active-text)",background:"var(--color-chat-sidebar-active-bg)"},title:"New chat",children:[(0,n.jsx)(oq,{}),"New"]})]})]})});return m?(0,n.jsx)("div",{className:"drawer-backdrop",onClick:()=>void(null==f||f()),children:(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),className:"fixed inset-y-0 right-0 z-50",children:W})}):W}function oQ(e){let{workspaceExists:t,expectedPath:r}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-6 px-8",children:[(0,n.jsx)("div",{className:"w-20 h-20 rounded-2xl flex items-center justify-center",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},children:(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",opacity:.5},children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"})]})}),(0,n.jsxs)("div",{className:"text-center max-w-md",children:[(0,n.jsx)("h2",{className:"font-instrument text-2xl tracking-tight mb-2",style:{color:"var(--color-text)"},children:t?"Workspace is empty":"No workspace found"}),(0,n.jsx)("p",{className:"text-sm leading-relaxed",style:{color:"var(--color-text-muted)"},children:t?(0,n.jsx)(n.Fragment,{children:"The workspace exists but has no knowledge tree yet. Ask the CRM agent to create objects and documents to populate it."}):(0,n.jsx)(n.Fragment,{children:"The workspace directory was not found. Run the denchclaw bootstrap flow or start a conversation and the agent will set it up automatically in the managed profile."})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 rounded-xl text-sm",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",color:"var(--color-text-muted)",boxShadow:"var(--shadow-sm)"},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-accent)",flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("path",{d:"M12 16v-4"}),(0,n.jsx)("path",{d:"M12 8h.01"})]}),(0,n.jsxs)("span",{children:["Expected location:"," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded-md text-xs",style:{background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:r?r.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Za-z]:[/\\]Users[/\\][^/\\]+/,"~"):"~/.openclaw-dench/workspace-<name>"})]})]}),(0,n.jsxs)("a",{href:"/",className:"flex items-center gap-2 text-sm mt-2",style:{color:"var(--color-accent)"},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]}),"Back to Home"]})]})}var oX=r(40077);function o0(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function o1(){return(0,n.jsxs)("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:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}function o2(e){var t,r;let{filter:o,value:l,onChange:a}=e,s=(null==l?void 0:l.type)==="dateRange"?l:{type:"dateRange"};return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] whitespace-nowrap",style:{color:"var(--color-text-muted)"},children:o.label}),(0,n.jsx)("input",{type:"date",value:null!=(t=s.from)?t:"",onChange:e=>a({...s,from:e.target.value||void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",colorScheme:"dark"}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"to"}),(0,n.jsx)("input",{type:"date",value:null!=(r=s.to)?r:"",onChange:e=>a({...s,to:e.target.value||void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",colorScheme:"dark"}})]})}function o4(e){let{filter:t,value:r,onChange:o,options:l}=e,a=(null==r?void 0:r.type)==="select"?r.value:void 0;return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] whitespace-nowrap",style:{color:"var(--color-text-muted)"},children:t.label}),(0,n.jsxs)("select",{value:null!=a?a:"",onChange:e=>o({type:"select",value:e.target.value||void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none cursor-pointer",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",minWidth:100},children:[(0,n.jsx)("option",{value:"",children:"All"}),l.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})]})}function o5(e){var t;let{filter:r,value:o,onChange:l,options:a}=e,s=(null==o?void 0:o.type)==="multiSelect"&&null!=(t=o.values)?t:[];return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] whitespace-nowrap",style:{color:"var(--color-text-muted)"},children:r.label}),(0,n.jsx)("div",{className:"flex flex-wrap gap-1",children:a.map(e=>{let t=s.includes(e);return(0,n.jsx)("button",{type:"button",onClick:()=>(e=>{let t=s.includes(e)?s.filter(t=>t!==e):[...s,e];l({type:"multiSelect",values:t.length>0?t:void 0})})(e),className:"px-2 py-0.5 rounded-full text-[10px] transition-colors cursor-pointer",style:{background:t?"var(--color-accent-light)":"var(--color-surface)",border:"1px solid ".concat(t?"var(--color-accent)":"var(--color-border)"),color:t?"var(--color-accent)":"var(--color-text-muted)"},children:e},e)})})]})}function o6(e){var t,r;let{filter:o,value:l,onChange:a}=e,s=(null==l?void 0:l.type)==="number"?l:{type:"number"};return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] whitespace-nowrap",style:{color:"var(--color-text-muted)"},children:o.label}),(0,n.jsx)("input",{type:"number",placeholder:"Min",value:null!=(t=s.min)?t:"",onChange:e=>a({...s,min:e.target.value?Number(e.target.value):void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none w-20",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"to"}),(0,n.jsx)("input",{type:"number",placeholder:"Max",value:null!=(r=s.max)?r:"",onChange:e=>a({...s,max:e.target.value?Number(e.target.value):void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none w-20",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}})]})}function o3(e){let{filters:t,value:r,onChange:l}=e,[a,s]=(0,o.useState)({}),i=(0,o.useCallback)(async()=>{let e=t.filter(e=>("select"===e.type||"multiSelect"===e.type)&&e.sql);if(0===e.length)return;let r={};await Promise.all(e.map(async e=>{try{var t;let n=await fetch("/api/workspace/reports/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:e.sql})});if(!n.ok)return;let o=(null!=(t=(await n.json()).rows)?t:[]).map(e=>{let t=Object.values(e)[0];return null==t?null:"object"==typeof t?JSON.stringify(t):"string"==typeof t?t:String(t)}).filter(e=>null!==e);r[e.id]=o}catch(e){}})),s(r)},[t]);(0,o.useEffect)(()=>{i()},[i]);let c=(0,o.useCallback)((e,t)=>{l({...r,[e]:t})},[r,l]),d=Object.values(r).some(e=>!!e&&("dateRange"===e.type?e.from||e.to:"select"===e.type?e.value:"multiSelect"===e.type?e.values&&e.values.length>0:"number"===e.type&&(void 0!==e.min||void 0!==e.max)));return 0===t.length?null:(0,n.jsxs)("div",{className:"flex items-center gap-4 px-4 py-2.5 border-b flex-wrap",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs font-medium",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(o0,{}),"Filters"]}),t.map(e=>{var t,o;let l=r[e.id];switch(e.type){case"dateRange":return(0,n.jsx)(o2,{filter:e,value:l,onChange:t=>c(e.id,t)},e.id);case"select":return(0,n.jsx)(o4,{filter:e,value:l,onChange:t=>c(e.id,t),options:null!=(t=a[e.id])?t:[]},e.id);case"multiSelect":return(0,n.jsx)(o5,{filter:e,value:l,onChange:t=>c(e.id,t),options:null!=(o=a[e.id])?o:[]},e.id);case"number":return(0,n.jsx)(o6,{filter:e,value:l,onChange:t=>c(e.id,t)},e.id);default:return null}}),d&&(0,n.jsxs)("button",{type:"button",onClick:()=>l({}),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] transition-colors cursor-pointer",style:{color:"var(--color-accent)",background:"var(--color-accent-light)"},children:[(0,n.jsx)(o1,{}),"Clear"]})]})}function o8(e){let{size:t=20}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",x2:"12",y1:"20",y2:"10"}),(0,n.jsx)("line",{x1:"18",x2:"18",y1:"20",y2:"4"}),(0,n.jsx)("line",{x1:"6",x2:"6",y1:"20",y2:"14"})]})}function o7(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"}),(0,n.jsx)("path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"}),(0,n.jsx)("path",{d:"M16 16h5v5"})]})}function o9(e){let{config:t,reportPath:r}=e,[l,a]=(0,o.useState)(null!=t?t:null),[s,i]=(0,o.useState)(!t&&!!r),[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)({}),[h,p]=(0,o.useState)({}),[m,f]=(0,o.useState)(0);(0,o.useEffect)(()=>{if(t)return void a(t);if(!r)return;let e=!1;return i(!0),d(null),fetch("/api/workspace/file?path=".concat(encodeURIComponent(r))).then(async t=>{if(!t.ok)throw Error("Failed to load report: HTTP ".concat(t.status));let r=await t.json();if(!e)try{let e=JSON.parse(r.content);a(e)}catch(e){throw Error("Invalid report JSON")}}).catch(t=>{e||d(t instanceof Error?t.message:"Failed to load report")}).finally(()=>{e||i(!1)}),()=>{e=!0}},[t,r]);let v=(0,o.useCallback)(async()=>{var e;if(!l)return;let t=function(e,t){let r=[];for(let n of t){let t=e[n.id];t&&("dateRange"===t.type&&(t.from||t.to)||"select"===t.type&&t.value||"multiSelect"===t.type&&t.values&&t.values.length>0||"number"===t.type&&(void 0!==t.min||void 0!==t.max))&&r.push({id:n.id,column:n.column,value:t})}return r}(h,null!=(e=l.filters)?e:[]),r={};for(let e of l.panels)r[e.id]={panelId:e.id,rows:[],loading:!0};x(r),await Promise.all(l.panels.map(async e=>{try{let r=await fetch("/api/workspace/reports/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:e.sql,filters:t.length>0?t:void 0})});if(!r.ok){let t=await r.json().catch(()=>({}));x(n=>({...n,[e.id]:{panelId:e.id,rows:[],loading:!1,error:t.error||"HTTP ".concat(r.status)}}));return}let n=await r.json();x(t=>{var r;return{...t,[e.id]:{panelId:e.id,rows:null!=(r=n.rows)?r:[],loading:!1}}})}catch(t){x(r=>({...r,[e.id]:{panelId:e.id,rows:[],loading:!1,error:t instanceof Error?t.message:"Query failed"}}))}}))},[l,h]);(0,o.useEffect)(()=>{v()},[v,m]);let g=(0,o.useMemo)(()=>Object.values(u).reduce((e,t)=>e+t.rows.length,0),[u]);return s?(0,n.jsxs)("div",{className:"flex items-center justify-center h-full gap-3",children:[(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Loading report..."})]}):c?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-4 p-8",children:[(0,n.jsx)(o8,{size:48}),(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Failed to load report"}),(0,n.jsx)("p",{className:"text-xs px-3 py-2 rounded-lg max-w-md text-center",style:{background:"var(--color-surface)",color:"#f87171"},children:c})]}):l?(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsx)("div",{className:"px-6 py-4 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:(0,n.jsxs)("div",{className:"flex items-start justify-between",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 mb-1",children:[(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:(0,n.jsx)(o8,{})}),(0,n.jsx)("h1",{className:"text-xl font-bold",style:{color:"var(--color-text)"},children:l.title})]}),l.description&&(0,n.jsx)("p",{className:"text-sm ml-7",style:{color:"var(--color-text-muted)"},children:l.description})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("span",{className:"text-[10px] px-2 py-1 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[l.panels.length," panel",1!==l.panels.length?"s":""]}),(0,n.jsxs)("span",{className:"text-[10px] px-2 py-1 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[g," rows"]}),(0,n.jsx)("button",{type:"button",onClick:()=>f(e=>e+1),className:"p-1.5 rounded-md transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Refresh data",children:(0,n.jsx)(o7,{})})]})]})}),l.filters&&l.filters.length>0&&(0,n.jsx)(o3,{filters:l.filters,value:h,onChange:p}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-6",children:(0,n.jsx)("div",{className:"grid grid-cols-6 gap-5",children:l.panels.map(e=>(0,n.jsx)(le,{panel:e,data:u[e.id]},e.id))})})]}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No report configuration found"})})}function le(e){var t;let{panel:r,data:o}=e,l=function(e){switch(e){case"full":return"col-span-6";case"third":return"col-span-2";default:return"col-span-3"}}(r.size);return(0,n.jsxs)("div",{className:"".concat(l," rounded-xl overflow-hidden"),style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"px-4 py-3 flex items-center justify-between",children:[(0,n.jsx)("h3",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:r.title}),o&&!o.loading&&!o.error&&(0,n.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{color:"var(--color-text-muted)"},children:[o.rows.length," rows"]})]}),(0,n.jsx)("div",{className:"px-2 pb-3",children:(null==o?void 0:o.loading)?(0,n.jsx)("div",{className:"flex items-center justify-center",style:{height:320},children:(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):(null==o?void 0:o.error)?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2",style:{height:320},children:[(0,n.jsx)("p",{className:"text-xs",style:{color:"#f87171"},children:"Query error"}),(0,n.jsx)("p",{className:"text-[10px] px-2 py-1 rounded max-w-xs text-center",style:{background:"rgba(248, 113, 113, 0.1)",color:"#f87171"},children:o.error})]}):(0,n.jsx)(oX.N,{config:r,data:null!=(t=null==o?void 0:o.rows)?t:[]})})]})}var lt=r(77592),lr=r(70793),ln=r(64698),lo=r(2289),ll=r(34438),la=r(98463),ls=r(10815),li=r(81375),lc=r(18520),ld=r(54121),lu=r(72092),lx=r(11592),lh=r(48297),lp=r(54113),lm=r(39128),lf=r(92909),lv=r(47186),lg=r(50045),ly=r(12586),lb=r(71788),lj=r(10491),lk=r(38033),lw=r(80236),lN=r(80096),lC=r(29341),lS=r(94003),lM=r(12594),lL=r(64049),lT=r(97185);let lD=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","tiff","tif","ico"]),lE=new Set(["mp4","webm","mov","avi","mkv"]),lR=new Set(["pdf"]),lW=new Set(["mp3","wav","ogg","m4a"]);function lI(e){var t;let r=(null!=(t=e.split(".").pop())?t:"").toLowerCase();return lD.has(r)?"image":lE.has(r)?"video":lR.has(r)?"pdf":lW.has(r)?"audio":null}function lB(e){return e.startsWith("http://")||e.startsWith("https://")?e:"/api/workspace/raw-file?path=".concat(encodeURIComponent(e))}let lF=/(?:^|[\s"'(=])(((?:\/|\.\/)?[\w.\-/\\]+)\.(?:jpe?g|png|gif|webp|svg|bmp|avif|heic|heif|tiff?|ico|mp4|webm|mov|avi|mkv|mp3|wav|ogg|m4a|pdf))\b/i,lA=["path","file","file_path","filePath","filename","url","src","name","target"];function lP(e,t){if(e)for(let t of lA){let r=e[t];if("string"==typeof r&&r.length>0)return r}if(t)for(let e of lA){let r=t[e];if("string"==typeof r&&r.length>0&&l_(r))return r}if(e){let t=lz(e);if(t)return t}if((null==t?void 0:t.text)&&"string"==typeof t.text){let e=t.text.match(lF);if(e)return e[1]}if(t){let e=lz(t);if(e)return e}return null}function l_(e){return e.length>2&&e.length<500&&/\.\w{1,5}$/.test(e)&&!e.includes(" ")}function lz(e){for(let t of Object.values(e))if("string"==typeof t&&l_(t))return t;return null}let lO=/https?:\/\/[^\s"'<>,;)}\]]+/gi;function lU(e){return"https://www.google.com/s2/favicons?sz=64&domain_url=".concat(encodeURIComponent(e))}function lH(e,t){let r=e.toLowerCase().replace(/[_-]/g,"");if(["websearch","search","googlesearch","bingsearch","browsersearch","tavily"].some(e=>r.includes(e)))return"search";if("browser"===r){let e="string"==typeof(null==t?void 0:t.action)?t.action.toLowerCase():"";return"open"===e||"navigate"===e?"fetch":"screenshot"===e?"image":"generic"}return["fetchurl","fetch","browse","browseurl","webfetch"].some(e=>r.includes(e))?"fetch":["read","file","readfile","getfile"].some(e=>r.includes(e))?"read":["bash","shell","execute","exec","terminal","command","run"].some(e=>r.includes(e))?"exec":["write","create","edit","str_replace","save","patch"].some(e=>r.includes(e))?"write":["image","screenshot","photo","picture","dalle","generateimage"].some(e=>r.includes(e))?"image":"generic"}function lV(e){let{parts:t,isStreaming:r}=e,[l,a]=(0,o.useState)(!!r),s=t.some(e=>"reasoning"===e.kind&&e.isStreaming||"tool"===e.kind&&"running"===e.status),i=(0,o.useRef)(null),[c,d]=(0,o.useState)(0);(0,o.useEffect)(()=>{s&&null===i.current&&(i.current=Date.now())},[s]),(0,o.useEffect)(()=>{if(!s)return;let e=()=>{null!==i.current&&d(Math.floor((Date.now()-i.current)/1e3))};e();let t=setInterval(e,1e3);return()=>clearInterval(t)},[s]);let u=(0,o.useCallback)(e=>{if(e<60)return"".concat(e,"s");let t=Math.floor(e/60),r=e%60;return r>0?"".concat(t,"m ").concat(r,"s"):"".concat(t,"m")},[]),x=(0,o.useRef)(!1);(0,o.useEffect)(()=>{r?x.current=!0:x.current&&t.length>0&&(x.current=!1,a(!1))},[r,t.length]);let h=t.filter(e=>"reasoning"===e.kind).map(e=>e.text).join(""),p=t.some(e=>"reasoning"===e.kind&&e.isStreaming),m=function(e){let t=[],r=0;for(;r<e.length;){let n=e[r],o=lH(n.toolName,n.args),l=lP(n.args,n.output),a=l?lI(l):null;if("read"===o&&a&&l){let o=[{path:l,tool:n}],s=r+1;for(;s<e.length;){let t=e[s],r=lH(t.toolName,t.args),n=lP(t.args,t.output),l=n?lI(n):null;if("read"===r&&l===a&&n)o.push({path:n,tool:t}),s++;else break}t.push({type:"media-group",mediaKind:a,items:o}),r=s}else if("fetch"===o){let o=[n],l=r+1;for(;l<e.length;){let t=e[l];if("fetch"===lH(t.toolName,t.args))o.push(t),l++;else break}o.length>1?t.push({type:"fetch-group",items:o}):t.push({type:"tool",tool:n}),r=l}else t.push({type:"tool",tool:n}),r++}return t}(t.filter(e=>"tool"===e.kind)),f=s?c>0?"Thinking for ".concat(u(c)):"Thinking...":c>0?"Thought for ".concat(u(c)):"Thought";return(0,n.jsxs)("div",{className:"my-3",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>a(e=>!e),className:"flex items-center gap-2 py-1 text-[13px] cursor-pointer group",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(l0,{className:"w-4 h-4 flex-shrink-0 opacity-60"}),(0,n.jsx)("span",{className:"font-medium",children:f}),(0,n.jsx)(l1,{className:"w-3.5 h-3.5 ml-1 flex-shrink-0 transition-transform duration-200 ".concat(l?"":"-rotate-90")})]}),(0,n.jsx)(lM.N,{initial:!1,children:l&&(0,n.jsx)(lo.P.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.3,ease:[.25,.1,.25,1]},className:"overflow-hidden",children:(0,n.jsxs)("div",{className:"relative pt-2 pb-1",children:[(0,n.jsx)("div",{className:"absolute w-px",style:{left:9,top:16,bottom:8,background:"var(--color-border)"}}),(0,n.jsxs)(lM.N,{initial:!1,children:[h&&(0,n.jsxs)(lo.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},className:"flex items-start gap-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2a7 7 0 0 0-7 7c0 2.38 1.19 4.47 3 5.74V17a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-2.26c1.81-1.27 3-3.36 3-5.74a7 7 0 0 0-7-7z"}),(0,n.jsx)("path",{d:"M10 21h4"})]})}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(lJ,{text:h,isStreaming:p})})]},"reasoning"),m.map((e,t)=>"media-group"===e.type?(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,n.jsx)(lq,{mediaKind:e.mediaKind,items:e.items})},"media-".concat(t)):"fetch-group"===e.type?(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,n.jsx)(lK,{items:e.items})},"fetch-".concat(t)):(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,n.jsx)(l$,{...e.tool})},e.tool.toolCallId))]})]})},"content")})]})}function lJ(e){let{text:t,isStreaming:r}=e;return(0,n.jsx)("div",{className:"mb-2",children:(0,n.jsx)("div",{className:"text-[13px] whitespace-pre-wrap leading-relaxed",style:{color:"var(--color-text-muted)"},children:t})})}function lK(e){let{items:t}=e,r=t.some(e=>"running"===e.status),o=t.filter(e=>"done"===e.status).length;return(0,n.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,n.jsx)("span",{className:r?"animate-pulse":"",children:(0,n.jsx)(lY,{kind:"fetch"})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"text-[13px] leading-snug mb-1.5 flex items-center justify-between",style:{color:r?"var(--color-text)":"var(--color-text-secondary)"},children:[(0,n.jsx)("span",{className:r?"animate-pulse":"",children:r?"Fetching ".concat(t.length," sources..."):"Fetched ".concat(t.length," sources")}),!r&&(0,n.jsxs)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:[o," ",1===o?"result":"results"]})]}),(0,n.jsx)("div",{className:"rounded-2xl overflow-hidden",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:t.map(e=>{var t,r;let{domain:o,url:l}=function(e,t){for(let t of["url","targetUrl","path","src"]){let r=null==e?void 0:e[t];if("string"==typeof r&&r.startsWith("http"))try{return{domain:new URL(r).hostname,url:r}}catch(e){}}for(let e of["url","finalUrl","targetUrl"]){let r=null==t?void 0:t[e];if("string"==typeof r&&r.startsWith("http"))try{return{domain:new URL(r).hostname,url:r}}catch(e){}}return{domain:null,url:null}}(e.args,e.output);return(0,n.jsxs)("a",{href:null!=l?l:void 0,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2.5 px-3 py-2.5 text-[12px] no-underline",style:{color:"var(--color-text)",cursor:l?"pointer":"default"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},onClick:l?void 0:e=>e.preventDefault(),children:[o?(0,n.jsx)("img",{src:lU(o),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",loading:"lazy"}):(0,n.jsx)("div",{className:"w-4 h-4 rounded-sm flex-shrink-0",style:{background:"var(--color-surface-hover)"}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",style:{color:"var(--color-text)"},children:null!=(r=null!=(t=null==o?void 0:o.replace(/^www\./,""))?t:l)?r:"Fetching..."}),"running"===e.status?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse flex-shrink-0",style:{background:"var(--color-accent)"}}):l?(0,n.jsx)("span",{className:"text-[11px] truncate max-w-[45%] text-right",style:{color:"var(--color-text-muted)"},title:l,children:l}):null]},e.toolCallId)})})]})]})}function lq(e){let{mediaKind:t,items:r}=e,[l,a]=(0,o.useState)(!1),s=r.some(e=>"running"===e.tool.status),i=r.filter(e=>"done"===e.tool.status),c=i.length,d=s?"Reading ".concat(r.length," ").concat(t).concat(r.length>1?"s":"","..."):"image"===t?1===r.length?"Read 1 image":"Read ".concat(r.length," images"):"video"===t?1===r.length?"Read 1 video":"Read ".concat(r.length," videos"):"pdf"===t?1===r.length?"Read 1 PDF":"Read ".concat(r.length," PDFs"):1===r.length?"Read 1 audio file":"Read ".concat(r.length," audio files"),u=l?i:i.slice(0,6),x=i.length>6&&!l;return(0,n.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,n.jsx)("span",{className:s?"animate-pulse":"",children:(0,n.jsx)(lY,{kind:"image"===t?"image":"read"})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-[13px] leading-snug mb-1.5".concat(s?" animate-pulse":""),style:{color:s?"var(--color-text)":"var(--color-text-secondary)"},children:d}),c>0&&"image"===t&&(0,n.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[u.map(e=>(0,n.jsx)(lG,{path:e.path,single:1===r.length},e.tool.toolCallId)),s&&(0,n.jsx)("div",{className:"flex items-center justify-center rounded-lg",style:{width:80,height:80,background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("span",{className:"animate-pulse",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(lY,{kind:"image"})})}),x&&(0,n.jsxs)("button",{type:"button",onClick:()=>a(!0),className:"flex items-center justify-center rounded-lg text-xs font-medium cursor-pointer",style:{width:80,height:80,background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:["+",i.length-6," ","more"]})]}),c>0&&"video"===t&&(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:u.map(e=>(0,n.jsx)("video",{src:lB(e.path),controls:!0,preload:"metadata",className:"rounded-lg max-w-[240px] max-h-[160px]",style:{border:"1px solid var(--color-border)"}},e.tool.toolCallId))}),c>0&&"pdf"===t&&(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:u.map(e=>{var t;let r=null!=(t=e.path.split("/").pop())?t:e.path;return(0,n.jsxs)("a",{href:lB(e.path),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 rounded-lg text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)(lX,{}),(0,n.jsx)("span",{className:"truncate max-w-[200px]",children:r})]},e.tool.toolCallId)})}),c>0&&"audio"===t&&(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:u.map(e=>(0,n.jsx)("audio",{src:lB(e.path),controls:!0,preload:"metadata",className:"max-w-[280px] h-8"},e.tool.toolCallId))})]})]})}function lG(e){var t;let{path:r,single:l}=e,[a,s]=(0,o.useState)(!1),i=null!=(t=r.split("/").pop())?t:r,c=lB(r),d=l?200:80,u=l?150:80;return a?(0,n.jsx)("div",{className:"flex items-center justify-center rounded-lg text-[10px] text-center p-1",style:{width:d,height:u,background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},title:r,children:(0,n.jsx)("span",{className:"truncate",children:i})}):(0,n.jsx)("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"block rounded-lg overflow-hidden flex-shrink-0",style:{border:"1px solid var(--color-border)",width:d,height:u},title:i,children:(0,n.jsx)("img",{src:c,alt:i,className:"w-full h-full object-cover",loading:"lazy",onError:()=>s(!0)})})}function l$(e){var t;let{toolName:r,status:l,args:a,output:s,errorText:i}=e,c=lH(r,a),[d,u]=(0,o.useState)("exec"===c||"generic"===c),[x,h]=(0,o.useState)(!0),p=function(e,t,r,n){var o,l,a,s,i,c,d,u,x,h,p,m,f,v,g,y,b,j,k;let w=e=>{let t=null==r?void 0:r[e];return"string"==typeof t&&t.length>0?t:null};switch(e){case"search":{let e=null!=(a=null!=(l=null!=(o=w("query"))?o:w("search_query"))?l:w("search"))?a:w("q");return e?"Searching for ".concat(e):"Searching..."}case"fetch":{let e=null!=(c=null!=(i=null!=(s=w("url"))?s:w("targetUrl"))?i:w("path"))?c:w("src");if(e)try{return"Fetching ".concat(new URL(e).hostname)}catch(t){return"Fetching ".concat(e)}let t="string"==typeof(null==n?void 0:n.finalUrl)&&n.finalUrl||"string"==typeof(null==n?void 0:n.url)&&n.url;if(t)try{return"Fetched ".concat(new URL(t).hostname)}catch(e){return"Fetched ".concat(t)}return"Fetching page"}case"read":{let e=lP(r,n);if(e){let t=null!=(d=e.split("/").pop())?d:e;return t.startsWith("http")?"Fetching ".concat(t):"Reading ".concat(t)}return"Reading file"}case"exec":{let e=null!=(u=w("command"))?u:w("cmd");if(e)return"Running: ".concat(e);return"Running command"}case"write":{let e=null!=(h=null!=(x=w("path"))?x:w("file"))?h:w("file_path");if(e){let t=null!=(p=e.split("/").pop())?p:e;return"Editing ".concat(t)}return"Editing file"}case"image":return w("description")?"Generating image: ".concat(w("description")):"Generating image";default:{let e=t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase()).trim();if(r){let t=null!=(k=null!=(j=null!=(b=null!=(y=null!=(g=null!=(v=null!=(f=null!=(m=w("command"))?m:w("cmd"))?f:w("query"))?v:w("path"))?g:w("url"))?y:w("message"))?b:w("description"))?j:w("input"))?k:w("text");if(t)return"".concat(e,": ").concat(t)}return e||"Tool"}}}(c,r,a,s),m="search"===c?function(e){var t;if(!e)return[];let r="string"==typeof e.text?e.text:"",n=e.results,o=e.citations,l=r;if(Array.isArray(n))for(let e of n)"string"==typeof e?l+=" ".concat(e):"object"==typeof e&&null!==e&&("string"==typeof e.url&&(l+=" ".concat(e.url)),"string"==typeof e.link&&(l+=" ".concat(e.link)));if(Array.isArray(o))for(let e of o)"string"==typeof e?l+=" ".concat(e):"object"==typeof e&&null!==e&&"string"==typeof e.url&&(l+=" ".concat(e.url));for(let t of Object.values(e))"string"==typeof t&&t!==r&&t.includes("http")&&(l+=" ".concat(t));let a=null!=(t=l.match(lO))?t:[],s=new Set;for(let e of a)try{let t=new URL(e).hostname;t&&!t.includes("localhost")&&s.add(t)}catch(e){}return[...s].slice(0,8)}(s):"fetch"===c?function(e,t){let r=new Set;for(let t of["url","targetUrl","path","src"]){let n=null==e?void 0:e[t];if("string"==typeof n&&n.startsWith("http"))try{let e=new URL(n).hostname;e&&!e.includes("localhost")&&r.add(e)}catch(e){}}for(let e of["url","finalUrl","targetUrl"]){let n=null==t?void 0:t[e];if("string"==typeof n&&n.startsWith("http"))try{let e=new URL(n).hostname;e&&!e.includes("localhost")&&r.add(e)}catch(e){}}return[...r].slice(0,4)}(a,s):[],f="string"==typeof(null==s?void 0:s.text)?s.text:void 0,v=(()=>{if("write"!==c||"done"!==l)return;if("string"==typeof(null==s?void 0:s.diff))return s.diff;let e="string"==typeof(null==a?void 0:a.old_string)?a.old_string:"string"==typeof(null==a?void 0:a.oldText)?a.oldText:null,t="string"==typeof(null==a?void 0:a.new_string)?a.new_string:"string"==typeof(null==a?void 0:a.newText)?a.newText:null;if(null!==e&&null!==t){var r="string"==typeof(null==a?void 0:a.path)?a.path:"string"==typeof(null==a?void 0:a.file_path)?a.file_path:"file";let n=e.split("\n"),o=t.split("\n"),l=["--- a/".concat(r),"+++ b/".concat(r),"@@ -1,".concat(n.length," +1,").concat(o.length," @@")];for(let e of n)l.push("-".concat(e));for(let e of o)l.push("+".concat(e));return l.join("\n")}})(),g=lP(a,s),y=g?lI(g):null,b="read"===c&&y&&"done"===l;return(0,n.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:"error"===l?(0,n.jsx)(lQ,{}):(0,n.jsx)("span",{className:"running"===l?"animate-pulse":"",children:(0,n.jsx)(lY,{kind:c})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"text-[13px] leading-snug flex items-center gap-2 flex-wrap",style:{color:"running"===l?"var(--color-text)":"var(--color-text-secondary)"},children:[(0,n.jsx)("span",{className:"break-all".concat("running"===l?" animate-pulse":""),children:p}),"exec"===c&&"done"===l&&(null==s?void 0:s.exitCode)!==void 0&&(0,n.jsxs)("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded",style:{background:0===s.exitCode?"color-mix(in srgb, var(--color-success, #22c55e) 12%, transparent)":"color-mix(in srgb, var(--color-error) 12%, transparent)",color:0===s.exitCode?"var(--color-success, #22c55e)":"var(--color-error)"},children:["exit ","object"==typeof s.exitCode&&null!=s.exitCode?JSON.stringify(s.exitCode):"number"==typeof s.exitCode?String(s.exitCode):"string"==typeof s.exitCode?s.exitCode:""]})]}),v&&"done"===l&&(0,n.jsxs)("div",{className:"mt-1.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>h(e=>!e),className:"text-[11px] hover:underline cursor-pointer mb-1",style:{color:"var(--color-accent)"},children:x?"Hide changes":"Show changes"}),x&&(0,n.jsx)(rP,{diff:v})]}),b&&g&&"image"===y&&(0,n.jsx)("div",{className:"mt-1.5",children:(0,n.jsx)(lG,{path:g,single:!0})}),b&&g&&"video"===y&&(0,n.jsx)("video",{src:lB(g),controls:!0,preload:"metadata",className:"mt-1.5 rounded-lg max-w-[240px] max-h-[160px]",style:{border:"1px solid var(--color-border)"}}),b&&g&&"pdf"===y&&(0,n.jsxs)("a",{href:lB(g),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 mt-1.5 px-3 py-2 rounded-lg text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)(lX,{}),(0,n.jsx)("span",{className:"truncate max-w-[200px]",children:null!=(t=g.split("/").pop())?t:g})]}),b&&g&&"audio"===y&&(0,n.jsx)("audio",{src:lB(g),controls:!0,preload:"metadata",className:"mt-1.5 max-w-[280px] h-8"}),m.length>0&&"running"!==l&&(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-1.5",children:m.map(e=>(0,n.jsx)(lZ,{domain:e},e))}),("search"===c||"fetch"===c)&&"running"===l&&a&&(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-1.5",children:m.length>0?m.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("img",{src:lU(e),alt:"",width:14,height:14,className:"rounded-sm flex-shrink-0",loading:"lazy"}),e.replace(/^www\./,""),(0,n.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}})]},e)):(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}}),"fetch"===c?"Fetching...":"Searching..."]})}),"error"===l&&i&&(0,n.jsx)("div",{className:"mt-1.5 text-[12px] font-mono rounded-lg px-2.5 py-1.5",style:{color:"var(--color-error)",background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))"},children:i}),!f&&!v&&!b&&"done"===l&&a&&Object.keys(a).length>0&&(0,n.jsx)("pre",{className:"mt-1 text-[11px] font-mono rounded-lg px-2.5 py-1.5 whitespace-pre-wrap break-all max-h-48 overflow-y-auto leading-relaxed",style:{color:"var(--color-text-muted)",background:"var(--color-bg)"},children:function(e){let t=[];for(let[r,n]of Object.entries(e)){if(null==n)continue;let e="string"==typeof n?n:JSON.stringify(n,null,2);t.push("".concat(r,": ").concat(e))}let r=t.join("\n");return r.length>2e3?r.slice(0,2e3)+"\n...":r}(a)}),f&&!b&&!v&&(0,n.jsxs)("div",{className:"mt-1",children:["done"===l&&(0,n.jsx)("button",{type:"button",onClick:()=>u(e=>!e),className:"text-[11px] hover:underline cursor-pointer",style:{color:"var(--color-accent)"},children:d?"Hide output":"Show output"}),(d||"running"===l)&&(0,n.jsx)("pre",{className:"mt-1 text-[11px] font-mono rounded-lg px-2.5 py-2 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto leading-relaxed",style:{color:"var(--color-text-muted)",background:"var(--color-bg)"},children:f.length>1e4?f.slice(0,1e4)+"\n... (truncated)":f})]})]})]})}function lZ(e){let{domain:t}=e,r=t.replace(/^www\./,"");return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("img",{src:lU(t),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",loading:"lazy"}),r]})}function lY(e){let{kind:t}=e,r="var(--color-text-muted)";switch(t){case"search":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]});case"fetch":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("path",{d:"M2 12h20"}),(0,n.jsx)("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]});case"read":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]});case"exec":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]});case"write":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,n.jsx)("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})]});case"image":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});default:return(0,n.jsx)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1"})})}}function lQ(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",x2:"9",y1:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",x2:"15",y1:"9",y2:"15"})]})}function lX(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,n.jsx)("path",{d:"M10 9H8"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"})]})}function l0(e){let{className:t}=e;return(0,n.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2a7 7 0 0 0-7 7c0 2.38 1.19 4.47 3 5.74V17a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-2.26c1.81-1.27 3-3.36 3-5.74a7 7 0 0 0-7-7z"}),(0,n.jsx)("path",{d:"M10 21h4"}),(0,n.jsx)("path",{d:"M9 9.4a3 3 0 0 1 5.1-2"})]})}function l1(e){let{className:t}=e;return(0,n.jsx)("svg",{className:t,viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M3 4.5L6 7.5L9 4.5"})})}let l2=null,l4=["typescript","tsx","javascript","jsx","python","ruby","go","rust","java","c","cpp","csharp","swift","kotlin","css","scss","html","xml","json","yaml","toml","bash","sql","graphql","markdown","diff","php","lua","vue","svelte","dart","zig"];function l5(e){let{code:t,lang:r}=e,[l,a]=(0,o.useState)(null);return((0,o.useEffect)(()=>{let e=!1;return(!l2&&(l2=(0,r8.O_)({themes:["github-dark","github-light"],langs:l4})),l2).then(n=>{if(!e)try{let e=n.codeToHtml(t,{lang:r,themes:{dark:"github-dark",light:"github-light"}});a(e)}catch(e){try{let e=n.codeToHtml(t,{lang:"text",themes:{dark:"github-dark",light:"github-light"}});a(e)}catch(e){}}}),()=>{e=!0}},[t,r]),l)?(0,n.jsx)("div",{className:"syntax-block",dangerouslySetInnerHTML:{__html:l}}):(0,n.jsx)("code",{className:"block",children:t})}let l6=(0,rD.default)(()=>r.e(5477).then(r.bind(r,45477)).then(e=>({default:e.ReportCard})),{loadableGenerated:{webpack:()=>[45477]},ssr:!1,loading:()=>(0,n.jsx)("div",{className:"h-48 rounded-2xl animate-pulse",style:{background:"var(--color-surface-hover)"}})}),l3="NO_REPLY";function l8(e){return"output-available"===e?"done":"error"===e?"error":"running"}function l7(e){if(e&&"object"==typeof e&&!Array.isArray(e))return e}function l9(e){let{paths:t}=e;return(0,n.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-2 justify-end",children:t.map((e,t)=>{var r,o,l;let a=function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(n)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(n)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(n)?"audio":"pdf"===n?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(n)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv","pages","numbers","key"].includes(n)?"document":"other"}(e),s="image"===a?"/api/workspace/raw-file?path=".concat(encodeURIComponent(e)):"/api/workspace/thumbnail?path=".concat(encodeURIComponent(e),"&size=200"),i=null!=(o=null==(r=e.split(".").pop())?void 0:r.toUpperCase())?o:"";return(0,n.jsxs)("div",{className:"relative rounded-xl overflow-hidden shrink-0",children:[(0,n.jsx)("img",{src:s,alt:null!=(l=e.split("/").pop())?l:"",className:"block rounded-xl object-cover",style:{maxHeight:140,maxWidth:160,background:"rgba(0,0,0,0.04)"},loading:"lazy",onError:e=>{e.currentTarget.style.display="none"}}),"image"!==a&&(0,n.jsx)("span",{className:"absolute bottom-2 left-2 rounded-md px-1.5 py-0.5 text-[10px] font-bold uppercase",style:{background:"rgba(255,255,255,0.85)",color:"rgba(0,0,0,0.5)",backdropFilter:"blur(4px)"},children:i})]},t)})})}function ae(e){let t=e.trim();if(!t||t.length<3||t.length>500)return!1;if(t.startsWith("~/")||t.startsWith("/")||t.startsWith("./")||t.startsWith("../")){let e=t.startsWith("~/")?t.slice(2):t.startsWith("../")?t.slice(3):t.startsWith("./")?t.slice(2):t.slice(1);return e.includes("/")||e.includes(".")}return!(!/\.(pdf|docx?|xlsx?|pptx?|csv|txt|rtf|pages|numbers|key|md|json|yaml|yml|toml|xml|html?|css|jsx?|tsx?|py|rb|go|rs|java|cpp|c|h|sh|sql|swift|kt|png|jpe?g|gif|webp|svg|bmp|ico|heic|tiff|mp[34]|webm|mov|avi|mkv|flv|wav|ogg|aac|flac|m4a|zip|tar|gz|dmg)$/i.test(t)||t.includes(" "))}async function at(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{let r=await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,reveal:t})});if(!r.ok){let e=await r.json().catch(()=>({}));console.error("Failed to open file:",e)}}catch(e){console.error("Failed to open file:",e)}}function ar(e){let t=e.trim();if(!t.startsWith("file://"))return t;try{let e=new URL(t);if("file:"!==e.protocol)return t;let r=decodeURIComponent(e.pathname);if(/^\/[A-Za-z]:\//.test(r))return r.slice(1);return r}catch(e){return t}}function an(e){let{path:t,children:r,onFilePathClick:l}=e,[a,s]=(0,o.useState)("idle"),i=async e=>{e.preventDefault(),s("opening");try{if(l){let e=await l(t);if(!1===e){s("error"),setTimeout(()=>s("idle"),2e3);return}s("idle")}else(await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})})).ok?s("idle"):(s("error"),setTimeout(()=>s("idle"),2e3))}catch(e){s("error"),setTimeout(()=>s("idle"),2e3)}},c=async e=>{e.preventDefault(),await at(t,!0)};return(0,n.jsx)("code",{className:"px-[0.3em] no-underline transition-colors duration-150 rounded-[4px] border border-[color:var(--color-border)] bg-white/20 hover:bg-white/40 active:bg-white ".concat("opening"===a?"cursor-wait opacity-70":"cursor-pointer"),style:{color:"var(--color-accent)"},onClick:i,onContextMenu:c,title:"error"===a?"File not found":l?"Click to preview in workspace \xb7 Right-click to reveal in Finder":"Click to open \xb7 Right-click to reveal in Finder",children:r})}function ao(e){let{messageId:t,sessionId:r}=e,l=(0,o.useCallback)((e,t)=>{var r;e&&fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:e,messageId:t,distinctId:null==(r=lC.Ay.get_distinct_id)?void 0:r.call(lC.Ay)})}).catch(()=>{})},[]),{respond:a,response:s,triggerRef:i}=(0,lS.y)({surveyId:"019cc021-a8bf-0000-d41d-b82956ef7e6a",properties:{$ai_trace_id:r,message_id:t},onResponse:()=>l(r,t)}),c="p-1 rounded-md transition-colors";return(0,n.jsxs)("div",{ref:i,className:"flex items-center gap-0.5 mt-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{type:"button",onClick:()=>a("up"),className:c,style:{color:"up"===s?"var(--color-accent)":"var(--color-text-muted)"},title:"Good response","aria-label":"Thumbs up",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"up"===s?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M7 10v12"}),(0,n.jsx)("path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z"})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>a("down"),className:c,style:{color:"down"===s?"var(--color-error, #ef4444)":"var(--color-text-muted)"},title:"Bad response","aria-label":"Thumbs down",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"down"===s?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17 14V2"}),(0,n.jsx)("path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z"})]})})]})}let al=(0,o.memo)(function(e){let{message:t,isStreaming:r,onSubagentClick:l,onFilePathClick:a,sessionId:s,userHtmlMap:i}=e,c="user"===t.role,d=function(e){let t=[],r=[],n=e=>{if(r.length>0){if(e)for(let e of r)"tool"===e.kind&&"running"===e.status&&(e.status="done");t.push({type:"chain",parts:[...r]}),r=[]}};for(let x of e)if("text"===x.type){let e=x.text;if(function(e){let t=e.trim();return!!t&&!!(new RegExp("^".concat(l3,"\\W*$")).test(t)||l3.startsWith(t)&&t.length>=2&&t.length<l3.length)}(e))continue;if(n(!0),rR(e))t.push(...rE(e));else if(rI(e))for(let r of rW(e))"diff-artifact"===r.type?t.push({type:"diff-artifact",diff:r.diff}):t.push({type:"text",text:r.text});else t.push({type:"text",text:e})}else if("reasoning"===x.type){let e=x;["Preparing response...","Optimizing session context...","Waiting for subagent results...","Waiting for subagents..."].some(t=>e.text.startsWith(t))||r.push({kind:"reasoning",text:e.text,isStreaming:"streaming"===e.state})}else if("dynamic-tool"===x.type)if("sessions_spawn"===x.toolName){n(!0);let e=l7(x.input),r=l7(x.output),o="string"==typeof(null==e?void 0:e.task)?e.task:"Subagent task",l="string"==typeof(null==e?void 0:e.label)?e.label:void 0,a="string"==typeof(null==r?void 0:r.sessionKey)?r.sessionKey:void 0;t.push({type:"subagent-card",task:o,label:l,sessionKey:a,status:l8(x.state)})}else r.push({kind:"tool",toolName:x.toolName,toolCallId:x.toolCallId,status:l8(x.state),args:l7(x.input),output:l7(x.output)});else if(x.type.startsWith("tool-")){var o,l,a,s,i,c,d,u;let e=null!=(l=null!=(o=x.title)?o:x.toolName)?l:x.type.replace("tool-","");if("sessions_spawn"===e){n(!0);let e=null!=(a=l7(x.input))?a:l7(x.args),r=null!=(s=l7(x.output))?s:l7(x.result),o="string"==typeof(null==e?void 0:e.task)?e.task:"Subagent task",l="string"==typeof(null==e?void 0:e.label)?e.label:void 0,c="string"==typeof(null==r?void 0:r.sessionKey)?r.sessionKey:void 0,d=null!=(i=x.state)?i:x.errorText?"error":"result"in x||"output"in x?"output-available":"input-available";t.push({type:"subagent-card",task:o,label:l,sessionKey:c,status:l8(d)})}else{let t=null!=(c=x.state)?c:x.errorText?"error":"result"in x||"output"in x?"output-available":"input-available";r.push({kind:"tool",toolName:e,toolCallId:x.toolCallId,status:l8(t),args:null!=(d=l7(x.input))?d:l7(x.args),output:null!=(u=l7(x.output))?u:l7(x.result)})}}return n(),t}(t.parts),u=(0,o.useMemo)(()=>({a:e=>{let{href:t,children:r,...o}=e,l="string"==typeof t?t:"",s=ar(l),i=l&&(l.startsWith("http://")||l.startsWith("https://")||l.startsWith("//")),c=!(l.startsWith("/workspace")||l.startsWith("/?"))&&(!!l.startsWith("file://")||ae(s));return(0,n.jsx)("a",{href:t,...i?{target:"_blank",rel:"noopener noreferrer"}:{},...o,onClick:e=>{c&&a&&(e.preventDefault(),a(s))},children:r})},img:e=>{let{src:t,alt:r,...o}=e,l="string"!=typeof t||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("data:")?t:"/api/workspace/raw-file?path=".concat(encodeURIComponent(t));return(0,n.jsx)("img",{src:l,alt:null!=r?r:"",loading:"lazy",...o})},pre:e=>{let{children:t,...r}=e,o=Array.isArray(t)?t[0]:t;if(o&&"object"==typeof o&&"type"in o&&"code"===o.type){var l,a,s,i;let e=(null!=(s=null==(l=o.props)?void 0:l.className)?s:"").match(/language-(\w+)/),t=null!=(i=null==e?void 0:e[1])?i:"",r="string"==typeof(null==(a=o.props)?void 0:a.children)?o.props.children.replace(/\n$/,""):"";if("diff"===t)return(0,n.jsx)(rP,{diff:r});if(t)return(0,n.jsxs)("div",{className:"chat-code-block",children:[(0,n.jsx)("div",{className:"chat-code-lang",children:t}),(0,n.jsx)(l5,{code:r,lang:t})]})}return(0,n.jsx)("pre",{...r,children:t})},code:e=>{let{children:t,className:r,...o}=e;if(null==r?void 0:r.startsWith("language-"))return(0,n.jsx)("code",{className:r,...o,children:t});let l=ar("string"==typeof t?t:"");return l&&ae(l)?(0,n.jsx)(an,{path:l,onFilePathClick:a,children:t}):(0,n.jsx)("code",{...o,children:t})},strong:e=>{let{children:t,...r}=e,o="string"==typeof t?t:Array.isArray(t)?t.filter(e=>"string"==typeof e).join(""):"";return o&&function(e){let t=e.trim();return!!t&&!(t.length<3)&&!(t.length>300)&&/\.(pdf|docx?|xlsx?|pptx?|csv|txt|rtf|pages|numbers|key|md|json|yaml|yml|toml|xml|html?|css|jsx?|tsx?|py|rb|go|rs|java|cpp|c|h|sh|sql|swift|kt|png|jpe?g|gif|webp|svg|bmp|ico|heic|tiff|mp[34]|webm|mov|avi|mkv|flv|wav|ogg|aac|flac|m4a|zip|tar|gz|dmg)$/i.test(t)}(o)?(0,n.jsx)("strong",{...r,children:(0,n.jsx)(an,{path:o,onFilePathClick:a,children:t})}):(0,n.jsx)("strong",{...r,children:t})}}),[a]);if(c){var x,h,p,m;let e=d.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),r=function(e){var t;let r=e.match(/\[Attached files: (.+?)\]/);if(!r)return null;let n=(null!=(t=r.index)?t:0)+r[0].length,o=e.slice(n).trim();return{paths:r[1].split(", ").map(e=>e.trim()).filter(Boolean),message:o}}(e),o=null!=(p=null!=(x=null==i?void 0:i.get(t.id))?x:null==i?void 0:i.get(e))?p:null==i?void 0:i.get(null!=(h=null==r?void 0:r.message)?h:""),l=o?(0,n.jsx)("div",{className:"chat-user-html-content",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("p",{className:"whitespace-pre-wrap break-words",children:null!=(m=null==r?void 0:r.message)?m:e});return r?(0,n.jsxs)("div",{className:"flex flex-col items-end gap-1.5 py-2",children:[(0,n.jsx)(l9,{paths:r.paths}),(r.message||o)&&(0,n.jsx)("div",{className:"max-w-[80%] w-fit rounded-2xl rounded-br-sm px-3 py-2 text-sm leading-6 break-words chat-message-font",style:{background:"var(--color-user-bubble)",color:"var(--color-user-bubble-text)"},children:l})]}):(0,n.jsx)("div",{className:"flex justify-end py-2",children:(0,n.jsx)("div",{className:"max-w-[80%] min-w-0 rounded-2xl rounded-br-sm px-3 py-2 text-sm leading-6 overflow-hidden break-words chat-message-font",style:{background:"var(--color-user-bubble)",color:"var(--color-user-bubble-text)"},children:l})})}return(0,n.jsxs)("div",{className:"py-3 space-y-2 min-w-0 overflow-hidden group",children:[(0,n.jsx)(lM.N,{initial:!1,children:d.map((e,t)=>{if("text"===e.type){let r=e.text.match(/^\[error\]\s*([\s\S]*)$/);return r?(0,n.jsxs)("div",{className:"chat-message-font flex items-start gap-2 rounded-xl px-3 py-2 text-[13px] leading-relaxed overflow-hidden",style:{background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))",color:"var(--color-error)",border:"1px solid color-mix(in srgb, var(--color-error) 18%, transparent)"},children:[(0,n.jsx)("span",{className:"flex-shrink-0 mt-0.5","aria-hidden":"true",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,n.jsx)("span",{className:"whitespace-pre-wrap break-all min-w-0",children:r[1].trim()})]},t):(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},className:"chat-prose chat-message-font text-sm",style:{color:"var(--color-text)"},children:(0,n.jsx)(lL.oz,{remarkPlugins:[lT.A],components:u,children:e.text})},"text-".concat(t))}if("report-artifact"===e.type)return(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)(l6,{config:e.config})},"report-".concat(t));if("diff-artifact"===e.type)return(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)(rP,{diff:e.diff})},"diff-".concat(t));if("subagent-card"===e.type){let r=e.task.length>80?e.task.slice(0,80)+"...":e.task,o="running"===e.status;return(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)("button",{type:"button",onClick:()=>{var t;return null==l?void 0:l(null!=(t=e.sessionKey)?t:e.task)},className:"w-full text-left rounded-xl px-3.5 py-2.5 transition-colors cursor-pointer",style:{background:"var(--color-accent-light)",border:"1px solid color-mix(in srgb, var(--color-accent) 20%, transparent)"},children:(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[o?(0,n.jsx)("span",{className:"inline-block w-2 h-2 rounded-full animate-pulse flex-shrink-0",style:{background:"var(--color-accent)"}}):(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{color:"var(--color-accent)"},children:[(0,n.jsx)("path",{d:"M16 3h5v5"}),(0,n.jsx)("path",{d:"m21 3-7 7"}),(0,n.jsx)("path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6"})]}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-accent)"},children:o?"Running Subagent":"Subagent"})}),(0,n.jsx)("p",{className:"text-xs mt-0.5 leading-relaxed",style:{color:"var(--color-text)"},children:e.label||r})]}),(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-40",style:{color:"var(--color-text)"},children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})]})})},"subagent-".concat(t))}return(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)(lV,{parts:e.parts,isStreaming:r})},"chain-".concat(t))})}),!r&&(0,n.jsx)(ao,{messageId:t.id,sessionId:s})]})}),aa={folder:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},image:{bg:"rgba(16, 185, 129, 0.12)",fg:"#10b981"},video:{bg:"rgba(139, 92, 246, 0.12)",fg:"#8b5cf6"},audio:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},pdf:{bg:"rgba(239, 68, 68, 0.12)",fg:"#ef4444"},code:{bg:"rgba(59, 130, 246, 0.12)",fg:"#3b82f6"},document:{bg:"rgba(107, 114, 128, 0.12)",fg:"#6b7280"},other:{bg:"rgba(107, 114, 128, 0.08)",fg:"#9ca3af"}};function as(e){let{category:t,size:r=16}=e,o={width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};switch(t){case"folder":return(0,n.jsx)("svg",{...o,children:(0,n.jsx)("path",{d:"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"})});case"image":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,n.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M10 13h4"}),(0,n.jsx)("path",{d:"M10 17h4"})]});case"code":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]});case"document":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"}),(0,n.jsx)("path",{d:"M10 9H8"})]});default:return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"})]})}}function ai(e){let{open:t,onClose:r,onSelect:l}=e,[a,s]=(0,o.useState)(null),[i,c]=(0,o.useState)(""),[d,u]=(0,o.useState)([]),[x,h]=(0,o.useState)(null),[p,m]=(0,o.useState)(new Map),[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(""),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(""),[N,C]=(0,o.useState)(null),[S,M]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t?requestAnimationFrame(()=>requestAnimationFrame(()=>M(!0))):M(!1)},[t]),(0,o.useEffect)(()=>{t||(y(""),j(!1),w(""),C(null))},[t]);let L=(0,o.useRef)(null),T=(0,o.useRef)(null),D=(0,o.useCallback)(async e=>{v(!0),C(null);try{var t;let r=e?"/api/workspace/browse?dir=".concat(encodeURIComponent(e)):"/api/workspace/browse",n=await fetch(r);if(!n.ok)throw Error("Failed to list directory");let o=await n.json();u(o.entries||[]),c(o.currentDir||""),h(null!=(t=o.parentDir)?t:null)}catch(e){C("Could not load this directory"),u([])}finally{v(!1)}},[]);(0,o.useEffect)(()=>{t&&D(a)},[t,a,D]),(0,o.useEffect)(()=>{if(!t)return;let e=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,r]);let E=(0,o.useCallback)(e=>{m(t=>{let r=new Map(t);return r.has(e.path)?r.delete(e.path):r.set(e.path,{name:e.name,path:e.path}),r})},[]),R=(0,o.useCallback)(e=>{s(e),y(""),j(!1)},[]),W=(0,o.useCallback)(async()=>{if(!k.trim()||!i)return;let e="".concat(i,"/").concat(k.trim());try{await fetch("/api/workspace/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}),j(!1),w(""),D(a)}catch(e){C("Failed to create folder")}},[k,i,a,D]),I=(0,o.useCallback)(()=>{l(Array.from(p.values())),m(new Map),r()},[p,l,r]),B=d.filter(e=>!g||e.name.toLowerCase().includes(g.toLowerCase())).toSorted((e,t)=>"folder"===e.type&&"folder"!==t.type?-1:"folder"!==e.type&&"folder"===t.type?1:e.name.localeCompare(t.name)),F=i?function(e){let t=[],r=e.match(/^(\/Users\/[^/]+|\/home\/[^/]+)/),n=null==r?void 0:r[1];if(n){t.push({label:"~",path:n});let r=e.slice(n.length).split("/").filter(Boolean),o=n;for(let e of r)o+="/"+e,t.push({label:e,path:o})}else if("/"===e)t.push({label:"/",path:"/"});else{t.push({label:"/",path:"/"});let r=e.split("/").filter(Boolean),n="";for(let e of r)n+="/"+e,t.push({label:e,path:n})}return t}(i):[];return t?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",style:{opacity:+!!S,transition:"opacity 150ms ease-out"},children:[(0,n.jsx)("div",{className:"absolute inset-0",style:{background:"rgba(0,0,0,0.4)",backdropFilter:"blur(4px)"},onClick:r}),(0,n.jsxs)("div",{className:"relative flex flex-col rounded-2xl shadow-2xl overflow-hidden w-[calc(100%-2rem)] max-w-[540px]",style:{maxHeight:"70vh",background:"var(--color-surface)",border:"1px solid var(--color-border)",transform:S?"scale(1)":"scale(0.97)",transition:"transform 150ms ease-out"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-3.5 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center",style:{background:aa.folder.bg,color:aa.folder.fg},children:(0,n.jsx)(as,{category:"folder",size:18})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-semibold",style:{color:"var(--color-text)"},children:"Select Files"}),(0,n.jsx)("p",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:"Browse and attach files"})]})]}),(0,n.jsx)("button",{type:"button",onClick:r,className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]}),i&&(0,n.jsx)("div",{className:"flex items-center gap-1 px-5 py-2 border-b overflow-x-auto flex-shrink-0",style:{borderColor:"var(--color-border)",scrollbarWidth:"thin"},children:F.map((e,t)=>(0,n.jsxs)(o.Fragment,{children:[t>0&&(0,n.jsx)("span",{className:"text-[10px] flex-shrink-0",style:{color:"var(--color-text-muted)",opacity:.5},children:"/"}),(0,n.jsx)("button",{type:"button",onClick:()=>R(e.path),className:"text-[12px] font-medium flex-shrink-0 rounded px-1 py-0.5 hover:underline",style:{color:t===F.length-1?"var(--color-text)":"var(--color-text-muted)"},children:e.label})]},e.path))}),(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 rounded-lg px-2.5 py-1.5",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",flexShrink:0},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]}),(0,n.jsx)("input",{ref:L,type:"text",value:g,onChange:e=>y(e.target.value),placeholder:"Filter files...",className:"flex-1 bg-transparent outline-none text-[13px] placeholder:text-[var(--color-text-muted)]",style:{color:"var(--color-text)"}})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{j(!0),setTimeout(()=>{var e;return null==(e=T.current)?void 0:e.focus()},50)},className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[12px] font-medium whitespace-nowrap",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]}),"Folder"]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",style:{background:"var(--color-bg)",minHeight:200},children:f?(0,n.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):N?(0,n.jsx)("div",{className:"flex items-center justify-center py-16 text-[13px]",style:{color:"var(--color-text-muted)"},children:N}):(0,n.jsxs)(n.Fragment,{children:[x&&(0,n.jsxs)("button",{type:"button",onClick:()=>R(x),className:"w-full flex items-center gap-3 px-4 py-2 text-left",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0",style:{background:"var(--color-surface-hover)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})})}),(0,n.jsx)("span",{className:"text-[13px] font-medium",children:".."})]}),b&&(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2",children:[(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0",style:{background:aa.folder.bg,color:aa.folder.fg},children:(0,n.jsx)(as,{category:"folder"})}),(0,n.jsx)("input",{ref:T,type:"text",value:k,onChange:e=>w(e.target.value),onKeyDown:e=>{"Enter"===e.key&&W(),"Escape"===e.key&&(j(!1),w(""))},placeholder:"Folder name...",className:"flex-1 bg-transparent outline-none text-[13px] placeholder:text-[var(--color-text-muted)] rounded px-2 py-1",style:{color:"var(--color-text)",background:"var(--color-surface)",border:"1px solid var(--color-accent)"}})]}),0===B.length&&!x&&(0,n.jsx)("div",{className:"flex items-center justify-center py-16 text-[13px]",style:{color:"var(--color-text-muted)"},children:"This folder is empty"}),B.map(e=>{var t;let r="folder"===e.type,o=r?"folder":function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(n)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(n)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(n)?"audio":"pdf"===n?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(n)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv"].includes(n)?"document":"other"}(e.name),l=null!=(t=aa[o])?t:aa.other,a=p.has(e.path);return(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-1.5 group cursor-pointer",style:{background:a?"color-mix(in srgb, var(--color-accent) 8%, transparent)":void 0},onClick:()=>{r?R(e.path):E(e)},children:[(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),E(e)},className:"w-4 h-4 rounded flex items-center justify-center flex-shrink-0 border",style:{borderColor:a?"var(--color-accent)":"var(--color-border-strong)",background:a?"var(--color-accent)":"transparent"},children:a&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}),(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0",style:{background:l.bg,color:l.fg},children:(0,n.jsx)(as,{category:o})}),(0,n.jsx)("span",{className:"flex-1 text-[13px] truncate",style:{color:"var(--color-text)",fontWeight:r?500:400},title:e.path,children:e.name}),r&&(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-0 group-hover:opacity-50 transition-opacity",children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})]},e.path)})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-3 border-t flex-shrink-0",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("span",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:p.size>0?"".concat(p.size," ").concat(1===p.size?"item":"items"," selected"):"No files selected"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:r,className:"px-3 py-1.5 rounded-lg text-[13px] font-medium",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:"Cancel"}),(0,n.jsxs)("button",{type:"button",onClick:I,disabled:0===p.size,className:"px-3 py-1.5 rounded-lg text-[13px] font-medium disabled:opacity-40 disabled:cursor-not-allowed",style:{color:"white",background:p.size>0?"var(--color-accent)":"var(--color-border-strong)"},children:["Attach"," ",p.size>0&&"".concat(p.size," ").concat(1===p.size?"file":"files")]})]})]})]})]}):null}var ac=r(48997),ad=r(79534);let au=new(r(63550)).hs("chatFileMention"),ax=ad.bP.create({name:"chatFileMention",group:"inline",inline:!0,atom:!0,selectable:!0,draggable:!0,addAttributes:()=>({label:{default:""},path:{default:""},mentionType:{default:"file"},objectName:{default:""}}),parseHTML:()=>[{tag:"span[data-chat-file-mention]"}],renderHTML(e){let{HTMLAttributes:t}=e,r=t.label||"file",n=function(e,t){var r,n;if("object"===t)return{bg:"rgba(14,165,233,0.15)",fg:"#0ea5e9"};if("entry"===t)return{bg:"rgba(34,197,94,0.15)",fg:"#22c55e"};let o=null!=(n=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?n:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(o)?{bg:"rgba(16,185,129,0.15)",fg:"#10b981"}:["mp4","webm","mov","avi","mkv","flv"].includes(o)?{bg:"rgba(139,92,246,0.15)",fg:"#8b5cf6"}:["mp3","wav","ogg","aac","flac","m4a"].includes(o)?{bg:"rgba(245,158,11,0.15)",fg:"#f59e0b"}:"pdf"===o?{bg:"rgba(239,68,68,0.15)",fg:"#ef4444"}:["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(o)?{bg:"rgba(59,130,246,0.15)",fg:"#3b82f6"}:["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv"].includes(o)?{bg:"rgba(107,114,128,0.15)",fg:"#6b7280"}:{bg:"rgba(107,114,128,0.10)",fg:"#9ca3af"}}(r,t.mentionType);return["span",(0,ad.KV)({"data-chat-file-mention":"",class:"chat-file-mention",style:"--mention-bg: ".concat(n.bg,"; --mention-fg: ").concat(n.fg,";"),title:t.path||""},t),"@".concat(r)]}}),ah={folder:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},image:{bg:"rgba(16, 185, 129, 0.12)",fg:"#10b981"},video:{bg:"rgba(139, 92, 246, 0.12)",fg:"#8b5cf6"},audio:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},pdf:{bg:"rgba(239, 68, 68, 0.12)",fg:"#ef4444"},code:{bg:"rgba(59, 130, 246, 0.12)",fg:"#3b82f6"},document:{bg:"rgba(107, 114, 128, 0.12)",fg:"#6b7280"},database:{bg:"rgba(168, 85, 247, 0.12)",fg:"#a855f7"},object:{bg:"rgba(14, 165, 233, 0.12)",fg:"#0ea5e9"},entry:{bg:"rgba(34, 197, 94, 0.12)",fg:"#22c55e"},other:{bg:"rgba(107, 114, 128, 0.08)",fg:"#9ca3af"}};function ap(e){let{category:t}=e,r={width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};switch(t){case"folder":return(0,n.jsx)("svg",{...r,children:(0,n.jsx)("path",{d:"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"})});case"image":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,n.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M10 13h4"}),(0,n.jsx)("path",{d:"M10 17h4"})]});case"code":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]});case"database":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]});case"object":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]});case"entry":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,n.jsx)("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),(0,n.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]});default:return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"})]})}}let am=(0,o.forwardRef)((e,t)=>{let{items:r,command:l,loading:a}=e,[s,i]=(0,o.useState)(0),c=(0,o.useRef)(null);(0,o.useEffect)(()=>{i(0)},[r]),(0,o.useEffect)(()=>{var e;let t=null==(e=c.current)?void 0:e.children[s];null==t||t.scrollIntoView({block:"nearest"})},[s]);let d=(0,o.useCallback)(e=>{let t=r[e];t&&l(t)},[r,l]);return((0,o.useImperativeHandle)(t,()=>({onKeyDown:e=>{let{event:t}=e;return"ArrowUp"===t.key?(i(e=>(e+r.length-1)%r.length),!0):"ArrowDown"===t.key?(i(e=>(e+1)%r.length),!0):("Enter"===t.key||"Tab"===t.key)&&(d(s),!0)}})),a)?(0,n.jsx)("div",{className:"rounded-xl py-3 px-4 shadow-xl",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",backdropFilter:"blur(12px)",minWidth:260},children:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"w-3.5 h-3.5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:"Searching..."})]})}):0===r.length?(0,n.jsx)("div",{className:"rounded-xl py-3 px-4 shadow-xl",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",backdropFilter:"blur(12px)",minWidth:260},children:(0,n.jsx)("span",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:"No results found"})}):(0,n.jsx)("div",{ref:c,className:"rounded-xl py-1 shadow-xl overflow-y-auto",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",backdropFilter:"blur(12px)",minWidth:280,maxWidth:400,maxHeight:300},children:r.map((e,t)=>{var r;let o=function(e,t){var r,n;if("folder"===t)return"folder";if("database"===t)return"database";if("object"===t)return"object";if("entry"===t)return"entry";let o=null!=(n=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?n:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(o)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(o)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(o)?"audio":"pdf"===o?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(o)?"code":"document"===t?"document":"other"}(e.name,e.type),l=null!=(r=ah[o])?r:ah.other,a=e.icon&&RegExp("\\p{Emoji_Presentation}","u").test(e.icon),c="object"===e.type||"entry"===e.type,u="entry"===e.type&&e.objectName?e.objectName:c?e.type:e.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Z]:\\Users\\[^\\]+/,"~");return(0,n.jsxs)("button",{type:"button",className:"w-full flex items-center gap-2.5 px-3 py-1.5 text-left transition-colors",style:{background:t===s?"var(--color-surface-hover)":"transparent"},onClick:()=>d(t),onMouseEnter:()=>i(t),children:[(0,n.jsx)("div",{className:"w-6 h-6 rounded-md flex items-center justify-center flex-shrink-0",style:{background:l.bg,color:l.fg},children:a?(0,n.jsx)("span",{className:"text-[13px] leading-none",children:e.icon}):(0,n.jsx)(ap,{category:o})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-[12px] font-medium truncate",style:{color:"var(--color-text)"},children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] truncate flex items-center gap-1",style:{color:"var(--color-text-muted)"},title:c?u:e.path,children:[c&&(0,n.jsx)("span",{className:"inline-block rounded px-1 py-px text-[9px] font-medium leading-tight",style:{background:l.bg,color:l.fg},children:e.type}),u]})]}),"folder"===e.type&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-40",children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})]},e.path)})})});function af(e){let{items:t,command:r,clientRect:l,componentRef:a,loading:i}=e,c=(0,o.useRef)(null);return(0,o.useLayoutEffect)(()=>{if(!c.current||!l)return;let e=l();if(!e)return;let t=c.current,r=t.offsetHeight||200;window.innerHeight-e.bottom<r+8?(t.style.position="fixed",t.style.left="".concat(e.left,"px"),t.style.bottom="".concat(window.innerHeight-e.top+4,"px"),t.style.top="auto"):(t.style.position="fixed",t.style.left="".concat(e.left,"px"),t.style.top="".concat(e.bottom+4,"px"),t.style.bottom="auto"),t.style.zIndex="100"},[l,t,i]),(0,s.createPortal)((0,n.jsx)("div",{ref:c,children:(0,n.jsx)(am,{ref:a,items:t,command:r,loading:i})}),document.body)}function av(e){if(!e)return{text:"",mentionedFiles:[]};let t=[],r=[];return e.state.doc.forEach(e=>{if("paragraph"===e.type.name||"hardBreak"===e.type.name){let n="";e.descendants(e=>{if("chatFileMention"===e.type.name){let r=e.attrs.label,o=e.attrs.path,l=e.attrs.mentionType,a=e.attrs.objectName;return t.push({name:r,path:o}),"object"===l?n+="[object: ".concat(r,"]"):"entry"===l?n+="[entry: ".concat(a?"".concat(a,"/"):"").concat(r,"]"):n+="[file: ".concat(o,"]"),!1}return e.isText&&e.text&&(n+=e.text),"hardBreak"===e.type.name&&(n+="\n"),!0}),r.push(n)}}),{text:r.join("\n").trim(),mentionedFiles:t}}am.displayName="FileMentionList";let ag=(0,o.forwardRef)(function(e,t){let{onSubmit:l,onChange:a,onNativeFileDrop:s,placeholder:i,disabled:c,compact:d}=e,u=(0,o.useRef)(l);u.current=l;let x=(0,o.useRef)(s);x.current=s;let h=(0,o.useRef)(null),p=(0,nG.hG)({immediatelyRender:!1,extensions:[nZ.A.configure({heading:!1,codeBlock:!1,blockquote:!1,horizontalRule:!1,bulletList:!1,orderedList:!1,listItem:!1}),n6.A.configure({placeholder:null!=i?i:"Ask anything...",showOnlyWhenEditable:!1}),ax,ad.YY.create({name:"chatFileMentionSuggestion",addProseMirrorPlugins(){return[(0,ac.Ay)({editor:this.editor,char:"@",pluginKey:au,startOfLine:!1,allowSpaces:!0,command:e=>{var t;let{editor:r,range:n,props:o}=e;if("folder"===o.type){let e=o.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Z]:\\Users\\[^\\]+/,"~");r.chain().focus().deleteRange(n).insertContent("@".concat(e,"/")).run();return}let l="object"===o.type?"object":"entry"===o.type?"entry":"file";r.chain().focus().deleteRange(n).insertContent([{type:"chatFileMention",attrs:{label:o.name,path:o.path,mentionType:l,objectName:null!=(t=o.objectName)?t:""}},{type:"text",text:" "}]).run()},items:e=>{let{query:t}=e;return[]},render:()=>{let e=null,t=null,o={current:null},l="",a=[],s=!1,i=null,c=null,d=null;function u(){t&&c&&t.render((0,n.jsx)(af,{items:a,command:c,clientRect:d,componentRef:o,loading:s}))}async function x(e){s=!0,u();try{var t;let r=e.startsWith("/")||e.startsWith("~/")||e.startsWith("../")||e.startsWith("./")||e.includes("/")?"path=".concat(encodeURIComponent(e)):e?"q=".concat(encodeURIComponent(e)):"",n=await fetch("/api/workspace/suggest-files".concat(r?"?".concat(r):""));a=null!=(t=(await n.json()).items)?t:[]}catch(e){a=[]}s=!1,u()}function h(e){i&&clearTimeout(i),i=setTimeout(()=>{x(e)},120)}return{onStart:n=>{var o;e=document.createElement("div"),document.body.appendChild(e),c=n.command,d=null!=(o=n.clientRect)?o:null,l=n.query,Promise.resolve().then(r.t.bind(r,80282,19)).then(r=>{let{createRoot:n}=r;t=n(e),h(l)})},onUpdate:e=>{var t;c=e.command,d=null!=(t=e.clientRect)?t:null,h(l=e.query)},onKeyDown:r=>{var n,l;if("Escape"===r.event.key)return null==t||t.unmount(),null==e||e.remove(),e=null,t=null,!0;let a=null!=(l=null==(n=o.current)?void 0:n.onKeyDown(r))&&l;return a&&r.event.stopImmediatePropagation(),a},onExit:()=>{i&&clearTimeout(i),null==t||t.unmount(),null==e||e.remove(),e=null,t=null}}}})]}})],editorProps:{attributes:{class:"chat-editor-content ".concat(d?"chat-editor-compact":""),style:"color: var(--color-text);"},handleKeyDown:(e,t)=>("Enter"===t.key&&!t.shiftKey,!1),handleDOMEvents:{paste:(e,t)=>{let r=t.clipboardData;if(!r)return!1;let n=[];if(r.items){for(let e of Array.from(r.items))if("file"===e.kind){let t=e.getAsFile();t&&n.push(t)}}if(n.length>0){var o;t.preventDefault();let e=new DataTransfer;for(let t of n)e.items.add(t);return null==(o=x.current)||o.call(x,e.files),!0}return!1},dragover:(e,t)=>{var r,n;return!!((null==(r=t.dataTransfer)?void 0:r.types.includes("application/x-file-mention"))||(null==(n=t.dataTransfer)?void 0:n.types.includes("Files")))&&(t.preventDefault(),t.dataTransfer.dropEffect="copy",!0)},drop:(e,t)=>{var r,n,o,l;let a=null==(r=t.dataTransfer)?void 0:r.getData("application/x-file-mention");if(a){t.preventDefault(),t.stopPropagation();try{let{name:e,path:t}=JSON.parse(a);e&&t&&(null==(o=h.current)||o.chain().focus().insertContent([{type:"chatFileMention",attrs:{label:e,path:t}},{type:"text",text:" "}]).run())}catch(e){}return!0}let s=null==(n=t.dataTransfer)?void 0:n.files;return!!s&&s.length>0&&(t.preventDefault(),t.stopPropagation(),null==(l=x.current)||l.call(x,s),!0)}}},onUpdate:e=>{let{editor:t}=e;null==a||a(t.isEmpty)}});return(0,o.useEffect)(()=>{h.current=null!=p?p:null},[p]),(0,o.useEffect)(()=>{if(!p)return;let e=e=>{if("Enter"===e.key&&!e.shiftKey&&!e.isComposing){let t=au.getState(p.state);if(null==t?void 0:t.active)return;e.preventDefault();let{text:r,mentionedFiles:n}=av(p);if(r.trim()||n.length>0){let e=p.getHTML();u.current(r,n,e),p.commands.clearContent(!0)}}},t=p.view.dom;return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[p]),(0,o.useEffect)(()=>{p&&p.setEditable(!c)},[p,c]),(0,o.useImperativeHandle)(t,()=>({insertFileMention:(e,t)=>{null==p||p.chain().focus().insertContent([{type:"chatFileMention",attrs:{label:e,path:t}},{type:"text",text:" "}]).run()},clear:()=>{null==p||p.commands.clearContent(!0)},focus:()=>{null==p||p.commands.focus()},isEmpty:()=>{var e;return null==(e=null==p?void 0:p.isEmpty)||e},submit:()=>{if(!p)return;let{text:e,mentionedFiles:t}=av(p);if(e.trim()||t.length>0){let r=p.getHTML();u.current(e,t,r),p.commands.clearContent(!0)}},setText:e=>{null==p||p.commands.setContent(e),null==p||p.commands.focus("end")}})),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(nG.$Z,{editor:p}),(0,n.jsx)("style",{children:"\n .chat-editor-content {\n outline: none;\n min-height: ".concat(d?"16px":"28px",";\n max-height: 200px;\n overflow-y: auto;\n padding: ").concat(d?"10px 12px":"14px 16px",";\n font-size: ").concat(d?"12px":"14px",';\n line-height: 1.5;\n transition: opacity 0.15s ease;\n }\n .chat-editor-content[contenteditable="false"] {\n opacity: 0.5;\n cursor: not-allowed;\n }\n .chat-editor-content p {\n margin: 0;\n }\n .chat-editor-content p.is-editor-empty:first-child::before {\n content: attr(data-placeholder);\n color: var(--color-text-muted);\n float: left;\n height: 0;\n pointer-events: none;\n }\n /* File mention pill styles */\n .chat-editor-content span[data-chat-file-mention] {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n padding: 1px 8px 1px 6px;\n margin: 0 1px;\n border-radius: 6px;\n background: var(--mention-bg, rgba(59, 130, 246, 0.12));\n color: var(--mention-fg, #3b82f6);\n font-size: 12px;\n font-weight: 500;\n line-height: 1.6;\n vertical-align: baseline;\n cursor: default;\n user-select: all;\n white-space: nowrap;\n transition: opacity 0.15s ease;\n }\n .chat-editor-content span[data-chat-file-mention]::before {\n content: "@";\n opacity: 0.5;\n font-size: 11px;\n }\n .chat-editor-content span[data-chat-file-mention]:hover {\n opacity: 0.85;\n }\n .chat-editor-content.chat-editor-compact {\n min-height: 16px;\n }\n ')})]})}),ay=[{id:"email-draft",label:"Draft an Email",icon:ll.A,prompt:"Draft a professional follow-up email to a client after our initial meeting, thanking them and summarizing the next steps we discussed"},{id:"enrich-contacts",label:"Enrich Leads",icon:la.A,prompt:"When a new contact is added to my CRM, find their LinkedIn profile and company details and update the record"},{id:"invoice-reminder",label:"Invoice Reminder",icon:ls.A,prompt:"Draft a friendly payment reminder email for an invoice that is 7 days overdue, including the invoice number and amount"},{id:"schedule-report",label:"Weekly Report",icon:li.A,prompt:"Set up a cron job that runs every Friday at 4pm to compile a summary of all completed tasks this week and email it to the team"},{id:"auto-tasks",label:"Auto Tasks",icon:lc.A,prompt:"Create a workflow that automatically creates a task whenever someone mentions me in an email with a request or action item"},{id:"summarize-docs",label:"Summarize Docs",icon:ld.A,prompt:"Read through all the documents in my workspace and create a concise summary of the key information across all files"},{id:"query-data",label:"Query Database",icon:lu.A,prompt:"Connect to my database and show me the top 10 customers by revenue this quarter, including their contact details"},{id:"code-review",label:"Review Code",icon:lx.A,prompt:"Review the code in my workspace for potential bugs, security issues, and performance improvements. Prioritize critical findings"},{id:"debug-error",label:"Debug Error",icon:lh.A,prompt:"Help me debug this error I'm seeing in production. Walk me through the likely causes and how to fix each one"},{id:"daily-digest",label:"Daily Digest",icon:lp.A,prompt:"Set up a daily digest that runs every morning at 9am summarizing my unread emails, calendar events, and pending tasks"},{id:"analyze-csv",label:"Analyze Data",icon:lm.A,prompt:"Analyze the CSV file in my workspace — find trends, outliers, and generate a visual report with key insights"},{id:"write-content",label:"Write Content",icon:lf.A,prompt:"Write a compelling blog post about how AI automation is transforming small business operations in 2026"},{id:"web-research",label:"Web Research",icon:lv.A,prompt:"Research the top 5 competitors in my industry and create a comparison table with their pricing, features, and market position"},{id:"search-files",label:"Search Files",icon:lg.A,prompt:"Search through all files in my workspace and find every mention of customer feedback, complaints, or feature requests"},{id:"brainstorm",label:"Brainstorm Ideas",icon:ly.A,prompt:"Help me brainstorm 10 creative marketing campaign ideas for launching a new product to our existing customer base"},{id:"organize-files",label:"Organize Files",icon:lb.A,prompt:"Look at all the files in my workspace and suggest a better folder structure. Then reorganize them for me"},{id:"create-spreadsheet",label:"Build Spreadsheet",icon:lj.A,prompt:"Create a project tracking spreadsheet with columns for task name, assignee, status, priority, due date, and notes"},{id:"ai-strategy",label:"AI Strategy",icon:lk.A,prompt:"Help me create an AI adoption strategy for my team — which tasks should we automate first for the biggest impact?"},{id:"meeting-prep",label:"Meeting Prep",icon:lw.A,prompt:"Prepare a briefing document for my upcoming client meeting. Include their recent activity, open issues, and talking points"},{id:"build-workflow",label:"Build Workflow",icon:lN.A,prompt:"Design an automated onboarding workflow for new clients — from welcome email to document collection to account setup"}];function ab(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(n)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(n)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(n)?"audio":"pdf"===n?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(n)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv","pages","numbers","key"].includes(n)?"document":"other"}let aj={image:{bg:"rgba(16, 185, 129, 0.12)",fg:"#10b981"},video:{bg:"rgba(139, 92, 246, 0.12)",fg:"#8b5cf6"},audio:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},pdf:{bg:"rgba(239, 68, 68, 0.12)",fg:"#ef4444"},code:{bg:"rgba(59, 130, 246, 0.12)",fg:"#3b82f6"},document:{bg:"rgba(107, 114, 128, 0.12)",fg:"#6b7280"},other:{bg:"rgba(107, 114, 128, 0.08)",fg:"#9ca3af"}};function ak(e){let{category:t}=e,r={width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};switch(t){case"image":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,n.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M10 13h4"}),(0,n.jsx)("path",{d:"M10 17h4"})]});case"code":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]});case"document":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"}),(0,n.jsx)("path",{d:"M10 9H8"})]});default:return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"})]})}}function aw(e){let{msg:t,idx:r,onEdit:l,onSendNow:a,onRemove:s}=e,[i,c]=(0,o.useState)(!1),[d,u]=(0,o.useState)(t.text),x=(0,o.useRef)(null),h=()=>{let e=x.current;e&&(e.style.height="auto",e.style.height="".concat(e.scrollHeight,"px"))};(0,o.useEffect)(()=>{if(i){var e,t,r,n;null==(e=x.current)||e.focus();let o=null!=(n=null==(t=x.current)?void 0:t.value.length)?n:0;null==(r=x.current)||r.setSelectionRange(o,o),h()}},[i]);let p=()=>{let e=d.trim();e&&e!==t.text?l(t.id,e):u(t.text),c(!1)};return(0,n.jsxs)("div",{className:"flex items-start gap-2.5 group py-2 ".concat(r>0?"border-t":""),style:r>0?{borderColor:"var(--color-border)"}:void 0,children:[(0,n.jsx)("span",{className:"shrink-0 mt-px text-[11px] font-medium tabular-nums w-4",style:{color:"var(--color-text-muted)"},children:r+1}),i?(0,n.jsx)("textarea",{ref:x,className:"flex-1 text-[13px] leading-[1.45] min-w-0 resize-none rounded-md px-2 py-1 outline-none",style:{color:"var(--color-text-secondary)",background:"var(--color-bg)",border:"1px solid var(--color-border)"},rows:1,value:d,onChange:e=>{u(e.target.value),h()},onBlur:p,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),p()),"Escape"===e.key&&(u(t.text),c(!1))}}):(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[t.attachedFiles.length>0&&(0,n.jsx)("div",{className:"flex gap-1 shrink-0",children:t.attachedFiles.map(e=>{let t="image"===ab(e.name)?e.localUrl||"/api/workspace/raw-file?path=".concat(encodeURIComponent(e.path)):e.path?"/api/workspace/thumbnail?path=".concat(encodeURIComponent(e.path),"&size=100"):void 0;return(0,n.jsx)("img",{src:t,alt:e.name,className:"rounded object-cover",style:{height:28,width:28,background:"var(--color-surface-hover)"},onError:e=>{e.currentTarget.style.display="none"}},e.id)})}),(0,n.jsx)("p",{className:"text-[13px] leading-[1.45] line-clamp-1 min-w-0",style:{color:"var(--color-text-secondary)"},children:t.text||"".concat(t.attachedFiles.length," ").concat(1===t.attachedFiles.length?"file":"files")})]}),!i&&(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Edit message",onClick:()=>{u(t.text),c(!0)},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,n.jsx)("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,n.jsx)("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})]})}),(0,n.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Send now",onClick:()=>a(t.id),children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,n.jsx)("path",{d:"M12 19V5"}),(0,n.jsx)("path",{d:"m5 12 7-7 7 7"})]})}),(0,n.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Remove from queue",onClick:()=>s(t.id),children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})})]})]})}function aN(e){let{files:t,compact:r,onRemove:o,onClearAll:l}=e;return 0===t.length?null:(0,n.jsx)("div",{className:"".concat(r?"px-2":"px-3"," pt-2"),children:(0,n.jsx)("div",{className:"flex gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"thin"},children:t.map(e=>{var t;let r=ab(e.name),l=null!=(t=aj[r])?t:aj.other,a=e.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Z]:\\Users\\[^\\]+/,"~");return(0,n.jsxs)("div",{className:"relative group flex-shrink-0 rounded-xl overflow-hidden",style:{background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>o(e.id),className:"absolute top-1 right-1 z-10 w-[18px] h-[18px] rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",style:{background:"rgba(0,0,0,0.55)",color:"white",backdropFilter:"blur(4px)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}),"image"===r?(0,n.jsx)("img",{src:e.localUrl||"/api/workspace/raw-file?path=".concat(encodeURIComponent(e.path)),alt:e.name,className:"block rounded-xl object-cover",style:{height:80,width:"auto",minWidth:60,maxWidth:140,opacity:e.uploading?.6:1,background:"var(--color-bg-secondary)"},onError:e=>{e.currentTarget.style.display="none"}}):"pdf"===r&&e.path?(0,n.jsx)("img",{src:"/api/workspace/thumbnail?path=".concat(encodeURIComponent(e.path),"&size=200"),alt:e.name,className:"block rounded-xl object-cover",style:{height:80,width:"auto",minWidth:60,maxWidth:140,opacity:e.uploading?.6:1,background:"var(--color-bg-secondary)"},onError:e=>{e.currentTarget.style.display="none"}}):(0,n.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2.5",style:{opacity:e.uploading?.6:1},children:[(0,n.jsx)("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:l.bg,color:l.fg},children:(0,n.jsx)(ak,{category:r})}),(0,n.jsxs)("div",{className:"min-w-0 max-w-[140px]",children:[(0,n.jsx)("p",{className:"text-[11px] font-medium truncate",style:{color:"var(--color-text)"},title:e.path||e.name,children:e.name}),(0,n.jsx)("p",{className:"text-[9px] truncate",style:{color:"var(--color-text-muted)"},title:e.path||e.name,children:e.uploading?"Uploading...":a})]})]})]},e.id)})})})}let aC=(0,o.forwardRef)(function(e,t){var r,l;let{fileContext:a,compact:s,sessionTitle:i,initialSessionId:c,onFileChanged:d,onActiveSessionChange:u,onSessionsChange:x,onSubagentSpawned:h,onSubagentClick:p,onFilePathClick:m,onDeleteSession:f,onRenameSession:v,sessionKey:g,subagentTask:y,subagentLabel:b,onBack:j}=e,k=!!g,w=(0,o.useRef)(null),[N,C]=(0,o.useState)(!0),[S,M]=(0,o.useState)(null),[L,T]=(0,o.useState)(!1),D=(0,o.useRef)(null),[E,R]=(0,o.useState)([]),[W,I]=(0,o.useState)(!1),[B,F]=(0,o.useState)(!1),A=(0,o.useRef)(null),[P,_]=(0,o.useState)(null),z=(0,o.useRef)(new Set),O=(0,o.useRef)(!1),U=(0,o.useRef)(!0),[H,V]=(0,o.useState)([]),J=(0,o.useRef)(new Map),K=(0,o.useRef)(null),[q,$]=(0,o.useState)([]),[Z,Y]=(0,o.useState)(!1),[Q,X]=(0,o.useState)(""),[ee,et]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=[(()=>{let e=new Date().getHours();return e<12?"Good morning!":e<17?"Good afternoon!":"Good evening!"})(),"Ready to build?","Let's automate something?","What shall we tackle?","Ready to get things done?","Let's get to work?","How can I help?"];X(e[Math.floor(Math.random()*e.length)])},[]),(0,o.useEffect)(()=>{et([...ay].sort(()=>.5-Math.random()).slice(0,7))},[]);let er=(0,o.useCallback)(e=>{var t;let r=ay.find(t=>t.id===e);r&&(null==(t=w.current)||t.setText(r.prompt),C(!1))},[]),en=null!=(r=null==a?void 0:a.path)?r:null,eo=(0,o.useRef)(null);(0,o.useEffect)(()=>{eo.current=S},[S]);let el=(0,o.useRef)(g);(0,o.useEffect)(()=>{el.current=g},[g]);let ea=(0,o.useMemo)(()=>new lr.rL({api:"/api/chat",body:()=>{let e={},t=el.current;t&&(e.sessionKey=t);let r=eo.current;return r&&(e.sessionId=r),K.current&&(e.userHtml=K.current,K.current=null),e}}),[]),{messages:es,sendMessage:ei,status:ec,stop:ed,error:eu,setMessages:ex}=(0,lt.Y_)({transport:ea}),eh="streaming"===ec||"submitted"===ec||B,ep=(0,o.useRef)(null);(0,o.useEffect)(()=>(ep.current&&(clearTimeout(ep.current),ep.current=null),"submitted"===ec&&(ep.current=setTimeout(()=>{ep.current=null,"submitted"===ec&&(_("Request timed out — no response from agent. Try again or check the gateway."),ed())},9e4)),()=>{ep.current&&(clearTimeout(ep.current),ep.current=null)}),[ec,ed]);let em=(0,o.useRef)(null),ef=(0,o.useRef)(!1),ev=(0,o.useRef)(0);(0,o.useEffect)(()=>{let e=em.current;if(!e)return;let t=()=>{ef.current=e.scrollHeight-e.scrollTop-e.clientHeight>80};return e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)},[]),(0,o.useEffect)(()=>{!ef.current&&(ev.current||(ev.current=requestAnimationFrame(()=>{var e;ev.current=0,null==(e=D.current)||e.scrollIntoView({behavior:"smooth"})})))},[es]);let eg=(0,o.useCallback)(async e=>{let t={title:e};en&&(t.filePath=en);let r=await fetch("/api/web-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return(await r.json()).session.id},[en]),ey=(0,o.useCallback)(async(e,t,r)=>{let n=new AbortController;A.current=n;try{let o=(null==r?void 0:r.sessionKey)?"sessionKey=".concat(encodeURIComponent(r.sessionKey)):"sessionId=".concat(encodeURIComponent(e)),l=await fetch("/api/chat/stream?".concat(o),{signal:n.signal});if(!l.ok||!l.body)return!1;if("false"===l.headers.get("X-Run-Active"))return l.body.cancel(),!1;F(!0);let a=function(){let e=[],t=-1,r=-1;return{processEvent:function(n){var o,l,a,s;switch(n.type){case"user-message":t=-1,r=-1,e.push({type:"user-message",id:n.id,text:null!=(o=n.text)?o:""});break;case"reasoning-start":e.push({type:"reasoning",text:"",state:"streaming"}),r=e.length-1;break;case"reasoning-delta":if(r>=0){let t=e[r];t.text+=n.delta}break;case"reasoning-end":if(r>=0){let t=e[r];delete t.state}r=-1;break;case"text-start":e.push({type:"text",text:""}),t=e.length-1;break;case"text-delta":if(t>=0){let r=e[t];r.text+=n.delta}break;case"text-end":t=-1;break;case"tool-input-start":e.push({type:"dynamic-tool",toolCallId:n.toolCallId,toolName:n.toolName,state:"input-available",input:{}});break;case"tool-input-available":for(let t=e.length-1;t>=0;t--){let r=e[t];if("dynamic-tool"===r.type&&r.toolCallId===n.toolCallId){r.input=null!=(l=n.input)?l:{};break}}break;case"tool-output-partial":for(let t=e.length-1;t>=0;t--){let r=e[t];if("dynamic-tool"===r.type&&r.toolCallId===n.toolCallId){r.output=null!=(a=n.output)?a:{};break}}break;case"tool-output-available":for(let t=e.length-1;t>=0;t--){let r=e[t];if("dynamic-tool"===r.type&&r.toolCallId===n.toolCallId){r.state="output-available",r.output=null!=(s=n.output)?s:{};break}}break;case"tool-output-error":for(let t=e.length-1;t>=0;t--){let r=e[t];if("dynamic-tool"===r.type&&r.toolCallId===n.toolCallId){r.state="error",r.output={error:n.errorText};break}}}},getParts:()=>e.map(e=>({...e}))}}(),s=l.body.getReader(),i=new TextDecoder,c="reconnect-".concat(e),d="",u=!1,x=()=>{if(n.signal.aborted)return;let e={id:c,role:"assistant",parts:a.getParts()};ex([...t,e])};for(;;){let e,{done:t,value:r}=await s.read();if(t)break;for(d+=i.decode(r,{stream:!0});-1!==(e=d.indexOf("\n\n"));){let t=d.slice(0,e);if(d=d.slice(e+2),t.startsWith("data: "))try{let e=JSON.parse(t.slice(6));a.processEvent(e)}catch(e){}}u||(u=!0,requestAnimationFrame(()=>{u=!1,x()}))}if(x(),!n.signal.aborted){for(let e of t)z.current.add(e.id);z.current.add(c)}return F(!1),A.current=null,!0}catch(e){return"AbortError"!==e.name&&console.error("Reconnection error:",e),F(!1),A.current=null,!1}},[ex]),eb=(0,o.useRef)(null);eb.current=async()=>{if(!en)return[];try{let e=await fetch("/api/web-sessions?filePath=".concat(encodeURIComponent(en)));return(await e.json()).sessions||[]}catch(e){return[]}},(0,o.useEffect)(()=>{if(!en||k)return;let e=!1;return eo.current=null,M(null),null==u||u(null),ex([]),z.current.clear(),U.current=!0,(async()=>{var t,r,n;let o=null!=(r=await (null==(t=eb.current)?void 0:t.call(eb)))?r:[];if(!e&&(V(o),o.length>0)){let t=null!=(n=c?o.find(e=>e.id===c):void 0)?n:o[0];M(t.id),eo.current=t.id,null==u||u(t.id),U.current=!1;try{let r=await fetch("/api/web-sessions/".concat(t.id));if(e)return;let n=(await r.json()).messages||[],o=n.some(e=>e._streaming)?n.filter(e=>!e._streaming):n;for(let e of o)"user"===e.role&&e.html&&J.current.set(e.id,e.html);let l=o.map(e=>{var t;return z.current.add(e.id),{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}});e||ex(l),e||await ey(t.id,l)}catch(e){}}})(),()=>{e=!0}},[en,ey]);let ej=(0,o.useRef)(!1),ek=(0,o.useRef)(null);(0,o.useEffect)(()=>{!en&&!k&&c&&(ej.current&&c===ek.current||(ej.current=!0,ek.current=c,eT(c)))},[c]),(0,o.useEffect)(()=>{var e;if(!g||!y)return;let t=!1;null==(e=A.current)||e.abort(),ed(),z.current.clear(),$([]);let r={id:"task-".concat(g),role:"user",parts:[{type:"text",text:y}]};return ex([r]),(async()=>{if(t)return;let e=[r];try{let n=await fetch("/api/web-sessions/".concat(encodeURIComponent(g)));if(t)return;if(n.ok){let o=(await n.json()).messages||[],l=o.some(e=>e._streaming)?o.filter(e=>!e._streaming):o;if(l.length>0){for(let e of l)"user"===e.role&&e.html&&J.current.set(e.id,e.html);let n=l.map(e=>{var t;return z.current.add(e.id),{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}});e=[r,...n],t||ex(e)}}}catch(e){}t||await ey(g,e,{sessionKey:g})})(),()=>{var e;t=!0,null==(e=A.current)||e.abort()}},[g,y,ey]);let[ew,eN]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!S||!h)return;let e=!1,t=async()=>{try{var t;let r=await fetch("/api/chat/subagents?sessionId=".concat(encodeURIComponent(S)));if(e||!r.ok)return;let n=null!=(t=(await r.json()).subagents)?t:[],o=!1;for(let e of n)"running"===e.status&&(o=!0),h({childSessionKey:e.sessionKey,runId:e.runId,task:e.task,label:e.label,parentSessionId:S,status:e.status});e||eN(o)}catch(e){}};t();let r=setInterval(t,3e3);return()=>{e=!0,clearInterval(r)}},[S,h]);let eC=(0,o.useRef)(ec);(0,o.useEffect)(()=>{let e="streaming"===eC.current||"submitted"===eC.current,t="ready"===ec;if(e&&t&&S){for(let e of es)z.current.add(e.id);if(en){var r;null==(r=eb.current)||r.call(eb).then(e=>{V(e)})}en&&d&&fetch("/api/workspace/file?path=".concat(encodeURIComponent(en))).then(e=>e.json()).then(e=>{e.content&&d(e.content)}).catch(()=>{}),null==x||x()}eC.current=ec},[ec,es,S,en,d,x]),(0,o.useEffect)(()=>{let e="streaming"===eC.current||"submitted"===eC.current,t="ready"===ec;if(e&&t){let e=es[es.length-1];(null==e?void 0:e.role)==="assistant"&&e.parts.some(e=>"text"===e.type&&e.text.trim().length>0||"tool-invocation"===e.type)||eu?_(null):_("No response received from agent.")}"submitted"===ec&&_(null)},[ec,es,eu]);let eS=(0,o.useRef)(()=>{}),eM=(0,o.useCallback)(async(e,t,r,n)=>{let o=e.trim().length>0,l=t.length>0,s=n?n.filter(e=>!e.uploading&&e.path):E.filter(e=>!e.uploading&&e.path),i=s.length>0;if(!o&&!l&&!i)return;let c=e.trim(),d=[...s];if("/new"===c.toLowerCase()){for(let e of E)e.localUrl&&URL.revokeObjectURL(e.localUrl);R([]),eS.current();return}if(eh){n||R([]),$(e=>[...e,{id:crypto.randomUUID(),text:c,html:r,mentionedFiles:t,attachedFiles:d,createdAt:Date.now()}]);return}if(!n&&d.length>0){for(let e of E)e.localUrl&&URL.revokeObjectURL(e.localUrl);R([])}let h=S;if(!h&&!k){let e=c||"File attachment",t=e.length>60?e.slice(0,60)+"...":e;if(M(h=await eg(t)),eo.current=h,null==u||u(h),null==x||x(),en){var p;null==(p=eb.current)||p.call(eb).then(e=>{V(e)})}}let m=c,f=[...t.map(e=>e.path),...d.map(e=>e.path)];if(f.length>0){let e="[Attached files: ".concat(f.join(", "),"]");m=m?"".concat(e,"\n\n").concat(m):e}if(a&&U.current){let e=a.isDirectory?"directory":"file";m="[Context: workspace ".concat(e," '").concat(a.path,"']\n\n").concat(m),U.current=!1}J.current.set(m,r),K.current=r,ef.current=!1,ei({text:m})},[E,eh,S,eg,u,x,en,a,ei]),eL=(0,o.useRef)(ec);(0,o.useEffect)(()=>{let e="streaming"===eL.current||"submitted"===eL.current,t="ready"===ec;if(eL.current=ec,e&&t&&q.length>0){let[e,...t]=q;for(let r of($(t),e.attachedFiles))r.localUrl&&URL.revokeObjectURL(r.localUrl);queueMicrotask(()=>{eM(e.text,e.mentionedFiles,e.html,e.attachedFiles)})}},[ec,q,eM]);let eT=(0,o.useCallback)(async e=>{var t;if(e!==S){null==(t=A.current)||t.abort(),ed(),T(!0),M(e),eo.current=e,null==u||u(e),z.current.clear(),U.current=!1,$([]);try{let t=await fetch("/api/web-sessions/".concat(e));if(!t.ok)throw Error("Failed to load session");let r=(await t.json()).messages||[],n=r.some(e=>e._streaming)?r.filter(e=>!e._streaming):r;for(let e of(J.current.clear(),n))"user"===e.role&&e.html&&J.current.set(e.id,e.html);let o=n.map(e=>{var t;return z.current.add(e.id),{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}});ex(o),T(!1),await ey(e,o)}catch(e){console.error("Error loading session:",e),T(!1)}}},[S,ex,u,ed,ey]),eD=(0,o.useCallback)(()=>{var e;null==(e=A.current)||e.abort(),ed(),F(!1),M(null),eo.current=null,null==u||u(null),ex([]),z.current.clear(),J.current.clear(),U.current=!0,O.current=!1,$([]),requestAnimationFrame(()=>{var e;null==(e=w.current)||e.focus()})},[ex,u,ed]);eS.current=eD,(0,o.useImperativeHandle)(t,()=>({loadSession:eT,newSession:async()=>{eD()},sendNewMessage:async e=>{eD();let t=e.length>60?e.slice(0,60)+"...":e,r=await eg(t);M(r),eo.current=r,null==u||u(r),null==x||x(),ef.current=!1,ei({text:e})},insertFileMention:(e,t)=>{var r;null==(r=w.current)||r.insertFileMention(e,t)}}),[eT,eD,eg,u,x,ei]);let eE=(0,o.useCallback)(async()=>{var e;if(null==(e=A.current)||e.abort(),F(!1),g||S)try{await fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g?{sessionKey:g}:{sessionId:S})})}catch(e){}ed()},[S,g,ed]),eR=(0,o.useCallback)(e=>{$(t=>t.filter(t=>t.id!==e))},[]),eW=(0,o.useCallback)((e,t)=>{$(r=>r.map(r=>r.id===e?{...r,text:t}:r))},[]),eI=(0,o.useCallback)(async e=>{let t=q.find(t=>t.id===e);t&&($(t=>t.filter(t=>t.id!==e)),await eE(),setTimeout(()=>{eM(t.text,t.mentionedFiles,t.html,t.attachedFiles)},100))},[q,eE,eM]),eB=(0,o.useCallback)(e=>{let t=e.map(e=>({id:"".concat(e.path,"-").concat(Date.now(),"-").concat(Math.random().toString(36).slice(2)),name:e.name,path:e.path}));R(e=>[...e,...t])},[]),eF=(0,o.useCallback)(e=>{R(t=>{let r=t.find(t=>t.id===e);return(null==r?void 0:r.localUrl)&&URL.revokeObjectURL(r.localUrl),t.filter(t=>t.id!==e)})},[]),eA=(0,o.useCallback)(()=>{R(e=>{for(let t of e)t.localUrl&&URL.revokeObjectURL(t.localUrl);return[]})},[]),eP=(0,o.useCallback)(e=>{let t=Array.from(e),r=t.map(e=>({id:"pending-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2)),name:e.name,path:"",uploading:!0,localUrl:URL.createObjectURL(e)}));R(e=>[...e,...r]);for(let e=0;e<t.length;e++){let n=t[e],o=r[e].id,l=r[e].localUrl,a=new FormData;a.append("file",n),fetch("/api/workspace/upload",{method:"POST",body:a}).then(e=>e.ok?e.json():null).then(e=>{(null==e?void 0:e.ok)&&e.path?R(t=>t.map(t=>t.id===o?{...t,path:e.path,uploading:!1}:t)):(R(e=>e.filter(e=>e.id!==o)),l&&URL.revokeObjectURL(l))}).catch(()=>{R(e=>e.filter(e=>e.id!==o)),l&&URL.revokeObjectURL(l)})}},[]),e_=es.length>0?es[es.length-1]:null,ez=(null==e_?void 0:e_.role)==="assistant"&&e_.parts.some(e=>"text"===e.type&&e.text.length>0),eO=eh&&!ez,eU=0===es.length&&!s&&!k&&!L,eH=(0,n.jsxs)(n.Fragment,{children:[q.length>0&&(0,n.jsx)("div",{className:s?"px-2 pt-2":"px-3 pt-3",children:(0,n.jsxs)("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",boxShadow:"var(--shadow-sm)"},children:[(0,n.jsxs)("div",{className:"px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:["Queue (",q.length,")"]}),(0,n.jsx)("div",{className:"flex flex-col p-2",children:q.map((e,t)=>(0,n.jsx)(aw,{msg:e,idx:t,onEdit:eW,onSendNow:eI,onRemove:eR},e.id))})]})}),!k&&(0,n.jsx)(aN,{files:E,compact:s,onRemove:eF,onClearAll:eA}),(0,n.jsx)(ag,{ref:w,onSubmit:eM,onChange:e=>C(e),onNativeFileDrop:k?void 0:eP,placeholder:eU?"Build a workflow to automate your tasks":k?eh?"Type to queue a message...":"Type @ to mention files...":s&&a?"Ask about ".concat(a.isDirectory?"this folder":a.filename,"..."):eh?"Type to queue a message...":E.length>0?"Add a message or send files...":"Type @ to mention files...",disabled:L,compact:s}),(0,n.jsxs)("div",{className:"flex items-center justify-between ".concat(s?"px-2 pb-1.5":"px-3 pb-2.5"),children:[(0,n.jsx)("div",{className:"flex items-center gap-0.5",children:!k&&(0,n.jsx)("button",{type:"button",onClick:()=>I(!0),className:"p-1.5 rounded-lg hover:opacity-80 transition-opacity",style:{color:E.length>0?"var(--color-accent)":"var(--color-text-muted)"},title:"Attach files",children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})})})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[eh&&(0,n.jsx)("button",{type:"button",onClick:()=>eE(),className:"".concat(s?"w-6 h-6":"w-7 h-7"," rounded-full flex items-center justify-center"),style:{background:"var(--color-text)",color:"var(--color-bg)"},title:"Stop generating",children:(0,n.jsx)("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"currentColor",children:(0,n.jsx)("rect",{width:"10",height:"10",rx:"1.5"})})}),eh?(0,n.jsxs)("button",{type:"button",onClick:()=>{var e;return null==(e=w.current)?void 0:e.submit()},disabled:N&&0===E.length||L,className:"h-7 px-3 rounded-full flex items-center gap-1.5 text-[12px] font-medium disabled:opacity-40 disabled:cursor-not-allowed",style:{background:!N||E.length>0?"var(--color-accent)":"var(--color-surface-hover)",color:!N||E.length>0?"white":"var(--color-text-muted)"},title:"Add to queue",children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"9 10 4 15 9 20"}),(0,n.jsx)("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"})]}),"Queue"]}):(0,n.jsx)("button",{type:"button",onClick:()=>{var e;return null==(e=w.current)?void 0:e.submit()},disabled:N&&0===E.length||L,className:"".concat(s?"w-6 h-6":"w-7 h-7"," rounded-full flex items-center justify-center disabled:opacity-50 disabled:cursor-not-allowed"),style:{background:!N||E.length>0?"var(--color-accent)":"var(--color-text-muted)",color:!N||E.length>0?"white":"var(--color-bg)"},title:"Send message",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 19V5"}),(0,n.jsx)("path",{d:"m5 12 7-7 7 7"})]})})]})]})]}),eV=(e,t,r)=>(0,n.jsx)("div",{"data-chat-drop-target":"",className:"rounded-3xl overflow-hidden border shadow-[0_0_32px_rgba(0,0,0,0.07)] transition-[outline,box-shadow] duration-150 ease-out data-drag-hover:outline-2 data-drag-hover:outline-dashed data-drag-hover:outline-(--color-accent) data-drag-hover:-outline-offset-2 data-drag-hover:shadow-[0_0_0_4px_color-mix(in_srgb,var(--color-accent)_15%,transparent),0_0_32px_rgba(0,0,0,0.07)]!",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},onDragOver:e,onDragLeave:t,onDrop:r,children:eH}),eJ=e=>{var t,r;((null==(t=e.dataTransfer)?void 0:t.types.includes("application/x-file-mention"))||(null==(r=e.dataTransfer)?void 0:r.types.includes("Files")))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy",e.currentTarget.setAttribute("data-drag-hover",""))},eK=e=>{e.currentTarget.contains(e.relatedTarget)||e.currentTarget.removeAttribute("data-drag-hover")},eq=e=>{var t,r,n;e.currentTarget.removeAttribute("data-drag-hover");let o=null==(t=e.dataTransfer)?void 0:t.getData("application/x-file-mention");if(o){e.preventDefault(),e.stopPropagation();try{let{name:e,path:t}=JSON.parse(o);e&&t&&(null==(n=w.current)||n.insertFileMention(e,t))}catch(e){}return}let l=null==(r=e.dataTransfer)?void 0:r.files;l&&l.length>0&&(e.preventDefault(),e.stopPropagation(),eP(l))};return(0,n.jsx)(ln.o,{children:(0,n.jsxs)("div",{className:"h-full flex flex-col",style:{background:"var(--color-main-bg)"},children:[(0,n.jsx)("header",{className:"".concat(s?"px-3 py-2":"px-3 py-2 md:px-6 md:py-3"," flex items-center ").concat(k?"gap-3":"justify-between"," z-20"),style:{background:"var(--color-bg-glass)"},children:k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:j,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Back to parent chat",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("h2",{className:"text-sm font-semibold truncate",style:{color:"var(--color-text)"},children:b||(y&&y.length>60?y.slice(0,60)+"...":y)}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:eh?(0,n.jsx)(G.V,{name:"braille"}):"Completed"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"min-w-0 flex-1",children:s&&a?(0,n.jsxs)("h2",{className:"text-xs font-semibold truncate",style:{color:"var(--color-text)"},children:["Chat: ",a.filename]}):(0,n.jsx)("h2",{className:"text-sm font-semibold",style:{color:"var(--color-text)"},children:S?i||"Chat Session":"New Chat"})}),(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[S&&f&&(0,n.jsxs)(oH,{children:[(0,n.jsx)(oV,{className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"More options","aria-label":"More options",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1"})]})}),(0,n.jsx)(oJ,{align:"end",side:"bottom",children:(0,n.jsxs)(oK,{variant:"destructive",onSelect:()=>f(S),children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]})})]}),s&&(0,n.jsx)("button",{type:"button",onClick:()=>eD(),className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"New chat",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]})})]})]})}),!k&&s&&a&&H.length>0&&(0,n.jsx)("div",{className:"px-2 py-1.5 border-b flex gap-1 overflow-x-auto z-20",style:{borderColor:"var(--color-border)",background:"var(--color-bg-glass)"},children:H.slice(0,10).map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>eT(e.id),className:"px-2.5 py-1 text-[10px] rounded-full whitespace-nowrap shrink-0 font-medium",style:{background:e.id===S?"var(--color-accent)":"var(--color-surface-hover)",color:e.id===S?"white":"var(--color-text-muted)",border:e.id===S?"none":"1px solid var(--color-border)"},children:e.title.length>25?e.title.slice(0,25)+"...":e.title},e.id))}),(0,n.jsxs)("div",{ref:em,className:"flex-1 overflow-y-auto min-h-0",children:[(0,n.jsx)("div",{className:s?"px-3":"px-6",children:L?(0,n.jsx)("div",{className:"flex items-center justify-center h-full min-h-[60vh]",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(G.V,{name:"braille",className:"block text-2xl mx-auto mb-3",style:{color:"var(--color-text-muted)"}}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading session..."})]})}):eU?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[75vh] py-12",children:[Q&&(0,n.jsx)(lo.P.h1,{className:"text-4xl md:text-5xl font-light tracking-normal font-instrument mb-10 text-center",style:{color:"var(--color-text)"},initial:"hidden",animate:"visible",variants:{hidden:{opacity:0},visible:{opacity:1,transition:{staggerChildren:.12,delayChildren:.2}}},children:Q.split(" ").map((e,t)=>(0,n.jsx)(lo.P.span,{className:"inline-block mr-2",variants:{hidden:{opacity:0,y:20,filter:"blur(8px)"},visible:{opacity:1,y:0,filter:"blur(0px)",transition:{duration:.8,ease:[.2,.65,.3,.9]}}},children:e},t))}),(0,n.jsx)(lo.P.div,{className:"w-full max-w-[720px] mx-auto px-4",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.8,delay:.8,ease:[.22,1,.36,1]},children:(0,n.jsx)(lo.P.div,{layout:!0,layoutId:"chat-input-bar",transition:{type:"spring",stiffness:260,damping:30},children:eV(eJ,eK,eq)})}),(0,n.jsxs)(lo.P.div,{className:"mt-6 flex flex-col gap-2.5 w-full max-w-[720px] mx-auto px-4",initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5,delay:1,ease:[.22,1,.36,1]},children:[(0,n.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:ee.slice(0,3).map(e=>{let t=e.icon;return(0,n.jsxs)("button",{type:"button",onClick:()=>er(e.id),className:"group flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium whitespace-nowrap rounded-xl transition-all duration-200 border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-secondary)"},children:[(0,n.jsx)(t,{className:"w-3.5 h-3.5 opacity-50 group-hover:opacity-100 transition-opacity duration-200"}),e.label]},e.id)})}),(0,n.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:ee.slice(3,7).map(e=>{let t=e.icon;return(0,n.jsxs)("button",{type:"button",onClick:()=>er(e.id),className:"group flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium whitespace-nowrap rounded-xl transition-all duration-200 border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-secondary)"},children:[(0,n.jsx)(t,{className:"w-3.5 h-3.5 opacity-50 group-hover:opacity-100 transition-opacity duration-200"}),e.label]},e.id)})})]})]}):0===es.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full min-h-[60vh]",children:(0,n.jsx)("div",{className:"text-center max-w-md px-4",children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Ask about this file"})})}):(0,n.jsxs)("div",{className:"".concat(s?"":"max-w-2xl mx-auto"," py-3"),children:[Z?(0,n.jsx)("pre",{className:"text-xs whitespace-pre-wrap break-all font-mono p-4 rounded-xl",style:{color:"var(--color-text)",background:"var(--color-surface-hover)"},children:JSON.stringify(es,null,2)}):es.map((e,t)=>(0,n.jsx)(al,{message:e,isStreaming:eh&&t===es.length-1,onSubagentClick:p,onFilePathClick:m,sessionId:S,userHtmlMap:J.current},e.id)),eO&&(0,n.jsx)("div",{className:"py-3 min-w-0",children:(0,n.jsx)(G.V,{name:"pulse",className:"text-base",style:{color:"var(--color-text-muted)"}})}),(0,n.jsx)("div",{ref:D})]})}),(eu||P)&&(0,n.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 sticky bottom-[72px] z-10",style:{background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))",borderColor:"color-mix(in srgb, var(--color-error) 18%, transparent)",color:"var(--color-error)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),(0,n.jsx)("p",{className:"text-xs",children:null!=(l=null==eu?void 0:eu.message)?l:P})]})]}),!eU&&(0,n.jsx)("div",{className:"".concat(s?"px-3 py-2":"px-3 pb-3 pt-0 md:px-6 md:pb-5"," z-20"),style:{background:"var(--color-bg-glass)"},children:(0,n.jsx)("div",{className:s?"":"max-w-[720px] mx-auto",children:(0,n.jsx)(lo.P.div,{layout:!0,layoutId:"chat-input-bar",transition:{type:"spring",stiffness:260,damping:30},children:eV(eJ,eK,eq)})})}),!k&&(0,n.jsx)(ai,{open:W,onClose:()=>I(!1),onSelect:eB})]})})});function aS(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):""}let aM=["created_at","Created","createdAt","created"],aL=["updated_at","Updated","updatedAt","updated"];function aT(e,t){for(let r of t){let t=e[r];if(null!=t&&""!==t)return t}}function aD(e){var t;let{value:r,enumValues:o,enumColors:l}=e,a=null!=(t=null==o?void 0:o.indexOf(r))?t:-1,s=a>=0&&l?l[a]:"#94a3b8";return(0,n.jsx)("span",{className:"inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium",style:{background:"".concat(s,"20"),color:s,border:"1px solid ".concat(s,"40")},children:r})}function aE(e){var t,r;let{value:o,members:l}=e,a=String(o),s=null==l?void 0:l.find(e=>e.id===a);return(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-6 h-6 rounded-full flex items-center justify-center text-xs font-medium flex-shrink-0",style:{background:"var(--color-accent)",color:"white"},children:(null!=(t=null==s?void 0:s.name)?t:a).charAt(0).toUpperCase()}),(0,n.jsx)("span",{children:null!=(r=null==s?void 0:s.name)?r:a})]})}function aR(e){let{value:t,field:r,relationLabels:o,onNavigateEntry:l}=e,a=null==o?void 0:o[r.name],s=function(e){if(!e)return[];let t=e.trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]}(String(t));return 0===s.length?(0,n.jsx)(aB,{}):(0,n.jsx)("span",{className:"flex items-center gap-1.5 flex-wrap",children:s.map(e=>{var t;let o=null!=(t=null==a?void 0:a[e])?t:e,s=r.related_object_name&&l?t=>{t.stopPropagation(),l(r.related_object_name,e)}:void 0;return(0,n.jsxs)("button",{type:"button",onClick:s,className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-md text-xs font-medium ".concat(s?"cursor-pointer hover:opacity-80":""),style:{background:"rgba(96, 165, 250, 0.1)",color:"#60a5fa",border:"1px solid rgba(96, 165, 250, 0.2)"},title:s?"Open ".concat(o):o,children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.5},children:[(0,n.jsx)("path",{d:"M7 7h10v10"}),(0,n.jsx)("path",{d:"M7 17 17 7"})]}),(0,n.jsx)("span",{className:"truncate max-w-[200px]",children:o})]},e)})})}function aW(e){let{value:t}=e,r=eZ(t);if(0===r.length)return(0,n.jsx)(aB,{});let o={background:"rgba(148, 163, 184, 0.12)",border:"1px solid var(--color-border)"};return(0,n.jsx)("span",{className:"flex items-center gap-1.5 flex-wrap",children:r.map(e=>{let t=eJ(e);return"link"===t.kind&&t.href?(0,n.jsx)("a",{href:t.href,target:"url"===t.linkType||"file"===t.linkType?"_blank":void 0,rel:"url"===t.linkType||"file"===t.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium underline-offset-2 hover:underline",style:{...o,color:"var(--color-accent)"},children:t.text},e):(0,n.jsx)("span",{className:"inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium",style:{...o,color:"var(--color-text-muted)"},children:e},e)})})}function aI(e){let{value:t,onChange:r,autoFocus:l}=e,a=eZ(t),[s,i]=(0,o.useState)(""),c=(0,o.useRef)(null);(0,o.useEffect)(()=>{l&&c.current&&c.current.focus()},[l]);let d=e=>{let t=e.trim();!t||a.includes(t)||(r(JSON.stringify([...a,t])),i(""))},u=e=>{let t=a.filter(t=>t!==e);r(t.length>0?JSON.stringify(t):"")};return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap min-h-[1.75rem]",children:[a.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-2.5 py-1 rounded-full text-xs font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[e,(0,n.jsx)("button",{type:"button",onClick:()=>u(e),className:"ml-0.5 hover:opacity-70",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]},e)),(0,n.jsx)("input",{ref:c,type:"text",value:s,onChange:e=>i(e.target.value),onKeyDown:e=>{("Enter"===e.key||","===e.key)&&s.trim()&&(e.preventDefault(),d(s)),"Backspace"===e.key&&!s&&a.length>0&&u(a[a.length-1])},onBlur:()=>{s.trim()&&d(s)},placeholder:0===a.length?"Type and press Enter...":"",className:"flex-1 min-w-[80px] text-sm outline-none bg-transparent",style:{color:"var(--color-text)"}})]})}function aB(){return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"})}function aF(e){let{relation:t,onNavigateEntry:r}=e,o=t.links.slice(0,10),l=t.links.length-o.length;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.4},children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]}),(0,n.jsx)("span",{className:"capitalize",children:t.sourceObjectName}),(0,n.jsxs)("span",{className:"normal-case tracking-normal font-normal opacity-60",children:["via ",t.fieldName]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap text-sm min-h-[1.75rem]",children:[o.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>null==r?void 0:r(t.sourceObjectName,e.id),className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-md text-xs font-medium cursor-pointer hover:opacity-80",style:{background:"rgba(192, 132, 252, 0.1)",color:"#c084fc",border:"1px solid rgba(192, 132, 252, 0.2)"},title:"Open ".concat(e.label," in ").concat(t.sourceObjectName),children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.5},children:[(0,n.jsx)("path",{d:"M7 7h10v10"}),(0,n.jsx)("path",{d:"M7 17 17 7"})]}),(0,n.jsx)("span",{className:"truncate max-w-[200px]",children:e.label})]},e.id)),l>0&&(0,n.jsxs)("span",{className:"text-xs px-1.5 py-0.5 rounded",style:{color:"var(--color-text-muted)"},children:["+",l," more"]})]})]})}function aA(e){let{value:t,field:r,members:o,relationLabels:l,onNavigateEntry:a}=e;if(null==t||""===t)return(0,n.jsx)(aB,{});switch(r.type){case"enum":return(0,n.jsx)(aD,{value:aS(t),enumValues:r.enum_values,enumColors:r.enum_colors});case"boolean":{let e=!0===t||"true"===t||"1"===t||"yes"===t;return(0,n.jsx)("span",{style:{color:e?"#22c55e":"var(--color-text-muted)"},children:e?"Yes":"No"})}case"user":return(0,n.jsx)(aE,{value:t,members:o});case"relation":return(0,n.jsx)(aR,{value:t,field:r,relationLabels:l,onNavigateEntry:a});case"tags":return(0,n.jsx)(aW,{value:t});default:return(0,n.jsx)(e$,{value:t,fieldType:r.type,mode:"detail"})}}function aP(e){let{objectName:t,entryId:r,members:l,onClose:a,onNavigateEntry:s,onNavigateObject:i,onRefresh:c}=e,[d,u]=(0,o.useState)(null),[x,h]=(0,o.useState)(!0),[p,m]=(0,o.useState)(null),[f,v]=(0,o.useState)(null),[g,y]=(0,o.useState)(""),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),N=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=!1;return h(!0),m(null),async function(){try{let o=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(r)));if(!o.ok){let t=await o.json().catch(()=>({error:"Failed to load"}));if(!e){var n;m(null!=(n=t.error)?n:"Failed to load entry"),h(!1)}return}let l=await o.json();e||(u(l),h(!1))}catch(t){e||(m("Network error"),h(!1))}}(),()=>{e=!0}},[t,r]),(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&a()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a]);let C=(0,o.useCallback)(e=>{e.target===N.current&&a()},[a]),S=(0,o.useCallback)(async(e,n)=>{j(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(r)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{[e]:n}})})).ok&&(u(t=>t?{...t,entry:{...t.entry,[e]:n}}:t),v(null),null==c||c())}catch(e){}finally{j(!1)}},[t,r,c]),M=(0,o.useCallback)(async()=>{if(confirm("Are you sure you want to delete this entry?")){w(!0);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(r)),{method:"DELETE"}),null==c||c(),a()}catch(e){}finally{w(!1)}}},[t,r,c,a]),L=null==d?void 0:d.effectiveDisplayField,T=L&&(null==d?void 0:d.entry[L])?aS(d.entry[L]):"".concat(String(t)," entry"),D=d?aT(d.entry,aM):void 0,E=d?aT(d.entry,aL):void 0;return(0,n.jsx)("div",{ref:N,onClick:C,className:"fixed inset-0 z-50 flex items-start justify-center",style:{background:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)"},children:(0,n.jsxs)("div",{className:"relative mt-4 mb-4 mx-3 md:mt-12 md:mb-12 md:mx-0 w-full max-w-2xl rounded-2xl overflow-hidden shadow-2xl flex flex-col",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",maxHeight:"calc(100vh - 2rem)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 md:px-6 md:py-4 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>void(null==i||i(t)),className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-medium capitalize transition-colors hover:opacity-80 flex-shrink-0",style:{background:"var(--color-accent-light)",color:"var(--color-accent)",border:"1px solid var(--color-border)"},title:"Go to ".concat(t),children:[(0,n.jsxs)("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:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]}),t]}),(0,n.jsx)("h2",{className:"text-lg font-semibold truncate",style:{color:"var(--color-text)"},children:x?"Loading...":T})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:()=>void M(),disabled:k,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-error)"},title:"Delete entry",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Close",children:(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:[x&&(0,n.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,n.jsx)("div",{className:"w-6 h-6 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}),p&&(0,n.jsx)("div",{className:"text-center py-16",children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:p})}),d&&!x&&(0,n.jsxs)("div",{className:"space-y-4",children:[d.fields.map(e=>{let t=d.entry[e.name];return(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"block text-xs font-medium uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:[e.name,"relation"===e.type&&e.related_object_name&&(0,n.jsxs)("span",{className:"normal-case tracking-normal font-normal opacity-60 ml-1",children:["(",e.related_object_name,")"]})]}),(0,n.jsx)("div",{className:"text-sm min-h-[1.75rem] flex items-center",style:{color:"var(--color-text)"},children:f===e.name?"tags"===e.type?(0,n.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,n.jsx)("div",{className:"flex-1 px-2 py-1 rounded-lg",style:{background:"var(--color-surface-hover)",border:"2px solid var(--color-accent)"},children:(0,n.jsx)(aI,{value:aS(t),onChange:t=>{S(e.name,t)},autoFocus:!0})}),(0,n.jsx)("button",{type:"button",onClick:()=>v(null),className:"px-2 py-1 text-xs rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Done"})]}):"relation"===e.type&&e.related_object_name?(0,n.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,n.jsx)("div",{className:"flex-1",children:(0,n.jsx)(ey,{relatedObjectName:e.related_object_name,value:aS(t),multiple:"many_to_many"===e.relationship_type,onChange:t=>{S(e.name,t)},autoFocus:!0})}),(0,n.jsx)("button",{type:"button",onClick:()=>v(null),className:"px-2 py-1 text-xs rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Cancel"})]}):(0,n.jsxs)("form",{onSubmit:t=>{t.preventDefault(),S(e.name,g)},className:"flex items-center gap-2 w-full",children:["enum"===e.type&&e.enum_values?(0,n.jsxs)("select",{value:g,onChange:t=>{y(t.target.value),S(e.name,t.target.value)},autoFocus:!0,className:"flex-1 px-2 py-1 text-sm rounded-lg outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"2px solid var(--color-accent)"},children:[(0,n.jsx)("option",{value:"",children:"--"}),e.enum_values.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}):"boolean"===e.type?(0,n.jsxs)("select",{value:g,onChange:t=>{y(t.target.value),S(e.name,t.target.value)},autoFocus:!0,className:"flex-1 px-2 py-1 text-sm rounded-lg outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"2px solid var(--color-accent)"},children:[(0,n.jsx)("option",{value:"true",children:"Yes"}),(0,n.jsx)("option",{value:"false",children:"No"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:function(e){switch(e){case"number":return"number";case"date":return"date";case"email":return"email";case"phone":return"tel";case"url":return"url";default:return"text"}}(e.type),value:g,onChange:e=>y(e.target.value),autoFocus:!0,className:"flex-1 px-2 py-1 text-sm rounded-lg outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"2px solid var(--color-accent)"}}),(0,n.jsx)("button",{type:"submit",disabled:b,className:"px-2 py-1 text-xs rounded-lg font-medium",style:{background:"var(--color-accent)",color:"white"},children:b?"...":"Save"})]}),(0,n.jsx)("button",{type:"button",onClick:()=>v(null),className:"px-2 py-1 text-xs rounded-lg",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Cancel"})]}):(0,n.jsx)("div",{className:"flex-1 ".concat(["user"].includes(e.type)?"":"cursor-pointer hover:opacity-80"),onClick:()=>{["user"].includes(e.type)||(v(e.name),y(aS(t)))},title:["user"].includes(e.type)?void 0:"Click to edit",children:(0,n.jsx)(aA,{value:t,field:e,members:l,relationLabels:d.relationLabels,onNavigateEntry:s})})})]},e.id)}),d.reverseRelations&&d.reverseRelations.length>0&&(0,n.jsxs)("div",{className:"pt-4 mt-4 border-t space-y-4",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-widest",style:{color:"var(--color-text-muted)",opacity:.6},children:"Linked from"}),d.reverseRelations.map(e=>(0,n.jsx)(aF,{relation:e,onNavigateEntry:s},"".concat(e.sourceObjectName,"_").concat(e.fieldName)))]}),(null!=D||null!=E)&&(0,n.jsxs)("div",{className:"pt-4 mt-4 border-t text-xs flex gap-6",style:{borderColor:"var(--color-border)",color:"var(--color-text-muted)"},children:[null!=D&&(0,n.jsxs)("span",{children:["Created: ",(0,n.jsx)(e$,{value:D,fieldType:"date",mode:"detail",className:"inline"})]}),null!=E&&(0,n.jsxs)("span",{children:["Updated: ",(0,n.jsx)(e$,{value:E,fieldType:"date",mode:"detail",className:"inline"})]})]})]})]})]})})}var a_=r(91365);let az={keys:[{name:"label",weight:3},{name:"sublabel",weight:1},{name:"objectName",weight:1.5},{name:"fieldValues",weight:2}],threshold:.4,distance:200,includeScore:!0,shouldSort:!0,minMatchCharLength:1},aO=new Set(["ts","tsx","js","jsx","mjs","cjs","py","rb","go","rs","java","kt","swift","c","cpp","h","hpp","cs","css","scss","less","html","htm","xml","svg","json","jsonc","yaml","yml","toml","sh","bash","zsh","fish","ps1","sql","graphql","gql","dockerfile","makefile","cmake","r","lua","php","vue","svelte","diff","patch","ini","env","tf","proto","zig","elixir","ex","erl","hs","scala","clj","dart"]);function aU(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return aO.has(n)}function aH(e){if(e<=0)return"now";let t=Math.ceil(e/1e3);if(t<60)return"".concat(t,"s");let r=Math.floor(t/60),n=t%60;if(r<60)return n>0?"".concat(r,"m ").concat(n,"s"):"".concat(r,"m");let o=Math.floor(r/60),l=r%60;return l>0?"".concat(o,"h ").concat(l,"m"):"".concat(o,"h")}function aV(e){return e<1e3?"".concat(e,"ms"):e<6e4?"".concat((e/1e3).toFixed(1),"s"):"".concat(Math.floor(e/6e4),"m ").concat(Math.floor(e%6e4/1e3),"s")}function aJ(e){switch(e){case"ok":return"var(--color-success, #22c55e)";case"running":return"var(--color-accent)";case"error":return"var(--color-error, #ef4444)";case"disabled":default:return"var(--color-text-muted)";case"skipped":return"var(--color-warning, #f59e0b)"}}function aK(e){let[t,r]=(0,o.useState)(Date.now());return((0,o.useEffect)(()=>{if(!e)return;let t=setInterval(()=>r(Date.now()),1e3);return()=>clearInterval(t)},[e]),e)?aH(e-t):null}let aq=[{id:"overview",label:"Overview"},{id:"calendar",label:"Calendar"},{id:"insights",label:"Insights"}];function aG(e){let{onSelectJob:t,onSendCommand:r,activeView:l="overview",onViewChange:a,calendarMode:s="month",onCalendarModeChange:i,calendarDate:c,onCalendarDateChange:d}=e,[u,x]=(0,o.useState)([]),[h,p]=(0,o.useState)({intervalMs:18e5,nextDueEstimateMs:null}),[m,f]=(0,o.useState)({enabled:!1,nextWakeAtMs:null}),[v,g]=(0,o.useState)(!0),[y,b]=(0,o.useState)([]),j=(0,o.useCallback)(async()=>{try{var e,t,r,n;let o=await fetch("/api/cron/jobs"),l=await o.json();x(null!=(e=l.jobs)?e:[]),p(null!=(t=l.heartbeat)?t:{intervalMs:18e5,nextDueEstimateMs:null}),f(null!=(r=l.cronStatus)?r:{enabled:!1,nextWakeAtMs:null});let a=(null!=(n=l.jobs)?n:[]).map(e=>e.id).map(async e=>{try{var t;let r=await fetch("/api/cron/jobs/".concat(encodeURIComponent(e),"/runs?limit=50"));return null!=(t=(await r.json()).entries)?t:[]}catch(e){return[]}}),s=await Promise.all(a);b(s.flat().toSorted((e,t)=>t.ts-e.ts))}catch(e){}finally{g(!1)}},[]);(0,o.useEffect)(()=>{j();let e=setInterval(()=>void j(),15e3);return()=>clearInterval(e)},[j]);let k=aK(h.nextDueEstimateMs),w=aK(m.nextWakeAtMs);if(v)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full p-8",children:(0,n.jsx)("div",{className:"w-6 h-6 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})});let N=u.filter(e=>e.enabled),C=u.filter(e=>!e.enabled);return(0,n.jsxs)("div",{className:"p-6 max-w-5xl mx-auto",children:[(0,n.jsx)("div",{className:"flex items-end justify-between mb-6",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight mb-1",style:{color:"var(--color-text)"},children:"Cron"}),(0,n.jsxs)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:[N.length," active job",1!==N.length?"s":"",C.length>0&&" / ".concat(C.length," disabled")]})]})}),(0,n.jsx)("div",{className:"flex items-center gap-1 mb-6 rounded-xl p-1",style:{background:"var(--color-surface-hover)"},children:aq.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>null==a?void 0:a(e.id),className:"px-4 py-1.5 rounded-lg text-sm font-medium transition-all cursor-pointer",style:{background:l===e.id?"var(--color-surface)":"transparent",color:l===e.id?"var(--color-text)":"var(--color-text-muted)",boxShadow:l===e.id?"var(--shadow-sm)":"none"},children:e.label},e.id))}),"overview"===l&&(0,n.jsx)(a$,{jobs:u,enabledJobs:N,disabledJobs:C,heartbeatCountdown:k,heartbeat:h,cronWakeCountdown:w,onSelectJob:t,onSendCommand:r}),"calendar"===l&&(0,n.jsx)(aX,{jobs:u,allRuns:y,mode:s,onModeChange:i,dateAnchor:c,onDateChange:d,onSelectJob:t}),"insights"===l&&(0,n.jsx)(a5,{jobs:u,allRuns:y,onSelectJob:t})]})}function a$(e){let{jobs:t,enabledJobs:r,disabledJobs:o,heartbeatCountdown:l,heartbeat:a,cronWakeCountdown:s,onSelectJob:i,onSendCommand:c}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 mb-8",children:[(0,n.jsx)(a3,{title:"Heartbeat",icon:(0,n.jsx)(se,{}),value:l?"in ".concat(l):"unknown",subtitle:"Interval: ".concat(aH(a.intervalMs))}),(0,n.jsx)(a3,{title:"Cron Scheduler",icon:(0,n.jsx)(st,{}),value:s?"next in ".concat(s):0===t.length?"no jobs":"idle",subtitle:"".concat(r.length," active / ").concat(t.length," total jobs")}),(0,n.jsx)(a3,{title:"Active Runs",icon:(0,n.jsx)(sr,{}),value:"".concat(t.filter(e=>e.state.runningAtMs).length),subtitle:(()=>{let e=t.filter(e=>e.state.runningAtMs),r=t.filter(e=>"error"===e.state.lastStatus).length;return e.length>0?e.map(e=>e.name).join(", "):r>0?"".concat(r," with errors"):"All clear"})()})]}),(0,n.jsx)(a8,{jobs:r}),(0,n.jsx)(a7,{jobs:[...r,...o],onSelectJob:i,onSendCommand:c})]})}function aZ(e){return"".concat(e.getFullYear(),"-").concat(String(e.getMonth()+1).padStart(2,"0"),"-").concat(String(e.getDate()).padStart(2,"0"))}function aY(e,t,r){let n=new Set;for(let o of e.split(",")){let e=o.match(/^(.+)\/(\d+)$/),l=e?parseInt(e[2],10):1,a=e?e[1]:o;if("*"===a)for(let e=t;e<=r;e+=l)n.add(e);else if(a.includes("-")){let[e,t]=a.split("-").map(Number);for(let r=e;r<=t;r+=l)n.add(r)}else n.add(parseInt(a,10))}return[...n].filter(e=>e>=t&&e<=r).sort((e,t)=>e-t)}function aQ(e){var t,r,o,l;let{ev:a,onSelectJob:s}=e;if("scheduled"===a.kind){let e=new Date(a.at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return(0,n.jsxs)("button",{type:"button",onClick:()=>s(a.job.id),className:"w-full text-left text-[10px] px-1.5 py-0.5 rounded truncate cursor-pointer",style:{background:"color-mix(in srgb, var(--color-accent) 15%, transparent)",color:"var(--color-accent)"},title:"Scheduled: ".concat(a.job.name," at ").concat(e),children:[e," ",a.job.name]})}let i="ok"===a.run.status?"var(--color-success, #22c55e)":"error"===a.run.status?"var(--color-error, #ef4444)":"var(--color-text-muted)";return(0,n.jsxs)("button",{type:"button",onClick:()=>a.job&&s(a.job.id),className:"w-full text-left text-[10px] px-1.5 py-0.5 rounded truncate flex items-center gap-1 cursor-pointer",style:{background:"color-mix(in srgb, ".concat(i," 10%, transparent)"),color:i},title:"".concat(a.run.status,": ").concat(null!=(o=null==(t=a.job)?void 0:t.name)?o:a.run.jobId),children:[(0,n.jsx)("span",{className:"w-1 h-1 rounded-full flex-shrink-0",style:{background:i}}),null!=(l=null==(r=a.job)?void 0:r.name)?l:a.run.jobId.slice(0,8)]})}function aX(e){let{jobs:t,allRuns:r,mode:l="month",onModeChange:a,dateAnchor:s,onDateChange:i,onSelectJob:c}=e,d=s?new Date(s):new Date,u=e=>{let t=new Date(d);"month"===l?t.setMonth(t.getMonth()+e):"week"===l?t.setDate(t.getDate()+7*e):"day"===l?t.setDate(t.getDate()+e):t.setFullYear(t.getFullYear()+e),null==i||i(t.toISOString().split("T")[0])},x=(0,o.useMemo)(()=>{let e=new Map;for(let r of t)e.set(r.id,r);return e},[t]),{rangeFrom:h,rangeTo:p}=(0,o.useMemo)(()=>{let e=d.getFullYear(),t=d.getMonth();if("day"===l)return{rangeFrom:new Date(e,t,d.getDate()).getTime(),rangeTo:new Date(e,t,d.getDate()+1).getTime()};if("week"===l){let e=new Date(d);return e.setDate(e.getDate()-e.getDay()),{rangeFrom:e.getTime(),rangeTo:e.getTime()+6048e5}}if("year"===l)return{rangeFrom:new Date(e,0,1).getTime(),rangeTo:new Date(e+1,0,1).getTime()};let r=new Date(e,t,1),n=new Date(e,t,1-r.getDay());return{rangeFrom:n.getTime(),rangeTo:n.getTime()+36288e5}},[d,l]),m=(0,o.useMemo)(()=>(function(e,t,r,n,o){var l,a;let s=new Map;for(let t of e){let e=aZ(new Date(t.ts)),n=null!=(l=s.get(e))?l:[];n.push({kind:"run",run:t,job:r.get(t.jobId)}),s.set(e,n)}for(let e of t)if(e.enabled)for(let t of function(e,t,r){if(!e.enabled)return[];let n=e.schedule;switch(n.kind){case"at":{let e=new Date(n.at).getTime();return e>=t&&e<=r?[e]:[]}case"every":{var o,l;let a=n.everyMs;if(a<=0)return[];let s=null!=(l=null!=(o=n.anchorMs)?o:e.createdAtMs)?l:t,i=[],c=s;if(c<t){let e=Math.floor((t-c)/a);c+=e*a}for(;c<=r&&i.length<5e3;)c>=t&&i.push(c),c+=a;return i}case"cron":return function(e,t,r,n){let o=e.trim().split(/\s+/);if(o.length<5)return[];let l=aY(o[0],0,59),a=aY(o[1],0,23),s=aY(o[2],1,31),i=aY(o[3],1,12),c=aY(o[4],0,6),d="*"===o[2],u="*"===o[4],x=[],h=new Date(t);h.setSeconds(0,0);let p=0;for(;h.getTime()<=r&&p++<5e4;){if(!i.includes(h.getMonth()+1)){h.setMonth(h.getMonth()+1,1),h.setHours(0,0,0,0);continue}let e=d||s.includes(h.getDate()),n=u||c.includes(h.getDay());if(!(d&&u||(d||u?e&&n:e||n))){h.setDate(h.getDate()+1),h.setHours(0,0,0,0);continue}for(let e of a)for(let n of l){let o=new Date(h.getFullYear(),h.getMonth(),h.getDate(),e,n,0,0).getTime();o>=t&&o<=r&&x.push(o)}h.setDate(h.getDate()+1),h.setHours(0,0,0,0)}return x}(n.expr,t,r,n.tz);default:return[]}}(e,n,o)){let r=aZ(new Date(t)),n=null!=(a=s.get(r))?a:[];n.push({kind:"scheduled",job:e,at:t}),s.set(r,n)}return s})(r,t,x,h,p),[r,t,x,h,p]),f=(0,o.useMemo)(()=>{if("day"===l)return d.toLocaleDateString(void 0,{weekday:"long",month:"long",day:"numeric",year:"numeric"});if("week"===l){let e=new Date(d);e.setDate(e.getDate()-e.getDay());let t=new Date(e);return(t.setDate(t.getDate()+6),e.getMonth()===t.getMonth())?"".concat(e.toLocaleDateString(void 0,{month:"long"})," ").concat(e.getDate(),"–").concat(t.getDate(),", ").concat(e.getFullYear()):"".concat(e.toLocaleDateString(void 0,{month:"short",day:"numeric"})," – ").concat(t.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"}))}return"year"===l?String(d.getFullYear()):d.toLocaleDateString(void 0,{month:"long",year:"numeric"})},[d,l]),v=aZ(new Date);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:()=>u(-1),className:"p-1.5 rounded-lg cursor-pointer",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})})}),(0,n.jsx)("h2",{className:"text-lg font-semibold",style:{color:"var(--color-text)"},children:f}),(0,n.jsx)("button",{type:"button",onClick:()=>u(1),className:"p-1.5 rounded-lg cursor-pointer",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}),(0,n.jsx)("button",{type:"button",onClick:()=>null==i?void 0:i(new Date().toISOString().split("T")[0]),className:"text-xs px-2.5 py-1 rounded-lg ml-2 cursor-pointer",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:"Today"})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 rounded-lg p-0.5",style:{background:"var(--color-surface-hover)"},children:["day","week","month","year"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>null==a?void 0:a(e),className:"px-3 py-1 rounded-md text-xs font-medium cursor-pointer",style:{background:l===e?"var(--color-surface)":"transparent",color:l===e?"var(--color-text)":"var(--color-text-muted)"},children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),"day"===l&&(0,n.jsx)(a0,{anchor:d,eventsByDay:m,todayStr:v,onSelectJob:c}),"week"===l&&(0,n.jsx)(a1,{anchor:d,eventsByDay:m,todayStr:v,onSelectJob:c,onDateChange:i,onModeChange:a}),"month"===l&&(0,n.jsx)(a2,{anchor:d,eventsByDay:m,todayStr:v,onSelectJob:c}),"year"===l&&(0,n.jsx)(a4,{anchor:d,eventsByDay:m,todayStr:v,onDateChange:i,onModeChange:a})]})}function a0(e){var t;let{anchor:r,eventsByDay:l,todayStr:a,onSelectJob:s}=e,i=aZ(r),c=null!=(t=l.get(i))?t:[],d=i===a,u=Array.from({length:24},(e,t)=>t),x=(0,o.useMemo)(()=>{let e=new Map;for(let r of c){var t;let n="run"===r.kind?new Date(r.run.ts).getHours():r.job.state.nextRunAtMs?new Date(r.job.state.nextRunAtMs).getHours():0,o=null!=(t=e.get(n))?t:[];o.push(r),e.set(n,o)}return e},[c]);return(0,n.jsx)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:u.map(e=>{var t;let r=null!=(t=x.get(e))?t:[],o=new Date().getHours(),l=d&&e===o;return(0,n.jsxs)("div",{className:"flex",style:{borderBottom:e<23?"1px solid var(--color-border)":void 0,background:l?"color-mix(in srgb, var(--color-accent) 4%, transparent)":void 0},children:[(0,n.jsx)("div",{className:"w-16 flex-shrink-0 px-3 py-2 text-right text-[11px] font-medium",style:{color:"var(--color-text-muted)",borderRight:"1px solid var(--color-border)"},children:0===e?"12 AM":e<12?"".concat(e," AM"):12===e?"12 PM":"".concat(e-12," PM")}),(0,n.jsx)("div",{className:"flex-1 min-h-[36px] px-2 py-1 flex flex-wrap gap-1 items-start",children:r.map((e,t)=>(0,n.jsx)(aQ,{ev:e,onSelectJob:s},t))})]},e)})})}function a1(e){let{anchor:t,eventsByDay:r,todayStr:o,onSelectJob:l,onDateChange:a,onModeChange:s}=e,i=new Date(t);i.setDate(i.getDate()-i.getDay());let c=Array.from({length:7},(e,t)=>{let r=new Date(i);return r.setDate(r.getDate()+t),r});return(0,n.jsxs)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"grid grid-cols-7",style:{borderBottom:"1px solid var(--color-border)"},children:c.map(e=>{let t=aZ(e),r=t===o;return(0,n.jsxs)("button",{type:"button",onClick:()=>{null==a||a(t),null==s||s("day")},className:"px-2 py-2 text-center cursor-pointer",style:{borderRight:6>e.getDay()?"1px solid var(--color-border)":void 0},children:[(0,n.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:e.toLocaleDateString(void 0,{weekday:"short"})}),(0,n.jsx)("div",{className:"text-sm font-semibold",style:{color:r?"var(--color-accent)":"var(--color-text)"},children:e.getDate()})]},t)})}),(0,n.jsx)("div",{className:"grid grid-cols-7",children:c.map(e=>{var t;let a=aZ(e),s=null!=(t=r.get(a))?t:[],i=a===o;return(0,n.jsx)("div",{className:"min-h-[200px] p-1.5",style:{borderRight:6>e.getDay()?"1px solid var(--color-border)":void 0,background:i?"color-mix(in srgb, var(--color-accent) 4%, transparent)":void 0},children:(0,n.jsxs)("div",{className:"space-y-0.5",children:[s.slice(0,8).map((e,t)=>(0,n.jsx)(aQ,{ev:e,onSelectJob:l},t)),s.length>8&&(0,n.jsxs)("div",{className:"text-[9px] px-1",style:{color:"var(--color-text-muted)"},children:["+",s.length-8," more"]})]})},a)})})]})}function a2(e){let{anchor:t,eventsByDay:r,todayStr:l,onSelectJob:a}=e,s=(0,o.useMemo)(()=>{let e=t.getFullYear(),r=t.getMonth(),n=new Date(e,r,1),o=new Date(e,r,1-n.getDay()),l=[];for(let e=0;e<6;e++){let t=[];for(let r=0;r<7;r++){let n=new Date(o);n.setDate(n.getDate()+7*e+r),t.push(n)}l.push(t)}return l},[t]);return(0,n.jsxs)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"grid grid-cols-7",style:{borderBottom:"1px solid var(--color-border)"},children:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(e=>(0,n.jsx)("div",{className:"px-2 py-2 text-center text-[11px] font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:e},e))}),s.map((e,o)=>(0,n.jsx)("div",{className:"grid grid-cols-7",style:{borderBottom:o<5?"1px solid var(--color-border)":void 0},children:e.map(e=>{var o;let s=aZ(e),i=null!=(o=r.get(s))?o:[],c=e.getMonth()===t.getMonth(),d=s===l;return(0,n.jsxs)("div",{className:"min-h-[80px] p-1.5",style:{borderRight:6>e.getDay()?"1px solid var(--color-border)":void 0,opacity:c?1:.4,background:d?"color-mix(in srgb, var(--color-accent) 5%, transparent)":void 0},children:[(0,n.jsx)("div",{className:"text-xs font-medium mb-1",style:{color:d?"var(--color-accent)":"var(--color-text-muted)"},children:e.getDate()}),(0,n.jsxs)("div",{className:"space-y-0.5",children:[i.slice(0,3).map((e,t)=>(0,n.jsx)(aQ,{ev:e,onSelectJob:a},t)),i.length>3&&(0,n.jsxs)("div",{className:"text-[9px] px-1",style:{color:"var(--color-text-muted)"},children:["+",i.length-3," more"]})]})]},s)})},o))]})}function a4(e){let{anchor:t,eventsByDay:r,todayStr:o,onDateChange:l,onModeChange:a}=e,s=t.getFullYear(),i=Array.from({length:12},(e,t)=>t);return(0,n.jsx)("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-4",children:i.map(e=>{let t=new Date(s,e,1),i=t.getDay(),c=new Date(s,e+1,0).getDate(),d=[];for(let e=0;e<i;e++)d.push(null);for(let e=1;e<=c;e++)d.push(e);return(0,n.jsxs)("button",{type:"button",onClick:()=>{null==l||l("".concat(s,"-").concat(String(e+1).padStart(2,"0"),"-01")),null==a||a("month")},className:"rounded-xl p-3 text-left cursor-pointer transition-colors",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--color-surface)"},children:[(0,n.jsx)("div",{className:"text-xs font-semibold mb-2",style:{color:"var(--color-text)"},children:t.toLocaleDateString(void 0,{month:"short"})}),(0,n.jsxs)("div",{className:"grid grid-cols-7 gap-px",children:[["S","M","T","W","T","F","S"].map((e,t)=>(0,n.jsx)("div",{className:"text-[8px] text-center font-medium",style:{color:"var(--color-text-muted)"},children:e},t)),d.map((t,l)=>{var a;if(null===t)return(0,n.jsx)("div",{},"e-".concat(l));let i="".concat(s,"-").concat(String(e+1).padStart(2,"0"),"-").concat(String(t).padStart(2,"0")),c=null!=(a=r.get(i))?a:[],d=i===o,u=c.length>0,x=c.some(e=>"run"===e.kind&&"error"===e.run.status);return(0,n.jsx)("div",{className:"text-[9px] text-center rounded-sm leading-[16px]",style:{color:d?"var(--color-accent)":u?"var(--color-text)":"var(--color-text-muted)",fontWeight:d||u?600:400,background:x?"color-mix(in srgb, var(--color-error, #ef4444) 15%, transparent)":u?"color-mix(in srgb, var(--color-accent) 10%, transparent)":void 0},children:t},i)})]}),(()=>{let t=0;for(let n=1;n<=c;n++){var o;let l="".concat(s,"-").concat(String(e+1).padStart(2,"0"),"-").concat(String(n).padStart(2,"0"));t+=(null!=(o=r.get(l))?o:[]).length}return t>0?(0,n.jsxs)("div",{className:"text-[9px] mt-1.5",style:{color:"var(--color-text-muted)"},children:[t," event",1!==t?"s":""]}):null})()]},e)})})}function a5(e){let{jobs:t,allRuns:r,onSelectJob:l}=e,a=(0,o.useMemo)(()=>{let e=r.length,n=r.filter(e=>"ok"===e.status).length,o=r.filter(e=>"error"===e.status).length,l=e>0?r.filter(e=>null!=e.durationMs).reduce((e,t)=>{var r;return e+(null!=(r=t.durationMs)?r:0)},0)/Math.max(1,r.filter(e=>null!=e.durationMs).length):0,a=e>0?Math.round(n/e*100):0,s=Date.now(),i=[];for(let e=13;e>=0;e--){let t=s-864e5*e,n=t+864e5,o=r.filter(e=>e.ts>=t&&e.ts<n),l=new Date(t);i.push({day:"".concat(l.getMonth()+1,"/").concat(l.getDate()),ok:o.filter(e=>"ok"===e.status).length,error:o.filter(e=>"error"===e.status).length,other:o.filter(e=>"ok"!==e.status&&"error"!==e.status).length})}return{total:e,ok:n,errors:o,avgDuration:l,successRate:a,runsByDay:i,jobStats:t.map(e=>{let t=r.filter(t=>t.jobId===e.id),n=t.filter(e=>"ok"===e.status).length,o=t.filter(e=>"error"===e.status).length,l=t.filter(e=>null!=e.durationMs).length>0?t.filter(e=>null!=e.durationMs).reduce((e,t)=>{var r;return e+(null!=(r=t.durationMs)?r:0)},0)/t.filter(e=>null!=e.durationMs).length:0;return{job:e,runs:t.length,ok:n,errors:o,avgDuration:l}}).toSorted((e,t)=>t.runs-e.runs)}},[r,t]);return(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[(0,n.jsx)(a6,{label:"Total Runs",value:String(a.total)}),(0,n.jsx)(a6,{label:"Success Rate",value:"".concat(a.successRate,"%"),accent:a.successRate>=90?"var(--color-success, #22c55e)":a.successRate>=70?"var(--color-warning, #f59e0b)":"var(--color-error, #ef4444)"}),(0,n.jsx)(a6,{label:"Errors",value:String(a.errors),accent:a.errors>0?"var(--color-error, #ef4444)":void 0}),(0,n.jsx)(a6,{label:"Avg Duration",value:aV(a.avgDuration)})]}),(0,n.jsxs)("div",{className:"rounded-2xl p-4",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("h3",{className:"text-xs font-medium uppercase tracking-wider mb-4",style:{color:"var(--color-text-muted)"},children:"Runs (Last 14 Days)"}),(0,n.jsx)("div",{className:"flex items-end gap-1 h-32",children:a.runsByDay.map(e=>{let t=Math.max(...a.runsByDay.map(e=>e.ok+e.error+e.other),1),r=e.ok+e.error+e.other,o=Math.max(2,r/t*100),l=r>0?e.ok/r*100:100;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-1",children:[(0,n.jsx)("div",{className:"w-full flex flex-col justify-end",style:{height:"100%"},children:(0,n.jsx)("div",{className:"w-full rounded-t-sm",style:{height:"".concat(o,"%"),background:0===r?"var(--color-surface-hover)":100===l?"var(--color-success, #22c55e)":l>50?"color-mix(in srgb, var(--color-success, #22c55e) 60%, var(--color-error, #ef4444))":"var(--color-error, #ef4444)",opacity:0===r?.3:.7},title:"".concat(e.day,": ").concat(e.ok," ok, ").concat(e.error," errors")})}),(0,n.jsx)("span",{className:"text-[9px]",style:{color:"var(--color-text-muted)"},children:e.day})]},e.day)})}),(0,n.jsxs)("div",{className:"flex items-center gap-4 mt-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-sm",style:{background:"var(--color-success, #22c55e)",opacity:.7}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"Success"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-sm",style:{background:"var(--color-error, #ef4444)",opacity:.7}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"Error"})]})]})]}),(0,n.jsxs)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"px-4 py-3",style:{borderBottom:"1px solid var(--color-border)"},children:(0,n.jsx)("h3",{className:"text-xs font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:"Per-Job Breakdown"})}),a.jobStats.map(e=>{let t=e.runs>0?Math.round(e.ok/e.runs*100):0;return(0,n.jsxs)("button",{type:"button",onClick:()=>l(e.job.id),className:"w-full flex items-center gap-3 px-4 py-3 text-left cursor-pointer transition-colors",style:{borderBottom:"1px solid var(--color-border)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:e.job.name}),(0,n.jsxs)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:[e.runs," runs / ",t,"% success / avg ",aV(e.avgDuration)]})]}),(0,n.jsx)("div",{className:"w-24 h-2 rounded-full overflow-hidden flex-shrink-0",style:{background:"var(--color-surface-hover)"},children:(0,n.jsx)("div",{className:"h-full rounded-full",style:{width:"".concat(t,"%"),background:t>=90?"var(--color-success, #22c55e)":t>=70?"var(--color-warning, #f59e0b)":"var(--color-error, #ef4444)"}})}),null!=e.job.state.consecutiveErrors&&e.job.state.consecutiveErrors>0&&(0,n.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 12%, transparent)",color:"var(--color-error, #ef4444)"},children:[e.job.state.consecutiveErrors," err"]})]},e.job.id)})]})]})}function a6(e){let{label:t,value:r,accent:o}=e;return(0,n.jsxs)("div",{className:"rounded-xl p-3",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-wider mb-1",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("div",{className:"text-xl font-semibold",style:{color:null!=o?o:"var(--color-text)"},children:r})]})}function a3(e){let{title:t,icon:r,value:o,subtitle:l}=e;return(0,n.jsxs)("div",{className:"rounded-2xl p-4",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:r}),(0,n.jsx)("span",{className:"text-xs font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:t})]}),(0,n.jsx)("div",{className:"text-lg font-semibold mb-0.5",style:{color:"var(--color-text)"},children:o}),(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:l})]})}function a8(e){let{jobs:t}=e,[r,l]=(0,o.useState)(Date.now());(0,o.useEffect)(()=>{let e=setInterval(()=>l(Date.now()),1e4);return()=>clearInterval(e)},[]);let a=t.filter(e=>e.state.nextRunAtMs&&e.state.nextRunAtMs>r&&e.state.nextRunAtMs<r+864e5).toSorted((e,t)=>{var r,n;return(null!=(r=e.state.nextRunAtMs)?r:0)-(null!=(n=t.state.nextRunAtMs)?n:0)});return 0===a.length?null:(0,n.jsxs)("div",{className:"mb-8",children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Upcoming (next 24h)"}),(0,n.jsx)("div",{className:"rounded-2xl p-4",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute top-0 left-3 bottom-0 w-px",style:{background:"var(--color-border)"}}),(0,n.jsx)("div",{className:"space-y-3",children:a.map(e=>{var t;return(0,n.jsxs)("div",{className:"flex items-center gap-3 pl-1",children:[(0,n.jsx)("div",{className:"relative z-10 w-5 h-5 rounded-full flex items-center justify-center flex-shrink-0",style:{background:"var(--color-accent)",opacity:.8},children:(0,n.jsx)("div",{className:"w-2 h-2 rounded-full",style:{background:"var(--color-bg)"}})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:e.name}),(0,n.jsxs)("span",{className:"text-xs ml-2",style:{color:"var(--color-text-muted)"},children:["in ",aH((null!=(t=e.state.nextRunAtMs)?t:0)-r)]})]}),(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",style:{color:"var(--color-text-muted)"},children:new Date(e.state.nextRunAtMs).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]},e.id)})})]})})]})}function a7(e){let{jobs:t,onSelectJob:r,onSendCommand:o}=e;return(0,n.jsxs)("div",{className:"mb-6",children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Jobs"}),0===t.length?(0,n.jsx)("div",{className:"p-8 text-center rounded-2xl",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No cron jobs configured."})}):(0,n.jsx)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:(0,n.jsxs)("table",{className:"w-full text-sm",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{style:{borderBottom:"1px solid var(--color-border)",color:"var(--color-text-muted)"},children:[(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Name"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Schedule"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Status"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Next Run"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Last Run"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider w-20"})]})}),(0,n.jsx)("tbody",{children:t.map(e=>(0,n.jsx)(a9,{job:e,onClick:()=>r(e.id),onSendCommand:o},e.id))})]})})]})}function a9(e){var t;let{job:r,onClick:l,onSendCommand:a}=e,s=r.enabled?r.state.runningAtMs?"running":null!=(t=r.state.lastStatus)?t:"idle":"disabled",i=aJ(s),[c,d]=(0,o.useState)(Date.now());return(0,o.useEffect)(()=>{let e=setInterval(()=>d(Date.now()),5e3);return()=>clearInterval(e)},[]),(0,n.jsxs)("tr",{className:"cursor-pointer transition-colors group",style:{borderBottom:"1px solid var(--color-border)"},onClick:l,onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsxs)("td",{className:"px-4 py-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"font-medium",style:{color:"var(--color-text)"},children:r.name}),null!=r.state.consecutiveErrors&&r.state.consecutiveErrors>0&&(0,n.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 12%, transparent)",color:"var(--color-error, #ef4444)"},children:[r.state.consecutiveErrors," err"]})]}),r.description&&(0,n.jsx)("div",{className:"text-xs truncate max-w-[200px]",style:{color:"var(--color-text-muted)"},children:r.description})]}),(0,n.jsx)("td",{className:"px-4 py-3 text-xs",style:{color:"var(--color-text-muted)"},children:function(e){switch(e.kind){case"cron":return"cron: ".concat(e.expr).concat(e.tz?" (".concat(e.tz,")"):"");case"every":{let t=e.everyMs;if(t>=864e5)return"every ".concat(Math.round(t/864e5),"d");if(t>=36e5)return"every ".concat(Math.round(t/36e5),"h");if(t>=6e4)return"every ".concat(Math.round(t/6e4),"m");return"every ".concat(Math.round(t/1e3),"s")}case"at":return"at ".concat(e.at);default:return"unknown"}}(r.schedule)}),(0,n.jsx)("td",{className:"px-4 py-3",children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-xs px-2 py-0.5 rounded-full",style:{background:"color-mix(in srgb, ".concat(i," 12%, transparent)"),color:i},children:["running"===s&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse",style:{background:i}}),s]})}),(0,n.jsx)("td",{className:"px-4 py-3 text-xs",style:{color:"var(--color-text-muted)"},children:r.state.nextRunAtMs?r.state.nextRunAtMs>c?"in ".concat(aH(r.state.nextRunAtMs-c)):"overdue":"-"}),(0,n.jsx)("td",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[r.state.lastStatus&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:aJ(r.state.lastStatus)}}),(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:r.state.lastRunAtMs?"".concat(function(e){let t=Date.now()-e;return t<6e4?"just now":t<36e5?"".concat(Math.floor(t/6e4),"m ago"):t<864e5?"".concat(Math.floor(t/36e5),"h ago"):"".concat(Math.floor(t/864e5),"d ago")}(r.state.lastRunAtMs)).concat(r.state.lastDurationMs?" (".concat(aV(r.state.lastDurationMs),")"):""):"-"})]})}),(0,n.jsx)("td",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[!r.state.runningAtMs&&r.enabled&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),null==a||a('Run cron job "'.concat(r.name,'" (').concat(r.id,") now with --force"))},className:"p-1 rounded cursor-pointer",style:{color:"var(--color-accent)"},title:"Run now",children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"6 3 20 12 6 21 6 3"})})}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),null==a||a("".concat(r.enabled?"Disable":"Enable",' cron job "').concat(r.name,'" (').concat(r.id,")"))},className:"p-1 rounded cursor-pointer",style:{color:r.enabled?"var(--color-text-muted)":"var(--color-success, #22c55e)"},title:r.enabled?"Disable":"Enable",children:r.enabled?(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("path",{d:"m4.93 4.93 14.14 14.14"})]}):(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})})})]})})]})}function se(){return(0,n.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M19.5 12.572l-7.5 7.428l-7.5 -7.428a5 5 0 1 1 7.5 -6.566a5 5 0 1 1 7.5 6.572"})})}function st(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function sr(){return(0,n.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"6 3 20 12 6 21 6 3"})})}function sn(e){var t;return{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}}function so(e){let{sessionId:t}=e,[r,l]=(0,o.useState)([]),[a,s]=(0,o.useState)(!0),[i,c]=(0,o.useState)(null),d=(0,o.useCallback)(async()=>{try{var e,r;let n=await fetch("/api/web-sessions/".concat(encodeURIComponent(t)));if(!n.ok){let r=await fetch("/api/cron/runs/".concat(encodeURIComponent(t)));if(!r.ok)return void c(404===r.status?"Session transcript not found":"Failed to load session");let n=(null!=(e=(await r.json()).messages)?e:[]).filter(e=>"system"!==e.role).map(e=>({id:e.id,role:e.role,content:e.parts.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),parts:e.parts.map(e=>{if("text"===e.type)return{type:"text",text:e.text};if("thinking"===e.type)return{type:"reasoning",text:e.thinking};if("tool-call"===e.type){var t;let r=null!=e.output?(()=>{try{return JSON.parse(e.output)}catch(t){return{output:e.output}}})():void 0,n={type:"tool-invocation",toolCallId:e.toolCallId,toolName:e.toolName,args:null!=(t=e.args)?t:{}};return null!=r&&(n.result=r),n}return{type:"text",text:""}}),timestamp:e.timestamp}));l(n);return}let o=await n.json();l(null!=(r=o.messages)?r:[])}catch(e){c("Failed to load session")}finally{s(!1)}},[t]);return((0,o.useEffect)(()=>{d()},[d]),a)?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-4",children:[(0,n.jsx)("div",{className:"w-4 h-4 border-[1.5px] rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading session transcript..."})]}):i?(0,n.jsx)("div",{className:"text-xs rounded-lg px-3 py-2",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:i}):0===r.length?(0,n.jsx)("div",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:"Empty session transcript."}):(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("div",{className:"text-[11px] uppercase tracking-wider font-medium mb-2",style:{color:"var(--color-text-muted)"},children:"Session Transcript"}),r.map(e=>(0,n.jsx)(al,{message:sn(e)},e.id))]})}function sl(e){let{jobId:t,runAtMs:r,summary:l,fallback:a}=e,[s,i]=(0,o.useState)([]),[c,d]=(0,o.useState)(!0),[u,x]=(0,o.useState)(!1),h=(0,o.useCallback)(async()=>{if(!r||!l){d(!1),x(!0);return}try{let e=new URLSearchParams({jobId:t,runAtMs:String(r),summary:l}),n=await fetch("/api/cron/runs/search-transcript?".concat(e));if(!n.ok)return void x(!0);let o=await n.json();if(o.sessionId){let e=await fetch("/api/web-sessions/".concat(encodeURIComponent(o.sessionId)));if(e.ok){let t=await e.json();if(t.messages&&t.messages.length>0)return void i(t.messages)}}if(o.messages&&o.messages.length>0){let e=o.messages.filter(e=>"system"!==e.role).map(e=>({id:e.id,role:e.role,content:e.parts.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),parts:e.parts.map(e=>{if("text"===e.type)return{type:"text",text:e.text};if("thinking"===e.type)return{type:"reasoning",text:e.thinking};if("tool-call"===e.type){var t;let r=null!=e.output?(()=>{try{return JSON.parse(e.output)}catch(t){return{output:e.output}}})():void 0,n={type:"tool-invocation",toolCallId:e.toolCallId,toolName:e.toolName,args:null!=(t=e.args)?t:{}};return null!=r&&(n.result=r),n}return{type:"text",text:""}}),timestamp:e.timestamp}));i(e)}else x(!0)}catch(e){x(!0)}finally{d(!1)}},[t,r,l]);return((0,o.useEffect)(()=>{h()},[h]),c)?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-4",children:[(0,n.jsx)("div",{className:"w-4 h-4 border-[1.5px] rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Searching for transcript..."})]}):u||0===s.length?(0,n.jsx)(n.Fragment,{children:a}):(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("div",{className:"text-[11px] uppercase tracking-wider font-medium mb-2",style:{color:"var(--color-text-muted)"},children:"Session Transcript"}),s.map(e=>(0,n.jsx)(al,{message:sn(e)},e.id))]})}function sa(e){return e<1e3?"".concat(e,"ms"):e<6e4?"".concat((e/1e3).toFixed(1),"s"):"".concat(Math.floor(e/6e4),"m ").concat(Math.floor(e%6e4/1e3),"s")}function ss(e){var t,r;let{job:l,onBack:a,onSendCommand:s,runFilter:i="all",onRunFilterChange:c,expandedRunTs:d,onExpandedRunChange:u}=e,[x,h]=(0,o.useState)([]),[p,m]=(0,o.useState)(!0),f=null!=d?d:null,v=null!=u?u:()=>{},g=(0,o.useCallback)(async()=>{try{var e;let t=await fetch("/api/cron/jobs/".concat(encodeURIComponent(l.id),"/runs?limit=50")),r=await t.json();h(null!=(e=r.entries)?e:[])}catch(e){}finally{m(!1)}},[l.id]);(0,o.useEffect)(()=>{g();let e=setInterval(g,15e3);return()=>clearInterval(e)},[g]);let y=l.enabled?l.state.runningAtMs?"running":null!=(t=l.state.lastStatus)?t:"idle":"disabled";return(0,n.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,n.jsxs)("button",{type:"button",onClick:a,className:"flex items-center gap-1 text-sm mb-4 cursor-pointer",style:{color:"var(--color-text-muted)"},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]}),"Back to Cron"]}),(0,n.jsxs)("div",{className:"mb-6",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 mb-1",children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight",style:{color:"var(--color-text)"},children:l.name}),(0,n.jsx)(sh,{status:y})]}),l.description&&(0,n.jsx)("p",{className:"text-sm mb-3",style:{color:"var(--color-text-muted)"},children:l.description}),(0,n.jsx)(su,{job:l,onSendCommand:s})]}),(0,n.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-8",children:[(0,n.jsx)(si,{job:l}),(0,n.jsxs)("div",{className:"rounded-2xl p-4",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("h3",{className:"text-xs font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Configuration"}),(0,n.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,n.jsx)(sp,{label:"Schedule",value:function(e){switch(e.kind){case"cron":return e.expr+(e.tz?" (".concat(e.tz,")"):"");case"every":{let t=e.everyMs;if(t>=864e5)return"every ".concat(Math.round(t/864e5)," day(s)");if(t>=36e5)return"every ".concat(Math.round(t/36e5)," hour(s)");if(t>=6e4)return"every ".concat(Math.round(t/6e4)," minute(s)");return"every ".concat(Math.round(t/1e3)," second(s)")}case"at":return new Date(e.at).toLocaleString();default:return"unknown"}}(l.schedule)}),(0,n.jsx)(sp,{label:"Target",value:l.sessionTarget}),(0,n.jsx)(sp,{label:"Wake mode",value:l.wakeMode}),(0,n.jsx)(sp,{label:"Payload",value:"".concat(l.payload.kind,": ").concat("systemEvent"===(r=l.payload).kind?r.text.slice(0,120):r.message.slice(0,120))}),l.agentId&&(0,n.jsx)(sp,{label:"Agent",value:l.agentId}),l.delivery&&(0,n.jsx)(sp,{label:"Delivery",value:l.delivery.mode}),(0,n.jsx)(sp,{label:"Created",value:new Date(l.createdAtMs).toLocaleString()})]})]})]}),null!=l.state.consecutiveErrors&&l.state.consecutiveErrors>0&&(0,n.jsxs)("div",{className:"rounded-2xl p-4 mb-6",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 6%, var(--color-surface))",border:"1px solid color-mix(in srgb, var(--color-error, #ef4444) 18%, transparent)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),(0,n.jsxs)("span",{className:"text-sm font-medium",style:{color:"var(--color-error, #ef4444)"},children:[l.state.consecutiveErrors," consecutive error",l.state.consecutiveErrors>1?"s":""]})]}),l.state.lastError&&(0,n.jsx)("p",{className:"text-xs font-mono mt-1",style:{color:"var(--color-error, #ef4444)",opacity:.8},children:l.state.lastError})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:"Run History"}),(0,n.jsx)("div",{className:"flex items-center gap-1 rounded-lg p-0.5",style:{background:"var(--color-surface-hover)"},children:["all","ok","error","running"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>null==c?void 0:c(e),className:"px-2.5 py-1 rounded-md text-[11px] font-medium cursor-pointer",style:{background:i===e?"var(--color-surface)":"transparent",color:i===e?"var(--color-text)":"var(--color-text-muted)",boxShadow:i===e?"var(--shadow-sm)":"none"},children:"all"===e?"All":e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),p?(0,n.jsx)("div",{className:"flex items-center justify-center p-8",children:(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):0===x.length?(0,n.jsx)("div",{className:"p-8 text-center rounded-2xl",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No runs recorded yet."})}):(0,n.jsx)("div",{className:"space-y-2",children:x.toReversed().filter(e=>"all"===i||e.status===i).map(e=>(0,n.jsx)(sc,{run:e,isExpanded:f===e.ts,onToggle:()=>v(f===e.ts?null:e.ts)},"".concat(e.ts,"-").concat(e.jobId)))})]})]})}function si(e){let{job:t}=e,[r,l]=(0,o.useState)(Date.now());(0,o.useEffect)(()=>{let e=setInterval(()=>l(Date.now()),1e3);return()=>clearInterval(e)},[]);let a=t.state.nextRunAtMs,s=!!t.state.runningAtMs;return(0,n.jsxs)("div",{className:"rounded-2xl p-4 flex flex-col justify-center",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("h3",{className:"text-xs font-medium uppercase tracking-wider mb-2",style:{color:"var(--color-text-muted)"},children:s?"Currently Running":"Next Run"}),s?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-2xl font-semibold",style:{color:"var(--color-accent)"},children:"Running now"})]}):a?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"text-3xl font-semibold mb-1",style:{color:"var(--color-text)"},children:a>r?function(e){if(e<=0)return"now";let t=Math.ceil(e/1e3);if(t<60)return"".concat(t,"s");let r=Math.floor(t/60),n=t%60;if(r<60)return n>0?"".concat(r,"m ").concat(n,"s"):"".concat(r,"m");let o=Math.floor(r/60),l=r%60;return l>0?"".concat(o,"h ").concat(l,"m"):"".concat(o,"h")}(a-r):"overdue"}),(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:new Date(a).toLocaleString()})]}):(0,n.jsx)("div",{className:"text-lg",style:{color:"var(--color-text-muted)"},children:t.enabled?"Not scheduled":"Disabled"})]})}function sc(e){var t;let{run:r,isExpanded:o,onToggle:l}=e,a="ok"===r.status?"var(--color-success, #22c55e)":"error"===r.status?"var(--color-error, #ef4444)":"var(--color-warning, #f59e0b)",s=!!r.sessionId;return(0,n.jsxs)("div",{className:"rounded-xl overflow-hidden",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:l,className:"w-full flex items-center gap-3 px-4 py-3 text-left cursor-pointer transition-colors",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:a}}),(0,n.jsx)("span",{className:"text-sm flex-shrink-0",style:{color:"var(--color-text)"},title:new Date(r.ts).toLocaleString(),children:function(e){let t=Date.now()-e;return t<0||t<6e4?"just now":t<36e5?"".concat(Math.floor(t/6e4),"m ago"):t<864e5?"".concat(Math.floor(t/36e5),"h ago"):t<6048e5?"".concat(Math.floor(t/864e5),"d ago"):new Date(e).toLocaleDateString()}(r.ts)}),(0,n.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"color-mix(in srgb, ".concat(a," 12%, transparent)"),color:a},children:null!=(t=r.status)?t:"unknown"}),null!=r.durationMs&&(0,n.jsx)("span",{className:"text-xs flex-shrink-0",style:{color:"var(--color-text-muted)"},children:sa(r.durationMs)}),r.summary&&(0,n.jsx)("span",{className:"text-xs truncate flex-1 min-w-0",style:{color:"var(--color-text-muted)"},children:r.summary}),s&&(0,n.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 flex items-center gap-1",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),"session"]}),(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 12 12",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 transition-transform duration-200 ".concat(o?"":"-rotate-90"),children:(0,n.jsx)("path",{d:"M3 4.5L6 7.5L9 4.5"})})]}),o&&(0,n.jsxs)("div",{className:"px-4 pb-4",style:{borderTop:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-4 mt-3 mb-3 flex-wrap",children:[(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:new Date(r.ts).toLocaleString()}),null!=r.durationMs&&(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["Duration: ",sa(r.durationMs)]})]}),r.error&&(0,n.jsx)("div",{className:"text-xs font-mono rounded-lg px-3 py-2 mb-3",style:{color:"var(--color-error, #ef4444)",background:"color-mix(in srgb, var(--color-error, #ef4444) 6%, var(--color-surface))"},children:r.error}),r.sessionId?(0,n.jsx)(so,{sessionId:r.sessionId}):(0,n.jsx)(sd,{run:r})]})]})}function sd(e){let{run:t}=e,r=t.summary?(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[11px] uppercase tracking-wider font-medium mb-2",style:{color:"var(--color-text-muted)"},children:"Run Output"}),(0,n.jsx)("div",{className:"chat-prose text-sm",style:{color:"var(--color-text)"},children:(0,n.jsx)(lL.oz,{remarkPlugins:[lT.A],children:t.summary})})]}):(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No output recorded for this run."});return(0,n.jsx)(sl,{jobId:t.jobId,runAtMs:t.runAtMs,summary:t.summary,fallback:r})}function su(e){let{job:t,onSendCommand:r}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[!t.state.runningAtMs&&t.enabled&&(0,n.jsxs)(sx,{onClick:()=>null==r?void 0:r('Run cron job "'.concat(t.name,'" (').concat(t.id,") now with --force")),accent:!0,children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"6 3 20 12 6 21 6 3"})}),"Run now"]}),t.state.runningAtMs&&(0,n.jsxs)(sx,{disabled:!0,accent:!0,children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse",style:{background:"currentColor"}}),"Running..."]}),(0,n.jsx)(sx,{onClick:()=>null==r?void 0:r("".concat(t.enabled?"Disable":"Enable",' cron job "').concat(t.name,'" (').concat(t.id,")")),children:t.enabled?"Disable":"Enable"}),(0,n.jsx)(sx,{onClick:()=>null==r?void 0:r('Delete cron job "'.concat(t.name,'" (').concat(t.id,")")),danger:!0,children:"Delete"})]})}function sx(e){let{children:t,onClick:r,disabled:o,accent:l,danger:a}=e;return(0,n.jsx)("button",{type:"button",onClick:r,disabled:o,className:"text-xs font-medium px-3 py-1.5 rounded-lg flex items-center gap-1.5 cursor-pointer transition-opacity disabled:opacity-40 disabled:cursor-not-allowed",style:{background:l?"var(--color-accent)":a?"color-mix(in srgb, var(--color-error, #ef4444) 12%, transparent)":"var(--color-surface-hover)",color:l?"white":a?"var(--color-error, #ef4444)":"var(--color-text-muted)"},children:t})}function sh(e){let{status:t}=e,r="ok"===t?"var(--color-success, #22c55e)":"running"===t?"var(--color-accent)":"error"===t?"var(--color-error, #ef4444)":"var(--color-text-muted)";return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-xs px-2.5 py-1 rounded-full",style:{background:"color-mix(in srgb, ".concat(r," 12%, transparent)"),color:r},children:["running"===t&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse",style:{background:r}}),t]})}function sp(e){let{label:t,value:r}=e;return(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium w-20 flex-shrink-0",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("span",{className:"text-xs break-all",style:{color:"var(--color-text)"},children:r})]})}function sm(e){var t,r;let{job:o,run:l,sessionId:a,onBack:s,onBackToJob:i}=e,c="ok"===l.status?"var(--color-success, #22c55e)":"error"===l.status?"var(--color-error, #ef4444)":"var(--color-warning, #f59e0b)";return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"px-4 py-3 flex items-center gap-3 flex-shrink-0",style:{borderBottom:"1px solid var(--color-border)",background:"var(--color-bg-glass)"},children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"p-1.5 rounded-lg flex-shrink-0 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Back to Cron",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:i,className:"text-sm font-semibold truncate cursor-pointer hover:underline",style:{color:"var(--color-text)"},title:"Back to job detail",children:o.name}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",style:{background:"color-mix(in srgb, ".concat(c," 12%, transparent)"),color:c},children:null!=(t=l.status)?t:"unknown"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 text-xs",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("span",{children:new Date(l.ts).toLocaleString()}),null!=l.durationMs&&(0,n.jsx)("span",{children:(r=l.durationMs)<1e3?"".concat(r,"ms"):r<6e4?"".concat((r/1e3).toFixed(1),"s"):"".concat(Math.floor(r/6e4),"m ").concat(Math.floor(r%6e4/1e3),"s")}),l.summary&&(0,n.jsx)("span",{className:"truncate",children:l.summary})]})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(aC,{initialSessionId:a,sessionTitle:"".concat(o.name," - Run ").concat(new Date(l.ts).toLocaleString())})})]})}function sf(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function sv(){return(0,n.jsxs)("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:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]})}function sg(e){let{size:t=12}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}function sy(){return(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:"m6 9 6 6 6-6"})})}function sb(){return(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"})})}function sj(){return(0,n.jsxs)("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:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})}let sk={text:"Aa",number:"#",date:"\uD83D\uDCC5",boolean:"☑",enum:"\uD83C\uDFF7",relation:"\uD83D\uDD17",user:"\uD83D\uDC64",richtext:"\xb6",email:"@"};function sw(e){let{trigger:t,open:r,onOpenChange:l,children:a,align:s="left"}=e,i=(0,o.useRef)(null);return(0,o.useEffect)(()=>{if(!r)return;let e=e=>{i.current&&!i.current.contains(e.target)&&l(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r,l]),(0,n.jsxs)("div",{ref:i,className:"relative inline-block",children:[(0,n.jsx)("div",{onClick:()=>l(!r),children:t}),r&&(0,n.jsx)("div",{className:"absolute z-50 mt-1 rounded-lg shadow-lg border py-1 min-w-[200px] max-h-[320px] overflow-y-auto",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",["right"===s?"right":"left"]:0},children:a})]})}function sN(e){let{children:t,onClick:r,danger:o,active:l}=e;return(0,n.jsx)("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs transition-colors cursor-pointer flex items-center gap-2",style:{color:o?"var(--color-error, #ef4444)":l?"var(--color-accent)":"var(--color-text)",background:l?"var(--color-accent-light, rgba(99,102,241,0.1))":"transparent"},onMouseEnter:e=>{e.currentTarget.style.background=o?"rgba(239,68,68,0.1)":"var(--color-accent-light, rgba(99,102,241,0.1))"},onMouseLeave:e=>{e.currentTarget.style.background=l?"var(--color-accent-light, rgba(99,102,241,0.1))":"transparent"},onClick:r,children:t})}function sC(e){let{value:t,onChange:r,placeholder:o}=e;return(0,n.jsx)("input",{type:"text",value:t,onChange:e=>r(e.target.value),placeholder:null!=o?o:"Value...",className:"px-2 py-1 rounded-md text-xs outline-none min-w-[120px]",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}})}function sS(e){let{value:t,valueTo:r,showRange:o,onChange:l}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{type:"number",value:null!=t?t:"",onChange:e=>l(e.target.value?Number(e.target.value):void 0,r),placeholder:o?"Min":"Value",className:"px-2 py-1 rounded-md text-xs outline-none w-20",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"to"}),(0,n.jsx)("input",{type:"number",value:null!=r?r:"",onChange:e=>l(t,e.target.value?Number(e.target.value):void 0),placeholder:"Max",className:"px-2 py-1 rounded-md text-xs outline-none w-20",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}})]})]})}function sM(e){let{value:t,valueTo:r,showRange:o,showRelative:l,relativeAmount:a,relativeUnit:s,onChange:i}=e;return l?(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{type:"number",min:1,value:null!=a?a:7,onChange:e=>i({relativeAmount:Number(e.target.value)||7}),className:"px-2 py-1 rounded-md text-xs outline-none w-16",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),(0,n.jsxs)("select",{value:null!=s?s:"days",onChange:e=>i({relativeUnit:e.target.value}),className:"px-2 py-1 rounded-md text-xs outline-none cursor-pointer",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"},children:[(0,n.jsx)("option",{value:"days",children:"days"}),(0,n.jsx)("option",{value:"weeks",children:"weeks"}),(0,n.jsx)("option",{value:"months",children:"months"})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{type:"date",value:t,onChange:e=>i({value:e.target.value}),className:"px-2 py-1 rounded-md text-xs outline-none",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",colorScheme:"dark"}}),o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"to"}),(0,n.jsx)("input",{type:"date",value:r,onChange:e=>i({valueTo:e.target.value}),className:"px-2 py-1 rounded-md text-xs outline-none",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",colorScheme:"dark"}})]})]})}function sL(e){var t;let{value:r,enumValues:o,enumColors:l,multiple:a,onChange:s}=e,i=Array.isArray(r)?r:r?[r]:[];return a?(0,n.jsx)("div",{className:"flex flex-wrap gap-1",children:o.map((e,t)=>{var o;let a=i.includes(e),c=null!=(o=null==l?void 0:l[t])?o:"#94a3b8";return(0,n.jsx)("button",{type:"button",onClick:()=>{let t=a?i.filter(t=>t!==e):[...i,e];s(1!==t.length||Array.isArray(r)?t:t[0])},className:"px-2 py-0.5 rounded-full text-[10px] transition-colors cursor-pointer",style:{background:a?"".concat(c,"20"):"var(--color-surface)",border:"1px solid ".concat(a?"".concat(c,"60"):"var(--color-border)"),color:a?c:"var(--color-text-muted)"},children:e},e)})}):(0,n.jsxs)("select",{value:"string"==typeof r?r:null!=(t=r[0])?t:"",onChange:e=>s(e.target.value),className:"px-2 py-1 rounded-md text-xs outline-none cursor-pointer",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",minWidth:100},children:[(0,n.jsx)("option",{value:"",children:"Select..."}),o.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})}function sT(){return null}function sD(e){let{value:t,relatedObjectName:r,members:o,multiple:l,onChange:a}=e;if(o&&o.length>0){let e=Array.isArray(t)?t:t?[t]:[];return(0,n.jsx)("div",{className:"flex flex-wrap gap-1",children:o.map(t=>{let r=e.includes(t.id);return(0,n.jsx)("button",{type:"button",onClick:()=>{l?a(r?e.filter(e=>e!==t.id):[...e,t.id]):a(r?"":t.id)},className:"px-2 py-0.5 rounded-full text-[10px] transition-colors cursor-pointer",style:{background:r?"var(--color-accent-light)":"var(--color-surface)",border:"1px solid ".concat(r?"var(--color-accent)":"var(--color-border)"),color:r?"var(--color-accent)":"var(--color-text-muted)"},children:t.name},t.id)})})}return(0,n.jsx)(sC,{value:Array.isArray(t)?t.join(", "):String(null!=t?t:""),onChange:e=>{let t=e.split(",").map(e=>e.trim()).filter(Boolean);a(1===t.length?t[0]:t)},placeholder:r?"Search ".concat(r,"..."):"ID..."})}function sE(e){var t,r,o,l,a,s,i;let{rule:c,field:d,fields:u,members:x,onUpdate:h,onRemove:p}=e,m=null!=(t=null==d?void 0:d.type)?t:"text",f=function(e){switch(e){case"text":case"richtext":case"email":default:return rs;case"number":return ri;case"date":return rc;case"enum":return rd;case"boolean":return ru;case"relation":case"user":return rx;case"tags":return rh}}(m),v="between"===c.operator||"date_between"===c.operator,g="relative_past"===c.operator||"relative_next"===c.operator,y="is_any_of"===c.operator||"is_none_of"===c.operator||"has_any"===c.operator||"has_none"===c.operator||"has_all"===c.operator,b="is_empty"===c.operator||"is_not_empty"===c.operator||"is_true"===c.operator||"is_false"===c.operator;return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[(0,n.jsx)("select",{value:c.field,onChange:e=>(e=>{var t;let r=u.find(t=>t.name===e);h({field:e,operator:rp(null!=(t=null==r?void 0:r.type)?t:"text"),value:void 0,valueTo:void 0,relativeAmount:void 0,relativeUnit:void 0})})(e.target.value),className:"px-2 py-1 rounded-md text-xs outline-none cursor-pointer font-medium",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",maxWidth:140},children:u.map(e=>{var t;return(0,n.jsxs)("option",{value:e.name,children:[null!=(t=sk[e.type])?t:"?"," ",e.name]},e.name)})}),(0,n.jsx)("select",{value:c.operator,onChange:e=>h({operator:e.target.value,value:void 0,valueTo:void 0}),className:"px-2 py-1 rounded-md text-xs outline-none cursor-pointer",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text-muted)"},children:f.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),!b&&(0,n.jsxs)(n.Fragment,{children:[("text"===m||"richtext"===m||"email"===m||"tags"===m)&&(0,n.jsx)(sC,{value:String(null!=(r=c.value)?r:""),onChange:e=>h({value:e})}),"number"===m&&(0,n.jsx)(sS,{value:"number"==typeof c.value?c.value:void 0,valueTo:"number"==typeof c.valueTo?c.valueTo:void 0,showRange:v,onChange:(e,t)=>h({value:e,valueTo:t})}),"date"===m&&(0,n.jsx)(sM,{value:String(null!=(o=c.value)?o:""),valueTo:String(null!=(l=c.valueTo)?l:""),showRange:v,showRelative:g,relativeAmount:c.relativeAmount,relativeUnit:c.relativeUnit,onChange:h}),"enum"===m&&(0,n.jsx)(sL,{value:null!=(a=c.value)?a:"",enumValues:null!=(s=null==d?void 0:d.enum_values)?s:[],enumColors:null==d?void 0:d.enum_colors,multiple:y,onChange:e=>h({value:e})}),"boolean"===m&&(0,n.jsx)(sT,{}),("relation"===m||"user"===m)&&(0,n.jsx)(sD,{value:null!=(i=c.value)?i:"",relatedObjectName:null==d?void 0:d.related_object_name,members:"user"===m?x:void 0,multiple:y,onChange:e=>h({value:e})})]}),(0,n.jsx)("button",{type:"button",onClick:p,className:"p-1 rounded transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Remove filter",children:(0,n.jsx)(sg,{size:14})})]})}function sR(e){let{fields:t,filters:r,onFiltersChange:l,savedViews:a,activeViewName:s,onSaveView:i,onLoadView:c,onDeleteView:d,onSetActiveView:u,members:x}=e,[h,p]=(0,o.useState)(!1),[m,f]=(0,o.useState)(!1),[v,g]=(0,o.useState)(!1),[y,b]=(0,o.useState)(""),j=(0,o.useRef)(null),k=r.rules.length>0;(0,o.useEffect)(()=>{v&&j.current&&j.current.focus()},[v]);let w=(0,o.useCallback)(e=>{var n;let o=t.find(t=>t.name===e),a=null!=(n=null==o?void 0:o.type)?n:"text",s={id:Math.random().toString(36).slice(2,9),field:e,operator:rp(a)};l({...r,rules:[...r.rules,s]}),p(!1)},[t,r,l]),N=(0,o.useCallback)((e,t)=>{let n=r.rules.map(r=>rm(r)||r.id!==e?r:{...r,...t});l({...r,rules:n})},[r,l]),C=(0,o.useCallback)(e=>{let t=r.rules.filter(t=>!!rm(t)||t.id!==e);l({...r,rules:t})},[r,l]),S=(0,o.useCallback)(()=>{l(rv()),u(void 0)},[l,u]),M=(0,o.useCallback)(()=>{l({...r,conjunction:"and"===r.conjunction?"or":"and"})},[r,l]),L=(0,o.useCallback)(()=>{y.trim()&&(i(y.trim()),b(""),g(!1))},[y,i]),T=(0,o.useMemo)(()=>{let e={};for(let n of t){var r;let t=null!=(r=e[n.type])?r:[];t.push(n),e[n.type]=t}return e},[t]);return(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs font-medium",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(sf,{}),"Filters"]}),r.rules.length>=2&&(0,n.jsx)("button",{type:"button",onClick:M,className:"px-2 py-0.5 rounded-full text-[10px] font-semibold uppercase tracking-wider transition-colors cursor-pointer",style:{background:"var(--color-accent-light, rgba(99,102,241,0.1))",color:"var(--color-accent)",border:"1px solid var(--color-accent)"},title:"Matching ".concat("and"===r.conjunction?"ALL":"ANY"," rules. Click to toggle."),children:r.conjunction}),r.rules.map(e=>rm(e)?null:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[11px] max-w-[250px] truncate",style:{background:"var(--color-accent-light, rgba(99,102,241,0.1))",color:"var(--color-accent)",border:"1px solid var(--color-accent)"},title:rg(e),children:[(0,n.jsx)("span",{className:"truncate",children:rg(e)}),(0,n.jsx)("button",{type:"button",onClick:()=>C(e.id),className:"flex-shrink-0 cursor-pointer p-0.5 rounded-full transition-colors",style:{color:"var(--color-accent)"},children:(0,n.jsx)(sg,{size:10})})]},e.id)),(0,n.jsx)(sw,{trigger:(0,n.jsxs)("button",{type:"button",className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-colors cursor-pointer",style:{color:"var(--color-text-muted)",border:"1px dashed var(--color-border)"},children:[(0,n.jsx)(sv,{})," Add filter"]}),open:h,onOpenChange:p,children:Object.entries(T).map(e=>{var t;let[r,o]=e;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"px-3 py-1 text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:[null!=(t=sk[r])?t:"?"," ",r]}),o.map(e=>(0,n.jsx)(sN,{onClick:()=>w(e.name),children:e.name},e.name))]},r)})}),k&&(0,n.jsxs)("button",{type:"button",onClick:S,className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] transition-colors cursor-pointer",style:{color:"var(--color-accent)",background:"var(--color-accent-light, rgba(99,102,241,0.1))"},children:[(0,n.jsx)(sg,{size:10}),"Clear all"]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)(sw,{trigger:(0,n.jsxs)("button",{type:"button",className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-colors cursor-pointer",style:{color:s?"var(--color-accent)":"var(--color-text-muted)",border:"1px solid ".concat(s?"var(--color-accent)":"var(--color-border)"),background:s?"var(--color-accent-light, rgba(99,102,241,0.1))":"transparent"},children:[(0,n.jsx)(sb,{}),null!=s?s:"Views",(0,n.jsx)(sy,{})]}),open:m,onOpenChange:f,align:"right",children:[0===a.length&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs",style:{color:"var(--color-text-muted)"},children:"No saved views"}),a.map(e=>(0,n.jsxs)("div",{className:"flex items-center group",children:[(0,n.jsxs)(sN,{onClick:()=>{c(e),f(!1)},active:s===e.name,children:[(0,n.jsx)("span",{className:"flex-1 truncate",children:e.name}),e.view_type&&"table"!==e.view_type&&(0,n.jsx)("span",{className:"text-[9px] px-1.5 py-0.5 rounded ml-1 capitalize",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:e.view_type}),e.filters&&e.filters.rules.length>0&&(0,n.jsxs)("span",{className:"text-[10px] ml-1",style:{color:"var(--color-text-muted)"},children:[e.filters.rules.length," filter",1!==e.filters.rules.length?"s":""]})]}),(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),d(e.name)},className:"px-2 py-1 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Delete view",children:(0,n.jsx)(sj,{})})]},e.name)),(0,n.jsx)("div",{className:"border-t my-1",style:{borderColor:"var(--color-border)"}}),k&&!v&&(0,n.jsxs)(sN,{onClick:()=>g(!0),children:[(0,n.jsx)(sb,{}),"Save current filters as view..."]}),v&&(0,n.jsxs)("div",{className:"px-3 py-2 flex items-center gap-1",children:[(0,n.jsx)("input",{ref:j,type:"text",value:y,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"===e.key&&L(),"Escape"===e.key&&g(!1)},placeholder:"View name...",className:"px-2 py-1 rounded-md text-xs outline-none flex-1",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),(0,n.jsx)("button",{type:"button",onClick:L,className:"px-2 py-1 rounded-md text-xs transition-colors cursor-pointer",style:{background:"var(--color-accent)",color:"white"},children:"Save"})]}),s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t my-1",style:{borderColor:"var(--color-border)"}}),(0,n.jsxs)(sN,{onClick:()=>{S(),f(!1)},children:[(0,n.jsx)(sg,{size:12}),"Clear active view"]})]})]})]}),k&&(0,n.jsx)("div",{className:"space-y-1.5 pl-5",children:r.rules.map((e,o)=>{if(rm(e))return null;let l=t.find(t=>t.name===e.field);return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[o>0&&(0,n.jsx)("span",{className:"text-[10px] font-semibold uppercase w-8 text-center flex-shrink-0",style:{color:"var(--color-text-muted)"},children:r.conjunction}),0===o&&(0,n.jsx)("span",{className:"w-8 flex-shrink-0"}),(0,n.jsx)(sE,{rule:e,field:l,fields:t,members:x,onUpdate:t=>N(e.id,t),onRemove:()=>C(e.id)})]},e.id)})})]})}let sW="__home__",sI={id:sW,type:"home",title:"Home",pinned:!0};function sB(e){return"".concat("dench:tabs",":").concat(e||"default")}function sF(e,t){return e.tabs.some(e=>e.id===t)?{...e,activeTabId:t}:e}function sA(e){let{tabs:t,activeTabId:r,onActivate:l,onClose:a,onCloseOthers:s,onCloseToRight:i,onCloseAll:c,onReorder:d,onTogglePin:u}=e,[x,h]=(0,o.useState)(null),[p,m]=(0,o.useState)(null),[f,v]=(0,o.useState)(null),g=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!x)return;let e=()=>h(null);return window.addEventListener("click",e),window.addEventListener("contextmenu",e),()=>{window.removeEventListener("click",e),window.removeEventListener("contextmenu",e)}},[x]);let y=(0,o.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),h({tabId:t,x:e.clientX,y:e.clientY})},[]),b=(0,o.useCallback)((e,t)=>{1===e.button&&(e.preventDefault(),a(t))},[a]),j=(0,o.useCallback)((e,t)=>{m(t),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",String(t))},[]),k=(0,o.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",v(t)},[]),w=(0,o.useCallback)((e,t)=>{e.preventDefault(),null!==p&&p!==t&&d(p,t),m(null),v(null)},[p,d]),N=(0,o.useCallback)(()=>{m(null),v(null)},[]);if(0===t.length)return null;let C=x?t.find(e=>e.id===x.tabId):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:g,className:"flex items-end overflow-x-auto flex-shrink-0",style:{background:"var(--color-surface)",borderBottom:"1px solid var(--color-border)",scrollbarWidth:"none"},children:t.map((e,t)=>{let o=e.id===r,s=f===t&&p!==t,i=e.id===sW;return(0,n.jsx)("button",{type:"button",draggable:!i,onClick:()=>l(e.id),onMouseDown:i?void 0:t=>b(t,e.id),onContextMenu:i?void 0:t=>y(t,e.id),onDragStart:i?void 0:e=>j(e,t),onDragOver:i?void 0:e=>k(e,t),onDrop:i?void 0:e=>w(e,t),onDragEnd:i?void 0:N,className:"group flex items-center gap-1.5 h-[34px] text-[12.5px] font-medium cursor-pointer flex-shrink-0 relative transition-colors duration-75 select-none ".concat(i?"px-2.5":"pl-3 pr-1.5"),style:{color:o?"var(--color-text)":"var(--color-text-muted)",background:o?"var(--color-bg)":"transparent",borderBottom:o?"2px solid var(--color-accent)":"2px solid transparent",borderLeft:s&&!i?"2px solid var(--color-accent)":"2px solid transparent",opacity:p===t?.5:1,maxWidth:i?void 0:200,borderRight:i?"1px solid var(--color-border)":void 0},title:i?"Home (New Chat)":void 0,children:i?(0,n.jsx)(sU,{}):(0,n.jsxs)(n.Fragment,{children:[e.pinned&&(0,n.jsx)(sO,{}),(0,n.jsx)(s_,{type:e.type,icon:e.icon,appPath:e.path}),(0,n.jsx)("span",{className:"truncate max-w-[140px]",children:e.title}),!e.pinned&&(0,n.jsx)("span",{role:"button",tabIndex:-1,onClick:t=>{t.stopPropagation(),a(e.id)},onKeyDown:t=>{"Enter"===t.key&&(t.stopPropagation(),a(e.id))},className:"ml-0.5 p-0.5 rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(sz,{})})]})},e.id)})}),x&&C&&(0,n.jsxs)("div",{className:"fixed z-[9999] min-w-[180px] rounded-lg border py-1 shadow-lg",style:{left:x.x,top:x.y,background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[(0,n.jsx)(sP,{label:C.pinned?"Unpin Tab":"Pin Tab",onClick:()=>{u(x.tabId),h(null)}}),(0,n.jsx)("div",{className:"h-px my-1",style:{background:"var(--color-border)"}}),(0,n.jsx)(sP,{label:"Close",shortcut:"⌘W",disabled:C.pinned,onClick:()=>{a(x.tabId),h(null)}}),(0,n.jsx)(sP,{label:"Close Others",onClick:()=>{s(x.tabId),h(null)}}),(0,n.jsx)(sP,{label:"Close to the Right",onClick:()=>{i(x.tabId),h(null)}}),(0,n.jsx)(sP,{label:"Close All",onClick:()=>{c(),h(null)}})]})]})}function sP(e){let{label:t,shortcut:r,disabled:o,onClick:l}=e;return(0,n.jsxs)("button",{type:"button",disabled:o,onClick:l,className:"w-full flex items-center justify-between px-3 py-1.5 text-[12.5px] text-left transition-colors disabled:opacity-40 cursor-pointer disabled:cursor-default",style:{color:"var(--color-text)"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{children:t}),r&&(0,n.jsx)("span",{className:"ml-4 text-[11px]",style:{color:"var(--color-text-muted)"},children:r})]})}function s_(e){let{type:t,icon:r,appPath:o}=e;if(r&&o&&(r.endsWith(".png")||r.endsWith(".svg")||r.endsWith(".jpg")||r.endsWith(".jpeg")||r.endsWith(".webp")))return(0,n.jsx)("img",{src:na(o,r),alt:"",width:14,height:14,className:"rounded-sm flex-shrink-0",style:{objectFit:"cover"}});switch(t){case"home":return(0,n.jsx)(sU,{});case"app":return(0,n.jsx)(sV,{});case"chat":return(0,n.jsx)(sJ,{});case"cron":return(0,n.jsx)(sK,{});case"object":return(0,n.jsx)(sq,{});default:return(0,n.jsx)(sH,{})}}function sz(){return(0,n.jsxs)("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:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}function sO(){return(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",className:"flex-shrink-0",style:{opacity:.5},children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"})})}function sU(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.7},children:[(0,n.jsx)("path",{d:"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),(0,n.jsx)("polyline",{points:"9 22 9 12 15 12 15 22"})]})}function sH(){return(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]})}function sV(){return(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]})}function sJ(){return(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function sK(){return(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function sq(){return(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M9 21V9"})]})}let sG=(0,rD.default)(()=>Promise.all([r.e(2078),r.e(4560),r.e(7858)]).then(r.bind(r,77858)),{loadableGenerated:{webpack:()=>[77858]},ssr:!1});function s$(e){return e.startsWith("~")&&!e.startsWith("~/")}function sZ(e){return e.startsWith("/")}function sY(e){return e.startsWith("~/")}function sQ(e){return s$(e)?"/api/workspace/virtual-file?path=".concat(encodeURIComponent(e)):sZ(e)||sY(e)?"/api/workspace/browse-file?path=".concat(encodeURIComponent(e)):"/api/workspace/file?path=".concat(encodeURIComponent(e))}function sX(e){return sZ(e)||sY(e)?"/api/workspace/browse-file?path=".concat(encodeURIComponent(e),"&raw=true"):"/api/workspace/raw-file?path=".concat(encodeURIComponent(e))}let s0="dench-workspace-left-sidebar-width",s1="dench-workspace-right-sidebar-width";function s2(e,t,r){return Math.min(r,Math.max(t,e))}function s4(e){let{mode:t,containerRef:r,min:l,max:a,onResize:s}=e,[i,c]=(0,o.useState)(!1),d=(0,o.useCallback)(e=>{e.preventDefault(),c(!0);let n=e=>{let n=r.current;if(!n)return;let o=n.getBoundingClientRect();s(s2("left"===t?e.clientX-o.left:o.right-e.clientX,l,a))},o=()=>{c(!1),document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",o),document.body.style.removeProperty("user-select"),document.body.style.removeProperty("cursor"),document.body.classList.remove("resizing")};document.body.style.setProperty("user-select","none"),document.body.style.setProperty("cursor","col-resize"),document.body.classList.add("resizing"),document.addEventListener("mousemove",n),document.addEventListener("mouseup",o)},[r,t,l,a,s]);return(0,n.jsx)("div",{role:"separator","aria-orientation":"vertical",onMouseDown:d,className:"cursor-col-resize flex justify-center transition-colors ".concat(i?"bg-blue-600/30":"hover:bg-blue-600/30"),style:{position:"absolute",["left"===t?"right":"left"]:-2,top:0,bottom:0,width:4,zIndex:20}})}function s5(e,t){for(let r of e){if(r.path===t)return r;if(r.children){let e=s5(r.children,t);if(e)return e}}return null}function s6(e){let t=e.split("/");return t[t.length-1]}function s3(e,t){let r=s5(e,t);if(r||!t.startsWith("knowledge/")&&(r=s5(e,"knowledge/".concat(t)))||t.startsWith("knowledge/")&&(r=s5(e,t.slice(10))))return r;let n=t.split("/").pop();return n&&(r=function e(t){for(let r of t){if("object"===r.type&&s6(r.path)===n)return r;if(r.children){let t=e(r.children);if(t)return t}}return null}(e))?r:null}function s8(){return(0,n.jsx)(o.Suspense,{fallback:(0,n.jsx)("div",{className:"flex h-screen items-center justify-center",style:{background:"var(--color-bg)"},children:(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})}),children:(0,n.jsx)(s7,{})})}function s7(){var e,t,a,s;let i=(0,l.useSearchParams)(),c=(0,l.useRouter)(),d=(0,o.useRef)(!1),u=(0,o.useRef)(-1),x=(0,o.useRef)(null),h=(0,o.useRef)(null),p=(0,o.useRef)(null),m=(0,o.useRef)(null),{tree:f,loading:v,exists:g,refresh:y,reconnect:b,browseDir:j,setBrowseDir:k,parentDir:w,workspaceRoot:N,openclawDir:C,activeWorkspace:S,showHidden:M,setShowHidden:L}=function(){let[e,t]=(0,o.useState)([]),[r,n]=(0,o.useState)(!0),[l,a]=(0,o.useState)(!1),[s,i]=(0,o.useState)(null),[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)(null),[h,p]=(0,o.useState)(null),[m,f]=(0,o.useState)(null),[v,g]=(0,o.useState)(!1),y=(0,o.useRef)(!0),b=(0,o.useRef)(1e3),j=(0,o.useRef)(0),[k,w]=(0,o.useState)(0),N=(0,o.useCallback)(async()=>{let e=++j.current;try{let d=v?"?showHidden=1":"",u=await fetch("/api/workspace/tree".concat(d)),h=await u.json();if(y.current&&j.current===e){var r,o,l,s,i,c;t(null!=(r=h.tree)?r:[]),a(null!=(o=h.exists)&&o),x(null!=(l=h.workspaceRoot)?l:null),p(null!=(s=h.openclawDir)?s:null),f(null!=(c=null!=(i=h.workspace)?i:h.profile)?c:null),n(!1)}}catch(t){y.current&&j.current===e&&n(!1)}},[v]),C=(0,o.useCallback)(async e=>{let r=++j.current;try{n(!0);let s=v?"&showHidden=1":"",i=await fetch("/api/workspace/browse?dir=".concat(encodeURIComponent(e)).concat(s)),c=await i.json();if(y.current&&j.current===r){var o,l;t(null!=(o=c.entries)?o:[]),d(null!=(l=c.parentDir)?l:null),a(!0),n(!1)}}catch(e){y.current&&j.current===r&&n(!1)}},[v]),S=(0,o.useRef)(null),M=(0,o.useCallback)(e=>{let t=e;null!=e&&u&&e===u&&(t=null),null!=t&&t!==S.current&&n(!0),S.current=t,i(t)},[u]),L=(0,o.useCallback)(async()=>{s?await C(s):await N()},[s,C,N]),T=(0,o.useCallback)(()=>{L()},[L]),D=(0,o.useCallback)(()=>{w(e=>e+1),L()},[L]);return(0,o.useEffect)(()=>(y.current=!0,L(),()=>{y.current=!1}),[L]),(0,o.useEffect)(()=>{if(s)return;let e=null,t=null,r=null,n=!0,o=null;function l(){!t&&n&&(t=setInterval(()=>{n&&N()},5e3))}return function a(){if(n)try{(e=new EventSource("/api/workspace/watch")).addEventListener("connected",()=>{b.current=1e3,t&&(clearInterval(t),t=null)}),e.addEventListener("change",()=>{o&&clearTimeout(o),o=setTimeout(()=>{n&&N()},300)}),e.addEventListener("error",()=>{null==e||e.close(),e=null,function(){if(!n)return;l();let e=b.current;b.current=Math.min(2*e,3e4),r=setTimeout(()=>{t&&(clearInterval(t),t=null),a()},e)}()})}catch(e){l()}}(),()=>{n=!1,e&&e.close(),t&&clearInterval(t),r&&clearTimeout(r),o&&clearTimeout(o)}},[s,N,k]),{tree:e,loading:r,exists:l,refresh:T,reconnect:D,browseDir:s,setBrowseDir:M,parentDir:c,workspaceRoot:u,openclawDir:h,activeWorkspace:m,showHidden:v,setShowHidden:g}}(),{search:T}=function(e){let[t,r]=(0,o.useState)([]),[n,l]=(0,o.useState)(!0),a=(0,o.useRef)(!0),s=(0,o.useCallback)(async()=>{try{let t=await fetch("/api/workspace/search-index"),n=await t.json();if(a.current){var e;r(null!=(e=n.items)?e:[]),l(!1)}}catch(e){a.current&&l(!1)}},[]);(0,o.useEffect)(()=>(a.current=!0,s(),()=>{a.current=!1}),[s,e]);let i=(0,o.useMemo)(()=>{if(0===t.length)return null;let e=t.map(e=>({...e,fieldValues:e.fields?Object.values(e.fields).join(" "):void 0}));return new a_.A(e,az)},[t]),c=(0,o.useCallback)(function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20;return e.trim()?i?i.search(e,{limit:r}).map(e=>e.item):[]:[...t].toSorted((e,t)=>{var r,n;let o={object:0,file:1,entry:2};return(null!=(r=o[e.kind])?r:9)-(null!=(n=o[t.kind])?n:9)}).slice(0,r)},[i,t]),d=(0,o.useRef)(c);return d.current=c,{items:t,loading:n,search:(0,o.useCallback)((e,t)=>d.current(e,t),[])}}(),[D,E]=(0,o.useState)(null),[R,W]=(0,o.useState)(null),[I,B]=(0,o.useState)({kind:"none"}),[F,A]=(0,o.useState)(!0),[P,_]=(0,o.useState)(null),[z,O]=(0,o.useState)(null),[U,H]=(0,o.useState)(null),[V,J]=(0,o.useState)([]),[K,q]=(0,o.useState)(!0),[G,$]=(0,o.useState)(0),[Z,Y]=(0,o.useState)(new Set),[Q,X]=(0,o.useState)([]),[ee,et]=(0,o.useState)(null),er=(0,o.useCallback)(e=>{X(t=>{let r=t.findIndex(t=>t.childSessionKey===e.childSessionKey);if(r>=0){if(t[r].status===e.status)return t;let n=[...t];return n[r]={...t[r],...e},n}return[...t,e]})},[]),en=(0,o.useCallback)(e=>{et(e)},[]),eo=(0,o.useCallback)(()=>{et(null)},[]),ea=(0,o.useCallback)(e=>{let t=Q.find(t=>t.childSessionKey===e);if(t)return void et(t.childSessionKey);let r=Q.find(t=>t.task===e);r&&et(r.childSessionKey)},[Q]),es=(0,o.useMemo)(()=>{var e;return ee&&null!=(e=Q.find(e=>e.childSessionKey===ee))?e:null},[ee,Q]),[ei,ec]=(0,o.useState)([]),[ed,eu]=(0,o.useState)("overview"),[ex,eh]=(0,o.useState)("month"),[ep,em]=(0,o.useState)(null),[ef,ev]=(0,o.useState)("all"),[eg,ey]=(0,o.useState)(null),[ej,ek]=(0,o.useState)(null),ew=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:768,[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia("(max-width: ".concat(e-1,"px)")),n=()=>r(t.matches);return n(),t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[e]),t}(),[eN,eC]=(0,o.useState)(!1),[eS,eM]=(0,o.useState)(!1),[eL,eT]=(0,o.useState)(!1),[eD,eE]=(0,o.useState)(!1),[eR,eW]=(0,o.useState)(!1),[eI,eB]=(0,o.useState)({tabs:[sI],activeTabId:sW}),eF=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=S||null;eF.current!==e&&(eF.current=e,eB(function(e){try{let t=localStorage.getItem(sB(e));if(!t)return{tabs:[sI],activeTabId:sW};let r=JSON.parse(t);if(!Array.isArray(r.tabs))return{tabs:[sI],activeTabId:sW};if(r.tabs.some(e=>e.id===sW)){let e=r.tabs.find(e=>e.id===sW),t=r.tabs.filter(e=>e.id!==sW);return{...r,tabs:[e,...t]}}return{tabs:[sI,...r.tabs],activeTabId:r.activeTabId||sW}}catch(e){return{tabs:[sI],activeTabId:sW}}}(e)))},[S]),(0,o.useEffect)(()=>{let e=S||null;if(eF.current===e)try{let t={tabs:eI.tabs.map(e=>{let{id:t,type:r,title:n,icon:o,path:l,sessionId:a,pinned:s}=e;return{id:t,type:r,title:n,icon:o,path:l,sessionId:a,pinned:s}}),activeTabId:eI.activeTabId};localStorage.setItem(sB(e),JSON.stringify(t))}catch(e){}},[eI,S]);let eA=(0,o.useRef)(null),eP=(0,o.useCallback)(e=>{var t,r,n;let o={id:Math.random().toString(36).slice(2,10),type:"object"===e.type?"object":(t=e.path).includes(".dench.app")?"app":t.startsWith("~cron")?"cron":"file",title:(r=e.path,(n=e.name)?n:r.split("/").pop()||r),path:e.path};eB(e=>(function(e,t){var r,n,o,l;let a=t.path?(r=e.tabs,n=t.path,r.find(e=>e.path===n)):t.sessionId?(o=e.tabs,l=t.sessionId,o.find(e=>"chat"===e.type&&e.sessionId===l)):void 0;return a?{...e,activeTabId:a.id}:{tabs:[...e.tabs,t],activeTabId:t.id}})(e,o))},[]),[e_,ez]=(0,o.useState)(260),[eO,eU]=(0,o.useState)(320);(0,o.useEffect)(()=>{let e=window.localStorage.getItem(s0),t=e?parseInt(e,10):NaN;Number.isFinite(t)&&ez(s2(t,200,480));let r=window.localStorage.getItem(s1),n=r?parseInt(r,10):NaN;Number.isFinite(n)&&eU(s2(n,260,900))},[]),(0,o.useEffect)(()=>{window.localStorage.setItem(s0,String(e_))},[e_]),(0,o.useEffect)(()=>{window.localStorage.setItem(s1,String(eO))},[eO]),(0,o.useEffect)(()=>{let e=e=>{let t=e.metaKey||e.ctrlKey,r=e.key.toLowerCase();if(t&&"b"===r){e.preventDefault(),e.shiftKey?eE(e=>!e):eT(e=>!e);return}if(t&&"j"===r&&!e.shiftKey&&!e.altKey){e.preventDefault(),eW(e=>!e);return}if(t&&"w"===r&&!e.shiftKey&&!e.altKey){var n;e.preventDefault(),null==(n=eA.current)||n.call(eA);return}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let eH=(0,o.useMemo)(()=>{if(!R||s$(R))return;let e=R.split("/").pop()||R;return{path:R,filename:e,isDirectory:"directory"===I.kind}},[R,I.kind]);(0,o.useEffect)(()=>{R||H(null)},[R]);let eV=(0,o.useCallback)(e=>{B(t=>"document"===t.kind||"file"===t.kind||"code"===t.kind?{...t,data:{...t.data,content:e}}:t)},[]),eJ=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/workspace/context"),t=await e.json();E(t)}catch(e){}},[]);(0,o.useEffect)(()=>{eJ()},[eJ]);let eK=(0,o.useCallback)(async()=>{q(!0);try{var e;let t=await fetch("/api/web-sessions"),r=await t.json();J(null!=(e=r.sessions)?e:[])}catch(e){}finally{q(!1)}},[]);(0,o.useEffect)(()=>{eK()},[eK,G]);let eq=(0,o.useCallback)(()=>{$(e=>e+1)},[]),eG=(0,o.useCallback)(()=>{var e;(e={setBrowseDir:k,setActivePath:W,setContent:B,setChatSidebarPreview:_,setShowChatSidebar:A,setActiveSessionId:O,setActiveSubagentKey:et,resetMainChat:()=>{var e;null==(e=h.current)||e.newSession()},replaceUrlToRoot:()=>{},reconnectWorkspaceWatcher:b,refreshSessions:eq,refreshContext:()=>{eJ()}}).setBrowseDir(null),e.setActivePath(null),e.setContent({kind:"none"}),e.setChatSidebarPreview(null),e.setShowChatSidebar(!0),e.setActiveSessionId(null),e.setActiveSubagentKey(null),e.resetMainChat(),e.replaceUrlToRoot(),e.reconnectWorkspaceWatcher(),e.refreshSessions(),e.refreshContext()},[b,eJ,eq,c,k]),e$=(0,o.useCallback)(async e=>{if((await fetch("/api/web-sessions/".concat(e),{method:"DELETE"})).ok){if(z===e){var t,r;O(null),et(null);let n=V.filter(t=>t.id!==e);if(n.length>0){let e=n[0];O(e.id),null==(t=h.current)||t.loadSession(e.id)}else null==(r=h.current)||r.newSession()}eK()}},[z,V,eK]),eZ=(0,o.useCallback)(async(e,t)=>{await fetch("/api/web-sessions/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:t})}),eK()},[eK]);(0,o.useEffect)(()=>{let e=!1,t=async()=>{try{var t;let r=await fetch("/api/chat/active");if(e)return;let n=null!=(t=(await r.json()).sessionIds)?t:[];Y(e=>e.size===n.length&&n.every(t=>e.has(t))?e:new Set(n))}catch(e){}};t();let r=setInterval(t,3e3);return()=>{e=!0,clearInterval(r)}},[]);let eY=(0,o.useCallback)(async()=>{try{var e;let t=await fetch("/api/cron/jobs"),r=await t.json();ec(null!=(e=r.jobs)?e:[])}catch(e){}},[]);(0,o.useEffect)(()=>{eY();let e=setInterval(eY,3e4);return()=>clearInterval(e)},[eY]);let eQ=(0,o.useCallback)(async e=>{W(e.path),B({kind:"loading"});try{if("object"===e.type){let t=s6(e.path),r=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t)));if(!r.ok){let e=await r.json().catch(()=>({}));if("DUCKDB_NOT_INSTALLED"===e.code)return void B({kind:"duckdb-missing"});B({kind:"none"});return}let n=await r.json();B({kind:"object",data:n})}else if("document"===e.type){let t=await fetch(sQ(e.path));if(!t.ok)return void B({kind:"none"});let r=await t.json();B({kind:"document",data:r,title:e.name.replace(/\.md$/,"")})}else if("database"===e.type)B({kind:"database",dbPath:e.path,filename:e.name});else if("report"===e.type)B({kind:"report",reportPath:e.path,filename:e.name});else if("file"===e.type){var t,n;if(rJ(e.name)){let t=sX(e.path);B({kind:"spreadsheet",url:t,filename:e.name,filePath:e.path});return}if(ol(e.name)){try{let t=await fetch(sX(e.path));if(!t.ok)return void B({kind:"none"});let n=await t.arrayBuffer(),o=await Promise.all([r.e(5360),r.e(4995)]).then(r.t.bind(r,14995,19)),l=await o.convertToHtml({arrayBuffer:n});B({kind:"richDocument",html:l.value,filePath:e.path,mode:"docx"})}catch(e){B({kind:"none"})}return}if(oa(e.name)){let t=await fetch(sQ(e.path));if(!t.ok)return void B({kind:"none"});let r=await t.json();B({kind:"richDocument",html:os(r.content),filePath:e.path,mode:"txt"});return}let o=null!=(n=null==(t=e.name.split(".").pop())?void 0:t.toLowerCase())?n:"";if("html"===o||"htm"===o)return void B({kind:"html",rawUrl:sX(e.path),contentUrl:sQ(e.path),filename:e.name});let l=nj(e.name);if(l){let t=sX(e.path);B({kind:"media",url:t,mediaType:l,filename:e.name,filePath:e.path});return}let a=await fetch(sQ(e.path));if(!a.ok)return void B({kind:"none"});let s=await a.json();aU(e.name)?B({kind:"code",data:s,filename:e.name,filePath:e.path}):B({kind:"file",data:s,filename:e.name})}else if("app"===e.type){let t=await fetch("/api/apps?app=".concat(encodeURIComponent(e.path),"&file=.dench.yaml&meta=1")),r={name:e.name};if(t.ok)try{r=await t.json()}catch(e){}B({kind:"app",appPath:e.path,manifest:r,filename:e.name})}else"folder"===e.type&&B({kind:"directory",node:e})}catch(e){B({kind:"none"})}},[]),eX=(0,o.useCallback)(e=>{var t,r,n;if(j&&sZ(e.path)){if(N&&e.path===N)return void k(null);if(C){if(e.path===C+"/cron"){k(null),W("~cron"),B({kind:"cron-dashboard"});return}if(C&&e.path.startsWith(C+"/web-chat")){k(null),W(null),B({kind:"none"}),null==(t=h.current)||t.newSession();return}}if("folder"===e.type){k(e.path),W(e.path),B({kind:"directory",node:{name:e.name,path:e.path,type:"folder"}});return}}if(e.path.startsWith("~chats/")){let t=e.path.slice(7);W(null),B({kind:"none"}),O(t),null==(r=h.current)||r.loadSession(t);return}if("~chats"===e.path){W(null),B({kind:"none"}),null==(n=h.current)||n.newSession();return}if(e.path.startsWith("~cron/")){let t=e.path.slice(6),r=ei.find(e=>e.id===t);if(r){W(e.path),B({kind:"cron-job",jobId:t,job:r});return}}if("~cron"===e.path){W(e.path),B({kind:"cron-dashboard"});return}eP(e),eQ(e)},[eQ,eP,ei,j,N,C,k]),e0=(0,o.useCallback)(e=>{if(e===sW){W(null),B({kind:"none"}),eB(t=>sF(t,e));return}eB(t=>{let r=sF(t,e),n=r.tabs.find(t=>t.id===e);if(null==n?void 0:n.path){let e=s3(f,n.path);if(e)eQ(e);else if("~cron"===n.path)W("~cron"),B({kind:"cron-dashboard"});else if(n.path.startsWith("~cron/")){W(n.path);let e=n.path.slice(6),t=ei.find(t=>t.id===e);t&&B({kind:"cron-job",jobId:e,job:t})}}return r})},[f,eQ,ei]),e1=(0,o.useCallback)(e=>{eB(t=>{let r=function(e,t){if(t===sW)return e;let r=e.tabs.findIndex(e=>e.id===t);if(-1===r||e.tabs[r].pinned)return e;let n=e.tabs.filter(e=>e.id!==t),o=e.activeTabId;return e.activeTabId===t&&(o=0===n.length?null:r<n.length?n[r].id:n[n.length-1].id),{tabs:n,activeTabId:o}}(t,e);if(r.activeTabId!==t.activeTabId)if(r.activeTabId!==sW&&r.activeTabId){let e=r.tabs.find(e=>e.id===r.activeTabId);if(null==e?void 0:e.path){let t=s3(f,e.path);t&&eQ(t)}}else W(null),B({kind:"none"});return r})},[f,eQ]);(0,o.useEffect)(()=>{eA.current=()=>{eI.activeTabId&&e1(eI.activeTabId)}},[eI.activeTabId,e1]);let e2=(0,o.useCallback)(e=>{eB(t=>({tabs:t.tabs.filter(t=>t.id===e||t.pinned),activeTabId:e}))},[]),e4=(0,o.useCallback)(e=>{eB(t=>(function(e,t){let r=e.tabs.findIndex(e=>e.id===t);if(-1===r)return e;let n=e.tabs.filter((e,t)=>t<=r||e.pinned),o=n.some(t=>t.id===e.activeTabId);return{tabs:n,activeTabId:o?e.activeTabId:t}})(t,e))},[]),e5=(0,o.useCallback)(()=>{eB(e=>{let t=function(e){let t=e.tabs.filter(e=>e.pinned),r=t.some(t=>t.id===e.activeTabId);return{tabs:t,activeTabId:r?e.activeTabId:sW}}(e);return W(null),B({kind:"none"}),t})},[]),e6=(0,o.useCallback)((e,t)=>{eB(r=>(function(e,t,r){var n;if(t===r||(null==(n=e.tabs[t])?void 0:n.id)===sW)return e;let o=Math.max(1,r),l=[...e.tabs],[a]=l.splice(t,1);return l.splice(o,0,a),{...e,tabs:l}})(r,e,t))},[]),e3=(0,o.useCallback)(e=>{eB(t=>({...t,tabs:t.tabs.map(t=>t.id===e?{...t,pinned:!t.pinned}:t)}))},[]),e8=(0,o.useCallback)(async e=>{if("folder"===e.type)return{kind:"directory",path:e.path,name:e.name};if("database"===e.type)return{kind:"database",dbPath:e.path,filename:e.name};let t=nj(e.name);if(t)return{kind:"media",url:sX(e.path),mediaType:t,filename:e.name,filePath:e.path};if(rJ(e.name))return{kind:"spreadsheet",url:sX(e.path),filename:e.name,filePath:e.path};if(ol(e.name))try{let t=await fetch(sX(e.path));if(!t.ok)return null;let n=await t.arrayBuffer(),o=await Promise.all([r.e(5360),r.e(4995)]).then(r.t.bind(r,14995,19)),l=await o.convertToHtml({arrayBuffer:n});return{kind:"richDocument",html:l.value,filePath:e.path,mode:"docx"}}catch(e){return null}if(oa(e.name)){let t=await fetch(sQ(e.path));return t.ok?{kind:"richDocument",html:os((await t.json()).content),filePath:e.path,mode:"txt"}:null}let n=await fetch(sQ(e.path));if(!n.ok)return null;let o=await n.json();return"document"===e.type||"markdown"===o.type?{kind:"document",data:o,title:e.name.replace(/\.mdx?$/,"")}:aU(e.name)?{kind:"code",data:o,filename:e.name,filePath:e.path}:{kind:"file",data:o,filename:e.name}},[]),e7=(0,o.useCallback)(async e=>{let t=function(e){let t=e.trim();if(!t.startsWith("file://"))return t;try{let e=new URL(t);if("file:"!==e.protocol)return t;let r=decodeURIComponent(e.pathname);if(/^\/[A-Za-z]:\//.test(r))return r.slice(1);return r}catch(e){return t}}(e);if(!t)return!1;let r=!ew,n=async e=>{if(!r)return eX(e),A(!0),!0;(R||"none"!==I.kind)&&(W(null),B({kind:"none"})),_({status:"loading",path:e.path,filename:e.name});let t=await e8(e);return t?(_({status:"ready",path:e.path,filename:e.name,content:t}),!0):(_({status:"error",path:e.path,filename:e.name,message:"Could not preview this file."}),!1)};if(!sZ(t)&&!sY(t)&&!t.startsWith("./")&&!t.startsWith("../")){let e=s3(f,t);if(e)return await n(e)}try{let e=await fetch("/api/workspace/path-info?path=".concat(encodeURIComponent(t)));if(!e.ok)return!1;let o=await e.json();if(!o.path||!o.name||!o.type)return!1;if(N&&(o.path===N||o.path.startsWith("".concat(N,"/")))){let e=o.path===N?"":o.path.slice(N.length+1);if(e){let t=s3(f,e);if(t)return await n(t)}}if("directory"===o.type){let e={name:o.name,path:o.path,type:"folder"};if(r)return await n(e);return k(o.path),W(o.path),B({kind:"directory",node:{name:o.name,path:o.path,type:"folder"}}),A(!0),!0}if("file"===o.type){let e={name:o.name,path:o.path,type:function(e){var t,r;if(e.endsWith(".dench.app"))return"app";let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return"md"===n||"mdx"===n?"document":"duckdb"===n||"sqlite"===n||"sqlite3"===n||"db"===n?"database":"file"}(o.name)};if(r)return await n(e);let t=o.path.split("/").slice(0,-1).join("/")||"/";return sZ(o.path)&&k(t),await eQ(e),A(!0),!0}}catch(e){}return!1},[R,I.kind,ew,f,eX,N,e8,k,eQ,c]),e9=(0,o.useMemo)(()=>{if(j)return f;let e=ei.map(e=>({name:"".concat(!e.enabled?"○":e.state.runningAtMs?"●":"error"===e.state.lastStatus?"◆":"ok"===e.state.lastStatus?"✓":"○"," ").concat(e.name),path:"~cron/".concat(e.id),type:"file",virtual:!0}));return[...f,{name:"Cron",path:"~cron",type:"folder",virtual:!0,children:e.length>0?e:void 0}]},[f,ei,j]),te=(0,o.useMemo)(()=>j?w:N?"/"===N?null:N.split("/").slice(0,-1).join("/")||"/":null,[j,w,N]),tt=(0,o.useCallback)(()=>{null!=te&&k(te)},[te,k]),tr=(0,o.useCallback)(()=>{k(null)},[k]),tn=(0,o.useCallback)(()=>{W(null),B({kind:"none"}),eB(e=>sF(e,sW))},[]),to=(0,o.useCallback)(e=>{var t,r;let n=null!=(r=h.current)?r:p.current;null==n||null==(t=n.insertFileMention)||t.call(n,e.name,e.path)},[]),tl=(0,o.useCallback)(e=>{"folder"===e.type?(k(e.path),W(e.path),B({kind:"directory",node:{name:e.name,path:e.path,type:"folder"}})):(k(e.path.split("/").slice(0,-1).join("/")||"/"),eQ({name:e.name,path:e.path,type:e.type}))},[k,eQ]),ta=["viewType","view","filters","search","sort","page","pageSize","cols"];(0,o.useEffect)(()=>{if(!d.current)return;if(0===u.current){u.current=1;return}let e=new URLSearchParams(window.location.search),t=new URLSearchParams;if(R){t.set("path",R);let r=e.get("entry");for(let n of(r&&t.set("entry",r),U&&t.set("fileChat",U),"~cron"===R?("overview"!==ed&&t.set("cronView",ed),"calendar"===ed&&"month"!==ex&&t.set("cronCalMode",ex),("calendar"===ed||"timeline"===ed)&&ep&&t.set("cronDate",ep)):R.startsWith("~cron/")&&("all"!==ef&&t.set("cronRunFilter",ef),null!=eg&&t.set("cronRun",String(eg))),ta)){let r=e.get(n);r&&t.set(n,r)}}else z&&(t.set("chat",z),ee&&t.set("subagent",ee));j&&t.set("browse",j),M&&t.set("hidden","1"),P&&t.set("preview",P.path);let r=t.toString();r!==e.toString()&&(x.current=r,c.push(r?"/?".concat(r):"/",{scroll:!1}))},[R,z,ee,U,j,M,P,c,ed,ex,ep,ef,eg]),(0,o.useEffect)(()=>{let e=new URLSearchParams(window.location.search);if("1"===e.get("terminal")===eR)return;eR?e.set("terminal","1"):e.delete("terminal");let t=e.toString();window.history.replaceState(window.history.state,"",t?"/?".concat(t):"/")},[eR]);let ts=(0,o.useCallback)((e,t)=>{ek({objectName:e,entryId:t});let r=new URLSearchParams(i.toString());r.set("entry","".concat(e,":").concat(t)),c.push("/?".concat(r.toString()),{scroll:!1})},[i,c]),ti=(0,o.useCallback)(()=>{ek(null);let e=new URLSearchParams(i.toString());e.delete("entry");let t=e.toString();c.replace(t?"/?".concat(t):"/",{scroll:!1})},[i,c]);(0,o.useEffect)(()=>{if(d.current||v||0===f.length)return;u.current=0;let e=(0,eb.yh)(i);if(e.path){d.current=!0;let t=s3(f,e.path);if(t)eP(t),eQ(t);else if("~cron"===e.path)eP({path:"~cron",name:"Cron",type:"folder"}),W("~cron"),B({kind:"cron-dashboard"}),e.cronView&&eu(e.cronView),e.cronCalMode&&eh(e.cronCalMode),e.cronDate&&em(e.cronDate);else if(e.path.startsWith("~cron/"))eP({path:e.path,name:e.path.split("/").pop()||"Cron Job",type:"file"}),W(e.path),B({kind:"cron-dashboard"}),e.cronRunFilter&&ev(e.cronRunFilter),null!=e.cronRun&&ey(e.cronRun);else if(sZ(e.path)||sY(e.path)){let t={name:e.path.split("/").pop()||e.path,path:e.path,type:"file"};eP(t),eQ(t)}e.fileChat&&H(e.fileChat)}else if(e.chat){var t;d.current=!0,O(e.chat),W(null),B({kind:"none"}),null==(t=h.current)||t.loadSession(e.chat),e.subagent&&et(e.subagent)}else d.current=!0;if(e.entry&&ek(e.entry),e.browse&&k(e.browse),e.hidden&&L(!0),e.preview){let t=e.preview,r=t.split("/").pop()||t;_({status:"loading",path:t,filename:r}),e8({name:r,path:t,type:"file"}).then(e=>{e?_({status:"ready",path:t,filename:r,content:e}):_({status:"error",path:t,filename:r,message:"Could not load preview"})})}e.terminal&&eW(!0)},[f,v,i,eQ,k,L,e8]),(0,o.useEffect)(()=>{let e=()=>{let e=window.location.search.replace(/^\?/,"");if(e===x.current)return;let t=(0,eb.yh)(window.location.search);if(t.path){let e=s3(f,t.path);if(e)eP(e),eQ(e);else if("~cron"===t.path)eP({path:"~cron",name:"Cron",type:"folder"}),W("~cron"),B({kind:"cron-dashboard"});else if(t.path.startsWith("~cron/")){eP({path:t.path,name:t.path.split("/").pop()||"Cron Job",type:"file"}),W(t.path);let e=t.path.slice(6),r=ei.find(t=>t.id===e);r?B({kind:"cron-job",jobId:e,job:r}):B({kind:"cron-dashboard"})}else if(sZ(t.path)||sY(t.path)){let e={name:t.path.split("/").pop()||t.path,path:t.path,type:"file"};eP(e),eQ(e)}H(t.fileChat)}else if(t.chat){var r;O(t.chat),W(null),B({kind:"none"}),null==(r=h.current)||r.loadSession(t.chat),et(t.subagent),eB(e=>sF(e,sW))}else W(null),B({kind:"none"}),O(null),et(null),eB(e=>sF(e,sW));if(t.entry?ek(t.entry):ek(null),t.browse?k(t.browse):t.path&&sZ(t.path)||k(null),t.hidden?L(!0):L(!1),_(null),t.preview){let e=t.preview.split("/").pop()||t.preview;_({status:"loading",path:t.preview,filename:e}),e8({name:e,path:t.preview,type:"file"}).then(r=>{r?_({status:"ready",path:t.preview,filename:e,content:r}):_({status:"error",path:t.preview,filename:e,message:"Could not load preview"})})}eW(t.terminal),x.current=e};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[f,ei,eQ,k,L,e8]),(0,o.useEffect)(()=>{if(!(null==R?void 0:R.startsWith("~cron/"))||0===ei.length||"cron-job"===I.kind)return;let e=R.slice(6),t=ei.find(t=>t.id===e);t&&B({kind:"cron-job",jobId:e,job:t})},[R,ei,I.kind]),(0,o.useEffect)(()=>{let e=i.get("send");if(!e)return;let t=new URLSearchParams(window.location.search);t.delete("send");let r=t.toString();c.replace(r?"/?".concat(r):"/",{scroll:!1}),W(null),B({kind:"none"}),requestAnimationFrame(()=>{var t;null==(t=h.current)||t.sendNewMessage(e)})},[i,c]);let tc=(0,o.useCallback)(e=>{if(!e){W(null),B({kind:"none"});return}if(sZ(e)){let t=e.split("/").pop()||e;k(e),W(e),B({kind:"directory",node:{name:t,path:e,type:"folder"}});return}let t=s3(f,e);t&&eX(t)},[f,eX,k]),td=(0,o.useCallback)(e=>{let t=function t(r){for(let n of r){if("object"===n.type&&s6(n.path)===e)return n;if(n.children){let e=t(n.children);if(e)return e}}return null}(f);t&&eQ(t)},[f,eQ]),tu=(0,o.useCallback)(e=>{let t=(0,eb.lc)(e);if(t){if("entry"===t.kind)return void ts(t.objectName,t.entryId);let e=s3(f,t.path);if(e)return void eX(e)}let r=s3(f,e);r&&eX(r)},[f,eX,ts]),tx=(0,o.useCallback)(async()=>{if("object"!==I.kind)return;let e=I.data.object.name;try{let t=await fetch("/api/workspace/objects/".concat(encodeURIComponent(e)));if(!t.ok)return;let r=await t.json();B({kind:"object",data:r})}catch(e){}},[I]),th=(0,o.useRef)(f);(0,o.useEffect)(()=>{th.current!==f&&(th.current=f,"object"===I.kind&&tx())},[f,I.kind,tx]);let tp=(0,o.useCallback)(e=>{let t=e.target.closest("a");if(!t)return;let r=t.getAttribute("href");r&&(0,eb.m9)(r)&&(e.preventDefault(),e.stopPropagation(),tu(r))},[tu]),tm=(0,o.useCallback)(e=>{let t=ei.find(t=>t.id===e);t&&(W("~cron/".concat(e)),B({kind:"cron-job",jobId:e,job:t}))},[ei]),tf=(0,o.useCallback)(()=>{W("~cron"),B({kind:"cron-dashboard"}),ev("all"),ey(null)},[]),tv=(0,o.useCallback)(e=>{W(null),B({kind:"none"}),requestAnimationFrame(()=>{var t;null==(t=h.current)||t.sendNewMessage(e)})},[]),tg=(0,o.useMemo)(()=>{if(!z)return;let e=V.find(e=>e.id===z);return(null==e?void 0:e.title)||void 0},[z,V]),ty=!R||"none"===I.kind;return(0,n.jsxs)("div",{ref:m,className:"flex h-screen",style:{background:"var(--color-main-bg)"},onClick:tp,children:[ew?eN&&(0,n.jsx)(el,{tree:e9,activePath:R,onSelect:e=>{eX(e),eC(!1)},onRefresh:y,orgName:null==D||null==(e=D.organization)?void 0:e.name,loading:v,browseDir:j,parentDir:te,onNavigateUp:tt,onGoHome:tr,onFileSearchSelect:e=>{null==tl||tl(e),eC(!1)},workspaceRoot:N,onGoToChat:()=>{tn(),eC(!1)},onExternalDrop:to,showHidden:M,onToggleHidden:()=>L(e=>!e),activeWorkspace:S,onWorkspaceChanged:eG,mobile:!0,onClose:()=>eC(!1)}):(0,n.jsx)(n.Fragment,{children:!eL&&(0,n.jsxs)("div",{className:"flex shrink-0 flex-col relative",style:{width:e_,minWidth:e_},children:[(0,n.jsx)(s4,{mode:"left",containerRef:m,min:200,max:480,onResize:ez}),(0,n.jsx)(el,{tree:e9,activePath:R,onSelect:eX,onRefresh:y,orgName:null==D||null==(t=D.organization)?void 0:t.name,loading:v,browseDir:j,parentDir:te,onNavigateUp:tt,onGoHome:tr,onFileSearchSelect:tl,workspaceRoot:N,onGoToChat:tn,onExternalDrop:to,showHidden:M,onToggleHidden:()=>L(e=>!e),width:e_,onCollapse:()=>eT(!0),activeWorkspace:S,onWorkspaceChanged:eG})]})}),!ew&&eL&&(0,n.jsx)("div",{className:"shrink-0 flex flex-col items-center pt-2.5 px-1.5",children:(0,n.jsx)("button",{type:"button",onClick:()=>eT(!1),className:"p-1.5 rounded-md transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Show sidebar (⌘B)",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M9 3v18"})]})})}),(0,n.jsxs)("main",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",style:{background:"var(--color-main-bg)"},children:[ew&&(0,n.jsxs)("div",{className:"px-3 py-2 border-b flex-shrink-0 flex items-center justify-between gap-2",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>eC(!0),className:"p-2 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Open sidebar",children:(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"4",x2:"20",y1:"12",y2:"12"}),(0,n.jsx)("line",{x1:"4",x2:"20",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"4",x2:"20",y1:"18",y2:"18"})]})}),(0,n.jsx)("div",{className:"flex-1 min-w-0 text-sm font-medium truncate",style:{color:"var(--color-text)"},children:R?R.split("/").pop():(null==D||null==(a=D.organization)?void 0:a.name)||"Workspace"}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[R&&"none"!==I.kind&&(0,n.jsx)("button",{type:"button",onClick:()=>{W(null),B({kind:"none"})},className:"p-2 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Back to chat",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]})}),ty&&(0,n.jsx)("button",{type:"button",onClick:()=>eM(!0),className:"p-2 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Chat sessions",children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})]})]}),!ew&&(0,n.jsx)(sA,{tabs:eI.tabs,activeTabId:eI.activeTabId,onActivate:e0,onClose:e1,onCloseOthers:e2,onCloseToRight:e4,onCloseAll:e5,onReorder:e6,onTogglePin:e3}),!ew&&R&&"none"!==I.kind&&(0,n.jsxs)("div",{className:"px-6 border-b flex-shrink-0 flex items-center justify-between",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)(oW,{path:R,onNavigate:tc}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{W(null),B({kind:"none"})},className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Back to chat",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]})}),eH&&(0,n.jsx)("button",{type:"button",onClick:()=>A(e=>!e),className:"p-1.5 rounded-lg flex-shrink-0",style:{color:F?"var(--color-accent)":"var(--color-text-muted)",background:F?"var(--color-accent-light)":"transparent"},title:F?"Hide chat":eH.isDirectory?"Chat about this folder":"Chat about this file",children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 flex min-h-0",children:ty?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0",style:{background:"var(--color-main-bg)"},children:(0,n.jsx)(aC,{ref:es?void 0:h,sessionTitle:tg,initialSessionId:null!=z?z:void 0,onActiveSessionChange:es?void 0:e=>{O(e),et(null)},onSessionsChange:es?void 0:eq,onSubagentSpawned:es?void 0:er,onSubagentClick:ea,onFilePathClick:e7,onDeleteSession:es?void 0:e$,onRenameSession:es?void 0:eZ,compact:ew,sessionKey:null==es?void 0:es.childSessionKey,subagentTask:null==es?void 0:es.task,subagentLabel:null==es?void 0:es.label,onBack:es?eo:void 0},null!=(s=null==es?void 0:es.childSessionKey)?s:"main")}),ew?eS&&(0,n.jsx)(oY,{sessions:V,activeSessionId:z,activeSessionTitle:tg,streamingSessionIds:Z,subagents:Q,activeSubagentKey:ee,loading:K,onSelectSession:e=>{var t;O(e),et(null),null==(t=h.current)||t.loadSession(e)},onNewSession:()=>{var e;O(null),et(null),null==(e=h.current)||e.newSession(),eM(!1)},onSelectSubagent:en,onDeleteSession:e$,onRenameSession:eZ,mobile:!0,onClose:()=>eM(!1)}):(0,n.jsxs)(n.Fragment,{children:[!eD&&(0,n.jsxs)("div",{className:"flex shrink-0 flex-col relative",style:{width:eO,minWidth:eO,background:"var(--color-sidebar-bg)"},children:[(0,n.jsx)(s4,{mode:"right",containerRef:m,min:260,max:900,onResize:eU}),P?(0,n.jsx)(s9,{preview:P,onClose:()=>_(null)}):(0,n.jsx)(oY,{sessions:V,activeSessionId:z,activeSessionTitle:tg,streamingSessionIds:Z,subagents:Q,activeSubagentKey:ee,loading:K,onSelectSession:e=>{var t;O(e),et(null),null==(t=h.current)||t.loadSession(e)},onNewSession:()=>{var e;O(null),et(null),null==(e=h.current)||e.newSession()},onSelectSubagent:en,onDeleteSession:e$,onRenameSession:eZ,onCollapse:()=>eE(!0),width:eO})]}),eD&&(0,n.jsx)("div",{className:"shrink-0 flex flex-col items-center pt-2.5 px-1.5",children:(0,n.jsx)("button",{type:"button",onClick:()=>eE(!1),className:"p-1.5 rounded-md transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Show chat sidebar (⌘⇧B)",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M15 3v18"})]})})})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,n.jsx)(ie,{content:I,workspaceExists:g,expectedPath:N,tree:f,activePath:R,browseDir:j,treeLoading:v,members:null==D?void 0:D.members,onNodeSelect:eX,onNavigateToObject:td,onRefreshObject:tx,onRefreshTree:y,onNavigate:tu,onOpenEntry:ts,searchFn:T,onSelectCronJob:tm,onBackToCronDashboard:tf,cronView:ed,onCronViewChange:eu,cronCalMode:ex,onCronCalModeChange:eh,cronDate:ep,onCronDateChange:em,cronRunFilter:ef,onCronRunFilterChange:ev,cronRun:eg,onCronRunChange:ey,onSendCommand:tv})}),!ew&&eH&&F&&!eD&&(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("aside",{className:"flex-shrink-0 border-l flex flex-col relative",style:{width:eO,borderColor:"var(--color-border)",background:"var(--color-bg)"},children:[(0,n.jsx)(s4,{mode:"right",containerRef:m,min:260,max:900,onResize:eU}),(0,n.jsx)(aC,{ref:p,compact:!0,fileContext:eH,initialSessionId:null!=U?U:void 0,onFileChanged:eV,onFilePathClick:e7,onActiveSessionChange:H})]})})]})}),eR&&(0,n.jsx)(sG,{onClose:()=>eW(!1),cwd:null!=N?N:void 0})]}),ej&&(0,n.jsx)(aP,{objectName:ej.objectName,entryId:ej.entryId,members:null==D?void 0:D.members,onClose:ti,onNavigateEntry:(e,t)=>ts(e,t),onNavigateObject:e=>{ti(),td(e)},onRefresh:tx})]})}function s9(e){let t,{preview:r,onClose:l}=e,a=function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return"pdf"===n?{label:"PDF",color:"#ef4444"}:["jpg","jpeg","png","gif","webp","svg","bmp","heic","avif"].includes(n)?{label:"Image",color:"#3b82f6"}:["mp4","webm","mov","avi","mkv"].includes(n)?{label:"Video",color:"#8b5cf6"}:["mp3","wav","ogg","m4a","aac","flac"].includes(n)?{label:"Audio",color:"#f59e0b"}:["md","mdx"].includes(n)?{label:"Markdown",color:"#10b981"}:["ts","tsx","js","jsx","py","go","rs","java","rb","swift","kt","c","cpp","h"].includes(n)?{label:n.toUpperCase(),color:"#3b82f6"}:["json","yaml","yml","toml","xml","csv"].includes(n)?{label:n.toUpperCase(),color:"#6b7280"}:["duckdb","sqlite","sqlite3","db"].includes(n)?{label:"Database",color:"#6366f1"}:{label:n.toUpperCase()||"File",color:"#6b7280"}}(r.filename),s=(0,o.useCallback)(async()=>{try{await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r.path,reveal:!0})})}catch(e){}},[r.path]),i=(0,o.useCallback)(async()=>{try{await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r.path})})}catch(e){}},[r.path]),c="ready"===r.status&&"media"===r.content.kind?r.content.url:null;if("loading"===r.status)t=(0,n.jsxs)("div",{className:"flex flex-col h-full items-center justify-center gap-3",children:[(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading preview..."})]});else if("error"===r.status)t=(0,n.jsxs)("div",{className:"flex flex-col h-full items-center justify-center gap-4 px-6",children:[(0,n.jsx)("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center",style:{background:"color-mix(in srgb, var(--color-error) 10%, transparent)"},children:(0,n.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",x2:"9",y1:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",x2:"15",y1:"9",y2:"15"})]})}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"Preview unavailable"}),(0,n.jsx)("p",{className:"text-xs mt-1",style:{color:"var(--color-text-muted)"},children:r.message})]})]});else{let e=r.content;switch(e.kind){case"media":if("pdf"===e.mediaType){let r=e.url+(e.url.includes("#")?"&":"#")+"toolbar=0&navpanes=0&scrollbar=1";t=(0,n.jsx)("iframe",{src:r,className:"w-full h-full",style:{border:"none",colorScheme:"light"},title:"Preview: ".concat(e.filename)})}else"image"===e.mediaType?t=(0,n.jsx)("div",{className:"flex items-center justify-center h-full p-4 overflow-auto",style:{background:"var(--color-bg)"},children:(0,n.jsx)("img",{src:e.url,alt:e.filename,className:"max-w-full max-h-full object-contain rounded-lg",style:{boxShadow:"0 2px 16px rgba(0,0,0,0.08)"},draggable:!1})}):"video"===e.mediaType?t=(0,n.jsx)("div",{className:"flex items-center justify-center h-full p-4",style:{background:"#000"},children:(0,n.jsx)("video",{src:e.url,controls:!0,className:"max-w-full max-h-full rounded-lg"})}):"audio"===e.mediaType&&(t=(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-6 px-6",children:[(0,n.jsx)("div",{className:"w-20 h-20 rounded-2xl flex items-center justify-center",style:{background:"linear-gradient(135deg, #f59e0b20, #f59e0b08)"},children:(0,n.jsxs)("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]})}),(0,n.jsx)("audio",{src:e.url,controls:!0,className:"w-full"})]}));break;case"document":t=(0,n.jsx)("div",{className:"p-5 overflow-auto h-full",children:(0,n.jsx)("div",{className:"workspace-prose text-sm",children:(0,n.jsx)(rU,{content:e.data.content,title:e.title})})});break;case"code":t=(0,n.jsx)("div",{className:"h-full",children:(0,n.jsx)(nm,{content:e.data.content,filename:e.filename,filePath:e.filePath})});break;case"file":t=(0,n.jsx)("div",{className:"overflow-auto h-full",children:(0,n.jsx)(rK,{content:e.data.content,filename:e.filename,type:"yaml"===e.data.type?"yaml":"text"})});break;case"spreadsheet":t=(0,n.jsx)("div",{className:"h-full",children:(0,n.jsx)(r6,{url:e.url,filename:e.filename,filePath:e.filePath,compact:!0})});break;case"database":t=(0,n.jsx)("div",{className:"overflow-auto h-full",children:(0,n.jsx)(nH,{dbPath:e.dbPath,filename:e.filename})});break;case"richDocument":t=(0,n.jsx)("div",{className:"h-full",children:(0,n.jsx)(oi,{mode:e.mode,initialHtml:e.html,filePath:e.filePath,compact:!0})});break;case"directory":t=(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-4 px-6",children:[(0,n.jsx)("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center",style:{background:"color-mix(in srgb, var(--color-accent) 10%, transparent)"},children:(0,n.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})})}),(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:e.name})]});break;default:t=null}}return(0,n.jsxs)("aside",{className:"h-full border-l flex flex-col",style:{borderColor:"var(--color-border)",background:"var(--color-bg)"},children:[(0,n.jsxs)("div",{className:"px-3 py-2.5 flex items-center gap-2 flex-shrink-0",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:l,className:"p-1 rounded-md transition-colors flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Close preview",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}),(0,n.jsx)("span",{className:"text-[13px] font-medium truncate min-w-0",style:{color:"var(--color-text)"},children:r.filename}),(0,n.jsx)("span",{className:"text-[10px] font-medium px-1.5 py-[1px] rounded flex-shrink-0",style:{background:"".concat(a.color,"14"),color:a.color},children:a.label}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 ml-auto flex-shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:i,className:"p-1.5 rounded-md transition-colors",style:{color:"var(--color-text-muted)"},title:"Open with default app",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}),c&&(0,n.jsx)("a",{href:c,download:r.filename,className:"p-1.5 rounded-md transition-colors",style:{color:"var(--color-text-muted)"},title:"Download",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]})}),(0,n.jsx)("button",{type:"button",onClick:s,className:"p-1.5 rounded-md transition-colors",style:{color:"var(--color-text-muted)"},title:"Reveal in Finder",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:t}),(0,n.jsx)("div",{className:"px-3 py-1.5 border-t flex-shrink-0",style:{borderColor:"var(--color-border)"},children:(0,n.jsx)("p",{className:"text-[10px] truncate",style:{color:"var(--color-text-muted)",fontFamily:"'SF Mono', 'Fira Code', monospace"},title:r.path,children:r.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~")})})]})}function ie(e){let{content:t,workspaceExists:r,expectedPath:o,tree:l,activePath:a,browseDir:s,treeLoading:i,members:c,onNodeSelect:d,onNavigateToObject:u,onRefreshObject:x,onRefreshTree:h,onNavigate:p,onOpenEntry:m,searchFn:f,onSelectCronJob:v,onBackToCronDashboard:g,cronView:y,onCronViewChange:b,cronCalMode:j,onCronCalModeChange:k,cronDate:w,onCronDateChange:N,cronRunFilter:C,onCronRunFilterChange:S,cronRun:M,onCronRunChange:L,onSendCommand:T}=e;switch(t.kind){case"loading":return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})});case"object":return(0,n.jsx)(it,{data:t.data,members:c,onNavigateToObject:u,onRefreshObject:x,onOpenEntry:m});case"document":return(0,n.jsx)(rU,{content:t.data.content,title:t.title,filePath:null!=a?a:void 0,tree:l,onSave:h,onNavigate:p,searchFn:f});case"file":return(0,n.jsx)(rK,{content:t.data.content,filename:t.filename,type:"yaml"===t.data.type?"yaml":"text"});case"code":return(0,n.jsx)(nm,{content:t.data.content,filename:t.filename,filePath:t.filePath});case"media":return(0,n.jsx)(nM,{url:t.url,filename:t.filename,mediaType:t.mediaType,filePath:t.filePath});case"spreadsheet":return(0,n.jsx)(r6,{url:t.url,filename:t.filename,filePath:t.filePath});case"html":return(0,n.jsx)(r9,{rawUrl:t.rawUrl,contentUrl:t.contentUrl,filename:t.filename});case"app":return(0,n.jsx)(ns,{appPath:t.appPath,manifest:t.manifest});case"database":return(0,n.jsx)(nH,{dbPath:t.dbPath,filename:t.filename});case"report":return(0,n.jsx)(o9,{reportPath:t.reportPath});case"directory":{let e=null!=s&&a===s;if(e&&i)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})});let r=e?{...t.node,children:l}:t.node;return(0,n.jsx)(ir,{node:r,onNodeSelect:d})}case"cron-dashboard":return(0,n.jsx)(aG,{onSelectJob:v,onSendCommand:T,activeView:y,onViewChange:b,calendarMode:j,onCalendarModeChange:k,calendarDate:w,onCalendarDateChange:N});case"cron-job":return(0,n.jsx)(ss,{job:t.job,onBack:g,onSendCommand:T,runFilter:C,onRunFilterChange:S,expandedRunTs:M,onExpandedRunChange:L});case"cron-session":return(0,n.jsx)(sm,{job:t.job,run:t.run,sessionId:t.sessionId,onBack:()=>g(),onBackToJob:()=>v(t.jobId)});case"duckdb-missing":return(0,n.jsx)(nU,{});case"richDocument":return(0,n.jsx)(oi,{mode:t.mode,initialHtml:t.html,filePath:t.filePath,onSave:h});default:if(0===l.length)return(0,n.jsx)(oQ,{workspaceExists:r,expectedPath:o});return(0,n.jsx)(io,{tree:l,onNodeSelect:d})}}function it(e){var t,r,a,s,i,c,d,u,x,h,p,m,f,v,g,y;let{data:b,members:j,onNavigateToObject:k,onRefreshObject:w,onOpenEntry:N}=e,C=(0,l.useSearchParams)(),S=(0,l.useRouter)(),M=e=>{var t;let r=null!=(t=e.entry_id)?t:e.id;return"string"==typeof r?r:"number"==typeof r||"boolean"==typeof r||"bigint"==typeof r?String(r):""},[L,T]=(0,o.useState)(!1),D=(0,o.useMemo)(()=>(0,eb.yh)(C),[]),[E,R]=(0,o.useState)(()=>{var e;return null!=(e=D.viewType)?e:ro(void 0,void 0,b.object.default_view)}),[W,I]=(0,o.useState)(()=>{var e;return null!=(e=b.viewSettings)?e:{}}),[B,F]=(0,o.useState)(()=>{var e;return null!=(e=D.filters)?e:rv()}),[A,P]=(0,o.useState)(null!=(t=b.savedViews)?t:[]),[_,z]=(0,o.useState)(null!=(r=D.view)?r:b.activeView),[O,U]=(0,o.useState)(null!=(s=null!=(a=D.page)?a:b.page)?s:1),[H,V]=(0,o.useState)(null!=(c=null!=(i=D.pageSize)?i:b.pageSize)?c:100),[J,K]=(0,o.useState)(null!=(d=b.totalCount)?d:b.entries.length),[q,G]=(0,o.useState)(b.entries),[$,Z]=(0,o.useState)(null!=(u=D.search)?u:""),[Y,Q]=(0,o.useState)(null!=(x=D.sort)?x:void 0),X=(0,o.useRef)(null),ee=B.rules.length>0||(null!=(h=null==Y?void 0:Y.length)?h:0)>0||$.trim().length>0,[et,er]=(0,o.useState)(null!=(p=D.cols)?p:void 0),en=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(!en.current){en.current=!0;return}let e=new URLSearchParams(window.location.search),t=new URLSearchParams(e);for(let e of["viewType","view","filters","search","sort","page","pageSize","cols"])t.delete(e);E!==ro(void 0,void 0,b.object.default_view)&&t.set("viewType",E),_&&t.set("view",_),B.rules.length>0&&t.set("filters",btoa(JSON.stringify(B))),$&&t.set("search",$),Y&&Y.length>0&&t.set("sort",btoa(JSON.stringify(Y))),O>1&&t.set("page",String(O)),100!==H&&t.set("pageSize",String(H)),et&&et.length>0&&t.set("cols",et.join(","));let r=t.toString();r!==e.toString()&&S.replace(r?"/?".concat(r):"/",{scroll:!1})},[E,_,B,$,Y,O,H,et]);let eo=(0,o.useMemo)(()=>{if(!et||0===et.length)return;let e={};for(let t of b.fields)e[t.id]=et.includes(t.name);return e.created_at=et.includes("created_at"),e.updated_at=et.includes("updated_at"),e},[et,b.fields]),el=(0,o.useCallback)(e=>{let t=[];for(let r of b.fields)!1!==e[r.id]&&t.push(r.name);!1!==e.created_at&&t.push("created_at"),!1!==e.updated_at&&t.push("updated_at"),er(t.length>0?t:void 0)},[b.fields]),ea=(0,o.useCallback)(async e=>{var t,r,n,o,l,a,s,i;let c=null!=(t=null==e?void 0:e.page)?t:O,d=null!=(r=null==e?void 0:e.pageSize)?r:H,u=null!=(n=null==e?void 0:e.filters)?n:B,x=null!=(o=null==e?void 0:e.sort)?o:Y,h=null!=(l=null==e?void 0:e.search)?l:$,p=new URLSearchParams;p.set("page",String(c)),p.set("pageSize",String(d)),u&&u.rules.length>0&&p.set("filters",rf(u)),x&&x.length>0&&p.set("sort",JSON.stringify(x)),h&&p.set("search",h);try{let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"?").concat(p.toString()));if(!e.ok)return;let t=await e.json();G(t.entries),K(null!=(a=t.totalCount)?a:t.entries.length),U(null!=(s=t.page)?s:c),V(null!=(i=t.pageSize)?i:d)}catch(e){}},[O,H,B,Y,$,b.object.name]);(0,o.useEffect)(()=>{var e;if(ee)return void ea();G(b.entries),K(null!=(e=b.totalCount)?e:b.entries.length)},[b.entries,b.totalCount]),(0,o.useEffect)(()=>{var e;P(null!=(e=b.savedViews)?e:[]),b.viewSettings&&I(b.viewSettings);let t=function(e){var t,r,n,o;let l=e.activeView;if(!l)return null;let a=(null!=(t=e.savedViews)?t:[]).find(e=>e.name===l);if(!a)return null;let s=null!=(r=a.filters)?r:rv(),i=a.columns,c=a.name,d=a.view_type,u=a.settings,x=e.currentActiveViewName!==c,h=(n=e.currentFilters,rf(n)!==rf(s)),p=!function(e,t){if(!e&&!t)return!0;if(!e||!t||e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1)if(e[r]!==t[r])return!1;return!0}(e.currentViewColumns,i),m=e.currentViewType!==d,f=(o=e.currentSettings,(!!o||!!u)&&(!o||!u||JSON.stringify(o)!==JSON.stringify(u)));return{shouldApply:x||h||p||m||f,nextFilters:s,nextColumns:i,nextActiveViewName:c,nextViewType:d,nextSettings:u}}({savedViews:b.savedViews,activeView:b.activeView,currentActiveViewName:_,currentFilters:B,currentViewColumns:et,currentViewType:E,currentSettings:W});(null==t?void 0:t.shouldApply)&&(F(t.nextFilters),er(t.nextColumns),z(t.nextActiveViewName),t.nextViewType&&R(t.nextViewType),t.nextSettings&&I(e=>({...e,...t.nextSettings})),ea({page:1,filters:t.nextFilters}))},[b.savedViews,b.activeView]);let es=(0,o.useCallback)(e=>{F(e),U(1),ea({page:1,filters:e})},[ea]),ei=(0,o.useCallback)(e=>{Z(e),X.current&&clearTimeout(X.current),X.current=setTimeout(()=>{U(1),ea({page:1,search:e})},300)},[ea]),ec=(0,o.useCallback)(e=>{U(e),ea({page:e})},[ea]),ed=(0,o.useCallback)(e=>{V(e),U(1),ea({page:1,pageSize:e})},[ea]),eu=(0,o.useCallback)(()=>{ea(),w()},[ea,w]),ex=(0,o.useCallback)(async e=>{let t=[...A.filter(t=>t.name!==e),{name:e,view_type:E,filters:B,columns:et,settings:W}];P(t),z(e);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:t,activeView:e,viewSettings:W})})}catch(e){}},[B,A,b.object.name,E,et,W]),eh=(0,o.useCallback)(e=>{var t;let r=null!=(t=e.filters)?t:rv();F(r),er(e.columns),z(e.name),e.view_type&&R(e.view_type),e.settings&&I(t=>({...t,...e.settings})),U(1),ea({page:1,filters:r})},[ea]),ep=(0,o.useCallback)(async e=>{let t=A.filter(t=>t.name!==e);P(t),_===e&&(z(void 0),F(rv()),er(void 0));try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:t,activeView:_===e?void 0:_})})}catch(e){}},[A,_,b.object.name]),em=(0,o.useCallback)(async e=>{z(e),e||er(void 0);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:A,activeView:e})})}catch(e){}},[A,b.object.name]),ef=(0,o.useCallback)(e=>{R(e)},[]),ev=(0,o.useCallback)(async e=>{I(e);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:A,activeView:_,viewSettings:e})})}catch(e){}},[A,_,b.object.name]),eg=(0,o.useMemo)(()=>{let e=A.find(e=>e.name===_),t=function(e,t){if(!t)return null!=e?e:{};if(!e)return t;let r={...t};for(let t of Object.keys(e)){let n=e[t];void 0!==n&&(r[t]=n)}return r}(null==e?void 0:e.settings,W),r=[...b.fields.map(e=>({name:e.name,type:e.type})),{name:"created_at",type:"date"},{name:"updated_at",type:"date"}];return"kanban"!==E||t.kanbanField||(t.kanbanField=rl("kanban","kanbanField",r)),"calendar"!==E||t.calendarDateField||(t.calendarDateField=rl("calendar","calendarDateField",r)),"timeline"!==E||t.timelineStartField||(t.timelineStartField=rl("timeline","timelineStartField",r)),"gallery"!==E||t.galleryTitleField||(t.galleryTitleField=rl("gallery","galleryTitleField",r)),"list"!==E||t.listTitleField||(t.listTitleField=rl("list","listTitleField",r)),t},[E,W,A,_,b.fields]),ey=async e=>{T(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/display-field"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayField:e})})).ok&&w()}catch(e){}finally{T(!1)}},ej=(0,o.useCallback)(async e=>{let t=eg.calendarDateField,r=eg.calendarEndDateField;if(!t)return;let n={[t]:e.newDate};r&&e.newEndDate&&(n[r]=e.newEndDate),G(n=>n.map(n=>{if(M(n)!==e.entryId)return n;let o={...n,[t]:e.newDate};return r&&e.newEndDate&&(o[r]=e.newEndDate),o}));try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/entries/").concat(encodeURIComponent(e.entryId)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:n})})}catch(e){}},[eg,b.object.name]),ek=(0,o.useCallback)(async e=>{let t=eg.timelineStartField,r=eg.timelineEndField;if(!t)return;let n={[t]:e.newStartDate};r&&(n[r]=e.newEndDate),G(n=>n.map(n=>{if(M(n)!==e.entryId)return n;let o={...n,[t]:e.newStartDate};return r&&(o[r]=e.newEndDate),o}));try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/entries/").concat(encodeURIComponent(e.entryId)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:n})})}catch(e){}},[eg,b.object.name]),ew=b.fields.filter(e=>!["relation","boolean","richtext"].includes(e.type)),eN=b.fields.some(e=>"relation"===e.type),eC=b.reverseRelations&&b.reverseRelations.some(e=>Object.keys(e.entries).length>0),eS=(0,o.useMemo)(()=>null==j?void 0:j.map(e=>({id:e.id,name:e.name})),[j]),eM=(0,o.useMemo)(()=>[...b.fields,{id:"created_at",name:"created_at",type:"date"},{id:"updated_at",name:"updated_at",type:"date"}],[b.fields]);return(0,n.jsxs)("div",{className:"p-6",children:[(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight capitalize",style:{color:"var(--color-text)"},children:b.object.name}),b.object.description&&(0,n.jsx)("p",{className:"text-sm mt-1",style:{color:"var(--color-text-muted)"},children:b.object.description}),(0,n.jsxs)("div",{className:"flex items-center gap-3 mt-3 flex-wrap",children:[(0,n.jsxs)("span",{className:"text-xs px-2 py-1 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[J," entries"]}),(0,n.jsxs)("span",{className:"text-xs px-2 py-1 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[b.fields.length," fields"]}),eN&&(0,n.jsxs)("span",{className:"text-xs px-2 py-1 rounded-full",style:{background:"var(--color-chip-document)",color:"var(--color-chip-document-text)",border:"1px solid var(--color-border)"},children:[b.fields.filter(e=>"relation"===e.type).length," relation",1!==b.fields.filter(e=>"relation"===e.type).length?"s":""]}),eC&&(0,n.jsxs)("span",{className:"text-xs px-2 py-1 rounded-full",style:{background:"var(--color-chip-database)",color:"var(--color-chip-database-text)",border:"1px solid var(--color-border)"},children:[b.reverseRelations.filter(e=>Object.keys(e.entries).length>0).length," linked from"]})]}),ew.length>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-3",children:[(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Display field:"}),(0,n.jsx)("select",{value:null!=(m=b.effectiveDisplayField)?m:"",onChange:e=>ey(e.target.value),disabled:L,className:"text-xs px-2 py-1 rounded-md outline-none transition-colors cursor-pointer",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)",opacity:L?.5:1},children:ew.map(e=>(0,n.jsx)("option",{value:e.name,children:e.name},e.id))}),L&&(0,n.jsx)("div",{className:"w-3 h-3 border border-t-transparent rounded-full animate-spin",style:{borderColor:"var(--color-text-muted)"}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)",opacity:.6},children:"Used when other objects link here"})]})]}),(0,n.jsxs)("div",{className:"mb-4 py-3 px-4 rounded-lg border",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 mb-2",children:[(0,n.jsx)(rb,{value:E,onChange:ef}),(0,n.jsx)(rT,{viewType:E,settings:eg,fields:eM,onSettingsChange:ev})]}),(0,n.jsx)(sR,{fields:b.fields,filters:B,onFiltersChange:es,savedViews:A,activeViewName:_,onSaveView:ex,onLoadView:eh,onDeleteView:ep,onSetActiveView:em,members:eS})]}),"kanban"===E&&(0,n.jsx)(ti,{objectName:b.object.name,fields:b.fields,entries:q,statuses:b.statuses,members:j,relationLabels:b.relationLabels,onEntryClick:N?e=>N(b.object.name,e):void 0,onRefresh:eu}),"table"===E&&(0,n.jsx)(tt,{objectName:b.object.name,fields:b.fields,entries:q,members:j,relationLabels:b.relationLabels,reverseRelations:b.reverseRelations,onNavigateToObject:k,onNavigateToEntry:N,onEntryClick:N?e=>N(b.object.name,e):void 0,onRefresh:eu,columnVisibility:eo,onColumnVisibilityChanged:el,serverPagination:{totalCount:J,page:O,pageSize:H,onPageChange:ec,onPageSizeChange:ed},onServerSearch:ei}),"calendar"===E&&(0,n.jsx)(tK,{objectName:b.object.name,fields:b.fields,entries:q,dateField:null!=(f=eg.calendarDateField)?f:"",endDateField:eg.calendarEndDateField,mode:null!=(v=eg.calendarMode)?v:"month",onModeChange:e=>ev({...eg,calendarMode:e}),members:j,onEntryClick:N?e=>N(b.object.name,e):void 0,onEntryDateChange:ej}),"timeline"===E&&(0,n.jsx)(t4,{objectName:b.object.name,fields:b.fields,entries:q,startDateField:null!=(g=eg.timelineStartField)?g:"",endDateField:eg.timelineEndField,groupField:eg.timelineGroupField,zoom:null!=(y=eg.timelineZoom)?y:"week",onZoomChange:e=>ev({...eg,timelineZoom:e}),members:j,onEntryClick:N?e=>N(b.object.name,e):void 0,onEntryDateChange:ek}),"gallery"===E&&(0,n.jsx)(t8,{objectName:b.object.name,fields:b.fields,entries:q,titleField:eg.galleryTitleField,coverField:eg.galleryCoverField,members:j,relationLabels:b.relationLabels,onEntryClick:N?e=>N(b.object.name,e):void 0}),"list"===E&&(0,n.jsx)(rt,{objectName:b.object.name,fields:b.fields,entries:q,titleField:eg.listTitleField,subtitleField:eg.listSubtitleField,members:j,onEntryClick:N?e=>N(b.object.name,e):void 0})]})}function ir(e){var t;let{node:r,onNodeSelect:o}=e,l=null!=(t=r.children)?t:[];return(0,n.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight mb-1 capitalize",style:{color:"var(--color-text)"},children:r.name}),(0,n.jsxs)("p",{className:"text-sm mb-6",style:{color:"var(--color-text-muted)"},children:[l.length," items"]}),0===l.length?(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"This folder is empty."}):(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:l.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>o(e),className:"flex items-center gap-3 p-4 rounded-2xl text-left transition-all duration-100 cursor-pointer",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--color-border-strong)",e.currentTarget.style.transform="translateY(-1px)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--color-border)",e.currentTarget.style.transform="translateY(0)"},children:[(0,n.jsx)("span",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:"object"===e.type?"var(--color-chip-object)":"document"===e.type?"var(--color-chip-document)":"database"===e.type?"var(--color-chip-database)":"report"===e.type?"var(--color-chip-report)":"var(--color-surface-hover)",color:"object"===e.type?"var(--color-chip-object-text)":"document"===e.type?"var(--color-chip-document-text)":"database"===e.type?"var(--color-chip-database-text)":"report"===e.type?"var(--color-chip-report-text)":"var(--color-text-muted)"},children:(0,n.jsx)(il,{type:e.type})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:e.name.replace(/\.md$/,"")}),(0,n.jsxs)("div",{className:"text-xs capitalize",style:{color:"var(--color-text-muted)"},children:[e.type,e.children?" (".concat(e.children.length,")"):""]})]})]},e.path))})]})}function io(e){let{tree:t,onNodeSelect:r}=e,o=[],l=[];return!function e(t){for(let r of t)"object"===r.type?o.push(r):"document"===r.type&&l.push(r),r.children&&e(r.children)}(t),(0,n.jsxs)("div",{className:"p-8 max-w-4xl mx-auto",children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight mb-2",style:{color:"var(--color-text)"},children:"Workspace"}),(0,n.jsx)("p",{className:"text-sm mb-8",style:{color:"var(--color-text-muted)"},children:"Select an item from the sidebar, or browse the sections below."}),o.length>0&&(0,n.jsxs)("div",{className:"mb-8",children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Objects"}),(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:o.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>r(e),className:"flex items-center gap-3 p-4 rounded-2xl text-left transition-all duration-100 cursor-pointer",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--color-accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--color-border)"},children:[(0,n.jsx)("span",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:"var(--color-chip-object)",color:"var(--color-chip-object-text)"},children:(0,n.jsx)(il,{type:"object"})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium capitalize truncate",style:{color:"var(--color-text)"},children:e.name}),(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"kanban"===e.defaultView?"Kanban board":"Table view"})]})]},e.path))})]}),l.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Documents"}),(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:l.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>r(e),className:"flex items-center gap-3 p-4 rounded-2xl text-left transition-all duration-100 cursor-pointer",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--color-chip-document-text)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--color-border)"},children:[(0,n.jsx)("span",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:"var(--color-chip-document)",color:"var(--color-chip-document-text)"},children:(0,n.jsx)(il,{type:"document"})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:e.name.replace(/\.md$/,"")}),(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Document"})]})]},e.path))})]})]})}function il(e){let{type:t}=e;switch(t){case"object":return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]});case"document":return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,n.jsx)("path",{d:"M10 9H8"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"})]});case"folder":return(0,n.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})});case"database":return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]});case"report":return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",x2:"12",y1:"20",y2:"10"}),(0,n.jsx)("line",{x1:"18",x2:"18",y1:"20",y2:"4"}),(0,n.jsx)("line",{x1:"6",x2:"6",y1:"20",y2:"14"})]});default:return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]})}}function ia(){return(0,n.jsx)(s8,{})}},40077:(e,t,r)=>{"use strict";r.d(t,{N:()=>U});var n=r(80534),o=r(74166),l=r(44960),a=r(2741),s=r(12890),i=r(19237),c=r(45770),d=r(68354),u=r(48357),x=r(3224),h=r(13707),p=r(23173),m=r(58313),f=r(97726),v=r(90171),g=r(66735),y=r(51329),b=r(12674),j=r(25249),k=r(11913),w=r(67283),N=r(60577),C=r(1208),S=r(84240),M=r(53940),L=r(13847),T=r(49166);let D=["#2563eb","#60a5fa","#22c55e","#f59e0b","#c084fc","#fb923c","#14b8a6","#f43f5e","#a78bfa","#38bdf8"],E={fontSize:11,fill:"var(--color-text-muted)"},R={stroke:"var(--color-border-strong)",strokeDasharray:"3 3"};function W(){return{contentStyle:{background:"var(--color-surface)",border:"1px solid var(--color-border)",borderRadius:8,fontSize:12,color:"var(--color-text)"},itemStyle:{color:"var(--color-text)"},labelStyle:{color:"var(--color-text-muted)",marginBottom:4}}}function I(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:String(e)}function B(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"number"==typeof e?Math.abs(e)>=1e6?"".concat((e/1e6).toFixed(1),"M"):Math.abs(e)>=1e3?"".concat((e/1e3).toFixed(1),"K"):Number.isInteger(e)?String(e):e.toFixed(2):I(e)}function F(e){if(null==e)return"";let t=I(e);return t.length>16&&!isNaN(Date.parse(t))?t.slice(0,10):t.length>20?t.slice(0,18)+"...":t}function A(e){var t,r,o,p,m,f;let{config:v,data:g,compact:y,ChartComponent:b,SeriesComponent:j,areaProps:k}=e,{mapping:w}=v,N=null!=(o=null!=(r=w.xAxis)?r:Object.keys(null!=(t=g[0])?t:{})[0])?o:"x",C=null!=(m=w.yAxis)?m:Object.keys(null!=(p=g[0])?p:{}).filter(e=>e!==N),S=null!=(f=w.colors)?f:D,M=W();return(0,n.jsx)(l.u,{width:"100%",height:y?200:320,children:(0,n.jsxs)(b,{data:g,margin:{top:8,right:16,left:0,bottom:4},children:[(0,n.jsx)(a.d,{...R}),(0,n.jsx)(s.W,{dataKey:N,tick:E,tickFormatter:F,axisLine:{stroke:"var(--color-border)"},tickLine:!1}),(0,n.jsx)(i.h,{tick:E,tickFormatter:B,axisLine:!1,tickLine:!1,width:48}),(0,n.jsx)(c.m,{...M,formatter:B,labelFormatter:F}),C.length>1&&!y&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}}),C.map((e,t)=>{let r=S[t%S.length],o={key:e,dataKey:e,fill:r,stroke:r,name:e,...k};return j===u.yP&&(o.radius=[4,4,0,0],o.maxBarSize=48),j===x.N1&&(o.strokeWidth=2,o.dot={r:3,fill:r},o.activeDot={r:5}),j===h.Gk&&(o.fillOpacity=.15,o.strokeWidth=2),(0,n.jsx)(j,{...o})})]})})}function P(e){var t,r,o,a,s,i,u;let{config:x,data:h,compact:v}=e,{mapping:g,type:y}=x,b=null!=(o=null!=(r=g.nameKey)?r:Object.keys(null!=(t=h[0])?t:{})[0])?o:"name",j=null!=(i=null!=(s=g.valueKey)?s:Object.keys(null!=(a=h[0])?a:{})[1])?i:"value",k=null!=(u=g.colors)?u:D,w=W();return(0,n.jsx)(l.u,{width:"100%",height:v?200:320,children:(0,n.jsxs)(p.r,{children:[(0,n.jsx)(m.Fq,{data:h,dataKey:j,nameKey:b,cx:"50%",cy:"50%",innerRadius:"donut"===y?"50%":0,outerRadius:v?70:110,paddingAngle:2,label:v?void 0:e=>{let t=e.name,r="number"==typeof e.percent?e.percent:0;return"".concat(F(t)," ").concat((100*r).toFixed(0),"%")},labelLine:!v,style:{fontSize:11},children:h.map((e,t)=>(0,n.jsx)(f.f,{fill:k[t%k.length]},t))}),(0,n.jsx)(c.m,{...w,formatter:B}),!v&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}})]})})}function _(e){var t,r,o,a,s,i,u,x;let{config:h,data:p,compact:m}=e,{mapping:f}=h,k=null!=(a=null!=(o=null!=(t=f.xAxis)?t:f.nameKey)?o:Object.keys(null!=(r=p[0])?r:{})[0])?a:"name",w=null!=(u=f.yAxis)?u:[null!=(i=Object.keys(null!=(s=p[0])?s:{})[1])?i:"value"],N=null!=(x=f.colors)?x:D,C=W();return(0,n.jsx)(l.u,{width:"100%",height:m?200:320,children:(0,n.jsxs)(v.V,{data:p,cx:"50%",cy:"50%",outerRadius:m?60:100,children:[(0,n.jsx)(g.z,{stroke:"var(--color-border)"}),(0,n.jsx)(y.r,{dataKey:k,tick:{fontSize:11,fill:"var(--color-text-muted)"}}),(0,n.jsx)(b.E,{tick:{fontSize:10,fill:"var(--color-text-muted)"}}),w.map((e,t)=>(0,n.jsx)(j.Vd,{name:e,dataKey:e,stroke:N[t%N.length],fill:N[t%N.length],fillOpacity:.2},e)),(0,n.jsx)(c.m,{...C}),!m&&w.length>1&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}})]})})}function z(e){var t,r,o,u,x,h,p;let{config:m,data:f,compact:v}=e,{mapping:g}=m,y=null!=(o=null!=(r=g.xAxis)?r:Object.keys(null!=(t=f[0])?t:{})[0])?o:"x",b=null!=(h=g.yAxis)?h:[null!=(x=Object.keys(null!=(u=f[0])?u:{})[1])?x:"y"],j=null!=(p=g.colors)?p:D,N=W();return(0,n.jsx)(l.u,{width:"100%",height:v?200:320,children:(0,n.jsxs)(k.t,{margin:{top:8,right:16,left:0,bottom:4},children:[(0,n.jsx)(a.d,{...R}),(0,n.jsx)(s.W,{dataKey:y,tick:E,name:y,axisLine:{stroke:"var(--color-border)"},tickLine:!1}),(0,n.jsx)(i.h,{tick:E,tickFormatter:B,axisLine:!1,tickLine:!1,width:48}),(0,n.jsx)(c.m,{...N}),b.map((e,t)=>(0,n.jsx)(w.Xl,{name:e,data:f,fill:j[t%j.length]},e)),!v&&b.length>1&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}})]})})}function O(e){var t,r,o,a,s,i,d;let{config:u,data:x,compact:h}=e,{mapping:p}=u,m=null!=(o=null!=(r=p.nameKey)?r:Object.keys(null!=(t=x[0])?t:{})[0])?o:"name",f=null!=(i=null!=(s=p.valueKey)?s:Object.keys(null!=(a=x[0])?a:{})[1])?i:"value",v=null!=(d=p.colors)?d:D,g=W(),y=x.map((e,t)=>({...e,fill:v[t%v.length]}));return(0,n.jsx)(l.u,{width:"100%",height:h?200:320,children:(0,n.jsxs)(N.v,{children:[(0,n.jsx)(c.m,{...g}),(0,n.jsx)(C.rh,{data:y,dataKey:f,nameKey:m,isAnimationActive:!0,children:(0,n.jsx)(S.Ze,{position:"right",fill:"var(--color-text-muted)",stroke:"none",fontSize:11,dataKey:m})})]})})}function U(e){let{config:t,data:r,compact:l}=e,a=(0,o.useMemo)(()=>{var e;if(!r||0===r.length)return[];let{mapping:n}=t,o=new Set([...null!=(e=n.yAxis)?e:[],...n.valueKey?[n.valueKey]:[]]);return r.map(e=>{let t={...e};for(let e of o)if(e in t){let r=t[e];"string"!=typeof r||""===r||isNaN(Number(r))||(t[e]=Number(r))}return t})},[r,t]);if(0===a.length)return(0,n.jsx)("div",{className:"flex items-center justify-center rounded-xl",style:{height:l?200:320,background:"var(--color-surface)",border:"1px solid var(--color-border)",color:"var(--color-text-muted)",fontSize:13},children:"No data"});switch(t.type){case"bar":default:return(0,n.jsx)(A,{config:t,data:a,compact:l,ChartComponent:M.E,SeriesComponent:u.yP});case"line":return(0,n.jsx)(A,{config:t,data:a,compact:l,ChartComponent:L.b,SeriesComponent:x.N1});case"area":return(0,n.jsx)(A,{config:t,data:a,compact:l,ChartComponent:T.Q,SeriesComponent:h.Gk});case"pie":case"donut":return(0,n.jsx)(P,{config:t,data:a,compact:l});case"radar":case"radialBar":return(0,n.jsx)(_,{config:t,data:a,compact:l});case"scatter":return(0,n.jsx)(z,{config:t,data:a,compact:l});case"funnel":return(0,n.jsx)(O,{config:t,data:a,compact:l})}}},48121:(e,t,r)=>{Promise.resolve().then(r.bind(r,7713))},68840:(e,t,r)=>{"use strict";r.d(t,{VE:()=>i,bJ:()=>c,lc:()=>d,m9:()=>u,yh:()=>s});let n=["table","kanban","calendar","timeline","gallery","list"],o=["overview","calendar","timeline","insights"],l=["day","week","month","year"],a=["all","ok","error","running"];function s(e){let t="string"==typeof e?new URLSearchParams(e):e,r=null,s=t.get("entry");if(s&&s.includes(":")){let e=s.indexOf(":");r={objectName:s.slice(0,e),entryId:s.slice(e+1)}}let i=null,c=t.get("filters");if(c)try{i=JSON.parse(atob(c))}catch(e){}let d=null,u=t.get("sort");if(u)try{d=JSON.parse(atob(u))}catch(e){}let x=t.get("page"),h=t.get("pageSize"),p=t.get("cols"),m=t.get("viewType"),f=t.get("cronView"),v=t.get("cronCalMode"),g=t.get("cronRunFilter"),y=t.get("cronRun");return{path:t.get("path"),chat:t.get("chat"),subagent:t.get("subagent"),fileChat:t.get("fileChat"),entry:r,send:t.get("send"),browse:t.get("browse"),hidden:"1"===t.get("hidden"),preview:t.get("preview"),view:t.get("view"),viewType:m&&n.includes(m)?m:null,filters:i,search:t.get("search"),sort:d,page:x&&parseInt(x,10)||null,pageSize:h&&parseInt(h,10)||null,cols:p?p.split(",").filter(Boolean):null,cronView:f&&o.includes(f)?f:null,cronCalMode:v&&l.includes(v)?v:null,cronDate:t.get("cronDate"),cronRunFilter:g&&a.includes(g)?g:null,cronRun:y&&parseInt(y,10)||null,terminal:"1"===t.get("terminal")}}function i(e,t){return"/?entry=".concat(encodeURIComponent(e),":").concat(encodeURIComponent(t))}function c(e){return"/?path=".concat(encodeURIComponent(e))}function d(e){let t=function(e){try{if(e.startsWith("/"))return new URL(e,"http://localhost");let t=new URL(e);if("/"===t.pathname||"/workspace"===t.pathname)return t}catch(e){}return null}(e);if(t&&("/"===t.pathname||"/workspace"===t.pathname)){let e=t.searchParams.get("entry");if(e&&e.includes(":")){let t=e.indexOf(":");return{kind:"entry",objectName:e.slice(0,t),entryId:e.slice(t+1)}}let r=t.searchParams.get("path");if(r)return{kind:"file",path:r}}if(e.startsWith("@entry/")){let t=e.slice(7),r=t.indexOf("/");if(r>0)return{kind:"entry",objectName:t.slice(0,r),entryId:t.slice(r+1)}}return null}function u(e){return!!(e.startsWith("@entry/")||"/workspace"===e||e.startsWith("/workspace?")||e.startsWith("/workspace#")||"/"===e||e.startsWith("/?")||e.startsWith("/#"))}},71615:()=>{},77704:(e,t,r)=>{"use strict";r.d(t,{$Q:()=>o,IB:()=>a,x_:()=>l,zM:()=>s});var n=r(80534);function o(e){let{children:t}=e;return(0,n.jsx)("div",{className:"editor-toolbar-group",children:t})}function l(){return(0,n.jsx)("div",{className:"editor-toolbar-divider"})}function a(e){let{active:t,onClick:r,title:o,children:l,disabled:a}=e;return(0,n.jsx)("button",{type:"button",className:"editor-toolbar-btn ".concat(t?"editor-toolbar-btn-active":""),onClick:r,title:o,disabled:a,children:l})}function s(e){let{active:t,onClick:r,title:o,children:l}=e;return(0,n.jsx)("button",{type:"button",className:"bubble-menu-btn ".concat(t?"bubble-menu-btn-active":""),onClick:r,title:o,children:l})}}},e=>{e.O(0,[5700,6237,2763,7073,1377,9363,1705,8522,7358],()=>e(e.s=48121)),_N_E=e.O()}]);
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{395:(e,t,r)=>{"use strict";r.d(t,{V:()=>a});var n=r(80534),o=r(74166),l=r(65163);function a(e){let{name:t="braille",children:r,className:a,style:s}=e,[i,c]=(0,o.useState)(0),d=l.Mb[t];return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>(e+1)%d.frames.length),d.interval);return()=>clearInterval(e)},[t,d.frames.length,d.interval]),(0,n.jsxs)("span",{className:a,style:{fontFamily:"monospace",...s},children:[d.frames[i],null!=r&&(0,n.jsxs)(n.Fragment,{children:[" ",r]})]})}},4582:()=>{},7713:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>ia});var n=r(80534),o=r(74166),l=r(99197),a=r(87694),s=r(17763);function i(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.5},children:[(0,n.jsx)("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function c(e){let{x:t,y:r,target:l,onAction:a,onClose:c}=e,d=(0,o.useRef)(null),u=function(e){let t="empty"!==e.kind&&e.isSystem;return"file"===e.kind?[{action:"open",label:"Open"},{separator:!0},{action:"rename",label:"Rename",shortcut:"Enter",disabled:t},{action:"duplicate",label:"Duplicate",shortcut:"⌘D",disabled:t},{action:"copy",label:"Copy Path",shortcut:"⌘C"},{separator:!0},{action:"getInfo",label:"Get Info",shortcut:"⌘I"},{separator:!0},{action:"delete",label:"Move to Trash",shortcut:"⌘⌫",disabled:t,danger:!0}]:"folder"===e.kind?[{action:"open",label:"Open"},{separator:!0},{action:"newFile",label:"New File",shortcut:"⌘N",disabled:t},{action:"newFolder",label:"New Folder",shortcut:"⇧⌘N",disabled:t},{separator:!0},{action:"rename",label:"Rename",shortcut:"Enter",disabled:t},{action:"duplicate",label:"Duplicate",shortcut:"⌘D",disabled:t},{action:"copy",label:"Copy Path",shortcut:"⌘C"},{separator:!0},{action:"getInfo",label:"Get Info",shortcut:"⌘I"},{separator:!0},{action:"delete",label:"Move to Trash",shortcut:"⌘⌫",disabled:t,danger:!0}]:[{action:"newFile",label:"New File",shortcut:"⌘N"},{action:"newFolder",label:"New Folder",shortcut:"⇧⌘N"},{separator:!0},{action:"paste",label:"Paste",shortcut:"⌘V",disabled:!0}]}(l),x="empty"!==l.kind&&l.isSystem,h=(0,o.useRef)({x:t,y:r});(0,o.useEffect)(()=>{let e=d.current;if(!e)return;let n=e.getBoundingClientRect(),o=window.innerWidth,l=window.innerHeight,a=t,s=r;a+n.width>o-8&&(a=o-n.width-8),s+n.height>l-8&&(s=l-n.height-8),a<8&&(a=8),s<8&&(s=8),h.current={x:a,y:s},e.style.left="".concat(a,"px"),e.style.top="".concat(s,"px")},[t,r]),(0,o.useEffect)(()=>{function e(e){d.current&&!d.current.contains(e.target)&&c()}function t(e){"Escape"===e.key&&c()}function r(){c()}return document.addEventListener("mousedown",e,!0),document.addEventListener("keydown",t,!0),window.addEventListener("scroll",r,!0),()=>{document.removeEventListener("mousedown",e,!0),document.removeEventListener("keydown",t,!0),window.removeEventListener("scroll",r,!0)}},[c]);let p=(0,o.useCallback)((e,t)=>{t||(a(e),c())},[a,c]);return(0,s.createPortal)((0,n.jsxs)("div",{ref:d,className:"fixed z-[9999] min-w-[200px] py-1 rounded-lg shadow-xl border",style:{left:t,top:r,background:"var(--color-surface)",borderColor:"var(--color-border)",backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",animation:"contextMenuFadeIn 100ms ease-out"},role:"menu",children:[x&&(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-[11px]",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(i,{}),(0,n.jsx)("span",{children:"System file (locked)"})]}),u.map((e,t)=>{if("separator"in e&&e.separator)return(0,n.jsx)("div",{className:"my-1 mx-2 border-t",style:{borderColor:"var(--color-border)"}},"sep-".concat(t));let r=e.disabled;return(0,n.jsxs)("button",{type:"button",role:"menuitem",disabled:r,className:"w-full flex items-center gap-2 px-3 py-1.5 text-[13px] text-left transition-colors",style:{color:r?"var(--color-text-muted)":e.danger?"#ef4444":"var(--color-text)",opacity:r?.5:1,cursor:r?"default":"pointer"},onMouseEnter:t=>{r||(t.currentTarget.style.background=e.danger?"rgba(239, 68, 68, 0.1)":"var(--color-surface-hover)")},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},onClick:()=>p(e.action,r),children:[e.icon,(0,n.jsx)("span",{className:"flex-1",children:e.label}),r&&x&&(0,n.jsx)(i,{}),e.shortcut&&(0,n.jsx)("span",{className:"text-[11px] ml-4",style:{color:"var(--color-text-muted)"},children:e.shortcut})]},e.action)}),(0,n.jsx)("style",{children:"\n @keyframes contextMenuFadeIn {\n from { opacity: 0; transform: scale(0.96); }\n to { opacity: 1; transform: scale(1); }\n }\n "})]}),document.body)}function d(e){let{currentName:t,onCommit:r,onCancel:l}=e,[a,s]=(0,o.useState)(t),[i,c]=(0,o.useState)(!1),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=d.current;if(!e)return;e.focus();let r=t.lastIndexOf(".");r>0?e.setSelectionRange(0,r):e.select()},[t]);let u=(0,o.useCallback)(e=>{let t=e.trim();return!(!t||t.includes("/")||t.includes("\\"))},[]),x=(0,o.useCallback)(()=>{let e=a.trim();if(!u(e)){c(!0),setTimeout(()=>c(!1),500);return}if(e===t)return void l();r(e)},[a,t,u,r,l]),h=(0,o.useCallback)(e=>{e.stopPropagation(),"Enter"===e.key?(e.preventDefault(),x()):"Escape"===e.key&&(e.preventDefault(),l())},[x,l]);return(0,n.jsx)("input",{ref:d,type:"text",value:a,onChange:e=>{s(e.target.value),c(!1)},onBlur:x,onKeyDown:h,className:"flex-1 text-sm rounded px-1 py-0 outline-none min-w-0",style:{background:"var(--color-bg)",color:"var(--color-text)",border:i?"1px solid #ef4444":"1px solid var(--color-accent)",animation:i?"renameShake 300ms ease":void 0},onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation()})}let u=new Set(["Chats","Skills","Memories"]);function x(e){return!!e.virtual||e.path.startsWith("~")}let h=[/^\.object\.yaml$/,/\.wal$/,/\.tmp$/],p=[/^workspace\.duckdb/,/^workspace_context\.yaml$/];function m(e){var t;let r=null!=(t=e.split("/").pop())?t:"";return!!h.some(e=>e.test(r))||!e.includes("/")&&p.some(e=>e.test(r))}function f(e){let{open:t}=e;return(0,n.jsx)("img",{src:t?"/icons/folder-open.png":"/icons/folder.png",alt:"",width:16,height:16,draggable:!1,style:{flexShrink:0}})}function v(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]})}function g(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"6",height:"14",x:"2",y:"5",rx:"1"}),(0,n.jsx)("rect",{width:"6",height:"10",x:"9",y:"5",rx:"1"}),(0,n.jsx)("rect",{width:"6",height:"16",x:"16",y:"3",rx:"1"})]})}function y(){return(0,n.jsx)("img",{src:"/icons/document.png",alt:"",width:16,height:16,draggable:!1,style:{flexShrink:0,filter:"drop-shadow(0 0.5px 1.5px rgba(0,0,0,0.2))"}})}function b(){return(0,n.jsx)("img",{src:"/icons/document.png",alt:"",width:16,height:16,draggable:!1,style:{flexShrink:0,filter:"drop-shadow(0 0.5px 1.5px rgba(0,0,0,0.2))"}})}function j(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]})}function k(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",x2:"12",y1:"20",y2:"10"}),(0,n.jsx)("line",{x1:"18",x2:"18",y1:"20",y2:"4"}),(0,n.jsx)("line",{x1:"6",x2:"6",y1:"20",y2:"14"})]})}function w(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function N(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#6366f1",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]})}function C(){return(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.4},children:[(0,n.jsx)("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function S(){return(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.55},children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}function M(e){let{open:t}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:t?"rotate(90deg)":"rotate(0deg)",transition:"transform 150ms ease"},children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}function L(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"})]})}function T(e){let{node:t,open:r}=e;if(t.path.startsWith("~chats/")||"~chats"===t.path)return(0,n.jsx)(w,{});switch(t.type){case"object":return"kanban"===t.defaultView?(0,n.jsx)(g,{}):(0,n.jsx)(v,{});case"document":return(0,n.jsx)(y,{});case"folder":return(0,n.jsx)(f,{open:r});case"database":return(0,n.jsx)(j,{});case"report":return(0,n.jsx)(k,{});case"app":{var o,l;let e=null!=(l=null==(o=t.appManifest)?void 0:o.icon)?l:t.icon;if(e&&(e.endsWith(".png")||e.endsWith(".svg")||e.endsWith(".jpg")||e.endsWith(".jpeg")||e.endsWith(".webp")))return(0,n.jsx)("img",{src:"/api/apps/serve/".concat(t.path,"/").concat(e),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",style:{objectFit:"cover"}});return(0,n.jsx)(N,{})}default:return(0,n.jsx)(b,{})}}function D(e){switch(e.type){case"object":return"var(--color-accent)";case"document":return"#60a5fa";case"database":return"#c084fc";case"report":return"#22c55e";case"app":return"#6366f1";default:return"var(--color-text-muted)"}}async function E(e,t){return(await fetch("/api/workspace/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,newName:t})})).json()}async function R(e){return(await fetch("/api/workspace/file",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})).json()}async function W(e,t){return(await fetch("/api/workspace/move",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourcePath:e,destinationDir:t})})).json()}async function I(e){return(await fetch("/api/workspace/copy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})).json()}async function B(e){return(await fetch("/api/workspace/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})).json()}async function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,content:t})})).json()}function P(e){let{message:t,onConfirm:r,onCancel:l}=e;return(0,o.useEffect)(()=>{function e(e){"Escape"===e.key&&l(),"Enter"===e.key&&r()}return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r,l]),(0,n.jsx)("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)"},children:(0,n.jsxs)("div",{className:"rounded-xl p-5 max-w-sm w-full shadow-2xl border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[(0,n.jsx)("p",{className:"text-sm mb-4",style:{color:"var(--color-text)"},children:t}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:l,className:"px-3 py-1.5 rounded-md text-sm",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:r,className:"px-3 py-1.5 rounded-md text-sm text-white",style:{background:"#ef4444"},children:"Delete"})]})]})})}function A(e){let{kind:t,parentPath:r,onSubmit:l,onCancel:a}=e,[s,i]=(0,o.useState)("file"===t?"untitled.md":"new-folder"),c=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let e=c.current;if(e)if(e.focus(),"file"===t){let t=s.lastIndexOf(".");e.setSelectionRange(0,t>0?t:s.length)}else e.select()},[]),(0,n.jsx)("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)"},children:(0,n.jsxs)("div",{className:"rounded-xl p-5 max-w-sm w-full shadow-2xl border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[(0,n.jsxs)("p",{className:"text-sm mb-3 font-medium",style:{color:"var(--color-text)"},children:["New ",t," in ",(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:r||"/"})]}),(0,n.jsx)("input",{ref:c,type:"text",value:s,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&l(s.trim()),"Escape"===e.key&&a()},className:"w-full px-3 py-2 rounded-md text-sm outline-none border",style:{background:"var(--color-bg)",color:"var(--color-text)",borderColor:"var(--color-border)"}}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-3",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 rounded-md text-sm",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l(s.trim()),className:"px-3 py-1.5 rounded-md text-sm text-white",style:{background:"var(--color-accent)"},children:"Create"})]})]})})}function _(e){let{node:t,depth:r,activePath:l,selectedPath:s,onSelect:i,onNodeSelect:c,expandedPaths:u,onToggleExpand:h,renamingPath:p,onStartRename:f,onCommitRename:v,onCancelRename:g,onContextMenu:y,compact:b,dragOverPath:j,workspaceRoot:k}=e,w=!!k&&t.path===k,N=t.children&&t.children.length>0,E=!w&&"app"!==t.type&&(N||"folder"===t.type||"object"===t.type),R=!w&&u.has(t.path),W=l===t.path,I=s===t.path,B=p===t.path,F=m(t.path),P=x(t),A=F||P||w,z=j===t.path&&E,{attributes:O,listeners:U,setNodeRef:H,isDragging:V}=(0,a.PM)({id:"drag-".concat(t.path),data:{node:t},disabled:A}),{setNodeRef:J,isOver:K}=(0,a.zM)({id:"drop-".concat(t.path),data:{node:t},disabled:!E||P}),q=(0,o.useCallback)(()=>{c(t.path),i(t),E&&h(t.path)},[t,E,i,c,h]),G=(0,o.useCallback)(()=>{A||f(t.path)},[t.path,A,f]),$=(0,o.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(t.path),y(e,t)},[t,c,y]),Z=(0,o.useCallback)(e=>{H(e),J(e)},[H,J]),Y=(K||z)&&E;return(0,n.jsxs)("div",{style:{opacity:V?.4:1},children:[(0,n.jsxs)("div",{ref:Z,...O,...U,role:"treeitem",tabIndex:-1,draggable:!A,onDragStart:e=>{e.dataTransfer.setData("application/x-file-mention",JSON.stringify({name:t.name,path:t.path})),e.dataTransfer.setData("text/plain",t.path),e.dataTransfer.effectAllowed="copy"},onClick:q,onDoubleClick:G,onContextMenu:$,className:"w-full flex items-center gap-1.5 py-1 px-2 rounded-md text-left text-sm transition-colors duration-100 cursor-pointer select-none",style:{paddingLeft:"".concat(16*r+8,"px"),background:w||Y?"var(--color-accent-light)":I||W?"var(--color-surface-hover)":"transparent",color:w?"var(--color-accent)":W||I?"var(--color-text)":"var(--color-text-muted)",outline:w?"1.5px solid var(--color-accent)":Y?"1px dashed var(--color-accent)":"none",outlineOffset:"-1px",borderRadius:w?"8px":"6px",marginTop:w?"2px":void 0,marginBottom:w?"2px":void 0},onMouseEnter:e=>{w?e.currentTarget.style.opacity="0.8":W||I||Y||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{w?e.currentTarget.style.opacity="1":W||I||Y||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{className:"flex-shrink-0 w-4 h-4 flex items-center justify-center",style:{opacity:+!!E,cursor:E?"pointer":void 0},onClick:E?e=>{e.stopPropagation(),h(t.path)}:void 0,children:E&&(0,n.jsx)(M,{open:R})}),(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",style:{color:w?"var(--color-accent)":D(t)},children:w?(0,n.jsx)(L,{}):(0,n.jsx)(T,{node:t,open:R})}),B?(0,n.jsx)(d,{currentName:t.name,onCommit:v,onCancel:g}):(0,n.jsx)("span",{className:"truncate flex-1",children:t.name}),w&&(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0 font-medium",style:{background:"var(--color-accent)",color:"white"},children:"workspace"}),"app"===t.type&&(0,n.jsx)("span",{className:"text-[9px] px-1.5 py-[1px] rounded flex-shrink-0 font-medium",style:{background:"#6366f118",color:"#6366f1"},children:"APP"}),A&&!w&&!b&&(0,n.jsx)("span",{className:"flex-shrink-0 ml-1",children:(0,n.jsx)(C,{})}),t.symlink&&!b&&(0,n.jsx)("span",{className:"flex-shrink-0 ml-0.5",title:"Symbolic link",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(S,{})}),"object"===t.type&&(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",style:{background:"var(--color-accent-light)",color:"var(--color-accent)"},children:"kanban"===t.defaultView?"board":"table"})]}),R&&N&&(0,n.jsx)("div",{className:"relative",style:{borderLeft:r>0?"1px solid var(--color-border)":"none",marginLeft:"".concat(16*r+16,"px")},children:t.children.map(e=>(0,n.jsx)(_,{node:e,depth:r+1,activePath:l,selectedPath:s,onSelect:i,onNodeSelect:c,expandedPaths:u,onToggleExpand:h,renamingPath:p,onStartRename:f,onCommitRename:v,onCancelRename:g,onContextMenu:y,compact:b,dragOverPath:j,workspaceRoot:k},e.path))})]})}function z(e){let{isDragging:t}=e,{setNodeRef:r,isOver:o}=(0,a.zM)({id:"drop-__root__",data:{rootDrop:!0}}),l=o&&t;return(0,n.jsx)("div",{ref:r,className:"flex-1 min-h-[48px]",style:{margin:t?"4px 8px":void 0,borderRadius:"6px",border:l?"1.5px dashed var(--color-accent)":t?"1.5px dashed var(--color-border)":"1.5px dashed transparent",background:l?"var(--color-accent-light)":"transparent",transition:"all 150ms ease",display:"flex",alignItems:"center",justifyContent:"center"},children:t&&(0,n.jsx)("span",{className:"text-[11px] select-none",style:{color:l?"var(--color-accent)":"var(--color-text-muted)",opacity:l?1:.6},children:"Drop here to move to root"})})}function O(e){let{node:t}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm shadow-lg border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text)",pointerEvents:"none"},children:[(0,n.jsx)("span",{style:{color:D(t)},children:(0,n.jsx)(T,{node:t})}),(0,n.jsx)("span",{children:t.name})]})}function U(e){let t=e.split("/");return t.pop(),t.join("/")||"."}let H="denchclaw-tree-expanded";function V(e){let{tree:t,activePath:r,onSelect:l,onRefresh:s,compact:i,parentDir:d,onNavigateUp:h,browseDir:p,workspaceRoot:v,onExternalDrop:g}=e,[y,b]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(H);if(e){let t=JSON.parse(e);if(Array.isArray(t))return new Set(t)}}catch(e){}return new Set})()),[j,k]=(0,o.useState)(null),[w,N]=(0,o.useState)(null),[C,S]=(0,o.useState)(null),[M,L]=(0,o.useState)(null),T=(0,o.useRef)({x:0,y:0}),D=(0,o.useRef)(null),V=(0,o.useCallback)(()=>{let e=e=>{T.current={x:e.clientX,y:e.clientY};let t=document.elementFromPoint(e.clientX,e.clientY),r=null==t?void 0:t.closest("[data-chat-drop-target]"),n=document.querySelector("[data-drag-hover]");r&&!r.hasAttribute("data-drag-hover")&&r.setAttribute("data-drag-hover",""),n&&n!==r&&n.removeAttribute("data-drag-hover")};D.current=e,window.addEventListener("pointermove",e,!0)},[]),J=(0,o.useCallback)(()=>{var e;D.current&&(window.removeEventListener("pointermove",D.current,!0),D.current=null),null==(e=document.querySelector("[data-drag-hover]"))||e.removeAttribute("data-drag-hover")},[]);(0,o.useEffect)(()=>J,[J]);let[K,q]=(0,o.useState)(null),[G,$]=(0,o.useState)(null),[Z,Y]=(0,o.useState)(null),Q=(0,o.useRef)(null),X=(0,o.useRef)(null),ee=(0,o.useRef)(null);(0,o.useEffect)(()=>{try{window.localStorage.setItem(H,JSON.stringify([...y]))}catch(e){}},[y]);let et=(0,o.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),er=(0,a.FR)((0,a.MS)(a.AN,{activationConstraint:{distance:8}})),en=(0,o.useCallback)(e=>{let t=e.active.data.current;(null==t?void 0:t.node)&&(L(t.node),V())},[V]),eo=(0,o.useCallback)(e=>{var t;let r=null==(t=e.over)?void 0:t.data.current;if(null==r?void 0:r.rootDrop)"__root__"!==ee.current&&(X.current&&clearTimeout(X.current),ee.current="__root__"),S("__root__");else if(null==r?void 0:r.node){let e=r.node.path;S(e),ee.current!==e&&(X.current&&clearTimeout(X.current),ee.current=e,("folder"===r.node.type||"object"===r.node.type)&&(X.current=setTimeout(()=>{ee.current===e&&b(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},300)))}else X.current&&clearTimeout(X.current),ee.current=null,S(null)},[]),el=(0,o.useCallback)(async e=>{var t;L(null),S(null),X.current&&clearTimeout(X.current),ee.current=null,J();let r=e.active.data.current;if(!(null==r?void 0:r.node))return;let n=r.node;if(g){let{x:e,y:t}=T.current,r=document.elementFromPoint(e,t);if(null==r?void 0:r.closest("[data-chat-drop-target]"))return void g(n)}let o=null==(t=e.over)?void 0:t.data.current;if(null==o?void 0:o.rootDrop){if("."===U(n.path))return;(await W(n.path,".")).ok&&s();return}if(!(null==o?void 0:o.node))return;let l=o.node;!("folder"!==l.type&&"object"!==l.type||l.path===n.path||l.path.startsWith(n.path+"/"))&&U(n.path)!==l.path&&(await W(n.path,l.path)).ok&&s()},[s,g,J]),ea=(0,o.useCallback)(()=>{L(null),S(null),X.current&&clearTimeout(X.current),ee.current=null,J()},[J]),es=(0,o.useCallback)((e,t)=>{let r=m(t.path)||x(t),n="folder"===t.type||"object"===t.type;q({x:e.clientX,y:e.clientY,target:{kind:n?"folder":"file",path:t.path,name:t.name,isSystem:r}})},[]),ei=(0,o.useCallback)(e=>{e.preventDefault(),q({x:e.clientX,y:e.clientY,target:{kind:"empty"}})},[]),ec=(0,o.useCallback)(async e=>{let r=null==K?void 0:K.target;if(r)switch(e){case"open":if("empty"!==r.kind){let e=function e(t,r){for(let n of t){if(n.path===r)return n;if(n.children){let t=e(n.children,r);if(t)return t}}return null}(t,r.path);e&&l(e)}break;case"rename":"empty"!==r.kind&&N(r.path);break;case"duplicate":"empty"!==r.kind&&(await I(r.path),s());break;case"copy":case"getInfo":"empty"!==r.kind&&await navigator.clipboard.writeText(r.path);break;case"delete":"empty"!==r.kind&&$(r.path);break;case"newFile":Y({kind:"file",parentPath:"folder"===r.kind?r.path:"file"===r.kind?U(r.path):""});break;case"newFolder":Y({kind:"folder",parentPath:"folder"===r.kind?r.path:"file"===r.kind?U(r.path):""})}},[K,t,l,s]),ed=(0,o.useCallback)(async e=>{if(!w)return;if(u.has(e)){alert('"'.concat(e,'" is a reserved name and cannot be used.')),N(null);return}let t=await E(w,e);N(null),t.ok&&s()},[w,s]),eu=(0,o.useCallback)(()=>{N(null)},[]),ex=(0,o.useCallback)(async()=>{if(!G)return;let e=await R(G);$(null),e.ok&&s()},[G,s]),eh=(0,o.useCallback)(async e=>{if(!Z||!e)return;if(u.has(e))return void alert('"'.concat(e,'" is a reserved name and cannot be used.'));let t=Z.parentPath?"".concat(Z.parentPath,"/").concat(e):e;"folder"===Z.kind?await B(t):await F(t,""),Y(null),s(),b(e=>{let t=new Set(e);return t.add(Z.parentPath),t})},[Z,s]),ep=(0,o.useCallback)(e=>{if(w)return;let r=function(e,t){let r=[];return!function e(n){for(let o of n)r.push(o),o.children&&t.has(o.path)&&e(o.children)}(e),r}(t,y),n=r.findIndex(e=>e.path===j),o=n>=0?r[n]:null;switch(e.key){case"ArrowDown":{e.preventDefault();let t=n<r.length-1?r[n+1]:r[0];t&&k(t.path);break}case"ArrowUp":{e.preventDefault();let t=n>0?r[n-1]:r[r.length-1];t&&k(t.path);break}case"ArrowRight":e.preventDefault(),o&&("folder"===o.type||"object"===o.type)&&b(e=>new Set([...e,o.path]));break;case"ArrowLeft":e.preventDefault(),o&&y.has(o.path)&&b(e=>{let t=new Set(e);return t.delete(o.path),t});break;case"Enter":if(e.preventDefault(),o){let t=m(o.path)||x(o);e.shiftKey||t?l(o):N(o.path)}break;case"F2":e.preventDefault(),!o||m(o.path)||x(o)||N(o.path);break;case"Backspace":case"Delete":!o||m(o.path)||x(o)||(e.preventDefault(),$(o.path));break;default:if(e.metaKey||e.ctrlKey){if("c"===e.key&&o)e.preventDefault(),navigator.clipboard.writeText(o.path);else if("d"===e.key&&o&&!m(o.path))e.preventDefault(),I(o.path).then(()=>s());else if("n"===e.key){e.preventDefault();let t=o?"folder"===o.type||"object"===o.type?o.path:U(o.path):"";e.shiftKey?Y({kind:"folder",parentPath:t}):Y({kind:"file",parentPath:t})}}}},[t,y,j,w,l,s]);return 0===t.length?(0,n.jsxs)("div",{className:"px-4 py-6 text-center text-sm",style:{color:"var(--color-text-muted)"},onContextMenu:ei,children:["No files in workspace",K&&(0,n.jsx)(c,{x:K.x,y:K.y,target:K.target,onAction:ec,onClose:()=>q(null)}),Z&&(0,n.jsx)(A,{kind:Z.kind,parentPath:Z.parentPath,onSubmit:eh,onCancel:()=>Y(null)})]}):(0,n.jsxs)(a.Mp,{sensors:er,collisionDetection:a.fp,onDragStart:en,onDragOver:eo,onDragEnd:el,onDragCancel:ea,children:[(0,n.jsxs)("div",{ref:Q,className:"py-1 outline-none flex flex-col min-h-full",tabIndex:0,role:"tree",onKeyDown:ep,onContextMenu:ei,children:[null!=d&&h&&(0,n.jsxs)("div",{role:"treeitem",tabIndex:-1,onClick:h,className:"w-full flex items-center gap-1.5 py-1 px-2 rounded-md text-left text-sm transition-colors duration-100 cursor-pointer select-none",style:{paddingLeft:"8px",color:"var(--color-text-muted)",borderRadius:"6px"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{className:"flex-shrink-0 w-4 h-4 flex items-center justify-center",children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})})}),(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(f,{})}),(0,n.jsx)("span",{className:"truncate flex-1",children:".."})]}),t.map(e=>(0,n.jsx)(_,{node:e,depth:0,activePath:r,selectedPath:j,onSelect:l,onNodeSelect:k,expandedPaths:y,onToggleExpand:et,renamingPath:w,onStartRename:N,onCommitRename:ed,onCancelRename:eu,onContextMenu:es,compact:i,dragOverPath:C,workspaceRoot:v},e.path)),(0,n.jsx)(z,{isDragging:!!M})]}),(0,n.jsx)(a.Hd,{dropAnimation:null,style:{pointerEvents:"none"},children:M?(0,n.jsx)(O,{node:M}):null}),K&&(0,n.jsx)(c,{x:K.x,y:K.y,target:K.target,onAction:ec,onClose:()=>q(null)}),G&&(0,n.jsx)(P,{message:'Are you sure you want to delete "'.concat(G.split("/").pop(),'"? This action cannot be undone.'),onConfirm:ex,onCancel:()=>$(null)}),Z&&(0,n.jsx)(A,{kind:Z.kind,parentPath:Z.parentPath,onSubmit:eh,onCancel:()=>Y(null)}),(0,n.jsx)("style",{children:"\n @keyframes renameShake {\n 0%, 100% { transform: translateX(0); }\n 20%, 60% { transform: translateX(-3px); }\n 40%, 80% { transform: translateX(3px); }\n }\n"})]})}function J(e){return e.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Za-z]:[/\\]Users[/\\][^/\\]+/,"~")}function K(e){let{onWorkspaceSwitch:t,onWorkspaceDelete:r,onCreateWorkspace:l,activeWorkspaceHint:a,trigger:s}=e,[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(null),[x,h]=(0,o.useState)(!1),[p,m]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),[g,y]=(0,o.useState)(null),b=(0,o.useRef)(null),j=(0,o.useCallback)(async()=>{try{var e,t,r,n,o,l,a,s;let i=await fetch("/api/workspace/list"),d=await i.json(),x=(null!=(n=null!=(r=d.workspaces)?r:d.profiles)?n:[]).filter(e=>!!e.workspaceDir),h=null!=(l=null!=(o=d.activeWorkspace)?o:d.activeProfile)?l:null,p=h&&x.some(e=>e.name===h)?h:null!=(s=null!=(a=null==(e=x.find(e=>e.isActive))?void 0:e.name)?a:null==(t=x[0])?void 0:t.name)?s:null;c(x),u(p)}catch(e){}},[]);(0,o.useEffect)(()=>{j()},[j,a]),(0,o.useEffect)(()=>{function e(e){b.current&&!b.current.contains(e.target)&&h(!1)}if(x)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[x]);let k=async e=>{if(e===d)return void h(!1);y(null),m(!0);try{var r,n,o;let l=await fetch("/api/workspace/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workspace:e})});if(l.ok){let e=await l.json();u(null!=(n=null!=(r=e.activeWorkspace)?r:e.activeProfile)?n:null),null==t||t(),j()}else{let e=await l.json().catch(()=>({}));y(null!=(o=e.error)?o:"Failed to switch workspace.")}}catch(e){y("Failed to switch workspace.")}finally{m(!1),h(!1)}},w=async e=>{let n=i.find(t=>t.name===e);if((null==n?void 0:n.workspaceDir)&&window.confirm('Delete workspace "'.concat(e,'"?\n\nThis permanently removes:\n').concat(J(n.workspaceDir),"\n\nThis cannot be undone."))){y(null),v(e);try{let n=await fetch("/api/workspace/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workspace:e})});if(!n.ok){var o;let t=await n.json().catch(()=>({}));y(null!=(o=t.error)?o:"Failed to delete workspace '".concat(e,"'."));return}e===d&&(null==t||t()),null==r||r(e),await j()}catch(t){y("Failed to delete workspace '".concat(e,"'."))}finally{v(null)}}},N=i.length>0,C=()=>{N&&h(e=>!e)};return s||N?(0,n.jsxs)("div",{className:"relative ".concat(s?"flex-1 min-w-0":""),ref:b,children:[s?s({isOpen:x,onClick:C,activeWorkspace:d,switching:p}):(0,n.jsxs)("button",{onClick:C,disabled:p,className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-xs transition-colors hover:bg-[var(--color-surface-hover)] disabled:opacity-50",style:{color:"var(--color-text-secondary)"},title:"Switch workspace",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})}),(0,n.jsx)("span",{className:"truncate max-w-[120px]",children:null!=d?d:"No workspace"}),(0,n.jsx)("svg",{className:"w-3 h-3 transition-transform ".concat(x?"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"})})]}),N&&x&&(0,n.jsxs)("div",{className:"absolute left-0 top-full mt-1 w-64 rounded-lg overflow-hidden z-50",style:{background:"var(--color-surface-raised)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-lg)"},children:[(0,n.jsx)("div",{className:"px-3 py-2 text-xs font-medium",style:{color:"var(--color-text-muted)",borderBottom:"1px solid var(--color-border)"},children:"Workspaces"}),(0,n.jsx)("div",{className:"py-1 max-h-64 overflow-y-auto",children:i.map(e=>{let t=e.name===d;return(0,n.jsxs)("div",{className:"flex items-center gap-1 px-1.5 py-0.5",children:[(0,n.jsxs)("button",{onClick:()=>void k(e.name),disabled:p||!!f,className:"flex-1 min-w-0 flex items-center gap-2 px-1.5 py-1.5 rounded text-left text-sm transition-colors hover:bg-[var(--color-surface-hover)] disabled:opacity-50",style:{color:"var(--color-text)"},children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:t?"var(--color-success)":"transparent",border:t?"none":"1px solid var(--color-border-strong)"}}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"flex items-center gap-1.5",children:(0,n.jsx)("span",{className:"truncate font-medium",children:e.name})}),(0,n.jsx)("div",{className:"text-xs truncate mt-0.5",style:{color:"var(--color-text-muted)"},children:e.workspaceDir?J(e.workspaceDir):"No workspace yet"})]}),t&&(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded",style:{background:"var(--color-accent-light)",color:"var(--color-accent)"},children:"Active"})]}),e.workspaceDir&&(0,n.jsx)("button",{onClick:()=>void w(e.name),disabled:p||!!f,title:"Delete workspace ".concat(e.name),className:"p-1.5 rounded transition-colors hover:bg-[var(--color-surface-hover)] disabled:opacity-50",style:{color:f===e.name?"var(--color-text-muted)":"var(--color-error)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M8 6V4h8v2"}),(0,n.jsx)("path",{d:"M19 6l-1 14H6L5 6"}),(0,n.jsx)("path",{d:"M10 11v6"}),(0,n.jsx)("path",{d:"M14 11v6"})]})})]},e.name)})}),g&&(0,n.jsx)("p",{className:"mx-3 mb-2 mt-1 rounded px-2 py-1 text-xs",style:{background:"rgba(220, 38, 38, 0.08)",color:"var(--color-error)"},children:g}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--color-border)"},children:(0,n.jsxs)("button",{onClick:()=>{h(!1),null==l||l()},className:"w-full flex items-center gap-2 px-3 py-2.5 text-sm transition-colors hover:bg-[var(--color-surface-hover)]",style:{color:"var(--color-accent)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]}),"New Workspace"]})})]})]}):null}function q(e){let{isOpen:t,onClose:r,onCreated:l}=e,[a,s]=(0,o.useState)(""),[i,c]=(0,o.useState)(!0),[d,u]=(0,o.useState)(!1),[x,h]=(0,o.useState)(null),[p,m]=(0,o.useState)(null),f=(0,o.useRef)(null),v=(0,o.useRef)(null);(0,o.useEffect)(()=>{t&&(s(""),h(null),m(null),setTimeout(()=>{var e;return null==(e=f.current)?void 0:e.focus()},100))},[t]),(0,o.useEffect)(()=>{function e(e){"Escape"===e.key&&r()}if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,r]);let g=async()=>{let e=a.trim();if(!e)return void h("Please enter a workspace name.");if(!/^[a-zA-Z0-9_-]+$/.test(e))return void h("Name must use only letters, numbers, hyphens, or underscores.");u(!0),h(null);try{var t;let r=await fetch("/api/workspace/init",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workspace:e,seedBootstrap:i})}),n=await r.json();if(!r.ok)return void h(n.error||"Failed to create workspace.");m({workspaceDir:n.workspaceDir,seededFiles:null!=(t=n.seededFiles)?t:[]}),null==l||l()}catch(e){h(e.message)}finally{u(!1)}};return t?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)"},onClick:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{ref:v,className:"w-full max-w-md rounded-xl overflow-hidden",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-xl)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("h2",{className:"text-base font-semibold",style:{color:"var(--color-text)"},children:"New Workspace"}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]}),(0,n.jsx)("div",{className:"px-5 py-4 space-y-4",children:p?(0,n.jsxs)("div",{className:"text-center py-4",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center mx-auto mb-3",style:{background:"rgba(22, 163, 74, 0.1)"},children:(0,n.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"#16a34a",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})})}),(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"Workspace created"}),(0,n.jsx)("code",{className:"text-xs px-2 py-1 rounded mt-2 inline-block",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:p.workspaceDir.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Za-z]:[/\\]Users[/\\][^/\\]+/,"~")}),p.seededFiles.length>0&&(0,n.jsxs)("p",{className:"text-xs mt-2",style:{color:"var(--color-text-muted)"},children:["Seeded: ",p.seededFiles.join(", ")]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium mb-1.5",style:{color:"var(--color-text-secondary)"},children:"Workspace name"}),(0,n.jsx)("input",{ref:f,type:"text",value:a,onChange:e=>{s(e.target.value),h(null)},onKeyDown:e=>{"Enter"!==e.key||d||g()},placeholder:"e.g. work, personal, project-x",className:"w-full px-3 py-2 text-sm rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--color-accent)]",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),(0,n.jsxs)("p",{className:"text-xs mt-1",style:{color:"var(--color-text-muted)"},children:["This creates a workspace under ~/.openclaw-dench/workspace-","{name}","."]})]}),(0,n.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer hidden",children:[(0,n.jsx)("input",{type:"checkbox",checked:i,onChange:e=>c(e.target.checked),className:"rounded",style:{accentColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-secondary)"},children:"Seed bootstrap files and workspace database"})]}),x&&(0,n.jsx)("p",{className:"text-sm px-3 py-2 rounded-lg",style:{background:"rgba(220, 38, 38, 0.08)",color:"var(--color-error)"},children:x})]})}),(0,n.jsx)("div",{className:"flex items-center justify-end gap-2 px-5 py-3",style:{borderTop:"1px solid var(--color-border)"},children:p?(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 text-sm font-medium rounded-lg transition-colors",style:{background:"var(--color-accent)",color:"#fff"},children:"Done"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 text-sm rounded-lg transition-colors hover:bg-[var(--color-surface-hover)]",style:{color:"var(--color-text-secondary)"},children:"Cancel"}),(0,n.jsx)("button",{onClick:()=>void g(),disabled:d||!a.trim(),className:"px-4 py-2 text-sm font-medium rounded-lg transition-colors disabled:opacity-50",style:{background:"var(--color-accent)",color:"#fff"},children:d?"Creating...":"Create Workspace"})]})})]})}):null}var G=r(395);function $(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),(0,n.jsx)("polyline",{points:"9 22 9 12 15 12 15 22"})]})}function Z(){return(0,n.jsx)("img",{src:"/icons/folder-open.png",alt:"",width:20,height:20,draggable:!1,style:{flexShrink:0}})}function Y(){let[e,t]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{t(document.documentElement.classList.contains("dark"))},[]),(0,n.jsx)("button",{type:"button",onClick:()=>{let r=!e;t(r),r?(document.documentElement.classList.add("dark"),localStorage.setItem("theme","dark")):(document.documentElement.classList.remove("dark"),localStorage.setItem("theme","light"))},className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:e?"Switch to light mode":"Switch to dark mode",children:e?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M12 2v2"}),(0,n.jsx)("path",{d:"M12 20v2"}),(0,n.jsx)("path",{d:"m4.93 4.93 1.41 1.41"}),(0,n.jsx)("path",{d:"m17.66 17.66 1.41 1.41"}),(0,n.jsx)("path",{d:"M2 12h2"}),(0,n.jsx)("path",{d:"M20 12h2"}),(0,n.jsx)("path",{d:"m6.34 17.66-1.41 1.41"}),(0,n.jsx)("path",{d:"m19.07 4.93-1.41 1.41"})]}):(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})})}function Q(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]})}function X(){return(0,n.jsx)("img",{src:"/icons/folder.png",alt:"",width:14,height:14,draggable:!1,style:{flexShrink:0}})}function ee(){return(0,n.jsx)("img",{src:"/icons/document.png",alt:"",width:14,height:14,draggable:!1,style:{flexShrink:0,filter:"drop-shadow(0 0.5px 1.5px rgba(0,0,0,0.2))"}})}function et(){return(0,n.jsx)("img",{src:"/icons/document.png",alt:"",width:14,height:14,draggable:!1,style:{flexShrink:0,filter:"drop-shadow(0 0.5px 1.5px rgba(0,0,0,0.2))"}})}function er(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]})}function en(e){let{type:t}=e;switch(t){case"folder":return(0,n.jsx)(X,{});case"document":return(0,n.jsx)(et,{});case"database":return(0,n.jsx)(er,{});default:return(0,n.jsx)(ee,{})}}function eo(e){let{onSelect:t}=e,[r,l]=(0,o.useState)(""),[a,s]=(0,o.useState)([]),[i,c]=(0,o.useState)(!1),[d,u]=(0,o.useState)(!1),[x,h]=(0,o.useState)(0),p=(0,o.useRef)(null),m=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!r.trim()){s([]),c(!1);return}u(!0);let e=setTimeout(async()=>{try{var e;let t=await fetch("/api/workspace/suggest-files?q=".concat(encodeURIComponent(r.trim()))),n=await t.json();s(null!=(e=n.items)?e:[]),c(!0),h(0)}catch(e){s([])}finally{u(!1)}},150);return()=>clearTimeout(e)},[r]),(0,o.useEffect)(()=>{function e(e){m.current&&!m.current.contains(e.target)&&c(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let f=(0,o.useCallback)(e=>{var r,n;"ArrowDown"===e.key?(e.preventDefault(),h(e=>Math.min(e+1,a.length-1))):"ArrowUp"===e.key?(e.preventDefault(),h(e=>Math.max(e-1,0))):"Enter"===e.key&&a[x]?(e.preventDefault(),t(a[x]),l(""),c(!1),null==(r=p.current)||r.blur()):"Escape"===e.key&&(c(!1),l(""),null==(n=p.current)||n.blur())},[a,x,t]),v=(0,o.useCallback)(e=>{t(e),l(""),c(!1)},[t]);return(0,n.jsxs)("div",{ref:m,className:"relative px-3 pt-2 pb-1",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 pointer-events-none",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(Q,{})}),(0,n.jsx)("input",{ref:p,type:"text",value:r,onChange:e=>l(e.target.value),onKeyDown:f,onFocus:()=>{a.length>0&&c(!0)},placeholder:"Search files...",className:"w-full pl-8 pr-3 py-1.5 rounded-lg text-xs outline-none transition-colors",style:{background:"var(--color-bg)",color:"var(--color-text)",border:"1px solid var(--color-border)"}}),d&&(0,n.jsx)("span",{className:"absolute right-2.5 top-1/2 -translate-y-1/2",children:(0,n.jsx)(G.V,{name:"braille",className:"text-sm",style:{color:"var(--color-text-muted)"}})})]}),i&&a.length>0&&(0,n.jsx)("div",{className:"absolute left-3 right-3 mt-1 rounded-lg shadow-lg border overflow-hidden z-50 max-h-[300px] overflow-y-auto",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:a.map((e,t)=>(0,n.jsxs)("button",{type:"button",onClick:()=>v(e),className:"w-full flex items-center gap-2 px-3 py-2 text-left text-xs cursor-pointer transition-colors",style:{background:t===x?"var(--color-surface-hover)":"transparent",color:"var(--color-text)"},onMouseEnter:()=>h(t),children:[(0,n.jsx)("span",{className:"flex-shrink-0",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(en,{type:e.type})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"truncate font-medium",children:e.name}),(0,n.jsx)("div",{className:"truncate",style:{color:"var(--color-text-muted)",fontSize:"10px"},children:e.path.split("/").slice(0,-1).join("/")})]}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0 capitalize",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:e.type})]},e.path))}),i&&r.trim()&&!d&&0===a.length&&(0,n.jsx)("div",{className:"absolute left-3 right-3 mt-1 rounded-lg shadow-lg border z-50 px-3 py-3 text-center",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No files found"})})]})}function el(e){let{tree:t,activePath:r,onSelect:l,onRefresh:a,orgName:s,loading:i,browseDir:c,parentDir:d,onNavigateUp:u,onGoHome:x,onFileSearchSelect:h,workspaceRoot:p,onGoToChat:m,onExternalDrop:f,mobile:v,onClose:g,showHidden:y,onToggleHidden:b,width:j,onCollapse:k,activeWorkspace:w,onWorkspaceChanged:N}=e,C=null!=c,S=v?"280px":null!=j?j:260,[M,L]=(0,o.useState)(!1),T=(0,n.jsxs)("aside",{className:"flex flex-col h-screen shrink-0 ".concat(v?"drawer-left":"border-r"),style:{width:"number"==typeof S?"".concat(S,"px"):S,minWidth:"number"==typeof S?"".concat(S,"px"):S,background:"var(--color-sidebar-bg)",borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[C?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:(0,n.jsx)(Z,{})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},title:c,children:"/"===c?"/":c.split("/").pop()||c}),(0,n.jsx)("div",{className:"text-[11px] truncate",style:{color:"var(--color-text-muted)"},title:c,children:c})]}),x&&(0,n.jsx)("button",{type:"button",onClick:x,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Return to workspace",children:(0,n.jsx)($,{})})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>void(null==m||m()),className:"w-7 h-7 rounded-lg flex items-center justify-center shrink-0 cursor-pointer transition-colors hover:bg-stone-200 dark:hover:bg-stone-700",style:{background:"transparent",color:"var(--color-text-muted)"},title:"All Chats",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),(0,n.jsx)("polyline",{points:"9 22 9 12 15 12 15 22"})]})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-1.5",children:[(0,n.jsx)("div",{className:"text-[13px] font-semibold truncate text-stone-700 dark:text-stone-200",children:s||"Workspace"}),(0,n.jsx)("div",{className:"mt-1",children:(0,n.jsx)(K,{activeWorkspaceHint:null!=w?w:null,onWorkspaceSwitch:()=>{null==N||N()},onWorkspaceDelete:()=>{null==N||N()},onCreateWorkspace:()=>{L(!0)},trigger:e=>{let{onClick:t,activeWorkspace:r,switching:o}=e;return(0,n.jsxs)("button",{type:"button",onClick:t,disabled:o,className:"text-[11px] flex items-center gap-1 truncate w-full transition-colors",style:{color:"var(--color-text-muted)"},title:"Switch workspace",children:[(0,n.jsx)("span",{children:"Workspace"}),(0,n.jsx)("span",{className:"px-1 py-0.5 rounded text-[10px] shrink-0 bg-stone-200 text-stone-600 dark:bg-stone-700 dark:text-stone-300",children:r||"-"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}})})]})]}),k&&(0,n.jsx)("button",{type:"button",onClick:k,className:"p-1 rounded-md shrink-0 transition-colors hover:bg-stone-200 dark:hover:bg-stone-700",style:{color:"var(--color-text-muted)"},title:"Hide sidebar (⌘B)",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M9 3v18"})]})})]}),h&&(0,n.jsx)(eo,{onSelect:h}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-1",children:i?(0,n.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})}):(0,n.jsx)(V,{tree:t,activePath:r,onSelect:l,onRefresh:a,parentDir:d,onNavigateUp:u,browseDir:c,workspaceRoot:p,onExternalDrop:f})}),(0,n.jsxs)("div",{className:"px-3 py-2.5 border-t flex items-center justify-between",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("a",{href:"https://denchclaw.com",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 px-2 py-1.5 rounded-lg text-sm",style:{color:"var(--color-text-muted)"},children:"denchclaw.com"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[b&&(0,n.jsx)("button",{type:"button",onClick:b,className:"p-1.5 rounded-lg transition-colors",style:{color:y?"var(--color-accent)":"var(--color-text-muted)"},title:y?"Hide dotfiles":"Show dotfiles",children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}),(0,n.jsx)("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),(0,n.jsx)("path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}),(0,n.jsx)("path",{d:"m2 2 20 20"})]})})}),(0,n.jsx)(Y,{})]})]})]});return v?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"drawer-backdrop",onClick:()=>void(null==g||g()),children:(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),className:"fixed inset-y-0 left-0 z-50",children:T})}),(0,n.jsx)(q,{isOpen:M,onClose:()=>L(!1),onCreated:()=>{null==N||N()}})]}):(0,n.jsxs)(n.Fragment,{children:[T,(0,n.jsx)(q,{isOpen:M,onClose:()=>L(!1),onCreated:()=>{null==N||N()}})]})}var ea=r(50890),es=r(76552),ei=r(42282),ec=r(24285),ed=r(98832);function eu(e,t,r){return(0,ed.IL)(e.getValue(t),r).passed}function ex(e){let{id:t,children:r,style:o,className:l}=e,{attributes:a,listeners:s,setNodeRef:i,transform:c,transition:d,isDragging:u}=(0,ei.gl)({id:t}),x={...o,transform:ec.Ks.Translate.toString(c),transition:d,opacity:u?.5:1,cursor:"grab"};return(0,n.jsx)("th",{ref:i,style:x,className:l,...a,...s,children:r})}function eh(e){let{direction:t}=e;return t?(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:"asc"===t?(0,n.jsx)("path",{d:"m5 12 7-7 7 7"}):(0,n.jsx)("path",{d:"m19 12-7 7-7-7"})}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.25},children:[(0,n.jsx)("path",{d:"m7 15 5 5 5-5"}),(0,n.jsx)("path",{d:"m7 9 5-5 5 5"})]})}function ep(e){let{columns:t,data:r,loading:l=!1,searchPlaceholder:s="Search...",enableGlobalFilter:i=!0,enableSorting:c=!0,enableRowSelection:d=!1,rowSelection:u,onRowSelectionChange:x,bulkActions:h,enableColumnReordering:p=!1,onColumnReorder:m,initialColumnVisibility:f,onColumnVisibilityChanged:v,pageSize:g=100,onRefresh:y,onAdd:b,addButtonLabel:j="+ Add",onRowClick:k,rowActions:w,toolbarExtra:N,title:C,titleIcon:S,stickyFirstColumn:M=!0,serverPagination:L,onServerSearch:T}=e,[D,E]=(0,o.useState)([]),[R,W]=(0,o.useState)(""),[I,B]=(0,o.useState)([]),[F,P]=(0,o.useState)(null!=f?f:{});(0,o.useEffect)(()=>{P(null!=f?f:{})},[f]);let[A,_]=(0,o.useState)({}),[z,O]=(0,o.useState)(!1),[U,H]=(0,o.useState)(M),[V,J]=(0,o.useState)(!1),[K,q]=(0,o.useState)({pageIndex:0,pageSize:g}),G=(0,o.useRef)(null),$=(0,o.useRef)(null),Z=void 0!==u?u:A,Y=(0,o.useCallback)(e=>"id"in e&&"string"==typeof e.id?e.id:"accessorKey"in e&&"string"==typeof e.accessorKey?e.accessorKey:"",[]),Q=(0,o.useCallback)(e=>{let t=e.map(Y),r=[];return d&&r.push("select"),r.push(...t),w&&r.push("actions"),r},[Y,d,w]),[X,ee]=(0,o.useState)(()=>Q(t));(0,o.useEffect)(()=>{ee(Q(t))},[t,Q]);let et=(0,a.FR)((0,a.MS)(a.AN,{activationConstraint:{distance:5}})),er=(0,o.useCallback)(e=>{let{active:t,over:r}=e;r&&t.id!==r.id&&ee(e=>{let n=e.indexOf(t.id),o=e.indexOf(r.id),l=(0,ei.be)(e,n,o);return null==m||m(l),l})},[m]),en=(0,o.useCallback)(e=>{J(e.currentTarget.scrollLeft>0)},[]);(0,o.useEffect)(()=>{function e(e){G.current&&!G.current.contains(e.target)&&O(!1)}if(z)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[z]);let eo=d?{id:"select",header:e=>{let{table:t}=e;return(0,n.jsx)("input",{type:"checkbox",checked:t.getIsAllPageRowsSelected(),onChange:t.getToggleAllPageRowsSelectedHandler(),className:"w-3.5 h-3.5 rounded accent-[var(--color-accent)] cursor-pointer"})},cell:e=>{let{row:t}=e;return(0,n.jsx)("input",{type:"checkbox",checked:t.getIsSelected(),onChange:t.getToggleSelectedHandler(),onClick:e=>e.stopPropagation(),className:"w-3.5 h-3.5 rounded accent-[var(--color-accent)] cursor-pointer"})},size:40,enableSorting:!1,enableHiding:!1}:null,el=w?{id:"actions",header:()=>null,cell:e=>{let{row:t}=e;return(0,n.jsx)(ef,{row:t.original,actions:w(t.original)})},size:48,enableSorting:!1,enableHiding:!1}:null,ec=(0,o.useMemo)(()=>{let e=[];return eo&&e.push(eo),e.push(...t),el&&e.push(el),e},[t,eo,el]),ed=L?{pageIndex:L.page-1,pageSize:L.pageSize}:void 0,ep=(0,ea.N4)({data:r,columns:ec,state:{sorting:D,globalFilter:R,columnFilters:I,columnVisibility:F,rowSelection:Z,columnOrder:p?X:void 0,pagination:null!=ed?ed:K},onSortingChange:E,onGlobalFilterChange:W,onColumnFiltersChange:B,onColumnVisibilityChange:e=>{let t="function"==typeof e?e(F):e;P(t),null==v||v(t)},onRowSelectionChange:e=>{x?x(e):_(e)},onPaginationChange:L?e=>{let t="function"==typeof e?e(ed):e;t.pageSize!==L.pageSize?L.onPageSizeChange(t.pageSize):t.pageIndex!==L.page-1&&L.onPageChange(t.pageIndex+1)}:q,getCoreRowModel:(0,es.HT)(),getSortedRowModel:c?(0,es.h5)():void 0,getFilteredRowModel:L?void 0:(0,es.hM)(),getPaginationRowModel:L?void 0:(0,es.kW)(),...L?{manualPagination:!0,pageCount:Math.ceil(L.totalCount/L.pageSize)}:{},enableRowSelection:d,enableSorting:c,globalFilterFn:eu,columnResizeMode:"onChange"}),eg=Object.keys(Z).filter(e=>Z[e]).length,ey=ep.getVisibleFlatColumns().filter(e=>"select"!==e.id&&"actions"!==e.id);return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 flex-shrink-0 flex-wrap",style:{borderBottom:"1px solid var(--color-border)"},children:[C&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mr-2",children:[S,(0,n.jsx)("span",{className:"text-sm font-semibold",style:{color:"var(--color-text)"},children:C})]}),i&&(0,n.jsxs)("div",{className:"relative flex-1 min-w-[180px] max-w-[320px]",children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"absolute left-3 top-1/2 -translate-y-1/2",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]}),(0,n.jsx)("input",{type:"text",value:R,onChange:e=>{W(e.target.value),null==T||T(e.target.value)},placeholder:s,className:"w-full pl-9 pr-3 py-1.5 text-xs rounded-full outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"1px solid var(--color-border)"}}),R&&(0,n.jsx)("button",{type:"button",onClick:()=>{W(""),null==T||T("")},className:"absolute right-2.5 top-1/2 -translate-y-1/2",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]}),eg>0&&h&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("span",{className:"text-xs font-medium",style:{color:"var(--color-text-muted)"},children:[eg," selected"]}),h]}),(0,n.jsx)("div",{className:"flex-1"}),N,y&&(0,n.jsx)("button",{type:"button",onClick:y,className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"Refresh",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}),(0,n.jsx)("path",{d:"M21 3v5h-5"}),(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"}),(0,n.jsx)("path",{d:"M3 21v-5h5"})]})}),(0,n.jsxs)("div",{className:"relative",ref:G,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>O(e=>!e),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)",background:z?"var(--color-surface-hover)":"transparent"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M9 3v18"}),(0,n.jsx)("path",{d:"M15 3v18"})]}),"Columns"]}),z&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[200px] rounded-xl overflow-hidden py-1",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-lg)"},children:[(0,n.jsxs)("label",{className:"flex items-center gap-2 px-3 py-2 text-xs cursor-pointer",style:{color:"var(--color-text-muted)",borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:U,onChange:()=>H(e=>!e),className:"w-3.5 h-3.5 rounded accent-[var(--color-accent)]"}),"Freeze first column"]}),0===ey.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs",style:{color:"var(--color-text-muted)"},children:"No toggleable columns"}):ep.getAllLeafColumns().filter(e=>"select"!==e.id&&"actions"!==e.id&&e.getCanHide()).map(e=>{var t,r;return(0,n.jsxs)("label",{className:"flex items-center gap-2 px-3 py-1.5 text-xs cursor-pointer",style:{color:"var(--color-text)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:e.getIsVisible(),onChange:e.getToggleVisibilityHandler(),className:"w-3.5 h-3.5 rounded accent-[var(--color-accent)]"}),"string"==typeof e.columnDef.header?e.columnDef.header:String(null!=(r=null==(t=e.columnDef.meta)?void 0:t.label)?r:e.id)]},e.id)})]})]}),b&&(0,n.jsx)("button",{type:"button",onClick:b,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium",style:{background:"var(--color-accent)",color:"white"},children:j})]}),(0,n.jsx)("div",{ref:$,className:"flex-1 overflow-auto min-w-0",onScroll:en,children:l?(0,n.jsx)(ev,{columnCount:ec.length}):0===r.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:[(0,n.jsxs)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"}),(0,n.jsx)("path",{d:"M9 3v18"})]}),(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No data"})]}):(0,n.jsx)(a.Mp,{sensors:et,collisionDetection:a.fp,onDragEnd:er,children:(0,n.jsxs)("table",{className:"w-full text-sm",style:{borderCollapse:"separate",borderSpacing:0},children:[(0,n.jsx)("thead",{children:ep.getHeaderGroups().map(e=>(0,n.jsx)("tr",{children:(0,n.jsx)(ei.gB,{items:X,strategy:ei.m$,children:e.headers.map((e,t)=>{let r=t===+!!d,o=U&&r,l="select"===e.id,a="actions"===e.id,s=e.column.getCanSort(),i={borderColor:"var(--color-border)",background:"var(--color-surface)",position:"sticky",top:0,zIndex:o||l?31:30,...o?{left:40*!!d,boxShadow:V?"4px 0 8px -2px rgba(0,0,0,0.08)":"none"}:{},...l?{left:0,position:"sticky",zIndex:31,width:40}:{},width:e.getSize()},c=e.isPlaceholder?null:(0,ea.Kv)(e.column.columnDef.header,e.getContext());return!p||l||a?(0,n.jsx)("th",{style:i,className:"text-left px-3 py-2.5 font-medium text-xs uppercase tracking-wider whitespace-nowrap border-b select-none",children:(0,n.jsxs)("span",{className:"flex items-center gap-1 ".concat(s?"cursor-pointer":""),onClick:s?e.column.getToggleSortingHandler():void 0,style:{color:"var(--color-text-muted)"},children:[c,s&&(0,n.jsx)(eh,{direction:e.column.getIsSorted()})]})},e.id):(0,n.jsx)(ex,{id:e.id,style:i,className:"text-left px-3 py-2.5 font-medium text-xs uppercase tracking-wider whitespace-nowrap border-b select-none",children:(0,n.jsxs)("span",{className:"flex items-center gap-1 ".concat(s?"cursor-pointer":""),onClick:s?e.column.getToggleSortingHandler():void 0,children:[c,s&&(0,n.jsx)(eh,{direction:e.column.getIsSorted()})]})},e.id)})})},e.id))}),(0,n.jsx)("tbody",{children:ep.getRowModel().rows.map((e,t)=>{let r=e.getIsSelected();return(0,n.jsx)("tr",{className:"transition-colors duration-75 ".concat(k?"cursor-pointer":""),style:{background:r?"var(--color-accent-light)":t%2==0?"transparent":"var(--color-surface)"},onClick:()=>null==k?void 0:k(e.original,t),onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background=t%2==0?"transparent":"var(--color-surface)")},children:e.getVisibleCells().map((e,t)=>{let o=t===+!!d,l=U&&o,a="select"===e.column.id,s={borderColor:"var(--color-border)",...l?{position:"sticky",left:40*!!d,zIndex:20,background:r?"var(--color-accent-light)":"var(--color-bg)",boxShadow:V?"4px 0 8px -2px rgba(0,0,0,0.08)":"none"}:{},...a?{position:"sticky",left:0,zIndex:20,background:r?"var(--color-accent-light)":"var(--color-bg)",width:40}:{}};return(0,n.jsx)("td",{className:"px-3 py-2 border-b whitespace-nowrap",style:s,children:(0,ea.Kv)(e.column.columnDef.cell,e.getContext())},e.id)})},e.id)})})]})})}),!l&&r.length>0&&(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 text-xs flex-shrink-0",style:{borderTop:"1px solid var(--color-border)",color:"var(--color-text-muted)"},children:[(0,n.jsxs)("span",{children:[L?"Showing ".concat((L.page-1)*L.pageSize+1,"–").concat(Math.min(L.page*L.pageSize,L.totalCount)," of ").concat(L.totalCount," results"):"Showing ".concat(ep.getRowModel().rows.length," of ").concat(r.length," results"),eg>0&&" (".concat(eg," selected)")]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{children:"Rows per page"}),(0,n.jsx)("select",{value:L?L.pageSize:K.pageSize,onChange:e=>{let t=Number(e.target.value);L?L.onPageSizeChange(t):q(e=>({...e,pageSize:t,pageIndex:0}))},className:"px-1.5 py-0.5 rounded-md text-xs outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[20,50,100,250,500].map(e=>(0,n.jsx)("option",{value:e,children:e},e))}),(0,n.jsxs)("span",{children:["Page ",L?L.page:K.pageIndex+1," of ",ep.getPageCount()]}),(0,n.jsx)("div",{className:"flex gap-0.5",children:L?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(em,{onClick:()=>L.onPageChange(1),disabled:L.page<=1,label:"\xab"}),(0,n.jsx)(em,{onClick:()=>L.onPageChange(L.page-1),disabled:L.page<=1,label:"‹"}),(0,n.jsx)(em,{onClick:()=>L.onPageChange(L.page+1),disabled:L.page>=Math.ceil(L.totalCount/L.pageSize),label:"›"}),(0,n.jsx)(em,{onClick:()=>L.onPageChange(Math.ceil(L.totalCount/L.pageSize)),disabled:L.page>=Math.ceil(L.totalCount/L.pageSize),label:"\xbb"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(em,{onClick:()=>q(e=>({...e,pageIndex:0})),disabled:!ep.getCanPreviousPage(),label:"\xab"}),(0,n.jsx)(em,{onClick:()=>ep.previousPage(),disabled:!ep.getCanPreviousPage(),label:"‹"}),(0,n.jsx)(em,{onClick:()=>ep.nextPage(),disabled:!ep.getCanNextPage(),label:"›"}),(0,n.jsx)(em,{onClick:()=>q(e=>({...e,pageIndex:ep.getPageCount()-1})),disabled:!ep.getCanNextPage(),label:"\xbb"})]})})]})]})]})}function em(e){let{onClick:t,disabled:r,label:o}=e;return(0,n.jsx)("button",{type:"button",onClick:t,disabled:r,className:"w-6 h-6 rounded flex items-center justify-center text-xs disabled:opacity-30",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},dangerouslySetInnerHTML:{__html:o}})}function ef(e){let{row:t,actions:r}=e,[l,a]=(0,o.useState)(!1),s=(0,o.useRef)(null);return(0,o.useEffect)(()=>{function e(e){s.current&&!s.current.contains(e.target)&&a(!1)}if(l)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]),(0,n.jsxs)("div",{className:"relative",ref:s,children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),a(e=>!e)},className:"p-1 rounded-md",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"12",cy:"5",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"19",r:"1.5"})]})}),l&&(0,n.jsx)("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[140px] rounded-xl overflow-hidden py-1",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-lg)"},children:r.map((e,r)=>(0,n.jsxs)("button",{type:"button",onClick:r=>{var n;r.stopPropagation(),null==(n=e.onClick)||n.call(e,t),a(!1)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-left",style:{color:"destructive"===e.variant?"var(--color-error)":"var(--color-text)"},children:[e.icon,e.label]},r))})]})}function ev(e){let{columnCount:t}=e;return(0,n.jsx)("div",{className:"p-4 space-y-2",children:Array.from({length:12}).map((e,r)=>(0,n.jsx)("div",{className:"flex gap-3",children:Array.from({length:Math.min(t,6)}).map((e,t)=>(0,n.jsx)("div",{className:"h-8 rounded-lg animate-pulse flex-1",style:{background:"var(--color-surface-hover)",animationDelay:"".concat(50*t,"ms")}},t))},r))})}function eg(e){if(!e)return[];let t=e.trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]}function ey(e){let{relatedObjectName:t,value:r,multiple:l=!1,onChange:a,placeholder:s,variant:i="modal",autoFocus:c=!1}=e,[d,u]=(0,o.useState)(c),[x,h]=(0,o.useState)(""),[p,m]=(0,o.useState)([]),[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(()=>eg(r)),b=(0,o.useRef)(null),j=(0,o.useRef)(null),k=(0,o.useRef)(null);(0,o.useEffect)(()=>{y(eg(r))},[r]);let w=(0,o.useCallback)(async e=>{v(!0);try{let n=new URLSearchParams;e&&n.set("q",e);let o=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/options?").concat(n));if(o.ok){var r;let e=await o.json();m(null!=(r=e.options)?r:[])}}catch(e){}finally{v(!1)}},[t]);(0,o.useEffect)(()=>{d&&w(x)},[d]),(0,o.useEffect)(()=>{if(d)return k.current&&clearTimeout(k.current),k.current=setTimeout(()=>w(x),250),()=>{k.current&&clearTimeout(k.current)}},[x]),(0,o.useEffect)(()=>{d&&j.current&&j.current.focus()},[d]),(0,o.useEffect)(()=>{if(!d)return;let e=e=>{b.current&&!b.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let N=g.map(e=>{var t;let r=p.find(t=>t.id===e),n=null!=(t=null==r?void 0:r.label)?t:e;return{id:e,label:String(null!=n&&"object"==typeof n?JSON.stringify(n):null!=n?n:"")}}),C="inline"===i;return(0,n.jsxs)("div",{ref:b,className:"relative w-full",children:[(0,n.jsxs)("div",{onClick:()=>u(!d),className:"w-full flex items-center flex-wrap gap-1 cursor-pointer min-h-[1.5em] ".concat(C?"text-xs":"px-3 py-2 text-sm rounded-lg"),style:C?{}:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[N.length>0?N.map(e=>{let{id:t,label:r}=e;return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium",style:{background:"rgba(96, 165, 250, 0.1)",color:"#60a5fa",border:"1px solid rgba(96, 165, 250, 0.2)"},children:[(0,n.jsx)("span",{className:"truncate max-w-[160px]",children:String(null!=r?r:"")}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation();let r=g.filter(e=>e!==t);y(r),l?a(0===r.length?"":JSON.stringify(r)):a("")},className:"ml-0.5 hover:opacity-70",style:{color:"#60a5fa"},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]},t)}):(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:null!=s?s:"Select ".concat(t,"...")}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"ml-auto flex-shrink-0",style:{color:"var(--color-text-muted)",transform:d?"rotate(180deg)":void 0,transition:"transform 0.15s"},children:(0,n.jsx)("path",{d:"m6 9 6 6 6-6"})})]}),d&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full rounded-lg shadow-lg overflow-hidden",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",maxHeight:260},children:[(0,n.jsx)("div",{className:"p-2 border-b",style:{borderColor:"var(--color-border)"},children:(0,n.jsx)("input",{ref:j,type:"text",value:x,onChange:e=>h(e.target.value),placeholder:"Search ".concat(t,"..."),className:"w-full px-2.5 py-1.5 text-xs rounded-md outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},onKeyDown:e=>{"Escape"===e.key&&u(!1)}})}),(0,n.jsx)("div",{className:"overflow-y-auto",style:{maxHeight:200},children:f?(0,n.jsx)("div",{className:"px-3 py-4 text-center text-xs",style:{color:"var(--color-text-muted)"},children:"Loading..."}):0===p.length?(0,n.jsx)("div",{className:"px-3 py-4 text-center text-xs",style:{color:"var(--color-text-muted)"},children:x?"No matches found":"No entries"}):p.map(e=>{var t;let r=g.includes(e.id);return(0,n.jsxs)("button",{type:"button",onClick:()=>(e=>{if(l){let t=g.includes(e)?g.filter(t=>t!==e):[...g,e];y(t),a(0===t.length?"":JSON.stringify(t))}else y([e]),a(e),u(!1)})(e.id),className:"w-full text-left px-3 py-2 text-xs flex items-center gap-2 transition-colors",style:{background:r?"var(--color-accent-light, rgba(96, 165, 250, 0.08))":"transparent",color:"var(--color-text)"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--color-surface-hover, rgba(255,255,255,0.04))")},onMouseLeave:e=>{e.currentTarget.style.background=r?"var(--color-accent-light, rgba(96, 165, 250, 0.08))":"transparent"},children:[l&&(0,n.jsx)("span",{className:"w-3.5 h-3.5 rounded border flex items-center justify-center flex-shrink-0",style:{borderColor:r?"var(--color-accent)":"var(--color-border)",background:r?"var(--color-accent)":"transparent"},children:r&&(0,n.jsx)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})})}),!l&&r&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-accent)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})}),(0,n.jsx)("span",{className:"truncate",children:String(null!=e.label&&"object"==typeof e.label?JSON.stringify(e.label):null!=(t=e.label)?t:"")})]},e.id)})})]})]})}var eb=r(68840);let ej=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,ek=/^https?:\/\/\S+$/i,ew=/^\+?[0-9().\-\s]{7,}$/,eN=/^\d{4}-\d{2}-\d{2}$/,eC=/^\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}(?::?\d{2})?)?)?$/,eS=/^\d{1,2}\/\d{1,2}\/\d{2,4}$/,eM=/^([$\u20ac\u00a3\u00a5])\s*(-?\d[\d,]*(?:\.\d+)?)$/,eL=/^-?\d[\d,]*(?:\.\d+)?$/,eT=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","ico","tiff","tif"]),eD=new Set(["mp4","webm","mov","avi","mkv"]),eE=new Set(["mp3","wav","ogg","m4a","aac","flac"]),eR=new Set(["pdf"]),eW=new Set([...eT,...eD,...eE,...eR,"txt","md","json","yaml","yml","csv","sql","doc","docx","xls","xlsx","ppt","pptx","zip","tar","gz"]);function eI(e){var t,r,n,o;return null!=(o=null==(r=(null!=(n=null==(t=e.split("?")[0])?void 0:t.split("#")[0])?n:e).split(".").pop())?void 0:r.toLowerCase())?o:""}function eB(e){let t=eI(e);if(t){if(eT.has(t))return"image";if(eD.has(t))return"video";if(eE.has(t))return"audio";if(eR.has(t))return"pdf"}}function eF(e){return e.startsWith("/")||e.startsWith("~/")||/^[A-Za-z]:[\\/]/.test(e)}function eP(e){let t=(0,eb.lc)(e);if((null==t?void 0:t.kind)==="file")return t.path;let r=function(e){if(!e.startsWith("file://"))return null;try{let t=new URL(e);if("file:"!==t.protocol)return null;let r=decodeURIComponent(t.pathname);if(/^\/[A-Za-z]:\//.test(r))return r.slice(1);return r}catch(e){return null}}(e);if(r)return r;let n=e.trim();return!function(e){let t=e.trim();if(!t||t.includes("://")&&!t.startsWith("file://"))return!1;if(t.startsWith("./")||t.startsWith("../")||eF(t))return!0;let r=t.includes("/")||t.includes("\\"),n=eI(t);return r?n.length>0&&n.length<=8:eW.has(n)}(n)?null:n}function eA(e){let t=e.trim();if(!t)return null;if(t.startsWith("www."))return"https://".concat(t);if(!ek.test(t))return null;try{let e=new URL(t);if("http:"!==e.protocol&&"https:"!==e.protocol)return null;return e.toString()}catch(e){return null}}function e_(e){let t=e.trim();if(!ew.test(t)||t.replace(/\D/g,"").length<7)return null;let r=t.replace(/[^\d+]/g,"");return r?"tel:".concat(r):null}function ez(e){let t=e.replace(/,/g,"").trim();if(!t)return null;let r=Number(t);return Number.isFinite(r)?r:null}function eO(e){return new Intl.NumberFormat(void 0,{maximumFractionDigits:6}).format(e)}function eU(e,t){let r=function(e){switch(e){case"$":return"USD";case"€":return"EUR";case"\xa3":return"GBP";case"\xa5":return"JPY";default:return null}}(e);return r?new Intl.NumberFormat(void 0,{style:"currency",currency:r,maximumFractionDigits:2}).format(t):"".concat(e).concat(eO(t))}function eH(e){let t=function(e){let t,r=e.trim();if(eN.test(r)){let[e,t,n]=r.split("-").map(e=>Number(e)),o=new Date(e,(null!=t?t:1)-1,null!=n?n:1);return Number.isNaN(o.getTime())?null:o}if(!(eC.test(r)||eS.test(r)))return null;let n=new Date(((t=r).includes(" ")&&(t=t.replace(" ","T")),t=(t=(t=t.replace(/(\.\d{3})\d+(?=(?:Z|[+-]\d{2}(?::?\d{2})?)?$)/,"$1")).replace(/([+-]\d{2})$/,"$1:00")).replace(/([+-]\d{2})(\d{2})$/,"$1:$2")));return Number.isNaN(n.getTime())?null:n}(e);return t?{text:e.includes("T")||/\d{1,2}:\d{2}/.test(e)?new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t):new Intl.DateTimeFormat(void 0,{dateStyle:"medium"}).format(t),iso:t.toISOString()}:null}function eV(e){return e.startsWith("http://")||e.startsWith("https://")?e:eF(e)?"/api/workspace/browse-file?path=".concat(encodeURIComponent(e),"&raw=true"):"/api/workspace/raw-file?path=".concat(encodeURIComponent(e))}function eJ(e,t){let r=function(e){if(null==e)return"";if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return String(e);if("object"==typeof e)try{return JSON.stringify(e)}catch(e){}return""}(e);if(!r||0===r.trim().length)return{kind:"empty",raw:r,text:""};let n=(null!=t?t:"").trim().toLowerCase(),o=function(e,t){if("email"===t&&ej.test(e.trim())){let t=e.trim();return{kind:"link",raw:e,text:t,linkType:"email",href:"mailto:".concat(t)}}if("phone"===t){let t=e_(e);if(t)return{kind:"link",raw:e,text:e.trim(),linkType:"phone",href:t}}if("url"===t){let t=eA(e);if(t)return{kind:"link",raw:e,text:e.trim(),linkType:"url",href:t,mediaType:eB(t),embedUrl:t}}if("date"===t){let t=eH(e);if(t)return{kind:"date",raw:e,text:t.text,isoDate:t.iso}}if("number"===t){let t=e.trim().match(eM);if(t){var r,n;let o=ez(null!=(r=t[2])?r:"");if(null!=o)return{kind:"currency",raw:e,text:eU(null!=(n=t[1])?n:"$",o),numericValue:o}}let o=ez(e);if(null!=o)return{kind:"number",raw:e,text:eO(o),numericValue:o}}if("file"===t){let t=eP(e);if(t)return{kind:"link",raw:e,text:t,linkType:"file",href:(0,eb.bJ)(t),filePath:t,mediaType:eB(t),embedUrl:eV(t)}}return null}(r,n);return o||("richtext"===n||"relation"===n||"enum"===n||"user"===n?{kind:"text",raw:r,text:r}:function(e){let t=e.trim(),r=eP(t);if(r)return{kind:"link",raw:e,text:r,linkType:"file",href:(0,eb.bJ)(r),filePath:r,mediaType:eB(r),embedUrl:eV(r)};if(ej.test(t))return{kind:"link",raw:e,text:t,linkType:"email",href:"mailto:".concat(t)};let n=eA(t);if(n)return{kind:"link",raw:e,text:t,linkType:"url",href:n,mediaType:eB(n),embedUrl:n};let o=e_(t);if(o)return{kind:"link",raw:e,text:t,linkType:"phone",href:o};let l=eH(t);if(l)return{kind:"date",raw:e,text:l.text,isoDate:l.iso};let a=t.match(eM);if(a){var s,i;let t=ez(null!=(s=a[2])?s:"");if(null!=t)return{kind:"currency",raw:e,text:eU(null!=(i=a[1])?i:"$",t),numericValue:t}}if(eL.test(t)){let r=ez(t);if(null!=r)return{kind:"number",raw:e,text:eO(r),numericValue:r}}return{kind:"text",raw:e,text:e}}(r))}function eK(){return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"})}function eq(e){let{mediaType:t,url:r,label:o}=e;return"image"===t?(0,n.jsx)("div",{className:"mt-2 rounded-lg overflow-hidden border",style:{borderColor:"var(--color-border)"},children:(0,n.jsx)("img",{src:r,alt:o,className:"max-h-64 w-auto"})}):"video"===t?(0,n.jsx)("video",{src:r,controls:!0,className:"mt-2 w-full max-h-72 rounded-lg border",style:{borderColor:"var(--color-border)",background:"#000"}}):"audio"===t?(0,n.jsx)("audio",{src:r,controls:!0,className:"mt-2 w-full"}):(0,n.jsx)("iframe",{src:"".concat(r,"#toolbar=0&navpanes=0&scrollbar=1"),title:o,className:"mt-2 w-full h-72 rounded-lg border",style:{borderColor:"var(--color-border)",background:"white"}})}function eG(e){let{text:t,fieldType:r}=e,o=t.trim();if(!o)return(0,n.jsx)(n.Fragment,{children:t});let l=r&&"text"!==r&&"richtext"!==r?r:void 0,a=eJ(o,l);if("link"===a.kind&&a.href){if(!l&&"file"===a.linkType&&o.includes(" "))return(0,n.jsx)(n.Fragment,{children:a.text});let e="url"===a.linkType||"file"===a.linkType;return(0,n.jsx)("a",{href:a.href,...e?{target:"_blank",rel:"noopener noreferrer"}:{},className:"underline underline-offset-2",style:{color:"var(--color-accent)"},onClick:e=>e.stopPropagation(),children:a.text})}return"number"===a.kind||"currency"===a.kind?(0,n.jsx)("span",{className:"tabular-nums",children:a.text}):(0,n.jsx)(n.Fragment,{children:a.text})}function e$(e){let{value:t,fieldType:r,mode:l="table",className:a}=e,s=eJ(t,r),i="table"===l;if("empty"===s.kind)return(0,n.jsx)(eK,{});let c=s.text.replace(/\\r\\n/g,"\n").replace(/\\n/g,"\n").replace(/\\r/g,"\n");if(c.includes("\n")){let e=c.split("\n"),t=null!=a?a:i?"block max-w-[300px] line-clamp-3":"break-words";return(0,n.jsx)("span",{className:t,children:e.map((e,t)=>(0,n.jsxs)(o.Fragment,{children:[t>0&&(0,n.jsx)("br",{}),(0,n.jsx)(eG,{text:e,fieldType:r})]},t))})}let d=null!=a?a:i?"truncate block max-w-[300px]":"break-words";if("link"===s.kind&&s.href){let e="url"===s.linkType||"file"===s.linkType,t=!i&&!!s.embedUrl&&!!s.mediaType;return(0,n.jsxs)("div",{className:i?"truncate block max-w-[300px]":"w-full",children:[(0,n.jsx)("a",{href:s.href,...e?{target:"_blank",rel:"noopener noreferrer"}:{},className:"underline underline-offset-2 ".concat(i?"truncate block":""),style:{color:"var(--color-accent)"},onClick:e=>e.stopPropagation(),children:s.text}),t&&(0,n.jsx)(eq,{mediaType:s.mediaType,url:s.embedUrl,label:s.text})]})}return"number"===s.kind||"currency"===s.kind?(0,n.jsx)("span",{className:"tabular-nums ".concat(d),children:s.text}):(0,n.jsx)("span",{className:d,children:c})}function eZ(e){if(null==e)return[];if(Array.isArray(e))return e.map(String).filter(Boolean);let t=String(e).trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]}let eY=["created_at","Created","createdAt","created"],eQ=["updated_at","Updated","updatedAt","updated"];function eX(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):""}function e0(e){switch(e){case"number":return"number";case"date":return"date";case"email":return"email";case"phone":return"tel";case"url":return"url";default:return"text"}}function e1(e,t){for(let r of t){let t=e[r];if(null!=t&&""!==t)return t}}function e2(e){var t;let{value:r,enumValues:o,enumColors:l}=e,a=null!=(t=null==o?void 0:o.indexOf(r))?t:-1,s=a>=0&&l?l[a]:"#94a3b8";return(0,n.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium",style:{background:"".concat(s,"20"),color:s,border:"1px solid ".concat(s,"40")},children:r})}function e4(e){let{value:t}=e,r=!0===t||"true"===t||"1"===t||"yes"===t;return(0,n.jsx)("span",{style:{color:r?"var(--color-success)":"var(--color-text-muted)"},children:r?"Yes":"No"})}function e5(e){var t,r;let{value:o,members:l}=e,a=String(o),s=null==l?void 0:l.find(e=>e.id===a);return(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] font-medium flex-shrink-0",style:{background:"var(--color-accent)",color:"white"},children:(null!=(t=null==s?void 0:s.name)?t:a).charAt(0).toUpperCase()}),(0,n.jsx)("span",{className:"truncate",children:null!=(r=null==s?void 0:s.name)?r:a})]})}function e6(e){let{value:t,field:r,relationLabels:o,onNavigateObject:l,onNavigateEntry:a}=e,s=null==o?void 0:o[r.name],i=function(e){if(!e)return[];let t=e.trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]}(String(t));return 0===i.length?(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"}):(0,n.jsx)("span",{className:"flex items-center gap-1 flex-wrap",children:i.map(e=>{var t;return(0,n.jsx)("span",{onClick:t=>{if(r.related_object_name&&(a||l)){if(t.stopPropagation(),a)return void a(r.related_object_name,e);null==l||l(r.related_object_name)}},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium ".concat(r.related_object_name&&(a||l)?"cursor-pointer":""),style:{background:"var(--color-chip-document)",color:"var(--color-chip-document-text)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("span",{className:"truncate max-w-[180px]",children:null!=(t=null==s?void 0:s[e])?t:e})},e)})})}function e3(e){let{tag:t}=e,r=eJ(t),o="link"===r.kind&&r.href,l={background:"rgba(148, 163, 184, 0.12)",border:"1px solid var(--color-border)"};return o?(0,n.jsx)("a",{href:r.href,target:"url"===r.linkType||"file"===r.linkType?"_blank":void 0,rel:"url"===r.linkType||"file"===r.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium underline-offset-2 hover:underline",style:{...l,color:"var(--color-accent)"},children:r.text}):(0,n.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium",style:{...l,color:"var(--color-text-muted)"},children:t})}function e8(e){let{value:t}=e,r=eZ(t);return 0===r.length?(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"}):(0,n.jsxs)("span",{className:"flex items-center gap-1 flex-wrap",children:[r.slice(0,5).map(e=>(0,n.jsx)(e3,{tag:e},e)),r.length>5&&(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["+",r.length-5]})]})}function e7(e){let{value:t,onChange:r,autoFocus:l}=e,a=eZ(t),[s,i]=(0,o.useState)(""),c=(0,o.useRef)(null);(0,o.useEffect)(()=>{l&&c.current&&c.current.focus()},[l]);let d=e=>{let t=e.trim();!t||a.includes(t)||(r(JSON.stringify([...a,t])),i(""))},u=e=>{let t=a.filter(t=>t!==e);r(t.length>0?JSON.stringify(t):"")};return(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-wrap min-h-[1.5em]",children:[a.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-2 py-0.5 rounded-full text-xs font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[e,(0,n.jsx)("button",{type:"button",onClick:()=>u(e),className:"ml-0.5 hover:opacity-70",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]},e)),(0,n.jsx)("input",{ref:c,type:"text",value:s,onChange:e=>i(e.target.value),onKeyDown:e=>{("Enter"===e.key||","===e.key)&&s.trim()&&(e.preventDefault(),d(s)),"Backspace"===e.key&&!s&&a.length>0&&u(a[a.length-1])},onBlur:()=>{s.trim()&&d(s)},placeholder:0===a.length?"Type and press Enter...":"",className:"flex-1 min-w-[80px] text-xs outline-none bg-transparent",style:{color:"var(--color-text)"}})]})}function e9(e){let{links:t,sourceObjectName:r,onNavigateObject:o,onNavigateEntry:l}=e;if(!t||0===t.length)return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"});let a=t.slice(0,5),s=t.length-a.length;return(0,n.jsxs)("span",{className:"flex items-center gap-1 flex-wrap",children:[a.map(e=>(0,n.jsx)("span",{onClick:t=>{if(l||o){if(t.stopPropagation(),l)return void l(r,e.id);null==o||o(r)}},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium ".concat(l||o?"cursor-pointer":""),style:{background:"var(--color-chip-database)",color:"var(--color-chip-database-text)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("span",{className:"truncate max-w-[180px]",children:e.label})},e.id)),s>0&&(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["+",s]})]})}function te(e){let{value:t,entryId:r,fieldName:l,objectName:a,field:s,members:i,relationLabels:c,onNavigateObject:d,onNavigateEntry:u,onLocalValueChange:x,onSaved:h}=e,[p,m]=(0,o.useState)(!1),[f,v]=(0,o.useState)(eX(t)),g=(0,o.useRef)(null),y=(0,o.useRef)(null);(0,o.useEffect)(()=>{p||v(eX(t))},[t,p]),(0,o.useEffect)(()=>{p&&g.current&&g.current.focus()},[p]);let b=!["user"].includes(s.type),j="relation"===s.type&&!!s.related_object_name,k="tags"===s.type,w=(0,o.useCallback)(async e=>{null==x||x(e);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(a),"/entries/").concat(encodeURIComponent(r)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{[l]:e}})}),null==h||h()}catch(e){}},[a,r,l,x,h]),N=e=>{v(e),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>w(e),500)},C=()=>{y.current&&(clearTimeout(y.current),w(f)),m(!1)},S=e=>{"Enter"===e.key&&C(),"Escape"===e.key&&(m(!1),v(eX(t)))};if(!b)return"user"===s.type?(0,n.jsx)(e5,{value:t,members:i}):(0,n.jsx)("span",{className:"truncate block max-w-[300px]",children:eX(t)});if(p){let e;return j?(0,n.jsx)("div",{className:"-mx-3 -my-2 px-3 py-2",style:{background:"var(--color-bg)",boxShadow:"inset 0 0 0 2px var(--color-accent)"},children:(0,n.jsx)(ey,{relatedObjectName:s.related_object_name,value:eX(t),multiple:"many_to_many"===s.relationship_type,onChange:e=>{w(e),m(!1)},variant:"inline",autoFocus:!0})}):k?(0,n.jsx)("div",{className:"-mx-3 -my-2 px-3 py-2",style:{background:"var(--color-bg)",boxShadow:"inset 0 0 0 2px var(--color-accent)"},children:(0,n.jsx)(e7,{value:eX(t),onChange:e=>{w(e)},autoFocus:!0})}):(e="enum"===s.type&&s.enum_values?(0,n.jsxs)("select",{ref:g,value:f,onChange:e=>{N(e.target.value),m(!1)},onBlur:C,onKeyDown:S,className:"w-full text-xs outline-none bg-transparent",style:{color:"var(--color-text)"},children:[(0,n.jsx)("option",{value:"",children:"--"}),s.enum_values.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}):"boolean"===s.type?(0,n.jsxs)("select",{ref:g,value:f,onChange:e=>{N(e.target.value),m(!1)},onBlur:C,onKeyDown:S,className:"w-full text-xs outline-none bg-transparent",style:{color:"var(--color-text)"},children:[(0,n.jsx)("option",{value:"true",children:"Yes"}),(0,n.jsx)("option",{value:"false",children:"No"})]}):(0,n.jsx)("input",{ref:g,type:e0(s.type),value:f,onChange:e=>N(e.target.value),onBlur:C,onKeyDown:S,className:"w-full text-xs outline-none bg-transparent",style:{color:"var(--color-text)"}}),(0,n.jsx)("div",{className:"-mx-3 -my-2 px-3 py-2",style:{background:"var(--color-bg)",boxShadow:"inset 0 0 0 2px var(--color-accent)"},children:e}))}return j?(0,n.jsx)("div",{onDoubleClick:()=>m(!0),className:"cursor-cell min-h-[1.5em]",title:"Double-click to edit",children:(0,n.jsx)(e6,{value:t,field:s,relationLabels:c,onNavigateObject:d,onNavigateEntry:u})}):k?(0,n.jsx)("div",{onDoubleClick:()=>m(!0),className:"cursor-cell min-h-[1.5em]",title:"Double-click to edit",children:(0,n.jsx)(e8,{value:t})}):(0,n.jsx)("div",{onDoubleClick:()=>m(!0),className:"cursor-cell min-h-[1.5em]",title:"Double-click to edit",children:null==t||""===t?(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"}):"enum"===s.type?(0,n.jsx)(e2,{value:eX(t),enumValues:s.enum_values,enumColors:s.enum_colors}):"boolean"===s.type?(0,n.jsx)(e4,{value:t}):(0,n.jsx)(e$,{value:t,fieldType:s.type,mode:"table"})})}function tt(e){let{objectName:t,fields:r,entries:l,members:a,relationLabels:s,reverseRelations:i,onNavigateToObject:c,onNavigateToEntry:d,onEntryClick:u,onRefresh:x,columnVisibility:h,onColumnVisibilityChanged:p,serverPagination:m,onServerSearch:f}=e,[v,g]=(0,o.useState)({}),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(l);(0,o.useEffect)(()=>{k(l)},[l]);let w=(0,o.useCallback)((e,t,r)=>{k(n=>n.map(n=>{let o=n.entry_id;return String(null!=o&&"object"==typeof o?JSON.stringify(o):null!=o?o:"")!==e?n:{...n,[t]:r}}))},[]),N=(0,o.useMemo)(()=>i?i.filter(e=>Object.keys(e.entries).length>0):[],[i]),C=(0,o.useMemo)(()=>{let e=r.map((e,r)=>({id:e.id,accessorKey:e.name,meta:{label:e.name,fieldName:e.name},header:()=>(0,n.jsxs)("span",{className:"flex items-center gap-1",style:{color:"var(--color-text-muted)"},children:[e.name,"relation"===e.type&&e.related_object_name&&(0,n.jsxs)("span",{className:"text-[9px] font-normal normal-case tracking-normal opacity-60",children:["(",e.related_object_name,")"]})]}),cell:o=>{let l=o.row.original.entry_id,i=String(null!=l&&"object"==typeof l?JSON.stringify(l):null!=l?l:"");if(0===r&&u){let e=o.getValue(),t=null==e||""===e?"--":eX(e),r="--"===t;return(0,n.jsx)("span",{className:"font-semibold truncate block max-w-[300px] ".concat(r?"":"cursor-pointer hover:underline"),style:{color:r?"var(--color-text-muted)":"var(--color-accent)",opacity:r?.5:1},onClick:e=>{e.stopPropagation(),i&&!r&&u(i)},children:t})}return(0,n.jsx)(te,{value:o.getValue(),entryId:i,fieldName:e.name,objectName:t,field:e,members:a,relationLabels:s,onNavigateObject:c,onNavigateEntry:d,onLocalValueChange:t=>w(i,e.name,t),onSaved:x})},size:"richtext"===e.type?300:"relation"===e.type||"tags"===e.type?200:180,enableSorting:!0}));for(let t of(e.push({id:"created_at",accessorFn:e=>e1(e,eY),meta:{label:"Created",fieldName:"created_at"},header:()=>(0,n.jsx)("span",{className:"flex items-center gap-1",style:{color:"var(--color-text-muted)"},children:"Created"}),cell:e=>(0,n.jsx)(e$,{value:e.getValue(),fieldType:"date",mode:"table"}),size:190,enableSorting:!0}),e.push({id:"updated_at",accessorFn:e=>e1(e,eQ),meta:{label:"Updated",fieldName:"updated_at"},header:()=>(0,n.jsx)("span",{className:"flex items-center gap-1",style:{color:"var(--color-text-muted)"},children:"Updated"}),cell:e=>(0,n.jsx)(e$,{value:e.getValue(),fieldType:"date",mode:"table"}),size:190,enableSorting:!0}),N))e.push({id:"rev_".concat(t.sourceObjectName,"_").concat(t.fieldName),meta:{label:"".concat(t.sourceObjectName," (via ").concat(t.fieldName,")")},header:()=>(0,n.jsxs)("span",{className:"flex items-center gap-1.5",style:{color:"var(--color-text-muted)"},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.4},children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]}),(0,n.jsx)("span",{className:"capitalize",children:t.sourceObjectName}),(0,n.jsxs)("span",{className:"text-[9px] font-normal normal-case tracking-normal opacity-50",children:["via ",t.fieldName]})]}),cell:e=>{var r;let o=e.row.original.entry_id,l=String(null!=o&&"object"==typeof o?JSON.stringify(o):null!=o?o:""),a=null!=(r=t.entries[l])?r:[];return(0,n.jsx)(e9,{links:a,sourceObjectName:t.sourceObjectName,onNavigateObject:c,onNavigateEntry:d})},enableSorting:!1,size:200});return e},[r,N,t,a,s,c,d,x]),S=(0,o.useCallback)(()=>{b(!0)},[]),M=(0,o.useCallback)(async()=>{let e=Object.keys(v).filter(e=>v[e]).map(e=>{var t;return eX(null==(t=j[Number(e)])?void 0:t.entry_id)}).filter(Boolean);if(0!==e.length&&confirm("Delete ".concat(e.length," entries?")))try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/bulk-delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entryIds:e})}),g({}),null==x||x()}catch(e){}},[v,j,t,x]),L=(0,o.useCallback)(async e=>{let r=e.entry_id,n=String(null!=r&&"object"==typeof r?JSON.stringify(r):null!=r?r:"");if(n&&confirm("Delete this entry?"))try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(n)),{method:"DELETE"}),null==x||x()}catch(e){}},[t,x]),T=(0,o.useCallback)(e=>{let t=[];return u&&t.push({label:"View details",onClick:e=>{var t;let r=String(null!=(t=e.entry_id)?t:"");r&&u(r)},icon:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}),t.push({label:"Delete",variant:"destructive",onClick:L,icon:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})}),t},[u,L]),D=(0,o.useCallback)(async e=>{let n=new Set(r.map(e=>e.id)),o=e.filter(e=>n.has(e));try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/fields/reorder"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fieldOrder:o})})}catch(e){}},[t,r]),E=(0,n.jsxs)("button",{type:"button",onClick:()=>void M(),className:"flex items-center gap-1 px-2.5 py-1 rounded-lg text-xs font-medium",style:{background:"rgba(220, 38, 38, 0.08)",color:"var(--color-error)",border:"1px solid rgba(220, 38, 38, 0.2)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ep,{columns:C,data:j,enableSorting:!0,enableGlobalFilter:!0,enableRowSelection:!0,enableColumnReordering:!0,rowSelection:v,onRowSelectionChange:g,bulkActions:E,onColumnReorder:D,searchPlaceholder:"Search ".concat(t,"..."),onRefresh:x,onAdd:S,addButtonLabel:"+ Add",rowActions:T,stickyFirstColumn:!0,initialColumnVisibility:h,onColumnVisibilityChanged:p,serverPagination:m,onServerSearch:f}),y&&(0,n.jsx)(tr,{objectName:t,fields:r,members:a,onClose:()=>b(!1),onSaved:x})]})}function tr(e){let{objectName:t,fields:r,members:l,onClose:a,onSaved:s}=e,[i,c]=(0,o.useState)({}),[d,u]=(0,o.useState)(!1),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&a()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a]);let h=(e,t)=>{c(r=>({...r,[e]:t}))},p=async()=>{u(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:i})})).ok&&(null==s||s(),a())}catch(e){}finally{u(!1)}};return(0,n.jsx)("div",{ref:x,onClick:e=>{e.target===x.current&&a()},className:"fixed inset-0 z-50 flex items-start justify-center",style:{background:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)"},children:(0,n.jsxs)("div",{className:"relative mt-12 mb-12 w-full max-w-lg rounded-2xl overflow-hidden shadow-2xl flex flex-col",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",maxHeight:"calc(100vh - 6rem)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("h2",{className:"text-lg font-semibold capitalize",style:{color:"var(--color-text)"},children:["Add ",t]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]}),(0,n.jsx)("form",{onSubmit:e=>{e.preventDefault(),p()},className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:r.map(e=>{var t,r,o,a,s,c,d;let u="relation"===e.type,x="user"===e.type;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"block text-xs font-medium uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:[e.name,u&&e.related_object_name&&(0,n.jsxs)("span",{className:"normal-case tracking-normal font-normal opacity-60 ml-1",children:["(",e.related_object_name,")"]})]}),"tags"===e.type?(0,n.jsx)("div",{className:"w-full px-3 py-2 text-sm rounded-lg",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:(0,n.jsx)(e7,{value:null!=(t=i[e.name])?t:"",onChange:t=>h(e.name,t)})}):"enum"===e.type&&e.enum_values?(0,n.jsxs)("select",{value:null!=(r=i[e.name])?r:"",onChange:t=>h(e.name,t.target.value),className:"w-full px-3 py-2 text-sm rounded-lg outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("option",{value:"",children:"-- Select --"}),e.enum_values.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}):"boolean"===e.type?(0,n.jsxs)("select",{value:null!=(o=i[e.name])?o:"",onChange:t=>h(e.name,t.target.value),className:"w-full px-3 py-2 text-sm rounded-lg outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("option",{value:"",children:"-- Select --"}),(0,n.jsx)("option",{value:"true",children:"Yes"}),(0,n.jsx)("option",{value:"false",children:"No"})]}):"richtext"===e.type?(0,n.jsx)("textarea",{value:null!=(a=i[e.name])?a:"",onChange:t=>h(e.name,t.target.value),rows:3,className:"w-full px-3 py-2 text-sm rounded-lg outline-none resize-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},placeholder:e.name}):u&&e.related_object_name?(0,n.jsx)(ey,{relatedObjectName:e.related_object_name,value:null!=(s=i[e.name])?s:"",multiple:"many_to_many"===e.relationship_type,onChange:t=>h(e.name,t),placeholder:"Select ".concat(e.related_object_name,"...")}):x?(0,n.jsxs)("select",{value:null!=(c=i[e.name])?c:"",onChange:t=>h(e.name,t.target.value),className:"w-full px-3 py-2 text-sm rounded-lg outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("option",{value:"",children:"-- Select member --"}),null==l?void 0:l.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]}):(0,n.jsx)("input",{type:e0(e.type),value:null!=(d=i[e.name])?d:"",onChange:t=>h(e.name,t.target.value),className:"w-full px-3 py-2 text-sm rounded-lg outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},placeholder:e.name})]},e.id)})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-4 py-2 text-sm rounded-lg",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>void p(),disabled:d,className:"px-4 py-2 text-sm font-medium rounded-lg",style:{background:"var(--color-accent)",color:"white",opacity:d?.7:1},children:d?"Saving...":"Save"})]})]})})}function tn(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):""}function to(e){let{entry:t,fields:r,members:o,relationLabels:l,onEntryClick:s}=e,i=tn(t.entry_id)||"",{attributes:c,listeners:d,setNodeRef:u,isDragging:x}=(0,a.PM)({id:i,data:{entry:t}});return(0,n.jsx)("div",{ref:u,...d,...c,onClick:e=>{!x&&s&&(e.stopPropagation(),s(i))},className:"rounded-lg p-3 mb-2 transition-all duration-100 cursor-grab active:cursor-grabbing select-none",style:{background:"var(--color-surface)",border:"1px solid ".concat(x?"var(--color-accent)":"var(--color-border)"),opacity:x?.4:1,transform:x?"scale(1.02)":void 0},children:(0,n.jsx)(tl,{entry:t,fields:r,members:o,relationLabels:l})})}function tl(e){let{entry:t,fields:r,members:o,relationLabels:l}=e,a=function(e,t){var r;let n=t.find(e=>e.name.toLowerCase().includes("name")||e.name.toLowerCase().includes("title"));return n?tn(e[n.name])||"Untitled":tn(e[null==(r=t[0])?void 0:r.name])||"Untitled"}(t,r),s=r.filter(e=>"richtext"!==e.type&&null!==t[e.name]&&void 0!==t[e.name]&&""!==t[e.name]).slice(0,4),i=r.find(e=>e.name.toLowerCase().includes("name")||e.name.toLowerCase().includes("title"));return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"text-sm font-medium mb-1.5 truncate",style:{color:"var(--color-text)"},children:a}),(0,n.jsx)("div",{className:"space-y-1",children:s.filter(e=>e!==i).slice(0,3).map(e=>{let r=t[e.name];if(!r)return null;let a=tn(r);if("user"===e.type){let e=null==o?void 0:o.find(e=>e.id===a);e&&(a=e.name)}else if("relation"===e.type){let t=null==l?void 0:l[e.name];a=(function(e){if(!e)return[];let t=e.trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]})(a).map(e=>{var r;return null!=(r=null==t?void 0:t[e])?r:e}).join(", ")}let s="tags"===e.type?eZ(r):[];return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs",children:[(0,n.jsxs)("span",{style:{color:"var(--color-text-muted)"},children:[e.name,":"]}),"enum"===e.type?(0,n.jsx)(ta,{value:tn(r),enumValues:e.enum_values,enumColors:e.enum_colors}):"tags"===e.type?(0,n.jsxs)("span",{className:"flex items-center gap-0.5 flex-wrap",children:[s.slice(0,3).map(e=>{let t=eJ(e);return"link"===t.kind&&t.href?(0,n.jsx)("a",{href:t.href,target:"url"===t.linkType||"file"===t.linkType?"_blank":void 0,rel:"url"===t.linkType||"file"===t.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium hover:underline underline-offset-2",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)"},children:t.text},e):(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)"},children:e},e)}),s.length>3&&(0,n.jsxs)("span",{style:{color:"var(--color-text-muted)",opacity:.6},children:["+",s.length-3]})]}):"relation"===e.type?(0,n.jsxs)("span",{className:"truncate inline-flex items-center gap-0.5",style:{color:"#60a5fa"},children:[(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.5},children:[(0,n.jsx)("path",{d:"M7 7h10v10"}),(0,n.jsx)("path",{d:"M7 17 17 7"})]}),a]}):(0,n.jsx)("span",{className:"whitespace-pre-line line-clamp-2",style:{color:"var(--color-text)"},children:a})]},e.id)})})]})}function ta(e){var t;let{value:r,enumValues:o,enumColors:l}=e,a=null!=(t=null==o?void 0:o.indexOf(r))?t:-1,s=a>=0&&l?l[a]:"#94a3b8";return(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:"".concat(s,"20"),color:s},children:r})}function ts(e){let{columnName:t,color:r,items:l,cardFields:s,members:i,relationLabels:c,onEntryClick:d,isOver:u,groupFieldId:x,objectName:h,onRefresh:p}=e,{setNodeRef:m}=(0,a.zM)({id:"column:".concat(t)}),[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(t),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);(0,o.useEffect)(()=>{f&&k.current&&(k.current.focus(),k.current.select())},[f]);let w=(0,o.useCallback)(async()=>{let e=g.trim();if(!e||e===t||!x){v(!1),y(t);return}j(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(h),"/fields/").concat(encodeURIComponent(x),"/enum-rename"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldValue:t,newValue:e})})).ok?null==p||p():y(t)}catch(e){y(t)}finally{j(!1),v(!1)}},[g,t,x,h,p]);return(0,n.jsxs)("div",{ref:m,className:"flex-shrink-0 flex flex-col rounded-xl transition-colors duration-150",style:{width:"280px",background:u?"var(--color-surface)":"var(--color-bg)",border:"1px solid ".concat(u?"var(--color-accent)":"var(--color-border)")},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:r}}),f?(0,n.jsx)("input",{ref:k,value:g,onChange:e=>y(e.target.value),onBlur:w,onKeyDown:e=>{"Enter"===e.key&&w(),"Escape"===e.key&&(y(t),v(!1))},disabled:b,className:"text-sm font-medium flex-1 bg-transparent outline-none rounded px-1 -mx-1",style:{color:"var(--color-text)",border:"1px solid var(--color-accent)"}}):(0,n.jsx)("span",{className:"text-sm font-medium flex-1 cursor-text rounded px-1 -mx-1 hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)"},onDoubleClick:()=>{x&&(y(t),v(!0))},title:x?"Double-click to rename":void 0,children:t}),(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:l.length})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2",style:{minHeight:"80px"},children:0===l.length?(0,n.jsx)("div",{className:"flex items-center justify-center py-8 rounded-lg border border-dashed text-xs transition-colors",style:{borderColor:u?"var(--color-accent)":"var(--color-border)",color:u?"var(--color-accent)":"var(--color-text-muted)"},children:u?"Drop here":"No entries"}):l.map((e,t)=>(0,n.jsx)(to,{entry:e,fields:s,members:i,relationLabels:c,onEntryClick:d},tn(e.entry_id)||String(t)))})]})}function ti(e){var t;let{objectName:r,fields:l,entries:s,statuses:i,members:c,relationLabels:d,onEntryClick:u,onRefresh:x}=e,[h,p]=(0,o.useState)(null),[m,f]=(0,o.useState)(null),[v,g]=(0,o.useState)(s);(0,o.useEffect)(()=>{g(s)},[s]);let y=(0,a.FR)((0,a.MS)(a.AN,{activationConstraint:{distance:5}})),b=(0,o.useMemo)(()=>{var e;let t=l.find(e=>"enum"===e.type&&e.name.toLowerCase().includes("status"));return t||(null!=(e=l.find(e=>"enum"===e.type))?e:null)},[l]),j=(0,o.useMemo)(()=>{if(i.length>0)return i.map(e=>{var t;return{name:e.name,color:null!=(t=e.color)?t:"#94a3b8"}});if(null==b?void 0:b.enum_values)return b.enum_values.map((e,t)=>{var r,n;return{name:e,color:null!=(n=null==(r=b.enum_colors)?void 0:r[t])?n:"#94a3b8"}});let e=new Set;for(let t of v){let r=b?t[b.name]:void 0;r&&e.add(tn(r))}return Array.from(e).map(e=>({name:e,color:"#94a3b8"}))},[i,b,v]),k=(0,o.useMemo)(()=>{let e={};for(let t of j)e[t.name]=[];for(let t of(e._ungrouped=[],v)){let r=b?tn(t[b.name]):"";e[r]?e[r].push(t):e._ungrouped.push(t)}return e},[j,v,b]),w=l.filter(e=>e!==b),N=(0,o.useMemo)(()=>{var e;return h&&null!=(e=v.find(e=>String(e.entry_id)===h))?e:null},[h,v]),C=(0,o.useCallback)(e=>{p(String(e.active.id))},[]),S=(0,o.useCallback)(e=>{var t;let r=(null==(t=e.over)?void 0:t.id)?String(e.over.id):null;(null==r?void 0:r.startsWith("column:"))?f(r.replace("column:","")):f(null)},[]),M=(0,o.useCallback)(async e=>{p(null),f(null);let{active:t,over:n}=e;if(!n||!b)return;let o=String(n.id);if(!o.startsWith("column:"))return;let l=o.replace("column:",""),a=String(t.id),s=v.find(e=>String(e.entry_id)===a);if(!s)return;let i=tn(s[b.name]);if(i!==l){g(e=>e.map(e=>String(e.entry_id)===a?{...e,[b.name]:l}:e));try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(r),"/entries/").concat(encodeURIComponent(a)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{[b.name]:l}})})).ok?null==x||x():g(e=>e.map(e=>String(e.entry_id)===a?{...e,[b.name]:i}:e))}catch(e){g(e=>e.map(e=>String(e.entry_id)===a?{...e,[b.name]:i}:e))}}},[b,v,r,x]);return b?(0,n.jsxs)(a.Mp,{sensors:y,collisionDetection:a.y$,onDragStart:C,onDragOver:S,onDragEnd:M,children:[(0,n.jsxs)("div",{className:"flex gap-4 overflow-x-auto pb-4 px-1",style:{minHeight:"400px"},children:[j.map(e=>{var t;return(0,n.jsx)(ts,{columnName:e.name,color:e.color,items:null!=(t=k[e.name])?t:[],cardFields:w,members:c,relationLabels:d,onEntryClick:u,isOver:m===e.name,groupFieldId:b.id,objectName:r,onRefresh:x},e.name)}),(null==(t=k._ungrouped)?void 0:t.length)>0&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex flex-col rounded-xl",style:{width:"280px",background:"var(--color-bg)",border:"1px dashed var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text-muted)"},children:"Ungrouped"}),(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:k._ungrouped.length})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2",children:k._ungrouped.map((e,t)=>(0,n.jsx)(to,{entry:e,fields:w,members:c,relationLabels:d,onEntryClick:u},tn(e.entry_id)||String(t)))})]})]}),(0,n.jsx)(a.Hd,{dropAnimation:null,children:N?(0,n.jsx)("div",{className:"rounded-lg p-3 shadow-xl",style:{width:"260px",background:"var(--color-surface)",border:"1px solid var(--color-accent)",transform:"rotate(2deg)"},children:(0,n.jsx)(tl,{entry:N,fields:w,members:c,relationLabels:d})}):null})]}):(0,n.jsx)("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:(0,n.jsxs)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:["No enum field found for kanban grouping in"," ",(0,n.jsx)("span",{className:"font-medium",style:{color:"var(--color-text)"},children:r})]})})}var tc=r(70739),td=r(30489),tu=r(75885),tx=r(65316),th=r(1059),tp=r(38804),tm=r(45609),tf=r(98540),tv=r(14716),tg=r(92423),ty=r(3904),tb=r(67977),tj=r(39682),tk=r(99509),tw=r(89748),tN=r(25277),tC=r(67697),tS=r(77894),tM=r(74575),tL=r(76149),tT=r(49054),tD=r(67034),tE=r(12904),tR=r(84373),tW=r(65440),tI=r(75096);function tB(e){return null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):"object"==typeof e?JSON.stringify(e):""}function tF(e){return(0,td.GP)(e,"yyyy-MM-dd")}function tP(e){return e.toISOString()}function tA(e,t,r){switch(t){case"day":return 1===r?(0,tu.f)(e,1):(0,tx.e)(e,1);case"week":return 1===r?(0,th.J)(e,1):(0,tp.k)(e,1);case"month":return 1===r?(0,tm.P)(e,1):(0,tf.a)(e,1);case"year":return 1===r?(0,tv.e)(e,1):(0,tg.d)(e,1)}}function t_(e){var t;let{event:r,compact:o,onClick:l,draggable:a,onDragStart:s}=e,i=null!=(t=r.color)?t:"var(--color-accent)";return(0,n.jsxs)("button",{type:"button",draggable:a,onDragStart:s,onClick:e=>{e.stopPropagation(),null==l||l()},className:"text-left rounded px-1.5 truncate cursor-pointer transition-opacity hover:opacity-80 ".concat(o?"text-[10px] py-0":"text-[11px] py-0.5"),style:{backgroundColor:i,color:"#fff",border:"none",width:"100%",lineHeight:o?"16px":"18px"},title:r.title,children:[!o&&(0,n.jsx)("span",{className:"opacity-70 mr-1",children:(0,td.GP)(r.date,"HH:mm")}),r.title||"Untitled"]})}function tz(e){let{date:t,events:r,onEntryClick:l,onEntryDateChange:a}=e,[s,i]=(0,o.useState)(null),c=(0,o.useRef)(null),d=(0,tj.w)(t),u=(0,tk.p)(t),x=(0,ty.k)(d,{weekStartsOn:1}),h=(0,tb.$)(u,{weekStartsOn:1}),p=(0,tw.k)({start:x,end:h}),m=(0,o.useMemo)(()=>{let e=new Map;for(let t of r){let r=(0,td.GP)(t.date,"yyyy-MM-dd");if(e.has(r)||e.set(r,[]),e.get(r).push(t),t.endDate&&!(0,tN.r)(t.date,t.endDate))for(let r of(0,tw.k)({start:(0,tu.f)(t.date,1),end:t.endDate})){let n=(0,td.GP)(r,"yyyy-MM-dd");e.has(n)||e.set(n,[]),e.get(n).push(t)}}return e},[r]),f=(0,o.useCallback)(e=>{c.current=e},[]),v=(0,o.useCallback)((e,t)=>{e.preventDefault(),i(t)},[]),g=(0,o.useCallback)((e,t)=>{e.preventDefault(),i(null);let r=c.current;if(!r||!a||(0,tN.r)(r.date,t))return;let n=(0,tC.o)((0,tS.o)(t),(0,tS.o)(r.date)),o=(0,tM.z)(r.date,n),l={entryId:r.id,newDate:tF(o)};r.endDate&&(l.newEndDate=tF((0,tM.z)(r.endDate,n))),a(l),c.current=null},[a]),y=(0,o.useCallback)(()=>i(null),[]);return(0,n.jsxs)("div",{className:"w-full",children:[(0,n.jsx)("div",{className:"grid grid-cols-7 border-b",style:{borderColor:"var(--color-border)"},children:["Mon","Tue","Wed","Thu","Fri","Sat","Sun"].map(e=>(0,n.jsx)("div",{className:"text-center text-[11px] font-medium py-2",style:{color:"var(--color-text-muted)"},children:e},e))}),(0,n.jsx)("div",{className:"grid grid-cols-7",children:p.map(e=>{var r;let o=(0,td.GP)(e,"yyyy-MM-dd"),i=null!=(r=m.get(o))?r:[],c=(0,tL.t)(e,t),d=(0,tT.c)(e),u=s===o;return(0,n.jsxs)("div",{className:"min-h-[100px] border-b border-r p-1 transition-colors",style:{borderColor:"var(--color-border)",opacity:c?1:.4,background:u?"var(--color-accent-light, rgba(99,102,241,0.12))":d?"var(--color-surface-hover)":void 0},onDragOver:e=>v(e,o),onDragLeave:y,onDrop:t=>g(t,e),children:[(0,n.jsx)("div",{className:"text-[11px] mb-0.5 ".concat(d?"font-bold":""),style:{color:d?"var(--color-accent)":"var(--color-text-muted)"},children:(0,td.GP)(e,"d")}),(0,n.jsxs)("div",{className:"flex flex-col gap-0.5",children:[i.slice(0,3).map(e=>(0,n.jsx)(t_,{event:e,compact:!0,onClick:()=>null==l?void 0:l(e.id),draggable:!!a,onDragStart:()=>f(e)},e.id)),i.length>3&&(0,n.jsxs)("span",{className:"text-[10px] pl-1",style:{color:"var(--color-text-muted)"},children:["+",i.length-3," more"]})]})]},o)})})]})}function tO(e){var t;let{event:r,hourHeight:l,onEntryClick:a,onEntryDateChange:s}=e,i=(0,o.useRef)(null),[c,d]=(0,o.useState)(null),u=(0,o.useRef)({y:0,startMinute:0,duration:0}),x=(0,tD.O)(r.date)/60*l,h=r.endDate?Math.max((0,tC.o)(r.endDate,r.date),15):30,p=h/60*l,[m,f]=(0,o.useState)(0),[v,g]=(0,o.useState)(0),y=(0,o.useCallback)(e=>{s&&(e.preventDefault(),e.stopPropagation(),d("move"),u.current={y:e.clientY,startMinute:60*(0,tE.q)(r.date)+(0,tD.O)(r.date),duration:h},e.target.setPointerCapture(e.pointerId))},[s,r.date,h]),b=(0,o.useCallback)(e=>{s&&(e.preventDefault(),e.stopPropagation(),d("resize"),u.current={y:e.clientY,startMinute:0,duration:h},e.target.setPointerCapture(e.pointerId))},[s,h]),j=(0,o.useCallback)(e=>{if(!c)return;let t=e.clientY-u.current.y;"move"===c?f(t):g(t)},[c]),k=(0,o.useCallback)(e=>{if(!c||!s)return;let t=15*Math.round((e.clientY-u.current.y)/l*60/15);if("move"===c&&0!==t){let e=(0,tM.z)(r.date,t),n={entryId:r.id,newDate:tP(e)};r.endDate&&(n.newEndDate=tP((0,tM.z)(r.endDate,t))),s(n)}else if("resize"===c&&0!==t){var n;let e=(0,tM.z)(null!=(n=r.endDate)?n:(0,tM.z)(r.date,h),t);e>r.date&&s({entryId:r.id,newDate:tP(r.date),newEndDate:tP(e)})}d(null),f(0),g(0)},[c,s,r,l,h]),w=x+("move"===c?m:0),N=Math.max(p+("resize"===c?v:0),15);return(0,n.jsxs)("div",{ref:i,className:"absolute left-0.5 right-0.5 rounded px-1 text-[10px] truncate select-none",style:{top:w,height:Math.min(N,6*l),backgroundColor:null!=(t=r.color)?t:"var(--color-accent)",color:"#fff",lineHeight:"16px",zIndex:c?20:2,cursor:s?"move"===c?"grabbing":"grab":"pointer",opacity:c?.85:1,transition:c?"none":"top 0.15s, height 0.15s"},onPointerDown:y,onPointerMove:j,onPointerUp:k,onClick:e=>{c||(e.stopPropagation(),null==a||a(r.id))},title:r.title,children:[r.title||"Untitled",s&&(0,n.jsx)("div",{className:"absolute bottom-0 left-0 right-0 h-2 cursor-ns-resize",style:{borderRadius:"0 0 4px 4px"},onPointerDown:b})]})}function tU(e){let{date:t,events:r,onEntryClick:l,onEntryDateChange:a}=e,s=(0,ty.k)(t,{weekStartsOn:1}),i=(0,tw.k)({start:s,end:(0,tu.f)(s,6)}),c=Array.from({length:24},(e,t)=>t+0),d=(0,o.useMemo)(()=>{let e=new Map;for(let t of r){let r=(0,td.GP)(t.date,"yyyy-MM-dd");e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[r]);return(0,n.jsx)("div",{className:"w-full overflow-auto",style:{maxHeight:"calc(100vh - 280px)"},children:(0,n.jsxs)("div",{className:"grid",style:{gridTemplateColumns:"50px repeat(7, 1fr)"},children:[(0,n.jsx)("div",{className:"sticky top-0 z-10",style:{background:"var(--color-bg)"}}),i.map(e=>(0,n.jsxs)("div",{className:"sticky top-0 z-10 text-center py-2 border-b border-l text-[12px] font-medium",style:{borderColor:"var(--color-border)",background:"var(--color-bg)",color:(0,tT.c)(e)?"var(--color-accent)":"var(--color-text)"},children:[(0,n.jsx)("div",{children:(0,td.GP)(e,"EEE")}),(0,n.jsx)("div",{className:"text-lg ".concat((0,tT.c)(e)?"font-bold":""),children:(0,td.GP)(e,"d")})]},e.toISOString())),c.map(e=>(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"text-[10px] text-right pr-2 pt-0.5",style:{color:"var(--color-text-muted)",height:60},children:(0,td.GP)(new Date(2e3,0,1,e),"ha")},"label-".concat(e)),i.map(t=>{var r;let o=(0,td.GP)(t,"yyyy-MM-dd"),s=(null!=(r=d.get(o))?r:[]).filter(t=>(0,tE.q)(t.date)===e);return(0,n.jsx)("div",{className:"border-b border-l relative",style:{borderColor:"var(--color-border)",height:60},children:s.map(e=>(0,n.jsx)(tO,{event:e,hourHeight:60,onEntryClick:l,onEntryDateChange:a},e.id))},"".concat(o,"-").concat(e))})]}))]})})}function tH(e){let{date:t,events:r,onEntryClick:l,onEntryDateChange:a}=e,s=Array.from({length:24},(e,t)=>t+0),i=(0,o.useMemo)(()=>r.filter(e=>(0,tN.r)(e.date,t)),[r,t]);return(0,n.jsx)("div",{className:"w-full overflow-auto",style:{maxHeight:"calc(100vh - 280px)"},children:(0,n.jsx)("div",{className:"grid",style:{gridTemplateColumns:"60px 1fr"},children:s.map(e=>{let t=i.filter(t=>(0,tE.q)(t.date)===e);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"text-[11px] text-right pr-3 pt-0.5",style:{color:"var(--color-text-muted)",height:60},children:(0,td.GP)(new Date(2e3,0,1,e),"h:mm a")},"label-".concat(e)),(0,n.jsx)("div",{className:"border-b border-l relative",style:{borderColor:"var(--color-border)",height:60},children:t.map(e=>(0,n.jsx)(tO,{event:e,hourHeight:60,onEntryClick:l,onEntryDateChange:a},e.id))},"cell-".concat(e))]})})})})}function tV(e){let{date:t,events:r}=e,l=(0,tR.D)(t),a=(0,tW.Q)(t),s=(0,tI.i)({start:l,end:a}),i=(0,o.useMemo)(()=>{let e=new Map;for(let t of r){let r=t.date.getMonth();e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[r]);return(0,n.jsx)("div",{className:"grid grid-cols-3 md:grid-cols-4 gap-4 p-2",children:s.map(e=>{var t;let r=(0,tj.w)(e),o=(0,tk.p)(e),l=(0,ty.k)(r,{weekStartsOn:1}),a=(0,tb.$)(o,{weekStartsOn:1}),s=(0,tw.k)({start:l,end:a}),c=null!=(t=i.get(e.getMonth()))?t:[];return(0,n.jsxs)("div",{className:"rounded-lg border p-2",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"text-[12px] font-semibold mb-1",style:{color:"var(--color-text)"},children:(0,td.GP)(e,"MMMM")}),(0,n.jsxs)("div",{className:"grid grid-cols-7 gap-px",children:[["M","T","W","T","F","S","S"].map((e,t)=>(0,n.jsx)("div",{className:"text-[9px] text-center",style:{color:"var(--color-text-muted)"},children:e},t)),s.map(t=>{let r=(0,tL.t)(t,e),o=(0,tT.c)(t),l=c.some(e=>(0,tN.r)(e.date,t));return(0,n.jsxs)("div",{className:"text-[9px] text-center py-0.5 relative",style:{color:r?o?"var(--color-accent)":"var(--color-text)":"transparent",fontWeight:o?700:400},children:[(0,td.GP)(t,"d"),l&&r&&(0,n.jsx)("div",{className:"absolute bottom-0 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full",style:{backgroundColor:"var(--color-accent)"}})]},t.toISOString())})]}),c.length>0&&(0,n.jsxs)("div",{className:"mt-1 text-[10px]",style:{color:"var(--color-text-muted)"},children:[c.length," event",1!==c.length?"s":""]})]},e.toISOString())})})}function tJ(e){let{reason:t}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 gap-2",children:[(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"4",rx:"2"}),(0,n.jsx)("path",{d:"M16 2v4"}),(0,n.jsx)("path",{d:"M8 2v4"}),(0,n.jsx)("path",{d:"M3 10h18"})]}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"no-date-field"===t?"No date field configured for calendar view. Open view settings to select one.":"No events to display in this range."})]})}function tK(e){let{objectName:t,fields:r,entries:l,dateField:a,endDateField:s,mode:i,onModeChange:c,members:d,onEntryClick:u,onEntryDateChange:x}=e,[h,p]=(0,o.useState)(()=>new Date),m=(0,o.useMemo)(()=>(function(e,t,r,n){let o=[];for(let a of e){let e=tB(a[r]);if(e)try{var l;let r,s=(0,tc.H)(e);if(Number.isNaN(s.getTime()))continue;if(n){let e=tB(a[n]);if(e){let t=(0,tc.H)(e);Number.isNaN(t.getTime())||(r=t)}}o.push({id:tB(null!=(l=a.entry_id)?l:a.id),title:function(e,t){var r;let n=null!=(r=t.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?r:t.find(e=>"text"===e.type);return n?tB(e[n.name]):tB(e.id)}(a,t),date:s,endDate:r,entry:a,color:function(e,t){var r,n;let o=t.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_colors)?void 0:t.length)});if(!o)return;let l=tB(e[o.name]),a=null!=(n=null==(r=o.enum_values)?void 0:r.indexOf(l))?n:-1;return a>=0?o.enum_colors[a]:void 0}(a,t)})}catch(e){}}return o})(l,r,a,s),[l,r,a,s]),f=(0,o.useCallback)(()=>p(e=>tA(e,i,-1)),[i]),v=(0,o.useCallback)(()=>p(e=>tA(e,i,1)),[i]),g=(0,o.useCallback)(()=>p(new Date),[]);return a?(0,n.jsxs)("div",{className:"w-full",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3 px-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:f,className:"p-1.5 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})})}),(0,n.jsx)("button",{type:"button",onClick:v,className:"p-1.5 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}),(0,n.jsx)("button",{type:"button",onClick:g,className:"text-[12px] px-2.5 py-1 rounded-md border hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)",borderColor:"var(--color-border)"},children:"Today"}),(0,n.jsx)("h3",{className:"text-sm font-semibold ml-2",style:{color:"var(--color-text)"},children:function(e,t){switch(t){case"day":return(0,td.GP)(e,"EEEE, MMMM d, yyyy");case"week":{let t=(0,ty.k)(e,{weekStartsOn:1}),r=(0,tb.$)(e,{weekStartsOn:1});return"".concat((0,td.GP)(t,"MMM d")," - ").concat((0,td.GP)(r,"MMM d, yyyy"))}case"month":return(0,td.GP)(e,"MMMM yyyy");case"year":return(0,td.GP)(e,"yyyy")}}(h,i)})]}),(0,n.jsx)("div",{className:"flex rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)"},children:["day","week","month","year"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>c(e),className:"text-[11px] px-3 py-1 capitalize transition-colors",style:{background:e===i?"var(--color-accent)":"var(--color-surface)",color:e===i?"#fff":"var(--color-text-muted)",borderRight:"year"!==e?"1px solid var(--color-border)":void 0},children:e},e))})]}),(0,n.jsxs)("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)",background:"var(--color-bg)"},children:["month"===i&&(0,n.jsx)(tz,{date:h,events:m,onEntryClick:u,onEntryDateChange:x}),"week"===i&&(0,n.jsx)(tU,{date:h,events:m,onEntryClick:u,onEntryDateChange:x}),"day"===i&&(0,n.jsx)(tH,{date:h,events:m,onEntryClick:u,onEntryDateChange:x}),"year"===i&&(0,n.jsx)(tV,{date:h,events:m})]})]}):(0,n.jsx)(tJ,{reason:"no-date-field"})}var tq=r(35933),tG=r(22507),t$=r(88382),tZ=r(29788);let tY={day:{dayWidth:80,headerFormat:"MMM d"},week:{dayWidth:30,headerFormat:"MMM d"},month:{dayWidth:10,headerFormat:"MMM yyyy"},quarter:{dayWidth:4,headerFormat:"QQQ yyyy"}},tQ=["#3b82f6","#22c55e","#f59e0b","#ef4444","#8b5cf6","#06b6d4","#ec4899","#14b8a6","#f97316","#6366f1"];function tX(e){return null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):"object"==typeof e?JSON.stringify(e):""}function t0(e){return(0,td.GP)(e,"yyyy-MM-dd")}function t1(e){let{item:t,x:r,w:l,dayWidth:a,onEntryClick:s,onEntryDateChange:i}=e,[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)(0),[h,p]=(0,o.useState)(0),m=(0,o.useRef)(0),f=!!i,v=(0,o.useCallback)(e=>Math.round(e/a)*a,[a]),g=(0,o.useCallback)(e=>Math.round(e/a),[a]),y=(0,o.useCallback)((e,t)=>{f&&(e.preventDefault(),e.stopPropagation(),m.current=e.clientX,d(t),e.target.setPointerCapture(e.pointerId))},[f]),b=(0,o.useCallback)(e=>{if(!c)return;let t=v(e.clientX-m.current);"move"===c?x(t):"resize-left"===c?(x(t),p(-t)):p(t)},[c,v]),j=(0,o.useCallback)(e=>{if(!c||!i)return void d(null);let r=g(e.clientX-m.current);if(0===r&&"move"===c){d(null),x(0),p(0);return}let n=t.startDate,o=t.endDate;"move"===c?(n=(0,tu.f)(t.startDate,r),o=(0,tu.f)(t.endDate,r)):"resize-left"===c?(n=(0,tu.f)(t.startDate,r))>=o&&(n=(0,tu.f)(o,-1)):(o=(0,tu.f)(t.endDate,r))<=n&&(o=(0,tu.f)(n,1)),i({entryId:t.id,newStartDate:t0(n),newEndDate:t0(o)}),d(null),x(0),p(0)},[c,i,t,g]),k=Math.max(l+h,.5*a);return(0,n.jsxs)("div",{className:"absolute rounded flex items-center text-[11px] truncate select-none",style:{left:r+u,width:k,top:6,height:28,backgroundColor:t.color,color:"#fff",zIndex:c?20:2,cursor:f?"move"===c?"grabbing":"grab":"pointer",opacity:c?.85:1,transition:c?"none":"left 0.15s, width 0.15s"},onPointerDown:e=>y(e,"move"),onPointerMove:b,onPointerUp:j,onClick:e=>{c||(e.stopPropagation(),null==s||s(t.id))},title:"".concat(t.title,"\n").concat((0,td.GP)(t.startDate,"MMM d")," - ").concat((0,td.GP)(t.endDate,"MMM d")),children:[f&&(0,n.jsx)("div",{className:"absolute left-0 top-0 bottom-0 cursor-ew-resize hover:bg-white/20 rounded-l",style:{width:8},onPointerDown:e=>y(e,"resize-left")}),(0,n.jsx)("span",{className:"px-2 truncate flex-1",children:k>60?t.title||"Untitled":""}),f&&(0,n.jsx)("div",{className:"absolute right-0 top-0 bottom-0 cursor-ew-resize hover:bg-white/20 rounded-r",style:{width:8},onPointerDown:e=>y(e,"resize-right")})]})}function t2(e){let{reason:t}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 gap-2",children:[(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("path",{d:"M8 6h13"}),(0,n.jsx)("path",{d:"M8 12h13"}),(0,n.jsx)("path",{d:"M8 18h13"}),(0,n.jsx)("path",{d:"M3 6h.01"}),(0,n.jsx)("path",{d:"M3 12h.01"}),(0,n.jsx)("path",{d:"M3 18h.01"})]}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"no-fields"===t?"No date fields configured for timeline view. Open view settings to select start/end dates.":"No items with dates to display in this view."})]})}function t4(e){let{objectName:t,fields:r,entries:l,startDateField:a,endDateField:s,groupField:i,zoom:c,onZoomChange:d,members:u,onEntryClick:x,onEntryDateChange:h}=e,p=(0,o.useRef)(null),m=(0,o.useMemo)(()=>(function(e,t,r,n,o){let l=[];for(let s=0;s<e.length;s++){let i=e[s],c=tX(i[r]);if(c)try{var a;let e,r=(0,tc.H)(c);if(Number.isNaN(r.getTime()))continue;if(n){let t=tX(i[n]);if(t){let n=(0,tc.H)(t);e=Number.isNaN(n.getTime())?(0,tu.f)(r,1):n}else e=(0,tu.f)(r,1)}else e=(0,tu.f)(r,1);e<=r&&(e=(0,tu.f)(r,1)),l.push({id:tX(null!=(a=i.entry_id)?a:i.id),title:function(e,t){var r;let n=null!=(r=t.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?r:t.find(e=>"text"===e.type);return n?tX(e[n.name]):tX(e.id)}(i,t),startDate:r,endDate:e,group:o?tX(i[o]):void 0,color:function(e,t,r){let n=t.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_colors)?void 0:t.length)});if(n){var o,l;let t=tX(e[n.name]),r=null!=(l=null==(o=n.enum_values)?void 0:o.indexOf(t))?l:-1;if(r>=0&&n.enum_colors[r])return n.enum_colors[r]}return tQ[r%tQ.length]}(i,t,s),entry:i})}catch(e){}}return l.toSorted((e,t)=>e.startDate.getTime()-t.startDate.getTime())})(l,r,a,s,i),[l,r,a,s,i]),{start:f,end:v}=(0,o.useMemo)(()=>(function(e,t){if(0===e.length){let e=new Date;return{start:(0,tf.a)(e,1),end:(0,tm.P)(e,2)}}let r=(0,tq.j)(e.map(e=>e.startDate)),n=(0,tG.T)(e.map(e=>e.endDate)),o="day"===t?3:"week"===t?7:"month"===t?14:30;return{start:(0,tu.f)(r,-o),end:(0,tu.f)(n,o)}})(m,c),[m,c]),{dayWidth:g}=tY[c],y=((0,tZ.c)(v,f)+1)*g,b=(0,o.useMemo)(()=>(function(e,t,r){switch(r){case"day":return(0,tw.k)({start:e,end:t}).map(e=>({date:e,label:(0,td.GP)(e,"MMM d")}));case"week":return(0,t$.Y)({start:e,end:t},{weekStartsOn:1}).map(e=>({date:e,label:(0,td.GP)(e,"MMM d")}));case"month":return(0,tI.i)({start:e,end:t}).map(e=>({date:e,label:(0,td.GP)(e,"MMM yyyy")}));case"quarter":return(0,tI.i)({start:e,end:t}).filter(e=>e.getMonth()%3==0).map(e=>({date:e,label:(0,td.GP)(e,"QQQ yyyy")}))}})(f,v,c),[f,v,c]),j=(0,o.useMemo)(()=>{if(!i)return[{name:"",items:m}];let e=new Map;for(let t of m){let r=t.group||"Ungrouped";e.has(r)||e.set(r,[]),e.get(r).push(t)}return Array.from(e.entries()).map(e=>{let[t,r]=e;return{name:t,items:r}})},[m,i]),k=(0,o.useMemo)(()=>{let e=[];for(let t of j)for(let r of(i&&t.name&&e.push({type:"group",group:t.name}),t.items))e.push({type:"item",item:r});return e},[j,i]),w=(0,o.useCallback)(e=>(0,tZ.c)(e,f)*g,[f,g]);if((0,o.useEffect)(()=>{if(!p.current)return;let e=w(new Date);p.current.scrollLeft=Math.max(0,e-300)},[w]),!a)return(0,n.jsx)(t2,{reason:"no-fields"});if(0===m.length)return(0,n.jsx)(t2,{reason:"no-items"});let N=w((0,tS.o)(new Date));return(0,n.jsxs)("div",{className:"w-full",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3 px-1",children:[(0,n.jsxs)("div",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:[m.length," item",1!==m.length?"s":""]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:"Zoom:"}),(0,n.jsx)("div",{className:"flex rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)"},children:["day","week","month","quarter"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>d(e),className:"text-[11px] px-3 py-1 capitalize transition-colors",style:{background:e===c?"var(--color-accent)":"var(--color-surface)",color:e===c?"#fff":"var(--color-text-muted)",borderRight:"quarter"!==e?"1px solid var(--color-border)":void 0},children:e},e))})]})]}),(0,n.jsx)("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)",background:"var(--color-bg)"},children:(0,n.jsxs)("div",{className:"flex",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 border-r",style:{width:200,borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"border-b px-3 flex items-center text-[11px] font-medium",style:{height:50,borderColor:"var(--color-border)",color:"var(--color-text-muted)"},children:"Name"}),k.map((e,t)=>{var r;return(0,n.jsx)("div",{className:"px-3 flex items-center border-b truncate ".concat("group"===e.type?"text-[10px] font-semibold uppercase tracking-wider":"text-[12px] cursor-pointer hover:bg-[var(--color-surface-hover)]"),style:{height:40,borderColor:"var(--color-border)",color:"group"===e.type?"var(--color-text-muted)":"var(--color-text)",background:"group"===e.type?"var(--color-surface-hover)":void 0},onClick:()=>e.item&&(null==x?void 0:x(e.item.id)),children:"group"===e.type?e.group:(null==(r=e.item)?void 0:r.title)||"Untitled"},t)})]}),(0,n.jsx)("div",{ref:p,className:"flex-1 overflow-x-auto overflow-y-hidden",style:{maxHeight:"calc(100vh - 280px)"},children:(0,n.jsxs)("div",{style:{width:y,position:"relative"},children:[(0,n.jsx)("div",{className:"border-b flex",style:{height:50,borderColor:"var(--color-border)"},children:b.map((e,t)=>{let r=w(e.date),o=t<b.length-1?w(b[t+1].date):y;return(0,n.jsx)("div",{className:"absolute border-r flex items-end pb-1 px-2 text-[10px]",style:{left:r,width:o-r,height:50,borderColor:"var(--color-border)",color:"var(--color-text-muted)"},children:e.label},t)})}),k.map((e,t)=>(0,n.jsx)("div",{className:"relative border-b",style:{height:40,borderColor:"var(--color-border)",background:"group"===e.type?"var(--color-surface-hover)":void 0},children:e.item&&(()=>{let t=e.item,r=w(t.startDate),o=Math.max(w(t.endDate)-r,.5*g);return(0,n.jsx)(t1,{item:t,x:r,w:o,dayWidth:g,onEntryClick:x,onEntryDateChange:h})})()},t)),N>=0&&N<=y&&(0,n.jsx)("div",{className:"absolute top-0 bottom-0 pointer-events-none",style:{left:N,width:2,backgroundColor:"var(--color-accent)",opacity:.6,zIndex:10}})]})})]})})]})}function t5(e){return null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):"object"==typeof e?JSON.stringify(e):""}function t6(e){var t;let{entry:r,fields:l,titleField:a,coverField:s,onEntryClick:i}=e,c=t5(null!=(t=r.entry_id)?t:r.id),d=function(e,t,r){var n;if(r){let t=t5(e[r]);if(t)return t}let o=null!=(n=t.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?n:t.find(e=>"text"===e.type);return o?t5(e[o.name]):t5(e.id)}(r,l,a),u=(0,o.useMemo)(()=>l.filter(e=>e.name!==a&&e.name!==s).slice(0,4),[l,a,s]),x=l.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_values)?void 0:t.length)}),h=x?t5(r[x.name]):null,p=x&&h?function(e,t){var r;if(!e||!t.enum_values)return null;let n=t.enum_values.indexOf(e);return{text:e,color:n>=0&&(null==(r=t.enum_colors)?void 0:r[n])?t.enum_colors[n]:"#94a3b8"}}(h,x):null;return(0,n.jsxs)("button",{type:"button",onClick:()=>null==i?void 0:i(c),className:"text-left rounded-xl border p-4 hover:shadow-md transition-all cursor-pointer w-full group",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2 mb-2",children:[(0,n.jsx)("h4",{className:"text-[13px] font-semibold leading-tight line-clamp-2 group-hover:underline",style:{color:"var(--color-text)"},children:d||"Untitled"}),p&&(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0 whitespace-nowrap",style:{backgroundColor:p.color,color:"#fff"},children:p.text})]}),(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:u.map(e=>{let t=r[e.name];if(null==t||""===t5(t))return null;let o="tags"===e.type?eZ(t):[];return(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("span",{className:"text-[10px] flex-shrink-0 min-w-[60px]",style:{color:"var(--color-text-muted)"},children:e.name}),(0,n.jsx)("div",{className:"text-[12px] whitespace-pre-line line-clamp-2",style:{color:"var(--color-text)"},children:"tags"===e.type?(0,n.jsxs)("span",{className:"flex items-center gap-0.5 flex-wrap",children:[o.slice(0,3).map(e=>{let t=eJ(e);return"link"===t.kind&&t.href?(0,n.jsx)("a",{href:t.href,target:"url"===t.linkType||"file"===t.linkType?"_blank":void 0,rel:"url"===t.linkType||"file"===t.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium hover:underline underline-offset-2",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)"},children:t.text},e):(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)"},children:e},e)}),o.length>3&&(0,n.jsxs)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:["+",o.length-3]})]}):(0,n.jsx)(e$,{value:t,fieldType:e.type,mode:"table"})})]},e.id)})}),null!=r.created_at&&(0,n.jsx)("div",{className:"mt-3 text-[10px]",style:{color:"var(--color-text-muted)",opacity:.6},children:t5(r.created_at).slice(0,10)})]})}function t3(){return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 gap-2",children:[(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No entries to display in gallery view."})]})}function t8(e){let{objectName:t,fields:r,entries:o,titleField:l,coverField:a,members:s,relationLabels:i,onEntryClick:c}=e;return 0===o.length?(0,n.jsx)(t3,{}):(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3",children:o.map(e=>{var t;return(0,n.jsx)(t6,{entry:e,fields:r,titleField:l,coverField:a,onEntryClick:c},t5(null!=(t=e.entry_id)?t:e.id))})})}function t7(e){return null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):"object"==typeof e?JSON.stringify(e):""}function t9(e){var t,r;let{entry:l,fields:a,titleField:s,subtitleField:i,onEntryClick:c}=e,d=t7(null!=(t=l.entry_id)?t:l.id),u=function(e,t,r){var n;if(r){let t=t7(e[r]);if(t)return t}let o=null!=(n=t.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?n:t.find(e=>"text"===e.type);return o?t7(e[o.name]):t7(e.id)}(l,a,s),x=(0,o.useMemo)(()=>{if(i){let e=t7(l[i]);if(e)return e}let e=a.find(e=>"text"===e.type&&e.name!==s&&!/name|title/i.test(e.name));return e?t7(l[e.name]):void 0},[l,a,s,i]),h=a.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_values)?void 0:t.length)}),p=h?t7(l[h.name]):null,m=h&&p?function(e,t){var r;if(!e||!t.enum_values)return null;let n=t.enum_values.indexOf(e);return{text:e,color:n>=0&&(null==(r=t.enum_colors)?void 0:r[n])?t.enum_colors[n]:"#94a3b8"}}(p,h):null,f=a.find(e=>"tags"===e.type),v=f?eZ(l[f.name]):[],g=a.find(e=>"date"===e.type),y=g?t7(l[g.name]):null;return(0,n.jsxs)("button",{type:"button",onClick:()=>null==c?void 0:c(d),className:"w-full text-left flex items-center gap-3 px-4 py-3 border-b hover:bg-[var(--color-surface-hover)] transition-colors cursor-pointer group",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:null!=(r=null==m?void 0:m.color)?r:"var(--color-text-muted)",opacity:.6}}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-[13px] font-medium truncate group-hover:underline",style:{color:"var(--color-text)"},children:u||"Untitled"}),m&&(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{backgroundColor:m.color,color:"#fff"},children:m.text}),v.slice(0,3).map(e=>{let t=eJ(e);return"link"===t.kind&&t.href?(0,n.jsx)("a",{href:t.href,target:"url"===t.linkType||"file"===t.linkType?"_blank":void 0,rel:"url"===t.linkType||"file"===t.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0 hover:underline underline-offset-2",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)",border:"1px solid var(--color-border)"},children:t.text},e):(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:e},e)})]}),x&&(0,n.jsx)("div",{className:"text-[11px] whitespace-pre-line line-clamp-1 mt-0.5",style:{color:"var(--color-text-muted)"},children:x})]}),y&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0 tabular-nums",style:{color:"var(--color-text-muted)"},children:y.slice(0,10)})]})}function re(){return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 gap-2",children:[(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--color-text-muted)",opacity:.4},children:[(0,n.jsx)("path",{d:"M8 6h13"}),(0,n.jsx)("path",{d:"M8 12h13"}),(0,n.jsx)("path",{d:"M8 18h13"}),(0,n.jsx)("path",{d:"M3 6h.01"}),(0,n.jsx)("path",{d:"M3 12h.01"}),(0,n.jsx)("path",{d:"M3 18h.01"})]}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No entries to display in list view."})]})}function rt(e){let{objectName:t,fields:r,entries:o,titleField:l,subtitleField:a,members:s,onEntryClick:i}=e;return 0===o.length?(0,n.jsx)(re,{}):(0,n.jsx)("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:o.map(e=>{var t;return(0,n.jsx)(t9,{entry:e,fields:r,titleField:l,subtitleField:a,onEntryClick:i},t7(null!=(t=e.entry_id)?t:e.id))})})}let rr=["table","kanban","calendar","timeline","gallery","list"];function rn(e){return"string"==typeof e&&rr.includes(e)}function ro(e,t,r){return(null==e?void 0:e.view_type)&&rn(e.view_type)?e.view_type:t&&rn(t)?t:r&&rn(r)?r:"table"}function rl(e,t,r){var n,o,l,a,s,i,c,d,u,x,h,p;switch(t){case"kanbanField":return null!=(l=null==(n=r.find(e=>"enum"===e.type&&/status/i.test(e.name)))?void 0:n.name)?l:null==(o=r.find(e=>"enum"===e.type))?void 0:o.name;case"calendarDateField":case"timelineStartField":return null!=(i=null==(a=r.find(e=>"date"===e.type&&/due|start|begin/i.test(e.name)))?void 0:a.name)?i:null==(s=r.find(e=>"date"===e.type))?void 0:s.name;case"calendarEndDateField":case"timelineEndField":return null==(c=r.find(e=>"date"===e.type&&/end|finish|close/i.test(e.name)))?void 0:c.name;case"timelineGroupField":return null==(d=r.find(e=>"enum"===e.type))?void 0:d.name;case"galleryTitleField":case"listTitleField":return null!=(h=null==(u=r.find(e=>"text"===e.type&&/name|title/i.test(e.name)))?void 0:u.name)?h:null==(x=r.find(e=>"text"===e.type))?void 0:x.name;case"galleryCoverField":default:return;case"listSubtitleField":return null==(p=r.find(e=>"text"===e.type&&!/name|title/i.test(e.name)))?void 0:p.name}}let ra=[{value:"is_empty",label:"is empty"},{value:"is_not_empty",label:"is not empty"}],rs=[{value:"contains",label:"contains"},{value:"not_contains",label:"does not contain"},{value:"equals",label:"equals"},{value:"not_equals",label:"does not equal"},{value:"starts_with",label:"starts with"},{value:"ends_with",label:"ends with"},...ra],ri=[{value:"eq",label:"="},{value:"neq",label:"≠"},{value:"gt",label:">"},{value:"gte",label:"≥"},{value:"lt",label:"<"},{value:"lte",label:"≤"},{value:"between",label:"between"},...ra],rc=[{value:"on",label:"is"},{value:"before",label:"before"},{value:"after",label:"after"},{value:"date_between",label:"between"},{value:"relative_past",label:"in the last"},{value:"relative_next",label:"in the next"},...ra],rd=[{value:"is",label:"is"},{value:"is_not",label:"is not"},{value:"is_any_of",label:"is any of"},{value:"is_none_of",label:"is none of"},...ra],ru=[{value:"is_true",label:"is true"},{value:"is_false",label:"is false"},...ra],rx=[{value:"has_any",label:"has any of"},{value:"has_none",label:"has none of"},{value:"has_all",label:"has all of"},...ra],rh=[{value:"contains",label:"contains"},{value:"not_contains",label:"does not contain"},...ra];function rp(e){switch(e){case"text":case"richtext":case"email":case"tags":default:return"contains";case"number":return"eq";case"date":return"relative_past";case"enum":return"is";case"boolean":return"is_true";case"relation":case"user":return"has_any"}}function rm(e){return"conjunction"in e&&"rules"in e}function rf(e){return btoa(JSON.stringify(e))}function rv(){return{id:"root",conjunction:"and",rules:[]}}function rg(e){var t,r;let n=e.field,o=e.operator,l=Array.isArray(e.value)?e.value.join(", "):String(null!=(t=e.value)?t:"");return"is_empty"===o?"".concat(n," is empty"):"is_not_empty"===o?"".concat(n," is not empty"):"is_true"===o?"".concat(n," is true"):"is_false"===o?"".concat(n," is false"):"between"===o||"date_between"===o?"".concat(n," between ").concat(l," and ").concat(e.valueTo):"relative_past"===o?"".concat(n," in the last ").concat(e.relativeAmount," ").concat(e.relativeUnit):"relative_next"===o?"".concat(n," in the next ").concat(e.relativeAmount," ").concat(e.relativeUnit):"".concat(n," ").concat(null!=(r=({contains:"contains",not_contains:"doesn't contain",equals:"=",not_equals:"≠",starts_with:"starts with",ends_with:"ends with",eq:"=",neq:"≠",gt:">",gte:"≥",lt:"<",lte:"≤",before:"before",after:"after",on:"is",is:"is",is_not:"is not",is_any_of:"is any of",is_none_of:"is none of",has_any:"has any of",has_none:"has none of",has_all:"has all of"})[o])?r:o," ").concat(l)}let ry={table:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("path",{d:"M3 12h18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})]})},label:"Table"},kanban:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"6",height:"14",x:"3",y:"5",rx:"1"}),(0,n.jsx)("rect",{width:"6",height:"10",x:"9",y:"9",rx:"1"}),(0,n.jsx)("rect",{width:"6",height:"16",x:"15",y:"3",rx:"1"})]})},label:"Board"},calendar:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"4",rx:"2"}),(0,n.jsx)("path",{d:"M16 2v4"}),(0,n.jsx)("path",{d:"M8 2v4"}),(0,n.jsx)("path",{d:"M3 10h18"})]})},label:"Calendar"},timeline:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h7"}),(0,n.jsx)("path",{d:"M6 12h10"}),(0,n.jsx)("path",{d:"M5 18h5"}),(0,n.jsx)("path",{d:"M14 6h7"}),(0,n.jsx)("path",{d:"M18 12h3"}),(0,n.jsx)("path",{d:"M12 18h9"})]})},label:"Timeline"},gallery:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]})},label:"Gallery"},list:{icon:function(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8 6h13"}),(0,n.jsx)("path",{d:"M8 12h13"}),(0,n.jsx)("path",{d:"M8 18h13"}),(0,n.jsx)("path",{d:"M3 6h.01"}),(0,n.jsx)("path",{d:"M3 12h.01"}),(0,n.jsx)("path",{d:"M3 18h.01"})]})},label:"List"}};function rb(e){let{value:t,onChange:r}=e;return(0,n.jsx)("div",{className:"flex items-center rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)"},children:rr.map(e=>{let o=ry[e],l=o.icon,a=e===t;return(0,n.jsxs)("button",{type:"button",onClick:()=>r(e),className:"flex items-center gap-1 px-2.5 py-1.5 text-[11px] transition-colors",style:{background:a?"var(--color-accent)":"var(--color-surface)",color:a?"#fff":"var(--color-text-muted)",borderRight:"list"!==e?"1px solid var(--color-border)":void 0},title:o.label,children:[(0,n.jsx)(l,{}),(0,n.jsx)("span",{className:"hidden sm:inline",children:o.label})]},e)})})}function rj(e){let{label:t,value:r,onChange:o,fields:l,filterType:a,allowEmpty:s}=e,i=a?Array.isArray(a)?a:[a]:null,c=i?l.filter(e=>i.includes(e.type)):l;return(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("label",{className:"text-[10px] font-medium",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsxs)("select",{value:null!=r?r:"",onChange:e=>o(e.target.value||void 0),className:"text-[12px] rounded-md border px-2 py-1.5 bg-transparent",style:{borderColor:"var(--color-border)",color:"var(--color-text)",background:"var(--color-surface)"},children:[s&&(0,n.jsx)("option",{value:"",children:"None"}),0===c.length&&(0,n.jsx)("option",{value:"",disabled:!0,children:"No matching fields"}),c.map(e=>(0,n.jsx)("option",{value:e.name,children:e.name},e.id))]})]})}function rk(e){let{label:t,value:r,options:o,onChange:l}=e;return(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("label",{className:"text-[10px] font-medium",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("div",{className:"flex rounded-md border overflow-hidden",style:{borderColor:"var(--color-border)"},children:o.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>l(e.value),className:"text-[11px] px-2.5 py-1 flex-1 transition-colors capitalize",style:{background:e.value===r?"var(--color-accent)":"var(--color-surface)",color:e.value===r?"#fff":"var(--color-text-muted)"},children:e.label},e.value))})]})}function rw(e){let{settings:t,fields:r,onSettingsChange:o}=e;return(0,n.jsx)(rj,{label:"Group by field",value:t.kanbanField,onChange:e=>o({...t,kanbanField:e}),fields:r,filterType:"enum"})}function rN(e){var t;let{settings:r,fields:o,onSettingsChange:l}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rj,{label:"Date field",value:r.calendarDateField,onChange:e=>l({...r,calendarDateField:e}),fields:o,filterType:"date"}),(0,n.jsx)(rj,{label:"End date field (optional)",value:r.calendarEndDateField,onChange:e=>l({...r,calendarEndDateField:e}),fields:o,filterType:"date",allowEmpty:!0}),(0,n.jsx)(rk,{label:"Default view",value:null!=(t=r.calendarMode)?t:"month",options:[{value:"day",label:"Day"},{value:"week",label:"Week"},{value:"month",label:"Month"},{value:"year",label:"Year"}],onChange:e=>l({...r,calendarMode:e})})]})}function rC(e){var t;let{settings:r,fields:o,onSettingsChange:l}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rj,{label:"Start date field",value:r.timelineStartField,onChange:e=>l({...r,timelineStartField:e}),fields:o,filterType:"date"}),(0,n.jsx)(rj,{label:"End date field",value:r.timelineEndField,onChange:e=>l({...r,timelineEndField:e}),fields:o,filterType:"date",allowEmpty:!0}),(0,n.jsx)(rj,{label:"Group by (optional)",value:r.timelineGroupField,onChange:e=>l({...r,timelineGroupField:e}),fields:o,filterType:"enum",allowEmpty:!0}),(0,n.jsx)(rk,{label:"Default zoom",value:null!=(t=r.timelineZoom)?t:"week",options:[{value:"day",label:"Day"},{value:"week",label:"Week"},{value:"month",label:"Month"},{value:"quarter",label:"Quarter"}],onChange:e=>l({...r,timelineZoom:e})})]})}function rS(e){let{settings:t,fields:r,onSettingsChange:o}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rj,{label:"Title field",value:t.galleryTitleField,onChange:e=>o({...t,galleryTitleField:e}),fields:r,filterType:"text"}),(0,n.jsx)(rj,{label:"Cover field (optional)",value:t.galleryCoverField,onChange:e=>o({...t,galleryCoverField:e}),fields:r,allowEmpty:!0})]})}function rM(e){let{settings:t,fields:r,onSettingsChange:o}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rj,{label:"Title field",value:t.listTitleField,onChange:e=>o({...t,listTitleField:e}),fields:r,filterType:"text"}),(0,n.jsx)(rj,{label:"Subtitle field (optional)",value:t.listSubtitleField,onChange:e=>o({...t,listSubtitleField:e}),fields:r,filterType:["text","email","richtext"],allowEmpty:!0})]})}function rL(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function rT(e){let{viewType:t,settings:r,fields:l,onSettingsChange:a}=e,[s,i]=(0,o.useState)(!1),c=(0,o.useRef)(null);return((0,o.useEffect)(()=>{if(!s)return;let e=e=>{c.current&&!c.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[s]),"table"===t)?null:(0,n.jsxs)("div",{className:"relative",ref:c,children:[(0,n.jsx)("button",{type:"button",onClick:()=>i(!s),className:"p-1.5 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text-muted)"},title:"View settings",children:(0,n.jsx)(rL,{})}),s&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-50 rounded-lg border shadow-lg p-3 min-w-[240px] flex flex-col gap-3",style:{borderColor:"var(--color-border)",background:"var(--color-surface)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,n.jsx)("div",{className:"text-[11px] font-semibold",style:{color:"var(--color-text)"},children:{table:"",kanban:"Board Settings",calendar:"Calendar Settings",timeline:"Timeline Settings",gallery:"Gallery Settings",list:"List Settings"}[t]}),"kanban"===t&&(0,n.jsx)(rw,{settings:r,fields:l,onSettingsChange:a}),"calendar"===t&&(0,n.jsx)(rN,{settings:r,fields:l,onSettingsChange:a}),"timeline"===t&&(0,n.jsx)(rC,{settings:r,fields:l,onSettingsChange:a}),"gallery"===t&&(0,n.jsx)(rS,{settings:r,fields:l,onSettingsChange:a}),"list"===t&&(0,n.jsx)(rM,{settings:r,fields:l,onSettingsChange:a})]})]})}var rD=r(24946);function rE(e){let t=[],r=0;for(let o of e.matchAll(/```report-json\s*\n([\s\S]*?)```/g)){var n;let l=e.slice(r,o.index);l.trim()&&t.push({type:"text",text:l});try{let e=JSON.parse(o[1]);e.panels&&Array.isArray(e.panels)?t.push({type:"report-artifact",config:e}):t.push({type:"text",text:o[0]})}catch(e){t.push({type:"text",text:o[0]})}r=(null!=(n=o.index)?n:0)+o[0].length}let o=e.slice(r);return o.trim()&&t.push({type:"text",text:o}),t}function rR(e){return e.includes("```report-json")}function rW(e){let t=[],r=0;for(let o of e.matchAll(/```diff\s*\n([\s\S]*?)```/g)){var n;let l=e.slice(r,o.index);l.trim()&&t.push({type:"text",text:l});let a=o[1].trimEnd();a?t.push({type:"diff-artifact",diff:a}):t.push({type:"text",text:o[0]}),r=(null!=(n=o.index)?n:0)+o[0].length}let o=e.slice(r);return o.trim()&&t.push({type:"text",text:o}),t}function rI(e){return e.includes("```diff")}function rB(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]})}function rF(e){let{expanded:t}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transition:"transform 150ms ease",transform:t?"rotate(90deg)":"rotate(0deg)"},children:(0,n.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function rP(e){let{file:t}=e,[r,l]=(0,o.useState)(!0),a=t.newPath&&"/dev/null"!==t.newPath?t.newPath:t.oldPath&&"/dev/null"!==t.oldPath?t.oldPath:"diff";return(0,n.jsxs)("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>l(!r),className:"flex items-center gap-2 w-full px-3 py-2 text-left",style:{background:"var(--color-surface)",borderBottom:r?"1px solid var(--color-border)":"none"},children:[(0,n.jsx)(rF,{expanded:r}),(0,n.jsx)(rB,{}),(0,n.jsx)("span",{className:"text-sm font-mono font-medium flex-1 truncate",style:{color:"var(--color-text)"},children:a}),t.additions>0&&(0,n.jsxs)("span",{className:"text-xs font-mono font-medium",style:{color:"var(--diff-add-badge)"},children:["+",t.additions]}),t.deletions>0&&(0,n.jsxs)("span",{className:"text-xs font-mono font-medium",style:{color:"var(--diff-del-badge)"},children:["-",t.deletions]})]}),r&&(0,n.jsx)("div",{className:"overflow-x-auto",style:{background:"var(--color-bg)"},children:(0,n.jsx)("table",{className:"w-full text-xs font-mono leading-5 border-collapse",style:{tabSize:4},children:(0,n.jsx)("tbody",{children:t.hunks.map((e,t)=>e.lines.map((e,r)=>{if("header"===e.type)return(0,n.jsx)("tr",{children:(0,n.jsx)("td",{colSpan:3,className:"px-3 py-1 select-none",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:e.content})},"".concat(t,"-").concat(r));let o="addition"===e.type?"var(--diff-add-bg)":"deletion"===e.type?"var(--diff-del-bg)":"transparent",l="addition"===e.type?"var(--diff-add-text)":"deletion"===e.type?"var(--diff-del-text)":"var(--color-text)",a="addition"===e.type?"+":"deletion"===e.type?"-":" ";return(0,n.jsxs)("tr",{style:{background:o},children:[(0,n.jsx)("td",{className:"select-none text-right pr-2 pl-3",style:{color:"var(--color-text-muted)",opacity:.5,width:"1%",whiteSpace:"nowrap",userSelect:"none"},children:"addition"!==e.type?e.oldLine:""}),(0,n.jsx)("td",{className:"select-none text-right pr-3",style:{color:"var(--color-text-muted)",opacity:.5,width:"1%",whiteSpace:"nowrap",userSelect:"none"},children:"deletion"!==e.type?e.newLine:""}),(0,n.jsxs)("td",{className:"pr-4",style:{color:l},children:[(0,n.jsx)("span",{className:"select-none inline-block w-4 text-center",style:{opacity:.6,userSelect:"none"},children:a}),e.content]})]},"".concat(t,"-").concat(r))}))})})})]})}function rA(e){let{diff:t}=e,r=(0,o.useMemo)(()=>(function(e){let t=[],r=e.split("\n"),n=null,o=null,l=0,a=0;for(let e=0;e<r.length;e++){let s=r[e];if(s.startsWith("--- ")){let o=r[e+1];if(null==o?void 0:o.startsWith("+++ ")){n={oldPath:s.replace(/^--- (a\/)?/,"").trim(),newPath:o.replace(/^\+\+\+ (b\/)?/,"").trim(),hunks:[],additions:0,deletions:0},t.push(n),e++;continue}}let i=s.match(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@(.*)/);if(i){l=parseInt(i[1],10),a=parseInt(i[2],10),o={header:s,lines:[{type:"header",content:s}]},n?n.hunks.push(o):(n={oldPath:"",newPath:"",hunks:[o],additions:0,deletions:0},t.push(n));continue}o&&n&&(s.startsWith("+")?(o.lines.push({type:"addition",content:s.slice(1),newLine:a}),n.additions++,a++):s.startsWith("-")?(o.lines.push({type:"deletion",content:s.slice(1),oldLine:l}),n.deletions++,l++):(s.startsWith(" ")||""===s)&&(o.lines.push({type:"context",content:s.slice(1)||"",oldLine:l,newLine:a}),l++,a++))}if(0===t.length&&e.trim()){let r=e.split("\n").map(e=>e.startsWith("+")?{type:"addition",content:e.slice(1)}:e.startsWith("-")?{type:"deletion",content:e.slice(1)}:{type:"context",content:e});t.push({oldPath:"",newPath:"",hunks:[{header:"",lines:r}],additions:r.filter(e=>"addition"===e.type).length,deletions:r.filter(e=>"deletion"===e.type).length})}return t})(t),[t]);return(0,n.jsx)("div",{className:"space-y-2 my-3",children:r.map((e,t)=>(0,n.jsx)(rP,{file:e},t))})}let r_=(0,rD.default)(()=>r.e(3867).then(r.bind(r,53867)).then(e=>e.MarkdownContent),{loadableGenerated:{webpack:()=>[53867]},ssr:!1,loading:()=>(0,n.jsxs)("div",{className:"animate-pulse space-y-3 py-4",children:[(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"80%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"60%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"70%"}})]})}),rz=(0,rD.default)(()=>r.e(5477).then(r.bind(r,45477)).then(e=>({default:e.ReportCard})),{loadableGenerated:{webpack:()=>[45477]},ssr:!1,loading:()=>(0,n.jsx)("div",{className:"h-48 rounded-xl animate-pulse my-4",style:{background:"var(--color-surface)"}})}),rO=(0,rD.default)(()=>Promise.all([r.e(4652),r.e(2597)]).then(r.bind(r,52597)).then(e=>({default:e.MarkdownEditor})),{loadableGenerated:{webpack:()=>[52597]},ssr:!1,loading:()=>(0,n.jsxs)("div",{className:"animate-pulse space-y-3 py-4 px-6",children:[(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"80%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"60%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"70%"}})]})});function rU(e){let{content:t,title:r,filePath:l,tree:a,onSave:s,onNavigate:i,searchFn:c}=e,[d,u]=(0,o.useState)(!!l),x=t.replace(/^---\s*\n[\s\S]*?\n---\s*\n/,""),h=x.match(/^#\s+(.+)/m),p=null!=r?r:null==h?void 0:h[1],m=p&&h?x.replace(/^#\s+.+\n?/,""):x;if(d&&l)return(0,n.jsx)("div",{className:"max-w-3xl mx-auto",children:(0,n.jsx)(rO,{content:x,rawContent:t,filePath:l,tree:null!=a?a:[],onSave:s,onNavigate:i,searchFn:c})});let f=rR(m)||rI(m),v=(0,o.useCallback)(e=>{if(!i)return;let t=e.target.closest("a");if(!t)return;let r=t.getAttribute("href");r&&(0,eb.m9)(r)&&(e.preventDefault(),e.stopPropagation(),i(r))},[i]);return(0,n.jsxs)("div",{className:"max-w-3xl mx-auto px-6 py-8",onClick:v,children:[(0,n.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[p&&(0,n.jsx)("h1",{className:"text-3xl font-bold mb-6 flex-1",style:{color:"var(--color-text)"},children:p}),l&&(0,n.jsxs)("button",{type:"button",onClick:()=>u(!0),className:"editor-mode-toggle flex-shrink-0 mt-1",title:"Edit this document",children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"}),(0,n.jsx)("path",{d:"m15 5 4 4"})]}),(0,n.jsx)("span",{children:"Edit"})]})]}),f?(0,n.jsx)(rH,{content:m}):(0,n.jsx)("div",{className:"workspace-prose",children:(0,n.jsx)(r_,{content:m})})]})}function rH(e){let{content:t}=e,r=rE(t),o=[];for(let e of r)if("text"===e.type&&rI(e.text))for(let t of rW(e.text))o.push(t);else o.push(e);return(0,n.jsx)("div",{className:"space-y-4",children:o.map((e,t)=>"report-artifact"===e.type?(0,n.jsx)("div",{className:"my-6",children:(0,n.jsx)(rz,{config:e.config})},t):"diff-artifact"===e.type?(0,n.jsx)("div",{className:"my-4",children:(0,n.jsx)(rA,{diff:e.diff})},t):(0,n.jsx)("div",{className:"workspace-prose",children:(0,n.jsx)(r_,{content:e.text})},t))})}let rV=new Set(["xlsx","xls","xlsb","xlsm","xltx","xltm","ods","fods","csv","tsv","numbers"]);function rJ(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return rV.has(n)}function rK(e){let{content:t,filename:r,type:o}=e,l=t.split("\n");return(0,n.jsxs)("div",{className:"max-w-4xl mx-auto px-6 py-8",children:[(0,n.jsx)(rq,{filename:r,label:o.toUpperCase()}),(0,n.jsx)("div",{className:"rounded-b-lg border overflow-x-auto",style:{background:"var(--color-bg)",borderColor:"var(--color-border)"},children:(0,n.jsx)("pre",{className:"text-sm leading-6",style:{margin:0},children:(0,n.jsx)("code",{children:l.map((e,t)=>(0,n.jsxs)("div",{className:"flex hover:bg-[var(--color-surface-hover)] transition-colors duration-75",children:[(0,n.jsx)("span",{className:"select-none text-right pr-4 pl-4 flex-shrink-0 tabular-nums",style:{color:"var(--color-text-muted)",opacity:.5,minWidth:"3rem",userSelect:"none"},children:t+1}),(0,n.jsx)("span",{className:"pr-4 flex-1",style:{color:"var(--color-text)"},children:"yaml"===o?(0,n.jsx)(rG,{line:e}):e||" "})]},t))})})})]})}function rq(e){let{filename:t,label:r,icon:o}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 rounded-t-lg border border-b-0",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[null!=o?o:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:t}),(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded ml-auto",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:r})]})}function rG(e){let{line:t}=e;if(t.trim().startsWith("#"))return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:t});let r=t.match(/^(\s*)([\w][\w_-]*)\s*(:)(.*)/);if(r){let[,e,t,o,l]=r;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:e}),(0,n.jsx)("span",{style:{color:"#60a5fa"},children:t}),(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:o}),(0,n.jsx)(r$,{value:l})]})}let o=t.match(/^(\s*)(-)(\s*)(.*)/);if(o){let[,e,t,r,l]=o;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:e}),(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:t}),(0,n.jsx)("span",{children:r}),(0,n.jsx)("span",{style:{color:"var(--color-text)"},children:l})]})}return(0,n.jsx)("span",{children:t||" "})}function r$(e){let{value:t}=e,r=t.trim();return r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'")?(0,n.jsxs)("span",{style:{color:"#a5d6a7"},children:[" ",r]}):"true"===r||"false"===r?(0,n.jsxs)("span",{style:{color:"#f59e0b"},children:[" ",r]}):/^-?\d+(\.\d+)?$/.test(r)?(0,n.jsxs)("span",{style:{color:"#c084fc"},children:[" ",r]}):"null"===r?(0,n.jsxs)("span",{style:{color:"var(--color-text-muted)",fontStyle:"italic"},children:[" ",r]}):(0,n.jsxs)("span",{style:{color:"var(--color-text)"},children:[" ",t]})}var rZ=r(81584),rY=r(13292);let rQ=new Set(["csv","tsv"]);function rX(e){var t,r;return null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:""}function r0(e){let t="",r=e;do t=String.fromCharCode(65+r%26)+t,r=Math.floor(r/26)-1;while(r>=0);return t}function r1(e){let{state:t,onClose:r,onInsertRowAbove:l,onInsertRowBelow:a,onInsertColLeft:s,onInsertColRight:i,onDeleteRow:c,onDeleteCol:d,onClearCells:u}=e,x=(0,o.useRef)(null);if((0,o.useEffect)(()=>{if(!t)return;let e=e=>{x.current&&!x.current.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]),!t)return null;let h={padding:"6px 12px",fontSize:"12px",cursor:"pointer",color:"var(--color-text)",borderRadius:"4px"};return(0,n.jsx)("div",{ref:x,style:{position:"fixed",top:t.y,left:t.x,zIndex:9999,background:"var(--color-surface-raised)",border:"1px solid var(--color-border)",borderRadius:"8px",padding:"4px",boxShadow:"var(--shadow-lg)",minWidth:"180px"},children:[{label:"Insert row above",action:l},{label:"Insert row below",action:a},{label:"Insert column left",action:s},{label:"Insert column right",action:i},{label:"Delete row",action:c,danger:!0},{label:"Delete column",action:d,danger:!0},{label:"Clear cells",action:u,danger:!0}].map((e,t)=>(0,n.jsxs)("div",{children:[4===t&&(0,n.jsx)("div",{style:{height:"1px",background:"var(--color-border)",margin:"4px 0"}}),(0,n.jsx)("button",{type:"button",onClick:()=>{e.action(),r()},style:{...h,color:e.danger?"var(--color-error)":"var(--color-text)",display:"block",width:"100%",textAlign:"left",background:"transparent",border:"none"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:e.label})]},t))})}function r2(e){let{data:t,onNavigate:r,onClose:l}=e,[a,s]=(0,o.useState)(""),[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(0),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;null==(e=x.current)||e.focus()},[]),(0,o.useEffect)(()=>{if(!a.trim()){c([]),u(0);return}let e=a.toLowerCase(),n=[];t.forEach((t,r)=>{null==t||t.forEach((t,o)=>{t&&String(t.value).toLowerCase().includes(e)&&n.push({row:r,column:o})})}),c(n),u(0),n.length>0&&r(n[0])},[a,t,r]);let h=(0,o.useCallback)(e=>{if(0===i.length)return;let t=(e%i.length+i.length)%i.length;u(t),r(i[t])},[i,r]);return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",background:"var(--color-surface)",borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]}),(0,n.jsx)("input",{ref:x,value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{"Escape"===e.key&&l(),"Enter"===e.key&&(e.preventDefault(),h(e.shiftKey?d-1:d+1))},placeholder:"Find in sheet...",style:{flex:1,background:"transparent",border:"none",outline:"none",fontSize:"12px",color:"var(--color-text)"}}),a&&(0,n.jsx)("span",{style:{fontSize:"11px",color:"var(--color-text-muted)",whiteSpace:"nowrap"},children:i.length>0?"".concat(d+1," of ").concat(i.length):"No results"}),(0,n.jsx)("button",{type:"button",onClick:()=>h(d-1),disabled:0===i.length,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px",color:"var(--color-text-muted)",opacity:0===i.length?.3:1},title:"Previous (Shift+Enter)",children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"m18 15-6-6-6 6"})})}),(0,n.jsx)("button",{type:"button",onClick:()=>h(d+1),disabled:0===i.length,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px",color:"var(--color-text-muted)",opacity:0===i.length?.3:1},title:"Next (Enter)",children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"m6 9 6 6 6-6"})})}),(0,n.jsx)("button",{type:"button",onClick:l,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px",color:"var(--color-text-muted)"},title:"Close (Esc)",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]})}function r4(e){let{onClick:t,title:r,disabled:o,children:l,accent:a}=e;return(0,n.jsx)("button",{type:"button",onClick:t,disabled:o,title:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",borderRadius:"6px",border:"none",background:a?"var(--color-accent)":"transparent",color:a?"#fff":"var(--color-text-muted)",cursor:o?"default":"pointer",opacity:o?.35:1,flexShrink:0,transition:"background 0.1s, color 0.1s"},onMouseEnter:e=>{o||a||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{a||(e.currentTarget.style.background="transparent")},children:l})}function r5(){return(0,n.jsx)("div",{style:{width:"1px",height:"18px",background:"var(--color-border)",margin:"0 4px",flexShrink:0}})}function r6(e){var t,r;let{url:l,filename:a,filePath:s,compact:i=!1}=e,[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)(0),[h,p]=(0,o.useState)(null),[m,f]=(0,o.useState)(!1),[v,g]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(null),[w,N]=(0,o.useState)(null),[C,S]=(0,o.useState)(null),[M,L]=(0,o.useState)(!1),T=(0,o.useRef)(null),[D,E]=(0,o.useState)([]),[R,W]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=!1;return d(null),x(0),p(null),f(!1),E([]),W([]),fetch(l).then(e=>{if(!e.ok)throw Error("Failed to load file (".concat(e.status,")"));return e.arrayBuffer()}).then(t=>{if(e)return;let r=(0,rY.LF)(t,{type:"array"}),n=r.SheetNames.map(e=>({name:e,data:function(e){let t=rY.Wp.sheet_to_json(e,{header:1,defval:""});if(0===t.length)return(0,rZ.JH)(1,1);let r=t.reduce((e,t)=>Math.max(e,t.length),0);return t.map(e=>{let t=[];for(let n=0;n<r;n++){let r=n<e.length?e[n]:"";t.push({value:null==r?"":r})}return t})}(r.Sheets[e])}));0===n.length&&n.push({name:"Sheet1",data:(0,rZ.JH)(50,26)}),d(n)}).catch(t=>{e||p(String(t))}),()=>{e=!0}},[l]);let I=null!=(r=null==c||null==(t=c[u])?void 0:t.data)?r:[],B=(0,o.useMemo)(()=>{let e=0;for(let t of I)t&&(e=Math.max(e,t.length));return e},[I]),F=(0,o.useMemo)(()=>Array.from({length:B},(e,t)=>r0(t)),[B]),P=(0,o.useCallback)(()=>{c&&(E(e=>[...e.slice(-49),{sheetIdx:u,data:c[u].data}]),W([]))},[c,u]),A=(0,o.useCallback)(e=>{d(t=>{if(!t)return t;let r=[...t];return r[u]={...r[u],data:e},r}),f(!0)},[u]),_=(0,o.useCallback)(e=>{P(),A(e)},[P,A]),z=(0,o.useCallback)(()=>{if(0===D.length||!c)return;let e=D[D.length-1];W(e=>[...e,{sheetIdx:u,data:c[u].data}]),E(e=>e.slice(0,-1)),d(t=>{if(!t)return t;let r=[...t];return r[e.sheetIdx]={...r[e.sheetIdx],data:e.data},r}),e.sheetIdx!==u&&x(e.sheetIdx)},[D,c,u]),O=(0,o.useCallback)(()=>{if(0===R.length||!c)return;let e=R[R.length-1];E(e=>[...e,{sheetIdx:u,data:c[u].data}]),W(e=>e.slice(0,-1)),d(t=>{if(!t)return t;let r=[...t];return r[e.sheetIdx]={...r[e.sheetIdx],data:e.data},r}),e.sheetIdx!==u&&x(e.sheetIdx)},[R,c,u]),U=(0,o.useCallback)(e=>{P();let t=Array.from({length:B},()=>({value:""})),r=[...I];r.splice(e,0,t),A(r)},[P,A,I,B]),H=(0,o.useCallback)(e=>{if(I.length<=1)return;P();let t=[...I];t.splice(e,1),A(t)},[P,A,I]),V=(0,o.useCallback)(e=>{P(),A(I.map(t=>{let r=[...null!=t?t:[]];return r.splice(e,0,{value:""}),r}))},[P,A,I]),J=(0,o.useCallback)(e=>{B<=1||(P(),A(I.map(t=>{let r=[...null!=t?t:[]];return r.splice(e,1),r})))},[P,A,I,B]),K=(0,o.useCallback)(()=>{if(!w)return;let e=w.toRange(I);if(!e)return;P();let t=I.map(e=>e?[...e]:[]);for(let r of e)t[r.row]&&(t[r.row][r.column]={value:""});A(t)},[w,I,P,A]),q=(0,o.useCallback)(async()=>{if(c&&!v){g(!0);try{if(rQ.has(rX(a))){let e="tsv"===rX(a)?" ":",",t=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:",";return e.map(e=>(null!=e?e:[]).map(e=>{let r=e?String(e.value):"";return r.includes(t)||r.includes('"')||r.includes("\n")?'"'.concat(r.replace(/"/g,'""'),'"'):r}).join(t)).join("\n")}(c[u].data,e);if(!(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s,content:t})})).ok)throw Error("Save failed")}else{let e=rY.Wp.book_new();for(let t of c)rY.Wp.book_append_sheet(e,function(e){let t=e.map(e=>(null!=e?e:[]).map(e=>e?e.value:""));return rY.Wp.aoa_to_sheet(t)}(t.data),t.name);let t=(0,rY.M9)(e,{type:"array",bookType:rX(a)});if(!(await fetch("/api/workspace/raw-file?path=".concat(encodeURIComponent(s)),{method:"POST",body:t})).ok)throw Error("Save failed")}f(!1),b(!0),setTimeout(()=>b(!1),1500)}catch(e){console.error("Spreadsheet save error:",e)}finally{g(!1)}}},[c,v,a,s,u]);(0,o.useEffect)(()=>{let e=e=>{let t=e.metaKey||e.ctrlKey;t&&"s"===e.key&&(e.preventDefault(),q()),t&&"z"===e.key&&!e.shiftKey&&(e.preventDefault(),z()),t&&"z"===e.key&&e.shiftKey&&(e.preventDefault(),O()),t&&"f"===e.key&&(e.preventDefault(),L(e=>!e))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[q,z,O]);let G=(0,o.useCallback)(e=>{e.preventDefault();let t=e.target.closest("td");if(!t)return;let r=t.closest("tr");if(!r)return;let n=r.closest("tbody");if(!n)return;let o=Array.from(n.children).indexOf(r),l=Array.from(r.children).indexOf(t)-1;o<0||l<0||S({x:e.clientX,y:e.clientY,row:o,col:l})},[]),$=(0,o.useCallback)(e=>{var t;k(e),null==(t=T.current)||t.activate(e),N(new rZ.MH(new rZ.m9(e,e)))},[]),Z=(0,o.useMemo)(()=>{var e;if(!j)return"";let t=null==(e=I[j.row])?void 0:e[j.column];return t?String(t.value):""},[j,I]),Y=(0,o.useCallback)(e=>{if(!j)return;P();let t=I.map(e=>e?[...e]:[]);t[j.row]||(t[j.row]=[]),t[j.row][j.column]={value:e},A(t)},[j,I,P,A]),Q=(0,o.useMemo)(()=>(function(e,t){if(!t)return null;let r=t.toRange(e);if(!r)return null;let n=0,o=0,l=0;for(let t of r){var a;let r=null==(a=e[t.row])?void 0:a[t.column];if(!r)continue;n++;let s=Number(r.value);""===r.value||isNaN(s)||(o++,l+=s)}return n<=1?null:{count:n,numericCount:o,sum:l,avg:o>0?l/o:0}})(I,w),[I,w]),X=rX(a).toUpperCase()||"SPREADSHEET";return h?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:"12px",padding:"24px"},children:[(0,n.jsx)(r3,{size:32}),(0,n.jsx)("p",{style:{color:"var(--color-text)",fontWeight:500,fontSize:"14px"},children:"Failed to load spreadsheet"}),(0,n.jsx)("p",{style:{color:"var(--color-text-muted)",fontSize:"12px"},children:h})]}):c?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%",background:"var(--color-bg)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:i?"6px 10px":"8px 16px",borderBottom:"1px solid var(--color-border)",background:"var(--color-surface)",flexShrink:0},children:[(0,n.jsx)(r3,{size:16}),(0,n.jsx)("span",{style:{fontSize:i?"12px":"13px",fontWeight:600,color:"var(--color-text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a}),(0,n.jsx)("span",{style:{fontSize:"10px",padding:"1px 6px",borderRadius:"4px",background:"var(--color-surface-hover)",color:"var(--color-text-muted)",fontWeight:500,flexShrink:0},children:X}),m&&(0,n.jsx)("span",{style:{fontSize:"10px",padding:"1px 6px",borderRadius:"4px",background:"var(--color-warning)",color:"#fff",fontWeight:500,flexShrink:0},children:"Unsaved"}),y&&(0,n.jsx)("span",{style:{fontSize:"10px",padding:"1px 6px",borderRadius:"4px",background:"var(--color-success)",color:"#fff",fontWeight:500,flexShrink:0},children:"Saved"}),(0,n.jsx)("div",{style:{flex:1}}),!i&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"2px"},children:[(0,n.jsx)(r4,{onClick:q,title:"Save (⌘S)",disabled:!m||v,accent:m,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}),(0,n.jsx)("path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}),(0,n.jsx)("path",{d:"M7 3v4a1 1 0 0 0 1 1h7"})]})}),(0,n.jsx)(r5,{}),(0,n.jsx)(r4,{onClick:z,title:"Undo (⌘Z)",disabled:0===D.length,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 7v6h6"}),(0,n.jsx)("path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"})]})}),(0,n.jsx)(r4,{onClick:O,title:"Redo (⌘⇧Z)",disabled:0===R.length,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 7v6h-6"}),(0,n.jsx)("path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"})]})}),(0,n.jsx)(r5,{}),(0,n.jsx)(r4,{onClick:()=>j&&U(j.row),title:"Insert row above",disabled:!j,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]})}),(0,n.jsx)(r4,{onClick:()=>j&&V(j.column),title:"Insert column left",disabled:!j,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("path",{d:"M12 8v8"}),(0,n.jsx)("path",{d:"M8 12h8"})]})}),(0,n.jsx)(r5,{}),(0,n.jsx)(r4,{onClick:()=>L(e=>!e),title:"Find (⌘F)",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]})})]}),i&&m&&(0,n.jsx)(r4,{onClick:q,title:"Save (⌘S)",disabled:v,accent:!0,children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}),(0,n.jsx)("path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}),(0,n.jsx)("path",{d:"M7 3v4a1 1 0 0 0 1 1h7"})]})})]}),!i&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"4px 16px",borderBottom:"1px solid var(--color-border)",background:"var(--color-surface)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--color-text-muted)",minWidth:"36px",textAlign:"center",padding:"2px 6px",borderRadius:"4px",background:"var(--color-surface-hover)",fontFamily:"monospace"},children:j?"".concat(r0(j.column)).concat(j.row+1):"\xa0"}),(0,n.jsx)("div",{style:{width:"1px",height:"18px",background:"var(--color-border)",flexShrink:0}}),(0,n.jsx)("span",{style:{fontSize:"11px",fontWeight:500,color:"var(--color-text-muted)",flexShrink:0},children:"fx"}),(0,n.jsx)("input",{type:"text",value:Z,onChange:e=>Y(e.target.value),placeholder:"Select a cell",style:{flex:1,background:"transparent",border:"none",outline:"none",fontSize:"12px",color:"var(--color-text)",fontFamily:"monospace"}})]}),M&&(0,n.jsx)(r2,{data:I,onNavigate:$,onClose:()=>L(!1)}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",position:"relative"},onContextMenu:G,children:(0,n.jsx)(rZ.Ay,{ref:T,data:I,onChange:_,columnLabels:F,onActivate:k,onSelect:N,darkMode:"undefined"!=typeof document&&document.documentElement.classList.contains("dark"),className:"spreadsheet-editor-grid"})}),(0,n.jsx)(r1,{state:C,onClose:()=>S(null),onInsertRowAbove:()=>C&&U(C.row),onInsertRowBelow:()=>C&&U(C.row+1),onInsertColLeft:()=>C&&V(C.col),onInsertColRight:()=>C&&V(C.col+1),onDeleteRow:()=>C&&H(C.row),onDeleteCol:()=>C&&J(C.col),onClearCells:K}),c.length>1&&(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:0,borderTop:"1px solid var(--color-border)",background:"var(--color-surface)",overflow:"auto",flexShrink:0},children:c.map((e,t)=>(0,n.jsxs)("button",{type:"button",onClick:()=>x(t),style:{padding:i?"4px 10px":"6px 16px",fontSize:i?"10px":"11px",fontWeight:t===u?600:400,color:t===u?"var(--color-text)":"var(--color-text-muted)",background:t===u?"var(--color-bg)":"transparent",border:"none",borderRight:"1px solid var(--color-border)",cursor:"pointer",whiteSpace:"nowrap",transition:"background 0.1s",position:"relative"},children:[e.name,t===u&&(0,n.jsx)("div",{style:{position:"absolute",top:0,left:0,right:0,height:"2px",background:"var(--color-accent)",borderRadius:"0 0 2px 2px"}})]},e.name))}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:i?"3px 10px":"4px 16px",borderTop:"1px solid var(--color-border)",background:"var(--color-surface)",fontSize:i?"10px":"11px",color:"var(--color-text-muted)",flexShrink:0,gap:"12px"},children:[(0,n.jsxs)("span",{children:[I.length," row",1!==I.length?"s":""," \xd7 ",B," col",1!==B?"s":"",c.length>1?" \xb7 ".concat(c.length," sheets"):""]}),Q&&(0,n.jsxs)("span",{style:{textAlign:"right"},children:["Count: ",Q.count,Q.numericCount>0&&(0,n.jsxs)(n.Fragment,{children:[" \xb7 ","Sum: ",Q.sum.toLocaleString()," \xb7 ","Avg: ",Q.avg.toLocaleString(void 0,{maximumFractionDigits:2})]})]})]})]}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:"12px"},children:[(0,n.jsx)("div",{className:"animate-spin",style:{width:"20px",height:"20px",border:"2px solid var(--color-border)",borderTopColor:"var(--color-accent)",borderRadius:"50%"}}),(0,n.jsx)("p",{style:{color:"var(--color-text-muted)",fontSize:"12px"},children:"Loading spreadsheet..."})]})}function r3(e){let{size:t=16}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"#22c55e",flexShrink:0},children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,n.jsx)("path",{d:"M8 13h2"}),(0,n.jsx)("path",{d:"M14 13h2"}),(0,n.jsx)("path",{d:"M8 17h2"}),(0,n.jsx)("path",{d:"M14 17h2"})]})}var r8=r(35778);let r7=null;function r9(e){let{filename:t,rawUrl:r,contentUrl:l}=e,[a,s]=(0,o.useState)("rendered"),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)(!1),x=(0,o.useCallback)(()=>{s("code"),null===i&&(u(!0),fetch(l).then(e=>e.json()).then(e=>c(e.content)).catch(()=>c("\x3c!-- Failed to load source --\x3e")).finally(()=>u(!1)))},[l,i]);return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-5 py-3 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)(nr,{}),(0,n.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:t}),(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"#f9731618",color:"#f97316",border:"1px solid #f9731630"},children:"HTML"}),(0,n.jsxs)("div",{className:"flex items-center ml-auto rounded-lg p-0.5",style:{background:"var(--color-surface-hover)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>s("rendered"),className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium transition-colors duration-100 cursor-pointer",style:{background:"rendered"===a?"var(--color-surface)":"transparent",color:"rendered"===a?"var(--color-text)":"var(--color-text-muted)",boxShadow:"rendered"===a?"0 1px 2px rgba(0,0,0,0.1)":"none"},children:[(0,n.jsx)(nn,{}),"Preview"]}),(0,n.jsxs)("button",{type:"button",onClick:x,className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium transition-colors duration-100 cursor-pointer",style:{background:"code"===a?"var(--color-surface)":"transparent",color:"code"===a?"var(--color-text)":"var(--color-text-muted)",boxShadow:"code"===a?"0 1px 2px rgba(0,0,0,0.1)":"none"},children:[(0,n.jsx)(no,{}),"Code"]})]}),(0,n.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md transition-colors duration-100",style:{color:"var(--color-text-muted)"},title:"Open in new tab",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nl,{})})]}),"rendered"===a?(0,n.jsx)(ne,{rawUrl:r}):d||null===i?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"w-6 h-6 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):(0,n.jsx)(nt,{content:i})]})}function ne(e){let{rawUrl:t}=e;return(0,n.jsx)("div",{className:"flex-1 overflow-hidden",style:{background:"white"},children:(0,n.jsx)("iframe",{src:t,className:"w-full h-full border-0",sandbox:"allow-same-origin allow-scripts allow-popups",title:"HTML preview",style:{minHeight:"calc(100vh - 120px)"}})})}function nt(e){let{content:t}=e,[r,l]=(0,o.useState)(null),a=(0,o.useMemo)(()=>t.split("\n").length,[t]);return(0,o.useEffect)(()=>{let e=!1;return(!r7&&(r7=(0,r8.O_)({themes:["github-dark","github-light"],langs:["html"]})),r7).then(r=>{e||l(r.codeToHtml(t,{lang:"html",themes:{dark:"github-dark",light:"github-light"}}))}),()=>{e=!0}},[t]),(0,n.jsx)("div",{className:"flex-1 overflow-auto",style:{background:"var(--color-surface)"},children:(0,n.jsxs)("div",{className:"max-w-4xl mx-auto px-6 py-8",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 rounded-t-lg border border-b-0",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[(0,n.jsx)(no,{}),(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"HTML"}),(0,n.jsxs)("span",{className:"text-xs ml-auto",style:{color:"var(--color-text-muted)"},children:[a," lines"]})]}),(0,n.jsx)("div",{className:"code-viewer-content rounded-b-lg border overflow-x-auto",style:{background:"var(--color-bg)",borderColor:"var(--color-border)"},children:r?(0,n.jsx)("div",{className:"code-viewer-highlighted",dangerouslySetInnerHTML:{__html:r}}):(0,n.jsx)("pre",{className:"text-sm leading-6",style:{margin:0},children:(0,n.jsx)("code",{children:t.split("\n").map((e,t)=>(0,n.jsxs)("div",{className:"flex hover:bg-[var(--color-surface-hover)] transition-colors duration-75",children:[(0,n.jsx)("span",{className:"select-none text-right pr-4 pl-4 flex-shrink-0 tabular-nums",style:{color:"var(--color-text-muted)",opacity:.5,minWidth:"3rem",userSelect:"none"},children:t+1}),(0,n.jsx)("span",{className:"pr-4 flex-1",style:{color:"var(--color-text)"},children:e||" "})]},t))})})})]})})}function nr(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f97316",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"}),(0,n.jsx)("line",{x1:"12",x2:"10",y1:"2",y2:"22"})]})}function nn(){return(0,n.jsxs)("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:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function no(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]})}function nl(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}function na(e,t){return"/api/apps/serve/".concat(e,"/").concat(t)}function ns(e){let{appPath:t,manifest:r}=e,l=(0,o.useRef)(null),[a,s]=(0,o.useState)(!0),[i,c]=(0,o.useState)(null),d=na(t,r.entry||"index.html"),u=(0,o.useCallback)(()=>{s(!0),c(null),l.current&&(l.current.src="".concat(d,"?_t=").concat(Date.now()))},[d]),x=(0,o.useCallback)(()=>{s(!1)},[]),h=(0,o.useCallback)(()=>{s(!1),c("Failed to load app")},[]);(0,o.useEffect)(()=>{let e=async e=>{if(!e.data||"dench:request"!==e.data.type)return;let{id:t,method:n,params:o}=e.data,a=l.current;if(!(null==a?void 0:a.contentWindow)||e.source!==a.contentWindow)return;let s=r.permissions||[];try{let e;if("app.getManifest"===n)e=r;else if("app.getTheme"===n)e=document.documentElement.classList.contains("dark")?"dark":"light";else if("db.query"===n&&s.includes("database")){let t=await fetch("/api/workspace/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:null==o?void 0:o.sql})});e=await t.json()}else if("db.execute"===n&&s.includes("database")){let t=await fetch("/api/workspace/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:null==o?void 0:o.sql})});e=await t.json()}else if("files.read"===n&&s.includes("files")){let t=await fetch("/api/workspace/file?path=".concat(encodeURIComponent(null==o?void 0:o.path)));e=await t.json()}else{if(!("files.list"===n&&s.includes("files")))return void a.contentWindow.postMessage({type:"dench:response",id:t,error:"Unknown method or insufficient permissions: ".concat(n)},"*");let r=await fetch("/api/workspace/tree?showHidden=0");e=await r.json()}a.contentWindow.postMessage({type:"dench:response",id:t,result:e},"*")}catch(e){var i;null==(i=a.contentWindow)||i.postMessage({type:"dench:response",id:t,error:e instanceof Error?e.message:"Unknown error"},"*")}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[r]);let p=r.icon&&(r.icon.endsWith(".png")||r.icon.endsWith(".svg")||r.icon.endsWith(".jpg")||r.icon.endsWith(".jpeg")||r.icon.endsWith(".webp"));return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-5 py-2.5 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[p?(0,n.jsx)("img",{src:na(t,r.icon),alt:"",width:20,height:20,className:"rounded flex-shrink-0",style:{objectFit:"cover"}}):(0,n.jsx)(ni,{}),(0,n.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:r.name}),r.version&&(0,n.jsxs)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"var(--color-accent-light)",color:"var(--color-accent)",border:"1px solid color-mix(in srgb, var(--color-accent) 20%, transparent)"},children:["v",r.version]}),(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"#6366f118",color:"#6366f1",border:"1px solid #6366f130"},children:"APP"}),(0,n.jsxs)("div",{className:"flex items-center gap-1 ml-auto",children:[(0,n.jsx)("button",{type:"button",onClick:u,className:"p-1.5 rounded-md transition-colors duration-100 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Reload app",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"}),(0,n.jsx)("path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"}),(0,n.jsx)("path",{d:"M16 16h5v5"})]})}),(0,n.jsx)("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md transition-colors duration-100",style:{color:"var(--color-text-muted)"},title:"Open in new tab",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden relative",style:{background:"white"},children:[a&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 z-10",style:{background:"var(--color-bg)"},children:[p?(0,n.jsx)("img",{src:na(t,r.icon),alt:"",width:48,height:48,className:"rounded-xl",style:{objectFit:"cover"}}):(0,n.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center",style:{background:"var(--color-accent-light)"},children:(0,n.jsx)(ni,{size:24})}),(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsxs)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["Loading ",r.name,"..."]})]}),i&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 z-10",style:{background:"var(--color-bg)"},children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center",style:{background:"color-mix(in srgb, var(--color-error) 10%, transparent)"},children:(0,n.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",x2:"9",y1:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",x2:"15",y1:"9",y2:"15"})]})}),(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:i}),(0,n.jsx)("button",{type:"button",onClick:u,className:"text-xs px-3 py-1.5 rounded-md cursor-pointer",style:{color:"var(--color-accent)",background:"var(--color-accent-light)"},children:"Try again"})]}),(0,n.jsx)("iframe",{ref:l,src:d,className:"w-full h-full border-0",sandbox:"allow-same-origin allow-scripts allow-popups allow-forms",title:r.name,onLoad:x,onError:h,style:{minHeight:"calc(100vh - 120px)"}})]})]})}function ni(e){let{size:t=18}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"#6366f1",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]})}var nc=r(47164);let nd={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",css:"css",scss:"scss",less:"less",html:"html",htm:"html",xml:"xml",svg:"xml",json:"json",jsonc:"json",yaml:"yaml",yml:"yaml",toml:"plaintext",md:"markdown",mdx:"markdown",sh:"shell",bash:"shell",zsh:"shell",fish:"shell",ps1:"powershell",sql:"sql",graphql:"graphql",gql:"graphql",dockerfile:"dockerfile",docker:"dockerfile",makefile:"plaintext",cmake:"plaintext",r:"r",lua:"lua",php:"php",vue:"html",svelte:"html",diff:"plaintext",patch:"plaintext",ini:"ini",env:"ini",tf:"plaintext",proto:"protobuf",zig:"plaintext",elixir:"plaintext",ex:"plaintext",erl:"plaintext",hs:"plaintext",scala:"scala",clj:"clojure",dart:"dart"};function nu(e){var t;let r=e.toLowerCase();return"dockerfile"===r||r.startsWith("dockerfile.")?"dockerfile":"makefile"===r||"gnumakefile"===r?"makefile":"cmakelists.txt"===r?"cmake":null!=(t=r.split(".").pop())?t:""}function nx(e){var t;return null!=(t=nd[nu(e)])?t:"plaintext"}let nh=!1;function np(){return"undefined"!=typeof document&&document.documentElement.classList.contains("dark")}function nm(e){let{content:t,filename:r,filePath:o,className:l}=e,a=nu(r);return"diff"===a||"patch"===a?(0,n.jsx)("div",{className:"max-w-4xl mx-auto px-6 py-8",children:(0,n.jsx)(rA,{diff:t})}):(0,n.jsx)(nf,{content:t,filename:r,filePath:o,className:l})}function nf(e){let{content:t,filename:r,filePath:l,className:a}=e,s=(0,o.useRef)(null),i=(0,o.useRef)(null),[c,d]=(0,o.useState)(np()?"denchclaw-dark":"denchclaw-light"),[u,x]=(0,o.useState)("clean"),[h,p]=(0,o.useState)({line:1,col:1}),m=(0,o.useRef)(null),f=(0,o.useRef)(t),v=nx(r),g=!!l;(0,o.useEffect)(()=>{f.current=t},[t]),(0,o.useEffect)(()=>{let e=document.documentElement,t=new MutationObserver(()=>d(np()?"denchclaw-dark":"denchclaw-light"));return t.observe(e,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let y=(0,o.useCallback)(async()=>{if(!l||!s.current)return;let e=s.current.getValue();x("saving");try{if(!(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:l,content:e})})).ok)throw Error("Save failed");f.current=e,x("saved"),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>x("clean"),2e3)}catch(e){x("error"),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>x("dirty"),3e3)}},[l]),b=(0,o.useCallback)((e,t)=>{s.current=e,i.current=t,nh||(nh=!0,t.editor.defineTheme("denchclaw-light",{base:"vs",inherit:!0,rules:[],colors:{"editor.background":"#ffffff","editor.foreground":"#1c1c1a","editor.lineHighlightBackground":"#f5f4f1","editor.selectionBackground":"#2563eb20","editor.inactiveSelectionBackground":"#2563eb10","editorLineNumber.foreground":"#8a8a82","editorLineNumber.activeForeground":"#44443e","editorIndentGuide.background":"#00000010","editorIndentGuide.activeBackground":"#00000020","editor.selectionHighlightBackground":"#2563eb12","editorCursor.foreground":"#2563eb","editorWhitespace.foreground":"#00000010","editorBracketMatch.background":"#2563eb15","editorBracketMatch.border":"#2563eb40","editorGutter.background":"#ffffff","editorWidget.background":"#ffffff","editorWidget.border":"#00000014","editorSuggestWidget.background":"#ffffff","editorSuggestWidget.border":"#00000014","editorSuggestWidget.selectedBackground":"#f5f4f1","editorHoverWidget.background":"#ffffff","editorHoverWidget.border":"#00000014","input.background":"#f5f5f4","input.border":"#00000014","input.foreground":"#1c1c1a","minimap.background":"#ffffff","scrollbarSlider.background":"#00000012","scrollbarSlider.hoverBackground":"#00000020","scrollbarSlider.activeBackground":"#0000002a"}}),t.editor.defineTheme("denchclaw-dark",{base:"vs-dark",inherit:!0,rules:[],colors:{"editor.background":"#0c0c0b","editor.foreground":"#ececea","editor.lineHighlightBackground":"#1e1e1c","editor.selectionBackground":"#3b82f630","editor.inactiveSelectionBackground":"#3b82f618","editorLineNumber.foreground":"#78776f","editorLineNumber.activeForeground":"#b8b8b0","editorIndentGuide.background":"#ffffff08","editorIndentGuide.activeBackground":"#ffffff14","editor.selectionHighlightBackground":"#3b82f618","editorCursor.foreground":"#3b82f6","editorWhitespace.foreground":"#ffffff08","editorBracketMatch.background":"#3b82f620","editorBracketMatch.border":"#3b82f650","editorGutter.background":"#0c0c0b","editorWidget.background":"#161615","editorWidget.border":"#ffffff14","editorSuggestWidget.background":"#161615","editorSuggestWidget.border":"#ffffff14","editorSuggestWidget.selectedBackground":"#1e1e1c","editorHoverWidget.background":"#161615","editorHoverWidget.border":"#ffffff14","input.background":"#1e1e1c","input.border":"#ffffff14","input.foreground":"#ececea","minimap.background":"#0c0c0b","scrollbarSlider.background":"#ffffff12","scrollbarSlider.hoverBackground":"#ffffff20","scrollbarSlider.activeBackground":"#ffffff2a"}})),t.editor.setTheme(np()?"denchclaw-dark":"denchclaw-light"),e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>{y()}),e.onDidChangeCursorPosition(e=>{p({line:e.position.lineNumber,col:e.position.column})}),e.onDidChangeModelContent(()=>{e.getValue()!==f.current?x("dirty"):x("clean")}),e.focus()},[y]);(0,o.useEffect)(()=>{i.current&&i.current.editor.setTheme(c)},[c]);let j=function(e){let t=nx(e);return"plaintext"===t?nu(e)||"TEXT":t}(r),k=t.split("\n").length;return(0,n.jsxs)("div",{className:"flex flex-col h-full ".concat(null!=a?a:""),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 flex-shrink-0",style:{background:"var(--color-surface)",borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",flexShrink:0},children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]}),(0,n.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:r}),"dirty"===u&&(0,n.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:"var(--color-text-muted)"},title:"Unsaved changes"}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("span",{className:"text-[11px] px-1.5 py-0.5 rounded font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:j.toUpperCase()}),(0,n.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:[k," lines"]}),(0,n.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:["Ln ",h.line,", Col ",h.col]}),g&&(0,n.jsxs)(n.Fragment,{children:["saving"===u&&(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:"Saving..."}),"saved"===u&&(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-success)"},children:"Saved"}),"error"===u&&(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-error)"},children:"Save failed"}),(0,n.jsx)("button",{type:"button",onClick:()=>void y(),disabled:"dirty"!==u,className:"text-[11px] px-2 py-0.5 rounded transition-colors",style:{background:"dirty"===u?"var(--color-accent)":"var(--color-surface-hover)",color:"dirty"===u?"#fff":"var(--color-text-muted)",cursor:"dirty"===u?"pointer":"default",opacity:"dirty"===u?1:.5},children:"Save"})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(nc.Ay,{defaultValue:t,language:v,theme:c,onMount:b,loading:(0,n.jsx)("div",{className:"flex items-center justify-center h-full",style:{background:"var(--color-bg)"},children:(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Loading editor..."})}),options:{readOnly:!g,fontSize:13,lineHeight:20,fontFamily:"'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Menlo, Monaco, 'Courier New', monospace",fontLigatures:!0,minimap:{enabled:!0,scale:1,showSlider:"mouseover"},scrollBeyondLastLine:!0,smoothScrolling:!0,cursorBlinking:"smooth",cursorSmoothCaretAnimation:"on",renderLineHighlight:"all",renderWhitespace:"selection",bracketPairColorization:{enabled:!0},guides:{bracketPairs:!0,indentation:!0,highlightActiveIndentation:!0},stickyScroll:{enabled:!0},folding:!0,foldingHighlight:!0,showFoldingControls:"mouseover",links:!0,wordWrap:"off",padding:{top:8,bottom:8},scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10,verticalSliderSize:10,horizontalSliderSize:10},overviewRulerBorder:!1,hideCursorInOverviewRuler:!0,automaticLayout:!0,tabSize:2,insertSpaces:!1,detectIndentation:!0,formatOnPaste:!1,formatOnType:!1,suggestOnTriggerCharacters:!0,quickSuggestions:!0,contextmenu:!0,mouseWheelZoom:!0,find:{addExtraSpaceOnTop:!1,autoFindInSelection:"multiline",seedSearchStringFromSelection:"selection"}}})})]})}let nv=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","ico","tiff","tif"]),ng=new Set(["mp4","webm","mov","avi","mkv"]),ny=new Set(["mp3","wav","ogg","m4a","aac","flac"]),nb=new Set(["pdf"]);function nj(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return nv.has(n)?"image":ng.has(n)?"video":ny.has(n)?"audio":nb.has(n)?"pdf":null}function nk(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]})}function nw(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}function nN(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65"}),(0,n.jsx)("line",{x1:"11",x2:"11",y1:"8",y2:"14"}),(0,n.jsx)("line",{x1:"8",x2:"14",y1:"11",y2:"11"})]})}function nC(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65"}),(0,n.jsx)("line",{x1:"8",x2:"14",y1:"11",y2:"11"})]})}function nS(e){switch(e){case"image":return"#60a5fa";case"video":return"#c084fc";case"audio":return"#f59e0b";case"pdf":return"#ef4444"}}function nM(e){let{url:t,filename:r,mediaType:o,filePath:l}=e;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-5 py-3 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)(nR,{mediaType:o}),(0,n.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:r}),(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"".concat(nS(o),"18"),color:nS(o),border:"1px solid ".concat(nS(o),"30")},children:function(e){switch(e){case"image":return"Image";case"video":return"Video";case"audio":return"Audio";case"pdf":return"PDF"}}(o)}),(0,n.jsxs)("div",{className:"flex items-center gap-1 ml-auto",children:[(0,n.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md transition-colors duration-100",style:{color:"var(--color-text-muted)"},title:"Open in new tab",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nw,{})}),(0,n.jsx)("a",{href:t,download:r,className:"p-1.5 rounded-md transition-colors duration-100",style:{color:"var(--color-text-muted)"},title:"Download",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nk,{})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto flex items-center justify-center p-6",style:{background:"var(--color-surface)"},children:["image"===o&&(0,n.jsx)(nL,{url:t,filename:r}),"video"===o&&(0,n.jsx)(nT,{url:t}),"audio"===o&&(0,n.jsx)(nD,{url:t,filename:r}),"pdf"===o&&(0,n.jsx)(nE,{url:t})]}),l&&(0,n.jsx)("div",{className:"px-5 py-2 border-t flex-shrink-0 flex items-center",style:{borderColor:"var(--color-border)"},children:(0,n.jsx)("span",{className:"text-[11px] truncate",style:{color:"var(--color-text-muted)",fontFamily:"'SF Mono', 'Fira Code', monospace"},children:l})})]})}function nL(e){let{url:t,filename:r}=e,[l,a]=(0,o.useState)(1),[s,i]=(0,o.useState)(!1),c=(0,o.useCallback)(()=>a(e=>Math.min(1.5*e,5)),[]),d=(0,o.useCallback)(()=>a(e=>Math.max(e/1.5,.25)),[]),u=(0,o.useCallback)(()=>a(1),[]);return s?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-3 py-12",children:[(0,n.jsx)("span",{className:"text-4xl",style:{opacity:.3},children:"\uD83D\uDDBC"}),(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Failed to load image"})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center gap-4 w-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{type:"button",onClick:d,className:"p-1.5 rounded-md transition-colors duration-100 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Zoom out",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nC,{})}),(0,n.jsxs)("button",{type:"button",onClick:u,className:"px-2 py-1 rounded-md text-[11px] tabular-nums transition-colors duration-100 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Reset zoom",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[Math.round(100*l),"%"]}),(0,n.jsx)("button",{type:"button",onClick:c,className:"p-1.5 rounded-md transition-colors duration-100 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Zoom in",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(nN,{})})]}),(0,n.jsx)("div",{className:"overflow-auto max-w-full max-h-[calc(100vh-260px)] rounded-xl border",style:{borderColor:"var(--color-border)",backgroundImage:"linear-gradient(45deg, var(--color-surface-hover) 25%, transparent 25%), linear-gradient(-45deg, var(--color-surface-hover) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--color-surface-hover) 75%), linear-gradient(-45deg, transparent 75%, var(--color-surface-hover) 75%)",backgroundSize:"20px 20px",backgroundPosition:"0 0, 0 10px, 10px -10px, -10px 0px"},children:(0,n.jsx)("img",{src:t,alt:r,onError:()=>i(!0),style:{transform:"scale(".concat(l,")"),transformOrigin:"center center",transition:"transform 200ms ease",maxWidth:l<=1?"100%":"none",display:"block"},draggable:!1})})]})}function nT(e){let{url:t}=e;return(0,n.jsx)("div",{className:"w-full max-w-4xl",children:(0,n.jsx)("video",{src:t,controls:!0,className:"w-full rounded-xl border",style:{borderColor:"var(--color-border)",maxHeight:"calc(100vh - 220px)",background:"#000"}})})}function nD(e){let{url:t,filename:r}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center gap-6 py-8",children:[(0,n.jsx)("div",{className:"w-32 h-32 rounded-2xl flex items-center justify-center",style:{background:"linear-gradient(135deg, #f59e0b20, #f59e0b10)",border:"1px solid #f59e0b30"},children:(0,n.jsxs)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]})}),(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:r}),(0,n.jsx)("audio",{src:t,controls:!0,className:"w-full max-w-md"})]})}function nE(e){let{url:t}=e;return(0,n.jsx)("div",{className:"w-full h-full flex flex-col",children:(0,n.jsx)("iframe",{src:t,className:"w-full flex-1 rounded-xl border",style:{borderColor:"var(--color-border)",minHeight:"calc(100vh - 220px)",background:"white"},title:"PDF viewer"})})}function nR(e){let{mediaType:t}=e,r=nS(t);switch(t){case"image":return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,n.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,n.jsx)("path",{d:"M10 9H8"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"})]})}}function nW(e){let{size:t=16}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]})}function nI(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]})}function nB(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function nF(){return(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)("circle",{cx:"12",cy:"12",r:"1"})})}function nP(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"6 3 20 12 6 21 6 3"})})}function nA(e){let{direction:t}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:"left"===t?(0,n.jsx)("path",{d:"m15 18-6-6 6-6"}):(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}function n_(e){let{active:t,direction:r}=e;return(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:t?1:.25},children:"asc"===r?(0,n.jsx)("path",{d:"m5 12 7-7 7 7"}):(0,n.jsx)("path",{d:"m19 12-7 7-7-7"})})}function nz(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):""}function nO(e){let t=e.toUpperCase();return t.includes("INT")||t.includes("BIGINT")||t.includes("SMALLINT")||t.includes("TINYINT")||t.includes("HUGEINT")?{label:"int",color:"#c084fc"}:t.includes("FLOAT")||t.includes("DOUBLE")||t.includes("DECIMAL")||t.includes("NUMERIC")||t.includes("REAL")?{label:"float",color:"#c084fc"}:t.includes("BOOL")?{label:"bool",color:"#f59e0b"}:t.includes("VARCHAR")||t.includes("TEXT")||t.includes("STRING")||t.includes("CHAR")||"UUID"===t||"BLOB"===t?{label:t.includes("UUID")?"uuid":"text",color:"#22c55e"}:t.includes("TIMESTAMP")||t.includes("DATETIME")?{label:"timestamp",color:"#60a5fa"}:t.includes("DATE")?{label:"date",color:"#60a5fa"}:t.includes("TIME")?{label:"time",color:"#60a5fa"}:t.includes("JSON")?{label:"json",color:"#fb923c"}:{label:e.toLowerCase(),color:"var(--color-text-muted)"}}function nU(){return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-5 p-8",children:[(0,n.jsx)("div",{className:"w-16 h-16 rounded-2xl flex items-center justify-center",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},children:(0,n.jsx)(nW,{size:32})}),(0,n.jsxs)("div",{className:"text-center max-w-sm",children:[(0,n.jsx)("h3",{className:"text-sm font-medium mb-1",style:{color:"var(--color-text)"},children:"DuckDB is not installed"}),(0,n.jsx)("p",{className:"text-xs leading-relaxed",style:{color:"var(--color-text-muted)"},children:"The DuckDB CLI is required to view database files and workspace data. Click below to install it automatically."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{let e=new URLSearchParams(window.location.search);e.set("send","install duckdb"),window.location.href="/?".concat(e.toString())},className:"flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors cursor-pointer",style:{background:"var(--color-accent)",color:"white"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]}),"Install DuckDB"]})]})}function nH(e){let{dbPath:t,filename:r}=e,[l,a]=(0,o.useState)([]),[s,i]=(0,o.useState)(!0),[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)(!0),[h,p]=(0,o.useState)(null),[m,f]=(0,o.useState)([]),[v,g]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(0),[w,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(""),[M,L]=(0,o.useState)(null),[T,D]=(0,o.useState)(null),[E,R]=(0,o.useState)(!1),[W,I]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=!1;return async function(){i(!0),d(null);try{let o=await fetch("/api/workspace/db/introspect?path=".concat(encodeURIComponent(t)));if(!o.ok){let e=await o.json().catch(()=>({}));throw Error(e.error||"HTTP ".concat(o.status))}let l=await o.json();if(!e)if(!1===l.duckdb_available)x(!1);else{var r,n;a(null!=(n=l.tables)?n:[]),(null==(r=l.tables)?void 0:r.length)>0&&p(l.tables[0].table_name)}}catch(t){e||d(t instanceof Error?t.message:"Failed to introspect database")}finally{e||i(!1)}}(),()=>{e=!0}},[t]);let B=(0,o.useCallback)(async(e,r)=>{g(!0);try{var n;let o=e.replace(/"/g,'""'),l='SELECT * FROM "'.concat(o,'" LIMIT ').concat(100," OFFSET ").concat(r),a=await fetch("/api/workspace/db/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t,sql:l})});if(!a.ok)return void f([]);let s=await a.json();f(null!=(n=s.rows)?n:[])}catch(e){f([])}finally{g(!1)}},[t]);(0,o.useEffect)(()=>{h&&(b(null),B(h,100*j))},[h,j,B]);let F=(0,o.useCallback)(async()=>{if(C.trim()){R(!0),D(null),L(null);try{let r=await fetch("/api/workspace/db/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t,sql:C})}),n=await r.json();if(r.ok){var e;L(null!=(e=n.rows)?e:[])}else D(n.error||"HTTP ".concat(r.status))}catch(e){D(e instanceof Error?e.message:"Query failed")}finally{R(!1)}}},[t,C]),P=(0,o.useMemo)(()=>{var e;return null!=(e=l.find(e=>e.table_name===h))?e:null},[l,h]),A=(0,o.useMemo)(()=>{let e=w&&M?M:m;return y?[...e].toSorted((e,t)=>{let r=nz(e[y.column]),n=nz(t[y.column]),o=r.localeCompare(n,void 0,{numeric:!0});return"asc"===y.direction?o:-o}):e},[w,M,m,y]),_=e=>{b(t=>(null==t?void 0:t.column)===e?"asc"===t.direction?{column:e,direction:"desc"}:null:{column:e,direction:"asc"})},z=(0,o.useMemo)(()=>{let e=w&&M?M:m;return 0===e.length?[]:Object.keys(e[0])},[w,M,m]),O=(0,o.useMemo)(()=>{var e;let t=null==(e=r.split(".").pop())?void 0:e.toLowerCase();return"duckdb"===t?"DuckDB":"sqlite"===t||"sqlite3"===t?"SQLite":"postgres"===t?"PostgreSQL":"Database"},[r]);return s?(0,n.jsxs)("div",{className:"flex items-center justify-center h-full gap-3",children:[(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Loading database..."})]}):c?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-4 p-8",children:[(0,n.jsx)(nW,{size:48}),(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Failed to open database"}),(0,n.jsx)("p",{className:"text-xs px-3 py-2 rounded-lg max-w-md text-center",style:{background:"var(--color-surface)",color:"#f87171"},children:c})]}):u?(0,n.jsxs)("div",{className:"flex h-full",children:[(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 border-r flex flex-col overflow-hidden",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("div",{className:"px-3 py-3 border-b flex items-center gap-2",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:(0,n.jsx)(nW,{size:18})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-xs font-medium truncate",style:{color:"var(--color-text)"},children:r}),(0,n.jsxs)("div",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:[O," \xb7 ",l.length," table",1!==l.length?"s":""]})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto py-1",children:0===l.length?(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs",style:{color:"var(--color-text-muted)"},children:"No tables found"}):l.map(e=>{var t;let r=e.table_name.startsWith("v_"),o=h===e.table_name;return(0,n.jsxs)("button",{type:"button",onClick:()=>{p(e.table_name),k(0),N(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors duration-75 cursor-pointer",style:{background:o?"var(--color-surface-hover)":"transparent",color:o?"var(--color-text)":"var(--color-text-muted)"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{className:"flex-shrink-0",style:{color:r?"#60a5fa":"var(--color-accent)"},children:r?(0,n.jsx)(nB,{}):(0,n.jsx)(nI,{})}),(0,n.jsx)("span",{className:"truncate flex-1",children:e.table_name}),(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] tabular-nums",style:{color:"var(--color-text-muted)"},children:(t=e.estimated_row_count)>=1e6?"".concat((t/1e6).toFixed(1),"M"):t>=1e3?"".concat((t/1e3).toFixed(1),"K"):String(t)})]},e.table_name)})}),(0,n.jsx)("div",{className:"px-3 py-2 border-t",style:{borderColor:"var(--color-border)"},children:(0,n.jsxs)("button",{type:"button",onClick:()=>N(!w),className:"w-full flex items-center justify-center gap-1.5 py-1.5 rounded-md text-xs font-medium transition-colors duration-100 cursor-pointer",style:{background:w?"var(--color-accent-light)":"var(--color-surface-hover)",color:w?"var(--color-accent)":"var(--color-text-muted)",border:"1px solid ".concat(w?"var(--color-accent)":"var(--color-border)")},children:[(0,n.jsx)(nP,{}),"SQL Query"]})})]}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:w?(0,n.jsx)(nJ,{sqlInput:C,setSqlInput:S,queryResult:M,queryError:T,queryRunning:E,runQuery:F,dataColumns:z,sortedData:A,sort:y,onSort:_}):P?(0,n.jsx)(nV,{table:P,data:A,dataLoading:v,dataColumns:z,sort:y,onSort:_,page:j,pageSize:100,onPageChange:k,showSchema:W,onToggleSchema:()=>I(!W)}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Select a table to view its data"})})})]}):(0,n.jsx)(nU,{})}function nV(e){let{table:t,data:r,dataLoading:o,dataColumns:l,sort:a,onSort:s,page:i,pageSize:c,onPageChange:d,showSchema:u,onToggleSchema:x}=e,h=t.estimated_row_count,p=Math.max(1,Math.ceil(h/c));return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2.5 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:(0,n.jsx)(nI,{})}),(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:t.table_name}),(0,n.jsxs)("div",{className:"flex items-center gap-2 ml-auto",children:[(0,n.jsxs)("span",{className:"text-[10px] px-2 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[t.estimated_row_count.toLocaleString()," rows"]}),(0,n.jsxs)("span",{className:"text-[10px] px-2 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[t.column_count," columns"]}),(0,n.jsx)("button",{type:"button",onClick:x,className:"text-[10px] px-2 py-0.5 rounded-full cursor-pointer transition-colors duration-100",style:{background:u?"rgba(96, 165, 250, 0.15)":"var(--color-surface)",color:u?"#60a5fa":"var(--color-text-muted)",border:"1px solid ".concat(u?"#60a5fa":"var(--color-border)")},children:"Schema"})]})]}),u&&(0,n.jsx)("div",{className:"px-4 py-3 border-b overflow-x-auto flex-shrink-0",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:(0,n.jsx)("div",{className:"flex flex-wrap gap-x-6 gap-y-1.5",children:t.columns.map(e=>{let t=nO(e.type);return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs",children:[(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(nF,{})}),(0,n.jsx)("span",{className:"font-medium",style:{color:"var(--color-text)"},children:e.name}),(0,n.jsx)("span",{className:"px-1 py-px rounded text-[10px]",style:{background:"".concat(t.color,"18"),color:t.color},children:t.label}),e.is_nullable&&(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)",opacity:.5},children:"null"})]},e.name)})})}),(0,n.jsx)("div",{className:"flex-1 overflow-auto relative",children:o?(0,n.jsx)("div",{className:"flex items-center justify-center h-32",children:(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):0===r.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-20 gap-2",children:[(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.4},children:(0,n.jsx)(nI,{})}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No data"})]}):(0,n.jsx)(nK,{columns:l,rows:r,sort:a,onSort:s,schemaColumns:t.columns})}),h>c&&(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-t flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["Page ",i+1," of ",p]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{type:"button",disabled:0===i,onClick:()=>d(i-1),className:"p-1 rounded transition-colors duration-100 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(nA,{direction:"left"})}),(0,n.jsx)("button",{type:"button",disabled:i>=p-1,onClick:()=>d(i+1),className:"p-1 rounded transition-colors duration-100 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(nA,{direction:"right"})})]})]})]})}function nJ(e){let{sqlInput:t,setSqlInput:r,queryResult:o,queryError:l,queryRunning:a,runQuery:s,dataColumns:i,sortedData:c,sort:d,onSort:u}=e;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsx)("div",{className:"px-4 py-3 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("textarea",{value:t,onChange:e=>r(e.target.value),placeholder:"SELECT * FROM table_name LIMIT 100",className:"w-full text-xs rounded-lg px-3 py-2 resize-none outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)",fontFamily:"'SF Mono', 'Fira Code', 'JetBrains Mono', monospace",minHeight:"60px"},onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),s())}}),(0,n.jsx)("div",{className:"text-[10px] mt-1",style:{color:"var(--color-text-muted)"},children:"Press Cmd+Enter to run"})]}),(0,n.jsxs)("button",{type:"button",onClick:s,disabled:a||!t.trim(),className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"var(--color-accent)",color:"white"},children:[a?(0,n.jsx)("div",{className:"w-3.5 h-3.5 border-2 rounded-full animate-spin",style:{borderColor:"rgba(255,255,255,0.3)",borderTopColor:"white"}}):(0,n.jsx)(nP,{}),"Run"]})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[l&&(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("div",{className:"px-3 py-2 rounded-lg text-xs",style:{background:"rgba(248, 113, 113, 0.1)",color:"#f87171",border:"1px solid rgba(248, 113, 113, 0.2)"},children:l})}),null!==o&&0===o.length&&!l&&(0,n.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Query returned no results"})}),null!==o&&o.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-4 py-1.5",children:(0,n.jsxs)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:[o.length," row",1!==o.length?"s":""]})}),(0,n.jsx)(nK,{columns:i,rows:c,sort:d,onSort:u})]}),null===o&&!l&&(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:[(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.3},children:(0,n.jsx)(nP,{})}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Write a SQL query and press Run"})]})]})]})}function nK(e){let{columns:t,rows:r,sort:o,onSort:l,schemaColumns:a}=e;return(0,n.jsxs)("table",{className:"w-full text-xs",style:{borderCollapse:"separate",borderSpacing:0},children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"text-right px-2 py-2 font-normal whitespace-nowrap border-b sticky top-0 z-[1]",style:{color:"var(--color-text-muted)",borderColor:"var(--color-border)",background:"var(--color-surface)",width:"2.5rem",opacity:.5},children:"#"}),t.map(e=>{let t=null==a?void 0:a.find(t=>t.name===e),r=t?nO(t.type):null;return(0,n.jsx)("th",{className:"text-left px-3 py-2 font-medium whitespace-nowrap border-b cursor-pointer select-none sticky top-0 z-[1]",style:{color:"var(--color-text-muted)",borderColor:"var(--color-border)",background:"var(--color-surface)"},onClick:()=>l(e),children:(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[e,r&&(0,n.jsx)("span",{className:"text-[9px] px-1 rounded",style:{color:r.color,opacity:.6},children:r.label}),(0,n.jsx)(n_,{active:(null==o?void 0:o.column)===e,direction:(null==o?void 0:o.column)===e?o.direction:"asc"})]})},e)})]})}),(0,n.jsx)("tbody",{children:r.map((e,r)=>(0,n.jsxs)("tr",{className:"transition-colors duration-75 group",style:{background:r%2==0?"transparent":"var(--color-surface)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background=r%2==0?"transparent":"var(--color-surface)"},children:[(0,n.jsx)("td",{className:"text-right px-2 py-1.5 border-b tabular-nums",style:{color:"var(--color-text-muted)",borderColor:"var(--color-border)",opacity:.4},children:r+1}),t.map(t=>(0,n.jsx)("td",{className:"px-3 py-1.5 border-b whitespace-nowrap",style:{borderColor:"var(--color-border)",color:"var(--color-text)"},children:(0,n.jsx)(nq,{value:e[t]})},t))]},r))})]})}function nq(e){let{value:t}=e;if(null==t)return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.4,fontStyle:"italic"},children:"null"});if("boolean"==typeof t)return(0,n.jsx)("span",{style:{color:t?"#22c55e":"#f87171"},children:t?"true":"false"});if("number"==typeof t)return(0,n.jsx)("span",{className:"tabular-nums",children:t});let r=nz(t);return r.length>120?(0,n.jsxs)("span",{title:r,className:"cursor-help",children:[r.slice(0,120),(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:"..."})]}):(0,n.jsx)("span",{children:r})}var nG=r(69176),n$=r(87131),nZ=r(22856),nY=r(3087),nQ=r(86233),nX=r(79919),n0=r(34872),n1=r(8466),n2=r(83879),n4=r(14273),n5=r(54602),n6=r(95107),n3=r(95573),n8=r(75643),n7=r(97199),n9=r(52454),oe=r(47697),ot=r(45679),or=r(47325),on=r(68996),oo=r(77704);function ol(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return"docx"===n||"doc"===n}function oa(e){var t;return(null==(t=e.split(".").pop())?void 0:t.toLowerCase())==="txt"}function os(e){return e.trim()?e.split("\n").map(e=>"<p>".concat(e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")||"<br>","</p>")).join(""):"<p></p>"}function oi(e){var t,l,a,s,i,c;let{mode:d,initialHtml:u,filePath:x,onSave:h,compact:p}=e,[m,f]=(0,o.useState)(!1),[v,g]=(0,o.useState)("idle"),[y,b]=(0,o.useState)(!1),j=(0,o.useRef)(null),k=(0,o.useRef)(null),w=null!=(s=x.split("/").pop())?s:x,N="txt"===d,C=(0,nG.hG)({extensions:[nZ.A.configure({codeBlock:{HTMLAttributes:{class:"code-block"}}}),n3.A,ot.A,or.A,n7.xJ,n9.A,oe.Ay.configure({multicolor:!0}),n8.A.configure({types:["heading","paragraph"]}),nY.Ay.configure({inline:!1,allowBase64:!0,HTMLAttributes:{class:"editor-image"}}),nQ.Ay.configure({openOnClick:!1,autolink:!0,HTMLAttributes:{class:"editor-link",rel:"noopener"}}),nX.XI.configure({resizable:!1}),n0.A,n1.A,n2.h,n4.A,n5.A.configure({nested:!0}),n6.A.configure({placeholder:N?"Start typing...":"Start writing your document..."}),on.A],content:u,immediatelyRender:!1,onUpdate:()=>{b(!0),g("idle")}}),S=(0,o.useCallback)(async e=>{let t=new FormData;t.append("file",e);try{let e=await fetch("/api/workspace/upload",{method:"POST",body:t});if(!e.ok)return null;let r=await e.json();return"/api/workspace/assets/".concat(r.path.replace(/^assets\//,""))}catch(e){return null}},[]),M=(0,o.useCallback)(async e=>{if(C)for(let t of e){let e=await S(t);e&&C.chain().focus().setImage({src:e,alt:t.name}).run()}},[C,S]);(0,o.useEffect)(()=>{if(!C)return;let e=C.view.dom,t=e=>{var t,r;if(!(null==(r=e.dataTransfer)||null==(t=r.files)?void 0:t.length))return;let n=Array.from(e.dataTransfer.files).filter(e=>e.type.startsWith("image/"));0!==n.length&&(e.preventDefault(),e.stopPropagation(),M(n))},r=e=>{var t,r;(null==(r=e.dataTransfer)||null==(t=r.types)?void 0:t.includes("Files"))&&e.preventDefault()},n=e=>{if(!e.clipboardData)return;let t=Array.from(e.clipboardData.files).filter(e=>e.type.startsWith("image/"));t.length>0&&(e.preventDefault(),e.stopPropagation(),M(t))};return e.addEventListener("drop",t),e.addEventListener("dragover",r),e.addEventListener("paste",n),()=>{e.removeEventListener("drop",t),e.removeEventListener("dragover",r),e.removeEventListener("paste",n)}},[C,M]);let L=(0,o.useCallback)(async()=>{if(C&&!m){f(!0),g("idle");try{if(N){let e=C.getText();if(!(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:x,content:e})})).ok)throw Error("Save failed")}else{let e=C.getHTML(),{default:t}=await Promise.all([r.e(515),r.e(8732),r.e(5360),r.e(2457),r.e(4062)]).then(r.bind(r,77373)),n=await t(e,void 0,{table:{row:{cantSplit:!0}},footer:!0,pageNumber:!0}),o=new FormData;if(o.append("file",n),o.append("path",x),!(await fetch("/api/workspace/write-binary",{method:"POST",body:o})).ok)throw Error("Save failed")}g("saved"),b(!1),null==h||h(),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>g("idle"),2e3)}catch(e){g("error")}finally{f(!1)}}},[C,x,m,N,h]);if((0,o.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),L())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[L]),!C)return(0,n.jsxs)("div",{className:"animate-pulse space-y-3 py-4 px-6",children:[(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"80%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"60%"}}),(0,n.jsx)("div",{className:"h-4 rounded",style:{background:"var(--color-surface)",width:"70%"}})]});let T=null!=(i=null==(t=C.storage.characterCount)?void 0:t.words())?i:0,D=null!=(c=null==(l=C.storage.characterCount)?void 0:l.characters())?c:0;return(0,n.jsxs)("div",{className:"rich-doc-editor ".concat(p?"rich-doc-editor--compact":""),children:[(0,n.jsxs)("div",{className:"rich-doc-topbar",children:[(0,n.jsxs)("div",{className:"rich-doc-topbar-left",children:[(0,n.jsx)(oR,{mode:d}),(0,n.jsx)("span",{className:"rich-doc-filename",children:w}),y&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-unsaved",children:"Unsaved changes"}),"saved"===v&&!y&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-saved",children:"Saved"}),"error"===v&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-error",children:"Save failed"})]}),(0,n.jsxs)("div",{className:"rich-doc-topbar-right",children:[(0,n.jsxs)("span",{className:"editor-save-hint",children:["undefined"!=typeof navigator&&(null==(a=navigator.platform)?void 0:a.includes("Mac"))?"⌘":"Ctrl","+S"]}),(0,n.jsx)("button",{type:"button",onClick:()=>void L(),disabled:m||!y,className:"editor-save-button",children:m?"Saving...":"Save"})]})]}),!N&&(0,n.jsx)(oc,{editor:C,onUploadImages:M,imageInputRef:k}),N&&!p&&(0,n.jsxs)("div",{className:"editor-toolbar rich-doc-toolbar-minimal",children:[(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:!1,onClick:()=>C.chain().focus().undo().run(),title:"Undo",disabled:!C.can().undo(),children:(0,n.jsx)(op,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>C.chain().focus().redo().run(),title:"Redo",disabled:!C.can().redo(),children:(0,n.jsx)(om,{})})]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("span",{className:"rich-doc-txt-hint",children:"Plain text — formatting not preserved on save"})]}),!N&&(0,n.jsx)(n$.m,{editor:C,children:(0,n.jsxs)("div",{className:"bubble-menu",children:[(0,n.jsx)(oo.zM,{active:C.isActive("bold"),onClick:()=>C.chain().focus().toggleBold().run(),title:"Bold",children:(0,n.jsx)("strong",{children:"B"})}),(0,n.jsx)(oo.zM,{active:C.isActive("italic"),onClick:()=>C.chain().focus().toggleItalic().run(),title:"Italic",children:(0,n.jsx)("em",{children:"I"})}),(0,n.jsx)(oo.zM,{active:C.isActive("underline"),onClick:()=>C.chain().focus().toggleUnderline().run(),title:"Underline",children:(0,n.jsx)("span",{style:{textDecoration:"underline"},children:"U"})}),(0,n.jsx)(oo.zM,{active:C.isActive("strike"),onClick:()=>C.chain().focus().toggleStrike().run(),title:"Strikethrough",children:(0,n.jsx)("s",{children:"S"})}),(0,n.jsx)(oo.zM,{active:C.isActive("code"),onClick:()=>C.chain().focus().toggleCode().run(),title:"Inline code",children:"<>"}),(0,n.jsx)(oo.zM,{active:C.isActive("link"),onClick:()=>{if(C.isActive("link"))C.chain().focus().unsetLink().run();else{let e=window.prompt("URL:");e&&C.chain().focus().setLink({href:e}).run()}},title:"Link",children:(0,n.jsx)(oS,{size:14})})]})}),(0,n.jsx)("div",{className:"rich-doc-scroll",children:(0,n.jsx)("div",{className:"rich-doc-page ".concat(N?"rich-doc-page--txt":""),children:(0,n.jsx)(nG.$Z,{editor:C})})}),!p&&(0,n.jsxs)("div",{className:"rich-doc-statusbar",children:[(0,n.jsxs)("span",{children:[T.toLocaleString()," word",1!==T?"s":""]}),(0,n.jsx)("span",{className:"rich-doc-statusbar-sep"}),(0,n.jsxs)("span",{children:[D.toLocaleString()," character",1!==D?"s":""]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("span",{className:"rich-doc-statusbar-mode",children:"docx"===d?"DOCX":"TXT"})]}),(0,n.jsx)("input",{ref:k,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{var t;let r=Array.from(null!=(t=e.target.files)?t:[]);r.length>0&&M(r),e.target.value=""}})]})}function oc(e){var t;let{editor:r,onUploadImages:l,imageInputRef:a}=e,[s,i]=(0,o.useState)(!1),[c,d]=(0,o.useState)(!1),u=(0,o.useRef)(null),x=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&i(!1),x.current&&!x.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.jsxs)("div",{className:"editor-toolbar rich-doc-toolbar",children:[(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:!1,onClick:()=>r.chain().focus().undo().run(),title:"Undo",disabled:!r.can().undo(),children:(0,n.jsx)(op,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>r.chain().focus().redo().run(),title:"Redo",disabled:!r.can().redo(),children:(0,n.jsx)(om,{})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsx)(oo.$Q,{children:(0,n.jsx)(ou,{editor:r})}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive("bold"),onClick:()=>r.chain().focus().toggleBold().run(),title:"Bold (Cmd+B)",children:(0,n.jsx)("strong",{children:"B"})}),(0,n.jsx)(oo.IB,{active:r.isActive("italic"),onClick:()=>r.chain().focus().toggleItalic().run(),title:"Italic (Cmd+I)",children:(0,n.jsx)("em",{children:"I"})}),(0,n.jsx)(oo.IB,{active:r.isActive("underline"),onClick:()=>r.chain().focus().toggleUnderline().run(),title:"Underline (Cmd+U)",children:(0,n.jsx)("span",{style:{textDecoration:"underline"},children:"U"})}),(0,n.jsx)(oo.IB,{active:r.isActive("strike"),onClick:()=>r.chain().focus().toggleStrike().run(),title:"Strikethrough",children:(0,n.jsx)("s",{children:"S"})}),(0,n.jsx)(oo.IB,{active:r.isActive("superscript"),onClick:()=>r.chain().focus().toggleSuperscript().run(),title:"Superscript",children:(0,n.jsxs)("span",{children:["X",(0,n.jsx)("sup",{style:{fontSize:"0.6em"},children:"2"})]})}),(0,n.jsx)(oo.IB,{active:r.isActive("subscript"),onClick:()=>r.chain().focus().toggleSubscript().run(),title:"Subscript",children:(0,n.jsxs)("span",{children:["X",(0,n.jsx)("sub",{style:{fontSize:"0.6em"},children:"2"})]})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsxs)("div",{className:"relative",ref:u,children:[(0,n.jsx)(oo.IB,{active:s,onClick:()=>{i(!s),d(!1)},title:"Text color",children:(0,n.jsx)(oD,{color:null!=(t=r.getAttributes("textStyle").color)?t:"currentColor"})}),s&&(0,n.jsx)(oh,{onSelect:e=>{e?r.chain().focus().setColor(e).run():r.chain().focus().unsetColor().run(),i(!1)}})]}),(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsx)(oo.IB,{active:c,onClick:()=>{d(!c),i(!1)},title:"Highlight color",children:(0,n.jsx)(oE,{})}),c&&(0,n.jsx)(oh,{onSelect:e=>{e?r.chain().focus().toggleHighlight({color:e}).run():r.chain().focus().unsetHighlight().run(),d(!1)}})]})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive({textAlign:"left"}),onClick:()=>r.chain().focus().setTextAlign("left").run(),title:"Align left",children:(0,n.jsx)(of,{})}),(0,n.jsx)(oo.IB,{active:r.isActive({textAlign:"center"}),onClick:()=>r.chain().focus().setTextAlign("center").run(),title:"Align center",children:(0,n.jsx)(ov,{})}),(0,n.jsx)(oo.IB,{active:r.isActive({textAlign:"right"}),onClick:()=>r.chain().focus().setTextAlign("right").run(),title:"Align right",children:(0,n.jsx)(og,{})}),(0,n.jsx)(oo.IB,{active:r.isActive({textAlign:"justify"}),onClick:()=>r.chain().focus().setTextAlign("justify").run(),title:"Justify",children:(0,n.jsx)(oy,{})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive("bulletList"),onClick:()=>r.chain().focus().toggleBulletList().run(),title:"Bullet list",children:(0,n.jsx)(ob,{})}),(0,n.jsx)(oo.IB,{active:r.isActive("orderedList"),onClick:()=>r.chain().focus().toggleOrderedList().run(),title:"Ordered list",children:(0,n.jsx)(oj,{})}),(0,n.jsx)(oo.IB,{active:r.isActive("taskList"),onClick:()=>r.chain().focus().toggleTaskList().run(),title:"Task list",children:(0,n.jsx)(ok,{})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive("blockquote"),onClick:()=>r.chain().focus().toggleBlockquote().run(),title:"Blockquote",children:(0,n.jsx)(ow,{})}),(0,n.jsx)(oo.IB,{active:r.isActive("codeBlock"),onClick:()=>r.chain().focus().toggleCodeBlock().run(),title:"Code block",children:(0,n.jsx)(oN,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>r.chain().focus().setHorizontalRule().run(),title:"Horizontal rule",children:(0,n.jsx)(oC,{})})]}),(0,n.jsx)(oo.x_,{}),(0,n.jsxs)(oo.$Q,{children:[(0,n.jsx)(oo.IB,{active:r.isActive("link"),onClick:()=>{if(r.isActive("link"))r.chain().focus().unsetLink().run();else{let e=window.prompt("Link URL:");e&&r.chain().focus().setLink({href:e}).run()}},title:"Insert link",children:(0,n.jsx)(oS,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>{if(l){var e;null==(e=a.current)||e.click()}else{let e=window.prompt("Image URL:");e&&r.chain().focus().setImage({src:e}).run()}},title:"Insert image",children:(0,n.jsx)(oM,{})}),(0,n.jsx)(oo.IB,{active:!1,onClick:()=>r.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),title:"Insert table",children:(0,n.jsx)(oL,{})})]})]})}let od=[{label:"Normal text",level:0},{label:"Heading 1",level:1},{label:"Heading 2",level:2},{label:"Heading 3",level:3},{label:"Heading 4",level:4},{label:"Heading 5",level:5},{label:"Heading 6",level:6}];function ou(e){var t;let{editor:r}=e,[l,a]=(0,o.useState)(!1),s=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=e=>{s.current&&!s.current.contains(e.target)&&a(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let i=null!=(t=od.find(e=>e.level>0&&r.isActive("heading",{level:e.level})))?t:od[0];return(0,n.jsxs)("div",{className:"relative",ref:s,children:[(0,n.jsxs)("button",{type:"button",className:"rich-doc-style-dropdown",onClick:()=>a(!l),title:"Paragraph style",children:[(0,n.jsx)("span",{children:i.label}),(0,n.jsx)(oT,{})]}),l&&(0,n.jsx)("div",{className:"rich-doc-style-menu",children:od.map(e=>(0,n.jsx)("button",{type:"button",className:"rich-doc-style-option ".concat(e.level===i.level?"rich-doc-style-option--active":""),onClick:()=>{0===e.level?r.chain().focus().setParagraph().run():r.chain().focus().toggleHeading({level:e.level}).run(),a(!1)},children:(0,n.jsx)("span",{style:{fontSize:0===e.level?void 0:"".concat(Math.max(.75,1.4-.1*e.level),"rem"),fontWeight:e.level>0?600:400},children:e.label})},e.level))})]})}let ox=[null,"#000000","#434343","#666666","#999999","#b7b7b7","#cccccc","#d9d9d9","#efefef","#ffffff","#980000","#ff0000","#ff9900","#ffff00","#00ff00","#00ffff","#4a86e8","#0000ff","#9900ff","#ff00ff","#e6b8af","#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#c9daf8","#cfe2f3","#d9d2e9","#ead1dc","#dd7e6b","#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#a4c2f4","#9fc5e8","#b4a7d6","#d5a6bd","#cc4125","#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6d9eeb","#6fa8dc","#8e7cc3","#c27ba0"];function oh(e){let{onSelect:t}=e;return(0,n.jsx)("div",{className:"rich-doc-color-palette",children:ox.map(e=>(0,n.jsx)("button",{type:"button",className:"rich-doc-color-swatch",style:{background:null!=e?e:"transparent",border:e?"1px solid var(--color-border)":"2px dashed var(--color-border)"},onClick:()=>t(e),title:null!=e?e:"Remove color",children:!e&&(0,n.jsx)("span",{style:{fontSize:"10px",color:"var(--color-text-muted)"},children:"\xd7"})},null!=e?e:"none"))})}function op(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 7v6h6"}),(0,n.jsx)("path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"})]})}function om(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 7v6h-6"}),(0,n.jsx)("path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"})]})}function of(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"17",x2:"3",y1:"10",y2:"10"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"14",y2:"14"}),(0,n.jsx)("line",{x1:"17",x2:"3",y1:"18",y2:"18"})]})}function ov(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",x2:"6",y1:"10",y2:"10"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"14",y2:"14"}),(0,n.jsx)("line",{x1:"18",x2:"6",y1:"18",y2:"18"})]})}function og(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"21",x2:"7",y1:"10",y2:"10"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"14",y2:"14"}),(0,n.jsx)("line",{x1:"21",x2:"7",y1:"18",y2:"18"})]})}function oy(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"21",x2:"3",y1:"10",y2:"10"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"14",y2:"14"}),(0,n.jsx)("line",{x1:"21",x2:"3",y1:"18",y2:"18"})]})}function ob(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"8",x2:"21",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"8",x2:"21",y1:"12",y2:"12"}),(0,n.jsx)("line",{x1:"8",x2:"21",y1:"18",y2:"18"}),(0,n.jsx)("line",{x1:"3",x2:"3.01",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"3",x2:"3.01",y1:"12",y2:"12"}),(0,n.jsx)("line",{x1:"3",x2:"3.01",y1:"18",y2:"18"})]})}function oj(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"10",x2:"21",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"10",x2:"21",y1:"12",y2:"12"}),(0,n.jsx)("line",{x1:"10",x2:"21",y1:"18",y2:"18"}),(0,n.jsx)("path",{d:"M4 6h1v4"}),(0,n.jsx)("path",{d:"M4 10h2"}),(0,n.jsx)("path",{d:"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"})]})}function ok(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"5",width:"6",height:"6",rx:"1"}),(0,n.jsx)("path",{d:"m3 17 2 2 4-4"}),(0,n.jsx)("line",{x1:"13",x2:"21",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"13",x2:"21",y1:"18",y2:"18"})]})}function ow(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V21z"}),(0,n.jsx)("path",{d:"M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3z"})]})}function oN(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]})}function oC(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("line",{x1:"2",x2:"22",y1:"12",y2:"12"})})}function oS(e){let{size:t=14}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),(0,n.jsx)("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}function oM(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]})}function oL(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]})}function oT(){return(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:"m6 9 6 6 6-6"})})}function oD(e){let{color:t}=e;return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M4 20h16",stroke:t,strokeWidth:"3"}),(0,n.jsx)("path",{d:"m8.5 3 3.5 11 3.5-11"})]})}function oE(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m9 11-6 6v3h9l3-3"}),(0,n.jsx)("path",{d:"m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"})]})}function oR(e){let{mode:t}=e;return"txt"===t?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("line",{x1:"8",x2:"16",y1:"13",y2:"13"}),(0,n.jsx)("line",{x1:"8",x2:"16",y1:"17",y2:"17"}),(0,n.jsx)("line",{x1:"8",x2:"10",y1:"9",y2:"9"})]}):(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#2b579a",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("line",{x1:"8",x2:"16",y1:"13",y2:"13"}),(0,n.jsx)("line",{x1:"8",x2:"16",y1:"17",y2:"17"}),(0,n.jsx)("line",{x1:"8",x2:"10",y1:"9",y2:"9"})]})}function oW(e){let{path:t,onNavigate:r}=e,o=t.startsWith("/"),l=t.split("/").filter(Boolean);return(0,n.jsxs)("nav",{className:"flex items-center gap-1 text-xs md:text-sm py-2 overflow-x-auto min-w-0",children:[(0,n.jsx)("button",{type:"button",onClick:()=>r(""),className:"px-1.5 py-0.5 rounded transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--color-text)",e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--color-text-muted)",e.currentTarget.style.background="transparent"},children:"All Chats"}),l.map((e,t)=>{let a=(o?"/":"")+l.slice(0,t+1).join("/"),s=t===l.length-1;return(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",opacity:.4},children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})}),s?(0,n.jsx)("span",{className:"px-1.5 py-0.5",style:{color:"var(--color-text)"},children:e.replace(/\.md$/,"")}):(0,n.jsx)("button",{type:"button",onClick:()=>r(a),className:"px-1.5 py-0.5 rounded transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--color-text)",e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--color-text-muted)",e.currentTarget.style.background="transparent"},children:e})]},a)})]})}var oI=r(77223),oB=r(90461),oF=r(13170),oP=r(33668),oA=r(86998),o_=r(2183),oz=r(66862),oO=r(7589);function oU(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return(0,oO.QP)((0,oz.$)(t))}function oH(e){let{...t}=e;return(0,n.jsx)(oI.i,{"data-slot":"dropdown-menu",...t})}function oV(e){let{className:t,...r}=e;return(0,n.jsx)(oB.c,{"data-slot":"dropdown-menu-trigger",className:oU("cursor-pointer outline-none ring-0 border-none",t),...r})}function oJ(e){let{align:t="start",alignOffset:r=0,side:o="bottom",sideOffset:l=4,className:a,...s}=e;return(0,n.jsx)(oF.g,{children:(0,n.jsx)(oP.y,{className:"isolate z-[100] outline-none",align:t,alignOffset:r,side:o,sideOffset:l,children:(0,n.jsx)(oA._,{"data-slot":"dropdown-menu-content",className:oU("bg-neutral-100/[0.67] border border-white backdrop-blur-md text-[var(--color-text)] z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] overflow-x-hidden overflow-y-auto rounded-3xl p-1 shadow-[0_0_25px_0_rgba(0,0,0,0.16)] outline-none","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...s})})})}function oK(e){let{className:t,inset:r,variant:o="default",onSelect:l,onClick:a,...s}=e;return(0,n.jsx)(o_.D,{"data-slot":"dropdown-menu-item","data-inset":r,"data-variant":o,className:oU("bg-transparent hover:bg-neutral-400/15 text-sm transition-all relative flex cursor-pointer items-center gap-2 rounded-full px-2 py-1.5 outline-none ring-0 border-none select-none","data-[variant=destructive]:text-[var(--color-error)] data-[variant=destructive]:hover:bg-[var(--color-error)]/10 data-[variant=destructive]:hover:text-[var(--color-error)]",r&&"pl-8","[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","data-disabled:pointer-events-none data-disabled:opacity-50",t),onClick:e=>{null==a||a(e),null==l||l()},...s})}function oq(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 12h14"}),(0,n.jsx)("path",{d:"M12 5v14"})]})}function oG(){return(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M16 3h5v5"}),(0,n.jsx)("path",{d:"m21 3-7 7"}),(0,n.jsx)("path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6"})]})}function o$(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function oZ(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1"})]})}function oY(e){let{sessions:t,activeSessionId:r,activeSessionTitle:l,streamingSessionIds:a,subagents:s,activeSubagentKey:i,onSelectSession:c,onNewSession:d,onSelectSubagent:u,onDeleteSession:x,onRenameSession:h,onCollapse:p,mobile:m,onClose:f,width:v,loading:g=!1}=e,[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(null),[w,N]=(0,o.useState)(""),C=(0,o.useCallback)(e=>{c(e),null==f||f()},[c,f]),S=(0,o.useCallback)(e=>{null==u||u(e),null==f||f()},[u,f]),M=(0,o.useCallback)(e=>{null==x||x(e)},[x]),L=(0,o.useCallback)((e,t)=>{k(e),N(t||"")},[]),T=(0,o.useCallback)(()=>{j&&w.trim()&&(null==h||h(j,w.trim())),k(null),N("")},[j,w,h]),D=(0,o.useMemo)(()=>{let e=new Map;if(!s)return e;for(let t of s){let r=e.get(t.parentSessionId);r||(r=[],e.set(t.parentSessionId,r)),r.push(t)}return e},[s]),E=function(e){let t=new Date,r=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),n=r-864e5,o=r-6048e5,l=r-2592e6,a=[],s=[],i=[],c=[],d=[];for(let t of e){let e=t.updatedAt;e>=r?a.push(t):e>=n?s.push(t):e>=o?i.push(t):e>=l?c.push(t):d.push(t)}let u=[];return a.length>0&&u.push({label:"Today",sessions:a}),s.length>0&&u.push({label:"Yesterday",sessions:s}),i.length>0&&u.push({label:"This Week",sessions:i}),c.length>0&&u.push({label:"This Month",sessions:c}),d.length>0&&u.push({label:"Older",sessions:d}),u}((0,o.useMemo)(()=>t.filter(e=>!e.id.includes(":subagent:")),[t])),R=m?"280px":null!=v?v:260,W=(0,n.jsx)("aside",{className:"flex flex-col h-full shrink-0 ".concat(m?"drawer-right":"border-l"),style:{width:"number"==typeof R?"".concat(R,"px"):R,minWidth:"number"==typeof R?"".concat(R,"px"):R,borderColor:"var(--color-border)",background:"var(--color-sidebar-bg)"},children:(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[(0,n.jsx)("div",{className:"absolute inset-0 overflow-y-auto",style:{paddingTop:40},children:g&&0===t.length?(0,n.jsxs)("div",{className:"px-4 py-8 flex flex-col items-center justify-center min-h-[120px]",children:[(0,n.jsx)(G.V,{name:"braille",className:"text-xl mb-2",style:{color:"var(--color-text-muted)"}}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading…"})]}):0===t.length?(0,n.jsxs)("div",{className:"px-4 py-8 text-center",children:[(0,n.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl flex items-center justify-center mb-3",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:(0,n.jsx)(o$,{})}),(0,n.jsxs)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["No conversations yet.",(0,n.jsx)("br",{}),"Start a new chat to begin."]})]}):(0,n.jsx)("div",{className:"px-2 py-1",children:E.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-2 pt-3 pb-1 text-[10px] font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:e.label}),e.sessions.map(e=>{var t;let o=e.id===r&&!i,l=e.id===y,s=null!=(t=null==a?void 0:a.has(e.id))&&t,c=D.get(e.id);return(0,n.jsxs)("div",{className:"group relative",onMouseEnter:()=>b(e.id),onMouseLeave:()=>b(null),children:[(0,n.jsxs)("div",{className:"flex items-stretch w-full rounded-lg",style:{background:o?"var(--color-chat-sidebar-active-bg)":l?"var(--color-surface-hover)":"transparent"},children:[j===e.id?(0,n.jsx)("form",{className:"flex-1 min-w-0 px-2 py-1.5",onSubmit:e=>{e.preventDefault(),T()},children:(0,n.jsx)("input",{type:"text",value:w,onChange:e=>N(e.target.value),onBlur:T,onKeyDown:e=>{"Escape"===e.key&&(k(null),N(""))},autoFocus:!0,className:"w-full text-xs font-medium px-1 py-0.5 rounded outline-none border",style:{color:"var(--color-text)",background:"var(--color-surface)",borderColor:"var(--color-border)"}})}):(0,n.jsxs)("button",{type:"button",onClick:()=>C(e.id),className:"flex-1 min-w-0 text-left px-2 py-2 rounded-l-lg transition-colors cursor-pointer",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[s&&(0,n.jsx)(G.V,{name:"braille",className:"text-[10px] flex-shrink-0",style:{color:"var(--color-chat-sidebar-muted)"}}),(0,n.jsx)("div",{className:"text-xs font-medium truncate",style:{color:o?"var(--color-chat-sidebar-active-text)":"var(--color-text)"},children:e.title||"Untitled chat"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",style:{paddingLeft:s?"calc(0.375rem + 6px)":void 0},children:[(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:function(e){let t=Math.floor((Date.now()-e)/1e3);if(t<60)return"just now";let r=Math.floor(t/60);if(r<60)return"".concat(r,"m ago");let n=Math.floor(r/60);if(n<24)return"".concat(n,"h ago");let o=Math.floor(n/24);if(o<30)return"".concat(o,"d ago");let l=Math.floor(o/30);return l<12?"".concat(l,"mo ago"):"".concat(Math.floor(l/12),"y ago")}(e.updatedAt)}),e.messageCount>0&&(0,n.jsxs)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:[e.messageCount," msg",1!==e.messageCount?"s":""]})]})]}),x&&(0,n.jsx)("div",{className:"shrink-0 flex items-center pr-1 transition-opacity ".concat(l?"opacity-100":"opacity-0"),children:(0,n.jsxs)(oH,{children:[(0,n.jsx)(oV,{onClick:e=>e.stopPropagation(),className:"flex items-center justify-center w-6 h-6 rounded-md",style:{color:"var(--color-text-muted)"},title:"More options","aria-label":"More options",children:(0,n.jsx)(oZ,{})}),(0,n.jsxs)(oJ,{align:"end",side:"bottom",children:[(0,n.jsxs)(oK,{onSelect:()=>L(e.id,e.title),children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"})}),"Rename"]}),(0,n.jsxs)(oK,{variant:"destructive",onSelect:()=>M(e.id),children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]})]})]})})]}),c&&c.length>0&&(0,n.jsx)("div",{className:"ml-4 border-l",style:{borderColor:"var(--color-border)"},children:c.map(e=>{let t=i===e.childSessionKey,r="running"===e.status,o=e.label||e.task,l=o.length>40?o.slice(0,40)+"...":o;return(0,n.jsx)("button",{type:"button",onClick:()=>S(e.childSessionKey),className:"w-full text-left pl-3 pr-2 py-1.5 rounded-r-lg transition-colors cursor-pointer",style:{background:t?"var(--color-chat-sidebar-active-bg)":"transparent"},children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[r&&(0,n.jsx)(G.V,{name:"braille",className:"text-[9px] flex-shrink-0",style:{color:"var(--color-chat-sidebar-muted)"}}),(0,n.jsx)(oG,{}),(0,n.jsx)("span",{className:"text-[11px] truncate",style:{color:t?"var(--color-chat-sidebar-active-text)":"var(--color-text-muted)"},children:l})]})},e.childSessionKey)})})]},e.id)})]},e.label))})}),(0,n.jsxs)("div",{className:"absolute top-0 left-0 right-0 z-10 flex items-center justify-between border-b px-4 py-2 backdrop-blur-md",style:{height:40,borderColor:"var(--color-border)",background:"color-mix(in srgb, var(--color-sidebar-bg) 80%, transparent)"},children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1 flex items-center gap-1.5",children:[p&&(0,n.jsx)("button",{type:"button",onClick:p,className:"p-1 rounded-md shrink-0 transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Hide chat sidebar (⌘⇧B)",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M15 3v18"})]})}),(0,n.jsx)("span",{className:"text-xs font-medium truncate block",style:{color:"var(--color-text)"},children:"Chats"})]}),(0,n.jsxs)("button",{type:"button",onClick:d,className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium transition-colors cursor-pointer shrink-0 ml-1.5",style:{color:"var(--color-chat-sidebar-active-text)",background:"var(--color-chat-sidebar-active-bg)"},title:"New chat",children:[(0,n.jsx)(oq,{}),"New"]})]})]})});return m?(0,n.jsx)("div",{className:"drawer-backdrop",onClick:()=>void(null==f||f()),children:(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),className:"fixed inset-y-0 right-0 z-50",children:W})}):W}function oQ(e){let{workspaceExists:t,expectedPath:r}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-6 px-8",children:[(0,n.jsx)("div",{className:"w-20 h-20 rounded-2xl flex items-center justify-center",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},children:(0,n.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",opacity:.5},children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"})]})}),(0,n.jsxs)("div",{className:"text-center max-w-md",children:[(0,n.jsx)("h2",{className:"font-instrument text-2xl tracking-tight mb-2",style:{color:"var(--color-text)"},children:t?"Workspace is empty":"No workspace found"}),(0,n.jsx)("p",{className:"text-sm leading-relaxed",style:{color:"var(--color-text-muted)"},children:t?(0,n.jsx)(n.Fragment,{children:"The workspace exists but has no knowledge tree yet. Ask the CRM agent to create objects and documents to populate it."}):(0,n.jsx)(n.Fragment,{children:"The workspace directory was not found. Run the denchclaw bootstrap flow or start a conversation and the agent will set it up automatically in the managed profile."})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 rounded-xl text-sm",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",color:"var(--color-text-muted)",boxShadow:"var(--shadow-sm)"},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-accent)",flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("path",{d:"M12 16v-4"}),(0,n.jsx)("path",{d:"M12 8h.01"})]}),(0,n.jsxs)("span",{children:["Expected location:"," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded-md text-xs",style:{background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:r?r.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Za-z]:[/\\]Users[/\\][^/\\]+/,"~"):"~/.openclaw-dench/workspace-<name>"})]})]}),(0,n.jsxs)("a",{href:"/",className:"flex items-center gap-2 text-sm mt-2",style:{color:"var(--color-accent)"},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]}),"Back to Home"]})]})}var oX=r(40077);function o0(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function o1(){return(0,n.jsxs)("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:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}function o2(e){var t,r;let{filter:o,value:l,onChange:a}=e,s=(null==l?void 0:l.type)==="dateRange"?l:{type:"dateRange"};return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] whitespace-nowrap",style:{color:"var(--color-text-muted)"},children:o.label}),(0,n.jsx)("input",{type:"date",value:null!=(t=s.from)?t:"",onChange:e=>a({...s,from:e.target.value||void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",colorScheme:"dark"}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"to"}),(0,n.jsx)("input",{type:"date",value:null!=(r=s.to)?r:"",onChange:e=>a({...s,to:e.target.value||void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",colorScheme:"dark"}})]})}function o4(e){let{filter:t,value:r,onChange:o,options:l}=e,a=(null==r?void 0:r.type)==="select"?r.value:void 0;return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] whitespace-nowrap",style:{color:"var(--color-text-muted)"},children:t.label}),(0,n.jsxs)("select",{value:null!=a?a:"",onChange:e=>o({type:"select",value:e.target.value||void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none cursor-pointer",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",minWidth:100},children:[(0,n.jsx)("option",{value:"",children:"All"}),l.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})]})}function o5(e){var t;let{filter:r,value:o,onChange:l,options:a}=e,s=(null==o?void 0:o.type)==="multiSelect"&&null!=(t=o.values)?t:[];return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] whitespace-nowrap",style:{color:"var(--color-text-muted)"},children:r.label}),(0,n.jsx)("div",{className:"flex flex-wrap gap-1",children:a.map(e=>{let t=s.includes(e);return(0,n.jsx)("button",{type:"button",onClick:()=>(e=>{let t=s.includes(e)?s.filter(t=>t!==e):[...s,e];l({type:"multiSelect",values:t.length>0?t:void 0})})(e),className:"px-2 py-0.5 rounded-full text-[10px] transition-colors cursor-pointer",style:{background:t?"var(--color-accent-light)":"var(--color-surface)",border:"1px solid ".concat(t?"var(--color-accent)":"var(--color-border)"),color:t?"var(--color-accent)":"var(--color-text-muted)"},children:e},e)})})]})}function o6(e){var t,r;let{filter:o,value:l,onChange:a}=e,s=(null==l?void 0:l.type)==="number"?l:{type:"number"};return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] whitespace-nowrap",style:{color:"var(--color-text-muted)"},children:o.label}),(0,n.jsx)("input",{type:"number",placeholder:"Min",value:null!=(t=s.min)?t:"",onChange:e=>a({...s,min:e.target.value?Number(e.target.value):void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none w-20",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"to"}),(0,n.jsx)("input",{type:"number",placeholder:"Max",value:null!=(r=s.max)?r:"",onChange:e=>a({...s,max:e.target.value?Number(e.target.value):void 0}),className:"px-2 py-1 rounded-md text-[11px] outline-none w-20",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}})]})}function o3(e){let{filters:t,value:r,onChange:l}=e,[a,s]=(0,o.useState)({}),i=(0,o.useCallback)(async()=>{let e=t.filter(e=>("select"===e.type||"multiSelect"===e.type)&&e.sql);if(0===e.length)return;let r={};await Promise.all(e.map(async e=>{try{var t;let n=await fetch("/api/workspace/reports/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:e.sql})});if(!n.ok)return;let o=(null!=(t=(await n.json()).rows)?t:[]).map(e=>{let t=Object.values(e)[0];return null==t?null:"object"==typeof t?JSON.stringify(t):"string"==typeof t?t:String(t)}).filter(e=>null!==e);r[e.id]=o}catch(e){}})),s(r)},[t]);(0,o.useEffect)(()=>{i()},[i]);let c=(0,o.useCallback)((e,t)=>{l({...r,[e]:t})},[r,l]),d=Object.values(r).some(e=>!!e&&("dateRange"===e.type?e.from||e.to:"select"===e.type?e.value:"multiSelect"===e.type?e.values&&e.values.length>0:"number"===e.type&&(void 0!==e.min||void 0!==e.max)));return 0===t.length?null:(0,n.jsxs)("div",{className:"flex items-center gap-4 px-4 py-2.5 border-b flex-wrap",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs font-medium",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(o0,{}),"Filters"]}),t.map(e=>{var t,o;let l=r[e.id];switch(e.type){case"dateRange":return(0,n.jsx)(o2,{filter:e,value:l,onChange:t=>c(e.id,t)},e.id);case"select":return(0,n.jsx)(o4,{filter:e,value:l,onChange:t=>c(e.id,t),options:null!=(t=a[e.id])?t:[]},e.id);case"multiSelect":return(0,n.jsx)(o5,{filter:e,value:l,onChange:t=>c(e.id,t),options:null!=(o=a[e.id])?o:[]},e.id);case"number":return(0,n.jsx)(o6,{filter:e,value:l,onChange:t=>c(e.id,t)},e.id);default:return null}}),d&&(0,n.jsxs)("button",{type:"button",onClick:()=>l({}),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] transition-colors cursor-pointer",style:{color:"var(--color-accent)",background:"var(--color-accent-light)"},children:[(0,n.jsx)(o1,{}),"Clear"]})]})}function o8(e){let{size:t=20}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",x2:"12",y1:"20",y2:"10"}),(0,n.jsx)("line",{x1:"18",x2:"18",y1:"20",y2:"4"}),(0,n.jsx)("line",{x1:"6",x2:"6",y1:"20",y2:"14"})]})}function o7(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"}),(0,n.jsx)("path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"}),(0,n.jsx)("path",{d:"M16 16h5v5"})]})}function o9(e){let{config:t,reportPath:r}=e,[l,a]=(0,o.useState)(null!=t?t:null),[s,i]=(0,o.useState)(!t&&!!r),[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)({}),[h,p]=(0,o.useState)({}),[m,f]=(0,o.useState)(0);(0,o.useEffect)(()=>{if(t)return void a(t);if(!r)return;let e=!1;return i(!0),d(null),fetch("/api/workspace/file?path=".concat(encodeURIComponent(r))).then(async t=>{if(!t.ok)throw Error("Failed to load report: HTTP ".concat(t.status));let r=await t.json();if(!e)try{let e=JSON.parse(r.content);a(e)}catch(e){throw Error("Invalid report JSON")}}).catch(t=>{e||d(t instanceof Error?t.message:"Failed to load report")}).finally(()=>{e||i(!1)}),()=>{e=!0}},[t,r]);let v=(0,o.useCallback)(async()=>{var e;if(!l)return;let t=function(e,t){let r=[];for(let n of t){let t=e[n.id];t&&("dateRange"===t.type&&(t.from||t.to)||"select"===t.type&&t.value||"multiSelect"===t.type&&t.values&&t.values.length>0||"number"===t.type&&(void 0!==t.min||void 0!==t.max))&&r.push({id:n.id,column:n.column,value:t})}return r}(h,null!=(e=l.filters)?e:[]),r={};for(let e of l.panels)r[e.id]={panelId:e.id,rows:[],loading:!0};x(r),await Promise.all(l.panels.map(async e=>{try{let r=await fetch("/api/workspace/reports/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:e.sql,filters:t.length>0?t:void 0})});if(!r.ok){let t=await r.json().catch(()=>({}));x(n=>({...n,[e.id]:{panelId:e.id,rows:[],loading:!1,error:t.error||"HTTP ".concat(r.status)}}));return}let n=await r.json();x(t=>{var r;return{...t,[e.id]:{panelId:e.id,rows:null!=(r=n.rows)?r:[],loading:!1}}})}catch(t){x(r=>({...r,[e.id]:{panelId:e.id,rows:[],loading:!1,error:t instanceof Error?t.message:"Query failed"}}))}}))},[l,h]);(0,o.useEffect)(()=>{v()},[v,m]);let g=(0,o.useMemo)(()=>Object.values(u).reduce((e,t)=>e+t.rows.length,0),[u]);return s?(0,n.jsxs)("div",{className:"flex items-center justify-center h-full gap-3",children:[(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Loading report..."})]}):c?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-4 p-8",children:[(0,n.jsx)(o8,{size:48}),(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Failed to load report"}),(0,n.jsx)("p",{className:"text-xs px-3 py-2 rounded-lg max-w-md text-center",style:{background:"var(--color-surface)",color:"#f87171"},children:c})]}):l?(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsx)("div",{className:"px-6 py-4 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:(0,n.jsxs)("div",{className:"flex items-start justify-between",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 mb-1",children:[(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:(0,n.jsx)(o8,{})}),(0,n.jsx)("h1",{className:"text-xl font-bold",style:{color:"var(--color-text)"},children:l.title})]}),l.description&&(0,n.jsx)("p",{className:"text-sm ml-7",style:{color:"var(--color-text-muted)"},children:l.description})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("span",{className:"text-[10px] px-2 py-1 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[l.panels.length," panel",1!==l.panels.length?"s":""]}),(0,n.jsxs)("span",{className:"text-[10px] px-2 py-1 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[g," rows"]}),(0,n.jsx)("button",{type:"button",onClick:()=>f(e=>e+1),className:"p-1.5 rounded-md transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Refresh data",children:(0,n.jsx)(o7,{})})]})]})}),l.filters&&l.filters.length>0&&(0,n.jsx)(o3,{filters:l.filters,value:h,onChange:p}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-6",children:(0,n.jsx)("div",{className:"grid grid-cols-6 gap-5",children:l.panels.map(e=>(0,n.jsx)(le,{panel:e,data:u[e.id]},e.id))})})]}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No report configuration found"})})}function le(e){var t;let{panel:r,data:o}=e,l=function(e){switch(e){case"full":return"col-span-6";case"third":return"col-span-2";default:return"col-span-3"}}(r.size);return(0,n.jsxs)("div",{className:"".concat(l," rounded-xl overflow-hidden"),style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"px-4 py-3 flex items-center justify-between",children:[(0,n.jsx)("h3",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:r.title}),o&&!o.loading&&!o.error&&(0,n.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{color:"var(--color-text-muted)"},children:[o.rows.length," rows"]})]}),(0,n.jsx)("div",{className:"px-2 pb-3",children:(null==o?void 0:o.loading)?(0,n.jsx)("div",{className:"flex items-center justify-center",style:{height:320},children:(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):(null==o?void 0:o.error)?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2",style:{height:320},children:[(0,n.jsx)("p",{className:"text-xs",style:{color:"#f87171"},children:"Query error"}),(0,n.jsx)("p",{className:"text-[10px] px-2 py-1 rounded max-w-xs text-center",style:{background:"rgba(248, 113, 113, 0.1)",color:"#f87171"},children:o.error})]}):(0,n.jsx)(oX.N,{config:r,data:null!=(t=null==o?void 0:o.rows)?t:[]})})]})}var lt=r(77592),lr=r(70793),ln=r(64698),lo=r(2289),ll=r(34438),la=r(98463),ls=r(10815),li=r(81375),lc=r(18520),ld=r(54121),lu=r(72092),lx=r(11592),lh=r(48297),lp=r(54113),lm=r(39128),lf=r(92909),lv=r(47186),lg=r(50045),ly=r(12586),lb=r(71788),lj=r(10491),lk=r(38033),lw=r(80236),lN=r(80096),lC=r(29341),lS=r(94003),lM=r(12594),lL=r(64049),lT=r(97185);let lD=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","tiff","tif","ico"]),lE=new Set(["mp4","webm","mov","avi","mkv"]),lR=new Set(["pdf"]),lW=new Set(["mp3","wav","ogg","m4a"]);function lI(e){var t;let r=(null!=(t=e.split(".").pop())?t:"").toLowerCase();return lD.has(r)?"image":lE.has(r)?"video":lR.has(r)?"pdf":lW.has(r)?"audio":null}function lB(e){return e.startsWith("http://")||e.startsWith("https://")?e:"/api/workspace/raw-file?path=".concat(encodeURIComponent(e))}let lF=/(?:^|[\s"'(=])(((?:\/|\.\/)?[\w.\-/\\]+)\.(?:jpe?g|png|gif|webp|svg|bmp|avif|heic|heif|tiff?|ico|mp4|webm|mov|avi|mkv|mp3|wav|ogg|m4a|pdf))\b/i,lP=["path","file","file_path","filePath","filename","url","src","name","target"];function lA(e,t){if(e)for(let t of lP){let r=e[t];if("string"==typeof r&&r.length>0)return r}if(t)for(let e of lP){let r=t[e];if("string"==typeof r&&r.length>0&&l_(r))return r}if(e){let t=lz(e);if(t)return t}if((null==t?void 0:t.text)&&"string"==typeof t.text){let e=t.text.match(lF);if(e)return e[1]}if(t){let e=lz(t);if(e)return e}return null}function l_(e){return e.length>2&&e.length<500&&/\.\w{1,5}$/.test(e)&&!e.includes(" ")}function lz(e){for(let t of Object.values(e))if("string"==typeof t&&l_(t))return t;return null}let lO=/https?:\/\/[^\s"'<>,;)}\]]+/gi;function lU(e){return"https://www.google.com/s2/favicons?sz=64&domain_url=".concat(encodeURIComponent(e))}function lH(e,t){let r=e.toLowerCase().replace(/[_-]/g,"");if(["websearch","search","googlesearch","bingsearch","browsersearch","tavily"].some(e=>r.includes(e)))return"search";if("browser"===r){let e="string"==typeof(null==t?void 0:t.action)?t.action.toLowerCase():"";return"open"===e||"navigate"===e?"fetch":"screenshot"===e?"image":"generic"}return["fetchurl","fetch","browse","browseurl","webfetch"].some(e=>r.includes(e))?"fetch":["read","file","readfile","getfile"].some(e=>r.includes(e))?"read":["bash","shell","execute","exec","terminal","command","run"].some(e=>r.includes(e))?"exec":["write","create","edit","str_replace","save","patch"].some(e=>r.includes(e))?"write":["image","screenshot","photo","picture","dalle","generateimage"].some(e=>r.includes(e))?"image":"generic"}function lV(e){let{parts:t,isStreaming:r}=e,[l,a]=(0,o.useState)(!!r),s=t.some(e=>"reasoning"===e.kind&&e.isStreaming||"tool"===e.kind&&"running"===e.status),i=(0,o.useRef)(null),[c,d]=(0,o.useState)(0);(0,o.useEffect)(()=>{s&&null===i.current&&(i.current=Date.now())},[s]),(0,o.useEffect)(()=>{if(!s)return;let e=()=>{null!==i.current&&d(Math.floor((Date.now()-i.current)/1e3))};e();let t=setInterval(e,1e3);return()=>clearInterval(t)},[s]);let u=(0,o.useCallback)(e=>{if(e<60)return"".concat(e,"s");let t=Math.floor(e/60),r=e%60;return r>0?"".concat(t,"m ").concat(r,"s"):"".concat(t,"m")},[]),x=(0,o.useRef)(!1);(0,o.useEffect)(()=>{r?x.current=!0:x.current&&t.length>0&&(x.current=!1,a(!1))},[r,t.length]);let h=t.filter(e=>"reasoning"===e.kind).map(e=>e.text).join(""),p=t.some(e=>"reasoning"===e.kind&&e.isStreaming),m=function(e){let t=[],r=0;for(;r<e.length;){let n=e[r],o=lH(n.toolName,n.args),l=lA(n.args,n.output),a=l?lI(l):null;if("read"===o&&a&&l){let o=[{path:l,tool:n}],s=r+1;for(;s<e.length;){let t=e[s],r=lH(t.toolName,t.args),n=lA(t.args,t.output),l=n?lI(n):null;if("read"===r&&l===a&&n)o.push({path:n,tool:t}),s++;else break}t.push({type:"media-group",mediaKind:a,items:o}),r=s}else if("fetch"===o){let o=[n],l=r+1;for(;l<e.length;){let t=e[l];if("fetch"===lH(t.toolName,t.args))o.push(t),l++;else break}o.length>1?t.push({type:"fetch-group",items:o}):t.push({type:"tool",tool:n}),r=l}else t.push({type:"tool",tool:n}),r++}return t}(t.filter(e=>"tool"===e.kind)),f=s?c>0?"Thinking for ".concat(u(c)):"Thinking...":c>0?"Thought for ".concat(u(c)):"Thought";return(0,n.jsxs)("div",{className:"my-3",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>a(e=>!e),className:"flex items-center gap-2 py-1 text-[13px] cursor-pointer group",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(l0,{className:"w-4 h-4 flex-shrink-0 opacity-60"}),(0,n.jsx)("span",{className:"font-medium",children:f}),(0,n.jsx)(l1,{className:"w-3.5 h-3.5 ml-1 flex-shrink-0 transition-transform duration-200 ".concat(l?"":"-rotate-90")})]}),(0,n.jsx)(lM.N,{initial:!1,children:l&&(0,n.jsx)(lo.P.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.3,ease:[.25,.1,.25,1]},className:"overflow-hidden",children:(0,n.jsxs)("div",{className:"relative pt-2 pb-1",children:[(0,n.jsx)("div",{className:"absolute w-px",style:{left:9,top:16,bottom:8,background:"var(--color-border)"}}),(0,n.jsxs)(lM.N,{initial:!1,children:[h&&(0,n.jsxs)(lo.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},className:"flex items-start gap-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2a7 7 0 0 0-7 7c0 2.38 1.19 4.47 3 5.74V17a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-2.26c1.81-1.27 3-3.36 3-5.74a7 7 0 0 0-7-7z"}),(0,n.jsx)("path",{d:"M10 21h4"})]})}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(lJ,{text:h,isStreaming:p})})]},"reasoning"),m.map((e,t)=>"media-group"===e.type?(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,n.jsx)(lq,{mediaKind:e.mediaKind,items:e.items})},"media-".concat(t)):"fetch-group"===e.type?(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,n.jsx)(lK,{items:e.items})},"fetch-".concat(t)):(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,n.jsx)(l$,{...e.tool})},e.tool.toolCallId))]})]})},"content")})]})}function lJ(e){let{text:t,isStreaming:r}=e;return(0,n.jsx)("div",{className:"mb-2",children:(0,n.jsx)("div",{className:"text-[13px] whitespace-pre-wrap leading-relaxed",style:{color:"var(--color-text-muted)"},children:t})})}function lK(e){let{items:t}=e,r=t.some(e=>"running"===e.status),o=t.filter(e=>"done"===e.status).length;return(0,n.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,n.jsx)("span",{className:r?"animate-pulse":"",children:(0,n.jsx)(lY,{kind:"fetch"})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"text-[13px] leading-snug mb-1.5 flex items-center justify-between",style:{color:r?"var(--color-text)":"var(--color-text-secondary)"},children:[(0,n.jsx)("span",{className:r?"animate-pulse":"",children:r?"Fetching ".concat(t.length," sources..."):"Fetched ".concat(t.length," sources")}),!r&&(0,n.jsxs)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:[o," ",1===o?"result":"results"]})]}),(0,n.jsx)("div",{className:"rounded-2xl overflow-hidden",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:t.map(e=>{var t,r;let{domain:o,url:l}=function(e,t){for(let t of["url","targetUrl","path","src"]){let r=null==e?void 0:e[t];if("string"==typeof r&&r.startsWith("http"))try{return{domain:new URL(r).hostname,url:r}}catch(e){}}for(let e of["url","finalUrl","targetUrl"]){let r=null==t?void 0:t[e];if("string"==typeof r&&r.startsWith("http"))try{return{domain:new URL(r).hostname,url:r}}catch(e){}}return{domain:null,url:null}}(e.args,e.output);return(0,n.jsxs)("a",{href:null!=l?l:void 0,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2.5 px-3 py-2.5 text-[12px] no-underline",style:{color:"var(--color-text)",cursor:l?"pointer":"default"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},onClick:l?void 0:e=>e.preventDefault(),children:[o?(0,n.jsx)("img",{src:lU(o),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",loading:"lazy"}):(0,n.jsx)("div",{className:"w-4 h-4 rounded-sm flex-shrink-0",style:{background:"var(--color-surface-hover)"}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",style:{color:"var(--color-text)"},children:null!=(r=null!=(t=null==o?void 0:o.replace(/^www\./,""))?t:l)?r:"Fetching..."}),"running"===e.status?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse flex-shrink-0",style:{background:"var(--color-accent)"}}):l?(0,n.jsx)("span",{className:"text-[11px] truncate max-w-[45%] text-right",style:{color:"var(--color-text-muted)"},title:l,children:l}):null]},e.toolCallId)})})]})]})}function lq(e){let{mediaKind:t,items:r}=e,[l,a]=(0,o.useState)(!1),s=r.some(e=>"running"===e.tool.status),i=r.filter(e=>"done"===e.tool.status),c=i.length,d=s?"Reading ".concat(r.length," ").concat(t).concat(r.length>1?"s":"","..."):"image"===t?1===r.length?"Read 1 image":"Read ".concat(r.length," images"):"video"===t?1===r.length?"Read 1 video":"Read ".concat(r.length," videos"):"pdf"===t?1===r.length?"Read 1 PDF":"Read ".concat(r.length," PDFs"):1===r.length?"Read 1 audio file":"Read ".concat(r.length," audio files"),u=l?i:i.slice(0,6),x=i.length>6&&!l;return(0,n.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,n.jsx)("span",{className:s?"animate-pulse":"",children:(0,n.jsx)(lY,{kind:"image"===t?"image":"read"})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-[13px] leading-snug mb-1.5".concat(s?" animate-pulse":""),style:{color:s?"var(--color-text)":"var(--color-text-secondary)"},children:d}),c>0&&"image"===t&&(0,n.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[u.map(e=>(0,n.jsx)(lG,{path:e.path,single:1===r.length},e.tool.toolCallId)),s&&(0,n.jsx)("div",{className:"flex items-center justify-center rounded-lg",style:{width:80,height:80,background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("span",{className:"animate-pulse",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(lY,{kind:"image"})})}),x&&(0,n.jsxs)("button",{type:"button",onClick:()=>a(!0),className:"flex items-center justify-center rounded-lg text-xs font-medium cursor-pointer",style:{width:80,height:80,background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:["+",i.length-6," ","more"]})]}),c>0&&"video"===t&&(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:u.map(e=>(0,n.jsx)("video",{src:lB(e.path),controls:!0,preload:"metadata",className:"rounded-lg max-w-[240px] max-h-[160px]",style:{border:"1px solid var(--color-border)"}},e.tool.toolCallId))}),c>0&&"pdf"===t&&(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:u.map(e=>{var t;let r=null!=(t=e.path.split("/").pop())?t:e.path;return(0,n.jsxs)("a",{href:lB(e.path),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 rounded-lg text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)(lX,{}),(0,n.jsx)("span",{className:"truncate max-w-[200px]",children:r})]},e.tool.toolCallId)})}),c>0&&"audio"===t&&(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:u.map(e=>(0,n.jsx)("audio",{src:lB(e.path),controls:!0,preload:"metadata",className:"max-w-[280px] h-8"},e.tool.toolCallId))})]})]})}function lG(e){var t;let{path:r,single:l}=e,[a,s]=(0,o.useState)(!1),i=null!=(t=r.split("/").pop())?t:r,c=lB(r),d=l?200:80,u=l?150:80;return a?(0,n.jsx)("div",{className:"flex items-center justify-center rounded-lg text-[10px] text-center p-1",style:{width:d,height:u,background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},title:r,children:(0,n.jsx)("span",{className:"truncate",children:i})}):(0,n.jsx)("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"block rounded-lg overflow-hidden flex-shrink-0",style:{border:"1px solid var(--color-border)",width:d,height:u},title:i,children:(0,n.jsx)("img",{src:c,alt:i,className:"w-full h-full object-cover",loading:"lazy",onError:()=>s(!0)})})}function l$(e){var t;let{toolName:r,status:l,args:a,output:s,errorText:i}=e,c=lH(r,a),[d,u]=(0,o.useState)("exec"===c||"generic"===c),[x,h]=(0,o.useState)(!0),p=function(e,t,r,n){var o,l,a,s,i,c,d,u,x,h,p,m,f,v,g,y,b,j,k;let w=e=>{let t=null==r?void 0:r[e];return"string"==typeof t&&t.length>0?t:null};switch(e){case"search":{let e=null!=(a=null!=(l=null!=(o=w("query"))?o:w("search_query"))?l:w("search"))?a:w("q");return e?"Searching for ".concat(e):"Searching..."}case"fetch":{let e=null!=(c=null!=(i=null!=(s=w("url"))?s:w("targetUrl"))?i:w("path"))?c:w("src");if(e)try{return"Fetching ".concat(new URL(e).hostname)}catch(t){return"Fetching ".concat(e)}let t="string"==typeof(null==n?void 0:n.finalUrl)&&n.finalUrl||"string"==typeof(null==n?void 0:n.url)&&n.url;if(t)try{return"Fetched ".concat(new URL(t).hostname)}catch(e){return"Fetched ".concat(t)}return"Fetching page"}case"read":{let e=lA(r,n);if(e){let t=null!=(d=e.split("/").pop())?d:e;return t.startsWith("http")?"Fetching ".concat(t):"Reading ".concat(t)}return"Reading file"}case"exec":{let e=null!=(u=w("command"))?u:w("cmd");if(e)return"Running: ".concat(e);return"Running command"}case"write":{let e=null!=(h=null!=(x=w("path"))?x:w("file"))?h:w("file_path");if(e){let t=null!=(p=e.split("/").pop())?p:e;return"Editing ".concat(t)}return"Editing file"}case"image":return w("description")?"Generating image: ".concat(w("description")):"Generating image";default:{let e=t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase()).trim();if(r){let t=null!=(k=null!=(j=null!=(b=null!=(y=null!=(g=null!=(v=null!=(f=null!=(m=w("command"))?m:w("cmd"))?f:w("query"))?v:w("path"))?g:w("url"))?y:w("message"))?b:w("description"))?j:w("input"))?k:w("text");if(t)return"".concat(e,": ").concat(t)}return e||"Tool"}}}(c,r,a,s),m="search"===c?function(e){var t;if(!e)return[];let r="string"==typeof e.text?e.text:"",n=e.results,o=e.citations,l=r;if(Array.isArray(n))for(let e of n)"string"==typeof e?l+=" ".concat(e):"object"==typeof e&&null!==e&&("string"==typeof e.url&&(l+=" ".concat(e.url)),"string"==typeof e.link&&(l+=" ".concat(e.link)));if(Array.isArray(o))for(let e of o)"string"==typeof e?l+=" ".concat(e):"object"==typeof e&&null!==e&&"string"==typeof e.url&&(l+=" ".concat(e.url));for(let t of Object.values(e))"string"==typeof t&&t!==r&&t.includes("http")&&(l+=" ".concat(t));let a=null!=(t=l.match(lO))?t:[],s=new Set;for(let e of a)try{let t=new URL(e).hostname;t&&!t.includes("localhost")&&s.add(t)}catch(e){}return[...s].slice(0,8)}(s):"fetch"===c?function(e,t){let r=new Set;for(let t of["url","targetUrl","path","src"]){let n=null==e?void 0:e[t];if("string"==typeof n&&n.startsWith("http"))try{let e=new URL(n).hostname;e&&!e.includes("localhost")&&r.add(e)}catch(e){}}for(let e of["url","finalUrl","targetUrl"]){let n=null==t?void 0:t[e];if("string"==typeof n&&n.startsWith("http"))try{let e=new URL(n).hostname;e&&!e.includes("localhost")&&r.add(e)}catch(e){}}return[...r].slice(0,4)}(a,s):[],f="string"==typeof(null==s?void 0:s.text)?s.text:void 0,v=(()=>{if("write"!==c||"done"!==l)return;if("string"==typeof(null==s?void 0:s.diff))return s.diff;let e="string"==typeof(null==a?void 0:a.old_string)?a.old_string:"string"==typeof(null==a?void 0:a.oldText)?a.oldText:null,t="string"==typeof(null==a?void 0:a.new_string)?a.new_string:"string"==typeof(null==a?void 0:a.newText)?a.newText:null;if(null!==e&&null!==t){var r="string"==typeof(null==a?void 0:a.path)?a.path:"string"==typeof(null==a?void 0:a.file_path)?a.file_path:"file";let n=e.split("\n"),o=t.split("\n"),l=["--- a/".concat(r),"+++ b/".concat(r),"@@ -1,".concat(n.length," +1,").concat(o.length," @@")];for(let e of n)l.push("-".concat(e));for(let e of o)l.push("+".concat(e));return l.join("\n")}})(),g=lA(a,s),y=g?lI(g):null,b="read"===c&&y&&"done"===l;return(0,n.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:"error"===l?(0,n.jsx)(lQ,{}):(0,n.jsx)("span",{className:"running"===l?"animate-pulse":"",children:(0,n.jsx)(lY,{kind:c})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"text-[13px] leading-snug flex items-center gap-2 flex-wrap",style:{color:"running"===l?"var(--color-text)":"var(--color-text-secondary)"},children:[(0,n.jsx)("span",{className:"break-all".concat("running"===l?" animate-pulse":""),children:p}),"exec"===c&&"done"===l&&(null==s?void 0:s.exitCode)!==void 0&&(0,n.jsxs)("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded",style:{background:0===s.exitCode?"color-mix(in srgb, var(--color-success, #22c55e) 12%, transparent)":"color-mix(in srgb, var(--color-error) 12%, transparent)",color:0===s.exitCode?"var(--color-success, #22c55e)":"var(--color-error)"},children:["exit ","object"==typeof s.exitCode&&null!=s.exitCode?JSON.stringify(s.exitCode):"number"==typeof s.exitCode?String(s.exitCode):"string"==typeof s.exitCode?s.exitCode:""]})]}),v&&"done"===l&&(0,n.jsxs)("div",{className:"mt-1.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>h(e=>!e),className:"text-[11px] hover:underline cursor-pointer mb-1",style:{color:"var(--color-accent)"},children:x?"Hide changes":"Show changes"}),x&&(0,n.jsx)(rA,{diff:v})]}),b&&g&&"image"===y&&(0,n.jsx)("div",{className:"mt-1.5",children:(0,n.jsx)(lG,{path:g,single:!0})}),b&&g&&"video"===y&&(0,n.jsx)("video",{src:lB(g),controls:!0,preload:"metadata",className:"mt-1.5 rounded-lg max-w-[240px] max-h-[160px]",style:{border:"1px solid var(--color-border)"}}),b&&g&&"pdf"===y&&(0,n.jsxs)("a",{href:lB(g),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 mt-1.5 px-3 py-2 rounded-lg text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)(lX,{}),(0,n.jsx)("span",{className:"truncate max-w-[200px]",children:null!=(t=g.split("/").pop())?t:g})]}),b&&g&&"audio"===y&&(0,n.jsx)("audio",{src:lB(g),controls:!0,preload:"metadata",className:"mt-1.5 max-w-[280px] h-8"}),m.length>0&&"running"!==l&&(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-1.5",children:m.map(e=>(0,n.jsx)(lZ,{domain:e},e))}),("search"===c||"fetch"===c)&&"running"===l&&a&&(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-1.5",children:m.length>0?m.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("img",{src:lU(e),alt:"",width:14,height:14,className:"rounded-sm flex-shrink-0",loading:"lazy"}),e.replace(/^www\./,""),(0,n.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}})]},e)):(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}}),"fetch"===c?"Fetching...":"Searching..."]})}),"error"===l&&i&&(0,n.jsx)("div",{className:"mt-1.5 text-[12px] font-mono rounded-lg px-2.5 py-1.5",style:{color:"var(--color-error)",background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))"},children:i}),!f&&!v&&!b&&"done"===l&&a&&Object.keys(a).length>0&&(0,n.jsx)("pre",{className:"mt-1 text-[11px] font-mono rounded-lg px-2.5 py-1.5 whitespace-pre-wrap break-all max-h-48 overflow-y-auto leading-relaxed",style:{color:"var(--color-text-muted)",background:"var(--color-bg)"},children:function(e){let t=[];for(let[r,n]of Object.entries(e)){if(null==n)continue;let e="string"==typeof n?n:JSON.stringify(n,null,2);t.push("".concat(r,": ").concat(e))}let r=t.join("\n");return r.length>2e3?r.slice(0,2e3)+"\n...":r}(a)}),f&&!b&&!v&&(0,n.jsxs)("div",{className:"mt-1",children:["done"===l&&(0,n.jsx)("button",{type:"button",onClick:()=>u(e=>!e),className:"text-[11px] hover:underline cursor-pointer",style:{color:"var(--color-accent)"},children:d?"Hide output":"Show output"}),(d||"running"===l)&&(0,n.jsx)("pre",{className:"mt-1 text-[11px] font-mono rounded-lg px-2.5 py-2 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto leading-relaxed",style:{color:"var(--color-text-muted)",background:"var(--color-bg)"},children:f.length>1e4?f.slice(0,1e4)+"\n... (truncated)":f})]})]})]})}function lZ(e){let{domain:t}=e,r=t.replace(/^www\./,"");return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("img",{src:lU(t),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",loading:"lazy"}),r]})}function lY(e){let{kind:t}=e,r="var(--color-text-muted)";switch(t){case"search":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]});case"fetch":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("path",{d:"M2 12h20"}),(0,n.jsx)("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]});case"read":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]});case"exec":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]});case"write":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,n.jsx)("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})]});case"image":return(0,n.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});default:return(0,n.jsx)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1"})})}}function lQ(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",x2:"9",y1:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",x2:"15",y1:"9",y2:"15"})]})}function lX(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,n.jsx)("path",{d:"M10 9H8"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"})]})}function l0(e){let{className:t}=e;return(0,n.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2a7 7 0 0 0-7 7c0 2.38 1.19 4.47 3 5.74V17a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-2.26c1.81-1.27 3-3.36 3-5.74a7 7 0 0 0-7-7z"}),(0,n.jsx)("path",{d:"M10 21h4"}),(0,n.jsx)("path",{d:"M9 9.4a3 3 0 0 1 5.1-2"})]})}function l1(e){let{className:t}=e;return(0,n.jsx)("svg",{className:t,viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M3 4.5L6 7.5L9 4.5"})})}let l2=null,l4=["typescript","tsx","javascript","jsx","python","ruby","go","rust","java","c","cpp","csharp","swift","kotlin","css","scss","html","xml","json","yaml","toml","bash","sql","graphql","markdown","diff","php","lua","vue","svelte","dart","zig"];function l5(e){let{code:t,lang:r}=e,[l,a]=(0,o.useState)(null);return((0,o.useEffect)(()=>{let e=!1;return(!l2&&(l2=(0,r8.O_)({themes:["github-dark","github-light"],langs:l4})),l2).then(n=>{if(!e)try{let e=n.codeToHtml(t,{lang:r,themes:{dark:"github-dark",light:"github-light"}});a(e)}catch(e){try{let e=n.codeToHtml(t,{lang:"text",themes:{dark:"github-dark",light:"github-light"}});a(e)}catch(e){}}}),()=>{e=!0}},[t,r]),l)?(0,n.jsx)("div",{className:"syntax-block",dangerouslySetInnerHTML:{__html:l}}):(0,n.jsx)("code",{className:"block",children:t})}let l6=(0,rD.default)(()=>r.e(5477).then(r.bind(r,45477)).then(e=>({default:e.ReportCard})),{loadableGenerated:{webpack:()=>[45477]},ssr:!1,loading:()=>(0,n.jsx)("div",{className:"h-48 rounded-2xl animate-pulse",style:{background:"var(--color-surface-hover)"}})}),l3="NO_REPLY";function l8(e){return"output-available"===e?"done":"error"===e?"error":"running"}function l7(e){if(e&&"object"==typeof e&&!Array.isArray(e))return e}function l9(e){let{paths:t}=e;return(0,n.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-2 justify-end",children:t.map((e,t)=>{var r,o,l;let a=function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(n)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(n)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(n)?"audio":"pdf"===n?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(n)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv","pages","numbers","key"].includes(n)?"document":"other"}(e),s="image"===a?"/api/workspace/raw-file?path=".concat(encodeURIComponent(e)):"/api/workspace/thumbnail?path=".concat(encodeURIComponent(e),"&size=200"),i=null!=(o=null==(r=e.split(".").pop())?void 0:r.toUpperCase())?o:"";return(0,n.jsxs)("div",{className:"relative rounded-xl overflow-hidden shrink-0",children:[(0,n.jsx)("img",{src:s,alt:null!=(l=e.split("/").pop())?l:"",className:"block rounded-xl object-cover",style:{maxHeight:140,maxWidth:160,background:"rgba(0,0,0,0.04)"},loading:"lazy",onError:e=>{e.currentTarget.style.display="none"}}),"image"!==a&&(0,n.jsx)("span",{className:"absolute bottom-2 left-2 rounded-md px-1.5 py-0.5 text-[10px] font-bold uppercase",style:{background:"rgba(255,255,255,0.85)",color:"rgba(0,0,0,0.5)",backdropFilter:"blur(4px)"},children:i})]},t)})})}function ae(e){let t=e.trim();if(!t||t.length<3||t.length>500)return!1;if(t.startsWith("~/")||t.startsWith("/")||t.startsWith("./")||t.startsWith("../")){let e=t.startsWith("~/")?t.slice(2):t.startsWith("../")?t.slice(3):t.startsWith("./")?t.slice(2):t.slice(1);return e.includes("/")||e.includes(".")}return!(!/\.(pdf|docx?|xlsx?|pptx?|csv|txt|rtf|pages|numbers|key|md|json|yaml|yml|toml|xml|html?|css|jsx?|tsx?|py|rb|go|rs|java|cpp|c|h|sh|sql|swift|kt|png|jpe?g|gif|webp|svg|bmp|ico|heic|tiff|mp[34]|webm|mov|avi|mkv|flv|wav|ogg|aac|flac|m4a|zip|tar|gz|dmg)$/i.test(t)||t.includes(" "))}async function at(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{let r=await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,reveal:t})});if(!r.ok){let e=await r.json().catch(()=>({}));console.error("Failed to open file:",e)}}catch(e){console.error("Failed to open file:",e)}}function ar(e){let t=e.trim();if(!t.startsWith("file://"))return t;try{let e=new URL(t);if("file:"!==e.protocol)return t;let r=decodeURIComponent(e.pathname);if(/^\/[A-Za-z]:\//.test(r))return r.slice(1);return r}catch(e){return t}}function an(e){let{path:t,children:r,onFilePathClick:l}=e,[a,s]=(0,o.useState)("idle"),i=async e=>{e.preventDefault(),s("opening");try{if(l){let e=await l(t);if(!1===e){s("error"),setTimeout(()=>s("idle"),2e3);return}s("idle")}else(await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})})).ok?s("idle"):(s("error"),setTimeout(()=>s("idle"),2e3))}catch(e){s("error"),setTimeout(()=>s("idle"),2e3)}},c=async e=>{e.preventDefault(),await at(t,!0)};return(0,n.jsx)("code",{className:"px-[0.3em] no-underline transition-colors duration-150 rounded-[4px] border border-[color:var(--color-border)] bg-white/20 hover:bg-white/40 active:bg-white ".concat("opening"===a?"cursor-wait opacity-70":"cursor-pointer"),style:{color:"var(--color-accent)"},onClick:i,onContextMenu:c,title:"error"===a?"File not found":l?"Click to preview in workspace \xb7 Right-click to reveal in Finder":"Click to open \xb7 Right-click to reveal in Finder",children:r})}function ao(e){let{messageId:t,sessionId:r}=e,l=(0,o.useCallback)((e,t)=>{var r;e&&fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:e,messageId:t,distinctId:null==(r=lC.Ay.get_distinct_id)?void 0:r.call(lC.Ay)})}).catch(()=>{})},[]),{respond:a,response:s,triggerRef:i}=(0,lS.y)({surveyId:"019cc021-a8bf-0000-d41d-b82956ef7e6a",properties:{$ai_trace_id:r,message_id:t},onResponse:()=>l(r,t)}),c="p-1 rounded-md transition-colors";return(0,n.jsxs)("div",{ref:i,className:"flex items-center gap-0.5 mt-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{type:"button",onClick:()=>a("up"),className:c,style:{color:"up"===s?"var(--color-accent)":"var(--color-text-muted)"},title:"Good response","aria-label":"Thumbs up",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"up"===s?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M7 10v12"}),(0,n.jsx)("path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z"})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>a("down"),className:c,style:{color:"down"===s?"var(--color-error, #ef4444)":"var(--color-text-muted)"},title:"Bad response","aria-label":"Thumbs down",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"down"===s?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17 14V2"}),(0,n.jsx)("path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z"})]})})]})}let al=(0,o.memo)(function(e){let{message:t,isStreaming:r,onSubagentClick:l,onFilePathClick:a,sessionId:s,userHtmlMap:i}=e,c="user"===t.role,d=function(e){let t=[],r=[],n=e=>{if(r.length>0){if(e)for(let e of r)"tool"===e.kind&&"running"===e.status&&(e.status="done");t.push({type:"chain",parts:[...r]}),r=[]}};for(let x of e)if("text"===x.type){let e=x.text;if(function(e){let t=e.trim();return!!t&&!!(new RegExp("^".concat(l3,"\\W*$")).test(t)||l3.startsWith(t)&&t.length>=2&&t.length<l3.length)}(e))continue;if(n(!0),rR(e))t.push(...rE(e));else if(rI(e))for(let r of rW(e))"diff-artifact"===r.type?t.push({type:"diff-artifact",diff:r.diff}):t.push({type:"text",text:r.text});else t.push({type:"text",text:e})}else if("reasoning"===x.type){let e=x;["Preparing response...","Optimizing session context...","Waiting for subagent results...","Waiting for subagents..."].some(t=>e.text.startsWith(t))||r.push({kind:"reasoning",text:e.text,isStreaming:"streaming"===e.state})}else if("dynamic-tool"===x.type)if("sessions_spawn"===x.toolName){n(!0);let e=l7(x.input),r=l7(x.output),o="string"==typeof(null==e?void 0:e.task)?e.task:"Subagent task",l="string"==typeof(null==e?void 0:e.label)?e.label:void 0,a="string"==typeof(null==r?void 0:r.sessionKey)?r.sessionKey:void 0;t.push({type:"subagent-card",task:o,label:l,sessionKey:a,status:l8(x.state)})}else r.push({kind:"tool",toolName:x.toolName,toolCallId:x.toolCallId,status:l8(x.state),args:l7(x.input),output:l7(x.output)});else if(x.type.startsWith("tool-")){var o,l,a,s,i,c,d,u;let e=null!=(l=null!=(o=x.title)?o:x.toolName)?l:x.type.replace("tool-","");if("sessions_spawn"===e){n(!0);let e=null!=(a=l7(x.input))?a:l7(x.args),r=null!=(s=l7(x.output))?s:l7(x.result),o="string"==typeof(null==e?void 0:e.task)?e.task:"Subagent task",l="string"==typeof(null==e?void 0:e.label)?e.label:void 0,c="string"==typeof(null==r?void 0:r.sessionKey)?r.sessionKey:void 0,d=null!=(i=x.state)?i:x.errorText?"error":"result"in x||"output"in x?"output-available":"input-available";t.push({type:"subagent-card",task:o,label:l,sessionKey:c,status:l8(d)})}else{let t=null!=(c=x.state)?c:x.errorText?"error":"result"in x||"output"in x?"output-available":"input-available";r.push({kind:"tool",toolName:e,toolCallId:x.toolCallId,status:l8(t),args:null!=(d=l7(x.input))?d:l7(x.args),output:null!=(u=l7(x.output))?u:l7(x.result)})}}return n(),t}(t.parts),u=(0,o.useMemo)(()=>({a:e=>{let{href:t,children:r,...o}=e,l="string"==typeof t?t:"",s=ar(l),i=l&&(l.startsWith("http://")||l.startsWith("https://")||l.startsWith("//")),c=!(l.startsWith("/workspace")||l.startsWith("/?"))&&(!!l.startsWith("file://")||ae(s));return(0,n.jsx)("a",{href:t,...i?{target:"_blank",rel:"noopener noreferrer"}:{},...o,onClick:e=>{c&&a&&(e.preventDefault(),a(s))},children:r})},img:e=>{let{src:t,alt:r,...o}=e,l="string"!=typeof t||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("data:")?t:"/api/workspace/raw-file?path=".concat(encodeURIComponent(t));return(0,n.jsx)("img",{src:l,alt:null!=r?r:"",loading:"lazy",...o})},pre:e=>{let{children:t,...r}=e,o=Array.isArray(t)?t[0]:t;if(o&&"object"==typeof o&&"type"in o&&"code"===o.type){var l,a,s,i;let e=(null!=(s=null==(l=o.props)?void 0:l.className)?s:"").match(/language-(\w+)/),t=null!=(i=null==e?void 0:e[1])?i:"",r="string"==typeof(null==(a=o.props)?void 0:a.children)?o.props.children.replace(/\n$/,""):"";if("diff"===t)return(0,n.jsx)(rA,{diff:r});if(t)return(0,n.jsxs)("div",{className:"chat-code-block",children:[(0,n.jsx)("div",{className:"chat-code-lang",children:t}),(0,n.jsx)(l5,{code:r,lang:t})]})}return(0,n.jsx)("pre",{...r,children:t})},code:e=>{let{children:t,className:r,...o}=e;if(null==r?void 0:r.startsWith("language-"))return(0,n.jsx)("code",{className:r,...o,children:t});let l=ar("string"==typeof t?t:"");return l&&ae(l)?(0,n.jsx)(an,{path:l,onFilePathClick:a,children:t}):(0,n.jsx)("code",{...o,children:t})},strong:e=>{let{children:t,...r}=e,o="string"==typeof t?t:Array.isArray(t)?t.filter(e=>"string"==typeof e).join(""):"";return o&&function(e){let t=e.trim();return!!t&&!(t.length<3)&&!(t.length>300)&&/\.(pdf|docx?|xlsx?|pptx?|csv|txt|rtf|pages|numbers|key|md|json|yaml|yml|toml|xml|html?|css|jsx?|tsx?|py|rb|go|rs|java|cpp|c|h|sh|sql|swift|kt|png|jpe?g|gif|webp|svg|bmp|ico|heic|tiff|mp[34]|webm|mov|avi|mkv|flv|wav|ogg|aac|flac|m4a|zip|tar|gz|dmg)$/i.test(t)}(o)?(0,n.jsx)("strong",{...r,children:(0,n.jsx)(an,{path:o,onFilePathClick:a,children:t})}):(0,n.jsx)("strong",{...r,children:t})}}),[a]);if(c){var x,h,p,m;let e=d.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),r=function(e){var t;let r=e.match(/\[Attached files: (.+?)\]/);if(!r)return null;let n=(null!=(t=r.index)?t:0)+r[0].length,o=e.slice(n).trim();return{paths:r[1].split(", ").map(e=>e.trim()).filter(Boolean),message:o}}(e),o=null!=(p=null!=(x=null==i?void 0:i.get(t.id))?x:null==i?void 0:i.get(e))?p:null==i?void 0:i.get(null!=(h=null==r?void 0:r.message)?h:""),l=o?(0,n.jsx)("div",{className:"chat-user-html-content",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("p",{className:"whitespace-pre-wrap break-words",children:null!=(m=null==r?void 0:r.message)?m:e});return r?(0,n.jsxs)("div",{className:"flex flex-col items-end gap-1.5 py-2",children:[(0,n.jsx)(l9,{paths:r.paths}),(r.message||o)&&(0,n.jsx)("div",{className:"max-w-[80%] w-fit rounded-2xl rounded-br-sm px-3 py-2 text-sm leading-6 break-words chat-message-font",style:{background:"var(--color-user-bubble)",color:"var(--color-user-bubble-text)"},children:l})]}):(0,n.jsx)("div",{className:"flex justify-end py-2",children:(0,n.jsx)("div",{className:"max-w-[80%] min-w-0 rounded-2xl rounded-br-sm px-3 py-2 text-sm leading-6 overflow-hidden break-words chat-message-font",style:{background:"var(--color-user-bubble)",color:"var(--color-user-bubble-text)"},children:l})})}return(0,n.jsxs)("div",{className:"py-3 space-y-2 min-w-0 overflow-hidden group",children:[(0,n.jsx)(lM.N,{initial:!1,children:d.map((e,t)=>{if("text"===e.type){let r=e.text.match(/^\[error\]\s*([\s\S]*)$/);return r?(0,n.jsxs)("div",{className:"chat-message-font flex items-start gap-2 rounded-xl px-3 py-2 text-[13px] leading-relaxed overflow-hidden",style:{background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))",color:"var(--color-error)",border:"1px solid color-mix(in srgb, var(--color-error) 18%, transparent)"},children:[(0,n.jsx)("span",{className:"flex-shrink-0 mt-0.5","aria-hidden":"true",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,n.jsx)("span",{className:"whitespace-pre-wrap break-all min-w-0",children:r[1].trim()})]},t):(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},className:"chat-prose chat-message-font text-sm",style:{color:"var(--color-text)"},children:(0,n.jsx)(lL.oz,{remarkPlugins:[lT.A],components:u,children:e.text})},"text-".concat(t))}if("report-artifact"===e.type)return(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)(l6,{config:e.config})},"report-".concat(t));if("diff-artifact"===e.type)return(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)(rA,{diff:e.diff})},"diff-".concat(t));if("subagent-card"===e.type){let r=e.task.length>80?e.task.slice(0,80)+"...":e.task,o="running"===e.status;return(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)("button",{type:"button",onClick:()=>{var t;return null==l?void 0:l(null!=(t=e.sessionKey)?t:e.task)},className:"w-full text-left rounded-xl px-3.5 py-2.5 transition-colors cursor-pointer",style:{background:"var(--color-accent-light)",border:"1px solid color-mix(in srgb, var(--color-accent) 20%, transparent)"},children:(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[o?(0,n.jsx)("span",{className:"inline-block w-2 h-2 rounded-full animate-pulse flex-shrink-0",style:{background:"var(--color-accent)"}}):(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{color:"var(--color-accent)"},children:[(0,n.jsx)("path",{d:"M16 3h5v5"}),(0,n.jsx)("path",{d:"m21 3-7 7"}),(0,n.jsx)("path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6"})]}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-accent)"},children:o?"Running Subagent":"Subagent"})}),(0,n.jsx)("p",{className:"text-xs mt-0.5 leading-relaxed",style:{color:"var(--color-text)"},children:e.label||r})]}),(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-40",style:{color:"var(--color-text)"},children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})]})})},"subagent-".concat(t))}return(0,n.jsx)(lo.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)(lV,{parts:e.parts,isStreaming:r})},"chain-".concat(t))})}),!r&&(0,n.jsx)(ao,{messageId:t.id,sessionId:s})]})}),aa={folder:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},image:{bg:"rgba(16, 185, 129, 0.12)",fg:"#10b981"},video:{bg:"rgba(139, 92, 246, 0.12)",fg:"#8b5cf6"},audio:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},pdf:{bg:"rgba(239, 68, 68, 0.12)",fg:"#ef4444"},code:{bg:"rgba(59, 130, 246, 0.12)",fg:"#3b82f6"},document:{bg:"rgba(107, 114, 128, 0.12)",fg:"#6b7280"},other:{bg:"rgba(107, 114, 128, 0.08)",fg:"#9ca3af"}};function as(e){let{category:t,size:r=16}=e,o={width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};switch(t){case"folder":return(0,n.jsx)("svg",{...o,children:(0,n.jsx)("path",{d:"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"})});case"image":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,n.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M10 13h4"}),(0,n.jsx)("path",{d:"M10 17h4"})]});case"code":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]});case"document":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"}),(0,n.jsx)("path",{d:"M10 9H8"})]});default:return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"})]})}}function ai(e){let{open:t,onClose:r,onSelect:l}=e,[a,s]=(0,o.useState)(null),[i,c]=(0,o.useState)(""),[d,u]=(0,o.useState)([]),[x,h]=(0,o.useState)(null),[p,m]=(0,o.useState)(new Map),[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(""),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(""),[N,C]=(0,o.useState)(null),[S,M]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t?requestAnimationFrame(()=>requestAnimationFrame(()=>M(!0))):M(!1)},[t]),(0,o.useEffect)(()=>{t||(y(""),j(!1),w(""),C(null))},[t]);let L=(0,o.useRef)(null),T=(0,o.useRef)(null),D=(0,o.useCallback)(async e=>{v(!0),C(null);try{var t;let r=e?"/api/workspace/browse?dir=".concat(encodeURIComponent(e)):"/api/workspace/browse",n=await fetch(r);if(!n.ok)throw Error("Failed to list directory");let o=await n.json();u(o.entries||[]),c(o.currentDir||""),h(null!=(t=o.parentDir)?t:null)}catch(e){C("Could not load this directory"),u([])}finally{v(!1)}},[]);(0,o.useEffect)(()=>{t&&D(a)},[t,a,D]),(0,o.useEffect)(()=>{if(!t)return;let e=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,r]);let E=(0,o.useCallback)(e=>{m(t=>{let r=new Map(t);return r.has(e.path)?r.delete(e.path):r.set(e.path,{name:e.name,path:e.path}),r})},[]),R=(0,o.useCallback)(e=>{s(e),y(""),j(!1)},[]),W=(0,o.useCallback)(async()=>{if(!k.trim()||!i)return;let e="".concat(i,"/").concat(k.trim());try{await fetch("/api/workspace/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}),j(!1),w(""),D(a)}catch(e){C("Failed to create folder")}},[k,i,a,D]),I=(0,o.useCallback)(()=>{l(Array.from(p.values())),m(new Map),r()},[p,l,r]),B=d.filter(e=>!g||e.name.toLowerCase().includes(g.toLowerCase())).toSorted((e,t)=>"folder"===e.type&&"folder"!==t.type?-1:"folder"!==e.type&&"folder"===t.type?1:e.name.localeCompare(t.name)),F=i?function(e){let t=[],r=e.match(/^(\/Users\/[^/]+|\/home\/[^/]+)/),n=null==r?void 0:r[1];if(n){t.push({label:"~",path:n});let r=e.slice(n.length).split("/").filter(Boolean),o=n;for(let e of r)o+="/"+e,t.push({label:e,path:o})}else if("/"===e)t.push({label:"/",path:"/"});else{t.push({label:"/",path:"/"});let r=e.split("/").filter(Boolean),n="";for(let e of r)n+="/"+e,t.push({label:e,path:n})}return t}(i):[];return t?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",style:{opacity:+!!S,transition:"opacity 150ms ease-out"},children:[(0,n.jsx)("div",{className:"absolute inset-0",style:{background:"rgba(0,0,0,0.4)",backdropFilter:"blur(4px)"},onClick:r}),(0,n.jsxs)("div",{className:"relative flex flex-col rounded-2xl shadow-2xl overflow-hidden w-[calc(100%-2rem)] max-w-[540px]",style:{maxHeight:"70vh",background:"var(--color-surface)",border:"1px solid var(--color-border)",transform:S?"scale(1)":"scale(0.97)",transition:"transform 150ms ease-out"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-3.5 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center",style:{background:aa.folder.bg,color:aa.folder.fg},children:(0,n.jsx)(as,{category:"folder",size:18})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-semibold",style:{color:"var(--color-text)"},children:"Select Files"}),(0,n.jsx)("p",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:"Browse and attach files"})]})]}),(0,n.jsx)("button",{type:"button",onClick:r,className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]}),i&&(0,n.jsx)("div",{className:"flex items-center gap-1 px-5 py-2 border-b overflow-x-auto flex-shrink-0",style:{borderColor:"var(--color-border)",scrollbarWidth:"thin"},children:F.map((e,t)=>(0,n.jsxs)(o.Fragment,{children:[t>0&&(0,n.jsx)("span",{className:"text-[10px] flex-shrink-0",style:{color:"var(--color-text-muted)",opacity:.5},children:"/"}),(0,n.jsx)("button",{type:"button",onClick:()=>R(e.path),className:"text-[12px] font-medium flex-shrink-0 rounded px-1 py-0.5 hover:underline",style:{color:t===F.length-1?"var(--color-text)":"var(--color-text-muted)"},children:e.label})]},e.path))}),(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 rounded-lg px-2.5 py-1.5",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",flexShrink:0},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]}),(0,n.jsx)("input",{ref:L,type:"text",value:g,onChange:e=>y(e.target.value),placeholder:"Filter files...",className:"flex-1 bg-transparent outline-none text-[13px] placeholder:text-[var(--color-text-muted)]",style:{color:"var(--color-text)"}})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{j(!0),setTimeout(()=>{var e;return null==(e=T.current)?void 0:e.focus()},50)},className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[12px] font-medium whitespace-nowrap",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]}),"Folder"]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",style:{background:"var(--color-bg)",minHeight:200},children:f?(0,n.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):N?(0,n.jsx)("div",{className:"flex items-center justify-center py-16 text-[13px]",style:{color:"var(--color-text-muted)"},children:N}):(0,n.jsxs)(n.Fragment,{children:[x&&(0,n.jsxs)("button",{type:"button",onClick:()=>R(x),className:"w-full flex items-center gap-3 px-4 py-2 text-left",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0",style:{background:"var(--color-surface-hover)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})})}),(0,n.jsx)("span",{className:"text-[13px] font-medium",children:".."})]}),b&&(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2",children:[(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0",style:{background:aa.folder.bg,color:aa.folder.fg},children:(0,n.jsx)(as,{category:"folder"})}),(0,n.jsx)("input",{ref:T,type:"text",value:k,onChange:e=>w(e.target.value),onKeyDown:e=>{"Enter"===e.key&&W(),"Escape"===e.key&&(j(!1),w(""))},placeholder:"Folder name...",className:"flex-1 bg-transparent outline-none text-[13px] placeholder:text-[var(--color-text-muted)] rounded px-2 py-1",style:{color:"var(--color-text)",background:"var(--color-surface)",border:"1px solid var(--color-accent)"}})]}),0===B.length&&!x&&(0,n.jsx)("div",{className:"flex items-center justify-center py-16 text-[13px]",style:{color:"var(--color-text-muted)"},children:"This folder is empty"}),B.map(e=>{var t;let r="folder"===e.type,o=r?"folder":function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(n)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(n)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(n)?"audio":"pdf"===n?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(n)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv"].includes(n)?"document":"other"}(e.name),l=null!=(t=aa[o])?t:aa.other,a=p.has(e.path);return(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-1.5 group cursor-pointer",style:{background:a?"color-mix(in srgb, var(--color-accent) 8%, transparent)":void 0},onClick:()=>{r?R(e.path):E(e)},children:[(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),E(e)},className:"w-4 h-4 rounded flex items-center justify-center flex-shrink-0 border",style:{borderColor:a?"var(--color-accent)":"var(--color-border-strong)",background:a?"var(--color-accent)":"transparent"},children:a&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}),(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0",style:{background:l.bg,color:l.fg},children:(0,n.jsx)(as,{category:o})}),(0,n.jsx)("span",{className:"flex-1 text-[13px] truncate",style:{color:"var(--color-text)",fontWeight:r?500:400},title:e.path,children:e.name}),r&&(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-0 group-hover:opacity-50 transition-opacity",children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})]},e.path)})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-3 border-t flex-shrink-0",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("span",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:p.size>0?"".concat(p.size," ").concat(1===p.size?"item":"items"," selected"):"No files selected"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:r,className:"px-3 py-1.5 rounded-lg text-[13px] font-medium",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:"Cancel"}),(0,n.jsxs)("button",{type:"button",onClick:I,disabled:0===p.size,className:"px-3 py-1.5 rounded-lg text-[13px] font-medium disabled:opacity-40 disabled:cursor-not-allowed",style:{color:"white",background:p.size>0?"var(--color-accent)":"var(--color-border-strong)"},children:["Attach"," ",p.size>0&&"".concat(p.size," ").concat(1===p.size?"file":"files")]})]})]})]})]}):null}var ac=r(48997),ad=r(79534);let au=new(r(63550)).hs("chatFileMention"),ax=ad.bP.create({name:"chatFileMention",group:"inline",inline:!0,atom:!0,selectable:!0,draggable:!0,addAttributes:()=>({label:{default:""},path:{default:""},mentionType:{default:"file"},objectName:{default:""}}),parseHTML:()=>[{tag:"span[data-chat-file-mention]"}],renderHTML(e){let{HTMLAttributes:t}=e,r=t.label||"file",n=function(e,t){var r,n;if("object"===t)return{bg:"rgba(14,165,233,0.15)",fg:"#0ea5e9"};if("entry"===t)return{bg:"rgba(34,197,94,0.15)",fg:"#22c55e"};let o=null!=(n=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?n:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(o)?{bg:"rgba(16,185,129,0.15)",fg:"#10b981"}:["mp4","webm","mov","avi","mkv","flv"].includes(o)?{bg:"rgba(139,92,246,0.15)",fg:"#8b5cf6"}:["mp3","wav","ogg","aac","flac","m4a"].includes(o)?{bg:"rgba(245,158,11,0.15)",fg:"#f59e0b"}:"pdf"===o?{bg:"rgba(239,68,68,0.15)",fg:"#ef4444"}:["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(o)?{bg:"rgba(59,130,246,0.15)",fg:"#3b82f6"}:["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv"].includes(o)?{bg:"rgba(107,114,128,0.15)",fg:"#6b7280"}:{bg:"rgba(107,114,128,0.10)",fg:"#9ca3af"}}(r,t.mentionType);return["span",(0,ad.KV)({"data-chat-file-mention":"",class:"chat-file-mention",style:"--mention-bg: ".concat(n.bg,"; --mention-fg: ").concat(n.fg,";"),title:t.path||""},t),"@".concat(r)]}}),ah={folder:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},image:{bg:"rgba(16, 185, 129, 0.12)",fg:"#10b981"},video:{bg:"rgba(139, 92, 246, 0.12)",fg:"#8b5cf6"},audio:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},pdf:{bg:"rgba(239, 68, 68, 0.12)",fg:"#ef4444"},code:{bg:"rgba(59, 130, 246, 0.12)",fg:"#3b82f6"},document:{bg:"rgba(107, 114, 128, 0.12)",fg:"#6b7280"},database:{bg:"rgba(168, 85, 247, 0.12)",fg:"#a855f7"},object:{bg:"rgba(14, 165, 233, 0.12)",fg:"#0ea5e9"},entry:{bg:"rgba(34, 197, 94, 0.12)",fg:"#22c55e"},other:{bg:"rgba(107, 114, 128, 0.08)",fg:"#9ca3af"}};function ap(e){let{category:t}=e,r={width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};switch(t){case"folder":return(0,n.jsx)("svg",{...r,children:(0,n.jsx)("path",{d:"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"})});case"image":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,n.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M10 13h4"}),(0,n.jsx)("path",{d:"M10 17h4"})]});case"code":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]});case"database":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]});case"object":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]});case"entry":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,n.jsx)("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),(0,n.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]});default:return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"})]})}}let am=(0,o.forwardRef)((e,t)=>{let{items:r,command:l,loading:a}=e,[s,i]=(0,o.useState)(0),c=(0,o.useRef)(null);(0,o.useEffect)(()=>{i(0)},[r]),(0,o.useEffect)(()=>{var e;let t=null==(e=c.current)?void 0:e.children[s];null==t||t.scrollIntoView({block:"nearest"})},[s]);let d=(0,o.useCallback)(e=>{let t=r[e];t&&l(t)},[r,l]);return((0,o.useImperativeHandle)(t,()=>({onKeyDown:e=>{let{event:t}=e;return"ArrowUp"===t.key?(i(e=>(e+r.length-1)%r.length),!0):"ArrowDown"===t.key?(i(e=>(e+1)%r.length),!0):("Enter"===t.key||"Tab"===t.key)&&(d(s),!0)}})),a)?(0,n.jsx)("div",{className:"rounded-xl py-3 px-4 shadow-xl",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",backdropFilter:"blur(12px)",minWidth:260},children:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"w-3.5 h-3.5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:"Searching..."})]})}):0===r.length?(0,n.jsx)("div",{className:"rounded-xl py-3 px-4 shadow-xl",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",backdropFilter:"blur(12px)",minWidth:260},children:(0,n.jsx)("span",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:"No results found"})}):(0,n.jsx)("div",{ref:c,className:"rounded-xl py-1 shadow-xl overflow-y-auto",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",backdropFilter:"blur(12px)",minWidth:280,maxWidth:400,maxHeight:300},children:r.map((e,t)=>{var r;let o=function(e,t){var r,n;if("folder"===t)return"folder";if("database"===t)return"database";if("object"===t)return"object";if("entry"===t)return"entry";let o=null!=(n=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?n:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(o)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(o)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(o)?"audio":"pdf"===o?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(o)?"code":"document"===t?"document":"other"}(e.name,e.type),l=null!=(r=ah[o])?r:ah.other,a=e.icon&&RegExp("\\p{Emoji_Presentation}","u").test(e.icon),c="object"===e.type||"entry"===e.type,u="entry"===e.type&&e.objectName?e.objectName:c?e.type:e.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Z]:\\Users\\[^\\]+/,"~");return(0,n.jsxs)("button",{type:"button",className:"w-full flex items-center gap-2.5 px-3 py-1.5 text-left transition-colors",style:{background:t===s?"var(--color-surface-hover)":"transparent"},onClick:()=>d(t),onMouseEnter:()=>i(t),children:[(0,n.jsx)("div",{className:"w-6 h-6 rounded-md flex items-center justify-center flex-shrink-0",style:{background:l.bg,color:l.fg},children:a?(0,n.jsx)("span",{className:"text-[13px] leading-none",children:e.icon}):(0,n.jsx)(ap,{category:o})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-[12px] font-medium truncate",style:{color:"var(--color-text)"},children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] truncate flex items-center gap-1",style:{color:"var(--color-text-muted)"},title:c?u:e.path,children:[c&&(0,n.jsx)("span",{className:"inline-block rounded px-1 py-px text-[9px] font-medium leading-tight",style:{background:l.bg,color:l.fg},children:e.type}),u]})]}),"folder"===e.type&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-40",children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})]},e.path)})})});function af(e){let{items:t,command:r,clientRect:l,componentRef:a,loading:i}=e,c=(0,o.useRef)(null);return(0,o.useLayoutEffect)(()=>{if(!c.current||!l)return;let e=l();if(!e)return;let t=c.current,r=t.offsetHeight||200;window.innerHeight-e.bottom<r+8?(t.style.position="fixed",t.style.left="".concat(e.left,"px"),t.style.bottom="".concat(window.innerHeight-e.top+4,"px"),t.style.top="auto"):(t.style.position="fixed",t.style.left="".concat(e.left,"px"),t.style.top="".concat(e.bottom+4,"px"),t.style.bottom="auto"),t.style.zIndex="100"},[l,t,i]),(0,s.createPortal)((0,n.jsx)("div",{ref:c,children:(0,n.jsx)(am,{ref:a,items:t,command:r,loading:i})}),document.body)}function av(e){if(!e)return{text:"",mentionedFiles:[]};let t=[],r=[];return e.state.doc.forEach(e=>{if("paragraph"===e.type.name||"hardBreak"===e.type.name){let n="";e.descendants(e=>{if("chatFileMention"===e.type.name){let r=e.attrs.label,o=e.attrs.path,l=e.attrs.mentionType,a=e.attrs.objectName;return t.push({name:r,path:o}),"object"===l?n+="[object: ".concat(r,"]"):"entry"===l?n+="[entry: ".concat(a?"".concat(a,"/"):"").concat(r,"]"):n+="[file: ".concat(o,"]"),!1}return e.isText&&e.text&&(n+=e.text),"hardBreak"===e.type.name&&(n+="\n"),!0}),r.push(n)}}),{text:r.join("\n").trim(),mentionedFiles:t}}am.displayName="FileMentionList";let ag=(0,o.forwardRef)(function(e,t){let{onSubmit:l,onChange:a,onNativeFileDrop:s,placeholder:i,disabled:c,compact:d}=e,u=(0,o.useRef)(l);u.current=l;let x=(0,o.useRef)(s);x.current=s;let h=(0,o.useRef)(null),p=(0,nG.hG)({immediatelyRender:!1,extensions:[nZ.A.configure({heading:!1,codeBlock:!1,blockquote:!1,horizontalRule:!1,bulletList:!1,orderedList:!1,listItem:!1}),n6.A.configure({placeholder:null!=i?i:"Ask anything...",showOnlyWhenEditable:!1}),ax,ad.YY.create({name:"chatFileMentionSuggestion",addProseMirrorPlugins(){return[(0,ac.Ay)({editor:this.editor,char:"@",pluginKey:au,startOfLine:!1,allowSpaces:!0,command:e=>{var t;let{editor:r,range:n,props:o}=e;if("folder"===o.type){let e=o.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Z]:\\Users\\[^\\]+/,"~");r.chain().focus().deleteRange(n).insertContent("@".concat(e,"/")).run();return}let l="object"===o.type?"object":"entry"===o.type?"entry":"file";r.chain().focus().deleteRange(n).insertContent([{type:"chatFileMention",attrs:{label:o.name,path:o.path,mentionType:l,objectName:null!=(t=o.objectName)?t:""}},{type:"text",text:" "}]).run()},items:e=>{let{query:t}=e;return[]},render:()=>{let e=null,t=null,o={current:null},l="",a=[],s=!1,i=null,c=null,d=null;function u(){t&&c&&t.render((0,n.jsx)(af,{items:a,command:c,clientRect:d,componentRef:o,loading:s}))}async function x(e){s=!0,u();try{var t;let r=e.startsWith("/")||e.startsWith("~/")||e.startsWith("../")||e.startsWith("./")||e.includes("/")?"path=".concat(encodeURIComponent(e)):e?"q=".concat(encodeURIComponent(e)):"",n=await fetch("/api/workspace/suggest-files".concat(r?"?".concat(r):""));a=null!=(t=(await n.json()).items)?t:[]}catch(e){a=[]}s=!1,u()}function h(e){i&&clearTimeout(i),i=setTimeout(()=>{x(e)},120)}return{onStart:n=>{var o;e=document.createElement("div"),document.body.appendChild(e),c=n.command,d=null!=(o=n.clientRect)?o:null,l=n.query,Promise.resolve().then(r.t.bind(r,80282,19)).then(r=>{let{createRoot:n}=r;t=n(e),h(l)})},onUpdate:e=>{var t;c=e.command,d=null!=(t=e.clientRect)?t:null,h(l=e.query)},onKeyDown:r=>{var n,l;if("Escape"===r.event.key)return null==t||t.unmount(),null==e||e.remove(),e=null,t=null,!0;let a=null!=(l=null==(n=o.current)?void 0:n.onKeyDown(r))&&l;return a&&r.event.stopImmediatePropagation(),a},onExit:()=>{i&&clearTimeout(i),null==t||t.unmount(),null==e||e.remove(),e=null,t=null}}}})]}})],editorProps:{attributes:{class:"chat-editor-content ".concat(d?"chat-editor-compact":""),style:"color: var(--color-text);"},handleKeyDown:(e,t)=>("Enter"===t.key&&!t.shiftKey,!1),handleDOMEvents:{paste:(e,t)=>{let r=t.clipboardData;if(!r)return!1;let n=[];if(r.items){for(let e of Array.from(r.items))if("file"===e.kind){let t=e.getAsFile();t&&n.push(t)}}if(n.length>0){var o;t.preventDefault();let e=new DataTransfer;for(let t of n)e.items.add(t);return null==(o=x.current)||o.call(x,e.files),!0}return!1},dragover:(e,t)=>{var r,n;return!!((null==(r=t.dataTransfer)?void 0:r.types.includes("application/x-file-mention"))||(null==(n=t.dataTransfer)?void 0:n.types.includes("Files")))&&(t.preventDefault(),t.dataTransfer.dropEffect="copy",!0)},drop:(e,t)=>{var r,n,o,l;let a=null==(r=t.dataTransfer)?void 0:r.getData("application/x-file-mention");if(a){t.preventDefault(),t.stopPropagation();try{let{name:e,path:t}=JSON.parse(a);e&&t&&(null==(o=h.current)||o.chain().focus().insertContent([{type:"chatFileMention",attrs:{label:e,path:t}},{type:"text",text:" "}]).run())}catch(e){}return!0}let s=null==(n=t.dataTransfer)?void 0:n.files;return!!s&&s.length>0&&(t.preventDefault(),t.stopPropagation(),null==(l=x.current)||l.call(x,s),!0)}}},onUpdate:e=>{let{editor:t}=e;null==a||a(t.isEmpty)}});return(0,o.useEffect)(()=>{h.current=null!=p?p:null},[p]),(0,o.useEffect)(()=>{if(!p)return;let e=e=>{if("Enter"===e.key&&!e.shiftKey&&!e.isComposing){let t=au.getState(p.state);if(null==t?void 0:t.active)return;e.preventDefault();let{text:r,mentionedFiles:n}=av(p);if(r.trim()||n.length>0){let e=p.getHTML();u.current(r,n,e),p.commands.clearContent(!0)}}},t=p.view.dom;return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[p]),(0,o.useEffect)(()=>{p&&p.setEditable(!c)},[p,c]),(0,o.useImperativeHandle)(t,()=>({insertFileMention:(e,t)=>{null==p||p.chain().focus().insertContent([{type:"chatFileMention",attrs:{label:e,path:t}},{type:"text",text:" "}]).run()},clear:()=>{null==p||p.commands.clearContent(!0)},focus:()=>{null==p||p.commands.focus()},isEmpty:()=>{var e;return null==(e=null==p?void 0:p.isEmpty)||e},submit:()=>{if(!p)return;let{text:e,mentionedFiles:t}=av(p);if(e.trim()||t.length>0){let r=p.getHTML();u.current(e,t,r),p.commands.clearContent(!0)}},setText:e=>{null==p||p.commands.setContent(e),null==p||p.commands.focus("end")}})),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(nG.$Z,{editor:p}),(0,n.jsx)("style",{children:"\n .chat-editor-content {\n outline: none;\n min-height: ".concat(d?"16px":"28px",";\n max-height: 200px;\n overflow-y: auto;\n padding: ").concat(d?"10px 12px":"14px 16px",";\n font-size: ").concat(d?"12px":"14px",';\n line-height: 1.5;\n transition: opacity 0.15s ease;\n }\n .chat-editor-content[contenteditable="false"] {\n opacity: 0.5;\n cursor: not-allowed;\n }\n .chat-editor-content p {\n margin: 0;\n }\n .chat-editor-content p.is-editor-empty:first-child::before {\n content: attr(data-placeholder);\n color: var(--color-text-muted);\n float: left;\n height: 0;\n pointer-events: none;\n }\n /* File mention pill styles */\n .chat-editor-content span[data-chat-file-mention] {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n padding: 1px 8px 1px 6px;\n margin: 0 1px;\n border-radius: 6px;\n background: var(--mention-bg, rgba(59, 130, 246, 0.12));\n color: var(--mention-fg, #3b82f6);\n font-size: 12px;\n font-weight: 500;\n line-height: 1.6;\n vertical-align: baseline;\n cursor: default;\n user-select: all;\n white-space: nowrap;\n transition: opacity 0.15s ease;\n }\n .chat-editor-content span[data-chat-file-mention]::before {\n content: "@";\n opacity: 0.5;\n font-size: 11px;\n }\n .chat-editor-content span[data-chat-file-mention]:hover {\n opacity: 0.85;\n }\n .chat-editor-content.chat-editor-compact {\n min-height: 16px;\n }\n ')})]})}),ay=[{id:"email-draft",label:"Draft an Email",icon:ll.A,prompt:"Draft a professional follow-up email to a client after our initial meeting, thanking them and summarizing the next steps we discussed"},{id:"enrich-contacts",label:"Enrich Leads",icon:la.A,prompt:"When a new contact is added to my CRM, find their LinkedIn profile and company details and update the record"},{id:"invoice-reminder",label:"Invoice Reminder",icon:ls.A,prompt:"Draft a friendly payment reminder email for an invoice that is 7 days overdue, including the invoice number and amount"},{id:"schedule-report",label:"Weekly Report",icon:li.A,prompt:"Set up a cron job that runs every Friday at 4pm to compile a summary of all completed tasks this week and email it to the team"},{id:"auto-tasks",label:"Auto Tasks",icon:lc.A,prompt:"Create a workflow that automatically creates a task whenever someone mentions me in an email with a request or action item"},{id:"summarize-docs",label:"Summarize Docs",icon:ld.A,prompt:"Read through all the documents in my workspace and create a concise summary of the key information across all files"},{id:"query-data",label:"Query Database",icon:lu.A,prompt:"Connect to my database and show me the top 10 customers by revenue this quarter, including their contact details"},{id:"code-review",label:"Review Code",icon:lx.A,prompt:"Review the code in my workspace for potential bugs, security issues, and performance improvements. Prioritize critical findings"},{id:"debug-error",label:"Debug Error",icon:lh.A,prompt:"Help me debug this error I'm seeing in production. Walk me through the likely causes and how to fix each one"},{id:"daily-digest",label:"Daily Digest",icon:lp.A,prompt:"Set up a daily digest that runs every morning at 9am summarizing my unread emails, calendar events, and pending tasks"},{id:"analyze-csv",label:"Analyze Data",icon:lm.A,prompt:"Analyze the CSV file in my workspace — find trends, outliers, and generate a visual report with key insights"},{id:"write-content",label:"Write Content",icon:lf.A,prompt:"Write a compelling blog post about how AI automation is transforming small business operations in 2026"},{id:"web-research",label:"Web Research",icon:lv.A,prompt:"Research the top 5 competitors in my industry and create a comparison table with their pricing, features, and market position"},{id:"search-files",label:"Search Files",icon:lg.A,prompt:"Search through all files in my workspace and find every mention of customer feedback, complaints, or feature requests"},{id:"brainstorm",label:"Brainstorm Ideas",icon:ly.A,prompt:"Help me brainstorm 10 creative marketing campaign ideas for launching a new product to our existing customer base"},{id:"organize-files",label:"Organize Files",icon:lb.A,prompt:"Look at all the files in my workspace and suggest a better folder structure. Then reorganize them for me"},{id:"create-spreadsheet",label:"Build Spreadsheet",icon:lj.A,prompt:"Create a project tracking spreadsheet with columns for task name, assignee, status, priority, due date, and notes"},{id:"ai-strategy",label:"AI Strategy",icon:lk.A,prompt:"Help me create an AI adoption strategy for my team — which tasks should we automate first for the biggest impact?"},{id:"meeting-prep",label:"Meeting Prep",icon:lw.A,prompt:"Prepare a briefing document for my upcoming client meeting. Include their recent activity, open issues, and talking points"},{id:"build-workflow",label:"Build Workflow",icon:lN.A,prompt:"Design an automated onboarding workflow for new clients — from welcome email to document collection to account setup"}];function ab(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(n)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(n)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(n)?"audio":"pdf"===n?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(n)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv","pages","numbers","key"].includes(n)?"document":"other"}let aj={image:{bg:"rgba(16, 185, 129, 0.12)",fg:"#10b981"},video:{bg:"rgba(139, 92, 246, 0.12)",fg:"#8b5cf6"},audio:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},pdf:{bg:"rgba(239, 68, 68, 0.12)",fg:"#ef4444"},code:{bg:"rgba(59, 130, 246, 0.12)",fg:"#3b82f6"},document:{bg:"rgba(107, 114, 128, 0.12)",fg:"#6b7280"},other:{bg:"rgba(107, 114, 128, 0.08)",fg:"#9ca3af"}};function ak(e){let{category:t}=e,r={width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};switch(t){case"image":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,n.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,n.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M10 13h4"}),(0,n.jsx)("path",{d:"M10 17h4"})]});case"code":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]});case"document":return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"}),(0,n.jsx)("path",{d:"M10 9H8"})]});default:return(0,n.jsxs)("svg",{...r,children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("path",{d:"M14 2v6h6"})]})}}function aw(e){let{msg:t,idx:r,onEdit:l,onSendNow:a,onRemove:s}=e,[i,c]=(0,o.useState)(!1),[d,u]=(0,o.useState)(t.text),x=(0,o.useRef)(null),h=()=>{let e=x.current;e&&(e.style.height="auto",e.style.height="".concat(e.scrollHeight,"px"))};(0,o.useEffect)(()=>{if(i){var e,t,r,n;null==(e=x.current)||e.focus();let o=null!=(n=null==(t=x.current)?void 0:t.value.length)?n:0;null==(r=x.current)||r.setSelectionRange(o,o),h()}},[i]);let p=()=>{let e=d.trim();e&&e!==t.text?l(t.id,e):u(t.text),c(!1)};return(0,n.jsxs)("div",{className:"flex items-start gap-2.5 group py-2 ".concat(r>0?"border-t":""),style:r>0?{borderColor:"var(--color-border)"}:void 0,children:[(0,n.jsx)("span",{className:"shrink-0 mt-px text-[11px] font-medium tabular-nums w-4",style:{color:"var(--color-text-muted)"},children:r+1}),i?(0,n.jsx)("textarea",{ref:x,className:"flex-1 text-[13px] leading-[1.45] min-w-0 resize-none rounded-md px-2 py-1 outline-none",style:{color:"var(--color-text-secondary)",background:"var(--color-bg)",border:"1px solid var(--color-border)"},rows:1,value:d,onChange:e=>{u(e.target.value),h()},onBlur:p,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),p()),"Escape"===e.key&&(u(t.text),c(!1))}}):(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[t.attachedFiles.length>0&&(0,n.jsx)("div",{className:"flex gap-1 shrink-0",children:t.attachedFiles.map(e=>{let t="image"===ab(e.name)?e.localUrl||"/api/workspace/raw-file?path=".concat(encodeURIComponent(e.path)):e.path?"/api/workspace/thumbnail?path=".concat(encodeURIComponent(e.path),"&size=100"):void 0;return(0,n.jsx)("img",{src:t,alt:e.name,className:"rounded object-cover",style:{height:28,width:28,background:"var(--color-surface-hover)"},onError:e=>{e.currentTarget.style.display="none"}},e.id)})}),(0,n.jsx)("p",{className:"text-[13px] leading-[1.45] line-clamp-1 min-w-0",style:{color:"var(--color-text-secondary)"},children:t.text||"".concat(t.attachedFiles.length," ").concat(1===t.attachedFiles.length?"file":"files")})]}),!i&&(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Edit message",onClick:()=>{u(t.text),c(!0)},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,n.jsx)("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,n.jsx)("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})]})}),(0,n.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Send now",onClick:()=>a(t.id),children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,n.jsx)("path",{d:"M12 19V5"}),(0,n.jsx)("path",{d:"m5 12 7-7 7 7"})]})}),(0,n.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Remove from queue",onClick:()=>s(t.id),children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})})]})]})}function aN(e){let{files:t,compact:r,onRemove:o,onClearAll:l}=e;return 0===t.length?null:(0,n.jsx)("div",{className:"".concat(r?"px-2":"px-3"," pt-2"),children:(0,n.jsx)("div",{className:"flex gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"thin"},children:t.map(e=>{var t;let r=ab(e.name),l=null!=(t=aj[r])?t:aj.other,a=e.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Z]:\\Users\\[^\\]+/,"~");return(0,n.jsxs)("div",{className:"relative group flex-shrink-0 rounded-xl overflow-hidden",style:{background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>o(e.id),className:"absolute top-1 right-1 z-10 w-[18px] h-[18px] rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",style:{background:"rgba(0,0,0,0.55)",color:"white",backdropFilter:"blur(4px)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}),"image"===r?(0,n.jsx)("img",{src:e.localUrl||"/api/workspace/raw-file?path=".concat(encodeURIComponent(e.path)),alt:e.name,className:"block rounded-xl object-cover",style:{height:80,width:"auto",minWidth:60,maxWidth:140,opacity:e.uploading?.6:1,background:"var(--color-bg-secondary)"},onError:e=>{e.currentTarget.style.display="none"}}):"pdf"===r&&e.path?(0,n.jsx)("img",{src:"/api/workspace/thumbnail?path=".concat(encodeURIComponent(e.path),"&size=200"),alt:e.name,className:"block rounded-xl object-cover",style:{height:80,width:"auto",minWidth:60,maxWidth:140,opacity:e.uploading?.6:1,background:"var(--color-bg-secondary)"},onError:e=>{e.currentTarget.style.display="none"}}):(0,n.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2.5",style:{opacity:e.uploading?.6:1},children:[(0,n.jsx)("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:l.bg,color:l.fg},children:(0,n.jsx)(ak,{category:r})}),(0,n.jsxs)("div",{className:"min-w-0 max-w-[140px]",children:[(0,n.jsx)("p",{className:"text-[11px] font-medium truncate",style:{color:"var(--color-text)"},title:e.path||e.name,children:e.name}),(0,n.jsx)("p",{className:"text-[9px] truncate",style:{color:"var(--color-text-muted)"},title:e.path||e.name,children:e.uploading?"Uploading...":a})]})]})]},e.id)})})})}let aC=(0,o.forwardRef)(function(e,t){var r,l;let{fileContext:a,compact:s,sessionTitle:i,initialSessionId:c,onFileChanged:d,onActiveSessionChange:u,onSessionsChange:x,onSubagentSpawned:h,onSubagentClick:p,onFilePathClick:m,onDeleteSession:f,onRenameSession:v,sessionKey:g,subagentTask:y,subagentLabel:b,onBack:j}=e,k=!!g,w=(0,o.useRef)(null),[N,C]=(0,o.useState)(!0),[S,M]=(0,o.useState)(null),[L,T]=(0,o.useState)(!1),D=(0,o.useRef)(null),[E,R]=(0,o.useState)([]),[W,I]=(0,o.useState)(!1),[B,F]=(0,o.useState)(!1),P=(0,o.useRef)(null),[A,_]=(0,o.useState)(null),z=(0,o.useRef)(new Set),O=(0,o.useRef)(!1),U=(0,o.useRef)(!0),[H,V]=(0,o.useState)([]),J=(0,o.useRef)(new Map),K=(0,o.useRef)(null),[q,$]=(0,o.useState)([]),[Z,Y]=(0,o.useState)(!1),[Q,X]=(0,o.useState)(""),[ee,et]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=[(()=>{let e=new Date().getHours();return e<12?"Good morning!":e<17?"Good afternoon!":"Good evening!"})(),"Ready to build?","Let's automate something?","What shall we tackle?","Ready to get things done?","Let's get to work?","How can I help?"];X(e[Math.floor(Math.random()*e.length)])},[]),(0,o.useEffect)(()=>{et([...ay].sort(()=>.5-Math.random()).slice(0,7))},[]);let er=(0,o.useCallback)(e=>{var t;let r=ay.find(t=>t.id===e);r&&(null==(t=w.current)||t.setText(r.prompt),C(!1))},[]),en=null!=(r=null==a?void 0:a.path)?r:null,eo=(0,o.useRef)(null);(0,o.useEffect)(()=>{eo.current=S},[S]);let el=(0,o.useRef)(g);(0,o.useEffect)(()=>{el.current=g},[g]);let ea=(0,o.useMemo)(()=>new lr.rL({api:"/api/chat",body:()=>{let e={},t=el.current;t&&(e.sessionKey=t);let r=eo.current;return r&&(e.sessionId=r),K.current&&(e.userHtml=K.current,K.current=null),e}}),[]),{messages:es,sendMessage:ei,status:ec,stop:ed,error:eu,setMessages:ex}=(0,lt.Y_)({transport:ea}),eh="streaming"===ec||"submitted"===ec||B,ep=(0,o.useRef)(null);(0,o.useEffect)(()=>(ep.current&&(clearTimeout(ep.current),ep.current=null),"submitted"===ec&&(ep.current=setTimeout(()=>{ep.current=null,"submitted"===ec&&(_("Request timed out — no response from agent. Try again or check the gateway."),ed())},9e4)),()=>{ep.current&&(clearTimeout(ep.current),ep.current=null)}),[ec,ed]);let em=(0,o.useRef)(null),ef=(0,o.useRef)(!1),ev=(0,o.useRef)(0);(0,o.useEffect)(()=>{let e=em.current;if(!e)return;let t=()=>{ef.current=e.scrollHeight-e.scrollTop-e.clientHeight>80};return e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)},[]),(0,o.useEffect)(()=>{!ef.current&&(ev.current||(ev.current=requestAnimationFrame(()=>{var e;ev.current=0,null==(e=D.current)||e.scrollIntoView({behavior:"smooth"})})))},[es]);let eg=(0,o.useCallback)(async e=>{let t={title:e};en&&(t.filePath=en);let r=await fetch("/api/web-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return(await r.json()).session.id},[en]),ey=(0,o.useCallback)(async(e,t,r)=>{let n=new AbortController;P.current=n;try{let o=(null==r?void 0:r.sessionKey)?"sessionKey=".concat(encodeURIComponent(r.sessionKey)):"sessionId=".concat(encodeURIComponent(e)),l=await fetch("/api/chat/stream?".concat(o),{signal:n.signal});if(!l.ok||!l.body)return!1;if("false"===l.headers.get("X-Run-Active"))return l.body.cancel(),!1;F(!0);let a=function(){let e=[],t=-1,r=-1;return{processEvent:function(n){var o,l,a,s;switch(n.type){case"user-message":t=-1,r=-1,e.push({type:"user-message",id:n.id,text:null!=(o=n.text)?o:""});break;case"reasoning-start":e.push({type:"reasoning",text:"",state:"streaming"}),r=e.length-1;break;case"reasoning-delta":if(r>=0){let t=e[r];t.text+=n.delta}break;case"reasoning-end":if(r>=0){let t=e[r];delete t.state}r=-1;break;case"text-start":e.push({type:"text",text:""}),t=e.length-1;break;case"text-delta":if(t>=0){let r=e[t];r.text+=n.delta}break;case"text-end":t=-1;break;case"tool-input-start":e.push({type:"dynamic-tool",toolCallId:n.toolCallId,toolName:n.toolName,state:"input-available",input:{}});break;case"tool-input-available":for(let t=e.length-1;t>=0;t--){let r=e[t];if("dynamic-tool"===r.type&&r.toolCallId===n.toolCallId){r.input=null!=(l=n.input)?l:{};break}}break;case"tool-output-partial":for(let t=e.length-1;t>=0;t--){let r=e[t];if("dynamic-tool"===r.type&&r.toolCallId===n.toolCallId){r.output=null!=(a=n.output)?a:{};break}}break;case"tool-output-available":for(let t=e.length-1;t>=0;t--){let r=e[t];if("dynamic-tool"===r.type&&r.toolCallId===n.toolCallId){r.state="output-available",r.output=null!=(s=n.output)?s:{};break}}break;case"tool-output-error":for(let t=e.length-1;t>=0;t--){let r=e[t];if("dynamic-tool"===r.type&&r.toolCallId===n.toolCallId){r.state="error",r.output={error:n.errorText};break}}}},getParts:()=>e.map(e=>({...e}))}}(),s=l.body.getReader(),i=new TextDecoder,c="reconnect-".concat(e),d="",u=!1,x=()=>{if(n.signal.aborted)return;let e={id:c,role:"assistant",parts:a.getParts()};ex([...t,e])};for(;;){let e,{done:t,value:r}=await s.read();if(t)break;for(d+=i.decode(r,{stream:!0});-1!==(e=d.indexOf("\n\n"));){let t=d.slice(0,e);if(d=d.slice(e+2),t.startsWith("data: "))try{let e=JSON.parse(t.slice(6));a.processEvent(e)}catch(e){}}u||(u=!0,requestAnimationFrame(()=>{u=!1,x()}))}if(x(),!n.signal.aborted){for(let e of t)z.current.add(e.id);z.current.add(c)}return F(!1),P.current=null,!0}catch(e){return"AbortError"!==e.name&&console.error("Reconnection error:",e),F(!1),P.current=null,!1}},[ex]),eb=(0,o.useRef)(null);eb.current=async()=>{if(!en)return[];try{let e=await fetch("/api/web-sessions?filePath=".concat(encodeURIComponent(en)));return(await e.json()).sessions||[]}catch(e){return[]}},(0,o.useEffect)(()=>{if(!en||k)return;let e=!1;return eo.current=null,M(null),null==u||u(null),ex([]),z.current.clear(),U.current=!0,(async()=>{var t,r,n;let o=null!=(r=await (null==(t=eb.current)?void 0:t.call(eb)))?r:[];if(!e&&(V(o),o.length>0)){let t=null!=(n=c?o.find(e=>e.id===c):void 0)?n:o[0];M(t.id),eo.current=t.id,null==u||u(t.id),U.current=!1;try{let r=await fetch("/api/web-sessions/".concat(t.id));if(e)return;let n=(await r.json()).messages||[],o=n.some(e=>e._streaming)?n.filter(e=>!e._streaming):n;for(let e of o)"user"===e.role&&e.html&&J.current.set(e.id,e.html);let l=o.map(e=>{var t;return z.current.add(e.id),{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}});e||ex(l),e||await ey(t.id,l)}catch(e){}}})(),()=>{e=!0}},[en,ey]);let ej=(0,o.useRef)(!1),ek=(0,o.useRef)(null);(0,o.useEffect)(()=>{!en&&!k&&c&&(ej.current&&c===ek.current||(ej.current=!0,ek.current=c,eT(c)))},[c]),(0,o.useEffect)(()=>{var e;if(!g||!y)return;let t=!1;null==(e=P.current)||e.abort(),ed(),z.current.clear(),$([]);let r={id:"task-".concat(g),role:"user",parts:[{type:"text",text:y}]};return ex([r]),(async()=>{if(t)return;let e=[r];try{let n=await fetch("/api/web-sessions/".concat(encodeURIComponent(g)));if(t)return;if(n.ok){let o=(await n.json()).messages||[],l=o.some(e=>e._streaming)?o.filter(e=>!e._streaming):o;if(l.length>0){for(let e of l)"user"===e.role&&e.html&&J.current.set(e.id,e.html);let n=l.map(e=>{var t;return z.current.add(e.id),{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}});e=[r,...n],t||ex(e)}}}catch(e){}t||await ey(g,e,{sessionKey:g})})(),()=>{var e;t=!0,null==(e=P.current)||e.abort()}},[g,y,ey]);let[ew,eN]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!S||!h)return;let e=!1,t=async()=>{try{var t;let r=await fetch("/api/chat/subagents?sessionId=".concat(encodeURIComponent(S)));if(e||!r.ok)return;let n=null!=(t=(await r.json()).subagents)?t:[],o=!1;for(let e of n)"running"===e.status&&(o=!0),h({childSessionKey:e.sessionKey,runId:e.runId,task:e.task,label:e.label,parentSessionId:S,status:e.status});e||eN(o)}catch(e){}};t();let r=setInterval(t,3e3);return()=>{e=!0,clearInterval(r)}},[S,h]);let eC=(0,o.useRef)(ec);(0,o.useEffect)(()=>{let e="streaming"===eC.current||"submitted"===eC.current,t="ready"===ec;if(e&&t&&S){for(let e of es)z.current.add(e.id);if(en){var r;null==(r=eb.current)||r.call(eb).then(e=>{V(e)})}en&&d&&fetch("/api/workspace/file?path=".concat(encodeURIComponent(en))).then(e=>e.json()).then(e=>{e.content&&d(e.content)}).catch(()=>{}),null==x||x()}eC.current=ec},[ec,es,S,en,d,x]),(0,o.useEffect)(()=>{let e="streaming"===eC.current||"submitted"===eC.current,t="ready"===ec;if(e&&t){let e=es[es.length-1];(null==e?void 0:e.role)==="assistant"&&e.parts.some(e=>"text"===e.type&&e.text.trim().length>0||"tool-invocation"===e.type)||eu?_(null):_("No response received from agent.")}"submitted"===ec&&_(null)},[ec,es,eu]);let eS=(0,o.useRef)(()=>{}),eM=(0,o.useCallback)(async(e,t,r,n)=>{let o=e.trim().length>0,l=t.length>0,s=n?n.filter(e=>!e.uploading&&e.path):E.filter(e=>!e.uploading&&e.path),i=s.length>0;if(!o&&!l&&!i)return;let c=e.trim(),d=[...s];if("/new"===c.toLowerCase()){for(let e of E)e.localUrl&&URL.revokeObjectURL(e.localUrl);R([]),eS.current();return}if(eh){n||R([]),$(e=>[...e,{id:crypto.randomUUID(),text:c,html:r,mentionedFiles:t,attachedFiles:d,createdAt:Date.now()}]);return}if(!n&&d.length>0){for(let e of E)e.localUrl&&URL.revokeObjectURL(e.localUrl);R([])}let h=S;if(!h&&!k){let e=c||"File attachment",t=e.length>60?e.slice(0,60)+"...":e;if(M(h=await eg(t)),eo.current=h,null==u||u(h),null==x||x(),en){var p;null==(p=eb.current)||p.call(eb).then(e=>{V(e)})}}let m=c,f=[...t.map(e=>e.path),...d.map(e=>e.path)];if(f.length>0){let e="[Attached files: ".concat(f.join(", "),"]");m=m?"".concat(e,"\n\n").concat(m):e}if(a&&U.current){let e=a.isDirectory?"directory":"file";m="[Context: workspace ".concat(e," '").concat(a.path,"']\n\n").concat(m),U.current=!1}J.current.set(m,r),K.current=r,ef.current=!1,ei({text:m})},[E,eh,S,eg,u,x,en,a,ei]),eL=(0,o.useRef)(ec);(0,o.useEffect)(()=>{let e="streaming"===eL.current||"submitted"===eL.current,t="ready"===ec;if(eL.current=ec,e&&t&&q.length>0){let[e,...t]=q;for(let r of($(t),e.attachedFiles))r.localUrl&&URL.revokeObjectURL(r.localUrl);queueMicrotask(()=>{eM(e.text,e.mentionedFiles,e.html,e.attachedFiles)})}},[ec,q,eM]);let eT=(0,o.useCallback)(async e=>{var t;if(e!==S){null==(t=P.current)||t.abort(),ed(),T(!0),M(e),eo.current=e,null==u||u(e),z.current.clear(),U.current=!1,$([]);try{let t=await fetch("/api/web-sessions/".concat(e));if(!t.ok)throw Error("Failed to load session");let r=(await t.json()).messages||[],n=r.some(e=>e._streaming)?r.filter(e=>!e._streaming):r;for(let e of(J.current.clear(),n))"user"===e.role&&e.html&&J.current.set(e.id,e.html);let o=n.map(e=>{var t;return z.current.add(e.id),{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}});ex(o),T(!1),await ey(e,o)}catch(e){console.error("Error loading session:",e),T(!1)}}},[S,ex,u,ed,ey]),eD=(0,o.useCallback)(()=>{var e;null==(e=P.current)||e.abort(),ed(),F(!1),M(null),eo.current=null,null==u||u(null),ex([]),z.current.clear(),J.current.clear(),U.current=!0,O.current=!1,$([]),requestAnimationFrame(()=>{var e;null==(e=w.current)||e.focus()})},[ex,u,ed]);eS.current=eD,(0,o.useImperativeHandle)(t,()=>({loadSession:eT,newSession:async()=>{eD()},sendNewMessage:async e=>{eD();let t=e.length>60?e.slice(0,60)+"...":e,r=await eg(t);M(r),eo.current=r,null==u||u(r),null==x||x(),ef.current=!1,ei({text:e})},insertFileMention:(e,t)=>{var r;null==(r=w.current)||r.insertFileMention(e,t)}}),[eT,eD,eg,u,x,ei]);let eE=(0,o.useCallback)(async()=>{var e;if(null==(e=P.current)||e.abort(),F(!1),g||S)try{await fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g?{sessionKey:g}:{sessionId:S})})}catch(e){}ed()},[S,g,ed]),eR=(0,o.useCallback)(e=>{$(t=>t.filter(t=>t.id!==e))},[]),eW=(0,o.useCallback)((e,t)=>{$(r=>r.map(r=>r.id===e?{...r,text:t}:r))},[]),eI=(0,o.useCallback)(async e=>{let t=q.find(t=>t.id===e);t&&($(t=>t.filter(t=>t.id!==e)),await eE(),setTimeout(()=>{eM(t.text,t.mentionedFiles,t.html,t.attachedFiles)},100))},[q,eE,eM]),eB=(0,o.useCallback)(e=>{let t=e.map(e=>({id:"".concat(e.path,"-").concat(Date.now(),"-").concat(Math.random().toString(36).slice(2)),name:e.name,path:e.path}));R(e=>[...e,...t])},[]),eF=(0,o.useCallback)(e=>{R(t=>{let r=t.find(t=>t.id===e);return(null==r?void 0:r.localUrl)&&URL.revokeObjectURL(r.localUrl),t.filter(t=>t.id!==e)})},[]),eP=(0,o.useCallback)(()=>{R(e=>{for(let t of e)t.localUrl&&URL.revokeObjectURL(t.localUrl);return[]})},[]),eA=(0,o.useCallback)(e=>{let t=Array.from(e),r=t.map(e=>({id:"pending-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2)),name:e.name,path:"",uploading:!0,localUrl:URL.createObjectURL(e)}));R(e=>[...e,...r]);for(let e=0;e<t.length;e++){let n=t[e],o=r[e].id,l=r[e].localUrl,a=new FormData;a.append("file",n),fetch("/api/workspace/upload",{method:"POST",body:a}).then(e=>e.ok?e.json():null).then(e=>{(null==e?void 0:e.ok)&&e.path?R(t=>t.map(t=>t.id===o?{...t,path:e.path,uploading:!1}:t)):(R(e=>e.filter(e=>e.id!==o)),l&&URL.revokeObjectURL(l))}).catch(()=>{R(e=>e.filter(e=>e.id!==o)),l&&URL.revokeObjectURL(l)})}},[]),e_=es.length>0?es[es.length-1]:null,ez=(null==e_?void 0:e_.role)==="assistant"&&e_.parts.some(e=>"text"===e.type&&e.text.length>0),eO=eh&&!ez,eU=0===es.length&&!s&&!k&&!L,eH=(0,n.jsxs)(n.Fragment,{children:[q.length>0&&(0,n.jsx)("div",{className:s?"px-2 pt-2":"px-3 pt-3",children:(0,n.jsxs)("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",boxShadow:"var(--shadow-sm)"},children:[(0,n.jsxs)("div",{className:"px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:["Queue (",q.length,")"]}),(0,n.jsx)("div",{className:"flex flex-col p-2",children:q.map((e,t)=>(0,n.jsx)(aw,{msg:e,idx:t,onEdit:eW,onSendNow:eI,onRemove:eR},e.id))})]})}),!k&&(0,n.jsx)(aN,{files:E,compact:s,onRemove:eF,onClearAll:eP}),(0,n.jsx)(ag,{ref:w,onSubmit:eM,onChange:e=>C(e),onNativeFileDrop:k?void 0:eA,placeholder:eU?"Build a workflow to automate your tasks":k?eh?"Type to queue a message...":"Type @ to mention files...":s&&a?"Ask about ".concat(a.isDirectory?"this folder":a.filename,"..."):eh?"Type to queue a message...":E.length>0?"Add a message or send files...":"Type @ to mention files...",disabled:L,compact:s}),(0,n.jsxs)("div",{className:"flex items-center justify-between ".concat(s?"px-2 pb-1.5":"px-3 pb-2.5"),children:[(0,n.jsx)("div",{className:"flex items-center gap-0.5",children:!k&&(0,n.jsx)("button",{type:"button",onClick:()=>I(!0),className:"p-1.5 rounded-lg hover:opacity-80 transition-opacity",style:{color:E.length>0?"var(--color-accent)":"var(--color-text-muted)"},title:"Attach files",children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})})})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[eh&&(0,n.jsx)("button",{type:"button",onClick:()=>eE(),className:"".concat(s?"w-6 h-6":"w-7 h-7"," rounded-full flex items-center justify-center"),style:{background:"var(--color-text)",color:"var(--color-bg)"},title:"Stop generating",children:(0,n.jsx)("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"currentColor",children:(0,n.jsx)("rect",{width:"10",height:"10",rx:"1.5"})})}),eh?(0,n.jsxs)("button",{type:"button",onClick:()=>{var e;return null==(e=w.current)?void 0:e.submit()},disabled:N&&0===E.length||L,className:"h-7 px-3 rounded-full flex items-center gap-1.5 text-[12px] font-medium disabled:opacity-40 disabled:cursor-not-allowed",style:{background:!N||E.length>0?"var(--color-accent)":"var(--color-surface-hover)",color:!N||E.length>0?"white":"var(--color-text-muted)"},title:"Add to queue",children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"9 10 4 15 9 20"}),(0,n.jsx)("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"})]}),"Queue"]}):(0,n.jsx)("button",{type:"button",onClick:()=>{var e;return null==(e=w.current)?void 0:e.submit()},disabled:N&&0===E.length||L,className:"".concat(s?"w-6 h-6":"w-7 h-7"," rounded-full flex items-center justify-center disabled:opacity-50 disabled:cursor-not-allowed"),style:{background:!N||E.length>0?"var(--color-accent)":"var(--color-text-muted)",color:!N||E.length>0?"white":"var(--color-bg)"},title:"Send message",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 19V5"}),(0,n.jsx)("path",{d:"m5 12 7-7 7 7"})]})})]})]})]}),eV=(e,t,r)=>(0,n.jsx)("div",{"data-chat-drop-target":"",className:"rounded-3xl overflow-hidden border shadow-[0_0_32px_rgba(0,0,0,0.07)] transition-[outline,box-shadow] duration-150 ease-out data-drag-hover:outline-2 data-drag-hover:outline-dashed data-drag-hover:outline-(--color-accent) data-drag-hover:-outline-offset-2 data-drag-hover:shadow-[0_0_0_4px_color-mix(in_srgb,var(--color-accent)_15%,transparent),0_0_32px_rgba(0,0,0,0.07)]!",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},onDragOver:e,onDragLeave:t,onDrop:r,children:eH}),eJ=e=>{var t,r;((null==(t=e.dataTransfer)?void 0:t.types.includes("application/x-file-mention"))||(null==(r=e.dataTransfer)?void 0:r.types.includes("Files")))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy",e.currentTarget.setAttribute("data-drag-hover",""))},eK=e=>{e.currentTarget.contains(e.relatedTarget)||e.currentTarget.removeAttribute("data-drag-hover")},eq=e=>{var t,r,n;e.currentTarget.removeAttribute("data-drag-hover");let o=null==(t=e.dataTransfer)?void 0:t.getData("application/x-file-mention");if(o){e.preventDefault(),e.stopPropagation();try{let{name:e,path:t}=JSON.parse(o);e&&t&&(null==(n=w.current)||n.insertFileMention(e,t))}catch(e){}return}let l=null==(r=e.dataTransfer)?void 0:r.files;l&&l.length>0&&(e.preventDefault(),e.stopPropagation(),eA(l))};return(0,n.jsx)(ln.o,{children:(0,n.jsxs)("div",{className:"h-full flex flex-col",style:{background:"var(--color-main-bg)"},children:[(0,n.jsx)("header",{className:"".concat(s?"px-3 py-2":"px-3 py-2 md:px-6 md:py-3"," flex items-center ").concat(k?"gap-3":"justify-between"," z-20"),style:{background:"var(--color-bg-glass)"},children:k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:j,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Back to parent chat",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("h2",{className:"text-sm font-semibold truncate",style:{color:"var(--color-text)"},children:b||(y&&y.length>60?y.slice(0,60)+"...":y)}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:eh?(0,n.jsx)(G.V,{name:"braille"}):"Completed"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"min-w-0 flex-1",children:s&&a?(0,n.jsxs)("h2",{className:"text-xs font-semibold truncate",style:{color:"var(--color-text)"},children:["Chat: ",a.filename]}):(0,n.jsx)("h2",{className:"text-sm font-semibold",style:{color:"var(--color-text)"},children:S?i||"Chat Session":"New Chat"})}),(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[S&&f&&(0,n.jsxs)(oH,{children:[(0,n.jsx)(oV,{className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"More options","aria-label":"More options",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1"})]})}),(0,n.jsx)(oJ,{align:"end",side:"bottom",children:(0,n.jsxs)(oK,{variant:"destructive",onSelect:()=>f(S),children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]})})]}),s&&(0,n.jsx)("button",{type:"button",onClick:()=>eD(),className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"New chat",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]})})]})]})}),!k&&s&&a&&H.length>0&&(0,n.jsx)("div",{className:"px-2 py-1.5 border-b flex gap-1 overflow-x-auto z-20",style:{borderColor:"var(--color-border)",background:"var(--color-bg-glass)"},children:H.slice(0,10).map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>eT(e.id),className:"px-2.5 py-1 text-[10px] rounded-full whitespace-nowrap shrink-0 font-medium",style:{background:e.id===S?"var(--color-accent)":"var(--color-surface-hover)",color:e.id===S?"white":"var(--color-text-muted)",border:e.id===S?"none":"1px solid var(--color-border)"},children:e.title.length>25?e.title.slice(0,25)+"...":e.title},e.id))}),(0,n.jsxs)("div",{ref:em,className:"flex-1 overflow-y-auto min-h-0",children:[(0,n.jsx)("div",{className:s?"px-3":"px-6",children:L?(0,n.jsx)("div",{className:"flex items-center justify-center h-full min-h-[60vh]",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(G.V,{name:"braille",className:"block text-2xl mx-auto mb-3",style:{color:"var(--color-text-muted)"}}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading session..."})]})}):eU?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[75vh] py-12",children:[Q&&(0,n.jsx)(lo.P.h1,{className:"text-4xl md:text-5xl font-light tracking-normal font-instrument mb-10 text-center",style:{color:"var(--color-text)"},initial:"hidden",animate:"visible",variants:{hidden:{opacity:0},visible:{opacity:1,transition:{staggerChildren:.12,delayChildren:.2}}},children:Q.split(" ").map((e,t)=>(0,n.jsx)(lo.P.span,{className:"inline-block mr-2",variants:{hidden:{opacity:0,y:20,filter:"blur(8px)"},visible:{opacity:1,y:0,filter:"blur(0px)",transition:{duration:.8,ease:[.2,.65,.3,.9]}}},children:e},t))}),(0,n.jsx)(lo.P.div,{className:"w-full max-w-[720px] mx-auto px-4",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.8,delay:.8,ease:[.22,1,.36,1]},children:(0,n.jsx)(lo.P.div,{layout:!0,layoutId:"chat-input-bar",transition:{type:"spring",stiffness:260,damping:30},children:eV(eJ,eK,eq)})}),(0,n.jsxs)(lo.P.div,{className:"mt-6 flex flex-col gap-2.5 w-full max-w-[720px] mx-auto px-4",initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5,delay:1,ease:[.22,1,.36,1]},children:[(0,n.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:ee.slice(0,3).map(e=>{let t=e.icon;return(0,n.jsxs)("button",{type:"button",onClick:()=>er(e.id),className:"group flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium whitespace-nowrap rounded-xl transition-all duration-200 border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-secondary)"},children:[(0,n.jsx)(t,{className:"w-3.5 h-3.5 opacity-50 group-hover:opacity-100 transition-opacity duration-200"}),e.label]},e.id)})}),(0,n.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:ee.slice(3,7).map(e=>{let t=e.icon;return(0,n.jsxs)("button",{type:"button",onClick:()=>er(e.id),className:"group flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium whitespace-nowrap rounded-xl transition-all duration-200 border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-secondary)"},children:[(0,n.jsx)(t,{className:"w-3.5 h-3.5 opacity-50 group-hover:opacity-100 transition-opacity duration-200"}),e.label]},e.id)})})]})]}):0===es.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full min-h-[60vh]",children:(0,n.jsx)("div",{className:"text-center max-w-md px-4",children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Ask about this file"})})}):(0,n.jsxs)("div",{className:"".concat(s?"":"max-w-2xl mx-auto"," py-3"),children:[Z?(0,n.jsx)("pre",{className:"text-xs whitespace-pre-wrap break-all font-mono p-4 rounded-xl",style:{color:"var(--color-text)",background:"var(--color-surface-hover)"},children:JSON.stringify(es,null,2)}):es.map((e,t)=>(0,n.jsx)(al,{message:e,isStreaming:eh&&t===es.length-1,onSubagentClick:p,onFilePathClick:m,sessionId:S,userHtmlMap:J.current},e.id)),eO&&(0,n.jsx)("div",{className:"py-3 min-w-0",children:(0,n.jsx)(G.V,{name:"pulse",className:"text-base",style:{color:"var(--color-text-muted)"}})}),(0,n.jsx)("div",{ref:D})]})}),(eu||A)&&(0,n.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 sticky bottom-[72px] z-10",style:{background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))",borderColor:"color-mix(in srgb, var(--color-error) 18%, transparent)",color:"var(--color-error)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),(0,n.jsx)("p",{className:"text-xs",children:null!=(l=null==eu?void 0:eu.message)?l:A})]})]}),!eU&&(0,n.jsx)("div",{className:"".concat(s?"px-3 py-2":"px-3 pb-3 pt-0 md:px-6 md:pb-5"," z-20"),style:{background:"var(--color-bg-glass)"},children:(0,n.jsx)("div",{className:s?"":"max-w-[720px] mx-auto",children:(0,n.jsx)(lo.P.div,{layout:!0,layoutId:"chat-input-bar",transition:{type:"spring",stiffness:260,damping:30},children:eV(eJ,eK,eq)})})}),!k&&(0,n.jsx)(ai,{open:W,onClose:()=>I(!1),onSelect:eB})]})})});function aS(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e?String(e):""}let aM=["created_at","Created","createdAt","created"],aL=["updated_at","Updated","updatedAt","updated"];function aT(e,t){for(let r of t){let t=e[r];if(null!=t&&""!==t)return t}}function aD(e){var t;let{value:r,enumValues:o,enumColors:l}=e,a=null!=(t=null==o?void 0:o.indexOf(r))?t:-1,s=a>=0&&l?l[a]:"#94a3b8";return(0,n.jsx)("span",{className:"inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium",style:{background:"".concat(s,"20"),color:s,border:"1px solid ".concat(s,"40")},children:r})}function aE(e){var t,r;let{value:o,members:l}=e,a=String(o),s=null==l?void 0:l.find(e=>e.id===a);return(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-6 h-6 rounded-full flex items-center justify-center text-xs font-medium flex-shrink-0",style:{background:"var(--color-accent)",color:"white"},children:(null!=(t=null==s?void 0:s.name)?t:a).charAt(0).toUpperCase()}),(0,n.jsx)("span",{children:null!=(r=null==s?void 0:s.name)?r:a})]})}function aR(e){let{value:t,field:r,relationLabels:o,onNavigateEntry:l}=e,a=null==o?void 0:o[r.name],s=function(e){if(!e)return[];let t=e.trim();if(!t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(Boolean)}catch(e){}return[t]}(String(t));return 0===s.length?(0,n.jsx)(aB,{}):(0,n.jsx)("span",{className:"flex items-center gap-1.5 flex-wrap",children:s.map(e=>{var t;let o=null!=(t=null==a?void 0:a[e])?t:e,s=r.related_object_name&&l?t=>{t.stopPropagation(),l(r.related_object_name,e)}:void 0;return(0,n.jsxs)("button",{type:"button",onClick:s,className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-md text-xs font-medium ".concat(s?"cursor-pointer hover:opacity-80":""),style:{background:"rgba(96, 165, 250, 0.1)",color:"#60a5fa",border:"1px solid rgba(96, 165, 250, 0.2)"},title:s?"Open ".concat(o):o,children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.5},children:[(0,n.jsx)("path",{d:"M7 7h10v10"}),(0,n.jsx)("path",{d:"M7 17 17 7"})]}),(0,n.jsx)("span",{className:"truncate max-w-[200px]",children:o})]},e)})})}function aW(e){let{value:t}=e,r=eZ(t);if(0===r.length)return(0,n.jsx)(aB,{});let o={background:"rgba(148, 163, 184, 0.12)",border:"1px solid var(--color-border)"};return(0,n.jsx)("span",{className:"flex items-center gap-1.5 flex-wrap",children:r.map(e=>{let t=eJ(e);return"link"===t.kind&&t.href?(0,n.jsx)("a",{href:t.href,target:"url"===t.linkType||"file"===t.linkType?"_blank":void 0,rel:"url"===t.linkType||"file"===t.linkType?"noopener noreferrer":void 0,onClick:e=>e.stopPropagation(),className:"inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium underline-offset-2 hover:underline",style:{...o,color:"var(--color-accent)"},children:t.text},e):(0,n.jsx)("span",{className:"inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium",style:{...o,color:"var(--color-text-muted)"},children:e},e)})})}function aI(e){let{value:t,onChange:r,autoFocus:l}=e,a=eZ(t),[s,i]=(0,o.useState)(""),c=(0,o.useRef)(null);(0,o.useEffect)(()=>{l&&c.current&&c.current.focus()},[l]);let d=e=>{let t=e.trim();!t||a.includes(t)||(r(JSON.stringify([...a,t])),i(""))},u=e=>{let t=a.filter(t=>t!==e);r(t.length>0?JSON.stringify(t):"")};return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap min-h-[1.75rem]",children:[a.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-2.5 py-1 rounded-full text-xs font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[e,(0,n.jsx)("button",{type:"button",onClick:()=>u(e),className:"ml-0.5 hover:opacity-70",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]},e)),(0,n.jsx)("input",{ref:c,type:"text",value:s,onChange:e=>i(e.target.value),onKeyDown:e=>{("Enter"===e.key||","===e.key)&&s.trim()&&(e.preventDefault(),d(s)),"Backspace"===e.key&&!s&&a.length>0&&u(a[a.length-1])},onBlur:()=>{s.trim()&&d(s)},placeholder:0===a.length?"Type and press Enter...":"",className:"flex-1 min-w-[80px] text-sm outline-none bg-transparent",style:{color:"var(--color-text)"}})]})}function aB(){return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"})}function aF(e){let{relation:t,onNavigateEntry:r}=e,o=t.links.slice(0,10),l=t.links.length-o.length;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.4},children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]}),(0,n.jsx)("span",{className:"capitalize",children:t.sourceObjectName}),(0,n.jsxs)("span",{className:"normal-case tracking-normal font-normal opacity-60",children:["via ",t.fieldName]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap text-sm min-h-[1.75rem]",children:[o.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>null==r?void 0:r(t.sourceObjectName,e.id),className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-md text-xs font-medium cursor-pointer hover:opacity-80",style:{background:"rgba(192, 132, 252, 0.1)",color:"#c084fc",border:"1px solid rgba(192, 132, 252, 0.2)"},title:"Open ".concat(e.label," in ").concat(t.sourceObjectName),children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.5},children:[(0,n.jsx)("path",{d:"M7 7h10v10"}),(0,n.jsx)("path",{d:"M7 17 17 7"})]}),(0,n.jsx)("span",{className:"truncate max-w-[200px]",children:e.label})]},e.id)),l>0&&(0,n.jsxs)("span",{className:"text-xs px-1.5 py-0.5 rounded",style:{color:"var(--color-text-muted)"},children:["+",l," more"]})]})]})}function aP(e){let{value:t,field:r,members:o,relationLabels:l,onNavigateEntry:a}=e;if(null==t||""===t)return(0,n.jsx)(aB,{});switch(r.type){case"enum":return(0,n.jsx)(aD,{value:aS(t),enumValues:r.enum_values,enumColors:r.enum_colors});case"boolean":{let e=!0===t||"true"===t||"1"===t||"yes"===t;return(0,n.jsx)("span",{style:{color:e?"#22c55e":"var(--color-text-muted)"},children:e?"Yes":"No"})}case"user":return(0,n.jsx)(aE,{value:t,members:o});case"relation":return(0,n.jsx)(aR,{value:t,field:r,relationLabels:l,onNavigateEntry:a});case"tags":return(0,n.jsx)(aW,{value:t});default:return(0,n.jsx)(e$,{value:t,fieldType:r.type,mode:"detail"})}}function aA(e){let{objectName:t,entryId:r,members:l,onClose:a,onNavigateEntry:s,onNavigateObject:i,onRefresh:c}=e,[d,u]=(0,o.useState)(null),[x,h]=(0,o.useState)(!0),[p,m]=(0,o.useState)(null),[f,v]=(0,o.useState)(null),[g,y]=(0,o.useState)(""),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),N=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=!1;return h(!0),m(null),async function(){try{let o=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(r)));if(!o.ok){let t=await o.json().catch(()=>({error:"Failed to load"}));if(!e){var n;m(null!=(n=t.error)?n:"Failed to load entry"),h(!1)}return}let l=await o.json();e||(u(l),h(!1))}catch(t){e||(m("Network error"),h(!1))}}(),()=>{e=!0}},[t,r]),(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&a()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a]);let C=(0,o.useCallback)(e=>{e.target===N.current&&a()},[a]),S=(0,o.useCallback)(async(e,n)=>{j(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(r)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{[e]:n}})})).ok&&(u(t=>t?{...t,entry:{...t.entry,[e]:n}}:t),v(null),null==c||c())}catch(e){}finally{j(!1)}},[t,r,c]),M=(0,o.useCallback)(async()=>{if(confirm("Are you sure you want to delete this entry?")){w(!0);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(r)),{method:"DELETE"}),null==c||c(),a()}catch(e){}finally{w(!1)}}},[t,r,c,a]),L=null==d?void 0:d.effectiveDisplayField,T=L&&(null==d?void 0:d.entry[L])?aS(d.entry[L]):"".concat(String(t)," entry"),D=d?aT(d.entry,aM):void 0,E=d?aT(d.entry,aL):void 0;return(0,n.jsx)("div",{ref:N,onClick:C,className:"fixed inset-0 z-50 flex items-start justify-center",style:{background:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)"},children:(0,n.jsxs)("div",{className:"relative mt-4 mb-4 mx-3 md:mt-12 md:mb-12 md:mx-0 w-full max-w-2xl rounded-2xl overflow-hidden shadow-2xl flex flex-col",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",maxHeight:"calc(100vh - 2rem)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 md:px-6 md:py-4 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>void(null==i||i(t)),className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-medium capitalize transition-colors hover:opacity-80 flex-shrink-0",style:{background:"var(--color-accent-light)",color:"var(--color-accent)",border:"1px solid var(--color-border)"},title:"Go to ".concat(t),children:[(0,n.jsxs)("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:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]}),t]}),(0,n.jsx)("h2",{className:"text-lg font-semibold truncate",style:{color:"var(--color-text)"},children:x?"Loading...":T})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:()=>void M(),disabled:k,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-error)"},title:"Delete entry",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Close",children:(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:[x&&(0,n.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,n.jsx)("div",{className:"w-6 h-6 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}),p&&(0,n.jsx)("div",{className:"text-center py-16",children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:p})}),d&&!x&&(0,n.jsxs)("div",{className:"space-y-4",children:[d.fields.map(e=>{let t=d.entry[e.name];return(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"block text-xs font-medium uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:[e.name,"relation"===e.type&&e.related_object_name&&(0,n.jsxs)("span",{className:"normal-case tracking-normal font-normal opacity-60 ml-1",children:["(",e.related_object_name,")"]})]}),(0,n.jsx)("div",{className:"text-sm min-h-[1.75rem] flex items-center",style:{color:"var(--color-text)"},children:f===e.name?"tags"===e.type?(0,n.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,n.jsx)("div",{className:"flex-1 px-2 py-1 rounded-lg",style:{background:"var(--color-surface-hover)",border:"2px solid var(--color-accent)"},children:(0,n.jsx)(aI,{value:aS(t),onChange:t=>{S(e.name,t)},autoFocus:!0})}),(0,n.jsx)("button",{type:"button",onClick:()=>v(null),className:"px-2 py-1 text-xs rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Done"})]}):"relation"===e.type&&e.related_object_name?(0,n.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,n.jsx)("div",{className:"flex-1",children:(0,n.jsx)(ey,{relatedObjectName:e.related_object_name,value:aS(t),multiple:"many_to_many"===e.relationship_type,onChange:t=>{S(e.name,t)},autoFocus:!0})}),(0,n.jsx)("button",{type:"button",onClick:()=>v(null),className:"px-2 py-1 text-xs rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Cancel"})]}):(0,n.jsxs)("form",{onSubmit:t=>{t.preventDefault(),S(e.name,g)},className:"flex items-center gap-2 w-full",children:["enum"===e.type&&e.enum_values?(0,n.jsxs)("select",{value:g,onChange:t=>{y(t.target.value),S(e.name,t.target.value)},autoFocus:!0,className:"flex-1 px-2 py-1 text-sm rounded-lg outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"2px solid var(--color-accent)"},children:[(0,n.jsx)("option",{value:"",children:"--"}),e.enum_values.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}):"boolean"===e.type?(0,n.jsxs)("select",{value:g,onChange:t=>{y(t.target.value),S(e.name,t.target.value)},autoFocus:!0,className:"flex-1 px-2 py-1 text-sm rounded-lg outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"2px solid var(--color-accent)"},children:[(0,n.jsx)("option",{value:"true",children:"Yes"}),(0,n.jsx)("option",{value:"false",children:"No"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:function(e){switch(e){case"number":return"number";case"date":return"date";case"email":return"email";case"phone":return"tel";case"url":return"url";default:return"text"}}(e.type),value:g,onChange:e=>y(e.target.value),autoFocus:!0,className:"flex-1 px-2 py-1 text-sm rounded-lg outline-none",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"2px solid var(--color-accent)"}}),(0,n.jsx)("button",{type:"submit",disabled:b,className:"px-2 py-1 text-xs rounded-lg font-medium",style:{background:"var(--color-accent)",color:"white"},children:b?"...":"Save"})]}),(0,n.jsx)("button",{type:"button",onClick:()=>v(null),className:"px-2 py-1 text-xs rounded-lg",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Cancel"})]}):(0,n.jsx)("div",{className:"flex-1 ".concat(["user"].includes(e.type)?"":"cursor-pointer hover:opacity-80"),onClick:()=>{["user"].includes(e.type)||(v(e.name),y(aS(t)))},title:["user"].includes(e.type)?void 0:"Click to edit",children:(0,n.jsx)(aP,{value:t,field:e,members:l,relationLabels:d.relationLabels,onNavigateEntry:s})})})]},e.id)}),d.reverseRelations&&d.reverseRelations.length>0&&(0,n.jsxs)("div",{className:"pt-4 mt-4 border-t space-y-4",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-widest",style:{color:"var(--color-text-muted)",opacity:.6},children:"Linked from"}),d.reverseRelations.map(e=>(0,n.jsx)(aF,{relation:e,onNavigateEntry:s},"".concat(e.sourceObjectName,"_").concat(e.fieldName)))]}),(null!=D||null!=E)&&(0,n.jsxs)("div",{className:"pt-4 mt-4 border-t text-xs flex gap-6",style:{borderColor:"var(--color-border)",color:"var(--color-text-muted)"},children:[null!=D&&(0,n.jsxs)("span",{children:["Created: ",(0,n.jsx)(e$,{value:D,fieldType:"date",mode:"detail",className:"inline"})]}),null!=E&&(0,n.jsxs)("span",{children:["Updated: ",(0,n.jsx)(e$,{value:E,fieldType:"date",mode:"detail",className:"inline"})]})]})]})]})]})})}var a_=r(91365);let az={keys:[{name:"label",weight:3},{name:"sublabel",weight:1},{name:"objectName",weight:1.5},{name:"fieldValues",weight:2}],threshold:.4,distance:200,includeScore:!0,shouldSort:!0,minMatchCharLength:1},aO=new Set(["ts","tsx","js","jsx","mjs","cjs","py","rb","go","rs","java","kt","swift","c","cpp","h","hpp","cs","css","scss","less","html","htm","xml","svg","json","jsonc","yaml","yml","toml","sh","bash","zsh","fish","ps1","sql","graphql","gql","dockerfile","makefile","cmake","r","lua","php","vue","svelte","diff","patch","ini","env","tf","proto","zig","elixir","ex","erl","hs","scala","clj","dart"]);function aU(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return aO.has(n)}function aH(e){if(e<=0)return"now";let t=Math.ceil(e/1e3);if(t<60)return"".concat(t,"s");let r=Math.floor(t/60),n=t%60;if(r<60)return n>0?"".concat(r,"m ").concat(n,"s"):"".concat(r,"m");let o=Math.floor(r/60),l=r%60;return l>0?"".concat(o,"h ").concat(l,"m"):"".concat(o,"h")}function aV(e){return e<1e3?"".concat(e,"ms"):e<6e4?"".concat((e/1e3).toFixed(1),"s"):"".concat(Math.floor(e/6e4),"m ").concat(Math.floor(e%6e4/1e3),"s")}function aJ(e){switch(e){case"ok":return"var(--color-success, #22c55e)";case"running":return"var(--color-accent)";case"error":return"var(--color-error, #ef4444)";case"disabled":default:return"var(--color-text-muted)";case"skipped":return"var(--color-warning, #f59e0b)"}}function aK(e){let[t,r]=(0,o.useState)(Date.now());return((0,o.useEffect)(()=>{if(!e)return;let t=setInterval(()=>r(Date.now()),1e3);return()=>clearInterval(t)},[e]),e)?aH(e-t):null}let aq=[{id:"overview",label:"Overview"},{id:"calendar",label:"Calendar"},{id:"insights",label:"Insights"}];function aG(e){let{onSelectJob:t,onSendCommand:r,activeView:l="overview",onViewChange:a,calendarMode:s="month",onCalendarModeChange:i,calendarDate:c,onCalendarDateChange:d}=e,[u,x]=(0,o.useState)([]),[h,p]=(0,o.useState)({intervalMs:18e5,nextDueEstimateMs:null}),[m,f]=(0,o.useState)({enabled:!1,nextWakeAtMs:null}),[v,g]=(0,o.useState)(!0),[y,b]=(0,o.useState)([]),j=(0,o.useCallback)(async()=>{try{var e,t,r,n;let o=await fetch("/api/cron/jobs"),l=await o.json();x(null!=(e=l.jobs)?e:[]),p(null!=(t=l.heartbeat)?t:{intervalMs:18e5,nextDueEstimateMs:null}),f(null!=(r=l.cronStatus)?r:{enabled:!1,nextWakeAtMs:null});let a=(null!=(n=l.jobs)?n:[]).map(e=>e.id).map(async e=>{try{var t;let r=await fetch("/api/cron/jobs/".concat(encodeURIComponent(e),"/runs?limit=50"));return null!=(t=(await r.json()).entries)?t:[]}catch(e){return[]}}),s=await Promise.all(a);b(s.flat().toSorted((e,t)=>t.ts-e.ts))}catch(e){}finally{g(!1)}},[]);(0,o.useEffect)(()=>{j();let e=setInterval(()=>void j(),15e3);return()=>clearInterval(e)},[j]);let k=aK(h.nextDueEstimateMs),w=aK(m.nextWakeAtMs);if(v)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full p-8",children:(0,n.jsx)("div",{className:"w-6 h-6 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})});let N=u.filter(e=>e.enabled),C=u.filter(e=>!e.enabled);return(0,n.jsxs)("div",{className:"p-6 max-w-5xl mx-auto",children:[(0,n.jsx)("div",{className:"flex items-end justify-between mb-6",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight mb-1",style:{color:"var(--color-text)"},children:"Cron"}),(0,n.jsxs)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:[N.length," active job",1!==N.length?"s":"",C.length>0&&" / ".concat(C.length," disabled")]})]})}),(0,n.jsx)("div",{className:"flex items-center gap-1 mb-6 rounded-xl p-1",style:{background:"var(--color-surface-hover)"},children:aq.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>null==a?void 0:a(e.id),className:"px-4 py-1.5 rounded-lg text-sm font-medium transition-all cursor-pointer",style:{background:l===e.id?"var(--color-surface)":"transparent",color:l===e.id?"var(--color-text)":"var(--color-text-muted)",boxShadow:l===e.id?"var(--shadow-sm)":"none"},children:e.label},e.id))}),"overview"===l&&(0,n.jsx)(a$,{jobs:u,enabledJobs:N,disabledJobs:C,heartbeatCountdown:k,heartbeat:h,cronWakeCountdown:w,onSelectJob:t,onSendCommand:r}),"calendar"===l&&(0,n.jsx)(aX,{jobs:u,allRuns:y,mode:s,onModeChange:i,dateAnchor:c,onDateChange:d,onSelectJob:t}),"insights"===l&&(0,n.jsx)(a5,{jobs:u,allRuns:y,onSelectJob:t})]})}function a$(e){let{jobs:t,enabledJobs:r,disabledJobs:o,heartbeatCountdown:l,heartbeat:a,cronWakeCountdown:s,onSelectJob:i,onSendCommand:c}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 mb-8",children:[(0,n.jsx)(a3,{title:"Heartbeat",icon:(0,n.jsx)(se,{}),value:l?"in ".concat(l):"unknown",subtitle:"Interval: ".concat(aH(a.intervalMs))}),(0,n.jsx)(a3,{title:"Cron Scheduler",icon:(0,n.jsx)(st,{}),value:s?"next in ".concat(s):0===t.length?"no jobs":"idle",subtitle:"".concat(r.length," active / ").concat(t.length," total jobs")}),(0,n.jsx)(a3,{title:"Active Runs",icon:(0,n.jsx)(sr,{}),value:"".concat(t.filter(e=>e.state.runningAtMs).length),subtitle:(()=>{let e=t.filter(e=>e.state.runningAtMs),r=t.filter(e=>"error"===e.state.lastStatus).length;return e.length>0?e.map(e=>e.name).join(", "):r>0?"".concat(r," with errors"):"All clear"})()})]}),(0,n.jsx)(a8,{jobs:r}),(0,n.jsx)(a7,{jobs:[...r,...o],onSelectJob:i,onSendCommand:c})]})}function aZ(e){return"".concat(e.getFullYear(),"-").concat(String(e.getMonth()+1).padStart(2,"0"),"-").concat(String(e.getDate()).padStart(2,"0"))}function aY(e,t,r){let n=new Set;for(let o of e.split(",")){let e=o.match(/^(.+)\/(\d+)$/),l=e?parseInt(e[2],10):1,a=e?e[1]:o;if("*"===a)for(let e=t;e<=r;e+=l)n.add(e);else if(a.includes("-")){let[e,t]=a.split("-").map(Number);for(let r=e;r<=t;r+=l)n.add(r)}else n.add(parseInt(a,10))}return[...n].filter(e=>e>=t&&e<=r).sort((e,t)=>e-t)}function aQ(e){var t,r,o,l;let{ev:a,onSelectJob:s}=e;if("scheduled"===a.kind){let e=new Date(a.at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return(0,n.jsxs)("button",{type:"button",onClick:()=>s(a.job.id),className:"w-full text-left text-[10px] px-1.5 py-0.5 rounded truncate cursor-pointer",style:{background:"color-mix(in srgb, var(--color-accent) 15%, transparent)",color:"var(--color-accent)"},title:"Scheduled: ".concat(a.job.name," at ").concat(e),children:[e," ",a.job.name]})}let i="ok"===a.run.status?"var(--color-success, #22c55e)":"error"===a.run.status?"var(--color-error, #ef4444)":"var(--color-text-muted)";return(0,n.jsxs)("button",{type:"button",onClick:()=>a.job&&s(a.job.id),className:"w-full text-left text-[10px] px-1.5 py-0.5 rounded truncate flex items-center gap-1 cursor-pointer",style:{background:"color-mix(in srgb, ".concat(i," 10%, transparent)"),color:i},title:"".concat(a.run.status,": ").concat(null!=(o=null==(t=a.job)?void 0:t.name)?o:a.run.jobId),children:[(0,n.jsx)("span",{className:"w-1 h-1 rounded-full flex-shrink-0",style:{background:i}}),null!=(l=null==(r=a.job)?void 0:r.name)?l:a.run.jobId.slice(0,8)]})}function aX(e){let{jobs:t,allRuns:r,mode:l="month",onModeChange:a,dateAnchor:s,onDateChange:i,onSelectJob:c}=e,d=s?new Date(s):new Date,u=e=>{let t=new Date(d);"month"===l?t.setMonth(t.getMonth()+e):"week"===l?t.setDate(t.getDate()+7*e):"day"===l?t.setDate(t.getDate()+e):t.setFullYear(t.getFullYear()+e),null==i||i(t.toISOString().split("T")[0])},x=(0,o.useMemo)(()=>{let e=new Map;for(let r of t)e.set(r.id,r);return e},[t]),{rangeFrom:h,rangeTo:p}=(0,o.useMemo)(()=>{let e=d.getFullYear(),t=d.getMonth();if("day"===l)return{rangeFrom:new Date(e,t,d.getDate()).getTime(),rangeTo:new Date(e,t,d.getDate()+1).getTime()};if("week"===l){let e=new Date(d);return e.setDate(e.getDate()-e.getDay()),{rangeFrom:e.getTime(),rangeTo:e.getTime()+6048e5}}if("year"===l)return{rangeFrom:new Date(e,0,1).getTime(),rangeTo:new Date(e+1,0,1).getTime()};let r=new Date(e,t,1),n=new Date(e,t,1-r.getDay());return{rangeFrom:n.getTime(),rangeTo:n.getTime()+36288e5}},[d,l]),m=(0,o.useMemo)(()=>(function(e,t,r,n,o){var l,a;let s=new Map;for(let t of e){let e=aZ(new Date(t.ts)),n=null!=(l=s.get(e))?l:[];n.push({kind:"run",run:t,job:r.get(t.jobId)}),s.set(e,n)}for(let e of t)if(e.enabled)for(let t of function(e,t,r){if(!e.enabled)return[];let n=e.schedule;switch(n.kind){case"at":{let e=new Date(n.at).getTime();return e>=t&&e<=r?[e]:[]}case"every":{var o,l;let a=n.everyMs;if(a<=0)return[];let s=null!=(l=null!=(o=n.anchorMs)?o:e.createdAtMs)?l:t,i=[],c=s;if(c<t){let e=Math.floor((t-c)/a);c+=e*a}for(;c<=r&&i.length<5e3;)c>=t&&i.push(c),c+=a;return i}case"cron":return function(e,t,r,n){let o=e.trim().split(/\s+/);if(o.length<5)return[];let l=aY(o[0],0,59),a=aY(o[1],0,23),s=aY(o[2],1,31),i=aY(o[3],1,12),c=aY(o[4],0,6),d="*"===o[2],u="*"===o[4],x=[],h=new Date(t);h.setSeconds(0,0);let p=0;for(;h.getTime()<=r&&p++<5e4;){if(!i.includes(h.getMonth()+1)){h.setMonth(h.getMonth()+1,1),h.setHours(0,0,0,0);continue}let e=d||s.includes(h.getDate()),n=u||c.includes(h.getDay());if(!(d&&u||(d||u?e&&n:e||n))){h.setDate(h.getDate()+1),h.setHours(0,0,0,0);continue}for(let e of a)for(let n of l){let o=new Date(h.getFullYear(),h.getMonth(),h.getDate(),e,n,0,0).getTime();o>=t&&o<=r&&x.push(o)}h.setDate(h.getDate()+1),h.setHours(0,0,0,0)}return x}(n.expr,t,r,n.tz);default:return[]}}(e,n,o)){let r=aZ(new Date(t)),n=null!=(a=s.get(r))?a:[];n.push({kind:"scheduled",job:e,at:t}),s.set(r,n)}return s})(r,t,x,h,p),[r,t,x,h,p]),f=(0,o.useMemo)(()=>{if("day"===l)return d.toLocaleDateString(void 0,{weekday:"long",month:"long",day:"numeric",year:"numeric"});if("week"===l){let e=new Date(d);e.setDate(e.getDate()-e.getDay());let t=new Date(e);return(t.setDate(t.getDate()+6),e.getMonth()===t.getMonth())?"".concat(e.toLocaleDateString(void 0,{month:"long"})," ").concat(e.getDate(),"–").concat(t.getDate(),", ").concat(e.getFullYear()):"".concat(e.toLocaleDateString(void 0,{month:"short",day:"numeric"})," – ").concat(t.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"}))}return"year"===l?String(d.getFullYear()):d.toLocaleDateString(void 0,{month:"long",year:"numeric"})},[d,l]),v=aZ(new Date);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:()=>u(-1),className:"p-1.5 rounded-lg cursor-pointer",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})})}),(0,n.jsx)("h2",{className:"text-lg font-semibold",style:{color:"var(--color-text)"},children:f}),(0,n.jsx)("button",{type:"button",onClick:()=>u(1),className:"p-1.5 rounded-lg cursor-pointer",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m9 18 6-6-6-6"})})}),(0,n.jsx)("button",{type:"button",onClick:()=>null==i?void 0:i(new Date().toISOString().split("T")[0]),className:"text-xs px-2.5 py-1 rounded-lg ml-2 cursor-pointer",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:"Today"})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 rounded-lg p-0.5",style:{background:"var(--color-surface-hover)"},children:["day","week","month","year"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>null==a?void 0:a(e),className:"px-3 py-1 rounded-md text-xs font-medium cursor-pointer",style:{background:l===e?"var(--color-surface)":"transparent",color:l===e?"var(--color-text)":"var(--color-text-muted)"},children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),"day"===l&&(0,n.jsx)(a0,{anchor:d,eventsByDay:m,todayStr:v,onSelectJob:c}),"week"===l&&(0,n.jsx)(a1,{anchor:d,eventsByDay:m,todayStr:v,onSelectJob:c,onDateChange:i,onModeChange:a}),"month"===l&&(0,n.jsx)(a2,{anchor:d,eventsByDay:m,todayStr:v,onSelectJob:c}),"year"===l&&(0,n.jsx)(a4,{anchor:d,eventsByDay:m,todayStr:v,onDateChange:i,onModeChange:a})]})}function a0(e){var t;let{anchor:r,eventsByDay:l,todayStr:a,onSelectJob:s}=e,i=aZ(r),c=null!=(t=l.get(i))?t:[],d=i===a,u=Array.from({length:24},(e,t)=>t),x=(0,o.useMemo)(()=>{let e=new Map;for(let r of c){var t;let n="run"===r.kind?new Date(r.run.ts).getHours():r.job.state.nextRunAtMs?new Date(r.job.state.nextRunAtMs).getHours():0,o=null!=(t=e.get(n))?t:[];o.push(r),e.set(n,o)}return e},[c]);return(0,n.jsx)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:u.map(e=>{var t;let r=null!=(t=x.get(e))?t:[],o=new Date().getHours(),l=d&&e===o;return(0,n.jsxs)("div",{className:"flex",style:{borderBottom:e<23?"1px solid var(--color-border)":void 0,background:l?"color-mix(in srgb, var(--color-accent) 4%, transparent)":void 0},children:[(0,n.jsx)("div",{className:"w-16 flex-shrink-0 px-3 py-2 text-right text-[11px] font-medium",style:{color:"var(--color-text-muted)",borderRight:"1px solid var(--color-border)"},children:0===e?"12 AM":e<12?"".concat(e," AM"):12===e?"12 PM":"".concat(e-12," PM")}),(0,n.jsx)("div",{className:"flex-1 min-h-[36px] px-2 py-1 flex flex-wrap gap-1 items-start",children:r.map((e,t)=>(0,n.jsx)(aQ,{ev:e,onSelectJob:s},t))})]},e)})})}function a1(e){let{anchor:t,eventsByDay:r,todayStr:o,onSelectJob:l,onDateChange:a,onModeChange:s}=e,i=new Date(t);i.setDate(i.getDate()-i.getDay());let c=Array.from({length:7},(e,t)=>{let r=new Date(i);return r.setDate(r.getDate()+t),r});return(0,n.jsxs)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"grid grid-cols-7",style:{borderBottom:"1px solid var(--color-border)"},children:c.map(e=>{let t=aZ(e),r=t===o;return(0,n.jsxs)("button",{type:"button",onClick:()=>{null==a||a(t),null==s||s("day")},className:"px-2 py-2 text-center cursor-pointer",style:{borderRight:6>e.getDay()?"1px solid var(--color-border)":void 0},children:[(0,n.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:e.toLocaleDateString(void 0,{weekday:"short"})}),(0,n.jsx)("div",{className:"text-sm font-semibold",style:{color:r?"var(--color-accent)":"var(--color-text)"},children:e.getDate()})]},t)})}),(0,n.jsx)("div",{className:"grid grid-cols-7",children:c.map(e=>{var t;let a=aZ(e),s=null!=(t=r.get(a))?t:[],i=a===o;return(0,n.jsx)("div",{className:"min-h-[200px] p-1.5",style:{borderRight:6>e.getDay()?"1px solid var(--color-border)":void 0,background:i?"color-mix(in srgb, var(--color-accent) 4%, transparent)":void 0},children:(0,n.jsxs)("div",{className:"space-y-0.5",children:[s.slice(0,8).map((e,t)=>(0,n.jsx)(aQ,{ev:e,onSelectJob:l},t)),s.length>8&&(0,n.jsxs)("div",{className:"text-[9px] px-1",style:{color:"var(--color-text-muted)"},children:["+",s.length-8," more"]})]})},a)})})]})}function a2(e){let{anchor:t,eventsByDay:r,todayStr:l,onSelectJob:a}=e,s=(0,o.useMemo)(()=>{let e=t.getFullYear(),r=t.getMonth(),n=new Date(e,r,1),o=new Date(e,r,1-n.getDay()),l=[];for(let e=0;e<6;e++){let t=[];for(let r=0;r<7;r++){let n=new Date(o);n.setDate(n.getDate()+7*e+r),t.push(n)}l.push(t)}return l},[t]);return(0,n.jsxs)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"grid grid-cols-7",style:{borderBottom:"1px solid var(--color-border)"},children:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(e=>(0,n.jsx)("div",{className:"px-2 py-2 text-center text-[11px] font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:e},e))}),s.map((e,o)=>(0,n.jsx)("div",{className:"grid grid-cols-7",style:{borderBottom:o<5?"1px solid var(--color-border)":void 0},children:e.map(e=>{var o;let s=aZ(e),i=null!=(o=r.get(s))?o:[],c=e.getMonth()===t.getMonth(),d=s===l;return(0,n.jsxs)("div",{className:"min-h-[80px] p-1.5",style:{borderRight:6>e.getDay()?"1px solid var(--color-border)":void 0,opacity:c?1:.4,background:d?"color-mix(in srgb, var(--color-accent) 5%, transparent)":void 0},children:[(0,n.jsx)("div",{className:"text-xs font-medium mb-1",style:{color:d?"var(--color-accent)":"var(--color-text-muted)"},children:e.getDate()}),(0,n.jsxs)("div",{className:"space-y-0.5",children:[i.slice(0,3).map((e,t)=>(0,n.jsx)(aQ,{ev:e,onSelectJob:a},t)),i.length>3&&(0,n.jsxs)("div",{className:"text-[9px] px-1",style:{color:"var(--color-text-muted)"},children:["+",i.length-3," more"]})]})]},s)})},o))]})}function a4(e){let{anchor:t,eventsByDay:r,todayStr:o,onDateChange:l,onModeChange:a}=e,s=t.getFullYear(),i=Array.from({length:12},(e,t)=>t);return(0,n.jsx)("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-4",children:i.map(e=>{let t=new Date(s,e,1),i=t.getDay(),c=new Date(s,e+1,0).getDate(),d=[];for(let e=0;e<i;e++)d.push(null);for(let e=1;e<=c;e++)d.push(e);return(0,n.jsxs)("button",{type:"button",onClick:()=>{null==l||l("".concat(s,"-").concat(String(e+1).padStart(2,"0"),"-01")),null==a||a("month")},className:"rounded-xl p-3 text-left cursor-pointer transition-colors",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--color-surface)"},children:[(0,n.jsx)("div",{className:"text-xs font-semibold mb-2",style:{color:"var(--color-text)"},children:t.toLocaleDateString(void 0,{month:"short"})}),(0,n.jsxs)("div",{className:"grid grid-cols-7 gap-px",children:[["S","M","T","W","T","F","S"].map((e,t)=>(0,n.jsx)("div",{className:"text-[8px] text-center font-medium",style:{color:"var(--color-text-muted)"},children:e},t)),d.map((t,l)=>{var a;if(null===t)return(0,n.jsx)("div",{},"e-".concat(l));let i="".concat(s,"-").concat(String(e+1).padStart(2,"0"),"-").concat(String(t).padStart(2,"0")),c=null!=(a=r.get(i))?a:[],d=i===o,u=c.length>0,x=c.some(e=>"run"===e.kind&&"error"===e.run.status);return(0,n.jsx)("div",{className:"text-[9px] text-center rounded-sm leading-[16px]",style:{color:d?"var(--color-accent)":u?"var(--color-text)":"var(--color-text-muted)",fontWeight:d||u?600:400,background:x?"color-mix(in srgb, var(--color-error, #ef4444) 15%, transparent)":u?"color-mix(in srgb, var(--color-accent) 10%, transparent)":void 0},children:t},i)})]}),(()=>{let t=0;for(let n=1;n<=c;n++){var o;let l="".concat(s,"-").concat(String(e+1).padStart(2,"0"),"-").concat(String(n).padStart(2,"0"));t+=(null!=(o=r.get(l))?o:[]).length}return t>0?(0,n.jsxs)("div",{className:"text-[9px] mt-1.5",style:{color:"var(--color-text-muted)"},children:[t," event",1!==t?"s":""]}):null})()]},e)})})}function a5(e){let{jobs:t,allRuns:r,onSelectJob:l}=e,a=(0,o.useMemo)(()=>{let e=r.length,n=r.filter(e=>"ok"===e.status).length,o=r.filter(e=>"error"===e.status).length,l=e>0?r.filter(e=>null!=e.durationMs).reduce((e,t)=>{var r;return e+(null!=(r=t.durationMs)?r:0)},0)/Math.max(1,r.filter(e=>null!=e.durationMs).length):0,a=e>0?Math.round(n/e*100):0,s=Date.now(),i=[];for(let e=13;e>=0;e--){let t=s-864e5*e,n=t+864e5,o=r.filter(e=>e.ts>=t&&e.ts<n),l=new Date(t);i.push({day:"".concat(l.getMonth()+1,"/").concat(l.getDate()),ok:o.filter(e=>"ok"===e.status).length,error:o.filter(e=>"error"===e.status).length,other:o.filter(e=>"ok"!==e.status&&"error"!==e.status).length})}return{total:e,ok:n,errors:o,avgDuration:l,successRate:a,runsByDay:i,jobStats:t.map(e=>{let t=r.filter(t=>t.jobId===e.id),n=t.filter(e=>"ok"===e.status).length,o=t.filter(e=>"error"===e.status).length,l=t.filter(e=>null!=e.durationMs).length>0?t.filter(e=>null!=e.durationMs).reduce((e,t)=>{var r;return e+(null!=(r=t.durationMs)?r:0)},0)/t.filter(e=>null!=e.durationMs).length:0;return{job:e,runs:t.length,ok:n,errors:o,avgDuration:l}}).toSorted((e,t)=>t.runs-e.runs)}},[r,t]);return(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[(0,n.jsx)(a6,{label:"Total Runs",value:String(a.total)}),(0,n.jsx)(a6,{label:"Success Rate",value:"".concat(a.successRate,"%"),accent:a.successRate>=90?"var(--color-success, #22c55e)":a.successRate>=70?"var(--color-warning, #f59e0b)":"var(--color-error, #ef4444)"}),(0,n.jsx)(a6,{label:"Errors",value:String(a.errors),accent:a.errors>0?"var(--color-error, #ef4444)":void 0}),(0,n.jsx)(a6,{label:"Avg Duration",value:aV(a.avgDuration)})]}),(0,n.jsxs)("div",{className:"rounded-2xl p-4",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("h3",{className:"text-xs font-medium uppercase tracking-wider mb-4",style:{color:"var(--color-text-muted)"},children:"Runs (Last 14 Days)"}),(0,n.jsx)("div",{className:"flex items-end gap-1 h-32",children:a.runsByDay.map(e=>{let t=Math.max(...a.runsByDay.map(e=>e.ok+e.error+e.other),1),r=e.ok+e.error+e.other,o=Math.max(2,r/t*100),l=r>0?e.ok/r*100:100;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-1",children:[(0,n.jsx)("div",{className:"w-full flex flex-col justify-end",style:{height:"100%"},children:(0,n.jsx)("div",{className:"w-full rounded-t-sm",style:{height:"".concat(o,"%"),background:0===r?"var(--color-surface-hover)":100===l?"var(--color-success, #22c55e)":l>50?"color-mix(in srgb, var(--color-success, #22c55e) 60%, var(--color-error, #ef4444))":"var(--color-error, #ef4444)",opacity:0===r?.3:.7},title:"".concat(e.day,": ").concat(e.ok," ok, ").concat(e.error," errors")})}),(0,n.jsx)("span",{className:"text-[9px]",style:{color:"var(--color-text-muted)"},children:e.day})]},e.day)})}),(0,n.jsxs)("div",{className:"flex items-center gap-4 mt-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-sm",style:{background:"var(--color-success, #22c55e)",opacity:.7}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"Success"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-sm",style:{background:"var(--color-error, #ef4444)",opacity:.7}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"Error"})]})]})]}),(0,n.jsxs)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"px-4 py-3",style:{borderBottom:"1px solid var(--color-border)"},children:(0,n.jsx)("h3",{className:"text-xs font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:"Per-Job Breakdown"})}),a.jobStats.map(e=>{let t=e.runs>0?Math.round(e.ok/e.runs*100):0;return(0,n.jsxs)("button",{type:"button",onClick:()=>l(e.job.id),className:"w-full flex items-center gap-3 px-4 py-3 text-left cursor-pointer transition-colors",style:{borderBottom:"1px solid var(--color-border)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:e.job.name}),(0,n.jsxs)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:[e.runs," runs / ",t,"% success / avg ",aV(e.avgDuration)]})]}),(0,n.jsx)("div",{className:"w-24 h-2 rounded-full overflow-hidden flex-shrink-0",style:{background:"var(--color-surface-hover)"},children:(0,n.jsx)("div",{className:"h-full rounded-full",style:{width:"".concat(t,"%"),background:t>=90?"var(--color-success, #22c55e)":t>=70?"var(--color-warning, #f59e0b)":"var(--color-error, #ef4444)"}})}),null!=e.job.state.consecutiveErrors&&e.job.state.consecutiveErrors>0&&(0,n.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 12%, transparent)",color:"var(--color-error, #ef4444)"},children:[e.job.state.consecutiveErrors," err"]})]},e.job.id)})]})]})}function a6(e){let{label:t,value:r,accent:o}=e;return(0,n.jsxs)("div",{className:"rounded-xl p-3",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-wider mb-1",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("div",{className:"text-xl font-semibold",style:{color:null!=o?o:"var(--color-text)"},children:r})]})}function a3(e){let{title:t,icon:r,value:o,subtitle:l}=e;return(0,n.jsxs)("div",{className:"rounded-2xl p-4",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)("span",{style:{color:"var(--color-accent)"},children:r}),(0,n.jsx)("span",{className:"text-xs font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:t})]}),(0,n.jsx)("div",{className:"text-lg font-semibold mb-0.5",style:{color:"var(--color-text)"},children:o}),(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:l})]})}function a8(e){let{jobs:t}=e,[r,l]=(0,o.useState)(Date.now());(0,o.useEffect)(()=>{let e=setInterval(()=>l(Date.now()),1e4);return()=>clearInterval(e)},[]);let a=t.filter(e=>e.state.nextRunAtMs&&e.state.nextRunAtMs>r&&e.state.nextRunAtMs<r+864e5).toSorted((e,t)=>{var r,n;return(null!=(r=e.state.nextRunAtMs)?r:0)-(null!=(n=t.state.nextRunAtMs)?n:0)});return 0===a.length?null:(0,n.jsxs)("div",{className:"mb-8",children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Upcoming (next 24h)"}),(0,n.jsx)("div",{className:"rounded-2xl p-4",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute top-0 left-3 bottom-0 w-px",style:{background:"var(--color-border)"}}),(0,n.jsx)("div",{className:"space-y-3",children:a.map(e=>{var t;return(0,n.jsxs)("div",{className:"flex items-center gap-3 pl-1",children:[(0,n.jsx)("div",{className:"relative z-10 w-5 h-5 rounded-full flex items-center justify-center flex-shrink-0",style:{background:"var(--color-accent)",opacity:.8},children:(0,n.jsx)("div",{className:"w-2 h-2 rounded-full",style:{background:"var(--color-bg)"}})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:e.name}),(0,n.jsxs)("span",{className:"text-xs ml-2",style:{color:"var(--color-text-muted)"},children:["in ",aH((null!=(t=e.state.nextRunAtMs)?t:0)-r)]})]}),(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",style:{color:"var(--color-text-muted)"},children:new Date(e.state.nextRunAtMs).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]},e.id)})})]})})]})}function a7(e){let{jobs:t,onSelectJob:r,onSendCommand:o}=e;return(0,n.jsxs)("div",{className:"mb-6",children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Jobs"}),0===t.length?(0,n.jsx)("div",{className:"p-8 text-center rounded-2xl",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No cron jobs configured."})}):(0,n.jsx)("div",{className:"rounded-2xl overflow-hidden",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:(0,n.jsxs)("table",{className:"w-full text-sm",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{style:{borderBottom:"1px solid var(--color-border)",color:"var(--color-text-muted)"},children:[(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Name"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Schedule"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Status"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Next Run"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider",children:"Last Run"}),(0,n.jsx)("th",{className:"text-left px-4 py-2.5 font-medium text-xs uppercase tracking-wider w-20"})]})}),(0,n.jsx)("tbody",{children:t.map(e=>(0,n.jsx)(a9,{job:e,onClick:()=>r(e.id),onSendCommand:o},e.id))})]})})]})}function a9(e){var t;let{job:r,onClick:l,onSendCommand:a}=e,s=r.enabled?r.state.runningAtMs?"running":null!=(t=r.state.lastStatus)?t:"idle":"disabled",i=aJ(s),[c,d]=(0,o.useState)(Date.now());return(0,o.useEffect)(()=>{let e=setInterval(()=>d(Date.now()),5e3);return()=>clearInterval(e)},[]),(0,n.jsxs)("tr",{className:"cursor-pointer transition-colors group",style:{borderBottom:"1px solid var(--color-border)"},onClick:l,onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsxs)("td",{className:"px-4 py-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"font-medium",style:{color:"var(--color-text)"},children:r.name}),null!=r.state.consecutiveErrors&&r.state.consecutiveErrors>0&&(0,n.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 12%, transparent)",color:"var(--color-error, #ef4444)"},children:[r.state.consecutiveErrors," err"]})]}),r.description&&(0,n.jsx)("div",{className:"text-xs truncate max-w-[200px]",style:{color:"var(--color-text-muted)"},children:r.description})]}),(0,n.jsx)("td",{className:"px-4 py-3 text-xs",style:{color:"var(--color-text-muted)"},children:function(e){switch(e.kind){case"cron":return"cron: ".concat(e.expr).concat(e.tz?" (".concat(e.tz,")"):"");case"every":{let t=e.everyMs;if(t>=864e5)return"every ".concat(Math.round(t/864e5),"d");if(t>=36e5)return"every ".concat(Math.round(t/36e5),"h");if(t>=6e4)return"every ".concat(Math.round(t/6e4),"m");return"every ".concat(Math.round(t/1e3),"s")}case"at":return"at ".concat(e.at);default:return"unknown"}}(r.schedule)}),(0,n.jsx)("td",{className:"px-4 py-3",children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-xs px-2 py-0.5 rounded-full",style:{background:"color-mix(in srgb, ".concat(i," 12%, transparent)"),color:i},children:["running"===s&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse",style:{background:i}}),s]})}),(0,n.jsx)("td",{className:"px-4 py-3 text-xs",style:{color:"var(--color-text-muted)"},children:r.state.nextRunAtMs?r.state.nextRunAtMs>c?"in ".concat(aH(r.state.nextRunAtMs-c)):"overdue":"-"}),(0,n.jsx)("td",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[r.state.lastStatus&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:aJ(r.state.lastStatus)}}),(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:r.state.lastRunAtMs?"".concat(function(e){let t=Date.now()-e;return t<6e4?"just now":t<36e5?"".concat(Math.floor(t/6e4),"m ago"):t<864e5?"".concat(Math.floor(t/36e5),"h ago"):"".concat(Math.floor(t/864e5),"d ago")}(r.state.lastRunAtMs)).concat(r.state.lastDurationMs?" (".concat(aV(r.state.lastDurationMs),")"):""):"-"})]})}),(0,n.jsx)("td",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[!r.state.runningAtMs&&r.enabled&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),null==a||a('Run cron job "'.concat(r.name,'" (').concat(r.id,") now with --force"))},className:"p-1 rounded cursor-pointer",style:{color:"var(--color-accent)"},title:"Run now",children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"6 3 20 12 6 21 6 3"})})}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),null==a||a("".concat(r.enabled?"Disable":"Enable",' cron job "').concat(r.name,'" (').concat(r.id,")"))},className:"p-1 rounded cursor-pointer",style:{color:r.enabled?"var(--color-text-muted)":"var(--color-success, #22c55e)"},title:r.enabled?"Disable":"Enable",children:r.enabled?(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("path",{d:"m4.93 4.93 14.14 14.14"})]}):(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})})})]})})]})}function se(){return(0,n.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M19.5 12.572l-7.5 7.428l-7.5 -7.428a5 5 0 1 1 7.5 -6.566a5 5 0 1 1 7.5 6.572"})})}function st(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function sr(){return(0,n.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"6 3 20 12 6 21 6 3"})})}function sn(e){var t;return{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}}function so(e){let{sessionId:t}=e,[r,l]=(0,o.useState)([]),[a,s]=(0,o.useState)(!0),[i,c]=(0,o.useState)(null),d=(0,o.useCallback)(async()=>{try{var e,r;let n=await fetch("/api/web-sessions/".concat(encodeURIComponent(t)));if(!n.ok){let r=await fetch("/api/cron/runs/".concat(encodeURIComponent(t)));if(!r.ok)return void c(404===r.status?"Session transcript not found":"Failed to load session");let n=(null!=(e=(await r.json()).messages)?e:[]).filter(e=>"system"!==e.role).map(e=>({id:e.id,role:e.role,content:e.parts.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),parts:e.parts.map(e=>{if("text"===e.type)return{type:"text",text:e.text};if("thinking"===e.type)return{type:"reasoning",text:e.thinking};if("tool-call"===e.type){var t;let r=null!=e.output?(()=>{try{return JSON.parse(e.output)}catch(t){return{output:e.output}}})():void 0,n={type:"tool-invocation",toolCallId:e.toolCallId,toolName:e.toolName,args:null!=(t=e.args)?t:{}};return null!=r&&(n.result=r),n}return{type:"text",text:""}}),timestamp:e.timestamp}));l(n);return}let o=await n.json();l(null!=(r=o.messages)?r:[])}catch(e){c("Failed to load session")}finally{s(!1)}},[t]);return((0,o.useEffect)(()=>{d()},[d]),a)?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-4",children:[(0,n.jsx)("div",{className:"w-4 h-4 border-[1.5px] rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading session transcript..."})]}):i?(0,n.jsx)("div",{className:"text-xs rounded-lg px-3 py-2",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:i}):0===r.length?(0,n.jsx)("div",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:"Empty session transcript."}):(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("div",{className:"text-[11px] uppercase tracking-wider font-medium mb-2",style:{color:"var(--color-text-muted)"},children:"Session Transcript"}),r.map(e=>(0,n.jsx)(al,{message:sn(e)},e.id))]})}function sl(e){let{jobId:t,runAtMs:r,summary:l,fallback:a}=e,[s,i]=(0,o.useState)([]),[c,d]=(0,o.useState)(!0),[u,x]=(0,o.useState)(!1),h=(0,o.useCallback)(async()=>{if(!r||!l){d(!1),x(!0);return}try{let e=new URLSearchParams({jobId:t,runAtMs:String(r),summary:l}),n=await fetch("/api/cron/runs/search-transcript?".concat(e));if(!n.ok)return void x(!0);let o=await n.json();if(o.sessionId){let e=await fetch("/api/web-sessions/".concat(encodeURIComponent(o.sessionId)));if(e.ok){let t=await e.json();if(t.messages&&t.messages.length>0)return void i(t.messages)}}if(o.messages&&o.messages.length>0){let e=o.messages.filter(e=>"system"!==e.role).map(e=>({id:e.id,role:e.role,content:e.parts.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),parts:e.parts.map(e=>{if("text"===e.type)return{type:"text",text:e.text};if("thinking"===e.type)return{type:"reasoning",text:e.thinking};if("tool-call"===e.type){var t;let r=null!=e.output?(()=>{try{return JSON.parse(e.output)}catch(t){return{output:e.output}}})():void 0,n={type:"tool-invocation",toolCallId:e.toolCallId,toolName:e.toolName,args:null!=(t=e.args)?t:{}};return null!=r&&(n.result=r),n}return{type:"text",text:""}}),timestamp:e.timestamp}));i(e)}else x(!0)}catch(e){x(!0)}finally{d(!1)}},[t,r,l]);return((0,o.useEffect)(()=>{h()},[h]),c)?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-4",children:[(0,n.jsx)("div",{className:"w-4 h-4 border-[1.5px] rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Searching for transcript..."})]}):u||0===s.length?(0,n.jsx)(n.Fragment,{children:a}):(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("div",{className:"text-[11px] uppercase tracking-wider font-medium mb-2",style:{color:"var(--color-text-muted)"},children:"Session Transcript"}),s.map(e=>(0,n.jsx)(al,{message:sn(e)},e.id))]})}function sa(e){return e<1e3?"".concat(e,"ms"):e<6e4?"".concat((e/1e3).toFixed(1),"s"):"".concat(Math.floor(e/6e4),"m ").concat(Math.floor(e%6e4/1e3),"s")}function ss(e){var t,r;let{job:l,onBack:a,onSendCommand:s,runFilter:i="all",onRunFilterChange:c,expandedRunTs:d,onExpandedRunChange:u}=e,[x,h]=(0,o.useState)([]),[p,m]=(0,o.useState)(!0),f=null!=d?d:null,v=null!=u?u:()=>{},g=(0,o.useCallback)(async()=>{try{var e;let t=await fetch("/api/cron/jobs/".concat(encodeURIComponent(l.id),"/runs?limit=50")),r=await t.json();h(null!=(e=r.entries)?e:[])}catch(e){}finally{m(!1)}},[l.id]);(0,o.useEffect)(()=>{g();let e=setInterval(g,15e3);return()=>clearInterval(e)},[g]);let y=l.enabled?l.state.runningAtMs?"running":null!=(t=l.state.lastStatus)?t:"idle":"disabled";return(0,n.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,n.jsxs)("button",{type:"button",onClick:a,className:"flex items-center gap-1 text-sm mb-4 cursor-pointer",style:{color:"var(--color-text-muted)"},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]}),"Back to Cron"]}),(0,n.jsxs)("div",{className:"mb-6",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 mb-1",children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight",style:{color:"var(--color-text)"},children:l.name}),(0,n.jsx)(sh,{status:y})]}),l.description&&(0,n.jsx)("p",{className:"text-sm mb-3",style:{color:"var(--color-text-muted)"},children:l.description}),(0,n.jsx)(su,{job:l,onSendCommand:s})]}),(0,n.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-8",children:[(0,n.jsx)(si,{job:l}),(0,n.jsxs)("div",{className:"rounded-2xl p-4",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("h3",{className:"text-xs font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Configuration"}),(0,n.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,n.jsx)(sp,{label:"Schedule",value:function(e){switch(e.kind){case"cron":return e.expr+(e.tz?" (".concat(e.tz,")"):"");case"every":{let t=e.everyMs;if(t>=864e5)return"every ".concat(Math.round(t/864e5)," day(s)");if(t>=36e5)return"every ".concat(Math.round(t/36e5)," hour(s)");if(t>=6e4)return"every ".concat(Math.round(t/6e4)," minute(s)");return"every ".concat(Math.round(t/1e3)," second(s)")}case"at":return new Date(e.at).toLocaleString();default:return"unknown"}}(l.schedule)}),(0,n.jsx)(sp,{label:"Target",value:l.sessionTarget}),(0,n.jsx)(sp,{label:"Wake mode",value:l.wakeMode}),(0,n.jsx)(sp,{label:"Payload",value:"".concat(l.payload.kind,": ").concat("systemEvent"===(r=l.payload).kind?r.text.slice(0,120):r.message.slice(0,120))}),l.agentId&&(0,n.jsx)(sp,{label:"Agent",value:l.agentId}),l.delivery&&(0,n.jsx)(sp,{label:"Delivery",value:l.delivery.mode}),(0,n.jsx)(sp,{label:"Created",value:new Date(l.createdAtMs).toLocaleString()})]})]})]}),null!=l.state.consecutiveErrors&&l.state.consecutiveErrors>0&&(0,n.jsxs)("div",{className:"rounded-2xl p-4 mb-6",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 6%, var(--color-surface))",border:"1px solid color-mix(in srgb, var(--color-error, #ef4444) 18%, transparent)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),(0,n.jsxs)("span",{className:"text-sm font-medium",style:{color:"var(--color-error, #ef4444)"},children:[l.state.consecutiveErrors," consecutive error",l.state.consecutiveErrors>1?"s":""]})]}),l.state.lastError&&(0,n.jsx)("p",{className:"text-xs font-mono mt-1",style:{color:"var(--color-error, #ef4444)",opacity:.8},children:l.state.lastError})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:"Run History"}),(0,n.jsx)("div",{className:"flex items-center gap-1 rounded-lg p-0.5",style:{background:"var(--color-surface-hover)"},children:["all","ok","error","running"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>null==c?void 0:c(e),className:"px-2.5 py-1 rounded-md text-[11px] font-medium cursor-pointer",style:{background:i===e?"var(--color-surface)":"transparent",color:i===e?"var(--color-text)":"var(--color-text-muted)",boxShadow:i===e?"var(--shadow-sm)":"none"},children:"all"===e?"All":e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),p?(0,n.jsx)("div",{className:"flex items-center justify-center p-8",children:(0,n.jsx)("div",{className:"w-5 h-5 border-2 rounded-full animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):0===x.length?(0,n.jsx)("div",{className:"p-8 text-center rounded-2xl",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"No runs recorded yet."})}):(0,n.jsx)("div",{className:"space-y-2",children:x.toReversed().filter(e=>"all"===i||e.status===i).map(e=>(0,n.jsx)(sc,{run:e,isExpanded:f===e.ts,onToggle:()=>v(f===e.ts?null:e.ts)},"".concat(e.ts,"-").concat(e.jobId)))})]})]})}function si(e){let{job:t}=e,[r,l]=(0,o.useState)(Date.now());(0,o.useEffect)(()=>{let e=setInterval(()=>l(Date.now()),1e3);return()=>clearInterval(e)},[]);let a=t.state.nextRunAtMs,s=!!t.state.runningAtMs;return(0,n.jsxs)("div",{className:"rounded-2xl p-4 flex flex-col justify-center",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)("h3",{className:"text-xs font-medium uppercase tracking-wider mb-2",style:{color:"var(--color-text-muted)"},children:s?"Currently Running":"Next Run"}),s?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"text-2xl font-semibold",style:{color:"var(--color-accent)"},children:"Running now"})]}):a?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"text-3xl font-semibold mb-1",style:{color:"var(--color-text)"},children:a>r?function(e){if(e<=0)return"now";let t=Math.ceil(e/1e3);if(t<60)return"".concat(t,"s");let r=Math.floor(t/60),n=t%60;if(r<60)return n>0?"".concat(r,"m ").concat(n,"s"):"".concat(r,"m");let o=Math.floor(r/60),l=r%60;return l>0?"".concat(o,"h ").concat(l,"m"):"".concat(o,"h")}(a-r):"overdue"}),(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:new Date(a).toLocaleString()})]}):(0,n.jsx)("div",{className:"text-lg",style:{color:"var(--color-text-muted)"},children:t.enabled?"Not scheduled":"Disabled"})]})}function sc(e){var t;let{run:r,isExpanded:o,onToggle:l}=e,a="ok"===r.status?"var(--color-success, #22c55e)":"error"===r.status?"var(--color-error, #ef4444)":"var(--color-warning, #f59e0b)",s=!!r.sessionId;return(0,n.jsxs)("div",{className:"rounded-xl overflow-hidden",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:l,className:"w-full flex items-center gap-3 px-4 py-3 text-left cursor-pointer transition-colors",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:a}}),(0,n.jsx)("span",{className:"text-sm flex-shrink-0",style:{color:"var(--color-text)"},title:new Date(r.ts).toLocaleString(),children:function(e){let t=Date.now()-e;return t<0||t<6e4?"just now":t<36e5?"".concat(Math.floor(t/6e4),"m ago"):t<864e5?"".concat(Math.floor(t/36e5),"h ago"):t<6048e5?"".concat(Math.floor(t/864e5),"d ago"):new Date(e).toLocaleDateString()}(r.ts)}),(0,n.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"color-mix(in srgb, ".concat(a," 12%, transparent)"),color:a},children:null!=(t=r.status)?t:"unknown"}),null!=r.durationMs&&(0,n.jsx)("span",{className:"text-xs flex-shrink-0",style:{color:"var(--color-text-muted)"},children:sa(r.durationMs)}),r.summary&&(0,n.jsx)("span",{className:"text-xs truncate flex-1 min-w-0",style:{color:"var(--color-text-muted)"},children:r.summary}),s&&(0,n.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 flex items-center gap-1",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),"session"]}),(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 12 12",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 transition-transform duration-200 ".concat(o?"":"-rotate-90"),children:(0,n.jsx)("path",{d:"M3 4.5L6 7.5L9 4.5"})})]}),o&&(0,n.jsxs)("div",{className:"px-4 pb-4",style:{borderTop:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-4 mt-3 mb-3 flex-wrap",children:[(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:new Date(r.ts).toLocaleString()}),null!=r.durationMs&&(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["Duration: ",sa(r.durationMs)]})]}),r.error&&(0,n.jsx)("div",{className:"text-xs font-mono rounded-lg px-3 py-2 mb-3",style:{color:"var(--color-error, #ef4444)",background:"color-mix(in srgb, var(--color-error, #ef4444) 6%, var(--color-surface))"},children:r.error}),r.sessionId?(0,n.jsx)(so,{sessionId:r.sessionId}):(0,n.jsx)(sd,{run:r})]})]})}function sd(e){let{run:t}=e,r=t.summary?(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[11px] uppercase tracking-wider font-medium mb-2",style:{color:"var(--color-text-muted)"},children:"Run Output"}),(0,n.jsx)("div",{className:"chat-prose text-sm",style:{color:"var(--color-text)"},children:(0,n.jsx)(lL.oz,{remarkPlugins:[lT.A],children:t.summary})})]}):(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No output recorded for this run."});return(0,n.jsx)(sl,{jobId:t.jobId,runAtMs:t.runAtMs,summary:t.summary,fallback:r})}function su(e){let{job:t,onSendCommand:r}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[!t.state.runningAtMs&&t.enabled&&(0,n.jsxs)(sx,{onClick:()=>null==r?void 0:r('Run cron job "'.concat(t.name,'" (').concat(t.id,") now with --force")),accent:!0,children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"6 3 20 12 6 21 6 3"})}),"Run now"]}),t.state.runningAtMs&&(0,n.jsxs)(sx,{disabled:!0,accent:!0,children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse",style:{background:"currentColor"}}),"Running..."]}),(0,n.jsx)(sx,{onClick:()=>null==r?void 0:r("".concat(t.enabled?"Disable":"Enable",' cron job "').concat(t.name,'" (').concat(t.id,")")),children:t.enabled?"Disable":"Enable"}),(0,n.jsx)(sx,{onClick:()=>null==r?void 0:r('Delete cron job "'.concat(t.name,'" (').concat(t.id,")")),danger:!0,children:"Delete"})]})}function sx(e){let{children:t,onClick:r,disabled:o,accent:l,danger:a}=e;return(0,n.jsx)("button",{type:"button",onClick:r,disabled:o,className:"text-xs font-medium px-3 py-1.5 rounded-lg flex items-center gap-1.5 cursor-pointer transition-opacity disabled:opacity-40 disabled:cursor-not-allowed",style:{background:l?"var(--color-accent)":a?"color-mix(in srgb, var(--color-error, #ef4444) 12%, transparent)":"var(--color-surface-hover)",color:l?"white":a?"var(--color-error, #ef4444)":"var(--color-text-muted)"},children:t})}function sh(e){let{status:t}=e,r="ok"===t?"var(--color-success, #22c55e)":"running"===t?"var(--color-accent)":"error"===t?"var(--color-error, #ef4444)":"var(--color-text-muted)";return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-xs px-2.5 py-1 rounded-full",style:{background:"color-mix(in srgb, ".concat(r," 12%, transparent)"),color:r},children:["running"===t&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse",style:{background:r}}),t]})}function sp(e){let{label:t,value:r}=e;return(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium w-20 flex-shrink-0",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("span",{className:"text-xs break-all",style:{color:"var(--color-text)"},children:r})]})}function sm(e){var t,r;let{job:o,run:l,sessionId:a,onBack:s,onBackToJob:i}=e,c="ok"===l.status?"var(--color-success, #22c55e)":"error"===l.status?"var(--color-error, #ef4444)":"var(--color-warning, #f59e0b)";return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"px-4 py-3 flex items-center gap-3 flex-shrink-0",style:{borderBottom:"1px solid var(--color-border)",background:"var(--color-bg-glass)"},children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"p-1.5 rounded-lg flex-shrink-0 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Back to Cron",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:i,className:"text-sm font-semibold truncate cursor-pointer hover:underline",style:{color:"var(--color-text)"},title:"Back to job detail",children:o.name}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",style:{background:"color-mix(in srgb, ".concat(c," 12%, transparent)"),color:c},children:null!=(t=l.status)?t:"unknown"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 text-xs",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("span",{children:new Date(l.ts).toLocaleString()}),null!=l.durationMs&&(0,n.jsx)("span",{children:(r=l.durationMs)<1e3?"".concat(r,"ms"):r<6e4?"".concat((r/1e3).toFixed(1),"s"):"".concat(Math.floor(r/6e4),"m ").concat(Math.floor(r%6e4/1e3),"s")}),l.summary&&(0,n.jsx)("span",{className:"truncate",children:l.summary})]})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(aC,{initialSessionId:a,sessionTitle:"".concat(o.name," - Run ").concat(new Date(l.ts).toLocaleString())})})]})}function sf(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function sv(){return(0,n.jsxs)("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:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]})}function sg(e){let{size:t=12}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}function sy(){return(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:"m6 9 6 6 6-6"})})}function sb(){return(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"})})}function sj(){return(0,n.jsxs)("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:"M3 6h18"}),(0,n.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,n.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})}let sk={text:"Aa",number:"#",date:"\uD83D\uDCC5",boolean:"☑",enum:"\uD83C\uDFF7",relation:"\uD83D\uDD17",user:"\uD83D\uDC64",richtext:"\xb6",email:"@"};function sw(e){let{trigger:t,open:r,onOpenChange:l,children:a,align:s="left"}=e,i=(0,o.useRef)(null);return(0,o.useEffect)(()=>{if(!r)return;let e=e=>{i.current&&!i.current.contains(e.target)&&l(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r,l]),(0,n.jsxs)("div",{ref:i,className:"relative inline-block",children:[(0,n.jsx)("div",{onClick:()=>l(!r),children:t}),r&&(0,n.jsx)("div",{className:"absolute z-50 mt-1 rounded-lg shadow-lg border py-1 min-w-[200px] max-h-[320px] overflow-y-auto",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",["right"===s?"right":"left"]:0},children:a})]})}function sN(e){let{children:t,onClick:r,danger:o,active:l}=e;return(0,n.jsx)("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs transition-colors cursor-pointer flex items-center gap-2",style:{color:o?"var(--color-error, #ef4444)":l?"var(--color-accent)":"var(--color-text)",background:l?"var(--color-accent-light, rgba(99,102,241,0.1))":"transparent"},onMouseEnter:e=>{e.currentTarget.style.background=o?"rgba(239,68,68,0.1)":"var(--color-accent-light, rgba(99,102,241,0.1))"},onMouseLeave:e=>{e.currentTarget.style.background=l?"var(--color-accent-light, rgba(99,102,241,0.1))":"transparent"},onClick:r,children:t})}function sC(e){let{value:t,onChange:r,placeholder:o}=e;return(0,n.jsx)("input",{type:"text",value:t,onChange:e=>r(e.target.value),placeholder:null!=o?o:"Value...",className:"px-2 py-1 rounded-md text-xs outline-none min-w-[120px]",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}})}function sS(e){let{value:t,valueTo:r,showRange:o,onChange:l}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{type:"number",value:null!=t?t:"",onChange:e=>l(e.target.value?Number(e.target.value):void 0,r),placeholder:o?"Min":"Value",className:"px-2 py-1 rounded-md text-xs outline-none w-20",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"to"}),(0,n.jsx)("input",{type:"number",value:null!=r?r:"",onChange:e=>l(t,e.target.value?Number(e.target.value):void 0),placeholder:"Max",className:"px-2 py-1 rounded-md text-xs outline-none w-20",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}})]})]})}function sM(e){let{value:t,valueTo:r,showRange:o,showRelative:l,relativeAmount:a,relativeUnit:s,onChange:i}=e;return l?(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{type:"number",min:1,value:null!=a?a:7,onChange:e=>i({relativeAmount:Number(e.target.value)||7}),className:"px-2 py-1 rounded-md text-xs outline-none w-16",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),(0,n.jsxs)("select",{value:null!=s?s:"days",onChange:e=>i({relativeUnit:e.target.value}),className:"px-2 py-1 rounded-md text-xs outline-none cursor-pointer",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"},children:[(0,n.jsx)("option",{value:"days",children:"days"}),(0,n.jsx)("option",{value:"weeks",children:"weeks"}),(0,n.jsx)("option",{value:"months",children:"months"})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{type:"date",value:t,onChange:e=>i({value:e.target.value}),className:"px-2 py-1 rounded-md text-xs outline-none",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",colorScheme:"dark"}}),o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"to"}),(0,n.jsx)("input",{type:"date",value:r,onChange:e=>i({valueTo:e.target.value}),className:"px-2 py-1 rounded-md text-xs outline-none",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",colorScheme:"dark"}})]})]})}function sL(e){var t;let{value:r,enumValues:o,enumColors:l,multiple:a,onChange:s}=e,i=Array.isArray(r)?r:r?[r]:[];return a?(0,n.jsx)("div",{className:"flex flex-wrap gap-1",children:o.map((e,t)=>{var o;let a=i.includes(e),c=null!=(o=null==l?void 0:l[t])?o:"#94a3b8";return(0,n.jsx)("button",{type:"button",onClick:()=>{let t=a?i.filter(t=>t!==e):[...i,e];s(1!==t.length||Array.isArray(r)?t:t[0])},className:"px-2 py-0.5 rounded-full text-[10px] transition-colors cursor-pointer",style:{background:a?"".concat(c,"20"):"var(--color-surface)",border:"1px solid ".concat(a?"".concat(c,"60"):"var(--color-border)"),color:a?c:"var(--color-text-muted)"},children:e},e)})}):(0,n.jsxs)("select",{value:"string"==typeof r?r:null!=(t=r[0])?t:"",onChange:e=>s(e.target.value),className:"px-2 py-1 rounded-md text-xs outline-none cursor-pointer",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",minWidth:100},children:[(0,n.jsx)("option",{value:"",children:"Select..."}),o.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})}function sT(){return null}function sD(e){let{value:t,relatedObjectName:r,members:o,multiple:l,onChange:a}=e;if(o&&o.length>0){let e=Array.isArray(t)?t:t?[t]:[];return(0,n.jsx)("div",{className:"flex flex-wrap gap-1",children:o.map(t=>{let r=e.includes(t.id);return(0,n.jsx)("button",{type:"button",onClick:()=>{l?a(r?e.filter(e=>e!==t.id):[...e,t.id]):a(r?"":t.id)},className:"px-2 py-0.5 rounded-full text-[10px] transition-colors cursor-pointer",style:{background:r?"var(--color-accent-light)":"var(--color-surface)",border:"1px solid ".concat(r?"var(--color-accent)":"var(--color-border)"),color:r?"var(--color-accent)":"var(--color-text-muted)"},children:t.name},t.id)})})}return(0,n.jsx)(sC,{value:Array.isArray(t)?t.join(", "):String(null!=t?t:""),onChange:e=>{let t=e.split(",").map(e=>e.trim()).filter(Boolean);a(1===t.length?t[0]:t)},placeholder:r?"Search ".concat(r,"..."):"ID..."})}function sE(e){var t,r,o,l,a,s,i;let{rule:c,field:d,fields:u,members:x,onUpdate:h,onRemove:p}=e,m=null!=(t=null==d?void 0:d.type)?t:"text",f=function(e){switch(e){case"text":case"richtext":case"email":default:return rs;case"number":return ri;case"date":return rc;case"enum":return rd;case"boolean":return ru;case"relation":case"user":return rx;case"tags":return rh}}(m),v="between"===c.operator||"date_between"===c.operator,g="relative_past"===c.operator||"relative_next"===c.operator,y="is_any_of"===c.operator||"is_none_of"===c.operator||"has_any"===c.operator||"has_none"===c.operator||"has_all"===c.operator,b="is_empty"===c.operator||"is_not_empty"===c.operator||"is_true"===c.operator||"is_false"===c.operator;return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[(0,n.jsx)("select",{value:c.field,onChange:e=>(e=>{var t;let r=u.find(t=>t.name===e);h({field:e,operator:rp(null!=(t=null==r?void 0:r.type)?t:"text"),value:void 0,valueTo:void 0,relativeAmount:void 0,relativeUnit:void 0})})(e.target.value),className:"px-2 py-1 rounded-md text-xs outline-none cursor-pointer font-medium",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)",maxWidth:140},children:u.map(e=>{var t;return(0,n.jsxs)("option",{value:e.name,children:[null!=(t=sk[e.type])?t:"?"," ",e.name]},e.name)})}),(0,n.jsx)("select",{value:c.operator,onChange:e=>h({operator:e.target.value,value:void 0,valueTo:void 0}),className:"px-2 py-1 rounded-md text-xs outline-none cursor-pointer",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text-muted)"},children:f.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),!b&&(0,n.jsxs)(n.Fragment,{children:[("text"===m||"richtext"===m||"email"===m||"tags"===m)&&(0,n.jsx)(sC,{value:String(null!=(r=c.value)?r:""),onChange:e=>h({value:e})}),"number"===m&&(0,n.jsx)(sS,{value:"number"==typeof c.value?c.value:void 0,valueTo:"number"==typeof c.valueTo?c.valueTo:void 0,showRange:v,onChange:(e,t)=>h({value:e,valueTo:t})}),"date"===m&&(0,n.jsx)(sM,{value:String(null!=(o=c.value)?o:""),valueTo:String(null!=(l=c.valueTo)?l:""),showRange:v,showRelative:g,relativeAmount:c.relativeAmount,relativeUnit:c.relativeUnit,onChange:h}),"enum"===m&&(0,n.jsx)(sL,{value:null!=(a=c.value)?a:"",enumValues:null!=(s=null==d?void 0:d.enum_values)?s:[],enumColors:null==d?void 0:d.enum_colors,multiple:y,onChange:e=>h({value:e})}),"boolean"===m&&(0,n.jsx)(sT,{}),("relation"===m||"user"===m)&&(0,n.jsx)(sD,{value:null!=(i=c.value)?i:"",relatedObjectName:null==d?void 0:d.related_object_name,members:"user"===m?x:void 0,multiple:y,onChange:e=>h({value:e})})]}),(0,n.jsx)("button",{type:"button",onClick:p,className:"p-1 rounded transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Remove filter",children:(0,n.jsx)(sg,{size:14})})]})}function sR(e){let{fields:t,filters:r,onFiltersChange:l,savedViews:a,activeViewName:s,onSaveView:i,onLoadView:c,onDeleteView:d,onSetActiveView:u,members:x}=e,[h,p]=(0,o.useState)(!1),[m,f]=(0,o.useState)(!1),[v,g]=(0,o.useState)(!1),[y,b]=(0,o.useState)(""),j=(0,o.useRef)(null),k=r.rules.length>0;(0,o.useEffect)(()=>{v&&j.current&&j.current.focus()},[v]);let w=(0,o.useCallback)(e=>{var n;let o=t.find(t=>t.name===e),a=null!=(n=null==o?void 0:o.type)?n:"text",s={id:Math.random().toString(36).slice(2,9),field:e,operator:rp(a)};l({...r,rules:[...r.rules,s]}),p(!1)},[t,r,l]),N=(0,o.useCallback)((e,t)=>{let n=r.rules.map(r=>rm(r)||r.id!==e?r:{...r,...t});l({...r,rules:n})},[r,l]),C=(0,o.useCallback)(e=>{let t=r.rules.filter(t=>!!rm(t)||t.id!==e);l({...r,rules:t})},[r,l]),S=(0,o.useCallback)(()=>{l(rv()),u(void 0)},[l,u]),M=(0,o.useCallback)(()=>{l({...r,conjunction:"and"===r.conjunction?"or":"and"})},[r,l]),L=(0,o.useCallback)(()=>{y.trim()&&(i(y.trim()),b(""),g(!1))},[y,i]),T=(0,o.useMemo)(()=>{let e={};for(let n of t){var r;let t=null!=(r=e[n.type])?r:[];t.push(n),e[n.type]=t}return e},[t]);return(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs font-medium",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(sf,{}),"Filters"]}),r.rules.length>=2&&(0,n.jsx)("button",{type:"button",onClick:M,className:"px-2 py-0.5 rounded-full text-[10px] font-semibold uppercase tracking-wider transition-colors cursor-pointer",style:{background:"var(--color-accent-light, rgba(99,102,241,0.1))",color:"var(--color-accent)",border:"1px solid var(--color-accent)"},title:"Matching ".concat("and"===r.conjunction?"ALL":"ANY"," rules. Click to toggle."),children:r.conjunction}),r.rules.map(e=>rm(e)?null:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[11px] max-w-[250px] truncate",style:{background:"var(--color-accent-light, rgba(99,102,241,0.1))",color:"var(--color-accent)",border:"1px solid var(--color-accent)"},title:rg(e),children:[(0,n.jsx)("span",{className:"truncate",children:rg(e)}),(0,n.jsx)("button",{type:"button",onClick:()=>C(e.id),className:"flex-shrink-0 cursor-pointer p-0.5 rounded-full transition-colors",style:{color:"var(--color-accent)"},children:(0,n.jsx)(sg,{size:10})})]},e.id)),(0,n.jsx)(sw,{trigger:(0,n.jsxs)("button",{type:"button",className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-colors cursor-pointer",style:{color:"var(--color-text-muted)",border:"1px dashed var(--color-border)"},children:[(0,n.jsx)(sv,{})," Add filter"]}),open:h,onOpenChange:p,children:Object.entries(T).map(e=>{var t;let[r,o]=e;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"px-3 py-1 text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:[null!=(t=sk[r])?t:"?"," ",r]}),o.map(e=>(0,n.jsx)(sN,{onClick:()=>w(e.name),children:e.name},e.name))]},r)})}),k&&(0,n.jsxs)("button",{type:"button",onClick:S,className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] transition-colors cursor-pointer",style:{color:"var(--color-accent)",background:"var(--color-accent-light, rgba(99,102,241,0.1))"},children:[(0,n.jsx)(sg,{size:10}),"Clear all"]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)(sw,{trigger:(0,n.jsxs)("button",{type:"button",className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-colors cursor-pointer",style:{color:s?"var(--color-accent)":"var(--color-text-muted)",border:"1px solid ".concat(s?"var(--color-accent)":"var(--color-border)"),background:s?"var(--color-accent-light, rgba(99,102,241,0.1))":"transparent"},children:[(0,n.jsx)(sb,{}),null!=s?s:"Views",(0,n.jsx)(sy,{})]}),open:m,onOpenChange:f,align:"right",children:[0===a.length&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs",style:{color:"var(--color-text-muted)"},children:"No saved views"}),a.map(e=>(0,n.jsxs)("div",{className:"flex items-center group",children:[(0,n.jsxs)(sN,{onClick:()=>{c(e),f(!1)},active:s===e.name,children:[(0,n.jsx)("span",{className:"flex-1 truncate",children:e.name}),e.view_type&&"table"!==e.view_type&&(0,n.jsx)("span",{className:"text-[9px] px-1.5 py-0.5 rounded ml-1 capitalize",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:e.view_type}),e.filters&&e.filters.rules.length>0&&(0,n.jsxs)("span",{className:"text-[10px] ml-1",style:{color:"var(--color-text-muted)"},children:[e.filters.rules.length," filter",1!==e.filters.rules.length?"s":""]})]}),(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),d(e.name)},className:"px-2 py-1 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Delete view",children:(0,n.jsx)(sj,{})})]},e.name)),(0,n.jsx)("div",{className:"border-t my-1",style:{borderColor:"var(--color-border)"}}),k&&!v&&(0,n.jsxs)(sN,{onClick:()=>g(!0),children:[(0,n.jsx)(sb,{}),"Save current filters as view..."]}),v&&(0,n.jsxs)("div",{className:"px-3 py-2 flex items-center gap-1",children:[(0,n.jsx)("input",{ref:j,type:"text",value:y,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"===e.key&&L(),"Escape"===e.key&&g(!1)},placeholder:"View name...",className:"px-2 py-1 rounded-md text-xs outline-none flex-1",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}}),(0,n.jsx)("button",{type:"button",onClick:L,className:"px-2 py-1 rounded-md text-xs transition-colors cursor-pointer",style:{background:"var(--color-accent)",color:"white"},children:"Save"})]}),s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t my-1",style:{borderColor:"var(--color-border)"}}),(0,n.jsxs)(sN,{onClick:()=>{S(),f(!1)},children:[(0,n.jsx)(sg,{size:12}),"Clear active view"]})]})]})]}),k&&(0,n.jsx)("div",{className:"space-y-1.5 pl-5",children:r.rules.map((e,o)=>{if(rm(e))return null;let l=t.find(t=>t.name===e.field);return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[o>0&&(0,n.jsx)("span",{className:"text-[10px] font-semibold uppercase w-8 text-center flex-shrink-0",style:{color:"var(--color-text-muted)"},children:r.conjunction}),0===o&&(0,n.jsx)("span",{className:"w-8 flex-shrink-0"}),(0,n.jsx)(sE,{rule:e,field:l,fields:t,members:x,onUpdate:t=>N(e.id,t),onRemove:()=>C(e.id)})]},e.id)})})]})}let sW="__home__",sI={id:sW,type:"home",title:"Home",pinned:!0};function sB(e){return"".concat("dench:tabs",":").concat(e||"default")}function sF(e,t){return e.tabs.some(e=>e.id===t)?{...e,activeTabId:t}:e}function sP(e){let{tabs:t,activeTabId:r,onActivate:l,onClose:a,onCloseOthers:s,onCloseToRight:i,onCloseAll:c,onReorder:d,onTogglePin:u}=e,[x,h]=(0,o.useState)(null),[p,m]=(0,o.useState)(null),[f,v]=(0,o.useState)(null),g=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!x)return;let e=()=>h(null);return window.addEventListener("click",e),window.addEventListener("contextmenu",e),()=>{window.removeEventListener("click",e),window.removeEventListener("contextmenu",e)}},[x]);let y=(0,o.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),h({tabId:t,x:e.clientX,y:e.clientY})},[]),b=(0,o.useCallback)((e,t)=>{1===e.button&&(e.preventDefault(),a(t))},[a]),j=(0,o.useCallback)((e,t)=>{m(t),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",String(t))},[]),k=(0,o.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",v(t)},[]),w=(0,o.useCallback)((e,t)=>{e.preventDefault(),null!==p&&p!==t&&d(p,t),m(null),v(null)},[p,d]),N=(0,o.useCallback)(()=>{m(null),v(null)},[]);if(0===t.length)return null;let C=x?t.find(e=>e.id===x.tabId):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:g,className:"flex items-end overflow-x-auto flex-shrink-0",style:{background:"var(--color-surface)",borderBottom:"1px solid var(--color-border)",scrollbarWidth:"none"},children:t.map((e,t)=>{let o=e.id===r,s=f===t&&p!==t,i=e.id===sW;return(0,n.jsx)("button",{type:"button",draggable:!i,onClick:()=>l(e.id),onMouseDown:i?void 0:t=>b(t,e.id),onContextMenu:i?void 0:t=>y(t,e.id),onDragStart:i?void 0:e=>j(e,t),onDragOver:i?void 0:e=>k(e,t),onDrop:i?void 0:e=>w(e,t),onDragEnd:i?void 0:N,className:"group flex items-center gap-1.5 h-[34px] text-[12.5px] font-medium cursor-pointer flex-shrink-0 relative transition-colors duration-75 select-none ".concat(i?"px-2.5":"pl-3 pr-1.5"),style:{color:o?"var(--color-text)":"var(--color-text-muted)",background:o?"var(--color-bg)":"transparent",borderBottom:o?"2px solid var(--color-accent)":"2px solid transparent",borderLeft:s&&!i?"2px solid var(--color-accent)":"2px solid transparent",opacity:p===t?.5:1,maxWidth:i?void 0:200,borderRight:i?"1px solid var(--color-border)":void 0},title:i?"Home (New Chat)":void 0,children:i?(0,n.jsx)(sU,{}):(0,n.jsxs)(n.Fragment,{children:[e.pinned&&(0,n.jsx)(sO,{}),(0,n.jsx)(s_,{type:e.type,icon:e.icon,appPath:e.path}),(0,n.jsx)("span",{className:"truncate max-w-[140px]",children:e.title}),!e.pinned&&(0,n.jsx)("span",{role:"button",tabIndex:-1,onClick:t=>{t.stopPropagation(),a(e.id)},onKeyDown:t=>{"Enter"===t.key&&(t.stopPropagation(),a(e.id))},className:"ml-0.5 p-0.5 rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)(sz,{})})]})},e.id)})}),x&&C&&(0,n.jsxs)("div",{className:"fixed z-[9999] min-w-[180px] rounded-lg border py-1 shadow-lg",style:{left:x.x,top:x.y,background:"var(--color-surface)",borderColor:"var(--color-border)"},children:[(0,n.jsx)(sA,{label:C.pinned?"Unpin Tab":"Pin Tab",onClick:()=>{u(x.tabId),h(null)}}),(0,n.jsx)("div",{className:"h-px my-1",style:{background:"var(--color-border)"}}),(0,n.jsx)(sA,{label:"Close",shortcut:"⌘W",disabled:C.pinned,onClick:()=>{a(x.tabId),h(null)}}),(0,n.jsx)(sA,{label:"Close Others",onClick:()=>{s(x.tabId),h(null)}}),(0,n.jsx)(sA,{label:"Close to the Right",onClick:()=>{i(x.tabId),h(null)}}),(0,n.jsx)(sA,{label:"Close All",onClick:()=>{c(),h(null)}})]})]})}function sA(e){let{label:t,shortcut:r,disabled:o,onClick:l}=e;return(0,n.jsxs)("button",{type:"button",disabled:o,onClick:l,className:"w-full flex items-center justify-between px-3 py-1.5 text-[12.5px] text-left transition-colors disabled:opacity-40 cursor-pointer disabled:cursor-default",style:{color:"var(--color-text)"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{children:t}),r&&(0,n.jsx)("span",{className:"ml-4 text-[11px]",style:{color:"var(--color-text-muted)"},children:r})]})}function s_(e){let{type:t,icon:r,appPath:o}=e;if(r&&o&&(r.endsWith(".png")||r.endsWith(".svg")||r.endsWith(".jpg")||r.endsWith(".jpeg")||r.endsWith(".webp")))return(0,n.jsx)("img",{src:na(o,r),alt:"",width:14,height:14,className:"rounded-sm flex-shrink-0",style:{objectFit:"cover"}});switch(t){case"home":return(0,n.jsx)(sU,{});case"app":return(0,n.jsx)(sV,{});case"chat":return(0,n.jsx)(sJ,{});case"cron":return(0,n.jsx)(sK,{});case"object":return(0,n.jsx)(sq,{});default:return(0,n.jsx)(sH,{})}}function sz(){return(0,n.jsxs)("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:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}function sO(){return(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",className:"flex-shrink-0",style:{opacity:.5},children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"})})}function sU(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.7},children:[(0,n.jsx)("path",{d:"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),(0,n.jsx)("polyline",{points:"9 22 9 12 15 12 15 22"})]})}function sH(){return(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]})}function sV(){return(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:[(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"}),(0,n.jsx)("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]})}function sJ(){return(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function sK(){return(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function sq(){return(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.6},children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M9 21V9"})]})}let sG=(0,rD.default)(()=>Promise.all([r.e(2078),r.e(4560),r.e(7858)]).then(r.bind(r,77858)),{loadableGenerated:{webpack:()=>[77858]},ssr:!1});function s$(e){return e.startsWith("~")&&!e.startsWith("~/")}function sZ(e){return e.startsWith("/")}function sY(e){return e.startsWith("~/")}function sQ(e){return s$(e)?"/api/workspace/virtual-file?path=".concat(encodeURIComponent(e)):sZ(e)||sY(e)?"/api/workspace/browse-file?path=".concat(encodeURIComponent(e)):"/api/workspace/file?path=".concat(encodeURIComponent(e))}function sX(e){return sZ(e)||sY(e)?"/api/workspace/browse-file?path=".concat(encodeURIComponent(e),"&raw=true"):"/api/workspace/raw-file?path=".concat(encodeURIComponent(e))}let s0="dench-workspace-left-sidebar-width",s1="dench-workspace-right-sidebar-width";function s2(e,t,r){return Math.min(r,Math.max(t,e))}function s4(e){let{mode:t,containerRef:r,min:l,max:a,onResize:s}=e,[i,c]=(0,o.useState)(!1),d=(0,o.useCallback)(e=>{e.preventDefault(),c(!0);let n=e=>{let n=r.current;if(!n)return;let o=n.getBoundingClientRect();s(s2("left"===t?e.clientX-o.left:o.right-e.clientX,l,a))},o=()=>{c(!1),document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",o),document.body.style.removeProperty("user-select"),document.body.style.removeProperty("cursor"),document.body.classList.remove("resizing")};document.body.style.setProperty("user-select","none"),document.body.style.setProperty("cursor","col-resize"),document.body.classList.add("resizing"),document.addEventListener("mousemove",n),document.addEventListener("mouseup",o)},[r,t,l,a,s]);return(0,n.jsx)("div",{role:"separator","aria-orientation":"vertical",onMouseDown:d,className:"cursor-col-resize flex justify-center transition-colors ".concat(i?"bg-blue-600/30":"hover:bg-blue-600/30"),style:{position:"absolute",["left"===t?"right":"left"]:-2,top:0,bottom:0,width:4,zIndex:20}})}function s5(e,t){for(let r of e){if(r.path===t)return r;if(r.children){let e=s5(r.children,t);if(e)return e}}return null}function s6(e){let t=e.split("/");return t[t.length-1]}function s3(e,t){let r=s5(e,t);if(r||!t.startsWith("knowledge/")&&(r=s5(e,"knowledge/".concat(t)))||t.startsWith("knowledge/")&&(r=s5(e,t.slice(10))))return r;let n=t.split("/").pop();return n&&(r=function e(t){for(let r of t){if("object"===r.type&&s6(r.path)===n)return r;if(r.children){let t=e(r.children);if(t)return t}}return null}(e))?r:null}function s8(){return(0,n.jsx)(o.Suspense,{fallback:(0,n.jsx)("div",{className:"flex h-screen items-center justify-center",style:{background:"var(--color-bg)"},children:(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})}),children:(0,n.jsx)(s7,{})})}function s7(){var e,t,a,s;let i=(0,l.useSearchParams)(),c=(0,l.useRouter)(),d=(0,o.useRef)(!1),u=(0,o.useRef)(-1),x=(0,o.useRef)(null),h=(0,o.useRef)(null),p=(0,o.useRef)(null),m=(0,o.useRef)(null),{tree:f,loading:v,exists:g,refresh:y,reconnect:b,browseDir:j,setBrowseDir:k,parentDir:w,workspaceRoot:N,openclawDir:C,activeWorkspace:S,showHidden:M,setShowHidden:L}=function(){let[e,t]=(0,o.useState)([]),[r,n]=(0,o.useState)(!0),[l,a]=(0,o.useState)(!1),[s,i]=(0,o.useState)(null),[c,d]=(0,o.useState)(null),[u,x]=(0,o.useState)(null),[h,p]=(0,o.useState)(null),[m,f]=(0,o.useState)(null),[v,g]=(0,o.useState)(!1),y=(0,o.useRef)(!0),b=(0,o.useRef)(1e3),j=(0,o.useRef)(0),[k,w]=(0,o.useState)(0),N=(0,o.useCallback)(async()=>{let e=++j.current;try{let d=v?"?showHidden=1":"",u=await fetch("/api/workspace/tree".concat(d)),h=await u.json();if(y.current&&j.current===e){var r,o,l,s,i,c;t(null!=(r=h.tree)?r:[]),a(null!=(o=h.exists)&&o),x(null!=(l=h.workspaceRoot)?l:null),p(null!=(s=h.openclawDir)?s:null),f(null!=(c=null!=(i=h.workspace)?i:h.profile)?c:null),n(!1)}}catch(t){y.current&&j.current===e&&n(!1)}},[v]),C=(0,o.useCallback)(async e=>{let r=++j.current;try{n(!0);let s=v?"&showHidden=1":"",i=await fetch("/api/workspace/browse?dir=".concat(encodeURIComponent(e)).concat(s)),c=await i.json();if(y.current&&j.current===r){var o,l;t(null!=(o=c.entries)?o:[]),d(null!=(l=c.parentDir)?l:null),a(!0),n(!1)}}catch(e){y.current&&j.current===r&&n(!1)}},[v]),S=(0,o.useRef)(null),M=(0,o.useCallback)(e=>{let t=e;null!=e&&u&&e===u&&(t=null),null!=t&&t!==S.current&&n(!0),S.current=t,i(t)},[u]),L=(0,o.useCallback)(async()=>{s?await C(s):await N()},[s,C,N]),T=(0,o.useCallback)(()=>{L()},[L]),D=(0,o.useCallback)(()=>{w(e=>e+1),L()},[L]);return(0,o.useEffect)(()=>(y.current=!0,L(),()=>{y.current=!1}),[L]),(0,o.useEffect)(()=>{if(s)return;let e=null,t=null,r=null,n=!0,o=null;function l(){!t&&n&&(t=setInterval(()=>{n&&N()},5e3))}return function a(){if(n)try{(e=new EventSource("/api/workspace/watch")).addEventListener("connected",()=>{b.current=1e3,t&&(clearInterval(t),t=null)}),e.addEventListener("change",()=>{o&&clearTimeout(o),o=setTimeout(()=>{n&&N()},300)}),e.addEventListener("error",()=>{null==e||e.close(),e=null,function(){if(!n)return;l();let e=b.current;b.current=Math.min(2*e,3e4),r=setTimeout(()=>{t&&(clearInterval(t),t=null),a()},e)}()})}catch(e){l()}}(),()=>{n=!1,e&&e.close(),t&&clearInterval(t),r&&clearTimeout(r),o&&clearTimeout(o)}},[s,N,k]),{tree:e,loading:r,exists:l,refresh:T,reconnect:D,browseDir:s,setBrowseDir:M,parentDir:c,workspaceRoot:u,openclawDir:h,activeWorkspace:m,showHidden:v,setShowHidden:g}}(),{search:T}=function(e){let[t,r]=(0,o.useState)([]),[n,l]=(0,o.useState)(!0),a=(0,o.useRef)(!0),s=(0,o.useCallback)(async()=>{try{let t=await fetch("/api/workspace/search-index"),n=await t.json();if(a.current){var e;r(null!=(e=n.items)?e:[]),l(!1)}}catch(e){a.current&&l(!1)}},[]);(0,o.useEffect)(()=>(a.current=!0,s(),()=>{a.current=!1}),[s,e]);let i=(0,o.useMemo)(()=>{if(0===t.length)return null;let e=t.map(e=>({...e,fieldValues:e.fields?Object.values(e.fields).join(" "):void 0}));return new a_.A(e,az)},[t]),c=(0,o.useCallback)(function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20;return e.trim()?i?i.search(e,{limit:r}).map(e=>e.item):[]:[...t].toSorted((e,t)=>{var r,n;let o={object:0,file:1,entry:2};return(null!=(r=o[e.kind])?r:9)-(null!=(n=o[t.kind])?n:9)}).slice(0,r)},[i,t]),d=(0,o.useRef)(c);return d.current=c,{items:t,loading:n,search:(0,o.useCallback)((e,t)=>d.current(e,t),[])}}(),[D,E]=(0,o.useState)(null),[R,W]=(0,o.useState)(null),[I,B]=(0,o.useState)({kind:"none"}),[F,P]=(0,o.useState)(!0),[A,_]=(0,o.useState)(null),[z,O]=(0,o.useState)(null),[U,H]=(0,o.useState)(null),[V,J]=(0,o.useState)([]),[K,q]=(0,o.useState)(!0),[G,$]=(0,o.useState)(0),[Z,Y]=(0,o.useState)(new Set),[Q,X]=(0,o.useState)([]),[ee,et]=(0,o.useState)(null),er=(0,o.useCallback)(e=>{X(t=>{let r=t.findIndex(t=>t.childSessionKey===e.childSessionKey);if(r>=0){if(t[r].status===e.status)return t;let n=[...t];return n[r]={...t[r],...e},n}return[...t,e]})},[]),en=(0,o.useCallback)(e=>{et(e)},[]),eo=(0,o.useCallback)(()=>{et(null)},[]),ea=(0,o.useCallback)(e=>{let t=Q.find(t=>t.childSessionKey===e);if(t)return void et(t.childSessionKey);let r=Q.find(t=>t.task===e);r&&et(r.childSessionKey)},[Q]),es=(0,o.useMemo)(()=>{var e;return ee&&null!=(e=Q.find(e=>e.childSessionKey===ee))?e:null},[ee,Q]),[ei,ec]=(0,o.useState)([]),[ed,eu]=(0,o.useState)("overview"),[ex,eh]=(0,o.useState)("month"),[ep,em]=(0,o.useState)(null),[ef,ev]=(0,o.useState)("all"),[eg,ey]=(0,o.useState)(null),[ej,ek]=(0,o.useState)(null),ew=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:768,[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia("(max-width: ".concat(e-1,"px)")),n=()=>r(t.matches);return n(),t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[e]),t}(),[eN,eC]=(0,o.useState)(!1),[eS,eM]=(0,o.useState)(!1),[eL,eT]=(0,o.useState)(!1),[eD,eE]=(0,o.useState)(!1),[eR,eW]=(0,o.useState)(!1),[eI,eB]=(0,o.useState)({tabs:[sI],activeTabId:sW}),eF=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=S||null;eF.current!==e&&(eF.current=e,eB(function(e){try{let t=localStorage.getItem(sB(e));if(!t)return{tabs:[sI],activeTabId:sW};let r=JSON.parse(t);if(!Array.isArray(r.tabs))return{tabs:[sI],activeTabId:sW};if(r.tabs.some(e=>e.id===sW)){let e=r.tabs.find(e=>e.id===sW),t=r.tabs.filter(e=>e.id!==sW);return{...r,tabs:[e,...t]}}return{tabs:[sI,...r.tabs],activeTabId:r.activeTabId||sW}}catch(e){return{tabs:[sI],activeTabId:sW}}}(e)))},[S]),(0,o.useEffect)(()=>{let e=S||null;if(eF.current===e)try{let t={tabs:eI.tabs.map(e=>{let{id:t,type:r,title:n,icon:o,path:l,sessionId:a,pinned:s}=e;return{id:t,type:r,title:n,icon:o,path:l,sessionId:a,pinned:s}}),activeTabId:eI.activeTabId};localStorage.setItem(sB(e),JSON.stringify(t))}catch(e){}},[eI,S]);let eP=(0,o.useRef)(null),eA=(0,o.useCallback)(e=>{var t,r,n;let o={id:Math.random().toString(36).slice(2,10),type:"object"===e.type?"object":(t=e.path).includes(".dench.app")?"app":t.startsWith("~cron")?"cron":"file",title:(r=e.path,(n=e.name)?n:r.split("/").pop()||r),path:e.path};eB(e=>(function(e,t){var r,n,o,l;let a=t.path?(r=e.tabs,n=t.path,r.find(e=>e.path===n)):t.sessionId?(o=e.tabs,l=t.sessionId,o.find(e=>"chat"===e.type&&e.sessionId===l)):void 0;return a?{...e,activeTabId:a.id}:{tabs:[...e.tabs,t],activeTabId:t.id}})(e,o))},[]),[e_,ez]=(0,o.useState)(260),[eO,eU]=(0,o.useState)(320);(0,o.useEffect)(()=>{let e=window.localStorage.getItem(s0),t=e?parseInt(e,10):NaN;Number.isFinite(t)&&ez(s2(t,200,480));let r=window.localStorage.getItem(s1),n=r?parseInt(r,10):NaN;Number.isFinite(n)&&eU(s2(n,260,900))},[]),(0,o.useEffect)(()=>{window.localStorage.setItem(s0,String(e_))},[e_]),(0,o.useEffect)(()=>{window.localStorage.setItem(s1,String(eO))},[eO]),(0,o.useEffect)(()=>{let e=e=>{let t=e.metaKey||e.ctrlKey,r=e.key.toLowerCase();if(t&&"b"===r){e.preventDefault(),e.shiftKey?eE(e=>!e):eT(e=>!e);return}if(t&&"j"===r&&!e.shiftKey&&!e.altKey){e.preventDefault(),eW(e=>!e);return}if(t&&"w"===r&&!e.shiftKey&&!e.altKey){var n;e.preventDefault(),null==(n=eP.current)||n.call(eP);return}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let eH=(0,o.useMemo)(()=>{if(!R||s$(R))return;let e=R.split("/").pop()||R;return{path:R,filename:e,isDirectory:"directory"===I.kind}},[R,I.kind]);(0,o.useEffect)(()=>{R||H(null)},[R]);let eV=(0,o.useCallback)(e=>{B(t=>"document"===t.kind||"file"===t.kind||"code"===t.kind?{...t,data:{...t.data,content:e}}:t)},[]),eJ=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/workspace/context"),t=await e.json();E(t)}catch(e){}},[]);(0,o.useEffect)(()=>{eJ()},[eJ]);let eK=(0,o.useCallback)(async()=>{q(!0);try{var e;let t=await fetch("/api/web-sessions"),r=await t.json();J(null!=(e=r.sessions)?e:[])}catch(e){}finally{q(!1)}},[]);(0,o.useEffect)(()=>{eK()},[eK,G]);let eq=(0,o.useCallback)(()=>{$(e=>e+1)},[]),eG=(0,o.useCallback)(()=>{var e;(e={setBrowseDir:k,setActivePath:W,setContent:B,setChatSidebarPreview:_,setShowChatSidebar:P,setActiveSessionId:O,setActiveSubagentKey:et,resetMainChat:()=>{var e;null==(e=h.current)||e.newSession()},replaceUrlToRoot:()=>{},reconnectWorkspaceWatcher:b,refreshSessions:eq,refreshContext:()=>{eJ()}}).setBrowseDir(null),e.setActivePath(null),e.setContent({kind:"none"}),e.setChatSidebarPreview(null),e.setShowChatSidebar(!0),e.setActiveSessionId(null),e.setActiveSubagentKey(null),e.resetMainChat(),e.replaceUrlToRoot(),e.reconnectWorkspaceWatcher(),e.refreshSessions(),e.refreshContext()},[b,eJ,eq,c,k]),e$=(0,o.useCallback)(async e=>{if((await fetch("/api/web-sessions/".concat(e),{method:"DELETE"})).ok){if(z===e){var t,r;O(null),et(null);let n=V.filter(t=>t.id!==e);if(n.length>0){let e=n[0];O(e.id),null==(t=h.current)||t.loadSession(e.id)}else null==(r=h.current)||r.newSession()}eK()}},[z,V,eK]),eZ=(0,o.useCallback)(async(e,t)=>{await fetch("/api/web-sessions/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:t})}),eK()},[eK]);(0,o.useEffect)(()=>{let e=!1,t=async()=>{try{var t;let r=await fetch("/api/chat/active");if(e)return;let n=null!=(t=(await r.json()).sessionIds)?t:[];Y(e=>e.size===n.length&&n.every(t=>e.has(t))?e:new Set(n))}catch(e){}};t();let r=setInterval(t,3e3);return()=>{e=!0,clearInterval(r)}},[]);let eY=(0,o.useCallback)(async()=>{try{var e;let t=await fetch("/api/cron/jobs"),r=await t.json();ec(null!=(e=r.jobs)?e:[])}catch(e){}},[]);(0,o.useEffect)(()=>{eY();let e=setInterval(eY,3e4);return()=>clearInterval(e)},[eY]);let eQ=(0,o.useCallback)(async e=>{W(e.path),B({kind:"loading"});try{if("object"===e.type){let t=s6(e.path),r=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t)));if(!r.ok){let e=await r.json().catch(()=>({}));if("DUCKDB_NOT_INSTALLED"===e.code)return void B({kind:"duckdb-missing"});B({kind:"none"});return}let n=await r.json();B({kind:"object",data:n})}else if("document"===e.type){let t=await fetch(sQ(e.path));if(!t.ok)return void B({kind:"none"});let r=await t.json();B({kind:"document",data:r,title:e.name.replace(/\.md$/,"")})}else if("database"===e.type)B({kind:"database",dbPath:e.path,filename:e.name});else if("report"===e.type)B({kind:"report",reportPath:e.path,filename:e.name});else if("file"===e.type){var t,n;if(rJ(e.name)){let t=sX(e.path);B({kind:"spreadsheet",url:t,filename:e.name,filePath:e.path});return}if(ol(e.name)){try{let t=await fetch(sX(e.path));if(!t.ok)return void B({kind:"none"});let n=await t.arrayBuffer(),o=await Promise.all([r.e(5360),r.e(4995)]).then(r.t.bind(r,14995,19)),l=await o.convertToHtml({arrayBuffer:n});B({kind:"richDocument",html:l.value,filePath:e.path,mode:"docx"})}catch(e){B({kind:"none"})}return}if(oa(e.name)){let t=await fetch(sQ(e.path));if(!t.ok)return void B({kind:"none"});let r=await t.json();B({kind:"richDocument",html:os(r.content),filePath:e.path,mode:"txt"});return}let o=null!=(n=null==(t=e.name.split(".").pop())?void 0:t.toLowerCase())?n:"";if("html"===o||"htm"===o)return void B({kind:"html",rawUrl:sX(e.path),contentUrl:sQ(e.path),filename:e.name});let l=nj(e.name);if(l){let t=sX(e.path);B({kind:"media",url:t,mediaType:l,filename:e.name,filePath:e.path});return}let a=await fetch(sQ(e.path));if(!a.ok)return void B({kind:"none"});let s=await a.json();aU(e.name)?B({kind:"code",data:s,filename:e.name,filePath:e.path}):B({kind:"file",data:s,filename:e.name})}else if("app"===e.type){let t=await fetch("/api/apps?app=".concat(encodeURIComponent(e.path),"&file=.dench.yaml&meta=1")),r={name:e.name};if(t.ok)try{r=await t.json()}catch(e){}B({kind:"app",appPath:e.path,manifest:r,filename:e.name})}else"folder"===e.type&&B({kind:"directory",node:e})}catch(e){B({kind:"none"})}},[]),eX=(0,o.useCallback)(e=>{var t,r,n;if(j&&sZ(e.path)){if(N&&e.path===N)return void k(null);if(C){if(e.path===C+"/cron"){k(null),W("~cron"),B({kind:"cron-dashboard"});return}if(C&&e.path.startsWith(C+"/web-chat")){k(null),W(null),B({kind:"none"}),null==(t=h.current)||t.newSession();return}}if("folder"===e.type){k(e.path),W(e.path),B({kind:"directory",node:{name:e.name,path:e.path,type:"folder"}});return}}if(e.path.startsWith("~chats/")){let t=e.path.slice(7);W(null),B({kind:"none"}),O(t),null==(r=h.current)||r.loadSession(t);return}if("~chats"===e.path){W(null),B({kind:"none"}),null==(n=h.current)||n.newSession();return}if(e.path.startsWith("~cron/")){let t=e.path.slice(6),r=ei.find(e=>e.id===t);if(r){W(e.path),B({kind:"cron-job",jobId:t,job:r});return}}if("~cron"===e.path){W(e.path),B({kind:"cron-dashboard"});return}eA(e),eQ(e)},[eQ,eA,ei,j,N,C,k]),e0=(0,o.useCallback)(e=>{if(e===sW){W(null),B({kind:"none"}),eB(t=>sF(t,e));return}eB(t=>{let r=sF(t,e),n=r.tabs.find(t=>t.id===e);if(null==n?void 0:n.path){let e=s3(f,n.path);if(e)eQ(e);else if("~cron"===n.path)W("~cron"),B({kind:"cron-dashboard"});else if(n.path.startsWith("~cron/")){W(n.path);let e=n.path.slice(6),t=ei.find(t=>t.id===e);t&&B({kind:"cron-job",jobId:e,job:t})}}return r})},[f,eQ,ei]),e1=(0,o.useCallback)(e=>{eB(t=>{let r=function(e,t){if(t===sW)return e;let r=e.tabs.findIndex(e=>e.id===t);if(-1===r||e.tabs[r].pinned)return e;let n=e.tabs.filter(e=>e.id!==t),o=e.activeTabId;return e.activeTabId===t&&(o=0===n.length?null:r<n.length?n[r].id:n[n.length-1].id),{tabs:n,activeTabId:o}}(t,e);if(r.activeTabId!==t.activeTabId)if(r.activeTabId!==sW&&r.activeTabId){let e=r.tabs.find(e=>e.id===r.activeTabId);if(null==e?void 0:e.path){let t=s3(f,e.path);t&&eQ(t)}}else W(null),B({kind:"none"});return r})},[f,eQ]);(0,o.useEffect)(()=>{eP.current=()=>{eI.activeTabId&&e1(eI.activeTabId)}},[eI.activeTabId,e1]);let e2=(0,o.useCallback)(e=>{eB(t=>({tabs:t.tabs.filter(t=>t.id===e||t.pinned),activeTabId:e}))},[]),e4=(0,o.useCallback)(e=>{eB(t=>(function(e,t){let r=e.tabs.findIndex(e=>e.id===t);if(-1===r)return e;let n=e.tabs.filter((e,t)=>t<=r||e.pinned),o=n.some(t=>t.id===e.activeTabId);return{tabs:n,activeTabId:o?e.activeTabId:t}})(t,e))},[]),e5=(0,o.useCallback)(()=>{eB(e=>{let t=function(e){let t=e.tabs.filter(e=>e.pinned),r=t.some(t=>t.id===e.activeTabId);return{tabs:t,activeTabId:r?e.activeTabId:sW}}(e);return W(null),B({kind:"none"}),t})},[]),e6=(0,o.useCallback)((e,t)=>{eB(r=>(function(e,t,r){var n;if(t===r||(null==(n=e.tabs[t])?void 0:n.id)===sW)return e;let o=Math.max(1,r),l=[...e.tabs],[a]=l.splice(t,1);return l.splice(o,0,a),{...e,tabs:l}})(r,e,t))},[]),e3=(0,o.useCallback)(e=>{eB(t=>({...t,tabs:t.tabs.map(t=>t.id===e?{...t,pinned:!t.pinned}:t)}))},[]),e8=(0,o.useCallback)(async e=>{if("folder"===e.type)return{kind:"directory",path:e.path,name:e.name};if("database"===e.type)return{kind:"database",dbPath:e.path,filename:e.name};let t=nj(e.name);if(t)return{kind:"media",url:sX(e.path),mediaType:t,filename:e.name,filePath:e.path};if(rJ(e.name))return{kind:"spreadsheet",url:sX(e.path),filename:e.name,filePath:e.path};if(ol(e.name))try{let t=await fetch(sX(e.path));if(!t.ok)return null;let n=await t.arrayBuffer(),o=await Promise.all([r.e(5360),r.e(4995)]).then(r.t.bind(r,14995,19)),l=await o.convertToHtml({arrayBuffer:n});return{kind:"richDocument",html:l.value,filePath:e.path,mode:"docx"}}catch(e){return null}if(oa(e.name)){let t=await fetch(sQ(e.path));return t.ok?{kind:"richDocument",html:os((await t.json()).content),filePath:e.path,mode:"txt"}:null}let n=await fetch(sQ(e.path));if(!n.ok)return null;let o=await n.json();return"document"===e.type||"markdown"===o.type?{kind:"document",data:o,title:e.name.replace(/\.mdx?$/,"")}:aU(e.name)?{kind:"code",data:o,filename:e.name,filePath:e.path}:{kind:"file",data:o,filename:e.name}},[]),e7=(0,o.useCallback)(async e=>{let t=function(e){let t=e.trim();if(!t.startsWith("file://"))return t;try{let e=new URL(t);if("file:"!==e.protocol)return t;let r=decodeURIComponent(e.pathname);if(/^\/[A-Za-z]:\//.test(r))return r.slice(1);return r}catch(e){return t}}(e);if(!t)return!1;let r=!ew,n=async e=>{if(!r)return eX(e),P(!0),!0;(R||"none"!==I.kind)&&(W(null),B({kind:"none"})),_({status:"loading",path:e.path,filename:e.name});let t=await e8(e);return t?(_({status:"ready",path:e.path,filename:e.name,content:t}),!0):(_({status:"error",path:e.path,filename:e.name,message:"Could not preview this file."}),!1)};if(!sZ(t)&&!sY(t)&&!t.startsWith("./")&&!t.startsWith("../")){let e=s3(f,t);if(e)return await n(e)}try{let e=await fetch("/api/workspace/path-info?path=".concat(encodeURIComponent(t)));if(!e.ok)return!1;let o=await e.json();if(!o.path||!o.name||!o.type)return!1;if(N&&(o.path===N||o.path.startsWith("".concat(N,"/")))){let e=o.path===N?"":o.path.slice(N.length+1);if(e){let t=s3(f,e);if(t)return await n(t)}}if("directory"===o.type){let e={name:o.name,path:o.path,type:"folder"};if(r)return await n(e);return k(o.path),W(o.path),B({kind:"directory",node:{name:o.name,path:o.path,type:"folder"}}),P(!0),!0}if("file"===o.type){let e={name:o.name,path:o.path,type:function(e){var t,r;if(e.endsWith(".dench.app"))return"app";let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return"md"===n||"mdx"===n?"document":"duckdb"===n||"sqlite"===n||"sqlite3"===n||"db"===n?"database":"file"}(o.name)};if(r)return await n(e);let t=o.path.split("/").slice(0,-1).join("/")||"/";return sZ(o.path)&&k(t),await eQ(e),P(!0),!0}}catch(e){}return!1},[R,I.kind,ew,f,eX,N,e8,k,eQ,c]),e9=(0,o.useMemo)(()=>{if(j)return f;let e=ei.map(e=>({name:"".concat(!e.enabled?"○":e.state.runningAtMs?"●":"error"===e.state.lastStatus?"◆":"ok"===e.state.lastStatus?"✓":"○"," ").concat(e.name),path:"~cron/".concat(e.id),type:"file",virtual:!0}));return[...f,{name:"Cron",path:"~cron",type:"folder",virtual:!0,children:e.length>0?e:void 0}]},[f,ei,j]),te=(0,o.useMemo)(()=>j?w:N?"/"===N?null:N.split("/").slice(0,-1).join("/")||"/":null,[j,w,N]),tt=(0,o.useCallback)(()=>{null!=te&&k(te)},[te,k]),tr=(0,o.useCallback)(()=>{k(null)},[k]),tn=(0,o.useCallback)(()=>{W(null),B({kind:"none"}),eB(e=>sF(e,sW))},[]),to=(0,o.useCallback)(e=>{var t,r;let n=null!=(r=h.current)?r:p.current;null==n||null==(t=n.insertFileMention)||t.call(n,e.name,e.path)},[]),tl=(0,o.useCallback)(e=>{"folder"===e.type?(k(e.path),W(e.path),B({kind:"directory",node:{name:e.name,path:e.path,type:"folder"}})):(k(e.path.split("/").slice(0,-1).join("/")||"/"),eQ({name:e.name,path:e.path,type:e.type}))},[k,eQ]);(0,o.useEffect)(()=>{var e;if(!d.current)return;if(0===u.current){u.current=1;return}let t=new URLSearchParams(window.location.search),r=(0,eb.ZC)({activePath:R,activeSessionId:z,activeSubagentKey:ee,fileChatSessionId:U,browseDir:j,showHidden:M,previewPath:null!=(e=null==A?void 0:A.path)?e:null,terminalOpen:eR,cronView:ed,cronCalMode:ex,cronDate:ep,cronRunFilter:ef,cronRun:eg},t).toString();r!==t.toString()&&(x.current=r,c.push(r?"/?".concat(r):"/",{scroll:!1}))},[R,z,ee,U,j,M,A,c,ed,ex,ep,ef,eg]),(0,o.useEffect)(()=>{let e=new URLSearchParams(window.location.search);if("1"===e.get("terminal")===eR)return;eR?e.set("terminal","1"):e.delete("terminal");let t=e.toString();window.history.replaceState(window.history.state,"",t?"/?".concat(t):"/")},[eR]);let ta=(0,o.useCallback)((e,t)=>{ek({objectName:e,entryId:t});let r=new URLSearchParams(i.toString());r.set("entry","".concat(e,":").concat(t)),c.push("/?".concat(r.toString()),{scroll:!1})},[i,c]),ts=(0,o.useCallback)(()=>{ek(null);let e=new URLSearchParams(i.toString());e.delete("entry");let t=e.toString();c.replace(t?"/?".concat(t):"/",{scroll:!1})},[i,c]);(0,o.useEffect)(()=>{if(d.current||v||0===f.length)return;u.current=0;let e=(0,eb.yh)(i);if(e.path){d.current=!0;let t=s3(f,e.path);if(t)eA(t),eQ(t);else if("~cron"===e.path)eA({path:"~cron",name:"Cron",type:"folder"}),W("~cron"),B({kind:"cron-dashboard"}),e.cronView&&eu(e.cronView),e.cronCalMode&&eh(e.cronCalMode),e.cronDate&&em(e.cronDate);else if(e.path.startsWith("~cron/"))eA({path:e.path,name:e.path.split("/").pop()||"Cron Job",type:"file"}),W(e.path),B({kind:"cron-dashboard"}),e.cronRunFilter&&ev(e.cronRunFilter),null!=e.cronRun&&ey(e.cronRun);else if(sZ(e.path)||sY(e.path)){let t={name:e.path.split("/").pop()||e.path,path:e.path,type:"file"};eA(t),eQ(t)}e.fileChat&&H(e.fileChat)}else if(e.chat){var t;d.current=!0,O(e.chat),W(null),B({kind:"none"}),null==(t=h.current)||t.loadSession(e.chat),e.subagent&&et(e.subagent)}else d.current=!0;if(e.entry&&ek(e.entry),e.browse&&k(e.browse),e.hidden&&L(!0),e.preview){let t=e.preview,r=t.split("/").pop()||t;_({status:"loading",path:t,filename:r}),e8({name:r,path:t,type:"file"}).then(e=>{e?_({status:"ready",path:t,filename:r,content:e}):_({status:"error",path:t,filename:r,message:"Could not load preview"})})}e.terminal&&eW(!0)},[f,v,i,eQ,k,L,e8]),(0,o.useEffect)(()=>{let e=()=>{let e=window.location.search.replace(/^\?/,"");if(e===x.current)return;let t=(0,eb.yh)(window.location.search);if(t.path){let e=s3(f,t.path);if(e)eA(e),eQ(e);else if("~cron"===t.path)eA({path:"~cron",name:"Cron",type:"folder"}),W("~cron"),B({kind:"cron-dashboard"});else if(t.path.startsWith("~cron/")){eA({path:t.path,name:t.path.split("/").pop()||"Cron Job",type:"file"}),W(t.path);let e=t.path.slice(6),r=ei.find(t=>t.id===e);r?B({kind:"cron-job",jobId:e,job:r}):B({kind:"cron-dashboard"})}else if(sZ(t.path)||sY(t.path)){let e={name:t.path.split("/").pop()||t.path,path:t.path,type:"file"};eA(e),eQ(e)}H(t.fileChat)}else if(t.chat){var r;O(t.chat),W(null),B({kind:"none"}),null==(r=h.current)||r.loadSession(t.chat),et(t.subagent),eB(e=>sF(e,sW))}else W(null),B({kind:"none"}),O(null),et(null),eB(e=>sF(e,sW));if(t.entry?ek(t.entry):ek(null),t.browse?k(t.browse):t.path&&sZ(t.path)||k(null),t.hidden?L(!0):L(!1),_(null),t.preview){let e=t.preview.split("/").pop()||t.preview;_({status:"loading",path:t.preview,filename:e}),e8({name:e,path:t.preview,type:"file"}).then(r=>{r?_({status:"ready",path:t.preview,filename:e,content:r}):_({status:"error",path:t.preview,filename:e,message:"Could not load preview"})})}eW(t.terminal),x.current=e};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[f,ei,eQ,k,L,e8]),(0,o.useEffect)(()=>{if(!(null==R?void 0:R.startsWith("~cron/"))||0===ei.length||"cron-job"===I.kind)return;let e=R.slice(6),t=ei.find(t=>t.id===e);t&&B({kind:"cron-job",jobId:e,job:t})},[R,ei,I.kind]),(0,o.useEffect)(()=>{let e=i.get("send");if(!e)return;let t=new URLSearchParams(window.location.search);t.delete("send");let r=t.toString();c.replace(r?"/?".concat(r):"/",{scroll:!1}),W(null),B({kind:"none"}),requestAnimationFrame(()=>{var t;null==(t=h.current)||t.sendNewMessage(e)})},[i,c]);let ti=(0,o.useCallback)(e=>{if(!e){W(null),B({kind:"none"});return}if(sZ(e)){let t=e.split("/").pop()||e;k(e),W(e),B({kind:"directory",node:{name:t,path:e,type:"folder"}});return}let t=s3(f,e);t&&eX(t)},[f,eX,k]),tc=(0,o.useCallback)(e=>{let t=function t(r){for(let n of r){if("object"===n.type&&s6(n.path)===e)return n;if(n.children){let e=t(n.children);if(e)return e}}return null}(f);t&&eQ(t)},[f,eQ]),td=(0,o.useCallback)(e=>{let t=(0,eb.lc)(e);if(t){if("entry"===t.kind)return void ta(t.objectName,t.entryId);let e=s3(f,t.path);if(e)return void eX(e)}let r=s3(f,e);r&&eX(r)},[f,eX,ta]),tu=(0,o.useCallback)(async()=>{if("object"!==I.kind)return;let e=I.data.object.name;try{let t=await fetch("/api/workspace/objects/".concat(encodeURIComponent(e)));if(!t.ok)return;let r=await t.json();B({kind:"object",data:r})}catch(e){}},[I]),tx=(0,o.useRef)(f);(0,o.useEffect)(()=>{tx.current!==f&&(tx.current=f,"object"===I.kind&&tu())},[f,I.kind,tu]);let th=(0,o.useCallback)(e=>{let t=e.target.closest("a");if(!t)return;let r=t.getAttribute("href");r&&(0,eb.m9)(r)&&(e.preventDefault(),e.stopPropagation(),td(r))},[td]),tp=(0,o.useCallback)(e=>{let t=ei.find(t=>t.id===e);t&&(W("~cron/".concat(e)),B({kind:"cron-job",jobId:e,job:t}))},[ei]),tm=(0,o.useCallback)(()=>{W("~cron"),B({kind:"cron-dashboard"}),ev("all"),ey(null)},[]),tf=(0,o.useCallback)(e=>{W(null),B({kind:"none"}),requestAnimationFrame(()=>{var t;null==(t=h.current)||t.sendNewMessage(e)})},[]),tv=(0,o.useMemo)(()=>{if(!z)return;let e=V.find(e=>e.id===z);return(null==e?void 0:e.title)||void 0},[z,V]),tg=!R||"none"===I.kind;return(0,n.jsxs)("div",{ref:m,className:"flex h-screen",style:{background:"var(--color-main-bg)"},onClick:th,children:[ew?eN&&(0,n.jsx)(el,{tree:e9,activePath:R,onSelect:e=>{eX(e),eC(!1)},onRefresh:y,orgName:null==D||null==(e=D.organization)?void 0:e.name,loading:v,browseDir:j,parentDir:te,onNavigateUp:tt,onGoHome:tr,onFileSearchSelect:e=>{null==tl||tl(e),eC(!1)},workspaceRoot:N,onGoToChat:()=>{tn(),eC(!1)},onExternalDrop:to,showHidden:M,onToggleHidden:()=>L(e=>!e),activeWorkspace:S,onWorkspaceChanged:eG,mobile:!0,onClose:()=>eC(!1)}):(0,n.jsx)(n.Fragment,{children:!eL&&(0,n.jsxs)("div",{className:"flex shrink-0 flex-col relative",style:{width:e_,minWidth:e_},children:[(0,n.jsx)(s4,{mode:"left",containerRef:m,min:200,max:480,onResize:ez}),(0,n.jsx)(el,{tree:e9,activePath:R,onSelect:eX,onRefresh:y,orgName:null==D||null==(t=D.organization)?void 0:t.name,loading:v,browseDir:j,parentDir:te,onNavigateUp:tt,onGoHome:tr,onFileSearchSelect:tl,workspaceRoot:N,onGoToChat:tn,onExternalDrop:to,showHidden:M,onToggleHidden:()=>L(e=>!e),width:e_,onCollapse:()=>eT(!0),activeWorkspace:S,onWorkspaceChanged:eG})]})}),!ew&&eL&&(0,n.jsx)("div",{className:"shrink-0 flex flex-col items-center pt-2.5 px-1.5",children:(0,n.jsx)("button",{type:"button",onClick:()=>eT(!1),className:"p-1.5 rounded-md transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Show sidebar (⌘B)",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M9 3v18"})]})})}),(0,n.jsxs)("main",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",style:{background:"var(--color-main-bg)"},children:[ew&&(0,n.jsxs)("div",{className:"px-3 py-2 border-b flex-shrink-0 flex items-center justify-between gap-2",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>eC(!0),className:"p-2 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Open sidebar",children:(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"4",x2:"20",y1:"12",y2:"12"}),(0,n.jsx)("line",{x1:"4",x2:"20",y1:"6",y2:"6"}),(0,n.jsx)("line",{x1:"4",x2:"20",y1:"18",y2:"18"})]})}),(0,n.jsx)("div",{className:"flex-1 min-w-0 text-sm font-medium truncate",style:{color:"var(--color-text)"},children:R?R.split("/").pop():(null==D||null==(a=D.organization)?void 0:a.name)||"Workspace"}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[R&&"none"!==I.kind&&(0,n.jsx)("button",{type:"button",onClick:()=>{W(null),B({kind:"none"})},className:"p-2 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Back to chat",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]})}),tg&&(0,n.jsx)("button",{type:"button",onClick:()=>eM(!0),className:"p-2 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Chat sessions",children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})]})]}),!ew&&(0,n.jsx)(sP,{tabs:eI.tabs,activeTabId:eI.activeTabId,onActivate:e0,onClose:e1,onCloseOthers:e2,onCloseToRight:e4,onCloseAll:e5,onReorder:e6,onTogglePin:e3}),!ew&&R&&"none"!==I.kind&&(0,n.jsxs)("div",{className:"px-6 border-b flex-shrink-0 flex items-center justify-between",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)(oW,{path:R,onNavigate:ti}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{W(null),B({kind:"none"})},className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Back to chat",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]})}),eH&&(0,n.jsx)("button",{type:"button",onClick:()=>P(e=>!e),className:"p-1.5 rounded-lg flex-shrink-0",style:{color:F?"var(--color-accent)":"var(--color-text-muted)",background:F?"var(--color-accent-light)":"transparent"},title:F?"Hide chat":eH.isDirectory?"Chat about this folder":"Chat about this file",children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 flex min-h-0",children:tg?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0",style:{background:"var(--color-main-bg)"},children:(0,n.jsx)(aC,{ref:es?void 0:h,sessionTitle:tv,initialSessionId:null!=z?z:void 0,onActiveSessionChange:es?void 0:e=>{O(e),et(null)},onSessionsChange:es?void 0:eq,onSubagentSpawned:es?void 0:er,onSubagentClick:ea,onFilePathClick:e7,onDeleteSession:es?void 0:e$,onRenameSession:es?void 0:eZ,compact:ew,sessionKey:null==es?void 0:es.childSessionKey,subagentTask:null==es?void 0:es.task,subagentLabel:null==es?void 0:es.label,onBack:es?eo:void 0},null!=(s=null==es?void 0:es.childSessionKey)?s:"main")}),ew?eS&&(0,n.jsx)(oY,{sessions:V,activeSessionId:z,activeSessionTitle:tv,streamingSessionIds:Z,subagents:Q,activeSubagentKey:ee,loading:K,onSelectSession:e=>{var t;O(e),et(null),null==(t=h.current)||t.loadSession(e)},onNewSession:()=>{var e;O(null),et(null),null==(e=h.current)||e.newSession(),eM(!1)},onSelectSubagent:en,onDeleteSession:e$,onRenameSession:eZ,mobile:!0,onClose:()=>eM(!1)}):(0,n.jsxs)(n.Fragment,{children:[!eD&&(0,n.jsxs)("div",{className:"flex shrink-0 flex-col relative",style:{width:eO,minWidth:eO,background:"var(--color-sidebar-bg)"},children:[(0,n.jsx)(s4,{mode:"right",containerRef:m,min:260,max:900,onResize:eU}),A?(0,n.jsx)(s9,{preview:A,onClose:()=>_(null)}):(0,n.jsx)(oY,{sessions:V,activeSessionId:z,activeSessionTitle:tv,streamingSessionIds:Z,subagents:Q,activeSubagentKey:ee,loading:K,onSelectSession:e=>{var t;O(e),et(null),null==(t=h.current)||t.loadSession(e)},onNewSession:()=>{var e;O(null),et(null),null==(e=h.current)||e.newSession()},onSelectSubagent:en,onDeleteSession:e$,onRenameSession:eZ,onCollapse:()=>eE(!0),width:eO})]}),eD&&(0,n.jsx)("div",{className:"shrink-0 flex flex-col items-center pt-2.5 px-1.5",children:(0,n.jsx)("button",{type:"button",onClick:()=>eE(!1),className:"p-1.5 rounded-md transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Show chat sidebar (⌘⇧B)",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M15 3v18"})]})})})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,n.jsx)(ie,{content:I,workspaceExists:g,expectedPath:N,tree:f,activePath:R,browseDir:j,treeLoading:v,members:null==D?void 0:D.members,onNodeSelect:eX,onNavigateToObject:tc,onRefreshObject:tu,onRefreshTree:y,onNavigate:td,onOpenEntry:ta,searchFn:T,onSelectCronJob:tp,onBackToCronDashboard:tm,cronView:ed,onCronViewChange:eu,cronCalMode:ex,onCronCalModeChange:eh,cronDate:ep,onCronDateChange:em,cronRunFilter:ef,onCronRunFilterChange:ev,cronRun:eg,onCronRunChange:ey,onSendCommand:tf})}),!ew&&eH&&F&&!eD&&(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("aside",{className:"flex-shrink-0 border-l flex flex-col relative",style:{width:eO,borderColor:"var(--color-border)",background:"var(--color-bg)"},children:[(0,n.jsx)(s4,{mode:"right",containerRef:m,min:260,max:900,onResize:eU}),(0,n.jsx)(aC,{ref:p,compact:!0,fileContext:eH,initialSessionId:null!=U?U:void 0,onFileChanged:eV,onFilePathClick:e7,onActiveSessionChange:H})]})})]})}),eR&&(0,n.jsx)(sG,{onClose:()=>eW(!1),cwd:null!=N?N:void 0})]}),ej&&(0,n.jsx)(aA,{objectName:ej.objectName,entryId:ej.entryId,members:null==D?void 0:D.members,onClose:ts,onNavigateEntry:(e,t)=>ta(e,t),onNavigateObject:e=>{ts(),tc(e)},onRefresh:tu})]})}function s9(e){let t,{preview:r,onClose:l}=e,a=function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return"pdf"===n?{label:"PDF",color:"#ef4444"}:["jpg","jpeg","png","gif","webp","svg","bmp","heic","avif"].includes(n)?{label:"Image",color:"#3b82f6"}:["mp4","webm","mov","avi","mkv"].includes(n)?{label:"Video",color:"#8b5cf6"}:["mp3","wav","ogg","m4a","aac","flac"].includes(n)?{label:"Audio",color:"#f59e0b"}:["md","mdx"].includes(n)?{label:"Markdown",color:"#10b981"}:["ts","tsx","js","jsx","py","go","rs","java","rb","swift","kt","c","cpp","h"].includes(n)?{label:n.toUpperCase(),color:"#3b82f6"}:["json","yaml","yml","toml","xml","csv"].includes(n)?{label:n.toUpperCase(),color:"#6b7280"}:["duckdb","sqlite","sqlite3","db"].includes(n)?{label:"Database",color:"#6366f1"}:{label:n.toUpperCase()||"File",color:"#6b7280"}}(r.filename),s=(0,o.useCallback)(async()=>{try{await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r.path,reveal:!0})})}catch(e){}},[r.path]),i=(0,o.useCallback)(async()=>{try{await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r.path})})}catch(e){}},[r.path]),c="ready"===r.status&&"media"===r.content.kind?r.content.url:null;if("loading"===r.status)t=(0,n.jsxs)("div",{className:"flex flex-col h-full items-center justify-center gap-3",children:[(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading preview..."})]});else if("error"===r.status)t=(0,n.jsxs)("div",{className:"flex flex-col h-full items-center justify-center gap-4 px-6",children:[(0,n.jsx)("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center",style:{background:"color-mix(in srgb, var(--color-error) 10%, transparent)"},children:(0,n.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",x2:"9",y1:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",x2:"15",y1:"9",y2:"15"})]})}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"Preview unavailable"}),(0,n.jsx)("p",{className:"text-xs mt-1",style:{color:"var(--color-text-muted)"},children:r.message})]})]});else{let e=r.content;switch(e.kind){case"media":if("pdf"===e.mediaType){let r=e.url+(e.url.includes("#")?"&":"#")+"toolbar=0&navpanes=0&scrollbar=1";t=(0,n.jsx)("iframe",{src:r,className:"w-full h-full",style:{border:"none",colorScheme:"light"},title:"Preview: ".concat(e.filename)})}else"image"===e.mediaType?t=(0,n.jsx)("div",{className:"flex items-center justify-center h-full p-4 overflow-auto",style:{background:"var(--color-bg)"},children:(0,n.jsx)("img",{src:e.url,alt:e.filename,className:"max-w-full max-h-full object-contain rounded-lg",style:{boxShadow:"0 2px 16px rgba(0,0,0,0.08)"},draggable:!1})}):"video"===e.mediaType?t=(0,n.jsx)("div",{className:"flex items-center justify-center h-full p-4",style:{background:"#000"},children:(0,n.jsx)("video",{src:e.url,controls:!0,className:"max-w-full max-h-full rounded-lg"})}):"audio"===e.mediaType&&(t=(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-6 px-6",children:[(0,n.jsx)("div",{className:"w-20 h-20 rounded-2xl flex items-center justify-center",style:{background:"linear-gradient(135deg, #f59e0b20, #f59e0b08)"},children:(0,n.jsxs)("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"16",r:"3"})]})}),(0,n.jsx)("audio",{src:e.url,controls:!0,className:"w-full"})]}));break;case"document":t=(0,n.jsx)("div",{className:"p-5 overflow-auto h-full",children:(0,n.jsx)("div",{className:"workspace-prose text-sm",children:(0,n.jsx)(rU,{content:e.data.content,title:e.title})})});break;case"code":t=(0,n.jsx)("div",{className:"h-full",children:(0,n.jsx)(nm,{content:e.data.content,filename:e.filename,filePath:e.filePath})});break;case"file":t=(0,n.jsx)("div",{className:"overflow-auto h-full",children:(0,n.jsx)(rK,{content:e.data.content,filename:e.filename,type:"yaml"===e.data.type?"yaml":"text"})});break;case"spreadsheet":t=(0,n.jsx)("div",{className:"h-full",children:(0,n.jsx)(r6,{url:e.url,filename:e.filename,filePath:e.filePath,compact:!0})});break;case"database":t=(0,n.jsx)("div",{className:"overflow-auto h-full",children:(0,n.jsx)(nH,{dbPath:e.dbPath,filename:e.filename})});break;case"richDocument":t=(0,n.jsx)("div",{className:"h-full",children:(0,n.jsx)(oi,{mode:e.mode,initialHtml:e.html,filePath:e.filePath,compact:!0})});break;case"directory":t=(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-4 px-6",children:[(0,n.jsx)("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center",style:{background:"color-mix(in srgb, var(--color-accent) 10%, transparent)"},children:(0,n.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})})}),(0,n.jsx)("p",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:e.name})]});break;default:t=null}}return(0,n.jsxs)("aside",{className:"h-full border-l flex flex-col",style:{borderColor:"var(--color-border)",background:"var(--color-bg)"},children:[(0,n.jsxs)("div",{className:"px-3 py-2.5 flex items-center gap-2 flex-shrink-0",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:l,className:"p-1 rounded-md transition-colors flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Close preview",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}),(0,n.jsx)("span",{className:"text-[13px] font-medium truncate min-w-0",style:{color:"var(--color-text)"},children:r.filename}),(0,n.jsx)("span",{className:"text-[10px] font-medium px-1.5 py-[1px] rounded flex-shrink-0",style:{background:"".concat(a.color,"14"),color:a.color},children:a.label}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 ml-auto flex-shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:i,className:"p-1.5 rounded-md transition-colors",style:{color:"var(--color-text-muted)"},title:"Open with default app",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}),c&&(0,n.jsx)("a",{href:c,download:r.filename,className:"p-1.5 rounded-md transition-colors",style:{color:"var(--color-text-muted)"},title:"Download",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]})}),(0,n.jsx)("button",{type:"button",onClick:s,className:"p-1.5 rounded-md transition-colors",style:{color:"var(--color-text-muted)"},title:"Reveal in Finder",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:t}),(0,n.jsx)("div",{className:"px-3 py-1.5 border-t flex-shrink-0",style:{borderColor:"var(--color-border)"},children:(0,n.jsx)("p",{className:"text-[10px] truncate",style:{color:"var(--color-text-muted)",fontFamily:"'SF Mono', 'Fira Code', monospace"},title:r.path,children:r.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~")})})]})}function ie(e){let{content:t,workspaceExists:r,expectedPath:o,tree:l,activePath:a,browseDir:s,treeLoading:i,members:c,onNodeSelect:d,onNavigateToObject:u,onRefreshObject:x,onRefreshTree:h,onNavigate:p,onOpenEntry:m,searchFn:f,onSelectCronJob:v,onBackToCronDashboard:g,cronView:y,onCronViewChange:b,cronCalMode:j,onCronCalModeChange:k,cronDate:w,onCronDateChange:N,cronRunFilter:C,onCronRunFilterChange:S,cronRun:M,onCronRunChange:L,onSendCommand:T}=e;switch(t.kind){case"loading":return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})});case"object":return(0,n.jsx)(it,{data:t.data,members:c,onNavigateToObject:u,onRefreshObject:x,onOpenEntry:m});case"document":return(0,n.jsx)(rU,{content:t.data.content,title:t.title,filePath:null!=a?a:void 0,tree:l,onSave:h,onNavigate:p,searchFn:f});case"file":return(0,n.jsx)(rK,{content:t.data.content,filename:t.filename,type:"yaml"===t.data.type?"yaml":"text"});case"code":return(0,n.jsx)(nm,{content:t.data.content,filename:t.filename,filePath:t.filePath});case"media":return(0,n.jsx)(nM,{url:t.url,filename:t.filename,mediaType:t.mediaType,filePath:t.filePath});case"spreadsheet":return(0,n.jsx)(r6,{url:t.url,filename:t.filename,filePath:t.filePath});case"html":return(0,n.jsx)(r9,{rawUrl:t.rawUrl,contentUrl:t.contentUrl,filename:t.filename});case"app":return(0,n.jsx)(ns,{appPath:t.appPath,manifest:t.manifest});case"database":return(0,n.jsx)(nH,{dbPath:t.dbPath,filename:t.filename});case"report":return(0,n.jsx)(o9,{reportPath:t.reportPath});case"directory":{let e=null!=s&&a===s;if(e&&i)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)(G.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})});let r=e?{...t.node,children:l}:t.node;return(0,n.jsx)(ir,{node:r,onNodeSelect:d})}case"cron-dashboard":return(0,n.jsx)(aG,{onSelectJob:v,onSendCommand:T,activeView:y,onViewChange:b,calendarMode:j,onCalendarModeChange:k,calendarDate:w,onCalendarDateChange:N});case"cron-job":return(0,n.jsx)(ss,{job:t.job,onBack:g,onSendCommand:T,runFilter:C,onRunFilterChange:S,expandedRunTs:M,onExpandedRunChange:L});case"cron-session":return(0,n.jsx)(sm,{job:t.job,run:t.run,sessionId:t.sessionId,onBack:()=>g(),onBackToJob:()=>v(t.jobId)});case"duckdb-missing":return(0,n.jsx)(nU,{});case"richDocument":return(0,n.jsx)(oi,{mode:t.mode,initialHtml:t.html,filePath:t.filePath,onSave:h});default:if(0===l.length)return(0,n.jsx)(oQ,{workspaceExists:r,expectedPath:o});return(0,n.jsx)(io,{tree:l,onNodeSelect:d})}}function it(e){var t,r,a,s,i,c,d,u,x,h,p,m,f,v,g,y;let{data:b,members:j,onNavigateToObject:k,onRefreshObject:w,onOpenEntry:N}=e,C=(0,l.useSearchParams)(),S=(0,l.useRouter)(),M=e=>{var t;let r=null!=(t=e.entry_id)?t:e.id;return"string"==typeof r?r:"number"==typeof r||"boolean"==typeof r||"bigint"==typeof r?String(r):""},[L,T]=(0,o.useState)(!1),D=(0,o.useMemo)(()=>(0,eb.yh)(C),[]),[E,R]=(0,o.useState)(()=>{var e;return null!=(e=D.viewType)?e:ro(void 0,void 0,b.object.default_view)}),[W,I]=(0,o.useState)(()=>{var e;return null!=(e=b.viewSettings)?e:{}}),[B,F]=(0,o.useState)(()=>{var e;return null!=(e=D.filters)?e:rv()}),[P,A]=(0,o.useState)(null!=(t=b.savedViews)?t:[]),[_,z]=(0,o.useState)(null!=(r=D.view)?r:b.activeView),[O,U]=(0,o.useState)(null!=(s=null!=(a=D.page)?a:b.page)?s:1),[H,V]=(0,o.useState)(null!=(c=null!=(i=D.pageSize)?i:b.pageSize)?c:100),[J,K]=(0,o.useState)(null!=(d=b.totalCount)?d:b.entries.length),[q,G]=(0,o.useState)(b.entries),[$,Z]=(0,o.useState)(null!=(u=D.search)?u:""),[Y,Q]=(0,o.useState)(null!=(x=D.sort)?x:void 0),X=(0,o.useRef)(null),ee=B.rules.length>0||(null!=(h=null==Y?void 0:Y.length)?h:0)>0||$.trim().length>0,[et,er]=(0,o.useState)(null!=(p=D.cols)?p:void 0),en=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(!en.current){en.current=!0;return}let e=new URLSearchParams(window.location.search),t=new URLSearchParams(e);for(let e of["viewType","view","filters","search","sort","page","pageSize","cols"])t.delete(e);E!==ro(void 0,void 0,b.object.default_view)&&t.set("viewType",E),_&&t.set("view",_),B.rules.length>0&&t.set("filters",btoa(JSON.stringify(B))),$&&t.set("search",$),Y&&Y.length>0&&t.set("sort",btoa(JSON.stringify(Y))),O>1&&t.set("page",String(O)),100!==H&&t.set("pageSize",String(H)),et&&et.length>0&&t.set("cols",et.join(","));let r=t.toString();r!==e.toString()&&S.replace(r?"/?".concat(r):"/",{scroll:!1})},[E,_,B,$,Y,O,H,et]);let eo=(0,o.useMemo)(()=>{if(!et||0===et.length)return;let e={};for(let t of b.fields)e[t.id]=et.includes(t.name);return e.created_at=et.includes("created_at"),e.updated_at=et.includes("updated_at"),e},[et,b.fields]),el=(0,o.useCallback)(e=>{let t=[];for(let r of b.fields)!1!==e[r.id]&&t.push(r.name);!1!==e.created_at&&t.push("created_at"),!1!==e.updated_at&&t.push("updated_at"),er(t.length>0?t:void 0)},[b.fields]),ea=(0,o.useCallback)(async e=>{var t,r,n,o,l,a,s,i;let c=null!=(t=null==e?void 0:e.page)?t:O,d=null!=(r=null==e?void 0:e.pageSize)?r:H,u=null!=(n=null==e?void 0:e.filters)?n:B,x=null!=(o=null==e?void 0:e.sort)?o:Y,h=null!=(l=null==e?void 0:e.search)?l:$,p=new URLSearchParams;p.set("page",String(c)),p.set("pageSize",String(d)),u&&u.rules.length>0&&p.set("filters",rf(u)),x&&x.length>0&&p.set("sort",JSON.stringify(x)),h&&p.set("search",h);try{let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"?").concat(p.toString()));if(!e.ok)return;let t=await e.json();G(t.entries),K(null!=(a=t.totalCount)?a:t.entries.length),U(null!=(s=t.page)?s:c),V(null!=(i=t.pageSize)?i:d)}catch(e){}},[O,H,B,Y,$,b.object.name]);(0,o.useEffect)(()=>{var e;if(ee)return void ea();G(b.entries),K(null!=(e=b.totalCount)?e:b.entries.length)},[b.entries,b.totalCount]),(0,o.useEffect)(()=>{var e;A(null!=(e=b.savedViews)?e:[]),b.viewSettings&&I(b.viewSettings);let t=function(e){var t,r,n,o;let l=e.activeView;if(!l)return null;let a=(null!=(t=e.savedViews)?t:[]).find(e=>e.name===l);if(!a)return null;let s=null!=(r=a.filters)?r:rv(),i=a.columns,c=a.name,d=a.view_type,u=a.settings,x=e.currentActiveViewName!==c,h=(n=e.currentFilters,rf(n)!==rf(s)),p=!function(e,t){if(!e&&!t)return!0;if(!e||!t||e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1)if(e[r]!==t[r])return!1;return!0}(e.currentViewColumns,i),m=e.currentViewType!==d,f=(o=e.currentSettings,(!!o||!!u)&&(!o||!u||JSON.stringify(o)!==JSON.stringify(u)));return{shouldApply:x||h||p||m||f,nextFilters:s,nextColumns:i,nextActiveViewName:c,nextViewType:d,nextSettings:u}}({savedViews:b.savedViews,activeView:b.activeView,currentActiveViewName:_,currentFilters:B,currentViewColumns:et,currentViewType:E,currentSettings:W});(null==t?void 0:t.shouldApply)&&(F(t.nextFilters),er(t.nextColumns),z(t.nextActiveViewName),t.nextViewType&&R(t.nextViewType),t.nextSettings&&I(e=>({...e,...t.nextSettings})),ea({page:1,filters:t.nextFilters}))},[b.savedViews,b.activeView]);let es=(0,o.useCallback)(e=>{F(e),U(1),ea({page:1,filters:e})},[ea]),ei=(0,o.useCallback)(e=>{Z(e),X.current&&clearTimeout(X.current),X.current=setTimeout(()=>{U(1),ea({page:1,search:e})},300)},[ea]),ec=(0,o.useCallback)(e=>{U(e),ea({page:e})},[ea]),ed=(0,o.useCallback)(e=>{V(e),U(1),ea({page:1,pageSize:e})},[ea]),eu=(0,o.useCallback)(()=>{ea(),w()},[ea,w]),ex=(0,o.useCallback)(async e=>{let t=[...P.filter(t=>t.name!==e),{name:e,view_type:E,filters:B,columns:et,settings:W}];A(t),z(e);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:t,activeView:e,viewSettings:W})})}catch(e){}},[B,P,b.object.name,E,et,W]),eh=(0,o.useCallback)(e=>{var t;let r=null!=(t=e.filters)?t:rv();F(r),er(e.columns),z(e.name),e.view_type&&R(e.view_type),e.settings&&I(t=>({...t,...e.settings})),U(1),ea({page:1,filters:r})},[ea]),ep=(0,o.useCallback)(async e=>{let t=P.filter(t=>t.name!==e);A(t),_===e&&(z(void 0),F(rv()),er(void 0));try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:t,activeView:_===e?void 0:_})})}catch(e){}},[P,_,b.object.name]),em=(0,o.useCallback)(async e=>{z(e),e||er(void 0);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:P,activeView:e})})}catch(e){}},[P,b.object.name]),ef=(0,o.useCallback)(e=>{R(e)},[]),ev=(0,o.useCallback)(async e=>{I(e);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:P,activeView:_,viewSettings:e})})}catch(e){}},[P,_,b.object.name]),eg=(0,o.useMemo)(()=>{let e=P.find(e=>e.name===_),t=function(e,t){if(!t)return null!=e?e:{};if(!e)return t;let r={...t};for(let t of Object.keys(e)){let n=e[t];void 0!==n&&(r[t]=n)}return r}(null==e?void 0:e.settings,W),r=[...b.fields.map(e=>({name:e.name,type:e.type})),{name:"created_at",type:"date"},{name:"updated_at",type:"date"}];return"kanban"!==E||t.kanbanField||(t.kanbanField=rl("kanban","kanbanField",r)),"calendar"!==E||t.calendarDateField||(t.calendarDateField=rl("calendar","calendarDateField",r)),"timeline"!==E||t.timelineStartField||(t.timelineStartField=rl("timeline","timelineStartField",r)),"gallery"!==E||t.galleryTitleField||(t.galleryTitleField=rl("gallery","galleryTitleField",r)),"list"!==E||t.listTitleField||(t.listTitleField=rl("list","listTitleField",r)),t},[E,W,P,_,b.fields]),ey=async e=>{T(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/display-field"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayField:e})})).ok&&w()}catch(e){}finally{T(!1)}},ej=(0,o.useCallback)(async e=>{let t=eg.calendarDateField,r=eg.calendarEndDateField;if(!t)return;let n={[t]:e.newDate};r&&e.newEndDate&&(n[r]=e.newEndDate),G(n=>n.map(n=>{if(M(n)!==e.entryId)return n;let o={...n,[t]:e.newDate};return r&&e.newEndDate&&(o[r]=e.newEndDate),o}));try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/entries/").concat(encodeURIComponent(e.entryId)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:n})})}catch(e){}},[eg,b.object.name]),ek=(0,o.useCallback)(async e=>{let t=eg.timelineStartField,r=eg.timelineEndField;if(!t)return;let n={[t]:e.newStartDate};r&&(n[r]=e.newEndDate),G(n=>n.map(n=>{if(M(n)!==e.entryId)return n;let o={...n,[t]:e.newStartDate};return r&&(o[r]=e.newEndDate),o}));try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(b.object.name),"/entries/").concat(encodeURIComponent(e.entryId)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:n})})}catch(e){}},[eg,b.object.name]),ew=b.fields.filter(e=>!["relation","boolean","richtext"].includes(e.type)),eN=b.fields.some(e=>"relation"===e.type),eC=b.reverseRelations&&b.reverseRelations.some(e=>Object.keys(e.entries).length>0),eS=(0,o.useMemo)(()=>null==j?void 0:j.map(e=>({id:e.id,name:e.name})),[j]),eM=(0,o.useMemo)(()=>[...b.fields,{id:"created_at",name:"created_at",type:"date"},{id:"updated_at",name:"updated_at",type:"date"}],[b.fields]);return(0,n.jsxs)("div",{className:"p-6",children:[(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight capitalize",style:{color:"var(--color-text)"},children:b.object.name}),b.object.description&&(0,n.jsx)("p",{className:"text-sm mt-1",style:{color:"var(--color-text-muted)"},children:b.object.description}),(0,n.jsxs)("div",{className:"flex items-center gap-3 mt-3 flex-wrap",children:[(0,n.jsxs)("span",{className:"text-xs px-2 py-1 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[J," entries"]}),(0,n.jsxs)("span",{className:"text-xs px-2 py-1 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[b.fields.length," fields"]}),eN&&(0,n.jsxs)("span",{className:"text-xs px-2 py-1 rounded-full",style:{background:"var(--color-chip-document)",color:"var(--color-chip-document-text)",border:"1px solid var(--color-border)"},children:[b.fields.filter(e=>"relation"===e.type).length," relation",1!==b.fields.filter(e=>"relation"===e.type).length?"s":""]}),eC&&(0,n.jsxs)("span",{className:"text-xs px-2 py-1 rounded-full",style:{background:"var(--color-chip-database)",color:"var(--color-chip-database-text)",border:"1px solid var(--color-border)"},children:[b.reverseRelations.filter(e=>Object.keys(e.entries).length>0).length," linked from"]})]}),ew.length>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-3",children:[(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Display field:"}),(0,n.jsx)("select",{value:null!=(m=b.effectiveDisplayField)?m:"",onChange:e=>ey(e.target.value),disabled:L,className:"text-xs px-2 py-1 rounded-md outline-none transition-colors cursor-pointer",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)",opacity:L?.5:1},children:ew.map(e=>(0,n.jsx)("option",{value:e.name,children:e.name},e.id))}),L&&(0,n.jsx)("div",{className:"w-3 h-3 border border-t-transparent rounded-full animate-spin",style:{borderColor:"var(--color-text-muted)"}}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)",opacity:.6},children:"Used when other objects link here"})]})]}),(0,n.jsxs)("div",{className:"mb-4 py-3 px-4 rounded-lg border",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 mb-2",children:[(0,n.jsx)(rb,{value:E,onChange:ef}),(0,n.jsx)(rT,{viewType:E,settings:eg,fields:eM,onSettingsChange:ev})]}),(0,n.jsx)(sR,{fields:b.fields,filters:B,onFiltersChange:es,savedViews:P,activeViewName:_,onSaveView:ex,onLoadView:eh,onDeleteView:ep,onSetActiveView:em,members:eS})]}),"kanban"===E&&(0,n.jsx)(ti,{objectName:b.object.name,fields:b.fields,entries:q,statuses:b.statuses,members:j,relationLabels:b.relationLabels,onEntryClick:N?e=>N(b.object.name,e):void 0,onRefresh:eu}),"table"===E&&(0,n.jsx)(tt,{objectName:b.object.name,fields:b.fields,entries:q,members:j,relationLabels:b.relationLabels,reverseRelations:b.reverseRelations,onNavigateToObject:k,onNavigateToEntry:N,onEntryClick:N?e=>N(b.object.name,e):void 0,onRefresh:eu,columnVisibility:eo,onColumnVisibilityChanged:el,serverPagination:{totalCount:J,page:O,pageSize:H,onPageChange:ec,onPageSizeChange:ed},onServerSearch:ei}),"calendar"===E&&(0,n.jsx)(tK,{objectName:b.object.name,fields:b.fields,entries:q,dateField:null!=(f=eg.calendarDateField)?f:"",endDateField:eg.calendarEndDateField,mode:null!=(v=eg.calendarMode)?v:"month",onModeChange:e=>ev({...eg,calendarMode:e}),members:j,onEntryClick:N?e=>N(b.object.name,e):void 0,onEntryDateChange:ej}),"timeline"===E&&(0,n.jsx)(t4,{objectName:b.object.name,fields:b.fields,entries:q,startDateField:null!=(g=eg.timelineStartField)?g:"",endDateField:eg.timelineEndField,groupField:eg.timelineGroupField,zoom:null!=(y=eg.timelineZoom)?y:"week",onZoomChange:e=>ev({...eg,timelineZoom:e}),members:j,onEntryClick:N?e=>N(b.object.name,e):void 0,onEntryDateChange:ek}),"gallery"===E&&(0,n.jsx)(t8,{objectName:b.object.name,fields:b.fields,entries:q,titleField:eg.galleryTitleField,coverField:eg.galleryCoverField,members:j,relationLabels:b.relationLabels,onEntryClick:N?e=>N(b.object.name,e):void 0}),"list"===E&&(0,n.jsx)(rt,{objectName:b.object.name,fields:b.fields,entries:q,titleField:eg.listTitleField,subtitleField:eg.listSubtitleField,members:j,onEntryClick:N?e=>N(b.object.name,e):void 0})]})}function ir(e){var t;let{node:r,onNodeSelect:o}=e,l=null!=(t=r.children)?t:[];return(0,n.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight mb-1 capitalize",style:{color:"var(--color-text)"},children:r.name}),(0,n.jsxs)("p",{className:"text-sm mb-6",style:{color:"var(--color-text-muted)"},children:[l.length," items"]}),0===l.length?(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"This folder is empty."}):(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:l.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>o(e),className:"flex items-center gap-3 p-4 rounded-2xl text-left transition-all duration-100 cursor-pointer",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--color-border-strong)",e.currentTarget.style.transform="translateY(-1px)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--color-border)",e.currentTarget.style.transform="translateY(0)"},children:[(0,n.jsx)("span",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:"object"===e.type?"var(--color-chip-object)":"document"===e.type?"var(--color-chip-document)":"database"===e.type?"var(--color-chip-database)":"report"===e.type?"var(--color-chip-report)":"var(--color-surface-hover)",color:"object"===e.type?"var(--color-chip-object-text)":"document"===e.type?"var(--color-chip-document-text)":"database"===e.type?"var(--color-chip-database-text)":"report"===e.type?"var(--color-chip-report-text)":"var(--color-text-muted)"},children:(0,n.jsx)(il,{type:e.type})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:e.name.replace(/\.md$/,"")}),(0,n.jsxs)("div",{className:"text-xs capitalize",style:{color:"var(--color-text-muted)"},children:[e.type,e.children?" (".concat(e.children.length,")"):""]})]})]},e.path))})]})}function io(e){let{tree:t,onNodeSelect:r}=e,o=[],l=[];return!function e(t){for(let r of t)"object"===r.type?o.push(r):"document"===r.type&&l.push(r),r.children&&e(r.children)}(t),(0,n.jsxs)("div",{className:"p-8 max-w-4xl mx-auto",children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight mb-2",style:{color:"var(--color-text)"},children:"Workspace"}),(0,n.jsx)("p",{className:"text-sm mb-8",style:{color:"var(--color-text-muted)"},children:"Select an item from the sidebar, or browse the sections below."}),o.length>0&&(0,n.jsxs)("div",{className:"mb-8",children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Objects"}),(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:o.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>r(e),className:"flex items-center gap-3 p-4 rounded-2xl text-left transition-all duration-100 cursor-pointer",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--color-accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--color-border)"},children:[(0,n.jsx)("span",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:"var(--color-chip-object)",color:"var(--color-chip-object-text)"},children:(0,n.jsx)(il,{type:"object"})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium capitalize truncate",style:{color:"var(--color-text)"},children:e.name}),(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"kanban"===e.defaultView?"Kanban board":"Table view"})]})]},e.path))})]}),l.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Documents"}),(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:l.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>r(e),className:"flex items-center gap-3 p-4 rounded-2xl text-left transition-all duration-100 cursor-pointer",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--color-chip-document-text)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--color-border)"},children:[(0,n.jsx)("span",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:"var(--color-chip-document)",color:"var(--color-chip-document-text)"},children:(0,n.jsx)(il,{type:"document"})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:e.name.replace(/\.md$/,"")}),(0,n.jsx)("div",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Document"})]})]},e.path))})]})]})}function il(e){let{type:t}=e;switch(t){case"object":return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M3 9h18"}),(0,n.jsx)("path",{d:"M3 15h18"})]});case"document":return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,n.jsx)("path",{d:"M10 9H8"}),(0,n.jsx)("path",{d:"M16 13H8"}),(0,n.jsx)("path",{d:"M16 17H8"})]});case"folder":return(0,n.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})});case"database":return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),(0,n.jsx)("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),(0,n.jsx)("path",{d:"M3 12A9 3 0 0 0 21 12"})]});case"report":return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",x2:"12",y1:"20",y2:"10"}),(0,n.jsx)("line",{x1:"18",x2:"18",y1:"20",y2:"4"}),(0,n.jsx)("line",{x1:"6",x2:"6",y1:"20",y2:"14"})]});default:return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,n.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]})}}function ia(){return(0,n.jsx)(s8,{})}},40077:(e,t,r)=>{"use strict";r.d(t,{N:()=>U});var n=r(80534),o=r(74166),l=r(44960),a=r(2741),s=r(12890),i=r(19237),c=r(45770),d=r(68354),u=r(48357),x=r(3224),h=r(13707),p=r(23173),m=r(58313),f=r(97726),v=r(90171),g=r(66735),y=r(51329),b=r(12674),j=r(25249),k=r(11913),w=r(67283),N=r(60577),C=r(1208),S=r(84240),M=r(53940),L=r(13847),T=r(49166);let D=["#2563eb","#60a5fa","#22c55e","#f59e0b","#c084fc","#fb923c","#14b8a6","#f43f5e","#a78bfa","#38bdf8"],E={fontSize:11,fill:"var(--color-text-muted)"},R={stroke:"var(--color-border-strong)",strokeDasharray:"3 3"};function W(){return{contentStyle:{background:"var(--color-surface)",border:"1px solid var(--color-border)",borderRadius:8,fontSize:12,color:"var(--color-text)"},itemStyle:{color:"var(--color-text)"},labelStyle:{color:"var(--color-text-muted)",marginBottom:4}}}function I(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:String(e)}function B(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"number"==typeof e?Math.abs(e)>=1e6?"".concat((e/1e6).toFixed(1),"M"):Math.abs(e)>=1e3?"".concat((e/1e3).toFixed(1),"K"):Number.isInteger(e)?String(e):e.toFixed(2):I(e)}function F(e){if(null==e)return"";let t=I(e);return t.length>16&&!isNaN(Date.parse(t))?t.slice(0,10):t.length>20?t.slice(0,18)+"...":t}function P(e){var t,r,o,p,m,f;let{config:v,data:g,compact:y,ChartComponent:b,SeriesComponent:j,areaProps:k}=e,{mapping:w}=v,N=null!=(o=null!=(r=w.xAxis)?r:Object.keys(null!=(t=g[0])?t:{})[0])?o:"x",C=null!=(m=w.yAxis)?m:Object.keys(null!=(p=g[0])?p:{}).filter(e=>e!==N),S=null!=(f=w.colors)?f:D,M=W();return(0,n.jsx)(l.u,{width:"100%",height:y?200:320,children:(0,n.jsxs)(b,{data:g,margin:{top:8,right:16,left:0,bottom:4},children:[(0,n.jsx)(a.d,{...R}),(0,n.jsx)(s.W,{dataKey:N,tick:E,tickFormatter:F,axisLine:{stroke:"var(--color-border)"},tickLine:!1}),(0,n.jsx)(i.h,{tick:E,tickFormatter:B,axisLine:!1,tickLine:!1,width:48}),(0,n.jsx)(c.m,{...M,formatter:B,labelFormatter:F}),C.length>1&&!y&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}}),C.map((e,t)=>{let r=S[t%S.length],o={key:e,dataKey:e,fill:r,stroke:r,name:e,...k};return j===u.yP&&(o.radius=[4,4,0,0],o.maxBarSize=48),j===x.N1&&(o.strokeWidth=2,o.dot={r:3,fill:r},o.activeDot={r:5}),j===h.Gk&&(o.fillOpacity=.15,o.strokeWidth=2),(0,n.jsx)(j,{...o})})]})})}function A(e){var t,r,o,a,s,i,u;let{config:x,data:h,compact:v}=e,{mapping:g,type:y}=x,b=null!=(o=null!=(r=g.nameKey)?r:Object.keys(null!=(t=h[0])?t:{})[0])?o:"name",j=null!=(i=null!=(s=g.valueKey)?s:Object.keys(null!=(a=h[0])?a:{})[1])?i:"value",k=null!=(u=g.colors)?u:D,w=W();return(0,n.jsx)(l.u,{width:"100%",height:v?200:320,children:(0,n.jsxs)(p.r,{children:[(0,n.jsx)(m.Fq,{data:h,dataKey:j,nameKey:b,cx:"50%",cy:"50%",innerRadius:"donut"===y?"50%":0,outerRadius:v?70:110,paddingAngle:2,label:v?void 0:e=>{let t=e.name,r="number"==typeof e.percent?e.percent:0;return"".concat(F(t)," ").concat((100*r).toFixed(0),"%")},labelLine:!v,style:{fontSize:11},children:h.map((e,t)=>(0,n.jsx)(f.f,{fill:k[t%k.length]},t))}),(0,n.jsx)(c.m,{...w,formatter:B}),!v&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}})]})})}function _(e){var t,r,o,a,s,i,u,x;let{config:h,data:p,compact:m}=e,{mapping:f}=h,k=null!=(a=null!=(o=null!=(t=f.xAxis)?t:f.nameKey)?o:Object.keys(null!=(r=p[0])?r:{})[0])?a:"name",w=null!=(u=f.yAxis)?u:[null!=(i=Object.keys(null!=(s=p[0])?s:{})[1])?i:"value"],N=null!=(x=f.colors)?x:D,C=W();return(0,n.jsx)(l.u,{width:"100%",height:m?200:320,children:(0,n.jsxs)(v.V,{data:p,cx:"50%",cy:"50%",outerRadius:m?60:100,children:[(0,n.jsx)(g.z,{stroke:"var(--color-border)"}),(0,n.jsx)(y.r,{dataKey:k,tick:{fontSize:11,fill:"var(--color-text-muted)"}}),(0,n.jsx)(b.E,{tick:{fontSize:10,fill:"var(--color-text-muted)"}}),w.map((e,t)=>(0,n.jsx)(j.Vd,{name:e,dataKey:e,stroke:N[t%N.length],fill:N[t%N.length],fillOpacity:.2},e)),(0,n.jsx)(c.m,{...C}),!m&&w.length>1&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}})]})})}function z(e){var t,r,o,u,x,h,p;let{config:m,data:f,compact:v}=e,{mapping:g}=m,y=null!=(o=null!=(r=g.xAxis)?r:Object.keys(null!=(t=f[0])?t:{})[0])?o:"x",b=null!=(h=g.yAxis)?h:[null!=(x=Object.keys(null!=(u=f[0])?u:{})[1])?x:"y"],j=null!=(p=g.colors)?p:D,N=W();return(0,n.jsx)(l.u,{width:"100%",height:v?200:320,children:(0,n.jsxs)(k.t,{margin:{top:8,right:16,left:0,bottom:4},children:[(0,n.jsx)(a.d,{...R}),(0,n.jsx)(s.W,{dataKey:y,tick:E,name:y,axisLine:{stroke:"var(--color-border)"},tickLine:!1}),(0,n.jsx)(i.h,{tick:E,tickFormatter:B,axisLine:!1,tickLine:!1,width:48}),(0,n.jsx)(c.m,{...N}),b.map((e,t)=>(0,n.jsx)(w.Xl,{name:e,data:f,fill:j[t%j.length]},e)),!v&&b.length>1&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}})]})})}function O(e){var t,r,o,a,s,i,d;let{config:u,data:x,compact:h}=e,{mapping:p}=u,m=null!=(o=null!=(r=p.nameKey)?r:Object.keys(null!=(t=x[0])?t:{})[0])?o:"name",f=null!=(i=null!=(s=p.valueKey)?s:Object.keys(null!=(a=x[0])?a:{})[1])?i:"value",v=null!=(d=p.colors)?d:D,g=W(),y=x.map((e,t)=>({...e,fill:v[t%v.length]}));return(0,n.jsx)(l.u,{width:"100%",height:h?200:320,children:(0,n.jsxs)(N.v,{children:[(0,n.jsx)(c.m,{...g}),(0,n.jsx)(C.rh,{data:y,dataKey:f,nameKey:m,isAnimationActive:!0,children:(0,n.jsx)(S.Ze,{position:"right",fill:"var(--color-text-muted)",stroke:"none",fontSize:11,dataKey:m})})]})})}function U(e){let{config:t,data:r,compact:l}=e,a=(0,o.useMemo)(()=>{var e;if(!r||0===r.length)return[];let{mapping:n}=t,o=new Set([...null!=(e=n.yAxis)?e:[],...n.valueKey?[n.valueKey]:[]]);return r.map(e=>{let t={...e};for(let e of o)if(e in t){let r=t[e];"string"!=typeof r||""===r||isNaN(Number(r))||(t[e]=Number(r))}return t})},[r,t]);if(0===a.length)return(0,n.jsx)("div",{className:"flex items-center justify-center rounded-xl",style:{height:l?200:320,background:"var(--color-surface)",border:"1px solid var(--color-border)",color:"var(--color-text-muted)",fontSize:13},children:"No data"});switch(t.type){case"bar":default:return(0,n.jsx)(P,{config:t,data:a,compact:l,ChartComponent:M.E,SeriesComponent:u.yP});case"line":return(0,n.jsx)(P,{config:t,data:a,compact:l,ChartComponent:L.b,SeriesComponent:x.N1});case"area":return(0,n.jsx)(P,{config:t,data:a,compact:l,ChartComponent:T.Q,SeriesComponent:h.Gk});case"pie":case"donut":return(0,n.jsx)(A,{config:t,data:a,compact:l});case"radar":case"radialBar":return(0,n.jsx)(_,{config:t,data:a,compact:l});case"scatter":return(0,n.jsx)(z,{config:t,data:a,compact:l});case"funnel":return(0,n.jsx)(O,{config:t,data:a,compact:l})}}},48121:(e,t,r)=>{Promise.resolve().then(r.bind(r,7713))},68840:(e,t,r)=>{"use strict";r.d(t,{VE:()=>d,ZC:()=>c,bJ:()=>u,lc:()=>x,m9:()=>h,yh:()=>s});let n=["table","kanban","calendar","timeline","gallery","list"],o=["overview","calendar","timeline","insights"],l=["day","week","month","year"],a=["all","ok","error","running"];function s(e){let t="string"==typeof e?new URLSearchParams(e):e,r=null,s=t.get("entry");if(s&&s.includes(":")){let e=s.indexOf(":");r={objectName:s.slice(0,e),entryId:s.slice(e+1)}}let i=null,c=t.get("filters");if(c)try{i=JSON.parse(atob(c))}catch(e){}let d=null,u=t.get("sort");if(u)try{d=JSON.parse(atob(u))}catch(e){}let x=t.get("page"),h=t.get("pageSize"),p=t.get("cols"),m=t.get("viewType"),f=t.get("cronView"),v=t.get("cronCalMode"),g=t.get("cronRunFilter"),y=t.get("cronRun");return{path:t.get("path"),chat:t.get("chat"),subagent:t.get("subagent"),fileChat:t.get("fileChat"),entry:r,send:t.get("send"),browse:t.get("browse"),hidden:"1"===t.get("hidden"),preview:t.get("preview"),view:t.get("view"),viewType:m&&n.includes(m)?m:null,filters:i,search:t.get("search"),sort:d,page:x&&parseInt(x,10)||null,pageSize:h&&parseInt(h,10)||null,cols:p?p.split(",").filter(Boolean):null,cronView:f&&o.includes(f)?f:null,cronCalMode:v&&l.includes(v)?v:null,cronDate:t.get("cronDate"),cronRunFilter:g&&a.includes(g)?g:null,cronRun:y&&parseInt(y,10)||null,terminal:"1"===t.get("terminal")}}let i=["viewType","view","filters","search","sort","page","pageSize","cols"];function c(e,t){let r=new URLSearchParams;if(e.activePath){r.set("path",e.activePath);let n=t.get("entry");for(let o of(n&&r.set("entry",n),e.fileChatSessionId&&r.set("fileChat",e.fileChatSessionId),"~cron"===e.activePath?("overview"!==e.cronView&&r.set("cronView",e.cronView),"calendar"===e.cronView&&"month"!==e.cronCalMode&&r.set("cronCalMode",e.cronCalMode),("calendar"===e.cronView||"timeline"===e.cronView)&&e.cronDate&&r.set("cronDate",e.cronDate)):e.activePath.startsWith("~cron/")&&("all"!==e.cronRunFilter&&r.set("cronRunFilter",e.cronRunFilter),null!=e.cronRun&&r.set("cronRun",String(e.cronRun))),i)){let e=t.get(o);e&&r.set(o,e)}}else e.activeSessionId&&(r.set("chat",e.activeSessionId),e.activeSubagentKey&&r.set("subagent",e.activeSubagentKey));return e.browseDir&&r.set("browse",e.browseDir),e.showHidden&&r.set("hidden","1"),e.previewPath&&r.set("preview",e.previewPath),e.terminalOpen&&r.set("terminal","1"),r}function d(e,t){return"/?entry=".concat(encodeURIComponent(e),":").concat(encodeURIComponent(t))}function u(e){return"/?path=".concat(encodeURIComponent(e))}function x(e){let t=function(e){try{if(e.startsWith("/"))return new URL(e,"http://localhost");let t=new URL(e);if("/"===t.pathname||"/workspace"===t.pathname)return t}catch(e){}return null}(e);if(t&&("/"===t.pathname||"/workspace"===t.pathname)){let e=t.searchParams.get("entry");if(e&&e.includes(":")){let t=e.indexOf(":");return{kind:"entry",objectName:e.slice(0,t),entryId:e.slice(t+1)}}let r=t.searchParams.get("path");if(r)return{kind:"file",path:r}}if(e.startsWith("@entry/")){let t=e.slice(7),r=t.indexOf("/");if(r>0)return{kind:"entry",objectName:t.slice(0,r),entryId:t.slice(r+1)}}return null}function h(e){return!!(e.startsWith("@entry/")||"/workspace"===e||e.startsWith("/workspace?")||e.startsWith("/workspace#")||"/"===e||e.startsWith("/?")||e.startsWith("/#"))}},71615:()=>{},77704:(e,t,r)=>{"use strict";r.d(t,{$Q:()=>o,IB:()=>a,x_:()=>l,zM:()=>s});var n=r(80534);function o(e){let{children:t}=e;return(0,n.jsx)("div",{className:"editor-toolbar-group",children:t})}function l(){return(0,n.jsx)("div",{className:"editor-toolbar-divider"})}function a(e){let{active:t,onClick:r,title:o,children:l,disabled:a}=e;return(0,n.jsx)("button",{type:"button",className:"editor-toolbar-btn ".concat(t?"editor-toolbar-btn-active":""),onClick:r,title:o,disabled:a,children:l})}function s(e){let{active:t,onClick:r,title:o,children:l}=e;return(0,n.jsx)("button",{type:"button",className:"bubble-menu-btn ".concat(t?"bubble-menu-btn-active":""),onClick:r,title:o,children:l})}}},e=>{e.O(0,[5700,6237,2763,7073,1377,9363,1705,8522,7358],()=>e(e.s=48121)),_N_E=e.O()}]);
|